Home | History | Annotate | Line # | Download | only in compiler
dtutils.c revision 1.20
      1 /******************************************************************************
      2  *
      3  * Module Name: dtutils.c - Utility routines for the data table compiler
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2022, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "aslcompiler.h"
     45 #include "actables.h"
     46 
     47 #define _COMPONENT          DT_COMPILER
     48         ACPI_MODULE_NAME    ("dtutils")
     49 
     50 /* Local prototypes */
     51 
     52 static void
     53 DtSum (
     54     DT_SUBTABLE             *Subtable,
     55     void                    *Context,
     56     void                    *ReturnValue);
     57 
     58 
     59 /******************************************************************************
     60  *
     61  * FUNCTION:    DtError
     62  *
     63  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
     64  *              MessageId           - Index into global message buffer
     65  *              Op                  - Parse node where error happened
     66  *              ExtraMessage        - additional error message
     67  *
     68  * RETURN:      None
     69  *
     70  * DESCRIPTION: Common error interface for data table compiler
     71  *
     72  *****************************************************************************/
     73 
     74 void
     75 DtError (
     76     UINT8                   Level,
     77     UINT16                  MessageId,
     78     DT_FIELD                *FieldObject,
     79     char                    *ExtraMessage)
     80 {
     81     UINT32                  Line = 0;
     82 
     83 
     84     /* Field object could be NULL */
     85 
     86     if (FieldObject)
     87     {
     88         Line = FieldObject->Line;
     89     }
     90 
     91     /* Check if user wants to ignore this exception */
     92 
     93     if (AslIsExceptionIgnored (AslGbl_Files[ASL_FILE_INPUT].Filename,
     94         Line, Level, MessageId))
     95     {
     96         return;
     97     }
     98 
     99     if (FieldObject)
    100     {
    101         AslCommonError (Level, MessageId,
    102             FieldObject->Line,
    103             FieldObject->Line,
    104             FieldObject->ByteOffset,
    105             FieldObject->Column,
    106             AslGbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage);
    107     }
    108     else
    109     {
    110         AslCommonError (Level, MessageId, 0,
    111             0, 0, 0, 0, ExtraMessage);
    112     }
    113 }
    114 
    115 
    116 /******************************************************************************
    117  *
    118  * FUNCTION:    DtNameError
    119  *
    120  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
    121  *              MessageId           - Index into global message buffer
    122  *              Op                  - Parse node where error happened
    123  *              ExtraMessage        - additional error message
    124  *
    125  * RETURN:      None
    126  *
    127  * DESCRIPTION: Error interface for named objects
    128  *
    129  *****************************************************************************/
    130 
    131 void
    132 DtNameError (
    133     UINT8                   Level,
    134     UINT16                  MessageId,
    135     DT_FIELD                *FieldObject,
    136     char                    *ExtraMessage)
    137 {
    138 
    139     switch (Level)
    140     {
    141     case ASL_WARNING2:
    142     case ASL_WARNING3:
    143 
    144         if (AslGbl_WarningLevel < Level)
    145         {
    146             return;
    147         }
    148         break;
    149 
    150     default:
    151 
    152         break;
    153     }
    154 
    155     if (FieldObject)
    156     {
    157         AslCommonError (Level, MessageId,
    158             FieldObject->Line,
    159             FieldObject->Line,
    160             FieldObject->ByteOffset,
    161             FieldObject->NameColumn,
    162             AslGbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage);
    163     }
    164     else
    165     {
    166         AslCommonError (Level, MessageId, 0,
    167             0, 0, 0, 0, ExtraMessage);
    168     }
    169 }
    170 
    171 
    172 /*******************************************************************************
    173  *
    174  * FUNCTION:    DtFatal
    175  *
    176  * PARAMETERS:  None
    177  *
    178  * RETURN:      None
    179  *
    180  * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
    181  *              compile or I/O errors
    182  *
    183  ******************************************************************************/
    184 
    185 void
    186 DtFatal (
    187     UINT16                  MessageId,
    188     DT_FIELD                *FieldObject,
    189     char                    *ExtraMessage)
    190 {
    191 
    192     DtError (ASL_ERROR, MessageId, FieldObject, ExtraMessage);
    193 
    194 /*
    195  * TBD: remove this entire function, DtFatal
    196  *
    197  * We cannot abort the compiler on error, because we may be compiling a
    198  * list of files. We must move on to the next file.
    199  */
    200 #ifdef __OBSOLETE
    201     CmCleanupAndExit ();
    202     exit (1);
    203 #endif
    204 }
    205 
    206 
    207 /*******************************************************************************
    208  *
    209  * FUNCTION:    DtDoConstant
    210  *
    211  * PARAMETERS:  String              - Only hex constants are supported,
    212  *                                    regardless of whether the 0x prefix
    213  *                                    is used
    214  *
    215  * RETURN:      Converted Integer
    216  *
    217  * DESCRIPTION: Convert a string to an integer, with overflow/error checking.
    218  *
    219  ******************************************************************************/
    220 
    221 UINT64
    222 DtDoConstant (
    223     char                    *String)
    224 {
    225     UINT64                  ConvertedInteger;
    226 
    227 
    228     /*
    229      * TBD: The ImplicitStrtoul64 function does not report overflow
    230      * conditions. The input string is simply truncated. If it is
    231      * desired to report overflow to the table compiler, this should
    232      * somehow be added here. Note: integers that are prefixed with 0x
    233      * or not are both hex integers.
    234      */
    235     ConvertedInteger = AcpiUtImplicitStrtoul64 (String);
    236     return (ConvertedInteger);
    237 }
    238 
    239 /******************************************************************************
    240  *
    241  * FUNCTION:    DtGetFieldValue
    242  *
    243  * PARAMETERS:  Field               - Current field list pointer
    244  *
    245  * RETURN:      Field value
    246  *
    247  * DESCRIPTION: Get field value
    248  *
    249  *****************************************************************************/
    250 
    251 char *
    252 DtGetFieldValue (
    253     DT_FIELD                *Field)
    254 {
    255     if (!Field)
    256     {
    257         return (NULL);
    258     }
    259 
    260     return (Field->Value);
    261 }
    262 
    263 
    264 /******************************************************************************
    265  *
    266  * FUNCTION:    DtGetFieldType
    267  *
    268  * PARAMETERS:  Info                - Data table info
    269  *
    270  * RETURN:      Field type
    271  *
    272  * DESCRIPTION: Get field type
    273  *
    274  *****************************************************************************/
    275 
    276 UINT8
    277 DtGetFieldType (
    278     ACPI_DMTABLE_INFO       *Info)
    279 {
    280     UINT8                   Type;
    281 
    282 
    283     /* DT_FLAG means that this is the start of a block of flag bits */
    284     /* TBD - we can make these a separate opcode later */
    285 
    286     if (Info->Flags & DT_FLAG)
    287     {
    288         return (DT_FIELD_TYPE_FLAGS_INTEGER);
    289     }
    290 
    291     /* Type is based upon the opcode for this field in the info table */
    292 
    293     switch (Info->Opcode)
    294     {
    295     case ACPI_DMT_FLAG0:
    296     case ACPI_DMT_FLAG1:
    297     case ACPI_DMT_FLAG2:
    298     case ACPI_DMT_FLAG3:
    299     case ACPI_DMT_FLAG4:
    300     case ACPI_DMT_FLAG5:
    301     case ACPI_DMT_FLAG6:
    302     case ACPI_DMT_FLAG7:
    303     case ACPI_DMT_FLAGS0:
    304     case ACPI_DMT_FLAGS1:
    305     case ACPI_DMT_FLAGS2:
    306     case ACPI_DMT_FLAGS8_2:
    307     case ACPI_DMT_FLAGS4:
    308     case ACPI_DMT_FLAGS4_0:
    309     case ACPI_DMT_FLAGS4_4:
    310     case ACPI_DMT_FLAGS4_8:
    311     case ACPI_DMT_FLAGS4_12:
    312     case ACPI_DMT_FLAGS16_16:
    313 
    314         Type = DT_FIELD_TYPE_FLAG;
    315         break;
    316 
    317     case ACPI_DMT_NAME4:
    318     case ACPI_DMT_SIG:
    319     case ACPI_DMT_NAME6:
    320     case ACPI_DMT_NAME8:
    321     case ACPI_DMT_STRING:
    322     case ACPI_DMT_IVRS_UNTERMINATED_STRING:
    323 
    324         Type = DT_FIELD_TYPE_STRING;
    325         break;
    326 
    327     case ACPI_DMT_BUFFER:
    328     case ACPI_DMT_RAW_BUFFER:
    329     case ACPI_DMT_BUF7:
    330     case ACPI_DMT_BUF10:
    331     case ACPI_DMT_BUF12:
    332     case ACPI_DMT_BUF16:
    333     case ACPI_DMT_BUF18:
    334     case ACPI_DMT_BUF128:
    335     case ACPI_DMT_PCI_PATH:
    336     case ACPI_DMT_PMTT_VENDOR:
    337 
    338         Type = DT_FIELD_TYPE_BUFFER;
    339         break;
    340 
    341     case ACPI_DMT_GAS:
    342     case ACPI_DMT_HESTNTFY:
    343     case ACPI_DMT_IORTMEM:
    344 
    345         Type = DT_FIELD_TYPE_INLINE_SUBTABLE;
    346         break;
    347 
    348     case ACPI_DMT_UNICODE:
    349     case ACPI_DMT_WPBT_UNICODE:
    350 
    351         Type = DT_FIELD_TYPE_UNICODE;
    352         break;
    353 
    354     case ACPI_DMT_UUID:
    355 
    356         Type = DT_FIELD_TYPE_UUID;
    357         break;
    358 
    359     case ACPI_DMT_DEVICE_PATH:
    360 
    361         Type = DT_FIELD_TYPE_DEVICE_PATH;
    362         break;
    363 
    364     case ACPI_DMT_LABEL:
    365 
    366         Type = DT_FIELD_TYPE_LABEL;
    367         break;
    368 
    369     default:
    370 
    371         Type = DT_FIELD_TYPE_INTEGER;
    372         break;
    373     }
    374 
    375     return (Type);
    376 }
    377 
    378 
    379 /******************************************************************************
    380  *
    381  * FUNCTION:    DtGetBufferLength
    382  *
    383  * PARAMETERS:  Buffer              - List of integers,
    384  *                                    for example "10 3A 4F 2E"
    385  *
    386  * RETURN:      Count of integer
    387  *
    388  * DESCRIPTION: Get length of bytes needed to store the integers
    389  *
    390  *****************************************************************************/
    391 
    392 UINT32
    393 DtGetBufferLength (
    394     char                    *Buffer)
    395 {
    396     UINT32                  ByteLength = 0;
    397 
    398 
    399     while (*Buffer)
    400     {
    401         if (*Buffer == ' ')
    402         {
    403             ByteLength++;
    404 
    405             while (*Buffer == ' ')
    406             {
    407                 Buffer++;
    408             }
    409         }
    410 
    411         Buffer++;
    412     }
    413 
    414     return (++ByteLength);
    415 }
    416 
    417 
    418 /******************************************************************************
    419  *
    420  * FUNCTION:    DtGetFieldLength
    421  *
    422  * PARAMETERS:  Field               - Current field
    423  *              Info                - Data table info
    424  *
    425  * RETURN:      Field length
    426  *
    427  * DESCRIPTION: Get length of bytes needed to compile the field
    428  *
    429  * Note: This function must remain in sync with AcpiDmDumpTable.
    430  *
    431  *****************************************************************************/
    432 
    433 UINT32
    434 DtGetFieldLength (
    435     DT_FIELD                *Field,
    436     ACPI_DMTABLE_INFO       *Info)
    437 {
    438     UINT32                  ByteLength = 0;
    439     char                    *Value;
    440 
    441 
    442     /* Length is based upon the opcode for this field in the info table */
    443 
    444     switch (Info->Opcode)
    445     {
    446     case ACPI_DMT_FLAG0:
    447     case ACPI_DMT_FLAG1:
    448     case ACPI_DMT_FLAG2:
    449     case ACPI_DMT_FLAG3:
    450     case ACPI_DMT_FLAG4:
    451     case ACPI_DMT_FLAG5:
    452     case ACPI_DMT_FLAG6:
    453     case ACPI_DMT_FLAG7:
    454     case ACPI_DMT_FLAGS0:
    455     case ACPI_DMT_FLAGS1:
    456     case ACPI_DMT_FLAGS2:
    457     case ACPI_DMT_FLAGS8_2:
    458     case ACPI_DMT_FLAGS4:
    459     case ACPI_DMT_FLAGS4_0:
    460     case ACPI_DMT_FLAGS4_4:
    461     case ACPI_DMT_FLAGS4_8:
    462     case ACPI_DMT_FLAGS4_12:
    463     case ACPI_DMT_FLAGS16_16:
    464     case ACPI_DMT_LABEL:
    465     case ACPI_DMT_EXTRA_TEXT:
    466 
    467         ByteLength = 0;
    468         break;
    469 
    470     case ACPI_DMT_UINT8:
    471     case ACPI_DMT_CHKSUM:
    472     case ACPI_DMT_SPACEID:
    473     case ACPI_DMT_ACCWIDTH:
    474     case ACPI_DMT_CEDT:
    475     case ACPI_DMT_IVRS:
    476     case ACPI_DMT_IVRS_DE:
    477     case ACPI_DMT_GTDT:
    478     case ACPI_DMT_MADT:
    479     case ACPI_DMT_NHLT1:
    480     case ACPI_DMT_NHLT1a:
    481     case ACPI_DMT_NHLT1b:
    482     case ACPI_DMT_NHLT1c:
    483     case ACPI_DMT_NHLT1d:
    484     case ACPI_DMT_NHLT1f:
    485     case ACPI_DMT_PCCT:
    486     case ACPI_DMT_PMTT:
    487     case ACPI_DMT_PPTT:
    488     case ACPI_DMT_RGRT:
    489     case ACPI_DMT_SDEV:
    490     case ACPI_DMT_SRAT:
    491     case ACPI_DMT_AEST:
    492     case ACPI_DMT_AEST_RES:
    493     case ACPI_DMT_AEST_XFACE:
    494     case ACPI_DMT_AEST_XRUPT:
    495     case ACPI_DMT_ASF:
    496     case ACPI_DMT_HESTNTYP:
    497     case ACPI_DMT_FADTPM:
    498     case ACPI_DMT_EINJACT:
    499     case ACPI_DMT_EINJINST:
    500     case ACPI_DMT_ERSTACT:
    501     case ACPI_DMT_ERSTINST:
    502     case ACPI_DMT_DMAR_SCOPE:
    503     case ACPI_DMT_VIOT:
    504 
    505         ByteLength = 1;
    506         break;
    507 
    508     case ACPI_DMT_UINT16:
    509     case ACPI_DMT_DMAR:
    510     case ACPI_DMT_HEST:
    511     case ACPI_DMT_HMAT:
    512     case ACPI_DMT_NFIT:
    513     case ACPI_DMT_NHLT1e:
    514     case ACPI_DMT_PCI_PATH:
    515     case ACPI_DMT_PHAT:
    516 
    517         ByteLength = 2;
    518         break;
    519 
    520     case ACPI_DMT_UINT24:
    521 
    522         ByteLength = 3;
    523         break;
    524 
    525     case ACPI_DMT_UINT32:
    526     case ACPI_DMT_AEST_CACHE:
    527     case ACPI_DMT_AEST_GIC:
    528     case ACPI_DMT_NAME4:
    529     case ACPI_DMT_SIG:
    530     case ACPI_DMT_LPIT:
    531     case ACPI_DMT_TPM2:
    532 
    533         ByteLength = 4;
    534         break;
    535 
    536     case ACPI_DMT_UINT40:
    537 
    538         ByteLength = 5;
    539         break;
    540 
    541     case ACPI_DMT_UINT48:
    542     case ACPI_DMT_NAME6:
    543 
    544         ByteLength = 6;
    545         break;
    546 
    547     case ACPI_DMT_UINT56:
    548     case ACPI_DMT_BUF7:
    549 
    550         ByteLength = 7;
    551         break;
    552 
    553     case ACPI_DMT_UINT64:
    554     case ACPI_DMT_NAME8:
    555 
    556         ByteLength = 8;
    557         break;
    558 
    559     case ACPI_DMT_STRING:
    560 
    561         Value = DtGetFieldValue (Field);
    562         if (Value)
    563         {
    564             ByteLength = strlen (Value) + 1;
    565         }
    566         else
    567         {   /* At this point, this is a fatal error */
    568 
    569             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Expected \"%s\"", Info->Name);
    570             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
    571             return (0);
    572         }
    573         break;
    574 
    575     case ACPI_DMT_IVRS_UNTERMINATED_STRING:
    576 
    577         Value = DtGetFieldValue (Field);
    578         if (Value)
    579         {
    580             ByteLength = strlen (Value);
    581         }
    582         else
    583         {   /* At this point, this is a fatal error */
    584 
    585             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Expected \"%s\"", Info->Name);
    586             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
    587             return (0);
    588         }
    589         break;
    590 
    591     case ACPI_DMT_GAS:
    592 
    593         ByteLength = sizeof (ACPI_GENERIC_ADDRESS);
    594         break;
    595 
    596     case ACPI_DMT_HESTNTFY:
    597 
    598         ByteLength = sizeof (ACPI_HEST_NOTIFY);
    599         break;
    600 
    601     case ACPI_DMT_IORTMEM:
    602 
    603         ByteLength = sizeof (ACPI_IORT_MEMORY_ACCESS);
    604         break;
    605 
    606     case ACPI_DMT_BUFFER:
    607     case ACPI_DMT_RAW_BUFFER:
    608     case ACPI_DMT_PMTT_VENDOR:
    609 
    610         Value = DtGetFieldValue (Field);
    611         if (Value)
    612         {
    613             ByteLength = DtGetBufferLength (Value);
    614         }
    615         else
    616         {   /* At this point, this is a fatal error */
    617 
    618             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Expected \"%s\"", Info->Name);
    619             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
    620             return (0);
    621         }
    622         break;
    623 
    624     case ACPI_DMT_BUF10:
    625 
    626         ByteLength = 10;
    627         break;
    628 
    629     case ACPI_DMT_BUF12:
    630 
    631         ByteLength = 12;
    632         break;
    633 
    634     case ACPI_DMT_BUF16:
    635     case ACPI_DMT_UUID:
    636 
    637         ByteLength = 16;
    638         break;
    639 
    640     case ACPI_DMT_BUF18:
    641 
    642         ByteLength = 18;
    643         break;
    644 
    645     case ACPI_DMT_BUF128:
    646 
    647         ByteLength = 128;
    648         break;
    649 
    650     case ACPI_DMT_UNICODE:
    651     case ACPI_DMT_WPBT_UNICODE:
    652 
    653         Value = DtGetFieldValue (Field);
    654 
    655         /* TBD: error if Value is NULL? (as below?) */
    656 
    657         ByteLength = (strlen (Value) + 1) * sizeof (UINT16);
    658         break;
    659 
    660     default:
    661 
    662         DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid table opcode");
    663         return (0);
    664     }
    665 
    666     return (ByteLength);
    667 }
    668 
    669 
    670 /******************************************************************************
    671  *
    672  * FUNCTION:    DtSum
    673  *
    674  * PARAMETERS:  DT_WALK_CALLBACK:
    675  *              Subtable            - Subtable
    676  *              Context             - Unused
    677  *              ReturnValue         - Store the checksum of subtable
    678  *
    679  * RETURN:      Status
    680  *
    681  * DESCRIPTION: Get the checksum of subtable
    682  *
    683  *****************************************************************************/
    684 
    685 static void
    686 DtSum (
    687     DT_SUBTABLE             *Subtable,
    688     void                    *Context,
    689     void                    *ReturnValue)
    690 {
    691     UINT8                   Checksum;
    692     UINT8                   *Sum = ReturnValue;
    693 
    694 
    695     Checksum = AcpiTbChecksum (Subtable->Buffer, Subtable->Length);
    696     *Sum = (UINT8) (*Sum + Checksum);
    697 }
    698 
    699 
    700 /******************************************************************************
    701  *
    702  * FUNCTION:    DtSetTableChecksum
    703  *
    704  * PARAMETERS:  ChecksumPointer     - Where to return the checksum
    705  *
    706  * RETURN:      None
    707  *
    708  * DESCRIPTION: Set checksum of the whole data table into the checksum field
    709  *
    710  *****************************************************************************/
    711 
    712 void
    713 DtSetTableChecksum (
    714     UINT8                   *ChecksumPointer)
    715 {
    716     UINT8                   Checksum = 0;
    717     UINT8                   OldSum;
    718 
    719 
    720     DtWalkTableTree (AslGbl_RootTable, DtSum, NULL, &Checksum);
    721 
    722     OldSum = *ChecksumPointer;
    723     Checksum = (UINT8) (Checksum - OldSum);
    724 
    725     /* Compute the final checksum */
    726 
    727     Checksum = (UINT8) (0 - Checksum);
    728     *ChecksumPointer = Checksum;
    729 }
    730 
    731 
    732 /******************************************************************************
    733  *
    734  * FUNCTION:    DtSetTableLength
    735  *
    736  * PARAMETERS:  None
    737  *
    738  * RETURN:      None
    739  *
    740  * DESCRIPTION: Walk the subtables and set all the length fields
    741  *
    742  *****************************************************************************/
    743 
    744 void
    745 DtSetTableLength (
    746     void)
    747 {
    748     DT_SUBTABLE             *ParentTable;
    749     DT_SUBTABLE             *ChildTable;
    750 
    751 
    752     ParentTable = AslGbl_RootTable;
    753     ChildTable = NULL;
    754 
    755     if (!ParentTable)
    756     {
    757         return;
    758     }
    759 
    760     DtSetSubtableLength (ParentTable);
    761 
    762     while (1)
    763     {
    764         ChildTable = DtGetNextSubtable (ParentTable, ChildTable);
    765         if (ChildTable)
    766         {
    767             if (ChildTable->LengthField)
    768             {
    769                 DtSetSubtableLength (ChildTable);
    770             }
    771 
    772             if (ChildTable->Child)
    773             {
    774                 ParentTable = ChildTable;
    775                 ChildTable = NULL;
    776             }
    777             else
    778             {
    779                 ParentTable->TotalLength += ChildTable->TotalLength;
    780                 if (ParentTable->LengthField)
    781                 {
    782                     DtSetSubtableLength (ParentTable);
    783                 }
    784             }
    785         }
    786         else
    787         {
    788             ChildTable = ParentTable;
    789 
    790             if (ChildTable == AslGbl_RootTable)
    791             {
    792                 break;
    793             }
    794 
    795             ParentTable = DtGetParentSubtable (ParentTable);
    796 
    797             ParentTable->TotalLength += ChildTable->TotalLength;
    798             if (ParentTable->LengthField)
    799             {
    800                 DtSetSubtableLength (ParentTable);
    801             }
    802         }
    803     }
    804 }
    805 
    806 
    807 /******************************************************************************
    808  *
    809  * FUNCTION:    DtWalkTableTree
    810  *
    811  * PARAMETERS:  StartTable          - Subtable in the tree where walking begins
    812  *              UserFunction        - Called during the walk
    813  *              Context             - Passed to user function
    814  *              ReturnValue         - The return value of UserFunction
    815  *
    816  * RETURN:      None
    817  *
    818  * DESCRIPTION: Performs a depth-first walk of the subtable tree
    819  *
    820  *****************************************************************************/
    821 
    822 void
    823 DtWalkTableTree (
    824     DT_SUBTABLE             *StartTable,
    825     DT_WALK_CALLBACK        UserFunction,
    826     void                    *Context,
    827     void                    *ReturnValue)
    828 {
    829     DT_SUBTABLE             *ParentTable;
    830     DT_SUBTABLE             *ChildTable;
    831 
    832 
    833     ParentTable = StartTable;
    834     ChildTable = NULL;
    835 
    836     if (!ParentTable)
    837     {
    838         return;
    839     }
    840 
    841     UserFunction (ParentTable, Context, ReturnValue);
    842 
    843     while (1)
    844     {
    845         ChildTable = DtGetNextSubtable (ParentTable, ChildTable);
    846         if (ChildTable)
    847         {
    848             UserFunction (ChildTable, Context, ReturnValue);
    849 
    850             if (ChildTable->Child)
    851             {
    852                 ParentTable = ChildTable;
    853                 ChildTable = NULL;
    854             }
    855         }
    856         else
    857         {
    858             ChildTable = ParentTable;
    859             if (ChildTable == AslGbl_RootTable)
    860             {
    861                 break;
    862             }
    863 
    864             ParentTable = DtGetParentSubtable (ParentTable);
    865 
    866             if (ChildTable->Peer == StartTable)
    867             {
    868                 break;
    869             }
    870         }
    871     }
    872 }
    873