nsload.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: nsload - namespace loading/expanding/contracting procedures
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acnamesp.h"
  12. #include "acdispat.h"
  13. #include "actables.h"
  14. #include "acinterp.h"
  15. #define _COMPONENT ACPI_NAMESPACE
  16. ACPI_MODULE_NAME("nsload")
  17. /* Local prototypes */
  18. #ifdef ACPI_FUTURE_IMPLEMENTATION
  19. acpi_status acpi_ns_unload_namespace(acpi_handle handle);
  20. static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
  21. #endif
  22. #ifndef ACPI_NO_METHOD_EXECUTION
  23. /*******************************************************************************
  24. *
  25. * FUNCTION: acpi_ns_load_table
  26. *
  27. * PARAMETERS: table_index - Index for table to be loaded
  28. * node - Owning NS node
  29. *
  30. * RETURN: Status
  31. *
  32. * DESCRIPTION: Load one ACPI table into the namespace
  33. *
  34. ******************************************************************************/
  35. acpi_status
  36. acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
  37. {
  38. acpi_status status;
  39. ACPI_FUNCTION_TRACE(ns_load_table);
  40. /* If table already loaded into namespace, just return */
  41. if (acpi_tb_is_table_loaded(table_index)) {
  42. status = AE_ALREADY_EXISTS;
  43. goto unlock;
  44. }
  45. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  46. "**** Loading table into namespace ****\n"));
  47. status = acpi_tb_allocate_owner_id(table_index);
  48. if (ACPI_FAILURE(status)) {
  49. goto unlock;
  50. }
  51. /*
  52. * Parse the table and load the namespace with all named
  53. * objects found within. Control methods are NOT parsed
  54. * at this time. In fact, the control methods cannot be
  55. * parsed until the entire namespace is loaded, because
  56. * if a control method makes a forward reference (call)
  57. * to another control method, we can't continue parsing
  58. * because we don't know how many arguments to parse next!
  59. */
  60. status = acpi_ns_parse_table(table_index, node);
  61. if (ACPI_SUCCESS(status)) {
  62. acpi_tb_set_table_loaded_flag(table_index, TRUE);
  63. } else {
  64. /*
  65. * On error, delete any namespace objects created by this table.
  66. * We cannot initialize these objects, so delete them. There are
  67. * a couple of expecially bad cases:
  68. * AE_ALREADY_EXISTS - namespace collision.
  69. * AE_NOT_FOUND - the target of a Scope operator does not
  70. * exist. This target of Scope must already exist in the
  71. * namespace, as per the ACPI specification.
  72. */
  73. acpi_ns_delete_namespace_by_owner(acpi_gbl_root_table_list.
  74. tables[table_index].owner_id);
  75. acpi_tb_release_owner_id(table_index);
  76. return_ACPI_STATUS(status);
  77. }
  78. unlock:
  79. if (ACPI_FAILURE(status)) {
  80. return_ACPI_STATUS(status);
  81. }
  82. /*
  83. * Now we can parse the control methods. We always parse
  84. * them here for a sanity check, and if configured for
  85. * just-in-time parsing, we delete the control method
  86. * parse trees.
  87. */
  88. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  89. "**** Begin Table Object Initialization\n"));
  90. acpi_ex_enter_interpreter();
  91. status = acpi_ds_initialize_objects(table_index, node);
  92. acpi_ex_exit_interpreter();
  93. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  94. "**** Completed Table Object Initialization\n"));
  95. /*
  96. * This case handles the legacy option that groups all module-level
  97. * code blocks together and defers execution until all of the tables
  98. * are loaded. Execute all of these blocks at this time.
  99. * Execute any module-level code that was detected during the table
  100. * load phase.
  101. *
  102. * Note: this option is deprecated and will be eliminated in the
  103. * future. Use of this option can cause problems with AML code that
  104. * depends upon in-order immediate execution of module-level code.
  105. */
  106. acpi_ns_exec_module_code_list();
  107. return_ACPI_STATUS(status);
  108. }
  109. #ifdef ACPI_OBSOLETE_FUNCTIONS
  110. /*******************************************************************************
  111. *
  112. * FUNCTION: acpi_load_namespace
  113. *
  114. * PARAMETERS: None
  115. *
  116. * RETURN: Status
  117. *
  118. * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
  119. * (DSDT points to either the BIOS or a buffer.)
  120. *
  121. ******************************************************************************/
  122. acpi_status acpi_ns_load_namespace(void)
  123. {
  124. acpi_status status;
  125. ACPI_FUNCTION_TRACE(acpi_load_name_space);
  126. /* There must be at least a DSDT installed */
  127. if (acpi_gbl_DSDT == NULL) {
  128. ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
  129. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  130. }
  131. /*
  132. * Load the namespace. The DSDT is required,
  133. * but the SSDT and PSDT tables are optional.
  134. */
  135. status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
  136. if (ACPI_FAILURE(status)) {
  137. return_ACPI_STATUS(status);
  138. }
  139. /* Ignore exceptions from these */
  140. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
  141. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
  142. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  143. "ACPI Namespace successfully loaded at root %p\n",
  144. acpi_gbl_root_node));
  145. return_ACPI_STATUS(status);
  146. }
  147. #endif
  148. #ifdef ACPI_FUTURE_IMPLEMENTATION
  149. /*******************************************************************************
  150. *
  151. * FUNCTION: acpi_ns_delete_subtree
  152. *
  153. * PARAMETERS: start_handle - Handle in namespace where search begins
  154. *
  155. * RETURNS Status
  156. *
  157. * DESCRIPTION: Walks the namespace starting at the given handle and deletes
  158. * all objects, entries, and scopes in the entire subtree.
  159. *
  160. * Namespace/Interpreter should be locked or the subsystem should
  161. * be in shutdown before this routine is called.
  162. *
  163. ******************************************************************************/
  164. static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
  165. {
  166. acpi_status status;
  167. acpi_handle child_handle;
  168. acpi_handle parent_handle;
  169. acpi_handle next_child_handle;
  170. acpi_handle dummy;
  171. u32 level;
  172. ACPI_FUNCTION_TRACE(ns_delete_subtree);
  173. parent_handle = start_handle;
  174. child_handle = NULL;
  175. level = 1;
  176. /*
  177. * Traverse the tree of objects until we bubble back up
  178. * to where we started.
  179. */
  180. while (level > 0) {
  181. /* Attempt to get the next object in this scope */
  182. status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
  183. child_handle, &next_child_handle);
  184. child_handle = next_child_handle;
  185. /* Did we get a new object? */
  186. if (ACPI_SUCCESS(status)) {
  187. /* Check if this object has any children */
  188. if (ACPI_SUCCESS
  189. (acpi_get_next_object
  190. (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
  191. /*
  192. * There is at least one child of this object,
  193. * visit the object
  194. */
  195. level++;
  196. parent_handle = child_handle;
  197. child_handle = NULL;
  198. }
  199. } else {
  200. /*
  201. * No more children in this object, go back up to
  202. * the object's parent
  203. */
  204. level--;
  205. /* Delete all children now */
  206. acpi_ns_delete_children(child_handle);
  207. child_handle = parent_handle;
  208. status = acpi_get_parent(parent_handle, &parent_handle);
  209. if (ACPI_FAILURE(status)) {
  210. return_ACPI_STATUS(status);
  211. }
  212. }
  213. }
  214. /* Now delete the starting object, and we are done */
  215. acpi_ns_remove_node(child_handle);
  216. return_ACPI_STATUS(AE_OK);
  217. }
  218. /*******************************************************************************
  219. *
  220. * FUNCTION: acpi_ns_unload_name_space
  221. *
  222. * PARAMETERS: handle - Root of namespace subtree to be deleted
  223. *
  224. * RETURN: Status
  225. *
  226. * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
  227. * event. Deletes an entire subtree starting from (and
  228. * including) the given handle.
  229. *
  230. ******************************************************************************/
  231. acpi_status acpi_ns_unload_namespace(acpi_handle handle)
  232. {
  233. acpi_status status;
  234. ACPI_FUNCTION_TRACE(ns_unload_name_space);
  235. /* Parameter validation */
  236. if (!acpi_gbl_root_node) {
  237. return_ACPI_STATUS(AE_NO_NAMESPACE);
  238. }
  239. if (!handle) {
  240. return_ACPI_STATUS(AE_BAD_PARAMETER);
  241. }
  242. /* This function does the real work */
  243. status = acpi_ns_delete_subtree(handle);
  244. return_ACPI_STATUS(status);
  245. }
  246. #endif
  247. #endif