tbget.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. ACPI_ERROR((AE_INFO,
  130. "Could not map memory at %8.8X%8.8X for table header",
  131. ACPI_FORMAT_UINT64(address->pointer.
  132. physical)));
  133. return_ACPI_STATUS(status);
  134. }
  135. /* Copy header and delete mapping */
  136. ACPI_MEMCPY(return_header, header,
  137. sizeof(struct acpi_table_header));
  138. acpi_os_unmap_memory(header, sizeof(struct acpi_table_header));
  139. break;
  140. default:
  141. ACPI_ERROR((AE_INFO, "Invalid address flags %X",
  142. address->pointer_type));
  143. return_ACPI_STATUS(AE_BAD_PARAMETER);
  144. }
  145. ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n",
  146. return_header->signature));
  147. return_ACPI_STATUS(AE_OK);
  148. }
  149. /*******************************************************************************
  150. *
  151. * FUNCTION: acpi_tb_get_table_body
  152. *
  153. * PARAMETERS: Address - Address of table to retrieve. Can be
  154. * Logical or Physical
  155. * Header - Header of the table to retrieve
  156. * table_info - Where the table info is returned
  157. *
  158. * RETURN: Status
  159. *
  160. * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
  161. * replace the table with a newer version (table override.)
  162. * Works in both physical or virtual
  163. * addressing mode. Works with both physical or logical pointers.
  164. * Table is either copied or mapped, depending on the pointer
  165. * type and mode of the processor.
  166. *
  167. ******************************************************************************/
  168. acpi_status
  169. acpi_tb_get_table_body(struct acpi_pointer *address,
  170. struct acpi_table_header *header,
  171. struct acpi_table_desc *table_info)
  172. {
  173. acpi_status status;
  174. ACPI_FUNCTION_TRACE(tb_get_table_body);
  175. if (!table_info || !address) {
  176. return_ACPI_STATUS(AE_BAD_PARAMETER);
  177. }
  178. /* Attempt table override. */
  179. status = acpi_tb_table_override(header, table_info);
  180. if (ACPI_SUCCESS(status)) {
  181. /* Table was overridden by the host OS */
  182. return_ACPI_STATUS(status);
  183. }
  184. /* No override, get the original table */
  185. status = acpi_tb_get_this_table(address, header, table_info);
  186. return_ACPI_STATUS(status);
  187. }
  188. /*******************************************************************************
  189. *
  190. * FUNCTION: acpi_tb_table_override
  191. *
  192. * PARAMETERS: Header - Pointer to table header
  193. * table_info - Return info if table is overridden
  194. *
  195. * RETURN: None
  196. *
  197. * DESCRIPTION: Attempts override of current table with a new one if provided
  198. * by the host OS.
  199. *
  200. ******************************************************************************/
  201. static acpi_status
  202. acpi_tb_table_override(struct acpi_table_header *header,
  203. struct acpi_table_desc *table_info)
  204. {
  205. struct acpi_table_header *new_table;
  206. acpi_status status;
  207. struct acpi_pointer address;
  208. ACPI_FUNCTION_TRACE(tb_table_override);
  209. /*
  210. * The OSL will examine the header and decide whether to override this
  211. * table. If it decides to override, a table will be returned in new_table,
  212. * which we will then copy.
  213. */
  214. status = acpi_os_table_override(header, &new_table);
  215. if (ACPI_FAILURE(status)) {
  216. /* Some severe error from the OSL, but we basically ignore it */
  217. ACPI_EXCEPTION((AE_INFO, status,
  218. "Could not override ACPI table"));
  219. return_ACPI_STATUS(status);
  220. }
  221. if (!new_table) {
  222. /* No table override */
  223. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  224. }
  225. /*
  226. * We have a new table to override the old one. Get a copy of
  227. * the new one. We know that the new table has a logical pointer.
  228. */
  229. address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
  230. address.pointer.logical = new_table;
  231. status = acpi_tb_get_this_table(&address, new_table, table_info);
  232. if (ACPI_FAILURE(status)) {
  233. ACPI_EXCEPTION((AE_INFO, status, "Could not copy ACPI table"));
  234. return_ACPI_STATUS(status);
  235. }
  236. /* Copy the table info */
  237. ACPI_INFO((AE_INFO, "Table [%4.4s] replaced by host OS",
  238. table_info->pointer->signature));
  239. return_ACPI_STATUS(AE_OK);
  240. }
  241. /*******************************************************************************
  242. *
  243. * FUNCTION: acpi_tb_get_this_table
  244. *
  245. * PARAMETERS: Address - Address of table to retrieve. Can be
  246. * Logical or Physical
  247. * Header - Header of the table to retrieve
  248. * table_info - Where the table info is returned
  249. *
  250. * RETURN: Status
  251. *
  252. * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual
  253. * addressing mode. Works with both physical or logical pointers.
  254. * Table is either copied or mapped, depending on the pointer
  255. * type and mode of the processor.
  256. *
  257. ******************************************************************************/
  258. static acpi_status
  259. acpi_tb_get_this_table(struct acpi_pointer *address,
  260. struct acpi_table_header *header,
  261. struct acpi_table_desc *table_info)
  262. {
  263. struct acpi_table_header *full_table = NULL;
  264. u8 allocation;
  265. acpi_status status = AE_OK;
  266. ACPI_FUNCTION_TRACE(tb_get_this_table);
  267. /* Validate minimum length */
  268. if (header->length < sizeof(struct acpi_table_header)) {
  269. ACPI_ERROR((AE_INFO,
  270. "Table length (%X) is smaller than minimum (%zX)",
  271. header->length, sizeof(struct acpi_table_header)));
  272. return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
  273. }
  274. /*
  275. * Flags contains the current processor mode (Virtual or Physical
  276. * addressing) The pointer_type is either Logical or Physical
  277. */
  278. switch (address->pointer_type) {
  279. case ACPI_PHYSMODE_PHYSPTR:
  280. case ACPI_LOGMODE_LOGPTR:
  281. /* Pointer matches processor mode, copy the table to a new buffer */
  282. full_table = ACPI_ALLOCATE(header->length);
  283. if (!full_table) {
  284. ACPI_ERROR((AE_INFO,
  285. "Could not allocate table memory for [%4.4s] length %X",
  286. header->signature, header->length));
  287. return_ACPI_STATUS(AE_NO_MEMORY);
  288. }
  289. /* Copy the entire table (including header) to the local buffer */
  290. ACPI_MEMCPY(full_table, address->pointer.logical,
  291. header->length);
  292. /* Save allocation type */
  293. allocation = ACPI_MEM_ALLOCATED;
  294. break;
  295. case ACPI_LOGMODE_PHYSPTR:
  296. /*
  297. * Just map the table's physical memory
  298. * into our address space.
  299. */
  300. status = acpi_os_map_memory(address->pointer.physical,
  301. (acpi_size) header->length,
  302. ACPI_CAST_PTR(void, &full_table));
  303. if (ACPI_FAILURE(status)) {
  304. ACPI_ERROR((AE_INFO,
  305. "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X",
  306. header->signature,
  307. ACPI_FORMAT_UINT64(address->pointer.
  308. physical),
  309. header->length));
  310. return (status);
  311. }
  312. /* Save allocation type */
  313. allocation = ACPI_MEM_MAPPED;
  314. break;
  315. default:
  316. ACPI_ERROR((AE_INFO, "Invalid address flags %X",
  317. address->pointer_type));
  318. return_ACPI_STATUS(AE_BAD_PARAMETER);
  319. }
  320. /*
  321. * Validate checksum for _most_ tables,
  322. * even the ones whose signature we don't recognize
  323. */
  324. if (table_info->type != ACPI_TABLE_ID_FACS) {
  325. status = acpi_tb_verify_table_checksum(full_table);
  326. #if (!ACPI_CHECKSUM_ABORT)
  327. if (ACPI_FAILURE(status)) {
  328. /* Ignore the error if configuration says so */
  329. status = AE_OK;
  330. }
  331. #endif
  332. }
  333. /* Return values */
  334. table_info->pointer = full_table;
  335. table_info->length = (acpi_size) header->length;
  336. table_info->allocation = allocation;
  337. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  338. "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
  339. full_table->signature,
  340. ACPI_FORMAT_UINT64(address->pointer.physical),
  341. full_table));
  342. return_ACPI_STATUS(status);
  343. }
  344. /*******************************************************************************
  345. *
  346. * FUNCTION: acpi_tb_get_table_ptr
  347. *
  348. * PARAMETERS: table_type - one of the defined table types
  349. * Instance - Which table of this type
  350. * return_table - pointer to location to place the pointer for
  351. * return
  352. *
  353. * RETURN: Status
  354. *
  355. * DESCRIPTION: This function is called to get the pointer to an ACPI table.
  356. *
  357. ******************************************************************************/
  358. acpi_status
  359. acpi_tb_get_table_ptr(acpi_table_type table_type,
  360. u32 instance, struct acpi_table_header **return_table)
  361. {
  362. struct acpi_table_desc *table_desc;
  363. u32 i;
  364. ACPI_FUNCTION_TRACE(tb_get_table_ptr);
  365. if (table_type > ACPI_TABLE_ID_MAX) {
  366. return_ACPI_STATUS(AE_BAD_PARAMETER);
  367. }
  368. /* Check for instance out of range of the current table count */
  369. if (instance > acpi_gbl_table_lists[table_type].count) {
  370. return_ACPI_STATUS(AE_NOT_EXIST);
  371. }
  372. /*
  373. * Walk the list to get the desired table
  374. * Note: Instance is one-based
  375. */
  376. table_desc = acpi_gbl_table_lists[table_type].next;
  377. for (i = 1; i < instance; i++) {
  378. table_desc = table_desc->next;
  379. }
  380. /* We are now pointing to the requested table's descriptor */
  381. *return_table = table_desc->pointer;
  382. return_ACPI_STATUS(AE_OK);
  383. }