1 /******************************************************************************
3 * Module Name: oslinuxtbl - Linux OSL for obtaining ACPI tables
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "acpidump.h"
155 #define _COMPONENT ACPI_OS_SERVICES
156 ACPI_MODULE_NAME ("oslinuxtbl")
164 /* List of information about obtained ACPI tables */
166 typedef struct osl_table_info
168 struct osl_table_info *Next;
170 char Signature[ACPI_NAMESEG_SIZE];
174 /* Local prototypes */
181 OslTableNameFromFile (
192 OslReadTableFromFile (
194 ACPI_SIZE FileOffset,
195 ACPI_TABLE_HEADER **Table);
201 ACPI_TABLE_HEADER **Table);
205 ACPI_TABLE_HEADER *Table);
207 static ACPI_PHYSICAL_ADDRESS
208 OslFindRsdpViaEfiByKeyword (
210 const char *Keyword);
212 static ACPI_PHYSICAL_ADDRESS
221 OslListCustomizedTables (
225 OslGetCustomizedTable (
229 ACPI_TABLE_HEADER **Table,
230 ACPI_PHYSICAL_ADDRESS *Address);
240 ACPI_TABLE_HEADER **Table,
241 ACPI_PHYSICAL_ADDRESS *Address);
245 ACPI_STATUS DefaultStatus);
250 #define DYNAMIC_TABLE_DIR "/sys/firmware/acpi/tables/dynamic"
251 #define STATIC_TABLE_DIR "/sys/firmware/acpi/tables"
252 #define EFI_SYSTAB "/sys/firmware/efi/systab"
254 /* Should we get dynamically loaded SSDTs from DYNAMIC_TABLE_DIR? */
256 UINT8 Gbl_DumpDynamicTables = TRUE;
258 /* Initialization flags */
260 UINT8 Gbl_TableListInitialized = FALSE;
262 /* Local copies of main ACPI tables */
264 ACPI_TABLE_RSDP Gbl_Rsdp;
265 ACPI_TABLE_FADT *Gbl_Fadt = NULL;
266 ACPI_TABLE_RSDT *Gbl_Rsdt = NULL;
267 ACPI_TABLE_XSDT *Gbl_Xsdt = NULL;
269 /* Table addresses */
271 ACPI_PHYSICAL_ADDRESS Gbl_FadtAddress = 0;
272 ACPI_PHYSICAL_ADDRESS Gbl_RsdpAddress = 0;
274 /* Revision of RSD PTR */
276 UINT8 Gbl_Revision = 0;
278 OSL_TABLE_INFO *Gbl_TableListHead = NULL;
279 UINT32 Gbl_TableCount = 0;
282 /******************************************************************************
284 * FUNCTION: OslGetLastStatus
286 * PARAMETERS: DefaultStatus - Default error status to return
288 * RETURN: Status; Converted from errno.
290 * DESCRIPTION: Get last errno and convert it to ACPI_STATUS.
292 *****************************************************************************/
296 ACPI_STATUS DefaultStatus)
308 return (AE_NOT_FOUND);
312 return (AE_NO_MEMORY);
316 return (DefaultStatus);
321 /******************************************************************************
323 * FUNCTION: AcpiOsGetTableByAddress
325 * PARAMETERS: Address - Physical address of the ACPI table
326 * Table - Where a pointer to the table is returned
328 * RETURN: Status; Table buffer is returned if AE_OK.
329 * AE_NOT_FOUND: A valid table was not found at the address
331 * DESCRIPTION: Get an ACPI table via a physical memory address.
333 *****************************************************************************/
336 AcpiOsGetTableByAddress (
337 ACPI_PHYSICAL_ADDRESS Address,
338 ACPI_TABLE_HEADER **Table)
341 ACPI_TABLE_HEADER *MappedTable;
342 ACPI_TABLE_HEADER *LocalTable = NULL;
343 ACPI_STATUS Status = AE_OK;
346 /* Get main ACPI tables from memory on first invocation of this function */
348 Status = OslTableInitialize ();
349 if (ACPI_FAILURE (Status))
354 /* Map the table and validate it */
356 Status = OslMapTable (Address, NULL, &MappedTable);
357 if (ACPI_FAILURE (Status))
362 /* Copy table to local buffer and return it */
364 TableLength = ApGetTableLength (MappedTable);
365 if (TableLength == 0)
367 Status = AE_BAD_HEADER;
371 LocalTable = calloc (1, TableLength);
374 Status = AE_NO_MEMORY;
378 memcpy (LocalTable, MappedTable, TableLength);
381 OslUnmapTable (MappedTable);
387 /******************************************************************************
389 * FUNCTION: AcpiOsGetTableByName
391 * PARAMETERS: Signature - ACPI Signature for desired table. Must be
392 * a null terminated 4-character string.
393 * Instance - Multiple table support for SSDT/UEFI (0...n)
394 * Must be 0 for other tables.
395 * Table - Where a pointer to the table is returned
396 * Address - Where the table physical address is returned
398 * RETURN: Status; Table buffer and physical address returned if AE_OK.
399 * AE_LIMIT: Instance is beyond valid limit
400 * AE_NOT_FOUND: A table with the signature was not found
402 * NOTE: Assumes the input signature is uppercase.
404 *****************************************************************************/
407 AcpiOsGetTableByName (
410 ACPI_TABLE_HEADER **Table,
411 ACPI_PHYSICAL_ADDRESS *Address)
416 /* Get main ACPI tables from memory on first invocation of this function */
418 Status = OslTableInitialize ();
419 if (ACPI_FAILURE (Status))
424 /* Not a main ACPI table, attempt to extract it from the RSDT/XSDT */
426 if (!Gbl_DumpCustomizedTables)
428 /* Attempt to get the table from the memory */
430 Status = OslGetBiosTable (Signature, Instance, Table, Address);
434 /* Attempt to get the table from the static directory */
436 Status = OslGetCustomizedTable (STATIC_TABLE_DIR, Signature,
437 Instance, Table, Address);
440 if (ACPI_FAILURE (Status) && Status == AE_LIMIT)
442 if (Gbl_DumpDynamicTables)
444 /* Attempt to get a dynamic table */
446 Status = OslGetCustomizedTable (DYNAMIC_TABLE_DIR, Signature,
447 Instance, Table, Address);
455 /******************************************************************************
457 * FUNCTION: OslAddTableToList
459 * PARAMETERS: Signature - Table signature
460 * Instance - Table instance
462 * RETURN: Status; Successfully added if AE_OK.
463 * AE_NO_MEMORY: Memory allocation error
465 * DESCRIPTION: Insert a table structure into OSL table list.
467 *****************************************************************************/
474 OSL_TABLE_INFO *NewInfo;
475 OSL_TABLE_INFO *Next;
476 UINT32 NextInstance = 0;
477 BOOLEAN Found = FALSE;
480 NewInfo = calloc (1, sizeof (OSL_TABLE_INFO));
483 return (AE_NO_MEMORY);
486 ACPI_COPY_NAMESEG (NewInfo->Signature, Signature);
488 if (!Gbl_TableListHead)
490 Gbl_TableListHead = NewInfo;
494 Next = Gbl_TableListHead;
497 if (ACPI_COMPARE_NAMESEG (Next->Signature, Signature))
499 if (Next->Instance == Instance)
503 if (Next->Instance >= NextInstance)
505 NextInstance = Next->Instance + 1;
515 Next->Next = NewInfo;
523 "%4.4s: Warning unmatched table instance %d, expected %d\n",
524 Signature, Instance, NextInstance);
526 Instance = NextInstance;
529 NewInfo->Instance = Instance;
536 /******************************************************************************
538 * FUNCTION: AcpiOsGetTableByIndex
540 * PARAMETERS: Index - Which table to get
541 * Table - Where a pointer to the table is returned
542 * Instance - Where a pointer to the table instance no. is
544 * Address - Where the table physical address is returned
546 * RETURN: Status; Table buffer and physical address returned if AE_OK.
547 * AE_LIMIT: Index is beyond valid limit
549 * DESCRIPTION: Get an ACPI table via an index value (0 through n). Returns
550 * AE_LIMIT when an invalid index is reached. Index is not
551 * necessarily an index into the RSDT/XSDT.
553 *****************************************************************************/
556 AcpiOsGetTableByIndex (
558 ACPI_TABLE_HEADER **Table,
560 ACPI_PHYSICAL_ADDRESS *Address)
562 OSL_TABLE_INFO *Info;
567 /* Get main ACPI tables from memory on first invocation of this function */
569 Status = OslTableInitialize ();
570 if (ACPI_FAILURE (Status))
577 if (Index >= Gbl_TableCount)
582 /* Point to the table list entry specified by the Index argument */
584 Info = Gbl_TableListHead;
585 for (i = 0; i < Index; i++)
590 /* Now we can just get the table via the signature */
592 Status = AcpiOsGetTableByName (Info->Signature, Info->Instance,
595 if (ACPI_SUCCESS (Status))
597 *Instance = Info->Instance;
603 /******************************************************************************
605 * FUNCTION: OslFindRsdpViaEfiByKeyword
607 * PARAMETERS: Keyword - Character string indicating ACPI GUID version
610 * RETURN: RSDP address if found
612 * DESCRIPTION: Find RSDP address via EFI using keyword indicating the ACPI
615 *****************************************************************************/
617 static ACPI_PHYSICAL_ADDRESS
618 OslFindRsdpViaEfiByKeyword (
623 unsigned long long Address = 0;
627 snprintf (Format, 32, "%s=%s", Keyword, "%llx");
628 fseek (File, 0, SEEK_SET);
629 while (fgets (Buffer, 80, File))
631 if (sscanf (Buffer, Format, &Address) == 1)
637 return ((ACPI_PHYSICAL_ADDRESS) (Address));
641 /******************************************************************************
643 * FUNCTION: OslFindRsdpViaEfi
647 * RETURN: RSDP address if found
649 * DESCRIPTION: Find RSDP address via EFI.
651 *****************************************************************************/
653 static ACPI_PHYSICAL_ADDRESS
658 ACPI_PHYSICAL_ADDRESS Address = 0;
661 File = fopen (EFI_SYSTAB, "r");
664 Address = OslFindRsdpViaEfiByKeyword (File, "ACPI20");
667 Address = OslFindRsdpViaEfiByKeyword (File, "ACPI");
676 /******************************************************************************
678 * FUNCTION: OslLoadRsdp
684 * DESCRIPTION: Scan and load RSDP.
686 *****************************************************************************/
692 ACPI_TABLE_HEADER *MappedTable;
694 ACPI_PHYSICAL_ADDRESS RsdpBase;
698 /* Get RSDP from memory */
700 RsdpSize = sizeof (ACPI_TABLE_RSDP);
703 RsdpBase = Gbl_RsdpBase;
707 RsdpBase = OslFindRsdpViaEfi ();
712 RsdpBase = ACPI_HI_RSDP_WINDOW_BASE;
713 RsdpSize = ACPI_HI_RSDP_WINDOW_SIZE;
716 RsdpAddress = AcpiOsMapMemory (RsdpBase, RsdpSize);
719 return (OslGetLastStatus (AE_BAD_ADDRESS));
722 /* Search low memory for the RSDP */
724 MappedTable = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
725 AcpiTbScanMemoryForRsdp (RsdpAddress, RsdpSize));
728 AcpiOsUnmapMemory (RsdpAddress, RsdpSize);
729 return (AE_NOT_FOUND);
732 Gbl_RsdpAddress = RsdpBase + (ACPI_CAST8 (MappedTable) - RsdpAddress);
734 memcpy (&Gbl_Rsdp, MappedTable, sizeof (ACPI_TABLE_RSDP));
735 AcpiOsUnmapMemory (RsdpAddress, RsdpSize);
741 /******************************************************************************
743 * FUNCTION: OslCanUseXsdt
747 * RETURN: TRUE if XSDT is allowed to be used.
749 * DESCRIPTION: This function collects logic that can be used to determine if
750 * XSDT should be used instead of RSDT.
752 *****************************************************************************/
758 if (Gbl_Revision && !AcpiGbl_DoNotUseXsdt)
769 /******************************************************************************
771 * FUNCTION: OslTableInitialize
777 * DESCRIPTION: Initialize ACPI table data. Get and store main ACPI tables to
778 * local variables. Main ACPI tables include RSDT, FADT, RSDT,
781 *****************************************************************************/
788 ACPI_PHYSICAL_ADDRESS Address;
791 if (Gbl_TableListInitialized)
796 if (!Gbl_DumpCustomizedTables)
798 /* Get RSDP from memory */
800 Status = OslLoadRsdp ();
801 if (ACPI_FAILURE (Status))
806 /* Get XSDT from memory */
808 if (Gbl_Rsdp.Revision && !Gbl_DoNotDumpXsdt)
817 Status = OslGetBiosTable (ACPI_SIG_XSDT, 0,
818 ACPI_CAST_PTR (ACPI_TABLE_HEADER *, &Gbl_Xsdt), &Address);
819 if (ACPI_FAILURE (Status))
825 /* Get RSDT from memory */
827 if (Gbl_Rsdp.RsdtPhysicalAddress)
835 Status = OslGetBiosTable (ACPI_SIG_RSDT, 0,
836 ACPI_CAST_PTR (ACPI_TABLE_HEADER *, &Gbl_Rsdt), &Address);
837 if (ACPI_FAILURE (Status))
843 /* Get FADT from memory */
851 Status = OslGetBiosTable (ACPI_SIG_FADT, 0,
852 ACPI_CAST_PTR (ACPI_TABLE_HEADER *, &Gbl_Fadt), &Gbl_FadtAddress);
853 if (ACPI_FAILURE (Status))
858 /* Add mandatory tables to global table list first */
860 Status = OslAddTableToList (ACPI_RSDP_NAME, 0);
861 if (ACPI_FAILURE (Status))
866 Status = OslAddTableToList (ACPI_SIG_RSDT, 0);
867 if (ACPI_FAILURE (Status))
872 if (Gbl_Revision == 2)
874 Status = OslAddTableToList (ACPI_SIG_XSDT, 0);
875 if (ACPI_FAILURE (Status))
881 Status = OslAddTableToList (ACPI_SIG_DSDT, 0);
882 if (ACPI_FAILURE (Status))
887 Status = OslAddTableToList (ACPI_SIG_FACS, 0);
888 if (ACPI_FAILURE (Status))
893 /* Add all tables found in the memory */
895 Status = OslListBiosTables ();
896 if (ACPI_FAILURE (Status))
903 /* Add all tables found in the static directory */
905 Status = OslListCustomizedTables (STATIC_TABLE_DIR);
906 if (ACPI_FAILURE (Status))
912 if (Gbl_DumpDynamicTables)
914 /* Add all dynamically loaded tables in the dynamic directory */
916 Status = OslListCustomizedTables (DYNAMIC_TABLE_DIR);
917 if (ACPI_FAILURE (Status))
923 Gbl_TableListInitialized = TRUE;
928 /******************************************************************************
930 * FUNCTION: OslListBiosTables
934 * RETURN: Status; Table list is initialized if AE_OK.
936 * DESCRIPTION: Add ACPI tables to the table list from memory.
938 * NOTE: This works on Linux as table customization does not modify the
939 * addresses stored in RSDP/RSDT/XSDT/FADT.
941 *****************************************************************************/
947 ACPI_TABLE_HEADER *MappedTable = NULL;
949 UINT8 NumberOfTables;
951 ACPI_PHYSICAL_ADDRESS TableAddress = 0;
952 ACPI_STATUS Status = AE_OK;
956 if (OslCanUseXsdt ())
958 ItemSize = sizeof (UINT64);
959 TableData = ACPI_CAST8 (Gbl_Xsdt) + sizeof (ACPI_TABLE_HEADER);
961 (UINT8) ((Gbl_Xsdt->Header.Length - sizeof (ACPI_TABLE_HEADER))
964 else /* Use RSDT if XSDT is not available */
966 ItemSize = sizeof (UINT32);
967 TableData = ACPI_CAST8 (Gbl_Rsdt) + sizeof (ACPI_TABLE_HEADER);
969 (UINT8) ((Gbl_Rsdt->Header.Length - sizeof (ACPI_TABLE_HEADER))
973 /* Search RSDT/XSDT for the requested table */
975 for (i = 0; i < NumberOfTables; ++i, TableData += ItemSize)
977 if (OslCanUseXsdt ())
980 (ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST64 (TableData));
985 (ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST32 (TableData));
988 /* Skip NULL entries in RSDT/XSDT */
990 if (TableAddress == 0)
995 Status = OslMapTable (TableAddress, NULL, &MappedTable);
996 if (ACPI_FAILURE (Status))
1001 OslAddTableToList (MappedTable->Signature, 0);
1002 OslUnmapTable (MappedTable);
1009 /******************************************************************************
1011 * FUNCTION: OslGetBiosTable
1013 * PARAMETERS: Signature - ACPI Signature for common table. Must be
1014 * a null terminated 4-character string.
1015 * Instance - Multiple table support for SSDT/UEFI (0...n)
1016 * Must be 0 for other tables.
1017 * Table - Where a pointer to the table is returned
1018 * Address - Where the table physical address is returned
1020 * RETURN: Status; Table buffer and physical address returned if AE_OK.
1021 * AE_LIMIT: Instance is beyond valid limit
1022 * AE_NOT_FOUND: A table with the signature was not found
1024 * DESCRIPTION: Get a BIOS provided ACPI table
1026 * NOTE: Assumes the input signature is uppercase.
1028 *****************************************************************************/
1034 ACPI_TABLE_HEADER **Table,
1035 ACPI_PHYSICAL_ADDRESS *Address)
1037 ACPI_TABLE_HEADER *LocalTable = NULL;
1038 ACPI_TABLE_HEADER *MappedTable = NULL;
1040 UINT8 NumberOfTables;
1042 UINT32 CurrentInstance = 0;
1043 ACPI_PHYSICAL_ADDRESS TableAddress;
1044 ACPI_PHYSICAL_ADDRESS FirstTableAddress = 0;
1045 UINT32 TableLength = 0;
1046 ACPI_STATUS Status = AE_OK;
1050 /* Handle special tables whose addresses are not in RSDT/XSDT */
1052 if (ACPI_COMPARE_NAMESEG (Signature, ACPI_RSDP_NAME) ||
1053 ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_RSDT) ||
1054 ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_XSDT) ||
1055 ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_DSDT) ||
1056 ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_FACS))
1064 * Get the appropriate address, either 32-bit or 64-bit. Be very
1065 * careful about the FADT length and validate table addresses.
1066 * Note: The 64-bit addresses have priority.
1068 if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_DSDT))
1070 if (CurrentInstance < 2)
1072 if ((Gbl_Fadt->Header.Length >= MIN_FADT_FOR_XDSDT) &&
1073 Gbl_Fadt->XDsdt && CurrentInstance == 0)
1075 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_Fadt->XDsdt;
1077 else if ((Gbl_Fadt->Header.Length >= MIN_FADT_FOR_DSDT) &&
1078 Gbl_Fadt->Dsdt != FirstTableAddress)
1080 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_Fadt->Dsdt;
1084 else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_FACS))
1086 if (CurrentInstance < 2)
1088 if ((Gbl_Fadt->Header.Length >= MIN_FADT_FOR_XFACS) &&
1089 Gbl_Fadt->XFacs && CurrentInstance == 0)
1091 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_Fadt->XFacs;
1093 else if ((Gbl_Fadt->Header.Length >= MIN_FADT_FOR_FACS) &&
1094 Gbl_Fadt->Facs != FirstTableAddress)
1096 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_Fadt->Facs;
1100 else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_XSDT))
1104 return (AE_BAD_SIGNATURE);
1106 if (CurrentInstance == 0)
1109 (ACPI_PHYSICAL_ADDRESS) Gbl_Rsdp.XsdtPhysicalAddress;
1112 else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_RSDT))
1114 if (CurrentInstance == 0)
1117 (ACPI_PHYSICAL_ADDRESS) Gbl_Rsdp.RsdtPhysicalAddress;
1122 if (CurrentInstance == 0)
1124 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_RsdpAddress;
1125 Signature = ACPI_SIG_RSDP;
1129 if (TableAddress == 0)
1134 /* Now we can get the requested special table */
1136 Status = OslMapTable (TableAddress, Signature, &MappedTable);
1137 if (ACPI_FAILURE (Status))
1142 TableLength = ApGetTableLength (MappedTable);
1143 if (FirstTableAddress == 0)
1145 FirstTableAddress = TableAddress;
1148 /* Match table instance */
1150 if (CurrentInstance != Instance)
1152 OslUnmapTable (MappedTable);
1155 goto FindNextInstance;
1158 else /* Case for a normal ACPI table */
1160 if (OslCanUseXsdt ())
1162 ItemSize = sizeof (UINT64);
1163 TableData = ACPI_CAST8 (Gbl_Xsdt) + sizeof (ACPI_TABLE_HEADER);
1165 (UINT8) ((Gbl_Xsdt->Header.Length - sizeof (ACPI_TABLE_HEADER))
1168 else /* Use RSDT if XSDT is not available */
1170 ItemSize = sizeof (UINT32);
1171 TableData = ACPI_CAST8 (Gbl_Rsdt) + sizeof (ACPI_TABLE_HEADER);
1173 (UINT8) ((Gbl_Rsdt->Header.Length - sizeof (ACPI_TABLE_HEADER))
1177 /* Search RSDT/XSDT for the requested table */
1179 for (i = 0; i < NumberOfTables; ++i, TableData += ItemSize)
1181 if (OslCanUseXsdt ())
1184 (ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST64 (TableData));
1189 (ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST32 (TableData));
1192 /* Skip NULL entries in RSDT/XSDT */
1194 if (TableAddress == 0)
1199 Status = OslMapTable (TableAddress, NULL, &MappedTable);
1200 if (ACPI_FAILURE (Status))
1204 TableLength = MappedTable->Length;
1206 /* Does this table match the requested signature? */
1208 if (!ACPI_COMPARE_NAMESEG (MappedTable->Signature, Signature))
1210 OslUnmapTable (MappedTable);
1215 /* Match table instance (for SSDT/UEFI tables) */
1217 if (CurrentInstance != Instance)
1219 OslUnmapTable (MappedTable);
1236 if (TableLength == 0)
1238 Status = AE_BAD_HEADER;
1242 /* Copy table to local buffer and return it */
1244 LocalTable = calloc (1, TableLength);
1247 Status = AE_NO_MEMORY;
1251 memcpy (LocalTable, MappedTable, TableLength);
1252 *Address = TableAddress;
1253 *Table = LocalTable;
1256 OslUnmapTable (MappedTable);
1261 /******************************************************************************
1263 * FUNCTION: OslListCustomizedTables
1265 * PARAMETERS: Directory - Directory that contains the tables
1267 * RETURN: Status; Table list is initialized if AE_OK.
1269 * DESCRIPTION: Add ACPI tables to the table list from a directory.
1271 *****************************************************************************/
1274 OslListCustomizedTables (
1279 char TempName[ACPI_NAMESEG_SIZE];
1281 ACPI_STATUS Status = AE_OK;
1284 /* Open the requested directory */
1286 TableDir = AcpiOsOpenDirectory (Directory, "*", REQUEST_FILE_ONLY);
1289 return (OslGetLastStatus (AE_NOT_FOUND));
1292 /* Examine all entries in this directory */
1294 while ((Filename = AcpiOsGetNextFilename (TableDir)))
1296 /* Extract table name and instance number */
1298 Status = OslTableNameFromFile (Filename, TempName, &Instance);
1300 /* Ignore meaningless files */
1302 if (ACPI_FAILURE (Status))
1307 /* Add new info node to global table list */
1309 Status = OslAddTableToList (TempName, Instance);
1310 if (ACPI_FAILURE (Status))
1316 AcpiOsCloseDirectory (TableDir);
1321 /******************************************************************************
1323 * FUNCTION: OslMapTable
1325 * PARAMETERS: Address - Address of the table in memory
1326 * Signature - Optional ACPI Signature for desired table.
1327 * Null terminated 4-character string.
1328 * Table - Where a pointer to the mapped table is
1331 * RETURN: Status; Mapped table is returned if AE_OK.
1332 * AE_NOT_FOUND: A valid table was not found at the address
1334 * DESCRIPTION: Map entire ACPI table into caller's address space.
1336 *****************************************************************************/
1342 ACPI_TABLE_HEADER **Table)
1344 ACPI_TABLE_HEADER *MappedTable;
1350 return (AE_BAD_ADDRESS);
1354 * Map the header so we can get the table length.
1355 * Use sizeof (ACPI_TABLE_HEADER) as:
1356 * 1. it is bigger than 24 to include RSDP->Length
1357 * 2. it is smaller than sizeof (ACPI_TABLE_RSDP)
1359 MappedTable = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
1362 fprintf (stderr, "Could not map table header at 0x%8.8X%8.8X\n",
1363 ACPI_FORMAT_UINT64 (Address));
1364 return (OslGetLastStatus (AE_BAD_ADDRESS));
1367 /* If specified, signature must match */
1371 if (ACPI_VALIDATE_RSDP_SIG (Signature))
1373 if (!ACPI_VALIDATE_RSDP_SIG (MappedTable->Signature))
1375 AcpiOsUnmapMemory (MappedTable, sizeof (ACPI_TABLE_HEADER));
1376 return (AE_BAD_SIGNATURE);
1379 else if (!ACPI_COMPARE_NAMESEG (Signature, MappedTable->Signature))
1381 AcpiOsUnmapMemory (MappedTable, sizeof (ACPI_TABLE_HEADER));
1382 return (AE_BAD_SIGNATURE);
1386 /* Map the entire table */
1388 Length = ApGetTableLength (MappedTable);
1389 AcpiOsUnmapMemory (MappedTable, sizeof (ACPI_TABLE_HEADER));
1392 return (AE_BAD_HEADER);
1395 MappedTable = AcpiOsMapMemory (Address, Length);
1398 fprintf (stderr, "Could not map table at 0x%8.8X%8.8X length %8.8X\n",
1399 ACPI_FORMAT_UINT64 (Address), Length);
1400 return (OslGetLastStatus (AE_INVALID_TABLE_LENGTH));
1403 (void) ApIsValidChecksum (MappedTable);
1405 *Table = MappedTable;
1410 /******************************************************************************
1412 * FUNCTION: OslUnmapTable
1414 * PARAMETERS: Table - A pointer to the mapped table
1418 * DESCRIPTION: Unmap entire ACPI table.
1420 *****************************************************************************/
1424 ACPI_TABLE_HEADER *Table)
1428 AcpiOsUnmapMemory (Table, ApGetTableLength (Table));
1433 /******************************************************************************
1435 * FUNCTION: OslTableNameFromFile
1437 * PARAMETERS: Filename - File that contains the desired table
1438 * Signature - Pointer to 4-character buffer to store
1439 * extracted table signature.
1440 * Instance - Pointer to integer to store extracted
1441 * table instance number.
1443 * RETURN: Status; Table name is extracted if AE_OK.
1445 * DESCRIPTION: Extract table signature and instance number from a table file
1448 *****************************************************************************/
1451 OslTableNameFromFile (
1457 /* Ignore meaningless files */
1459 if (strlen (Filename) < ACPI_NAMESEG_SIZE)
1461 return (AE_BAD_SIGNATURE);
1464 /* Extract instance number */
1466 if (isdigit ((int) Filename[ACPI_NAMESEG_SIZE]))
1468 sscanf (&Filename[ACPI_NAMESEG_SIZE], "%u", Instance);
1470 else if (strlen (Filename) != ACPI_NAMESEG_SIZE)
1472 return (AE_BAD_SIGNATURE);
1479 /* Extract signature */
1481 ACPI_COPY_NAMESEG (Signature, Filename);
1486 /******************************************************************************
1488 * FUNCTION: OslReadTableFromFile
1490 * PARAMETERS: Filename - File that contains the desired table
1491 * FileOffset - Offset of the table in file
1492 * Table - Where a pointer to the table is returned
1494 * RETURN: Status; Table buffer is returned if AE_OK.
1496 * DESCRIPTION: Read a ACPI table from a file.
1498 *****************************************************************************/
1501 OslReadTableFromFile (
1503 ACPI_SIZE FileOffset,
1504 ACPI_TABLE_HEADER **Table)
1507 ACPI_TABLE_HEADER Header;
1508 ACPI_TABLE_HEADER *LocalTable = NULL;
1511 ACPI_STATUS Status = AE_OK;
1516 TableFile = fopen (Filename, "rb");
1517 if (TableFile == NULL)
1519 fprintf (stderr, "Could not open table file: %s\n", Filename);
1520 return (OslGetLastStatus (AE_NOT_FOUND));
1523 fseek (TableFile, FileOffset, SEEK_SET);
1525 /* Read the Table header to get the table length */
1527 Count = fread (&Header, 1, sizeof (ACPI_TABLE_HEADER), TableFile);
1528 if (Count != sizeof (ACPI_TABLE_HEADER))
1530 fprintf (stderr, "Could not read table header: %s\n", Filename);
1531 Status = AE_BAD_HEADER;
1535 #ifdef ACPI_OBSOLETE_FUNCTIONS
1537 /* If signature is specified, it must match the table */
1541 if (ACPI_VALIDATE_RSDP_SIG (Signature))
1543 if (!ACPI_VALIDATE_RSDP_SIG (Header.Signature)) {
1544 fprintf (stderr, "Incorrect RSDP signature: found %8.8s\n",
1546 Status = AE_BAD_SIGNATURE;
1550 else if (!ACPI_COMPARE_NAMESEG (Signature, Header.Signature))
1552 fprintf (stderr, "Incorrect signature: Expecting %4.4s, found %4.4s\n",
1553 Signature, Header.Signature);
1554 Status = AE_BAD_SIGNATURE;
1560 TableLength = ApGetTableLength (&Header);
1561 if (TableLength == 0)
1563 Status = AE_BAD_HEADER;
1567 /* Read the entire table into a local buffer */
1569 LocalTable = calloc (1, TableLength);
1573 "%4.4s: Could not allocate buffer for table of length %X\n",
1574 Header.Signature, TableLength);
1575 Status = AE_NO_MEMORY;
1579 fseek (TableFile, FileOffset, SEEK_SET);
1581 Count = fread (LocalTable, 1, TableLength, TableFile);
1582 if (Count != TableLength)
1584 fprintf (stderr, "%4.4s: Could not read table content\n",
1586 Status = AE_INVALID_TABLE_LENGTH;
1590 /* Validate checksum */
1592 (void) ApIsValidChecksum (LocalTable);
1596 *Table = LocalTable;
1601 /******************************************************************************
1603 * FUNCTION: OslGetCustomizedTable
1605 * PARAMETERS: Pathname - Directory to find Linux customized table
1606 * Signature - ACPI Signature for desired table. Must be
1607 * a null terminated 4-character string.
1608 * Instance - Multiple table support for SSDT/UEFI (0...n)
1609 * Must be 0 for other tables.
1610 * Table - Where a pointer to the table is returned
1611 * Address - Where the table physical address is returned
1613 * RETURN: Status; Table buffer is returned if AE_OK.
1614 * AE_LIMIT: Instance is beyond valid limit
1615 * AE_NOT_FOUND: A table with the signature was not found
1617 * DESCRIPTION: Get an OS customized table.
1619 *****************************************************************************/
1622 OslGetCustomizedTable (
1626 ACPI_TABLE_HEADER **Table,
1627 ACPI_PHYSICAL_ADDRESS *Address)
1630 UINT32 CurrentInstance = 0;
1631 char TempName[ACPI_NAMESEG_SIZE];
1632 char TableFilename[PATH_MAX];
1637 /* Open the directory for customized tables */
1639 TableDir = AcpiOsOpenDirectory (Pathname, "*", REQUEST_FILE_ONLY);
1642 return (OslGetLastStatus (AE_NOT_FOUND));
1645 /* Attempt to find the table in the directory */
1647 while ((Filename = AcpiOsGetNextFilename (TableDir)))
1649 /* Ignore meaningless files */
1651 if (!ACPI_COMPARE_NAMESEG (Filename, Signature))
1656 /* Extract table name and instance number */
1658 Status = OslTableNameFromFile (Filename, TempName, &CurrentInstance);
1660 /* Ignore meaningless files */
1662 if (ACPI_FAILURE (Status) || CurrentInstance != Instance)
1667 /* Create the table pathname */
1671 sprintf (TableFilename, "%s/%4.4s%d", Pathname, TempName, Instance);
1675 sprintf (TableFilename, "%s/%4.4s", Pathname, TempName);
1680 AcpiOsCloseDirectory (TableDir);
1687 /* There is no physical address saved for customized tables, use zero */
1690 Status = OslReadTableFromFile (TableFilename, 0, Table);