tbget.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. /******************************************************************************
  2. *
  3. * Module Name: tbget - ACPI Table get* routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/actables.h>
  44. #define _COMPONENT ACPI_TABLES
  45. ACPI_MODULE_NAME ("tbget")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_tb_get_table
  49. *
  50. * PARAMETERS: Address - Address of table to retrieve. Can be
  51. * Logical or Physical
  52. * table_info - Where table info is returned
  53. *
  54. * RETURN: None
  55. *
  56. * DESCRIPTION: Get entire table of unknown size.
  57. *
  58. ******************************************************************************/
  59. acpi_status
  60. acpi_tb_get_table (
  61. struct acpi_pointer *address,
  62. struct acpi_table_desc *table_info)
  63. {
  64. acpi_status status;
  65. struct acpi_table_header header;
  66. ACPI_FUNCTION_TRACE ("tb_get_table");
  67. /*
  68. * Get the header in order to get signature and table size
  69. */
  70. status = acpi_tb_get_table_header (address, &header);
  71. if (ACPI_FAILURE (status)) {
  72. return_ACPI_STATUS (status);
  73. }
  74. /* Get the entire table */
  75. status = acpi_tb_get_table_body (address, &header, table_info);
  76. if (ACPI_FAILURE (status)) {
  77. ACPI_REPORT_ERROR (("Could not get ACPI table (size %X), %s\n",
  78. header.length, acpi_format_exception (status)));
  79. return_ACPI_STATUS (status);
  80. }
  81. return_ACPI_STATUS (AE_OK);
  82. }
  83. /*******************************************************************************
  84. *
  85. * FUNCTION: acpi_tb_get_table_header
  86. *
  87. * PARAMETERS: Address - Address of table to retrieve. Can be
  88. * Logical or Physical
  89. * return_header - Where the table header is returned
  90. *
  91. * RETURN: Status
  92. *
  93. * DESCRIPTION: Get an ACPI table header. Works in both physical or virtual
  94. * addressing mode. Works with both physical or logical pointers.
  95. * Table is either copied or mapped, depending on the pointer
  96. * type and mode of the processor.
  97. *
  98. ******************************************************************************/
  99. acpi_status
  100. acpi_tb_get_table_header (
  101. struct acpi_pointer *address,
  102. struct acpi_table_header *return_header)
  103. {
  104. acpi_status status = AE_OK;
  105. struct acpi_table_header *header = NULL;
  106. ACPI_FUNCTION_TRACE ("tb_get_table_header");
  107. /*
  108. * Flags contains the current processor mode (Virtual or Physical addressing)
  109. * The pointer_type is either Logical or Physical
  110. */
  111. switch (address->pointer_type) {
  112. case ACPI_PHYSMODE_PHYSPTR:
  113. case ACPI_LOGMODE_LOGPTR:
  114. /* Pointer matches processor mode, copy the header */
  115. ACPI_MEMCPY (return_header, address->pointer.logical, sizeof (struct acpi_table_header));
  116. break;
  117. case ACPI_LOGMODE_PHYSPTR:
  118. /* Create a logical address for the physical pointer*/
  119. status = acpi_os_map_memory (address->pointer.physical, sizeof (struct acpi_table_header),
  120. (void *) &header);
  121. if (ACPI_FAILURE (status)) {
  122. ACPI_REPORT_ERROR (("Could not map memory at %8.8X%8.8X for length %X\n",
  123. ACPI_FORMAT_UINT64 (address->pointer.physical),
  124. sizeof (struct acpi_table_header)));
  125. return_ACPI_STATUS (status);
  126. }
  127. /* Copy header and delete mapping */
  128. ACPI_MEMCPY (return_header, header, sizeof (struct acpi_table_header));
  129. acpi_os_unmap_memory (header, sizeof (struct acpi_table_header));
  130. break;
  131. default:
  132. ACPI_REPORT_ERROR (("Invalid address flags %X\n",
  133. address->pointer_type));
  134. return_ACPI_STATUS (AE_BAD_PARAMETER);
  135. }
  136. ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n",
  137. return_header->signature));
  138. return_ACPI_STATUS (AE_OK);
  139. }
  140. /*******************************************************************************
  141. *
  142. * FUNCTION: acpi_tb_get_table_body
  143. *
  144. * PARAMETERS: Address - Address of table to retrieve. Can be
  145. * Logical or Physical
  146. * Header - Header of the table to retrieve
  147. * table_info - Where the table info is returned
  148. *
  149. * RETURN: Status
  150. *
  151. * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
  152. * replace the table with a newer version (table override.)
  153. * Works in both physical or virtual
  154. * addressing mode. Works with both physical or logical pointers.
  155. * Table is either copied or mapped, depending on the pointer
  156. * type and mode of the processor.
  157. *
  158. ******************************************************************************/
  159. acpi_status
  160. acpi_tb_get_table_body (
  161. struct acpi_pointer *address,
  162. struct acpi_table_header *header,
  163. struct acpi_table_desc *table_info)
  164. {
  165. acpi_status status;
  166. ACPI_FUNCTION_TRACE ("tb_get_table_body");
  167. if (!table_info || !address) {
  168. return_ACPI_STATUS (AE_BAD_PARAMETER);
  169. }
  170. /*
  171. * Attempt table override.
  172. */
  173. status = acpi_tb_table_override (header, table_info);
  174. if (ACPI_SUCCESS (status)) {
  175. /* Table was overridden by the host OS */
  176. return_ACPI_STATUS (status);
  177. }
  178. /* No override, get the original table */
  179. status = acpi_tb_get_this_table (address, header, table_info);
  180. return_ACPI_STATUS (status);
  181. }
  182. /*******************************************************************************
  183. *
  184. * FUNCTION: acpi_tb_table_override
  185. *
  186. * PARAMETERS: Header - Pointer to table header
  187. * table_info - Return info if table is overridden
  188. *
  189. * RETURN: None
  190. *
  191. * DESCRIPTION: Attempts override of current table with a new one if provided
  192. * by the host OS.
  193. *
  194. ******************************************************************************/
  195. acpi_status
  196. acpi_tb_table_override (
  197. struct acpi_table_header *header,
  198. struct acpi_table_desc *table_info)
  199. {
  200. struct acpi_table_header *new_table;
  201. acpi_status status;
  202. struct acpi_pointer address;
  203. ACPI_FUNCTION_TRACE ("tb_table_override");
  204. /*
  205. * The OSL will examine the header and decide whether to override this
  206. * table. If it decides to override, a table will be returned in new_table,
  207. * which we will then copy.
  208. */
  209. status = acpi_os_table_override (header, &new_table);
  210. if (ACPI_FAILURE (status)) {
  211. /* Some severe error from the OSL, but we basically ignore it */
  212. ACPI_REPORT_ERROR (("Could not override ACPI table, %s\n",
  213. acpi_format_exception (status)));
  214. return_ACPI_STATUS (status);
  215. }
  216. if (!new_table) {
  217. /* No table override */
  218. return_ACPI_STATUS (AE_NO_ACPI_TABLES);
  219. }
  220. /*
  221. * We have a new table to override the old one. Get a copy of
  222. * the new one. We know that the new table has a logical pointer.
  223. */
  224. address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
  225. address.pointer.logical = new_table;
  226. status = acpi_tb_get_this_table (&address, new_table, table_info);
  227. if (ACPI_FAILURE (status)) {
  228. ACPI_REPORT_ERROR (("Could not copy override ACPI table, %s\n",
  229. acpi_format_exception (status)));
  230. return_ACPI_STATUS (status);
  231. }
  232. /* Copy the table info */
  233. ACPI_REPORT_INFO (("Table [%4.4s] replaced by host OS\n",
  234. table_info->pointer->signature));
  235. return_ACPI_STATUS (AE_OK);
  236. }
  237. /*******************************************************************************
  238. *
  239. * FUNCTION: acpi_tb_get_this_table
  240. *
  241. * PARAMETERS: Address - Address of table to retrieve. Can be
  242. * Logical or Physical
  243. * Header - Header of the table to retrieve
  244. * table_info - Where the table info is returned
  245. *
  246. * RETURN: Status
  247. *
  248. * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual
  249. * addressing mode. Works with both physical or logical pointers.
  250. * Table is either copied or mapped, depending on the pointer
  251. * type and mode of the processor.
  252. *
  253. ******************************************************************************/
  254. acpi_status
  255. acpi_tb_get_this_table (
  256. struct acpi_pointer *address,
  257. struct acpi_table_header *header,
  258. struct acpi_table_desc *table_info)
  259. {
  260. struct acpi_table_header *full_table = NULL;
  261. u8 allocation;
  262. acpi_status status = AE_OK;
  263. ACPI_FUNCTION_TRACE ("tb_get_this_table");
  264. /*
  265. * Flags contains the current processor mode (Virtual or Physical addressing)
  266. * The pointer_type is either Logical or Physical
  267. */
  268. switch (address->pointer_type) {
  269. case ACPI_PHYSMODE_PHYSPTR:
  270. case ACPI_LOGMODE_LOGPTR:
  271. /* Pointer matches processor mode, copy the table to a new buffer */
  272. full_table = ACPI_MEM_ALLOCATE (header->length);
  273. if (!full_table) {
  274. ACPI_REPORT_ERROR (("Could not allocate table memory for [%4.4s] length %X\n",
  275. header->signature, header->length));
  276. return_ACPI_STATUS (AE_NO_MEMORY);
  277. }
  278. /* Copy the entire table (including header) to the local buffer */
  279. ACPI_MEMCPY (full_table, address->pointer.logical, header->length);
  280. /* Save allocation type */
  281. allocation = ACPI_MEM_ALLOCATED;
  282. break;
  283. case ACPI_LOGMODE_PHYSPTR:
  284. /*
  285. * Just map the table's physical memory
  286. * into our address space.
  287. */
  288. status = acpi_os_map_memory (address->pointer.physical, (acpi_size) header->length,
  289. (void *) &full_table);
  290. if (ACPI_FAILURE (status)) {
  291. ACPI_REPORT_ERROR (("Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n",
  292. header->signature,
  293. ACPI_FORMAT_UINT64 (address->pointer.physical), header->length));
  294. return (status);
  295. }
  296. /* Save allocation type */
  297. allocation = ACPI_MEM_MAPPED;
  298. break;
  299. default:
  300. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid address flags %X\n",
  301. address->pointer_type));
  302. return_ACPI_STATUS (AE_BAD_PARAMETER);
  303. }
  304. /*
  305. * Validate checksum for _most_ tables,
  306. * even the ones whose signature we don't recognize
  307. */
  308. if (table_info->type != ACPI_TABLE_FACS) {
  309. status = acpi_tb_verify_table_checksum (full_table);
  310. #if (!ACPI_CHECKSUM_ABORT)
  311. if (ACPI_FAILURE (status)) {
  312. /* Ignore the error if configuration says so */
  313. status = AE_OK;
  314. }
  315. #endif
  316. }
  317. /* Return values */
  318. table_info->pointer = full_table;
  319. table_info->length = (acpi_size) header->length;
  320. table_info->allocation = allocation;
  321. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  322. "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
  323. full_table->signature,
  324. ACPI_FORMAT_UINT64 (address->pointer.physical), full_table));
  325. return_ACPI_STATUS (status);
  326. }
  327. /*******************************************************************************
  328. *
  329. * FUNCTION: acpi_tb_get_table_ptr
  330. *
  331. * PARAMETERS: table_type - one of the defined table types
  332. * Instance - Which table of this type
  333. * table_ptr_loc - pointer to location to place the pointer for
  334. * return
  335. *
  336. * RETURN: Status
  337. *
  338. * DESCRIPTION: This function is called to get the pointer to an ACPI table.
  339. *
  340. ******************************************************************************/
  341. acpi_status
  342. acpi_tb_get_table_ptr (
  343. acpi_table_type table_type,
  344. u32 instance,
  345. struct acpi_table_header **table_ptr_loc)
  346. {
  347. struct acpi_table_desc *table_desc;
  348. u32 i;
  349. ACPI_FUNCTION_TRACE ("tb_get_table_ptr");
  350. if (!acpi_gbl_DSDT) {
  351. return_ACPI_STATUS (AE_NO_ACPI_TABLES);
  352. }
  353. if (table_type > ACPI_TABLE_MAX) {
  354. return_ACPI_STATUS (AE_BAD_PARAMETER);
  355. }
  356. /*
  357. * For all table types (Single/Multiple), the first
  358. * instance is always in the list head.
  359. */
  360. if (instance == 1) {
  361. /* Get the first */
  362. *table_ptr_loc = NULL;
  363. if (acpi_gbl_table_lists[table_type].next) {
  364. *table_ptr_loc = acpi_gbl_table_lists[table_type].next->pointer;
  365. }
  366. return_ACPI_STATUS (AE_OK);
  367. }
  368. /*
  369. * Check for instance out of range
  370. */
  371. if (instance > acpi_gbl_table_lists[table_type].count) {
  372. return_ACPI_STATUS (AE_NOT_EXIST);
  373. }
  374. /* Walk the list to get the desired table
  375. * Since the if (Instance == 1) check above checked for the
  376. * first table, setting table_desc equal to the .Next member
  377. * is actually pointing to the second table. Therefore, we
  378. * need to walk from the 2nd table until we reach the Instance
  379. * that the user is looking for and return its table pointer.
  380. */
  381. table_desc = acpi_gbl_table_lists[table_type].next;
  382. for (i = 2; i < instance; i++) {
  383. table_desc = table_desc->next;
  384. }
  385. /* We are now pointing to the requested table's descriptor */
  386. *table_ptr_loc = table_desc->pointer;
  387. return_ACPI_STATUS (AE_OK);
  388. }