1 /******************************************************************************
3 * Module Name: aetables - ACPI table setup/install for acpiexec 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.
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);
64 AeLocalGetRootPointer (
67 /* User table (DSDT) */
69 static ACPI_TABLE_HEADER *DsdtToInstallOverride;
71 /* Non-AML tables that are constructed locally and installed */
73 static ACPI_TABLE_RSDP LocalRSDP;
74 static ACPI_TABLE_FACS LocalFACS;
75 static ACPI_TABLE_HEADER LocalTEST;
76 static ACPI_TABLE_HEADER LocalBADTABLE;
79 * We need a local FADT so that the hardware subcomponent will function,
80 * even though the underlying OSD HW access functions don't do anything.
82 static ACPI_TABLE_FADT LocalFADT;
85 * Use XSDT so that both 32- and 64-bit versions of this utility will
86 * function automatically.
88 static ACPI_TABLE_XSDT *LocalXSDT;
90 #define BASE_XSDT_TABLES 9
91 #define BASE_XSDT_SIZE ((BASE_XSDT_TABLES) * sizeof (UINT64))
93 #define ACPI_MAX_INIT_TABLES (32)
94 static ACPI_TABLE_DESC Tables[ACPI_MAX_INIT_TABLES];
97 /******************************************************************************
99 * FUNCTION: AeTableOverride
101 * DESCRIPTION: Local implementation of AcpiOsTableOverride.
102 * Exercise the override mechanism
104 *****************************************************************************/
108 ACPI_TABLE_HEADER *ExistingTable,
109 ACPI_TABLE_HEADER **NewTable)
112 if (!AcpiGbl_LoadTestTables)
118 /* This code exercises the table override mechanism in the core */
120 if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT))
122 *NewTable = DsdtToInstallOverride;
125 /* This code tests override of dynamically loaded tables */
127 else if (ACPI_COMPARE_NAME (ExistingTable->Signature, "OEM9"))
129 *NewTable = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Ssdt3Code);
134 /******************************************************************************
136 * FUNCTION: AeInitializeTableHeader
138 * PARAMETERS: Header - A valid standard ACPI table header
139 * Signature - Signature to insert
140 * Length - Length of the table
142 * RETURN: None. Header is modified.
144 * DESCRIPTION: Initialize the table header for a local ACPI table.
146 *****************************************************************************/
149 AeInitializeTableHeader (
150 ACPI_TABLE_HEADER *Header,
155 ACPI_MOVE_NAME (Header->Signature, Signature);
156 Header->Length = Length;
158 Header->OemRevision = 0x1001;
159 ACPI_STRNCPY (Header->OemId, "Intel", ACPI_OEM_ID_SIZE);
160 ACPI_STRNCPY (Header->OemTableId, "AcpiExec", ACPI_OEM_TABLE_ID_SIZE);
161 ACPI_STRNCPY (Header->AslCompilerId, "INTL", ACPI_NAME_SIZE);
162 Header->AslCompilerRevision = 0x20131218;
166 /******************************************************************************
168 * FUNCTION: AeBuildLocalTables
170 * PARAMETERS: TableCount - Number of tables on the command line
171 * TableList - List of actual tables from files
175 * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
176 * FADT, and several other test tables.
178 *****************************************************************************/
183 AE_TABLE_DESC *TableList)
185 ACPI_PHYSICAL_ADDRESS DsdtAddress = 0;
187 AE_TABLE_DESC *NextTable;
189 ACPI_TABLE_FADT *ExternalFadt = NULL;
193 * Update the table count. For the DSDT, it is not put into the XSDT.
194 * For the FADT, this table is already accounted for since we usually
195 * install a local FADT.
197 NextTable = TableList;
200 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) ||
201 ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
205 NextTable = NextTable->Next;
208 XsdtSize = (((TableCount + 1) * sizeof (UINT64)) + sizeof (ACPI_TABLE_HEADER));
209 if (AcpiGbl_LoadTestTables)
211 XsdtSize += BASE_XSDT_SIZE;
216 LocalXSDT = AcpiOsAllocate (XsdtSize);
219 return (AE_NO_MEMORY);
222 ACPI_MEMSET (LocalXSDT, 0, XsdtSize);
223 AeInitializeTableHeader ((void *) LocalXSDT, ACPI_SIG_XSDT, XsdtSize);
225 LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT);
229 * Install the user tables. The DSDT must be installed in the FADT.
230 * All other tables are installed directly into the XSDT.
232 * Note: The tables are loaded in reverse order from the incoming
233 * input, which makes it match the command line order.
235 NextTable = TableList;
239 * Incoming DSDT or FADT are special cases. All other tables are
240 * just immediately installed into the XSDT.
242 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT))
246 printf ("Already found a DSDT, only one allowed\n");
247 return (AE_ALREADY_EXISTS);
250 /* The incoming user table is a DSDT */
252 DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
253 DsdtToInstallOverride = NextTable->Table;
255 else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
257 ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table);
258 LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
262 /* Install the table in the XSDT */
264 LocalXSDT->TableOffsetEntry[TableCount - NextIndex + 1] =
265 ACPI_PTR_TO_PHYSADDR (NextTable->Table);
269 NextTable = NextTable->Next;
272 /* Install the optional extra local tables */
274 if (AcpiGbl_LoadTestTables)
276 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalTEST);
277 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalBADTABLE);
279 /* Install two SSDTs to test multiple table support */
281 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt1Code);
282 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt2Code);
284 /* Install the OEM1 table to test LoadTable */
286 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Oem1Code);
288 /* Install the OEMx table to test LoadTable */
290 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&OemxCode);
292 /* Install the ECDT table to test _REG */
294 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&EcdtCode);
296 /* Install two UEFIs to test multiple table support */
298 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi1Code);
299 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi2Code);
302 /* Build an RSDP. Contains a valid XSDT only, no RSDT */
304 ACPI_MEMSET (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP));
305 ACPI_MAKE_RSDP_SIG (LocalRSDP.Signature);
306 ACPI_MEMCPY (LocalRSDP.OemId, "Intel", 6);
308 LocalRSDP.Revision = 2;
309 LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT);
310 LocalRSDP.Length = sizeof (ACPI_TABLE_RSDP);
312 /* Set checksums for both XSDT and RSDP */
314 LocalXSDT->Header.Checksum = 0;
315 LocalXSDT->Header.Checksum = (UINT8) -AcpiTbChecksum (
316 (void *) LocalXSDT, LocalXSDT->Header.Length);
318 LocalRSDP.Checksum = 0;
319 LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum (
320 (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH);
324 /* Use the local DSDT because incoming table(s) are all SSDT(s) */
326 DsdtAddress = ACPI_PTR_TO_PHYSADDR (LocalDsdtCode);
327 DsdtToInstallOverride = ACPI_CAST_PTR (ACPI_TABLE_HEADER, LocalDsdtCode);
331 * Build an FADT. There are three options for the FADT:
332 * 1) Incoming external FADT specified on the command line
333 * 2) A "hardware reduced" local FADT
334 * 3) A fully featured local FADT
339 * Use the external FADT, but we must update the DSDT/FACS addresses
340 * as well as the checksum
342 ExternalFadt->Dsdt = DsdtAddress;
343 if (!AcpiGbl_ReducedHardware)
345 ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
348 /* Is there room in the FADT for the XDsdst and XFacs 64-bit pointers? */
350 if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (&ExternalFadt->XDsdt, ExternalFadt))
352 ExternalFadt->XDsdt = DsdtAddress;
354 if (!AcpiGbl_ReducedHardware)
356 ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
360 /* Complete the FADT with the checksum */
362 ExternalFadt->Header.Checksum = 0;
363 ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum (
364 (void *) ExternalFadt, ExternalFadt->Header.Length);
366 else if (AcpiGbl_UseHwReducedFadt)
368 ACPI_MEMCPY (&LocalFADT, HwReducedFadtCode, sizeof (ACPI_TABLE_FADT));
369 LocalFADT.Dsdt = DsdtAddress;
370 LocalFADT.XDsdt = DsdtAddress;
372 LocalFADT.Header.Checksum = 0;
373 LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum (
374 (void *) &LocalFADT, LocalFADT.Header.Length);
379 * Build a local FADT so we can test the hardware/event init
381 ACPI_MEMSET (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT));
382 LocalFADT.Header.Revision = 5;
383 AeInitializeTableHeader ((void *) &LocalFADT, ACPI_SIG_FADT, sizeof (ACPI_TABLE_FADT));
385 /* Setup FADT header and DSDT/FACS addresses */
390 LocalFADT.XDsdt = DsdtAddress;
391 LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
393 /* Miscellaneous FADT fields */
395 LocalFADT.Gpe0BlockLength = 16;
396 LocalFADT.Gpe0Block = 0x00001234;
398 LocalFADT.Gpe1BlockLength = 6;
399 LocalFADT.Gpe1Block = 0x00005678;
400 LocalFADT.Gpe1Base = 96;
402 LocalFADT.Pm1EventLength = 4;
403 LocalFADT.Pm1aEventBlock = 0x00001aaa;
404 LocalFADT.Pm1bEventBlock = 0x00001bbb;
406 LocalFADT.Pm1ControlLength = 2;
407 LocalFADT.Pm1aControlBlock = 0xB0;
409 LocalFADT.PmTimerLength = 4;
410 LocalFADT.PmTimerBlock = 0xA0;
412 LocalFADT.Pm2ControlBlock = 0xC0;
413 LocalFADT.Pm2ControlLength = 1;
415 /* Setup one example X-64 GAS field */
417 LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
418 LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock;
419 LocalFADT.XPm1bEventBlock.BitWidth = (UINT8) ACPI_MUL_8 (LocalFADT.Pm1EventLength);
421 /* Complete the FADT with the checksum */
423 LocalFADT.Header.Checksum = 0;
424 LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum (
425 (void *) &LocalFADT, LocalFADT.Header.Length);
430 ACPI_MEMSET (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS));
431 ACPI_MOVE_NAME (LocalFACS.Signature, ACPI_SIG_FACS);
433 LocalFACS.Length = sizeof (ACPI_TABLE_FACS);
434 LocalFACS.GlobalLock = 0x11AA0011;
436 /* Build the optional local tables */
438 if (AcpiGbl_LoadTestTables)
441 * Build a fake table [TEST] so that we make sure that the
442 * ACPICA core ignores it
444 ACPI_MEMSET (&LocalTEST, 0, sizeof (ACPI_TABLE_HEADER));
445 ACPI_MOVE_NAME (LocalTEST.Signature, "TEST");
447 LocalTEST.Revision = 1;
448 LocalTEST.Length = sizeof (ACPI_TABLE_HEADER);
449 LocalTEST.Checksum = (UINT8) -AcpiTbChecksum (
450 (void *) &LocalTEST, LocalTEST.Length);
453 * Build a fake table with a bad signature [BAD!] so that we make
454 * sure that the ACPICA core ignores it
456 ACPI_MEMSET (&LocalBADTABLE, 0, sizeof (ACPI_TABLE_HEADER));
457 ACPI_MOVE_NAME (LocalBADTABLE.Signature, "BAD!");
459 LocalBADTABLE.Revision = 1;
460 LocalBADTABLE.Length = sizeof (ACPI_TABLE_HEADER);
461 LocalBADTABLE.Checksum = (UINT8) -AcpiTbChecksum (
462 (void *) &LocalBADTABLE, LocalBADTABLE.Length);
469 /******************************************************************************
471 * FUNCTION: AeInstallTables
477 * DESCRIPTION: Install the various ACPI tables
479 *****************************************************************************/
486 ACPI_TABLE_HEADER Header;
487 ACPI_TABLE_HEADER *Table;
490 Status = AcpiInitializeTables (Tables, ACPI_MAX_INIT_TABLES, TRUE);
491 AE_CHECK_OK (AcpiInitializeTables, Status);
493 Status = AcpiReallocateRootTable ();
494 AE_CHECK_OK (AcpiReallocateRootTable, Status);
496 Status = AcpiLoadTables ();
497 AE_CHECK_OK (AcpiLoadTables, Status);
500 * Test run-time control method installation. Do it twice to test code
501 * for an existing name.
503 Status = AcpiInstallMethod (MethodCode);
504 if (ACPI_FAILURE (Status))
506 AcpiOsPrintf ("%s, Could not install method\n",
507 AcpiFormatException (Status));
510 Status = AcpiInstallMethod (MethodCode);
511 if (ACPI_FAILURE (Status))
513 AcpiOsPrintf ("%s, Could not install method\n",
514 AcpiFormatException (Status));
517 if (AcpiGbl_LoadTestTables)
519 /* Test multiple table/UEFI support. First, get the headers */
521 Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 1, &Header);
522 AE_CHECK_OK (AcpiGetTableHeader, Status);
524 Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 2, &Header);
525 AE_CHECK_OK (AcpiGetTableHeader, Status);
527 Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 3, &Header);
528 AE_CHECK_STATUS (AcpiGetTableHeader, Status, AE_NOT_FOUND);
530 /* Now get the actual tables */
532 Status = AcpiGetTable (ACPI_SIG_UEFI, 1, &Table);
533 AE_CHECK_OK (AcpiGetTable, Status);
535 Status = AcpiGetTable (ACPI_SIG_UEFI, 2, &Table);
536 AE_CHECK_OK (AcpiGetTable, Status);
538 Status = AcpiGetTable (ACPI_SIG_UEFI, 3, &Table);
539 AE_CHECK_STATUS (AcpiGetTable, Status, AE_NOT_FOUND);
546 /******************************************************************************
548 * FUNCTION: AeLocalGetRootPointer
550 * PARAMETERS: Flags - not used
551 * Address - Where the root pointer is returned
555 * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
556 * standard ACPI mechanism.
558 *****************************************************************************/
560 ACPI_PHYSICAL_ADDRESS
561 AeLocalGetRootPointer (
565 return ((ACPI_PHYSICAL_ADDRESS) &LocalRSDP);