tbxface.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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 <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_EXCEPTION((AE_INFO, status, "Could not get the RSDP"));
  71. goto error_exit;
  72. }
  73. /* Map and validate the RSDP */
  74. acpi_gbl_table_flags = rsdp_address.pointer_type;
  75. status = acpi_tb_verify_rsdp(&rsdp_address);
  76. if (ACPI_FAILURE(status)) {
  77. ACPI_EXCEPTION((AE_INFO, status, "During RSDP validation"));
  78. goto error_exit;
  79. }
  80. /* Get the RSDT via the RSDP */
  81. status = acpi_tb_get_table_rsdt();
  82. if (ACPI_FAILURE(status)) {
  83. ACPI_EXCEPTION((AE_INFO, status, "Could not load RSDT"));
  84. goto error_exit;
  85. }
  86. /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */
  87. status = acpi_tb_get_required_tables();
  88. if (ACPI_FAILURE(status)) {
  89. ACPI_EXCEPTION((AE_INFO, status,
  90. "Could not get all required tables (DSDT/FADT/FACS)"));
  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_EXCEPTION((AE_INFO, status, "Could not load namespace"));
  98. goto error_exit;
  99. }
  100. return_ACPI_STATUS(AE_OK);
  101. error_exit:
  102. ACPI_EXCEPTION((AE_INFO, status, "Could not load tables"));
  103. return_ACPI_STATUS(status);
  104. }
  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_FADT:
  156. status = acpi_tb_convert_table_fadt();
  157. break;
  158. case ACPI_TABLE_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. /*******************************************************************************
  175. *
  176. * FUNCTION: acpi_unload_table
  177. *
  178. * PARAMETERS: table_type - Type of table to be unloaded
  179. *
  180. * RETURN: Status
  181. *
  182. * DESCRIPTION: This routine is used to force the unload of a table
  183. *
  184. ******************************************************************************/
  185. acpi_status acpi_unload_table(acpi_table_type table_type)
  186. {
  187. struct acpi_table_desc *table_desc;
  188. ACPI_FUNCTION_TRACE("acpi_unload_table");
  189. /* Parameter validation */
  190. if (table_type > ACPI_TABLE_MAX) {
  191. return_ACPI_STATUS(AE_BAD_PARAMETER);
  192. }
  193. /* Find all tables of the requested type */
  194. table_desc = acpi_gbl_table_lists[table_type].next;
  195. while (table_desc) {
  196. /*
  197. * Delete all namespace entries owned by this table. Note that these
  198. * entries can appear anywhere in the namespace by virtue of the AML
  199. * "Scope" operator. Thus, we need to track ownership by an ID, not
  200. * simply a position within the hierarchy
  201. */
  202. acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
  203. acpi_ut_release_owner_id(&table_desc->owner_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(acpi_table_type table_type,
  232. u32 instance, 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) || (!out_table_header)) {
  239. return_ACPI_STATUS(AE_BAD_PARAMETER);
  240. }
  241. /* Check the table type and instance */
  242. if ((table_type > ACPI_TABLE_MAX) ||
  243. (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
  244. instance > 1)) {
  245. return_ACPI_STATUS(AE_BAD_PARAMETER);
  246. }
  247. /* Get a pointer to the entire table */
  248. status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
  249. if (ACPI_FAILURE(status)) {
  250. return_ACPI_STATUS(status);
  251. }
  252. /* The function will return a NULL pointer if the table is not loaded */
  253. if (tbl_ptr == NULL) {
  254. return_ACPI_STATUS(AE_NOT_EXIST);
  255. }
  256. /* Copy the header to the caller's buffer */
  257. ACPI_MEMCPY((void *)out_table_header, (void *)tbl_ptr,
  258. sizeof(struct acpi_table_header));
  259. return_ACPI_STATUS(status);
  260. }
  261. #endif /* ACPI_FUTURE_USAGE */
  262. /*******************************************************************************
  263. *
  264. * FUNCTION: acpi_get_table
  265. *
  266. * PARAMETERS: table_type - one of the defined table types
  267. * Instance - the non zero instance of the table, allows
  268. * support for multiple tables of the same type
  269. * see acpi_gbl_acpi_table_flag
  270. * ret_buffer - pointer to a structure containing a buffer to
  271. * receive the table
  272. *
  273. * RETURN: Status
  274. *
  275. * DESCRIPTION: This function is called to get an ACPI table. The caller
  276. * supplies an out_buffer large enough to contain the entire ACPI
  277. * table. The caller should call the acpi_get_table_header function
  278. * first to determine the buffer size needed. Upon completion
  279. * the out_buffer->Length field will indicate the number of bytes
  280. * copied into the out_buffer->buf_ptr buffer. This table will be
  281. * a complete table including the header.
  282. *
  283. ******************************************************************************/
  284. acpi_status
  285. acpi_get_table(acpi_table_type table_type,
  286. u32 instance, struct acpi_buffer *ret_buffer)
  287. {
  288. struct acpi_table_header *tbl_ptr;
  289. acpi_status status;
  290. acpi_size table_length;
  291. ACPI_FUNCTION_TRACE("acpi_get_table");
  292. /* Parameter validation */
  293. if (instance == 0) {
  294. return_ACPI_STATUS(AE_BAD_PARAMETER);
  295. }
  296. status = acpi_ut_validate_buffer(ret_buffer);
  297. if (ACPI_FAILURE(status)) {
  298. return_ACPI_STATUS(status);
  299. }
  300. /* Check the table type and instance */
  301. if ((table_type > ACPI_TABLE_MAX) ||
  302. (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
  303. instance > 1)) {
  304. return_ACPI_STATUS(AE_BAD_PARAMETER);
  305. }
  306. /* Get a pointer to the entire table */
  307. status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
  308. if (ACPI_FAILURE(status)) {
  309. return_ACPI_STATUS(status);
  310. }
  311. /*
  312. * acpi_tb_get_table_ptr will return a NULL pointer if the
  313. * table is not loaded.
  314. */
  315. if (tbl_ptr == NULL) {
  316. return_ACPI_STATUS(AE_NOT_EXIST);
  317. }
  318. /* Get the table length */
  319. if (table_type == ACPI_TABLE_RSDP) {
  320. /* RSD PTR is the only "table" without a header */
  321. table_length = sizeof(struct rsdp_descriptor);
  322. } else {
  323. table_length = (acpi_size) tbl_ptr->length;
  324. }
  325. /* Validate/Allocate/Clear caller buffer */
  326. status = acpi_ut_initialize_buffer(ret_buffer, table_length);
  327. if (ACPI_FAILURE(status)) {
  328. return_ACPI_STATUS(status);
  329. }
  330. /* Copy the table to the buffer */
  331. ACPI_MEMCPY((void *)ret_buffer->pointer, (void *)tbl_ptr, table_length);
  332. return_ACPI_STATUS(AE_OK);
  333. }
  334. EXPORT_SYMBOL(acpi_get_table);