tbxface.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. #ifdef ACPI_FUTURE_USAGE
  106. /*******************************************************************************
  107. *
  108. * FUNCTION: acpi_load_table
  109. *
  110. * PARAMETERS: table_ptr - pointer to a buffer containing the entire
  111. * table to be loaded
  112. *
  113. * RETURN: Status
  114. *
  115. * DESCRIPTION: This function is called to load a table from the caller's
  116. * buffer. The buffer must contain an entire ACPI Table including
  117. * a valid header. The header fields will be verified, and if it
  118. * is determined that the table is invalid, the call will fail.
  119. *
  120. ******************************************************************************/
  121. acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
  122. {
  123. acpi_status status;
  124. struct acpi_table_desc table_info;
  125. struct acpi_pointer address;
  126. ACPI_FUNCTION_TRACE(acpi_load_table);
  127. if (!table_ptr) {
  128. return_ACPI_STATUS(AE_BAD_PARAMETER);
  129. }
  130. /* Copy the table to a local buffer */
  131. address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
  132. address.pointer.logical = table_ptr;
  133. status = acpi_tb_get_table_body(&address, table_ptr, &table_info);
  134. if (ACPI_FAILURE(status)) {
  135. return_ACPI_STATUS(status);
  136. }
  137. /* Check signature for a valid table type */
  138. status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL);
  139. if (ACPI_FAILURE(status)) {
  140. return_ACPI_STATUS(status);
  141. }
  142. /* Install the new table into the local data structures */
  143. status = acpi_tb_install_table(&table_info);
  144. if (ACPI_FAILURE(status)) {
  145. if (status == AE_ALREADY_EXISTS) {
  146. /* Table already exists, no error */
  147. status = AE_OK;
  148. }
  149. /* Free table allocated by acpi_tb_get_table_body */
  150. acpi_tb_delete_single_table(&table_info);
  151. return_ACPI_STATUS(status);
  152. }
  153. /* Convert the table to common format if necessary */
  154. switch (table_info.type) {
  155. case ACPI_TABLE_ID_FADT:
  156. status = acpi_tb_convert_table_fadt();
  157. break;
  158. case ACPI_TABLE_ID_FACS:
  159. status = acpi_tb_build_common_facs(&table_info);
  160. break;
  161. default:
  162. /* Load table into namespace if it contains executable AML */
  163. status =
  164. acpi_ns_load_table(table_info.installed_desc,
  165. acpi_gbl_root_node);
  166. break;
  167. }
  168. if (ACPI_FAILURE(status)) {
  169. /* Uninstall table and free the buffer */
  170. (void)acpi_tb_uninstall_table(table_info.installed_desc);
  171. }
  172. return_ACPI_STATUS(status);
  173. }
  174. ACPI_EXPORT_SYMBOL(acpi_load_table)
  175. /*******************************************************************************
  176. *
  177. * FUNCTION: acpi_unload_table
  178. *
  179. * PARAMETERS: table_type - Type of table to be unloaded
  180. *
  181. * RETURN: Status
  182. *
  183. * DESCRIPTION: This routine is used to force the unload of a table
  184. *
  185. ******************************************************************************/
  186. acpi_status acpi_unload_table(acpi_table_type table_type)
  187. {
  188. struct acpi_table_desc *table_desc;
  189. ACPI_FUNCTION_TRACE(acpi_unload_table);
  190. /* Parameter validation */
  191. if (table_type > ACPI_TABLE_ID_MAX) {
  192. return_ACPI_STATUS(AE_BAD_PARAMETER);
  193. }
  194. /* Find all tables of the requested type */
  195. table_desc = acpi_gbl_table_lists[table_type].next;
  196. if (!table_desc) {
  197. return_ACPI_STATUS(AE_NOT_EXIST);
  198. }
  199. while (table_desc) {
  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. table_desc = table_desc->next;
  208. }
  209. /* Delete (or unmap) all tables of this type */
  210. acpi_tb_delete_tables_by_type(table_type);
  211. return_ACPI_STATUS(AE_OK);
  212. }
  213. ACPI_EXPORT_SYMBOL(acpi_unload_table)
  214. /*******************************************************************************
  215. *
  216. * FUNCTION: acpi_get_table_header
  217. *
  218. * PARAMETERS: table_type - one of the defined table types
  219. * Instance - the non zero instance of the table, allows
  220. * support for multiple tables of the same type
  221. * see acpi_gbl_acpi_table_flag
  222. * out_table_header - pointer to the struct acpi_table_header if successful
  223. *
  224. * DESCRIPTION: This function is called to get an ACPI table header. The caller
  225. * supplies an pointer to a data area sufficient to contain an ACPI
  226. * struct acpi_table_header structure.
  227. *
  228. * The header contains a length field that can be used to determine
  229. * the size of the buffer needed to contain the entire table. This
  230. * function is not valid for the RSD PTR table since it does not
  231. * have a standard header and is fixed length.
  232. *
  233. ******************************************************************************/
  234. acpi_status
  235. acpi_get_table_header(acpi_table_type table_type,
  236. u32 instance, struct acpi_table_header *out_table_header)
  237. {
  238. struct acpi_table_header *tbl_ptr;
  239. acpi_status status;
  240. ACPI_FUNCTION_TRACE(acpi_get_table_header);
  241. if ((instance == 0) ||
  242. (table_type == ACPI_TABLE_ID_RSDP) || (!out_table_header)) {
  243. return_ACPI_STATUS(AE_BAD_PARAMETER);
  244. }
  245. /* Check the table type and instance */
  246. if ((table_type > ACPI_TABLE_ID_MAX) ||
  247. (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
  248. instance > 1)) {
  249. return_ACPI_STATUS(AE_BAD_PARAMETER);
  250. }
  251. /* Get a pointer to the entire table */
  252. status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
  253. if (ACPI_FAILURE(status)) {
  254. return_ACPI_STATUS(status);
  255. }
  256. /* The function will return a NULL pointer if the table is not loaded */
  257. if (tbl_ptr == NULL) {
  258. return_ACPI_STATUS(AE_NOT_EXIST);
  259. }
  260. /* Copy the header to the caller's buffer */
  261. ACPI_MEMCPY(ACPI_CAST_PTR(void, out_table_header),
  262. ACPI_CAST_PTR(void, tbl_ptr),
  263. sizeof(struct acpi_table_header));
  264. return_ACPI_STATUS(status);
  265. }
  266. ACPI_EXPORT_SYMBOL(acpi_get_table_header)
  267. #endif /* ACPI_FUTURE_USAGE */
  268. /*******************************************************************************
  269. *
  270. * FUNCTION: acpi_get_table
  271. *
  272. * PARAMETERS: table_type - one of the defined table types
  273. * Instance - the non zero instance of the table, allows
  274. * support for multiple tables of the same type
  275. * see acpi_gbl_acpi_table_flag
  276. * ret_buffer - pointer to a structure containing a buffer to
  277. * receive the table
  278. *
  279. * RETURN: Status
  280. *
  281. * DESCRIPTION: This function is called to get an ACPI table. The caller
  282. * supplies an out_buffer large enough to contain the entire ACPI
  283. * table. The caller should call the acpi_get_table_header function
  284. * first to determine the buffer size needed. Upon completion
  285. * the out_buffer->Length field will indicate the number of bytes
  286. * copied into the out_buffer->buf_ptr buffer. This table will be
  287. * a complete table including the header.
  288. *
  289. ******************************************************************************/
  290. acpi_status
  291. acpi_get_table(acpi_table_type table_type,
  292. u32 instance, struct acpi_buffer *ret_buffer)
  293. {
  294. struct acpi_table_header *tbl_ptr;
  295. acpi_status status;
  296. acpi_size table_length;
  297. ACPI_FUNCTION_TRACE(acpi_get_table);
  298. /* Parameter validation */
  299. if (instance == 0) {
  300. return_ACPI_STATUS(AE_BAD_PARAMETER);
  301. }
  302. status = acpi_ut_validate_buffer(ret_buffer);
  303. if (ACPI_FAILURE(status)) {
  304. return_ACPI_STATUS(status);
  305. }
  306. /* Check the table type and instance */
  307. if ((table_type > ACPI_TABLE_ID_MAX) ||
  308. (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
  309. instance > 1)) {
  310. return_ACPI_STATUS(AE_BAD_PARAMETER);
  311. }
  312. /* Get a pointer to the entire table */
  313. status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
  314. if (ACPI_FAILURE(status)) {
  315. return_ACPI_STATUS(status);
  316. }
  317. /*
  318. * acpi_tb_get_table_ptr will return a NULL pointer if the
  319. * table is not loaded.
  320. */
  321. if (tbl_ptr == NULL) {
  322. return_ACPI_STATUS(AE_NOT_EXIST);
  323. }
  324. /* Get the table length */
  325. if (table_type == ACPI_TABLE_ID_RSDP) {
  326. /* RSD PTR is the only "table" without a header */
  327. table_length = sizeof(struct rsdp_descriptor);
  328. } else {
  329. table_length = (acpi_size) tbl_ptr->length;
  330. }
  331. /* Validate/Allocate/Clear caller buffer */
  332. status = acpi_ut_initialize_buffer(ret_buffer, table_length);
  333. if (ACPI_FAILURE(status)) {
  334. return_ACPI_STATUS(status);
  335. }
  336. /* Copy the table to the buffer */
  337. ACPI_MEMCPY(ACPI_CAST_PTR(void, ret_buffer->pointer),
  338. ACPI_CAST_PTR(void, tbl_ptr), table_length);
  339. return_ACPI_STATUS(AE_OK);
  340. }
  341. ACPI_EXPORT_SYMBOL(acpi_get_table)