Home | History | Annotate | Line # | Download | only in compiler
dttable.c revision 1.18
      1   1.1    jruoho /******************************************************************************
      2   1.1    jruoho  *
      3   1.1    jruoho  * Module Name: dttable.c - handling for specific ACPI tables
      4   1.1    jruoho  *
      5   1.1    jruoho  *****************************************************************************/
      6   1.1    jruoho 
      7   1.2  christos /*
      8  1.18  christos  * Copyright (C) 2000 - 2023, Intel Corp.
      9   1.1    jruoho  * All rights reserved.
     10   1.1    jruoho  *
     11   1.2  christos  * Redistribution and use in source and binary forms, with or without
     12   1.2  christos  * modification, are permitted provided that the following conditions
     13   1.2  christos  * are met:
     14   1.2  christos  * 1. Redistributions of source code must retain the above copyright
     15   1.2  christos  *    notice, this list of conditions, and the following disclaimer,
     16   1.2  christos  *    without modification.
     17   1.2  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.2  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.2  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.2  christos  *    including a substantially similar Disclaimer requirement for further
     21   1.2  christos  *    binary redistribution.
     22   1.2  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.2  christos  *    of any contributors may be used to endorse or promote products derived
     24   1.2  christos  *    from this software without specific prior written permission.
     25   1.2  christos  *
     26   1.2  christos  * Alternatively, this software may be distributed under the terms of the
     27   1.2  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.2  christos  * Software Foundation.
     29   1.2  christos  *
     30   1.2  christos  * NO WARRANTY
     31   1.2  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.2  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.15  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34   1.2  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.2  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.2  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.2  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.2  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.2  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.2  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.2  christos  * POSSIBILITY OF SUCH DAMAGES.
     42   1.2  christos  */
     43   1.1    jruoho 
     44   1.7  christos /* Compile routines for the basic ACPI tables */
     45   1.1    jruoho 
     46   1.1    jruoho #include "aslcompiler.h"
     47   1.1    jruoho 
     48   1.1    jruoho #define _COMPONENT          DT_COMPILER
     49   1.1    jruoho         ACPI_MODULE_NAME    ("dttable")
     50   1.1    jruoho 
     51   1.1    jruoho 
     52   1.1    jruoho /******************************************************************************
     53   1.1    jruoho  *
     54   1.1    jruoho  * FUNCTION:    DtCompileRsdp
     55   1.1    jruoho  *
     56   1.1    jruoho  * PARAMETERS:  PFieldList          - Current field list pointer
     57   1.1    jruoho  *
     58   1.1    jruoho  * RETURN:      Status
     59   1.1    jruoho  *
     60   1.1    jruoho  * DESCRIPTION: Compile RSDP.
     61   1.1    jruoho  *
     62   1.1    jruoho  *****************************************************************************/
     63   1.1    jruoho 
     64   1.1    jruoho ACPI_STATUS
     65   1.1    jruoho DtCompileRsdp (
     66   1.1    jruoho     DT_FIELD                **PFieldList)
     67   1.1    jruoho {
     68   1.1    jruoho     DT_SUBTABLE             *Subtable;
     69   1.2  christos     ACPI_TABLE_RSDP         *Rsdp;
     70   1.2  christos     ACPI_RSDP_EXTENSION     *RsdpExtension;
     71   1.1    jruoho     ACPI_STATUS             Status;
     72   1.1    jruoho 
     73   1.1    jruoho 
     74   1.2  christos     /* Compile the "common" RSDP (ACPI 1.0) */
     75   1.2  christos 
     76   1.1    jruoho     Status = DtCompileTable (PFieldList, AcpiDmTableInfoRsdp1,
     77  1.12  christos         &AslGbl_RootTable);
     78   1.1    jruoho     if (ACPI_FAILURE (Status))
     79   1.1    jruoho     {
     80   1.1    jruoho         return (Status);
     81   1.1    jruoho     }
     82   1.1    jruoho 
     83  1.12  christos     Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, AslGbl_RootTable->Buffer);
     84   1.2  christos     DtSetTableChecksum (&Rsdp->Checksum);
     85   1.1    jruoho 
     86   1.2  christos     if (Rsdp->Revision > 0)
     87   1.1    jruoho     {
     88   1.2  christos         /* Compile the "extended" part of the RSDP as a subtable */
     89   1.2  christos 
     90   1.1    jruoho         Status = DtCompileTable (PFieldList, AcpiDmTableInfoRsdp2,
     91  1.11  christos             &Subtable);
     92   1.1    jruoho         if (ACPI_FAILURE (Status))
     93   1.1    jruoho         {
     94   1.1    jruoho             return (Status);
     95   1.1    jruoho         }
     96   1.1    jruoho 
     97  1.12  christos         DtInsertSubtable (AslGbl_RootTable, Subtable);
     98   1.2  christos 
     99   1.2  christos         /* Set length and extended checksum for entire RSDP */
    100   1.2  christos 
    101   1.2  christos         RsdpExtension = ACPI_CAST_PTR (ACPI_RSDP_EXTENSION, Subtable->Buffer);
    102  1.12  christos         RsdpExtension->Length = AslGbl_RootTable->Length + Subtable->Length;
    103   1.2  christos         DtSetTableChecksum (&RsdpExtension->ExtendedChecksum);
    104   1.1    jruoho     }
    105   1.1    jruoho 
    106   1.1    jruoho     return (AE_OK);
    107   1.1    jruoho }
    108   1.1    jruoho 
    109   1.1    jruoho 
    110   1.1    jruoho /******************************************************************************
    111   1.1    jruoho  *
    112   1.7  christos  * FUNCTION:    DtCompileFadt
    113   1.1    jruoho  *
    114   1.1    jruoho  * PARAMETERS:  List                - Current field list pointer
    115   1.1    jruoho  *
    116   1.1    jruoho  * RETURN:      Status
    117   1.1    jruoho  *
    118  1.16  christos  * DESCRIPTION: Compile FADT (signature FACP).
    119   1.1    jruoho  *
    120   1.1    jruoho  *****************************************************************************/
    121   1.1    jruoho 
    122  1.16  christos #define ACPI_XDSDT_LOCATION_IN_LIST         11
    123  1.16  christos 
    124   1.1    jruoho ACPI_STATUS
    125   1.7  christos DtCompileFadt (
    126   1.1    jruoho     void                    **List)
    127   1.1    jruoho {
    128   1.7  christos     ACPI_STATUS             Status;
    129   1.1    jruoho     DT_SUBTABLE             *Subtable;
    130   1.1    jruoho     DT_SUBTABLE             *ParentTable;
    131   1.1    jruoho     DT_FIELD                **PFieldList = (DT_FIELD **) List;
    132  1.16  christos     DT_FIELD                *DsdtFieldList;
    133  1.16  christos     ACPI_TABLE_FADT         *Table;
    134   1.9  christos     UINT8                   Revision;
    135  1.16  christos     UINT32                  DsdtAddress;
    136  1.16  christos     UINT64                  X_DsdtAddress;
    137  1.16  christos     UINT32                  i;
    138  1.16  christos 
    139   1.1    jruoho 
    140  1.16  christos     /* Get the table revision and 32-bit DSDT Address definition */
    141   1.1    jruoho 
    142  1.16  christos     DsdtFieldList = (*PFieldList)->Next;
    143   1.7  christos     Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt1,
    144  1.11  christos         &Subtable);
    145   1.7  christos     if (ACPI_FAILURE (Status))
    146   1.1    jruoho     {
    147   1.7  christos         return (Status);
    148   1.7  christos     }
    149   1.1    jruoho 
    150   1.7  christos     ParentTable = DtPeekSubtable ();
    151   1.7  christos     DtInsertSubtable (ParentTable, Subtable);
    152   1.1    jruoho 
    153  1.16  christos     Table = ACPI_CAST_PTR (ACPI_TABLE_FADT, ParentTable->Buffer);
    154  1.16  christos     Revision = Table->Header.Revision;
    155  1.16  christos     DsdtAddress = Table->Dsdt;
    156  1.16  christos 
    157  1.16  christos     /* FADT version 1 has only 32-bit addresses - error if DSDT address is NULL */
    158  1.16  christos 
    159  1.16  christos     if ((Revision == 1) && (!DsdtAddress))
    160  1.16  christos     {
    161  1.16  christos         DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, DsdtFieldList, NULL);
    162  1.16  christos     }
    163   1.8  christos 
    164   1.9  christos     if (Revision == 2)
    165   1.8  christos     {
    166   1.9  christos         Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt2,
    167  1.11  christos             &Subtable);
    168   1.9  christos         if (ACPI_FAILURE (Status))
    169   1.9  christos         {
    170   1.9  christos             return (Status);
    171   1.9  christos         }
    172   1.8  christos 
    173   1.9  christos         DtInsertSubtable (ParentTable, Subtable);
    174   1.8  christos     }
    175  1.16  christos 
    176  1.16  christos     else if (Revision > 2)
    177   1.7  christos     {
    178  1.16  christos         /*
    179  1.16  christos          * Rev 3 and greater have 64-bit addresses (as well as 32-bit).
    180  1.16  christos          * Get the 64-bit DSDT (X_DSDT) Address definition. Note: This
    181  1.16  christos          * appears at field list offset 11 within AcpiDmTableInfoFadt3.
    182  1.16  christos          */
    183  1.16  christos         DsdtFieldList = *PFieldList;
    184  1.16  christos         for (i = 0; i < ACPI_XDSDT_LOCATION_IN_LIST; i++)
    185  1.16  christos         {
    186  1.16  christos             DsdtFieldList = DsdtFieldList->Next;
    187  1.16  christos             if (!DsdtFieldList)
    188  1.16  christos             {
    189  1.16  christos                 return (ASL_MSG_BAD_PARSE_TREE);
    190  1.16  christos             }
    191  1.16  christos         }
    192  1.16  christos 
    193   1.9  christos         Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt3,
    194  1.11  christos             &Subtable);
    195   1.9  christos         if (ACPI_FAILURE (Status))
    196   1.9  christos         {
    197   1.9  christos             return (Status);
    198   1.9  christos         }
    199   1.8  christos 
    200   1.9  christos         DtInsertSubtable (ParentTable, Subtable);
    201   1.8  christos 
    202  1.16  christos         Table = ACPI_CAST_PTR (ACPI_TABLE_FADT, ParentTable->Buffer);
    203  1.16  christos         X_DsdtAddress = Table->XDsdt;
    204  1.16  christos 
    205  1.16  christos         /*
    206  1.16  christos          * Error if both the 32-bit DSDT address and the
    207  1.16  christos          * 64-bit X_DSDT address are zero.
    208  1.16  christos          */
    209  1.16  christos         if ((!X_DsdtAddress) && (!DsdtAddress))
    210  1.16  christos         {
    211  1.16  christos             DtError (ASL_ERROR, ASL_MSG_TWO_ZERO_VALUES, DsdtFieldList, NULL);
    212  1.16  christos         }
    213  1.16  christos 
    214  1.16  christos         /* Fields specific to FADT Revision 5 (appended to previous) */
    215  1.16  christos 
    216   1.9  christos         if (Revision >= 5)
    217   1.9  christos         {
    218   1.9  christos             Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt5,
    219  1.11  christos                 &Subtable);
    220   1.9  christos             if (ACPI_FAILURE (Status))
    221   1.9  christos             {
    222   1.9  christos                 return (Status);
    223   1.9  christos             }
    224   1.8  christos 
    225   1.9  christos             DtInsertSubtable (ParentTable, Subtable);
    226   1.1    jruoho         }
    227   1.1    jruoho 
    228  1.16  christos         /* Fields specific to FADT Revision 6 (appended to previous) */
    229  1.16  christos 
    230   1.9  christos         if (Revision >= 6)
    231   1.9  christos         {
    232   1.9  christos             Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt6,
    233  1.11  christos                 &Subtable);
    234   1.9  christos             if (ACPI_FAILURE (Status))
    235   1.9  christos             {
    236   1.9  christos                 return (Status);
    237   1.9  christos             }
    238   1.8  christos 
    239   1.9  christos             DtInsertSubtable (ParentTable, Subtable);
    240   1.2  christos         }
    241   1.2  christos     }
    242   1.2  christos 
    243   1.7  christos     return (AE_OK);
    244   1.2  christos }
    245   1.2  christos 
    246   1.2  christos 
    247   1.2  christos /******************************************************************************
    248   1.2  christos  *
    249   1.7  christos  * FUNCTION:    DtCompileFacs
    250   1.2  christos  *
    251   1.7  christos  * PARAMETERS:  PFieldList          - Current field list pointer
    252   1.2  christos  *
    253   1.2  christos  * RETURN:      Status
    254   1.2  christos  *
    255   1.7  christos  * DESCRIPTION: Compile FACS.
    256   1.2  christos  *
    257   1.2  christos  *****************************************************************************/
    258   1.2  christos 
    259   1.2  christos ACPI_STATUS
    260   1.7  christos DtCompileFacs (
    261   1.7  christos     DT_FIELD                **PFieldList)
    262   1.2  christos {
    263   1.7  christos     DT_SUBTABLE             *Subtable;
    264   1.7  christos     UINT8                   *ReservedBuffer;
    265   1.2  christos     ACPI_STATUS             Status;
    266   1.7  christos     UINT32                  ReservedSize;
    267   1.2  christos 
    268   1.2  christos 
    269   1.7  christos     Status = DtCompileTable (PFieldList, AcpiDmTableInfoFacs,
    270  1.12  christos         &AslGbl_RootTable);
    271   1.2  christos     if (ACPI_FAILURE (Status))
    272   1.2  christos     {
    273   1.2  christos         return (Status);
    274   1.2  christos     }
    275   1.2  christos 
    276   1.7  christos     /* Large FACS reserved area at the end of the table */
    277   1.2  christos 
    278   1.7  christos     ReservedSize = (UINT32) sizeof (((ACPI_TABLE_FACS *) NULL)->Reserved1);
    279   1.7  christos     ReservedBuffer = UtLocalCalloc (ReservedSize);
    280   1.2  christos 
    281   1.7  christos     DtCreateSubtable (ReservedBuffer, ReservedSize, &Subtable);
    282   1.2  christos 
    283   1.7  christos     ACPI_FREE (ReservedBuffer);
    284  1.12  christos     DtInsertSubtable (AslGbl_RootTable, Subtable);
    285   1.2  christos     return (AE_OK);
    286   1.2  christos }
    287