blob: 13c6ddb2f5466c048ab984c0b1bc7b973bb68e22 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
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
65acpi_status
66acpi_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 */
Robert Moore44f6c012005-04-18 22:49:35 -040087 status = acpi_os_map_memory (address->pointer.physical,
88 sizeof (struct rsdp_descriptor),
89 (void *) &rsdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 if (ACPI_FAILURE (status)) {
91 return_ACPI_STATUS (status);
92 }
93 break;
94
95 default:
96 return_ACPI_STATUS (AE_BAD_PARAMETER);
97 }
98
99 /*
100 * The signature and checksum must both be correct
101 */
102 if (ACPI_STRNCMP ((char *) rsdp, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0) {
103 /* Nope, BAD Signature */
104
105 status = AE_BAD_SIGNATURE;
106 goto cleanup;
107 }
108
109 /* Check the standard checksum */
110
111 if (acpi_tb_checksum (rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
112 status = AE_BAD_CHECKSUM;
113 goto cleanup;
114 }
115
116 /* Check extended checksum if table version >= 2 */
117
118 if (rsdp->revision >= 2) {
119 if (acpi_tb_checksum (rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0) {
120 status = AE_BAD_CHECKSUM;
121 goto cleanup;
122 }
123 }
124
125 /* The RSDP supplied is OK */
126
127 table_info.pointer = ACPI_CAST_PTR (struct acpi_table_header, rsdp);
128 table_info.length = sizeof (struct rsdp_descriptor);
129 table_info.allocation = ACPI_MEM_MAPPED;
130
131 /* Save the table pointers and allocation info */
132
133 status = acpi_tb_init_table_descriptor (ACPI_TABLE_RSDP, &table_info);
134 if (ACPI_FAILURE (status)) {
135 goto cleanup;
136 }
137
138 /* Save the RSDP in a global for easy access */
139
140 acpi_gbl_RSDP = ACPI_CAST_PTR (struct rsdp_descriptor, table_info.pointer);
141 return_ACPI_STATUS (status);
142
143
144 /* Error exit */
145cleanup:
146
147 if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) {
148 acpi_os_unmap_memory (rsdp, sizeof (struct rsdp_descriptor));
149 }
150 return_ACPI_STATUS (status);
151}
152
153
154/*******************************************************************************
155 *
156 * FUNCTION: acpi_tb_get_rsdt_address
157 *
Robert Moore44f6c012005-04-18 22:49:35 -0400158 * PARAMETERS: out_address - Where the address is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 *
Robert Moore44f6c012005-04-18 22:49:35 -0400160 * RETURN: None, Address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 *
Robert Moore73459f72005-06-24 00:00:00 -0400162 * DESCRIPTION: Extract the address of either the RSDT or XSDT, depending on the
163 * version of the RSDP and whether the XSDT pointer is valid
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 *
165 ******************************************************************************/
166
167void
168acpi_tb_get_rsdt_address (
169 struct acpi_pointer *out_address)
170{
171
172 ACPI_FUNCTION_ENTRY ();
173
174
175 out_address->pointer_type = acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
176
Robert Moore73459f72005-06-24 00:00:00 -0400177 /* Use XSDT if it is present */
178
179 if ((acpi_gbl_RSDP->revision >= 2) &&
180 acpi_gbl_RSDP->xsdt_physical_address) {
Robert Moore44f6c012005-04-18 22:49:35 -0400181 out_address->pointer.value =
182 acpi_gbl_RSDP->xsdt_physical_address;
Robert Moore73459f72005-06-24 00:00:00 -0400183 acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT;
184 }
185 else {
186 /* No XSDT, use the RSDT */
187
188 out_address->pointer.value = acpi_gbl_RSDP->rsdt_physical_address;
189 acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 }
191}
192
193
194/*******************************************************************************
195 *
196 * FUNCTION: acpi_tb_validate_rsdt
197 *
198 * PARAMETERS: table_ptr - Addressable pointer to the RSDT.
199 *
200 * RETURN: Status
201 *
202 * DESCRIPTION: Validate signature for the RSDT or XSDT
203 *
204 ******************************************************************************/
205
206acpi_status
207acpi_tb_validate_rsdt (
208 struct acpi_table_header *table_ptr)
209{
210 int no_match;
211
212
213 ACPI_FUNCTION_NAME ("tb_validate_rsdt");
214
215
216 /*
Robert Moore73459f72005-06-24 00:00:00 -0400217 * Search for appropriate signature, RSDT or XSDT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 */
Robert Moore73459f72005-06-24 00:00:00 -0400219 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 no_match = ACPI_STRNCMP ((char *) table_ptr, RSDT_SIG,
221 sizeof (RSDT_SIG) -1);
222 }
223 else {
224 no_match = ACPI_STRNCMP ((char *) table_ptr, XSDT_SIG,
225 sizeof (XSDT_SIG) -1);
226 }
227
228 if (no_match) {
229 /* Invalid RSDT or XSDT signature */
230
Robert Moore44f6c012005-04-18 22:49:35 -0400231 ACPI_REPORT_ERROR ((
232 "Invalid signature where RSDP indicates RSDT/XSDT should be located\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 ACPI_DUMP_BUFFER (acpi_gbl_RSDP, 20);
235
236 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_ERROR,
237 "RSDT/XSDT signature at %X (%p) is invalid\n",
238 acpi_gbl_RSDP->rsdt_physical_address,
239 (void *) (acpi_native_uint) acpi_gbl_RSDP->rsdt_physical_address));
240
Robert Moore73459f72005-06-24 00:00:00 -0400241 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
242 ACPI_REPORT_ERROR (("Looking for RSDT\n"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 }
244 else {
Robert Moore73459f72005-06-24 00:00:00 -0400245 ACPI_REPORT_ERROR (("Looking for XSDT\n"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247
248 ACPI_DUMP_BUFFER ((char *) table_ptr, 48);
249
250 return (AE_BAD_SIGNATURE);
251 }
252
253 return (AE_OK);
254}
255
256
257/*******************************************************************************
258 *
259 * FUNCTION: acpi_tb_get_table_rsdt
260 *
261 * PARAMETERS: None
262 *
263 * RETURN: Status
264 *
265 * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
266 *
267 ******************************************************************************/
268
269acpi_status
270acpi_tb_get_table_rsdt (
271 void)
272{
273 struct acpi_table_desc table_info;
274 acpi_status status;
275 struct acpi_pointer address;
276
277
278 ACPI_FUNCTION_TRACE ("tb_get_table_rsdt");
279
280
281 /* Get the RSDT/XSDT via the RSDP */
282
283 acpi_tb_get_rsdt_address (&address);
284
285 table_info.type = ACPI_TABLE_XSDT;
286 status = acpi_tb_get_table (&address, &table_info);
287 if (ACPI_FAILURE (status)) {
288 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not get the RSDT/XSDT, %s\n",
289 acpi_format_exception (status)));
Robert Moore44f6c012005-04-18 22:49:35 -0400290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 return_ACPI_STATUS (status);
292 }
293
294 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
295 "RSDP located at %p, points to RSDT physical=%8.8X%8.8X \n",
296 acpi_gbl_RSDP,
297 ACPI_FORMAT_UINT64 (address.pointer.value)));
298
299 /* Check the RSDT or XSDT signature */
300
301 status = acpi_tb_validate_rsdt (table_info.pointer);
302 if (ACPI_FAILURE (status)) {
303 return_ACPI_STATUS (status);
304 }
305
306 /* Get the number of tables defined in the RSDT or XSDT */
307
Robert Moore44f6c012005-04-18 22:49:35 -0400308 acpi_gbl_rsdt_table_count = acpi_tb_get_table_count (acpi_gbl_RSDP,
309 table_info.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 /* Convert and/or copy to an XSDT structure */
312
313 status = acpi_tb_convert_to_xsdt (&table_info);
314 if (ACPI_FAILURE (status)) {
315 return_ACPI_STATUS (status);
316 }
317
318 /* Save the table pointers and allocation info */
319
320 status = acpi_tb_init_table_descriptor (ACPI_TABLE_XSDT, &table_info);
321 if (ACPI_FAILURE (status)) {
322 return_ACPI_STATUS (status);
323 }
324
325 acpi_gbl_XSDT = ACPI_CAST_PTR (XSDT_DESCRIPTOR, table_info.pointer);
326
327 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
328 return_ACPI_STATUS (status);
329}
330
331