tbxfroot.c 8.0 KB

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