1 /******************************************************************************
3 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, 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 <linux/module.h>
46 #include <acpi/acpi.h>
47 #include <acpi/actables.h>
50 #define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbxfroot")
53 /* Local prototypes */
57 struct acpi_table_desc
*table_info
,
61 acpi_tb_scan_memory_for_rsdp (
66 /*******************************************************************************
68 * FUNCTION: acpi_tb_find_table
70 * PARAMETERS: Signature - String with ACPI table signature
71 * oem_id - String with the table OEM ID
72 * oem_table_id - String with the OEM Table ID
73 * table_ptr - Where the table pointer is returned
77 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
78 * Signature, OEM ID and OEM Table ID.
80 ******************************************************************************/
87 struct acpi_table_header
**table_ptr
)
90 struct acpi_table_header
*table
;
93 ACPI_FUNCTION_TRACE ("tb_find_table");
96 /* Validate string lengths */
98 if ((ACPI_STRLEN (signature
) > ACPI_NAME_SIZE
) ||
99 (ACPI_STRLEN (oem_id
) > sizeof (table
->oem_id
)) ||
100 (ACPI_STRLEN (oem_table_id
) > sizeof (table
->oem_table_id
))) {
101 return_ACPI_STATUS (AE_AML_STRING_LIMIT
);
104 if (!ACPI_STRNCMP (signature
, DSDT_SIG
, ACPI_NAME_SIZE
)) {
106 * The DSDT pointer is contained in the FADT, not the RSDT.
107 * This code should suffice, because the only code that would perform
108 * a "find" on the DSDT is the data_table_region() AML opcode -- in
109 * which case, the DSDT is guaranteed to be already loaded.
110 * If this becomes insufficient, the FADT will have to be found first.
112 if (!acpi_gbl_DSDT
) {
113 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
115 table
= acpi_gbl_DSDT
;
120 status
= acpi_get_firmware_table (signature
, 1,
121 ACPI_LOGICAL_ADDRESSING
, &table
);
122 if (ACPI_FAILURE (status
)) {
123 return_ACPI_STATUS (status
);
127 /* Check oem_id and oem_table_id */
129 if ((oem_id
[0] && ACPI_STRNCMP (
130 oem_id
, table
->oem_id
,
131 sizeof (table
->oem_id
))) ||
133 (oem_table_id
[0] && ACPI_STRNCMP (
134 oem_table_id
, table
->oem_table_id
,
135 sizeof (table
->oem_table_id
)))) {
136 return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND
);
139 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES
, "Found table [%4.4s]\n",
143 return_ACPI_STATUS (AE_OK
);
147 /*******************************************************************************
149 * FUNCTION: acpi_get_firmware_table
151 * PARAMETERS: Signature - Any ACPI table signature
152 * Instance - the non zero instance of the table, allows
153 * support for multiple tables of the same type
154 * Flags - Physical/Virtual support
155 * table_pointer - Where a buffer containing the table is
160 * DESCRIPTION: This function is called to get an ACPI table. A buffer is
161 * allocated for the table and returned in table_pointer.
162 * This table will be a complete table including the header.
164 ******************************************************************************/
167 acpi_get_firmware_table (
168 acpi_string signature
,
171 struct acpi_table_header
**table_pointer
)
174 struct acpi_pointer address
;
175 struct acpi_table_header
*header
= NULL
;
176 struct acpi_table_desc
*table_info
= NULL
;
177 struct acpi_table_desc
*rsdt_info
;
183 ACPI_FUNCTION_TRACE ("acpi_get_firmware_table");
187 * Ensure that at least the table manager is initialized. We don't
188 * require that the entire ACPI subsystem is up for this interface.
189 * If we have a buffer, we must have a length too
191 if ((instance
== 0) ||
194 return_ACPI_STATUS (AE_BAD_PARAMETER
);
197 /* Ensure that we have a RSDP */
199 if (!acpi_gbl_RSDP
) {
202 status
= acpi_os_get_root_pointer (flags
, &address
);
203 if (ACPI_FAILURE (status
)) {
204 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "RSDP not found\n"));
205 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
208 /* Map and validate the RSDP */
210 if ((flags
& ACPI_MEMORY_MODE
) == ACPI_LOGICAL_ADDRESSING
) {
211 status
= acpi_os_map_memory (address
.pointer
.physical
,
212 sizeof (struct rsdp_descriptor
), (void *) &acpi_gbl_RSDP
);
213 if (ACPI_FAILURE (status
)) {
214 return_ACPI_STATUS (status
);
218 acpi_gbl_RSDP
= address
.pointer
.logical
;
221 /* The signature and checksum must both be correct */
223 if (ACPI_STRNCMP ((char *) acpi_gbl_RSDP
, RSDP_SIG
,
224 sizeof (RSDP_SIG
)-1) != 0) {
225 /* Nope, BAD Signature */
227 return_ACPI_STATUS (AE_BAD_SIGNATURE
);
230 if (acpi_tb_checksum (acpi_gbl_RSDP
, ACPI_RSDP_CHECKSUM_LENGTH
) != 0) {
231 /* Nope, BAD Checksum */
233 return_ACPI_STATUS (AE_BAD_CHECKSUM
);
237 /* Get the RSDT address via the RSDP */
239 acpi_tb_get_rsdt_address (&address
);
240 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
241 "RSDP located at %p, RSDT physical=%8.8X%8.8X \n",
243 ACPI_FORMAT_UINT64 (address
.pointer
.value
)));
245 /* Insert processor_mode flags */
247 address
.pointer_type
|= flags
;
249 /* Get and validate the RSDT */
251 rsdt_info
= ACPI_MEM_CALLOCATE (sizeof (struct acpi_table_desc
));
253 return_ACPI_STATUS (AE_NO_MEMORY
);
256 status
= acpi_tb_get_table (&address
, rsdt_info
);
257 if (ACPI_FAILURE (status
)) {
261 status
= acpi_tb_validate_rsdt (rsdt_info
->pointer
);
262 if (ACPI_FAILURE (status
)) {
266 /* Allocate a scratch table header and table descriptor */
268 header
= ACPI_MEM_ALLOCATE (sizeof (struct acpi_table_header
));
270 status
= AE_NO_MEMORY
;
274 table_info
= ACPI_MEM_ALLOCATE (sizeof (struct acpi_table_desc
));
276 status
= AE_NO_MEMORY
;
280 /* Get the number of table pointers within the RSDT */
282 table_count
= acpi_tb_get_table_count (acpi_gbl_RSDP
, rsdt_info
->pointer
);
283 address
.pointer_type
= acpi_gbl_table_flags
| flags
;
286 * Search the RSDT/XSDT for the correct instance of the
289 for (i
= 0, j
= 0; i
< table_count
; i
++) {
290 /* Get the next table pointer, handle RSDT vs. XSDT */
292 if (acpi_gbl_RSDP
->revision
< 2) {
293 address
.pointer
.value
= (ACPI_CAST_PTR (
294 RSDT_DESCRIPTOR
, rsdt_info
->pointer
))->table_offset_entry
[i
];
297 address
.pointer
.value
= (ACPI_CAST_PTR (
298 XSDT_DESCRIPTOR
, rsdt_info
->pointer
))->table_offset_entry
[i
];
301 /* Get the table header */
303 status
= acpi_tb_get_table_header (&address
, header
);
304 if (ACPI_FAILURE (status
)) {
308 /* Compare table signatures and table instance */
310 if (!ACPI_STRNCMP (header
->signature
, signature
, ACPI_NAME_SIZE
)) {
311 /* An instance of the table was found */
315 /* Found the correct instance, get the entire table */
317 status
= acpi_tb_get_table_body (&address
, header
, table_info
);
318 if (ACPI_FAILURE (status
)) {
322 *table_pointer
= table_info
->pointer
;
328 /* Did not find the table */
330 status
= AE_NOT_EXIST
;
334 acpi_os_unmap_memory (rsdt_info
->pointer
,
335 (acpi_size
) rsdt_info
->pointer
->length
);
336 ACPI_MEM_FREE (rsdt_info
);
339 ACPI_MEM_FREE (header
);
342 ACPI_MEM_FREE (table_info
);
344 return_ACPI_STATUS (status
);
346 EXPORT_SYMBOL(acpi_get_firmware_table
);
349 /* TBD: Move to a new file */
351 #if ACPI_MACHINE_WIDTH != 16
353 /*******************************************************************************
355 * FUNCTION: acpi_find_root_pointer
357 * PARAMETERS: Flags - Logical/Physical addressing
358 * rsdp_address - Where to place the RSDP address
360 * RETURN: Status, Physical address of the RSDP
362 * DESCRIPTION: Find the RSDP
364 ******************************************************************************/
367 acpi_find_root_pointer (
369 struct acpi_pointer
*rsdp_address
)
371 struct acpi_table_desc table_info
;
375 ACPI_FUNCTION_TRACE ("acpi_find_root_pointer");
380 status
= acpi_tb_find_rsdp (&table_info
, flags
);
381 if (ACPI_FAILURE (status
)) {
382 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
383 "RSDP structure not found, %s Flags=%X\n",
384 acpi_format_exception (status
), flags
));
386 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
389 rsdp_address
->pointer_type
= ACPI_PHYSICAL_POINTER
;
390 rsdp_address
->pointer
.physical
= table_info
.physical_address
;
391 return_ACPI_STATUS (AE_OK
);
395 /*******************************************************************************
397 * FUNCTION: acpi_tb_scan_memory_for_rsdp
399 * PARAMETERS: start_address - Starting pointer for search
400 * Length - Maximum length to search
402 * RETURN: Pointer to the RSDP if found, otherwise NULL.
404 * DESCRIPTION: Search a block of memory for the RSDP signature
406 ******************************************************************************/
409 acpi_tb_scan_memory_for_rsdp (
418 ACPI_FUNCTION_TRACE ("tb_scan_memory_for_rsdp");
421 end_address
= start_address
+ length
;
423 /* Search from given start address for the requested length */
425 for (mem_rover
= start_address
; mem_rover
< end_address
;
426 mem_rover
+= ACPI_RSDP_SCAN_STEP
) {
427 /* The signature and checksum must both be correct */
429 if (ACPI_STRNCMP ((char *) mem_rover
,
430 RSDP_SIG
, sizeof (RSDP_SIG
) - 1) != 0) {
431 /* No signature match, keep looking */
436 /* Signature matches, check the appropriate checksum */
438 if ((ACPI_CAST_PTR (struct rsdp_descriptor
, mem_rover
))->revision
< 2) {
439 /* ACPI version 1.0 */
441 checksum
= acpi_tb_checksum (mem_rover
, ACPI_RSDP_CHECKSUM_LENGTH
);
444 /* Post ACPI 1.0, use extended_checksum */
446 checksum
= acpi_tb_checksum (mem_rover
, ACPI_RSDP_XCHECKSUM_LENGTH
);
450 /* Checksum valid, we have found a valid RSDP */
452 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
453 "RSDP located at physical address %p\n", mem_rover
));
454 return_PTR (mem_rover
);
457 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
458 "Found an RSDP at physical address %p, but it has a bad checksum\n",
462 /* Searched entire block, no RSDP was found */
464 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
465 "Searched entire block, no valid RSDP was found.\n"));
470 /*******************************************************************************
472 * FUNCTION: acpi_tb_find_rsdp
474 * PARAMETERS: table_info - Where the table info is returned
475 * Flags - Current memory mode (logical vs.
476 * physical addressing)
478 * RETURN: Status, RSDP physical address
480 * DESCRIPTION: search lower 1_mbyte of memory for the root system descriptor
481 * pointer structure. If it is found, set *RSDP to point to it.
483 * NOTE1: The RSDp must be either in the first 1_k of the Extended
484 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
485 * Only a 32-bit physical address is necessary.
487 * NOTE2: This function is always available, regardless of the
488 * initialization state of the rest of ACPI.
490 ******************************************************************************/
494 struct acpi_table_desc
*table_info
,
499 u32 physical_address
;
503 ACPI_FUNCTION_TRACE ("tb_find_rsdp");
507 * Scan supports either logical addressing or physical addressing
509 if ((flags
& ACPI_MEMORY_MODE
) == ACPI_LOGICAL_ADDRESSING
) {
510 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
512 status
= acpi_os_map_memory (
513 (acpi_physical_address
) ACPI_EBDA_PTR_LOCATION
,
514 ACPI_EBDA_PTR_LENGTH
, (void *) &table_ptr
);
515 if (ACPI_FAILURE (status
)) {
516 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
517 "Could not map memory at %8.8X for length %X\n",
518 ACPI_EBDA_PTR_LOCATION
, ACPI_EBDA_PTR_LENGTH
));
520 return_ACPI_STATUS (status
);
523 ACPI_MOVE_16_TO_32 (&physical_address
, table_ptr
);
525 /* Convert segment part to physical address */
527 physical_address
<<= 4;
528 acpi_os_unmap_memory (table_ptr
, ACPI_EBDA_PTR_LENGTH
);
532 if (physical_address
> 0x400) {
534 * 1b) Search EBDA paragraphs (EBDa is required to be a
535 * minimum of 1_k length)
537 status
= acpi_os_map_memory (
538 (acpi_physical_address
) physical_address
,
539 ACPI_EBDA_WINDOW_SIZE
, (void *) &table_ptr
);
540 if (ACPI_FAILURE (status
)) {
541 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
542 "Could not map memory at %8.8X for length %X\n",
543 physical_address
, ACPI_EBDA_WINDOW_SIZE
));
545 return_ACPI_STATUS (status
);
548 mem_rover
= acpi_tb_scan_memory_for_rsdp (table_ptr
,
549 ACPI_EBDA_WINDOW_SIZE
);
550 acpi_os_unmap_memory (table_ptr
, ACPI_EBDA_WINDOW_SIZE
);
553 /* Found it, return the physical address */
555 physical_address
+= ACPI_PTR_DIFF (mem_rover
, table_ptr
);
557 table_info
->physical_address
=
558 (acpi_physical_address
) physical_address
;
559 return_ACPI_STATUS (AE_OK
);
564 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
566 status
= acpi_os_map_memory (
567 (acpi_physical_address
) ACPI_HI_RSDP_WINDOW_BASE
,
568 ACPI_HI_RSDP_WINDOW_SIZE
, (void *) &table_ptr
);
570 if (ACPI_FAILURE (status
)) {
571 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
572 "Could not map memory at %8.8X for length %X\n",
573 ACPI_HI_RSDP_WINDOW_BASE
, ACPI_HI_RSDP_WINDOW_SIZE
));
575 return_ACPI_STATUS (status
);
578 mem_rover
= acpi_tb_scan_memory_for_rsdp (table_ptr
, ACPI_HI_RSDP_WINDOW_SIZE
);
579 acpi_os_unmap_memory (table_ptr
, ACPI_HI_RSDP_WINDOW_SIZE
);
582 /* Found it, return the physical address */
585 ACPI_HI_RSDP_WINDOW_BASE
+ ACPI_PTR_DIFF (mem_rover
, table_ptr
);
587 table_info
->physical_address
=
588 (acpi_physical_address
) physical_address
;
589 return_ACPI_STATUS (AE_OK
);
594 * Physical addressing
597 /* 1a) Get the location of the EBDA */
599 ACPI_MOVE_16_TO_32 (&physical_address
, ACPI_EBDA_PTR_LOCATION
);
600 physical_address
<<= 4; /* Convert segment to physical address */
604 if (physical_address
> 0x400) {
606 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of
609 mem_rover
= acpi_tb_scan_memory_for_rsdp (
610 ACPI_PHYSADDR_TO_PTR (physical_address
),
611 ACPI_EBDA_WINDOW_SIZE
);
613 /* Found it, return the physical address */
615 table_info
->physical_address
= ACPI_TO_INTEGER (mem_rover
);
616 return_ACPI_STATUS (AE_OK
);
620 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
622 mem_rover
= acpi_tb_scan_memory_for_rsdp (
623 ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE
),
624 ACPI_HI_RSDP_WINDOW_SIZE
);
626 /* Found it, return the physical address */
628 table_info
->physical_address
= ACPI_TO_INTEGER (mem_rover
);
629 return_ACPI_STATUS (AE_OK
);
633 /* RSDP signature was not found */
635 return_ACPI_STATUS (AE_NOT_FOUND
);