tbrsdt.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /******************************************************************************
  2. *
  3. * Module Name: tbrsdt - ACPI RSDT table utilities
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, 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 acpi_tb_verify_rsdp(struct acpi_pointer *address)
  58. {
  59. struct acpi_table_desc table_info;
  60. acpi_status status;
  61. struct rsdp_descriptor *rsdp;
  62. ACPI_FUNCTION_TRACE(tb_verify_rsdp);
  63. switch (address->pointer_type) {
  64. case ACPI_LOGICAL_POINTER:
  65. rsdp = address->pointer.logical;
  66. break;
  67. case ACPI_PHYSICAL_POINTER:
  68. /*
  69. * Obtain access to the RSDP structure
  70. */
  71. status = acpi_os_map_memory(address->pointer.physical,
  72. sizeof(struct rsdp_descriptor),
  73. ACPI_CAST_PTR(void, &rsdp));
  74. if (ACPI_FAILURE(status)) {
  75. return_ACPI_STATUS(status);
  76. }
  77. break;
  78. default:
  79. return_ACPI_STATUS(AE_BAD_PARAMETER);
  80. }
  81. /* Verify RSDP signature and checksum */
  82. status = acpi_tb_validate_rsdp(rsdp);
  83. if (ACPI_FAILURE(status)) {
  84. goto cleanup;
  85. }
  86. /* RSDP is ok. Init the table info */
  87. table_info.pointer = ACPI_CAST_PTR(struct acpi_table_header, rsdp);
  88. table_info.length = sizeof(struct rsdp_descriptor);
  89. if (address->pointer_type == ACPI_PHYSICAL_POINTER) {
  90. table_info.allocation = ACPI_MEM_MAPPED;
  91. } else {
  92. table_info.allocation = ACPI_MEM_NOT_ALLOCATED;
  93. }
  94. /* Save the table pointers and allocation info */
  95. status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_RSDP, &table_info);
  96. if (ACPI_FAILURE(status)) {
  97. goto cleanup;
  98. }
  99. /* Save the RSDP in a global for easy access */
  100. acpi_gbl_RSDP =
  101. ACPI_CAST_PTR(struct rsdp_descriptor, table_info.pointer);
  102. return_ACPI_STATUS(status);
  103. /* Error exit */
  104. cleanup:
  105. if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) {
  106. acpi_os_unmap_memory(rsdp, sizeof(struct rsdp_descriptor));
  107. }
  108. return_ACPI_STATUS(status);
  109. }
  110. /*******************************************************************************
  111. *
  112. * FUNCTION: acpi_tb_get_rsdt_address
  113. *
  114. * PARAMETERS: out_address - Where the address is returned
  115. *
  116. * RETURN: None, Address
  117. *
  118. * DESCRIPTION: Extract the address of either the RSDT or XSDT, depending on the
  119. * version of the RSDP and whether the XSDT pointer is valid
  120. *
  121. ******************************************************************************/
  122. void acpi_tb_get_rsdt_address(struct acpi_pointer *out_address)
  123. {
  124. ACPI_FUNCTION_ENTRY();
  125. out_address->pointer_type =
  126. acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
  127. /* Use XSDT if it is present */
  128. if ((acpi_gbl_RSDP->revision >= 2) &&
  129. acpi_gbl_RSDP->xsdt_physical_address) {
  130. out_address->pointer.value =
  131. acpi_gbl_RSDP->xsdt_physical_address;
  132. acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT;
  133. } else {
  134. /* No XSDT, use the RSDT */
  135. out_address->pointer.value =
  136. acpi_gbl_RSDP->rsdt_physical_address;
  137. acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT;
  138. }
  139. }
  140. /*******************************************************************************
  141. *
  142. * FUNCTION: acpi_tb_validate_rsdt
  143. *
  144. * PARAMETERS: table_ptr - Addressable pointer to the RSDT.
  145. *
  146. * RETURN: Status
  147. *
  148. * DESCRIPTION: Validate signature for the RSDT or XSDT
  149. *
  150. ******************************************************************************/
  151. acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
  152. {
  153. char *signature;
  154. ACPI_FUNCTION_ENTRY();
  155. /* Validate minimum length */
  156. if (table_ptr->length < sizeof(struct acpi_table_header)) {
  157. ACPI_ERROR((AE_INFO,
  158. "RSDT/XSDT length (%X) is smaller than minimum (%zX)",
  159. table_ptr->length,
  160. sizeof(struct acpi_table_header)));
  161. return (AE_INVALID_TABLE_LENGTH);
  162. }
  163. /* Search for appropriate signature, RSDT or XSDT */
  164. if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
  165. signature = RSDT_SIG;
  166. } else {
  167. signature = XSDT_SIG;
  168. }
  169. if (!ACPI_COMPARE_NAME(table_ptr->signature, signature)) {
  170. /* Invalid RSDT or XSDT signature */
  171. ACPI_ERROR((AE_INFO,
  172. "Invalid signature where RSDP indicates RSDT/XSDT should be located. RSDP:"));
  173. ACPI_DUMP_BUFFER(acpi_gbl_RSDP, 20);
  174. ACPI_ERROR((AE_INFO,
  175. "RSDT/XSDT signature at %X is invalid",
  176. acpi_gbl_RSDP->rsdt_physical_address));
  177. if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
  178. ACPI_ERROR((AE_INFO, "Looking for RSDT"));
  179. } else {
  180. ACPI_ERROR((AE_INFO, "Looking for XSDT"));
  181. }
  182. ACPI_DUMP_BUFFER(ACPI_CAST_PTR(char, table_ptr), 48);
  183. return (AE_BAD_SIGNATURE);
  184. }
  185. return (AE_OK);
  186. }
  187. /*******************************************************************************
  188. *
  189. * FUNCTION: acpi_tb_get_table_rsdt
  190. *
  191. * PARAMETERS: None
  192. *
  193. * RETURN: Status
  194. *
  195. * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
  196. *
  197. ******************************************************************************/
  198. acpi_status acpi_tb_get_table_rsdt(void)
  199. {
  200. struct acpi_table_desc table_info;
  201. acpi_status status;
  202. struct acpi_pointer address;
  203. ACPI_FUNCTION_TRACE(tb_get_table_rsdt);
  204. /* Get the RSDT/XSDT via the RSDP */
  205. acpi_tb_get_rsdt_address(&address);
  206. table_info.type = ACPI_TABLE_ID_XSDT;
  207. status = acpi_tb_get_table(&address, &table_info);
  208. if (ACPI_FAILURE(status)) {
  209. ACPI_EXCEPTION((AE_INFO, status,
  210. "Could not get the RSDT/XSDT"));
  211. return_ACPI_STATUS(status);
  212. }
  213. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  214. "RSDP located at %p, points to RSDT physical=%8.8X%8.8X\n",
  215. acpi_gbl_RSDP,
  216. ACPI_FORMAT_UINT64(address.pointer.value)));
  217. /* Check the RSDT or XSDT signature */
  218. status = acpi_tb_validate_rsdt(table_info.pointer);
  219. if (ACPI_FAILURE(status)) {
  220. goto error_cleanup;
  221. }
  222. /* Get the number of tables defined in the RSDT or XSDT */
  223. acpi_gbl_rsdt_table_count = acpi_tb_get_table_count(acpi_gbl_RSDP,
  224. table_info.pointer);
  225. /* Convert and/or copy to an XSDT structure */
  226. status = acpi_tb_convert_to_xsdt(&table_info);
  227. if (ACPI_FAILURE(status)) {
  228. goto error_cleanup;
  229. }
  230. /* Save the table pointers and allocation info */
  231. status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info);
  232. if (ACPI_FAILURE(status)) {
  233. goto error_cleanup;
  234. }
  235. acpi_gbl_XSDT =
  236. ACPI_CAST_PTR(struct xsdt_descriptor, table_info.pointer);
  237. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
  238. return_ACPI_STATUS(status);
  239. error_cleanup:
  240. /* Free table allocated by acpi_tb_get_table */
  241. acpi_tb_delete_single_table(&table_info);
  242. return_ACPI_STATUS(status);
  243. }