tbxfroot.c 7.9 KB

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