nsload.c 11 KB

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