nsload.c 7.5 KB

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