exconfig.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /******************************************************************************
  2. *
  3. * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2007, R. Byron Moore
  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 <acpi/acinterp.h>
  44. #include <acpi/amlcode.h>
  45. #include <acpi/acnamesp.h>
  46. #include <acpi/acevents.h>
  47. #include <acpi/actables.h>
  48. #include <acpi/acdispat.h>
  49. #define _COMPONENT ACPI_EXECUTER
  50. ACPI_MODULE_NAME("exconfig")
  51. /* Local prototypes */
  52. static acpi_status
  53. acpi_ex_add_table(acpi_native_uint table_index,
  54. struct acpi_namespace_node *parent_node,
  55. union acpi_operand_object **ddb_handle);
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: acpi_ex_add_table
  59. *
  60. * PARAMETERS: Table - Pointer to raw table
  61. * parent_node - Where to load the table (scope)
  62. * ddb_handle - Where to return the table handle.
  63. *
  64. * RETURN: Status
  65. *
  66. * DESCRIPTION: Common function to Install and Load an ACPI table with a
  67. * returned table handle.
  68. *
  69. ******************************************************************************/
  70. static acpi_status
  71. acpi_ex_add_table(acpi_native_uint table_index,
  72. struct acpi_namespace_node *parent_node,
  73. union acpi_operand_object **ddb_handle)
  74. {
  75. acpi_status status;
  76. union acpi_operand_object *obj_desc;
  77. ACPI_FUNCTION_TRACE(ex_add_table);
  78. /* Create an object to be the table handle */
  79. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
  80. if (!obj_desc) {
  81. return_ACPI_STATUS(AE_NO_MEMORY);
  82. }
  83. /* Init the table handle */
  84. obj_desc->reference.opcode = AML_LOAD_OP;
  85. *ddb_handle = obj_desc;
  86. /* Install the new table into the local data structures */
  87. obj_desc->reference.object = ACPI_CAST_PTR(void, table_index);
  88. /* Add the table to the namespace */
  89. status = acpi_ns_load_table(table_index, parent_node);
  90. if (ACPI_FAILURE(status)) {
  91. acpi_ut_remove_reference(obj_desc);
  92. *ddb_handle = NULL;
  93. }
  94. return_ACPI_STATUS(status);
  95. }
  96. /*******************************************************************************
  97. *
  98. * FUNCTION: acpi_ex_load_table_op
  99. *
  100. * PARAMETERS: walk_state - Current state with operands
  101. * return_desc - Where to store the return object
  102. *
  103. * RETURN: Status
  104. *
  105. * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
  106. *
  107. ******************************************************************************/
  108. acpi_status
  109. acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
  110. union acpi_operand_object **return_desc)
  111. {
  112. acpi_status status;
  113. union acpi_operand_object **operand = &walk_state->operands[0];
  114. acpi_native_uint table_index;
  115. struct acpi_namespace_node *parent_node;
  116. struct acpi_namespace_node *start_node;
  117. struct acpi_namespace_node *parameter_node = NULL;
  118. union acpi_operand_object *ddb_handle;
  119. struct acpi_table_header *table;
  120. ACPI_FUNCTION_TRACE(ex_load_table_op);
  121. /* Find the ACPI table in the RSDT/XSDT */
  122. status = acpi_tb_find_table(operand[0]->string.pointer,
  123. operand[1]->string.pointer,
  124. operand[2]->string.pointer, &table_index);
  125. if (ACPI_FAILURE(status)) {
  126. if (status != AE_NOT_FOUND) {
  127. return_ACPI_STATUS(status);
  128. }
  129. /* Table not found, return an Integer=0 and AE_OK */
  130. ddb_handle = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  131. if (!ddb_handle) {
  132. return_ACPI_STATUS(AE_NO_MEMORY);
  133. }
  134. ddb_handle->integer.value = 0;
  135. *return_desc = ddb_handle;
  136. return_ACPI_STATUS(AE_OK);
  137. }
  138. /* Default nodes */
  139. start_node = walk_state->scope_info->scope.node;
  140. parent_node = acpi_gbl_root_node;
  141. /* root_path (optional parameter) */
  142. if (operand[3]->string.length > 0) {
  143. /*
  144. * Find the node referenced by the root_path_string. This is the
  145. * location within the namespace where the table will be loaded.
  146. */
  147. status =
  148. acpi_ns_get_node(start_node, operand[3]->string.pointer,
  149. ACPI_NS_SEARCH_PARENT, &parent_node);
  150. if (ACPI_FAILURE(status)) {
  151. return_ACPI_STATUS(status);
  152. }
  153. }
  154. /* parameter_path (optional parameter) */
  155. if (operand[4]->string.length > 0) {
  156. if ((operand[4]->string.pointer[0] != '\\') &&
  157. (operand[4]->string.pointer[0] != '^')) {
  158. /*
  159. * Path is not absolute, so it will be relative to the node
  160. * referenced by the root_path_string (or the NS root if omitted)
  161. */
  162. start_node = parent_node;
  163. }
  164. /* Find the node referenced by the parameter_path_string */
  165. status =
  166. acpi_ns_get_node(start_node, operand[4]->string.pointer,
  167. ACPI_NS_SEARCH_PARENT, &parameter_node);
  168. if (ACPI_FAILURE(status)) {
  169. return_ACPI_STATUS(status);
  170. }
  171. }
  172. /* Load the table into the namespace */
  173. status = acpi_ex_add_table(table_index, parent_node, &ddb_handle);
  174. if (ACPI_FAILURE(status)) {
  175. return_ACPI_STATUS(status);
  176. }
  177. /* Parameter Data (optional) */
  178. if (parameter_node) {
  179. /* Store the parameter data into the optional parameter object */
  180. status = acpi_ex_store(operand[5],
  181. ACPI_CAST_PTR(union acpi_operand_object,
  182. parameter_node),
  183. walk_state);
  184. if (ACPI_FAILURE(status)) {
  185. (void)acpi_ex_unload_table(ddb_handle);
  186. return_ACPI_STATUS(status);
  187. }
  188. }
  189. status = acpi_get_table_by_index(table_index, &table);
  190. if (ACPI_SUCCESS(status)) {
  191. ACPI_INFO((AE_INFO,
  192. "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]",
  193. table->signature, table->oem_id,
  194. table->oem_table_id));
  195. }
  196. *return_desc = ddb_handle;
  197. return_ACPI_STATUS(status);
  198. }
  199. /*******************************************************************************
  200. *
  201. * FUNCTION: acpi_ex_load_op
  202. *
  203. * PARAMETERS: obj_desc - Region or Buffer/Field where the table will be
  204. * obtained
  205. * Target - Where a handle to the table will be stored
  206. * walk_state - Current state
  207. *
  208. * RETURN: Status
  209. *
  210. * DESCRIPTION: Load an ACPI table from a field or operation region
  211. *
  212. * NOTE: Region Fields (Field, bank_field, index_fields) are resolved to buffer
  213. * objects before this code is reached.
  214. *
  215. * If source is an operation region, it must refer to system_memory, as
  216. * per the ACPI specification.
  217. *
  218. ******************************************************************************/
  219. acpi_status
  220. acpi_ex_load_op(union acpi_operand_object *obj_desc,
  221. union acpi_operand_object *target,
  222. struct acpi_walk_state *walk_state)
  223. {
  224. union acpi_operand_object *ddb_handle;
  225. struct acpi_table_desc table_desc;
  226. acpi_native_uint table_index;
  227. acpi_status status;
  228. ACPI_FUNCTION_TRACE(ex_load_op);
  229. ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
  230. /* Source Object can be either an op_region or a Buffer/Field */
  231. switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
  232. case ACPI_TYPE_REGION:
  233. /* Region must be system_memory (from ACPI spec) */
  234. if (obj_desc->region.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
  235. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  236. }
  237. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Region %p %s\n",
  238. obj_desc,
  239. acpi_ut_get_object_type_name(obj_desc)));
  240. /*
  241. * If the Region Address and Length have not been previously evaluated,
  242. * evaluate them now and save the results.
  243. */
  244. if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
  245. status = acpi_ds_get_region_arguments(obj_desc);
  246. if (ACPI_FAILURE(status)) {
  247. return_ACPI_STATUS(status);
  248. }
  249. }
  250. table_desc.address = obj_desc->region.address;
  251. table_desc.length = obj_desc->region.length;
  252. table_desc.flags = ACPI_TABLE_ORIGIN_MAPPED;
  253. break;
  254. case ACPI_TYPE_BUFFER: /* Buffer or resolved region_field */
  255. /* Simply extract the buffer from the buffer object */
  256. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  257. "Load from Buffer or Field %p %s\n", obj_desc,
  258. acpi_ut_get_object_type_name(obj_desc)));
  259. table_desc.pointer = ACPI_CAST_PTR(struct acpi_table_header,
  260. obj_desc->buffer.pointer);
  261. table_desc.length = table_desc.pointer->length;
  262. table_desc.flags = ACPI_TABLE_ORIGIN_ALLOCATED;
  263. obj_desc->buffer.pointer = NULL;
  264. break;
  265. default:
  266. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  267. }
  268. /*
  269. * Install the new table into the local data structures
  270. */
  271. status = acpi_tb_add_table(&table_desc, &table_index);
  272. if (ACPI_FAILURE(status)) {
  273. goto cleanup;
  274. }
  275. status =
  276. acpi_ex_add_table(table_index, acpi_gbl_root_node, &ddb_handle);
  277. if (ACPI_FAILURE(status)) {
  278. /* On error, table_ptr was deallocated above */
  279. return_ACPI_STATUS(status);
  280. }
  281. /* Store the ddb_handle into the Target operand */
  282. status = acpi_ex_store(ddb_handle, target, walk_state);
  283. if (ACPI_FAILURE(status)) {
  284. (void)acpi_ex_unload_table(ddb_handle);
  285. /* table_ptr was deallocated above */
  286. return_ACPI_STATUS(status);
  287. }
  288. cleanup:
  289. if (ACPI_FAILURE(status)) {
  290. acpi_tb_delete_table(&table_desc);
  291. }
  292. return_ACPI_STATUS(status);
  293. }
  294. /*******************************************************************************
  295. *
  296. * FUNCTION: acpi_ex_unload_table
  297. *
  298. * PARAMETERS: ddb_handle - Handle to a previously loaded table
  299. *
  300. * RETURN: Status
  301. *
  302. * DESCRIPTION: Unload an ACPI table
  303. *
  304. ******************************************************************************/
  305. acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
  306. {
  307. acpi_status status = AE_OK;
  308. union acpi_operand_object *table_desc = ddb_handle;
  309. acpi_native_uint table_index;
  310. ACPI_FUNCTION_TRACE(ex_unload_table);
  311. /*
  312. * Validate the handle
  313. * Although the handle is partially validated in acpi_ex_reconfiguration(),
  314. * when it calls acpi_ex_resolve_operands(), the handle is more completely
  315. * validated here.
  316. */
  317. if ((!ddb_handle) ||
  318. (ACPI_GET_DESCRIPTOR_TYPE(ddb_handle) != ACPI_DESC_TYPE_OPERAND) ||
  319. (ACPI_GET_OBJECT_TYPE(ddb_handle) != ACPI_TYPE_LOCAL_REFERENCE)) {
  320. return_ACPI_STATUS(AE_BAD_PARAMETER);
  321. }
  322. /* Get the table index from the ddb_handle */
  323. table_index = (acpi_native_uint) table_desc->reference.object;
  324. /*
  325. * Delete the entire namespace under this table Node
  326. * (Offset contains the table_id)
  327. */
  328. acpi_tb_delete_namespace_by_owner(table_index);
  329. acpi_tb_release_owner_id(table_index);
  330. acpi_tb_set_table_loaded_flag(table_index, FALSE);
  331. /* Delete the table descriptor (ddb_handle) */
  332. acpi_ut_remove_reference(table_desc);
  333. return_ACPI_STATUS(status);
  334. }