blob: 134e5dce0bc172d03cf3d788cebb2cf4daa65a80 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbgetall - Get all required ACPI tables
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("tbgetall")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Robert Moore44f6c012005-04-18 22:49:35 -040050/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040051static acpi_status
52acpi_tb_get_primary_table(struct acpi_pointer *address,
53 struct acpi_table_desc *table_info);
Robert Moore44f6c012005-04-18 22:49:35 -040054
55static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040056acpi_tb_get_secondary_table(struct acpi_pointer *address,
57 acpi_string signature,
58 struct acpi_table_desc *table_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_tb_get_primary_table
63 *
64 * PARAMETERS: Address - Physical address of table to retrieve
65 * *table_info - Where the table info is returned
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Maps the physical address of table into a logical address
70 *
71 ******************************************************************************/
72
Robert Moore44f6c012005-04-18 22:49:35 -040073static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040074acpi_tb_get_primary_table(struct acpi_pointer *address,
75 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Len Brown4be44fc2005-08-05 00:44:28 -040077 acpi_status status;
78 struct acpi_table_header header;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Len Brown4be44fc2005-08-05 00:44:28 -040080 ACPI_FUNCTION_TRACE("tb_get_primary_table");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 /* Ignore a NULL address in the RSDT */
83
84 if (!address->pointer.value) {
Len Brown4be44fc2005-08-05 00:44:28 -040085 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 }
87
Robert Moore44f6c012005-04-18 22:49:35 -040088 /* Get the header in order to get signature and table size */
89
Len Brown4be44fc2005-08-05 00:44:28 -040090 status = acpi_tb_get_table_header(address, &header);
91 if (ACPI_FAILURE(status)) {
92 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 }
94
95 /* Clear the table_info */
96
Len Brown4be44fc2005-08-05 00:44:28 -040097 ACPI_MEMSET(table_info, 0, sizeof(struct acpi_table_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 /*
100 * Check the table signature and make sure it is recognized.
101 * Also checks the header checksum
102 */
103 table_info->pointer = &header;
Len Brown4be44fc2005-08-05 00:44:28 -0400104 status = acpi_tb_recognize_table(table_info, ACPI_TABLE_PRIMARY);
105 if (ACPI_FAILURE(status)) {
106 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108
109 /* Get the entire table */
110
Len Brown4be44fc2005-08-05 00:44:28 -0400111 status = acpi_tb_get_table_body(address, &header, table_info);
112 if (ACPI_FAILURE(status)) {
113 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115
116 /* Install the table */
117
Len Brown4be44fc2005-08-05 00:44:28 -0400118 status = acpi_tb_install_table(table_info);
119 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/*******************************************************************************
123 *
124 * FUNCTION: acpi_tb_get_secondary_table
125 *
126 * PARAMETERS: Address - Physical address of table to retrieve
127 * *table_info - Where the table info is returned
128 *
129 * RETURN: Status
130 *
131 * DESCRIPTION: Maps the physical address of table into a logical address
132 *
133 ******************************************************************************/
134
Robert Moore44f6c012005-04-18 22:49:35 -0400135static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400136acpi_tb_get_secondary_table(struct acpi_pointer *address,
137 acpi_string signature,
138 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Len Brown4be44fc2005-08-05 00:44:28 -0400140 acpi_status status;
141 struct acpi_table_header header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Len Brown4be44fc2005-08-05 00:44:28 -0400143 ACPI_FUNCTION_TRACE_STR("tb_get_secondary_table", signature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 /* Get the header in order to match the signature */
146
Len Brown4be44fc2005-08-05 00:44:28 -0400147 status = acpi_tb_get_table_header(address, &header);
148 if (ACPI_FAILURE(status)) {
149 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 }
151
152 /* Signature must match request */
153
Len Brown4be44fc2005-08-05 00:44:28 -0400154 if (ACPI_STRNCMP(header.signature, signature, ACPI_NAME_SIZE)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500155 ACPI_ERROR((AE_INFO,
156 "Incorrect table signature - wanted [%s] found [%4.4s]",
157 signature, header.signature));
Len Brown4be44fc2005-08-05 00:44:28 -0400158 return_ACPI_STATUS(AE_BAD_SIGNATURE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160
161 /*
162 * Check the table signature and make sure it is recognized.
163 * Also checks the header checksum
164 */
165 table_info->pointer = &header;
Len Brown4be44fc2005-08-05 00:44:28 -0400166 status = acpi_tb_recognize_table(table_info, ACPI_TABLE_SECONDARY);
167 if (ACPI_FAILURE(status)) {
168 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 }
170
171 /* Get the entire table */
172
Len Brown4be44fc2005-08-05 00:44:28 -0400173 status = acpi_tb_get_table_body(address, &header, table_info);
174 if (ACPI_FAILURE(status)) {
175 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
177
178 /* Install the table */
179
Len Brown4be44fc2005-08-05 00:44:28 -0400180 status = acpi_tb_install_table(table_info);
181 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/*******************************************************************************
185 *
186 * FUNCTION: acpi_tb_get_required_tables
187 *
188 * PARAMETERS: None
189 *
190 * RETURN: Status
191 *
192 * DESCRIPTION: Load and validate tables other than the RSDT. The RSDT must
193 * already be loaded and validated.
194 *
195 * Get the minimum set of ACPI tables, namely:
196 *
197 * 1) FADT (via RSDT in loop below)
198 * 2) FACS (via FADT)
199 * 3) DSDT (via FADT)
200 *
201 ******************************************************************************/
202
Len Brown4be44fc2005-08-05 00:44:28 -0400203acpi_status acpi_tb_get_required_tables(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Len Brown4be44fc2005-08-05 00:44:28 -0400205 acpi_status status = AE_OK;
206 u32 i;
207 struct acpi_table_desc table_info;
208 struct acpi_pointer address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Len Brown4be44fc2005-08-05 00:44:28 -0400210 ACPI_FUNCTION_TRACE("tb_get_required_tables");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Len Brown4be44fc2005-08-05 00:44:28 -0400212 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%d ACPI tables in RSDT\n",
213 acpi_gbl_rsdt_table_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Len Brown4be44fc2005-08-05 00:44:28 -0400215 address.pointer_type = acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 /*
218 * Loop through all table pointers found in RSDT.
219 * This will NOT include the FACS and DSDT - we must get
220 * them after the loop.
221 *
222 * The only tables we are interested in getting here is the FADT and
223 * any SSDTs.
224 */
225 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
226 /* Get the table address from the common internal XSDT */
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228 address.pointer.value = acpi_gbl_XSDT->table_offset_entry[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 /*
231 * Get the tables needed by this subsystem (FADT and any SSDTs).
232 * NOTE: All other tables are completely ignored at this time.
233 */
Len Brown4be44fc2005-08-05 00:44:28 -0400234 status = acpi_tb_get_primary_table(&address, &table_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 if ((status != AE_OK) && (status != AE_TABLE_NOT_SUPPORTED)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500236 ACPI_WARNING((AE_INFO,
237 "%s, while getting table at %8.8X%8.8X",
238 acpi_format_exception(status),
239 ACPI_FORMAT_UINT64(address.pointer.
240 value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
242 }
243
244 /* We must have a FADT to continue */
245
246 if (!acpi_gbl_FADT) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500247 ACPI_ERROR((AE_INFO, "No FADT present in RSDT/XSDT"));
Len Brown4be44fc2005-08-05 00:44:28 -0400248 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250
251 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400252 * Convert the FADT to a common format. This allows earlier revisions of
253 * the table to coexist with newer versions, using common access code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 */
Len Brown4be44fc2005-08-05 00:44:28 -0400255 status = acpi_tb_convert_table_fadt();
256 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500257 ACPI_ERROR((AE_INFO,
258 "Could not convert FADT to internal common format"));
Len Brown4be44fc2005-08-05 00:44:28 -0400259 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
261
Robert Moore44f6c012005-04-18 22:49:35 -0400262 /* Get the FACS (Pointed to by the FADT) */
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 address.pointer.value = acpi_gbl_FADT->xfirmware_ctrl;
265
Len Brown4be44fc2005-08-05 00:44:28 -0400266 status = acpi_tb_get_secondary_table(&address, FACS_SIG, &table_info);
267 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500268 ACPI_EXCEPTION((AE_INFO, status,
269 "Could not get/install the FACS"));
Len Brown4be44fc2005-08-05 00:44:28 -0400270 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 }
272
273 /*
274 * Create the common FACS pointer table
275 * (Contains pointers to the original table)
276 */
Len Brown4be44fc2005-08-05 00:44:28 -0400277 status = acpi_tb_build_common_facs(&table_info);
278 if (ACPI_FAILURE(status)) {
279 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281
Robert Moore44f6c012005-04-18 22:49:35 -0400282 /* Get/install the DSDT (Pointed to by the FADT) */
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 address.pointer.value = acpi_gbl_FADT->Xdsdt;
285
Len Brown4be44fc2005-08-05 00:44:28 -0400286 status = acpi_tb_get_secondary_table(&address, DSDT_SIG, &table_info);
287 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500288 ACPI_ERROR((AE_INFO, "Could not get/install the DSDT"));
Len Brown4be44fc2005-08-05 00:44:28 -0400289 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
291
292 /* Set Integer Width (32/64) based upon DSDT revision */
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 acpi_ut_set_integer_width(acpi_gbl_DSDT->revision);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 /* Dump the entire DSDT */
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
299 "Hex dump of entire DSDT, size %d (0x%X), Integer width = %d\n",
300 acpi_gbl_DSDT->length, acpi_gbl_DSDT->length,
301 acpi_gbl_integer_bit_width));
Bob Moorec51a4de2005-11-17 13:07:00 -0500302
303 ACPI_DUMP_BUFFER(ACPI_CAST_PTR(u8, acpi_gbl_DSDT),
304 acpi_gbl_DSDT->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 /* Always delete the RSDP mapping, we are done with it */
307
Len Brown4be44fc2005-08-05 00:44:28 -0400308 acpi_tb_delete_tables_by_type(ACPI_TABLE_RSDP);
309 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}