exconfig.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /******************************************************************************
  2. *
  3. * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, 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(struct acpi_table_header *table,
  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(struct acpi_table_header *table,
  72. struct acpi_namespace_node *parent_node,
  73. union acpi_operand_object **ddb_handle)
  74. {
  75. acpi_status status;
  76. struct acpi_table_desc table_info;
  77. union acpi_operand_object *obj_desc;
  78. ACPI_FUNCTION_TRACE(ex_add_table);
  79. /* Create an object to be the table handle */
  80. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
  81. if (!obj_desc) {
  82. return_ACPI_STATUS(AE_NO_MEMORY);
  83. }
  84. /* Init the table handle */
  85. obj_desc->reference.opcode = AML_LOAD_OP;
  86. *ddb_handle = obj_desc;
  87. /* Install the new table into the local data structures */
  88. ACPI_MEMSET(&table_info, 0, sizeof(struct acpi_table_desc));
  89. table_info.type = ACPI_TABLE_ID_SSDT;
  90. table_info.pointer = table;
  91. table_info.length = (acpi_size) table->length;
  92. table_info.allocation = ACPI_MEM_ALLOCATED;
  93. status = acpi_tb_install_table(&table_info);
  94. obj_desc->reference.object = table_info.installed_desc;
  95. if (ACPI_FAILURE(status)) {
  96. if (status == AE_ALREADY_EXISTS) {
  97. /* Table already exists, just return the handle */
  98. return_ACPI_STATUS(AE_OK);
  99. }
  100. goto cleanup;
  101. }
  102. /* Add the table to the namespace */
  103. status = acpi_ns_load_table(table_info.installed_desc, parent_node);
  104. if (ACPI_FAILURE(status)) {
  105. /* Uninstall table on error */
  106. (void)acpi_tb_uninstall_table(table_info.installed_desc);
  107. goto cleanup;
  108. }
  109. return_ACPI_STATUS(AE_OK);
  110. cleanup:
  111. acpi_ut_remove_reference(obj_desc);
  112. *ddb_handle = NULL;
  113. return_ACPI_STATUS(status);
  114. }
  115. /*******************************************************************************
  116. *
  117. * FUNCTION: acpi_ex_load_table_op
  118. *
  119. * PARAMETERS: walk_state - Current state with operands
  120. * return_desc - Where to store the return object
  121. *
  122. * RETURN: Status
  123. *
  124. * DESCRIPTION: Load an ACPI table
  125. *
  126. ******************************************************************************/
  127. acpi_status
  128. acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
  129. union acpi_operand_object **return_desc)
  130. {
  131. acpi_status status;
  132. union acpi_operand_object **operand = &walk_state->operands[0];
  133. struct acpi_table_header *table;
  134. struct acpi_namespace_node *parent_node;
  135. struct acpi_namespace_node *start_node;
  136. struct acpi_namespace_node *parameter_node = NULL;
  137. union acpi_operand_object *ddb_handle;
  138. ACPI_FUNCTION_TRACE(ex_load_table_op);
  139. #if 0
  140. /*
  141. * Make sure that the signature does not match one of the tables that
  142. * is already loaded.
  143. */
  144. status = acpi_tb_match_signature(operand[0]->string.pointer, NULL);
  145. if (status == AE_OK) {
  146. /* Signature matched -- don't allow override */
  147. return_ACPI_STATUS(AE_ALREADY_EXISTS);
  148. }
  149. #endif
  150. /* Find the ACPI table */
  151. status = acpi_tb_find_table(operand[0]->string.pointer,
  152. operand[1]->string.pointer,
  153. operand[2]->string.pointer, &table);
  154. if (ACPI_FAILURE(status)) {
  155. if (status != AE_NOT_FOUND) {
  156. return_ACPI_STATUS(status);
  157. }
  158. /* Table not found, return an Integer=0 and AE_OK */
  159. ddb_handle = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  160. if (!ddb_handle) {
  161. return_ACPI_STATUS(AE_NO_MEMORY);
  162. }
  163. ddb_handle->integer.value = 0;
  164. *return_desc = ddb_handle;
  165. return_ACPI_STATUS(AE_OK);
  166. }
  167. /* Default nodes */
  168. start_node = walk_state->scope_info->scope.node;
  169. parent_node = acpi_gbl_root_node;
  170. /* root_path (optional parameter) */
  171. if (operand[3]->string.length > 0) {
  172. /*
  173. * Find the node referenced by the root_path_string. This is the
  174. * location within the namespace where the table will be loaded.
  175. */
  176. status =
  177. acpi_ns_get_node(start_node, operand[3]->string.pointer,
  178. ACPI_NS_SEARCH_PARENT, &parent_node);
  179. if (ACPI_FAILURE(status)) {
  180. return_ACPI_STATUS(status);
  181. }
  182. }
  183. /* parameter_path (optional parameter) */
  184. if (operand[4]->string.length > 0) {
  185. if ((operand[4]->string.pointer[0] != '\\') &&
  186. (operand[4]->string.pointer[0] != '^')) {
  187. /*
  188. * Path is not absolute, so it will be relative to the node
  189. * referenced by the root_path_string (or the NS root if omitted)
  190. */
  191. start_node = parent_node;
  192. }
  193. /* Find the node referenced by the parameter_path_string */
  194. status =
  195. acpi_ns_get_node(start_node, operand[4]->string.pointer,
  196. ACPI_NS_SEARCH_PARENT, &parameter_node);
  197. if (ACPI_FAILURE(status)) {
  198. return_ACPI_STATUS(status);
  199. }
  200. }
  201. /* Load the table into the namespace */
  202. status = acpi_ex_add_table(table, parent_node, &ddb_handle);
  203. if (ACPI_FAILURE(status)) {
  204. return_ACPI_STATUS(status);
  205. }
  206. /* Parameter Data (optional) */
  207. if (parameter_node) {
  208. /* Store the parameter data into the optional parameter object */
  209. status = acpi_ex_store(operand[5],
  210. ACPI_CAST_PTR(union acpi_operand_object,
  211. parameter_node),
  212. walk_state);
  213. if (ACPI_FAILURE(status)) {
  214. (void)acpi_ex_unload_table(ddb_handle);
  215. return_ACPI_STATUS(status);
  216. }
  217. }
  218. ACPI_INFO((AE_INFO,
  219. "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]",
  220. table->signature, table->oem_id, table->oem_table_id));
  221. *return_desc = ddb_handle;
  222. return_ACPI_STATUS(status);
  223. }
  224. /*******************************************************************************
  225. *
  226. * FUNCTION: acpi_ex_load_op
  227. *
  228. * PARAMETERS: obj_desc - Region or Field where the table will be
  229. * obtained
  230. * Target - Where a handle to the table will be stored
  231. * walk_state - Current state
  232. *
  233. * RETURN: Status
  234. *
  235. * DESCRIPTION: Load an ACPI table from a field or operation region
  236. *
  237. ******************************************************************************/
  238. acpi_status
  239. acpi_ex_load_op(union acpi_operand_object *obj_desc,
  240. union acpi_operand_object *target,
  241. struct acpi_walk_state *walk_state)
  242. {
  243. acpi_status status;
  244. union acpi_operand_object *ddb_handle;
  245. union acpi_operand_object *buffer_desc = NULL;
  246. struct acpi_table_header *table_ptr = NULL;
  247. acpi_physical_address address;
  248. struct acpi_table_header table_header;
  249. acpi_integer temp;
  250. u32 i;
  251. ACPI_FUNCTION_TRACE(ex_load_op);
  252. /* Object can be either an op_region or a Field */
  253. switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
  254. case ACPI_TYPE_REGION:
  255. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Region %p %s\n",
  256. obj_desc,
  257. acpi_ut_get_object_type_name(obj_desc)));
  258. /*
  259. * If the Region Address and Length have not been previously evaluated,
  260. * evaluate them now and save the results.
  261. */
  262. if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
  263. status = acpi_ds_get_region_arguments(obj_desc);
  264. if (ACPI_FAILURE(status)) {
  265. return_ACPI_STATUS(status);
  266. }
  267. }
  268. /* Get the base physical address of the region */
  269. address = obj_desc->region.address;
  270. /* Get part of the table header to get the table length */
  271. table_header.length = 0;
  272. for (i = 0; i < 8; i++) {
  273. status =
  274. acpi_ev_address_space_dispatch(obj_desc, ACPI_READ,
  275. (acpi_physical_address)
  276. (i + address), 8,
  277. &temp);
  278. if (ACPI_FAILURE(status)) {
  279. return_ACPI_STATUS(status);
  280. }
  281. /* Get the one valid byte of the returned 64-bit value */
  282. ACPI_CAST_PTR(u8, &table_header)[i] = (u8) temp;
  283. }
  284. /* Sanity check the table length */
  285. if (table_header.length < sizeof(struct acpi_table_header)) {
  286. return_ACPI_STATUS(AE_BAD_HEADER);
  287. }
  288. /* Allocate a buffer for the entire table */
  289. table_ptr = ACPI_ALLOCATE(table_header.length);
  290. if (!table_ptr) {
  291. return_ACPI_STATUS(AE_NO_MEMORY);
  292. }
  293. /* Get the entire table from the op region */
  294. for (i = 0; i < table_header.length; i++) {
  295. status =
  296. acpi_ev_address_space_dispatch(obj_desc, ACPI_READ,
  297. (acpi_physical_address)
  298. (i + address), 8,
  299. &temp);
  300. if (ACPI_FAILURE(status)) {
  301. goto cleanup;
  302. }
  303. /* Get the one valid byte of the returned 64-bit value */
  304. ACPI_CAST_PTR(u8, table_ptr)[i] = (u8) temp;
  305. }
  306. break;
  307. case ACPI_TYPE_LOCAL_REGION_FIELD:
  308. case ACPI_TYPE_LOCAL_BANK_FIELD:
  309. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  310. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Field %p %s\n",
  311. obj_desc,
  312. acpi_ut_get_object_type_name(obj_desc)));
  313. /*
  314. * The length of the field must be at least as large as the table.
  315. * Read the entire field and thus the entire table. Buffer is
  316. * allocated during the read.
  317. */
  318. status =
  319. acpi_ex_read_data_from_field(walk_state, obj_desc,
  320. &buffer_desc);
  321. if (ACPI_FAILURE(status)) {
  322. return_ACPI_STATUS(status);
  323. }
  324. table_ptr = ACPI_CAST_PTR(struct acpi_table_header,
  325. buffer_desc->buffer.pointer);
  326. /* All done with the buffer_desc, delete it */
  327. buffer_desc->buffer.pointer = NULL;
  328. acpi_ut_remove_reference(buffer_desc);
  329. /* Sanity check the table length */
  330. if (table_ptr->length < sizeof(struct acpi_table_header)) {
  331. status = AE_BAD_HEADER;
  332. goto cleanup;
  333. }
  334. break;
  335. default:
  336. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  337. }
  338. /* The table must be either an SSDT or a PSDT */
  339. if ((!ACPI_COMPARE_NAME(table_ptr->signature, PSDT_SIG)) &&
  340. (!ACPI_COMPARE_NAME(table_ptr->signature, SSDT_SIG))) {
  341. ACPI_ERROR((AE_INFO,
  342. "Table has invalid signature [%4.4s], must be SSDT or PSDT",
  343. table_ptr->signature));
  344. status = AE_BAD_SIGNATURE;
  345. goto cleanup;
  346. }
  347. /* Install the new table into the local data structures */
  348. status = acpi_ex_add_table(table_ptr, acpi_gbl_root_node, &ddb_handle);
  349. if (ACPI_FAILURE(status)) {
  350. /* On error, table_ptr was deallocated above */
  351. return_ACPI_STATUS(status);
  352. }
  353. /* Store the ddb_handle into the Target operand */
  354. status = acpi_ex_store(ddb_handle, target, walk_state);
  355. if (ACPI_FAILURE(status)) {
  356. (void)acpi_ex_unload_table(ddb_handle);
  357. /* table_ptr was deallocated above */
  358. return_ACPI_STATUS(status);
  359. }
  360. ACPI_INFO((AE_INFO,
  361. "Dynamic SSDT Load - OemId [%6.6s] OemTableId [%8.8s]",
  362. table_ptr->oem_id, table_ptr->oem_table_id));
  363. cleanup:
  364. if (ACPI_FAILURE(status)) {
  365. ACPI_FREE(table_ptr);
  366. }
  367. return_ACPI_STATUS(status);
  368. }
  369. /*******************************************************************************
  370. *
  371. * FUNCTION: acpi_ex_unload_table
  372. *
  373. * PARAMETERS: ddb_handle - Handle to a previously loaded table
  374. *
  375. * RETURN: Status
  376. *
  377. * DESCRIPTION: Unload an ACPI table
  378. *
  379. ******************************************************************************/
  380. acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
  381. {
  382. acpi_status status = AE_OK;
  383. union acpi_operand_object *table_desc = ddb_handle;
  384. struct acpi_table_desc *table_info;
  385. ACPI_FUNCTION_TRACE(ex_unload_table);
  386. /*
  387. * Validate the handle
  388. * Although the handle is partially validated in acpi_ex_reconfiguration(),
  389. * when it calls acpi_ex_resolve_operands(), the handle is more completely
  390. * validated here.
  391. */
  392. if ((!ddb_handle) ||
  393. (ACPI_GET_DESCRIPTOR_TYPE(ddb_handle) != ACPI_DESC_TYPE_OPERAND) ||
  394. (ACPI_GET_OBJECT_TYPE(ddb_handle) != ACPI_TYPE_LOCAL_REFERENCE)) {
  395. return_ACPI_STATUS(AE_BAD_PARAMETER);
  396. }
  397. /* Get the actual table descriptor from the ddb_handle */
  398. table_info = (struct acpi_table_desc *)table_desc->reference.object;
  399. /*
  400. * Delete the entire namespace under this table Node
  401. * (Offset contains the table_id)
  402. */
  403. acpi_ns_delete_namespace_by_owner(table_info->owner_id);
  404. /* Delete the table itself */
  405. (void)acpi_tb_uninstall_table(table_info->installed_desc);
  406. /* Delete the table descriptor (ddb_handle) */
  407. acpi_ut_remove_reference(table_desc);
  408. return_ACPI_STATUS(status);
  409. }