xref: /freebsd/sys/contrib/dev/acpica/compiler/aslresource.c (revision 722b16673c40aedf280895f2f2f676bb494518d7)
153289f6aSNate Lawson /******************************************************************************
253289f6aSNate Lawson  *
33f5e024cSJung-uk Kim  * Module Name: aslresource - Resource template/descriptor utilities
453289f6aSNate Lawson  *
553289f6aSNate Lawson  *****************************************************************************/
653289f6aSNate Lawson 
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim  *
90d84335fSJung-uk Kim  * 1. Copyright Notice
100d84335fSJung-uk Kim  *
11*722b1667SJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
1253289f6aSNate Lawson  * All rights reserved.
1353289f6aSNate Lawson  *
140d84335fSJung-uk Kim  * 2. License
150d84335fSJung-uk Kim  *
160d84335fSJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim  * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim  * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim  * property rights.
200d84335fSJung-uk Kim  *
210d84335fSJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim  *
280d84335fSJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim  * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim  * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim  *
370d84335fSJung-uk Kim  * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim  * conditions are met:
390d84335fSJung-uk Kim  *
400d84335fSJung-uk Kim  * 3. Conditions
410d84335fSJung-uk Kim  *
420d84335fSJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim  * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim  * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim  * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim  * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim  * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim  * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim  *
540d84335fSJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim  * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim  * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim  * make.
650d84335fSJung-uk Kim  *
660d84335fSJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim  * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim  * distribution.
710d84335fSJung-uk Kim  *
720d84335fSJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim  * Intel Code.
740d84335fSJung-uk Kim  *
750d84335fSJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim  * without prior written authorization from Intel.
790d84335fSJung-uk Kim  *
800d84335fSJung-uk Kim  * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim  *
820d84335fSJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim  * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim  *
900d84335fSJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim  * LIMITED REMEDY.
980d84335fSJung-uk Kim  *
990d84335fSJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim  * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim  * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim  * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim  * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim  * such license, approval or letter.
1130d84335fSJung-uk Kim  *
1140d84335fSJung-uk Kim  *****************************************************************************
1150d84335fSJung-uk Kim  *
1160d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim  * following license:
1180d84335fSJung-uk Kim  *
119d244b227SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
120d244b227SJung-uk Kim  * modification, are permitted provided that the following conditions
121d244b227SJung-uk Kim  * are met:
122d244b227SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
123d244b227SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
124d244b227SJung-uk Kim  *    without modification.
125d244b227SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126d244b227SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
127d244b227SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
128d244b227SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
129d244b227SJung-uk Kim  *    binary redistribution.
130d244b227SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
131d244b227SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
132d244b227SJung-uk Kim  *    from this software without specific prior written permission.
13353289f6aSNate Lawson  *
1340d84335fSJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim  *
1460d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
147d244b227SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
148d244b227SJung-uk Kim  * Software Foundation.
14953289f6aSNate Lawson  *
1500d84335fSJung-uk Kim  *****************************************************************************/
15153289f6aSNate Lawson 
152ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
15353289f6aSNate Lawson #include "aslcompiler.y.h"
154ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
15553289f6aSNate Lawson 
15653289f6aSNate Lawson 
15753289f6aSNate Lawson #define _COMPONENT          ACPI_COMPILER
15853289f6aSNate Lawson         ACPI_MODULE_NAME    ("aslresource")
15953289f6aSNate Lawson 
16053289f6aSNate Lawson 
16153289f6aSNate Lawson /*******************************************************************************
16253289f6aSNate Lawson  *
1633f5e024cSJung-uk Kim  * FUNCTION:    RsSmallAddressCheck
1643f5e024cSJung-uk Kim  *
1653f5e024cSJung-uk Kim  * PARAMETERS:  Minimum             - Address Min value
1663f5e024cSJung-uk Kim  *              Maximum             - Address Max value
1673f5e024cSJung-uk Kim  *              Length              - Address range value
1683f5e024cSJung-uk Kim  *              Alignment           - Address alignment value
1693f5e024cSJung-uk Kim  *              MinOp               - Original Op for Address Min
1703f5e024cSJung-uk Kim  *              MaxOp               - Original Op for Address Max
1713f5e024cSJung-uk Kim  *              LengthOp            - Original Op for address range
1723f5e024cSJung-uk Kim  *              AlignOp             - Original Op for address alignment. If
1733f5e024cSJung-uk Kim  *                                    NULL, means "zero value for alignment is
1743f5e024cSJung-uk Kim  *                                    OK, and means 64K alignment" (for
1753f5e024cSJung-uk Kim  *                                    Memory24 descriptor)
1763c1812acSJung-uk Kim  *              Op                  - Parent Op for entire construct
1773f5e024cSJung-uk Kim  *
1783f5e024cSJung-uk Kim  * RETURN:      None. Adds error messages to error log if necessary
1793f5e024cSJung-uk Kim  *
1803f5e024cSJung-uk Kim  * DESCRIPTION: Perform common value checks for "small" address descriptors.
1813f5e024cSJung-uk Kim  *              Currently:
1823f5e024cSJung-uk Kim  *                  Io, Memory24, Memory32
1833f5e024cSJung-uk Kim  *
1843f5e024cSJung-uk Kim  ******************************************************************************/
1853f5e024cSJung-uk Kim 
1863f5e024cSJung-uk Kim void
RsSmallAddressCheck(UINT8 Type,UINT32 Minimum,UINT32 Maximum,UINT32 Length,UINT32 Alignment,ACPI_PARSE_OBJECT * MinOp,ACPI_PARSE_OBJECT * MaxOp,ACPI_PARSE_OBJECT * LengthOp,ACPI_PARSE_OBJECT * AlignOp,ACPI_PARSE_OBJECT * Op)1873f5e024cSJung-uk Kim RsSmallAddressCheck (
1883f5e024cSJung-uk Kim     UINT8                   Type,
1893f5e024cSJung-uk Kim     UINT32                  Minimum,
1903f5e024cSJung-uk Kim     UINT32                  Maximum,
1913f5e024cSJung-uk Kim     UINT32                  Length,
1923f5e024cSJung-uk Kim     UINT32                  Alignment,
1933f5e024cSJung-uk Kim     ACPI_PARSE_OBJECT       *MinOp,
1943f5e024cSJung-uk Kim     ACPI_PARSE_OBJECT       *MaxOp,
1953f5e024cSJung-uk Kim     ACPI_PARSE_OBJECT       *LengthOp,
1963c1812acSJung-uk Kim     ACPI_PARSE_OBJECT       *AlignOp,
1973c1812acSJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
1983f5e024cSJung-uk Kim {
1993f5e024cSJung-uk Kim 
2006f1f1a63SJung-uk Kim     if (AslGbl_NoResourceChecking)
2013f5e024cSJung-uk Kim     {
2023f5e024cSJung-uk Kim         return;
2033f5e024cSJung-uk Kim     }
2043f5e024cSJung-uk Kim 
2053c1812acSJung-uk Kim     /*
2063c1812acSJung-uk Kim      * Check for a so-called "null descriptor". These are descriptors that are
2073c1812acSJung-uk Kim      * created with most fields set to zero. The intent is that the descriptor
2083c1812acSJung-uk Kim      * will be updated/completed at runtime via a BufferField.
2093c1812acSJung-uk Kim      *
2103c1812acSJung-uk Kim      * If the descriptor does NOT have a resource tag, it cannot be referenced
2113c1812acSJung-uk Kim      * by a BufferField and we will flag this as an error. Conversely, if
2123c1812acSJung-uk Kim      * the descriptor has a resource tag, we will assume that a BufferField
2133c1812acSJung-uk Kim      * will be used to dynamically update it, so no error.
2143c1812acSJung-uk Kim      *
2153c1812acSJung-uk Kim      * A possible enhancement to this check would be to verify that in fact
2163c1812acSJung-uk Kim      * a BufferField is created using the resource tag, and perhaps even
2173c1812acSJung-uk Kim      * verify that a Store is performed to the BufferField.
2183c1812acSJung-uk Kim      *
2193c1812acSJung-uk Kim      * Note: for these descriptors, Alignment is allowed to be zero
2203c1812acSJung-uk Kim      */
2213c1812acSJung-uk Kim     if (!Minimum && !Maximum && !Length)
2223c1812acSJung-uk Kim     {
2233c1812acSJung-uk Kim         if (!Op->Asl.ExternalName)
2243c1812acSJung-uk Kim         {
2253c1812acSJung-uk Kim             /* No resource tag. Descriptor is fixed and is also illegal */
2263c1812acSJung-uk Kim 
2273c1812acSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
2283c1812acSJung-uk Kim         }
2293c1812acSJung-uk Kim 
2303c1812acSJung-uk Kim         return;
2313c1812acSJung-uk Kim     }
2323c1812acSJung-uk Kim 
233313a0c13SJung-uk Kim     /*
234313a0c13SJung-uk Kim      * Range checks for Memory24 and Memory32.
235313a0c13SJung-uk Kim      * IO descriptor has different definition of min/max, don't check.
236313a0c13SJung-uk Kim      */
2373f5e024cSJung-uk Kim     if (Type != ACPI_RESOURCE_NAME_IO)
2383f5e024cSJung-uk Kim     {
2393f5e024cSJung-uk Kim         /* Basic checks on Min/Max/Length */
2403f5e024cSJung-uk Kim 
2413f5e024cSJung-uk Kim         if (Minimum > Maximum)
2423f5e024cSJung-uk Kim         {
2433f5e024cSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
2443f5e024cSJung-uk Kim         }
2453f5e024cSJung-uk Kim         else if (Length > (Maximum - Minimum + 1))
2463f5e024cSJung-uk Kim         {
2473f5e024cSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
2483f5e024cSJung-uk Kim         }
249313a0c13SJung-uk Kim 
250313a0c13SJung-uk Kim         /* Special case for Memory24, min/max values are compressed */
251313a0c13SJung-uk Kim 
252313a0c13SJung-uk Kim         if (Type == ACPI_RESOURCE_NAME_MEMORY24)
253313a0c13SJung-uk Kim         {
254313a0c13SJung-uk Kim             if (!Alignment) /* Alignment==0 means 64K alignment */
255313a0c13SJung-uk Kim             {
256313a0c13SJung-uk Kim                 Alignment = ACPI_UINT16_MAX + 1;
257313a0c13SJung-uk Kim             }
258313a0c13SJung-uk Kim 
259313a0c13SJung-uk Kim             Minimum <<= 8;
260313a0c13SJung-uk Kim             Maximum <<= 8;
261313a0c13SJung-uk Kim         }
2623f5e024cSJung-uk Kim     }
2633f5e024cSJung-uk Kim 
2643f5e024cSJung-uk Kim     /* Alignment of zero is not in ACPI spec, but is used to mean byte acc */
2653f5e024cSJung-uk Kim 
2663f5e024cSJung-uk Kim     if (!Alignment)
2673f5e024cSJung-uk Kim     {
2683f5e024cSJung-uk Kim         Alignment = 1;
2693f5e024cSJung-uk Kim     }
2703f5e024cSJung-uk Kim 
2713f5e024cSJung-uk Kim     /* Addresses must be an exact multiple of the alignment value */
2723f5e024cSJung-uk Kim 
2733f5e024cSJung-uk Kim     if (Minimum % Alignment)
2743f5e024cSJung-uk Kim     {
2753f5e024cSJung-uk Kim         AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
2763f5e024cSJung-uk Kim     }
2773f5e024cSJung-uk Kim     if (Maximum % Alignment)
2783f5e024cSJung-uk Kim     {
2793f5e024cSJung-uk Kim         AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL);
2803f5e024cSJung-uk Kim     }
2813f5e024cSJung-uk Kim }
2823f5e024cSJung-uk Kim 
2833f5e024cSJung-uk Kim 
2843f5e024cSJung-uk Kim /*******************************************************************************
2853f5e024cSJung-uk Kim  *
2863f5e024cSJung-uk Kim  * FUNCTION:    RsLargeAddressCheck
2873f5e024cSJung-uk Kim  *
2883f5e024cSJung-uk Kim  * PARAMETERS:  Minimum             - Address Min value
2893f5e024cSJung-uk Kim  *              Maximum             - Address Max value
2903f5e024cSJung-uk Kim  *              Length              - Address range value
2913f5e024cSJung-uk Kim  *              Granularity         - Address granularity value
2923f5e024cSJung-uk Kim  *              Flags               - General flags for address descriptors:
2933f5e024cSJung-uk Kim  *                                    _MIF, _MAF, _DEC
2943f5e024cSJung-uk Kim  *              MinOp               - Original Op for Address Min
2953f5e024cSJung-uk Kim  *              MaxOp               - Original Op for Address Max
2963f5e024cSJung-uk Kim  *              LengthOp            - Original Op for address range
2973f5e024cSJung-uk Kim  *              GranOp              - Original Op for address granularity
2983c1812acSJung-uk Kim  *              Op                  - Parent Op for entire construct
2993f5e024cSJung-uk Kim  *
3003f5e024cSJung-uk Kim  * RETURN:      None. Adds error messages to error log if necessary
3013f5e024cSJung-uk Kim  *
3023f5e024cSJung-uk Kim  * DESCRIPTION: Perform common value checks for "large" address descriptors.
3033f5e024cSJung-uk Kim  *              Currently:
3043f5e024cSJung-uk Kim  *                  WordIo,     WordBusNumber,  WordSpace
3053f5e024cSJung-uk Kim  *                  DWordIo,    DWordMemory,    DWordSpace
3063f5e024cSJung-uk Kim  *                  QWordIo,    QWordMemory,    QWordSpace
3073f5e024cSJung-uk Kim  *                  ExtendedIo, ExtendedMemory, ExtendedSpace
3083f5e024cSJung-uk Kim  *
3093f5e024cSJung-uk Kim  * _MIF flag set means that the minimum address is fixed and is not relocatable
3103f5e024cSJung-uk Kim  * _MAF flag set means that the maximum address is fixed and is not relocatable
3113f5e024cSJung-uk Kim  * Length of zero means that the record size is variable
3123f5e024cSJung-uk Kim  *
3133f5e024cSJung-uk Kim  * This function implements the LEN/MIF/MAF/MIN/MAX/GRA rules within Table 6-40
3143f5e024cSJung-uk Kim  * of the ACPI 4.0a specification. Added 04/2010.
3153f5e024cSJung-uk Kim  *
3163f5e024cSJung-uk Kim  ******************************************************************************/
3173f5e024cSJung-uk Kim 
3183f5e024cSJung-uk Kim void
RsLargeAddressCheck(UINT64 Minimum,UINT64 Maximum,UINT64 Length,UINT64 Granularity,UINT8 Flags,ACPI_PARSE_OBJECT * MinOp,ACPI_PARSE_OBJECT * MaxOp,ACPI_PARSE_OBJECT * LengthOp,ACPI_PARSE_OBJECT * GranOp,ACPI_PARSE_OBJECT * Op)3193f5e024cSJung-uk Kim RsLargeAddressCheck (
3203f5e024cSJung-uk Kim     UINT64                  Minimum,
3213f5e024cSJung-uk Kim     UINT64                  Maximum,
3223f5e024cSJung-uk Kim     UINT64                  Length,
3233f5e024cSJung-uk Kim     UINT64                  Granularity,
3243f5e024cSJung-uk Kim     UINT8                   Flags,
3253f5e024cSJung-uk Kim     ACPI_PARSE_OBJECT       *MinOp,
3263f5e024cSJung-uk Kim     ACPI_PARSE_OBJECT       *MaxOp,
3273f5e024cSJung-uk Kim     ACPI_PARSE_OBJECT       *LengthOp,
3283c1812acSJung-uk Kim     ACPI_PARSE_OBJECT       *GranOp,
3293c1812acSJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
3303f5e024cSJung-uk Kim {
3313f5e024cSJung-uk Kim 
3326f1f1a63SJung-uk Kim     if (AslGbl_NoResourceChecking)
3333f5e024cSJung-uk Kim     {
3343f5e024cSJung-uk Kim         return;
3353f5e024cSJung-uk Kim     }
3363f5e024cSJung-uk Kim 
3373c1812acSJung-uk Kim     /*
3383c1812acSJung-uk Kim      * Check for a so-called "null descriptor". These are descriptors that are
3393c1812acSJung-uk Kim      * created with most fields set to zero. The intent is that the descriptor
3403c1812acSJung-uk Kim      * will be updated/completed at runtime via a BufferField.
3413c1812acSJung-uk Kim      *
3423c1812acSJung-uk Kim      * If the descriptor does NOT have a resource tag, it cannot be referenced
3433c1812acSJung-uk Kim      * by a BufferField and we will flag this as an error. Conversely, if
3443c1812acSJung-uk Kim      * the descriptor has a resource tag, we will assume that a BufferField
3453c1812acSJung-uk Kim      * will be used to dynamically update it, so no error.
3463c1812acSJung-uk Kim      *
3473c1812acSJung-uk Kim      * A possible enhancement to this check would be to verify that in fact
3483c1812acSJung-uk Kim      * a BufferField is created using the resource tag, and perhaps even
3493c1812acSJung-uk Kim      * verify that a Store is performed to the BufferField.
3503c1812acSJung-uk Kim      */
3513c1812acSJung-uk Kim     if (!Minimum && !Maximum && !Length && !Granularity)
3523c1812acSJung-uk Kim     {
3533c1812acSJung-uk Kim         if (!Op->Asl.ExternalName)
3543c1812acSJung-uk Kim         {
3553c1812acSJung-uk Kim             /* No resource tag. Descriptor is fixed and is also illegal */
3563c1812acSJung-uk Kim 
3573c1812acSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
3583c1812acSJung-uk Kim         }
3593c1812acSJung-uk Kim 
3603c1812acSJung-uk Kim         return;
3613c1812acSJung-uk Kim     }
3623c1812acSJung-uk Kim 
3633f5e024cSJung-uk Kim     /* Basic checks on Min/Max/Length */
3643f5e024cSJung-uk Kim 
3653f5e024cSJung-uk Kim     if (Minimum > Maximum)
3663f5e024cSJung-uk Kim     {
3673f5e024cSJung-uk Kim         AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
3683f5e024cSJung-uk Kim         return;
3693f5e024cSJung-uk Kim     }
3703f5e024cSJung-uk Kim     else if (Length > (Maximum - Minimum + 1))
3713f5e024cSJung-uk Kim     {
3723f5e024cSJung-uk Kim         AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
3733f5e024cSJung-uk Kim         return;
3743f5e024cSJung-uk Kim     }
3753f5e024cSJung-uk Kim 
3763f5e024cSJung-uk Kim     /* If specified (non-zero), ensure granularity is a power-of-two minus one */
3773f5e024cSJung-uk Kim 
3783f5e024cSJung-uk Kim     if (Granularity)
3793f5e024cSJung-uk Kim     {
3803f5e024cSJung-uk Kim         if ((Granularity + 1) &
3813f5e024cSJung-uk Kim              Granularity)
3823f5e024cSJung-uk Kim         {
3833f5e024cSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL);
3843f5e024cSJung-uk Kim             return;
3853f5e024cSJung-uk Kim         }
3863f5e024cSJung-uk Kim     }
3873f5e024cSJung-uk Kim 
3883f5e024cSJung-uk Kim     /*
3893f5e024cSJung-uk Kim      * Check the various combinations of Length, MinFixed, and MaxFixed
3903f5e024cSJung-uk Kim      */
3913f5e024cSJung-uk Kim     if (Length)
3923f5e024cSJung-uk Kim     {
3933f5e024cSJung-uk Kim         /* Fixed non-zero length */
3943f5e024cSJung-uk Kim 
3953f5e024cSJung-uk Kim         switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
3963f5e024cSJung-uk Kim         {
3973f5e024cSJung-uk Kim         case 0:
3983f5e024cSJung-uk Kim             /*
3993f5e024cSJung-uk Kim              * Fixed length, variable locations (both _MIN and _MAX).
4003f5e024cSJung-uk Kim              * Length must be a multiple of granularity
4013f5e024cSJung-uk Kim              */
4023f5e024cSJung-uk Kim             if (Granularity & Length)
4033f5e024cSJung-uk Kim             {
4043f5e024cSJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL);
4053f5e024cSJung-uk Kim             }
4063f5e024cSJung-uk Kim             break;
4073f5e024cSJung-uk Kim 
4083f5e024cSJung-uk Kim         case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
4093f5e024cSJung-uk Kim 
4103f5e024cSJung-uk Kim             /* Fixed length, fixed location. Granularity must be zero */
4113f5e024cSJung-uk Kim 
4123f5e024cSJung-uk Kim             if (Granularity != 0)
4133f5e024cSJung-uk Kim             {
4143f5e024cSJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL);
4153f5e024cSJung-uk Kim             }
4163f5e024cSJung-uk Kim 
4173f5e024cSJung-uk Kim             /* Length must be exactly the size of the min/max window */
4183f5e024cSJung-uk Kim 
4193f5e024cSJung-uk Kim             if (Length != (Maximum - Minimum + 1))
4203f5e024cSJung-uk Kim             {
4213f5e024cSJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL);
4223f5e024cSJung-uk Kim             }
4233f5e024cSJung-uk Kim             break;
4243f5e024cSJung-uk Kim 
4253f5e024cSJung-uk Kim         /* All other combinations are invalid */
4263f5e024cSJung-uk Kim 
4273f5e024cSJung-uk Kim         case ACPI_RESOURCE_FLAG_MIF:
4283f5e024cSJung-uk Kim         case ACPI_RESOURCE_FLAG_MAF:
4293f5e024cSJung-uk Kim         default:
430a9d8d09cSJung-uk Kim 
4313f5e024cSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
4323f5e024cSJung-uk Kim         }
4333f5e024cSJung-uk Kim     }
4343f5e024cSJung-uk Kim     else
4353f5e024cSJung-uk Kim     {
4363f5e024cSJung-uk Kim         /* Variable length (length==0) */
4373f5e024cSJung-uk Kim 
4383f5e024cSJung-uk Kim         switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
4393f5e024cSJung-uk Kim         {
4403f5e024cSJung-uk Kim         case 0:
4413f5e024cSJung-uk Kim             /*
4423f5e024cSJung-uk Kim              * Both _MIN and _MAX are variable.
4433f5e024cSJung-uk Kim              * No additional requirements, just exit
4443f5e024cSJung-uk Kim              */
4453f5e024cSJung-uk Kim             break;
4463f5e024cSJung-uk Kim 
4473f5e024cSJung-uk Kim         case ACPI_RESOURCE_FLAG_MIF:
4483f5e024cSJung-uk Kim 
4493f5e024cSJung-uk Kim             /* _MIN is fixed. _MIN must be multiple of _GRA */
4503f5e024cSJung-uk Kim 
4513f5e024cSJung-uk Kim             /*
4523f5e024cSJung-uk Kim              * The granularity is defined by the ACPI specification to be a
4533f5e024cSJung-uk Kim              * power-of-two minus one, therefore the granularity is a
4543f5e024cSJung-uk Kim              * bitmask which can be used to easily validate the addresses.
4553f5e024cSJung-uk Kim              */
4563f5e024cSJung-uk Kim             if (Granularity & Minimum)
4573f5e024cSJung-uk Kim             {
4583f5e024cSJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
4593f5e024cSJung-uk Kim             }
4603f5e024cSJung-uk Kim             break;
4613f5e024cSJung-uk Kim 
4623f5e024cSJung-uk Kim         case ACPI_RESOURCE_FLAG_MAF:
4633f5e024cSJung-uk Kim 
4643f5e024cSJung-uk Kim             /* _MAX is fixed. (_MAX + 1) must be multiple of _GRA */
4653f5e024cSJung-uk Kim 
4663f5e024cSJung-uk Kim             if (Granularity & (Maximum + 1))
4673f5e024cSJung-uk Kim             {
4683f5e024cSJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, "-1");
4693f5e024cSJung-uk Kim             }
4703f5e024cSJung-uk Kim             break;
4713f5e024cSJung-uk Kim 
4723f5e024cSJung-uk Kim         /* Both MIF/MAF set is invalid if length is zero */
4733f5e024cSJung-uk Kim 
4743f5e024cSJung-uk Kim         case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
4753f5e024cSJung-uk Kim         default:
476a9d8d09cSJung-uk Kim 
4773f5e024cSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
4783f5e024cSJung-uk Kim         }
4793f5e024cSJung-uk Kim     }
4803f5e024cSJung-uk Kim }
4813f5e024cSJung-uk Kim 
4823f5e024cSJung-uk Kim 
4833f5e024cSJung-uk Kim /*******************************************************************************
4843f5e024cSJung-uk Kim  *
4853f5e024cSJung-uk Kim  * FUNCTION:    RsGetStringDataLength
4863f5e024cSJung-uk Kim  *
4873f5e024cSJung-uk Kim  * PARAMETERS:  InitializerOp     - Start of a subtree of init nodes
4883f5e024cSJung-uk Kim  *
4893f5e024cSJung-uk Kim  * RETURN:      Valid string length if a string node is found (otherwise 0)
4903f5e024cSJung-uk Kim  *
4913f5e024cSJung-uk Kim  * DESCRIPTION: In a list of peer nodes, find the first one that contains a
4923f5e024cSJung-uk Kim  *              string and return the length of the string.
4933f5e024cSJung-uk Kim  *
4943f5e024cSJung-uk Kim  ******************************************************************************/
4953f5e024cSJung-uk Kim 
4963f5e024cSJung-uk Kim UINT16
RsGetStringDataLength(ACPI_PARSE_OBJECT * InitializerOp)4973f5e024cSJung-uk Kim RsGetStringDataLength (
4983f5e024cSJung-uk Kim     ACPI_PARSE_OBJECT       *InitializerOp)
4993f5e024cSJung-uk Kim {
5003f5e024cSJung-uk Kim 
5013f5e024cSJung-uk Kim     while (InitializerOp)
5023f5e024cSJung-uk Kim     {
5033f5e024cSJung-uk Kim         if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)
5043f5e024cSJung-uk Kim         {
5053f5e024cSJung-uk Kim             return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1));
5063f5e024cSJung-uk Kim         }
507f8146b88SJung-uk Kim 
5083f5e024cSJung-uk Kim         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
5093f5e024cSJung-uk Kim     }
5103f5e024cSJung-uk Kim 
5118ef1a331SJung-uk Kim     return (0);
5123f5e024cSJung-uk Kim }
5133f5e024cSJung-uk Kim 
5143f5e024cSJung-uk Kim 
5153f5e024cSJung-uk Kim /*******************************************************************************
5163f5e024cSJung-uk Kim  *
51753289f6aSNate Lawson  * FUNCTION:    RsAllocateResourceNode
51853289f6aSNate Lawson  *
51953289f6aSNate Lawson  * PARAMETERS:  Size        - Size of node in bytes
52053289f6aSNate Lawson  *
52153289f6aSNate Lawson  * RETURN:      The allocated node - aborts on allocation failure
52253289f6aSNate Lawson  *
52353289f6aSNate Lawson  * DESCRIPTION: Allocate a resource description node and the resource
52453289f6aSNate Lawson  *              descriptor itself (the nodes are used to link descriptors).
52553289f6aSNate Lawson  *
52653289f6aSNate Lawson  ******************************************************************************/
52753289f6aSNate Lawson 
52853289f6aSNate Lawson ASL_RESOURCE_NODE *
RsAllocateResourceNode(UINT32 Size)52953289f6aSNate Lawson RsAllocateResourceNode (
53053289f6aSNate Lawson     UINT32                  Size)
53153289f6aSNate Lawson {
53253289f6aSNate Lawson     ASL_RESOURCE_NODE       *Rnode;
53353289f6aSNate Lawson 
53453289f6aSNate Lawson 
53553289f6aSNate Lawson     /* Allocate the node */
53653289f6aSNate Lawson 
53753289f6aSNate Lawson     Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
53853289f6aSNate Lawson 
53953289f6aSNate Lawson     /* Allocate the resource descriptor itself */
54053289f6aSNate Lawson 
54153289f6aSNate Lawson     Rnode->Buffer = UtLocalCalloc (Size);
54253289f6aSNate Lawson     Rnode->BufferLength = Size;
54353289f6aSNate Lawson     return (Rnode);
54453289f6aSNate Lawson }
54553289f6aSNate Lawson 
54653289f6aSNate Lawson 
54753289f6aSNate Lawson /*******************************************************************************
54853289f6aSNate Lawson  *
5493f0275a0SJung-uk Kim  * FUNCTION:    RsCreateResourceField
55053289f6aSNate Lawson  *
55153289f6aSNate Lawson  * PARAMETERS:  Op              - Resource field node
55253289f6aSNate Lawson  *              Name            - Name of the field (Used only to reference
55353289f6aSNate Lawson  *                                the field in the ASL, not in the AML)
55453289f6aSNate Lawson  *              ByteOffset      - Offset from the field start
55553289f6aSNate Lawson  *              BitOffset       - Additional bit offset
5563f0275a0SJung-uk Kim  *              BitLength       - Number of bits in the field
55753289f6aSNate Lawson  *
55853289f6aSNate Lawson  * RETURN:      None, sets fields within the input node
55953289f6aSNate Lawson  *
56053289f6aSNate Lawson  * DESCRIPTION: Utility function to generate a named bit field within a
56153289f6aSNate Lawson  *              resource descriptor. Mark a node as 1) a field in a resource
56253289f6aSNate Lawson  *              descriptor, and 2) set the value to be a BIT offset
56353289f6aSNate Lawson  *
56453289f6aSNate Lawson  ******************************************************************************/
56553289f6aSNate Lawson 
56653289f6aSNate Lawson void
RsCreateResourceField(ACPI_PARSE_OBJECT * Op,char * Name,UINT32 ByteOffset,UINT32 BitOffset,UINT32 BitLength)5673f0275a0SJung-uk Kim RsCreateResourceField (
56853289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
56953289f6aSNate Lawson     char                    *Name,
57053289f6aSNate Lawson     UINT32                  ByteOffset,
5713f0275a0SJung-uk Kim     UINT32                  BitOffset,
5723f0275a0SJung-uk Kim     UINT32                  BitLength)
57353289f6aSNate Lawson {
57453289f6aSNate Lawson 
57553289f6aSNate Lawson     Op->Asl.ExternalName = Name;
5765f9b24faSJung-uk Kim     Op->Asl.CompileFlags |= OP_IS_RESOURCE_FIELD;
5773f0275a0SJung-uk Kim 
5783f0275a0SJung-uk Kim     Op->Asl.Value.Tag.BitOffset = (ByteOffset * 8) + BitOffset;
5793f0275a0SJung-uk Kim     Op->Asl.Value.Tag.BitLength = BitLength;
58053289f6aSNate Lawson }
58153289f6aSNate Lawson 
58253289f6aSNate Lawson 
58353289f6aSNate Lawson /*******************************************************************************
58453289f6aSNate Lawson  *
58553289f6aSNate Lawson  * FUNCTION:    RsSetFlagBits
58653289f6aSNate Lawson  *
58753289f6aSNate Lawson  * PARAMETERS:  *Flags          - Pointer to the flag byte
58853289f6aSNate Lawson  *              Op              - Flag initialization node
58953289f6aSNate Lawson  *              Position        - Bit position within the flag byte
59053289f6aSNate Lawson  *              Default         - Used if the node is DEFAULT.
59153289f6aSNate Lawson  *
59253289f6aSNate Lawson  * RETURN:      Sets bits within the *Flags output byte.
59353289f6aSNate Lawson  *
59453289f6aSNate Lawson  * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
59553289f6aSNate Lawson  *              node. Will use a default value if the node is DEFAULT, meaning
59653289f6aSNate Lawson  *              that no value was specified in the ASL. Used to merge multiple
59753289f6aSNate Lawson  *              keywords into a single flags byte.
59853289f6aSNate Lawson  *
59953289f6aSNate Lawson  ******************************************************************************/
60053289f6aSNate Lawson 
60153289f6aSNate Lawson void
RsSetFlagBits(UINT8 * Flags,ACPI_PARSE_OBJECT * Op,UINT8 Position,UINT8 DefaultBit)60253289f6aSNate Lawson RsSetFlagBits (
60353289f6aSNate Lawson     UINT8                   *Flags,
60453289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
60553289f6aSNate Lawson     UINT8                   Position,
60653289f6aSNate Lawson     UINT8                   DefaultBit)
60753289f6aSNate Lawson {
60853289f6aSNate Lawson 
60953289f6aSNate Lawson     if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
61053289f6aSNate Lawson     {
61153289f6aSNate Lawson         /* Use the default bit */
61253289f6aSNate Lawson 
61353289f6aSNate Lawson         *Flags |= (DefaultBit << Position);
61453289f6aSNate Lawson     }
61553289f6aSNate Lawson     else
61653289f6aSNate Lawson     {
61753289f6aSNate Lawson         /* Use the bit specified in the initialization node */
61853289f6aSNate Lawson 
61953289f6aSNate Lawson         *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
62053289f6aSNate Lawson     }
62153289f6aSNate Lawson }
62253289f6aSNate Lawson 
62353289f6aSNate Lawson 
6243f0275a0SJung-uk Kim void
RsSetFlagBits16(UINT16 * Flags,ACPI_PARSE_OBJECT * Op,UINT8 Position,UINT8 DefaultBit)6253f0275a0SJung-uk Kim RsSetFlagBits16 (
6263f0275a0SJung-uk Kim     UINT16                  *Flags,
6273f0275a0SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
6283f0275a0SJung-uk Kim     UINT8                   Position,
6293f0275a0SJung-uk Kim     UINT8                   DefaultBit)
6303f0275a0SJung-uk Kim {
6313f0275a0SJung-uk Kim 
6323f0275a0SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
6333f0275a0SJung-uk Kim     {
6343f0275a0SJung-uk Kim         /* Use the default bit */
6353f0275a0SJung-uk Kim 
6363f0275a0SJung-uk Kim         *Flags |= (DefaultBit << Position);
6373f0275a0SJung-uk Kim     }
6383f0275a0SJung-uk Kim     else
6393f0275a0SJung-uk Kim     {
6403f0275a0SJung-uk Kim         /* Use the bit specified in the initialization node */
6413f0275a0SJung-uk Kim 
6423f0275a0SJung-uk Kim         *Flags |= (((UINT16) Op->Asl.Value.Integer) << Position);
6433f0275a0SJung-uk Kim     }
6443f0275a0SJung-uk Kim }
6453f0275a0SJung-uk Kim 
6463f0275a0SJung-uk Kim 
64753289f6aSNate Lawson /*******************************************************************************
64853289f6aSNate Lawson  *
64953289f6aSNate Lawson  * FUNCTION:    RsCompleteNodeAndGetNext
65053289f6aSNate Lawson  *
65153289f6aSNate Lawson  * PARAMETERS:  Op            - Resource node to be completed
65253289f6aSNate Lawson  *
65353289f6aSNate Lawson  * RETURN:      The next peer to the input node.
65453289f6aSNate Lawson  *
65553289f6aSNate Lawson  * DESCRIPTION: Mark the current node completed and return the next peer.
65653289f6aSNate Lawson  *              The node ParseOpcode is set to DEFAULT_ARG, meaning that
65753289f6aSNate Lawson  *              this node is to be ignored from now on.
65853289f6aSNate Lawson  *
65953289f6aSNate Lawson  ******************************************************************************/
66053289f6aSNate Lawson 
66153289f6aSNate Lawson ACPI_PARSE_OBJECT *
RsCompleteNodeAndGetNext(ACPI_PARSE_OBJECT * Op)66253289f6aSNate Lawson RsCompleteNodeAndGetNext (
66353289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op)
66453289f6aSNate Lawson {
66553289f6aSNate Lawson 
66653289f6aSNate Lawson     /* Mark this node unused */
66753289f6aSNate Lawson 
66853289f6aSNate Lawson     Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
66953289f6aSNate Lawson 
67053289f6aSNate Lawson     /* Move on to the next peer node in the initializer list */
67153289f6aSNate Lawson 
67253289f6aSNate Lawson     return (ASL_GET_PEER_NODE (Op));
67353289f6aSNate Lawson }
67453289f6aSNate Lawson 
67553289f6aSNate Lawson 
67653289f6aSNate Lawson /*******************************************************************************
67753289f6aSNate Lawson  *
678fba7fc7eSJung-uk Kim  * FUNCTION:    RsCheckListForDuplicates
679fba7fc7eSJung-uk Kim  *
680fba7fc7eSJung-uk Kim  * PARAMETERS:  Op                  - First op in the initializer list
681fba7fc7eSJung-uk Kim  *
682fba7fc7eSJung-uk Kim  * RETURN:      None
683fba7fc7eSJung-uk Kim  *
684fba7fc7eSJung-uk Kim  * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
685fba7fc7eSJung-uk Kim  *              if any duplicates are found.
686fba7fc7eSJung-uk Kim  *
687fba7fc7eSJung-uk Kim  ******************************************************************************/
688fba7fc7eSJung-uk Kim 
689fba7fc7eSJung-uk Kim void
RsCheckListForDuplicates(ACPI_PARSE_OBJECT * Op)690fba7fc7eSJung-uk Kim RsCheckListForDuplicates (
691fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
692fba7fc7eSJung-uk Kim {
693fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *NextValueOp = Op;
694fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *NextOp;
695fba7fc7eSJung-uk Kim     UINT32                  Value;
696fba7fc7eSJung-uk Kim 
697fba7fc7eSJung-uk Kim 
698fba7fc7eSJung-uk Kim     if (!Op)
699fba7fc7eSJung-uk Kim     {
700fba7fc7eSJung-uk Kim         return;
701fba7fc7eSJung-uk Kim     }
702fba7fc7eSJung-uk Kim 
703fba7fc7eSJung-uk Kim     /* Search list once for each value in the list */
704fba7fc7eSJung-uk Kim 
705fba7fc7eSJung-uk Kim     while (NextValueOp)
706fba7fc7eSJung-uk Kim     {
707fba7fc7eSJung-uk Kim         Value = (UINT32) NextValueOp->Asl.Value.Integer;
708fba7fc7eSJung-uk Kim 
709fba7fc7eSJung-uk Kim         /* Compare this value to all remaining values in the list */
710fba7fc7eSJung-uk Kim 
711fba7fc7eSJung-uk Kim         NextOp = ASL_GET_PEER_NODE (NextValueOp);
712fba7fc7eSJung-uk Kim         while (NextOp)
713fba7fc7eSJung-uk Kim         {
714fba7fc7eSJung-uk Kim             if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
715fba7fc7eSJung-uk Kim             {
716fba7fc7eSJung-uk Kim                 /* Compare values */
717fba7fc7eSJung-uk Kim 
718fba7fc7eSJung-uk Kim                 if (Value == (UINT32) NextOp->Asl.Value.Integer)
719fba7fc7eSJung-uk Kim                 {
720fba7fc7eSJung-uk Kim                     /* Emit error only once per duplicate node */
721fba7fc7eSJung-uk Kim 
7225f9b24faSJung-uk Kim                     if (!(NextOp->Asl.CompileFlags & OP_IS_DUPLICATE))
723fba7fc7eSJung-uk Kim                     {
7245f9b24faSJung-uk Kim                         NextOp->Asl.CompileFlags |= OP_IS_DUPLICATE;
725fba7fc7eSJung-uk Kim                         AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
726fba7fc7eSJung-uk Kim                             NextOp, NULL);
727fba7fc7eSJung-uk Kim                     }
728fba7fc7eSJung-uk Kim                 }
729fba7fc7eSJung-uk Kim             }
730fba7fc7eSJung-uk Kim 
731fba7fc7eSJung-uk Kim             NextOp = ASL_GET_PEER_NODE (NextOp);
732fba7fc7eSJung-uk Kim         }
733fba7fc7eSJung-uk Kim 
734fba7fc7eSJung-uk Kim         NextValueOp = ASL_GET_PEER_NODE (NextValueOp);
735fba7fc7eSJung-uk Kim     }
736fba7fc7eSJung-uk Kim }
737fba7fc7eSJung-uk Kim 
738fba7fc7eSJung-uk Kim 
739fba7fc7eSJung-uk Kim /*******************************************************************************
740fba7fc7eSJung-uk Kim  *
74153289f6aSNate Lawson  * FUNCTION:    RsDoOneResourceDescriptor
74253289f6aSNate Lawson  *
74353289f6aSNate Lawson  * PARAMETERS:  DescriptorTypeOp    - Parent parse node of the descriptor
74453289f6aSNate Lawson  *              CurrentByteOffset   - Offset in the resource descriptor
74553289f6aSNate Lawson  *                                    buffer.
74653289f6aSNate Lawson  *
74753289f6aSNate Lawson  * RETURN:      A valid resource node for the descriptor
74853289f6aSNate Lawson  *
74953289f6aSNate Lawson  * DESCRIPTION: Dispatches the processing of one resource descriptor
75053289f6aSNate Lawson  *
75153289f6aSNate Lawson  ******************************************************************************/
75253289f6aSNate Lawson 
75353289f6aSNate Lawson ASL_RESOURCE_NODE *
RsDoOneResourceDescriptor(ASL_RESOURCE_INFO * Info,UINT8 * State)75453289f6aSNate Lawson RsDoOneResourceDescriptor (
755313a0c13SJung-uk Kim     ASL_RESOURCE_INFO       *Info,
75653289f6aSNate Lawson     UINT8                   *State)
75753289f6aSNate Lawson {
75853289f6aSNate Lawson     ASL_RESOURCE_NODE       *Rnode = NULL;
75953289f6aSNate Lawson 
76053289f6aSNate Lawson 
7611a39cfb0SJung-uk Kim     /* Construct the resource */
76253289f6aSNate Lawson 
763313a0c13SJung-uk Kim     switch (Info->DescriptorTypeOp->Asl.ParseOpcode)
76453289f6aSNate Lawson     {
765*722b1667SJung-uk Kim 
766*722b1667SJung-uk Kim     case PARSEOP_CLOCKINPUT:
767*722b1667SJung-uk Kim 
768*722b1667SJung-uk Kim         Rnode = RsDoClockInputDescriptor(Info);
769*722b1667SJung-uk Kim         break;
770*722b1667SJung-uk Kim 
77153289f6aSNate Lawson     case PARSEOP_DMA:
772a9d8d09cSJung-uk Kim 
773313a0c13SJung-uk Kim         Rnode = RsDoDmaDescriptor (Info);
77453289f6aSNate Lawson         break;
77553289f6aSNate Lawson 
7763f0275a0SJung-uk Kim     case PARSEOP_FIXEDDMA:
777a9d8d09cSJung-uk Kim 
778313a0c13SJung-uk Kim         Rnode = RsDoFixedDmaDescriptor (Info);
7793f0275a0SJung-uk Kim         break;
7803f0275a0SJung-uk Kim 
78153289f6aSNate Lawson     case PARSEOP_DWORDIO:
782a9d8d09cSJung-uk Kim 
783313a0c13SJung-uk Kim         Rnode = RsDoDwordIoDescriptor (Info);
78453289f6aSNate Lawson         break;
78553289f6aSNate Lawson 
78653289f6aSNate Lawson     case PARSEOP_DWORDMEMORY:
787a9d8d09cSJung-uk Kim 
788313a0c13SJung-uk Kim         Rnode = RsDoDwordMemoryDescriptor (Info);
789fba7fc7eSJung-uk Kim         break;
790fba7fc7eSJung-uk Kim 
791fba7fc7eSJung-uk Kim     case PARSEOP_DWORDSPACE:
792a9d8d09cSJung-uk Kim 
793313a0c13SJung-uk Kim         Rnode = RsDoDwordSpaceDescriptor (Info);
79453289f6aSNate Lawson         break;
79553289f6aSNate Lawson 
79653289f6aSNate Lawson     case PARSEOP_ENDDEPENDENTFN:
797a9d8d09cSJung-uk Kim 
79853289f6aSNate Lawson         switch (*State)
79953289f6aSNate Lawson         {
80053289f6aSNate Lawson         case ACPI_RSTATE_NORMAL:
801a9d8d09cSJung-uk Kim 
802fba7fc7eSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
803313a0c13SJung-uk Kim                 Info->DescriptorTypeOp, NULL);
80453289f6aSNate Lawson             break;
80553289f6aSNate Lawson 
80653289f6aSNate Lawson         case ACPI_RSTATE_START_DEPENDENT:
807a9d8d09cSJung-uk Kim 
808fba7fc7eSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
809313a0c13SJung-uk Kim                 Info->DescriptorTypeOp, NULL);
81053289f6aSNate Lawson             break;
81153289f6aSNate Lawson 
81253289f6aSNate Lawson         case ACPI_RSTATE_DEPENDENT_LIST:
81353289f6aSNate Lawson         default:
814a9d8d09cSJung-uk Kim 
81553289f6aSNate Lawson             break;
81653289f6aSNate Lawson         }
81753289f6aSNate Lawson 
81853289f6aSNate Lawson         *State = ACPI_RSTATE_NORMAL;
819313a0c13SJung-uk Kim         Rnode = RsDoEndDependentDescriptor (Info);
820fba7fc7eSJung-uk Kim         break;
821fba7fc7eSJung-uk Kim 
8221a39cfb0SJung-uk Kim     case PARSEOP_ENDTAG:
823a9d8d09cSJung-uk Kim 
824313a0c13SJung-uk Kim         Rnode = RsDoEndTagDescriptor (Info);
8251a39cfb0SJung-uk Kim         break;
8261a39cfb0SJung-uk Kim 
827fba7fc7eSJung-uk Kim     case PARSEOP_EXTENDEDIO:
828a9d8d09cSJung-uk Kim 
829313a0c13SJung-uk Kim         Rnode = RsDoExtendedIoDescriptor (Info);
830fba7fc7eSJung-uk Kim         break;
831fba7fc7eSJung-uk Kim 
832fba7fc7eSJung-uk Kim     case PARSEOP_EXTENDEDMEMORY:
833a9d8d09cSJung-uk Kim 
834313a0c13SJung-uk Kim         Rnode = RsDoExtendedMemoryDescriptor (Info);
835fba7fc7eSJung-uk Kim         break;
836fba7fc7eSJung-uk Kim 
837fba7fc7eSJung-uk Kim     case PARSEOP_EXTENDEDSPACE:
838a9d8d09cSJung-uk Kim 
839313a0c13SJung-uk Kim         Rnode = RsDoExtendedSpaceDescriptor (Info);
84053289f6aSNate Lawson         break;
84153289f6aSNate Lawson 
84253289f6aSNate Lawson     case PARSEOP_FIXEDIO:
843a9d8d09cSJung-uk Kim 
844313a0c13SJung-uk Kim         Rnode = RsDoFixedIoDescriptor (Info);
84553289f6aSNate Lawson         break;
84653289f6aSNate Lawson 
84753289f6aSNate Lawson     case PARSEOP_INTERRUPT:
848a9d8d09cSJung-uk Kim 
849313a0c13SJung-uk Kim         Rnode = RsDoInterruptDescriptor (Info);
85053289f6aSNate Lawson         break;
85153289f6aSNate Lawson 
85253289f6aSNate Lawson     case PARSEOP_IO:
853a9d8d09cSJung-uk Kim 
854313a0c13SJung-uk Kim         Rnode = RsDoIoDescriptor (Info);
85553289f6aSNate Lawson         break;
85653289f6aSNate Lawson 
85753289f6aSNate Lawson     case PARSEOP_IRQ:
858a9d8d09cSJung-uk Kim 
859313a0c13SJung-uk Kim         Rnode = RsDoIrqDescriptor (Info);
86053289f6aSNate Lawson         break;
86153289f6aSNate Lawson 
86253289f6aSNate Lawson     case PARSEOP_IRQNOFLAGS:
863a9d8d09cSJung-uk Kim 
864313a0c13SJung-uk Kim         Rnode = RsDoIrqNoFlagsDescriptor (Info);
86553289f6aSNate Lawson         break;
86653289f6aSNate Lawson 
86753289f6aSNate Lawson     case PARSEOP_MEMORY24:
868a9d8d09cSJung-uk Kim 
869313a0c13SJung-uk Kim         Rnode = RsDoMemory24Descriptor (Info);
87053289f6aSNate Lawson         break;
87153289f6aSNate Lawson 
87253289f6aSNate Lawson     case PARSEOP_MEMORY32:
873a9d8d09cSJung-uk Kim 
874313a0c13SJung-uk Kim         Rnode = RsDoMemory32Descriptor (Info);
87553289f6aSNate Lawson         break;
87653289f6aSNate Lawson 
87753289f6aSNate Lawson     case PARSEOP_MEMORY32FIXED:
878a9d8d09cSJung-uk Kim 
879313a0c13SJung-uk Kim         Rnode = RsDoMemory32FixedDescriptor (Info);
88053289f6aSNate Lawson         break;
88153289f6aSNate Lawson 
88253289f6aSNate Lawson     case PARSEOP_QWORDIO:
883a9d8d09cSJung-uk Kim 
884313a0c13SJung-uk Kim         Rnode = RsDoQwordIoDescriptor (Info);
88553289f6aSNate Lawson         break;
88653289f6aSNate Lawson 
88753289f6aSNate Lawson     case PARSEOP_QWORDMEMORY:
888a9d8d09cSJung-uk Kim 
889313a0c13SJung-uk Kim         Rnode = RsDoQwordMemoryDescriptor (Info);
890fba7fc7eSJung-uk Kim         break;
891fba7fc7eSJung-uk Kim 
892fba7fc7eSJung-uk Kim     case PARSEOP_QWORDSPACE:
893a9d8d09cSJung-uk Kim 
894313a0c13SJung-uk Kim         Rnode = RsDoQwordSpaceDescriptor (Info);
89553289f6aSNate Lawson         break;
89653289f6aSNate Lawson 
89753289f6aSNate Lawson     case PARSEOP_REGISTER:
898a9d8d09cSJung-uk Kim 
899313a0c13SJung-uk Kim         Rnode = RsDoGeneralRegisterDescriptor (Info);
90053289f6aSNate Lawson         break;
90153289f6aSNate Lawson 
90253289f6aSNate Lawson     case PARSEOP_STARTDEPENDENTFN:
903a9d8d09cSJung-uk Kim 
90453289f6aSNate Lawson         switch (*State)
90553289f6aSNate Lawson         {
90653289f6aSNate Lawson         case ACPI_RSTATE_START_DEPENDENT:
907a9d8d09cSJung-uk Kim 
908fba7fc7eSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
909313a0c13SJung-uk Kim                 Info->DescriptorTypeOp, NULL);
91053289f6aSNate Lawson             break;
91153289f6aSNate Lawson 
91253289f6aSNate Lawson         case ACPI_RSTATE_NORMAL:
91353289f6aSNate Lawson         case ACPI_RSTATE_DEPENDENT_LIST:
91453289f6aSNate Lawson         default:
915a9d8d09cSJung-uk Kim 
91653289f6aSNate Lawson             break;
91753289f6aSNate Lawson         }
91853289f6aSNate Lawson 
91953289f6aSNate Lawson         *State = ACPI_RSTATE_START_DEPENDENT;
920313a0c13SJung-uk Kim         Rnode = RsDoStartDependentDescriptor (Info);
92153289f6aSNate Lawson         *State = ACPI_RSTATE_DEPENDENT_LIST;
92253289f6aSNate Lawson         break;
92353289f6aSNate Lawson 
92453289f6aSNate Lawson     case PARSEOP_STARTDEPENDENTFN_NOPRI:
925a9d8d09cSJung-uk Kim 
92653289f6aSNate Lawson         switch (*State)
92753289f6aSNate Lawson         {
92853289f6aSNate Lawson         case ACPI_RSTATE_START_DEPENDENT:
929a9d8d09cSJung-uk Kim 
930fba7fc7eSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
931313a0c13SJung-uk Kim                 Info->DescriptorTypeOp, NULL);
93253289f6aSNate Lawson             break;
93353289f6aSNate Lawson 
93453289f6aSNate Lawson         case ACPI_RSTATE_NORMAL:
93553289f6aSNate Lawson         case ACPI_RSTATE_DEPENDENT_LIST:
93653289f6aSNate Lawson         default:
937a9d8d09cSJung-uk Kim 
93853289f6aSNate Lawson             break;
93953289f6aSNate Lawson         }
94053289f6aSNate Lawson 
94153289f6aSNate Lawson         *State = ACPI_RSTATE_START_DEPENDENT;
942313a0c13SJung-uk Kim         Rnode = RsDoStartDependentNoPriDescriptor (Info);
94353289f6aSNate Lawson         *State = ACPI_RSTATE_DEPENDENT_LIST;
94453289f6aSNate Lawson         break;
94553289f6aSNate Lawson 
94653289f6aSNate Lawson     case PARSEOP_VENDORLONG:
947a9d8d09cSJung-uk Kim 
948313a0c13SJung-uk Kim         Rnode = RsDoVendorLargeDescriptor (Info);
94953289f6aSNate Lawson         break;
95053289f6aSNate Lawson 
95153289f6aSNate Lawson     case PARSEOP_VENDORSHORT:
952a9d8d09cSJung-uk Kim 
953313a0c13SJung-uk Kim         Rnode = RsDoVendorSmallDescriptor (Info);
95453289f6aSNate Lawson         break;
95553289f6aSNate Lawson 
95653289f6aSNate Lawson     case PARSEOP_WORDBUSNUMBER:
957a9d8d09cSJung-uk Kim 
958313a0c13SJung-uk Kim         Rnode = RsDoWordBusNumberDescriptor (Info);
95953289f6aSNate Lawson         break;
96053289f6aSNate Lawson 
96153289f6aSNate Lawson     case PARSEOP_WORDIO:
962a9d8d09cSJung-uk Kim 
963313a0c13SJung-uk Kim         Rnode = RsDoWordIoDescriptor (Info);
964fba7fc7eSJung-uk Kim         break;
965fba7fc7eSJung-uk Kim 
966fba7fc7eSJung-uk Kim     case PARSEOP_WORDSPACE:
967a9d8d09cSJung-uk Kim 
968313a0c13SJung-uk Kim         Rnode = RsDoWordSpaceDescriptor (Info);
96953289f6aSNate Lawson         break;
97053289f6aSNate Lawson 
9713f0275a0SJung-uk Kim     case PARSEOP_GPIO_INT:
972a9d8d09cSJung-uk Kim 
973313a0c13SJung-uk Kim         Rnode = RsDoGpioIntDescriptor (Info);
9743f0275a0SJung-uk Kim         break;
9753f0275a0SJung-uk Kim 
9763f0275a0SJung-uk Kim     case PARSEOP_GPIO_IO:
977a9d8d09cSJung-uk Kim 
978313a0c13SJung-uk Kim         Rnode = RsDoGpioIoDescriptor (Info);
9793f0275a0SJung-uk Kim         break;
9803f0275a0SJung-uk Kim 
9813f0275a0SJung-uk Kim     case PARSEOP_I2C_SERIALBUS:
982f8146b88SJung-uk Kim     case PARSEOP_I2C_SERIALBUS_V2:
983a9d8d09cSJung-uk Kim 
984313a0c13SJung-uk Kim         Rnode = RsDoI2cSerialBusDescriptor (Info);
9853f0275a0SJung-uk Kim         break;
9863f0275a0SJung-uk Kim 
9873f0275a0SJung-uk Kim     case PARSEOP_SPI_SERIALBUS:
988f8146b88SJung-uk Kim     case PARSEOP_SPI_SERIALBUS_V2:
989a9d8d09cSJung-uk Kim 
990313a0c13SJung-uk Kim         Rnode = RsDoSpiSerialBusDescriptor (Info);
9913f0275a0SJung-uk Kim         break;
9923f0275a0SJung-uk Kim 
9933f0275a0SJung-uk Kim     case PARSEOP_UART_SERIALBUS:
994f8146b88SJung-uk Kim     case PARSEOP_UART_SERIALBUS_V2:
995a9d8d09cSJung-uk Kim 
996313a0c13SJung-uk Kim         Rnode = RsDoUartSerialBusDescriptor (Info);
9973f0275a0SJung-uk Kim         break;
9983f0275a0SJung-uk Kim 
999cfd1ed46SJung-uk Kim     case PARSEOP_CSI2_SERIALBUS:
1000cfd1ed46SJung-uk Kim 
1001cfd1ed46SJung-uk Kim         Rnode = RsDoCsi2SerialBusDescriptor (Info);
1002cfd1ed46SJung-uk Kim         break;
1003cfd1ed46SJung-uk Kim 
1004af051161SJung-uk Kim     case PARSEOP_PINCONFIG:
1005af051161SJung-uk Kim 
1006af051161SJung-uk Kim         Rnode = RsDoPinConfigDescriptor (Info);
1007af051161SJung-uk Kim         break;
1008af051161SJung-uk Kim 
1009af051161SJung-uk Kim     case PARSEOP_PINFUNCTION:
1010af051161SJung-uk Kim 
1011af051161SJung-uk Kim         Rnode = RsDoPinFunctionDescriptor (Info);
1012af051161SJung-uk Kim         break;
1013af051161SJung-uk Kim 
1014af051161SJung-uk Kim     case PARSEOP_PINGROUP:
1015af051161SJung-uk Kim 
1016af051161SJung-uk Kim         Rnode = RsDoPinGroupDescriptor (Info);
1017af051161SJung-uk Kim         break;
1018af051161SJung-uk Kim 
1019af051161SJung-uk Kim     case PARSEOP_PINGROUPFUNCTION:
1020af051161SJung-uk Kim 
1021af051161SJung-uk Kim         Rnode = RsDoPinGroupFunctionDescriptor (Info);
1022af051161SJung-uk Kim         break;
1023af051161SJung-uk Kim 
1024af051161SJung-uk Kim     case PARSEOP_PINGROUPCONFIG:
1025af051161SJung-uk Kim 
1026af051161SJung-uk Kim         Rnode = RsDoPinGroupConfigDescriptor (Info);
1027af051161SJung-uk Kim         break;
1028af051161SJung-uk Kim 
102953289f6aSNate Lawson     case PARSEOP_DEFAULT_ARG:
1030a9d8d09cSJung-uk Kim 
103153289f6aSNate Lawson         /* Just ignore any of these, they are used as fillers/placeholders */
103253289f6aSNate Lawson         break;
103353289f6aSNate Lawson 
103453289f6aSNate Lawson     default:
1035a9d8d09cSJung-uk Kim 
103653289f6aSNate Lawson         printf ("Unknown resource descriptor type [%s]\n",
1037313a0c13SJung-uk Kim             Info->DescriptorTypeOp->Asl.ParseOpName);
103853289f6aSNate Lawson         break;
103953289f6aSNate Lawson     }
104053289f6aSNate Lawson 
104153289f6aSNate Lawson     /*
104253289f6aSNate Lawson      * Mark original node as unused, but head of a resource descriptor.
104353289f6aSNate Lawson      * This allows the resource to be installed in the namespace so that
104453289f6aSNate Lawson      * references to the descriptor can be resolved.
104553289f6aSNate Lawson      */
1046313a0c13SJung-uk Kim     Info->DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
10475f9b24faSJung-uk Kim     Info->DescriptorTypeOp->Asl.CompileFlags = OP_IS_RESOURCE_DESC;
1048313a0c13SJung-uk Kim     Info->DescriptorTypeOp->Asl.Value.Integer = Info->CurrentByteOffset;
10491a39cfb0SJung-uk Kim 
10501a39cfb0SJung-uk Kim     if (Rnode)
10511a39cfb0SJung-uk Kim     {
1052313a0c13SJung-uk Kim         Info->DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
1053f8146b88SJung-uk Kim         Info->DescriptorTypeOp->Asl.Extra =
1054f8146b88SJung-uk Kim             ((AML_RESOURCE *) Rnode->Buffer)->DescriptorType;
10551a39cfb0SJung-uk Kim     }
105653289f6aSNate Lawson 
105753289f6aSNate Lawson     return (Rnode);
105853289f6aSNate Lawson }
105953289f6aSNate Lawson 
106053289f6aSNate Lawson 
106153289f6aSNate Lawson /*******************************************************************************
106253289f6aSNate Lawson  *
106353289f6aSNate Lawson  * FUNCTION:    RsLinkDescriptorChain
106453289f6aSNate Lawson  *
106553289f6aSNate Lawson  * PARAMETERS:  PreviousRnode       - Pointer to the node that will be previous
106653289f6aSNate Lawson  *                                    to the linked node,  At exit, set to the
106753289f6aSNate Lawson  *                                    last node in the new chain.
106853289f6aSNate Lawson  *              Rnode               - Resource node to link into the list
106953289f6aSNate Lawson  *
107053289f6aSNate Lawson  * RETURN:      Cumulative buffer byte offset of the new segment of chain
107153289f6aSNate Lawson  *
107253289f6aSNate Lawson  * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
107353289f6aSNate Lawson  *
107453289f6aSNate Lawson  ******************************************************************************/
107553289f6aSNate Lawson 
107653289f6aSNate Lawson UINT32
RsLinkDescriptorChain(ASL_RESOURCE_NODE ** PreviousRnode,ASL_RESOURCE_NODE * Rnode)107753289f6aSNate Lawson RsLinkDescriptorChain (
107853289f6aSNate Lawson     ASL_RESOURCE_NODE       **PreviousRnode,
107953289f6aSNate Lawson     ASL_RESOURCE_NODE       *Rnode)
108053289f6aSNate Lawson {
108153289f6aSNate Lawson     ASL_RESOURCE_NODE       *LastRnode;
108253289f6aSNate Lawson     UINT32                  CurrentByteOffset;
108353289f6aSNate Lawson 
108453289f6aSNate Lawson 
108553289f6aSNate Lawson     /* Anything to do? */
108653289f6aSNate Lawson 
108753289f6aSNate Lawson     if (!Rnode)
108853289f6aSNate Lawson     {
10898ef1a331SJung-uk Kim         return (0);
109053289f6aSNate Lawson     }
109153289f6aSNate Lawson 
109253289f6aSNate Lawson     /* Point the previous node to the new node */
109353289f6aSNate Lawson 
109453289f6aSNate Lawson     (*PreviousRnode)->Next = Rnode;
109553289f6aSNate Lawson     CurrentByteOffset = Rnode->BufferLength;
109653289f6aSNate Lawson 
109753289f6aSNate Lawson     /* Walk to the end of the chain headed by Rnode */
109853289f6aSNate Lawson 
109953289f6aSNate Lawson     LastRnode = Rnode;
110053289f6aSNate Lawson     while (LastRnode->Next)
110153289f6aSNate Lawson     {
110253289f6aSNate Lawson         LastRnode = LastRnode->Next;
110353289f6aSNate Lawson         CurrentByteOffset += LastRnode->BufferLength;
110453289f6aSNate Lawson     }
110553289f6aSNate Lawson 
110653289f6aSNate Lawson     /* Previous node becomes the last node in the chain */
110753289f6aSNate Lawson 
110853289f6aSNate Lawson     *PreviousRnode = LastRnode;
11098ef1a331SJung-uk Kim     return (CurrentByteOffset);
111053289f6aSNate Lawson }
111153289f6aSNate Lawson 
111253289f6aSNate Lawson 
111353289f6aSNate Lawson /*******************************************************************************
111453289f6aSNate Lawson  *
111553289f6aSNate Lawson  * FUNCTION:    RsDoResourceTemplate
111653289f6aSNate Lawson  *
111753289f6aSNate Lawson  * PARAMETERS:  Op        - Parent of a resource template list
111853289f6aSNate Lawson  *
111953289f6aSNate Lawson  * RETURN:      None. Sets input node to point to a list of AML code
112053289f6aSNate Lawson  *
112153289f6aSNate Lawson  * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
112253289f6aSNate Lawson  *              in preparation for output to the AML output file.
112353289f6aSNate Lawson  *
112453289f6aSNate Lawson  ******************************************************************************/
112553289f6aSNate Lawson 
112653289f6aSNate Lawson void
RsDoResourceTemplate(ACPI_PARSE_OBJECT * Op)112753289f6aSNate Lawson RsDoResourceTemplate (
112853289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op)
112953289f6aSNate Lawson {
113053289f6aSNate Lawson     ACPI_PARSE_OBJECT       *BufferLengthOp;
113153289f6aSNate Lawson     ACPI_PARSE_OBJECT       *BufferOp;
113253289f6aSNate Lawson     ACPI_PARSE_OBJECT       *DescriptorTypeOp;
113353289f6aSNate Lawson     ACPI_PARSE_OBJECT       *LastOp = NULL;
113453289f6aSNate Lawson     UINT32                  CurrentByteOffset = 0;
113553289f6aSNate Lawson     ASL_RESOURCE_NODE       HeadRnode;
113653289f6aSNate Lawson     ASL_RESOURCE_NODE       *PreviousRnode;
113753289f6aSNate Lawson     ASL_RESOURCE_NODE       *Rnode;
1138313a0c13SJung-uk Kim     ASL_RESOURCE_INFO       Info;
113953289f6aSNate Lawson     UINT8                   State;
114053289f6aSNate Lawson 
114153289f6aSNate Lawson 
11421a39cfb0SJung-uk Kim     /* Mark parent as containing a resource template */
11431a39cfb0SJung-uk Kim 
11441a39cfb0SJung-uk Kim     if (Op->Asl.Parent)
11451a39cfb0SJung-uk Kim     {
11465f9b24faSJung-uk Kim         Op->Asl.Parent->Asl.CompileFlags |= OP_IS_RESOURCE_DESC;
11471a39cfb0SJung-uk Kim     }
11481a39cfb0SJung-uk Kim 
114953289f6aSNate Lawson     /* ResourceTemplate Opcode is first (Op) */
115053289f6aSNate Lawson     /* Buffer Length node is first child */
115153289f6aSNate Lawson 
115253289f6aSNate Lawson     BufferLengthOp = ASL_GET_CHILD_NODE (Op);
115353289f6aSNate Lawson 
115453289f6aSNate Lawson     /* Buffer Op is first peer */
115553289f6aSNate Lawson 
115653289f6aSNate Lawson     BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
115753289f6aSNate Lawson 
115853289f6aSNate Lawson     /* First Descriptor type is next */
115953289f6aSNate Lawson 
116053289f6aSNate Lawson     DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
116153289f6aSNate Lawson 
11622f6a1a81SJung-uk Kim     /* DEFAULT_ARG indicates null template - ResourceTemplate(){} */
11632f6a1a81SJung-uk Kim 
11642f6a1a81SJung-uk Kim     if (DescriptorTypeOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
11652f6a1a81SJung-uk Kim     {
11662f6a1a81SJung-uk Kim         AslError (ASL_WARNING, ASL_MSG_NULL_RESOURCE_TEMPLATE,
11672f6a1a81SJung-uk Kim             DescriptorTypeOp, DescriptorTypeOp->Asl.Value.String);
11682f6a1a81SJung-uk Kim     }
11692f6a1a81SJung-uk Kim 
11701a39cfb0SJung-uk Kim     /*
11711a39cfb0SJung-uk Kim      * Process all resource descriptors in the list
11721a39cfb0SJung-uk Kim      * Note: It is assumed that the EndTag node has been automatically
11731a39cfb0SJung-uk Kim      * inserted at the end of the template by the parser.
11741a39cfb0SJung-uk Kim      */
117553289f6aSNate Lawson     State = ACPI_RSTATE_NORMAL;
117653289f6aSNate Lawson     PreviousRnode = &HeadRnode;
117753289f6aSNate Lawson     while (DescriptorTypeOp)
117853289f6aSNate Lawson     {
1179313a0c13SJung-uk Kim         /* Save information for optional mapfile */
1180313a0c13SJung-uk Kim 
1181313a0c13SJung-uk Kim         if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1182313a0c13SJung-uk Kim         {
1183313a0c13SJung-uk Kim             Info.MappingOp = Op->Asl.Parent;
1184313a0c13SJung-uk Kim         }
1185313a0c13SJung-uk Kim         else
1186313a0c13SJung-uk Kim         {
1187313a0c13SJung-uk Kim             Info.MappingOp = DescriptorTypeOp;
1188313a0c13SJung-uk Kim         }
1189313a0c13SJung-uk Kim 
1190313a0c13SJung-uk Kim         Info.DescriptorTypeOp = DescriptorTypeOp;
1191313a0c13SJung-uk Kim         Info.CurrentByteOffset = CurrentByteOffset;
1192313a0c13SJung-uk Kim 
11935f9b24faSJung-uk Kim         DescriptorTypeOp->Asl.CompileFlags |= OP_IS_RESOURCE_DESC;
1194313a0c13SJung-uk Kim         Rnode = RsDoOneResourceDescriptor (&Info, &State);
119553289f6aSNate Lawson 
119653289f6aSNate Lawson         /*
119753289f6aSNate Lawson          * Update current byte offset to indicate the number of bytes from the
119853289f6aSNate Lawson          * start of the buffer. Buffer can include multiple descriptors, we
119953289f6aSNate Lawson          * must keep track of the offset of not only each descriptor, but each
120053289f6aSNate Lawson          * element (field) within each descriptor as well.
120153289f6aSNate Lawson          */
120253289f6aSNate Lawson         CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
120353289f6aSNate Lawson 
120453289f6aSNate Lawson         /* Get the next descriptor in the list */
120553289f6aSNate Lawson 
120653289f6aSNate Lawson         LastOp = DescriptorTypeOp;
120753289f6aSNate Lawson         DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
120853289f6aSNate Lawson     }
120953289f6aSNate Lawson 
121053289f6aSNate Lawson     if (State == ACPI_RSTATE_DEPENDENT_LIST)
121153289f6aSNate Lawson     {
121253289f6aSNate Lawson         if (LastOp)
121353289f6aSNate Lawson         {
121453289f6aSNate Lawson             LastOp = LastOp->Asl.Parent;
121553289f6aSNate Lawson         }
121653289f6aSNate Lawson         AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
121753289f6aSNate Lawson     }
121853289f6aSNate Lawson 
121953289f6aSNate Lawson     /*
122053289f6aSNate Lawson      * Transform the nodes into the following
122153289f6aSNate Lawson      *
122253289f6aSNate Lawson      * Op           -> AML_BUFFER_OP
122353289f6aSNate Lawson      * First Child  -> BufferLength
122453289f6aSNate Lawson      * Second Child -> Descriptor Buffer (raw byte data)
122553289f6aSNate Lawson      */
122653289f6aSNate Lawson     Op->Asl.ParseOpcode               = PARSEOP_BUFFER;
122753289f6aSNate Lawson     Op->Asl.AmlOpcode                 = AML_BUFFER_OP;
12285f9b24faSJung-uk Kim     Op->Asl.CompileFlags              = OP_AML_PACKAGE | OP_IS_RESOURCE_DESC;
12293f0275a0SJung-uk Kim     UtSetParseOpName (Op);
123053289f6aSNate Lawson 
123153289f6aSNate Lawson     BufferLengthOp->Asl.ParseOpcode   = PARSEOP_INTEGER;
123253289f6aSNate Lawson     BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
123353289f6aSNate Lawson     (void) OpcSetOptimalIntegerSize (BufferLengthOp);
12343f0275a0SJung-uk Kim     UtSetParseOpName (BufferLengthOp);
123553289f6aSNate Lawson 
123653289f6aSNate Lawson     BufferOp->Asl.ParseOpcode         = PARSEOP_RAW_DATA;
123753289f6aSNate Lawson     BufferOp->Asl.AmlOpcode           = AML_RAW_DATA_CHAIN;
123853289f6aSNate Lawson     BufferOp->Asl.AmlOpcodeLength     = 0;
123953289f6aSNate Lawson     BufferOp->Asl.AmlLength           = CurrentByteOffset;
1240a009b7dcSJung-uk Kim     BufferOp->Asl.Value.Buffer        = ACPI_CAST_PTR (UINT8,  HeadRnode.Next);
12415f9b24faSJung-uk Kim     BufferOp->Asl.CompileFlags       |= OP_IS_RESOURCE_DATA;
12423f0275a0SJung-uk Kim     UtSetParseOpName (BufferOp);
124353289f6aSNate Lawson 
124453289f6aSNate Lawson     return;
124553289f6aSNate Lawson }
1246