tbget.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /******************************************************************************
  2. *
  3. * Module Name: tbget - ACPI Table get* routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, 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_EXCEPTION((AE_INFO, status,
  83. "Could not get ACPI table (size %X)",
  84. header.length));
  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. return_ACPI_STATUS(status);
  130. }
  131. /* Copy header and delete mapping */
  132. ACPI_MEMCPY(return_header, header,
  133. sizeof(struct acpi_table_header));
  134. acpi_os_unmap_memory(header, sizeof(struct acpi_table_header));
  135. break;
  136. default:
  137. ACPI_ERROR((AE_INFO, "Invalid address flags %X",
  138. address->pointer_type));
  139. return_ACPI_STATUS(AE_BAD_PARAMETER);
  140. }
  141. ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n",
  142. return_header->signature));
  143. return_ACPI_STATUS(AE_OK);
  144. }
  145. /*******************************************************************************
  146. *
  147. * FUNCTION: acpi_tb_get_table_body
  148. *
  149. * PARAMETERS: Address - Address of table to retrieve. Can be
  150. * Logical or Physical
  151. * Header - Header of the table to retrieve
  152. * table_info - Where the table info is returned
  153. *
  154. * RETURN: Status
  155. *
  156. * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
  157. * replace the table with a newer version (table override.)
  158. * Works in both physical or virtual
  159. * addressing mode. Works with both physical or logical pointers.
  160. * Table is either copied or mapped, depending on the pointer
  161. * type and mode of the processor.
  162. *
  163. ******************************************************************************/
  164. acpi_status
  165. acpi_tb_get_table_body(struct acpi_pointer *address,
  166. struct acpi_table_header *header,
  167. struct acpi_table_desc *table_info)
  168. {
  169. acpi_status status;
  170. ACPI_FUNCTION_TRACE("tb_get_table_body");
  171. if (!table_info || !address) {
  172. return_ACPI_STATUS(AE_BAD_PARAMETER);
  173. }
  174. /* Attempt table override. */
  175. status = acpi_tb_table_override(header, table_info);
  176. if (ACPI_SUCCESS(status)) {
  177. /* Table was overridden by the host OS */
  178. return_ACPI_STATUS(status);
  179. }
  180. /* No override, get the original table */
  181. status = acpi_tb_get_this_table(address, header, table_info);
  182. return_ACPI_STATUS(status);
  183. }
  184. /*******************************************************************************
  185. *
  186. * FUNCTION: acpi_tb_table_override
  187. *
  188. * PARAMETERS: Header - Pointer to table header
  189. * table_info - Return info if table is overridden
  190. *
  191. * RETURN: None
  192. *
  193. * DESCRIPTION: Attempts override of current table with a new one if provided
  194. * by the host OS.
  195. *
  196. ******************************************************************************/
  197. static acpi_status
  198. acpi_tb_table_override(struct acpi_table_header *header,
  199. struct acpi_table_desc *table_info)
  200. {
  201. struct acpi_table_header *new_table;
  202. acpi_status status;
  203. struct acpi_pointer address;
  204. ACPI_FUNCTION_TRACE("tb_table_override");
  205. /*
  206. * The OSL will examine the header and decide whether to override this
  207. * table. If it decides to override, a table will be returned in new_table,
  208. * which we will then copy.
  209. */
  210. status = acpi_os_table_override(header, &new_table);
  211. if (ACPI_FAILURE(status)) {
  212. /* Some severe error from the OSL, but we basically ignore it */
  213. ACPI_EXCEPTION((AE_INFO, status,
  214. "Could not override ACPI table"));
  215. return_ACPI_STATUS(status);
  216. }
  217. if (!new_table) {
  218. /* No table override */
  219. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  220. }
  221. /*
  222. * We have a new table to override the old one. Get a copy of
  223. * the new one. We know that the new table has a logical pointer.
  224. */
  225. address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
  226. address.pointer.logical = new_table;
  227. status = acpi_tb_get_this_table(&address, new_table, table_info);
  228. if (ACPI_FAILURE(status)) {
  229. ACPI_EXCEPTION((AE_INFO, status, "Could not copy ACPI table"));
  230. return_ACPI_STATUS(status);
  231. }
  232. /* Copy the table info */
  233. ACPI_INFO((AE_INFO, "Table [%4.4s] replaced by host OS",
  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. static acpi_status
  255. acpi_tb_get_this_table(struct acpi_pointer *address,
  256. struct acpi_table_header *header,
  257. struct acpi_table_desc *table_info)
  258. {
  259. struct acpi_table_header *full_table = NULL;
  260. u8 allocation;
  261. acpi_status status = AE_OK;
  262. ACPI_FUNCTION_TRACE("tb_get_this_table");
  263. /*
  264. * Flags contains the current processor mode (Virtual or Physical
  265. * addressing) The pointer_type is either Logical or Physical
  266. */
  267. switch (address->pointer_type) {
  268. case ACPI_PHYSMODE_PHYSPTR:
  269. case ACPI_LOGMODE_LOGPTR:
  270. /* Pointer matches processor mode, copy the table to a new buffer */
  271. full_table = ACPI_MEM_ALLOCATE(header->length);
  272. if (!full_table) {
  273. ACPI_ERROR((AE_INFO,
  274. "Could not allocate table memory for [%4.4s] length %X",
  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,
  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_ERROR((AE_INFO,
  294. "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X",
  295. header->signature,
  296. ACPI_FORMAT_UINT64(address->pointer.
  297. physical),
  298. header->length));
  299. return (status);
  300. }
  301. /* Save allocation type */
  302. allocation = ACPI_MEM_MAPPED;
  303. break;
  304. default:
  305. ACPI_ERROR((AE_INFO, "Invalid address flags %X",
  306. address->pointer_type));
  307. return_ACPI_STATUS(AE_BAD_PARAMETER);
  308. }
  309. /*
  310. * Validate checksum for _most_ tables,
  311. * even the ones whose signature we don't recognize
  312. */
  313. if (table_info->type != ACPI_TABLE_FACS) {
  314. status = acpi_tb_verify_table_checksum(full_table);
  315. #if (!ACPI_CHECKSUM_ABORT)
  316. if (ACPI_FAILURE(status)) {
  317. /* Ignore the error if configuration says so */
  318. status = AE_OK;
  319. }
  320. #endif
  321. }
  322. /* Return values */
  323. table_info->pointer = full_table;
  324. table_info->length = (acpi_size) header->length;
  325. table_info->allocation = allocation;
  326. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  327. "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
  328. full_table->signature,
  329. ACPI_FORMAT_UINT64(address->pointer.physical),
  330. full_table));
  331. return_ACPI_STATUS(status);
  332. }
  333. /*******************************************************************************
  334. *
  335. * FUNCTION: acpi_tb_get_table_ptr
  336. *
  337. * PARAMETERS: table_type - one of the defined table types
  338. * Instance - Which table of this type
  339. * table_ptr_loc - pointer to location to place the pointer for
  340. * return
  341. *
  342. * RETURN: Status
  343. *
  344. * DESCRIPTION: This function is called to get the pointer to an ACPI table.
  345. *
  346. ******************************************************************************/
  347. acpi_status
  348. acpi_tb_get_table_ptr(acpi_table_type table_type,
  349. u32 instance, struct acpi_table_header **table_ptr_loc)
  350. {
  351. struct acpi_table_desc *table_desc;
  352. u32 i;
  353. ACPI_FUNCTION_TRACE("tb_get_table_ptr");
  354. if (!acpi_gbl_DSDT) {
  355. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  356. }
  357. if (table_type > ACPI_TABLE_MAX) {
  358. return_ACPI_STATUS(AE_BAD_PARAMETER);
  359. }
  360. /*
  361. * For all table types (Single/Multiple), the first
  362. * instance is always in the list head.
  363. */
  364. if (instance == 1) {
  365. /* Get the first */
  366. *table_ptr_loc = NULL;
  367. if (acpi_gbl_table_lists[table_type].next) {
  368. *table_ptr_loc =
  369. acpi_gbl_table_lists[table_type].next->pointer;
  370. }
  371. return_ACPI_STATUS(AE_OK);
  372. }
  373. /* Check for instance out of range */
  374. if (instance > acpi_gbl_table_lists[table_type].count) {
  375. return_ACPI_STATUS(AE_NOT_EXIST);
  376. }
  377. /* Walk the list to get the desired table
  378. * Since the if (Instance == 1) check above checked for the
  379. * first table, setting table_desc equal to the .Next member
  380. * is actually pointing to the second table. Therefore, we
  381. * need to walk from the 2nd table until we reach the Instance
  382. * that the user is looking for and return its table pointer.
  383. */
  384. table_desc = acpi_gbl_table_lists[table_type].next;
  385. for (i = 2; i < instance; i++) {
  386. table_desc = table_desc->next;
  387. }
  388. /* We are now pointing to the requested table's descriptor */
  389. *table_ptr_loc = table_desc->pointer;
  390. return_ACPI_STATUS(AE_OK);
  391. }