tbxfroot.c 8.2 KB

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