nsload.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. #include "acinterp.h"
  48. #define _COMPONENT ACPI_NAMESPACE
  49. ACPI_MODULE_NAME("nsload")
  50. /* Local prototypes */
  51. #ifdef ACPI_FUTURE_IMPLEMENTATION
  52. acpi_status acpi_ns_unload_namespace(acpi_handle handle);
  53. static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
  54. #endif
  55. #ifndef ACPI_NO_METHOD_EXECUTION
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: acpi_ns_load_table
  59. *
  60. * PARAMETERS: table_index - Index for table to be loaded
  61. * node - Owning NS node
  62. *
  63. * RETURN: Status
  64. *
  65. * DESCRIPTION: Load one ACPI table into the namespace
  66. *
  67. ******************************************************************************/
  68. acpi_status
  69. acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
  70. {
  71. acpi_status status;
  72. ACPI_FUNCTION_TRACE(ns_load_table);
  73. /* If table already loaded into namespace, just return */
  74. if (acpi_tb_is_table_loaded(table_index)) {
  75. status = AE_ALREADY_EXISTS;
  76. goto unlock;
  77. }
  78. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  79. "**** Loading table into namespace ****\n"));
  80. status = acpi_tb_allocate_owner_id(table_index);
  81. if (ACPI_FAILURE(status)) {
  82. goto unlock;
  83. }
  84. /*
  85. * Parse the table and load the namespace with all named
  86. * objects found within. Control methods are NOT parsed
  87. * at this time. In fact, the control methods cannot be
  88. * parsed until the entire namespace is loaded, because
  89. * if a control method makes a forward reference (call)
  90. * to another control method, we can't continue parsing
  91. * because we don't know how many arguments to parse next!
  92. */
  93. status = acpi_ns_parse_table(table_index, node);
  94. if (ACPI_SUCCESS(status)) {
  95. acpi_tb_set_table_loaded_flag(table_index, TRUE);
  96. } else {
  97. /*
  98. * On error, delete any namespace objects created by this table.
  99. * We cannot initialize these objects, so delete them. There are
  100. * a couple of expecially bad cases:
  101. * AE_ALREADY_EXISTS - namespace collision.
  102. * AE_NOT_FOUND - the target of a Scope operator does not
  103. * exist. This target of Scope must already exist in the
  104. * namespace, as per the ACPI specification.
  105. */
  106. acpi_ns_delete_namespace_by_owner(acpi_gbl_root_table_list.
  107. tables[table_index].owner_id);
  108. acpi_tb_release_owner_id(table_index);
  109. return_ACPI_STATUS(status);
  110. }
  111. unlock:
  112. if (ACPI_FAILURE(status)) {
  113. return_ACPI_STATUS(status);
  114. }
  115. /*
  116. * Now we can parse the control methods. We always parse
  117. * them here for a sanity check, and if configured for
  118. * just-in-time parsing, we delete the control method
  119. * parse trees.
  120. */
  121. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  122. "**** Begin Table Object Initialization\n"));
  123. acpi_ex_enter_interpreter();
  124. status = acpi_ds_initialize_objects(table_index, node);
  125. acpi_ex_exit_interpreter();
  126. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  127. "**** Completed Table Object Initialization\n"));
  128. /*
  129. * Execute any module-level code that was detected during the table load
  130. * phase. Although illegal since ACPI 2.0, there are many machines that
  131. * contain this type of code. Each block of detected executable AML code
  132. * outside of any control method is wrapped with a temporary control
  133. * method object and placed on a global list. The methods on this list
  134. * are executed below.
  135. *
  136. * This case executes the module-level code for each table immediately
  137. * after the table has been loaded. This provides compatibility with
  138. * other ACPI implementations. Optionally, the execution can be deferred
  139. * until later, see acpi_initialize_objects.
  140. */
  141. if (!acpi_gbl_parse_table_as_term_list
  142. && !acpi_gbl_group_module_level_code) {
  143. acpi_ns_exec_module_code_list();
  144. }
  145. return_ACPI_STATUS(status);
  146. }
  147. #ifdef ACPI_OBSOLETE_FUNCTIONS
  148. /*******************************************************************************
  149. *
  150. * FUNCTION: acpi_load_namespace
  151. *
  152. * PARAMETERS: None
  153. *
  154. * RETURN: Status
  155. *
  156. * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
  157. * (DSDT points to either the BIOS or a buffer.)
  158. *
  159. ******************************************************************************/
  160. acpi_status acpi_ns_load_namespace(void)
  161. {
  162. acpi_status status;
  163. ACPI_FUNCTION_TRACE(acpi_load_name_space);
  164. /* There must be at least a DSDT installed */
  165. if (acpi_gbl_DSDT == NULL) {
  166. ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
  167. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  168. }
  169. /*
  170. * Load the namespace. The DSDT is required,
  171. * but the SSDT and PSDT tables are optional.
  172. */
  173. status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
  174. if (ACPI_FAILURE(status)) {
  175. return_ACPI_STATUS(status);
  176. }
  177. /* Ignore exceptions from these */
  178. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
  179. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
  180. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  181. "ACPI Namespace successfully loaded at root %p\n",
  182. acpi_gbl_root_node));
  183. return_ACPI_STATUS(status);
  184. }
  185. #endif
  186. #ifdef ACPI_FUTURE_IMPLEMENTATION
  187. /*******************************************************************************
  188. *
  189. * FUNCTION: acpi_ns_delete_subtree
  190. *
  191. * PARAMETERS: start_handle - Handle in namespace where search begins
  192. *
  193. * RETURNS Status
  194. *
  195. * DESCRIPTION: Walks the namespace starting at the given handle and deletes
  196. * all objects, entries, and scopes in the entire subtree.
  197. *
  198. * Namespace/Interpreter should be locked or the subsystem should
  199. * be in shutdown before this routine is called.
  200. *
  201. ******************************************************************************/
  202. static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
  203. {
  204. acpi_status status;
  205. acpi_handle child_handle;
  206. acpi_handle parent_handle;
  207. acpi_handle next_child_handle;
  208. acpi_handle dummy;
  209. u32 level;
  210. ACPI_FUNCTION_TRACE(ns_delete_subtree);
  211. parent_handle = start_handle;
  212. child_handle = NULL;
  213. level = 1;
  214. /*
  215. * Traverse the tree of objects until we bubble back up
  216. * to where we started.
  217. */
  218. while (level > 0) {
  219. /* Attempt to get the next object in this scope */
  220. status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
  221. child_handle, &next_child_handle);
  222. child_handle = next_child_handle;
  223. /* Did we get a new object? */
  224. if (ACPI_SUCCESS(status)) {
  225. /* Check if this object has any children */
  226. if (ACPI_SUCCESS
  227. (acpi_get_next_object
  228. (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
  229. /*
  230. * There is at least one child of this object,
  231. * visit the object
  232. */
  233. level++;
  234. parent_handle = child_handle;
  235. child_handle = NULL;
  236. }
  237. } else {
  238. /*
  239. * No more children in this object, go back up to
  240. * the object's parent
  241. */
  242. level--;
  243. /* Delete all children now */
  244. acpi_ns_delete_children(child_handle);
  245. child_handle = parent_handle;
  246. status = acpi_get_parent(parent_handle, &parent_handle);
  247. if (ACPI_FAILURE(status)) {
  248. return_ACPI_STATUS(status);
  249. }
  250. }
  251. }
  252. /* Now delete the starting object, and we are done */
  253. acpi_ns_remove_node(child_handle);
  254. return_ACPI_STATUS(AE_OK);
  255. }
  256. /*******************************************************************************
  257. *
  258. * FUNCTION: acpi_ns_unload_name_space
  259. *
  260. * PARAMETERS: handle - Root of namespace subtree to be deleted
  261. *
  262. * RETURN: Status
  263. *
  264. * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
  265. * event. Deletes an entire subtree starting from (and
  266. * including) the given handle.
  267. *
  268. ******************************************************************************/
  269. acpi_status acpi_ns_unload_namespace(acpi_handle handle)
  270. {
  271. acpi_status status;
  272. ACPI_FUNCTION_TRACE(ns_unload_name_space);
  273. /* Parameter validation */
  274. if (!acpi_gbl_root_node) {
  275. return_ACPI_STATUS(AE_NO_NAMESPACE);
  276. }
  277. if (!handle) {
  278. return_ACPI_STATUS(AE_BAD_PARAMETER);
  279. }
  280. /* This function does the real work */
  281. status = acpi_ns_delete_subtree(handle);
  282. return_ACPI_STATUS(status);
  283. }
  284. #endif
  285. #endif