exconfig.c 14 KB

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