Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: tbrsdt - ACPI RSDT table utilities | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | |
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 | ||
44 | ||
45 | #include <acpi/acpi.h> | |
46 | #include <acpi/actables.h> | |
47 | ||
48 | ||
49 | #define _COMPONENT ACPI_TABLES | |
50 | ACPI_MODULE_NAME ("tbrsdt") | |
51 | ||
52 | ||
53 | /******************************************************************************* | |
54 | * | |
55 | * FUNCTION: acpi_tb_verify_rsdp | |
56 | * | |
57 | * PARAMETERS: Address - RSDP (Pointer to RSDT) | |
58 | * | |
59 | * RETURN: Status | |
60 | * | |
61 | * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table) | |
62 | * | |
63 | ******************************************************************************/ | |
64 | ||
65 | acpi_status | |
66 | acpi_tb_verify_rsdp ( | |
67 | struct acpi_pointer *address) | |
68 | { | |
69 | struct acpi_table_desc table_info; | |
70 | acpi_status status; | |
71 | struct rsdp_descriptor *rsdp; | |
72 | ||
73 | ||
74 | ACPI_FUNCTION_TRACE ("tb_verify_rsdp"); | |
75 | ||
76 | ||
77 | switch (address->pointer_type) { | |
78 | case ACPI_LOGICAL_POINTER: | |
79 | ||
80 | rsdp = address->pointer.logical; | |
81 | break; | |
82 | ||
83 | case ACPI_PHYSICAL_POINTER: | |
84 | /* | |
85 | * Obtain access to the RSDP structure | |
86 | */ | |
44f6c012 RM |
87 | status = acpi_os_map_memory (address->pointer.physical, |
88 | sizeof (struct rsdp_descriptor), | |
89 | (void *) &rsdp); | |
1da177e4 LT |
90 | if (ACPI_FAILURE (status)) { |
91 | return_ACPI_STATUS (status); | |
92 | } | |
93 | break; | |
94 | ||
95 | default: | |
96 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
97 | } | |
98 | ||
f9f4601f | 99 | /* Verify RSDP signature and checksum */ |
1da177e4 | 100 | |
f9f4601f RM |
101 | status = acpi_tb_validate_rsdp (rsdp); |
102 | if (ACPI_FAILURE (status)) { | |
1da177e4 LT |
103 | goto cleanup; |
104 | } | |
105 | ||
1da177e4 LT |
106 | /* The RSDP supplied is OK */ |
107 | ||
108 | table_info.pointer = ACPI_CAST_PTR (struct acpi_table_header, rsdp); | |
109 | table_info.length = sizeof (struct rsdp_descriptor); | |
110 | table_info.allocation = ACPI_MEM_MAPPED; | |
111 | ||
112 | /* Save the table pointers and allocation info */ | |
113 | ||
114 | status = acpi_tb_init_table_descriptor (ACPI_TABLE_RSDP, &table_info); | |
115 | if (ACPI_FAILURE (status)) { | |
116 | goto cleanup; | |
117 | } | |
118 | ||
119 | /* Save the RSDP in a global for easy access */ | |
120 | ||
121 | acpi_gbl_RSDP = ACPI_CAST_PTR (struct rsdp_descriptor, table_info.pointer); | |
122 | return_ACPI_STATUS (status); | |
123 | ||
124 | ||
125 | /* Error exit */ | |
126 | cleanup: | |
127 | ||
128 | if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) { | |
129 | acpi_os_unmap_memory (rsdp, sizeof (struct rsdp_descriptor)); | |
130 | } | |
131 | return_ACPI_STATUS (status); | |
132 | } | |
133 | ||
134 | ||
135 | /******************************************************************************* | |
136 | * | |
137 | * FUNCTION: acpi_tb_get_rsdt_address | |
138 | * | |
44f6c012 | 139 | * PARAMETERS: out_address - Where the address is returned |
1da177e4 | 140 | * |
44f6c012 | 141 | * RETURN: None, Address |
1da177e4 | 142 | * |
73459f73 RM |
143 | * DESCRIPTION: Extract the address of either the RSDT or XSDT, depending on the |
144 | * version of the RSDP and whether the XSDT pointer is valid | |
1da177e4 LT |
145 | * |
146 | ******************************************************************************/ | |
147 | ||
148 | void | |
149 | acpi_tb_get_rsdt_address ( | |
150 | struct acpi_pointer *out_address) | |
151 | { | |
152 | ||
153 | ACPI_FUNCTION_ENTRY (); | |
154 | ||
155 | ||
156 | out_address->pointer_type = acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING; | |
157 | ||
73459f73 RM |
158 | /* Use XSDT if it is present */ |
159 | ||
160 | if ((acpi_gbl_RSDP->revision >= 2) && | |
161 | acpi_gbl_RSDP->xsdt_physical_address) { | |
44f6c012 RM |
162 | out_address->pointer.value = |
163 | acpi_gbl_RSDP->xsdt_physical_address; | |
73459f73 RM |
164 | acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT; |
165 | } | |
166 | else { | |
167 | /* No XSDT, use the RSDT */ | |
168 | ||
169 | out_address->pointer.value = acpi_gbl_RSDP->rsdt_physical_address; | |
170 | acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT; | |
1da177e4 LT |
171 | } |
172 | } | |
173 | ||
174 | ||
175 | /******************************************************************************* | |
176 | * | |
177 | * FUNCTION: acpi_tb_validate_rsdt | |
178 | * | |
179 | * PARAMETERS: table_ptr - Addressable pointer to the RSDT. | |
180 | * | |
181 | * RETURN: Status | |
182 | * | |
183 | * DESCRIPTION: Validate signature for the RSDT or XSDT | |
184 | * | |
185 | ******************************************************************************/ | |
186 | ||
187 | acpi_status | |
188 | acpi_tb_validate_rsdt ( | |
189 | struct acpi_table_header *table_ptr) | |
190 | { | |
191 | int no_match; | |
192 | ||
193 | ||
194 | ACPI_FUNCTION_NAME ("tb_validate_rsdt"); | |
195 | ||
196 | ||
197 | /* | |
73459f73 | 198 | * Search for appropriate signature, RSDT or XSDT |
1da177e4 | 199 | */ |
73459f73 | 200 | if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { |
1da177e4 LT |
201 | no_match = ACPI_STRNCMP ((char *) table_ptr, RSDT_SIG, |
202 | sizeof (RSDT_SIG) -1); | |
203 | } | |
204 | else { | |
205 | no_match = ACPI_STRNCMP ((char *) table_ptr, XSDT_SIG, | |
206 | sizeof (XSDT_SIG) -1); | |
207 | } | |
208 | ||
209 | if (no_match) { | |
210 | /* Invalid RSDT or XSDT signature */ | |
211 | ||
44f6c012 RM |
212 | ACPI_REPORT_ERROR (( |
213 | "Invalid signature where RSDP indicates RSDT/XSDT should be located\n")); | |
1da177e4 LT |
214 | |
215 | ACPI_DUMP_BUFFER (acpi_gbl_RSDP, 20); | |
216 | ||
217 | ACPI_DEBUG_PRINT_RAW ((ACPI_DB_ERROR, | |
218 | "RSDT/XSDT signature at %X (%p) is invalid\n", | |
219 | acpi_gbl_RSDP->rsdt_physical_address, | |
220 | (void *) (acpi_native_uint) acpi_gbl_RSDP->rsdt_physical_address)); | |
221 | ||
73459f73 RM |
222 | if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { |
223 | ACPI_REPORT_ERROR (("Looking for RSDT\n")) | |
1da177e4 LT |
224 | } |
225 | else { | |
73459f73 | 226 | ACPI_REPORT_ERROR (("Looking for XSDT\n")) |
1da177e4 LT |
227 | } |
228 | ||
229 | ACPI_DUMP_BUFFER ((char *) table_ptr, 48); | |
230 | ||
231 | return (AE_BAD_SIGNATURE); | |
232 | } | |
233 | ||
234 | return (AE_OK); | |
235 | } | |
236 | ||
237 | ||
238 | /******************************************************************************* | |
239 | * | |
240 | * FUNCTION: acpi_tb_get_table_rsdt | |
241 | * | |
242 | * PARAMETERS: None | |
243 | * | |
244 | * RETURN: Status | |
245 | * | |
246 | * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table) | |
247 | * | |
248 | ******************************************************************************/ | |
249 | ||
250 | acpi_status | |
251 | acpi_tb_get_table_rsdt ( | |
252 | void) | |
253 | { | |
254 | struct acpi_table_desc table_info; | |
255 | acpi_status status; | |
256 | struct acpi_pointer address; | |
257 | ||
258 | ||
259 | ACPI_FUNCTION_TRACE ("tb_get_table_rsdt"); | |
260 | ||
261 | ||
262 | /* Get the RSDT/XSDT via the RSDP */ | |
263 | ||
264 | acpi_tb_get_rsdt_address (&address); | |
265 | ||
266 | table_info.type = ACPI_TABLE_XSDT; | |
267 | status = acpi_tb_get_table (&address, &table_info); | |
268 | if (ACPI_FAILURE (status)) { | |
269 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not get the RSDT/XSDT, %s\n", | |
270 | acpi_format_exception (status))); | |
44f6c012 | 271 | |
1da177e4 LT |
272 | return_ACPI_STATUS (status); |
273 | } | |
274 | ||
275 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | |
276 | "RSDP located at %p, points to RSDT physical=%8.8X%8.8X \n", | |
277 | acpi_gbl_RSDP, | |
278 | ACPI_FORMAT_UINT64 (address.pointer.value))); | |
279 | ||
280 | /* Check the RSDT or XSDT signature */ | |
281 | ||
282 | status = acpi_tb_validate_rsdt (table_info.pointer); | |
283 | if (ACPI_FAILURE (status)) { | |
284 | return_ACPI_STATUS (status); | |
285 | } | |
286 | ||
287 | /* Get the number of tables defined in the RSDT or XSDT */ | |
288 | ||
44f6c012 RM |
289 | acpi_gbl_rsdt_table_count = acpi_tb_get_table_count (acpi_gbl_RSDP, |
290 | table_info.pointer); | |
1da177e4 LT |
291 | |
292 | /* Convert and/or copy to an XSDT structure */ | |
293 | ||
294 | status = acpi_tb_convert_to_xsdt (&table_info); | |
295 | if (ACPI_FAILURE (status)) { | |
296 | return_ACPI_STATUS (status); | |
297 | } | |
298 | ||
299 | /* Save the table pointers and allocation info */ | |
300 | ||
301 | status = acpi_tb_init_table_descriptor (ACPI_TABLE_XSDT, &table_info); | |
302 | if (ACPI_FAILURE (status)) { | |
303 | return_ACPI_STATUS (status); | |
304 | } | |
305 | ||
306 | acpi_gbl_XSDT = ACPI_CAST_PTR (XSDT_DESCRIPTOR, table_info.pointer); | |
307 | ||
308 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT)); | |
309 | return_ACPI_STATUS (status); | |
310 | } | |
311 | ||
312 |