tbutils.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. /******************************************************************************
  2. *
  3. * Module Name: tbutils - table utilities
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, Intel Corp.
  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 "accommon.h"
  44. #include "actables.h"
  45. #define _COMPONENT ACPI_TABLES
  46. ACPI_MODULE_NAME("tbutils")
  47. /* Local prototypes */
  48. static void acpi_tb_fix_string(char *string, acpi_size length);
  49. static void
  50. acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
  51. struct acpi_table_header *header);
  52. static acpi_physical_address
  53. acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
  54. /*******************************************************************************
  55. *
  56. * FUNCTION: acpi_tb_check_xsdt
  57. *
  58. * PARAMETERS: address - Pointer to the XSDT
  59. *
  60. * RETURN: status
  61. * AE_OK - XSDT is okay
  62. * AE_NO_MEMORY - can't map XSDT
  63. * AE_INVALID_TABLE_LENGTH - invalid table length
  64. * AE_NULL_ENTRY - XSDT has NULL entry
  65. *
  66. * DESCRIPTION: validate XSDT
  67. ******************************************************************************/
  68. static acpi_status
  69. acpi_tb_check_xsdt(acpi_physical_address address)
  70. {
  71. struct acpi_table_header *table;
  72. u32 length;
  73. u64 xsdt_entry_address;
  74. u8 *table_entry;
  75. u32 table_count;
  76. int i;
  77. table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
  78. if (!table)
  79. return AE_NO_MEMORY;
  80. length = table->length;
  81. acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
  82. if (length < sizeof(struct acpi_table_header))
  83. return AE_INVALID_TABLE_LENGTH;
  84. table = acpi_os_map_memory(address, length);
  85. if (!table)
  86. return AE_NO_MEMORY;
  87. /* Calculate the number of tables described in XSDT */
  88. table_count =
  89. (u32) ((table->length -
  90. sizeof(struct acpi_table_header)) / sizeof(u64));
  91. table_entry =
  92. ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
  93. for (i = 0; i < table_count; i++) {
  94. ACPI_MOVE_64_TO_64(&xsdt_entry_address, table_entry);
  95. if (!xsdt_entry_address) {
  96. /* XSDT has NULL entry */
  97. break;
  98. }
  99. table_entry += sizeof(u64);
  100. }
  101. acpi_os_unmap_memory(table, length);
  102. if (i < table_count)
  103. return AE_NULL_ENTRY;
  104. else
  105. return AE_OK;
  106. }
  107. #if (!ACPI_REDUCED_HARDWARE)
  108. /*******************************************************************************
  109. *
  110. * FUNCTION: acpi_tb_initialize_facs
  111. *
  112. * PARAMETERS: None
  113. *
  114. * RETURN: Status
  115. *
  116. * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
  117. * for accessing the Global Lock and Firmware Waking Vector
  118. *
  119. ******************************************************************************/
  120. acpi_status acpi_tb_initialize_facs(void)
  121. {
  122. acpi_status status;
  123. /* If Hardware Reduced flag is set, there is no FACS */
  124. if (acpi_gbl_reduced_hardware) {
  125. acpi_gbl_FACS = NULL;
  126. return (AE_OK);
  127. }
  128. status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
  129. ACPI_CAST_INDIRECT_PTR(struct
  130. acpi_table_header,
  131. &acpi_gbl_FACS));
  132. return status;
  133. }
  134. #endif /* !ACPI_REDUCED_HARDWARE */
  135. /*******************************************************************************
  136. *
  137. * FUNCTION: acpi_tb_tables_loaded
  138. *
  139. * PARAMETERS: None
  140. *
  141. * RETURN: TRUE if required ACPI tables are loaded
  142. *
  143. * DESCRIPTION: Determine if the minimum required ACPI tables are present
  144. * (FADT, FACS, DSDT)
  145. *
  146. ******************************************************************************/
  147. u8 acpi_tb_tables_loaded(void)
  148. {
  149. if (acpi_gbl_root_table_list.current_table_count >= 3) {
  150. return (TRUE);
  151. }
  152. return (FALSE);
  153. }
  154. /*******************************************************************************
  155. *
  156. * FUNCTION: acpi_tb_fix_string
  157. *
  158. * PARAMETERS: string - String to be repaired
  159. * length - Maximum length
  160. *
  161. * RETURN: None
  162. *
  163. * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
  164. * with a question mark '?'.
  165. *
  166. ******************************************************************************/
  167. static void acpi_tb_fix_string(char *string, acpi_size length)
  168. {
  169. while (length && *string) {
  170. if (!ACPI_IS_PRINT(*string)) {
  171. *string = '?';
  172. }
  173. string++;
  174. length--;
  175. }
  176. }
  177. /*******************************************************************************
  178. *
  179. * FUNCTION: acpi_tb_cleanup_table_header
  180. *
  181. * PARAMETERS: out_header - Where the cleaned header is returned
  182. * header - Input ACPI table header
  183. *
  184. * RETURN: Returns the cleaned header in out_header
  185. *
  186. * DESCRIPTION: Copy the table header and ensure that all "string" fields in
  187. * the header consist of printable characters.
  188. *
  189. ******************************************************************************/
  190. static void
  191. acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
  192. struct acpi_table_header *header)
  193. {
  194. ACPI_MEMCPY(out_header, header, sizeof(struct acpi_table_header));
  195. acpi_tb_fix_string(out_header->signature, ACPI_NAME_SIZE);
  196. acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
  197. acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
  198. acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAME_SIZE);
  199. }
  200. /*******************************************************************************
  201. *
  202. * FUNCTION: acpi_tb_print_table_header
  203. *
  204. * PARAMETERS: address - Table physical address
  205. * header - Table header
  206. *
  207. * RETURN: None
  208. *
  209. * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
  210. *
  211. ******************************************************************************/
  212. void
  213. acpi_tb_print_table_header(acpi_physical_address address,
  214. struct acpi_table_header *header)
  215. {
  216. struct acpi_table_header local_header;
  217. /*
  218. * The reason that the Address is cast to a void pointer is so that we
  219. * can use %p which will work properly on both 32-bit and 64-bit hosts.
  220. */
  221. if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
  222. /* FACS only has signature and length fields */
  223. ACPI_INFO((AE_INFO, "%4.4s %p %05X",
  224. header->signature, ACPI_CAST_PTR(void, address),
  225. header->length));
  226. } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
  227. /* RSDP has no common fields */
  228. ACPI_MEMCPY(local_header.oem_id,
  229. ACPI_CAST_PTR(struct acpi_table_rsdp,
  230. header)->oem_id, ACPI_OEM_ID_SIZE);
  231. acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
  232. ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)",
  233. ACPI_CAST_PTR (void, address),
  234. (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
  235. revision >
  236. 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
  237. header)->length : 20,
  238. ACPI_CAST_PTR(struct acpi_table_rsdp,
  239. header)->revision,
  240. local_header.oem_id));
  241. } else {
  242. /* Standard ACPI table with full common header */
  243. acpi_tb_cleanup_table_header(&local_header, header);
  244. ACPI_INFO((AE_INFO,
  245. "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
  246. local_header.signature, ACPI_CAST_PTR(void, address),
  247. local_header.length, local_header.revision,
  248. local_header.oem_id, local_header.oem_table_id,
  249. local_header.oem_revision,
  250. local_header.asl_compiler_id,
  251. local_header.asl_compiler_revision));
  252. }
  253. }
  254. /*******************************************************************************
  255. *
  256. * FUNCTION: acpi_tb_validate_checksum
  257. *
  258. * PARAMETERS: table - ACPI table to verify
  259. * length - Length of entire table
  260. *
  261. * RETURN: Status
  262. *
  263. * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
  264. * exception on bad checksum.
  265. *
  266. ******************************************************************************/
  267. acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
  268. {
  269. u8 checksum;
  270. /* Compute the checksum on the table */
  271. checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
  272. /* Checksum ok? (should be zero) */
  273. if (checksum) {
  274. ACPI_BIOS_WARNING((AE_INFO,
  275. "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
  276. "should be 0x%2.2X",
  277. table->signature, table->checksum,
  278. (u8)(table->checksum - checksum)));
  279. #if (ACPI_CHECKSUM_ABORT)
  280. return (AE_BAD_CHECKSUM);
  281. #endif
  282. }
  283. return (AE_OK);
  284. }
  285. /*******************************************************************************
  286. *
  287. * FUNCTION: acpi_tb_checksum
  288. *
  289. * PARAMETERS: buffer - Pointer to memory region to be checked
  290. * length - Length of this memory region
  291. *
  292. * RETURN: Checksum (u8)
  293. *
  294. * DESCRIPTION: Calculates circular checksum of memory region.
  295. *
  296. ******************************************************************************/
  297. u8 acpi_tb_checksum(u8 *buffer, u32 length)
  298. {
  299. u8 sum = 0;
  300. u8 *end = buffer + length;
  301. while (buffer < end) {
  302. sum = (u8) (sum + *(buffer++));
  303. }
  304. return sum;
  305. }
  306. /*******************************************************************************
  307. *
  308. * FUNCTION: acpi_tb_check_dsdt_header
  309. *
  310. * PARAMETERS: None
  311. *
  312. * RETURN: None
  313. *
  314. * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
  315. * if the DSDT has been replaced from outside the OS and/or if
  316. * the DSDT header has been corrupted.
  317. *
  318. ******************************************************************************/
  319. void acpi_tb_check_dsdt_header(void)
  320. {
  321. /* Compare original length and checksum to current values */
  322. if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
  323. acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
  324. ACPI_BIOS_ERROR((AE_INFO,
  325. "The DSDT has been corrupted or replaced - "
  326. "old, new headers below"));
  327. acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
  328. acpi_tb_print_table_header(0, acpi_gbl_DSDT);
  329. ACPI_ERROR((AE_INFO,
  330. "Please send DMI info to linux-acpi@vger.kernel.org\n"
  331. "If system does not work as expected, please boot with acpi=copy_dsdt"));
  332. /* Disable further error messages */
  333. acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
  334. acpi_gbl_original_dsdt_header.checksum =
  335. acpi_gbl_DSDT->checksum;
  336. }
  337. }
  338. /*******************************************************************************
  339. *
  340. * FUNCTION: acpi_tb_copy_dsdt
  341. *
  342. * PARAMETERS: table_desc - Installed table to copy
  343. *
  344. * RETURN: None
  345. *
  346. * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
  347. * Some very bad BIOSs are known to either corrupt the DSDT or
  348. * install a new, bad DSDT. This copy works around the problem.
  349. *
  350. ******************************************************************************/
  351. struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
  352. {
  353. struct acpi_table_header *new_table;
  354. struct acpi_table_desc *table_desc;
  355. table_desc = &acpi_gbl_root_table_list.tables[table_index];
  356. new_table = ACPI_ALLOCATE(table_desc->length);
  357. if (!new_table) {
  358. ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
  359. table_desc->length));
  360. return (NULL);
  361. }
  362. ACPI_MEMCPY(new_table, table_desc->pointer, table_desc->length);
  363. acpi_tb_delete_table(table_desc);
  364. table_desc->pointer = new_table;
  365. table_desc->flags = ACPI_TABLE_ORIGIN_ALLOCATED;
  366. ACPI_INFO((AE_INFO,
  367. "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
  368. new_table->length));
  369. return (new_table);
  370. }
  371. /*******************************************************************************
  372. *
  373. * FUNCTION: acpi_tb_install_table
  374. *
  375. * PARAMETERS: address - Physical address of DSDT or FACS
  376. * signature - Table signature, NULL if no need to
  377. * match
  378. * table_index - Index into root table array
  379. *
  380. * RETURN: None
  381. *
  382. * DESCRIPTION: Install an ACPI table into the global data structure. The
  383. * table override mechanism is called to allow the host
  384. * OS to replace any table before it is installed in the root
  385. * table array.
  386. *
  387. ******************************************************************************/
  388. void
  389. acpi_tb_install_table(acpi_physical_address address,
  390. char *signature, u32 table_index)
  391. {
  392. struct acpi_table_header *table;
  393. struct acpi_table_header *final_table;
  394. struct acpi_table_desc *table_desc;
  395. if (!address) {
  396. ACPI_ERROR((AE_INFO,
  397. "Null physical address for ACPI table [%s]",
  398. signature));
  399. return;
  400. }
  401. /* Map just the table header */
  402. table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
  403. if (!table) {
  404. ACPI_ERROR((AE_INFO,
  405. "Could not map memory for table [%s] at %p",
  406. signature, ACPI_CAST_PTR(void, address)));
  407. return;
  408. }
  409. /* If a particular signature is expected (DSDT/FACS), it must match */
  410. if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) {
  411. ACPI_BIOS_ERROR((AE_INFO,
  412. "Invalid signature 0x%X for ACPI table, expected [%s]",
  413. *ACPI_CAST_PTR(u32, table->signature),
  414. signature));
  415. goto unmap_and_exit;
  416. }
  417. /*
  418. * Initialize the table entry. Set the pointer to NULL, since the
  419. * table is not fully mapped at this time.
  420. */
  421. table_desc = &acpi_gbl_root_table_list.tables[table_index];
  422. table_desc->address = address;
  423. table_desc->pointer = NULL;
  424. table_desc->length = table->length;
  425. table_desc->flags = ACPI_TABLE_ORIGIN_MAPPED;
  426. ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
  427. /*
  428. * ACPI Table Override:
  429. *
  430. * Before we install the table, let the host OS override it with a new
  431. * one if desired. Any table within the RSDT/XSDT can be replaced,
  432. * including the DSDT which is pointed to by the FADT.
  433. *
  434. * NOTE: If the table is overridden, then final_table will contain a
  435. * mapped pointer to the full new table. If the table is not overridden,
  436. * or if there has been a physical override, then the table will be
  437. * fully mapped later (in verify table). In any case, we must
  438. * unmap the header that was mapped above.
  439. */
  440. final_table = acpi_tb_table_override(table, table_desc);
  441. if (!final_table) {
  442. final_table = table; /* There was no override */
  443. }
  444. acpi_tb_print_table_header(table_desc->address, final_table);
  445. /* Set the global integer width (based upon revision of the DSDT) */
  446. if (table_index == ACPI_TABLE_INDEX_DSDT) {
  447. acpi_ut_set_integer_width(final_table->revision);
  448. }
  449. /*
  450. * If we have a physical override during this early loading of the ACPI
  451. * tables, unmap the table for now. It will be mapped again later when
  452. * it is actually used. This supports very early loading of ACPI tables,
  453. * before virtual memory is fully initialized and running within the
  454. * host OS. Note: A logical override has the ACPI_TABLE_ORIGIN_OVERRIDE
  455. * flag set and will not be deleted below.
  456. */
  457. if (final_table != table) {
  458. acpi_tb_delete_table(table_desc);
  459. }
  460. unmap_and_exit:
  461. /* Always unmap the table header that we mapped above */
  462. acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
  463. }
  464. /*******************************************************************************
  465. *
  466. * FUNCTION: acpi_tb_get_root_table_entry
  467. *
  468. * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
  469. * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
  470. *
  471. * RETURN: Physical address extracted from the root table
  472. *
  473. * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
  474. * both 32-bit and 64-bit platforms
  475. *
  476. * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
  477. * 64-bit platforms.
  478. *
  479. ******************************************************************************/
  480. static acpi_physical_address
  481. acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
  482. {
  483. u64 address64;
  484. /*
  485. * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
  486. * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
  487. */
  488. if (table_entry_size == sizeof(u32)) {
  489. /*
  490. * 32-bit platform, RSDT: Return 32-bit table entry
  491. * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
  492. */
  493. return ((acpi_physical_address)
  494. (*ACPI_CAST_PTR(u32, table_entry)));
  495. } else {
  496. /*
  497. * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
  498. * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
  499. * return 64-bit
  500. */
  501. ACPI_MOVE_64_TO_64(&address64, table_entry);
  502. #if ACPI_MACHINE_WIDTH == 32
  503. if (address64 > ACPI_UINT32_MAX) {
  504. /* Will truncate 64-bit address to 32 bits, issue warning */
  505. ACPI_BIOS_WARNING((AE_INFO,
  506. "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
  507. " truncating",
  508. ACPI_FORMAT_UINT64(address64)));
  509. }
  510. #endif
  511. return ((acpi_physical_address) (address64));
  512. }
  513. }
  514. /*******************************************************************************
  515. *
  516. * FUNCTION: acpi_tb_parse_root_table
  517. *
  518. * PARAMETERS: rsdp - Pointer to the RSDP
  519. *
  520. * RETURN: Status
  521. *
  522. * DESCRIPTION: This function is called to parse the Root System Description
  523. * Table (RSDT or XSDT)
  524. *
  525. * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
  526. * be mapped and cannot be copied because it contains the actual
  527. * memory location of the ACPI Global Lock.
  528. *
  529. ******************************************************************************/
  530. acpi_status __init
  531. acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
  532. {
  533. struct acpi_table_rsdp *rsdp;
  534. u32 table_entry_size;
  535. u32 i;
  536. u32 table_count;
  537. struct acpi_table_header *table;
  538. acpi_physical_address address;
  539. acpi_physical_address uninitialized_var(rsdt_address);
  540. u32 length;
  541. u8 *table_entry;
  542. acpi_status status;
  543. ACPI_FUNCTION_TRACE(tb_parse_root_table);
  544. /*
  545. * Map the entire RSDP and extract the address of the RSDT or XSDT
  546. */
  547. rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
  548. if (!rsdp) {
  549. return_ACPI_STATUS(AE_NO_MEMORY);
  550. }
  551. acpi_tb_print_table_header(rsdp_address,
  552. ACPI_CAST_PTR(struct acpi_table_header,
  553. rsdp));
  554. /* Differentiate between RSDT and XSDT root tables */
  555. if (rsdp->revision > 1 && rsdp->xsdt_physical_address
  556. && !acpi_rsdt_forced) {
  557. /*
  558. * Root table is an XSDT (64-bit physical addresses). We must use the
  559. * XSDT if the revision is > 1 and the XSDT pointer is present, as per
  560. * the ACPI specification.
  561. */
  562. address = (acpi_physical_address) rsdp->xsdt_physical_address;
  563. table_entry_size = sizeof(u64);
  564. rsdt_address = (acpi_physical_address)
  565. rsdp->rsdt_physical_address;
  566. } else {
  567. /* Root table is an RSDT (32-bit physical addresses) */
  568. address = (acpi_physical_address) rsdp->rsdt_physical_address;
  569. table_entry_size = sizeof(u32);
  570. }
  571. /*
  572. * It is not possible to map more than one entry in some environments,
  573. * so unmap the RSDP here before mapping other tables
  574. */
  575. acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
  576. if (table_entry_size == sizeof(u64)) {
  577. if (acpi_tb_check_xsdt(address) == AE_NULL_ENTRY) {
  578. /* XSDT has NULL entry, RSDT is used */
  579. address = rsdt_address;
  580. table_entry_size = sizeof(u32);
  581. ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry, "
  582. "using RSDT"));
  583. }
  584. }
  585. /* Map the RSDT/XSDT table header to get the full table length */
  586. table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
  587. if (!table) {
  588. return_ACPI_STATUS(AE_NO_MEMORY);
  589. }
  590. acpi_tb_print_table_header(address, table);
  591. /* Get the length of the full table, verify length and map entire table */
  592. length = table->length;
  593. acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
  594. if (length < sizeof(struct acpi_table_header)) {
  595. ACPI_BIOS_ERROR((AE_INFO,
  596. "Invalid table length 0x%X in RSDT/XSDT",
  597. length));
  598. return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
  599. }
  600. table = acpi_os_map_memory(address, length);
  601. if (!table) {
  602. return_ACPI_STATUS(AE_NO_MEMORY);
  603. }
  604. /* Validate the root table checksum */
  605. status = acpi_tb_verify_checksum(table, length);
  606. if (ACPI_FAILURE(status)) {
  607. acpi_os_unmap_memory(table, length);
  608. return_ACPI_STATUS(status);
  609. }
  610. /* Calculate the number of tables described in the root table */
  611. table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
  612. table_entry_size);
  613. /*
  614. * First two entries in the table array are reserved for the DSDT
  615. * and FACS, which are not actually present in the RSDT/XSDT - they
  616. * come from the FADT
  617. */
  618. table_entry =
  619. ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
  620. acpi_gbl_root_table_list.current_table_count = 2;
  621. /*
  622. * Initialize the root table array from the RSDT/XSDT
  623. */
  624. for (i = 0; i < table_count; i++) {
  625. if (acpi_gbl_root_table_list.current_table_count >=
  626. acpi_gbl_root_table_list.max_table_count) {
  627. /* There is no more room in the root table array, attempt resize */
  628. status = acpi_tb_resize_root_table_list();
  629. if (ACPI_FAILURE(status)) {
  630. ACPI_WARNING((AE_INFO,
  631. "Truncating %u table entries!",
  632. (unsigned) (table_count -
  633. (acpi_gbl_root_table_list.
  634. current_table_count -
  635. 2))));
  636. break;
  637. }
  638. }
  639. /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
  640. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
  641. current_table_count].address =
  642. acpi_tb_get_root_table_entry(table_entry, table_entry_size);
  643. table_entry += table_entry_size;
  644. acpi_gbl_root_table_list.current_table_count++;
  645. }
  646. /*
  647. * It is not possible to map more than one entry in some environments,
  648. * so unmap the root table here before mapping other tables
  649. */
  650. acpi_os_unmap_memory(table, length);
  651. /*
  652. * Complete the initialization of the root table array by examining
  653. * the header of each table
  654. */
  655. for (i = 2; i < acpi_gbl_root_table_list.current_table_count; i++) {
  656. acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
  657. address, NULL, i);
  658. /* Special case for FADT - get the DSDT and FACS */
  659. if (ACPI_COMPARE_NAME
  660. (&acpi_gbl_root_table_list.tables[i].signature,
  661. ACPI_SIG_FADT)) {
  662. acpi_tb_parse_fadt(i);
  663. }
  664. }
  665. return_ACPI_STATUS(AE_OK);
  666. }