blob: da2648bbdbc013ea1de77775cf37e26671120ced [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
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("tbxfroot")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Robert Moore44f6c012005-04-18 22:49:35 -040050/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040051static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040052acpi_tb_find_rsdp(struct acpi_table_desc *table_info, u32 flags);
Robert Moore44f6c012005-04-18 22:49:35 -040053
Len Brown4be44fc2005-08-05 00:44:28 -040054static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/*******************************************************************************
57 *
Robert Mooref9f46012005-07-08 00:00:00 -040058 * FUNCTION: acpi_tb_validate_rsdp
59 *
60 * PARAMETERS: Rsdp - Pointer to unvalidated RSDP
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: Validate the RSDP (ptr)
65 *
66 ******************************************************************************/
67
Len Brown4be44fc2005-08-05 00:44:28 -040068acpi_status acpi_tb_validate_rsdp(struct rsdp_descriptor *rsdp)
Robert Mooref9f46012005-07-08 00:00:00 -040069{
Len Brown4be44fc2005-08-05 00:44:28 -040070 ACPI_FUNCTION_ENTRY();
Robert Mooref9f46012005-07-08 00:00:00 -040071
72 /*
73 * The signature and checksum must both be correct
74 */
Len Brown4be44fc2005-08-05 00:44:28 -040075 if (ACPI_STRNCMP((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -040076
Robert Mooref9f46012005-07-08 00:00:00 -040077 /* Nope, BAD Signature */
78
79 return (AE_BAD_SIGNATURE);
80 }
81
82 /* Check the standard checksum */
83
Bob Moore793c2382006-03-31 00:00:00 -050084 if (acpi_tb_sum_table(rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
Robert Mooref9f46012005-07-08 00:00:00 -040085 return (AE_BAD_CHECKSUM);
86 }
87
88 /* Check extended checksum if table version >= 2 */
89
90 if ((rsdp->revision >= 2) &&
Bob Moore793c2382006-03-31 00:00:00 -050091 (acpi_tb_sum_table(rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0)) {
Robert Mooref9f46012005-07-08 00:00:00 -040092 return (AE_BAD_CHECKSUM);
93 }
94
95 return (AE_OK);
96}
97
Robert Mooref9f46012005-07-08 00:00:00 -040098/*******************************************************************************
99 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 * FUNCTION: acpi_tb_find_table
101 *
102 * PARAMETERS: Signature - String with ACPI table signature
103 * oem_id - String with the table OEM ID
Robert Moore44f6c012005-04-18 22:49:35 -0400104 * oem_table_id - String with the OEM Table ID
105 * table_ptr - Where the table pointer is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 *
107 * RETURN: Status
108 *
109 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
110 * Signature, OEM ID and OEM Table ID.
111 *
112 ******************************************************************************/
113
114acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400115acpi_tb_find_table(char *signature,
116 char *oem_id,
117 char *oem_table_id, struct acpi_table_header ** table_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Len Brown4be44fc2005-08-05 00:44:28 -0400119 acpi_status status;
120 struct acpi_table_header *table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Bob Mooreb229cf92006-04-21 17:15:00 -0400122 ACPI_FUNCTION_TRACE(tb_find_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /* Validate string lengths */
125
Len Brown4be44fc2005-08-05 00:44:28 -0400126 if ((ACPI_STRLEN(signature) > ACPI_NAME_SIZE) ||
127 (ACPI_STRLEN(oem_id) > sizeof(table->oem_id)) ||
128 (ACPI_STRLEN(oem_table_id) > sizeof(table->oem_table_id))) {
129 return_ACPI_STATUS(AE_AML_STRING_LIMIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Bob Mooreb229cf92006-04-21 17:15:00 -0400132 if (ACPI_COMPARE_NAME(signature, DSDT_SIG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 /*
134 * The DSDT pointer is contained in the FADT, not the RSDT.
135 * This code should suffice, because the only code that would perform
136 * a "find" on the DSDT is the data_table_region() AML opcode -- in
137 * which case, the DSDT is guaranteed to be already loaded.
138 * If this becomes insufficient, the FADT will have to be found first.
139 */
140 if (!acpi_gbl_DSDT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400141 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 table = acpi_gbl_DSDT;
Len Brown4be44fc2005-08-05 00:44:28 -0400144 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 /* Find the table */
146
Len Brown4be44fc2005-08-05 00:44:28 -0400147 status = acpi_get_firmware_table(signature, 1,
148 ACPI_LOGICAL_ADDRESSING,
149 &table);
150 if (ACPI_FAILURE(status)) {
151 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
153 }
154
155 /* Check oem_id and oem_table_id */
156
Bob Mooreb229cf92006-04-21 17:15:00 -0400157 if ((oem_id[0] &&
158 ACPI_STRNCMP(oem_id, table->oem_id,
159 sizeof(table->oem_id))) ||
160 (oem_table_id[0] &&
161 ACPI_STRNCMP(oem_table_id, table->oem_table_id,
162 sizeof(table->oem_table_id)))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400163 return_ACPI_STATUS(AE_AML_NAME_NOT_FOUND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
165
Len Brown4be44fc2005-08-05 00:44:28 -0400166 ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Found table [%4.4s]\n",
167 table->signature));
Robert Moore44f6c012005-04-18 22:49:35 -0400168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 *table_ptr = table;
Len Brown4be44fc2005-08-05 00:44:28 -0400170 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/*******************************************************************************
174 *
175 * FUNCTION: acpi_get_firmware_table
176 *
177 * PARAMETERS: Signature - Any ACPI table signature
178 * Instance - the non zero instance of the table, allows
179 * support for multiple tables of the same type
180 * Flags - Physical/Virtual support
181 * table_pointer - Where a buffer containing the table is
182 * returned
183 *
184 * RETURN: Status
185 *
186 * DESCRIPTION: This function is called to get an ACPI table. A buffer is
187 * allocated for the table and returned in table_pointer.
188 * This table will be a complete table including the header.
189 *
190 ******************************************************************************/
191
192acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400193acpi_get_firmware_table(acpi_string signature,
194 u32 instance,
195 u32 flags, struct acpi_table_header **table_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Len Brown4be44fc2005-08-05 00:44:28 -0400197 acpi_status status;
198 struct acpi_pointer address;
199 struct acpi_table_header *header = NULL;
200 struct acpi_table_desc *table_info = NULL;
201 struct acpi_table_desc *rsdt_info;
202 u32 table_count;
203 u32 i;
204 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Bob Mooreb229cf92006-04-21 17:15:00 -0400206 ACPI_FUNCTION_TRACE(acpi_get_firmware_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 /*
209 * Ensure that at least the table manager is initialized. We don't
210 * require that the entire ACPI subsystem is up for this interface.
211 * If we have a buffer, we must have a length too
212 */
Len Brown4be44fc2005-08-05 00:44:28 -0400213 if ((instance == 0) || (!signature) || (!table_pointer)) {
214 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
217 /* Ensure that we have a RSDP */
218
219 if (!acpi_gbl_RSDP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /* Get the RSDP */
222
Len Brown4be44fc2005-08-05 00:44:28 -0400223 status = acpi_os_get_root_pointer(flags, &address);
224 if (ACPI_FAILURE(status)) {
225 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "RSDP not found\n"));
226 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228
229 /* Map and validate the RSDP */
230
231 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
Len Brown4be44fc2005-08-05 00:44:28 -0400232 status = acpi_os_map_memory(address.pointer.physical,
233 sizeof(struct
234 rsdp_descriptor),
235 (void *)&acpi_gbl_RSDP);
236 if (ACPI_FAILURE(status)) {
237 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 }
Len Brown4be44fc2005-08-05 00:44:28 -0400239 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 acpi_gbl_RSDP = address.pointer.logical;
241 }
242
Robert Mooref9f46012005-07-08 00:00:00 -0400243 /* The RDSP signature and checksum must both be correct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Len Brown4be44fc2005-08-05 00:44:28 -0400245 status = acpi_tb_validate_rsdp(acpi_gbl_RSDP);
246 if (ACPI_FAILURE(status)) {
247 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
249 }
250
251 /* Get the RSDT address via the RSDP */
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253 acpi_tb_get_rsdt_address(&address);
254 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore50eca3e2005-09-30 19:03:00 -0400255 "RSDP located at %p, RSDT physical=%8.8X%8.8X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400256 acpi_gbl_RSDP,
257 ACPI_FORMAT_UINT64(address.pointer.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 /* Insert processor_mode flags */
260
261 address.pointer_type |= flags;
262
263 /* Get and validate the RSDT */
264
Bob Moore83135242006-10-03 00:00:00 -0400265 rsdt_info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_table_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 if (!rsdt_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400267 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 status = acpi_tb_get_table(&address, rsdt_info);
271 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 goto cleanup;
273 }
274
Len Brown4be44fc2005-08-05 00:44:28 -0400275 status = acpi_tb_validate_rsdt(rsdt_info->pointer);
276 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 goto cleanup;
278 }
279
280 /* Allocate a scratch table header and table descriptor */
281
Bob Moore83135242006-10-03 00:00:00 -0400282 header = ACPI_ALLOCATE(sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (!header) {
284 status = AE_NO_MEMORY;
285 goto cleanup;
286 }
287
Bob Moore83135242006-10-03 00:00:00 -0400288 table_info = ACPI_ALLOCATE(sizeof(struct acpi_table_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (!table_info) {
290 status = AE_NO_MEMORY;
291 goto cleanup;
292 }
293
294 /* Get the number of table pointers within the RSDT */
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296 table_count =
297 acpi_tb_get_table_count(acpi_gbl_RSDP, rsdt_info->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 address.pointer_type = acpi_gbl_table_flags | flags;
299
300 /*
301 * Search the RSDT/XSDT for the correct instance of the
302 * requested table
303 */
304 for (i = 0, j = 0; i < table_count; i++) {
Robert Moore73459f72005-06-24 00:00:00 -0400305 /*
306 * Get the next table pointer, handle RSDT vs. XSDT
307 * RSDT pointers are 32 bits, XSDT pointers are 64 bits
308 */
309 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400310 address.pointer.value =
311 (ACPI_CAST_PTR
Bob Moore793c2382006-03-31 00:00:00 -0500312 (struct rsdt_descriptor,
Len Brown4be44fc2005-08-05 00:44:28 -0400313 rsdt_info->pointer))->table_offset_entry[i];
314 } else {
315 address.pointer.value =
316 (ACPI_CAST_PTR
Bob Moore793c2382006-03-31 00:00:00 -0500317 (struct xsdt_descriptor,
Len Brown4be44fc2005-08-05 00:44:28 -0400318 rsdt_info->pointer))->table_offset_entry[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
320
321 /* Get the table header */
322
Len Brown4be44fc2005-08-05 00:44:28 -0400323 status = acpi_tb_get_table_header(&address, header);
324 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 goto cleanup;
326 }
327
328 /* Compare table signatures and table instance */
329
Bob Mooreb229cf92006-04-21 17:15:00 -0400330 if (ACPI_COMPARE_NAME(header->signature, signature)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 /* An instance of the table was found */
333
334 j++;
335 if (j >= instance) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 /* Found the correct instance, get the entire table */
338
Len Brown4be44fc2005-08-05 00:44:28 -0400339 status =
340 acpi_tb_get_table_body(&address, header,
341 table_info);
342 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 goto cleanup;
344 }
345
346 *table_pointer = table_info->pointer;
347 goto cleanup;
348 }
349 }
350 }
351
352 /* Did not find the table */
353
354 status = AE_NOT_EXIST;
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 cleanup:
Robert Moore88ac00f2005-05-26 00:00:00 -0400357 if (rsdt_info->pointer) {
Len Brown4be44fc2005-08-05 00:44:28 -0400358 acpi_os_unmap_memory(rsdt_info->pointer,
359 (acpi_size) rsdt_info->pointer->length);
Robert Moore88ac00f2005-05-26 00:00:00 -0400360 }
Bob Moore83135242006-10-03 00:00:00 -0400361 ACPI_FREE(rsdt_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363 if (header) {
Bob Moore83135242006-10-03 00:00:00 -0400364 ACPI_FREE(header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366 if (table_info) {
Bob Moore83135242006-10-03 00:00:00 -0400367 ACPI_FREE(table_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
Len Brown4be44fc2005-08-05 00:44:28 -0400369 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Bob Moore83135242006-10-03 00:00:00 -0400372ACPI_EXPORT_SYMBOL(acpi_get_firmware_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374/* TBD: Move to a new file */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#if ACPI_MACHINE_WIDTH != 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376/*******************************************************************************
377 *
378 * FUNCTION: acpi_find_root_pointer
379 *
Robert Moore44f6c012005-04-18 22:49:35 -0400380 * PARAMETERS: Flags - Logical/Physical addressing
381 * rsdp_address - Where to place the RSDP address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 *
383 * RETURN: Status, Physical address of the RSDP
384 *
385 * DESCRIPTION: Find the RSDP
386 *
387 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400388acpi_status acpi_find_root_pointer(u32 flags, struct acpi_pointer *rsdp_address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Len Brown4be44fc2005-08-05 00:44:28 -0400390 struct acpi_table_desc table_info;
391 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Bob Mooreb229cf92006-04-21 17:15:00 -0400393 ACPI_FUNCTION_TRACE(acpi_find_root_pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 /* Get the RSDP */
396
Len Brown4be44fc2005-08-05 00:44:28 -0400397 status = acpi_tb_find_rsdp(&table_info, flags);
398 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500399 ACPI_EXCEPTION((AE_INFO, status,
400 "RSDP structure not found - Flags=%X", flags));
Robert Moore44f6c012005-04-18 22:49:35 -0400401
Len Brown4be44fc2005-08-05 00:44:28 -0400402 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404
405 rsdp_address->pointer_type = ACPI_PHYSICAL_POINTER;
406 rsdp_address->pointer.physical = table_info.physical_address;
Len Brown4be44fc2005-08-05 00:44:28 -0400407 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
Bob Moore83135242006-10-03 00:00:00 -0400410ACPI_EXPORT_SYMBOL(acpi_find_root_pointer)
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412/*******************************************************************************
413 *
414 * FUNCTION: acpi_tb_scan_memory_for_rsdp
415 *
416 * PARAMETERS: start_address - Starting pointer for search
417 * Length - Maximum length to search
418 *
419 * RETURN: Pointer to the RSDP if found, otherwise NULL.
420 *
421 * DESCRIPTION: Search a block of memory for the RSDP signature
422 *
423 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400424static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
Len Brown4be44fc2005-08-05 00:44:28 -0400426 acpi_status status;
427 u8 *mem_rover;
428 u8 *end_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Bob Mooreb229cf92006-04-21 17:15:00 -0400430 ACPI_FUNCTION_TRACE(tb_scan_memory_for_rsdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 end_address = start_address + length;
433
434 /* Search from given start address for the requested length */
435
436 for (mem_rover = start_address; mem_rover < end_address;
Len Brown4be44fc2005-08-05 00:44:28 -0400437 mem_rover += ACPI_RSDP_SCAN_STEP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400438
Robert Mooref9f46012005-07-08 00:00:00 -0400439 /* The RSDP signature and checksum must both be correct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Len Brown4be44fc2005-08-05 00:44:28 -0400441 status =
442 acpi_tb_validate_rsdp(ACPI_CAST_PTR
443 (struct rsdp_descriptor, mem_rover));
444 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400445
Robert Mooref9f46012005-07-08 00:00:00 -0400446 /* Sig and checksum valid, we have found a real RSDP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Len Brown4be44fc2005-08-05 00:44:28 -0400448 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
449 "RSDP located at physical address %p\n",
450 mem_rover));
451 return_PTR(mem_rover);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 }
453
Robert Mooref9f46012005-07-08 00:00:00 -0400454 /* No sig match or bad checksum, keep searching */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456
457 /* Searched entire block, no RSDP was found */
458
Len Brown4be44fc2005-08-05 00:44:28 -0400459 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
460 "Searched entire block from %p, valid RSDP was not found\n",
461 start_address));
462 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463}
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465/*******************************************************************************
466 *
467 * FUNCTION: acpi_tb_find_rsdp
468 *
Robert Moore44f6c012005-04-18 22:49:35 -0400469 * PARAMETERS: table_info - Where the table info is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 * Flags - Current memory mode (logical vs.
471 * physical addressing)
472 *
473 * RETURN: Status, RSDP physical address
474 *
Bob Moore958dd242006-05-12 17:12:00 -0400475 * DESCRIPTION: Search lower 1_mbyte of memory for the root system descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 * pointer structure. If it is found, set *RSDP to point to it.
477 *
Bob Moore958dd242006-05-12 17:12:00 -0400478 * NOTE1: The RSDP must be either in the first 1_k of the Extended
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
480 * Only a 32-bit physical address is necessary.
481 *
482 * NOTE2: This function is always available, regardless of the
483 * initialization state of the rest of ACPI.
484 *
485 ******************************************************************************/
486
Robert Moore44f6c012005-04-18 22:49:35 -0400487static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400488acpi_tb_find_rsdp(struct acpi_table_desc *table_info, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
Len Brown4be44fc2005-08-05 00:44:28 -0400490 u8 *table_ptr;
491 u8 *mem_rover;
492 u32 physical_address;
493 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Bob Mooreb229cf92006-04-21 17:15:00 -0400495 ACPI_FUNCTION_TRACE(tb_find_rsdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400498 * Scan supports either logical addressing or physical addressing
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 */
500 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400501
Robert Moore44f6c012005-04-18 22:49:35 -0400502 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
503
Len Brown4be44fc2005-08-05 00:44:28 -0400504 status = acpi_os_map_memory((acpi_physical_address)
505 ACPI_EBDA_PTR_LOCATION,
506 ACPI_EBDA_PTR_LENGTH,
507 (void *)&table_ptr);
508 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500509 ACPI_ERROR((AE_INFO,
510 "Could not map memory at %8.8X for length %X",
511 ACPI_EBDA_PTR_LOCATION,
512 ACPI_EBDA_PTR_LENGTH));
Robert Moore44f6c012005-04-18 22:49:35 -0400513
Len Brown4be44fc2005-08-05 00:44:28 -0400514 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
516
Len Brown4be44fc2005-08-05 00:44:28 -0400517 ACPI_MOVE_16_TO_32(&physical_address, table_ptr);
Robert Moore44f6c012005-04-18 22:49:35 -0400518
519 /* Convert segment part to physical address */
520
521 physical_address <<= 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400522 acpi_os_unmap_memory(table_ptr, ACPI_EBDA_PTR_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 /* EBDA present? */
525
526 if (physical_address > 0x400) {
527 /*
Bob Moore958dd242006-05-12 17:12:00 -0400528 * 1b) Search EBDA paragraphs (EBDA is required to be a
Robert Moore44f6c012005-04-18 22:49:35 -0400529 * minimum of 1_k length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 */
Len Brown4be44fc2005-08-05 00:44:28 -0400531 status = acpi_os_map_memory((acpi_physical_address)
532 physical_address,
533 ACPI_EBDA_WINDOW_SIZE,
534 (void *)&table_ptr);
535 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500536 ACPI_ERROR((AE_INFO,
537 "Could not map memory at %8.8X for length %X",
538 physical_address,
539 ACPI_EBDA_WINDOW_SIZE));
Robert Moore44f6c012005-04-18 22:49:35 -0400540
Len Brown4be44fc2005-08-05 00:44:28 -0400541 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543
Len Brown4be44fc2005-08-05 00:44:28 -0400544 mem_rover = acpi_tb_scan_memory_for_rsdp(table_ptr,
545 ACPI_EBDA_WINDOW_SIZE);
546 acpi_os_unmap_memory(table_ptr, ACPI_EBDA_WINDOW_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 if (mem_rover) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400549
Robert Mooref9f46012005-07-08 00:00:00 -0400550 /* Return the physical address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Len Brown4be44fc2005-08-05 00:44:28 -0400552 physical_address +=
Bob Moore958dd242006-05-12 17:12:00 -0400553 (u32) ACPI_PTR_DIFF(mem_rover, table_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Robert Moore44f6c012005-04-18 22:49:35 -0400555 table_info->physical_address =
Len Brown4be44fc2005-08-05 00:44:28 -0400556 (acpi_physical_address) physical_address;
557 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 }
559 }
560
561 /*
562 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
563 */
Len Brown4be44fc2005-08-05 00:44:28 -0400564 status = acpi_os_map_memory((acpi_physical_address)
565 ACPI_HI_RSDP_WINDOW_BASE,
566 ACPI_HI_RSDP_WINDOW_SIZE,
567 (void *)&table_ptr);
Robert Moore44f6c012005-04-18 22:49:35 -0400568
Len Brown4be44fc2005-08-05 00:44:28 -0400569 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500570 ACPI_ERROR((AE_INFO,
571 "Could not map memory at %8.8X for length %X",
572 ACPI_HI_RSDP_WINDOW_BASE,
573 ACPI_HI_RSDP_WINDOW_SIZE));
Robert Moore44f6c012005-04-18 22:49:35 -0400574
Len Brown4be44fc2005-08-05 00:44:28 -0400575 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577
Len Brown4be44fc2005-08-05 00:44:28 -0400578 mem_rover =
579 acpi_tb_scan_memory_for_rsdp(table_ptr,
580 ACPI_HI_RSDP_WINDOW_SIZE);
581 acpi_os_unmap_memory(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 if (mem_rover) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400584
Robert Mooref9f46012005-07-08 00:00:00 -0400585 /* Return the physical address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Bob Moore958dd242006-05-12 17:12:00 -0400587 physical_address = (u32)
588 (ACPI_HI_RSDP_WINDOW_BASE +
589 ACPI_PTR_DIFF(mem_rover, table_ptr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Robert Moore44f6c012005-04-18 22:49:35 -0400591 table_info->physical_address =
Len Brown4be44fc2005-08-05 00:44:28 -0400592 (acpi_physical_address) physical_address;
593 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
595 }
596
597 /*
598 * Physical addressing
599 */
600 else {
Robert Moore44f6c012005-04-18 22:49:35 -0400601 /* 1a) Get the location of the EBDA */
602
Len Brown4be44fc2005-08-05 00:44:28 -0400603 ACPI_MOVE_16_TO_32(&physical_address, ACPI_EBDA_PTR_LOCATION);
604 physical_address <<= 4; /* Convert segment to physical address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 /* EBDA present? */
607
608 if (physical_address > 0x400) {
609 /*
Bob Moore958dd242006-05-12 17:12:00 -0400610 * 1b) Search EBDA paragraphs (EBDA is required to be a minimum of
Robert Moore44f6c012005-04-18 22:49:35 -0400611 * 1_k length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 */
Len Brown4be44fc2005-08-05 00:44:28 -0400613 mem_rover =
614 acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
615 (physical_address),
616 ACPI_EBDA_WINDOW_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 if (mem_rover) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400618
Robert Mooref9f46012005-07-08 00:00:00 -0400619 /* Return the physical address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Len Brown4be44fc2005-08-05 00:44:28 -0400621 table_info->physical_address =
622 ACPI_TO_INTEGER(mem_rover);
623 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 }
625 }
626
Robert Moore44f6c012005-04-18 22:49:35 -0400627 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
628
Len Brown4be44fc2005-08-05 00:44:28 -0400629 mem_rover =
630 acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
631 (ACPI_HI_RSDP_WINDOW_BASE),
632 ACPI_HI_RSDP_WINDOW_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 if (mem_rover) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /* Found it, return the physical address */
636
Len Brown4be44fc2005-08-05 00:44:28 -0400637 table_info->physical_address =
638 ACPI_TO_INTEGER(mem_rover);
639 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641 }
642
Robert Mooref9f46012005-07-08 00:00:00 -0400643 /* A valid RSDP was not found */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Bob Mooreb8e4d892006-01-27 16:43:00 -0500645 ACPI_ERROR((AE_INFO, "No valid RSDP was found"));
Len Brown4be44fc2005-08-05 00:44:28 -0400646 return_ACPI_STATUS(AE_NOT_FOUND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648
649#endif