tbxface.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /******************************************************************************
  2. *
  3. * Module Name: tbxface - Public interfaces to the ACPI subsystem
  4. * ACPI table oriented interfaces
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2006, R. Byron Moore
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <acpi/acpi.h>
  44. #include <acpi/acnamesp.h>
  45. #include <acpi/actables.h>
  46. #define _COMPONENT ACPI_TABLES
  47. ACPI_MODULE_NAME("tbxface")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_load_tables
  51. *
  52. * PARAMETERS: None
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: This function is called to load the ACPI tables from the
  57. * provided RSDT
  58. *
  59. ******************************************************************************/
  60. acpi_status acpi_load_tables(void)
  61. {
  62. struct acpi_pointer rsdp_address;
  63. acpi_status status;
  64. ACPI_FUNCTION_TRACE(acpi_load_tables);
  65. /* Get the RSDP */
  66. status = acpi_os_get_root_pointer(ACPI_LOGICAL_ADDRESSING,
  67. &rsdp_address);
  68. if (ACPI_FAILURE(status)) {
  69. ACPI_EXCEPTION((AE_INFO, status, "Could not get the RSDP"));
  70. goto error_exit;
  71. }
  72. /* Map and validate the RSDP */
  73. acpi_gbl_table_flags = rsdp_address.pointer_type;
  74. status = acpi_tb_verify_rsdp(&rsdp_address);
  75. if (ACPI_FAILURE(status)) {
  76. ACPI_EXCEPTION((AE_INFO, status, "During RSDP validation"));
  77. goto error_exit;
  78. }
  79. /* Get the RSDT via the RSDP */
  80. status = acpi_tb_get_table_rsdt();
  81. if (ACPI_FAILURE(status)) {
  82. ACPI_EXCEPTION((AE_INFO, status, "Could not load RSDT"));
  83. goto error_exit;
  84. }
  85. /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */
  86. status = acpi_tb_get_required_tables();
  87. if (ACPI_FAILURE(status)) {
  88. ACPI_EXCEPTION((AE_INFO, status,
  89. "Could not get all required tables (DSDT/FADT/FACS)"));
  90. goto error_exit;
  91. }
  92. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
  93. /* Load the namespace from the tables */
  94. status = acpi_ns_load_namespace();
  95. if (ACPI_FAILURE(status)) {
  96. ACPI_EXCEPTION((AE_INFO, status, "Could not load namespace"));
  97. goto error_exit;
  98. }
  99. return_ACPI_STATUS(AE_OK);
  100. error_exit:
  101. ACPI_EXCEPTION((AE_INFO, status, "Could not load tables"));
  102. return_ACPI_STATUS(status);
  103. }
  104. ACPI_EXPORT_SYMBOL(acpi_load_tables)
  105. /*******************************************************************************
  106. *
  107. * FUNCTION: acpi_load_table
  108. *
  109. * PARAMETERS: table_ptr - pointer to a buffer containing the entire
  110. * table to be loaded
  111. *
  112. * RETURN: Status
  113. *
  114. * DESCRIPTION: This function is called to load a table from the caller's
  115. * buffer. The buffer must contain an entire ACPI Table including
  116. * a valid header. The header fields will be verified, and if it
  117. * is determined that the table is invalid, the call will fail.
  118. *
  119. ******************************************************************************/
  120. acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
  121. {
  122. acpi_status status;
  123. struct acpi_table_desc table_info;
  124. struct acpi_pointer address;
  125. ACPI_FUNCTION_TRACE(acpi_load_table);
  126. if (!table_ptr) {
  127. return_ACPI_STATUS(AE_BAD_PARAMETER);
  128. }
  129. /* Copy the table to a local buffer */
  130. address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
  131. address.pointer.logical = table_ptr;
  132. status = acpi_tb_get_table_body(&address, table_ptr, &table_info);
  133. if (ACPI_FAILURE(status)) {
  134. return_ACPI_STATUS(status);
  135. }
  136. /* Check signature for a valid table type */
  137. status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL);
  138. if (ACPI_FAILURE(status)) {
  139. return_ACPI_STATUS(status);
  140. }
  141. /* Install the new table into the local data structures */
  142. status = acpi_tb_install_table(&table_info);
  143. if (ACPI_FAILURE(status)) {
  144. if (status == AE_ALREADY_EXISTS) {
  145. /* Table already exists, no error */
  146. status = AE_OK;
  147. }
  148. /* Free table allocated by acpi_tb_get_table_body */
  149. acpi_tb_delete_single_table(&table_info);
  150. return_ACPI_STATUS(status);
  151. }
  152. /* Convert the table to common format if necessary */
  153. switch (table_info.type) {
  154. case ACPI_TABLE_ID_FADT:
  155. status = acpi_tb_convert_table_fadt();
  156. break;
  157. case ACPI_TABLE_ID_FACS:
  158. status = acpi_tb_build_common_facs(&table_info);
  159. break;
  160. default:
  161. /* Load table into namespace if it contains executable AML */
  162. status =
  163. acpi_ns_load_table(table_info.installed_desc,
  164. acpi_gbl_root_node);
  165. break;
  166. }
  167. if (ACPI_FAILURE(status)) {
  168. /* Uninstall table and free the buffer */
  169. (void)acpi_tb_uninstall_table(table_info.installed_desc);
  170. }
  171. return_ACPI_STATUS(status);
  172. }
  173. ACPI_EXPORT_SYMBOL(acpi_load_table)
  174. /*******************************************************************************
  175. *
  176. * FUNCTION: acpi_unload_table_id
  177. *
  178. * PARAMETERS: table_type - Type of table to be unloaded
  179. * id - Owner ID of the table to be removed.
  180. *
  181. * RETURN: Status
  182. *
  183. * DESCRIPTION: This routine is used to force the unload of a table (by id)
  184. *
  185. ******************************************************************************/
  186. acpi_status acpi_unload_table_id(acpi_table_type table_type, acpi_owner_id id)
  187. {
  188. struct acpi_table_desc *table_desc;
  189. acpi_status status;
  190. ACPI_FUNCTION_TRACE(acpi_unload_table);
  191. /* Parameter validation */
  192. if (table_type > ACPI_TABLE_ID_MAX)
  193. return_ACPI_STATUS(AE_BAD_PARAMETER);
  194. /* Find table from the requested type list */
  195. table_desc = acpi_gbl_table_lists[table_type].next;
  196. while (table_desc && table_desc->owner_id != id)
  197. table_desc = table_desc->next;
  198. if (!table_desc)
  199. return_ACPI_STATUS(AE_NOT_EXIST);
  200. /*
  201. * Delete all namespace objects owned by this table. Note that these
  202. * objects can appear anywhere in the namespace by virtue of the AML
  203. * "Scope" operator. Thus, we need to track ownership by an ID, not
  204. * simply a position within the hierarchy
  205. */
  206. acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
  207. status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  208. if (ACPI_FAILURE(status))
  209. return_ACPI_STATUS(status);
  210. (void)acpi_tb_uninstall_table(table_desc);
  211. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  212. return_ACPI_STATUS(AE_OK);
  213. }
  214. ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
  215. #ifdef ACPI_FUTURE_USAGE
  216. /*******************************************************************************
  217. *
  218. * FUNCTION: acpi_unload_table
  219. *
  220. * PARAMETERS: table_type - Type of table to be unloaded
  221. *
  222. * RETURN: Status
  223. *
  224. * DESCRIPTION: This routine is used to force the unload of a table
  225. *
  226. ******************************************************************************/
  227. acpi_status acpi_unload_table(acpi_table_type table_type)
  228. {
  229. struct acpi_table_desc *table_desc;
  230. ACPI_FUNCTION_TRACE(acpi_unload_table);
  231. /* Parameter validation */
  232. if (table_type > ACPI_TABLE_ID_MAX) {
  233. return_ACPI_STATUS(AE_BAD_PARAMETER);
  234. }
  235. /* Find all tables of the requested type */
  236. table_desc = acpi_gbl_table_lists[table_type].next;
  237. if (!table_desc) {
  238. return_ACPI_STATUS(AE_NOT_EXIST);
  239. }
  240. while (table_desc) {
  241. /*
  242. * Delete all namespace objects owned by this table. Note that these
  243. * objects can appear anywhere in the namespace by virtue of the AML
  244. * "Scope" operator. Thus, we need to track ownership by an ID, not
  245. * simply a position within the hierarchy
  246. */
  247. acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
  248. table_desc = table_desc->next;
  249. }
  250. /* Delete (or unmap) all tables of this type */
  251. acpi_tb_delete_tables_by_type(table_type);
  252. return_ACPI_STATUS(AE_OK);
  253. }
  254. ACPI_EXPORT_SYMBOL(acpi_unload_table)
  255. /*******************************************************************************
  256. *
  257. * FUNCTION: acpi_get_table_header
  258. *
  259. * PARAMETERS: table_type - one of the defined table types
  260. * Instance - the non zero instance of the table, allows
  261. * support for multiple tables of the same type
  262. * see acpi_gbl_acpi_table_flag
  263. * out_table_header - pointer to the struct acpi_table_header if successful
  264. *
  265. * DESCRIPTION: This function is called to get an ACPI table header. The caller
  266. * supplies an pointer to a data area sufficient to contain an ACPI
  267. * struct acpi_table_header structure.
  268. *
  269. * The header contains a length field that can be used to determine
  270. * the size of the buffer needed to contain the entire table. This
  271. * function is not valid for the RSD PTR table since it does not
  272. * have a standard header and is fixed length.
  273. *
  274. ******************************************************************************/
  275. acpi_status
  276. acpi_get_table_header(acpi_table_type table_type,
  277. u32 instance, struct acpi_table_header *out_table_header)
  278. {
  279. struct acpi_table_header *tbl_ptr;
  280. acpi_status status;
  281. ACPI_FUNCTION_TRACE(acpi_get_table_header);
  282. if ((instance == 0) ||
  283. (table_type == ACPI_TABLE_ID_RSDP) || (!out_table_header)) {
  284. return_ACPI_STATUS(AE_BAD_PARAMETER);
  285. }
  286. /* Check the table type and instance */
  287. if ((table_type > ACPI_TABLE_ID_MAX) ||
  288. (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
  289. instance > 1)) {
  290. return_ACPI_STATUS(AE_BAD_PARAMETER);
  291. }
  292. /* Get a pointer to the entire table */
  293. status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
  294. if (ACPI_FAILURE(status)) {
  295. return_ACPI_STATUS(status);
  296. }
  297. /* The function will return a NULL pointer if the table is not loaded */
  298. if (tbl_ptr == NULL) {
  299. return_ACPI_STATUS(AE_NOT_EXIST);
  300. }
  301. /* Copy the header to the caller's buffer */
  302. ACPI_MEMCPY(ACPI_CAST_PTR(void, out_table_header),
  303. ACPI_CAST_PTR(void, tbl_ptr),
  304. sizeof(struct acpi_table_header));
  305. return_ACPI_STATUS(status);
  306. }
  307. ACPI_EXPORT_SYMBOL(acpi_get_table_header)
  308. #endif /* ACPI_FUTURE_USAGE */
  309. /*******************************************************************************
  310. *
  311. * FUNCTION: acpi_get_table
  312. *
  313. * PARAMETERS: table_type - one of the defined table types
  314. * Instance - the non zero instance of the table, allows
  315. * support for multiple tables of the same type
  316. * see acpi_gbl_acpi_table_flag
  317. * ret_buffer - pointer to a structure containing a buffer to
  318. * receive the table
  319. *
  320. * RETURN: Status
  321. *
  322. * DESCRIPTION: This function is called to get an ACPI table. The caller
  323. * supplies an out_buffer large enough to contain the entire ACPI
  324. * table. The caller should call the acpi_get_table_header function
  325. * first to determine the buffer size needed. Upon completion
  326. * the out_buffer->Length field will indicate the number of bytes
  327. * copied into the out_buffer->buf_ptr buffer. This table will be
  328. * a complete table including the header.
  329. *
  330. ******************************************************************************/
  331. acpi_status
  332. acpi_get_table(acpi_table_type table_type,
  333. u32 instance, struct acpi_buffer *ret_buffer)
  334. {
  335. struct acpi_table_header *tbl_ptr;
  336. acpi_status status;
  337. acpi_size table_length;
  338. ACPI_FUNCTION_TRACE(acpi_get_table);
  339. /* Parameter validation */
  340. if (instance == 0) {
  341. return_ACPI_STATUS(AE_BAD_PARAMETER);
  342. }
  343. status = acpi_ut_validate_buffer(ret_buffer);
  344. if (ACPI_FAILURE(status)) {
  345. return_ACPI_STATUS(status);
  346. }
  347. /* Check the table type and instance */
  348. if ((table_type > ACPI_TABLE_ID_MAX) ||
  349. (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
  350. instance > 1)) {
  351. return_ACPI_STATUS(AE_BAD_PARAMETER);
  352. }
  353. /* Get a pointer to the entire table */
  354. status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
  355. if (ACPI_FAILURE(status)) {
  356. return_ACPI_STATUS(status);
  357. }
  358. /*
  359. * acpi_tb_get_table_ptr will return a NULL pointer if the
  360. * table is not loaded.
  361. */
  362. if (tbl_ptr == NULL) {
  363. return_ACPI_STATUS(AE_NOT_EXIST);
  364. }
  365. /* Get the table length */
  366. if (table_type == ACPI_TABLE_ID_RSDP) {
  367. /* RSD PTR is the only "table" without a header */
  368. table_length = sizeof(struct rsdp_descriptor);
  369. } else {
  370. table_length = (acpi_size) tbl_ptr->length;
  371. }
  372. /* Validate/Allocate/Clear caller buffer */
  373. status = acpi_ut_initialize_buffer(ret_buffer, table_length);
  374. if (ACPI_FAILURE(status)) {
  375. return_ACPI_STATUS(status);
  376. }
  377. /* Copy the table to the buffer */
  378. ACPI_MEMCPY(ACPI_CAST_PTR(void, ret_buffer->pointer),
  379. ACPI_CAST_PTR(void, tbl_ptr), table_length);
  380. return_ACPI_STATUS(AE_OK);
  381. }
  382. ACPI_EXPORT_SYMBOL(acpi_get_table)