1 /******************************************************************************
3 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2006, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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("tbxfroot")
50 /* Local prototypes */
52 acpi_tb_find_rsdp(struct acpi_table_desc
*table_info
, u32 flags
);
54 static u8
*acpi_tb_scan_memory_for_rsdp(u8
* start_address
, u32 length
);
56 /*******************************************************************************
58 * FUNCTION: acpi_tb_validate_rsdp
60 * PARAMETERS: Rsdp - Pointer to unvalidated RSDP
64 * DESCRIPTION: Validate the RSDP (ptr)
66 ******************************************************************************/
68 acpi_status
acpi_tb_validate_rsdp(struct rsdp_descriptor
*rsdp
)
70 ACPI_FUNCTION_ENTRY();
73 * The signature and checksum must both be correct
75 if (ACPI_STRNCMP((char *)rsdp
, RSDP_SIG
, sizeof(RSDP_SIG
) - 1) != 0) {
77 /* Nope, BAD Signature */
79 return (AE_BAD_SIGNATURE
);
82 /* Check the standard checksum */
84 if (acpi_tb_sum_table(rsdp
, ACPI_RSDP_CHECKSUM_LENGTH
) != 0) {
85 return (AE_BAD_CHECKSUM
);
88 /* Check extended checksum if table version >= 2 */
90 if ((rsdp
->revision
>= 2) &&
91 (acpi_tb_sum_table(rsdp
, ACPI_RSDP_XCHECKSUM_LENGTH
) != 0)) {
92 return (AE_BAD_CHECKSUM
);
98 /*******************************************************************************
100 * FUNCTION: acpi_tb_find_table
102 * PARAMETERS: Signature - String with ACPI table signature
103 * oem_id - String with the table OEM ID
104 * oem_table_id - String with the OEM Table ID
105 * table_ptr - Where the table pointer is returned
109 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
110 * Signature, OEM ID and OEM Table ID.
112 ******************************************************************************/
115 acpi_tb_find_table(char *signature
,
117 char *oem_table_id
, struct acpi_table_header
** table_ptr
)
120 struct acpi_table_header
*table
;
122 ACPI_FUNCTION_TRACE(tb_find_table
);
124 /* Validate string lengths */
126 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
);
132 if (ACPI_COMPARE_NAME(signature
, DSDT_SIG
)) {
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.
140 if (!acpi_gbl_DSDT
) {
141 return_ACPI_STATUS(AE_NO_ACPI_TABLES
);
143 table
= acpi_gbl_DSDT
;
147 status
= acpi_get_firmware_table(signature
, 1,
148 ACPI_LOGICAL_ADDRESSING
,
150 if (ACPI_FAILURE(status
)) {
151 return_ACPI_STATUS(status
);
155 /* Check oem_id and oem_table_id */
158 ACPI_STRNCMP(oem_id
, table
->oem_id
,
159 sizeof(table
->oem_id
))) ||
161 ACPI_STRNCMP(oem_table_id
, table
->oem_table_id
,
162 sizeof(table
->oem_table_id
)))) {
163 return_ACPI_STATUS(AE_AML_NAME_NOT_FOUND
);
166 ACPI_DEBUG_PRINT((ACPI_DB_TABLES
, "Found table [%4.4s]\n",
170 return_ACPI_STATUS(AE_OK
);
173 /*******************************************************************************
175 * FUNCTION: acpi_get_firmware_table
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
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.
190 ******************************************************************************/
193 acpi_get_firmware_table(acpi_string signature
,
195 u32 flags
, struct acpi_table_header
**table_pointer
)
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
;
206 ACPI_FUNCTION_TRACE(acpi_get_firmware_table
);
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
213 if ((instance
== 0) || (!signature
) || (!table_pointer
)) {
214 return_ACPI_STATUS(AE_BAD_PARAMETER
);
217 /* Ensure that we have a RSDP */
219 if (!acpi_gbl_RSDP
) {
223 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
);
229 /* Map and validate the RSDP */
231 if ((flags
& ACPI_MEMORY_MODE
) == ACPI_LOGICAL_ADDRESSING
) {
232 status
= acpi_os_map_memory(address
.pointer
.physical
,
235 (void *)&acpi_gbl_RSDP
);
236 if (ACPI_FAILURE(status
)) {
237 return_ACPI_STATUS(status
);
240 acpi_gbl_RSDP
= address
.pointer
.logical
;
243 /* The RDSP signature and checksum must both be correct */
245 status
= acpi_tb_validate_rsdp(acpi_gbl_RSDP
);
246 if (ACPI_FAILURE(status
)) {
247 return_ACPI_STATUS(status
);
251 /* Get the RSDT address via the RSDP */
253 acpi_tb_get_rsdt_address(&address
);
254 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
255 "RSDP located at %p, RSDT physical=%8.8X%8.8X\n",
257 ACPI_FORMAT_UINT64(address
.pointer
.value
)));
259 /* Insert processor_mode flags */
261 address
.pointer_type
|= flags
;
263 /* Get and validate the RSDT */
265 rsdt_info
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_table_desc
));
267 return_ACPI_STATUS(AE_NO_MEMORY
);
270 status
= acpi_tb_get_table(&address
, rsdt_info
);
271 if (ACPI_FAILURE(status
)) {
275 status
= acpi_tb_validate_rsdt(rsdt_info
->pointer
);
276 if (ACPI_FAILURE(status
)) {
280 /* Allocate a scratch table header and table descriptor */
282 header
= ACPI_ALLOCATE(sizeof(struct acpi_table_header
));
284 status
= AE_NO_MEMORY
;
288 table_info
= ACPI_ALLOCATE(sizeof(struct acpi_table_desc
));
290 status
= AE_NO_MEMORY
;
294 /* Get the number of table pointers within the RSDT */
297 acpi_tb_get_table_count(acpi_gbl_RSDP
, rsdt_info
->pointer
);
298 address
.pointer_type
= acpi_gbl_table_flags
| flags
;
301 * Search the RSDT/XSDT for the correct instance of the
304 for (i
= 0, j
= 0; i
< table_count
; i
++) {
306 * Get the next table pointer, handle RSDT vs. XSDT
307 * RSDT pointers are 32 bits, XSDT pointers are 64 bits
309 if (acpi_gbl_root_table_type
== ACPI_TABLE_TYPE_RSDT
) {
310 address
.pointer
.value
=
312 (struct rsdt_descriptor
,
313 rsdt_info
->pointer
))->table_offset_entry
[i
];
315 address
.pointer
.value
=
317 (struct xsdt_descriptor
,
318 rsdt_info
->pointer
))->table_offset_entry
[i
];
321 /* Get the table header */
323 status
= acpi_tb_get_table_header(&address
, header
);
324 if (ACPI_FAILURE(status
)) {
328 /* Compare table signatures and table instance */
330 if (ACPI_COMPARE_NAME(header
->signature
, signature
)) {
332 /* An instance of the table was found */
337 /* Found the correct instance, get the entire table */
340 acpi_tb_get_table_body(&address
, header
,
342 if (ACPI_FAILURE(status
)) {
346 *table_pointer
= table_info
->pointer
;
352 /* Did not find the table */
354 status
= AE_NOT_EXIST
;
357 if (rsdt_info
->pointer
) {
358 acpi_os_unmap_memory(rsdt_info
->pointer
,
359 (acpi_size
) rsdt_info
->pointer
->length
);
361 ACPI_FREE(rsdt_info
);
367 ACPI_FREE(table_info
);
369 return_ACPI_STATUS(status
);
372 ACPI_EXPORT_SYMBOL(acpi_get_firmware_table
)
374 /* TBD: Move to a new file */
375 #if ACPI_MACHINE_WIDTH != 16
376 /*******************************************************************************
378 * FUNCTION: acpi_find_root_pointer
380 * PARAMETERS: Flags - Logical/Physical addressing
381 * rsdp_address - Where to place the RSDP address
383 * RETURN: Status, Physical address of the RSDP
385 * DESCRIPTION: Find the RSDP
387 ******************************************************************************/
388 acpi_status
acpi_find_root_pointer(u32 flags
, struct acpi_pointer
*rsdp_address
)
390 struct acpi_table_desc table_info
;
393 ACPI_FUNCTION_TRACE(acpi_find_root_pointer
);
397 status
= acpi_tb_find_rsdp(&table_info
, flags
);
398 if (ACPI_FAILURE(status
)) {
399 ACPI_EXCEPTION((AE_INFO
, status
,
400 "RSDP structure not found - Flags=%X", flags
));
402 return_ACPI_STATUS(AE_NO_ACPI_TABLES
);
405 rsdp_address
->pointer_type
= ACPI_PHYSICAL_POINTER
;
406 rsdp_address
->pointer
.physical
= table_info
.physical_address
;
407 return_ACPI_STATUS(AE_OK
);
410 ACPI_EXPORT_SYMBOL(acpi_find_root_pointer
)
412 /*******************************************************************************
414 * FUNCTION: acpi_tb_scan_memory_for_rsdp
416 * PARAMETERS: start_address - Starting pointer for search
417 * Length - Maximum length to search
419 * RETURN: Pointer to the RSDP if found, otherwise NULL.
421 * DESCRIPTION: Search a block of memory for the RSDP signature
423 ******************************************************************************/
424 static u8
*acpi_tb_scan_memory_for_rsdp(u8
* start_address
, u32 length
)
430 ACPI_FUNCTION_TRACE(tb_scan_memory_for_rsdp
);
432 end_address
= start_address
+ length
;
434 /* Search from given start address for the requested length */
436 for (mem_rover
= start_address
; mem_rover
< end_address
;
437 mem_rover
+= ACPI_RSDP_SCAN_STEP
) {
439 /* The RSDP signature and checksum must both be correct */
442 acpi_tb_validate_rsdp(ACPI_CAST_PTR
443 (struct rsdp_descriptor
, mem_rover
));
444 if (ACPI_SUCCESS(status
)) {
446 /* Sig and checksum valid, we have found a real RSDP */
448 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
449 "RSDP located at physical address %p\n",
451 return_PTR(mem_rover
);
454 /* No sig match or bad checksum, keep searching */
457 /* Searched entire block, no RSDP was found */
459 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
460 "Searched entire block from %p, valid RSDP was not found\n",
465 /*******************************************************************************
467 * FUNCTION: acpi_tb_find_rsdp
469 * PARAMETERS: table_info - Where the table info is returned
470 * Flags - Current memory mode (logical vs.
471 * physical addressing)
473 * RETURN: Status, RSDP physical address
475 * DESCRIPTION: Search lower 1_mbyte of memory for the root system descriptor
476 * pointer structure. If it is found, set *RSDP to point to it.
478 * NOTE1: The RSDP must be either in the first 1_k of the Extended
479 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
480 * Only a 32-bit physical address is necessary.
482 * NOTE2: This function is always available, regardless of the
483 * initialization state of the rest of ACPI.
485 ******************************************************************************/
488 acpi_tb_find_rsdp(struct acpi_table_desc
*table_info
, u32 flags
)
492 u32 physical_address
;
495 ACPI_FUNCTION_TRACE(tb_find_rsdp
);
498 * Scan supports either logical addressing or physical addressing
500 if ((flags
& ACPI_MEMORY_MODE
) == ACPI_LOGICAL_ADDRESSING
) {
502 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
504 status
= acpi_os_map_memory((acpi_physical_address
)
505 ACPI_EBDA_PTR_LOCATION
,
506 ACPI_EBDA_PTR_LENGTH
,
508 if (ACPI_FAILURE(status
)) {
510 "Could not map memory at %8.8X for length %X",
511 ACPI_EBDA_PTR_LOCATION
,
512 ACPI_EBDA_PTR_LENGTH
));
514 return_ACPI_STATUS(status
);
517 ACPI_MOVE_16_TO_32(&physical_address
, table_ptr
);
519 /* Convert segment part to physical address */
521 physical_address
<<= 4;
522 acpi_os_unmap_memory(table_ptr
, ACPI_EBDA_PTR_LENGTH
);
526 if (physical_address
> 0x400) {
528 * 1b) Search EBDA paragraphs (EBDA is required to be a
529 * minimum of 1_k length)
531 status
= acpi_os_map_memory((acpi_physical_address
)
533 ACPI_EBDA_WINDOW_SIZE
,
535 if (ACPI_FAILURE(status
)) {
537 "Could not map memory at %8.8X for length %X",
539 ACPI_EBDA_WINDOW_SIZE
));
541 return_ACPI_STATUS(status
);
544 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
);
550 /* Return the physical address */
553 (u32
) ACPI_PTR_DIFF(mem_rover
, table_ptr
);
555 table_info
->physical_address
=
556 (acpi_physical_address
) physical_address
;
557 return_ACPI_STATUS(AE_OK
);
562 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
564 status
= acpi_os_map_memory((acpi_physical_address
)
565 ACPI_HI_RSDP_WINDOW_BASE
,
566 ACPI_HI_RSDP_WINDOW_SIZE
,
569 if (ACPI_FAILURE(status
)) {
571 "Could not map memory at %8.8X for length %X",
572 ACPI_HI_RSDP_WINDOW_BASE
,
573 ACPI_HI_RSDP_WINDOW_SIZE
));
575 return_ACPI_STATUS(status
);
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
);
585 /* Return the physical address */
587 physical_address
= (u32
)
588 (ACPI_HI_RSDP_WINDOW_BASE
+
589 ACPI_PTR_DIFF(mem_rover
, table_ptr
));
591 table_info
->physical_address
=
592 (acpi_physical_address
) physical_address
;
593 return_ACPI_STATUS(AE_OK
);
598 * Physical addressing
601 /* 1a) Get the location of the EBDA */
603 ACPI_MOVE_16_TO_32(&physical_address
, ACPI_EBDA_PTR_LOCATION
);
604 physical_address
<<= 4; /* Convert segment to physical address */
608 if (physical_address
> 0x400) {
610 * 1b) Search EBDA paragraphs (EBDA is required to be a minimum of
614 acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
616 ACPI_EBDA_WINDOW_SIZE
);
619 /* Return the physical address */
621 table_info
->physical_address
=
622 ACPI_TO_INTEGER(mem_rover
);
623 return_ACPI_STATUS(AE_OK
);
627 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
630 acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
631 (ACPI_HI_RSDP_WINDOW_BASE
),
632 ACPI_HI_RSDP_WINDOW_SIZE
);
635 /* Found it, return the physical address */
637 table_info
->physical_address
=
638 ACPI_TO_INTEGER(mem_rover
);
639 return_ACPI_STATUS(AE_OK
);
643 /* A valid RSDP was not found */
645 ACPI_ERROR((AE_INFO
, "No valid RSDP was found"));
646 return_ACPI_STATUS(AE_NOT_FOUND
);