tbxface.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /******************************************************************************
  2. *
  3. * Module Name: tbxface - Public interfaces to the ACPI subsystem
  4. * ACPI table oriented interfaces
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2005, 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 <linux/module.h>
  44. #include <acpi/acpi.h>
  45. #include <acpi/acnamesp.h>
  46. #include <acpi/actables.h>
  47. #define _COMPONENT ACPI_TABLES
  48. ACPI_MODULE_NAME("tbxface")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_load_tables
  52. *
  53. * PARAMETERS: None
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: This function is called to load the ACPI tables from the
  58. * provided RSDT
  59. *
  60. ******************************************************************************/
  61. acpi_status acpi_load_tables(void)
  62. {
  63. struct acpi_pointer rsdp_address;
  64. acpi_status status;
  65. ACPI_FUNCTION_TRACE("acpi_load_tables");
  66. /* Get the RSDP */
  67. status = acpi_os_get_root_pointer(ACPI_LOGICAL_ADDRESSING,
  68. &rsdp_address);
  69. if (ACPI_FAILURE(status)) {
  70. ACPI_REPORT_ERROR(("acpi_load_tables: Could not get RSDP, %s\n",
  71. acpi_format_exception(status)));
  72. goto error_exit;
  73. }
  74. /* Map and validate the RSDP */
  75. acpi_gbl_table_flags = rsdp_address.pointer_type;
  76. status = acpi_tb_verify_rsdp(&rsdp_address);
  77. if (ACPI_FAILURE(status)) {
  78. ACPI_REPORT_ERROR(("acpi_load_tables: RSDP Failed validation: %s\n", acpi_format_exception(status)));
  79. goto error_exit;
  80. }
  81. /* Get the RSDT via the RSDP */
  82. status = acpi_tb_get_table_rsdt();
  83. if (ACPI_FAILURE(status)) {
  84. ACPI_REPORT_ERROR(("acpi_load_tables: Could not load RSDT: %s\n", acpi_format_exception(status)));
  85. goto error_exit;
  86. }
  87. /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */
  88. status = acpi_tb_get_required_tables();
  89. if (ACPI_FAILURE(status)) {
  90. ACPI_REPORT_ERROR(("acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n", acpi_format_exception(status)));
  91. goto error_exit;
  92. }
  93. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
  94. /* Load the namespace from the tables */
  95. status = acpi_ns_load_namespace();
  96. if (ACPI_FAILURE(status)) {
  97. ACPI_REPORT_ERROR(("acpi_load_tables: Could not load namespace: %s\n", acpi_format_exception(status)));
  98. goto error_exit;
  99. }
  100. return_ACPI_STATUS(AE_OK);
  101. error_exit:
  102. ACPI_REPORT_ERROR(("acpi_load_tables: Could not load tables: %s\n",
  103. acpi_format_exception(status)));
  104. return_ACPI_STATUS(status);
  105. }
  106. #ifdef ACPI_FUTURE_USAGE
  107. /*******************************************************************************
  108. *
  109. * FUNCTION: acpi_load_table
  110. *
  111. * PARAMETERS: table_ptr - pointer to a buffer containing the entire
  112. * table to be loaded
  113. *
  114. * RETURN: Status
  115. *
  116. * DESCRIPTION: This function is called to load a table from the caller's
  117. * buffer. The buffer must contain an entire ACPI Table including
  118. * a valid header. The header fields will be verified, and if it
  119. * is determined that the table is invalid, the call will fail.
  120. *
  121. ******************************************************************************/
  122. acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
  123. {
  124. acpi_status status;
  125. struct acpi_table_desc table_info;
  126. struct acpi_pointer address;
  127. ACPI_FUNCTION_TRACE("acpi_load_table");
  128. if (!table_ptr) {
  129. return_ACPI_STATUS(AE_BAD_PARAMETER);
  130. }
  131. /* Copy the table to a local buffer */
  132. address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
  133. address.pointer.logical = table_ptr;
  134. status = acpi_tb_get_table_body(&address, table_ptr, &table_info);
  135. if (ACPI_FAILURE(status)) {
  136. return_ACPI_STATUS(status);
  137. }
  138. /* Check signature for a valid table type */
  139. status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL);
  140. if (ACPI_FAILURE(status)) {
  141. return_ACPI_STATUS(status);
  142. }
  143. /* Install the new table into the local data structures */
  144. status = acpi_tb_install_table(&table_info);
  145. if (ACPI_FAILURE(status)) {
  146. if (status == AE_ALREADY_EXISTS) {
  147. /* Table already exists, no error */
  148. status = AE_OK;
  149. }
  150. /* Free table allocated by acpi_tb_get_table_body */
  151. acpi_tb_delete_single_table(&table_info);
  152. return_ACPI_STATUS(status);
  153. }
  154. /* Convert the table to common format if necessary */
  155. switch (table_info.type) {
  156. case ACPI_TABLE_FADT:
  157. status = acpi_tb_convert_table_fadt();
  158. break;
  159. case ACPI_TABLE_FACS:
  160. status = acpi_tb_build_common_facs(&table_info);
  161. break;
  162. default:
  163. /* Load table into namespace if it contains executable AML */
  164. status =
  165. acpi_ns_load_table(table_info.installed_desc,
  166. acpi_gbl_root_node);
  167. break;
  168. }
  169. if (ACPI_FAILURE(status)) {
  170. /* Uninstall table and free the buffer */
  171. (void)acpi_tb_uninstall_table(table_info.installed_desc);
  172. }
  173. return_ACPI_STATUS(status);
  174. }
  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_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. while (table_desc) {
  197. /*
  198. * Delete all namespace entries owned by this table. Note that these
  199. * entries can appear anywhere in the namespace by virtue of the AML
  200. * "Scope" operator. Thus, we need to track ownership by an ID, not
  201. * simply a position within the hierarchy
  202. */
  203. acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
  204. acpi_ut_release_owner_id(&table_desc->owner_id);
  205. table_desc = table_desc->next;
  206. }
  207. /* Delete (or unmap) all tables of this type */
  208. acpi_tb_delete_tables_by_type(table_type);
  209. return_ACPI_STATUS(AE_OK);
  210. }
  211. /*******************************************************************************
  212. *
  213. * FUNCTION: acpi_get_table_header
  214. *
  215. * PARAMETERS: table_type - one of the defined table types
  216. * Instance - the non zero instance of the table, allows
  217. * support for multiple tables of the same type
  218. * see acpi_gbl_acpi_table_flag
  219. * out_table_header - pointer to the struct acpi_table_header if successful
  220. *
  221. * DESCRIPTION: This function is called to get an ACPI table header. The caller
  222. * supplies an pointer to a data area sufficient to contain an ACPI
  223. * struct acpi_table_header structure.
  224. *
  225. * The header contains a length field that can be used to determine
  226. * the size of the buffer needed to contain the entire table. This
  227. * function is not valid for the RSD PTR table since it does not
  228. * have a standard header and is fixed length.
  229. *
  230. ******************************************************************************/
  231. acpi_status
  232. acpi_get_table_header(acpi_table_type table_type,
  233. u32 instance, struct acpi_table_header *out_table_header)
  234. {
  235. struct acpi_table_header *tbl_ptr;
  236. acpi_status status;
  237. ACPI_FUNCTION_TRACE("acpi_get_table_header");
  238. if ((instance == 0) ||
  239. (table_type == ACPI_TABLE_RSDP) || (!out_table_header)) {
  240. return_ACPI_STATUS(AE_BAD_PARAMETER);
  241. }
  242. /* Check the table type and instance */
  243. if ((table_type > ACPI_TABLE_MAX) ||
  244. (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
  245. instance > 1)) {
  246. return_ACPI_STATUS(AE_BAD_PARAMETER);
  247. }
  248. /* Get a pointer to the entire table */
  249. status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
  250. if (ACPI_FAILURE(status)) {
  251. return_ACPI_STATUS(status);
  252. }
  253. /* The function will return a NULL pointer if the table is not loaded */
  254. if (tbl_ptr == NULL) {
  255. return_ACPI_STATUS(AE_NOT_EXIST);
  256. }
  257. /* Copy the header to the caller's buffer */
  258. ACPI_MEMCPY((void *)out_table_header, (void *)tbl_ptr,
  259. sizeof(struct acpi_table_header));
  260. return_ACPI_STATUS(status);
  261. }
  262. #endif /* ACPI_FUTURE_USAGE */
  263. /*******************************************************************************
  264. *
  265. * FUNCTION: acpi_get_table
  266. *
  267. * PARAMETERS: table_type - one of the defined table types
  268. * Instance - the non zero instance of the table, allows
  269. * support for multiple tables of the same type
  270. * see acpi_gbl_acpi_table_flag
  271. * ret_buffer - pointer to a structure containing a buffer to
  272. * receive the table
  273. *
  274. * RETURN: Status
  275. *
  276. * DESCRIPTION: This function is called to get an ACPI table. The caller
  277. * supplies an out_buffer large enough to contain the entire ACPI
  278. * table. The caller should call the acpi_get_table_header function
  279. * first to determine the buffer size needed. Upon completion
  280. * the out_buffer->Length field will indicate the number of bytes
  281. * copied into the out_buffer->buf_ptr buffer. This table will be
  282. * a complete table including the header.
  283. *
  284. ******************************************************************************/
  285. acpi_status
  286. acpi_get_table(acpi_table_type table_type,
  287. u32 instance, struct acpi_buffer *ret_buffer)
  288. {
  289. struct acpi_table_header *tbl_ptr;
  290. acpi_status status;
  291. acpi_size table_length;
  292. ACPI_FUNCTION_TRACE("acpi_get_table");
  293. /* Parameter validation */
  294. if (instance == 0) {
  295. return_ACPI_STATUS(AE_BAD_PARAMETER);
  296. }
  297. status = acpi_ut_validate_buffer(ret_buffer);
  298. if (ACPI_FAILURE(status)) {
  299. return_ACPI_STATUS(status);
  300. }
  301. /* Check the table type and instance */
  302. if ((table_type > ACPI_TABLE_MAX) ||
  303. (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
  304. instance > 1)) {
  305. return_ACPI_STATUS(AE_BAD_PARAMETER);
  306. }
  307. /* Get a pointer to the entire table */
  308. status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
  309. if (ACPI_FAILURE(status)) {
  310. return_ACPI_STATUS(status);
  311. }
  312. /*
  313. * acpi_tb_get_table_ptr will return a NULL pointer if the
  314. * table is not loaded.
  315. */
  316. if (tbl_ptr == NULL) {
  317. return_ACPI_STATUS(AE_NOT_EXIST);
  318. }
  319. /* Get the table length */
  320. if (table_type == ACPI_TABLE_RSDP) {
  321. /* RSD PTR is the only "table" without a header */
  322. table_length = sizeof(struct rsdp_descriptor);
  323. } else {
  324. table_length = (acpi_size) tbl_ptr->length;
  325. }
  326. /* Validate/Allocate/Clear caller buffer */
  327. status = acpi_ut_initialize_buffer(ret_buffer, table_length);
  328. if (ACPI_FAILURE(status)) {
  329. return_ACPI_STATUS(status);
  330. }
  331. /* Copy the table to the buffer */
  332. ACPI_MEMCPY((void *)ret_buffer->pointer, (void *)tbl_ptr, table_length);
  333. return_ACPI_STATUS(AE_OK);
  334. }
  335. EXPORT_SYMBOL(acpi_get_table);