Home | History | Annotate | Line # | Download | only in acpiexec
aetables.c revision 1.1.1.5.2.2
      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.5.2.1     skrll  * Copyright (C) 2000 - 2015, 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.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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.1.2    jruoho static ACPI_TABLE_DESC          Tables[ACPI_MAX_INIT_TABLES];
     91          1.1    jruoho 
     92          1.1    jruoho 
     93          1.1    jruoho /******************************************************************************
     94          1.1    jruoho  *
     95          1.1    jruoho  * FUNCTION:    AeTableOverride
     96          1.1    jruoho  *
     97          1.1    jruoho  * DESCRIPTION: Local implementation of AcpiOsTableOverride.
     98          1.1    jruoho  *              Exercise the override mechanism
     99          1.1    jruoho  *
    100          1.1    jruoho  *****************************************************************************/
    101          1.1    jruoho 
    102          1.1    jruoho void
    103          1.1    jruoho AeTableOverride (
    104          1.1    jruoho     ACPI_TABLE_HEADER       *ExistingTable,
    105          1.1    jruoho     ACPI_TABLE_HEADER       **NewTable)
    106          1.1    jruoho {
    107          1.1    jruoho 
    108      1.1.1.5  christos     if (!AcpiGbl_LoadTestTables)
    109      1.1.1.5  christos     {
    110      1.1.1.5  christos         *NewTable = NULL;
    111      1.1.1.5  christos         return;
    112      1.1.1.5  christos     }
    113      1.1.1.5  christos 
    114          1.1    jruoho     /* This code exercises the table override mechanism in the core */
    115          1.1    jruoho 
    116          1.1    jruoho     if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT))
    117          1.1    jruoho     {
    118          1.1    jruoho         *NewTable = DsdtToInstallOverride;
    119          1.1    jruoho     }
    120          1.1    jruoho 
    121          1.1    jruoho     /* This code tests override of dynamically loaded tables */
    122          1.1    jruoho 
    123      1.1.1.4  christos     else if (ACPI_COMPARE_NAME (ExistingTable->Signature, "OEM9"))
    124          1.1    jruoho     {
    125          1.1    jruoho         *NewTable = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Ssdt3Code);
    126          1.1    jruoho     }
    127          1.1    jruoho }
    128          1.1    jruoho 
    129          1.1    jruoho 
    130          1.1    jruoho /******************************************************************************
    131          1.1    jruoho  *
    132      1.1.1.5  christos  * FUNCTION:    AeInitializeTableHeader
    133      1.1.1.5  christos  *
    134      1.1.1.5  christos  * PARAMETERS:  Header          - A valid standard ACPI table header
    135      1.1.1.5  christos  *              Signature       - Signature to insert
    136      1.1.1.5  christos  *              Length          - Length of the table
    137      1.1.1.5  christos  *
    138      1.1.1.5  christos  * RETURN:      None. Header is modified.
    139      1.1.1.5  christos  *
    140      1.1.1.5  christos  * DESCRIPTION: Initialize the table header for a local ACPI table.
    141      1.1.1.5  christos  *
    142      1.1.1.5  christos  *****************************************************************************/
    143      1.1.1.5  christos 
    144      1.1.1.5  christos static void
    145      1.1.1.5  christos AeInitializeTableHeader (
    146      1.1.1.5  christos     ACPI_TABLE_HEADER       *Header,
    147      1.1.1.5  christos     char                    *Signature,
    148      1.1.1.5  christos     UINT32                  Length)
    149      1.1.1.5  christos {
    150      1.1.1.5  christos 
    151      1.1.1.5  christos     ACPI_MOVE_NAME (Header->Signature, Signature);
    152      1.1.1.5  christos     Header->Length = Length;
    153      1.1.1.5  christos 
    154      1.1.1.5  christos     Header->OemRevision = 0x1001;
    155  1.1.1.5.2.2     skrll     strncpy (Header->OemId, "Intel", ACPI_OEM_ID_SIZE);
    156  1.1.1.5.2.2     skrll     strncpy (Header->OemTableId, "AcpiExec", ACPI_OEM_TABLE_ID_SIZE);
    157  1.1.1.5.2.2     skrll     strncpy (Header->AslCompilerId, "INTL", ACPI_NAME_SIZE);
    158      1.1.1.5  christos     Header->AslCompilerRevision = 0x20131218;
    159      1.1.1.5  christos }
    160      1.1.1.5  christos 
    161      1.1.1.5  christos 
    162      1.1.1.5  christos /******************************************************************************
    163      1.1.1.5  christos  *
    164          1.1    jruoho  * FUNCTION:    AeBuildLocalTables
    165          1.1    jruoho  *
    166          1.1    jruoho  * PARAMETERS:  TableCount      - Number of tables on the command line
    167          1.1    jruoho  *              TableList       - List of actual tables from files
    168          1.1    jruoho  *
    169          1.1    jruoho  * RETURN:      Status
    170          1.1    jruoho  *
    171      1.1.1.2    jruoho  * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
    172          1.1    jruoho  *              FADT, and several other test tables.
    173          1.1    jruoho  *
    174          1.1    jruoho  *****************************************************************************/
    175          1.1    jruoho 
    176          1.1    jruoho ACPI_STATUS
    177          1.1    jruoho AeBuildLocalTables (
    178          1.1    jruoho     UINT32                  TableCount,
    179          1.1    jruoho     AE_TABLE_DESC           *TableList)
    180          1.1    jruoho {
    181          1.1    jruoho     ACPI_PHYSICAL_ADDRESS   DsdtAddress = 0;
    182      1.1.1.2    jruoho     UINT32                  XsdtSize;
    183          1.1    jruoho     AE_TABLE_DESC           *NextTable;
    184          1.1    jruoho     UINT32                  NextIndex;
    185          1.1    jruoho     ACPI_TABLE_FADT         *ExternalFadt = NULL;
    186          1.1    jruoho 
    187          1.1    jruoho 
    188          1.1    jruoho     /*
    189      1.1.1.5  christos      * Update the table count. For the DSDT, it is not put into the XSDT.
    190      1.1.1.5  christos      * For the FADT, this table is already accounted for since we usually
    191      1.1.1.5  christos      * install a local FADT.
    192          1.1    jruoho      */
    193          1.1    jruoho     NextTable = TableList;
    194          1.1    jruoho     while (NextTable)
    195          1.1    jruoho     {
    196          1.1    jruoho         if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) ||
    197          1.1    jruoho             ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
    198          1.1    jruoho         {
    199          1.1    jruoho             TableCount--;
    200          1.1    jruoho         }
    201          1.1    jruoho         NextTable = NextTable->Next;
    202          1.1    jruoho     }
    203          1.1    jruoho 
    204      1.1.1.5  christos     XsdtSize = (((TableCount + 1) * sizeof (UINT64)) + sizeof (ACPI_TABLE_HEADER));
    205      1.1.1.5  christos     if (AcpiGbl_LoadTestTables)
    206      1.1.1.5  christos     {
    207      1.1.1.5  christos         XsdtSize += BASE_XSDT_SIZE;
    208      1.1.1.5  christos     }
    209          1.1    jruoho 
    210      1.1.1.2    jruoho     /* Build an XSDT */
    211          1.1    jruoho 
    212      1.1.1.2    jruoho     LocalXSDT = AcpiOsAllocate (XsdtSize);
    213      1.1.1.2    jruoho     if (!LocalXSDT)
    214          1.1    jruoho     {
    215      1.1.1.2    jruoho         return (AE_NO_MEMORY);
    216          1.1    jruoho     }
    217          1.1    jruoho 
    218  1.1.1.5.2.2     skrll     memset (LocalXSDT, 0, XsdtSize);
    219      1.1.1.5  christos     AeInitializeTableHeader ((void *) LocalXSDT, ACPI_SIG_XSDT, XsdtSize);
    220          1.1    jruoho 
    221      1.1.1.5  christos     LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT);
    222      1.1.1.5  christos     NextIndex = 1;
    223      1.1.1.4  christos 
    224      1.1.1.4  christos     /*
    225          1.1    jruoho      * Install the user tables. The DSDT must be installed in the FADT.
    226      1.1.1.2    jruoho      * All other tables are installed directly into the XSDT.
    227      1.1.1.5  christos      *
    228      1.1.1.5  christos      * Note: The tables are loaded in reverse order from the incoming
    229      1.1.1.5  christos      * input, which makes it match the command line order.
    230          1.1    jruoho      */
    231          1.1    jruoho     NextTable = TableList;
    232          1.1    jruoho     while (NextTable)
    233          1.1    jruoho     {
    234          1.1    jruoho         /*
    235          1.1    jruoho          * Incoming DSDT or FADT are special cases. All other tables are
    236      1.1.1.2    jruoho          * just immediately installed into the XSDT.
    237          1.1    jruoho          */
    238          1.1    jruoho         if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT))
    239          1.1    jruoho         {
    240          1.1    jruoho             if (DsdtAddress)
    241          1.1    jruoho             {
    242          1.1    jruoho                 printf ("Already found a DSDT, only one allowed\n");
    243      1.1.1.2    jruoho                 return (AE_ALREADY_EXISTS);
    244          1.1    jruoho             }
    245          1.1    jruoho 
    246          1.1    jruoho             /* The incoming user table is a DSDT */
    247          1.1    jruoho 
    248      1.1.1.5  christos             DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
    249          1.1    jruoho             DsdtToInstallOverride = NextTable->Table;
    250          1.1    jruoho         }
    251          1.1    jruoho         else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
    252          1.1    jruoho         {
    253          1.1    jruoho             ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table);
    254      1.1.1.5  christos             LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
    255          1.1    jruoho         }
    256          1.1    jruoho         else
    257          1.1    jruoho         {
    258      1.1.1.2    jruoho             /* Install the table in the XSDT */
    259          1.1    jruoho 
    260      1.1.1.5  christos             LocalXSDT->TableOffsetEntry[TableCount - NextIndex + 1] =
    261      1.1.1.5  christos                 ACPI_PTR_TO_PHYSADDR (NextTable->Table);
    262          1.1    jruoho             NextIndex++;
    263          1.1    jruoho         }
    264          1.1    jruoho 
    265          1.1    jruoho         NextTable = NextTable->Next;
    266          1.1    jruoho     }
    267          1.1    jruoho 
    268      1.1.1.5  christos     /* Install the optional extra local tables */
    269      1.1.1.5  christos 
    270      1.1.1.5  christos     if (AcpiGbl_LoadTestTables)
    271      1.1.1.5  christos     {
    272      1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalTEST);
    273      1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&LocalBADTABLE);
    274      1.1.1.5  christos 
    275      1.1.1.5  christos         /* Install two SSDTs to test multiple table support */
    276      1.1.1.5  christos 
    277      1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt1Code);
    278      1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Ssdt2Code);
    279      1.1.1.5  christos 
    280      1.1.1.5  christos         /* Install the OEM1 table to test LoadTable */
    281      1.1.1.5  christos 
    282      1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Oem1Code);
    283      1.1.1.5  christos 
    284      1.1.1.5  christos         /* Install the OEMx table to test LoadTable */
    285      1.1.1.5  christos 
    286      1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&OemxCode);
    287      1.1.1.5  christos 
    288      1.1.1.5  christos          /* Install the ECDT table to test _REG */
    289      1.1.1.5  christos 
    290      1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&EcdtCode);
    291      1.1.1.5  christos 
    292      1.1.1.5  christos         /* Install two UEFIs to test multiple table support */
    293      1.1.1.5  christos 
    294      1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi1Code);
    295      1.1.1.5  christos         LocalXSDT->TableOffsetEntry[NextIndex++] = ACPI_PTR_TO_PHYSADDR (&Uefi2Code);
    296      1.1.1.5  christos     }
    297      1.1.1.5  christos 
    298      1.1.1.5  christos     /* Build an RSDP. Contains a valid XSDT only, no RSDT */
    299          1.1    jruoho 
    300  1.1.1.5.2.2     skrll     memset (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP));
    301      1.1.1.4  christos     ACPI_MAKE_RSDP_SIG (LocalRSDP.Signature);
    302  1.1.1.5.2.2     skrll     memcpy (LocalRSDP.OemId, "Intel", 6);
    303      1.1.1.5  christos 
    304      1.1.1.2    jruoho     LocalRSDP.Revision = 2;
    305      1.1.1.2    jruoho     LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT);
    306      1.1.1.5  christos     LocalRSDP.Length = sizeof (ACPI_TABLE_RSDP);
    307          1.1    jruoho 
    308      1.1.1.2    jruoho     /* Set checksums for both XSDT and RSDP */
    309          1.1    jruoho 
    310      1.1.1.5  christos     LocalXSDT->Header.Checksum = 0;
    311      1.1.1.2    jruoho     LocalXSDT->Header.Checksum = (UINT8) -AcpiTbChecksum (
    312      1.1.1.2    jruoho         (void *) LocalXSDT, LocalXSDT->Header.Length);
    313      1.1.1.5  christos 
    314      1.1.1.5  christos     LocalRSDP.Checksum = 0;
    315          1.1    jruoho     LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum (
    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.5.2.2     skrll     memset (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT));
    333  1.1.1.5.2.2     skrll 
    334          1.1    jruoho     if (ExternalFadt)
    335          1.1    jruoho     {
    336          1.1    jruoho         /*
    337          1.1    jruoho          * Use the external FADT, but we must update the DSDT/FACS addresses
    338          1.1    jruoho          * as well as the checksum
    339          1.1    jruoho          */
    340  1.1.1.5.2.1     skrll         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.5  christos         /* Is there room in the FADT for the XDsdst and XFacs 64-bit pointers? */
    347      1.1.1.5  christos 
    348          1.1    jruoho         if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (&ExternalFadt->XDsdt, ExternalFadt))
    349          1.1    jruoho         {
    350          1.1    jruoho             ExternalFadt->XDsdt = DsdtAddress;
    351      1.1.1.4  christos 
    352      1.1.1.4  christos             if (!AcpiGbl_ReducedHardware)
    353      1.1.1.4  christos             {
    354      1.1.1.4  christos                 ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
    355      1.1.1.4  christos             }
    356          1.1    jruoho         }
    357      1.1.1.4  christos 
    358          1.1    jruoho         /* Complete the FADT with the checksum */
    359          1.1    jruoho 
    360          1.1    jruoho         ExternalFadt->Header.Checksum = 0;
    361          1.1    jruoho         ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum (
    362          1.1    jruoho             (void *) ExternalFadt, ExternalFadt->Header.Length);
    363          1.1    jruoho     }
    364      1.1.1.4  christos     else if (AcpiGbl_UseHwReducedFadt)
    365      1.1.1.4  christos     {
    366  1.1.1.5.2.2     skrll         memcpy (&LocalFADT, HwReducedFadtCode, ACPI_FADT_V5_SIZE);
    367  1.1.1.5.2.1     skrll         LocalFADT.Dsdt = (UINT32) DsdtAddress;
    368      1.1.1.4  christos         LocalFADT.XDsdt = DsdtAddress;
    369      1.1.1.4  christos 
    370      1.1.1.4  christos         LocalFADT.Header.Checksum = 0;
    371      1.1.1.4  christos         LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum (
    372      1.1.1.4  christos             (void *) &LocalFADT, LocalFADT.Header.Length);
    373      1.1.1.4  christos     }
    374          1.1    jruoho     else
    375          1.1    jruoho     {
    376          1.1    jruoho         /*
    377          1.1    jruoho          * Build a local FADT so we can test the hardware/event init
    378          1.1    jruoho          */
    379      1.1.1.5  christos         LocalFADT.Header.Revision = 5;
    380      1.1.1.5  christos         AeInitializeTableHeader ((void *) &LocalFADT, ACPI_SIG_FADT, sizeof (ACPI_TABLE_FADT));
    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.5  christos         LocalFADT.Gpe0BlockLength = 0x08;
    393      1.1.1.2    jruoho         LocalFADT.Gpe0Block = 0x00001234;
    394      1.1.1.2    jruoho 
    395      1.1.1.5  christos         LocalFADT.Gpe1BlockLength = 0x80;
    396      1.1.1.2    jruoho         LocalFADT.Gpe1Block = 0x00005678;
    397      1.1.1.5  christos         LocalFADT.Gpe1Base = 100;
    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    jruoho         LocalFADT.XPm1bEventBlock.BitWidth = (UINT8) ACPI_MUL_8 (LocalFADT.Pm1EventLength);
    417          1.1    jruoho 
    418          1.1    jruoho         /* Complete the FADT with the checksum */
    419          1.1    jruoho 
    420          1.1    jruoho         LocalFADT.Header.Checksum = 0;
    421          1.1    jruoho         LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum (
    422          1.1    jruoho             (void *) &LocalFADT, LocalFADT.Header.Length);
    423          1.1    jruoho     }
    424          1.1    jruoho 
    425          1.1    jruoho     /* Build a FACS */
    426          1.1    jruoho 
    427  1.1.1.5.2.2     skrll     memset (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS));
    428      1.1.1.4  christos     ACPI_MOVE_NAME (LocalFACS.Signature, ACPI_SIG_FACS);
    429          1.1    jruoho 
    430          1.1    jruoho     LocalFACS.Length = sizeof (ACPI_TABLE_FACS);
    431          1.1    jruoho     LocalFACS.GlobalLock = 0x11AA0011;
    432          1.1    jruoho 
    433      1.1.1.5  christos     /* Build the optional local tables */
    434      1.1.1.5  christos 
    435      1.1.1.5  christos     if (AcpiGbl_LoadTestTables)
    436      1.1.1.5  christos     {
    437      1.1.1.5  christos         /*
    438      1.1.1.5  christos          * Build a fake table [TEST] so that we make sure that the
    439      1.1.1.5  christos          * ACPICA core ignores it
    440      1.1.1.5  christos          */
    441  1.1.1.5.2.2     skrll         memset (&LocalTEST, 0, sizeof (ACPI_TABLE_HEADER));
    442      1.1.1.5  christos         ACPI_MOVE_NAME (LocalTEST.Signature, "TEST");
    443          1.1    jruoho 
    444      1.1.1.5  christos         LocalTEST.Revision = 1;
    445      1.1.1.5  christos         LocalTEST.Length = sizeof (ACPI_TABLE_HEADER);
    446      1.1.1.5  christos         LocalTEST.Checksum = (UINT8) -AcpiTbChecksum (
    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.5.2.2     skrll         memset (&LocalBADTABLE, 0, sizeof (ACPI_TABLE_HEADER));
    454      1.1.1.5  christos         ACPI_MOVE_NAME (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.5  christos         LocalBADTABLE.Checksum = (UINT8) -AcpiTbChecksum (
    459      1.1.1.5  christos             (void *) &LocalBADTABLE, LocalBADTABLE.Length);
    460      1.1.1.5  christos     }
    461          1.1    jruoho 
    462          1.1    jruoho     return (AE_OK);
    463          1.1    jruoho }
    464          1.1    jruoho 
    465          1.1    jruoho 
    466          1.1    jruoho /******************************************************************************
    467          1.1    jruoho  *
    468          1.1    jruoho  * FUNCTION:    AeInstallTables
    469          1.1    jruoho  *
    470          1.1    jruoho  * PARAMETERS:  None
    471          1.1    jruoho  *
    472          1.1    jruoho  * RETURN:      Status
    473          1.1    jruoho  *
    474          1.1    jruoho  * DESCRIPTION: Install the various ACPI tables
    475          1.1    jruoho  *
    476          1.1    jruoho  *****************************************************************************/
    477          1.1    jruoho 
    478          1.1    jruoho ACPI_STATUS
    479          1.1    jruoho AeInstallTables (
    480          1.1    jruoho     void)
    481          1.1    jruoho {
    482          1.1    jruoho     ACPI_STATUS             Status;
    483      1.1.1.4  christos     ACPI_TABLE_HEADER       Header;
    484      1.1.1.4  christos     ACPI_TABLE_HEADER       *Table;
    485          1.1    jruoho 
    486      1.1.1.2    jruoho 
    487          1.1    jruoho     Status = AcpiInitializeTables (Tables, ACPI_MAX_INIT_TABLES, TRUE);
    488      1.1.1.2    jruoho     AE_CHECK_OK (AcpiInitializeTables, Status);
    489      1.1.1.2    jruoho 
    490          1.1    jruoho     Status = AcpiReallocateRootTable ();
    491      1.1.1.2    jruoho     AE_CHECK_OK (AcpiReallocateRootTable, Status);
    492      1.1.1.2    jruoho 
    493          1.1    jruoho     Status = AcpiLoadTables ();
    494      1.1.1.2    jruoho     AE_CHECK_OK (AcpiLoadTables, Status);
    495          1.1    jruoho 
    496          1.1    jruoho     /*
    497          1.1    jruoho      * Test run-time control method installation. Do it twice to test code
    498          1.1    jruoho      * for an existing name.
    499          1.1    jruoho      */
    500          1.1    jruoho     Status = AcpiInstallMethod (MethodCode);
    501          1.1    jruoho     if (ACPI_FAILURE (Status))
    502          1.1    jruoho     {
    503          1.1    jruoho         AcpiOsPrintf ("%s, Could not install method\n",
    504          1.1    jruoho             AcpiFormatException (Status));
    505          1.1    jruoho     }
    506          1.1    jruoho 
    507          1.1    jruoho     Status = AcpiInstallMethod (MethodCode);
    508          1.1    jruoho     if (ACPI_FAILURE (Status))
    509          1.1    jruoho     {
    510          1.1    jruoho         AcpiOsPrintf ("%s, Could not install method\n",
    511          1.1    jruoho             AcpiFormatException (Status));
    512          1.1    jruoho     }
    513          1.1    jruoho 
    514      1.1.1.5  christos     if (AcpiGbl_LoadTestTables)
    515      1.1.1.5  christos     {
    516      1.1.1.5  christos         /* Test multiple table/UEFI support. First, get the headers */
    517      1.1.1.4  christos 
    518      1.1.1.5  christos         Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 1, &Header);
    519      1.1.1.5  christos         AE_CHECK_OK (AcpiGetTableHeader, Status);
    520      1.1.1.4  christos 
    521      1.1.1.5  christos         Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 2, &Header);
    522      1.1.1.5  christos         AE_CHECK_OK (AcpiGetTableHeader, Status);
    523      1.1.1.4  christos 
    524      1.1.1.5  christos         Status = AcpiGetTableHeader (ACPI_SIG_UEFI, 3, &Header);
    525      1.1.1.5  christos         AE_CHECK_STATUS (AcpiGetTableHeader, Status, AE_NOT_FOUND);
    526      1.1.1.4  christos 
    527      1.1.1.5  christos         /* Now get the actual tables */
    528      1.1.1.4  christos 
    529      1.1.1.5  christos         Status = AcpiGetTable (ACPI_SIG_UEFI, 1, &Table);
    530      1.1.1.5  christos         AE_CHECK_OK (AcpiGetTable, Status);
    531      1.1.1.4  christos 
    532      1.1.1.5  christos         Status = AcpiGetTable (ACPI_SIG_UEFI, 2, &Table);
    533      1.1.1.5  christos         AE_CHECK_OK (AcpiGetTable, Status);
    534      1.1.1.4  christos 
    535      1.1.1.5  christos         Status = AcpiGetTable (ACPI_SIG_UEFI, 3, &Table);
    536      1.1.1.5  christos         AE_CHECK_STATUS (AcpiGetTable, Status, AE_NOT_FOUND);
    537      1.1.1.5  christos     }
    538      1.1.1.4  christos 
    539          1.1    jruoho     return (AE_OK);
    540          1.1    jruoho }
    541          1.1    jruoho 
    542          1.1    jruoho 
    543          1.1    jruoho /******************************************************************************
    544          1.1    jruoho  *
    545      1.1.1.5  christos  * FUNCTION:    AcpiOsGetRootPointer
    546          1.1    jruoho  *
    547          1.1    jruoho  * PARAMETERS:  Flags       - not used
    548          1.1    jruoho  *              Address     - Where the root pointer is returned
    549          1.1    jruoho  *
    550          1.1    jruoho  * RETURN:      Status
    551          1.1    jruoho  *
    552          1.1    jruoho  * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
    553          1.1    jruoho  *              standard ACPI mechanism.
    554          1.1    jruoho  *
    555          1.1    jruoho  *****************************************************************************/
    556          1.1    jruoho 
    557          1.1    jruoho ACPI_PHYSICAL_ADDRESS
    558      1.1.1.5  christos AcpiOsGetRootPointer (
    559          1.1    jruoho     void)
    560          1.1    jruoho {
    561          1.1    jruoho 
    562  1.1.1.5.2.1     skrll     return (ACPI_PTR_TO_PHYSADDR (&LocalRSDP));
    563          1.1    jruoho }
    564