tbxfroot.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: tbxfroot - Find the root ACPI table (RSDT)
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "actables.h"
  12. #define _COMPONENT ACPI_TABLES
  13. ACPI_MODULE_NAME("tbxfroot")
  14. /*******************************************************************************
  15. *
  16. * FUNCTION: acpi_tb_get_rsdp_length
  17. *
  18. * PARAMETERS: rsdp - Pointer to RSDP
  19. *
  20. * RETURN: Table length
  21. *
  22. * DESCRIPTION: Get the length of the RSDP
  23. *
  24. ******************************************************************************/
  25. u32 acpi_tb_get_rsdp_length(struct acpi_table_rsdp *rsdp)
  26. {
  27. if (!ACPI_VALIDATE_RSDP_SIG(rsdp->signature)) {
  28. /* BAD Signature */
  29. return (0);
  30. }
  31. /* "Length" field is available if table version >= 2 */
  32. if (rsdp->revision >= 2) {
  33. return (rsdp->length);
  34. } else {
  35. return (ACPI_RSDP_CHECKSUM_LENGTH);
  36. }
  37. }
  38. /*******************************************************************************
  39. *
  40. * FUNCTION: acpi_tb_validate_rsdp
  41. *
  42. * PARAMETERS: rsdp - Pointer to unvalidated RSDP
  43. *
  44. * RETURN: Status
  45. *
  46. * DESCRIPTION: Validate the RSDP (ptr)
  47. *
  48. ******************************************************************************/
  49. acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp)
  50. {
  51. /*
  52. * The signature and checksum must both be correct
  53. *
  54. * Note: Sometimes there exists more than one RSDP in memory; the valid
  55. * RSDP has a valid checksum, all others have an invalid checksum.
  56. */
  57. if (!ACPI_VALIDATE_RSDP_SIG(rsdp->signature)) {
  58. /* Nope, BAD Signature */
  59. return (AE_BAD_SIGNATURE);
  60. }
  61. /* Check the standard checksum */
  62. if (acpi_tb_checksum((u8 *) rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
  63. return (AE_BAD_CHECKSUM);
  64. }
  65. /* Check extended checksum if table version >= 2 */
  66. if ((rsdp->revision >= 2) &&
  67. (acpi_tb_checksum((u8 *) rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0)) {
  68. return (AE_BAD_CHECKSUM);
  69. }
  70. return (AE_OK);
  71. }
  72. /*******************************************************************************
  73. *
  74. * FUNCTION: acpi_find_root_pointer
  75. *
  76. * PARAMETERS: table_address - Where the table pointer is returned
  77. *
  78. * RETURN: Status, RSDP physical address
  79. *
  80. * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor
  81. * pointer structure. If it is found, set *RSDP to point to it.
  82. *
  83. * NOTE1: The RSDP must be either in the first 1K of the Extended
  84. * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
  85. * Only a 32-bit physical address is necessary.
  86. *
  87. * NOTE2: This function is always available, regardless of the
  88. * initialization state of the rest of ACPI.
  89. *
  90. ******************************************************************************/
  91. acpi_status ACPI_INIT_FUNCTION
  92. acpi_find_root_pointer(acpi_physical_address *table_address)
  93. {
  94. u8 *table_ptr;
  95. u8 *mem_rover;
  96. u32 physical_address;
  97. ACPI_FUNCTION_TRACE(acpi_find_root_pointer);
  98. /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
  99. table_ptr = acpi_os_map_memory((acpi_physical_address)
  100. ACPI_EBDA_PTR_LOCATION,
  101. ACPI_EBDA_PTR_LENGTH);
  102. if (!table_ptr) {
  103. ACPI_ERROR((AE_INFO,
  104. "Could not map memory at 0x%8.8X for length %u",
  105. ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
  106. return_ACPI_STATUS(AE_NO_MEMORY);
  107. }
  108. ACPI_MOVE_16_TO_32(&physical_address, table_ptr);
  109. /* Convert segment part to physical address */
  110. physical_address <<= 4;
  111. acpi_os_unmap_memory(table_ptr, ACPI_EBDA_PTR_LENGTH);
  112. /* EBDA present? */
  113. if (physical_address > 0x400) {
  114. /*
  115. * 1b) Search EBDA paragraphs (EBDA is required to be a
  116. * minimum of 1K length)
  117. */
  118. table_ptr = acpi_os_map_memory((acpi_physical_address)
  119. physical_address,
  120. ACPI_EBDA_WINDOW_SIZE);
  121. if (!table_ptr) {
  122. ACPI_ERROR((AE_INFO,
  123. "Could not map memory at 0x%8.8X for length %u",
  124. physical_address, ACPI_EBDA_WINDOW_SIZE));
  125. return_ACPI_STATUS(AE_NO_MEMORY);
  126. }
  127. mem_rover =
  128. acpi_tb_scan_memory_for_rsdp(table_ptr,
  129. ACPI_EBDA_WINDOW_SIZE);
  130. acpi_os_unmap_memory(table_ptr, ACPI_EBDA_WINDOW_SIZE);
  131. if (mem_rover) {
  132. /* Return the physical address */
  133. physical_address +=
  134. (u32) ACPI_PTR_DIFF(mem_rover, table_ptr);
  135. *table_address =
  136. (acpi_physical_address)physical_address;
  137. return_ACPI_STATUS(AE_OK);
  138. }
  139. }
  140. /*
  141. * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
  142. */
  143. table_ptr = acpi_os_map_memory((acpi_physical_address)
  144. ACPI_HI_RSDP_WINDOW_BASE,
  145. ACPI_HI_RSDP_WINDOW_SIZE);
  146. if (!table_ptr) {
  147. ACPI_ERROR((AE_INFO,
  148. "Could not map memory at 0x%8.8X for length %u",
  149. ACPI_HI_RSDP_WINDOW_BASE,
  150. ACPI_HI_RSDP_WINDOW_SIZE));
  151. return_ACPI_STATUS(AE_NO_MEMORY);
  152. }
  153. mem_rover =
  154. acpi_tb_scan_memory_for_rsdp(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
  155. acpi_os_unmap_memory(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
  156. if (mem_rover) {
  157. /* Return the physical address */
  158. physical_address = (u32)
  159. (ACPI_HI_RSDP_WINDOW_BASE +
  160. ACPI_PTR_DIFF(mem_rover, table_ptr));
  161. *table_address = (acpi_physical_address)physical_address;
  162. return_ACPI_STATUS(AE_OK);
  163. }
  164. /* A valid RSDP was not found */
  165. ACPI_BIOS_ERROR((AE_INFO, "A valid RSDP was not found"));
  166. return_ACPI_STATUS(AE_NOT_FOUND);
  167. }
  168. ACPI_EXPORT_SYMBOL_INIT(acpi_find_root_pointer)
  169. /*******************************************************************************
  170. *
  171. * FUNCTION: acpi_tb_scan_memory_for_rsdp
  172. *
  173. * PARAMETERS: start_address - Starting pointer for search
  174. * length - Maximum length to search
  175. *
  176. * RETURN: Pointer to the RSDP if found, otherwise NULL.
  177. *
  178. * DESCRIPTION: Search a block of memory for the RSDP signature
  179. *
  180. ******************************************************************************/
  181. u8 *acpi_tb_scan_memory_for_rsdp(u8 *start_address, u32 length)
  182. {
  183. acpi_status status;
  184. u8 *mem_rover;
  185. u8 *end_address;
  186. ACPI_FUNCTION_TRACE(tb_scan_memory_for_rsdp);
  187. end_address = start_address + length;
  188. /* Search from given start address for the requested length */
  189. for (mem_rover = start_address; mem_rover < end_address;
  190. mem_rover += ACPI_RSDP_SCAN_STEP) {
  191. /* The RSDP signature and checksum must both be correct */
  192. status =
  193. acpi_tb_validate_rsdp(ACPI_CAST_PTR
  194. (struct acpi_table_rsdp, mem_rover));
  195. if (ACPI_SUCCESS(status)) {
  196. /* Sig and checksum valid, we have found a real RSDP */
  197. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  198. "RSDP located at physical address %p\n",
  199. mem_rover));
  200. return_PTR(mem_rover);
  201. }
  202. /* No sig match or bad checksum, keep searching */
  203. }
  204. /* Searched entire block, no RSDP was found */
  205. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  206. "Searched entire block from %p, valid RSDP was not found\n",
  207. start_address));
  208. return_PTR(NULL);
  209. }