tbxfroot.c 8.2 KB

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