Home | History | Annotate | Line # | Download | only in acpiexec
aetables.c revision 1.1.1.2
      1 /******************************************************************************
      2  *
      3  * Module Name: aetables - ACPI table setup/install for acpiexec utility
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2011, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     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.
     25  *
     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.
     29  *
     30  * NO WARRANTY
     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.
     42  */
     43 
     44 #include "aecommon.h"
     45 #include "aetables.h"
     46 
     47 #define _COMPONENT          ACPI_TOOLS
     48         ACPI_MODULE_NAME    ("aetables")
     49 
     50 /* Local prototypes */
     51 
     52 void
     53 AeTableOverride (
     54     ACPI_TABLE_HEADER       *ExistingTable,
     55     ACPI_TABLE_HEADER       **NewTable);
     56 
     57 ACPI_PHYSICAL_ADDRESS
     58 AeLocalGetRootPointer (
     59     void);
     60 
     61 /* User table (DSDT) */
     62 
     63 static ACPI_TABLE_HEADER        *DsdtToInstallOverride;
     64 
     65 /* Non-AML tables that are constructed locally and installed */
     66 
     67 static ACPI_TABLE_RSDP          LocalRSDP;
     68 static ACPI_TABLE_FACS          LocalFACS;
     69 static ACPI_TABLE_HEADER        LocalTEST;
     70 static ACPI_TABLE_HEADER        LocalBADTABLE;
     71 
     72 /*
     73  * We need a local FADT so that the hardware subcomponent will function,
     74  * even though the underlying OSD HW access functions don't do anything.
     75  */
     76 static ACPI_TABLE_FADT          LocalFADT;
     77 
     78 /*
     79  * Use XSDT so that both 32- and 64-bit versions of this utility will
     80  * function automatically.
     81  */
     82 static ACPI_TABLE_XSDT          *LocalXSDT;
     83 
     84 #define BASE_XSDT_TABLES        7
     85 #define BASE_XSDT_SIZE          (sizeof (ACPI_TABLE_XSDT) + \
     86                                     ((BASE_XSDT_TABLES -1) * sizeof (UINT64)))
     87 
     88 #define ACPI_MAX_INIT_TABLES    (32)
     89 static ACPI_TABLE_DESC          Tables[ACPI_MAX_INIT_TABLES];
     90 
     91 
     92 /******************************************************************************
     93  *
     94  * FUNCTION:    AeTableOverride
     95  *
     96  * DESCRIPTION: Local implementation of AcpiOsTableOverride.
     97  *              Exercise the override mechanism
     98  *
     99  *****************************************************************************/
    100 
    101 void
    102 AeTableOverride (
    103     ACPI_TABLE_HEADER       *ExistingTable,
    104     ACPI_TABLE_HEADER       **NewTable)
    105 {
    106 
    107     /* This code exercises the table override mechanism in the core */
    108 
    109     if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT))
    110     {
    111         *NewTable = DsdtToInstallOverride;
    112     }
    113 
    114     /* This code tests override of dynamically loaded tables */
    115 
    116     else if (ACPI_COMPARE_NAME (ExistingTable->Signature, "TSDT"))
    117     {
    118         *NewTable = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Ssdt3Code);
    119     }
    120 }
    121 
    122 
    123 /******************************************************************************
    124  *
    125  * FUNCTION:    AeBuildLocalTables
    126  *
    127  * PARAMETERS:  TableCount      - Number of tables on the command line
    128  *              TableList       - List of actual tables from files
    129  *
    130  * RETURN:      Status
    131  *
    132  * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
    133  *              FADT, and several other test tables.
    134  *
    135  *****************************************************************************/
    136 
    137 ACPI_STATUS
    138 AeBuildLocalTables (
    139     UINT32                  TableCount,
    140     AE_TABLE_DESC           *TableList)
    141 {
    142     ACPI_PHYSICAL_ADDRESS   DsdtAddress = 0;
    143     UINT32                  XsdtSize;
    144     AE_TABLE_DESC           *NextTable;
    145     UINT32                  NextIndex;
    146     ACPI_TABLE_FADT         *ExternalFadt = NULL;
    147 
    148 
    149     /*
    150      * Update the table count. For DSDT, it is not put into the XSDT. For
    151      * FADT, this is already accounted for since we usually install a
    152      * local FADT.
    153      */
    154     NextTable = TableList;
    155     while (NextTable)
    156     {
    157         if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) ||
    158             ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
    159         {
    160             TableCount--;
    161         }
    162         NextTable = NextTable->Next;
    163     }
    164 
    165     XsdtSize = BASE_XSDT_SIZE + (TableCount * sizeof (UINT64));
    166 
    167     /* Build an XSDT */
    168 
    169     LocalXSDT = AcpiOsAllocate (XsdtSize);
    170     if (!LocalXSDT)
    171     {
    172         return (AE_NO_MEMORY);
    173     }
    174 
    175     ACPI_MEMSET (LocalXSDT, 0, XsdtSize);
    176     ACPI_STRNCPY (LocalXSDT->Header.Signature, ACPI_SIG_XSDT, 4);
    177     LocalXSDT->Header.Length = XsdtSize;
    178     LocalXSDT->Header.Revision = 1;
    179 
    180     LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalTEST);
    181     LocalXSDT->TableOffsetEntry[1] = ACPI_PTR_TO_PHYSADDR (&LocalBADTABLE);
    182     LocalXSDT->TableOffsetEntry[2] = ACPI_PTR_TO_PHYSADDR (&LocalFADT);
    183 
    184     /* Install two SSDTs to test multiple table support */
    185 
    186     LocalXSDT->TableOffsetEntry[3] = ACPI_PTR_TO_PHYSADDR (&Ssdt1Code);
    187     LocalXSDT->TableOffsetEntry[4] = ACPI_PTR_TO_PHYSADDR (&Ssdt2Code);
    188 
    189     /* Install the OEM1 table to test LoadTable */
    190 
    191     LocalXSDT->TableOffsetEntry[5] = ACPI_PTR_TO_PHYSADDR (&Oem1Code);
    192 
    193     /* Install the OEMx table to test LoadTable */
    194 
    195     LocalXSDT->TableOffsetEntry[6] = ACPI_PTR_TO_PHYSADDR (&OemxCode);
    196 
    197     /*
    198      * Install the user tables. The DSDT must be installed in the FADT.
    199      * All other tables are installed directly into the XSDT.
    200      */
    201     NextIndex = BASE_XSDT_TABLES;
    202     NextTable = TableList;
    203     while (NextTable)
    204     {
    205         /*
    206          * Incoming DSDT or FADT are special cases. All other tables are
    207          * just immediately installed into the XSDT.
    208          */
    209         if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT))
    210         {
    211             if (DsdtAddress)
    212             {
    213                 printf ("Already found a DSDT, only one allowed\n");
    214                 return (AE_ALREADY_EXISTS);
    215             }
    216 
    217             /* The incoming user table is a DSDT */
    218 
    219             DsdtAddress = ACPI_PTR_TO_PHYSADDR (&DsdtCode);
    220             DsdtToInstallOverride = NextTable->Table;
    221         }
    222         else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
    223         {
    224             ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table);
    225             LocalXSDT->TableOffsetEntry[2] = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
    226         }
    227         else
    228         {
    229             /* Install the table in the XSDT */
    230 
    231             LocalXSDT->TableOffsetEntry[NextIndex] = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
    232             NextIndex++;
    233         }
    234 
    235         NextTable = NextTable->Next;
    236     }
    237 
    238     /* Build an RSDP */
    239 
    240     ACPI_MEMSET (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP));
    241     ACPI_MEMCPY (LocalRSDP.Signature, ACPI_SIG_RSDP, 8);
    242     ACPI_MEMCPY (LocalRSDP.OemId, "I_TEST", 6);
    243     LocalRSDP.Revision = 2;
    244     LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT);
    245     LocalRSDP.Length = sizeof (ACPI_TABLE_XSDT);
    246 
    247     /* Set checksums for both XSDT and RSDP */
    248 
    249     LocalXSDT->Header.Checksum = (UINT8) -AcpiTbChecksum (
    250         (void *) LocalXSDT, LocalXSDT->Header.Length);
    251     LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum (
    252         (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH);
    253 
    254     if (!DsdtAddress)
    255     {
    256         /* Use the local DSDT because incoming table(s) are all SSDT(s) */
    257 
    258         DsdtAddress = ACPI_PTR_TO_PHYSADDR (LocalDsdtCode);
    259         DsdtToInstallOverride = ACPI_CAST_PTR (ACPI_TABLE_HEADER, LocalDsdtCode);
    260     }
    261 
    262     if (ExternalFadt)
    263     {
    264         /*
    265          * Use the external FADT, but we must update the DSDT/FACS addresses
    266          * as well as the checksum
    267          */
    268         ExternalFadt->Dsdt = DsdtAddress;
    269         ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
    270 
    271         if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (&ExternalFadt->XDsdt, ExternalFadt))
    272         {
    273             ExternalFadt->XDsdt = DsdtAddress;
    274             ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
    275         }
    276         /* Complete the FADT with the checksum */
    277 
    278         ExternalFadt->Header.Checksum = 0;
    279         ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum (
    280             (void *) ExternalFadt, ExternalFadt->Header.Length);
    281     }
    282     else
    283     {
    284         /*
    285          * Build a local FADT so we can test the hardware/event init
    286          */
    287         ACPI_MEMSET (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT));
    288         ACPI_STRNCPY (LocalFADT.Header.Signature, ACPI_SIG_FADT, 4);
    289 
    290         /* Setup FADT header and DSDT/FACS addresses */
    291 
    292         LocalFADT.Dsdt = 0;
    293         LocalFADT.Facs = 0;
    294 
    295         LocalFADT.XDsdt = DsdtAddress;
    296         LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
    297 
    298         LocalFADT.Header.Revision = 3;
    299         LocalFADT.Header.Length = sizeof (ACPI_TABLE_FADT);
    300 
    301         /* Miscellaneous FADT fields */
    302 
    303         LocalFADT.Gpe0BlockLength = 16;
    304         LocalFADT.Gpe0Block = 0x00001234;
    305 
    306         LocalFADT.Gpe1BlockLength = 6;
    307         LocalFADT.Gpe1Block = 0x00005678;
    308         LocalFADT.Gpe1Base = 96;
    309 
    310         LocalFADT.Pm1EventLength = 4;
    311         LocalFADT.Pm1aEventBlock = 0x00001aaa;
    312         LocalFADT.Pm1bEventBlock = 0x00001bbb;
    313 
    314         LocalFADT.Pm1ControlLength = 2;
    315         LocalFADT.Pm1aControlBlock = 0xB0;
    316 
    317         LocalFADT.PmTimerLength = 4;
    318         LocalFADT.PmTimerBlock = 0xA0;
    319 
    320         LocalFADT.Pm2ControlBlock = 0xC0;
    321         LocalFADT.Pm2ControlLength = 1;
    322 
    323         /* Setup one example X-64 field */
    324 
    325         LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
    326         LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock;
    327         LocalFADT.XPm1bEventBlock.BitWidth = (UINT8) ACPI_MUL_8 (LocalFADT.Pm1EventLength);
    328 
    329         /* Complete the FADT with the checksum */
    330 
    331         LocalFADT.Header.Checksum = 0;
    332         LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum (
    333             (void *) &LocalFADT, LocalFADT.Header.Length);
    334     }
    335 
    336     /* Build a FACS */
    337 
    338     ACPI_MEMSET (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS));
    339     ACPI_STRNCPY (LocalFACS.Signature, ACPI_SIG_FACS, 4);
    340 
    341     LocalFACS.Length = sizeof (ACPI_TABLE_FACS);
    342     LocalFACS.GlobalLock = 0x11AA0011;
    343 
    344     /*
    345      * Build a fake table [TEST] so that we make sure that the
    346      * ACPICA core ignores it
    347      */
    348     ACPI_MEMSET (&LocalTEST, 0, sizeof (ACPI_TABLE_HEADER));
    349     ACPI_STRNCPY (LocalTEST.Signature, "TEST", 4);
    350 
    351     LocalTEST.Revision = 1;
    352     LocalTEST.Length = sizeof (ACPI_TABLE_HEADER);
    353     LocalTEST.Checksum = (UINT8) -AcpiTbChecksum (
    354         (void *) &LocalTEST, LocalTEST.Length);
    355 
    356     /*
    357      * Build a fake table with a bad signature [BAD!] so that we make
    358      * sure that the ACPICA core ignores it
    359      */
    360     ACPI_MEMSET (&LocalBADTABLE, 0, sizeof (ACPI_TABLE_HEADER));
    361     ACPI_STRNCPY (LocalBADTABLE.Signature, "BAD!", 4);
    362 
    363     LocalBADTABLE.Revision = 1;
    364     LocalBADTABLE.Length = sizeof (ACPI_TABLE_HEADER);
    365     LocalBADTABLE.Checksum = (UINT8) -AcpiTbChecksum (
    366         (void *) &LocalBADTABLE, LocalBADTABLE.Length);
    367 
    368     return (AE_OK);
    369 }
    370 
    371 
    372 /******************************************************************************
    373  *
    374  * FUNCTION:    AeInstallTables
    375  *
    376  * PARAMETERS:  None
    377  *
    378  * RETURN:      Status
    379  *
    380  * DESCRIPTION: Install the various ACPI tables
    381  *
    382  *****************************************************************************/
    383 
    384 ACPI_STATUS
    385 AeInstallTables (
    386     void)
    387 {
    388     ACPI_STATUS             Status;
    389 
    390 
    391     Status = AcpiInitializeTables (Tables, ACPI_MAX_INIT_TABLES, TRUE);
    392     AE_CHECK_OK (AcpiInitializeTables, Status);
    393 
    394     Status = AcpiReallocateRootTable ();
    395     AE_CHECK_OK (AcpiReallocateRootTable, Status);
    396 
    397     Status = AcpiLoadTables ();
    398     AE_CHECK_OK (AcpiLoadTables, Status);
    399 
    400     /*
    401      * Test run-time control method installation. Do it twice to test code
    402      * for an existing name.
    403      */
    404     Status = AcpiInstallMethod (MethodCode);
    405     if (ACPI_FAILURE (Status))
    406     {
    407         AcpiOsPrintf ("%s, Could not install method\n",
    408             AcpiFormatException (Status));
    409     }
    410 
    411     Status = AcpiInstallMethod (MethodCode);
    412     if (ACPI_FAILURE (Status))
    413     {
    414         AcpiOsPrintf ("%s, Could not install method\n",
    415             AcpiFormatException (Status));
    416     }
    417 
    418     return (AE_OK);
    419 }
    420 
    421 
    422 /******************************************************************************
    423  *
    424  * FUNCTION:    AeLocalGetRootPointer
    425  *
    426  * PARAMETERS:  Flags       - not used
    427  *              Address     - Where the root pointer is returned
    428  *
    429  * RETURN:      Status
    430  *
    431  * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
    432  *              standard ACPI mechanism.
    433  *
    434  *****************************************************************************/
    435 
    436 ACPI_PHYSICAL_ADDRESS
    437 AeLocalGetRootPointer (
    438     void)
    439 {
    440 
    441     return ((ACPI_PHYSICAL_ADDRESS) &LocalRSDP);
    442 }
    443