Home | History | Annotate | Line # | Download | only in compiler
aslresource.c revision 1.1.1.2.24.1
      1           1.1  jruoho /******************************************************************************
      2           1.1  jruoho  *
      3           1.1  jruoho  * Module Name: aslresource - Resource template/descriptor utilities
      4           1.1  jruoho  *
      5           1.1  jruoho  *****************************************************************************/
      6           1.1  jruoho 
      7       1.1.1.2  jruoho /*
      8  1.1.1.2.24.1   rmind  * Copyright (C) 2000 - 2013, Intel Corp.
      9           1.1  jruoho  * All rights reserved.
     10           1.1  jruoho  *
     11       1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     13       1.1.1.2  jruoho  * are met:
     14       1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.1.1.2  jruoho  *    without modification.
     17       1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.1.1.2  jruoho  *    binary redistribution.
     22       1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.1.1.2  jruoho  *    from this software without specific prior written permission.
     25       1.1.1.2  jruoho  *
     26       1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1.1.2  jruoho  * Software Foundation.
     29       1.1.1.2  jruoho  *
     30       1.1.1.2  jruoho  * NO WARRANTY
     31       1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33       1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34       1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1.1.2  jruoho  */
     43           1.1  jruoho 
     44           1.1  jruoho 
     45           1.1  jruoho #include "aslcompiler.h"
     46           1.1  jruoho #include "aslcompiler.y.h"
     47           1.1  jruoho #include "amlcode.h"
     48           1.1  jruoho 
     49           1.1  jruoho 
     50           1.1  jruoho #define _COMPONENT          ACPI_COMPILER
     51           1.1  jruoho         ACPI_MODULE_NAME    ("aslresource")
     52           1.1  jruoho 
     53           1.1  jruoho 
     54           1.1  jruoho /*******************************************************************************
     55           1.1  jruoho  *
     56           1.1  jruoho  * FUNCTION:    RsSmallAddressCheck
     57           1.1  jruoho  *
     58           1.1  jruoho  * PARAMETERS:  Minimum             - Address Min value
     59           1.1  jruoho  *              Maximum             - Address Max value
     60           1.1  jruoho  *              Length              - Address range value
     61           1.1  jruoho  *              Alignment           - Address alignment value
     62           1.1  jruoho  *              MinOp               - Original Op for Address Min
     63           1.1  jruoho  *              MaxOp               - Original Op for Address Max
     64           1.1  jruoho  *              LengthOp            - Original Op for address range
     65           1.1  jruoho  *              AlignOp             - Original Op for address alignment. If
     66           1.1  jruoho  *                                    NULL, means "zero value for alignment is
     67           1.1  jruoho  *                                    OK, and means 64K alignment" (for
     68           1.1  jruoho  *                                    Memory24 descriptor)
     69       1.1.1.2  jruoho  *              Op                  - Parent Op for entire construct
     70           1.1  jruoho  *
     71           1.1  jruoho  * RETURN:      None. Adds error messages to error log if necessary
     72           1.1  jruoho  *
     73           1.1  jruoho  * DESCRIPTION: Perform common value checks for "small" address descriptors.
     74           1.1  jruoho  *              Currently:
     75           1.1  jruoho  *                  Io, Memory24, Memory32
     76           1.1  jruoho  *
     77           1.1  jruoho  ******************************************************************************/
     78           1.1  jruoho 
     79           1.1  jruoho void
     80           1.1  jruoho RsSmallAddressCheck (
     81           1.1  jruoho     UINT8                   Type,
     82           1.1  jruoho     UINT32                  Minimum,
     83           1.1  jruoho     UINT32                  Maximum,
     84           1.1  jruoho     UINT32                  Length,
     85           1.1  jruoho     UINT32                  Alignment,
     86           1.1  jruoho     ACPI_PARSE_OBJECT       *MinOp,
     87           1.1  jruoho     ACPI_PARSE_OBJECT       *MaxOp,
     88           1.1  jruoho     ACPI_PARSE_OBJECT       *LengthOp,
     89       1.1.1.2  jruoho     ACPI_PARSE_OBJECT       *AlignOp,
     90       1.1.1.2  jruoho     ACPI_PARSE_OBJECT       *Op)
     91           1.1  jruoho {
     92           1.1  jruoho 
     93           1.1  jruoho     if (Gbl_NoResourceChecking)
     94           1.1  jruoho     {
     95           1.1  jruoho         return;
     96           1.1  jruoho     }
     97           1.1  jruoho 
     98       1.1.1.2  jruoho     /*
     99       1.1.1.2  jruoho      * Check for a so-called "null descriptor". These are descriptors that are
    100       1.1.1.2  jruoho      * created with most fields set to zero. The intent is that the descriptor
    101       1.1.1.2  jruoho      * will be updated/completed at runtime via a BufferField.
    102       1.1.1.2  jruoho      *
    103       1.1.1.2  jruoho      * If the descriptor does NOT have a resource tag, it cannot be referenced
    104       1.1.1.2  jruoho      * by a BufferField and we will flag this as an error. Conversely, if
    105       1.1.1.2  jruoho      * the descriptor has a resource tag, we will assume that a BufferField
    106       1.1.1.2  jruoho      * will be used to dynamically update it, so no error.
    107       1.1.1.2  jruoho      *
    108       1.1.1.2  jruoho      * A possible enhancement to this check would be to verify that in fact
    109       1.1.1.2  jruoho      * a BufferField is created using the resource tag, and perhaps even
    110       1.1.1.2  jruoho      * verify that a Store is performed to the BufferField.
    111       1.1.1.2  jruoho      *
    112       1.1.1.2  jruoho      * Note: for these descriptors, Alignment is allowed to be zero
    113       1.1.1.2  jruoho      */
    114       1.1.1.2  jruoho     if (!Minimum && !Maximum && !Length)
    115       1.1.1.2  jruoho     {
    116       1.1.1.2  jruoho         if (!Op->Asl.ExternalName)
    117       1.1.1.2  jruoho         {
    118       1.1.1.2  jruoho             /* No resource tag. Descriptor is fixed and is also illegal */
    119       1.1.1.2  jruoho 
    120       1.1.1.2  jruoho             AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
    121       1.1.1.2  jruoho         }
    122       1.1.1.2  jruoho 
    123       1.1.1.2  jruoho         return;
    124       1.1.1.2  jruoho     }
    125       1.1.1.2  jruoho 
    126           1.1  jruoho     /* Special case for Memory24, values are compressed */
    127           1.1  jruoho 
    128           1.1  jruoho     if (Type == ACPI_RESOURCE_NAME_MEMORY24)
    129           1.1  jruoho     {
    130           1.1  jruoho         if (!Alignment) /* Alignment==0 means 64K - no invalid alignment */
    131           1.1  jruoho         {
    132           1.1  jruoho             Alignment = ACPI_UINT16_MAX + 1;
    133           1.1  jruoho         }
    134           1.1  jruoho 
    135           1.1  jruoho         Minimum <<= 8;
    136           1.1  jruoho         Maximum <<= 8;
    137           1.1  jruoho         Length *= 256;
    138           1.1  jruoho     }
    139           1.1  jruoho 
    140           1.1  jruoho     /* IO descriptor has different definition of min/max, don't check */
    141           1.1  jruoho 
    142           1.1  jruoho     if (Type != ACPI_RESOURCE_NAME_IO)
    143           1.1  jruoho     {
    144           1.1  jruoho         /* Basic checks on Min/Max/Length */
    145           1.1  jruoho 
    146           1.1  jruoho         if (Minimum > Maximum)
    147           1.1  jruoho         {
    148           1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
    149           1.1  jruoho         }
    150           1.1  jruoho         else if (Length > (Maximum - Minimum + 1))
    151           1.1  jruoho         {
    152           1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
    153           1.1  jruoho         }
    154           1.1  jruoho     }
    155           1.1  jruoho 
    156           1.1  jruoho     /* Alignment of zero is not in ACPI spec, but is used to mean byte acc */
    157           1.1  jruoho 
    158           1.1  jruoho     if (!Alignment)
    159           1.1  jruoho     {
    160           1.1  jruoho         Alignment = 1;
    161           1.1  jruoho     }
    162           1.1  jruoho 
    163           1.1  jruoho     /* Addresses must be an exact multiple of the alignment value */
    164           1.1  jruoho 
    165           1.1  jruoho     if (Minimum % Alignment)
    166           1.1  jruoho     {
    167           1.1  jruoho         AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
    168           1.1  jruoho     }
    169           1.1  jruoho     if (Maximum % Alignment)
    170           1.1  jruoho     {
    171           1.1  jruoho         AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL);
    172           1.1  jruoho     }
    173           1.1  jruoho }
    174           1.1  jruoho 
    175           1.1  jruoho 
    176           1.1  jruoho /*******************************************************************************
    177           1.1  jruoho  *
    178           1.1  jruoho  * FUNCTION:    RsLargeAddressCheck
    179           1.1  jruoho  *
    180           1.1  jruoho  * PARAMETERS:  Minimum             - Address Min value
    181           1.1  jruoho  *              Maximum             - Address Max value
    182           1.1  jruoho  *              Length              - Address range value
    183           1.1  jruoho  *              Granularity         - Address granularity value
    184           1.1  jruoho  *              Flags               - General flags for address descriptors:
    185           1.1  jruoho  *                                    _MIF, _MAF, _DEC
    186           1.1  jruoho  *              MinOp               - Original Op for Address Min
    187           1.1  jruoho  *              MaxOp               - Original Op for Address Max
    188           1.1  jruoho  *              LengthOp            - Original Op for address range
    189           1.1  jruoho  *              GranOp              - Original Op for address granularity
    190       1.1.1.2  jruoho  *              Op                  - Parent Op for entire construct
    191           1.1  jruoho  *
    192           1.1  jruoho  * RETURN:      None. Adds error messages to error log if necessary
    193           1.1  jruoho  *
    194           1.1  jruoho  * DESCRIPTION: Perform common value checks for "large" address descriptors.
    195           1.1  jruoho  *              Currently:
    196           1.1  jruoho  *                  WordIo,     WordBusNumber,  WordSpace
    197           1.1  jruoho  *                  DWordIo,    DWordMemory,    DWordSpace
    198           1.1  jruoho  *                  QWordIo,    QWordMemory,    QWordSpace
    199           1.1  jruoho  *                  ExtendedIo, ExtendedMemory, ExtendedSpace
    200           1.1  jruoho  *
    201           1.1  jruoho  * _MIF flag set means that the minimum address is fixed and is not relocatable
    202           1.1  jruoho  * _MAF flag set means that the maximum address is fixed and is not relocatable
    203           1.1  jruoho  * Length of zero means that the record size is variable
    204           1.1  jruoho  *
    205           1.1  jruoho  * This function implements the LEN/MIF/MAF/MIN/MAX/GRA rules within Table 6-40
    206           1.1  jruoho  * of the ACPI 4.0a specification. Added 04/2010.
    207           1.1  jruoho  *
    208           1.1  jruoho  ******************************************************************************/
    209           1.1  jruoho 
    210           1.1  jruoho void
    211           1.1  jruoho RsLargeAddressCheck (
    212           1.1  jruoho     UINT64                  Minimum,
    213           1.1  jruoho     UINT64                  Maximum,
    214           1.1  jruoho     UINT64                  Length,
    215           1.1  jruoho     UINT64                  Granularity,
    216           1.1  jruoho     UINT8                   Flags,
    217           1.1  jruoho     ACPI_PARSE_OBJECT       *MinOp,
    218           1.1  jruoho     ACPI_PARSE_OBJECT       *MaxOp,
    219           1.1  jruoho     ACPI_PARSE_OBJECT       *LengthOp,
    220       1.1.1.2  jruoho     ACPI_PARSE_OBJECT       *GranOp,
    221       1.1.1.2  jruoho     ACPI_PARSE_OBJECT       *Op)
    222           1.1  jruoho {
    223           1.1  jruoho 
    224           1.1  jruoho     if (Gbl_NoResourceChecking)
    225           1.1  jruoho     {
    226           1.1  jruoho         return;
    227           1.1  jruoho     }
    228           1.1  jruoho 
    229       1.1.1.2  jruoho     /*
    230       1.1.1.2  jruoho      * Check for a so-called "null descriptor". These are descriptors that are
    231       1.1.1.2  jruoho      * created with most fields set to zero. The intent is that the descriptor
    232       1.1.1.2  jruoho      * will be updated/completed at runtime via a BufferField.
    233       1.1.1.2  jruoho      *
    234       1.1.1.2  jruoho      * If the descriptor does NOT have a resource tag, it cannot be referenced
    235       1.1.1.2  jruoho      * by a BufferField and we will flag this as an error. Conversely, if
    236       1.1.1.2  jruoho      * the descriptor has a resource tag, we will assume that a BufferField
    237       1.1.1.2  jruoho      * will be used to dynamically update it, so no error.
    238       1.1.1.2  jruoho      *
    239       1.1.1.2  jruoho      * A possible enhancement to this check would be to verify that in fact
    240       1.1.1.2  jruoho      * a BufferField is created using the resource tag, and perhaps even
    241       1.1.1.2  jruoho      * verify that a Store is performed to the BufferField.
    242       1.1.1.2  jruoho      */
    243       1.1.1.2  jruoho     if (!Minimum && !Maximum && !Length && !Granularity)
    244       1.1.1.2  jruoho     {
    245       1.1.1.2  jruoho         if (!Op->Asl.ExternalName)
    246       1.1.1.2  jruoho         {
    247       1.1.1.2  jruoho             /* No resource tag. Descriptor is fixed and is also illegal */
    248       1.1.1.2  jruoho 
    249       1.1.1.2  jruoho             AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
    250       1.1.1.2  jruoho         }
    251       1.1.1.2  jruoho 
    252       1.1.1.2  jruoho         return;
    253       1.1.1.2  jruoho     }
    254       1.1.1.2  jruoho 
    255           1.1  jruoho     /* Basic checks on Min/Max/Length */
    256           1.1  jruoho 
    257           1.1  jruoho     if (Minimum > Maximum)
    258           1.1  jruoho     {
    259           1.1  jruoho         AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
    260           1.1  jruoho         return;
    261           1.1  jruoho     }
    262           1.1  jruoho     else if (Length > (Maximum - Minimum + 1))
    263           1.1  jruoho     {
    264           1.1  jruoho         AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
    265           1.1  jruoho         return;
    266           1.1  jruoho     }
    267           1.1  jruoho 
    268           1.1  jruoho     /* If specified (non-zero), ensure granularity is a power-of-two minus one */
    269           1.1  jruoho 
    270           1.1  jruoho     if (Granularity)
    271           1.1  jruoho     {
    272           1.1  jruoho         if ((Granularity + 1) &
    273           1.1  jruoho              Granularity)
    274           1.1  jruoho         {
    275           1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL);
    276           1.1  jruoho             return;
    277           1.1  jruoho         }
    278           1.1  jruoho     }
    279           1.1  jruoho 
    280           1.1  jruoho     /*
    281           1.1  jruoho      * Check the various combinations of Length, MinFixed, and MaxFixed
    282           1.1  jruoho      */
    283           1.1  jruoho     if (Length)
    284           1.1  jruoho     {
    285           1.1  jruoho         /* Fixed non-zero length */
    286           1.1  jruoho 
    287           1.1  jruoho         switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
    288           1.1  jruoho         {
    289           1.1  jruoho         case 0:
    290           1.1  jruoho             /*
    291           1.1  jruoho              * Fixed length, variable locations (both _MIN and _MAX).
    292           1.1  jruoho              * Length must be a multiple of granularity
    293           1.1  jruoho              */
    294           1.1  jruoho             if (Granularity & Length)
    295           1.1  jruoho             {
    296           1.1  jruoho                 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL);
    297           1.1  jruoho             }
    298           1.1  jruoho             break;
    299           1.1  jruoho 
    300           1.1  jruoho         case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
    301           1.1  jruoho 
    302           1.1  jruoho             /* Fixed length, fixed location. Granularity must be zero */
    303           1.1  jruoho 
    304           1.1  jruoho             if (Granularity != 0)
    305           1.1  jruoho             {
    306           1.1  jruoho                 AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL);
    307           1.1  jruoho             }
    308           1.1  jruoho 
    309           1.1  jruoho             /* Length must be exactly the size of the min/max window */
    310           1.1  jruoho 
    311           1.1  jruoho             if (Length != (Maximum - Minimum + 1))
    312           1.1  jruoho             {
    313           1.1  jruoho                 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL);
    314           1.1  jruoho             }
    315           1.1  jruoho             break;
    316           1.1  jruoho 
    317           1.1  jruoho         /* All other combinations are invalid */
    318           1.1  jruoho 
    319           1.1  jruoho         case ACPI_RESOURCE_FLAG_MIF:
    320           1.1  jruoho         case ACPI_RESOURCE_FLAG_MAF:
    321           1.1  jruoho         default:
    322  1.1.1.2.24.1   rmind 
    323           1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
    324           1.1  jruoho         }
    325           1.1  jruoho     }
    326           1.1  jruoho     else
    327           1.1  jruoho     {
    328           1.1  jruoho         /* Variable length (length==0) */
    329           1.1  jruoho 
    330           1.1  jruoho         switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
    331           1.1  jruoho         {
    332           1.1  jruoho         case 0:
    333           1.1  jruoho             /*
    334           1.1  jruoho              * Both _MIN and _MAX are variable.
    335           1.1  jruoho              * No additional requirements, just exit
    336           1.1  jruoho              */
    337           1.1  jruoho             break;
    338           1.1  jruoho 
    339           1.1  jruoho         case ACPI_RESOURCE_FLAG_MIF:
    340           1.1  jruoho 
    341           1.1  jruoho             /* _MIN is fixed. _MIN must be multiple of _GRA */
    342           1.1  jruoho 
    343           1.1  jruoho             /*
    344           1.1  jruoho              * The granularity is defined by the ACPI specification to be a
    345           1.1  jruoho              * power-of-two minus one, therefore the granularity is a
    346           1.1  jruoho              * bitmask which can be used to easily validate the addresses.
    347           1.1  jruoho              */
    348           1.1  jruoho             if (Granularity & Minimum)
    349           1.1  jruoho             {
    350           1.1  jruoho                 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
    351           1.1  jruoho             }
    352           1.1  jruoho             break;
    353           1.1  jruoho 
    354           1.1  jruoho         case ACPI_RESOURCE_FLAG_MAF:
    355           1.1  jruoho 
    356           1.1  jruoho             /* _MAX is fixed. (_MAX + 1) must be multiple of _GRA */
    357           1.1  jruoho 
    358           1.1  jruoho             if (Granularity & (Maximum + 1))
    359           1.1  jruoho             {
    360           1.1  jruoho                 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, "-1");
    361           1.1  jruoho             }
    362           1.1  jruoho             break;
    363           1.1  jruoho 
    364           1.1  jruoho         /* Both MIF/MAF set is invalid if length is zero */
    365           1.1  jruoho 
    366           1.1  jruoho         case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
    367           1.1  jruoho         default:
    368  1.1.1.2.24.1   rmind 
    369           1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
    370           1.1  jruoho         }
    371           1.1  jruoho     }
    372           1.1  jruoho }
    373           1.1  jruoho 
    374           1.1  jruoho 
    375           1.1  jruoho /*******************************************************************************
    376           1.1  jruoho  *
    377           1.1  jruoho  * FUNCTION:    RsGetStringDataLength
    378           1.1  jruoho  *
    379           1.1  jruoho  * PARAMETERS:  InitializerOp     - Start of a subtree of init nodes
    380           1.1  jruoho  *
    381           1.1  jruoho  * RETURN:      Valid string length if a string node is found (otherwise 0)
    382           1.1  jruoho  *
    383           1.1  jruoho  * DESCRIPTION: In a list of peer nodes, find the first one that contains a
    384           1.1  jruoho  *              string and return the length of the string.
    385           1.1  jruoho  *
    386           1.1  jruoho  ******************************************************************************/
    387           1.1  jruoho 
    388           1.1  jruoho UINT16
    389           1.1  jruoho RsGetStringDataLength (
    390           1.1  jruoho     ACPI_PARSE_OBJECT       *InitializerOp)
    391           1.1  jruoho {
    392           1.1  jruoho 
    393           1.1  jruoho     while (InitializerOp)
    394           1.1  jruoho     {
    395           1.1  jruoho         if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)
    396           1.1  jruoho         {
    397           1.1  jruoho             return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1));
    398           1.1  jruoho         }
    399           1.1  jruoho         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
    400           1.1  jruoho     }
    401           1.1  jruoho 
    402  1.1.1.2.24.1   rmind     return (0);
    403           1.1  jruoho }
    404           1.1  jruoho 
    405           1.1  jruoho 
    406           1.1  jruoho /*******************************************************************************
    407           1.1  jruoho  *
    408           1.1  jruoho  * FUNCTION:    RsAllocateResourceNode
    409           1.1  jruoho  *
    410           1.1  jruoho  * PARAMETERS:  Size        - Size of node in bytes
    411           1.1  jruoho  *
    412           1.1  jruoho  * RETURN:      The allocated node - aborts on allocation failure
    413           1.1  jruoho  *
    414           1.1  jruoho  * DESCRIPTION: Allocate a resource description node and the resource
    415           1.1  jruoho  *              descriptor itself (the nodes are used to link descriptors).
    416           1.1  jruoho  *
    417           1.1  jruoho  ******************************************************************************/
    418           1.1  jruoho 
    419           1.1  jruoho ASL_RESOURCE_NODE *
    420           1.1  jruoho RsAllocateResourceNode (
    421           1.1  jruoho     UINT32                  Size)
    422           1.1  jruoho {
    423           1.1  jruoho     ASL_RESOURCE_NODE       *Rnode;
    424           1.1  jruoho 
    425           1.1  jruoho 
    426           1.1  jruoho     /* Allocate the node */
    427           1.1  jruoho 
    428           1.1  jruoho     Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
    429           1.1  jruoho 
    430           1.1  jruoho     /* Allocate the resource descriptor itself */
    431           1.1  jruoho 
    432           1.1  jruoho     Rnode->Buffer = UtLocalCalloc (Size);
    433           1.1  jruoho     Rnode->BufferLength = Size;
    434           1.1  jruoho 
    435           1.1  jruoho     return (Rnode);
    436           1.1  jruoho }
    437           1.1  jruoho 
    438           1.1  jruoho 
    439           1.1  jruoho /*******************************************************************************
    440           1.1  jruoho  *
    441  1.1.1.2.24.1   rmind  * FUNCTION:    RsCreateResourceField
    442           1.1  jruoho  *
    443           1.1  jruoho  * PARAMETERS:  Op              - Resource field node
    444           1.1  jruoho  *              Name            - Name of the field (Used only to reference
    445           1.1  jruoho  *                                the field in the ASL, not in the AML)
    446           1.1  jruoho  *              ByteOffset      - Offset from the field start
    447           1.1  jruoho  *              BitOffset       - Additional bit offset
    448  1.1.1.2.24.1   rmind  *              BitLength       - Number of bits in the field
    449           1.1  jruoho  *
    450           1.1  jruoho  * RETURN:      None, sets fields within the input node
    451           1.1  jruoho  *
    452           1.1  jruoho  * DESCRIPTION: Utility function to generate a named bit field within a
    453  1.1.1.2.24.1   rmind  *              resource descriptor. Mark a node as 1) a field in a resource
    454           1.1  jruoho  *              descriptor, and 2) set the value to be a BIT offset
    455           1.1  jruoho  *
    456           1.1  jruoho  ******************************************************************************/
    457           1.1  jruoho 
    458           1.1  jruoho void
    459  1.1.1.2.24.1   rmind RsCreateResourceField (
    460           1.1  jruoho     ACPI_PARSE_OBJECT       *Op,
    461           1.1  jruoho     char                    *Name,
    462           1.1  jruoho     UINT32                  ByteOffset,
    463  1.1.1.2.24.1   rmind     UINT32                  BitOffset,
    464  1.1.1.2.24.1   rmind     UINT32                  BitLength)
    465           1.1  jruoho {
    466           1.1  jruoho 
    467  1.1.1.2.24.1   rmind     Op->Asl.ExternalName = Name;
    468  1.1.1.2.24.1   rmind     Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
    469           1.1  jruoho 
    470           1.1  jruoho 
    471  1.1.1.2.24.1   rmind     Op->Asl.Value.Tag.BitOffset = (ByteOffset * 8) + BitOffset;
    472  1.1.1.2.24.1   rmind     Op->Asl.Value.Tag.BitLength = BitLength;
    473           1.1  jruoho }
    474           1.1  jruoho 
    475           1.1  jruoho 
    476           1.1  jruoho /*******************************************************************************
    477           1.1  jruoho  *
    478           1.1  jruoho  * FUNCTION:    RsSetFlagBits
    479           1.1  jruoho  *
    480           1.1  jruoho  * PARAMETERS:  *Flags          - Pointer to the flag byte
    481           1.1  jruoho  *              Op              - Flag initialization node
    482           1.1  jruoho  *              Position        - Bit position within the flag byte
    483           1.1  jruoho  *              Default         - Used if the node is DEFAULT.
    484           1.1  jruoho  *
    485           1.1  jruoho  * RETURN:      Sets bits within the *Flags output byte.
    486           1.1  jruoho  *
    487           1.1  jruoho  * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
    488  1.1.1.2.24.1   rmind  *              node. Will use a default value if the node is DEFAULT, meaning
    489  1.1.1.2.24.1   rmind  *              that no value was specified in the ASL. Used to merge multiple
    490           1.1  jruoho  *              keywords into a single flags byte.
    491           1.1  jruoho  *
    492           1.1  jruoho  ******************************************************************************/
    493           1.1  jruoho 
    494           1.1  jruoho void
    495           1.1  jruoho RsSetFlagBits (
    496           1.1  jruoho     UINT8                   *Flags,
    497           1.1  jruoho     ACPI_PARSE_OBJECT       *Op,
    498           1.1  jruoho     UINT8                   Position,
    499           1.1  jruoho     UINT8                   DefaultBit)
    500           1.1  jruoho {
    501           1.1  jruoho 
    502           1.1  jruoho     if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
    503           1.1  jruoho     {
    504           1.1  jruoho         /* Use the default bit */
    505           1.1  jruoho 
    506           1.1  jruoho         *Flags |= (DefaultBit << Position);
    507           1.1  jruoho     }
    508           1.1  jruoho     else
    509           1.1  jruoho     {
    510           1.1  jruoho         /* Use the bit specified in the initialization node */
    511           1.1  jruoho 
    512           1.1  jruoho         *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
    513           1.1  jruoho     }
    514           1.1  jruoho }
    515           1.1  jruoho 
    516           1.1  jruoho 
    517  1.1.1.2.24.1   rmind void
    518  1.1.1.2.24.1   rmind RsSetFlagBits16 (
    519  1.1.1.2.24.1   rmind     UINT16                  *Flags,
    520  1.1.1.2.24.1   rmind     ACPI_PARSE_OBJECT       *Op,
    521  1.1.1.2.24.1   rmind     UINT8                   Position,
    522  1.1.1.2.24.1   rmind     UINT8                   DefaultBit)
    523  1.1.1.2.24.1   rmind {
    524  1.1.1.2.24.1   rmind 
    525  1.1.1.2.24.1   rmind     if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
    526  1.1.1.2.24.1   rmind     {
    527  1.1.1.2.24.1   rmind         /* Use the default bit */
    528  1.1.1.2.24.1   rmind 
    529  1.1.1.2.24.1   rmind         *Flags |= (DefaultBit << Position);
    530  1.1.1.2.24.1   rmind     }
    531  1.1.1.2.24.1   rmind     else
    532  1.1.1.2.24.1   rmind     {
    533  1.1.1.2.24.1   rmind         /* Use the bit specified in the initialization node */
    534  1.1.1.2.24.1   rmind 
    535  1.1.1.2.24.1   rmind         *Flags |= (((UINT16) Op->Asl.Value.Integer) << Position);
    536  1.1.1.2.24.1   rmind     }
    537  1.1.1.2.24.1   rmind }
    538  1.1.1.2.24.1   rmind 
    539  1.1.1.2.24.1   rmind 
    540           1.1  jruoho /*******************************************************************************
    541           1.1  jruoho  *
    542           1.1  jruoho  * FUNCTION:    RsCompleteNodeAndGetNext
    543           1.1  jruoho  *
    544           1.1  jruoho  * PARAMETERS:  Op            - Resource node to be completed
    545           1.1  jruoho  *
    546           1.1  jruoho  * RETURN:      The next peer to the input node.
    547           1.1  jruoho  *
    548           1.1  jruoho  * DESCRIPTION: Mark the current node completed and return the next peer.
    549           1.1  jruoho  *              The node ParseOpcode is set to DEFAULT_ARG, meaning that
    550           1.1  jruoho  *              this node is to be ignored from now on.
    551           1.1  jruoho  *
    552           1.1  jruoho  ******************************************************************************/
    553           1.1  jruoho 
    554           1.1  jruoho ACPI_PARSE_OBJECT *
    555           1.1  jruoho RsCompleteNodeAndGetNext (
    556           1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    557           1.1  jruoho {
    558           1.1  jruoho 
    559           1.1  jruoho     /* Mark this node unused */
    560           1.1  jruoho 
    561           1.1  jruoho     Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    562           1.1  jruoho 
    563           1.1  jruoho     /* Move on to the next peer node in the initializer list */
    564           1.1  jruoho 
    565           1.1  jruoho     return (ASL_GET_PEER_NODE (Op));
    566           1.1  jruoho }
    567           1.1  jruoho 
    568           1.1  jruoho 
    569           1.1  jruoho /*******************************************************************************
    570           1.1  jruoho  *
    571           1.1  jruoho  * FUNCTION:    RsCheckListForDuplicates
    572           1.1  jruoho  *
    573           1.1  jruoho  * PARAMETERS:  Op                  - First op in the initializer list
    574           1.1  jruoho  *
    575           1.1  jruoho  * RETURN:      None
    576           1.1  jruoho  *
    577           1.1  jruoho  * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
    578           1.1  jruoho  *              if any duplicates are found.
    579           1.1  jruoho  *
    580           1.1  jruoho  ******************************************************************************/
    581           1.1  jruoho 
    582           1.1  jruoho void
    583           1.1  jruoho RsCheckListForDuplicates (
    584           1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    585           1.1  jruoho {
    586           1.1  jruoho     ACPI_PARSE_OBJECT       *NextValueOp = Op;
    587           1.1  jruoho     ACPI_PARSE_OBJECT       *NextOp;
    588           1.1  jruoho     UINT32                  Value;
    589           1.1  jruoho 
    590           1.1  jruoho 
    591           1.1  jruoho     if (!Op)
    592           1.1  jruoho     {
    593           1.1  jruoho         return;
    594           1.1  jruoho     }
    595           1.1  jruoho 
    596           1.1  jruoho     /* Search list once for each value in the list */
    597           1.1  jruoho 
    598           1.1  jruoho     while (NextValueOp)
    599           1.1  jruoho     {
    600           1.1  jruoho         Value = (UINT32) NextValueOp->Asl.Value.Integer;
    601           1.1  jruoho 
    602           1.1  jruoho         /* Compare this value to all remaining values in the list */
    603           1.1  jruoho 
    604           1.1  jruoho         NextOp = ASL_GET_PEER_NODE (NextValueOp);
    605           1.1  jruoho         while (NextOp)
    606           1.1  jruoho         {
    607           1.1  jruoho             if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
    608           1.1  jruoho             {
    609           1.1  jruoho                 /* Compare values */
    610           1.1  jruoho 
    611           1.1  jruoho                 if (Value == (UINT32) NextOp->Asl.Value.Integer)
    612           1.1  jruoho                 {
    613           1.1  jruoho                     /* Emit error only once per duplicate node */
    614           1.1  jruoho 
    615           1.1  jruoho                     if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE))
    616           1.1  jruoho                     {
    617           1.1  jruoho                         NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE;
    618           1.1  jruoho                         AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
    619           1.1  jruoho                             NextOp, NULL);
    620           1.1  jruoho                     }
    621           1.1  jruoho                 }
    622           1.1  jruoho             }
    623           1.1  jruoho 
    624           1.1  jruoho             NextOp = ASL_GET_PEER_NODE (NextOp);
    625           1.1  jruoho         }
    626           1.1  jruoho 
    627           1.1  jruoho         NextValueOp = ASL_GET_PEER_NODE (NextValueOp);
    628           1.1  jruoho     }
    629           1.1  jruoho }
    630           1.1  jruoho 
    631           1.1  jruoho 
    632           1.1  jruoho /*******************************************************************************
    633           1.1  jruoho  *
    634           1.1  jruoho  * FUNCTION:    RsDoOneResourceDescriptor
    635           1.1  jruoho  *
    636           1.1  jruoho  * PARAMETERS:  DescriptorTypeOp    - Parent parse node of the descriptor
    637           1.1  jruoho  *              CurrentByteOffset   - Offset in the resource descriptor
    638           1.1  jruoho  *                                    buffer.
    639           1.1  jruoho  *
    640           1.1  jruoho  * RETURN:      A valid resource node for the descriptor
    641           1.1  jruoho  *
    642           1.1  jruoho  * DESCRIPTION: Dispatches the processing of one resource descriptor
    643           1.1  jruoho  *
    644           1.1  jruoho  ******************************************************************************/
    645           1.1  jruoho 
    646           1.1  jruoho ASL_RESOURCE_NODE *
    647           1.1  jruoho RsDoOneResourceDescriptor (
    648           1.1  jruoho     ACPI_PARSE_OBJECT       *DescriptorTypeOp,
    649           1.1  jruoho     UINT32                  CurrentByteOffset,
    650           1.1  jruoho     UINT8                   *State)
    651           1.1  jruoho {
    652           1.1  jruoho     ASL_RESOURCE_NODE       *Rnode = NULL;
    653           1.1  jruoho 
    654           1.1  jruoho 
    655           1.1  jruoho     /* Construct the resource */
    656           1.1  jruoho 
    657           1.1  jruoho     switch (DescriptorTypeOp->Asl.ParseOpcode)
    658           1.1  jruoho     {
    659           1.1  jruoho     case PARSEOP_DMA:
    660  1.1.1.2.24.1   rmind 
    661           1.1  jruoho         Rnode = RsDoDmaDescriptor (DescriptorTypeOp,
    662           1.1  jruoho                     CurrentByteOffset);
    663           1.1  jruoho         break;
    664           1.1  jruoho 
    665  1.1.1.2.24.1   rmind     case PARSEOP_FIXEDDMA:
    666  1.1.1.2.24.1   rmind 
    667  1.1.1.2.24.1   rmind         Rnode = RsDoFixedDmaDescriptor (DescriptorTypeOp,
    668  1.1.1.2.24.1   rmind                     CurrentByteOffset);
    669  1.1.1.2.24.1   rmind         break;
    670  1.1.1.2.24.1   rmind 
    671           1.1  jruoho     case PARSEOP_DWORDIO:
    672  1.1.1.2.24.1   rmind 
    673           1.1  jruoho         Rnode = RsDoDwordIoDescriptor (DescriptorTypeOp,
    674           1.1  jruoho                     CurrentByteOffset);
    675           1.1  jruoho         break;
    676           1.1  jruoho 
    677           1.1  jruoho     case PARSEOP_DWORDMEMORY:
    678  1.1.1.2.24.1   rmind 
    679           1.1  jruoho         Rnode = RsDoDwordMemoryDescriptor (DescriptorTypeOp,
    680           1.1  jruoho                     CurrentByteOffset);
    681           1.1  jruoho         break;
    682           1.1  jruoho 
    683           1.1  jruoho     case PARSEOP_DWORDSPACE:
    684  1.1.1.2.24.1   rmind 
    685           1.1  jruoho         Rnode = RsDoDwordSpaceDescriptor (DescriptorTypeOp,
    686           1.1  jruoho                     CurrentByteOffset);
    687           1.1  jruoho         break;
    688           1.1  jruoho 
    689           1.1  jruoho     case PARSEOP_ENDDEPENDENTFN:
    690  1.1.1.2.24.1   rmind 
    691           1.1  jruoho         switch (*State)
    692           1.1  jruoho         {
    693           1.1  jruoho         case ACPI_RSTATE_NORMAL:
    694  1.1.1.2.24.1   rmind 
    695           1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
    696           1.1  jruoho                 DescriptorTypeOp, NULL);
    697           1.1  jruoho             break;
    698           1.1  jruoho 
    699           1.1  jruoho         case ACPI_RSTATE_START_DEPENDENT:
    700  1.1.1.2.24.1   rmind 
    701           1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
    702           1.1  jruoho                 DescriptorTypeOp, NULL);
    703           1.1  jruoho             break;
    704           1.1  jruoho 
    705           1.1  jruoho         case ACPI_RSTATE_DEPENDENT_LIST:
    706           1.1  jruoho         default:
    707  1.1.1.2.24.1   rmind 
    708           1.1  jruoho             break;
    709           1.1  jruoho         }
    710           1.1  jruoho 
    711           1.1  jruoho         *State = ACPI_RSTATE_NORMAL;
    712           1.1  jruoho         Rnode = RsDoEndDependentDescriptor (DescriptorTypeOp,
    713           1.1  jruoho                     CurrentByteOffset);
    714           1.1  jruoho         break;
    715           1.1  jruoho 
    716           1.1  jruoho     case PARSEOP_ENDTAG:
    717  1.1.1.2.24.1   rmind 
    718           1.1  jruoho         Rnode = RsDoEndTagDescriptor (DescriptorTypeOp,
    719           1.1  jruoho                     CurrentByteOffset);
    720           1.1  jruoho         break;
    721           1.1  jruoho 
    722           1.1  jruoho     case PARSEOP_EXTENDEDIO:
    723  1.1.1.2.24.1   rmind 
    724           1.1  jruoho         Rnode = RsDoExtendedIoDescriptor (DescriptorTypeOp,
    725           1.1  jruoho                     CurrentByteOffset);
    726           1.1  jruoho         break;
    727           1.1  jruoho 
    728           1.1  jruoho     case PARSEOP_EXTENDEDMEMORY:
    729  1.1.1.2.24.1   rmind 
    730           1.1  jruoho         Rnode = RsDoExtendedMemoryDescriptor (DescriptorTypeOp,
    731           1.1  jruoho                     CurrentByteOffset);
    732           1.1  jruoho         break;
    733           1.1  jruoho 
    734           1.1  jruoho     case PARSEOP_EXTENDEDSPACE:
    735  1.1.1.2.24.1   rmind 
    736           1.1  jruoho         Rnode = RsDoExtendedSpaceDescriptor (DescriptorTypeOp,
    737           1.1  jruoho                     CurrentByteOffset);
    738           1.1  jruoho         break;
    739           1.1  jruoho 
    740           1.1  jruoho     case PARSEOP_FIXEDIO:
    741  1.1.1.2.24.1   rmind 
    742           1.1  jruoho         Rnode = RsDoFixedIoDescriptor (DescriptorTypeOp,
    743           1.1  jruoho                     CurrentByteOffset);
    744           1.1  jruoho         break;
    745           1.1  jruoho 
    746           1.1  jruoho     case PARSEOP_INTERRUPT:
    747  1.1.1.2.24.1   rmind 
    748           1.1  jruoho         Rnode = RsDoInterruptDescriptor (DescriptorTypeOp,
    749           1.1  jruoho                     CurrentByteOffset);
    750           1.1  jruoho         break;
    751           1.1  jruoho 
    752           1.1  jruoho     case PARSEOP_IO:
    753  1.1.1.2.24.1   rmind 
    754           1.1  jruoho         Rnode = RsDoIoDescriptor (DescriptorTypeOp,
    755           1.1  jruoho                     CurrentByteOffset);
    756           1.1  jruoho         break;
    757           1.1  jruoho 
    758           1.1  jruoho     case PARSEOP_IRQ:
    759  1.1.1.2.24.1   rmind 
    760           1.1  jruoho         Rnode = RsDoIrqDescriptor (DescriptorTypeOp,
    761           1.1  jruoho                     CurrentByteOffset);
    762           1.1  jruoho         break;
    763           1.1  jruoho 
    764           1.1  jruoho     case PARSEOP_IRQNOFLAGS:
    765  1.1.1.2.24.1   rmind 
    766           1.1  jruoho         Rnode = RsDoIrqNoFlagsDescriptor (DescriptorTypeOp,
    767           1.1  jruoho                     CurrentByteOffset);
    768           1.1  jruoho         break;
    769           1.1  jruoho 
    770           1.1  jruoho     case PARSEOP_MEMORY24:
    771  1.1.1.2.24.1   rmind 
    772           1.1  jruoho         Rnode = RsDoMemory24Descriptor (DescriptorTypeOp,
    773           1.1  jruoho                     CurrentByteOffset);
    774           1.1  jruoho         break;
    775           1.1  jruoho 
    776           1.1  jruoho     case PARSEOP_MEMORY32:
    777  1.1.1.2.24.1   rmind 
    778           1.1  jruoho         Rnode = RsDoMemory32Descriptor (DescriptorTypeOp,
    779           1.1  jruoho                     CurrentByteOffset);
    780           1.1  jruoho         break;
    781           1.1  jruoho 
    782           1.1  jruoho     case PARSEOP_MEMORY32FIXED:
    783  1.1.1.2.24.1   rmind 
    784           1.1  jruoho         Rnode = RsDoMemory32FixedDescriptor (DescriptorTypeOp,
    785           1.1  jruoho                     CurrentByteOffset);
    786           1.1  jruoho         break;
    787           1.1  jruoho 
    788           1.1  jruoho     case PARSEOP_QWORDIO:
    789  1.1.1.2.24.1   rmind 
    790           1.1  jruoho         Rnode = RsDoQwordIoDescriptor (DescriptorTypeOp,
    791           1.1  jruoho                     CurrentByteOffset);
    792           1.1  jruoho         break;
    793           1.1  jruoho 
    794           1.1  jruoho     case PARSEOP_QWORDMEMORY:
    795  1.1.1.2.24.1   rmind 
    796           1.1  jruoho         Rnode = RsDoQwordMemoryDescriptor (DescriptorTypeOp,
    797           1.1  jruoho                     CurrentByteOffset);
    798           1.1  jruoho         break;
    799           1.1  jruoho 
    800           1.1  jruoho     case PARSEOP_QWORDSPACE:
    801  1.1.1.2.24.1   rmind 
    802           1.1  jruoho         Rnode = RsDoQwordSpaceDescriptor (DescriptorTypeOp,
    803           1.1  jruoho                     CurrentByteOffset);
    804           1.1  jruoho         break;
    805           1.1  jruoho 
    806           1.1  jruoho     case PARSEOP_REGISTER:
    807  1.1.1.2.24.1   rmind 
    808           1.1  jruoho         Rnode = RsDoGeneralRegisterDescriptor (DescriptorTypeOp,
    809           1.1  jruoho                     CurrentByteOffset);
    810           1.1  jruoho         break;
    811           1.1  jruoho 
    812           1.1  jruoho     case PARSEOP_STARTDEPENDENTFN:
    813  1.1.1.2.24.1   rmind 
    814           1.1  jruoho         switch (*State)
    815           1.1  jruoho         {
    816           1.1  jruoho         case ACPI_RSTATE_START_DEPENDENT:
    817  1.1.1.2.24.1   rmind 
    818           1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
    819           1.1  jruoho                 DescriptorTypeOp, NULL);
    820           1.1  jruoho             break;
    821           1.1  jruoho 
    822           1.1  jruoho         case ACPI_RSTATE_NORMAL:
    823           1.1  jruoho         case ACPI_RSTATE_DEPENDENT_LIST:
    824           1.1  jruoho         default:
    825  1.1.1.2.24.1   rmind 
    826           1.1  jruoho             break;
    827           1.1  jruoho         }
    828           1.1  jruoho 
    829           1.1  jruoho         *State = ACPI_RSTATE_START_DEPENDENT;
    830           1.1  jruoho         Rnode = RsDoStartDependentDescriptor (DescriptorTypeOp,
    831           1.1  jruoho                     CurrentByteOffset);
    832           1.1  jruoho         *State = ACPI_RSTATE_DEPENDENT_LIST;
    833           1.1  jruoho         break;
    834           1.1  jruoho 
    835           1.1  jruoho     case PARSEOP_STARTDEPENDENTFN_NOPRI:
    836  1.1.1.2.24.1   rmind 
    837           1.1  jruoho         switch (*State)
    838           1.1  jruoho         {
    839           1.1  jruoho         case ACPI_RSTATE_START_DEPENDENT:
    840  1.1.1.2.24.1   rmind 
    841           1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
    842           1.1  jruoho                 DescriptorTypeOp, NULL);
    843           1.1  jruoho             break;
    844           1.1  jruoho 
    845           1.1  jruoho         case ACPI_RSTATE_NORMAL:
    846           1.1  jruoho         case ACPI_RSTATE_DEPENDENT_LIST:
    847           1.1  jruoho         default:
    848  1.1.1.2.24.1   rmind 
    849           1.1  jruoho             break;
    850           1.1  jruoho         }
    851           1.1  jruoho 
    852           1.1  jruoho         *State = ACPI_RSTATE_START_DEPENDENT;
    853           1.1  jruoho         Rnode = RsDoStartDependentNoPriDescriptor (DescriptorTypeOp,
    854           1.1  jruoho                     CurrentByteOffset);
    855           1.1  jruoho         *State = ACPI_RSTATE_DEPENDENT_LIST;
    856           1.1  jruoho         break;
    857           1.1  jruoho 
    858           1.1  jruoho     case PARSEOP_VENDORLONG:
    859  1.1.1.2.24.1   rmind 
    860           1.1  jruoho         Rnode = RsDoVendorLargeDescriptor (DescriptorTypeOp,
    861           1.1  jruoho                     CurrentByteOffset);
    862           1.1  jruoho         break;
    863           1.1  jruoho 
    864           1.1  jruoho     case PARSEOP_VENDORSHORT:
    865  1.1.1.2.24.1   rmind 
    866           1.1  jruoho         Rnode = RsDoVendorSmallDescriptor (DescriptorTypeOp,
    867           1.1  jruoho                     CurrentByteOffset);
    868           1.1  jruoho         break;
    869           1.1  jruoho 
    870           1.1  jruoho     case PARSEOP_WORDBUSNUMBER:
    871  1.1.1.2.24.1   rmind 
    872           1.1  jruoho         Rnode = RsDoWordBusNumberDescriptor (DescriptorTypeOp,
    873           1.1  jruoho                     CurrentByteOffset);
    874           1.1  jruoho         break;
    875           1.1  jruoho 
    876           1.1  jruoho     case PARSEOP_WORDIO:
    877  1.1.1.2.24.1   rmind 
    878           1.1  jruoho         Rnode = RsDoWordIoDescriptor (DescriptorTypeOp,
    879           1.1  jruoho                     CurrentByteOffset);
    880           1.1  jruoho         break;
    881           1.1  jruoho 
    882           1.1  jruoho     case PARSEOP_WORDSPACE:
    883  1.1.1.2.24.1   rmind 
    884           1.1  jruoho         Rnode = RsDoWordSpaceDescriptor (DescriptorTypeOp,
    885           1.1  jruoho                     CurrentByteOffset);
    886           1.1  jruoho         break;
    887           1.1  jruoho 
    888  1.1.1.2.24.1   rmind     case PARSEOP_GPIO_INT:
    889  1.1.1.2.24.1   rmind 
    890  1.1.1.2.24.1   rmind         Rnode = RsDoGpioIntDescriptor (DescriptorTypeOp,
    891  1.1.1.2.24.1   rmind                     CurrentByteOffset);
    892  1.1.1.2.24.1   rmind         break;
    893  1.1.1.2.24.1   rmind 
    894  1.1.1.2.24.1   rmind     case PARSEOP_GPIO_IO:
    895  1.1.1.2.24.1   rmind 
    896  1.1.1.2.24.1   rmind         Rnode = RsDoGpioIoDescriptor (DescriptorTypeOp,
    897  1.1.1.2.24.1   rmind                     CurrentByteOffset);
    898  1.1.1.2.24.1   rmind         break;
    899  1.1.1.2.24.1   rmind 
    900  1.1.1.2.24.1   rmind     case PARSEOP_I2C_SERIALBUS:
    901  1.1.1.2.24.1   rmind 
    902  1.1.1.2.24.1   rmind         Rnode = RsDoI2cSerialBusDescriptor (DescriptorTypeOp,
    903  1.1.1.2.24.1   rmind                     CurrentByteOffset);
    904  1.1.1.2.24.1   rmind         break;
    905  1.1.1.2.24.1   rmind 
    906  1.1.1.2.24.1   rmind     case PARSEOP_SPI_SERIALBUS:
    907  1.1.1.2.24.1   rmind 
    908  1.1.1.2.24.1   rmind         Rnode = RsDoSpiSerialBusDescriptor (DescriptorTypeOp,
    909  1.1.1.2.24.1   rmind                     CurrentByteOffset);
    910  1.1.1.2.24.1   rmind         break;
    911  1.1.1.2.24.1   rmind 
    912  1.1.1.2.24.1   rmind     case PARSEOP_UART_SERIALBUS:
    913  1.1.1.2.24.1   rmind 
    914  1.1.1.2.24.1   rmind         Rnode = RsDoUartSerialBusDescriptor (DescriptorTypeOp,
    915  1.1.1.2.24.1   rmind                     CurrentByteOffset);
    916  1.1.1.2.24.1   rmind         break;
    917  1.1.1.2.24.1   rmind 
    918           1.1  jruoho     case PARSEOP_DEFAULT_ARG:
    919  1.1.1.2.24.1   rmind 
    920           1.1  jruoho         /* Just ignore any of these, they are used as fillers/placeholders */
    921           1.1  jruoho         break;
    922           1.1  jruoho 
    923           1.1  jruoho     default:
    924  1.1.1.2.24.1   rmind 
    925           1.1  jruoho         printf ("Unknown resource descriptor type [%s]\n",
    926           1.1  jruoho                     DescriptorTypeOp->Asl.ParseOpName);
    927           1.1  jruoho         break;
    928           1.1  jruoho     }
    929           1.1  jruoho 
    930           1.1  jruoho     /*
    931           1.1  jruoho      * Mark original node as unused, but head of a resource descriptor.
    932           1.1  jruoho      * This allows the resource to be installed in the namespace so that
    933           1.1  jruoho      * references to the descriptor can be resolved.
    934           1.1  jruoho      */
    935           1.1  jruoho     DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    936           1.1  jruoho     DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
    937           1.1  jruoho     DescriptorTypeOp->Asl.Value.Integer = CurrentByteOffset;
    938           1.1  jruoho 
    939           1.1  jruoho     if (Rnode)
    940           1.1  jruoho     {
    941           1.1  jruoho         DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
    942  1.1.1.2.24.1   rmind         DescriptorTypeOp->Asl.Extra = ((AML_RESOURCE *) Rnode->Buffer)->DescriptorType;
    943           1.1  jruoho     }
    944           1.1  jruoho 
    945           1.1  jruoho     return (Rnode);
    946           1.1  jruoho }
    947           1.1  jruoho 
    948           1.1  jruoho 
    949           1.1  jruoho /*******************************************************************************
    950           1.1  jruoho  *
    951           1.1  jruoho  * FUNCTION:    RsLinkDescriptorChain
    952           1.1  jruoho  *
    953           1.1  jruoho  * PARAMETERS:  PreviousRnode       - Pointer to the node that will be previous
    954           1.1  jruoho  *                                    to the linked node,  At exit, set to the
    955           1.1  jruoho  *                                    last node in the new chain.
    956           1.1  jruoho  *              Rnode               - Resource node to link into the list
    957           1.1  jruoho  *
    958           1.1  jruoho  * RETURN:      Cumulative buffer byte offset of the new segment of chain
    959           1.1  jruoho  *
    960           1.1  jruoho  * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
    961           1.1  jruoho  *
    962           1.1  jruoho  ******************************************************************************/
    963           1.1  jruoho 
    964           1.1  jruoho UINT32
    965           1.1  jruoho RsLinkDescriptorChain (
    966           1.1  jruoho     ASL_RESOURCE_NODE       **PreviousRnode,
    967           1.1  jruoho     ASL_RESOURCE_NODE       *Rnode)
    968           1.1  jruoho {
    969           1.1  jruoho     ASL_RESOURCE_NODE       *LastRnode;
    970           1.1  jruoho     UINT32                  CurrentByteOffset;
    971           1.1  jruoho 
    972           1.1  jruoho 
    973           1.1  jruoho     /* Anything to do? */
    974           1.1  jruoho 
    975           1.1  jruoho     if (!Rnode)
    976           1.1  jruoho     {
    977  1.1.1.2.24.1   rmind         return (0);
    978           1.1  jruoho     }
    979           1.1  jruoho 
    980           1.1  jruoho     /* Point the previous node to the new node */
    981           1.1  jruoho 
    982           1.1  jruoho     (*PreviousRnode)->Next = Rnode;
    983           1.1  jruoho     CurrentByteOffset = Rnode->BufferLength;
    984           1.1  jruoho 
    985           1.1  jruoho     /* Walk to the end of the chain headed by Rnode */
    986           1.1  jruoho 
    987           1.1  jruoho     LastRnode = Rnode;
    988           1.1  jruoho     while (LastRnode->Next)
    989           1.1  jruoho     {
    990           1.1  jruoho         LastRnode = LastRnode->Next;
    991           1.1  jruoho         CurrentByteOffset += LastRnode->BufferLength;
    992           1.1  jruoho     }
    993           1.1  jruoho 
    994           1.1  jruoho     /* Previous node becomes the last node in the chain */
    995           1.1  jruoho 
    996           1.1  jruoho     *PreviousRnode = LastRnode;
    997  1.1.1.2.24.1   rmind     return (CurrentByteOffset);
    998           1.1  jruoho }
    999           1.1  jruoho 
   1000           1.1  jruoho 
   1001           1.1  jruoho /*******************************************************************************
   1002           1.1  jruoho  *
   1003           1.1  jruoho  * FUNCTION:    RsDoResourceTemplate
   1004           1.1  jruoho  *
   1005           1.1  jruoho  * PARAMETERS:  Op        - Parent of a resource template list
   1006           1.1  jruoho  *
   1007  1.1.1.2.24.1   rmind  * RETURN:      None. Sets input node to point to a list of AML code
   1008           1.1  jruoho  *
   1009           1.1  jruoho  * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
   1010           1.1  jruoho  *              in preparation for output to the AML output file.
   1011           1.1  jruoho  *
   1012           1.1  jruoho  ******************************************************************************/
   1013           1.1  jruoho 
   1014           1.1  jruoho void
   1015           1.1  jruoho RsDoResourceTemplate (
   1016           1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
   1017           1.1  jruoho {
   1018           1.1  jruoho     ACPI_PARSE_OBJECT       *BufferLengthOp;
   1019           1.1  jruoho     ACPI_PARSE_OBJECT       *BufferOp;
   1020           1.1  jruoho     ACPI_PARSE_OBJECT       *DescriptorTypeOp;
   1021           1.1  jruoho     ACPI_PARSE_OBJECT       *LastOp = NULL;
   1022           1.1  jruoho     UINT32                  CurrentByteOffset = 0;
   1023           1.1  jruoho     ASL_RESOURCE_NODE       HeadRnode;
   1024           1.1  jruoho     ASL_RESOURCE_NODE       *PreviousRnode;
   1025           1.1  jruoho     ASL_RESOURCE_NODE       *Rnode;
   1026           1.1  jruoho     UINT8                   State;
   1027           1.1  jruoho 
   1028           1.1  jruoho 
   1029           1.1  jruoho     /* Mark parent as containing a resource template */
   1030           1.1  jruoho 
   1031           1.1  jruoho     if (Op->Asl.Parent)
   1032           1.1  jruoho     {
   1033           1.1  jruoho         Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
   1034           1.1  jruoho     }
   1035           1.1  jruoho 
   1036           1.1  jruoho     /* ResourceTemplate Opcode is first (Op) */
   1037           1.1  jruoho     /* Buffer Length node is first child */
   1038           1.1  jruoho 
   1039           1.1  jruoho     BufferLengthOp = ASL_GET_CHILD_NODE (Op);
   1040           1.1  jruoho 
   1041           1.1  jruoho     /* Buffer Op is first peer */
   1042           1.1  jruoho 
   1043           1.1  jruoho     BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
   1044           1.1  jruoho 
   1045           1.1  jruoho     /* First Descriptor type is next */
   1046           1.1  jruoho 
   1047           1.1  jruoho     DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
   1048           1.1  jruoho 
   1049           1.1  jruoho     /*
   1050           1.1  jruoho      * Process all resource descriptors in the list
   1051           1.1  jruoho      * Note: It is assumed that the EndTag node has been automatically
   1052           1.1  jruoho      * inserted at the end of the template by the parser.
   1053           1.1  jruoho      */
   1054           1.1  jruoho     State = ACPI_RSTATE_NORMAL;
   1055           1.1  jruoho     PreviousRnode = &HeadRnode;
   1056           1.1  jruoho     while (DescriptorTypeOp)
   1057           1.1  jruoho     {
   1058           1.1  jruoho         DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
   1059           1.1  jruoho         Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset,
   1060           1.1  jruoho                     &State);
   1061           1.1  jruoho 
   1062           1.1  jruoho         /*
   1063           1.1  jruoho          * Update current byte offset to indicate the number of bytes from the
   1064  1.1.1.2.24.1   rmind          * start of the buffer. Buffer can include multiple descriptors, we
   1065           1.1  jruoho          * must keep track of the offset of not only each descriptor, but each
   1066           1.1  jruoho          * element (field) within each descriptor as well.
   1067           1.1  jruoho          */
   1068           1.1  jruoho         CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
   1069           1.1  jruoho 
   1070           1.1  jruoho         /* Get the next descriptor in the list */
   1071           1.1  jruoho 
   1072           1.1  jruoho         LastOp = DescriptorTypeOp;
   1073           1.1  jruoho         DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
   1074           1.1  jruoho     }
   1075           1.1  jruoho 
   1076           1.1  jruoho     if (State == ACPI_RSTATE_DEPENDENT_LIST)
   1077           1.1  jruoho     {
   1078           1.1  jruoho         if (LastOp)
   1079           1.1  jruoho         {
   1080           1.1  jruoho             LastOp = LastOp->Asl.Parent;
   1081           1.1  jruoho         }
   1082           1.1  jruoho         AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
   1083           1.1  jruoho     }
   1084           1.1  jruoho 
   1085           1.1  jruoho     /*
   1086           1.1  jruoho      * Transform the nodes into the following
   1087           1.1  jruoho      *
   1088           1.1  jruoho      * Op           -> AML_BUFFER_OP
   1089           1.1  jruoho      * First Child  -> BufferLength
   1090           1.1  jruoho      * Second Child -> Descriptor Buffer (raw byte data)
   1091           1.1  jruoho      */
   1092           1.1  jruoho     Op->Asl.ParseOpcode               = PARSEOP_BUFFER;
   1093           1.1  jruoho     Op->Asl.AmlOpcode                 = AML_BUFFER_OP;
   1094           1.1  jruoho     Op->Asl.CompileFlags              = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC;
   1095  1.1.1.2.24.1   rmind     UtSetParseOpName (Op);
   1096           1.1  jruoho 
   1097           1.1  jruoho     BufferLengthOp->Asl.ParseOpcode   = PARSEOP_INTEGER;
   1098           1.1  jruoho     BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
   1099           1.1  jruoho     (void) OpcSetOptimalIntegerSize (BufferLengthOp);
   1100  1.1.1.2.24.1   rmind     UtSetParseOpName (BufferLengthOp);
   1101           1.1  jruoho 
   1102           1.1  jruoho     BufferOp->Asl.ParseOpcode         = PARSEOP_RAW_DATA;
   1103           1.1  jruoho     BufferOp->Asl.AmlOpcode           = AML_RAW_DATA_CHAIN;
   1104           1.1  jruoho     BufferOp->Asl.AmlOpcodeLength     = 0;
   1105           1.1  jruoho     BufferOp->Asl.AmlLength           = CurrentByteOffset;
   1106           1.1  jruoho     BufferOp->Asl.Value.Buffer        = (UINT8 *) HeadRnode.Next;
   1107           1.1  jruoho     BufferOp->Asl.CompileFlags       |= NODE_IS_RESOURCE_DATA;
   1108  1.1.1.2.24.1   rmind     UtSetParseOpName (BufferOp);
   1109           1.1  jruoho 
   1110           1.1  jruoho     return;
   1111           1.1  jruoho }
   1112