tbxfroot.c 8.1 KB

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