[ACPI] ACPICA 20060210
[firewire-audio.git] / drivers / acpi / tables / tbrsdt.c
blob946d2f2d611d205fea5f11c50bd90b55945c8fe3
1 /******************************************************************************
3 * Module Name: tbrsdt - ACPI RSDT table utilities
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2006, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/actables.h>
47 #define _COMPONENT ACPI_TABLES
48 ACPI_MODULE_NAME("tbrsdt")
50 /*******************************************************************************
52 * FUNCTION: acpi_tb_verify_rsdp
54 * PARAMETERS: Address - RSDP (Pointer to RSDT)
56 * RETURN: Status
58 * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
60 ******************************************************************************/
61 acpi_status acpi_tb_verify_rsdp(struct acpi_pointer *address)
63 struct acpi_table_desc table_info;
64 acpi_status status;
65 struct rsdp_descriptor *rsdp;
67 ACPI_FUNCTION_TRACE("tb_verify_rsdp");
69 switch (address->pointer_type) {
70 case ACPI_LOGICAL_POINTER:
72 rsdp = address->pointer.logical;
73 break;
75 case ACPI_PHYSICAL_POINTER:
77 * Obtain access to the RSDP structure
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);
85 break;
87 default:
88 return_ACPI_STATUS(AE_BAD_PARAMETER);
91 /* Verify RSDP signature and checksum */
93 status = acpi_tb_validate_rsdp(rsdp);
94 if (ACPI_FAILURE(status)) {
95 goto cleanup;
98 /* The RSDP supplied is OK */
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;
104 /* Save the table pointers and allocation info */
106 status = acpi_tb_init_table_descriptor(ACPI_TABLE_RSDP, &table_info);
107 if (ACPI_FAILURE(status)) {
108 goto cleanup;
111 /* Save the RSDP in a global for easy access */
113 acpi_gbl_RSDP =
114 ACPI_CAST_PTR(struct rsdp_descriptor, table_info.pointer);
115 return_ACPI_STATUS(status);
117 /* Error exit */
118 cleanup:
120 if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) {
121 acpi_os_unmap_memory(rsdp, sizeof(struct rsdp_descriptor));
123 return_ACPI_STATUS(status);
126 /*******************************************************************************
128 * FUNCTION: acpi_tb_get_rsdt_address
130 * PARAMETERS: out_address - Where the address is returned
132 * RETURN: None, Address
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
137 ******************************************************************************/
139 void acpi_tb_get_rsdt_address(struct acpi_pointer *out_address)
142 ACPI_FUNCTION_ENTRY();
144 out_address->pointer_type =
145 acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
147 /* Use XSDT if it is present */
149 if ((acpi_gbl_RSDP->revision >= 2) &&
150 acpi_gbl_RSDP->xsdt_physical_address) {
151 out_address->pointer.value =
152 acpi_gbl_RSDP->xsdt_physical_address;
153 acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT;
154 } else {
155 /* No XSDT, use the RSDT */
157 out_address->pointer.value =
158 acpi_gbl_RSDP->rsdt_physical_address;
159 acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT;
163 /*******************************************************************************
165 * FUNCTION: acpi_tb_validate_rsdt
167 * PARAMETERS: table_ptr - Addressable pointer to the RSDT.
169 * RETURN: Status
171 * DESCRIPTION: Validate signature for the RSDT or XSDT
173 ******************************************************************************/
175 acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
177 int no_match;
179 ACPI_FUNCTION_ENTRY();
182 * Search for appropriate signature, RSDT or XSDT
184 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
185 no_match = ACPI_STRNCMP((char *)table_ptr, RSDT_SIG,
186 sizeof(RSDT_SIG) - 1);
187 } else {
188 no_match = ACPI_STRNCMP((char *)table_ptr, XSDT_SIG,
189 sizeof(XSDT_SIG) - 1);
192 if (no_match) {
194 /* Invalid RSDT or XSDT signature */
196 ACPI_ERROR((AE_INFO,
197 "Invalid signature where RSDP indicates RSDT/XSDT should be located. RSDP:"));
199 ACPI_DUMP_BUFFER(acpi_gbl_RSDP, 20);
201 ACPI_ERROR((AE_INFO,
202 "RSDT/XSDT signature at %X (%p) is invalid",
203 acpi_gbl_RSDP->rsdt_physical_address,
204 (void *)(acpi_native_uint) acpi_gbl_RSDP->
205 rsdt_physical_address));
207 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
208 ACPI_ERROR((AE_INFO, "Looking for RSDT"));
209 } else {
210 ACPI_ERROR((AE_INFO, "Looking for XSDT"));
213 ACPI_DUMP_BUFFER((char *)table_ptr, 48);
214 return (AE_BAD_SIGNATURE);
217 return (AE_OK);
220 /*******************************************************************************
222 * FUNCTION: acpi_tb_get_table_rsdt
224 * PARAMETERS: None
226 * RETURN: Status
228 * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
230 ******************************************************************************/
232 acpi_status acpi_tb_get_table_rsdt(void)
234 struct acpi_table_desc table_info;
235 acpi_status status;
236 struct acpi_pointer address;
238 ACPI_FUNCTION_TRACE("tb_get_table_rsdt");
240 /* Get the RSDT/XSDT via the RSDP */
242 acpi_tb_get_rsdt_address(&address);
244 table_info.type = ACPI_TABLE_XSDT;
245 status = acpi_tb_get_table(&address, &table_info);
246 if (ACPI_FAILURE(status)) {
247 ACPI_EXCEPTION((AE_INFO, status,
248 "Could not get the RSDT/XSDT"));
249 return_ACPI_STATUS(status);
252 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
253 "RSDP located at %p, points to RSDT physical=%8.8X%8.8X\n",
254 acpi_gbl_RSDP,
255 ACPI_FORMAT_UINT64(address.pointer.value)));
257 /* Check the RSDT or XSDT signature */
259 status = acpi_tb_validate_rsdt(table_info.pointer);
260 if (ACPI_FAILURE(status)) {
261 return_ACPI_STATUS(status);
264 /* Get the number of tables defined in the RSDT or XSDT */
266 acpi_gbl_rsdt_table_count = acpi_tb_get_table_count(acpi_gbl_RSDP,
267 table_info.pointer);
269 /* Convert and/or copy to an XSDT structure */
271 status = acpi_tb_convert_to_xsdt(&table_info);
272 if (ACPI_FAILURE(status)) {
273 return_ACPI_STATUS(status);
276 /* Save the table pointers and allocation info */
278 status = acpi_tb_init_table_descriptor(ACPI_TABLE_XSDT, &table_info);
279 if (ACPI_FAILURE(status)) {
280 return_ACPI_STATUS(status);
283 acpi_gbl_XSDT = ACPI_CAST_PTR(XSDT_DESCRIPTOR, table_info.pointer);
285 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
286 return_ACPI_STATUS(status);