exconfig.c 14 KB

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