tbxface.c 13 KB

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