Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: tbrsdt - ACPI RSDT table utilities | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
4a90c7e8 | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
1da177e4 LT |
9 | * All rights reserved. |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/actables.h> | |
46 | ||
1da177e4 | 47 | #define _COMPONENT ACPI_TABLES |
4be44fcd | 48 | ACPI_MODULE_NAME("tbrsdt") |
1da177e4 LT |
49 | |
50 | /******************************************************************************* | |
51 | * | |
52 | * FUNCTION: acpi_tb_verify_rsdp | |
53 | * | |
54 | * PARAMETERS: Address - RSDP (Pointer to RSDT) | |
55 | * | |
56 | * RETURN: Status | |
57 | * | |
58 | * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table) | |
59 | * | |
60 | ******************************************************************************/ | |
4be44fcd | 61 | acpi_status acpi_tb_verify_rsdp(struct acpi_pointer *address) |
1da177e4 | 62 | { |
4be44fcd LB |
63 | struct acpi_table_desc table_info; |
64 | acpi_status status; | |
65 | struct rsdp_descriptor *rsdp; | |
1da177e4 | 66 | |
b229cf92 | 67 | ACPI_FUNCTION_TRACE(tb_verify_rsdp); |
1da177e4 LT |
68 | |
69 | switch (address->pointer_type) { | |
70 | case ACPI_LOGICAL_POINTER: | |
71 | ||
72 | rsdp = address->pointer.logical; | |
73 | break; | |
74 | ||
75 | case ACPI_PHYSICAL_POINTER: | |
76 | /* | |
77 | * Obtain access to the RSDP structure | |
78 | */ | |
4be44fcd LB |
79 | status = acpi_os_map_memory(address->pointer.physical, |
80 | sizeof(struct rsdp_descriptor), | |
81 | (void *)&rsdp); | |
82 | if (ACPI_FAILURE(status)) { | |
83 | return_ACPI_STATUS(status); | |
1da177e4 LT |
84 | } |
85 | break; | |
86 | ||
87 | default: | |
4be44fcd | 88 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
89 | } |
90 | ||
f9f4601f | 91 | /* Verify RSDP signature and checksum */ |
1da177e4 | 92 | |
4be44fcd LB |
93 | status = acpi_tb_validate_rsdp(rsdp); |
94 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
95 | goto cleanup; |
96 | } | |
97 | ||
1da177e4 LT |
98 | /* The RSDP supplied is OK */ |
99 | ||
4be44fcd LB |
100 | table_info.pointer = ACPI_CAST_PTR(struct acpi_table_header, rsdp); |
101 | table_info.length = sizeof(struct rsdp_descriptor); | |
102 | table_info.allocation = ACPI_MEM_MAPPED; | |
1da177e4 LT |
103 | |
104 | /* Save the table pointers and allocation info */ | |
105 | ||
b229cf92 | 106 | status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_RSDP, &table_info); |
4be44fcd | 107 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
108 | goto cleanup; |
109 | } | |
110 | ||
111 | /* Save the RSDP in a global for easy access */ | |
112 | ||
4be44fcd LB |
113 | acpi_gbl_RSDP = |
114 | ACPI_CAST_PTR(struct rsdp_descriptor, table_info.pointer); | |
115 | return_ACPI_STATUS(status); | |
1da177e4 LT |
116 | |
117 | /* Error exit */ | |
4be44fcd | 118 | cleanup: |
1da177e4 LT |
119 | |
120 | if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) { | |
4be44fcd | 121 | acpi_os_unmap_memory(rsdp, sizeof(struct rsdp_descriptor)); |
1da177e4 | 122 | } |
4be44fcd | 123 | return_ACPI_STATUS(status); |
1da177e4 LT |
124 | } |
125 | ||
1da177e4 LT |
126 | /******************************************************************************* |
127 | * | |
128 | * FUNCTION: acpi_tb_get_rsdt_address | |
129 | * | |
44f6c012 | 130 | * PARAMETERS: out_address - Where the address is returned |
1da177e4 | 131 | * |
44f6c012 | 132 | * RETURN: None, Address |
1da177e4 | 133 | * |
73459f73 RM |
134 | * DESCRIPTION: Extract the address of either the RSDT or XSDT, depending on the |
135 | * version of the RSDP and whether the XSDT pointer is valid | |
1da177e4 LT |
136 | * |
137 | ******************************************************************************/ | |
138 | ||
4be44fcd | 139 | void acpi_tb_get_rsdt_address(struct acpi_pointer *out_address) |
1da177e4 LT |
140 | { |
141 | ||
4be44fcd | 142 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 143 | |
4be44fcd LB |
144 | out_address->pointer_type = |
145 | acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING; | |
1da177e4 | 146 | |
73459f73 RM |
147 | /* Use XSDT if it is present */ |
148 | ||
149 | if ((acpi_gbl_RSDP->revision >= 2) && | |
4be44fcd | 150 | acpi_gbl_RSDP->xsdt_physical_address) { |
44f6c012 | 151 | out_address->pointer.value = |
4be44fcd | 152 | acpi_gbl_RSDP->xsdt_physical_address; |
73459f73 | 153 | acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT; |
4be44fcd | 154 | } else { |
73459f73 RM |
155 | /* No XSDT, use the RSDT */ |
156 | ||
4be44fcd LB |
157 | out_address->pointer.value = |
158 | acpi_gbl_RSDP->rsdt_physical_address; | |
73459f73 | 159 | acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT; |
1da177e4 LT |
160 | } |
161 | } | |
162 | ||
1da177e4 LT |
163 | /******************************************************************************* |
164 | * | |
165 | * FUNCTION: acpi_tb_validate_rsdt | |
166 | * | |
167 | * PARAMETERS: table_ptr - Addressable pointer to the RSDT. | |
168 | * | |
169 | * RETURN: Status | |
170 | * | |
171 | * DESCRIPTION: Validate signature for the RSDT or XSDT | |
172 | * | |
173 | ******************************************************************************/ | |
174 | ||
4be44fcd | 175 | acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr) |
1da177e4 | 176 | { |
b229cf92 | 177 | char *signature; |
1da177e4 | 178 | |
4a90c7e8 | 179 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 180 | |
b229cf92 BM |
181 | /* Search for appropriate signature, RSDT or XSDT */ |
182 | ||
73459f73 | 183 | if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { |
b229cf92 | 184 | signature = RSDT_SIG; |
4be44fcd | 185 | } else { |
b229cf92 | 186 | signature = XSDT_SIG; |
1da177e4 LT |
187 | } |
188 | ||
b229cf92 | 189 | if (!ACPI_COMPARE_NAME(table_ptr->signature, signature)) { |
52fc0b02 | 190 | |
1da177e4 LT |
191 | /* Invalid RSDT or XSDT signature */ |
192 | ||
b8e4d893 BM |
193 | ACPI_ERROR((AE_INFO, |
194 | "Invalid signature where RSDP indicates RSDT/XSDT should be located. RSDP:")); | |
1da177e4 | 195 | |
4be44fcd | 196 | ACPI_DUMP_BUFFER(acpi_gbl_RSDP, 20); |
1da177e4 | 197 | |
b8e4d893 BM |
198 | ACPI_ERROR((AE_INFO, |
199 | "RSDT/XSDT signature at %X (%p) is invalid", | |
200 | acpi_gbl_RSDP->rsdt_physical_address, | |
201 | (void *)(acpi_native_uint) acpi_gbl_RSDP-> | |
202 | rsdt_physical_address)); | |
1da177e4 | 203 | |
73459f73 | 204 | if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { |
b8e4d893 | 205 | ACPI_ERROR((AE_INFO, "Looking for RSDT")); |
4be44fcd | 206 | } else { |
b8e4d893 | 207 | ACPI_ERROR((AE_INFO, "Looking for XSDT")); |
1da177e4 LT |
208 | } |
209 | ||
4be44fcd | 210 | ACPI_DUMP_BUFFER((char *)table_ptr, 48); |
1da177e4 LT |
211 | return (AE_BAD_SIGNATURE); |
212 | } | |
213 | ||
214 | return (AE_OK); | |
215 | } | |
216 | ||
1da177e4 LT |
217 | /******************************************************************************* |
218 | * | |
219 | * FUNCTION: acpi_tb_get_table_rsdt | |
220 | * | |
221 | * PARAMETERS: None | |
222 | * | |
223 | * RETURN: Status | |
224 | * | |
225 | * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table) | |
226 | * | |
227 | ******************************************************************************/ | |
228 | ||
4be44fcd | 229 | acpi_status acpi_tb_get_table_rsdt(void) |
1da177e4 | 230 | { |
4be44fcd LB |
231 | struct acpi_table_desc table_info; |
232 | acpi_status status; | |
233 | struct acpi_pointer address; | |
1da177e4 | 234 | |
b229cf92 | 235 | ACPI_FUNCTION_TRACE(tb_get_table_rsdt); |
1da177e4 LT |
236 | |
237 | /* Get the RSDT/XSDT via the RSDP */ | |
238 | ||
4be44fcd | 239 | acpi_tb_get_rsdt_address(&address); |
1da177e4 | 240 | |
b229cf92 | 241 | table_info.type = ACPI_TABLE_ID_XSDT; |
4be44fcd LB |
242 | status = acpi_tb_get_table(&address, &table_info); |
243 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
244 | ACPI_EXCEPTION((AE_INFO, status, |
245 | "Could not get the RSDT/XSDT")); | |
4be44fcd | 246 | return_ACPI_STATUS(status); |
1da177e4 LT |
247 | } |
248 | ||
4be44fcd | 249 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
50eca3eb | 250 | "RSDP located at %p, points to RSDT physical=%8.8X%8.8X\n", |
4be44fcd LB |
251 | acpi_gbl_RSDP, |
252 | ACPI_FORMAT_UINT64(address.pointer.value))); | |
1da177e4 LT |
253 | |
254 | /* Check the RSDT or XSDT signature */ | |
255 | ||
4be44fcd LB |
256 | status = acpi_tb_validate_rsdt(table_info.pointer); |
257 | if (ACPI_FAILURE(status)) { | |
258 | return_ACPI_STATUS(status); | |
1da177e4 LT |
259 | } |
260 | ||
261 | /* Get the number of tables defined in the RSDT or XSDT */ | |
262 | ||
4be44fcd LB |
263 | acpi_gbl_rsdt_table_count = acpi_tb_get_table_count(acpi_gbl_RSDP, |
264 | table_info.pointer); | |
1da177e4 LT |
265 | |
266 | /* Convert and/or copy to an XSDT structure */ | |
267 | ||
4be44fcd LB |
268 | status = acpi_tb_convert_to_xsdt(&table_info); |
269 | if (ACPI_FAILURE(status)) { | |
270 | return_ACPI_STATUS(status); | |
1da177e4 LT |
271 | } |
272 | ||
273 | /* Save the table pointers and allocation info */ | |
274 | ||
b229cf92 | 275 | status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info); |
4be44fcd LB |
276 | if (ACPI_FAILURE(status)) { |
277 | return_ACPI_STATUS(status); | |
1da177e4 LT |
278 | } |
279 | ||
793c2388 BM |
280 | acpi_gbl_XSDT = |
281 | ACPI_CAST_PTR(struct xsdt_descriptor, table_info.pointer); | |
1da177e4 | 282 | |
4be44fcd LB |
283 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT)); |
284 | return_ACPI_STATUS(status); | |
1da177e4 | 285 | } |