exconfig.c 18 KB

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