exconfig.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. /******************************************************************************
  2. *
  3. * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, 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_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_by_path(operand[3]->string.pointer,
  178. start_node, ACPI_NS_SEARCH_PARENT,
  179. &parent_node);
  180. if (ACPI_FAILURE(status)) {
  181. return_ACPI_STATUS(status);
  182. }
  183. }
  184. /* parameter_path (optional parameter) */
  185. if (operand[4]->string.length > 0) {
  186. if ((operand[4]->string.pointer[0] != '\\') &&
  187. (operand[4]->string.pointer[0] != '^')) {
  188. /*
  189. * Path is not absolute, so it will be relative to the node
  190. * referenced by the root_path_string (or the NS root if omitted)
  191. */
  192. start_node = parent_node;
  193. }
  194. /* Find the node referenced by the parameter_path_string */
  195. status =
  196. acpi_ns_get_node_by_path(operand[4]->string.pointer,
  197. start_node, ACPI_NS_SEARCH_PARENT,
  198. &parameter_node);
  199. if (ACPI_FAILURE(status)) {
  200. return_ACPI_STATUS(status);
  201. }
  202. }
  203. /* Load the table into the namespace */
  204. status = acpi_ex_add_table(table, parent_node, &ddb_handle);
  205. if (ACPI_FAILURE(status)) {
  206. return_ACPI_STATUS(status);
  207. }
  208. /* Parameter Data (optional) */
  209. if (parameter_node) {
  210. /* Store the parameter data into the optional parameter object */
  211. status = acpi_ex_store(operand[5],
  212. ACPI_CAST_PTR(union acpi_operand_object,
  213. parameter_node),
  214. walk_state);
  215. if (ACPI_FAILURE(status)) {
  216. (void)acpi_ex_unload_table(ddb_handle);
  217. return_ACPI_STATUS(status);
  218. }
  219. }
  220. *return_desc = ddb_handle;
  221. return_ACPI_STATUS(status);
  222. }
  223. /*******************************************************************************
  224. *
  225. * FUNCTION: acpi_ex_load_op
  226. *
  227. * PARAMETERS: obj_desc - Region or Field where the table will be
  228. * obtained
  229. * Target - Where a handle to the table will be stored
  230. * walk_state - Current state
  231. *
  232. * RETURN: Status
  233. *
  234. * DESCRIPTION: Load an ACPI table from a field or operation region
  235. *
  236. ******************************************************************************/
  237. acpi_status
  238. acpi_ex_load_op(union acpi_operand_object *obj_desc,
  239. union acpi_operand_object *target,
  240. struct acpi_walk_state *walk_state)
  241. {
  242. acpi_status status;
  243. union acpi_operand_object *ddb_handle;
  244. union acpi_operand_object *buffer_desc = NULL;
  245. struct acpi_table_header *table_ptr = NULL;
  246. acpi_physical_address address;
  247. struct acpi_table_header table_header;
  248. u32 i;
  249. ACPI_FUNCTION_TRACE("ex_load_op");
  250. /* Object can be either an op_region or a Field */
  251. switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
  252. case ACPI_TYPE_REGION:
  253. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Region %p %s\n",
  254. obj_desc,
  255. acpi_ut_get_object_type_name(obj_desc)));
  256. /*
  257. * If the Region Address and Length have not been previously evaluated,
  258. * evaluate them now and save the results.
  259. */
  260. if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
  261. status = acpi_ds_get_region_arguments(obj_desc);
  262. if (ACPI_FAILURE(status)) {
  263. return_ACPI_STATUS(status);
  264. }
  265. }
  266. /* Get the base physical address of the region */
  267. address = obj_desc->region.address;
  268. /* Get the table length from the table header */
  269. table_header.length = 0;
  270. for (i = 0; i < 8; i++) {
  271. status =
  272. acpi_ev_address_space_dispatch(obj_desc, ACPI_READ,
  273. (acpi_physical_address)
  274. (i + address), 8,
  275. ((u8 *) &
  276. table_header) + i);
  277. if (ACPI_FAILURE(status)) {
  278. return_ACPI_STATUS(status);
  279. }
  280. }
  281. /* Sanity check the table length */
  282. if (table_header.length < sizeof(struct acpi_table_header)) {
  283. return_ACPI_STATUS(AE_BAD_HEADER);
  284. }
  285. /* Allocate a buffer for the entire table */
  286. table_ptr = ACPI_MEM_ALLOCATE(table_header.length);
  287. if (!table_ptr) {
  288. return_ACPI_STATUS(AE_NO_MEMORY);
  289. }
  290. /* Get the entire table from the op region */
  291. for (i = 0; i < table_header.length; i++) {
  292. status =
  293. acpi_ev_address_space_dispatch(obj_desc, ACPI_READ,
  294. (acpi_physical_address)
  295. (i + address), 8,
  296. ((u8 *) table_ptr +
  297. i));
  298. if (ACPI_FAILURE(status)) {
  299. goto cleanup;
  300. }
  301. }
  302. break;
  303. case ACPI_TYPE_LOCAL_REGION_FIELD:
  304. case ACPI_TYPE_LOCAL_BANK_FIELD:
  305. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  306. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Field %p %s\n",
  307. obj_desc,
  308. acpi_ut_get_object_type_name(obj_desc)));
  309. /*
  310. * The length of the field must be at least as large as the table.
  311. * Read the entire field and thus the entire table. Buffer is
  312. * allocated during the read.
  313. */
  314. status =
  315. acpi_ex_read_data_from_field(walk_state, obj_desc,
  316. &buffer_desc);
  317. if (ACPI_FAILURE(status)) {
  318. return_ACPI_STATUS(status);
  319. }
  320. table_ptr = ACPI_CAST_PTR(struct acpi_table_header,
  321. buffer_desc->buffer.pointer);
  322. /* All done with the buffer_desc, delete it */
  323. buffer_desc->buffer.pointer = NULL;
  324. acpi_ut_remove_reference(buffer_desc);
  325. /* Sanity check the table length */
  326. if (table_ptr->length < sizeof(struct acpi_table_header)) {
  327. status = AE_BAD_HEADER;
  328. goto cleanup;
  329. }
  330. break;
  331. default:
  332. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  333. }
  334. /* The table must be either an SSDT or a PSDT */
  335. if ((!ACPI_STRNCMP(table_ptr->signature,
  336. acpi_gbl_table_data[ACPI_TABLE_PSDT].signature,
  337. acpi_gbl_table_data[ACPI_TABLE_PSDT].sig_length)) &&
  338. (!ACPI_STRNCMP(table_ptr->signature,
  339. acpi_gbl_table_data[ACPI_TABLE_SSDT].signature,
  340. acpi_gbl_table_data[ACPI_TABLE_SSDT].sig_length))) {
  341. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  342. "Table has invalid signature [%4.4s], must be SSDT or PSDT\n",
  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. cleanup:
  361. if (ACPI_FAILURE(status)) {
  362. ACPI_MEM_FREE(table_ptr);
  363. }
  364. return_ACPI_STATUS(status);
  365. }
  366. /*******************************************************************************
  367. *
  368. * FUNCTION: acpi_ex_unload_table
  369. *
  370. * PARAMETERS: ddb_handle - Handle to a previously loaded table
  371. *
  372. * RETURN: Status
  373. *
  374. * DESCRIPTION: Unload an ACPI table
  375. *
  376. ******************************************************************************/
  377. acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
  378. {
  379. acpi_status status = AE_OK;
  380. union acpi_operand_object *table_desc = ddb_handle;
  381. struct acpi_table_desc *table_info;
  382. ACPI_FUNCTION_TRACE("ex_unload_table");
  383. /*
  384. * Validate the handle
  385. * Although the handle is partially validated in acpi_ex_reconfiguration(),
  386. * when it calls acpi_ex_resolve_operands(), the handle is more completely
  387. * validated here.
  388. */
  389. if ((!ddb_handle) ||
  390. (ACPI_GET_DESCRIPTOR_TYPE(ddb_handle) != ACPI_DESC_TYPE_OPERAND) ||
  391. (ACPI_GET_OBJECT_TYPE(ddb_handle) != ACPI_TYPE_LOCAL_REFERENCE)) {
  392. return_ACPI_STATUS(AE_BAD_PARAMETER);
  393. }
  394. /* Get the actual table descriptor from the ddb_handle */
  395. table_info = (struct acpi_table_desc *)table_desc->reference.object;
  396. /*
  397. * Delete the entire namespace under this table Node
  398. * (Offset contains the table_id)
  399. */
  400. acpi_ns_delete_namespace_by_owner(table_info->owner_id);
  401. acpi_ut_release_owner_id(&table_info->owner_id);
  402. /* Delete the table itself */
  403. (void)acpi_tb_uninstall_table(table_info->installed_desc);
  404. /* Delete the table descriptor (ddb_handle) */
  405. acpi_ut_remove_reference(table_desc);
  406. return_ACPI_STATUS(status);
  407. }