dsinit.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /******************************************************************************
  2. *
  3. * Module Name: dsinit - Object initialization namespace walk
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acdispat.h"
  45. #include "acnamesp.h"
  46. #include "actables.h"
  47. #define _COMPONENT ACPI_DISPATCHER
  48. ACPI_MODULE_NAME("dsinit")
  49. /* Local prototypes */
  50. static acpi_status
  51. acpi_ds_init_one_object(acpi_handle obj_handle,
  52. u32 level, void *context, void **return_value);
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_ds_init_one_object
  56. *
  57. * PARAMETERS: obj_handle - Node for the object
  58. * Level - Current nesting level
  59. * Context - Points to a init info struct
  60. * return_value - Not used
  61. *
  62. * RETURN: Status
  63. *
  64. * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  65. * within the namespace.
  66. *
  67. * Currently, the only objects that require initialization are:
  68. * 1) Methods
  69. * 2) Operation Regions
  70. *
  71. ******************************************************************************/
  72. static acpi_status
  73. acpi_ds_init_one_object(acpi_handle obj_handle,
  74. u32 level, void *context, void **return_value)
  75. {
  76. struct acpi_init_walk_info *info =
  77. (struct acpi_init_walk_info *)context;
  78. struct acpi_namespace_node *node =
  79. (struct acpi_namespace_node *)obj_handle;
  80. acpi_object_type type;
  81. acpi_status status;
  82. ACPI_FUNCTION_ENTRY();
  83. /*
  84. * We are only interested in NS nodes owned by the table that
  85. * was just loaded
  86. */
  87. if (node->owner_id != info->owner_id) {
  88. return (AE_OK);
  89. }
  90. info->object_count++;
  91. /* And even then, we are only interested in a few object types */
  92. type = acpi_ns_get_type(obj_handle);
  93. switch (type) {
  94. case ACPI_TYPE_REGION:
  95. status = acpi_ds_initialize_region(obj_handle);
  96. if (ACPI_FAILURE(status)) {
  97. ACPI_EXCEPTION((AE_INFO, status,
  98. "During Region initialization %p [%4.4s]",
  99. obj_handle,
  100. acpi_ut_get_node_name(obj_handle)));
  101. }
  102. info->op_region_count++;
  103. break;
  104. case ACPI_TYPE_METHOD:
  105. info->method_count++;
  106. break;
  107. case ACPI_TYPE_DEVICE:
  108. info->device_count++;
  109. break;
  110. default:
  111. break;
  112. }
  113. /*
  114. * We ignore errors from above, and always return OK, since
  115. * we don't want to abort the walk on a single error.
  116. */
  117. return (AE_OK);
  118. }
  119. /*******************************************************************************
  120. *
  121. * FUNCTION: acpi_ds_initialize_objects
  122. *
  123. * PARAMETERS: table_desc - Descriptor for parent ACPI table
  124. * start_node - Root of subtree to be initialized.
  125. *
  126. * RETURN: Status
  127. *
  128. * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
  129. * necessary initialization on the objects found therein
  130. *
  131. ******************************************************************************/
  132. acpi_status
  133. acpi_ds_initialize_objects(u32 table_index,
  134. struct acpi_namespace_node * start_node)
  135. {
  136. acpi_status status;
  137. struct acpi_init_walk_info info;
  138. struct acpi_table_header *table;
  139. acpi_owner_id owner_id;
  140. ACPI_FUNCTION_TRACE(ds_initialize_objects);
  141. status = acpi_tb_get_owner_id(table_index, &owner_id);
  142. if (ACPI_FAILURE(status)) {
  143. return_ACPI_STATUS(status);
  144. }
  145. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  146. "**** Starting initialization of namespace objects ****\n"));
  147. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Parsing all Control Methods:"));
  148. /* Set all init info to zero */
  149. ACPI_MEMSET(&info, 0, sizeof(struct acpi_init_walk_info));
  150. info.owner_id = owner_id;
  151. info.table_index = table_index;
  152. /* Walk entire namespace from the supplied root */
  153. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  154. if (ACPI_FAILURE(status)) {
  155. return_ACPI_STATUS(status);
  156. }
  157. /*
  158. * We don't use acpi_walk_namespace since we do not want to acquire
  159. * the namespace reader lock.
  160. */
  161. status =
  162. acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
  163. ACPI_NS_WALK_UNLOCK, acpi_ds_init_one_object,
  164. NULL, &info, NULL);
  165. if (ACPI_FAILURE(status)) {
  166. ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
  167. }
  168. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  169. status = acpi_get_table_by_index(table_index, &table);
  170. if (ACPI_FAILURE(status)) {
  171. return_ACPI_STATUS(status);
  172. }
  173. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  174. "\nTable [%4.4s](id %4.4X) - %u Objects with %u Devices %u Methods %u Regions\n",
  175. table->signature, owner_id, info.object_count,
  176. info.device_count, info.method_count,
  177. info.op_region_count));
  178. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  179. "%u Methods, %u Regions\n", info.method_count,
  180. info.op_region_count));
  181. return_ACPI_STATUS(AE_OK);
  182. }