exconfig.c 15 KB

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