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_validate_rsdp
70 * PARAMETERS: Rsdp - Pointer to unvalidated RSDP
74 * DESCRIPTION: Validate the RSDP (ptr)
76 ******************************************************************************/
79 acpi_tb_validate_rsdp (
80 struct rsdp_descriptor *rsdp)
82 ACPI_FUNCTION_ENTRY ();
86 * The signature and checksum must both be correct
88 if (ACPI_STRNCMP ((char *) rsdp, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0) {
89 /* Nope, BAD Signature */
91 return (AE_BAD_SIGNATURE);
94 /* Check the standard checksum */
96 if (acpi_tb_generate_checksum (rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
97 return (AE_BAD_CHECKSUM);
100 /* Check extended checksum if table version >= 2 */
102 if ((rsdp->revision >= 2) &&
103 (acpi_tb_generate_checksum (rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0)) {
104 return (AE_BAD_CHECKSUM);
111 /*******************************************************************************
113 * FUNCTION: acpi_tb_find_table
115 * PARAMETERS: Signature - String with ACPI table signature
116 * oem_id - String with the table OEM ID
117 * oem_table_id - String with the OEM Table ID
118 * table_ptr - Where the table pointer is returned
122 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
123 * Signature, OEM ID and OEM Table ID.
125 ******************************************************************************/
132 struct acpi_table_header **table_ptr)
135 struct acpi_table_header *table;
138 ACPI_FUNCTION_TRACE ("tb_find_table");
141 /* Validate string lengths */
143 if ((ACPI_STRLEN (signature) > ACPI_NAME_SIZE) ||
144 (ACPI_STRLEN (oem_id) > sizeof (table->oem_id)) ||
145 (ACPI_STRLEN (oem_table_id) > sizeof (table->oem_table_id))) {
146 return_ACPI_STATUS (AE_AML_STRING_LIMIT);
149 if (!ACPI_STRNCMP (signature, DSDT_SIG, ACPI_NAME_SIZE)) {
151 * The DSDT pointer is contained in the FADT, not the RSDT.
152 * This code should suffice, because the only code that would perform
153 * a "find" on the DSDT is the data_table_region() AML opcode -- in
154 * which case, the DSDT is guaranteed to be already loaded.
155 * If this becomes insufficient, the FADT will have to be found first.
157 if (!acpi_gbl_DSDT) {
158 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
160 table = acpi_gbl_DSDT;
165 status = acpi_get_firmware_table (signature, 1,
166 ACPI_LOGICAL_ADDRESSING, &table);
167 if (ACPI_FAILURE (status)) {
168 return_ACPI_STATUS (status);
172 /* Check oem_id and oem_table_id */
174 if ((oem_id[0] && ACPI_STRNCMP (
175 oem_id, table->oem_id,
176 sizeof (table->oem_id))) ||
178 (oem_table_id[0] && ACPI_STRNCMP (
179 oem_table_id, table->oem_table_id,
180 sizeof (table->oem_table_id)))) {
181 return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND);
184 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n",
188 return_ACPI_STATUS (AE_OK);
192 /*******************************************************************************
194 * FUNCTION: acpi_get_firmware_table
196 * PARAMETERS: Signature - Any ACPI table signature
197 * Instance - the non zero instance of the table, allows
198 * support for multiple tables of the same type
199 * Flags - Physical/Virtual support
200 * table_pointer - Where a buffer containing the table is
205 * DESCRIPTION: This function is called to get an ACPI table. A buffer is
206 * allocated for the table and returned in table_pointer.
207 * This table will be a complete table including the header.
209 ******************************************************************************/
212 acpi_get_firmware_table (
213 acpi_string signature,
216 struct acpi_table_header **table_pointer)
219 struct acpi_pointer address;
220 struct acpi_table_header *header = NULL;
221 struct acpi_table_desc *table_info = NULL;
222 struct acpi_table_desc *rsdt_info;
228 ACPI_FUNCTION_TRACE ("acpi_get_firmware_table");
232 * Ensure that at least the table manager is initialized. We don't
233 * require that the entire ACPI subsystem is up for this interface.
234 * If we have a buffer, we must have a length too
236 if ((instance == 0) ||
239 return_ACPI_STATUS (AE_BAD_PARAMETER);
242 /* Ensure that we have a RSDP */
244 if (!acpi_gbl_RSDP) {
247 status = acpi_os_get_root_pointer (flags, &address);
248 if (ACPI_FAILURE (status)) {
249 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "RSDP not found\n"));
250 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
253 /* Map and validate the RSDP */
255 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
256 status = acpi_os_map_memory (address.pointer.physical,
257 sizeof (struct rsdp_descriptor), (void *) &acpi_gbl_RSDP);
258 if (ACPI_FAILURE (status)) {
259 return_ACPI_STATUS (status);
263 acpi_gbl_RSDP = address.pointer.logical;
266 /* The RDSP signature and checksum must both be correct */
268 status = acpi_tb_validate_rsdp (acpi_gbl_RSDP);
269 if (ACPI_FAILURE (status)) {
270 return_ACPI_STATUS (status);
274 /* Get the RSDT address via the RSDP */
276 acpi_tb_get_rsdt_address (&address);
277 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
278 "RSDP located at %p, RSDT physical=%8.8X%8.8X \n",
280 ACPI_FORMAT_UINT64 (address.pointer.value)));
282 /* Insert processor_mode flags */
284 address.pointer_type |= flags;
286 /* Get and validate the RSDT */
288 rsdt_info = ACPI_MEM_CALLOCATE (sizeof (struct acpi_table_desc));
290 return_ACPI_STATUS (AE_NO_MEMORY);
293 status = acpi_tb_get_table (&address, rsdt_info);
294 if (ACPI_FAILURE (status)) {
298 status = acpi_tb_validate_rsdt (rsdt_info->pointer);
299 if (ACPI_FAILURE (status)) {
303 /* Allocate a scratch table header and table descriptor */
305 header = ACPI_MEM_ALLOCATE (sizeof (struct acpi_table_header));
307 status = AE_NO_MEMORY;
311 table_info = ACPI_MEM_ALLOCATE (sizeof (struct acpi_table_desc));
313 status = AE_NO_MEMORY;
317 /* Get the number of table pointers within the RSDT */
319 table_count = acpi_tb_get_table_count (acpi_gbl_RSDP, rsdt_info->pointer);
320 address.pointer_type = acpi_gbl_table_flags | flags;
323 * Search the RSDT/XSDT for the correct instance of the
326 for (i = 0, j = 0; i < table_count; i++) {
328 * Get the next table pointer, handle RSDT vs. XSDT
329 * RSDT pointers are 32 bits, XSDT pointers are 64 bits
331 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
332 address.pointer.value = (ACPI_CAST_PTR (
333 RSDT_DESCRIPTOR, rsdt_info->pointer))->table_offset_entry[i];
336 address.pointer.value = (ACPI_CAST_PTR (
337 XSDT_DESCRIPTOR, rsdt_info->pointer))->table_offset_entry[i];
340 /* Get the table header */
342 status = acpi_tb_get_table_header (&address, header);
343 if (ACPI_FAILURE (status)) {
347 /* Compare table signatures and table instance */
349 if (!ACPI_STRNCMP (header->signature, signature, ACPI_NAME_SIZE)) {
350 /* An instance of the table was found */
354 /* Found the correct instance, get the entire table */
356 status = acpi_tb_get_table_body (&address, header, table_info);
357 if (ACPI_FAILURE (status)) {
361 *table_pointer = table_info->pointer;
367 /* Did not find the table */
369 status = AE_NOT_EXIST;
373 if (rsdt_info->pointer) {
374 acpi_os_unmap_memory (rsdt_info->pointer,
375 (acpi_size) rsdt_info->pointer->length);
377 ACPI_MEM_FREE (rsdt_info);
380 ACPI_MEM_FREE (header);
383 ACPI_MEM_FREE (table_info);
385 return_ACPI_STATUS (status);
387 EXPORT_SYMBOL(acpi_get_firmware_table);
390 /* TBD: Move to a new file */
392 #if ACPI_MACHINE_WIDTH != 16
394 /*******************************************************************************
396 * FUNCTION: acpi_find_root_pointer
398 * PARAMETERS: Flags - Logical/Physical addressing
399 * rsdp_address - Where to place the RSDP address
401 * RETURN: Status, Physical address of the RSDP
403 * DESCRIPTION: Find the RSDP
405 ******************************************************************************/
408 acpi_find_root_pointer (
410 struct acpi_pointer *rsdp_address)
412 struct acpi_table_desc table_info;
416 ACPI_FUNCTION_TRACE ("acpi_find_root_pointer");
421 status = acpi_tb_find_rsdp (&table_info, flags);
422 if (ACPI_FAILURE (status)) {
423 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
424 "RSDP structure not found, %s Flags=%X\n",
425 acpi_format_exception (status), flags));
427 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
430 rsdp_address->pointer_type = ACPI_PHYSICAL_POINTER;
431 rsdp_address->pointer.physical = table_info.physical_address;
432 return_ACPI_STATUS (AE_OK);
436 /*******************************************************************************
438 * FUNCTION: acpi_tb_scan_memory_for_rsdp
440 * PARAMETERS: start_address - Starting pointer for search
441 * Length - Maximum length to search
443 * RETURN: Pointer to the RSDP if found, otherwise NULL.
445 * DESCRIPTION: Search a block of memory for the RSDP signature
447 ******************************************************************************/
450 acpi_tb_scan_memory_for_rsdp (
459 ACPI_FUNCTION_TRACE ("tb_scan_memory_for_rsdp");
462 end_address = start_address + length;
464 /* Search from given start address for the requested length */
466 for (mem_rover = start_address; mem_rover < end_address;
467 mem_rover += ACPI_RSDP_SCAN_STEP) {
468 /* The RSDP signature and checksum must both be correct */
470 status = acpi_tb_validate_rsdp (ACPI_CAST_PTR (struct rsdp_descriptor, mem_rover));
471 if (ACPI_SUCCESS (status)) {
472 /* Sig and checksum valid, we have found a real RSDP */
474 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
475 "RSDP located at physical address %p\n", mem_rover));
476 return_PTR (mem_rover);
479 /* No sig match or bad checksum, keep searching */
482 /* Searched entire block, no RSDP was found */
484 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
485 "Searched entire block from %p, valid RSDP was not found\n",
491 /*******************************************************************************
493 * FUNCTION: acpi_tb_find_rsdp
495 * PARAMETERS: table_info - Where the table info is returned
496 * Flags - Current memory mode (logical vs.
497 * physical addressing)
499 * RETURN: Status, RSDP physical address
501 * DESCRIPTION: search lower 1_mbyte of memory for the root system descriptor
502 * pointer structure. If it is found, set *RSDP to point to it.
504 * NOTE1: The RSDp must be either in the first 1_k of the Extended
505 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
506 * Only a 32-bit physical address is necessary.
508 * NOTE2: This function is always available, regardless of the
509 * initialization state of the rest of ACPI.
511 ******************************************************************************/
515 struct acpi_table_desc *table_info,
520 u32 physical_address;
524 ACPI_FUNCTION_TRACE ("tb_find_rsdp");
528 * Scan supports either logical addressing or physical addressing
530 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
531 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
533 status = acpi_os_map_memory (
534 (acpi_physical_address) ACPI_EBDA_PTR_LOCATION,
535 ACPI_EBDA_PTR_LENGTH, (void *) &table_ptr);
536 if (ACPI_FAILURE (status)) {
537 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
538 "Could not map memory at %8.8X for length %X\n",
539 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
541 return_ACPI_STATUS (status);
544 ACPI_MOVE_16_TO_32 (&physical_address, table_ptr);
546 /* Convert segment part to physical address */
548 physical_address <<= 4;
549 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_PTR_LENGTH);
553 if (physical_address > 0x400) {
555 * 1b) Search EBDA paragraphs (EBDa is required to be a
556 * minimum of 1_k length)
558 status = acpi_os_map_memory (
559 (acpi_physical_address) physical_address,
560 ACPI_EBDA_WINDOW_SIZE, (void *) &table_ptr);
561 if (ACPI_FAILURE (status)) {
562 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
563 "Could not map memory at %8.8X for length %X\n",
564 physical_address, ACPI_EBDA_WINDOW_SIZE));
566 return_ACPI_STATUS (status);
569 mem_rover = acpi_tb_scan_memory_for_rsdp (table_ptr,
570 ACPI_EBDA_WINDOW_SIZE);
571 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_WINDOW_SIZE);
574 /* Return the physical address */
576 physical_address += ACPI_PTR_DIFF (mem_rover, table_ptr);
578 table_info->physical_address =
579 (acpi_physical_address) physical_address;
580 return_ACPI_STATUS (AE_OK);
585 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
587 status = acpi_os_map_memory (
588 (acpi_physical_address) ACPI_HI_RSDP_WINDOW_BASE,
589 ACPI_HI_RSDP_WINDOW_SIZE, (void *) &table_ptr);
591 if (ACPI_FAILURE (status)) {
592 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
593 "Could not map memory at %8.8X for length %X\n",
594 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
596 return_ACPI_STATUS (status);
599 mem_rover = acpi_tb_scan_memory_for_rsdp (table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
600 acpi_os_unmap_memory (table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
603 /* Return the physical address */
606 ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (mem_rover, table_ptr);
608 table_info->physical_address =
609 (acpi_physical_address) physical_address;
610 return_ACPI_STATUS (AE_OK);
615 * Physical addressing
618 /* 1a) Get the location of the EBDA */
620 ACPI_MOVE_16_TO_32 (&physical_address, ACPI_EBDA_PTR_LOCATION);
621 physical_address <<= 4; /* Convert segment to physical address */
625 if (physical_address > 0x400) {
627 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of
630 mem_rover = acpi_tb_scan_memory_for_rsdp (
631 ACPI_PHYSADDR_TO_PTR (physical_address),
632 ACPI_EBDA_WINDOW_SIZE);
634 /* Return the physical address */
636 table_info->physical_address = ACPI_TO_INTEGER (mem_rover);
637 return_ACPI_STATUS (AE_OK);
641 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
643 mem_rover = acpi_tb_scan_memory_for_rsdp (
644 ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE),
645 ACPI_HI_RSDP_WINDOW_SIZE);
647 /* Found it, return the physical address */
649 table_info->physical_address = ACPI_TO_INTEGER (mem_rover);
650 return_ACPI_STATUS (AE_OK);
654 /* A valid RSDP was not found */
656 ACPI_REPORT_ERROR (("No valid RSDP was found\n"));
657 return_ACPI_STATUS (AE_NOT_FOUND);