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)
92 /******************************************************************************
94 * FUNCTION: AeTableOverride
96 * DESCRIPTION: Local implementation of AcpiOsTableOverride.
97 * Exercise the override mechanism
99 *****************************************************************************/
103 ACPI_TABLE_HEADER *ExistingTable,
104 ACPI_TABLE_HEADER **NewTable)
107 if (!AcpiGbl_LoadTestTables)
113 /* This code exercises the table override mechanism in the core */
115 if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT))
117 *NewTable = DsdtToInstallOverride;
120 /* This code tests override of dynamically loaded tables */
122 else if (ACPI_COMPARE_NAME (ExistingTable->Signature, "OEM9"))
124 *NewTable = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Ssdt3Code);
129 /******************************************************************************
131 * FUNCTION: AeInitializeTableHeader
133 * PARAMETERS: Header - A valid standard ACPI table header
134 * Signature - Signature to insert
135 * Length - Length of the table
137 * RETURN: None. Header is modified.
139 * DESCRIPTION: Initialize the table header for a local ACPI table.
141 *****************************************************************************/
144 AeInitializeTableHeader (
145 ACPI_TABLE_HEADER *Header,
150 ACPI_MOVE_NAME (Header->Signature, Signature);
151 Header->Length = Length;
153 Header->OemRevision = 0x1001;
154 strncpy (Header->OemId, "Intel", ACPI_OEM_ID_SIZE);
155 strncpy (Header->OemTableId, "AcpiExec", ACPI_OEM_TABLE_ID_SIZE);
156 strncpy (Header->AslCompilerId, "INTL", ACPI_NAME_SIZE);
157 Header->AslCompilerRevision = ACPI_CA_VERSION;
159 /* Set the checksum, must set to zero first */
161 Header->Checksum = 0;
162 Header->Checksum = (UINT8) -AcpiTbChecksum (
163 (void *) Header, Header->Length);
167 /******************************************************************************
169 * FUNCTION: AeBuildLocalTables
171 * PARAMETERS: TableCount - Number of tables on the command line
172 * TableList - List of actual tables from files
176 * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
177 * FADT, and several other test tables.
179 *****************************************************************************/
184 AE_TABLE_DESC *TableList)
186 ACPI_PHYSICAL_ADDRESS DsdtAddress = 0;
188 AE_TABLE_DESC *NextTable;
190 ACPI_TABLE_FADT *ExternalFadt = NULL;
194 * Update the table count. For the DSDT, it is not put into the XSDT.
195 * For the FADT, this table is already accounted for since we usually
196 * install a local FADT.
198 NextTable = TableList;
201 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) ||
202 ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
206 NextTable = NextTable->Next;
209 XsdtSize = (((TableCount + 1) * sizeof (UINT64)) + sizeof (ACPI_TABLE_HEADER));
210 if (AcpiGbl_LoadTestTables)
212 XsdtSize += BASE_XSDT_SIZE;
217 LocalXSDT = AcpiOsAllocate (XsdtSize);
220 return (AE_NO_MEMORY);
223 memset (LocalXSDT, 0, XsdtSize);
224 LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT);
228 * Install the user tables. The DSDT must be installed in the FADT.
229 * All other tables are installed directly into the XSDT.
231 * Note: The tables are loaded in reverse order from the incoming
232 * input, which makes it match the command line order.
234 NextTable = TableList;
238 * Incoming DSDT or FADT are special cases. All other tables are
239 * just immediately installed into the XSDT.
241 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT))
245 printf ("Already found a DSDT, only one allowed\n");
246 return (AE_ALREADY_EXISTS);
249 /* The incoming user table is a DSDT */
251 DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
252 DsdtToInstallOverride = NextTable->Table;
254 else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
256 ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table);
257 LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
261 /* Install the table in the XSDT */
263 LocalXSDT->TableOffsetEntry[TableCount - NextIndex + 1] =
264 ACPI_PTR_TO_PHYSADDR (NextTable->Table);
268 NextTable = NextTable->Next;
271 /* Install the optional extra local tables */
273 if (AcpiGbl_LoadTestTables)
275 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalTEST);
276 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalBADTABLE);
278 /* Install two SSDTs to test multiple table support */
280 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt1Code);
281 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt2Code);
283 /* Install the OEM1 table to test LoadTable */
285 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Oem1Code);
287 /* Install the OEMx table to test LoadTable */
289 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&OemxCode);
291 /* Install the ECDT table to test _REG */
293 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&EcdtCode);
295 /* Install two UEFIs to test multiple table support */
297 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi1Code);
298 LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi2Code);
301 /* Build an RSDP. Contains a valid XSDT only, no RSDT */
303 memset (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP));
304 ACPI_MAKE_RSDP_SIG (LocalRSDP.Signature);
305 memcpy (LocalRSDP.OemId, "Intel", 6);
307 LocalRSDP.Revision = 2;
308 LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT);
309 LocalRSDP.Length = sizeof (ACPI_TABLE_RSDP);
311 /* Set checksums for both XSDT and RSDP */
313 AeInitializeTableHeader ((void *) LocalXSDT, ACPI_SIG_XSDT, XsdtSize);
315 LocalRSDP.Checksum = 0;
316 LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum (
317 (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH);
321 /* Use the local DSDT because incoming table(s) are all SSDT(s) */
323 DsdtAddress = ACPI_PTR_TO_PHYSADDR (LocalDsdtCode);
324 DsdtToInstallOverride = ACPI_CAST_PTR (ACPI_TABLE_HEADER, LocalDsdtCode);
328 * Build an FADT. There are three options for the FADT:
329 * 1) Incoming external FADT specified on the command line
330 * 2) A "hardware reduced" local FADT
331 * 3) A fully featured local FADT
333 memset (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT));
338 * Use the external FADT, but we must update the DSDT/FACS
339 * addresses as well as the checksum
341 ExternalFadt->Dsdt = (UINT32) DsdtAddress;
342 if (!AcpiGbl_ReducedHardware)
344 ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
348 * If there room in the FADT for the XDsdt and XFacs 64-bit
349 * pointers, use them.
351 if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (
352 &ExternalFadt->XDsdt, ExternalFadt))
354 ExternalFadt->Dsdt = 0;
355 ExternalFadt->Facs = 0;
357 ExternalFadt->XDsdt = DsdtAddress;
358 if (!AcpiGbl_ReducedHardware)
360 ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
364 /* Complete the external FADT with the checksum */
366 ExternalFadt->Header.Checksum = 0;
367 ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum (
368 (void *) ExternalFadt, ExternalFadt->Header.Length);
370 else if (AcpiGbl_UseHwReducedFadt)
372 memcpy (&LocalFADT, HwReducedFadtCode, ACPI_FADT_V5_SIZE);
374 LocalFADT.XDsdt = DsdtAddress;
379 * Build a local FADT so we can test the hardware/event init
381 LocalFADT.Header.Revision = 5;
383 /* Setup FADT header and DSDT/FACS addresses */
388 LocalFADT.XDsdt = DsdtAddress;
389 LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
391 /* Miscellaneous FADT fields */
393 LocalFADT.Gpe0BlockLength = 0x08;
394 LocalFADT.Gpe0Block = 0x00001234;
396 LocalFADT.Gpe1BlockLength = 0x80;
397 LocalFADT.Gpe1Block = 0x00005678;
398 LocalFADT.Gpe1Base = 100;
400 LocalFADT.Pm1EventLength = 4;
401 LocalFADT.Pm1aEventBlock = 0x00001aaa;
402 LocalFADT.Pm1bEventBlock = 0x00001bbb;
404 LocalFADT.Pm1ControlLength = 2;
405 LocalFADT.Pm1aControlBlock = 0xB0;
407 LocalFADT.PmTimerLength = 4;
408 LocalFADT.PmTimerBlock = 0xA0;
410 LocalFADT.Pm2ControlBlock = 0xC0;
411 LocalFADT.Pm2ControlLength = 1;
413 /* Setup one example X-64 GAS field */
415 LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
416 LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock;
417 LocalFADT.XPm1bEventBlock.BitWidth = (UINT8)
418 ACPI_MUL_8 (LocalFADT.Pm1EventLength);
421 AeInitializeTableHeader ((void *) &LocalFADT,
422 ACPI_SIG_FADT, sizeof (ACPI_TABLE_FADT));
426 memset (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS));
427 ACPI_MOVE_NAME (LocalFACS.Signature, ACPI_SIG_FACS);
429 LocalFACS.Length = sizeof (ACPI_TABLE_FACS);
430 LocalFACS.GlobalLock = 0x11AA0011;
432 /* Build the optional local tables */
434 if (AcpiGbl_LoadTestTables)
437 * Build a fake table [TEST] so that we make sure that the
438 * ACPICA core ignores it
440 memset (&LocalTEST, 0, sizeof (ACPI_TABLE_HEADER));
441 ACPI_MOVE_NAME (LocalTEST.Signature, "TEST");
443 LocalTEST.Revision = 1;
444 LocalTEST.Length = sizeof (ACPI_TABLE_HEADER);
446 LocalTEST.Checksum = 0;
447 LocalTEST.Checksum = (UINT8) -AcpiTbChecksum (
448 (void *) &LocalTEST, LocalTEST.Length);
451 * Build a fake table with a bad signature [BAD!] so that we make
452 * sure that the ACPICA core ignores it
454 memset (&LocalBADTABLE, 0, sizeof (ACPI_TABLE_HEADER));
455 ACPI_MOVE_NAME (LocalBADTABLE.Signature, "BAD!");
457 LocalBADTABLE.Revision = 1;
458 LocalBADTABLE.Length = sizeof (ACPI_TABLE_HEADER);
460 LocalBADTABLE.Checksum = 0;
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;
491 Status = AcpiInitializeTables (NULL, ACPI_MAX_INIT_TABLES, TRUE);
492 AE_CHECK_OK (AcpiInitializeTables, Status);
494 Status = AcpiLoadTables ();
495 AE_CHECK_OK (AcpiLoadTables, Status);
498 * Test run-time control method installation. Do it twice to test code
499 * for an existing name.
501 Status = AcpiInstallMethod (MethodCode);
502 if (ACPI_FAILURE (Status))
504 AcpiOsPrintf ("%s, Could not install method\n",
505 AcpiFormatException (Status));
508 Status = AcpiInstallMethod (MethodCode);
509 if (ACPI_FAILURE (Status))
511 AcpiOsPrintf ("%s, Could not install method\n",
512 AcpiFormatException (Status));
515 if (AcpiGbl_LoadTestTables)
517 /* Test multiple table/UEFI support. First, get the headers */
519 Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 1, &Header);
520 AE_CHECK_OK (AcpiGetTableHeader, Status);
522 Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 2, &Header);
523 AE_CHECK_OK (AcpiGetTableHeader, Status);
525 Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 3, &Header);
526 AE_CHECK_STATUS (AcpiGetTableHeader, Status, AE_NOT_FOUND);
528 /* Now get the actual tables */
530 Status = AcpiGetTable (ACPI_SIG_UEFI, 1, &Table);
531 AE_CHECK_OK (AcpiGetTable, Status);
533 Status = AcpiGetTable (ACPI_SIG_UEFI, 2, &Table);
534 AE_CHECK_OK (AcpiGetTable, Status);
536 Status = AcpiGetTable (ACPI_SIG_UEFI, 3, &Table);
537 AE_CHECK_STATUS (AcpiGetTable, Status, AE_NOT_FOUND);
540 /* Check that we can get all of the ACPI tables */
544 Status = AcpiGetTableByIndex (i, &Table);
545 if ((Status == AE_BAD_PARAMETER) || !Table)
549 AE_CHECK_OK (AcpiGetTableByIndex, Status);
556 /******************************************************************************
558 * FUNCTION: AcpiOsGetRootPointer
560 * PARAMETERS: Flags - not used
561 * Address - Where the root pointer is returned
565 * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
566 * standard ACPI mechanism.
568 *****************************************************************************/
570 ACPI_PHYSICAL_ADDRESS
571 AcpiOsGetRootPointer (
575 return (ACPI_PTR_TO_PHYSADDR (&LocalRSDP));