tbxface.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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
  62. acpi_load_tables (
  63. void)
  64. {
  65. struct acpi_pointer rsdp_address;
  66. acpi_status status;
  67. ACPI_FUNCTION_TRACE ("acpi_load_tables");
  68. /* Get the RSDP */
  69. status = acpi_os_get_root_pointer (ACPI_LOGICAL_ADDRESSING,
  70. &rsdp_address);
  71. if (ACPI_FAILURE (status)) {
  72. ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n",
  73. acpi_format_exception (status)));
  74. goto error_exit;
  75. }
  76. /* Map and validate the RSDP */
  77. acpi_gbl_table_flags = rsdp_address.pointer_type;
  78. status = acpi_tb_verify_rsdp (&rsdp_address);
  79. if (ACPI_FAILURE (status)) {
  80. ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n",
  81. acpi_format_exception (status)));
  82. goto error_exit;
  83. }
  84. /* Get the RSDT via the RSDP */
  85. status = acpi_tb_get_table_rsdt ();
  86. if (ACPI_FAILURE (status)) {
  87. ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n",
  88. acpi_format_exception (status)));
  89. goto error_exit;
  90. }
  91. /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */
  92. status = acpi_tb_get_required_tables ();
  93. if (ACPI_FAILURE (status)) {
  94. ACPI_REPORT_ERROR ((
  95. "acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n",
  96. acpi_format_exception (status)));
  97. goto error_exit;
  98. }
  99. ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
  100. /* Load the namespace from the tables */
  101. status = acpi_ns_load_namespace ();
  102. if (ACPI_FAILURE (status)) {
  103. ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n",
  104. acpi_format_exception (status)));
  105. goto error_exit;
  106. }
  107. return_ACPI_STATUS (AE_OK);
  108. error_exit:
  109. ACPI_REPORT_ERROR (("acpi_load_tables: Could not load tables: %s\n",
  110. acpi_format_exception (status)));
  111. return_ACPI_STATUS (status);
  112. }
  113. #ifdef ACPI_FUTURE_USAGE
  114. /*******************************************************************************
  115. *
  116. * FUNCTION: acpi_load_table
  117. *
  118. * PARAMETERS: table_ptr - pointer to a buffer containing the entire
  119. * table to be loaded
  120. *
  121. * RETURN: Status
  122. *
  123. * DESCRIPTION: This function is called to load a table from the caller's
  124. * buffer. The buffer must contain an entire ACPI Table including
  125. * a valid header. The header fields will be verified, and if it
  126. * is determined that the table is invalid, the call will fail.
  127. *
  128. ******************************************************************************/
  129. acpi_status
  130. acpi_load_table (
  131. struct acpi_table_header *table_ptr)
  132. {
  133. acpi_status status;
  134. struct acpi_table_desc table_info;
  135. struct acpi_pointer address;
  136. ACPI_FUNCTION_TRACE ("acpi_load_table");
  137. if (!table_ptr) {
  138. return_ACPI_STATUS (AE_BAD_PARAMETER);
  139. }
  140. /* Copy the table to a local buffer */
  141. address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
  142. address.pointer.logical = table_ptr;
  143. status = acpi_tb_get_table_body (&address, table_ptr, &table_info);
  144. if (ACPI_FAILURE (status)) {
  145. return_ACPI_STATUS (status);
  146. }
  147. /* Install the new table into the local data structures */
  148. status = acpi_tb_install_table (&table_info);
  149. if (ACPI_FAILURE (status)) {
  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 = acpi_ns_load_table (table_info.installed_desc, 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. /*******************************************************************************
  174. *
  175. * FUNCTION: acpi_unload_table
  176. *
  177. * PARAMETERS: table_type - Type of table to be unloaded
  178. *
  179. * RETURN: Status
  180. *
  181. * DESCRIPTION: This routine is used to force the unload of a table
  182. *
  183. ******************************************************************************/
  184. acpi_status
  185. acpi_unload_table (
  186. 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->table_id);
  204. table_desc = table_desc->next;
  205. }
  206. /* Delete (or unmap) all tables of this type */
  207. acpi_tb_delete_tables_by_type (table_type);
  208. return_ACPI_STATUS (AE_OK);
  209. }
  210. /*******************************************************************************
  211. *
  212. * FUNCTION: acpi_get_table_header
  213. *
  214. * PARAMETERS: table_type - one of the defined table types
  215. * Instance - the non zero instance of the table, allows
  216. * support for multiple tables of the same type
  217. * see acpi_gbl_acpi_table_flag
  218. * out_table_header - pointer to the struct acpi_table_header if successful
  219. *
  220. * DESCRIPTION: This function is called to get an ACPI table header. The caller
  221. * supplies an pointer to a data area sufficient to contain an ACPI
  222. * struct acpi_table_header structure.
  223. *
  224. * The header contains a length field that can be used to determine
  225. * the size of the buffer needed to contain the entire table. This
  226. * function is not valid for the RSD PTR table since it does not
  227. * have a standard header and is fixed length.
  228. *
  229. ******************************************************************************/
  230. acpi_status
  231. acpi_get_table_header (
  232. acpi_table_type table_type,
  233. u32 instance,
  234. struct acpi_table_header *out_table_header)
  235. {
  236. struct acpi_table_header *tbl_ptr;
  237. acpi_status status;
  238. ACPI_FUNCTION_TRACE ("acpi_get_table_header");
  239. if ((instance == 0) ||
  240. (table_type == ACPI_TABLE_RSDP) ||
  241. (!out_table_header)) {
  242. return_ACPI_STATUS (AE_BAD_PARAMETER);
  243. }
  244. /* Check the table type and instance */
  245. if ((table_type > ACPI_TABLE_MAX) ||
  246. (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags) &&
  247. instance > 1)) {
  248. return_ACPI_STATUS (AE_BAD_PARAMETER);
  249. }
  250. /* Get a pointer to the entire table */
  251. status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
  252. if (ACPI_FAILURE (status)) {
  253. return_ACPI_STATUS (status);
  254. }
  255. /* The function will return a NULL pointer if the table is not loaded */
  256. if (tbl_ptr == NULL) {
  257. return_ACPI_STATUS (AE_NOT_EXIST);
  258. }
  259. /* Copy the header to the caller's buffer */
  260. ACPI_MEMCPY ((void *) out_table_header, (void *) tbl_ptr,
  261. sizeof (struct acpi_table_header));
  262. return_ACPI_STATUS (status);
  263. }
  264. #endif /* ACPI_FUTURE_USAGE */
  265. /*******************************************************************************
  266. *
  267. * FUNCTION: acpi_get_table
  268. *
  269. * PARAMETERS: table_type - one of the defined table types
  270. * Instance - the non zero instance of the table, allows
  271. * support for multiple tables of the same type
  272. * see acpi_gbl_acpi_table_flag
  273. * ret_buffer - pointer to a structure containing a buffer to
  274. * receive the table
  275. *
  276. * RETURN: Status
  277. *
  278. * DESCRIPTION: This function is called to get an ACPI table. The caller
  279. * supplies an out_buffer large enough to contain the entire ACPI
  280. * table. The caller should call the acpi_get_table_header function
  281. * first to determine the buffer size needed. Upon completion
  282. * the out_buffer->Length field will indicate the number of bytes
  283. * copied into the out_buffer->buf_ptr buffer. This table will be
  284. * a complete table including the header.
  285. *
  286. ******************************************************************************/
  287. acpi_status
  288. acpi_get_table (
  289. acpi_table_type table_type,
  290. u32 instance,
  291. struct acpi_buffer *ret_buffer)
  292. {
  293. struct acpi_table_header *tbl_ptr;
  294. acpi_status status;
  295. acpi_size table_length;
  296. ACPI_FUNCTION_TRACE ("acpi_get_table");
  297. /* Parameter validation */
  298. if (instance == 0) {
  299. return_ACPI_STATUS (AE_BAD_PARAMETER);
  300. }
  301. status = acpi_ut_validate_buffer (ret_buffer);
  302. if (ACPI_FAILURE (status)) {
  303. return_ACPI_STATUS (status);
  304. }
  305. /* Check the table type and instance */
  306. if ((table_type > ACPI_TABLE_MAX) ||
  307. (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags) &&
  308. instance > 1)) {
  309. return_ACPI_STATUS (AE_BAD_PARAMETER);
  310. }
  311. /* Get a pointer to the entire table */
  312. status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
  313. if (ACPI_FAILURE (status)) {
  314. return_ACPI_STATUS (status);
  315. }
  316. /*
  317. * acpi_tb_get_table_ptr will return a NULL pointer if the
  318. * table is not loaded.
  319. */
  320. if (tbl_ptr == NULL) {
  321. return_ACPI_STATUS (AE_NOT_EXIST);
  322. }
  323. /* Get the table length */
  324. if (table_type == ACPI_TABLE_RSDP) {
  325. /* RSD PTR is the only "table" without a header */
  326. table_length = sizeof (struct rsdp_descriptor);
  327. }
  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 ((void *) ret_buffer->pointer, (void *) tbl_ptr, table_length);
  338. return_ACPI_STATUS (AE_OK);
  339. }
  340. EXPORT_SYMBOL(acpi_get_table);