Home | History | Annotate | Line # | Download | only in compiler
dtutils.c revision 1.23
      1 /******************************************************************************
      2  *
      3  * Module Name: dtutils.c - Utility routines for the data table compiler
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2023, 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_BUF32:
    335     case ACPI_DMT_BUF112:
    336     case ACPI_DMT_BUF128:
    337     case ACPI_DMT_PCI_PATH:
    338     case ACPI_DMT_PMTT_VENDOR:
    339 
    340         Type = DT_FIELD_TYPE_BUFFER;
    341         break;
    342 
    343     case ACPI_DMT_GAS:
    344     case ACPI_DMT_HESTNTFY:
    345     case ACPI_DMT_IORTMEM:
    346 
    347         Type = DT_FIELD_TYPE_INLINE_SUBTABLE;
    348         break;
    349 
    350     case ACPI_DMT_UNICODE:
    351     case ACPI_DMT_WPBT_UNICODE:
    352 
    353         Type = DT_FIELD_TYPE_UNICODE;
    354         break;
    355 
    356     case ACPI_DMT_UUID:
    357 
    358         Type = DT_FIELD_TYPE_UUID;
    359         break;
    360 
    361     case ACPI_DMT_DEVICE_PATH:
    362 
    363         Type = DT_FIELD_TYPE_DEVICE_PATH;
    364         break;
    365 
    366     case ACPI_DMT_LABEL:
    367 
    368         Type = DT_FIELD_TYPE_LABEL;
    369         break;
    370 
    371     default:
    372 
    373         Type = DT_FIELD_TYPE_INTEGER;
    374         break;
    375     }
    376 
    377     return (Type);
    378 }
    379 
    380 
    381 /******************************************************************************
    382  *
    383  * FUNCTION:    DtGetBufferLength
    384  *
    385  * PARAMETERS:  Buffer              - List of integers,
    386  *                                    for example "10 3A 4F 2E"
    387  *
    388  * RETURN:      Count of integer
    389  *
    390  * DESCRIPTION: Get length of bytes needed to store the integers
    391  *
    392  *****************************************************************************/
    393 
    394 UINT32
    395 DtGetBufferLength (
    396     char                    *Buffer)
    397 {
    398     UINT32                  ByteLength = 0;
    399 
    400 
    401     while (*Buffer)
    402     {
    403         if (*Buffer == ' ')
    404         {
    405             ByteLength++;
    406 
    407             while (*Buffer == ' ')
    408             {
    409                 Buffer++;
    410             }
    411         }
    412 
    413         Buffer++;
    414     }
    415 
    416     return (++ByteLength);
    417 }
    418 
    419 
    420 /******************************************************************************
    421  *
    422  * FUNCTION:    DtGetFieldLength
    423  *
    424  * PARAMETERS:  Field               - Current field
    425  *              Info                - Data table info
    426  *
    427  * RETURN:      Field length
    428  *
    429  * DESCRIPTION: Get length of bytes needed to compile the field
    430  *
    431  * Note: This function must remain in sync with AcpiDmDumpTable.
    432  *
    433  *****************************************************************************/
    434 
    435 UINT32
    436 DtGetFieldLength (
    437     DT_FIELD                *Field,
    438     ACPI_DMTABLE_INFO       *Info)
    439 {
    440     UINT32                  ByteLength = 0;
    441     char                    *Value;
    442 
    443 
    444     /* Length is based upon the opcode for this field in the info table */
    445 
    446     switch (Info->Opcode)
    447     {
    448     case ACPI_DMT_FLAG0:
    449     case ACPI_DMT_FLAG1:
    450     case ACPI_DMT_FLAG2:
    451     case ACPI_DMT_FLAG3:
    452     case ACPI_DMT_FLAG4:
    453     case ACPI_DMT_FLAG5:
    454     case ACPI_DMT_FLAG6:
    455     case ACPI_DMT_FLAG7:
    456     case ACPI_DMT_FLAGS0:
    457     case ACPI_DMT_FLAGS1:
    458     case ACPI_DMT_FLAGS2:
    459     case ACPI_DMT_FLAGS8_2:
    460     case ACPI_DMT_FLAGS4:
    461     case ACPI_DMT_FLAGS4_0:
    462     case ACPI_DMT_FLAGS4_4:
    463     case ACPI_DMT_FLAGS4_8:
    464     case ACPI_DMT_FLAGS4_12:
    465     case ACPI_DMT_FLAGS16_16:
    466     case ACPI_DMT_LABEL:
    467     case ACPI_DMT_EXTRA_TEXT:
    468 
    469         ByteLength = 0;
    470         break;
    471 
    472     case ACPI_DMT_UINT8:
    473     case ACPI_DMT_CHKSUM:
    474     case ACPI_DMT_SPACEID:
    475     case ACPI_DMT_ACCWIDTH:
    476     case ACPI_DMT_CEDT:
    477     case ACPI_DMT_IVRS:
    478     case ACPI_DMT_IVRS_DE:
    479     case ACPI_DMT_GTDT:
    480     case ACPI_DMT_MADT:
    481     case ACPI_DMT_MPAM_LOCATOR:
    482     case ACPI_DMT_PCCT:
    483     case ACPI_DMT_PMTT:
    484     case ACPI_DMT_PPTT:
    485     case ACPI_DMT_RGRT:
    486     case ACPI_DMT_SDEV:
    487     case ACPI_DMT_SRAT:
    488     case ACPI_DMT_AEST:
    489     case ACPI_DMT_AEST_RES:
    490     case ACPI_DMT_AEST_XFACE:
    491     case ACPI_DMT_AEST_XRUPT:
    492     case ACPI_DMT_ASF:
    493     case ACPI_DMT_CDAT:
    494     case ACPI_DMT_HESTNTYP:
    495     case ACPI_DMT_FADTPM:
    496     case ACPI_DMT_EINJACT:
    497     case ACPI_DMT_EINJINST:
    498     case ACPI_DMT_ERSTACT:
    499     case ACPI_DMT_ERSTINST:
    500     case ACPI_DMT_DMAR_SCOPE:
    501     case ACPI_DMT_VIOT:
    502 
    503         ByteLength = 1;
    504         break;
    505 
    506     case ACPI_DMT_ASPT:
    507     case ACPI_DMT_UINT16:
    508     case ACPI_DMT_DMAR:
    509     case ACPI_DMT_HEST:
    510     case ACPI_DMT_HMAT:
    511     case ACPI_DMT_NFIT:
    512     case ACPI_DMT_PCI_PATH:
    513     case ACPI_DMT_PHAT:
    514 
    515         ByteLength = 2;
    516         break;
    517 
    518     case ACPI_DMT_UINT24:
    519 
    520         ByteLength = 3;
    521         break;
    522 
    523     case ACPI_DMT_UINT32:
    524     case ACPI_DMT_AEST_CACHE:
    525     case ACPI_DMT_AEST_GIC:
    526     case ACPI_DMT_NAME4:
    527     case ACPI_DMT_SIG:
    528     case ACPI_DMT_LPIT:
    529     case ACPI_DMT_TPM2:
    530 
    531         ByteLength = 4;
    532         break;
    533 
    534     case ACPI_DMT_UINT40:
    535 
    536         ByteLength = 5;
    537         break;
    538 
    539     case ACPI_DMT_UINT48:
    540     case ACPI_DMT_NAME6:
    541 
    542         ByteLength = 6;
    543         break;
    544 
    545     case ACPI_DMT_UINT56:
    546     case ACPI_DMT_BUF7:
    547 
    548         ByteLength = 7;
    549         break;
    550 
    551     case ACPI_DMT_UINT64:
    552     case ACPI_DMT_NAME8:
    553 
    554         ByteLength = 8;
    555         break;
    556 
    557     case ACPI_DMT_STRING:
    558 
    559         Value = DtGetFieldValue (Field);
    560         if (Value)
    561         {
    562             ByteLength = strlen (Value) + 1;
    563         }
    564         else
    565         {   /* At this point, this is a fatal error */
    566 
    567             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Expected \"%s\"", Info->Name);
    568             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
    569             return (0);
    570         }
    571         break;
    572 
    573     case ACPI_DMT_IVRS_UNTERMINATED_STRING:
    574 
    575         Value = DtGetFieldValue (Field);
    576         if (Value)
    577         {
    578             ByteLength = strlen (Value);
    579         }
    580         else
    581         {   /* At this point, this is a fatal error */
    582 
    583             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Expected \"%s\"", Info->Name);
    584             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
    585             return (0);
    586         }
    587         break;
    588 
    589     case ACPI_DMT_GAS:
    590 
    591         ByteLength = sizeof (ACPI_GENERIC_ADDRESS);
    592         break;
    593 
    594     case ACPI_DMT_HESTNTFY:
    595 
    596         ByteLength = sizeof (ACPI_HEST_NOTIFY);
    597         break;
    598 
    599     case ACPI_DMT_IORTMEM:
    600 
    601         ByteLength = sizeof (ACPI_IORT_MEMORY_ACCESS);
    602         break;
    603 
    604     case ACPI_DMT_BUFFER:
    605     case ACPI_DMT_RAW_BUFFER:
    606     case ACPI_DMT_PMTT_VENDOR:
    607 
    608         Value = DtGetFieldValue (Field);
    609         if (Value)
    610         {
    611             ByteLength = DtGetBufferLength (Value);
    612         }
    613         else
    614         {   /* At this point, this is a fatal error */
    615 
    616             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Expected \"%s\"", Info->Name);
    617             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer);
    618             return (0);
    619         }
    620         break;
    621 
    622     case ACPI_DMT_BUF10:
    623 
    624         ByteLength = 10;
    625         break;
    626 
    627     case ACPI_DMT_BUF12:
    628 
    629         ByteLength = 12;
    630         break;
    631 
    632     case ACPI_DMT_BUF16:
    633     case ACPI_DMT_UUID:
    634 
    635         ByteLength = 16;
    636         break;
    637 
    638     case ACPI_DMT_BUF18:
    639 
    640         ByteLength = 18;
    641         break;
    642 
    643     case ACPI_DMT_BUF32:
    644 
    645         ByteLength = 32;
    646         break;
    647 
    648     case ACPI_DMT_BUF112:
    649 
    650         ByteLength = 112;
    651         break;
    652 
    653     case ACPI_DMT_BUF128:
    654 
    655         ByteLength = 128;
    656         break;
    657 
    658     case ACPI_DMT_UNICODE:
    659     case ACPI_DMT_WPBT_UNICODE:
    660 
    661         Value = DtGetFieldValue (Field);
    662 
    663         /* TBD: error if Value is NULL? (as below?) */
    664 
    665         ByteLength = (strlen (Value) + 1) * sizeof (UINT16);
    666         break;
    667 
    668     default:
    669 
    670         DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid table opcode");
    671         return (0);
    672     }
    673 
    674     return (ByteLength);
    675 }
    676 
    677 
    678 /******************************************************************************
    679  *
    680  * FUNCTION:    DtSum
    681  *
    682  * PARAMETERS:  DT_WALK_CALLBACK:
    683  *              Subtable            - Subtable
    684  *              Context             - Unused
    685  *              ReturnValue         - Store the checksum of subtable
    686  *
    687  * RETURN:      Status
    688  *
    689  * DESCRIPTION: Get the checksum of subtable
    690  *
    691  *****************************************************************************/
    692 
    693 static void
    694 DtSum (
    695     DT_SUBTABLE             *Subtable,
    696     void                    *Context,
    697     void                    *ReturnValue)
    698 {
    699     UINT8                   Checksum;
    700     UINT8                   *Sum = ReturnValue;
    701 
    702 
    703     Checksum = AcpiUtChecksum (Subtable->Buffer, Subtable->Length);
    704     *Sum = (UINT8) (*Sum + Checksum);
    705 }
    706 
    707 
    708 /******************************************************************************
    709  *
    710  * FUNCTION:    DtSetTableChecksum
    711  *
    712  * PARAMETERS:  ChecksumPointer     - Where to return the checksum
    713  *
    714  * RETURN:      None
    715  *
    716  * DESCRIPTION: Set checksum of the whole data table into the checksum field
    717  *
    718  *****************************************************************************/
    719 
    720 void
    721 DtSetTableChecksum (
    722     UINT8                   *ChecksumPointer)
    723 {
    724     UINT8                   Checksum = 0;
    725     UINT8                   OldSum;
    726 
    727 
    728     DtWalkTableTree (AslGbl_RootTable, DtSum, NULL, &Checksum);
    729 
    730     OldSum = *ChecksumPointer;
    731     Checksum = (UINT8) (Checksum - OldSum);
    732 
    733     /* Compute the final checksum */
    734 
    735     Checksum = (UINT8) (0 - Checksum);
    736     *ChecksumPointer = Checksum;
    737 }
    738 
    739 
    740 /******************************************************************************
    741  *
    742  * FUNCTION:    DtSetTableLength
    743  *
    744  * PARAMETERS:  None
    745  *
    746  * RETURN:      None
    747  *
    748  * DESCRIPTION: Walk the subtables and set all the length fields
    749  *
    750  *****************************************************************************/
    751 
    752 void
    753 DtSetTableLength (
    754     void)
    755 {
    756     DT_SUBTABLE             *ParentTable;
    757     DT_SUBTABLE             *ChildTable;
    758 
    759 
    760     ParentTable = AslGbl_RootTable;
    761     ChildTable = NULL;
    762 
    763     if (!ParentTable)
    764     {
    765         return;
    766     }
    767 
    768     DtSetSubtableLength (ParentTable);
    769 
    770     while (1)
    771     {
    772         ChildTable = DtGetNextSubtable (ParentTable, ChildTable);
    773         if (ChildTable)
    774         {
    775             if (ChildTable->LengthField)
    776             {
    777                 DtSetSubtableLength (ChildTable);
    778             }
    779 
    780             if (ChildTable->Child)
    781             {
    782                 ParentTable = ChildTable;
    783                 ChildTable = NULL;
    784             }
    785             else
    786             {
    787                 ParentTable->TotalLength += ChildTable->TotalLength;
    788                 if (ParentTable->LengthField)
    789                 {
    790                     DtSetSubtableLength (ParentTable);
    791                 }
    792             }
    793         }
    794         else
    795         {
    796             ChildTable = ParentTable;
    797 
    798             if (ChildTable == AslGbl_RootTable)
    799             {
    800                 break;
    801             }
    802 
    803             ParentTable = DtGetParentSubtable (ParentTable);
    804 
    805             ParentTable->TotalLength += ChildTable->TotalLength;
    806             if (ParentTable->LengthField)
    807             {
    808                 DtSetSubtableLength (ParentTable);
    809             }
    810         }
    811     }
    812 }
    813 
    814 
    815 /******************************************************************************
    816  *
    817  * FUNCTION:    DtWalkTableTree
    818  *
    819  * PARAMETERS:  StartTable          - Subtable in the tree where walking begins
    820  *              UserFunction        - Called during the walk
    821  *              Context             - Passed to user function
    822  *              ReturnValue         - The return value of UserFunction
    823  *
    824  * RETURN:      None
    825  *
    826  * DESCRIPTION: Performs a depth-first walk of the subtable tree
    827  *
    828  *****************************************************************************/
    829 
    830 void
    831 DtWalkTableTree (
    832     DT_SUBTABLE             *StartTable,
    833     DT_WALK_CALLBACK        UserFunction,
    834     void                    *Context,
    835     void                    *ReturnValue)
    836 {
    837     DT_SUBTABLE             *ParentTable;
    838     DT_SUBTABLE             *ChildTable;
    839 
    840 
    841     ParentTable = StartTable;
    842     ChildTable = NULL;
    843 
    844     if (!ParentTable)
    845     {
    846         return;
    847     }
    848 
    849     UserFunction (ParentTable, Context, ReturnValue);
    850 
    851     while (1)
    852     {
    853         ChildTable = DtGetNextSubtable (ParentTable, ChildTable);
    854         if (ChildTable)
    855         {
    856             UserFunction (ChildTable, Context, ReturnValue);
    857 
    858             if (ChildTable->Child)
    859             {
    860                 ParentTable = ChildTable;
    861                 ChildTable = NULL;
    862             }
    863         }
    864         else
    865         {
    866             ChildTable = ParentTable;
    867             if (ChildTable == AslGbl_RootTable)
    868             {
    869                 break;
    870             }
    871 
    872             ParentTable = DtGetParentSubtable (ParentTable);
    873 
    874             if (ChildTable->Peer == StartTable)
    875             {
    876                 break;
    877             }
    878         }
    879     }
    880 }
    881