exconfig.c 14 KB

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