nsload.c 8.9 KB

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