Home | History | Annotate | Line # | Download | only in compiler
dtsubtable.c revision 1.1.1.2.4.2
      1  1.1.1.2.4.2  rmind /******************************************************************************
      2  1.1.1.2.4.2  rmind  *
      3  1.1.1.2.4.2  rmind  * Module Name: dtsubtable.c - handling of subtables within ACPI tables
      4  1.1.1.2.4.2  rmind  *
      5  1.1.1.2.4.2  rmind  *****************************************************************************/
      6  1.1.1.2.4.2  rmind 
      7  1.1.1.2.4.2  rmind /*
      8  1.1.1.2.4.2  rmind  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.1.1.2.4.2  rmind  * All rights reserved.
     10  1.1.1.2.4.2  rmind  *
     11  1.1.1.2.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2.4.2  rmind  * modification, are permitted provided that the following conditions
     13  1.1.1.2.4.2  rmind  * are met:
     14  1.1.1.2.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2.4.2  rmind  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2.4.2  rmind  *    without modification.
     17  1.1.1.2.4.2  rmind  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2.4.2  rmind  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2.4.2  rmind  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2.4.2  rmind  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2.4.2  rmind  *    binary redistribution.
     22  1.1.1.2.4.2  rmind  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2.4.2  rmind  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2.4.2  rmind  *    from this software without specific prior written permission.
     25  1.1.1.2.4.2  rmind  *
     26  1.1.1.2.4.2  rmind  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2.4.2  rmind  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2.4.2  rmind  * Software Foundation.
     29  1.1.1.2.4.2  rmind  *
     30  1.1.1.2.4.2  rmind  * NO WARRANTY
     31  1.1.1.2.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2.4.2  rmind  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2.4.2  rmind  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2.4.2  rmind  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2.4.2  rmind  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2.4.2  rmind  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2.4.2  rmind  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2.4.2  rmind  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2.4.2  rmind  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2.4.2  rmind  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2.4.2  rmind  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2.4.2  rmind  */
     43  1.1.1.2.4.2  rmind 
     44  1.1.1.2.4.2  rmind #define __DTSUBTABLE_C__
     45  1.1.1.2.4.2  rmind 
     46  1.1.1.2.4.2  rmind #include "aslcompiler.h"
     47  1.1.1.2.4.2  rmind #include "dtcompiler.h"
     48  1.1.1.2.4.2  rmind 
     49  1.1.1.2.4.2  rmind #define _COMPONENT          DT_COMPILER
     50  1.1.1.2.4.2  rmind         ACPI_MODULE_NAME    ("dtsubtable")
     51  1.1.1.2.4.2  rmind 
     52  1.1.1.2.4.2  rmind 
     53  1.1.1.2.4.2  rmind /******************************************************************************
     54  1.1.1.2.4.2  rmind  *
     55  1.1.1.2.4.2  rmind  * FUNCTION:    DtCreateSubtable
     56  1.1.1.2.4.2  rmind  *
     57  1.1.1.2.4.2  rmind  * PARAMETERS:  Buffer              - Input buffer
     58  1.1.1.2.4.2  rmind  *              Length              - Buffer length
     59  1.1.1.2.4.2  rmind  *              RetSubtable         - Returned newly created subtable
     60  1.1.1.2.4.2  rmind  *
     61  1.1.1.2.4.2  rmind  * RETURN:      None
     62  1.1.1.2.4.2  rmind  *
     63  1.1.1.2.4.2  rmind  * DESCRIPTION: Create a subtable that is not listed with ACPI_DMTABLE_INFO
     64  1.1.1.2.4.2  rmind  *              For example, FACS has 24 bytes reserved at the end
     65  1.1.1.2.4.2  rmind  *              and it's not listed at AcpiDmTableInfoFacs
     66  1.1.1.2.4.2  rmind  *
     67  1.1.1.2.4.2  rmind  *****************************************************************************/
     68  1.1.1.2.4.2  rmind 
     69  1.1.1.2.4.2  rmind void
     70  1.1.1.2.4.2  rmind DtCreateSubtable (
     71  1.1.1.2.4.2  rmind     UINT8                   *Buffer,
     72  1.1.1.2.4.2  rmind     UINT32                  Length,
     73  1.1.1.2.4.2  rmind     DT_SUBTABLE             **RetSubtable)
     74  1.1.1.2.4.2  rmind {
     75  1.1.1.2.4.2  rmind     DT_SUBTABLE             *Subtable;
     76  1.1.1.2.4.2  rmind 
     77  1.1.1.2.4.2  rmind 
     78  1.1.1.2.4.2  rmind     Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE));
     79  1.1.1.2.4.2  rmind 
     80  1.1.1.2.4.2  rmind     /* Create a new buffer for the subtable data */
     81  1.1.1.2.4.2  rmind 
     82  1.1.1.2.4.2  rmind     Subtable->Buffer = UtLocalCalloc (Length);
     83  1.1.1.2.4.2  rmind     ACPI_MEMCPY (Subtable->Buffer, Buffer, Length);
     84  1.1.1.2.4.2  rmind 
     85  1.1.1.2.4.2  rmind     Subtable->Length = Length;
     86  1.1.1.2.4.2  rmind     Subtable->TotalLength = Length;
     87  1.1.1.2.4.2  rmind 
     88  1.1.1.2.4.2  rmind     *RetSubtable = Subtable;
     89  1.1.1.2.4.2  rmind }
     90  1.1.1.2.4.2  rmind 
     91  1.1.1.2.4.2  rmind 
     92  1.1.1.2.4.2  rmind /******************************************************************************
     93  1.1.1.2.4.2  rmind  *
     94  1.1.1.2.4.2  rmind  * FUNCTION:    DtInsertSubtable
     95  1.1.1.2.4.2  rmind  *
     96  1.1.1.2.4.2  rmind  * PARAMETERS:  ParentTable         - The Parent of the new subtable
     97  1.1.1.2.4.2  rmind  *              Subtable            - The new subtable to insert
     98  1.1.1.2.4.2  rmind  *
     99  1.1.1.2.4.2  rmind  * RETURN:      None
    100  1.1.1.2.4.2  rmind  *
    101  1.1.1.2.4.2  rmind  * DESCRIPTION: Insert the new subtable to the parent table
    102  1.1.1.2.4.2  rmind  *
    103  1.1.1.2.4.2  rmind  *****************************************************************************/
    104  1.1.1.2.4.2  rmind 
    105  1.1.1.2.4.2  rmind void
    106  1.1.1.2.4.2  rmind DtInsertSubtable (
    107  1.1.1.2.4.2  rmind     DT_SUBTABLE             *ParentTable,
    108  1.1.1.2.4.2  rmind     DT_SUBTABLE             *Subtable)
    109  1.1.1.2.4.2  rmind {
    110  1.1.1.2.4.2  rmind     DT_SUBTABLE             *ChildTable;
    111  1.1.1.2.4.2  rmind 
    112  1.1.1.2.4.2  rmind 
    113  1.1.1.2.4.2  rmind     Subtable->Peer = NULL;
    114  1.1.1.2.4.2  rmind     Subtable->Parent = ParentTable;
    115  1.1.1.2.4.2  rmind 
    116  1.1.1.2.4.2  rmind     /* Link the new entry into the child list */
    117  1.1.1.2.4.2  rmind 
    118  1.1.1.2.4.2  rmind     if (!ParentTable->Child)
    119  1.1.1.2.4.2  rmind     {
    120  1.1.1.2.4.2  rmind         ParentTable->Child = Subtable;
    121  1.1.1.2.4.2  rmind     }
    122  1.1.1.2.4.2  rmind     else
    123  1.1.1.2.4.2  rmind     {
    124  1.1.1.2.4.2  rmind         /* Walk to the end of the child list */
    125  1.1.1.2.4.2  rmind 
    126  1.1.1.2.4.2  rmind         ChildTable = ParentTable->Child;
    127  1.1.1.2.4.2  rmind         while (ChildTable->Peer)
    128  1.1.1.2.4.2  rmind         {
    129  1.1.1.2.4.2  rmind             ChildTable = ChildTable->Peer;
    130  1.1.1.2.4.2  rmind         }
    131  1.1.1.2.4.2  rmind 
    132  1.1.1.2.4.2  rmind         /* Add new subtable at the end of the child list */
    133  1.1.1.2.4.2  rmind 
    134  1.1.1.2.4.2  rmind         ChildTable->Peer = Subtable;
    135  1.1.1.2.4.2  rmind     }
    136  1.1.1.2.4.2  rmind }
    137  1.1.1.2.4.2  rmind 
    138  1.1.1.2.4.2  rmind 
    139  1.1.1.2.4.2  rmind /******************************************************************************
    140  1.1.1.2.4.2  rmind  *
    141  1.1.1.2.4.2  rmind  * FUNCTION:    DtPushSubtable
    142  1.1.1.2.4.2  rmind  *
    143  1.1.1.2.4.2  rmind  * PARAMETERS:  Subtable            - Subtable to push
    144  1.1.1.2.4.2  rmind  *
    145  1.1.1.2.4.2  rmind  * RETURN:      None
    146  1.1.1.2.4.2  rmind  *
    147  1.1.1.2.4.2  rmind  * DESCRIPTION: Push a subtable onto a subtable stack
    148  1.1.1.2.4.2  rmind  *
    149  1.1.1.2.4.2  rmind  *****************************************************************************/
    150  1.1.1.2.4.2  rmind 
    151  1.1.1.2.4.2  rmind void
    152  1.1.1.2.4.2  rmind DtPushSubtable (
    153  1.1.1.2.4.2  rmind     DT_SUBTABLE             *Subtable)
    154  1.1.1.2.4.2  rmind {
    155  1.1.1.2.4.2  rmind 
    156  1.1.1.2.4.2  rmind     Subtable->StackTop = Gbl_SubtableStack;
    157  1.1.1.2.4.2  rmind     Gbl_SubtableStack = Subtable;
    158  1.1.1.2.4.2  rmind }
    159  1.1.1.2.4.2  rmind 
    160  1.1.1.2.4.2  rmind 
    161  1.1.1.2.4.2  rmind /******************************************************************************
    162  1.1.1.2.4.2  rmind  *
    163  1.1.1.2.4.2  rmind  * FUNCTION:    DtPopSubtable
    164  1.1.1.2.4.2  rmind  *
    165  1.1.1.2.4.2  rmind  * PARAMETERS:  None
    166  1.1.1.2.4.2  rmind  *
    167  1.1.1.2.4.2  rmind  * RETURN:      None
    168  1.1.1.2.4.2  rmind  *
    169  1.1.1.2.4.2  rmind  * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack
    170  1.1.1.2.4.2  rmind  *
    171  1.1.1.2.4.2  rmind  *****************************************************************************/
    172  1.1.1.2.4.2  rmind 
    173  1.1.1.2.4.2  rmind void
    174  1.1.1.2.4.2  rmind DtPopSubtable (
    175  1.1.1.2.4.2  rmind     void)
    176  1.1.1.2.4.2  rmind {
    177  1.1.1.2.4.2  rmind     DT_SUBTABLE             *Subtable;
    178  1.1.1.2.4.2  rmind 
    179  1.1.1.2.4.2  rmind 
    180  1.1.1.2.4.2  rmind     Subtable = Gbl_SubtableStack;
    181  1.1.1.2.4.2  rmind 
    182  1.1.1.2.4.2  rmind     if (Subtable)
    183  1.1.1.2.4.2  rmind     {
    184  1.1.1.2.4.2  rmind         Gbl_SubtableStack = Subtable->StackTop;
    185  1.1.1.2.4.2  rmind     }
    186  1.1.1.2.4.2  rmind }
    187  1.1.1.2.4.2  rmind 
    188  1.1.1.2.4.2  rmind 
    189  1.1.1.2.4.2  rmind /******************************************************************************
    190  1.1.1.2.4.2  rmind  *
    191  1.1.1.2.4.2  rmind  * FUNCTION:    DtPeekSubtable
    192  1.1.1.2.4.2  rmind  *
    193  1.1.1.2.4.2  rmind  * PARAMETERS:  None
    194  1.1.1.2.4.2  rmind  *
    195  1.1.1.2.4.2  rmind  * RETURN:      The subtable on top of stack
    196  1.1.1.2.4.2  rmind  *
    197  1.1.1.2.4.2  rmind  * DESCRIPTION: Get the subtable on top of stack
    198  1.1.1.2.4.2  rmind  *
    199  1.1.1.2.4.2  rmind  *****************************************************************************/
    200  1.1.1.2.4.2  rmind 
    201  1.1.1.2.4.2  rmind DT_SUBTABLE *
    202  1.1.1.2.4.2  rmind DtPeekSubtable (
    203  1.1.1.2.4.2  rmind     void)
    204  1.1.1.2.4.2  rmind {
    205  1.1.1.2.4.2  rmind 
    206  1.1.1.2.4.2  rmind     return (Gbl_SubtableStack);
    207  1.1.1.2.4.2  rmind }
    208  1.1.1.2.4.2  rmind 
    209  1.1.1.2.4.2  rmind 
    210  1.1.1.2.4.2  rmind /******************************************************************************
    211  1.1.1.2.4.2  rmind  *
    212  1.1.1.2.4.2  rmind  * FUNCTION:    DtGetNextSubtable
    213  1.1.1.2.4.2  rmind  *
    214  1.1.1.2.4.2  rmind  * PARAMETERS:  ParentTable         - Parent table whose children we are
    215  1.1.1.2.4.2  rmind  *                                    getting
    216  1.1.1.2.4.2  rmind  *              ChildTable          - Previous child that was found.
    217  1.1.1.2.4.2  rmind  *                                    The NEXT child will be returned
    218  1.1.1.2.4.2  rmind  *
    219  1.1.1.2.4.2  rmind  * RETURN:      Pointer to the NEXT child or NULL if none is found.
    220  1.1.1.2.4.2  rmind  *
    221  1.1.1.2.4.2  rmind  * DESCRIPTION: Return the next peer subtable within the tree.
    222  1.1.1.2.4.2  rmind  *
    223  1.1.1.2.4.2  rmind  *****************************************************************************/
    224  1.1.1.2.4.2  rmind 
    225  1.1.1.2.4.2  rmind DT_SUBTABLE *
    226  1.1.1.2.4.2  rmind DtGetNextSubtable (
    227  1.1.1.2.4.2  rmind     DT_SUBTABLE             *ParentTable,
    228  1.1.1.2.4.2  rmind     DT_SUBTABLE             *ChildTable)
    229  1.1.1.2.4.2  rmind {
    230  1.1.1.2.4.2  rmind     ACPI_FUNCTION_ENTRY ();
    231  1.1.1.2.4.2  rmind 
    232  1.1.1.2.4.2  rmind 
    233  1.1.1.2.4.2  rmind     if (!ChildTable)
    234  1.1.1.2.4.2  rmind     {
    235  1.1.1.2.4.2  rmind         /* It's really the parent's _scope_ that we want */
    236  1.1.1.2.4.2  rmind 
    237  1.1.1.2.4.2  rmind         return (ParentTable->Child);
    238  1.1.1.2.4.2  rmind     }
    239  1.1.1.2.4.2  rmind 
    240  1.1.1.2.4.2  rmind     /* Otherwise just return the next peer (NULL if at end-of-list) */
    241  1.1.1.2.4.2  rmind 
    242  1.1.1.2.4.2  rmind     return (ChildTable->Peer);
    243  1.1.1.2.4.2  rmind }
    244  1.1.1.2.4.2  rmind 
    245  1.1.1.2.4.2  rmind 
    246  1.1.1.2.4.2  rmind /******************************************************************************
    247  1.1.1.2.4.2  rmind  *
    248  1.1.1.2.4.2  rmind  * FUNCTION:    DtGetParentSubtable
    249  1.1.1.2.4.2  rmind  *
    250  1.1.1.2.4.2  rmind  * PARAMETERS:  Subtable            - Current subtable
    251  1.1.1.2.4.2  rmind  *
    252  1.1.1.2.4.2  rmind  * RETURN:      Parent of the given subtable
    253  1.1.1.2.4.2  rmind  *
    254  1.1.1.2.4.2  rmind  * DESCRIPTION: Get the parent of the given subtable in the tree
    255  1.1.1.2.4.2  rmind  *
    256  1.1.1.2.4.2  rmind  *****************************************************************************/
    257  1.1.1.2.4.2  rmind 
    258  1.1.1.2.4.2  rmind DT_SUBTABLE *
    259  1.1.1.2.4.2  rmind DtGetParentSubtable (
    260  1.1.1.2.4.2  rmind     DT_SUBTABLE             *Subtable)
    261  1.1.1.2.4.2  rmind {
    262  1.1.1.2.4.2  rmind 
    263  1.1.1.2.4.2  rmind     if (!Subtable)
    264  1.1.1.2.4.2  rmind     {
    265  1.1.1.2.4.2  rmind         return (NULL);
    266  1.1.1.2.4.2  rmind     }
    267  1.1.1.2.4.2  rmind 
    268  1.1.1.2.4.2  rmind     return (Subtable->Parent);
    269  1.1.1.2.4.2  rmind }
    270  1.1.1.2.4.2  rmind 
    271  1.1.1.2.4.2  rmind 
    272  1.1.1.2.4.2  rmind /******************************************************************************
    273  1.1.1.2.4.2  rmind  *
    274  1.1.1.2.4.2  rmind  * FUNCTION:    DtGetSubtableLength
    275  1.1.1.2.4.2  rmind  *
    276  1.1.1.2.4.2  rmind  * PARAMETERS:  Field               - Current field list pointer
    277  1.1.1.2.4.2  rmind  *              Info                - Data table info
    278  1.1.1.2.4.2  rmind  *
    279  1.1.1.2.4.2  rmind  * RETURN:      Subtable length
    280  1.1.1.2.4.2  rmind  *
    281  1.1.1.2.4.2  rmind  * DESCRIPTION: Get length of bytes needed to compile the subtable
    282  1.1.1.2.4.2  rmind  *
    283  1.1.1.2.4.2  rmind  *****************************************************************************/
    284  1.1.1.2.4.2  rmind 
    285  1.1.1.2.4.2  rmind UINT32
    286  1.1.1.2.4.2  rmind DtGetSubtableLength (
    287  1.1.1.2.4.2  rmind     DT_FIELD                *Field,
    288  1.1.1.2.4.2  rmind     ACPI_DMTABLE_INFO       *Info)
    289  1.1.1.2.4.2  rmind {
    290  1.1.1.2.4.2  rmind     UINT32                  ByteLength = 0;
    291  1.1.1.2.4.2  rmind 
    292  1.1.1.2.4.2  rmind 
    293  1.1.1.2.4.2  rmind     /* Walk entire Info table; Null name terminates */
    294  1.1.1.2.4.2  rmind 
    295  1.1.1.2.4.2  rmind     for (; Info->Name; Info++)
    296  1.1.1.2.4.2  rmind     {
    297  1.1.1.2.4.2  rmind         ByteLength += DtGetFieldLength (Field, Info);
    298  1.1.1.2.4.2  rmind     }
    299  1.1.1.2.4.2  rmind 
    300  1.1.1.2.4.2  rmind     return (ByteLength);
    301  1.1.1.2.4.2  rmind }
    302  1.1.1.2.4.2  rmind 
    303  1.1.1.2.4.2  rmind 
    304  1.1.1.2.4.2  rmind /******************************************************************************
    305  1.1.1.2.4.2  rmind  *
    306  1.1.1.2.4.2  rmind  * FUNCTION:    DtSetSubtableLength
    307  1.1.1.2.4.2  rmind  *
    308  1.1.1.2.4.2  rmind  * PARAMETERS:  Subtable            - Subtable
    309  1.1.1.2.4.2  rmind  *
    310  1.1.1.2.4.2  rmind  * RETURN:      None
    311  1.1.1.2.4.2  rmind  *
    312  1.1.1.2.4.2  rmind  * DESCRIPTION: Set length of the subtable into its length field
    313  1.1.1.2.4.2  rmind  *
    314  1.1.1.2.4.2  rmind  *****************************************************************************/
    315  1.1.1.2.4.2  rmind 
    316  1.1.1.2.4.2  rmind void
    317  1.1.1.2.4.2  rmind DtSetSubtableLength (
    318  1.1.1.2.4.2  rmind     DT_SUBTABLE             *Subtable)
    319  1.1.1.2.4.2  rmind {
    320  1.1.1.2.4.2  rmind 
    321  1.1.1.2.4.2  rmind     if (!Subtable->LengthField)
    322  1.1.1.2.4.2  rmind     {
    323  1.1.1.2.4.2  rmind         return;
    324  1.1.1.2.4.2  rmind     }
    325  1.1.1.2.4.2  rmind 
    326  1.1.1.2.4.2  rmind     ACPI_MEMCPY (Subtable->LengthField, &Subtable->TotalLength,
    327  1.1.1.2.4.2  rmind         Subtable->SizeOfLengthField);
    328  1.1.1.2.4.2  rmind }
    329