1 /******************************************************************************
3 * Module Name: aetables - ACPI table setup/install for acpiexec 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.
47 #define _COMPONENT ACPI_TOOLS
48 ACPI_MODULE_NAME ("aetables")
50 /* Local prototypes */
53 AeInitializeTableHeader (
54 ACPI_TABLE_HEADER *Header,
60 ACPI_TABLE_HEADER *ExistingTable,
61 ACPI_TABLE_HEADER **NewTable);
63 /* User table (DSDT) */
65 static ACPI_TABLE_HEADER *DsdtToInstallOverride;
67 /* Non-AML tables that are constructed locally and installed */
69 static ACPI_TABLE_RSDP LocalRSDP;
70 static ACPI_TABLE_FACS LocalFACS;
71 static ACPI_TABLE_HEADER LocalTEST;
72 static ACPI_TABLE_HEADER LocalBADTABLE;
75 * We need a local FADT so that the hardware subcomponent will function,
76 * even though the underlying OSD HW access functions don't do anything.
78 static ACPI_TABLE_FADT LocalFADT;
81 * Use XSDT so that both 32- and 64-bit versions of this utility will
82 * function automatically.
84 static ACPI_TABLE_XSDT *LocalXSDT;
86 #define BASE_XSDT_TABLES 9
87 #define BASE_XSDT_SIZE ((BASE_XSDT_TABLES) * sizeof (UINT64))
89 #define ACPI_MAX_INIT_TABLES (32)
90 static ACPI_TABLE_DESC Tables[ACPI_MAX_INIT_TABLES];
93 /******************************************************************************
95 * FUNCTION: AeTableOverride
97 * DESCRIPTION: Local implementation of AcpiOsTableOverride.
98 * Exercise the override mechanism
100 *****************************************************************************/
104 ACPI_TABLE_HEADER *ExistingTable,
105 ACPI_TABLE_HEADER **NewTable)
108 if (!AcpiGbl_LoadTestTables)
114 /* This code exercises the table override mechanism in the core */
116 if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT))
118 *NewTable = DsdtToInstallOverride;
121 /* This code tests override of dynamically loaded tables */
123 else if (ACPI_COMPARE_NAME (ExistingTable->Signature, "OEM9"))
125 *NewTable = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Ssdt3Code);
130 /******************************************************************************
132 * FUNCTION: AeInitializeTableHeader
134 * PARAMETERS: Header - A valid standard ACPI table header
135 * Signature - Signature to insert
136 * Length - Length of the table
138 * RETURN: None. Header is modified.
140 * DESCRIPTION: Initialize the table header for a local ACPI table.
142 *****************************************************************************/
145 AeInitializeTableHeader (
146 ACPI_TABLE_HEADER *Header,
151 ACPI_MOVE_NAME (Header->Signature, Signature);
152 Header->Length = Length;
154 Header->OemRevision = 0x1001;
155 strncpy (Header->OemId, "Intel", ACPI_OEM_ID_SIZE);
156 strncpy (Header->OemTableId, "AcpiExec", ACPI_OEM_TABLE_ID_SIZE);
157 strncpy (Header->AslCompilerId, "INTL", ACPI_NAME_SIZE);
158 Header->AslCompilerRevision = 0x20131218;
162 /******************************************************************************
164 * FUNCTION: AeBuildLocalTables
166 * PARAMETERS: TableCount - Number of tables on the command line
167 * TableList - List of actual tables from files
171 * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
172 * FADT, and several other test tables.
174 *****************************************************************************/
179 AE_TABLE_DESC *TableList)
181 ACPI_PHYSICAL_ADDRESS DsdtAddress = 0;
183 AE_TABLE_DESC *NextTable;
185 ACPI_TABLE_FADT *ExternalFadt = NULL;
189 * Update the table count. For the DSDT, it is not put into the XSDT.
190 * For the FADT, this table is already accounted for since we usually
191 * install a local FADT.
193 NextTable = TableList;
196 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) ||
197 ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
201 NextTable = NextTable->Next;
204 XsdtSize = (((TableCount + 1) * sizeof (UINT64)) + sizeof (ACPI_TABLE_HEADER));
205 if (AcpiGbl_LoadTestTables)
207 XsdtSize += BASE_XSDT_SIZE;
212 LocalXSDT = AcpiOsAllocate (XsdtSize);
215 return (AE_NO_MEMORY);
218 memset (LocalXSDT, 0, XsdtSize);
219 AeInitializeTableHeader ((void *) LocalXSDT, ACPI_SIG_XSDT, XsdtSize);
221 LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT);
225 * Install the user tables. The DSDT must be installed in the FADT.
226 * All other tables are installed directly into the XSDT.
228 * Note: The tables are loaded in reverse order from the incoming
229 * input, which makes it match the command line order.
231 NextTable = TableList;
235 * Incoming DSDT or FADT are special cases. All other tables are
236 * just immediately installed into the XSDT.
238 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT))
242 printf ("Already found a DSDT, only one allowed\n");
243 return (AE_ALREADY_EXISTS);
246 /* The incoming user table is a DSDT */
248 DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
249 DsdtToInstallOverride = NextTable->Table;
251 else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
253 ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table);
254 LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
258 /* Install the table in the XSDT */
260 LocalXSDT->TableOffsetEntry[TableCount - NextIndex + 1] =
261 ACPI_PTR_TO_PHYSADDR (NextTable->Table);
265 NextTable = NextTable->Next;
268 /* Install the optional extra local tables */
270 if (AcpiGbl_LoadTestTables)
272 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalTEST);
273 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalBADTABLE);
275 /* Install two SSDTs to test multiple table support */
277 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt1Code);
278 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt2Code);
280 /* Install the OEM1 table to test LoadTable */
282 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Oem1Code);
284 /* Install the OEMx table to test LoadTable */
286 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&OemxCode);
288 /* Install the ECDT table to test _REG */
290 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&EcdtCode);
292 /* Install two UEFIs to test multiple table support */
294 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi1Code);
295 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi2Code);
298 /* Build an RSDP. Contains a valid XSDT only, no RSDT */
300 memset (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP));
301 ACPI_MAKE_RSDP_SIG (LocalRSDP.Signature);
302 memcpy (LocalRSDP.OemId, "Intel", 6);
304 LocalRSDP.Revision = 2;
305 LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT);
306 LocalRSDP.Length = sizeof (ACPI_TABLE_RSDP);
308 /* Set checksums for both XSDT and RSDP */
310 LocalXSDT->Header.Checksum = 0;
311 LocalXSDT->Header.Checksum = (UINT8) -AcpiTbChecksum (
312 (void *) LocalXSDT, LocalXSDT->Header.Length);
314 LocalRSDP.Checksum = 0;
315 LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum (
316 (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH);
320 /* Use the local DSDT because incoming table(s) are all SSDT(s) */
322 DsdtAddress = ACPI_PTR_TO_PHYSADDR (LocalDsdtCode);
323 DsdtToInstallOverride = ACPI_CAST_PTR (ACPI_TABLE_HEADER, LocalDsdtCode);
327 * Build an FADT. There are three options for the FADT:
328 * 1) Incoming external FADT specified on the command line
329 * 2) A "hardware reduced" local FADT
330 * 3) A fully featured local FADT
332 memset (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT));
337 * Use the external FADT, but we must update the DSDT/FACS addresses
338 * as well as the checksum
340 ExternalFadt->Dsdt = (UINT32) DsdtAddress;
341 if (!AcpiGbl_ReducedHardware)
343 ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
346 /* Is there room in the FADT for the XDsdst and XFacs 64-bit pointers? */
348 if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (&ExternalFadt->XDsdt, ExternalFadt))
350 ExternalFadt->XDsdt = DsdtAddress;
352 if (!AcpiGbl_ReducedHardware)
354 ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
358 /* Complete the FADT with the checksum */
360 ExternalFadt->Header.Checksum = 0;
361 ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum (
362 (void *) ExternalFadt, ExternalFadt->Header.Length);
364 else if (AcpiGbl_UseHwReducedFadt)
366 memcpy (&LocalFADT, HwReducedFadtCode, ACPI_FADT_V5_SIZE);
367 LocalFADT.Dsdt = (UINT32) DsdtAddress;
368 LocalFADT.XDsdt = DsdtAddress;
370 LocalFADT.Header.Checksum = 0;
371 LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum (
372 (void *) &LocalFADT, LocalFADT.Header.Length);
377 * Build a local FADT so we can test the hardware/event init
379 LocalFADT.Header.Revision = 5;
380 AeInitializeTableHeader ((void *) &LocalFADT, ACPI_SIG_FADT, sizeof (ACPI_TABLE_FADT));
382 /* Setup FADT header and DSDT/FACS addresses */
387 LocalFADT.XDsdt = DsdtAddress;
388 LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
390 /* Miscellaneous FADT fields */
392 LocalFADT.Gpe0BlockLength = 0x08;
393 LocalFADT.Gpe0Block = 0x00001234;
395 LocalFADT.Gpe1BlockLength = 0x80;
396 LocalFADT.Gpe1Block = 0x00005678;
397 LocalFADT.Gpe1Base = 100;
399 LocalFADT.Pm1EventLength = 4;
400 LocalFADT.Pm1aEventBlock = 0x00001aaa;
401 LocalFADT.Pm1bEventBlock = 0x00001bbb;
403 LocalFADT.Pm1ControlLength = 2;
404 LocalFADT.Pm1aControlBlock = 0xB0;
406 LocalFADT.PmTimerLength = 4;
407 LocalFADT.PmTimerBlock = 0xA0;
409 LocalFADT.Pm2ControlBlock = 0xC0;
410 LocalFADT.Pm2ControlLength = 1;
412 /* Setup one example X-64 GAS field */
414 LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
415 LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock;
416 LocalFADT.XPm1bEventBlock.BitWidth = (UINT8) ACPI_MUL_8 (LocalFADT.Pm1EventLength);
418 /* Complete the FADT with the checksum */
420 LocalFADT.Header.Checksum = 0;
421 LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum (
422 (void *) &LocalFADT, LocalFADT.Header.Length);
427 memset (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS));
428 ACPI_MOVE_NAME (LocalFACS.Signature, ACPI_SIG_FACS);
430 LocalFACS.Length = sizeof (ACPI_TABLE_FACS);
431 LocalFACS.GlobalLock = 0x11AA0011;
433 /* Build the optional local tables */
435 if (AcpiGbl_LoadTestTables)
438 * Build a fake table [TEST] so that we make sure that the
439 * ACPICA core ignores it
441 memset (&LocalTEST, 0, sizeof (ACPI_TABLE_HEADER));
442 ACPI_MOVE_NAME (LocalTEST.Signature, "TEST");
444 LocalTEST.Revision = 1;
445 LocalTEST.Length = sizeof (ACPI_TABLE_HEADER);
446 LocalTEST.Checksum = (UINT8) -AcpiTbChecksum (
447 (void *) &LocalTEST, LocalTEST.Length);
450 * Build a fake table with a bad signature [BAD!] so that we make
451 * sure that the ACPICA core ignores it
453 memset (&LocalBADTABLE, 0, sizeof (ACPI_TABLE_HEADER));
454 ACPI_MOVE_NAME (LocalBADTABLE.Signature, "BAD!");
456 LocalBADTABLE.Revision = 1;
457 LocalBADTABLE.Length = sizeof (ACPI_TABLE_HEADER);
458 LocalBADTABLE.Checksum = (UINT8) -AcpiTbChecksum (
459 (void *) &LocalBADTABLE, LocalBADTABLE.Length);
466 /******************************************************************************
468 * FUNCTION: AeInstallTables
474 * DESCRIPTION: Install the various ACPI tables
476 *****************************************************************************/
483 ACPI_TABLE_HEADER Header;
484 ACPI_TABLE_HEADER *Table;
487 Status = AcpiInitializeTables (Tables, ACPI_MAX_INIT_TABLES, TRUE);
488 AE_CHECK_OK (AcpiInitializeTables, Status);
490 Status = AcpiReallocateRootTable ();
491 AE_CHECK_OK (AcpiReallocateRootTable, Status);
493 Status = AcpiLoadTables ();
494 AE_CHECK_OK (AcpiLoadTables, Status);
497 * Test run-time control method installation. Do it twice to test code
498 * for an existing name.
500 Status = AcpiInstallMethod (MethodCode);
501 if (ACPI_FAILURE (Status))
503 AcpiOsPrintf ("%s, Could not install method\n",
504 AcpiFormatException (Status));
507 Status = AcpiInstallMethod (MethodCode);
508 if (ACPI_FAILURE (Status))
510 AcpiOsPrintf ("%s, Could not install method\n",
511 AcpiFormatException (Status));
514 if (AcpiGbl_LoadTestTables)
516 /* Test multiple table/UEFI support. First, get the headers */
518 Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 1, &Header);
519 AE_CHECK_OK (AcpiGetTableHeader, Status);
521 Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 2, &Header);
522 AE_CHECK_OK (AcpiGetTableHeader, Status);
524 Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 3, &Header);
525 AE_CHECK_STATUS (AcpiGetTableHeader, Status, AE_NOT_FOUND);
527 /* Now get the actual tables */
529 Status = AcpiGetTable (ACPI_SIG_UEFI, 1, &Table);
530 AE_CHECK_OK (AcpiGetTable, Status);
532 Status = AcpiGetTable (ACPI_SIG_UEFI, 2, &Table);
533 AE_CHECK_OK (AcpiGetTable, Status);
535 Status = AcpiGetTable (ACPI_SIG_UEFI, 3, &Table);
536 AE_CHECK_STATUS (AcpiGetTable, Status, AE_NOT_FOUND);
543 /******************************************************************************
545 * FUNCTION: AcpiOsGetRootPointer
547 * PARAMETERS: Flags - not used
548 * Address - Where the root pointer is returned
552 * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
553 * standard ACPI mechanism.
555 *****************************************************************************/
557 ACPI_PHYSICAL_ADDRESS
558 AcpiOsGetRootPointer (
562 return (ACPI_PTR_TO_PHYSADDR (&LocalRSDP));