tbget.c 14 KB

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