1 /******************************************************************************
3 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2004, 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.
45 #include <acpi/acpi.h>
46 #include <acpi/actables.h>
49 #define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbxfroot")
53 /*******************************************************************************
55 * FUNCTION: acpi_tb_find_table
57 * PARAMETERS: Signature - String with ACPI table signature
58 * oem_id - String with the table OEM ID
59 * oem_table_id - String with the OEM Table ID.
63 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
64 * Signature, OEM ID and OEM Table ID.
66 ******************************************************************************/
73 struct acpi_table_header
**table_ptr
)
76 struct acpi_table_header
*table
;
79 ACPI_FUNCTION_TRACE ("tb_find_table");
82 /* Validate string lengths */
84 if ((ACPI_STRLEN (signature
) > ACPI_NAME_SIZE
) ||
85 (ACPI_STRLEN (oem_id
) > sizeof (table
->oem_id
)) ||
86 (ACPI_STRLEN (oem_table_id
) > sizeof (table
->oem_table_id
))) {
87 return_ACPI_STATUS (AE_AML_STRING_LIMIT
);
92 status
= acpi_get_firmware_table (signature
, 1,
93 ACPI_LOGICAL_ADDRESSING
, &table
);
94 if (ACPI_FAILURE (status
)) {
95 return_ACPI_STATUS (status
);
98 /* Check oem_id and oem_table_id */
100 if ((oem_id
[0] && ACPI_STRCMP (oem_id
, table
->oem_id
)) ||
101 (oem_table_id
[0] && ACPI_STRCMP (oem_table_id
, table
->oem_table_id
))) {
102 return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND
);
106 return_ACPI_STATUS (AE_OK
);
110 /*******************************************************************************
112 * FUNCTION: acpi_get_firmware_table
114 * PARAMETERS: Signature - Any ACPI table signature
115 * Instance - the non zero instance of the table, allows
116 * support for multiple tables of the same type
117 * Flags - Physical/Virtual support
118 * table_pointer - Where a buffer containing the table is
123 * DESCRIPTION: This function is called to get an ACPI table. A buffer is
124 * allocated for the table and returned in table_pointer.
125 * This table will be a complete table including the header.
127 ******************************************************************************/
130 acpi_get_firmware_table (
131 acpi_string signature
,
134 struct acpi_table_header
**table_pointer
)
137 struct acpi_pointer address
;
138 struct acpi_table_header
*header
= NULL
;
139 struct acpi_table_desc
*table_info
= NULL
;
140 struct acpi_table_desc
*rsdt_info
;
146 ACPI_FUNCTION_TRACE ("acpi_get_firmware_table");
150 * Ensure that at least the table manager is initialized. We don't
151 * require that the entire ACPI subsystem is up for this interface.
152 * If we have a buffer, we must have a length too
154 if ((instance
== 0) ||
157 return_ACPI_STATUS (AE_BAD_PARAMETER
);
160 /* Ensure that we have a RSDP */
162 if (!acpi_gbl_RSDP
) {
165 status
= acpi_os_get_root_pointer (flags
, &address
);
166 if (ACPI_FAILURE (status
)) {
167 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "RSDP not found\n"));
168 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
171 /* Map and validate the RSDP */
173 if ((flags
& ACPI_MEMORY_MODE
) == ACPI_LOGICAL_ADDRESSING
) {
174 status
= acpi_os_map_memory (address
.pointer
.physical
, sizeof (struct rsdp_descriptor
),
175 (void *) &acpi_gbl_RSDP
);
176 if (ACPI_FAILURE (status
)) {
177 return_ACPI_STATUS (status
);
181 acpi_gbl_RSDP
= address
.pointer
.logical
;
184 /* The signature and checksum must both be correct */
186 if (ACPI_STRNCMP ((char *) acpi_gbl_RSDP
, RSDP_SIG
, sizeof (RSDP_SIG
)-1) != 0) {
187 /* Nope, BAD Signature */
189 return_ACPI_STATUS (AE_BAD_SIGNATURE
);
192 if (acpi_tb_checksum (acpi_gbl_RSDP
, ACPI_RSDP_CHECKSUM_LENGTH
) != 0) {
193 /* Nope, BAD Checksum */
195 return_ACPI_STATUS (AE_BAD_CHECKSUM
);
199 /* Get the RSDT address via the RSDP */
201 acpi_tb_get_rsdt_address (&address
);
202 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
203 "RSDP located at %p, RSDT physical=%8.8X%8.8X \n",
205 ACPI_FORMAT_UINT64 (address
.pointer
.value
)));
207 /* Insert processor_mode flags */
209 address
.pointer_type
|= flags
;
211 /* Get and validate the RSDT */
213 rsdt_info
= ACPI_MEM_CALLOCATE (sizeof (struct acpi_table_desc
));
215 return_ACPI_STATUS (AE_NO_MEMORY
);
218 status
= acpi_tb_get_table (&address
, rsdt_info
);
219 if (ACPI_FAILURE (status
)) {
223 status
= acpi_tb_validate_rsdt (rsdt_info
->pointer
);
224 if (ACPI_FAILURE (status
)) {
228 /* Allocate a scratch table header and table descriptor */
230 header
= ACPI_MEM_ALLOCATE (sizeof (struct acpi_table_header
));
232 status
= AE_NO_MEMORY
;
236 table_info
= ACPI_MEM_ALLOCATE (sizeof (struct acpi_table_desc
));
238 status
= AE_NO_MEMORY
;
242 /* Get the number of table pointers within the RSDT */
244 table_count
= acpi_tb_get_table_count (acpi_gbl_RSDP
, rsdt_info
->pointer
);
245 address
.pointer_type
= acpi_gbl_table_flags
| flags
;
248 * Search the RSDT/XSDT for the correct instance of the
251 for (i
= 0, j
= 0; i
< table_count
; i
++) {
252 /* Get the next table pointer, handle RSDT vs. XSDT */
254 if (acpi_gbl_RSDP
->revision
< 2) {
255 address
.pointer
.value
= (ACPI_CAST_PTR (
256 RSDT_DESCRIPTOR
, rsdt_info
->pointer
))->table_offset_entry
[i
];
259 address
.pointer
.value
= (ACPI_CAST_PTR (
260 XSDT_DESCRIPTOR
, rsdt_info
->pointer
))->table_offset_entry
[i
];
263 /* Get the table header */
265 status
= acpi_tb_get_table_header (&address
, header
);
266 if (ACPI_FAILURE (status
)) {
270 /* Compare table signatures and table instance */
272 if (!ACPI_STRNCMP (header
->signature
, signature
, ACPI_NAME_SIZE
)) {
273 /* An instance of the table was found */
277 /* Found the correct instance, get the entire table */
279 status
= acpi_tb_get_table_body (&address
, header
, table_info
);
280 if (ACPI_FAILURE (status
)) {
284 *table_pointer
= table_info
->pointer
;
290 /* Did not find the table */
292 status
= AE_NOT_EXIST
;
296 acpi_os_unmap_memory (rsdt_info
->pointer
, (acpi_size
) rsdt_info
->pointer
->length
);
297 ACPI_MEM_FREE (rsdt_info
);
300 ACPI_MEM_FREE (header
);
303 ACPI_MEM_FREE (table_info
);
305 return_ACPI_STATUS (status
);
309 /* TBD: Move to a new file */
311 #if ACPI_MACHINE_WIDTH != 16
313 /*******************************************************************************
315 * FUNCTION: acpi_find_root_pointer
317 * PARAMETERS: **rsdp_address - Where to place the RSDP address
318 * Flags - Logical/Physical addressing
320 * RETURN: Status, Physical address of the RSDP
322 * DESCRIPTION: Find the RSDP
324 ******************************************************************************/
327 acpi_find_root_pointer (
329 struct acpi_pointer
*rsdp_address
)
331 struct acpi_table_desc table_info
;
335 ACPI_FUNCTION_TRACE ("acpi_find_root_pointer");
340 status
= acpi_tb_find_rsdp (&table_info
, flags
);
341 if (ACPI_FAILURE (status
)) {
342 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "RSDP structure not found, %s Flags=%X\n",
343 acpi_format_exception (status
), flags
));
344 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
347 rsdp_address
->pointer_type
= ACPI_PHYSICAL_POINTER
;
348 rsdp_address
->pointer
.physical
= table_info
.physical_address
;
349 return_ACPI_STATUS (AE_OK
);
353 /*******************************************************************************
355 * FUNCTION: acpi_tb_scan_memory_for_rsdp
357 * PARAMETERS: start_address - Starting pointer for search
358 * Length - Maximum length to search
360 * RETURN: Pointer to the RSDP if found, otherwise NULL.
362 * DESCRIPTION: Search a block of memory for the RSDP signature
364 ******************************************************************************/
367 acpi_tb_scan_memory_for_rsdp (
375 ACPI_FUNCTION_TRACE ("tb_scan_memory_for_rsdp");
378 /* Search from given start addr for the requested length */
380 for (offset
= 0, mem_rover
= start_address
;
382 offset
+= ACPI_RSDP_SCAN_STEP
, mem_rover
+= ACPI_RSDP_SCAN_STEP
) {
384 /* The signature and checksum must both be correct */
386 if (ACPI_STRNCMP ((char *) mem_rover
,
387 RSDP_SIG
, sizeof (RSDP_SIG
)-1) == 0 &&
388 acpi_tb_checksum (mem_rover
, ACPI_RSDP_CHECKSUM_LENGTH
) == 0) {
389 /* If so, we have found the RSDP */
391 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
392 "RSDP located at physical address %p\n",mem_rover
));
393 return_PTR (mem_rover
);
397 /* Searched entire block, no RSDP was found */
399 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,"Searched entire block, no RSDP was found.\n"));
404 /*******************************************************************************
406 * FUNCTION: acpi_tb_find_rsdp
408 * PARAMETERS: *table_info - Where the table info is returned
409 * Flags - Current memory mode (logical vs.
410 * physical addressing)
412 * RETURN: Status, RSDP physical address
414 * DESCRIPTION: search lower 1_mbyte of memory for the root system descriptor
415 * pointer structure. If it is found, set *RSDP to point to it.
417 * NOTE1: The RSDp must be either in the first 1_k of the Extended
418 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
419 * Only a 32-bit physical address is necessary.
421 * NOTE2: This function is always available, regardless of the
422 * initialization state of the rest of ACPI.
424 ******************************************************************************/
428 struct acpi_table_desc
*table_info
,
433 u32 physical_address
;
437 ACPI_FUNCTION_TRACE ("tb_find_rsdp");
441 * Scan supports either 1) Logical addressing or 2) Physical addressing
443 if ((flags
& ACPI_MEMORY_MODE
) == ACPI_LOGICAL_ADDRESSING
) {
445 * 1a) Get the location of the EBDA
447 status
= acpi_os_map_memory ((acpi_physical_address
) ACPI_EBDA_PTR_LOCATION
,
448 ACPI_EBDA_PTR_LENGTH
,
449 (void *) &table_ptr
);
450 if (ACPI_FAILURE (status
)) {
451 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Could not map memory at %8.8X for length %X\n",
452 ACPI_EBDA_PTR_LOCATION
, ACPI_EBDA_PTR_LENGTH
));
453 return_ACPI_STATUS (status
);
456 ACPI_MOVE_16_TO_32 (&physical_address
, table_ptr
);
457 physical_address
<<= 4; /* Convert segment to physical address */
458 acpi_os_unmap_memory (table_ptr
, ACPI_EBDA_PTR_LENGTH
);
462 if (physical_address
> 0x400) {
464 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of 1_k length)
466 status
= acpi_os_map_memory ((acpi_physical_address
) physical_address
,
467 ACPI_EBDA_WINDOW_SIZE
,
468 (void *) &table_ptr
);
469 if (ACPI_FAILURE (status
)) {
470 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Could not map memory at %8.8X for length %X\n",
471 physical_address
, ACPI_EBDA_WINDOW_SIZE
));
472 return_ACPI_STATUS (status
);
475 mem_rover
= acpi_tb_scan_memory_for_rsdp (table_ptr
, ACPI_EBDA_WINDOW_SIZE
);
476 acpi_os_unmap_memory (table_ptr
, ACPI_EBDA_WINDOW_SIZE
);
479 /* Found it, return the physical address */
481 physical_address
+= ACPI_PTR_DIFF (mem_rover
, table_ptr
);
483 table_info
->physical_address
= (acpi_physical_address
) physical_address
;
484 return_ACPI_STATUS (AE_OK
);
489 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
491 status
= acpi_os_map_memory ((acpi_physical_address
) ACPI_HI_RSDP_WINDOW_BASE
,
492 ACPI_HI_RSDP_WINDOW_SIZE
,
493 (void *) &table_ptr
);
494 if (ACPI_FAILURE (status
)) {
495 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Could not map memory at %8.8X for length %X\n",
496 ACPI_HI_RSDP_WINDOW_BASE
, ACPI_HI_RSDP_WINDOW_SIZE
));
497 return_ACPI_STATUS (status
);
500 mem_rover
= acpi_tb_scan_memory_for_rsdp (table_ptr
, ACPI_HI_RSDP_WINDOW_SIZE
);
501 acpi_os_unmap_memory (table_ptr
, ACPI_HI_RSDP_WINDOW_SIZE
);
504 /* Found it, return the physical address */
506 physical_address
= ACPI_HI_RSDP_WINDOW_BASE
+ ACPI_PTR_DIFF (mem_rover
, table_ptr
);
508 table_info
->physical_address
= (acpi_physical_address
) physical_address
;
509 return_ACPI_STATUS (AE_OK
);
514 * Physical addressing
518 * 1a) Get the location of the EBDA
520 ACPI_MOVE_16_TO_32 (&physical_address
, ACPI_EBDA_PTR_LOCATION
);
521 physical_address
<<= 4; /* Convert segment to physical address */
525 if (physical_address
> 0x400) {
527 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of 1_k length)
529 mem_rover
= acpi_tb_scan_memory_for_rsdp (ACPI_PHYSADDR_TO_PTR (physical_address
),
530 ACPI_EBDA_WINDOW_SIZE
);
532 /* Found it, return the physical address */
534 table_info
->physical_address
= ACPI_TO_INTEGER (mem_rover
);
535 return_ACPI_STATUS (AE_OK
);
540 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
542 mem_rover
= acpi_tb_scan_memory_for_rsdp (ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE
),
543 ACPI_HI_RSDP_WINDOW_SIZE
);
545 /* Found it, return the physical address */
547 table_info
->physical_address
= ACPI_TO_INTEGER (mem_rover
);
548 return_ACPI_STATUS (AE_OK
);
552 /* RSDP signature was not found */
554 return_ACPI_STATUS (AE_NOT_FOUND
);