nsload.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /******************************************************************************
  2. *
  3. * Module Name: nsload - namespace loading/expanding/contracting procedures
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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. return_ACPI_STATUS(status);
  132. }
  133. #ifdef ACPI_OBSOLETE_FUNCTIONS
  134. /*******************************************************************************
  135. *
  136. * FUNCTION: acpi_load_namespace
  137. *
  138. * PARAMETERS: None
  139. *
  140. * RETURN: Status
  141. *
  142. * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
  143. * (DSDT points to either the BIOS or a buffer.)
  144. *
  145. ******************************************************************************/
  146. acpi_status acpi_ns_load_namespace(void)
  147. {
  148. acpi_status status;
  149. ACPI_FUNCTION_TRACE(acpi_load_name_space);
  150. /* There must be at least a DSDT installed */
  151. if (acpi_gbl_DSDT == NULL) {
  152. ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
  153. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  154. }
  155. /*
  156. * Load the namespace. The DSDT is required,
  157. * but the SSDT and PSDT tables are optional.
  158. */
  159. status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
  160. if (ACPI_FAILURE(status)) {
  161. return_ACPI_STATUS(status);
  162. }
  163. /* Ignore exceptions from these */
  164. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
  165. (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
  166. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  167. "ACPI Namespace successfully loaded at root %p\n",
  168. acpi_gbl_root_node));
  169. return_ACPI_STATUS(status);
  170. }
  171. #endif
  172. #ifdef ACPI_FUTURE_IMPLEMENTATION
  173. /*******************************************************************************
  174. *
  175. * FUNCTION: acpi_ns_delete_subtree
  176. *
  177. * PARAMETERS: start_handle - Handle in namespace where search begins
  178. *
  179. * RETURNS Status
  180. *
  181. * DESCRIPTION: Walks the namespace starting at the given handle and deletes
  182. * all objects, entries, and scopes in the entire subtree.
  183. *
  184. * Namespace/Interpreter should be locked or the subsystem should
  185. * be in shutdown before this routine is called.
  186. *
  187. ******************************************************************************/
  188. static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
  189. {
  190. acpi_status status;
  191. acpi_handle child_handle;
  192. acpi_handle parent_handle;
  193. acpi_handle next_child_handle;
  194. acpi_handle dummy;
  195. u32 level;
  196. ACPI_FUNCTION_TRACE(ns_delete_subtree);
  197. parent_handle = start_handle;
  198. child_handle = NULL;
  199. level = 1;
  200. /*
  201. * Traverse the tree of objects until we bubble back up
  202. * to where we started.
  203. */
  204. while (level > 0) {
  205. /* Attempt to get the next object in this scope */
  206. status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
  207. child_handle, &next_child_handle);
  208. child_handle = next_child_handle;
  209. /* Did we get a new object? */
  210. if (ACPI_SUCCESS(status)) {
  211. /* Check if this object has any children */
  212. if (ACPI_SUCCESS
  213. (acpi_get_next_object
  214. (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
  215. /*
  216. * There is at least one child of this object,
  217. * visit the object
  218. */
  219. level++;
  220. parent_handle = child_handle;
  221. child_handle = NULL;
  222. }
  223. } else {
  224. /*
  225. * No more children in this object, go back up to
  226. * the object's parent
  227. */
  228. level--;
  229. /* Delete all children now */
  230. acpi_ns_delete_children(child_handle);
  231. child_handle = parent_handle;
  232. status = acpi_get_parent(parent_handle, &parent_handle);
  233. if (ACPI_FAILURE(status)) {
  234. return_ACPI_STATUS(status);
  235. }
  236. }
  237. }
  238. /* Now delete the starting object, and we are done */
  239. acpi_ns_remove_node(child_handle);
  240. return_ACPI_STATUS(AE_OK);
  241. }
  242. /*******************************************************************************
  243. *
  244. * FUNCTION: acpi_ns_unload_name_space
  245. *
  246. * PARAMETERS: handle - Root of namespace subtree to be deleted
  247. *
  248. * RETURN: Status
  249. *
  250. * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
  251. * event. Deletes an entire subtree starting from (and
  252. * including) the given handle.
  253. *
  254. ******************************************************************************/
  255. acpi_status acpi_ns_unload_namespace(acpi_handle handle)
  256. {
  257. acpi_status status;
  258. ACPI_FUNCTION_TRACE(ns_unload_name_space);
  259. /* Parameter validation */
  260. if (!acpi_gbl_root_node) {
  261. return_ACPI_STATUS(AE_NO_NAMESPACE);
  262. }
  263. if (!handle) {
  264. return_ACPI_STATUS(AE_BAD_PARAMETER);
  265. }
  266. /* This function does the real work */
  267. status = acpi_ns_delete_subtree(handle);
  268. return_ACPI_STATUS(status);
  269. }
  270. #endif
  271. #endif