Home | History | Annotate | Line # | Download | only in compiler
dtfield.c revision 1.2
      1  1.1    jruoho /******************************************************************************
      2  1.1    jruoho  *
      3  1.1    jruoho  * Module Name: dtfield.c - Code generation for individual source fields
      4  1.1    jruoho  *
      5  1.1    jruoho  *****************************************************************************/
      6  1.1    jruoho 
      7  1.2  christos /*
      8  1.2  christos  * Copyright (C) 2000 - 2013, 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.2  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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.1    jruoho #define __DTFIELD_C__
     45  1.1    jruoho 
     46  1.1    jruoho #include "aslcompiler.h"
     47  1.1    jruoho #include "dtcompiler.h"
     48  1.1    jruoho 
     49  1.1    jruoho #define _COMPONENT          DT_COMPILER
     50  1.1    jruoho         ACPI_MODULE_NAME    ("dtfield")
     51  1.1    jruoho 
     52  1.1    jruoho 
     53  1.1    jruoho /* Local prototypes */
     54  1.1    jruoho 
     55  1.1    jruoho static void
     56  1.1    jruoho DtCompileString (
     57  1.1    jruoho     UINT8                   *Buffer,
     58  1.1    jruoho     DT_FIELD                *Field,
     59  1.1    jruoho     UINT32                  ByteLength);
     60  1.1    jruoho 
     61  1.2  christos static void
     62  1.2  christos DtCompileUnicode (
     63  1.2  christos     UINT8                   *Buffer,
     64  1.2  christos     DT_FIELD                *Field,
     65  1.2  christos     UINT32                  ByteLength);
     66  1.1    jruoho 
     67  1.2  christos static ACPI_STATUS
     68  1.2  christos DtCompileUuid (
     69  1.1    jruoho     UINT8                   *Buffer,
     70  1.1    jruoho     DT_FIELD                *Field,
     71  1.1    jruoho     UINT32                  ByteLength);
     72  1.1    jruoho 
     73  1.2  christos static char *
     74  1.2  christos DtNormalizeBuffer (
     75  1.2  christos     char                    *Buffer,
     76  1.2  christos     UINT32                  *Count);
     77  1.2  christos 
     78  1.1    jruoho 
     79  1.1    jruoho /******************************************************************************
     80  1.1    jruoho  *
     81  1.1    jruoho  * FUNCTION:    DtCompileOneField
     82  1.1    jruoho  *
     83  1.1    jruoho  * PARAMETERS:  Buffer              - Output buffer
     84  1.1    jruoho  *              Field               - Field to be compiled
     85  1.1    jruoho  *              ByteLength          - Byte length of the field
     86  1.1    jruoho  *              Type                - Field type
     87  1.1    jruoho  *
     88  1.1    jruoho  * RETURN:      None
     89  1.1    jruoho  *
     90  1.1    jruoho  * DESCRIPTION: Compile a field value to binary
     91  1.1    jruoho  *
     92  1.1    jruoho  *****************************************************************************/
     93  1.1    jruoho 
     94  1.1    jruoho void
     95  1.1    jruoho DtCompileOneField (
     96  1.1    jruoho     UINT8                   *Buffer,
     97  1.1    jruoho     DT_FIELD                *Field,
     98  1.1    jruoho     UINT32                  ByteLength,
     99  1.1    jruoho     UINT8                   Type,
    100  1.1    jruoho     UINT8                   Flags)
    101  1.1    jruoho {
    102  1.2  christos     ACPI_STATUS             Status;
    103  1.1    jruoho 
    104  1.1    jruoho     switch (Type)
    105  1.1    jruoho     {
    106  1.1    jruoho     case DT_FIELD_TYPE_INTEGER:
    107  1.2  christos 
    108  1.1    jruoho         DtCompileInteger (Buffer, Field, ByteLength, Flags);
    109  1.1    jruoho         break;
    110  1.1    jruoho 
    111  1.1    jruoho     case DT_FIELD_TYPE_STRING:
    112  1.2  christos 
    113  1.1    jruoho         DtCompileString (Buffer, Field, ByteLength);
    114  1.1    jruoho         break;
    115  1.1    jruoho 
    116  1.2  christos     case DT_FIELD_TYPE_UUID:
    117  1.2  christos 
    118  1.2  christos         Status = DtCompileUuid (Buffer, Field, ByteLength);
    119  1.2  christos         if (ACPI_SUCCESS (Status))
    120  1.2  christos         {
    121  1.2  christos             break;
    122  1.2  christos         }
    123  1.2  christos 
    124  1.2  christos         /* Fall through. */
    125  1.2  christos 
    126  1.1    jruoho     case DT_FIELD_TYPE_BUFFER:
    127  1.2  christos 
    128  1.1    jruoho         DtCompileBuffer (Buffer, Field->Value, Field, ByteLength);
    129  1.1    jruoho         break;
    130  1.1    jruoho 
    131  1.2  christos     case DT_FIELD_TYPE_UNICODE:
    132  1.2  christos 
    133  1.2  christos         DtCompileUnicode (Buffer, Field, ByteLength);
    134  1.2  christos         break;
    135  1.2  christos 
    136  1.2  christos     case DT_FIELD_TYPE_DEVICE_PATH:
    137  1.2  christos 
    138  1.1    jruoho         break;
    139  1.1    jruoho 
    140  1.1    jruoho     default:
    141  1.2  christos 
    142  1.1    jruoho         DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid field type");
    143  1.1    jruoho         break;
    144  1.1    jruoho     }
    145  1.1    jruoho }
    146  1.1    jruoho 
    147  1.1    jruoho 
    148  1.1    jruoho /******************************************************************************
    149  1.1    jruoho  *
    150  1.1    jruoho  * FUNCTION:    DtCompileString
    151  1.1    jruoho  *
    152  1.1    jruoho  * PARAMETERS:  Buffer              - Output buffer
    153  1.1    jruoho  *              Field               - String to be copied to buffer
    154  1.1    jruoho  *              ByteLength          - Maximum length of string
    155  1.1    jruoho  *
    156  1.1    jruoho  * RETURN:      None
    157  1.1    jruoho  *
    158  1.1    jruoho  * DESCRIPTION: Copy string to the buffer
    159  1.1    jruoho  *
    160  1.1    jruoho  *****************************************************************************/
    161  1.1    jruoho 
    162  1.1    jruoho static void
    163  1.1    jruoho DtCompileString (
    164  1.1    jruoho     UINT8                   *Buffer,
    165  1.1    jruoho     DT_FIELD                *Field,
    166  1.1    jruoho     UINT32                  ByteLength)
    167  1.1    jruoho {
    168  1.1    jruoho     UINT32                  Length;
    169  1.1    jruoho 
    170  1.1    jruoho 
    171  1.1    jruoho     Length = ACPI_STRLEN (Field->Value);
    172  1.1    jruoho 
    173  1.1    jruoho     /* Check if the string is too long for the field */
    174  1.1    jruoho 
    175  1.1    jruoho     if (Length > ByteLength)
    176  1.1    jruoho     {
    177  1.2  christos         snprintf (MsgBuffer, sizeof(MsgBuffer), "Maximum %u characters", ByteLength);
    178  1.1    jruoho         DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, MsgBuffer);
    179  1.1    jruoho         Length = ByteLength;
    180  1.1    jruoho     }
    181  1.1    jruoho 
    182  1.2  christos     ACPI_MEMCPY (Buffer, Field->Value, Length);
    183  1.2  christos }
    184  1.2  christos 
    185  1.2  christos 
    186  1.2  christos /******************************************************************************
    187  1.2  christos  *
    188  1.2  christos  * FUNCTION:    DtCompileUnicode
    189  1.2  christos  *
    190  1.2  christos  * PARAMETERS:  Buffer              - Output buffer
    191  1.2  christos  *              Field               - String to be copied to buffer
    192  1.2  christos  *              ByteLength          - Maximum length of string
    193  1.2  christos  *
    194  1.2  christos  * RETURN:      None
    195  1.2  christos  *
    196  1.2  christos  * DESCRIPTION: Convert ASCII string to Unicode string
    197  1.2  christos  *
    198  1.2  christos  * Note:  The Unicode string is 16 bits per character, no leading signature,
    199  1.2  christos  *        with a 16-bit terminating NULL.
    200  1.2  christos  *
    201  1.2  christos  *****************************************************************************/
    202  1.2  christos 
    203  1.2  christos static void
    204  1.2  christos DtCompileUnicode (
    205  1.2  christos     UINT8                   *Buffer,
    206  1.2  christos     DT_FIELD                *Field,
    207  1.2  christos     UINT32                  ByteLength)
    208  1.2  christos {
    209  1.2  christos     UINT32                  Count;
    210  1.2  christos     UINT32                  i;
    211  1.2  christos     char                    *AsciiString;
    212  1.2  christos     UINT16                  *UnicodeString;
    213  1.2  christos 
    214  1.2  christos 
    215  1.2  christos     AsciiString = Field->Value;
    216  1.2  christos     UnicodeString = (UINT16 *) Buffer;
    217  1.2  christos     Count = ACPI_STRLEN (AsciiString) + 1;
    218  1.2  christos 
    219  1.2  christos     /* Convert to Unicode string (including null terminator) */
    220  1.2  christos 
    221  1.2  christos     for (i = 0; i < Count; i++)
    222  1.2  christos     {
    223  1.2  christos         UnicodeString[i] = (UINT16) AsciiString[i];
    224  1.2  christos     }
    225  1.2  christos }
    226  1.2  christos 
    227  1.2  christos 
    228  1.2  christos /*******************************************************************************
    229  1.2  christos  *
    230  1.2  christos  * FUNCTION:    DtCompileUuid
    231  1.2  christos  *
    232  1.2  christos  * PARAMETERS:  Buffer              - Output buffer
    233  1.2  christos  *              Field               - String to be copied to buffer
    234  1.2  christos  *              ByteLength          - Maximum length of string
    235  1.2  christos  *
    236  1.2  christos  * RETURN:      None
    237  1.2  christos  *
    238  1.2  christos  * DESCRIPTION: Convert UUID string to 16-byte buffer
    239  1.2  christos  *
    240  1.2  christos  ******************************************************************************/
    241  1.2  christos 
    242  1.2  christos static ACPI_STATUS
    243  1.2  christos DtCompileUuid (
    244  1.2  christos     UINT8                   *Buffer,
    245  1.2  christos     DT_FIELD                *Field,
    246  1.2  christos     UINT32                  ByteLength)
    247  1.2  christos {
    248  1.2  christos     char                    *InString;
    249  1.2  christos     ACPI_STATUS             Status;
    250  1.2  christos 
    251  1.2  christos 
    252  1.2  christos     InString = Field->Value;
    253  1.1    jruoho 
    254  1.2  christos     Status = AuValidateUuid (InString);
    255  1.2  christos     if (ACPI_FAILURE (Status))
    256  1.2  christos     {
    257  1.2  christos         snprintf (MsgBuffer, sizeof(MsgBuffer), "%s", Field->Value);
    258  1.2  christos         DtNameError (ASL_ERROR, ASL_MSG_INVALID_UUID, Field, MsgBuffer);
    259  1.2  christos     }
    260  1.2  christos     else
    261  1.2  christos     {
    262  1.2  christos         Status = AuConvertStringToUuid (InString, (char *) Buffer);
    263  1.2  christos     }
    264  1.2  christos 
    265  1.2  christos     return (Status);
    266  1.1    jruoho }
    267  1.1    jruoho 
    268  1.1    jruoho 
    269  1.1    jruoho /******************************************************************************
    270  1.1    jruoho  *
    271  1.1    jruoho  * FUNCTION:    DtCompileInteger
    272  1.1    jruoho  *
    273  1.1    jruoho  * PARAMETERS:  Buffer              - Output buffer
    274  1.1    jruoho  *              Field               - Field obj with Integer to be compiled
    275  1.1    jruoho  *              ByteLength          - Byte length of the integer
    276  1.2  christos  *              Flags               - Additional compile info
    277  1.1    jruoho  *
    278  1.1    jruoho  * RETURN:      None
    279  1.1    jruoho  *
    280  1.2  christos  * DESCRIPTION: Compile an integer. Supports integer expressions with C-style
    281  1.2  christos  *              operators.
    282  1.1    jruoho  *
    283  1.1    jruoho  *****************************************************************************/
    284  1.1    jruoho 
    285  1.1    jruoho void
    286  1.1    jruoho DtCompileInteger (
    287  1.1    jruoho     UINT8                   *Buffer,
    288  1.1    jruoho     DT_FIELD                *Field,
    289  1.1    jruoho     UINT32                  ByteLength,
    290  1.1    jruoho     UINT8                   Flags)
    291  1.1    jruoho {
    292  1.2  christos     UINT64                  Value;
    293  1.1    jruoho     UINT64                  MaxValue;
    294  1.1    jruoho     ACPI_STATUS             Status;
    295  1.1    jruoho 
    296  1.1    jruoho 
    297  1.2  christos     /* Output buffer byte length must be in range 1-8 */
    298  1.1    jruoho 
    299  1.1    jruoho     if ((ByteLength > 8) || (ByteLength == 0))
    300  1.1    jruoho     {
    301  1.1    jruoho         DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
    302  1.1    jruoho             "Invalid internal Byte length");
    303  1.1    jruoho         return;
    304  1.1    jruoho     }
    305  1.1    jruoho 
    306  1.2  christos     /* Resolve integer expression to a single integer value */
    307  1.1    jruoho 
    308  1.2  christos     Status = DtResolveIntegerExpression (Field, &Value);
    309  1.1    jruoho     if (ACPI_FAILURE (Status))
    310  1.1    jruoho     {
    311  1.2  christos         return;
    312  1.1    jruoho     }
    313  1.1    jruoho 
    314  1.1    jruoho     /* Ensure that reserved fields are set to zero */
    315  1.1    jruoho     /* TBD: should we set to zero, or just make this an ERROR? */
    316  1.1    jruoho     /* TBD: Probably better to use a flag */
    317  1.1    jruoho 
    318  1.1    jruoho     if (!ACPI_STRCMP (Field->Name, "Reserved") &&
    319  1.1    jruoho         (Value != 0))
    320  1.1    jruoho     {
    321  1.1    jruoho         DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
    322  1.1    jruoho             "Setting to zero");
    323  1.1    jruoho         Value = 0;
    324  1.1    jruoho     }
    325  1.1    jruoho 
    326  1.1    jruoho     /* Check if the value must be non-zero */
    327  1.1    jruoho 
    328  1.1    jruoho     if ((Value == 0) && (Flags & DT_NON_ZERO))
    329  1.1    jruoho     {
    330  1.1    jruoho         DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL);
    331  1.1    jruoho     }
    332  1.1    jruoho 
    333  1.1    jruoho     /*
    334  1.1    jruoho      * Generate the maximum value for the data type (ByteLength)
    335  1.1    jruoho      * Note: construct chosen for maximum portability
    336  1.1    jruoho      */
    337  1.1    jruoho     MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8));
    338  1.1    jruoho 
    339  1.1    jruoho     /* Validate that the input value is within range of the target */
    340  1.1    jruoho 
    341  1.1    jruoho     if (Value > MaxValue)
    342  1.1    jruoho     {
    343  1.2  christos         snprintf (MsgBuffer, sizeof(MsgBuffer), "%8.8X%8.8X - max %u bytes",
    344  1.2  christos             ACPI_FORMAT_UINT64 (Value), ByteLength);
    345  1.1    jruoho         DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer);
    346  1.1    jruoho     }
    347  1.1    jruoho 
    348  1.1    jruoho     ACPI_MEMCPY (Buffer, &Value, ByteLength);
    349  1.1    jruoho     return;
    350  1.1    jruoho }
    351  1.1    jruoho 
    352  1.1    jruoho 
    353  1.1    jruoho /******************************************************************************
    354  1.1    jruoho  *
    355  1.2  christos  * FUNCTION:    DtNormalizeBuffer
    356  1.1    jruoho  *
    357  1.2  christos  * PARAMETERS:  Buffer              - Input buffer
    358  1.2  christos  *              Count               - Output the count of hex number in
    359  1.2  christos  *                                    the Buffer
    360  1.1    jruoho  *
    361  1.2  christos  * RETURN:      The normalized buffer, freed by caller
    362  1.1    jruoho  *
    363  1.2  christos  * DESCRIPTION: [1A,2B,3C,4D] or 1A, 2B, 3C, 4D will be normalized
    364  1.2  christos  *              to 1A 2B 3C 4D
    365  1.1    jruoho  *
    366  1.1    jruoho  *****************************************************************************/
    367  1.1    jruoho 
    368  1.1    jruoho static char *
    369  1.2  christos DtNormalizeBuffer (
    370  1.2  christos     char                    *Buffer,
    371  1.2  christos     UINT32                  *Count)
    372  1.1    jruoho {
    373  1.2  christos     char                    *NewBuffer;
    374  1.2  christos     char                    *TmpBuffer;
    375  1.2  christos     UINT32                  BufferCount = 0;
    376  1.2  christos     BOOLEAN                 Separator = TRUE;
    377  1.2  christos     char                    c;
    378  1.2  christos 
    379  1.2  christos 
    380  1.2  christos     NewBuffer = UtLocalCalloc (ACPI_STRLEN (Buffer) + 1);
    381  1.2  christos     TmpBuffer = NewBuffer;
    382  1.2  christos 
    383  1.2  christos     while ((c = *Buffer++))
    384  1.2  christos     {
    385  1.2  christos         switch (c)
    386  1.2  christos         {
    387  1.2  christos         /* Valid separators */
    388  1.1    jruoho 
    389  1.2  christos         case '[':
    390  1.2  christos         case ']':
    391  1.2  christos         case ' ':
    392  1.2  christos         case ',':
    393  1.1    jruoho 
    394  1.2  christos             Separator = TRUE;
    395  1.2  christos             break;
    396  1.1    jruoho 
    397  1.2  christos         default:
    398  1.1    jruoho 
    399  1.2  christos             if (Separator)
    400  1.2  christos             {
    401  1.2  christos                 /* Insert blank as the standard separator */
    402  1.2  christos 
    403  1.2  christos                 if (NewBuffer[0])
    404  1.2  christos                 {
    405  1.2  christos                     *TmpBuffer++ = ' ';
    406  1.2  christos                     BufferCount++;
    407  1.2  christos                 }
    408  1.2  christos 
    409  1.2  christos                 Separator = FALSE;
    410  1.2  christos             }
    411  1.2  christos 
    412  1.2  christos             *TmpBuffer++ = c;
    413  1.2  christos             break;
    414  1.2  christos         }
    415  1.2  christos     }
    416  1.2  christos 
    417  1.2  christos     *Count = BufferCount + 1;
    418  1.2  christos     return (NewBuffer);
    419  1.1    jruoho }
    420  1.1    jruoho 
    421  1.1    jruoho 
    422  1.1    jruoho /******************************************************************************
    423  1.1    jruoho  *
    424  1.1    jruoho  * FUNCTION:    DtCompileBuffer
    425  1.1    jruoho  *
    426  1.1    jruoho  * PARAMETERS:  Buffer              - Output buffer
    427  1.1    jruoho  *              StringValue         - Integer list to be compiled
    428  1.1    jruoho  *              Field               - Current field object
    429  1.1    jruoho  *              ByteLength          - Byte length of the integer list
    430  1.1    jruoho  *
    431  1.1    jruoho  * RETURN:      Count of remaining data in the input list
    432  1.1    jruoho  *
    433  1.1    jruoho  * DESCRIPTION: Compile and pack an integer list, for example
    434  1.1    jruoho  *              "AA 1F 20 3B" ==> Buffer[] = {0xAA,0x1F,0x20,0x3B}
    435  1.1    jruoho  *
    436  1.1    jruoho  *****************************************************************************/
    437  1.1    jruoho 
    438  1.1    jruoho UINT32
    439  1.1    jruoho DtCompileBuffer (
    440  1.1    jruoho     UINT8                   *Buffer,
    441  1.1    jruoho     char                    *StringValue,
    442  1.1    jruoho     DT_FIELD                *Field,
    443  1.1    jruoho     UINT32                  ByteLength)
    444  1.1    jruoho {
    445  1.1    jruoho     ACPI_STATUS             Status;
    446  1.1    jruoho     char                    Hex[3];
    447  1.1    jruoho     UINT64                  Value;
    448  1.1    jruoho     UINT32                  i;
    449  1.1    jruoho     UINT32                  Count;
    450  1.1    jruoho 
    451  1.1    jruoho 
    452  1.2  christos     /* Allow several different types of value separators */
    453  1.2  christos 
    454  1.2  christos     StringValue = DtNormalizeBuffer (StringValue, &Count);
    455  1.1    jruoho 
    456  1.1    jruoho     Hex[2] = 0;
    457  1.1    jruoho     for (i = 0; i < Count; i++)
    458  1.1    jruoho     {
    459  1.2  christos         /* Each element of StringValue is three chars */
    460  1.2  christos 
    461  1.2  christos         Hex[0] = StringValue[(3 * i)];
    462  1.2  christos         Hex[1] = StringValue[(3 * i) + 1];
    463  1.1    jruoho 
    464  1.1    jruoho         /* Convert one hex byte */
    465  1.1    jruoho 
    466  1.1    jruoho         Value = 0;
    467  1.1    jruoho         Status = DtStrtoul64 (Hex, &Value);
    468  1.1    jruoho         if (ACPI_FAILURE (Status))
    469  1.1    jruoho         {
    470  1.1    jruoho             DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, MsgBuffer);
    471  1.2  christos             goto Exit;
    472  1.1    jruoho         }
    473  1.1    jruoho 
    474  1.1    jruoho         Buffer[i] = (UINT8) Value;
    475  1.1    jruoho     }
    476  1.1    jruoho 
    477  1.2  christos Exit:
    478  1.2  christos     ACPI_FREE (StringValue);
    479  1.1    jruoho     return (ByteLength - Count);
    480  1.1    jruoho }
    481  1.1    jruoho 
    482  1.1    jruoho 
    483  1.1    jruoho /******************************************************************************
    484  1.1    jruoho  *
    485  1.1    jruoho  * FUNCTION:    DtCompileFlag
    486  1.1    jruoho  *
    487  1.1    jruoho  * PARAMETERS:  Buffer              - Output buffer
    488  1.1    jruoho  *              Field               - Field to be compiled
    489  1.1    jruoho  *              Info                - Flag info
    490  1.1    jruoho  *
    491  1.2  christos  * RETURN:
    492  1.1    jruoho  *
    493  1.1    jruoho  * DESCRIPTION: Compile a flag
    494  1.1    jruoho  *
    495  1.1    jruoho  *****************************************************************************/
    496  1.1    jruoho 
    497  1.2  christos void
    498  1.1    jruoho DtCompileFlag (
    499  1.1    jruoho     UINT8                   *Buffer,
    500  1.1    jruoho     DT_FIELD                *Field,
    501  1.2  christos     ACPI_DMTABLE_INFO       *Info)
    502  1.1    jruoho {
    503  1.1    jruoho     UINT64                  Value = 0;
    504  1.1    jruoho     UINT32                  BitLength = 1;
    505  1.2  christos     UINT8                   BitPosition = 0;
    506  1.1    jruoho     ACPI_STATUS             Status;
    507  1.1    jruoho 
    508  1.1    jruoho 
    509  1.1    jruoho     Status = DtStrtoul64 (Field->Value, &Value);
    510  1.1    jruoho     if (ACPI_FAILURE (Status))
    511  1.1    jruoho     {
    512  1.1    jruoho         DtError (ASL_ERROR, ASL_MSG_INVALID_HEX_INTEGER, Field, NULL);
    513  1.1    jruoho     }
    514  1.1    jruoho 
    515  1.1    jruoho     switch (Info->Opcode)
    516  1.1    jruoho     {
    517  1.1    jruoho     case ACPI_DMT_FLAG0:
    518  1.1    jruoho     case ACPI_DMT_FLAG1:
    519  1.1    jruoho     case ACPI_DMT_FLAG2:
    520  1.1    jruoho     case ACPI_DMT_FLAG3:
    521  1.1    jruoho     case ACPI_DMT_FLAG4:
    522  1.1    jruoho     case ACPI_DMT_FLAG5:
    523  1.1    jruoho     case ACPI_DMT_FLAG6:
    524  1.1    jruoho     case ACPI_DMT_FLAG7:
    525  1.1    jruoho 
    526  1.2  christos         BitPosition = Info->Opcode;
    527  1.1    jruoho         BitLength = 1;
    528  1.1    jruoho         break;
    529  1.1    jruoho 
    530  1.1    jruoho     case ACPI_DMT_FLAGS0:
    531  1.2  christos 
    532  1.2  christos         BitPosition = 0;
    533  1.2  christos         BitLength = 2;
    534  1.2  christos         break;
    535  1.2  christos 
    536  1.2  christos 
    537  1.2  christos     case ACPI_DMT_FLAGS1:
    538  1.2  christos 
    539  1.2  christos         BitPosition = 1;
    540  1.2  christos         BitLength = 2;
    541  1.2  christos         break;
    542  1.2  christos 
    543  1.2  christos 
    544  1.1    jruoho     case ACPI_DMT_FLAGS2:
    545  1.1    jruoho 
    546  1.2  christos         BitPosition = 2;
    547  1.2  christos         BitLength = 2;
    548  1.2  christos         break;
    549  1.2  christos 
    550  1.2  christos     case ACPI_DMT_FLAGS4:
    551  1.2  christos 
    552  1.2  christos         BitPosition = 4;
    553  1.1    jruoho         BitLength = 2;
    554  1.1    jruoho         break;
    555  1.1    jruoho 
    556  1.1    jruoho     default:
    557  1.1    jruoho 
    558  1.1    jruoho         DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid flag opcode");
    559  1.1    jruoho         break;
    560  1.1    jruoho     }
    561  1.1    jruoho 
    562  1.1    jruoho     /* Check range of the input flag value */
    563  1.1    jruoho 
    564  1.1    jruoho     if (Value >= ((UINT64) 1 << BitLength))
    565  1.1    jruoho     {
    566  1.2  christos         snprintf (MsgBuffer, sizeof(MsgBuffer), "Maximum %u bit", BitLength);
    567  1.1    jruoho         DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, MsgBuffer);
    568  1.1    jruoho         Value = 0;
    569  1.1    jruoho     }
    570  1.1    jruoho 
    571  1.2  christos     *Buffer |= (UINT8) (Value << BitPosition);
    572  1.1    jruoho }
    573