blob: abcb08c2592ae3f5ca128dfb4d60debd6f76ac9a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbrsdt - ACPI RSDT table utilities
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("tbrsdt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
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 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040061acpi_status acpi_tb_verify_rsdp(struct acpi_pointer *address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Len Brown4be44fc2005-08-05 00:44:28 -040063 struct acpi_table_desc table_info;
64 acpi_status status;
65 struct rsdp_descriptor *rsdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Bob Mooreb229cf92006-04-21 17:15:00 -040067 ACPI_FUNCTION_TRACE(tb_verify_rsdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
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 */
Len Brown4be44fc2005-08-05 00:44:28 -040079 status = acpi_os_map_memory(address->pointer.physical,
80 sizeof(struct rsdp_descriptor),
Bob Moore41195322006-05-26 16:36:00 -040081 ACPI_CAST_PTR(void, &rsdp));
Len Brown4be44fc2005-08-05 00:44:28 -040082 if (ACPI_FAILURE(status)) {
83 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85 break;
86
87 default:
Len Brown4be44fc2005-08-05 00:44:28 -040088 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90
Robert Mooref9f46012005-07-08 00:00:00 -040091 /* Verify RSDP signature and checksum */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Len Brown4be44fc2005-08-05 00:44:28 -040093 status = acpi_tb_validate_rsdp(rsdp);
94 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 goto cleanup;
96 }
97
Bob Moore41195322006-05-26 16:36:00 -040098 /* RSDP is ok. Init the table info */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Len Brown4be44fc2005-08-05 00:44:28 -0400100 table_info.pointer = ACPI_CAST_PTR(struct acpi_table_header, rsdp);
101 table_info.length = sizeof(struct rsdp_descriptor);
Bob Moore41195322006-05-26 16:36:00 -0400102
103 if (address->pointer_type == ACPI_PHYSICAL_POINTER) {
104 table_info.allocation = ACPI_MEM_MAPPED;
105 } else {
106 table_info.allocation = ACPI_MEM_NOT_ALLOCATED;
107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 /* Save the table pointers and allocation info */
110
Bob Mooreb229cf92006-04-21 17:15:00 -0400111 status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_RSDP, &table_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400112 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 goto cleanup;
114 }
115
116 /* Save the RSDP in a global for easy access */
117
Len Brown4be44fc2005-08-05 00:44:28 -0400118 acpi_gbl_RSDP =
119 ACPI_CAST_PTR(struct rsdp_descriptor, table_info.pointer);
120 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 /* Error exit */
Len Brown4be44fc2005-08-05 00:44:28 -0400123 cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) {
Len Brown4be44fc2005-08-05 00:44:28 -0400126 acpi_os_unmap_memory(rsdp, sizeof(struct rsdp_descriptor));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
Len Brown4be44fc2005-08-05 00:44:28 -0400128 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/*******************************************************************************
132 *
133 * FUNCTION: acpi_tb_get_rsdt_address
134 *
Robert Moore44f6c012005-04-18 22:49:35 -0400135 * PARAMETERS: out_address - Where the address is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 *
Robert Moore44f6c012005-04-18 22:49:35 -0400137 * RETURN: None, Address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 *
Robert Moore73459f72005-06-24 00:00:00 -0400139 * DESCRIPTION: Extract the address of either the RSDT or XSDT, depending on the
140 * version of the RSDP and whether the XSDT pointer is valid
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 *
142 ******************************************************************************/
143
Len Brown4be44fc2005-08-05 00:44:28 -0400144void acpi_tb_get_rsdt_address(struct acpi_pointer *out_address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146
Len Brown4be44fc2005-08-05 00:44:28 -0400147 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Len Brown4be44fc2005-08-05 00:44:28 -0400149 out_address->pointer_type =
150 acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Robert Moore73459f72005-06-24 00:00:00 -0400152 /* Use XSDT if it is present */
153
154 if ((acpi_gbl_RSDP->revision >= 2) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400155 acpi_gbl_RSDP->xsdt_physical_address) {
Robert Moore44f6c012005-04-18 22:49:35 -0400156 out_address->pointer.value =
Len Brown4be44fc2005-08-05 00:44:28 -0400157 acpi_gbl_RSDP->xsdt_physical_address;
Robert Moore73459f72005-06-24 00:00:00 -0400158 acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT;
Len Brown4be44fc2005-08-05 00:44:28 -0400159 } else {
Robert Moore73459f72005-06-24 00:00:00 -0400160 /* No XSDT, use the RSDT */
161
Len Brown4be44fc2005-08-05 00:44:28 -0400162 out_address->pointer.value =
163 acpi_gbl_RSDP->rsdt_physical_address;
Robert Moore73459f72005-06-24 00:00:00 -0400164 acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166}
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/*******************************************************************************
169 *
170 * FUNCTION: acpi_tb_validate_rsdt
171 *
172 * PARAMETERS: table_ptr - Addressable pointer to the RSDT.
173 *
174 * RETURN: Status
175 *
176 * DESCRIPTION: Validate signature for the RSDT or XSDT
177 *
178 ******************************************************************************/
179
Len Brown4be44fc2005-08-05 00:44:28 -0400180acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
Bob Mooreb229cf92006-04-21 17:15:00 -0400182 char *signature;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Bob Moore4a90c7e2006-01-13 16:22:00 -0500184 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Bob Mooreb229cf92006-04-21 17:15:00 -0400186 /* Search for appropriate signature, RSDT or XSDT */
187
Robert Moore73459f72005-06-24 00:00:00 -0400188 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400189 signature = RSDT_SIG;
Len Brown4be44fc2005-08-05 00:44:28 -0400190 } else {
Bob Mooreb229cf92006-04-21 17:15:00 -0400191 signature = XSDT_SIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193
Bob Mooreb229cf92006-04-21 17:15:00 -0400194 if (!ACPI_COMPARE_NAME(table_ptr->signature, signature)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 /* Invalid RSDT or XSDT signature */
197
Bob Mooreb8e4d892006-01-27 16:43:00 -0500198 ACPI_ERROR((AE_INFO,
199 "Invalid signature where RSDP indicates RSDT/XSDT should be located. RSDP:"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 ACPI_DUMP_BUFFER(acpi_gbl_RSDP, 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Bob Mooreb8e4d892006-01-27 16:43:00 -0500203 ACPI_ERROR((AE_INFO,
Bob Moore958dd242006-05-12 17:12:00 -0400204 "RSDT/XSDT signature at %X is invalid",
205 acpi_gbl_RSDP->rsdt_physical_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Robert Moore73459f72005-06-24 00:00:00 -0400207 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500208 ACPI_ERROR((AE_INFO, "Looking for RSDT"));
Len Brown4be44fc2005-08-05 00:44:28 -0400209 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500210 ACPI_ERROR((AE_INFO, "Looking for XSDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213 ACPI_DUMP_BUFFER((char *)table_ptr, 48);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 return (AE_BAD_SIGNATURE);
215 }
216
217 return (AE_OK);
218}
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/*******************************************************************************
221 *
222 * FUNCTION: acpi_tb_get_table_rsdt
223 *
224 * PARAMETERS: None
225 *
226 * RETURN: Status
227 *
228 * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
229 *
230 ******************************************************************************/
231
Len Brown4be44fc2005-08-05 00:44:28 -0400232acpi_status acpi_tb_get_table_rsdt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Len Brown4be44fc2005-08-05 00:44:28 -0400234 struct acpi_table_desc table_info;
235 acpi_status status;
236 struct acpi_pointer address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Bob Mooreb229cf92006-04-21 17:15:00 -0400238 ACPI_FUNCTION_TRACE(tb_get_table_rsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 /* Get the RSDT/XSDT via the RSDP */
241
Len Brown4be44fc2005-08-05 00:44:28 -0400242 acpi_tb_get_rsdt_address(&address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Bob Mooreb229cf92006-04-21 17:15:00 -0400244 table_info.type = ACPI_TABLE_ID_XSDT;
Len Brown4be44fc2005-08-05 00:44:28 -0400245 status = acpi_tb_get_table(&address, &table_info);
246 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500247 ACPI_EXCEPTION((AE_INFO, status,
248 "Could not get the RSDT/XSDT"));
Len Brown4be44fc2005-08-05 00:44:28 -0400249 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251
Len Brown4be44fc2005-08-05 00:44:28 -0400252 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore50eca3e2005-09-30 19:03:00 -0400253 "RSDP located at %p, points to RSDT physical=%8.8X%8.8X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400254 acpi_gbl_RSDP,
255 ACPI_FORMAT_UINT64(address.pointer.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 /* Check the RSDT or XSDT signature */
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 status = acpi_tb_validate_rsdt(table_info.pointer);
260 if (ACPI_FAILURE(status)) {
261 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
263
264 /* Get the number of tables defined in the RSDT or XSDT */
265
Len Brown4be44fc2005-08-05 00:44:28 -0400266 acpi_gbl_rsdt_table_count = acpi_tb_get_table_count(acpi_gbl_RSDP,
267 table_info.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269 /* Convert and/or copy to an XSDT structure */
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271 status = acpi_tb_convert_to_xsdt(&table_info);
272 if (ACPI_FAILURE(status)) {
273 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
275
276 /* Save the table pointers and allocation info */
277
Bob Mooreb229cf92006-04-21 17:15:00 -0400278 status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400279 if (ACPI_FAILURE(status)) {
280 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282
Bob Moore793c2382006-03-31 00:00:00 -0500283 acpi_gbl_XSDT =
284 ACPI_CAST_PTR(struct xsdt_descriptor, table_info.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Len Brown4be44fc2005-08-05 00:44:28 -0400286 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
287 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}