Home | History | Annotate | Line # | Download | only in compiler
dtfield.c revision 1.1.1.2.2.2
      1  1.1.1.2.2.2  bouyer /******************************************************************************
      2  1.1.1.2.2.2  bouyer  *
      3  1.1.1.2.2.2  bouyer  * Module Name: dtfield.c - Code generation for individual source fields
      4  1.1.1.2.2.2  bouyer  *
      5  1.1.1.2.2.2  bouyer  *****************************************************************************/
      6  1.1.1.2.2.2  bouyer 
      7  1.1.1.2.2.2  bouyer /*
      8  1.1.1.2.2.2  bouyer  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.1.1.2.2.2  bouyer  * All rights reserved.
     10  1.1.1.2.2.2  bouyer  *
     11  1.1.1.2.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2.2.2  bouyer  * modification, are permitted provided that the following conditions
     13  1.1.1.2.2.2  bouyer  * are met:
     14  1.1.1.2.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2.2.2  bouyer  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2.2.2  bouyer  *    without modification.
     17  1.1.1.2.2.2  bouyer  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2.2.2  bouyer  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2.2.2  bouyer  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2.2.2  bouyer  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2.2.2  bouyer  *    binary redistribution.
     22  1.1.1.2.2.2  bouyer  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2.2.2  bouyer  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2.2.2  bouyer  *    from this software without specific prior written permission.
     25  1.1.1.2.2.2  bouyer  *
     26  1.1.1.2.2.2  bouyer  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2.2.2  bouyer  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2.2.2  bouyer  * Software Foundation.
     29  1.1.1.2.2.2  bouyer  *
     30  1.1.1.2.2.2  bouyer  * NO WARRANTY
     31  1.1.1.2.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2.2.2  bouyer  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2.2.2  bouyer  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2.2.2  bouyer  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2.2.2  bouyer  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2.2.2  bouyer  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2.2.2  bouyer  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2.2.2  bouyer  */
     43  1.1.1.2.2.2  bouyer 
     44  1.1.1.2.2.2  bouyer #define __DTFIELD_C__
     45  1.1.1.2.2.2  bouyer 
     46  1.1.1.2.2.2  bouyer #include "aslcompiler.h"
     47  1.1.1.2.2.2  bouyer #include "dtcompiler.h"
     48  1.1.1.2.2.2  bouyer 
     49  1.1.1.2.2.2  bouyer #define _COMPONENT          DT_COMPILER
     50  1.1.1.2.2.2  bouyer         ACPI_MODULE_NAME    ("dtfield")
     51  1.1.1.2.2.2  bouyer 
     52  1.1.1.2.2.2  bouyer 
     53  1.1.1.2.2.2  bouyer /* Local prototypes */
     54  1.1.1.2.2.2  bouyer 
     55  1.1.1.2.2.2  bouyer static void
     56  1.1.1.2.2.2  bouyer DtCompileString (
     57  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
     58  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
     59  1.1.1.2.2.2  bouyer     UINT32                  ByteLength);
     60  1.1.1.2.2.2  bouyer 
     61  1.1.1.2.2.2  bouyer static void
     62  1.1.1.2.2.2  bouyer DtCompileUnicode (
     63  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
     64  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
     65  1.1.1.2.2.2  bouyer     UINT32                  ByteLength);
     66  1.1.1.2.2.2  bouyer 
     67  1.1.1.2.2.2  bouyer static ACPI_STATUS
     68  1.1.1.2.2.2  bouyer DtCompileUuid (
     69  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
     70  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
     71  1.1.1.2.2.2  bouyer     UINT32                  ByteLength);
     72  1.1.1.2.2.2  bouyer 
     73  1.1.1.2.2.2  bouyer static char *
     74  1.1.1.2.2.2  bouyer DtNormalizeBuffer (
     75  1.1.1.2.2.2  bouyer     char                    *Buffer,
     76  1.1.1.2.2.2  bouyer     UINT32                  *Count);
     77  1.1.1.2.2.2  bouyer 
     78  1.1.1.2.2.2  bouyer 
     79  1.1.1.2.2.2  bouyer /******************************************************************************
     80  1.1.1.2.2.2  bouyer  *
     81  1.1.1.2.2.2  bouyer  * FUNCTION:    DtCompileOneField
     82  1.1.1.2.2.2  bouyer  *
     83  1.1.1.2.2.2  bouyer  * PARAMETERS:  Buffer              - Output buffer
     84  1.1.1.2.2.2  bouyer  *              Field               - Field to be compiled
     85  1.1.1.2.2.2  bouyer  *              ByteLength          - Byte length of the field
     86  1.1.1.2.2.2  bouyer  *              Type                - Field type
     87  1.1.1.2.2.2  bouyer  *
     88  1.1.1.2.2.2  bouyer  * RETURN:      None
     89  1.1.1.2.2.2  bouyer  *
     90  1.1.1.2.2.2  bouyer  * DESCRIPTION: Compile a field value to binary
     91  1.1.1.2.2.2  bouyer  *
     92  1.1.1.2.2.2  bouyer  *****************************************************************************/
     93  1.1.1.2.2.2  bouyer 
     94  1.1.1.2.2.2  bouyer void
     95  1.1.1.2.2.2  bouyer DtCompileOneField (
     96  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
     97  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
     98  1.1.1.2.2.2  bouyer     UINT32                  ByteLength,
     99  1.1.1.2.2.2  bouyer     UINT8                   Type,
    100  1.1.1.2.2.2  bouyer     UINT8                   Flags)
    101  1.1.1.2.2.2  bouyer {
    102  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status;
    103  1.1.1.2.2.2  bouyer 
    104  1.1.1.2.2.2  bouyer     switch (Type)
    105  1.1.1.2.2.2  bouyer     {
    106  1.1.1.2.2.2  bouyer     case DT_FIELD_TYPE_INTEGER:
    107  1.1.1.2.2.2  bouyer         DtCompileInteger (Buffer, Field, ByteLength, Flags);
    108  1.1.1.2.2.2  bouyer         break;
    109  1.1.1.2.2.2  bouyer 
    110  1.1.1.2.2.2  bouyer     case DT_FIELD_TYPE_STRING:
    111  1.1.1.2.2.2  bouyer         DtCompileString (Buffer, Field, ByteLength);
    112  1.1.1.2.2.2  bouyer         break;
    113  1.1.1.2.2.2  bouyer 
    114  1.1.1.2.2.2  bouyer     case DT_FIELD_TYPE_UUID:
    115  1.1.1.2.2.2  bouyer         Status = DtCompileUuid (Buffer, Field, ByteLength);
    116  1.1.1.2.2.2  bouyer         if (ACPI_SUCCESS (Status))
    117  1.1.1.2.2.2  bouyer         {
    118  1.1.1.2.2.2  bouyer             break;
    119  1.1.1.2.2.2  bouyer         }
    120  1.1.1.2.2.2  bouyer 
    121  1.1.1.2.2.2  bouyer         /* Fall through. */
    122  1.1.1.2.2.2  bouyer 
    123  1.1.1.2.2.2  bouyer     case DT_FIELD_TYPE_BUFFER:
    124  1.1.1.2.2.2  bouyer         DtCompileBuffer (Buffer, Field->Value, Field, ByteLength);
    125  1.1.1.2.2.2  bouyer         break;
    126  1.1.1.2.2.2  bouyer 
    127  1.1.1.2.2.2  bouyer     case DT_FIELD_TYPE_UNICODE:
    128  1.1.1.2.2.2  bouyer         DtCompileUnicode (Buffer, Field, ByteLength);
    129  1.1.1.2.2.2  bouyer         break;
    130  1.1.1.2.2.2  bouyer 
    131  1.1.1.2.2.2  bouyer     case DT_FIELD_TYPE_DEVICE_PATH:
    132  1.1.1.2.2.2  bouyer         break;
    133  1.1.1.2.2.2  bouyer 
    134  1.1.1.2.2.2  bouyer     default:
    135  1.1.1.2.2.2  bouyer         DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid field type");
    136  1.1.1.2.2.2  bouyer         break;
    137  1.1.1.2.2.2  bouyer     }
    138  1.1.1.2.2.2  bouyer }
    139  1.1.1.2.2.2  bouyer 
    140  1.1.1.2.2.2  bouyer 
    141  1.1.1.2.2.2  bouyer /******************************************************************************
    142  1.1.1.2.2.2  bouyer  *
    143  1.1.1.2.2.2  bouyer  * FUNCTION:    DtCompileString
    144  1.1.1.2.2.2  bouyer  *
    145  1.1.1.2.2.2  bouyer  * PARAMETERS:  Buffer              - Output buffer
    146  1.1.1.2.2.2  bouyer  *              Field               - String to be copied to buffer
    147  1.1.1.2.2.2  bouyer  *              ByteLength          - Maximum length of string
    148  1.1.1.2.2.2  bouyer  *
    149  1.1.1.2.2.2  bouyer  * RETURN:      None
    150  1.1.1.2.2.2  bouyer  *
    151  1.1.1.2.2.2  bouyer  * DESCRIPTION: Copy string to the buffer
    152  1.1.1.2.2.2  bouyer  *
    153  1.1.1.2.2.2  bouyer  *****************************************************************************/
    154  1.1.1.2.2.2  bouyer 
    155  1.1.1.2.2.2  bouyer static void
    156  1.1.1.2.2.2  bouyer DtCompileString (
    157  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
    158  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
    159  1.1.1.2.2.2  bouyer     UINT32                  ByteLength)
    160  1.1.1.2.2.2  bouyer {
    161  1.1.1.2.2.2  bouyer     UINT32                  Length;
    162  1.1.1.2.2.2  bouyer 
    163  1.1.1.2.2.2  bouyer 
    164  1.1.1.2.2.2  bouyer     Length = ACPI_STRLEN (Field->Value);
    165  1.1.1.2.2.2  bouyer 
    166  1.1.1.2.2.2  bouyer     /* Check if the string is too long for the field */
    167  1.1.1.2.2.2  bouyer 
    168  1.1.1.2.2.2  bouyer     if (Length > ByteLength)
    169  1.1.1.2.2.2  bouyer     {
    170  1.1.1.2.2.2  bouyer         sprintf (MsgBuffer, "Maximum %u characters", ByteLength);
    171  1.1.1.2.2.2  bouyer         DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, MsgBuffer);
    172  1.1.1.2.2.2  bouyer         Length = ByteLength;
    173  1.1.1.2.2.2  bouyer     }
    174  1.1.1.2.2.2  bouyer 
    175  1.1.1.2.2.2  bouyer     ACPI_MEMCPY (Buffer, Field->Value, Length);
    176  1.1.1.2.2.2  bouyer }
    177  1.1.1.2.2.2  bouyer 
    178  1.1.1.2.2.2  bouyer 
    179  1.1.1.2.2.2  bouyer /******************************************************************************
    180  1.1.1.2.2.2  bouyer  *
    181  1.1.1.2.2.2  bouyer  * FUNCTION:    DtCompileUnicode
    182  1.1.1.2.2.2  bouyer  *
    183  1.1.1.2.2.2  bouyer  * PARAMETERS:  Buffer              - Output buffer
    184  1.1.1.2.2.2  bouyer  *              Field               - String to be copied to buffer
    185  1.1.1.2.2.2  bouyer  *              ByteLength          - Maximum length of string
    186  1.1.1.2.2.2  bouyer  *
    187  1.1.1.2.2.2  bouyer  * RETURN:      None
    188  1.1.1.2.2.2  bouyer  *
    189  1.1.1.2.2.2  bouyer  * DESCRIPTION: Convert ASCII string to Unicode string
    190  1.1.1.2.2.2  bouyer  *
    191  1.1.1.2.2.2  bouyer  * Note:  The Unicode string is 16 bits per character, no leading signature,
    192  1.1.1.2.2.2  bouyer  *        with a 16-bit terminating NULL.
    193  1.1.1.2.2.2  bouyer  *
    194  1.1.1.2.2.2  bouyer  *****************************************************************************/
    195  1.1.1.2.2.2  bouyer 
    196  1.1.1.2.2.2  bouyer static void
    197  1.1.1.2.2.2  bouyer DtCompileUnicode (
    198  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
    199  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
    200  1.1.1.2.2.2  bouyer     UINT32                  ByteLength)
    201  1.1.1.2.2.2  bouyer {
    202  1.1.1.2.2.2  bouyer     UINT32                  Count;
    203  1.1.1.2.2.2  bouyer     UINT32                  i;
    204  1.1.1.2.2.2  bouyer     char                    *AsciiString;
    205  1.1.1.2.2.2  bouyer     UINT16                  *UnicodeString;
    206  1.1.1.2.2.2  bouyer 
    207  1.1.1.2.2.2  bouyer 
    208  1.1.1.2.2.2  bouyer     AsciiString = Field->Value;
    209  1.1.1.2.2.2  bouyer     UnicodeString = (UINT16 *) Buffer;
    210  1.1.1.2.2.2  bouyer     Count = ACPI_STRLEN (AsciiString) + 1;
    211  1.1.1.2.2.2  bouyer 
    212  1.1.1.2.2.2  bouyer     /* Convert to Unicode string (including null terminator) */
    213  1.1.1.2.2.2  bouyer 
    214  1.1.1.2.2.2  bouyer     for (i = 0; i < Count; i++)
    215  1.1.1.2.2.2  bouyer     {
    216  1.1.1.2.2.2  bouyer         UnicodeString[i] = (UINT16) AsciiString[i];
    217  1.1.1.2.2.2  bouyer     }
    218  1.1.1.2.2.2  bouyer }
    219  1.1.1.2.2.2  bouyer 
    220  1.1.1.2.2.2  bouyer 
    221  1.1.1.2.2.2  bouyer /*******************************************************************************
    222  1.1.1.2.2.2  bouyer  *
    223  1.1.1.2.2.2  bouyer  * FUNCTION:    DtCompileUuid
    224  1.1.1.2.2.2  bouyer  *
    225  1.1.1.2.2.2  bouyer  * PARAMETERS:  Buffer              - Output buffer
    226  1.1.1.2.2.2  bouyer  *              Field               - String to be copied to buffer
    227  1.1.1.2.2.2  bouyer  *              ByteLength          - Maximum length of string
    228  1.1.1.2.2.2  bouyer  *
    229  1.1.1.2.2.2  bouyer  * RETURN:      None
    230  1.1.1.2.2.2  bouyer  *
    231  1.1.1.2.2.2  bouyer  * DESCRIPTION: Convert UUID string to 16-byte buffer
    232  1.1.1.2.2.2  bouyer  *
    233  1.1.1.2.2.2  bouyer  ******************************************************************************/
    234  1.1.1.2.2.2  bouyer 
    235  1.1.1.2.2.2  bouyer static ACPI_STATUS
    236  1.1.1.2.2.2  bouyer DtCompileUuid (
    237  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
    238  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
    239  1.1.1.2.2.2  bouyer     UINT32                  ByteLength)
    240  1.1.1.2.2.2  bouyer {
    241  1.1.1.2.2.2  bouyer     char                    *InString;
    242  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status;
    243  1.1.1.2.2.2  bouyer 
    244  1.1.1.2.2.2  bouyer 
    245  1.1.1.2.2.2  bouyer     InString = Field->Value;
    246  1.1.1.2.2.2  bouyer 
    247  1.1.1.2.2.2  bouyer     Status = AuValidateUuid (InString);
    248  1.1.1.2.2.2  bouyer     if (ACPI_FAILURE (Status))
    249  1.1.1.2.2.2  bouyer     {
    250  1.1.1.2.2.2  bouyer         sprintf (MsgBuffer, "%s", Field->Value);
    251  1.1.1.2.2.2  bouyer         DtNameError (ASL_ERROR, ASL_MSG_INVALID_UUID, Field, MsgBuffer);
    252  1.1.1.2.2.2  bouyer     }
    253  1.1.1.2.2.2  bouyer     else
    254  1.1.1.2.2.2  bouyer     {
    255  1.1.1.2.2.2  bouyer         Status = AuConvertStringToUuid (InString, (char *) Buffer);
    256  1.1.1.2.2.2  bouyer     }
    257  1.1.1.2.2.2  bouyer 
    258  1.1.1.2.2.2  bouyer     return (Status);
    259  1.1.1.2.2.2  bouyer }
    260  1.1.1.2.2.2  bouyer 
    261  1.1.1.2.2.2  bouyer 
    262  1.1.1.2.2.2  bouyer /******************************************************************************
    263  1.1.1.2.2.2  bouyer  *
    264  1.1.1.2.2.2  bouyer  * FUNCTION:    DtCompileInteger
    265  1.1.1.2.2.2  bouyer  *
    266  1.1.1.2.2.2  bouyer  * PARAMETERS:  Buffer              - Output buffer
    267  1.1.1.2.2.2  bouyer  *              Field               - Field obj with Integer to be compiled
    268  1.1.1.2.2.2  bouyer  *              ByteLength          - Byte length of the integer
    269  1.1.1.2.2.2  bouyer  *              Flags               - Additional compile info
    270  1.1.1.2.2.2  bouyer  *
    271  1.1.1.2.2.2  bouyer  * RETURN:      None
    272  1.1.1.2.2.2  bouyer  *
    273  1.1.1.2.2.2  bouyer  * DESCRIPTION: Compile an integer. Supports integer expressions with C-style
    274  1.1.1.2.2.2  bouyer  *              operators.
    275  1.1.1.2.2.2  bouyer  *
    276  1.1.1.2.2.2  bouyer  *****************************************************************************/
    277  1.1.1.2.2.2  bouyer 
    278  1.1.1.2.2.2  bouyer void
    279  1.1.1.2.2.2  bouyer DtCompileInteger (
    280  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
    281  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
    282  1.1.1.2.2.2  bouyer     UINT32                  ByteLength,
    283  1.1.1.2.2.2  bouyer     UINT8                   Flags)
    284  1.1.1.2.2.2  bouyer {
    285  1.1.1.2.2.2  bouyer     UINT64                  Value;
    286  1.1.1.2.2.2  bouyer     UINT64                  MaxValue;
    287  1.1.1.2.2.2  bouyer 
    288  1.1.1.2.2.2  bouyer 
    289  1.1.1.2.2.2  bouyer     /* Output buffer byte length must be in range 1-8 */
    290  1.1.1.2.2.2  bouyer 
    291  1.1.1.2.2.2  bouyer     if ((ByteLength > 8) || (ByteLength == 0))
    292  1.1.1.2.2.2  bouyer     {
    293  1.1.1.2.2.2  bouyer         DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
    294  1.1.1.2.2.2  bouyer             "Invalid internal Byte length");
    295  1.1.1.2.2.2  bouyer         return;
    296  1.1.1.2.2.2  bouyer     }
    297  1.1.1.2.2.2  bouyer 
    298  1.1.1.2.2.2  bouyer     /* Resolve integer expression to a single integer value */
    299  1.1.1.2.2.2  bouyer 
    300  1.1.1.2.2.2  bouyer     Value = DtResolveIntegerExpression (Field);
    301  1.1.1.2.2.2  bouyer 
    302  1.1.1.2.2.2  bouyer     /* Ensure that reserved fields are set to zero */
    303  1.1.1.2.2.2  bouyer     /* TBD: should we set to zero, or just make this an ERROR? */
    304  1.1.1.2.2.2  bouyer     /* TBD: Probably better to use a flag */
    305  1.1.1.2.2.2  bouyer 
    306  1.1.1.2.2.2  bouyer     if (!ACPI_STRCMP (Field->Name, "Reserved") &&
    307  1.1.1.2.2.2  bouyer         (Value != 0))
    308  1.1.1.2.2.2  bouyer     {
    309  1.1.1.2.2.2  bouyer         DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
    310  1.1.1.2.2.2  bouyer             "Setting to zero");
    311  1.1.1.2.2.2  bouyer         Value = 0;
    312  1.1.1.2.2.2  bouyer     }
    313  1.1.1.2.2.2  bouyer 
    314  1.1.1.2.2.2  bouyer     /* Check if the value must be non-zero */
    315  1.1.1.2.2.2  bouyer 
    316  1.1.1.2.2.2  bouyer     if ((Value == 0) && (Flags & DT_NON_ZERO))
    317  1.1.1.2.2.2  bouyer     {
    318  1.1.1.2.2.2  bouyer         DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL);
    319  1.1.1.2.2.2  bouyer     }
    320  1.1.1.2.2.2  bouyer 
    321  1.1.1.2.2.2  bouyer     /*
    322  1.1.1.2.2.2  bouyer      * Generate the maximum value for the data type (ByteLength)
    323  1.1.1.2.2.2  bouyer      * Note: construct chosen for maximum portability
    324  1.1.1.2.2.2  bouyer      */
    325  1.1.1.2.2.2  bouyer     MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8));
    326  1.1.1.2.2.2  bouyer 
    327  1.1.1.2.2.2  bouyer     /* Validate that the input value is within range of the target */
    328  1.1.1.2.2.2  bouyer 
    329  1.1.1.2.2.2  bouyer     if (Value > MaxValue)
    330  1.1.1.2.2.2  bouyer     {
    331  1.1.1.2.2.2  bouyer         sprintf (MsgBuffer, "%8.8X%8.8X", ACPI_FORMAT_UINT64 (Value));
    332  1.1.1.2.2.2  bouyer         DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer);
    333  1.1.1.2.2.2  bouyer     }
    334  1.1.1.2.2.2  bouyer 
    335  1.1.1.2.2.2  bouyer     ACPI_MEMCPY (Buffer, &Value, ByteLength);
    336  1.1.1.2.2.2  bouyer     return;
    337  1.1.1.2.2.2  bouyer }
    338  1.1.1.2.2.2  bouyer 
    339  1.1.1.2.2.2  bouyer 
    340  1.1.1.2.2.2  bouyer /******************************************************************************
    341  1.1.1.2.2.2  bouyer  *
    342  1.1.1.2.2.2  bouyer  * FUNCTION:    DtNormalizeBuffer
    343  1.1.1.2.2.2  bouyer  *
    344  1.1.1.2.2.2  bouyer  * PARAMETERS:  Buffer              - Input buffer
    345  1.1.1.2.2.2  bouyer  *              Count               - Output the count of hex number in
    346  1.1.1.2.2.2  bouyer  *                                    the Buffer
    347  1.1.1.2.2.2  bouyer  *
    348  1.1.1.2.2.2  bouyer  * RETURN:      The normalized buffer, freed by caller
    349  1.1.1.2.2.2  bouyer  *
    350  1.1.1.2.2.2  bouyer  * DESCRIPTION: [1A,2B,3C,4D] or 1A, 2B, 3C, 4D will be normalized
    351  1.1.1.2.2.2  bouyer  *              to 1A 2B 3C 4D
    352  1.1.1.2.2.2  bouyer  *
    353  1.1.1.2.2.2  bouyer  *****************************************************************************/
    354  1.1.1.2.2.2  bouyer 
    355  1.1.1.2.2.2  bouyer static char *
    356  1.1.1.2.2.2  bouyer DtNormalizeBuffer (
    357  1.1.1.2.2.2  bouyer     char                    *Buffer,
    358  1.1.1.2.2.2  bouyer     UINT32                  *Count)
    359  1.1.1.2.2.2  bouyer {
    360  1.1.1.2.2.2  bouyer     char                    *NewBuffer;
    361  1.1.1.2.2.2  bouyer     char                    *TmpBuffer;
    362  1.1.1.2.2.2  bouyer     UINT32                  BufferCount = 0;
    363  1.1.1.2.2.2  bouyer     BOOLEAN                 Separator = TRUE;
    364  1.1.1.2.2.2  bouyer     char                    c;
    365  1.1.1.2.2.2  bouyer 
    366  1.1.1.2.2.2  bouyer 
    367  1.1.1.2.2.2  bouyer     NewBuffer = UtLocalCalloc (ACPI_STRLEN (Buffer) + 1);
    368  1.1.1.2.2.2  bouyer     TmpBuffer = NewBuffer;
    369  1.1.1.2.2.2  bouyer 
    370  1.1.1.2.2.2  bouyer     while ((c = *Buffer++))
    371  1.1.1.2.2.2  bouyer     {
    372  1.1.1.2.2.2  bouyer         switch (c)
    373  1.1.1.2.2.2  bouyer         {
    374  1.1.1.2.2.2  bouyer         /* Valid separators */
    375  1.1.1.2.2.2  bouyer 
    376  1.1.1.2.2.2  bouyer         case '[':
    377  1.1.1.2.2.2  bouyer         case ']':
    378  1.1.1.2.2.2  bouyer         case ' ':
    379  1.1.1.2.2.2  bouyer         case ',':
    380  1.1.1.2.2.2  bouyer             Separator = TRUE;
    381  1.1.1.2.2.2  bouyer             break;
    382  1.1.1.2.2.2  bouyer 
    383  1.1.1.2.2.2  bouyer         default:
    384  1.1.1.2.2.2  bouyer             if (Separator)
    385  1.1.1.2.2.2  bouyer             {
    386  1.1.1.2.2.2  bouyer                 /* Insert blank as the standard separator */
    387  1.1.1.2.2.2  bouyer 
    388  1.1.1.2.2.2  bouyer                 if (NewBuffer[0])
    389  1.1.1.2.2.2  bouyer                 {
    390  1.1.1.2.2.2  bouyer                     *TmpBuffer++ = ' ';
    391  1.1.1.2.2.2  bouyer                     BufferCount++;
    392  1.1.1.2.2.2  bouyer                 }
    393  1.1.1.2.2.2  bouyer 
    394  1.1.1.2.2.2  bouyer                 Separator = FALSE;
    395  1.1.1.2.2.2  bouyer             }
    396  1.1.1.2.2.2  bouyer 
    397  1.1.1.2.2.2  bouyer             *TmpBuffer++ = c;
    398  1.1.1.2.2.2  bouyer             break;
    399  1.1.1.2.2.2  bouyer         }
    400  1.1.1.2.2.2  bouyer     }
    401  1.1.1.2.2.2  bouyer 
    402  1.1.1.2.2.2  bouyer     *Count = BufferCount + 1;
    403  1.1.1.2.2.2  bouyer     return (NewBuffer);
    404  1.1.1.2.2.2  bouyer }
    405  1.1.1.2.2.2  bouyer 
    406  1.1.1.2.2.2  bouyer 
    407  1.1.1.2.2.2  bouyer /******************************************************************************
    408  1.1.1.2.2.2  bouyer  *
    409  1.1.1.2.2.2  bouyer  * FUNCTION:    DtCompileBuffer
    410  1.1.1.2.2.2  bouyer  *
    411  1.1.1.2.2.2  bouyer  * PARAMETERS:  Buffer              - Output buffer
    412  1.1.1.2.2.2  bouyer  *              StringValue         - Integer list to be compiled
    413  1.1.1.2.2.2  bouyer  *              Field               - Current field object
    414  1.1.1.2.2.2  bouyer  *              ByteLength          - Byte length of the integer list
    415  1.1.1.2.2.2  bouyer  *
    416  1.1.1.2.2.2  bouyer  * RETURN:      Count of remaining data in the input list
    417  1.1.1.2.2.2  bouyer  *
    418  1.1.1.2.2.2  bouyer  * DESCRIPTION: Compile and pack an integer list, for example
    419  1.1.1.2.2.2  bouyer  *              "AA 1F 20 3B" ==> Buffer[] = {0xAA,0x1F,0x20,0x3B}
    420  1.1.1.2.2.2  bouyer  *
    421  1.1.1.2.2.2  bouyer  *****************************************************************************/
    422  1.1.1.2.2.2  bouyer 
    423  1.1.1.2.2.2  bouyer UINT32
    424  1.1.1.2.2.2  bouyer DtCompileBuffer (
    425  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
    426  1.1.1.2.2.2  bouyer     char                    *StringValue,
    427  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
    428  1.1.1.2.2.2  bouyer     UINT32                  ByteLength)
    429  1.1.1.2.2.2  bouyer {
    430  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status;
    431  1.1.1.2.2.2  bouyer     char                    Hex[3];
    432  1.1.1.2.2.2  bouyer     UINT64                  Value;
    433  1.1.1.2.2.2  bouyer     UINT32                  i;
    434  1.1.1.2.2.2  bouyer     UINT32                  Count;
    435  1.1.1.2.2.2  bouyer 
    436  1.1.1.2.2.2  bouyer 
    437  1.1.1.2.2.2  bouyer     /* Allow several different types of value separators */
    438  1.1.1.2.2.2  bouyer 
    439  1.1.1.2.2.2  bouyer     StringValue = DtNormalizeBuffer (StringValue, &Count);
    440  1.1.1.2.2.2  bouyer 
    441  1.1.1.2.2.2  bouyer     Hex[2] = 0;
    442  1.1.1.2.2.2  bouyer     for (i = 0; i < Count; i++)
    443  1.1.1.2.2.2  bouyer     {
    444  1.1.1.2.2.2  bouyer         /* Each element of StringValue is three chars */
    445  1.1.1.2.2.2  bouyer 
    446  1.1.1.2.2.2  bouyer         Hex[0] = StringValue[(3 * i)];
    447  1.1.1.2.2.2  bouyer         Hex[1] = StringValue[(3 * i) + 1];
    448  1.1.1.2.2.2  bouyer 
    449  1.1.1.2.2.2  bouyer         /* Convert one hex byte */
    450  1.1.1.2.2.2  bouyer 
    451  1.1.1.2.2.2  bouyer         Value = 0;
    452  1.1.1.2.2.2  bouyer         Status = DtStrtoul64 (Hex, &Value);
    453  1.1.1.2.2.2  bouyer         if (ACPI_FAILURE (Status))
    454  1.1.1.2.2.2  bouyer         {
    455  1.1.1.2.2.2  bouyer             DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, MsgBuffer);
    456  1.1.1.2.2.2  bouyer             return (ByteLength - Count);
    457  1.1.1.2.2.2  bouyer         }
    458  1.1.1.2.2.2  bouyer 
    459  1.1.1.2.2.2  bouyer         Buffer[i] = (UINT8) Value;
    460  1.1.1.2.2.2  bouyer     }
    461  1.1.1.2.2.2  bouyer 
    462  1.1.1.2.2.2  bouyer     ACPI_FREE (StringValue);
    463  1.1.1.2.2.2  bouyer     return (ByteLength - Count);
    464  1.1.1.2.2.2  bouyer }
    465  1.1.1.2.2.2  bouyer 
    466  1.1.1.2.2.2  bouyer 
    467  1.1.1.2.2.2  bouyer /******************************************************************************
    468  1.1.1.2.2.2  bouyer  *
    469  1.1.1.2.2.2  bouyer  * FUNCTION:    DtCompileFlag
    470  1.1.1.2.2.2  bouyer  *
    471  1.1.1.2.2.2  bouyer  * PARAMETERS:  Buffer              - Output buffer
    472  1.1.1.2.2.2  bouyer  *              Field               - Field to be compiled
    473  1.1.1.2.2.2  bouyer  *              Info                - Flag info
    474  1.1.1.2.2.2  bouyer  *
    475  1.1.1.2.2.2  bouyer  * RETURN:
    476  1.1.1.2.2.2  bouyer  *
    477  1.1.1.2.2.2  bouyer  * DESCRIPTION: Compile a flag
    478  1.1.1.2.2.2  bouyer  *
    479  1.1.1.2.2.2  bouyer  *****************************************************************************/
    480  1.1.1.2.2.2  bouyer 
    481  1.1.1.2.2.2  bouyer void
    482  1.1.1.2.2.2  bouyer DtCompileFlag (
    483  1.1.1.2.2.2  bouyer     UINT8                   *Buffer,
    484  1.1.1.2.2.2  bouyer     DT_FIELD                *Field,
    485  1.1.1.2.2.2  bouyer     ACPI_DMTABLE_INFO       *Info)
    486  1.1.1.2.2.2  bouyer {
    487  1.1.1.2.2.2  bouyer     UINT64                  Value = 0;
    488  1.1.1.2.2.2  bouyer     UINT32                  BitLength = 1;
    489  1.1.1.2.2.2  bouyer     UINT8                   BitPosition = 0;
    490  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status;
    491  1.1.1.2.2.2  bouyer 
    492  1.1.1.2.2.2  bouyer 
    493  1.1.1.2.2.2  bouyer     Status = DtStrtoul64 (Field->Value, &Value);
    494  1.1.1.2.2.2  bouyer     if (ACPI_FAILURE (Status))
    495  1.1.1.2.2.2  bouyer     {
    496  1.1.1.2.2.2  bouyer         DtError (ASL_ERROR, ASL_MSG_INVALID_HEX_INTEGER, Field, NULL);
    497  1.1.1.2.2.2  bouyer     }
    498  1.1.1.2.2.2  bouyer 
    499  1.1.1.2.2.2  bouyer     switch (Info->Opcode)
    500  1.1.1.2.2.2  bouyer     {
    501  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAG0:
    502  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAG1:
    503  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAG2:
    504  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAG3:
    505  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAG4:
    506  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAG5:
    507  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAG6:
    508  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAG7:
    509  1.1.1.2.2.2  bouyer 
    510  1.1.1.2.2.2  bouyer         BitPosition = Info->Opcode;
    511  1.1.1.2.2.2  bouyer         BitLength = 1;
    512  1.1.1.2.2.2  bouyer         break;
    513  1.1.1.2.2.2  bouyer 
    514  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAGS0:
    515  1.1.1.2.2.2  bouyer 
    516  1.1.1.2.2.2  bouyer         BitPosition = 0;
    517  1.1.1.2.2.2  bouyer         BitLength = 2;
    518  1.1.1.2.2.2  bouyer         break;
    519  1.1.1.2.2.2  bouyer 
    520  1.1.1.2.2.2  bouyer 
    521  1.1.1.2.2.2  bouyer     case ACPI_DMT_FLAGS2:
    522  1.1.1.2.2.2  bouyer 
    523  1.1.1.2.2.2  bouyer         BitPosition = 2;
    524  1.1.1.2.2.2  bouyer         BitLength = 2;
    525  1.1.1.2.2.2  bouyer         break;
    526  1.1.1.2.2.2  bouyer 
    527  1.1.1.2.2.2  bouyer     default:
    528  1.1.1.2.2.2  bouyer 
    529  1.1.1.2.2.2  bouyer         DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid flag opcode");
    530  1.1.1.2.2.2  bouyer         break;
    531  1.1.1.2.2.2  bouyer     }
    532  1.1.1.2.2.2  bouyer 
    533  1.1.1.2.2.2  bouyer     /* Check range of the input flag value */
    534  1.1.1.2.2.2  bouyer 
    535  1.1.1.2.2.2  bouyer     if (Value >= ((UINT64) 1 << BitLength))
    536  1.1.1.2.2.2  bouyer     {
    537  1.1.1.2.2.2  bouyer         sprintf (MsgBuffer, "Maximum %u bit", BitLength);
    538  1.1.1.2.2.2  bouyer         DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, MsgBuffer);
    539  1.1.1.2.2.2  bouyer         Value = 0;
    540  1.1.1.2.2.2  bouyer     }
    541  1.1.1.2.2.2  bouyer 
    542  1.1.1.2.2.2  bouyer     *Buffer |= (UINT8) (Value << BitPosition);
    543  1.1.1.2.2.2  bouyer }
    544