1 /******************************************************************************
3 * Module Name: oslinuxtbl - Linux OSL for obtaining ACPI tables
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, 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_NAME_SIZE];
174 /* Local prototypes */
181 OslTableNameFromFile (
192 OslReadTableFromFile (
194 ACPI_SIZE FileOffset,
196 ACPI_TABLE_HEADER **Table);
202 ACPI_TABLE_HEADER **Table);
206 ACPI_TABLE_HEADER *Table);
208 static ACPI_PHYSICAL_ADDRESS
209 OslFindRsdpViaEfiByKeyword (
211 const char *Keyword);
213 static ACPI_PHYSICAL_ADDRESS
222 OslListCustomizedTables (
226 OslGetCustomizedTable (
230 ACPI_TABLE_HEADER **Table,
231 ACPI_PHYSICAL_ADDRESS *Address);
241 ACPI_TABLE_HEADER **Table,
242 ACPI_PHYSICAL_ADDRESS *Address);
246 ACPI_STATUS DefaultStatus);
251 #define DYNAMIC_TABLE_DIR "/sys/firmware/acpi/tables/dynamic"
252 #define STATIC_TABLE_DIR "/sys/firmware/acpi/tables"
253 #define EFI_SYSTAB "/sys/firmware/efi/systab"
255 /* Should we get dynamically loaded SSDTs from DYNAMIC_TABLE_DIR? */
257 UINT8 Gbl_DumpDynamicTables = TRUE;
259 /* Initialization flags */
261 UINT8 Gbl_TableListInitialized = FALSE;
263 /* Local copies of main ACPI tables */
265 ACPI_TABLE_RSDP Gbl_Rsdp;
266 ACPI_TABLE_FADT *Gbl_Fadt = NULL;
267 ACPI_TABLE_RSDT *Gbl_Rsdt = NULL;
268 ACPI_TABLE_XSDT *Gbl_Xsdt = NULL;
270 /* Table addresses */
272 ACPI_PHYSICAL_ADDRESS Gbl_FadtAddress = 0;
273 ACPI_PHYSICAL_ADDRESS Gbl_RsdpAddress = 0;
275 /* Revision of RSD PTR */
277 UINT8 Gbl_Revision = 0;
279 OSL_TABLE_INFO *Gbl_TableListHead = NULL;
280 UINT32 Gbl_TableCount = 0;
283 /******************************************************************************
285 * FUNCTION: OslGetLastStatus
287 * PARAMETERS: DefaultStatus - Default error status to return
289 * RETURN: Status; Converted from errno.
291 * DESCRIPTION: Get last errno and conver it to ACPI_STATUS.
293 *****************************************************************************/
297 ACPI_STATUS DefaultStatus)
309 return (AE_NOT_FOUND);
313 return (AE_NO_MEMORY);
317 return (DefaultStatus);
322 /******************************************************************************
324 * FUNCTION: AcpiOsGetTableByAddress
326 * PARAMETERS: Address - Physical address of the ACPI table
327 * Table - Where a pointer to the table is returned
329 * RETURN: Status; Table buffer is returned if AE_OK.
330 * AE_NOT_FOUND: A valid table was not found at the address
332 * DESCRIPTION: Get an ACPI table via a physical memory address.
334 *****************************************************************************/
337 AcpiOsGetTableByAddress (
338 ACPI_PHYSICAL_ADDRESS Address,
339 ACPI_TABLE_HEADER **Table)
342 ACPI_TABLE_HEADER *MappedTable;
343 ACPI_TABLE_HEADER *LocalTable = NULL;
344 ACPI_STATUS Status = AE_OK;
347 /* Get main ACPI tables from memory on first invocation of this function */
349 Status = OslTableInitialize ();
350 if (ACPI_FAILURE (Status))
355 /* Map the table and validate it */
357 Status = OslMapTable (Address, NULL, &MappedTable);
358 if (ACPI_FAILURE (Status))
363 /* Copy table to local buffer and return it */
365 TableLength = ApGetTableLength (MappedTable);
366 if (TableLength == 0)
368 Status = AE_BAD_HEADER;
372 LocalTable = calloc (1, TableLength);
375 Status = AE_NO_MEMORY;
379 memcpy (LocalTable, MappedTable, TableLength);
382 OslUnmapTable (MappedTable);
388 /******************************************************************************
390 * FUNCTION: AcpiOsGetTableByName
392 * PARAMETERS: Signature - ACPI Signature for desired table. Must be
393 * a null terminated 4-character string.
394 * Instance - Multiple table support for SSDT/UEFI (0...n)
395 * Must be 0 for other tables.
396 * Table - Where a pointer to the table is returned
397 * Address - Where the table physical address is returned
399 * RETURN: Status; Table buffer and physical address returned if AE_OK.
400 * AE_LIMIT: Instance is beyond valid limit
401 * AE_NOT_FOUND: A table with the signature was not found
403 * NOTE: Assumes the input signature is uppercase.
405 *****************************************************************************/
408 AcpiOsGetTableByName (
411 ACPI_TABLE_HEADER **Table,
412 ACPI_PHYSICAL_ADDRESS *Address)
417 /* Get main ACPI tables from memory on first invocation of this function */
419 Status = OslTableInitialize ();
420 if (ACPI_FAILURE (Status))
425 /* Not a main ACPI table, attempt to extract it from the RSDT/XSDT */
427 if (!Gbl_DumpCustomizedTables)
429 /* Attempt to get the table from the memory */
431 Status = OslGetBiosTable (Signature, Instance, Table, Address);
435 /* Attempt to get the table from the static directory */
437 Status = OslGetCustomizedTable (STATIC_TABLE_DIR, Signature,
438 Instance, Table, Address);
441 if (ACPI_FAILURE (Status) && Status == AE_LIMIT)
443 if (Gbl_DumpDynamicTables)
445 /* Attempt to get a dynamic table */
447 Status = OslGetCustomizedTable (DYNAMIC_TABLE_DIR, Signature,
448 Instance, Table, Address);
456 /******************************************************************************
458 * FUNCTION: OslAddTableToList
460 * PARAMETERS: Signature - Table signature
461 * Instance - Table instance
463 * RETURN: Status; Successfully added if AE_OK.
464 * AE_NO_MEMORY: Memory allocation error
466 * DESCRIPTION: Insert a table structure into OSL table list.
468 *****************************************************************************/
475 OSL_TABLE_INFO *NewInfo;
476 OSL_TABLE_INFO *Next;
477 UINT32 NextInstance = 0;
478 BOOLEAN Found = FALSE;
481 NewInfo = calloc (1, sizeof (OSL_TABLE_INFO));
484 return (AE_NO_MEMORY);
487 ACPI_MOVE_NAME (NewInfo->Signature, Signature);
489 if (!Gbl_TableListHead)
491 Gbl_TableListHead = NewInfo;
495 Next = Gbl_TableListHead;
498 if (ACPI_COMPARE_NAME (Next->Signature, Signature))
500 if (Next->Instance == Instance)
504 if (Next->Instance >= NextInstance)
506 NextInstance = Next->Instance + 1;
516 Next->Next = NewInfo;
524 "%4.4s: Warning unmatched table instance %d, expected %d\n",
525 Signature, Instance, NextInstance);
527 Instance = NextInstance;
530 NewInfo->Instance = Instance;
537 /******************************************************************************
539 * FUNCTION: AcpiOsGetTableByIndex
541 * PARAMETERS: Index - Which table to get
542 * Table - Where a pointer to the table is returned
543 * Instance - Where a pointer to the table instance no. is
545 * Address - Where the table physical address is returned
547 * RETURN: Status; Table buffer and physical address returned if AE_OK.
548 * AE_LIMIT: Index is beyond valid limit
550 * DESCRIPTION: Get an ACPI table via an index value (0 through n). Returns
551 * AE_LIMIT when an invalid index is reached. Index is not
552 * necessarily an index into the RSDT/XSDT.
554 *****************************************************************************/
557 AcpiOsGetTableByIndex (
559 ACPI_TABLE_HEADER **Table,
561 ACPI_PHYSICAL_ADDRESS *Address)
563 OSL_TABLE_INFO *Info;
568 /* Get main ACPI tables from memory on first invocation of this function */
570 Status = OslTableInitialize ();
571 if (ACPI_FAILURE (Status))
578 if (Index >= Gbl_TableCount)
583 /* Point to the table list entry specified by the Index argument */
585 Info = Gbl_TableListHead;
586 for (i = 0; i < Index; i++)
591 /* Now we can just get the table via the signature */
593 Status = AcpiOsGetTableByName (Info->Signature, Info->Instance,
596 if (ACPI_SUCCESS (Status))
598 *Instance = Info->Instance;
604 /******************************************************************************
606 * FUNCTION: OslFindRsdpViaEfiByKeyword
608 * PARAMETERS: Keyword - Character string indicating ACPI GUID version
611 * RETURN: RSDP address if found
613 * DESCRIPTION: Find RSDP address via EFI using keyword indicating the ACPI
616 *****************************************************************************/
618 static ACPI_PHYSICAL_ADDRESS
619 OslFindRsdpViaEfiByKeyword (
624 unsigned long long Address = 0;
628 snprintf (Format, 32, "%s=%s", Keyword, "%llx");
629 fseek (File, 0, SEEK_SET);
630 while (fgets (Buffer, 80, File))
632 if (sscanf (Buffer, Format, &Address) == 1)
638 return ((ACPI_PHYSICAL_ADDRESS) (Address));
642 /******************************************************************************
644 * FUNCTION: OslFindRsdpViaEfi
648 * RETURN: RSDP address if found
650 * DESCRIPTION: Find RSDP address via EFI.
652 *****************************************************************************/
654 static ACPI_PHYSICAL_ADDRESS
659 ACPI_PHYSICAL_ADDRESS Address = 0;
662 File = fopen (EFI_SYSTAB, "r");
665 Address = OslFindRsdpViaEfiByKeyword (File, "ACPI20");
668 Address = OslFindRsdpViaEfiByKeyword (File, "ACPI");
677 /******************************************************************************
679 * FUNCTION: OslLoadRsdp
685 * DESCRIPTION: Scan and load RSDP.
687 *****************************************************************************/
693 ACPI_TABLE_HEADER *MappedTable;
695 ACPI_PHYSICAL_ADDRESS RsdpBase;
699 /* Get RSDP from memory */
701 RsdpSize = sizeof (ACPI_TABLE_RSDP);
704 RsdpBase = Gbl_RsdpBase;
708 RsdpBase = OslFindRsdpViaEfi ();
713 RsdpBase = ACPI_HI_RSDP_WINDOW_BASE;
714 RsdpSize = ACPI_HI_RSDP_WINDOW_SIZE;
717 RsdpAddress = AcpiOsMapMemory (RsdpBase, RsdpSize);
720 return (OslGetLastStatus (AE_BAD_ADDRESS));
723 /* Search low memory for the RSDP */
725 MappedTable = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
726 AcpiTbScanMemoryForRsdp (RsdpAddress, RsdpSize));
729 AcpiOsUnmapMemory (RsdpAddress, RsdpSize);
730 return (AE_NOT_FOUND);
733 Gbl_RsdpAddress = RsdpBase + (ACPI_CAST8 (MappedTable) - RsdpAddress);
735 memcpy (&Gbl_Rsdp, MappedTable, sizeof (ACPI_TABLE_RSDP));
736 AcpiOsUnmapMemory (RsdpAddress, RsdpSize);
742 /******************************************************************************
744 * FUNCTION: OslCanUseXsdt
748 * RETURN: TRUE if XSDT is allowed to be used.
750 * DESCRIPTION: This function collects logic that can be used to determine if
751 * XSDT should be used instead of RSDT.
753 *****************************************************************************/
759 if (Gbl_Revision && !AcpiGbl_DoNotUseXsdt)
770 /******************************************************************************
772 * FUNCTION: OslTableInitialize
778 * DESCRIPTION: Initialize ACPI table data. Get and store main ACPI tables to
779 * local variables. Main ACPI tables include RSDT, FADT, RSDT,
782 *****************************************************************************/
789 ACPI_PHYSICAL_ADDRESS Address;
792 if (Gbl_TableListInitialized)
797 if (!Gbl_DumpCustomizedTables)
799 /* Get RSDP from memory */
801 Status = OslLoadRsdp ();
802 if (ACPI_FAILURE (Status))
807 /* Get XSDT from memory */
809 if (Gbl_Rsdp.Revision && !Gbl_DoNotDumpXsdt)
818 Status = OslGetBiosTable (ACPI_SIG_XSDT, 0,
819 ACPI_CAST_PTR (ACPI_TABLE_HEADER *, &Gbl_Xsdt), &Address);
820 if (ACPI_FAILURE (Status))
826 /* Get RSDT from memory */
828 if (Gbl_Rsdp.RsdtPhysicalAddress)
836 Status = OslGetBiosTable (ACPI_SIG_RSDT, 0,
837 ACPI_CAST_PTR (ACPI_TABLE_HEADER *, &Gbl_Rsdt), &Address);
838 if (ACPI_FAILURE (Status))
844 /* Get FADT from memory */
852 Status = OslGetBiosTable (ACPI_SIG_FADT, 0,
853 ACPI_CAST_PTR (ACPI_TABLE_HEADER *, &Gbl_Fadt), &Gbl_FadtAddress);
854 if (ACPI_FAILURE (Status))
859 /* Add mandatory tables to global table list first */
861 Status = OslAddTableToList (ACPI_RSDP_NAME, 0);
862 if (ACPI_FAILURE (Status))
867 Status = OslAddTableToList (ACPI_SIG_RSDT, 0);
868 if (ACPI_FAILURE (Status))
873 if (Gbl_Revision == 2)
875 Status = OslAddTableToList (ACPI_SIG_XSDT, 0);
876 if (ACPI_FAILURE (Status))
882 Status = OslAddTableToList (ACPI_SIG_DSDT, 0);
883 if (ACPI_FAILURE (Status))
888 Status = OslAddTableToList (ACPI_SIG_FACS, 0);
889 if (ACPI_FAILURE (Status))
894 /* Add all tables found in the memory */
896 Status = OslListBiosTables ();
897 if (ACPI_FAILURE (Status))
904 /* Add all tables found in the static directory */
906 Status = OslListCustomizedTables (STATIC_TABLE_DIR);
907 if (ACPI_FAILURE (Status))
913 if (Gbl_DumpDynamicTables)
915 /* Add all dynamically loaded tables in the dynamic directory */
917 Status = OslListCustomizedTables (DYNAMIC_TABLE_DIR);
918 if (ACPI_FAILURE (Status))
924 Gbl_TableListInitialized = TRUE;
929 /******************************************************************************
931 * FUNCTION: OslListBiosTables
935 * RETURN: Status; Table list is initialized if AE_OK.
937 * DESCRIPTION: Add ACPI tables to the table list from memory.
939 * NOTE: This works on Linux as table customization does not modify the
940 * addresses stored in RSDP/RSDT/XSDT/FADT.
942 *****************************************************************************/
948 ACPI_TABLE_HEADER *MappedTable = NULL;
950 UINT8 NumberOfTables;
952 ACPI_PHYSICAL_ADDRESS TableAddress = 0;
953 ACPI_STATUS Status = AE_OK;
957 if (OslCanUseXsdt ())
959 ItemSize = sizeof (UINT64);
960 TableData = ACPI_CAST8 (Gbl_Xsdt) + sizeof (ACPI_TABLE_HEADER);
962 (UINT8) ((Gbl_Xsdt->Header.Length - sizeof (ACPI_TABLE_HEADER))
965 else /* Use RSDT if XSDT is not available */
967 ItemSize = sizeof (UINT32);
968 TableData = ACPI_CAST8 (Gbl_Rsdt) + sizeof (ACPI_TABLE_HEADER);
970 (UINT8) ((Gbl_Rsdt->Header.Length - sizeof (ACPI_TABLE_HEADER))
974 /* Search RSDT/XSDT for the requested table */
976 for (i = 0; i < NumberOfTables; ++i, TableData += ItemSize)
978 if (OslCanUseXsdt ())
981 (ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST64 (TableData));
986 (ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST32 (TableData));
989 /* Skip NULL entries in RSDT/XSDT */
991 if (TableAddress == 0)
996 Status = OslMapTable (TableAddress, NULL, &MappedTable);
997 if (ACPI_FAILURE (Status))
1002 OslAddTableToList (MappedTable->Signature, 0);
1003 OslUnmapTable (MappedTable);
1010 /******************************************************************************
1012 * FUNCTION: OslGetBiosTable
1014 * PARAMETERS: Signature - ACPI Signature for common table. Must be
1015 * a null terminated 4-character string.
1016 * Instance - Multiple table support for SSDT/UEFI (0...n)
1017 * Must be 0 for other tables.
1018 * Table - Where a pointer to the table is returned
1019 * Address - Where the table physical address is returned
1021 * RETURN: Status; Table buffer and physical address returned if AE_OK.
1022 * AE_LIMIT: Instance is beyond valid limit
1023 * AE_NOT_FOUND: A table with the signature was not found
1025 * DESCRIPTION: Get a BIOS provided ACPI table
1027 * NOTE: Assumes the input signature is uppercase.
1029 *****************************************************************************/
1035 ACPI_TABLE_HEADER **Table,
1036 ACPI_PHYSICAL_ADDRESS *Address)
1038 ACPI_TABLE_HEADER *LocalTable = NULL;
1039 ACPI_TABLE_HEADER *MappedTable = NULL;
1041 UINT8 NumberOfTables;
1043 UINT32 CurrentInstance = 0;
1044 ACPI_PHYSICAL_ADDRESS TableAddress;
1045 ACPI_PHYSICAL_ADDRESS FirstTableAddress = 0;
1046 UINT32 TableLength = 0;
1047 ACPI_STATUS Status = AE_OK;
1051 /* Handle special tables whose addresses are not in RSDT/XSDT */
1053 if (ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME) ||
1054 ACPI_COMPARE_NAME (Signature, ACPI_SIG_RSDT) ||
1055 ACPI_COMPARE_NAME (Signature, ACPI_SIG_XSDT) ||
1056 ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT) ||
1057 ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS))
1065 * Get the appropriate address, either 32-bit or 64-bit. Be very
1066 * careful about the FADT length and validate table addresses.
1067 * Note: The 64-bit addresses have priority.
1069 if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT))
1071 if (CurrentInstance < 2)
1073 if ((Gbl_Fadt->Header.Length >= MIN_FADT_FOR_XDSDT) &&
1074 Gbl_Fadt->XDsdt && CurrentInstance == 0)
1076 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_Fadt->XDsdt;
1078 else if ((Gbl_Fadt->Header.Length >= MIN_FADT_FOR_DSDT) &&
1079 Gbl_Fadt->Dsdt != FirstTableAddress)
1081 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_Fadt->Dsdt;
1085 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS))
1087 if (CurrentInstance < 2)
1089 if ((Gbl_Fadt->Header.Length >= MIN_FADT_FOR_XFACS) &&
1090 Gbl_Fadt->XFacs && CurrentInstance == 0)
1092 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_Fadt->XFacs;
1094 else if ((Gbl_Fadt->Header.Length >= MIN_FADT_FOR_FACS) &&
1095 Gbl_Fadt->Facs != FirstTableAddress)
1097 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_Fadt->Facs;
1101 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_XSDT))
1105 return (AE_BAD_SIGNATURE);
1107 if (CurrentInstance == 0)
1110 (ACPI_PHYSICAL_ADDRESS) Gbl_Rsdp.XsdtPhysicalAddress;
1113 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_RSDT))
1115 if (CurrentInstance == 0)
1118 (ACPI_PHYSICAL_ADDRESS) Gbl_Rsdp.RsdtPhysicalAddress;
1123 if (CurrentInstance == 0)
1125 TableAddress = (ACPI_PHYSICAL_ADDRESS) Gbl_RsdpAddress;
1126 Signature = ACPI_SIG_RSDP;
1130 if (TableAddress == 0)
1135 /* Now we can get the requested special table */
1137 Status = OslMapTable (TableAddress, Signature, &MappedTable);
1138 if (ACPI_FAILURE (Status))
1143 TableLength = ApGetTableLength (MappedTable);
1144 if (FirstTableAddress == 0)
1146 FirstTableAddress = TableAddress;
1149 /* Match table instance */
1151 if (CurrentInstance != Instance)
1153 OslUnmapTable (MappedTable);
1156 goto FindNextInstance;
1159 else /* Case for a normal ACPI table */
1161 if (OslCanUseXsdt ())
1163 ItemSize = sizeof (UINT64);
1164 TableData = ACPI_CAST8 (Gbl_Xsdt) + sizeof (ACPI_TABLE_HEADER);
1166 (UINT8) ((Gbl_Xsdt->Header.Length - sizeof (ACPI_TABLE_HEADER))
1169 else /* Use RSDT if XSDT is not available */
1171 ItemSize = sizeof (UINT32);
1172 TableData = ACPI_CAST8 (Gbl_Rsdt) + sizeof (ACPI_TABLE_HEADER);
1174 (UINT8) ((Gbl_Rsdt->Header.Length - sizeof (ACPI_TABLE_HEADER))
1178 /* Search RSDT/XSDT for the requested table */
1180 for (i = 0; i < NumberOfTables; ++i, TableData += ItemSize)
1182 if (OslCanUseXsdt ())
1185 (ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST64 (TableData));
1190 (ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST32 (TableData));
1193 /* Skip NULL entries in RSDT/XSDT */
1195 if (TableAddress == 0)
1200 Status = OslMapTable (TableAddress, NULL, &MappedTable);
1201 if (ACPI_FAILURE (Status))
1205 TableLength = MappedTable->Length;
1207 /* Does this table match the requested signature? */
1209 if (!ACPI_COMPARE_NAME (MappedTable->Signature, Signature))
1211 OslUnmapTable (MappedTable);
1216 /* Match table instance (for SSDT/UEFI tables) */
1218 if (CurrentInstance != Instance)
1220 OslUnmapTable (MappedTable);
1237 if (TableLength == 0)
1239 Status = AE_BAD_HEADER;
1243 /* Copy table to local buffer and return it */
1245 LocalTable = calloc (1, TableLength);
1248 Status = AE_NO_MEMORY;
1252 memcpy (LocalTable, MappedTable, TableLength);
1253 *Address = TableAddress;
1254 *Table = LocalTable;
1257 OslUnmapTable (MappedTable);
1262 /******************************************************************************
1264 * FUNCTION: OslListCustomizedTables
1266 * PARAMETERS: Directory - Directory that contains the tables
1268 * RETURN: Status; Table list is initialized if AE_OK.
1270 * DESCRIPTION: Add ACPI tables to the table list from a directory.
1272 *****************************************************************************/
1275 OslListCustomizedTables (
1280 char TempName[ACPI_NAME_SIZE];
1282 ACPI_STATUS Status = AE_OK;
1285 /* Open the requested directory */
1287 TableDir = AcpiOsOpenDirectory (Directory, "*", REQUEST_FILE_ONLY);
1290 return (OslGetLastStatus (AE_NOT_FOUND));
1293 /* Examine all entries in this directory */
1295 while ((Filename = AcpiOsGetNextFilename (TableDir)))
1297 /* Extract table name and instance number */
1299 Status = OslTableNameFromFile (Filename, TempName, &Instance);
1301 /* Ignore meaningless files */
1303 if (ACPI_FAILURE (Status))
1308 /* Add new info node to global table list */
1310 Status = OslAddTableToList (TempName, Instance);
1311 if (ACPI_FAILURE (Status))
1317 AcpiOsCloseDirectory (TableDir);
1322 /******************************************************************************
1324 * FUNCTION: OslMapTable
1326 * PARAMETERS: Address - Address of the table in memory
1327 * Signature - Optional ACPI Signature for desired table.
1328 * Null terminated 4-character string.
1329 * Table - Where a pointer to the mapped table is
1332 * RETURN: Status; Mapped table is returned if AE_OK.
1333 * AE_NOT_FOUND: A valid table was not found at the address
1335 * DESCRIPTION: Map entire ACPI table into caller's address space.
1337 *****************************************************************************/
1343 ACPI_TABLE_HEADER **Table)
1345 ACPI_TABLE_HEADER *MappedTable;
1351 return (AE_BAD_ADDRESS);
1355 * Map the header so we can get the table length.
1356 * Use sizeof (ACPI_TABLE_HEADER) as:
1357 * 1. it is bigger than 24 to include RSDP->Length
1358 * 2. it is smaller than sizeof (ACPI_TABLE_RSDP)
1360 MappedTable = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
1363 fprintf (stderr, "Could not map table header at 0x%8.8X%8.8X\n",
1364 ACPI_FORMAT_UINT64 (Address));
1365 return (OslGetLastStatus (AE_BAD_ADDRESS));
1368 /* If specified, signature must match */
1372 if (ACPI_VALIDATE_RSDP_SIG (Signature))
1374 if (!ACPI_VALIDATE_RSDP_SIG (MappedTable->Signature))
1376 AcpiOsUnmapMemory (MappedTable, sizeof (ACPI_TABLE_HEADER));
1377 return (AE_BAD_SIGNATURE);
1380 else if (!ACPI_COMPARE_NAME (Signature, MappedTable->Signature))
1382 AcpiOsUnmapMemory (MappedTable, sizeof (ACPI_TABLE_HEADER));
1383 return (AE_BAD_SIGNATURE);
1387 /* Map the entire table */
1389 Length = ApGetTableLength (MappedTable);
1390 AcpiOsUnmapMemory (MappedTable, sizeof (ACPI_TABLE_HEADER));
1393 return (AE_BAD_HEADER);
1396 MappedTable = AcpiOsMapMemory (Address, Length);
1399 fprintf (stderr, "Could not map table at 0x%8.8X%8.8X length %8.8X\n",
1400 ACPI_FORMAT_UINT64 (Address), Length);
1401 return (OslGetLastStatus (AE_INVALID_TABLE_LENGTH));
1404 (void) ApIsValidChecksum (MappedTable);
1406 *Table = MappedTable;
1411 /******************************************************************************
1413 * FUNCTION: OslUnmapTable
1415 * PARAMETERS: Table - A pointer to the mapped table
1419 * DESCRIPTION: Unmap entire ACPI table.
1421 *****************************************************************************/
1425 ACPI_TABLE_HEADER *Table)
1429 AcpiOsUnmapMemory (Table, ApGetTableLength (Table));
1434 /******************************************************************************
1436 * FUNCTION: OslTableNameFromFile
1438 * PARAMETERS: Filename - File that contains the desired table
1439 * Signature - Pointer to 4-character buffer to store
1440 * extracted table signature.
1441 * Instance - Pointer to integer to store extracted
1442 * table instance number.
1444 * RETURN: Status; Table name is extracted if AE_OK.
1446 * DESCRIPTION: Extract table signature and instance number from a table file
1449 *****************************************************************************/
1452 OslTableNameFromFile (
1458 /* Ignore meaningless files */
1460 if (strlen (Filename) < ACPI_NAME_SIZE)
1462 return (AE_BAD_SIGNATURE);
1465 /* Extract instance number */
1467 if (isdigit ((int) Filename[ACPI_NAME_SIZE]))
1469 sscanf (&Filename[ACPI_NAME_SIZE], "%u", Instance);
1471 else if (strlen (Filename) != ACPI_NAME_SIZE)
1473 return (AE_BAD_SIGNATURE);
1480 /* Extract signature */
1482 ACPI_MOVE_NAME (Signature, Filename);
1487 /******************************************************************************
1489 * FUNCTION: OslReadTableFromFile
1491 * PARAMETERS: Filename - File that contains the desired table
1492 * FileOffset - Offset of the table in file
1493 * Signature - Optional ACPI Signature for desired table.
1494 * A null terminated 4-character string.
1495 * Table - Where a pointer to the table is returned
1497 * RETURN: Status; Table buffer is returned if AE_OK.
1499 * DESCRIPTION: Read a ACPI table from a file.
1501 *****************************************************************************/
1504 OslReadTableFromFile (
1506 ACPI_SIZE FileOffset,
1508 ACPI_TABLE_HEADER **Table)
1511 ACPI_TABLE_HEADER Header;
1512 ACPI_TABLE_HEADER *LocalTable = NULL;
1515 ACPI_STATUS Status = AE_OK;
1520 TableFile = fopen (Filename, "rb");
1521 if (TableFile == NULL)
1523 fprintf (stderr, "Could not open table file: %s\n", Filename);
1524 return (OslGetLastStatus (AE_NOT_FOUND));
1527 fseek (TableFile, FileOffset, SEEK_SET);
1529 /* Read the Table header to get the table length */
1531 Count = fread (&Header, 1, sizeof (ACPI_TABLE_HEADER), TableFile);
1532 if (Count != sizeof (ACPI_TABLE_HEADER))
1534 fprintf (stderr, "Could not read table header: %s\n", Filename);
1535 Status = AE_BAD_HEADER;
1539 /* If signature is specified, it must match the table */
1543 if (ACPI_VALIDATE_RSDP_SIG (Signature))
1545 if (!ACPI_VALIDATE_RSDP_SIG (Header.Signature)) {
1546 fprintf (stderr, "Incorrect RSDP signature: found %8.8s\n",
1548 Status = AE_BAD_SIGNATURE;
1552 else if (!ACPI_COMPARE_NAME (Signature, Header.Signature))
1554 fprintf (stderr, "Incorrect signature: Expecting %4.4s, found %4.4s\n",
1555 Signature, Header.Signature);
1556 Status = AE_BAD_SIGNATURE;
1561 TableLength = ApGetTableLength (&Header);
1562 if (TableLength == 0)
1564 Status = AE_BAD_HEADER;
1568 /* Read the entire table into a local buffer */
1570 LocalTable = calloc (1, TableLength);
1574 "%4.4s: Could not allocate buffer for table of length %X\n",
1575 Header.Signature, TableLength);
1576 Status = AE_NO_MEMORY;
1580 fseek (TableFile, FileOffset, SEEK_SET);
1582 Count = fread (LocalTable, 1, TableLength, TableFile);
1583 if (Count != TableLength)
1585 fprintf (stderr, "%4.4s: Could not read table content\n",
1587 Status = AE_INVALID_TABLE_LENGTH;
1591 /* Validate checksum */
1593 (void) ApIsValidChecksum (LocalTable);
1597 *Table = LocalTable;
1602 /******************************************************************************
1604 * FUNCTION: OslGetCustomizedTable
1606 * PARAMETERS: Pathname - Directory to find Linux customized table
1607 * Signature - ACPI Signature for desired table. Must be
1608 * a null terminated 4-character string.
1609 * Instance - Multiple table support for SSDT/UEFI (0...n)
1610 * Must be 0 for other tables.
1611 * Table - Where a pointer to the table is returned
1612 * Address - Where the table physical address is returned
1614 * RETURN: Status; Table buffer is returned if AE_OK.
1615 * AE_LIMIT: Instance is beyond valid limit
1616 * AE_NOT_FOUND: A table with the signature was not found
1618 * DESCRIPTION: Get an OS customized table.
1620 *****************************************************************************/
1623 OslGetCustomizedTable (
1627 ACPI_TABLE_HEADER **Table,
1628 ACPI_PHYSICAL_ADDRESS *Address)
1631 UINT32 CurrentInstance = 0;
1632 char TempName[ACPI_NAME_SIZE];
1633 char TableFilename[PATH_MAX];
1638 /* Open the directory for customized tables */
1640 TableDir = AcpiOsOpenDirectory (Pathname, "*", REQUEST_FILE_ONLY);
1643 return (OslGetLastStatus (AE_NOT_FOUND));
1646 /* Attempt to find the table in the directory */
1648 while ((Filename = AcpiOsGetNextFilename (TableDir)))
1650 /* Ignore meaningless files */
1652 if (!ACPI_COMPARE_NAME (Filename, Signature))
1657 /* Extract table name and instance number */
1659 Status = OslTableNameFromFile (Filename, TempName, &CurrentInstance);
1661 /* Ignore meaningless files */
1663 if (ACPI_FAILURE (Status) || CurrentInstance != Instance)
1668 /* Create the table pathname */
1672 sprintf (TableFilename, "%s/%4.4s%d", Pathname, TempName, Instance);
1676 sprintf (TableFilename, "%s/%4.4s", Pathname, TempName);
1681 AcpiOsCloseDirectory (TableDir);
1688 /* There is no physical address saved for customized tables, use zero */
1691 Status = OslReadTableFromFile (TableFilename, 0, NULL, Table);