/drivers/acpi/dispatcher/dsinit.c

https://bitbucket.org/evzijst/gittest · C · 235 lines · 88 code · 48 blank · 99 comment · 8 complexity · 82b276b35680ba8baee21aa1aa7eb33a MD5 · raw file

  1. /******************************************************************************
  2. *
  3. * Module Name: dsinit - Object initialization namespace walk
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <acpi/acdispat.h>
  44. #include <acpi/acnamesp.h>
  45. #define _COMPONENT ACPI_DISPATCHER
  46. ACPI_MODULE_NAME ("dsinit")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_ds_init_one_object
  50. *
  51. * PARAMETERS: obj_handle - Node
  52. * Level - Current nesting level
  53. * Context - Points to a init info struct
  54. * return_value - Not used
  55. *
  56. * RETURN: Status
  57. *
  58. * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  59. * within the namespace.
  60. *
  61. * Currently, the only objects that require initialization are:
  62. * 1) Methods
  63. * 2) Operation Regions
  64. *
  65. ******************************************************************************/
  66. acpi_status
  67. acpi_ds_init_one_object (
  68. acpi_handle obj_handle,
  69. u32 level,
  70. void *context,
  71. void **return_value)
  72. {
  73. acpi_object_type type;
  74. acpi_status status;
  75. struct acpi_init_walk_info *info = (struct acpi_init_walk_info *) context;
  76. ACPI_FUNCTION_NAME ("ds_init_one_object");
  77. /*
  78. * We are only interested in objects owned by the table that
  79. * was just loaded
  80. */
  81. if (((struct acpi_namespace_node *) obj_handle)->owner_id !=
  82. info->table_desc->table_id) {
  83. return (AE_OK);
  84. }
  85. info->object_count++;
  86. /* And even then, we are only interested in a few object types */
  87. type = acpi_ns_get_type (obj_handle);
  88. switch (type) {
  89. case ACPI_TYPE_REGION:
  90. status = acpi_ds_initialize_region (obj_handle);
  91. if (ACPI_FAILURE (status)) {
  92. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Region %p [%4.4s] - Init failure, %s\n",
  93. obj_handle, acpi_ut_get_node_name (obj_handle),
  94. acpi_format_exception (status)));
  95. }
  96. info->op_region_count++;
  97. break;
  98. case ACPI_TYPE_METHOD:
  99. info->method_count++;
  100. /* Print a dot for each method unless we are going to print the entire pathname */
  101. if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
  102. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
  103. }
  104. /*
  105. * Set the execution data width (32 or 64) based upon the
  106. * revision number of the parent ACPI table.
  107. * TBD: This is really for possible future support of integer width
  108. * on a per-table basis. Currently, we just use a global for the width.
  109. */
  110. if (info->table_desc->pointer->revision == 1) {
  111. ((struct acpi_namespace_node *) obj_handle)->flags |= ANOBJ_DATA_WIDTH_32;
  112. }
  113. /*
  114. * Always parse methods to detect errors, we will delete
  115. * the parse tree below
  116. */
  117. status = acpi_ds_parse_method (obj_handle);
  118. if (ACPI_FAILURE (status)) {
  119. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Method %p [%4.4s] - parse failure, %s\n",
  120. obj_handle, acpi_ut_get_node_name (obj_handle),
  121. acpi_format_exception (status)));
  122. /* This parse failed, but we will continue parsing more methods */
  123. break;
  124. }
  125. /*
  126. * Delete the parse tree. We simply re-parse the method
  127. * for every execution since there isn't much overhead
  128. */
  129. acpi_ns_delete_namespace_subtree (obj_handle);
  130. acpi_ns_delete_namespace_by_owner (((struct acpi_namespace_node *) obj_handle)->object->method.owning_id);
  131. break;
  132. case ACPI_TYPE_DEVICE:
  133. info->device_count++;
  134. break;
  135. default:
  136. break;
  137. }
  138. /*
  139. * We ignore errors from above, and always return OK, since
  140. * we don't want to abort the walk on a single error.
  141. */
  142. return (AE_OK);
  143. }
  144. /*******************************************************************************
  145. *
  146. * FUNCTION: acpi_ds_initialize_objects
  147. *
  148. * PARAMETERS: table_desc - Descriptor for parent ACPI table
  149. * start_node - Root of subtree to be initialized.
  150. *
  151. * RETURN: Status
  152. *
  153. * DESCRIPTION: Walk the namespace starting at "start_node" and perform any
  154. * necessary initialization on the objects found therein
  155. *
  156. ******************************************************************************/
  157. acpi_status
  158. acpi_ds_initialize_objects (
  159. struct acpi_table_desc *table_desc,
  160. struct acpi_namespace_node *start_node)
  161. {
  162. acpi_status status;
  163. struct acpi_init_walk_info info;
  164. ACPI_FUNCTION_TRACE ("ds_initialize_objects");
  165. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  166. "**** Starting initialization of namespace objects ****\n"));
  167. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "Parsing all Control Methods:"));
  168. info.method_count = 0;
  169. info.op_region_count = 0;
  170. info.object_count = 0;
  171. info.device_count = 0;
  172. info.table_desc = table_desc;
  173. /* Walk entire namespace from the supplied root */
  174. status = acpi_walk_namespace (ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
  175. acpi_ds_init_one_object, &info, NULL);
  176. if (ACPI_FAILURE (status)) {
  177. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed, %s\n",
  178. acpi_format_exception (status)));
  179. }
  180. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
  181. "\nTable [%4.4s](id %4.4X) - %hd Objects with %hd Devices %hd Methods %hd Regions\n",
  182. table_desc->pointer->signature, table_desc->table_id, info.object_count,
  183. info.device_count, info.method_count, info.op_region_count));
  184. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  185. "%hd Methods, %hd Regions\n", info.method_count, info.op_region_count));
  186. return_ACPI_STATUS (AE_OK);
  187. }