nsload.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /******************************************************************************
  2. *
  3. * Module Name: nsload - namespace loading/expanding/contracting procedures
  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/acnamesp.h>
  44. #include <acpi/acdispat.h>
  45. #define _COMPONENT ACPI_NAMESPACE
  46. ACPI_MODULE_NAME ("nsload")
  47. /* Local prototypes */
  48. static acpi_status
  49. acpi_ns_load_table_by_type (
  50. acpi_table_type table_type);
  51. #ifdef ACPI_FUTURE_IMPLEMENTATION
  52. acpi_status
  53. acpi_ns_unload_namespace (
  54. acpi_handle handle);
  55. static acpi_status
  56. acpi_ns_delete_subtree (
  57. acpi_handle start_handle);
  58. #endif
  59. #ifndef ACPI_NO_METHOD_EXECUTION
  60. /*******************************************************************************
  61. *
  62. * FUNCTION: acpi_ns_load_table
  63. *
  64. * PARAMETERS: table_desc - Descriptor for table to be loaded
  65. * Node - Owning NS node
  66. *
  67. * RETURN: Status
  68. *
  69. * DESCRIPTION: Load one ACPI table into the namespace
  70. *
  71. ******************************************************************************/
  72. acpi_status
  73. acpi_ns_load_table (
  74. struct acpi_table_desc *table_desc,
  75. struct acpi_namespace_node *node)
  76. {
  77. acpi_status status;
  78. ACPI_FUNCTION_TRACE ("ns_load_table");
  79. /* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */
  80. if (!(acpi_gbl_table_data[table_desc->type].flags & ACPI_TABLE_EXECUTABLE)) {
  81. /* Just ignore this table */
  82. return_ACPI_STATUS (AE_OK);
  83. }
  84. /* Check validity of the AML start and length */
  85. if (!table_desc->aml_start) {
  86. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null AML pointer\n"));
  87. return_ACPI_STATUS (AE_BAD_PARAMETER);
  88. }
  89. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AML block at %p\n",
  90. table_desc->aml_start));
  91. /* Ignore table if there is no AML contained within */
  92. if (!table_desc->aml_length) {
  93. ACPI_REPORT_WARNING (("Zero-length AML block in table [%4.4s]\n",
  94. table_desc->pointer->signature));
  95. return_ACPI_STATUS (AE_OK);
  96. }
  97. /*
  98. * Parse the table and load the namespace with all named
  99. * objects found within. Control methods are NOT parsed
  100. * at this time. In fact, the control methods cannot be
  101. * parsed until the entire namespace is loaded, because
  102. * if a control method makes a forward reference (call)
  103. * to another control method, we can't continue parsing
  104. * because we don't know how many arguments to parse next!
  105. */
  106. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  107. "**** Loading table into namespace ****\n"));
  108. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  109. if (ACPI_FAILURE (status)) {
  110. return_ACPI_STATUS (status);
  111. }
  112. status = acpi_ns_parse_table (table_desc, node->child);
  113. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  114. if (ACPI_FAILURE (status)) {
  115. return_ACPI_STATUS (status);
  116. }
  117. /*
  118. * Now we can parse the control methods. We always parse
  119. * them here for a sanity check, and if configured for
  120. * just-in-time parsing, we delete the control method
  121. * parse trees.
  122. */
  123. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  124. "**** Begin Table Method Parsing and Object Initialization ****\n"));
  125. status = acpi_ds_initialize_objects (table_desc, node);
  126. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  127. "**** Completed Table Method Parsing and Object Initialization ****\n"));
  128. return_ACPI_STATUS (status);
  129. }
  130. /*******************************************************************************
  131. *
  132. * FUNCTION: acpi_ns_load_table_by_type
  133. *
  134. * PARAMETERS: table_type - Id of the table type to load
  135. *
  136. * RETURN: Status
  137. *
  138. * DESCRIPTION: Load an ACPI table or tables into the namespace. All tables
  139. * of the given type are loaded. The mechanism allows this
  140. * routine to be called repeatedly.
  141. *
  142. ******************************************************************************/
  143. static acpi_status
  144. acpi_ns_load_table_by_type (
  145. acpi_table_type table_type)
  146. {
  147. u32 i;
  148. acpi_status status;
  149. struct acpi_table_desc *table_desc;
  150. ACPI_FUNCTION_TRACE ("ns_load_table_by_type");
  151. status = acpi_ut_acquire_mutex (ACPI_MTX_TABLES);
  152. if (ACPI_FAILURE (status)) {
  153. return_ACPI_STATUS (status);
  154. }
  155. /*
  156. * Table types supported are:
  157. * DSDT (one), SSDT/PSDT (multiple)
  158. */
  159. switch (table_type) {
  160. case ACPI_TABLE_DSDT:
  161. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading DSDT\n"));
  162. table_desc = acpi_gbl_table_lists[ACPI_TABLE_DSDT].next;
  163. /* If table already loaded into namespace, just return */
  164. if (table_desc->loaded_into_namespace) {
  165. goto unlock_and_exit;
  166. }
  167. /* Now load the single DSDT */
  168. status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
  169. if (ACPI_SUCCESS (status)) {
  170. table_desc->loaded_into_namespace = TRUE;
  171. }
  172. break;
  173. case ACPI_TABLE_SSDT:
  174. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d SSDTs\n",
  175. acpi_gbl_table_lists[ACPI_TABLE_SSDT].count));
  176. /*
  177. * Traverse list of SSDT tables
  178. */
  179. table_desc = acpi_gbl_table_lists[ACPI_TABLE_SSDT].next;
  180. for (i = 0; i < acpi_gbl_table_lists[ACPI_TABLE_SSDT].count; i++) {
  181. /*
  182. * Only attempt to load table if it is not
  183. * already loaded!
  184. */
  185. if (!table_desc->loaded_into_namespace) {
  186. status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
  187. if (ACPI_FAILURE (status)) {
  188. break;
  189. }
  190. table_desc->loaded_into_namespace = TRUE;
  191. }
  192. table_desc = table_desc->next;
  193. }
  194. break;
  195. case ACPI_TABLE_PSDT:
  196. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d PSDTs\n",
  197. acpi_gbl_table_lists[ACPI_TABLE_PSDT].count));
  198. /*
  199. * Traverse list of PSDT tables
  200. */
  201. table_desc = acpi_gbl_table_lists[ACPI_TABLE_PSDT].next;
  202. for (i = 0; i < acpi_gbl_table_lists[ACPI_TABLE_PSDT].count; i++) {
  203. /* Only attempt to load table if it is not already loaded! */
  204. if (!table_desc->loaded_into_namespace) {
  205. status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
  206. if (ACPI_FAILURE (status)) {
  207. break;
  208. }
  209. table_desc->loaded_into_namespace = TRUE;
  210. }
  211. table_desc = table_desc->next;
  212. }
  213. break;
  214. default:
  215. status = AE_SUPPORT;
  216. break;
  217. }
  218. unlock_and_exit:
  219. (void) acpi_ut_release_mutex (ACPI_MTX_TABLES);
  220. return_ACPI_STATUS (status);
  221. }
  222. /*******************************************************************************
  223. *
  224. * FUNCTION: acpi_load_namespace
  225. *
  226. * PARAMETERS: None
  227. *
  228. * RETURN: Status
  229. *
  230. * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
  231. * (DSDT points to either the BIOS or a buffer.)
  232. *
  233. ******************************************************************************/
  234. acpi_status
  235. acpi_ns_load_namespace (
  236. void)
  237. {
  238. acpi_status status;
  239. ACPI_FUNCTION_TRACE ("acpi_load_name_space");
  240. /* There must be at least a DSDT installed */
  241. if (acpi_gbl_DSDT == NULL) {
  242. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "DSDT is not in memory\n"));
  243. return_ACPI_STATUS (AE_NO_ACPI_TABLES);
  244. }
  245. /*
  246. * Load the namespace. The DSDT is required,
  247. * but the SSDT and PSDT tables are optional.
  248. */
  249. status = acpi_ns_load_table_by_type (ACPI_TABLE_DSDT);
  250. if (ACPI_FAILURE (status)) {
  251. return_ACPI_STATUS (status);
  252. }
  253. /* Ignore exceptions from these */
  254. (void) acpi_ns_load_table_by_type (ACPI_TABLE_SSDT);
  255. (void) acpi_ns_load_table_by_type (ACPI_TABLE_PSDT);
  256. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
  257. "ACPI Namespace successfully loaded at root %p\n",
  258. acpi_gbl_root_node));
  259. return_ACPI_STATUS (status);
  260. }
  261. #ifdef ACPI_FUTURE_IMPLEMENTATION
  262. /*******************************************************************************
  263. *
  264. * FUNCTION: acpi_ns_delete_subtree
  265. *
  266. * PARAMETERS: start_handle - Handle in namespace where search begins
  267. *
  268. * RETURNS Status
  269. *
  270. * DESCRIPTION: Walks the namespace starting at the given handle and deletes
  271. * all objects, entries, and scopes in the entire subtree.
  272. *
  273. * Namespace/Interpreter should be locked or the subsystem should
  274. * be in shutdown before this routine is called.
  275. *
  276. ******************************************************************************/
  277. static acpi_status
  278. acpi_ns_delete_subtree (
  279. acpi_handle start_handle)
  280. {
  281. acpi_status status;
  282. acpi_handle child_handle;
  283. acpi_handle parent_handle;
  284. acpi_handle next_child_handle;
  285. acpi_handle dummy;
  286. u32 level;
  287. ACPI_FUNCTION_TRACE ("ns_delete_subtree");
  288. parent_handle = start_handle;
  289. child_handle = NULL;
  290. level = 1;
  291. /*
  292. * Traverse the tree of objects until we bubble back up
  293. * to where we started.
  294. */
  295. while (level > 0) {
  296. /* Attempt to get the next object in this scope */
  297. status = acpi_get_next_object (ACPI_TYPE_ANY, parent_handle,
  298. child_handle, &next_child_handle);
  299. child_handle = next_child_handle;
  300. /* Did we get a new object? */
  301. if (ACPI_SUCCESS (status)) {
  302. /* Check if this object has any children */
  303. if (ACPI_SUCCESS (acpi_get_next_object (ACPI_TYPE_ANY, child_handle,
  304. NULL, &dummy))) {
  305. /*
  306. * There is at least one child of this object,
  307. * visit the object
  308. */
  309. level++;
  310. parent_handle = child_handle;
  311. child_handle = NULL;
  312. }
  313. }
  314. else {
  315. /*
  316. * No more children in this object, go back up to
  317. * the object's parent
  318. */
  319. level--;
  320. /* Delete all children now */
  321. acpi_ns_delete_children (child_handle);
  322. child_handle = parent_handle;
  323. status = acpi_get_parent (parent_handle, &parent_handle);
  324. if (ACPI_FAILURE (status)) {
  325. return_ACPI_STATUS (status);
  326. }
  327. }
  328. }
  329. /* Now delete the starting object, and we are done */
  330. acpi_ns_delete_node (child_handle);
  331. return_ACPI_STATUS (AE_OK);
  332. }
  333. /*******************************************************************************
  334. *
  335. * FUNCTION: acpi_ns_unload_name_space
  336. *
  337. * PARAMETERS: Handle - Root of namespace subtree to be deleted
  338. *
  339. * RETURN: Status
  340. *
  341. * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
  342. * event. Deletes an entire subtree starting from (and
  343. * including) the given handle.
  344. *
  345. ******************************************************************************/
  346. acpi_status
  347. acpi_ns_unload_namespace (
  348. acpi_handle handle)
  349. {
  350. acpi_status status;
  351. ACPI_FUNCTION_TRACE ("ns_unload_name_space");
  352. /* Parameter validation */
  353. if (!acpi_gbl_root_node) {
  354. return_ACPI_STATUS (AE_NO_NAMESPACE);
  355. }
  356. if (!handle) {
  357. return_ACPI_STATUS (AE_BAD_PARAMETER);
  358. }
  359. /* This function does the real work */
  360. status = acpi_ns_delete_subtree (handle);
  361. return_ACPI_STATUS (status);
  362. }
  363. #endif
  364. #endif