Home | History | Annotate | Line # | Download | only in acpiexec
aetables.c revision 1.1.1.17
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3   1.1.1.2    jruoho  * Module Name: aetables - ACPI table setup/install for acpiexec utility
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.16  christos  * Copyright (C) 2000 - 2022, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.15  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "aecommon.h"
     45   1.1.1.2    jruoho #include "aetables.h"
     46       1.1    jruoho 
     47       1.1    jruoho #define _COMPONENT          ACPI_TOOLS
     48       1.1    jruoho         ACPI_MODULE_NAME    ("aetables")
     49       1.1    jruoho 
     50       1.1    jruoho /* Local prototypes */
     51       1.1    jruoho 
     52   1.1.1.5  christos static void
     53   1.1.1.5  christos AeInitializeTableHeader (
     54   1.1.1.5  christos     ACPI_TABLE_HEADER       *Header,
     55   1.1.1.5  christos     char                    *Signature,
     56   1.1.1.5  christos     UINT32                  Length);
     57   1.1.1.5  christos 
     58       1.1    jruoho void
     59       1.1    jruoho AeTableOverride (
     60       1.1    jruoho     ACPI_TABLE_HEADER       *ExistingTable,
     61       1.1    jruoho     ACPI_TABLE_HEADER       **NewTable);
     62       1.1    jruoho 
     63   1.1.1.2    jruoho /* User table (DSDT) */
     64       1.1    jruoho 
     65   1.1.1.2    jruoho static ACPI_TABLE_HEADER        *DsdtToInstallOverride;
     66       1.1    jruoho 
     67   1.1.1.2    jruoho /* Non-AML tables that are constructed locally and installed */
     68       1.1    jruoho 
     69   1.1.1.2    jruoho static ACPI_TABLE_RSDP          LocalRSDP;
     70   1.1.1.2    jruoho static ACPI_TABLE_FACS          LocalFACS;
     71   1.1.1.2    jruoho static ACPI_TABLE_HEADER        LocalTEST;
     72   1.1.1.2    jruoho static ACPI_TABLE_HEADER        LocalBADTABLE;
     73       1.1    jruoho 
     74       1.1    jruoho /*
     75   1.1.1.2    jruoho  * We need a local FADT so that the hardware subcomponent will function,
     76   1.1.1.2    jruoho  * even though the underlying OSD HW access functions don't do anything.
     77       1.1    jruoho  */
     78   1.1.1.2    jruoho static ACPI_TABLE_FADT          LocalFADT;
     79       1.1    jruoho 
     80       1.1    jruoho /*
     81   1.1.1.2    jruoho  * Use XSDT so that both 32- and 64-bit versions of this utility will
     82   1.1.1.2    jruoho  * function automatically.
     83       1.1    jruoho  */
     84   1.1.1.2    jruoho static ACPI_TABLE_XSDT          *LocalXSDT;
     85       1.1    jruoho 
     86   1.1.1.5  christos #define BASE_XSDT_TABLES        9
     87   1.1.1.5  christos #define BASE_XSDT_SIZE          ((BASE_XSDT_TABLES) * sizeof (UINT64))
     88       1.1    jruoho 
     89   1.1.1.2    jruoho #define ACPI_MAX_INIT_TABLES    (32)
     90       1.1    jruoho 
     91       1.1    jruoho 
     92       1.1    jruoho /******************************************************************************
     93       1.1    jruoho  *
     94       1.1    jruoho  * FUNCTION:    AeTableOverride
     95       1.1    jruoho  *
     96       1.1    jruoho  * DESCRIPTION: Local implementation of AcpiOsTableOverride.
     97       1.1    jruoho  *              Exercise the override mechanism
     98       1.1    jruoho  *
     99       1.1    jruoho  *****************************************************************************/
    100       1.1    jruoho 
    101       1.1    jruoho void
    102       1.1    jruoho AeTableOverride (
    103       1.1    jruoho     ACPI_TABLE_HEADER       *ExistingTable,
    104       1.1    jruoho     ACPI_TABLE_HEADER       **NewTable)
    105       1.1    jruoho {
    106       1.1    jruoho 
    107   1.1.1.5  christos     if (!AcpiGbl_LoadTestTables)
    108   1.1.1.5  christos     {
    109   1.1.1.5  christos         *NewTable = NULL;
    110   1.1.1.5  christos         return;
    111   1.1.1.5  christos     }
    112   1.1.1.5  christos 
    113       1.1    jruoho     /* This code exercises the table override mechanism in the core */
    114       1.1    jruoho 
    115  1.1.1.13  christos     if (ACPI_COMPARE_NAMESEG (ExistingTable->Signature, ACPI_SIG_DSDT))
    116       1.1    jruoho     {
    117       1.1    jruoho         *NewTable = DsdtToInstallOverride;
    118       1.1    jruoho     }
    119       1.1    jruoho 
    120       1.1    jruoho     /* This code tests override of dynamically loaded tables */
    121       1.1    jruoho 
    122  1.1.1.13  christos     else if (ACPI_COMPARE_NAMESEG (ExistingTable->Signature, "OEM9"))
    123       1.1    jruoho     {
    124       1.1    jruoho         *NewTable = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Ssdt3Code);
    125       1.1    jruoho     }
    126       1.1    jruoho }
    127       1.1    jruoho 
    128       1.1    jruoho 
    129       1.1    jruoho /******************************************************************************
    130       1.1    jruoho  *
    131   1.1.1.5  christos  * FUNCTION:    AeInitializeTableHeader
    132   1.1.1.5  christos  *
    133   1.1.1.5  christos  * PARAMETERS:  Header          - A valid standard ACPI table header
    134   1.1.1.5  christos  *              Signature       - Signature to insert
    135   1.1.1.5  christos  *              Length          - Length of the table
    136   1.1.1.5  christos  *
    137   1.1.1.5  christos  * RETURN:      None. Header is modified.
    138   1.1.1.5  christos  *
    139   1.1.1.5  christos  * DESCRIPTION: Initialize the table header for a local ACPI table.
    140   1.1.1.5  christos  *
    141   1.1.1.5  christos  *****************************************************************************/
    142   1.1.1.5  christos 
    143   1.1.1.5  christos static void
    144   1.1.1.5  christos AeInitializeTableHeader (
    145   1.1.1.5  christos     ACPI_TABLE_HEADER       *Header,
    146   1.1.1.5  christos     char                    *Signature,
    147   1.1.1.5  christos     UINT32                  Length)
    148   1.1.1.5  christos {
    149   1.1.1.5  christos 
    150  1.1.1.13  christos     ACPI_COPY_NAMESEG (Header->Signature, Signature);
    151   1.1.1.5  christos     Header->Length = Length;
    152   1.1.1.5  christos 
    153   1.1.1.5  christos     Header->OemRevision = 0x1001;
    154  1.1.1.11  christos     memcpy (Header->OemId, "Intel ", ACPI_OEM_ID_SIZE);
    155  1.1.1.11  christos     memcpy (Header->OemTableId, "AcpiExec", ACPI_OEM_TABLE_ID_SIZE);
    156  1.1.1.13  christos     ACPI_COPY_NAMESEG (Header->AslCompilerId, "INTL");
    157   1.1.1.8  christos     Header->AslCompilerRevision = ACPI_CA_VERSION;
    158   1.1.1.8  christos 
    159   1.1.1.8  christos     /* Set the checksum, must set to zero first */
    160   1.1.1.8  christos 
    161   1.1.1.8  christos     Header->Checksum = 0;
    162  1.1.1.17  christos     Header->Checksum = (UINT8) -AcpiUtChecksum (
    163   1.1.1.8  christos         (void *) Header, Header->Length);
    164   1.1.1.5  christos }
    165   1.1.1.5  christos 
    166   1.1.1.5  christos 
    167   1.1.1.5  christos /******************************************************************************
    168   1.1.1.5  christos  *
    169       1.1    jruoho  * FUNCTION:    AeBuildLocalTables
    170       1.1    jruoho  *
    171       1.1    jruoho  * PARAMETERS:  TableCount      - Number of tables on the command line
    172   1.1.1.8  christos  *              ListHead        - List of actual tables from files
    173       1.1    jruoho  *
    174       1.1    jruoho  * RETURN:      Status
    175       1.1    jruoho  *
    176   1.1.1.2    jruoho  * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
    177       1.1    jruoho  *              FADT, and several other test tables.
    178       1.1    jruoho  *
    179       1.1    jruoho  *****************************************************************************/
    180       1.1    jruoho 
    181       1.1    jruoho ACPI_STATUS
    182       1.1    jruoho AeBuildLocalTables (
    183   1.1.1.8  christos     ACPI_NEW_TABLE_DESC     *ListHead)
    184       1.1    jruoho {
    185   1.1.1.8  christos     UINT32                  TableCount = 1;
    186       1.1    jruoho     ACPI_PHYSICAL_ADDRESS   DsdtAddress = 0;
    187   1.1.1.2    jruoho     UINT32                  XsdtSize;
    188   1.1.1.8  christos     ACPI_NEW_TABLE_DESC     *NextTable;
    189       1.1    jruoho     UINT32                  NextIndex;
    190       1.1    jruoho     ACPI_TABLE_FADT         *ExternalFadt = NULL;
    191       1.1    jruoho 
    192       1.1    jruoho 
    193       1.1    jruoho     /*
    194   1.1.1.5  christos      * Update the table count. For the DSDT, it is not put into the XSDT.
    195   1.1.1.5  christos      * For the FADT, this table is already accounted for since we usually
    196   1.1.1.5  christos      * install a local FADT.
    197       1.1    jruoho      */
    198   1.1.1.8  christos     NextTable = ListHead;
    199       1.1    jruoho     while (NextTable)
    200       1.1    jruoho     {
    201  1.1.1.13  christos         if (!ACPI_COMPARE_NAMESEG (NextTable->Table->Signature, ACPI_SIG_DSDT) &&
    202  1.1.1.13  christos             !ACPI_COMPARE_NAMESEG (NextTable->Table->Signature, ACPI_SIG_FADT))
    203       1.1    jruoho         {
    204   1.1.1.8  christos             TableCount++;
    205       1.1    jruoho         }
    206   1.1.1.8  christos 
    207       1.1    jruoho         NextTable = NextTable->Next;
    208       1.1    jruoho     }
    209       1.1    jruoho 
    210   1.1.1.8  christos     XsdtSize = (((TableCount + 1) * sizeof (UINT64)) +
    211   1.1.1.8  christos         sizeof (ACPI_TABLE_HEADER));
    212   1.1.1.5  christos     if (AcpiGbl_LoadTestTables)
    213   1.1.1.5  christos     {
    214   1.1.1.5  christos         XsdtSize += BASE_XSDT_SIZE;
    215   1.1.1.5  christos     }
    216       1.1    jruoho 
    217   1.1.1.2    jruoho     /* Build an XSDT */
    218       1.1    jruoho 
    219   1.1.1.2    jruoho     LocalXSDT = AcpiOsAllocate (XsdtSize);
    220   1.1.1.2    jruoho     if (!LocalXSDT)
    221       1.1    jruoho     {
    222   1.1.1.2    jruoho         return (AE_NO_MEMORY);
    223       1.1    jruoho     }
    224       1.1    jruoho 
    225   1.1.1.7  christos     memset (LocalXSDT, 0, XsdtSize);
    226   1.1.1.5  christos     LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT);
    227   1.1.1.5  christos     NextIndex = 1;
    228   1.1.1.4  christos 
    229   1.1.1.4  christos     /*
    230       1.1    jruoho      * Install the user tables. The DSDT must be installed in the FADT.
    231   1.1.1.2    jruoho      * All other tables are installed directly into the XSDT.
    232       1.1    jruoho      */
    233   1.1.1.8  christos     NextTable = ListHead;
    234       1.1    jruoho     while (NextTable)
    235       1.1    jruoho     {
    236       1.1    jruoho         /*
    237       1.1    jruoho          * Incoming DSDT or FADT are special cases. All other tables are
    238   1.1.1.2    jruoho          * just immediately installed into the XSDT.
    239       1.1    jruoho          */
    240  1.1.1.13  christos         if (ACPI_COMPARE_NAMESEG (NextTable->Table->Signature, ACPI_SIG_DSDT))
    241       1.1    jruoho         {
    242       1.1    jruoho             if (DsdtAddress)
    243       1.1    jruoho             {
    244       1.1    jruoho                 printf ("Already found a DSDT, only one allowed\n");
    245   1.1.1.2    jruoho                 return (AE_ALREADY_EXISTS);
    246       1.1    jruoho             }
    247       1.1    jruoho 
    248       1.1    jruoho             /* The incoming user table is a DSDT */
    249       1.1    jruoho 
    250   1.1.1.5  christos             DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
    251       1.1    jruoho             DsdtToInstallOverride = NextTable->Table;
    252       1.1    jruoho         }
    253  1.1.1.13  christos         else if (ACPI_COMPARE_NAMESEG (NextTable->Table->Signature, ACPI_SIG_FADT))
    254       1.1    jruoho         {
    255       1.1    jruoho             ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table);
    256   1.1.1.5  christos             LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
    257       1.1    jruoho         }
    258       1.1    jruoho         else
    259       1.1    jruoho         {
    260   1.1.1.2    jruoho             /* Install the table in the XSDT */
    261       1.1    jruoho 
    262   1.1.1.8  christos             LocalXSDT->TableOffsetEntry[NextIndex] =
    263   1.1.1.5  christos                 ACPI_PTR_TO_PHYSADDR (NextTable->Table);
    264       1.1    jruoho             NextIndex++;
    265       1.1    jruoho         }
    266       1.1    jruoho 
    267       1.1    jruoho         NextTable = NextTable->Next;
    268       1.1    jruoho     }
    269       1.1    jruoho 
    270   1.1.1.5  christos     /* Install the optional extra local tables */
    271   1.1.1.5  christos 
    272   1.1.1.5  christos     if (AcpiGbl_LoadTestTables)
    273   1.1.1.5  christos     {
    274   1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalTEST);
    275   1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalBADTABLE);
    276   1.1.1.5  christos 
    277   1.1.1.5  christos         /* Install two SSDTs to test multiple table support */
    278   1.1.1.5  christos 
    279   1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt1Code);
    280   1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt2Code);
    281   1.1.1.5  christos 
    282   1.1.1.5  christos         /* Install the OEM1 table to test LoadTable */
    283   1.1.1.5  christos 
    284   1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Oem1Code);
    285   1.1.1.5  christos 
    286   1.1.1.5  christos         /* Install the OEMx table to test LoadTable */
    287   1.1.1.5  christos 
    288   1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&OemxCode);
    289   1.1.1.5  christos 
    290   1.1.1.5  christos          /* Install the ECDT table to test _REG */
    291   1.1.1.5  christos 
    292   1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&EcdtCode);
    293   1.1.1.5  christos 
    294   1.1.1.5  christos         /* Install two UEFIs to test multiple table support */
    295   1.1.1.5  christos 
    296   1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi1Code);
    297   1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi2Code);
    298   1.1.1.5  christos     }
    299   1.1.1.5  christos 
    300   1.1.1.5  christos     /* Build an RSDP. Contains a valid XSDT only, no RSDT */
    301       1.1    jruoho 
    302   1.1.1.7  christos     memset (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP));
    303   1.1.1.4  christos     ACPI_MAKE_RSDP_SIG (LocalRSDP.Signature);
    304   1.1.1.7  christos     memcpy (LocalRSDP.OemId, "Intel", 6);
    305   1.1.1.5  christos 
    306   1.1.1.2    jruoho     LocalRSDP.Revision = 2;
    307   1.1.1.2    jruoho     LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT);
    308   1.1.1.5  christos     LocalRSDP.Length = sizeof (ACPI_TABLE_RSDP);
    309       1.1    jruoho 
    310   1.1.1.2    jruoho     /* Set checksums for both XSDT and RSDP */
    311       1.1    jruoho 
    312   1.1.1.8  christos     AeInitializeTableHeader ((void *) LocalXSDT, ACPI_SIG_XSDT, XsdtSize);
    313   1.1.1.5  christos 
    314   1.1.1.5  christos     LocalRSDP.Checksum = 0;
    315  1.1.1.17  christos     LocalRSDP.Checksum = (UINT8) -AcpiUtChecksum (
    316       1.1    jruoho         (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH);
    317       1.1    jruoho 
    318       1.1    jruoho     if (!DsdtAddress)
    319       1.1    jruoho     {
    320       1.1    jruoho         /* Use the local DSDT because incoming table(s) are all SSDT(s) */
    321       1.1    jruoho 
    322       1.1    jruoho         DsdtAddress = ACPI_PTR_TO_PHYSADDR (LocalDsdtCode);
    323       1.1    jruoho         DsdtToInstallOverride = ACPI_CAST_PTR (ACPI_TABLE_HEADER, LocalDsdtCode);
    324       1.1    jruoho     }
    325       1.1    jruoho 
    326   1.1.1.5  christos     /*
    327   1.1.1.5  christos      * Build an FADT. There are three options for the FADT:
    328   1.1.1.5  christos      * 1) Incoming external FADT specified on the command line
    329   1.1.1.5  christos      * 2) A "hardware reduced" local FADT
    330   1.1.1.5  christos      * 3) A fully featured local FADT
    331   1.1.1.5  christos      */
    332   1.1.1.7  christos     memset (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT));
    333   1.1.1.7  christos 
    334       1.1    jruoho     if (ExternalFadt)
    335       1.1    jruoho     {
    336       1.1    jruoho         /*
    337   1.1.1.8  christos          * Use the external FADT, but we must update the DSDT/FACS
    338   1.1.1.8  christos          * addresses as well as the checksum
    339       1.1    jruoho          */
    340   1.1.1.6  christos         ExternalFadt->Dsdt = (UINT32) DsdtAddress;
    341   1.1.1.4  christos         if (!AcpiGbl_ReducedHardware)
    342   1.1.1.4  christos         {
    343   1.1.1.4  christos             ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
    344   1.1.1.4  christos         }
    345       1.1    jruoho 
    346   1.1.1.8  christos         /*
    347   1.1.1.8  christos          * If there room in the FADT for the XDsdt and XFacs 64-bit
    348   1.1.1.8  christos          * pointers, use them.
    349   1.1.1.8  christos          */
    350   1.1.1.8  christos         if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (
    351   1.1.1.8  christos             &ExternalFadt->XDsdt, ExternalFadt))
    352       1.1    jruoho         {
    353   1.1.1.8  christos             ExternalFadt->Dsdt = 0;
    354   1.1.1.8  christos             ExternalFadt->Facs = 0;
    355   1.1.1.4  christos 
    356   1.1.1.8  christos             ExternalFadt->XDsdt = DsdtAddress;
    357   1.1.1.4  christos             if (!AcpiGbl_ReducedHardware)
    358   1.1.1.4  christos             {
    359   1.1.1.4  christos                 ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
    360   1.1.1.4  christos             }
    361       1.1    jruoho         }
    362   1.1.1.4  christos 
    363   1.1.1.8  christos         /* Complete the external FADT with the checksum */
    364       1.1    jruoho 
    365       1.1    jruoho         ExternalFadt->Header.Checksum = 0;
    366  1.1.1.17  christos         ExternalFadt->Header.Checksum = (UINT8) -AcpiUtChecksum (
    367       1.1    jruoho             (void *) ExternalFadt, ExternalFadt->Header.Length);
    368       1.1    jruoho     }
    369   1.1.1.4  christos     else if (AcpiGbl_UseHwReducedFadt)
    370   1.1.1.4  christos     {
    371   1.1.1.7  christos         memcpy (&LocalFADT, HwReducedFadtCode, ACPI_FADT_V5_SIZE);
    372   1.1.1.8  christos         LocalFADT.Dsdt = 0;
    373   1.1.1.4  christos         LocalFADT.XDsdt = DsdtAddress;
    374   1.1.1.4  christos     }
    375       1.1    jruoho     else
    376       1.1    jruoho     {
    377       1.1    jruoho         /*
    378       1.1    jruoho          * Build a local FADT so we can test the hardware/event init
    379       1.1    jruoho          */
    380   1.1.1.5  christos         LocalFADT.Header.Revision = 5;
    381       1.1    jruoho 
    382       1.1    jruoho         /* Setup FADT header and DSDT/FACS addresses */
    383       1.1    jruoho 
    384   1.1.1.2    jruoho         LocalFADT.Dsdt = 0;
    385   1.1.1.2    jruoho         LocalFADT.Facs = 0;
    386       1.1    jruoho 
    387       1.1    jruoho         LocalFADT.XDsdt = DsdtAddress;
    388       1.1    jruoho         LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
    389       1.1    jruoho 
    390       1.1    jruoho         /* Miscellaneous FADT fields */
    391       1.1    jruoho 
    392  1.1.1.11  christos         LocalFADT.Gpe0BlockLength = 0x20;
    393  1.1.1.11  christos         LocalFADT.Gpe0Block = 0x00003210;
    394   1.1.1.2    jruoho 
    395  1.1.1.11  christos         LocalFADT.Gpe1BlockLength = 0x20;
    396  1.1.1.11  christos         LocalFADT.Gpe1Block = 0x0000BA98;
    397  1.1.1.11  christos         LocalFADT.Gpe1Base = 0x80;
    398       1.1    jruoho 
    399       1.1    jruoho         LocalFADT.Pm1EventLength = 4;
    400       1.1    jruoho         LocalFADT.Pm1aEventBlock = 0x00001aaa;
    401       1.1    jruoho         LocalFADT.Pm1bEventBlock = 0x00001bbb;
    402   1.1.1.2    jruoho 
    403   1.1.1.2    jruoho         LocalFADT.Pm1ControlLength = 2;
    404       1.1    jruoho         LocalFADT.Pm1aControlBlock = 0xB0;
    405       1.1    jruoho 
    406   1.1.1.2    jruoho         LocalFADT.PmTimerLength = 4;
    407   1.1.1.2    jruoho         LocalFADT.PmTimerBlock = 0xA0;
    408   1.1.1.2    jruoho 
    409   1.1.1.2    jruoho         LocalFADT.Pm2ControlBlock = 0xC0;
    410   1.1.1.2    jruoho         LocalFADT.Pm2ControlLength = 1;
    411   1.1.1.2    jruoho 
    412   1.1.1.5  christos         /* Setup one example X-64 GAS field */
    413       1.1    jruoho 
    414       1.1    jruoho         LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
    415       1.1    jruoho         LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock;
    416   1.1.1.8  christos         LocalFADT.XPm1bEventBlock.BitWidth = (UINT8)
    417   1.1.1.8  christos             ACPI_MUL_8 (LocalFADT.Pm1EventLength);
    418       1.1    jruoho     }
    419       1.1    jruoho 
    420   1.1.1.8  christos     AeInitializeTableHeader ((void *) &LocalFADT,
    421   1.1.1.8  christos         ACPI_SIG_FADT, sizeof (ACPI_TABLE_FADT));
    422   1.1.1.8  christos 
    423       1.1    jruoho     /* Build a FACS */
    424       1.1    jruoho 
    425   1.1.1.7  christos     memset (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS));
    426  1.1.1.13  christos     ACPI_COPY_NAMESEG (LocalFACS.Signature, ACPI_SIG_FACS);
    427       1.1    jruoho 
    428       1.1    jruoho     LocalFACS.Length = sizeof (ACPI_TABLE_FACS);
    429       1.1    jruoho     LocalFACS.GlobalLock = 0x11AA0011;
    430       1.1    jruoho 
    431   1.1.1.5  christos     /* Build the optional local tables */
    432   1.1.1.5  christos 
    433   1.1.1.5  christos     if (AcpiGbl_LoadTestTables)
    434   1.1.1.5  christos     {
    435   1.1.1.5  christos         /*
    436   1.1.1.5  christos          * Build a fake table [TEST] so that we make sure that the
    437   1.1.1.5  christos          * ACPICA core ignores it
    438   1.1.1.5  christos          */
    439   1.1.1.7  christos         memset (&LocalTEST, 0, sizeof (ACPI_TABLE_HEADER));
    440  1.1.1.13  christos         ACPI_COPY_NAMESEG (LocalTEST.Signature, "TEST");
    441       1.1    jruoho 
    442   1.1.1.5  christos         LocalTEST.Revision = 1;
    443   1.1.1.5  christos         LocalTEST.Length = sizeof (ACPI_TABLE_HEADER);
    444   1.1.1.8  christos 
    445   1.1.1.8  christos         LocalTEST.Checksum = 0;
    446  1.1.1.17  christos         LocalTEST.Checksum = (UINT8) -AcpiUtChecksum (
    447   1.1.1.5  christos             (void *) &LocalTEST, LocalTEST.Length);
    448       1.1    jruoho 
    449   1.1.1.5  christos         /*
    450   1.1.1.5  christos          * Build a fake table with a bad signature [BAD!] so that we make
    451   1.1.1.5  christos          * sure that the ACPICA core ignores it
    452   1.1.1.5  christos          */
    453   1.1.1.7  christos         memset (&LocalBADTABLE, 0, sizeof (ACPI_TABLE_HEADER));
    454  1.1.1.13  christos         ACPI_COPY_NAMESEG (LocalBADTABLE.Signature, "BAD!");
    455       1.1    jruoho 
    456   1.1.1.5  christos         LocalBADTABLE.Revision = 1;
    457   1.1.1.5  christos         LocalBADTABLE.Length = sizeof (ACPI_TABLE_HEADER);
    458   1.1.1.8  christos 
    459   1.1.1.8  christos         LocalBADTABLE.Checksum = 0;
    460  1.1.1.17  christos         LocalBADTABLE.Checksum = (UINT8) -AcpiUtChecksum (
    461   1.1.1.5  christos             (void *) &LocalBADTABLE, LocalBADTABLE.Length);
    462   1.1.1.5  christos     }
    463       1.1    jruoho 
    464       1.1    jruoho     return (AE_OK);
    465       1.1    jruoho }
    466       1.1    jruoho 
    467       1.1    jruoho 
    468       1.1    jruoho /******************************************************************************
    469       1.1    jruoho  *
    470       1.1    jruoho  * FUNCTION:    AeInstallTables
    471       1.1    jruoho  *
    472       1.1    jruoho  * PARAMETERS:  None
    473       1.1    jruoho  *
    474       1.1    jruoho  * RETURN:      Status
    475       1.1    jruoho  *
    476       1.1    jruoho  * DESCRIPTION: Install the various ACPI tables
    477       1.1    jruoho  *
    478       1.1    jruoho  *****************************************************************************/
    479       1.1    jruoho 
    480       1.1    jruoho ACPI_STATUS
    481       1.1    jruoho AeInstallTables (
    482       1.1    jruoho     void)
    483       1.1    jruoho {
    484       1.1    jruoho     ACPI_STATUS             Status;
    485   1.1.1.4  christos     ACPI_TABLE_HEADER       Header;
    486   1.1.1.4  christos     ACPI_TABLE_HEADER       *Table;
    487   1.1.1.8  christos     UINT32                  i;
    488   1.1.1.8  christos 
    489   1.1.1.8  christos 
    490   1.1.1.8  christos     Status = AcpiInitializeTables (NULL, ACPI_MAX_INIT_TABLES, TRUE);
    491   1.1.1.8  christos     ACPI_CHECK_OK (AcpiInitializeTables, Status);
    492   1.1.1.8  christos 
    493  1.1.1.10  christos     /*
    494  1.1.1.10  christos      * The following code is prepared to test the deferred table
    495  1.1.1.10  christos      * verification mechanism. When AcpiGbl_EnableTableValidation is set
    496  1.1.1.10  christos      * to FALSE by default, AcpiReallocateRootTable() sets it back to TRUE
    497  1.1.1.10  christos      * and triggers the deferred table verification mechanism accordingly.
    498  1.1.1.10  christos      */
    499  1.1.1.10  christos     (void) AcpiReallocateRootTable ();
    500  1.1.1.10  christos 
    501   1.1.1.8  christos     if (AcpiGbl_LoadTestTables)
    502   1.1.1.8  christos     {
    503   1.1.1.8  christos         /* Test multiple table/UEFI support. First, get the headers */
    504   1.1.1.8  christos 
    505   1.1.1.8  christos         Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 1, &Header);
    506   1.1.1.8  christos         ACPI_CHECK_OK (AcpiGetTableHeader, Status);
    507   1.1.1.8  christos 
    508   1.1.1.8  christos         Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 2, &Header);
    509   1.1.1.8  christos         ACPI_CHECK_OK (AcpiGetTableHeader, Status);
    510   1.1.1.8  christos 
    511   1.1.1.8  christos         Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 3, &Header);
    512   1.1.1.8  christos         ACPI_CHECK_STATUS (AcpiGetTableHeader, Status, AE_NOT_FOUND);
    513   1.1.1.8  christos 
    514   1.1.1.8  christos         /* Now get the actual tables */
    515   1.1.1.8  christos 
    516   1.1.1.8  christos         Status = AcpiGetTable (ACPI_SIG_UEFI, 1, &Table);
    517   1.1.1.8  christos         ACPI_CHECK_OK (AcpiGetTable, Status);
    518   1.1.1.8  christos 
    519   1.1.1.8  christos         Status = AcpiGetTable (ACPI_SIG_UEFI, 2, &Table);
    520   1.1.1.8  christos         ACPI_CHECK_OK (AcpiGetTable, Status);
    521   1.1.1.8  christos 
    522   1.1.1.8  christos         Status = AcpiGetTable (ACPI_SIG_UEFI, 3, &Table);
    523   1.1.1.8  christos         ACPI_CHECK_STATUS (AcpiGetTable, Status, AE_NOT_FOUND);
    524   1.1.1.8  christos     }
    525   1.1.1.8  christos 
    526   1.1.1.8  christos     /* Check that we can get all of the ACPI tables */
    527   1.1.1.8  christos 
    528   1.1.1.8  christos     for (i = 0; ; i++)
    529   1.1.1.8  christos     {
    530   1.1.1.8  christos         Status = AcpiGetTableByIndex (i, &Table);
    531   1.1.1.8  christos         if ((Status == AE_BAD_PARAMETER) || !Table)
    532   1.1.1.8  christos         {
    533   1.1.1.8  christos             break;
    534   1.1.1.8  christos         }
    535       1.1    jruoho 
    536   1.1.1.8  christos         ACPI_CHECK_OK (AcpiGetTableByIndex, Status);
    537   1.1.1.8  christos     }
    538   1.1.1.2    jruoho 
    539   1.1.1.8  christos     return (AE_OK);
    540   1.1.1.8  christos }
    541   1.1.1.8  christos 
    542   1.1.1.8  christos 
    543   1.1.1.8  christos /******************************************************************************
    544   1.1.1.8  christos  *
    545   1.1.1.8  christos  * FUNCTION:    AeLoadTables
    546   1.1.1.8  christos  *
    547   1.1.1.8  christos  * PARAMETERS:  None
    548   1.1.1.8  christos  *
    549   1.1.1.8  christos  * RETURN:      Status
    550   1.1.1.8  christos  *
    551   1.1.1.8  christos  * DESCRIPTION: Load the definition block ACPI tables
    552   1.1.1.8  christos  *
    553   1.1.1.8  christos  *****************************************************************************/
    554   1.1.1.8  christos 
    555   1.1.1.8  christos ACPI_STATUS
    556   1.1.1.8  christos AeLoadTables (
    557   1.1.1.8  christos     void)
    558   1.1.1.8  christos {
    559   1.1.1.8  christos     ACPI_STATUS             Status;
    560   1.1.1.2    jruoho 
    561   1.1.1.2    jruoho 
    562       1.1    jruoho     Status = AcpiLoadTables ();
    563   1.1.1.8  christos     ACPI_CHECK_OK (AcpiLoadTables, Status);
    564       1.1    jruoho 
    565       1.1    jruoho     /*
    566       1.1    jruoho      * Test run-time control method installation. Do it twice to test code
    567       1.1    jruoho      * for an existing name.
    568       1.1    jruoho      */
    569       1.1    jruoho     Status = AcpiInstallMethod (MethodCode);
    570  1.1.1.12  christos     ACPI_CHECK_OK (AcpiInstallMethod, Status);
    571       1.1    jruoho 
    572       1.1    jruoho     Status = AcpiInstallMethod (MethodCode);
    573  1.1.1.12  christos     ACPI_CHECK_OK (AcpiInstallMethod, Status);
    574       1.1    jruoho 
    575       1.1    jruoho     return (AE_OK);
    576       1.1    jruoho }
    577       1.1    jruoho 
    578       1.1    jruoho 
    579       1.1    jruoho /******************************************************************************
    580       1.1    jruoho  *
    581   1.1.1.5  christos  * FUNCTION:    AcpiOsGetRootPointer
    582       1.1    jruoho  *
    583       1.1    jruoho  * PARAMETERS:  Flags       - not used
    584       1.1    jruoho  *              Address     - Where the root pointer is returned
    585       1.1    jruoho  *
    586       1.1    jruoho  * RETURN:      Status
    587       1.1    jruoho  *
    588       1.1    jruoho  * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
    589       1.1    jruoho  *              standard ACPI mechanism.
    590       1.1    jruoho  *
    591       1.1    jruoho  *****************************************************************************/
    592       1.1    jruoho 
    593       1.1    jruoho ACPI_PHYSICAL_ADDRESS
    594   1.1.1.5  christos AcpiOsGetRootPointer (
    595       1.1    jruoho     void)
    596       1.1    jruoho {
    597       1.1    jruoho 
    598   1.1.1.6  christos     return (ACPI_PTR_TO_PHYSADDR (&LocalRSDP));
    599       1.1    jruoho }
    600