exconfig.c 14 KB

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