nsload.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /******************************************************************************
  2. *
  3. * Module Name: nsload - namespace loading/expanding/contracting procedures
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, 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 <acpi/acnamesp.h>
  44. #include <acpi/acdispat.h>
  45. #include <acpi/actables.h>
  46. #define _COMPONENT ACPI_NAMESPACE
  47. ACPI_MODULE_NAME("nsload")
  48. /* Local prototypes */
  49. #ifdef ACPI_FUTURE_IMPLEMENTATION
  50. acpi_status acpi_ns_unload_namespace(acpi_handle handle);
  51. static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
  52. #endif
  53. #ifndef ACPI_NO_METHOD_EXECUTION
  54. /*******************************************************************************
  55. *
  56. * FUNCTION: acpi_ns_load_table
  57. *
  58. * PARAMETERS: table_index - Index for table to be loaded
  59. * Node - Owning NS node
  60. *
  61. * RETURN: Status
  62. *
  63. * DESCRIPTION: Load one ACPI table into the namespace
  64. *
  65. ******************************************************************************/
  66. acpi_status
  67. acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
  68. {
  69. acpi_status status;
  70. ACPI_FUNCTION_TRACE(ns_load_table);
  71. /*
  72. * Parse the table and load the namespace with all named
  73. * objects found within. Control methods are NOT parsed
  74. * at this time. In fact, the control methods cannot be
  75. * parsed until the entire namespace is loaded, because
  76. * if a control method makes a forward reference (call)
  77. * to another control method, we can't continue parsing
  78. * because we don't know how many arguments to parse next!
  79. */
  80. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  81. if (ACPI_FAILURE(status)) {
  82. return_ACPI_STATUS(status);
  83. }
  84. /* If table already loaded into namespace, just return */
  85. if (acpi_tb_is_table_loaded(table_index)) {
  86. status = AE_ALREADY_EXISTS;
  87. goto unlock;
  88. }
  89. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  90. "**** Loading table into namespace ****\n"));
  91. status = acpi_tb_allocate_owner_id(table_index);
  92. if (ACPI_FAILURE(status)) {
  93. goto unlock;
  94. }
  95. status = acpi_ns_parse_table(table_index, node);
  96. if (ACPI_SUCCESS(status)) {
  97. acpi_tb_set_table_loaded_flag(table_index, TRUE);
  98. } else {
  99. (void)acpi_tb_release_owner_id(table_index);
  100. }
  101. unlock:
  102. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  103. if (ACPI_FAILURE(status)) {
  104. return_ACPI_STATUS(status);
  105. }
  106. /*
  107. * Now we can parse the control methods. We always parse
  108. * them here for a sanity check, and if configured for
  109. * just-in-time parsing, we delete the control method
  110. * parse trees.
  111. */
  112. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  113. "**** Begin Table Method Parsing and Object Initialization ****\n"));
  114. status = acpi_ds_initialize_objects(table_index, node);
  115. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  116. "**** Completed Table Method Parsing and Object Initialization ****\n"));
  117. return_ACPI_STATUS(status);
  118. }
  119. #ifdef ACPI_OBSOLETE_FUNCTIONS
  120. /*******************************************************************************
  121. *
  122. * FUNCTION: acpi_load_namespace
  123. *
  124. * PARAMETERS: None
  125. *
  126. * RETURN: Status
  127. *
  128. * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
  129. * (DSDT points to either the BIOS or a buffer.)
  130. *
  131. ******************************************************************************/
  132. acpi_status acpi_ns_load_namespace(void)
  133. {
  134. acpi_status status;
  135. ACPI_FUNCTION_TRACE(acpi_load_name_space);
  136. /* There must be at least a DSDT installed */
  137. if (acpi_gbl_DSDT == NULL) {
  138. ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
  139. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  140. }
  141. /*
  142. * Load the namespace. The DSDT is required,
  143. * but the SSDT and PSDT tables are optional.
  144. */
  145. status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
  146. if (ACPI_FAILURE(status)) {
  147. return_ACPI_STATUS(status);
  148. }
  149. /* Ignore exceptions from these */
  150. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
  151. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
  152. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  153. "ACPI Namespace successfully loaded at root %p\n",
  154. acpi_gbl_root_node));
  155. return_ACPI_STATUS(status);
  156. }
  157. #endif
  158. #ifdef ACPI_FUTURE_IMPLEMENTATION
  159. /*******************************************************************************
  160. *
  161. * FUNCTION: acpi_ns_delete_subtree
  162. *
  163. * PARAMETERS: start_handle - Handle in namespace where search begins
  164. *
  165. * RETURNS Status
  166. *
  167. * DESCRIPTION: Walks the namespace starting at the given handle and deletes
  168. * all objects, entries, and scopes in the entire subtree.
  169. *
  170. * Namespace/Interpreter should be locked or the subsystem should
  171. * be in shutdown before this routine is called.
  172. *
  173. ******************************************************************************/
  174. static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
  175. {
  176. acpi_status status;
  177. acpi_handle child_handle;
  178. acpi_handle parent_handle;
  179. acpi_handle next_child_handle;
  180. acpi_handle dummy;
  181. u32 level;
  182. ACPI_FUNCTION_TRACE(ns_delete_subtree);
  183. parent_handle = start_handle;
  184. child_handle = NULL;
  185. level = 1;
  186. /*
  187. * Traverse the tree of objects until we bubble back up
  188. * to where we started.
  189. */
  190. while (level > 0) {
  191. /* Attempt to get the next object in this scope */
  192. status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
  193. child_handle, &next_child_handle);
  194. child_handle = next_child_handle;
  195. /* Did we get a new object? */
  196. if (ACPI_SUCCESS(status)) {
  197. /* Check if this object has any children */
  198. if (ACPI_SUCCESS
  199. (acpi_get_next_object
  200. (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
  201. /*
  202. * There is at least one child of this object,
  203. * visit the object
  204. */
  205. level++;
  206. parent_handle = child_handle;
  207. child_handle = NULL;
  208. }
  209. } else {
  210. /*
  211. * No more children in this object, go back up to
  212. * the object's parent
  213. */
  214. level--;
  215. /* Delete all children now */
  216. acpi_ns_delete_children(child_handle);
  217. child_handle = parent_handle;
  218. status = acpi_get_parent(parent_handle, &parent_handle);
  219. if (ACPI_FAILURE(status)) {
  220. return_ACPI_STATUS(status);
  221. }
  222. }
  223. }
  224. /* Now delete the starting object, and we are done */
  225. acpi_ns_delete_node(child_handle);
  226. return_ACPI_STATUS(AE_OK);
  227. }
  228. /*******************************************************************************
  229. *
  230. * FUNCTION: acpi_ns_unload_name_space
  231. *
  232. * PARAMETERS: Handle - Root of namespace subtree to be deleted
  233. *
  234. * RETURN: Status
  235. *
  236. * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
  237. * event. Deletes an entire subtree starting from (and
  238. * including) the given handle.
  239. *
  240. ******************************************************************************/
  241. acpi_status acpi_ns_unload_namespace(acpi_handle handle)
  242. {
  243. acpi_status status;
  244. ACPI_FUNCTION_TRACE(ns_unload_name_space);
  245. /* Parameter validation */
  246. if (!acpi_gbl_root_node) {
  247. return_ACPI_STATUS(AE_NO_NAMESPACE);
  248. }
  249. if (!handle) {
  250. return_ACPI_STATUS(AE_BAD_PARAMETER);
  251. }
  252. /* This function does the real work */
  253. status = acpi_ns_delete_subtree(handle);
  254. return_ACPI_STATUS(status);
  255. }
  256. #endif
  257. #endif