1 /******************************************************************************
3 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
117 #define __TBXFROOT_C__
119 #include <contrib/dev/acpica/acpi.h>
120 #include <contrib/dev/acpica/actables.h>
123 #define _COMPONENT ACPI_TABLES
124 ACPI_MODULE_NAME ("tbxfroot")
126 /* Local prototypes */
130 ACPI_TABLE_DESC *TableInfo,
134 AcpiTbScanMemoryForRsdp (
139 /*******************************************************************************
141 * FUNCTION: AcpiTbValidateRsdp
143 * PARAMETERS: Rsdp - Pointer to unvalidated RSDP
147 * DESCRIPTION: Validate the RSDP (ptr)
149 ******************************************************************************/
153 RSDP_DESCRIPTOR *Rsdp)
155 ACPI_FUNCTION_ENTRY ();
159 * The signature and checksum must both be correct
161 if (ACPI_STRNCMP ((char *) Rsdp, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0)
163 /* Nope, BAD Signature */
165 return (AE_BAD_SIGNATURE);
168 /* Check the standard checksum */
170 if (AcpiTbGenerateChecksum (Rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0)
172 return (AE_BAD_CHECKSUM);
175 /* Check extended checksum if table version >= 2 */
177 if ((Rsdp->Revision >= 2) &&
178 (AcpiTbGenerateChecksum (Rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0))
180 return (AE_BAD_CHECKSUM);
187 /*******************************************************************************
189 * FUNCTION: AcpiTbFindTable
191 * PARAMETERS: Signature - String with ACPI table signature
192 * OemId - String with the table OEM ID
193 * OemTableId - String with the OEM Table ID
194 * TablePtr - Where the table pointer is returned
198 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
199 * Signature, OEM ID and OEM Table ID.
201 ******************************************************************************/
208 ACPI_TABLE_HEADER **TablePtr)
211 ACPI_TABLE_HEADER *Table;
214 ACPI_FUNCTION_TRACE ("TbFindTable");
217 /* Validate string lengths */
219 if ((ACPI_STRLEN (Signature) > ACPI_NAME_SIZE) ||
220 (ACPI_STRLEN (OemId) > sizeof (Table->OemId)) ||
221 (ACPI_STRLEN (OemTableId) > sizeof (Table->OemTableId)))
223 return_ACPI_STATUS (AE_AML_STRING_LIMIT);
226 if (!ACPI_STRNCMP (Signature, DSDT_SIG, ACPI_NAME_SIZE))
229 * The DSDT pointer is contained in the FADT, not the RSDT.
230 * This code should suffice, because the only code that would perform
231 * a "find" on the DSDT is the DataTableRegion() AML opcode -- in
232 * which case, the DSDT is guaranteed to be already loaded.
233 * If this becomes insufficient, the FADT will have to be found first.
237 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
239 Table = AcpiGbl_DSDT;
245 Status = AcpiGetFirmwareTable (Signature, 1,
246 ACPI_LOGICAL_ADDRESSING, &Table);
247 if (ACPI_FAILURE (Status))
249 return_ACPI_STATUS (Status);
253 /* Check OemId and OemTableId */
255 if ((OemId[0] && ACPI_STRNCMP (
257 sizeof (Table->OemId))) ||
259 (OemTableId[0] && ACPI_STRNCMP (
260 OemTableId, Table->OemTableId,
261 sizeof (Table->OemTableId))))
263 return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND);
266 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n",
270 return_ACPI_STATUS (AE_OK);
274 /*******************************************************************************
276 * FUNCTION: AcpiGetFirmwareTable
278 * PARAMETERS: Signature - Any ACPI table signature
279 * Instance - the non zero instance of the table, allows
280 * support for multiple tables of the same type
281 * Flags - Physical/Virtual support
282 * TablePointer - Where a buffer containing the table is
287 * DESCRIPTION: This function is called to get an ACPI table. A buffer is
288 * allocated for the table and returned in TablePointer.
289 * This table will be a complete table including the header.
291 ******************************************************************************/
294 AcpiGetFirmwareTable (
295 ACPI_STRING Signature,
298 ACPI_TABLE_HEADER **TablePointer)
301 ACPI_POINTER Address;
302 ACPI_TABLE_HEADER *Header = NULL;
303 ACPI_TABLE_DESC *TableInfo = NULL;
304 ACPI_TABLE_DESC *RsdtInfo;
310 ACPI_FUNCTION_TRACE ("AcpiGetFirmwareTable");
314 * Ensure that at least the table manager is initialized. We don't
315 * require that the entire ACPI subsystem is up for this interface.
316 * If we have a buffer, we must have a length too
318 if ((Instance == 0) ||
322 return_ACPI_STATUS (AE_BAD_PARAMETER);
325 /* Ensure that we have a RSDP */
331 Status = AcpiOsGetRootPointer (Flags, &Address);
332 if (ACPI_FAILURE (Status))
334 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "RSDP not found\n"));
335 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
338 /* Map and validate the RSDP */
340 if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
342 Status = AcpiOsMapMemory (Address.Pointer.Physical,
343 sizeof (RSDP_DESCRIPTOR), (void *) &AcpiGbl_RSDP);
344 if (ACPI_FAILURE (Status))
346 return_ACPI_STATUS (Status);
351 AcpiGbl_RSDP = Address.Pointer.Logical;
354 /* The RDSP signature and checksum must both be correct */
356 Status = AcpiTbValidateRsdp (AcpiGbl_RSDP);
357 if (ACPI_FAILURE (Status))
359 return_ACPI_STATUS (Status);
363 /* Get the RSDT address via the RSDP */
365 AcpiTbGetRsdtAddress (&Address);
366 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
367 "RSDP located at %p, RSDT physical=%8.8X%8.8X\n",
369 ACPI_FORMAT_UINT64 (Address.Pointer.Value)));
371 /* Insert ProcessorMode flags */
373 Address.PointerType |= Flags;
375 /* Get and validate the RSDT */
377 RsdtInfo = ACPI_MEM_CALLOCATE (sizeof (ACPI_TABLE_DESC));
380 return_ACPI_STATUS (AE_NO_MEMORY);
383 Status = AcpiTbGetTable (&Address, RsdtInfo);
384 if (ACPI_FAILURE (Status))
389 Status = AcpiTbValidateRsdt (RsdtInfo->Pointer);
390 if (ACPI_FAILURE (Status))
395 /* Allocate a scratch table header and table descriptor */
397 Header = ACPI_MEM_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
400 Status = AE_NO_MEMORY;
404 TableInfo = ACPI_MEM_ALLOCATE (sizeof (ACPI_TABLE_DESC));
407 Status = AE_NO_MEMORY;
411 /* Get the number of table pointers within the RSDT */
413 TableCount = AcpiTbGetTableCount (AcpiGbl_RSDP, RsdtInfo->Pointer);
414 Address.PointerType = AcpiGbl_TableFlags | Flags;
417 * Search the RSDT/XSDT for the correct instance of the
420 for (i = 0, j = 0; i < TableCount; i++)
423 * Get the next table pointer, handle RSDT vs. XSDT
424 * RSDT pointers are 32 bits, XSDT pointers are 64 bits
426 if (AcpiGbl_RootTableType == ACPI_TABLE_TYPE_RSDT)
428 Address.Pointer.Value = (ACPI_CAST_PTR (
429 RSDT_DESCRIPTOR, RsdtInfo->Pointer))->TableOffsetEntry[i];
433 Address.Pointer.Value = ACPI_GET_ADDRESS ((ACPI_CAST_PTR (
434 XSDT_DESCRIPTOR, RsdtInfo->Pointer))->TableOffsetEntry[i]);
437 /* Get the table header */
439 Status = AcpiTbGetTableHeader (&Address, Header);
440 if (ACPI_FAILURE (Status))
445 /* Compare table signatures and table instance */
447 if (!ACPI_STRNCMP (Header->Signature, Signature, ACPI_NAME_SIZE))
449 /* An instance of the table was found */
454 /* Found the correct instance, get the entire table */
456 Status = AcpiTbGetTableBody (&Address, Header, TableInfo);
457 if (ACPI_FAILURE (Status))
462 *TablePointer = TableInfo->Pointer;
468 /* Did not find the table */
470 Status = AE_NOT_EXIST;
474 if (RsdtInfo->Pointer)
476 AcpiOsUnmapMemory (RsdtInfo->Pointer,
477 (ACPI_SIZE) RsdtInfo->Pointer->Length);
479 ACPI_MEM_FREE (RsdtInfo);
483 ACPI_MEM_FREE (Header);
487 ACPI_MEM_FREE (TableInfo);
489 return_ACPI_STATUS (Status);
493 /* TBD: Move to a new file */
495 #if ACPI_MACHINE_WIDTH != 16
497 /*******************************************************************************
499 * FUNCTION: AcpiFindRootPointer
501 * PARAMETERS: Flags - Logical/Physical addressing
502 * RsdpAddress - Where to place the RSDP address
504 * RETURN: Status, Physical address of the RSDP
506 * DESCRIPTION: Find the RSDP
508 ******************************************************************************/
511 AcpiFindRootPointer (
513 ACPI_POINTER *RsdpAddress)
515 ACPI_TABLE_DESC TableInfo;
519 ACPI_FUNCTION_TRACE ("AcpiFindRootPointer");
524 Status = AcpiTbFindRsdp (&TableInfo, Flags);
525 if (ACPI_FAILURE (Status))
527 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
528 "RSDP structure not found, %s Flags=%X\n",
529 AcpiFormatException (Status), Flags));
531 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
534 RsdpAddress->PointerType = ACPI_PHYSICAL_POINTER;
535 RsdpAddress->Pointer.Physical = TableInfo.PhysicalAddress;
536 return_ACPI_STATUS (AE_OK);
540 /*******************************************************************************
542 * FUNCTION: AcpiTbScanMemoryForRsdp
544 * PARAMETERS: StartAddress - Starting pointer for search
545 * Length - Maximum length to search
547 * RETURN: Pointer to the RSDP if found, otherwise NULL.
549 * DESCRIPTION: Search a block of memory for the RSDP signature
551 ******************************************************************************/
554 AcpiTbScanMemoryForRsdp (
563 ACPI_FUNCTION_TRACE ("TbScanMemoryForRsdp");
566 EndAddress = StartAddress + Length;
568 /* Search from given start address for the requested length */
570 for (MemRover = StartAddress; MemRover < EndAddress;
571 MemRover += ACPI_RSDP_SCAN_STEP)
573 /* The RSDP signature and checksum must both be correct */
575 Status = AcpiTbValidateRsdp (ACPI_CAST_PTR (RSDP_DESCRIPTOR, MemRover));
576 if (ACPI_SUCCESS (Status))
578 /* Sig and checksum valid, we have found a real RSDP */
580 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
581 "RSDP located at physical address %p\n", MemRover));
582 return_PTR (MemRover);
585 /* No sig match or bad checksum, keep searching */
588 /* Searched entire block, no RSDP was found */
590 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
591 "Searched entire block from %p, valid RSDP was not found\n",
597 /*******************************************************************************
599 * FUNCTION: AcpiTbFindRsdp
601 * PARAMETERS: TableInfo - Where the table info is returned
602 * Flags - Current memory mode (logical vs.
603 * physical addressing)
605 * RETURN: Status, RSDP physical address
607 * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor
608 * pointer structure. If it is found, set *RSDP to point to it.
610 * NOTE1: The RSDP must be either in the first 1K of the Extended
611 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
612 * Only a 32-bit physical address is necessary.
614 * NOTE2: This function is always available, regardless of the
615 * initialization state of the rest of ACPI.
617 ******************************************************************************/
621 ACPI_TABLE_DESC *TableInfo,
626 UINT32 PhysicalAddress;
630 ACPI_FUNCTION_TRACE ("TbFindRsdp");
634 * Scan supports either logical addressing or physical addressing
636 if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
638 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
640 Status = AcpiOsMapMemory (
641 (ACPI_PHYSICAL_ADDRESS) ACPI_EBDA_PTR_LOCATION,
642 ACPI_EBDA_PTR_LENGTH, (void *) &TablePtr);
643 if (ACPI_FAILURE (Status))
645 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
646 "Could not map memory at %8.8X for length %X\n",
647 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
649 return_ACPI_STATUS (Status);
652 ACPI_MOVE_16_TO_32 (&PhysicalAddress, TablePtr);
654 /* Convert segment part to physical address */
656 PhysicalAddress <<= 4;
657 AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_PTR_LENGTH);
661 if (PhysicalAddress > 0x400)
664 * 1b) Search EBDA paragraphs (EBDA is required to be a
665 * minimum of 1K length)
667 Status = AcpiOsMapMemory (
668 (ACPI_PHYSICAL_ADDRESS) PhysicalAddress,
669 ACPI_EBDA_WINDOW_SIZE, (void *) &TablePtr);
670 if (ACPI_FAILURE (Status))
672 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
673 "Could not map memory at %8.8X for length %X\n",
674 PhysicalAddress, ACPI_EBDA_WINDOW_SIZE));
676 return_ACPI_STATUS (Status);
679 MemRover = AcpiTbScanMemoryForRsdp (TablePtr,
680 ACPI_EBDA_WINDOW_SIZE);
681 AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_WINDOW_SIZE);
685 /* Return the physical address */
687 PhysicalAddress += ACPI_PTR_DIFF (MemRover, TablePtr);
689 TableInfo->PhysicalAddress =
690 (ACPI_PHYSICAL_ADDRESS) PhysicalAddress;
691 return_ACPI_STATUS (AE_OK);
696 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
698 Status = AcpiOsMapMemory (
699 (ACPI_PHYSICAL_ADDRESS) ACPI_HI_RSDP_WINDOW_BASE,
700 ACPI_HI_RSDP_WINDOW_SIZE, (void *) &TablePtr);
702 if (ACPI_FAILURE (Status))
704 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
705 "Could not map memory at %8.8X for length %X\n",
706 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
708 return_ACPI_STATUS (Status);
711 MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
712 AcpiOsUnmapMemory (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
716 /* Return the physical address */
719 ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (MemRover, TablePtr);
721 TableInfo->PhysicalAddress =
722 (ACPI_PHYSICAL_ADDRESS) PhysicalAddress;
723 return_ACPI_STATUS (AE_OK);
728 * Physical addressing
732 /* 1a) Get the location of the EBDA */
734 ACPI_MOVE_16_TO_32 (&PhysicalAddress, ACPI_EBDA_PTR_LOCATION);
735 PhysicalAddress <<= 4; /* Convert segment to physical address */
739 if (PhysicalAddress > 0x400)
742 * 1b) Search EBDA paragraphs (EBDA is required to be a minimum of
745 MemRover = AcpiTbScanMemoryForRsdp (
746 ACPI_PHYSADDR_TO_PTR (PhysicalAddress),
747 ACPI_EBDA_WINDOW_SIZE);
750 /* Return the physical address */
752 TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
753 return_ACPI_STATUS (AE_OK);
757 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
759 MemRover = AcpiTbScanMemoryForRsdp (
760 ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE),
761 ACPI_HI_RSDP_WINDOW_SIZE);
764 /* Found it, return the physical address */
766 TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
767 return_ACPI_STATUS (AE_OK);
771 /* A valid RSDP was not found */
773 ACPI_REPORT_ERROR (("No valid RSDP was found\n"));
774 return_ACPI_STATUS (AE_NOT_FOUND);