1 /******************************************************************************
3 * Module Name: antables - ACPI table setup/install for AcpiNames utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 */
52 AnInitializeTableHeader (
53 ACPI_TABLE_HEADER *Header,
58 /* Non-AML tables that are constructed locally and installed */
60 static ACPI_TABLE_RSDP LocalRSDP;
61 static ACPI_TABLE_FACS LocalFACS;
64 * We need a local FADT so that the hardware subcomponent will function,
65 * even though the underlying OSD HW access functions don't do anything.
67 static ACPI_TABLE_FADT LocalFADT;
70 * Use XSDT so that both 32- and 64-bit versions of this utility will
71 * function automatically.
73 static ACPI_TABLE_XSDT *LocalXSDT;
75 #define BASE_XSDT_TABLES 1
76 #define BASE_XSDT_SIZE (sizeof (ACPI_TABLE_XSDT) + \
77 ((BASE_XSDT_TABLES -1) * sizeof (UINT64)))
80 /******************************************************************************
82 * FUNCTION: AnInitializeTableHeader
84 * PARAMETERS: Header - A valid standard ACPI table header
85 * Signature - Signature to insert
86 * Length - Length of the table
88 * RETURN: None. Header is modified.
90 * DESCRIPTION: Initialize the table header for a local ACPI table.
92 *****************************************************************************/
95 AnInitializeTableHeader (
96 ACPI_TABLE_HEADER *Header,
101 ACPI_MOVE_NAME (Header->Signature, Signature);
102 Header->Length = Length;
104 Header->OemRevision = 0x1001;
105 strncpy (Header->OemId, "Intel", ACPI_OEM_ID_SIZE);
106 strncpy (Header->OemTableId, "AcpiName", ACPI_OEM_TABLE_ID_SIZE);
107 strncpy (Header->AslCompilerId, "INTL", ACPI_NAME_SIZE);
108 Header->AslCompilerRevision = ACPI_CA_VERSION;
110 /* Set the checksum, must set to zero first */
112 Header->Checksum = 0;
113 Header->Checksum = (UINT8) -AcpiTbChecksum (
114 (void *) Header, Header->Length);
118 /******************************************************************************
120 * FUNCTION: AnBuildLocalTables
122 * PARAMETERS: TableCount - Number of tables on the command line
123 * TableList - List of actual tables from files
127 * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
128 * FADT, FACS, and the input DSDT/SSDT.
130 *****************************************************************************/
134 ACPI_NEW_TABLE_DESC *TableList)
136 UINT32 TableCount = 0;
137 ACPI_PHYSICAL_ADDRESS DsdtAddress = 0;
139 ACPI_NEW_TABLE_DESC *NextTable;
141 ACPI_TABLE_FADT *ExternalFadt = NULL;
145 * Update the table count. For the DSDT, it is not put into the XSDT.
146 * For the FADT, this table is already accounted for since we usually
147 * install a local FADT.
149 NextTable = TableList;
152 if (!ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) &&
153 !ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
158 NextTable = NextTable->Next;
161 XsdtSize = BASE_XSDT_SIZE + (TableCount * sizeof (UINT64));
165 LocalXSDT = AcpiOsAllocate (XsdtSize);
168 return (AE_NO_MEMORY);
171 memset (LocalXSDT, 0, XsdtSize);
172 LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT);
175 * Install the user tables. The DSDT must be installed in the FADT.
176 * All other tables are installed directly into the XSDT.
178 * Note: The tables are loaded in reverse order from the incoming
179 * input, which makes it match the command line order.
181 NextIndex = BASE_XSDT_TABLES;
182 NextTable = TableList;
186 * Incoming DSDT or FADT are special cases. All other tables are
187 * just immediately installed into the XSDT.
189 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT))
193 printf ("Already found a DSDT, only one allowed\n");
194 return (AE_ALREADY_EXISTS);
197 /* The incoming user table is a DSDT */
199 DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
201 else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
204 ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table);
205 LocalXSDT->TableOffsetEntry[0] =
206 ACPI_PTR_TO_PHYSADDR (NextTable->Table);
210 /* Install the table in the XSDT */
212 LocalXSDT->TableOffsetEntry[TableCount - NextIndex + 1] =
213 ACPI_PTR_TO_PHYSADDR (NextTable->Table);
217 NextTable = NextTable->Next;
220 /* Build an RSDP. Contains a valid XSDT only, no RSDT */
222 memset (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP));
223 ACPI_MAKE_RSDP_SIG (LocalRSDP.Signature);
224 memcpy (LocalRSDP.OemId, "Intel", 6);
226 LocalRSDP.Revision = 2;
227 LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT);
228 LocalRSDP.Length = sizeof (ACPI_TABLE_XSDT);
230 /* Set checksums for both XSDT and RSDP */
232 AnInitializeTableHeader ((void *) LocalXSDT, ACPI_SIG_XSDT, XsdtSize);
234 LocalRSDP.Checksum = 0;
235 LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum (
236 (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH);
244 * Build an FADT. There are two options for the FADT:
245 * 1) Incoming external FADT specified on the command line
246 * 2) A fully featured local FADT
248 memset (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT));
253 * Use the external FADT, but we must update the DSDT/FACS
254 * addresses as well as the checksum
256 ExternalFadt->Dsdt = (UINT32) DsdtAddress;
257 ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
260 * If there room in the FADT for the XDsdt and XFacs 64-bit
261 * pointers, use them.
263 if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (
264 &ExternalFadt->XDsdt, ExternalFadt))
266 ExternalFadt->Dsdt = 0;
267 ExternalFadt->Facs = 0;
268 ExternalFadt->XDsdt = DsdtAddress;
269 ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
272 /* Complete the external FADT with the checksum */
274 ExternalFadt->Header.Checksum = 0;
275 ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum (
276 (void *) ExternalFadt, ExternalFadt->Header.Length);
281 * Build a local FADT so we can test the hardware/event init
283 LocalFADT.Header.Revision = 5;
285 /* Setup FADT header and DSDT/FACS addresses */
290 LocalFADT.XDsdt = DsdtAddress;
291 LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
293 /* Miscellaneous FADT fields */
295 LocalFADT.Gpe0BlockLength = 16;
296 LocalFADT.Gpe0Block = 0x00001234;
298 LocalFADT.Gpe1BlockLength = 6;
299 LocalFADT.Gpe1Block = 0x00005678;
300 LocalFADT.Gpe1Base = 96;
302 LocalFADT.Pm1EventLength = 4;
303 LocalFADT.Pm1aEventBlock = 0x00001aaa;
304 LocalFADT.Pm1bEventBlock = 0x00001bbb;
306 LocalFADT.Pm1ControlLength = 2;
307 LocalFADT.Pm1aControlBlock = 0xB0;
309 LocalFADT.PmTimerLength = 4;
310 LocalFADT.PmTimerBlock = 0xA0;
312 LocalFADT.Pm2ControlBlock = 0xC0;
313 LocalFADT.Pm2ControlLength = 1;
315 /* Setup one example X-64 field */
317 LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
318 LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock;
319 LocalFADT.XPm1bEventBlock.BitWidth = (UINT8)
320 ACPI_MUL_8 (LocalFADT.Pm1EventLength);
323 AnInitializeTableHeader ((void *) &LocalFADT,
324 ACPI_SIG_FADT, sizeof (ACPI_TABLE_FADT));
328 memset (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS));
329 ACPI_MOVE_NAME (LocalFACS.Signature, ACPI_SIG_FACS);
331 LocalFACS.Length = sizeof (ACPI_TABLE_FACS);
332 LocalFACS.GlobalLock = 0x11AA0011;
337 /******************************************************************************
339 * FUNCTION: AcpiOsGetRootPointer
343 * RETURN: Address of the RSDP
345 * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
346 * standard ACPI mechanism.
348 *****************************************************************************/
350 ACPI_PHYSICAL_ADDRESS
351 AcpiOsGetRootPointer (
355 return (ACPI_PTR_TO_PHYSADDR (&LocalRSDP));