blob: 550284f5d1ed46415236afa3b93455a65668aa69 [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
Len Brown4be44fc2005-08-05 00:44:28 -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
Len Brown4be44fc2005-08-05 00:44:28 -0400132 if (!ACPI_STRNCMP(signature, DSDT_SIG, ACPI_NAME_SIZE)) {
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
Len Brown4be44fc2005-08-05 00:44:28 -0400157 if ((oem_id[0] && ACPI_STRNCMP(oem_id, table->oem_id,
158 sizeof(table->oem_id))) ||
159 (oem_table_id[0] && ACPI_STRNCMP(oem_table_id, table->oem_table_id,
160 sizeof(table->oem_table_id)))) {
161 return_ACPI_STATUS(AE_AML_NAME_NOT_FOUND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163
Len Brown4be44fc2005-08-05 00:44:28 -0400164 ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Found table [%4.4s]\n",
165 table->signature));
Robert Moore44f6c012005-04-18 22:49:35 -0400166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 *table_ptr = table;
Len Brown4be44fc2005-08-05 00:44:28 -0400168 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171/*******************************************************************************
172 *
173 * FUNCTION: acpi_get_firmware_table
174 *
175 * PARAMETERS: Signature - Any ACPI table signature
176 * Instance - the non zero instance of the table, allows
177 * support for multiple tables of the same type
178 * Flags - Physical/Virtual support
179 * table_pointer - Where a buffer containing the table is
180 * returned
181 *
182 * RETURN: Status
183 *
184 * DESCRIPTION: This function is called to get an ACPI table. A buffer is
185 * allocated for the table and returned in table_pointer.
186 * This table will be a complete table including the header.
187 *
188 ******************************************************************************/
189
190acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400191acpi_get_firmware_table(acpi_string signature,
192 u32 instance,
193 u32 flags, struct acpi_table_header **table_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Len Brown4be44fc2005-08-05 00:44:28 -0400195 acpi_status status;
196 struct acpi_pointer address;
197 struct acpi_table_header *header = NULL;
198 struct acpi_table_desc *table_info = NULL;
199 struct acpi_table_desc *rsdt_info;
200 u32 table_count;
201 u32 i;
202 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Len Brown4be44fc2005-08-05 00:44:28 -0400204 ACPI_FUNCTION_TRACE("acpi_get_firmware_table");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 /*
207 * Ensure that at least the table manager is initialized. We don't
208 * require that the entire ACPI subsystem is up for this interface.
209 * If we have a buffer, we must have a length too
210 */
Len Brown4be44fc2005-08-05 00:44:28 -0400211 if ((instance == 0) || (!signature) || (!table_pointer)) {
212 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214
215 /* Ensure that we have a RSDP */
216
217 if (!acpi_gbl_RSDP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 /* Get the RSDP */
220
Len Brown4be44fc2005-08-05 00:44:28 -0400221 status = acpi_os_get_root_pointer(flags, &address);
222 if (ACPI_FAILURE(status)) {
223 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "RSDP not found\n"));
224 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
226
227 /* Map and validate the RSDP */
228
229 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
Len Brown4be44fc2005-08-05 00:44:28 -0400230 status = acpi_os_map_memory(address.pointer.physical,
231 sizeof(struct
232 rsdp_descriptor),
233 (void *)&acpi_gbl_RSDP);
234 if (ACPI_FAILURE(status)) {
235 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
Len Brown4be44fc2005-08-05 00:44:28 -0400237 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 acpi_gbl_RSDP = address.pointer.logical;
239 }
240
Robert Mooref9f46012005-07-08 00:00:00 -0400241 /* The RDSP signature and checksum must both be correct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Len Brown4be44fc2005-08-05 00:44:28 -0400243 status = acpi_tb_validate_rsdp(acpi_gbl_RSDP);
244 if (ACPI_FAILURE(status)) {
245 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247 }
248
249 /* Get the RSDT address via the RSDP */
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251 acpi_tb_get_rsdt_address(&address);
252 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore50eca3e2005-09-30 19:03:00 -0400253 "RSDP located at %p, 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 /* Insert processor_mode flags */
258
259 address.pointer_type |= flags;
260
261 /* Get and validate the RSDT */
262
Bob Moore83135242006-10-03 00:00:00 -0400263 rsdt_info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_table_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 if (!rsdt_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400265 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267
Len Brown4be44fc2005-08-05 00:44:28 -0400268 status = acpi_tb_get_table(&address, rsdt_info);
269 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 goto cleanup;
271 }
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 status = acpi_tb_validate_rsdt(rsdt_info->pointer);
274 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 goto cleanup;
276 }
277
278 /* Allocate a scratch table header and table descriptor */
279
Bob Moore83135242006-10-03 00:00:00 -0400280 header = ACPI_ALLOCATE(sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 if (!header) {
282 status = AE_NO_MEMORY;
283 goto cleanup;
284 }
285
Bob Moore83135242006-10-03 00:00:00 -0400286 table_info = ACPI_ALLOCATE(sizeof(struct acpi_table_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 if (!table_info) {
288 status = AE_NO_MEMORY;
289 goto cleanup;
290 }
291
292 /* Get the number of table pointers within the RSDT */
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 table_count =
295 acpi_tb_get_table_count(acpi_gbl_RSDP, rsdt_info->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 address.pointer_type = acpi_gbl_table_flags | flags;
297
298 /*
299 * Search the RSDT/XSDT for the correct instance of the
300 * requested table
301 */
302 for (i = 0, j = 0; i < table_count; i++) {
Robert Moore73459f72005-06-24 00:00:00 -0400303 /*
304 * Get the next table pointer, handle RSDT vs. XSDT
305 * RSDT pointers are 32 bits, XSDT pointers are 64 bits
306 */
307 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400308 address.pointer.value =
309 (ACPI_CAST_PTR
Bob Moore793c2382006-03-31 00:00:00 -0500310 (struct rsdt_descriptor,
Len Brown4be44fc2005-08-05 00:44:28 -0400311 rsdt_info->pointer))->table_offset_entry[i];
312 } else {
313 address.pointer.value =
314 (ACPI_CAST_PTR
Bob Moore793c2382006-03-31 00:00:00 -0500315 (struct xsdt_descriptor,
Len Brown4be44fc2005-08-05 00:44:28 -0400316 rsdt_info->pointer))->table_offset_entry[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 }
318
319 /* Get the table header */
320
Len Brown4be44fc2005-08-05 00:44:28 -0400321 status = acpi_tb_get_table_header(&address, header);
322 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 goto cleanup;
324 }
325
326 /* Compare table signatures and table instance */
327
Len Brown4be44fc2005-08-05 00:44:28 -0400328 if (!ACPI_STRNCMP(header->signature, signature, ACPI_NAME_SIZE)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 /* An instance of the table was found */
331
332 j++;
333 if (j >= instance) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 /* Found the correct instance, get the entire table */
336
Len Brown4be44fc2005-08-05 00:44:28 -0400337 status =
338 acpi_tb_get_table_body(&address, header,
339 table_info);
340 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 goto cleanup;
342 }
343
344 *table_pointer = table_info->pointer;
345 goto cleanup;
346 }
347 }
348 }
349
350 /* Did not find the table */
351
352 status = AE_NOT_EXIST;
353
Len Brown4be44fc2005-08-05 00:44:28 -0400354 cleanup:
Robert Moore88ac00f2005-05-26 00:00:00 -0400355 if (rsdt_info->pointer) {
Len Brown4be44fc2005-08-05 00:44:28 -0400356 acpi_os_unmap_memory(rsdt_info->pointer,
357 (acpi_size) rsdt_info->pointer->length);
Robert Moore88ac00f2005-05-26 00:00:00 -0400358 }
Bob Moore83135242006-10-03 00:00:00 -0400359 ACPI_FREE(rsdt_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 if (header) {
Bob Moore83135242006-10-03 00:00:00 -0400362 ACPI_FREE(header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364 if (table_info) {
Bob Moore83135242006-10-03 00:00:00 -0400365 ACPI_FREE(table_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
Len Brown4be44fc2005-08-05 00:44:28 -0400367 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Bob Moore83135242006-10-03 00:00:00 -0400370ACPI_EXPORT_SYMBOL(acpi_get_firmware_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372/* TBD: Move to a new file */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#if ACPI_MACHINE_WIDTH != 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374/*******************************************************************************
375 *
376 * FUNCTION: acpi_find_root_pointer
377 *
Robert Moore44f6c012005-04-18 22:49:35 -0400378 * PARAMETERS: Flags - Logical/Physical addressing
379 * rsdp_address - Where to place the RSDP address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 *
381 * RETURN: Status, Physical address of the RSDP
382 *
383 * DESCRIPTION: Find the RSDP
384 *
385 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400386acpi_status acpi_find_root_pointer(u32 flags, struct acpi_pointer *rsdp_address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Len Brown4be44fc2005-08-05 00:44:28 -0400388 struct acpi_table_desc table_info;
389 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Len Brown4be44fc2005-08-05 00:44:28 -0400391 ACPI_FUNCTION_TRACE("acpi_find_root_pointer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 /* Get the RSDP */
394
Len Brown4be44fc2005-08-05 00:44:28 -0400395 status = acpi_tb_find_rsdp(&table_info, flags);
396 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500397 ACPI_EXCEPTION((AE_INFO, status,
398 "RSDP structure not found - Flags=%X", flags));
Robert Moore44f6c012005-04-18 22:49:35 -0400399
Len Brown4be44fc2005-08-05 00:44:28 -0400400 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402
403 rsdp_address->pointer_type = ACPI_PHYSICAL_POINTER;
404 rsdp_address->pointer.physical = table_info.physical_address;
Len Brown4be44fc2005-08-05 00:44:28 -0400405 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406}
407
Bob Moore83135242006-10-03 00:00:00 -0400408ACPI_EXPORT_SYMBOL(acpi_find_root_pointer)
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410/*******************************************************************************
411 *
412 * FUNCTION: acpi_tb_scan_memory_for_rsdp
413 *
414 * PARAMETERS: start_address - Starting pointer for search
415 * Length - Maximum length to search
416 *
417 * RETURN: Pointer to the RSDP if found, otherwise NULL.
418 *
419 * DESCRIPTION: Search a block of memory for the RSDP signature
420 *
421 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400422static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
Len Brown4be44fc2005-08-05 00:44:28 -0400424 acpi_status status;
425 u8 *mem_rover;
426 u8 *end_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 ACPI_FUNCTION_TRACE("tb_scan_memory_for_rsdp");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 end_address = start_address + length;
431
432 /* Search from given start address for the requested length */
433
434 for (mem_rover = start_address; mem_rover < end_address;
Len Brown4be44fc2005-08-05 00:44:28 -0400435 mem_rover += ACPI_RSDP_SCAN_STEP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400436
Robert Mooref9f46012005-07-08 00:00:00 -0400437 /* The RSDP signature and checksum must both be correct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 status =
440 acpi_tb_validate_rsdp(ACPI_CAST_PTR
441 (struct rsdp_descriptor, mem_rover));
442 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400443
Robert Mooref9f46012005-07-08 00:00:00 -0400444 /* Sig and checksum valid, we have found a real RSDP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Len Brown4be44fc2005-08-05 00:44:28 -0400446 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
447 "RSDP located at physical address %p\n",
448 mem_rover));
449 return_PTR(mem_rover);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 }
451
Robert Mooref9f46012005-07-08 00:00:00 -0400452 /* No sig match or bad checksum, keep searching */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454
455 /* Searched entire block, no RSDP was found */
456
Len Brown4be44fc2005-08-05 00:44:28 -0400457 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
458 "Searched entire block from %p, valid RSDP was not found\n",
459 start_address));
460 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463/*******************************************************************************
464 *
465 * FUNCTION: acpi_tb_find_rsdp
466 *
Robert Moore44f6c012005-04-18 22:49:35 -0400467 * PARAMETERS: table_info - Where the table info is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 * Flags - Current memory mode (logical vs.
469 * physical addressing)
470 *
471 * RETURN: Status, RSDP physical address
472 *
473 * DESCRIPTION: search lower 1_mbyte of memory for the root system descriptor
474 * pointer structure. If it is found, set *RSDP to point to it.
475 *
476 * NOTE1: The RSDp must be either in the first 1_k of the Extended
477 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
478 * Only a 32-bit physical address is necessary.
479 *
480 * NOTE2: This function is always available, regardless of the
481 * initialization state of the rest of ACPI.
482 *
483 ******************************************************************************/
484
Robert Moore44f6c012005-04-18 22:49:35 -0400485static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400486acpi_tb_find_rsdp(struct acpi_table_desc *table_info, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
Len Brown4be44fc2005-08-05 00:44:28 -0400488 u8 *table_ptr;
489 u8 *mem_rover;
490 u32 physical_address;
491 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Len Brown4be44fc2005-08-05 00:44:28 -0400493 ACPI_FUNCTION_TRACE("tb_find_rsdp");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400496 * Scan supports either logical addressing or physical addressing
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 */
498 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400499
Robert Moore44f6c012005-04-18 22:49:35 -0400500 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
501
Len Brown4be44fc2005-08-05 00:44:28 -0400502 status = acpi_os_map_memory((acpi_physical_address)
503 ACPI_EBDA_PTR_LOCATION,
504 ACPI_EBDA_PTR_LENGTH,
505 (void *)&table_ptr);
506 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500507 ACPI_ERROR((AE_INFO,
508 "Could not map memory at %8.8X for length %X",
509 ACPI_EBDA_PTR_LOCATION,
510 ACPI_EBDA_PTR_LENGTH));
Robert Moore44f6c012005-04-18 22:49:35 -0400511
Len Brown4be44fc2005-08-05 00:44:28 -0400512 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514
Len Brown4be44fc2005-08-05 00:44:28 -0400515 ACPI_MOVE_16_TO_32(&physical_address, table_ptr);
Robert Moore44f6c012005-04-18 22:49:35 -0400516
517 /* Convert segment part to physical address */
518
519 physical_address <<= 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400520 acpi_os_unmap_memory(table_ptr, ACPI_EBDA_PTR_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 /* EBDA present? */
523
524 if (physical_address > 0x400) {
525 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400526 * 1b) Search EBDA paragraphs (EBDa is required to be a
527 * minimum of 1_k length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 */
Len Brown4be44fc2005-08-05 00:44:28 -0400529 status = acpi_os_map_memory((acpi_physical_address)
530 physical_address,
531 ACPI_EBDA_WINDOW_SIZE,
532 (void *)&table_ptr);
533 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500534 ACPI_ERROR((AE_INFO,
535 "Could not map memory at %8.8X for length %X",
536 physical_address,
537 ACPI_EBDA_WINDOW_SIZE));
Robert Moore44f6c012005-04-18 22:49:35 -0400538
Len Brown4be44fc2005-08-05 00:44:28 -0400539 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 }
541
Len Brown4be44fc2005-08-05 00:44:28 -0400542 mem_rover = acpi_tb_scan_memory_for_rsdp(table_ptr,
543 ACPI_EBDA_WINDOW_SIZE);
544 acpi_os_unmap_memory(table_ptr, ACPI_EBDA_WINDOW_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 if (mem_rover) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400547
Robert Mooref9f46012005-07-08 00:00:00 -0400548 /* Return the physical address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Len Brown4be44fc2005-08-05 00:44:28 -0400550 physical_address +=
551 ACPI_PTR_DIFF(mem_rover, table_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Robert Moore44f6c012005-04-18 22:49:35 -0400553 table_info->physical_address =
Len Brown4be44fc2005-08-05 00:44:28 -0400554 (acpi_physical_address) physical_address;
555 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557 }
558
559 /*
560 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
561 */
Len Brown4be44fc2005-08-05 00:44:28 -0400562 status = acpi_os_map_memory((acpi_physical_address)
563 ACPI_HI_RSDP_WINDOW_BASE,
564 ACPI_HI_RSDP_WINDOW_SIZE,
565 (void *)&table_ptr);
Robert Moore44f6c012005-04-18 22:49:35 -0400566
Len Brown4be44fc2005-08-05 00:44:28 -0400567 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500568 ACPI_ERROR((AE_INFO,
569 "Could not map memory at %8.8X for length %X",
570 ACPI_HI_RSDP_WINDOW_BASE,
571 ACPI_HI_RSDP_WINDOW_SIZE));
Robert Moore44f6c012005-04-18 22:49:35 -0400572
Len Brown4be44fc2005-08-05 00:44:28 -0400573 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 }
575
Len Brown4be44fc2005-08-05 00:44:28 -0400576 mem_rover =
577 acpi_tb_scan_memory_for_rsdp(table_ptr,
578 ACPI_HI_RSDP_WINDOW_SIZE);
579 acpi_os_unmap_memory(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 if (mem_rover) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400582
Robert Mooref9f46012005-07-08 00:00:00 -0400583 /* Return the physical address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Robert Moore44f6c012005-04-18 22:49:35 -0400585 physical_address =
Len Brown4be44fc2005-08-05 00:44:28 -0400586 ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF(mem_rover,
587 table_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Robert Moore44f6c012005-04-18 22:49:35 -0400589 table_info->physical_address =
Len Brown4be44fc2005-08-05 00:44:28 -0400590 (acpi_physical_address) physical_address;
591 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
593 }
594
595 /*
596 * Physical addressing
597 */
598 else {
Robert Moore44f6c012005-04-18 22:49:35 -0400599 /* 1a) Get the location of the EBDA */
600
Len Brown4be44fc2005-08-05 00:44:28 -0400601 ACPI_MOVE_16_TO_32(&physical_address, ACPI_EBDA_PTR_LOCATION);
602 physical_address <<= 4; /* Convert segment to physical address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 /* EBDA present? */
605
606 if (physical_address > 0x400) {
607 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400608 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of
609 * 1_k length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 */
Len Brown4be44fc2005-08-05 00:44:28 -0400611 mem_rover =
612 acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
613 (physical_address),
614 ACPI_EBDA_WINDOW_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 if (mem_rover) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400616
Robert Mooref9f46012005-07-08 00:00:00 -0400617 /* Return the physical address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Len Brown4be44fc2005-08-05 00:44:28 -0400619 table_info->physical_address =
620 ACPI_TO_INTEGER(mem_rover);
621 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 }
623 }
624
Robert Moore44f6c012005-04-18 22:49:35 -0400625 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
626
Len Brown4be44fc2005-08-05 00:44:28 -0400627 mem_rover =
628 acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
629 (ACPI_HI_RSDP_WINDOW_BASE),
630 ACPI_HI_RSDP_WINDOW_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 if (mem_rover) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /* Found it, return the physical address */
634
Len Brown4be44fc2005-08-05 00:44:28 -0400635 table_info->physical_address =
636 ACPI_TO_INTEGER(mem_rover);
637 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
639 }
640
Robert Mooref9f46012005-07-08 00:00:00 -0400641 /* A valid RSDP was not found */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Bob Mooreb8e4d892006-01-27 16:43:00 -0500643 ACPI_ERROR((AE_INFO, "No valid RSDP was found"));
Len Brown4be44fc2005-08-05 00:44:28 -0400644 return_ACPI_STATUS(AE_NOT_FOUND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
646
647#endif