nsload.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /******************************************************************************
  2. *
  3. * Module Name: nsload - namespace loading/expanding/contracting procedures
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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. /*
  101. * On error, delete any namespace objects created by this table.
  102. * We cannot initialize these objects, so delete them. There are
  103. * a couple of expecially bad cases:
  104. * AE_ALREADY_EXISTS - namespace collision.
  105. * AE_NOT_FOUND - the target of a Scope operator does not
  106. * exist. This target of Scope must already exist in the
  107. * namespace, as per the ACPI specification.
  108. */
  109. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  110. acpi_ns_delete_namespace_by_owner(acpi_gbl_root_table_list.
  111. tables[table_index].owner_id);
  112. acpi_tb_release_owner_id(table_index);
  113. return_ACPI_STATUS(status);
  114. }
  115. unlock:
  116. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  117. if (ACPI_FAILURE(status)) {
  118. return_ACPI_STATUS(status);
  119. }
  120. /*
  121. * Now we can parse the control methods. We always parse
  122. * them here for a sanity check, and if configured for
  123. * just-in-time parsing, we delete the control method
  124. * parse trees.
  125. */
  126. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  127. "**** Begin Table Object Initialization\n"));
  128. status = acpi_ds_initialize_objects(table_index, node);
  129. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  130. "**** Completed Table Object Initialization\n"));
  131. /*
  132. * Execute any module-level code that was detected during the table load
  133. * phase. Although illegal since ACPI 2.0, there are many machines that
  134. * contain this type of code. Each block of detected executable AML code
  135. * outside of any control method is wrapped with a temporary control
  136. * method object and placed on a global list. The methods on this list
  137. * are executed below.
  138. *
  139. * This case executes the module-level code for each table immediately
  140. * after the table has been loaded. This provides compatibility with
  141. * other ACPI implementations. Optionally, the execution can be deferred
  142. * until later, see acpi_initialize_objects.
  143. */
  144. if (!acpi_gbl_group_module_level_code) {
  145. acpi_ns_exec_module_code_list();
  146. }
  147. return_ACPI_STATUS(status);
  148. }
  149. #ifdef ACPI_OBSOLETE_FUNCTIONS
  150. /*******************************************************************************
  151. *
  152. * FUNCTION: acpi_load_namespace
  153. *
  154. * PARAMETERS: None
  155. *
  156. * RETURN: Status
  157. *
  158. * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
  159. * (DSDT points to either the BIOS or a buffer.)
  160. *
  161. ******************************************************************************/
  162. acpi_status acpi_ns_load_namespace(void)
  163. {
  164. acpi_status status;
  165. ACPI_FUNCTION_TRACE(acpi_load_name_space);
  166. /* There must be at least a DSDT installed */
  167. if (acpi_gbl_DSDT == NULL) {
  168. ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
  169. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  170. }
  171. /*
  172. * Load the namespace. The DSDT is required,
  173. * but the SSDT and PSDT tables are optional.
  174. */
  175. status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
  176. if (ACPI_FAILURE(status)) {
  177. return_ACPI_STATUS(status);
  178. }
  179. /* Ignore exceptions from these */
  180. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
  181. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
  182. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  183. "ACPI Namespace successfully loaded at root %p\n",
  184. acpi_gbl_root_node));
  185. return_ACPI_STATUS(status);
  186. }
  187. #endif
  188. #ifdef ACPI_FUTURE_IMPLEMENTATION
  189. /*******************************************************************************
  190. *
  191. * FUNCTION: acpi_ns_delete_subtree
  192. *
  193. * PARAMETERS: start_handle - Handle in namespace where search begins
  194. *
  195. * RETURNS Status
  196. *
  197. * DESCRIPTION: Walks the namespace starting at the given handle and deletes
  198. * all objects, entries, and scopes in the entire subtree.
  199. *
  200. * Namespace/Interpreter should be locked or the subsystem should
  201. * be in shutdown before this routine is called.
  202. *
  203. ******************************************************************************/
  204. static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
  205. {
  206. acpi_status status;
  207. acpi_handle child_handle;
  208. acpi_handle parent_handle;
  209. acpi_handle next_child_handle;
  210. acpi_handle dummy;
  211. u32 level;
  212. ACPI_FUNCTION_TRACE(ns_delete_subtree);
  213. parent_handle = start_handle;
  214. child_handle = NULL;
  215. level = 1;
  216. /*
  217. * Traverse the tree of objects until we bubble back up
  218. * to where we started.
  219. */
  220. while (level > 0) {
  221. /* Attempt to get the next object in this scope */
  222. status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
  223. child_handle, &next_child_handle);
  224. child_handle = next_child_handle;
  225. /* Did we get a new object? */
  226. if (ACPI_SUCCESS(status)) {
  227. /* Check if this object has any children */
  228. if (ACPI_SUCCESS
  229. (acpi_get_next_object
  230. (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
  231. /*
  232. * There is at least one child of this object,
  233. * visit the object
  234. */
  235. level++;
  236. parent_handle = child_handle;
  237. child_handle = NULL;
  238. }
  239. } else {
  240. /*
  241. * No more children in this object, go back up to
  242. * the object's parent
  243. */
  244. level--;
  245. /* Delete all children now */
  246. acpi_ns_delete_children(child_handle);
  247. child_handle = parent_handle;
  248. status = acpi_get_parent(parent_handle, &parent_handle);
  249. if (ACPI_FAILURE(status)) {
  250. return_ACPI_STATUS(status);
  251. }
  252. }
  253. }
  254. /* Now delete the starting object, and we are done */
  255. acpi_ns_remove_node(child_handle);
  256. return_ACPI_STATUS(AE_OK);
  257. }
  258. /*******************************************************************************
  259. *
  260. * FUNCTION: acpi_ns_unload_name_space
  261. *
  262. * PARAMETERS: handle - Root of namespace subtree to be deleted
  263. *
  264. * RETURN: Status
  265. *
  266. * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
  267. * event. Deletes an entire subtree starting from (and
  268. * including) the given handle.
  269. *
  270. ******************************************************************************/
  271. acpi_status acpi_ns_unload_namespace(acpi_handle handle)
  272. {
  273. acpi_status status;
  274. ACPI_FUNCTION_TRACE(ns_unload_name_space);
  275. /* Parameter validation */
  276. if (!acpi_gbl_root_node) {
  277. return_ACPI_STATUS(AE_NO_NAMESPACE);
  278. }
  279. if (!handle) {
  280. return_ACPI_STATUS(AE_BAD_PARAMETER);
  281. }
  282. /* This function does the real work */
  283. status = acpi_ns_delete_subtree(handle);
  284. return_ACPI_STATUS(status);
  285. }
  286. #endif
  287. #endif