1 /******************************************************************************
3 * Module Name: antables - ACPI table setup/install for AcpiNames utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "acpinames.h"
46 #define _COMPONENT ACPI_TOOLS
47 ACPI_MODULE_NAME ("antables")
49 /* Local prototypes */
51 /* Non-AML tables that are constructed locally and installed */
53 static ACPI_TABLE_RSDP LocalRSDP;
54 static ACPI_TABLE_FACS LocalFACS;
57 * We need a local FADT so that the hardware subcomponent will function,
58 * even though the underlying OSD HW access functions don't do anything.
60 static ACPI_TABLE_FADT LocalFADT;
63 * Use XSDT so that both 32- and 64-bit versions of this utility will
64 * function automatically.
66 static ACPI_TABLE_XSDT *LocalXSDT;
68 #define BASE_XSDT_TABLES 1
69 #define BASE_XSDT_SIZE (sizeof (ACPI_TABLE_XSDT) + \
70 ((BASE_XSDT_TABLES -1) * sizeof (UINT64)))
72 ACPI_TABLE_DESC Tables[ACPI_MAX_INIT_TABLES];
75 /******************************************************************************
77 * FUNCTION: AeBuildLocalTables
79 * PARAMETERS: TableCount - Number of tables on the command line
80 * TableList - List of actual tables from files
84 * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
85 * FADT, FACS, and the input DSDT/SSDT.
87 *****************************************************************************/
92 AE_TABLE_DESC *TableList)
94 ACPI_PHYSICAL_ADDRESS DsdtAddress = 0;
96 AE_TABLE_DESC *NextTable;
98 ACPI_TABLE_FADT *ExternalFadt = NULL;
102 * Update the table count. For DSDT, it is not put into the XSDT. For
103 * FADT, this is already accounted for since we usually install a
106 NextTable = TableList;
109 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) ||
110 ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
114 NextTable = NextTable->Next;
117 XsdtSize = BASE_XSDT_SIZE + (TableCount * sizeof (UINT64));
121 LocalXSDT = AcpiOsAllocate (XsdtSize);
124 return (AE_NO_MEMORY);
127 ACPI_MEMSET (LocalXSDT, 0, XsdtSize);
128 ACPI_MOVE_NAME (LocalXSDT->Header.Signature, ACPI_SIG_XSDT);
129 LocalXSDT->Header.Length = XsdtSize;
130 LocalXSDT->Header.Revision = 1;
132 LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT);
135 * Install the user tables. The DSDT must be installed in the FADT.
136 * All other tables are installed directly into the XSDT.
138 NextIndex = BASE_XSDT_TABLES;
139 NextTable = TableList;
143 * Incoming DSDT or FADT are special cases. All other tables are
144 * just immediately installed into the XSDT.
146 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT))
150 printf ("Already found a DSDT, only one allowed\n");
151 return (AE_ALREADY_EXISTS);
154 /* The incoming user table is a DSDT */
156 DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
158 else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
160 ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table);
161 LocalXSDT->TableOffsetEntry[2] = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
165 /* Install the table in the XSDT */
167 LocalXSDT->TableOffsetEntry[NextIndex] = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
171 NextTable = NextTable->Next;
176 ACPI_MEMSET (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP));
177 ACPI_MAKE_RSDP_SIG (LocalRSDP.Signature);
178 ACPI_MEMCPY (LocalRSDP.OemId, "I_TEST", 6);
179 LocalRSDP.Revision = 2;
180 LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT);
181 LocalRSDP.Length = sizeof (ACPI_TABLE_XSDT);
183 /* Set checksums for both XSDT and RSDP */
185 LocalXSDT->Header.Checksum = (UINT8) -AcpiTbChecksum (
186 (void *) LocalXSDT, LocalXSDT->Header.Length);
187 LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum (
188 (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH);
198 * Use the external FADT, but we must update the DSDT/FACS addresses
199 * as well as the checksum
201 ExternalFadt->Dsdt = DsdtAddress;
202 ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
204 if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (&ExternalFadt->XDsdt, ExternalFadt))
206 ExternalFadt->XDsdt = DsdtAddress;
207 ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
209 /* Complete the FADT with the checksum */
211 ExternalFadt->Header.Checksum = 0;
212 ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum (
213 (void *) ExternalFadt, ExternalFadt->Header.Length);
218 * Build a local FADT so we can test the hardware/event init
220 ACPI_MEMSET (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT));
221 ACPI_MOVE_NAME (LocalFADT.Header.Signature, ACPI_SIG_FADT);
223 /* Setup FADT header and DSDT/FACS addresses */
228 LocalFADT.XDsdt = DsdtAddress;
229 LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
231 LocalFADT.Header.Revision = 3;
232 LocalFADT.Header.Length = sizeof (ACPI_TABLE_FADT);
234 /* Miscellaneous FADT fields */
236 LocalFADT.Gpe0BlockLength = 16;
237 LocalFADT.Gpe0Block = 0x00001234;
239 LocalFADT.Gpe1BlockLength = 6;
240 LocalFADT.Gpe1Block = 0x00005678;
241 LocalFADT.Gpe1Base = 96;
243 LocalFADT.Pm1EventLength = 4;
244 LocalFADT.Pm1aEventBlock = 0x00001aaa;
245 LocalFADT.Pm1bEventBlock = 0x00001bbb;
247 LocalFADT.Pm1ControlLength = 2;
248 LocalFADT.Pm1aControlBlock = 0xB0;
250 LocalFADT.PmTimerLength = 4;
251 LocalFADT.PmTimerBlock = 0xA0;
253 LocalFADT.Pm2ControlBlock = 0xC0;
254 LocalFADT.Pm2ControlLength = 1;
256 /* Setup one example X-64 field */
258 LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
259 LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock;
260 LocalFADT.XPm1bEventBlock.BitWidth = (UINT8) ACPI_MUL_8 (LocalFADT.Pm1EventLength);
262 /* Complete the FADT with the checksum */
264 LocalFADT.Header.Checksum = 0;
265 LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum (
266 (void *) &LocalFADT, LocalFADT.Header.Length);
271 ACPI_MEMSET (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS));
272 ACPI_MOVE_NAME (LocalFACS.Signature, ACPI_SIG_FACS);
274 LocalFACS.Length = sizeof (ACPI_TABLE_FACS);
275 LocalFACS.GlobalLock = 0x11AA0011;
281 /******************************************************************************
283 * FUNCTION: AcpiOsGetRootPointer
287 * RETURN: Address of the RSDP
289 * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
290 * standard ACPI mechanism.
292 *****************************************************************************/
294 ACPI_PHYSICAL_ADDRESS
295 AcpiOsGetRootPointer (
299 return ((ACPI_PHYSICAL_ADDRESS) &LocalRSDP);