tbrsdt.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /******************************************************************************
  2. *
  3. * Module Name: tbrsdt - ACPI RSDT table utilities
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 ("tbrsdt")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_tb_verify_rsdp
  49. *
  50. * PARAMETERS: Address - RSDP (Pointer to RSDT)
  51. *
  52. * RETURN: Status
  53. *
  54. * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
  55. *
  56. ******************************************************************************/
  57. acpi_status
  58. acpi_tb_verify_rsdp (
  59. struct acpi_pointer *address)
  60. {
  61. struct acpi_table_desc table_info;
  62. acpi_status status;
  63. struct rsdp_descriptor *rsdp;
  64. ACPI_FUNCTION_TRACE ("tb_verify_rsdp");
  65. switch (address->pointer_type) {
  66. case ACPI_LOGICAL_POINTER:
  67. rsdp = address->pointer.logical;
  68. break;
  69. case ACPI_PHYSICAL_POINTER:
  70. /*
  71. * Obtain access to the RSDP structure
  72. */
  73. status = acpi_os_map_memory (address->pointer.physical,
  74. sizeof (struct rsdp_descriptor),
  75. (void *) &rsdp);
  76. if (ACPI_FAILURE (status)) {
  77. return_ACPI_STATUS (status);
  78. }
  79. break;
  80. default:
  81. return_ACPI_STATUS (AE_BAD_PARAMETER);
  82. }
  83. /*
  84. * The signature and checksum must both be correct
  85. */
  86. if (ACPI_STRNCMP ((char *) rsdp, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0) {
  87. /* Nope, BAD Signature */
  88. status = AE_BAD_SIGNATURE;
  89. goto cleanup;
  90. }
  91. /* Check the standard checksum */
  92. if (acpi_tb_checksum (rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
  93. status = AE_BAD_CHECKSUM;
  94. goto cleanup;
  95. }
  96. /* Check extended checksum if table version >= 2 */
  97. if (rsdp->revision >= 2) {
  98. if (acpi_tb_checksum (rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0) {
  99. status = AE_BAD_CHECKSUM;
  100. goto cleanup;
  101. }
  102. }
  103. /* The RSDP supplied is OK */
  104. table_info.pointer = ACPI_CAST_PTR (struct acpi_table_header, rsdp);
  105. table_info.length = sizeof (struct rsdp_descriptor);
  106. table_info.allocation = ACPI_MEM_MAPPED;
  107. /* Save the table pointers and allocation info */
  108. status = acpi_tb_init_table_descriptor (ACPI_TABLE_RSDP, &table_info);
  109. if (ACPI_FAILURE (status)) {
  110. goto cleanup;
  111. }
  112. /* Save the RSDP in a global for easy access */
  113. acpi_gbl_RSDP = ACPI_CAST_PTR (struct rsdp_descriptor, table_info.pointer);
  114. return_ACPI_STATUS (status);
  115. /* Error exit */
  116. cleanup:
  117. if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) {
  118. acpi_os_unmap_memory (rsdp, sizeof (struct rsdp_descriptor));
  119. }
  120. return_ACPI_STATUS (status);
  121. }
  122. /*******************************************************************************
  123. *
  124. * FUNCTION: acpi_tb_get_rsdt_address
  125. *
  126. * PARAMETERS: out_address - Where the address is returned
  127. *
  128. * RETURN: None, Address
  129. *
  130. * DESCRIPTION: Extract the address of the RSDT or XSDT, depending on the
  131. * version of the RSDP
  132. *
  133. ******************************************************************************/
  134. void
  135. acpi_tb_get_rsdt_address (
  136. struct acpi_pointer *out_address)
  137. {
  138. ACPI_FUNCTION_ENTRY ();
  139. out_address->pointer_type = acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
  140. /*
  141. * For RSDP revision 0 or 1, we use the RSDT.
  142. * For RSDP revision 2 (and above), we use the XSDT
  143. */
  144. if (acpi_gbl_RSDP->revision < 2) {
  145. out_address->pointer.value = acpi_gbl_RSDP->rsdt_physical_address;
  146. }
  147. else {
  148. out_address->pointer.value =
  149. acpi_gbl_RSDP->xsdt_physical_address;
  150. }
  151. }
  152. /*******************************************************************************
  153. *
  154. * FUNCTION: acpi_tb_validate_rsdt
  155. *
  156. * PARAMETERS: table_ptr - Addressable pointer to the RSDT.
  157. *
  158. * RETURN: Status
  159. *
  160. * DESCRIPTION: Validate signature for the RSDT or XSDT
  161. *
  162. ******************************************************************************/
  163. acpi_status
  164. acpi_tb_validate_rsdt (
  165. struct acpi_table_header *table_ptr)
  166. {
  167. int no_match;
  168. ACPI_FUNCTION_NAME ("tb_validate_rsdt");
  169. /*
  170. * For RSDP revision 0 or 1, we use the RSDT.
  171. * For RSDP revision 2 and above, we use the XSDT
  172. */
  173. if (acpi_gbl_RSDP->revision < 2) {
  174. no_match = ACPI_STRNCMP ((char *) table_ptr, RSDT_SIG,
  175. sizeof (RSDT_SIG) -1);
  176. }
  177. else {
  178. no_match = ACPI_STRNCMP ((char *) table_ptr, XSDT_SIG,
  179. sizeof (XSDT_SIG) -1);
  180. }
  181. if (no_match) {
  182. /* Invalid RSDT or XSDT signature */
  183. ACPI_REPORT_ERROR ((
  184. "Invalid signature where RSDP indicates RSDT/XSDT should be located\n"));
  185. ACPI_DUMP_BUFFER (acpi_gbl_RSDP, 20);
  186. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_ERROR,
  187. "RSDT/XSDT signature at %X (%p) is invalid\n",
  188. acpi_gbl_RSDP->rsdt_physical_address,
  189. (void *) (acpi_native_uint) acpi_gbl_RSDP->rsdt_physical_address));
  190. if (acpi_gbl_RSDP->revision < 2) {
  191. ACPI_REPORT_ERROR (("Looking for RSDT (RSDP->Rev < 2)\n"))
  192. }
  193. else {
  194. ACPI_REPORT_ERROR (("Looking for XSDT (RSDP->Rev >= 2)\n"))
  195. }
  196. ACPI_DUMP_BUFFER ((char *) table_ptr, 48);
  197. return (AE_BAD_SIGNATURE);
  198. }
  199. return (AE_OK);
  200. }
  201. /*******************************************************************************
  202. *
  203. * FUNCTION: acpi_tb_get_table_rsdt
  204. *
  205. * PARAMETERS: None
  206. *
  207. * RETURN: Status
  208. *
  209. * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
  210. *
  211. ******************************************************************************/
  212. acpi_status
  213. acpi_tb_get_table_rsdt (
  214. void)
  215. {
  216. struct acpi_table_desc table_info;
  217. acpi_status status;
  218. struct acpi_pointer address;
  219. ACPI_FUNCTION_TRACE ("tb_get_table_rsdt");
  220. /* Get the RSDT/XSDT via the RSDP */
  221. acpi_tb_get_rsdt_address (&address);
  222. table_info.type = ACPI_TABLE_XSDT;
  223. status = acpi_tb_get_table (&address, &table_info);
  224. if (ACPI_FAILURE (status)) {
  225. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not get the RSDT/XSDT, %s\n",
  226. acpi_format_exception (status)));
  227. return_ACPI_STATUS (status);
  228. }
  229. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  230. "RSDP located at %p, points to RSDT physical=%8.8X%8.8X \n",
  231. acpi_gbl_RSDP,
  232. ACPI_FORMAT_UINT64 (address.pointer.value)));
  233. /* Check the RSDT or XSDT signature */
  234. status = acpi_tb_validate_rsdt (table_info.pointer);
  235. if (ACPI_FAILURE (status)) {
  236. return_ACPI_STATUS (status);
  237. }
  238. /* Get the number of tables defined in the RSDT or XSDT */
  239. acpi_gbl_rsdt_table_count = acpi_tb_get_table_count (acpi_gbl_RSDP,
  240. table_info.pointer);
  241. /* Convert and/or copy to an XSDT structure */
  242. status = acpi_tb_convert_to_xsdt (&table_info);
  243. if (ACPI_FAILURE (status)) {
  244. return_ACPI_STATUS (status);
  245. }
  246. /* Save the table pointers and allocation info */
  247. status = acpi_tb_init_table_descriptor (ACPI_TABLE_XSDT, &table_info);
  248. if (ACPI_FAILURE (status)) {
  249. return_ACPI_STATUS (status);
  250. }
  251. acpi_gbl_XSDT = ACPI_CAST_PTR (XSDT_DESCRIPTOR, table_info.pointer);
  252. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
  253. return_ACPI_STATUS (status);
  254. }