tbxfroot.c 8.7 KB

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