tbget.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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. /* Local prototypes */
  47. static acpi_status
  48. acpi_tb_get_this_table (
  49. struct acpi_pointer *address,
  50. struct acpi_table_header *header,
  51. struct acpi_table_desc *table_info);
  52. static acpi_status
  53. acpi_tb_table_override (
  54. struct acpi_table_header *header,
  55. struct acpi_table_desc *table_info);
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: acpi_tb_get_table
  59. *
  60. * PARAMETERS: Address - Address of table to retrieve. Can be
  61. * Logical or Physical
  62. * table_info - Where table info is returned
  63. *
  64. * RETURN: None
  65. *
  66. * DESCRIPTION: Get entire table of unknown size.
  67. *
  68. ******************************************************************************/
  69. acpi_status
  70. acpi_tb_get_table (
  71. struct acpi_pointer *address,
  72. struct acpi_table_desc *table_info)
  73. {
  74. acpi_status status;
  75. struct acpi_table_header header;
  76. ACPI_FUNCTION_TRACE ("tb_get_table");
  77. /* Get the header in order to get signature and table size */
  78. status = acpi_tb_get_table_header (address, &header);
  79. if (ACPI_FAILURE (status)) {
  80. return_ACPI_STATUS (status);
  81. }
  82. /* Get the entire table */
  83. status = acpi_tb_get_table_body (address, &header, table_info);
  84. if (ACPI_FAILURE (status)) {
  85. ACPI_REPORT_ERROR (("Could not get ACPI table (size %X), %s\n",
  86. header.length, acpi_format_exception (status)));
  87. return_ACPI_STATUS (status);
  88. }
  89. return_ACPI_STATUS (AE_OK);
  90. }
  91. /*******************************************************************************
  92. *
  93. * FUNCTION: acpi_tb_get_table_header
  94. *
  95. * PARAMETERS: Address - Address of table to retrieve. Can be
  96. * Logical or Physical
  97. * return_header - Where the table header is returned
  98. *
  99. * RETURN: Status
  100. *
  101. * DESCRIPTION: Get an ACPI table header. Works in both physical or virtual
  102. * addressing mode. Works with both physical or logical pointers.
  103. * Table is either copied or mapped, depending on the pointer
  104. * type and mode of the processor.
  105. *
  106. ******************************************************************************/
  107. acpi_status
  108. acpi_tb_get_table_header (
  109. struct acpi_pointer *address,
  110. struct acpi_table_header *return_header)
  111. {
  112. acpi_status status = AE_OK;
  113. struct acpi_table_header *header = NULL;
  114. ACPI_FUNCTION_TRACE ("tb_get_table_header");
  115. /*
  116. * Flags contains the current processor mode (Virtual or Physical
  117. * addressing) The pointer_type is either Logical or Physical
  118. */
  119. switch (address->pointer_type) {
  120. case ACPI_PHYSMODE_PHYSPTR:
  121. case ACPI_LOGMODE_LOGPTR:
  122. /* Pointer matches processor mode, copy the header */
  123. ACPI_MEMCPY (return_header, address->pointer.logical,
  124. sizeof (struct acpi_table_header));
  125. break;
  126. case ACPI_LOGMODE_PHYSPTR:
  127. /* Create a logical address for the physical pointer*/
  128. status = acpi_os_map_memory (address->pointer.physical,
  129. sizeof (struct acpi_table_header), (void *) &header);
  130. if (ACPI_FAILURE (status)) {
  131. ACPI_REPORT_ERROR ((
  132. "Could not map memory at %8.8X%8.8X for length %X\n",
  133. ACPI_FORMAT_UINT64 (address->pointer.physical),
  134. sizeof (struct acpi_table_header)));
  135. return_ACPI_STATUS (status);
  136. }
  137. /* Copy header and delete mapping */
  138. ACPI_MEMCPY (return_header, header, sizeof (struct acpi_table_header));
  139. acpi_os_unmap_memory (header, sizeof (struct acpi_table_header));
  140. break;
  141. default:
  142. ACPI_REPORT_ERROR (("Invalid address flags %X\n",
  143. address->pointer_type));
  144. return_ACPI_STATUS (AE_BAD_PARAMETER);
  145. }
  146. ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n",
  147. return_header->signature));
  148. return_ACPI_STATUS (AE_OK);
  149. }
  150. /*******************************************************************************
  151. *
  152. * FUNCTION: acpi_tb_get_table_body
  153. *
  154. * PARAMETERS: Address - Address of table to retrieve. Can be
  155. * Logical or Physical
  156. * Header - Header of the table to retrieve
  157. * table_info - Where the table info is returned
  158. *
  159. * RETURN: Status
  160. *
  161. * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
  162. * replace the table with a newer version (table override.)
  163. * Works in both physical or virtual
  164. * addressing mode. Works with both physical or logical pointers.
  165. * Table is either copied or mapped, depending on the pointer
  166. * type and mode of the processor.
  167. *
  168. ******************************************************************************/
  169. acpi_status
  170. acpi_tb_get_table_body (
  171. struct acpi_pointer *address,
  172. struct acpi_table_header *header,
  173. struct acpi_table_desc *table_info)
  174. {
  175. acpi_status status;
  176. ACPI_FUNCTION_TRACE ("tb_get_table_body");
  177. if (!table_info || !address) {
  178. return_ACPI_STATUS (AE_BAD_PARAMETER);
  179. }
  180. /* Attempt table override. */
  181. status = acpi_tb_table_override (header, table_info);
  182. if (ACPI_SUCCESS (status)) {
  183. /* Table was overridden by the host OS */
  184. return_ACPI_STATUS (status);
  185. }
  186. /* No override, get the original table */
  187. status = acpi_tb_get_this_table (address, header, table_info);
  188. return_ACPI_STATUS (status);
  189. }
  190. /*******************************************************************************
  191. *
  192. * FUNCTION: acpi_tb_table_override
  193. *
  194. * PARAMETERS: Header - Pointer to table header
  195. * table_info - Return info if table is overridden
  196. *
  197. * RETURN: None
  198. *
  199. * DESCRIPTION: Attempts override of current table with a new one if provided
  200. * by the host OS.
  201. *
  202. ******************************************************************************/
  203. static acpi_status
  204. acpi_tb_table_override (
  205. struct acpi_table_header *header,
  206. struct acpi_table_desc *table_info)
  207. {
  208. struct acpi_table_header *new_table;
  209. acpi_status status;
  210. struct acpi_pointer address;
  211. ACPI_FUNCTION_TRACE ("tb_table_override");
  212. /*
  213. * The OSL will examine the header and decide whether to override this
  214. * table. If it decides to override, a table will be returned in new_table,
  215. * which we will then copy.
  216. */
  217. status = acpi_os_table_override (header, &new_table);
  218. if (ACPI_FAILURE (status)) {
  219. /* Some severe error from the OSL, but we basically ignore it */
  220. ACPI_REPORT_ERROR (("Could not override ACPI table, %s\n",
  221. acpi_format_exception (status)));
  222. return_ACPI_STATUS (status);
  223. }
  224. if (!new_table) {
  225. /* No table override */
  226. return_ACPI_STATUS (AE_NO_ACPI_TABLES);
  227. }
  228. /*
  229. * We have a new table to override the old one. Get a copy of
  230. * the new one. We know that the new table has a logical pointer.
  231. */
  232. address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
  233. address.pointer.logical = new_table;
  234. status = acpi_tb_get_this_table (&address, new_table, table_info);
  235. if (ACPI_FAILURE (status)) {
  236. ACPI_REPORT_ERROR (("Could not copy override ACPI table, %s\n",
  237. acpi_format_exception (status)));
  238. return_ACPI_STATUS (status);
  239. }
  240. /* Copy the table info */
  241. ACPI_REPORT_INFO (("Table [%4.4s] replaced by host OS\n",
  242. table_info->pointer->signature));
  243. return_ACPI_STATUS (AE_OK);
  244. }
  245. /*******************************************************************************
  246. *
  247. * FUNCTION: acpi_tb_get_this_table
  248. *
  249. * PARAMETERS: Address - Address of table to retrieve. Can be
  250. * Logical or Physical
  251. * Header - Header of the table to retrieve
  252. * table_info - Where the table info is returned
  253. *
  254. * RETURN: Status
  255. *
  256. * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual
  257. * addressing mode. Works with both physical or logical pointers.
  258. * Table is either copied or mapped, depending on the pointer
  259. * type and mode of the processor.
  260. *
  261. ******************************************************************************/
  262. static acpi_status
  263. acpi_tb_get_this_table (
  264. struct acpi_pointer *address,
  265. struct acpi_table_header *header,
  266. struct acpi_table_desc *table_info)
  267. {
  268. struct acpi_table_header *full_table = NULL;
  269. u8 allocation;
  270. acpi_status status = AE_OK;
  271. ACPI_FUNCTION_TRACE ("tb_get_this_table");
  272. /*
  273. * Flags contains the current processor mode (Virtual or Physical
  274. * addressing) The pointer_type is either Logical or Physical
  275. */
  276. switch (address->pointer_type) {
  277. case ACPI_PHYSMODE_PHYSPTR:
  278. case ACPI_LOGMODE_LOGPTR:
  279. /* Pointer matches processor mode, copy the table to a new buffer */
  280. full_table = ACPI_MEM_ALLOCATE (header->length);
  281. if (!full_table) {
  282. ACPI_REPORT_ERROR ((
  283. "Could not allocate table memory for [%4.4s] length %X\n",
  284. header->signature, header->length));
  285. return_ACPI_STATUS (AE_NO_MEMORY);
  286. }
  287. /* Copy the entire table (including header) to the local buffer */
  288. ACPI_MEMCPY (full_table, address->pointer.logical, header->length);
  289. /* Save allocation type */
  290. allocation = ACPI_MEM_ALLOCATED;
  291. break;
  292. case ACPI_LOGMODE_PHYSPTR:
  293. /*
  294. * Just map the table's physical memory
  295. * into our address space.
  296. */
  297. status = acpi_os_map_memory (address->pointer.physical,
  298. (acpi_size) header->length, (void *) &full_table);
  299. if (ACPI_FAILURE (status)) {
  300. ACPI_REPORT_ERROR ((
  301. "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n",
  302. header->signature,
  303. ACPI_FORMAT_UINT64 (address->pointer.physical),
  304. header->length));
  305. return (status);
  306. }
  307. /* Save allocation type */
  308. allocation = ACPI_MEM_MAPPED;
  309. break;
  310. default:
  311. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid address flags %X\n",
  312. address->pointer_type));
  313. return_ACPI_STATUS (AE_BAD_PARAMETER);
  314. }
  315. /*
  316. * Validate checksum for _most_ tables,
  317. * even the ones whose signature we don't recognize
  318. */
  319. if (table_info->type != ACPI_TABLE_FACS) {
  320. status = acpi_tb_verify_table_checksum (full_table);
  321. #if (!ACPI_CHECKSUM_ABORT)
  322. if (ACPI_FAILURE (status)) {
  323. /* Ignore the error if configuration says so */
  324. status = AE_OK;
  325. }
  326. #endif
  327. }
  328. /* Return values */
  329. table_info->pointer = full_table;
  330. table_info->length = (acpi_size) header->length;
  331. table_info->allocation = allocation;
  332. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  333. "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
  334. full_table->signature,
  335. ACPI_FORMAT_UINT64 (address->pointer.physical), full_table));
  336. return_ACPI_STATUS (status);
  337. }
  338. /*******************************************************************************
  339. *
  340. * FUNCTION: acpi_tb_get_table_ptr
  341. *
  342. * PARAMETERS: table_type - one of the defined table types
  343. * Instance - Which table of this type
  344. * table_ptr_loc - pointer to location to place the pointer for
  345. * return
  346. *
  347. * RETURN: Status
  348. *
  349. * DESCRIPTION: This function is called to get the pointer to an ACPI table.
  350. *
  351. ******************************************************************************/
  352. acpi_status
  353. acpi_tb_get_table_ptr (
  354. acpi_table_type table_type,
  355. u32 instance,
  356. struct acpi_table_header **table_ptr_loc)
  357. {
  358. struct acpi_table_desc *table_desc;
  359. u32 i;
  360. ACPI_FUNCTION_TRACE ("tb_get_table_ptr");
  361. if (!acpi_gbl_DSDT) {
  362. return_ACPI_STATUS (AE_NO_ACPI_TABLES);
  363. }
  364. if (table_type > ACPI_TABLE_MAX) {
  365. return_ACPI_STATUS (AE_BAD_PARAMETER);
  366. }
  367. /*
  368. * For all table types (Single/Multiple), the first
  369. * instance is always in the list head.
  370. */
  371. if (instance == 1) {
  372. /* Get the first */
  373. *table_ptr_loc = NULL;
  374. if (acpi_gbl_table_lists[table_type].next) {
  375. *table_ptr_loc = acpi_gbl_table_lists[table_type].next->pointer;
  376. }
  377. return_ACPI_STATUS (AE_OK);
  378. }
  379. /* Check for instance out of range */
  380. if (instance > acpi_gbl_table_lists[table_type].count) {
  381. return_ACPI_STATUS (AE_NOT_EXIST);
  382. }
  383. /* Walk the list to get the desired table
  384. * Since the if (Instance == 1) check above checked for the
  385. * first table, setting table_desc equal to the .Next member
  386. * is actually pointing to the second table. Therefore, we
  387. * need to walk from the 2nd table until we reach the Instance
  388. * that the user is looking for and return its table pointer.
  389. */
  390. table_desc = acpi_gbl_table_lists[table_type].next;
  391. for (i = 2; i < instance; i++) {
  392. table_desc = table_desc->next;
  393. }
  394. /* We are now pointing to the requested table's descriptor */
  395. *table_ptr_loc = table_desc->pointer;
  396. return_ACPI_STATUS (AE_OK);
  397. }