153289f6aSNate Lawson /******************************************************************************
253289f6aSNate Lawson *
353289f6aSNate Lawson * Module Name: aslopcode - AML opcode generation
453289f6aSNate Lawson *
553289f6aSNate Lawson *****************************************************************************/
653289f6aSNate Lawson
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim *
90d84335fSJung-uk Kim * 1. Copyright Notice
100d84335fSJung-uk Kim *
11722b1667SJung-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 #define _COMPONENT ACPI_COMPILER
15753289f6aSNate Lawson ACPI_MODULE_NAME ("aslopcodes")
15853289f6aSNate Lawson
15953289f6aSNate Lawson
160fba7fc7eSJung-uk Kim /* Local prototypes */
161fba7fc7eSJung-uk Kim
162fba7fc7eSJung-uk Kim static void
163fba7fc7eSJung-uk Kim OpcDoAccessAs (
164fba7fc7eSJung-uk Kim ACPI_PARSE_OBJECT *Op);
165fba7fc7eSJung-uk Kim
166fba7fc7eSJung-uk Kim static void
1673f0275a0SJung-uk Kim OpcDoConnection (
1683f0275a0SJung-uk Kim ACPI_PARSE_OBJECT *Op);
1693f0275a0SJung-uk Kim
1703f0275a0SJung-uk Kim static void
171fba7fc7eSJung-uk Kim OpcDoUnicode (
172fba7fc7eSJung-uk Kim ACPI_PARSE_OBJECT *Op);
173fba7fc7eSJung-uk Kim
174fba7fc7eSJung-uk Kim static void
175fba7fc7eSJung-uk Kim OpcDoEisaId (
176fba7fc7eSJung-uk Kim ACPI_PARSE_OBJECT *Op);
177fba7fc7eSJung-uk Kim
178fba7fc7eSJung-uk Kim static void
179fba7fc7eSJung-uk Kim OpcDoUuId (
180fba7fc7eSJung-uk Kim ACPI_PARSE_OBJECT *Op);
181fba7fc7eSJung-uk Kim
182fba7fc7eSJung-uk Kim
183fba7fc7eSJung-uk Kim /*******************************************************************************
184fba7fc7eSJung-uk Kim *
185fba7fc7eSJung-uk Kim * FUNCTION: OpcAmlOpcodeUpdateWalk
186fba7fc7eSJung-uk Kim *
187fba7fc7eSJung-uk Kim * PARAMETERS: ASL_WALK_CALLBACK
188fba7fc7eSJung-uk Kim *
189fba7fc7eSJung-uk Kim * RETURN: Status
190fba7fc7eSJung-uk Kim *
191fba7fc7eSJung-uk Kim * DESCRIPTION: Opcode update walk, ascending callback
192fba7fc7eSJung-uk Kim *
193fba7fc7eSJung-uk Kim ******************************************************************************/
194fba7fc7eSJung-uk Kim
195fba7fc7eSJung-uk Kim ACPI_STATUS
OpcAmlOpcodeUpdateWalk(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)196fba7fc7eSJung-uk Kim OpcAmlOpcodeUpdateWalk (
197fba7fc7eSJung-uk Kim ACPI_PARSE_OBJECT *Op,
198fba7fc7eSJung-uk Kim UINT32 Level,
199fba7fc7eSJung-uk Kim void *Context)
200fba7fc7eSJung-uk Kim {
201fba7fc7eSJung-uk Kim
202fba7fc7eSJung-uk Kim /*
203fba7fc7eSJung-uk Kim * Handle the Package() case where the actual opcode cannot be determined
204fba7fc7eSJung-uk Kim * until the PackageLength operand has been folded and minimized.
205fba7fc7eSJung-uk Kim * (PackageOp versus VarPackageOp)
206fba7fc7eSJung-uk Kim *
207fba7fc7eSJung-uk Kim * This is (as of ACPI 3.0) the only case where the AML opcode can change
208fba7fc7eSJung-uk Kim * based upon the value of a parameter.
209fba7fc7eSJung-uk Kim *
210fba7fc7eSJung-uk Kim * The parser always inserts a VarPackage opcode, which can possibly be
211fba7fc7eSJung-uk Kim * optimized to a Package opcode.
212fba7fc7eSJung-uk Kim */
213fba7fc7eSJung-uk Kim if (Op->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)
214fba7fc7eSJung-uk Kim {
215fba7fc7eSJung-uk Kim OpnDoPackage (Op);
216fba7fc7eSJung-uk Kim }
217fba7fc7eSJung-uk Kim
218fba7fc7eSJung-uk Kim return (AE_OK);
219fba7fc7eSJung-uk Kim }
220fba7fc7eSJung-uk Kim
221fba7fc7eSJung-uk Kim
22253289f6aSNate Lawson /*******************************************************************************
22353289f6aSNate Lawson *
22453289f6aSNate Lawson * FUNCTION: OpcAmlOpcodeWalk
22553289f6aSNate Lawson *
22653289f6aSNate Lawson * PARAMETERS: ASL_WALK_CALLBACK
22753289f6aSNate Lawson *
22853289f6aSNate Lawson * RETURN: Status
22953289f6aSNate Lawson *
23053289f6aSNate Lawson * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
23153289f6aSNate Lawson * operands.
23253289f6aSNate Lawson *
23353289f6aSNate Lawson ******************************************************************************/
23453289f6aSNate Lawson
23553289f6aSNate Lawson ACPI_STATUS
OpcAmlOpcodeWalk(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)23653289f6aSNate Lawson OpcAmlOpcodeWalk (
23753289f6aSNate Lawson ACPI_PARSE_OBJECT *Op,
23853289f6aSNate Lawson UINT32 Level,
23953289f6aSNate Lawson void *Context)
24053289f6aSNate Lawson {
24153289f6aSNate Lawson
2426f1f1a63SJung-uk Kim AslGbl_TotalParseNodes++;
24353289f6aSNate Lawson
24453289f6aSNate Lawson OpcGenerateAmlOpcode (Op);
24553289f6aSNate Lawson OpnGenerateAmlOperands (Op);
24653289f6aSNate Lawson return (AE_OK);
24753289f6aSNate Lawson }
24853289f6aSNate Lawson
24953289f6aSNate Lawson
25053289f6aSNate Lawson /*******************************************************************************
25153289f6aSNate Lawson *
25253289f6aSNate Lawson * FUNCTION: OpcGetIntegerWidth
25353289f6aSNate Lawson *
25453289f6aSNate Lawson * PARAMETERS: Op - DEFINITION BLOCK op
25553289f6aSNate Lawson *
25653289f6aSNate Lawson * RETURN: none
25753289f6aSNate Lawson *
25853289f6aSNate Lawson * DESCRIPTION: Extract integer width from the table revision
25953289f6aSNate Lawson *
26053289f6aSNate Lawson ******************************************************************************/
26153289f6aSNate Lawson
26253289f6aSNate Lawson void
OpcGetIntegerWidth(ACPI_PARSE_OBJECT * Op)26353289f6aSNate Lawson OpcGetIntegerWidth (
26453289f6aSNate Lawson ACPI_PARSE_OBJECT *Op)
26553289f6aSNate Lawson {
26653289f6aSNate Lawson ACPI_PARSE_OBJECT *Child;
26753289f6aSNate Lawson
268fba7fc7eSJung-uk Kim
26953289f6aSNate Lawson if (!Op)
27053289f6aSNate Lawson {
27153289f6aSNate Lawson return;
27253289f6aSNate Lawson }
27353289f6aSNate Lawson
2746f1f1a63SJung-uk Kim if (AslGbl_RevisionOverride)
275fba7fc7eSJung-uk Kim {
2766f1f1a63SJung-uk Kim AcpiUtSetIntegerWidth (AslGbl_RevisionOverride);
277fba7fc7eSJung-uk Kim }
278fba7fc7eSJung-uk Kim else
279fba7fc7eSJung-uk Kim {
28053289f6aSNate Lawson Child = Op->Asl.Child;
28153289f6aSNate Lawson Child = Child->Asl.Next;
28253289f6aSNate Lawson Child = Child->Asl.Next;
28353289f6aSNate Lawson
28453289f6aSNate Lawson /* Use the revision to set the integer width */
28553289f6aSNate Lawson
28653289f6aSNate Lawson AcpiUtSetIntegerWidth ((UINT8) Child->Asl.Value.Integer);
28753289f6aSNate Lawson }
288fba7fc7eSJung-uk Kim }
28953289f6aSNate Lawson
29053289f6aSNate Lawson
29153289f6aSNate Lawson /*******************************************************************************
29253289f6aSNate Lawson *
29353289f6aSNate Lawson * FUNCTION: OpcSetOptimalIntegerSize
29453289f6aSNate Lawson *
29553289f6aSNate Lawson * PARAMETERS: Op - A parse tree node
29653289f6aSNate Lawson *
29753289f6aSNate Lawson * RETURN: Integer width, in bytes. Also sets the node AML opcode to the
29853289f6aSNate Lawson * optimal integer AML prefix opcode.
29953289f6aSNate Lawson *
30053289f6aSNate Lawson * DESCRIPTION: Determine the optimal AML encoding of an integer. All leading
30153289f6aSNate Lawson * zeros can be truncated to squeeze the integer into the
30253289f6aSNate Lawson * minimal number of AML bytes.
30353289f6aSNate Lawson *
30453289f6aSNate Lawson ******************************************************************************/
30553289f6aSNate Lawson
30653289f6aSNate Lawson UINT32
OpcSetOptimalIntegerSize(ACPI_PARSE_OBJECT * Op)30753289f6aSNate Lawson OpcSetOptimalIntegerSize (
30853289f6aSNate Lawson ACPI_PARSE_OBJECT *Op)
30953289f6aSNate Lawson {
31053289f6aSNate Lawson
311fba7fc7eSJung-uk Kim #if 0
31253289f6aSNate Lawson /*
313fba7fc7eSJung-uk Kim * TBD: - we don't want to optimize integers in the block header, but the
314fba7fc7eSJung-uk Kim * code below does not work correctly.
315fba7fc7eSJung-uk Kim */
316c8466860SMark Santcroos if (Op->Asl.Parent &&
317c8466860SMark Santcroos Op->Asl.Parent->Asl.Parent &&
318f8146b88SJung-uk Kim (Op->Asl.Parent->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK))
319c8466860SMark Santcroos {
3208ef1a331SJung-uk Kim return (0);
321c8466860SMark Santcroos }
322fba7fc7eSJung-uk Kim #endif
323c8466860SMark Santcroos
324c8466860SMark Santcroos /*
32553289f6aSNate Lawson * Check for the special AML integers first - Zero, One, Ones.
32653289f6aSNate Lawson * These are single-byte opcodes that are the smallest possible
32753289f6aSNate Lawson * representation of an integer.
32853289f6aSNate Lawson *
32953289f6aSNate Lawson * This optimization is optional.
33053289f6aSNate Lawson */
3316f1f1a63SJung-uk Kim if (AslGbl_IntegerOptimizationFlag)
33253289f6aSNate Lawson {
33353289f6aSNate Lawson switch (Op->Asl.Value.Integer)
33453289f6aSNate Lawson {
33553289f6aSNate Lawson case 0:
33653289f6aSNate Lawson
33753289f6aSNate Lawson Op->Asl.AmlOpcode = AML_ZERO_OP;
338fba7fc7eSJung-uk Kim AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
339fba7fc7eSJung-uk Kim Op, "Zero");
3408ef1a331SJung-uk Kim return (1);
34153289f6aSNate Lawson
34253289f6aSNate Lawson case 1:
34353289f6aSNate Lawson
34453289f6aSNate Lawson Op->Asl.AmlOpcode = AML_ONE_OP;
345fba7fc7eSJung-uk Kim AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
346fba7fc7eSJung-uk Kim Op, "One");
3478ef1a331SJung-uk Kim return (1);
34853289f6aSNate Lawson
34953289f6aSNate Lawson case ACPI_UINT32_MAX:
35053289f6aSNate Lawson
35153289f6aSNate Lawson /* Check for table integer width (32 or 64) */
35253289f6aSNate Lawson
35353289f6aSNate Lawson if (AcpiGbl_IntegerByteWidth == 4)
35453289f6aSNate Lawson {
35553289f6aSNate Lawson Op->Asl.AmlOpcode = AML_ONES_OP;
356fba7fc7eSJung-uk Kim AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
357fba7fc7eSJung-uk Kim Op, "Ones");
3588ef1a331SJung-uk Kim return (1);
35953289f6aSNate Lawson }
36053289f6aSNate Lawson break;
36153289f6aSNate Lawson
3629a179dd8SJung-uk Kim case ACPI_UINT64_MAX:
36353289f6aSNate Lawson
36453289f6aSNate Lawson /* Check for table integer width (32 or 64) */
36553289f6aSNate Lawson
36653289f6aSNate Lawson if (AcpiGbl_IntegerByteWidth == 8)
36753289f6aSNate Lawson {
36853289f6aSNate Lawson Op->Asl.AmlOpcode = AML_ONES_OP;
369fba7fc7eSJung-uk Kim AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
370fba7fc7eSJung-uk Kim Op, "Ones");
3718ef1a331SJung-uk Kim return (1);
37253289f6aSNate Lawson }
37353289f6aSNate Lawson break;
37453289f6aSNate Lawson
37553289f6aSNate Lawson default:
376a9d8d09cSJung-uk Kim
37753289f6aSNate Lawson break;
37853289f6aSNate Lawson }
37953289f6aSNate Lawson }
38053289f6aSNate Lawson
38153289f6aSNate Lawson /* Find the best fit using the various AML integer prefixes */
38253289f6aSNate Lawson
38353289f6aSNate Lawson if (Op->Asl.Value.Integer <= ACPI_UINT8_MAX)
38453289f6aSNate Lawson {
38553289f6aSNate Lawson Op->Asl.AmlOpcode = AML_BYTE_OP;
3868ef1a331SJung-uk Kim return (1);
38753289f6aSNate Lawson }
388f8146b88SJung-uk Kim
38953289f6aSNate Lawson if (Op->Asl.Value.Integer <= ACPI_UINT16_MAX)
39053289f6aSNate Lawson {
39153289f6aSNate Lawson Op->Asl.AmlOpcode = AML_WORD_OP;
3928ef1a331SJung-uk Kim return (2);
39353289f6aSNate Lawson }
394f8146b88SJung-uk Kim
39553289f6aSNate Lawson if (Op->Asl.Value.Integer <= ACPI_UINT32_MAX)
39653289f6aSNate Lawson {
39753289f6aSNate Lawson Op->Asl.AmlOpcode = AML_DWORD_OP;
3988ef1a331SJung-uk Kim return (4);
39953289f6aSNate Lawson }
4001cc50d6bSJung-uk Kim else /* 64-bit integer */
40153289f6aSNate Lawson {
402fba7fc7eSJung-uk Kim if (AcpiGbl_IntegerByteWidth == 4)
403fba7fc7eSJung-uk Kim {
404fba7fc7eSJung-uk Kim AslError (ASL_WARNING, ASL_MSG_INTEGER_LENGTH,
405fba7fc7eSJung-uk Kim Op, NULL);
406fba7fc7eSJung-uk Kim
4076f1f1a63SJung-uk Kim if (!AslGbl_IgnoreErrors)
408fba7fc7eSJung-uk Kim {
409fba7fc7eSJung-uk Kim /* Truncate the integer to 32-bit */
4101cc50d6bSJung-uk Kim
4111cc50d6bSJung-uk Kim Op->Asl.Value.Integer &= ACPI_UINT32_MAX;
4121cc50d6bSJung-uk Kim
4131cc50d6bSJung-uk Kim /* Now set the optimal integer size */
4141cc50d6bSJung-uk Kim
4151cc50d6bSJung-uk Kim return (OpcSetOptimalIntegerSize (Op));
416fba7fc7eSJung-uk Kim }
417fba7fc7eSJung-uk Kim }
418fba7fc7eSJung-uk Kim
41953289f6aSNate Lawson Op->Asl.AmlOpcode = AML_QWORD_OP;
4208ef1a331SJung-uk Kim return (8);
42153289f6aSNate Lawson }
42253289f6aSNate Lawson }
42353289f6aSNate Lawson
42453289f6aSNate Lawson
42553289f6aSNate Lawson /*******************************************************************************
42653289f6aSNate Lawson *
42753289f6aSNate Lawson * FUNCTION: OpcDoAccessAs
42853289f6aSNate Lawson *
42953289f6aSNate Lawson * PARAMETERS: Op - Parse node
43053289f6aSNate Lawson *
43153289f6aSNate Lawson * RETURN: None
43253289f6aSNate Lawson *
43353289f6aSNate Lawson * DESCRIPTION: Implement the ACCESS_AS ASL keyword.
43453289f6aSNate Lawson *
43553289f6aSNate Lawson ******************************************************************************/
43653289f6aSNate Lawson
437fba7fc7eSJung-uk Kim static void
OpcDoAccessAs(ACPI_PARSE_OBJECT * Op)43853289f6aSNate Lawson OpcDoAccessAs (
43953289f6aSNate Lawson ACPI_PARSE_OBJECT *Op)
44053289f6aSNate Lawson {
4413f0275a0SJung-uk Kim ACPI_PARSE_OBJECT *TypeOp;
4423f0275a0SJung-uk Kim ACPI_PARSE_OBJECT *AttribOp;
4433f0275a0SJung-uk Kim ACPI_PARSE_OBJECT *LengthOp;
4443f0275a0SJung-uk Kim UINT8 Attribute;
44553289f6aSNate Lawson
44653289f6aSNate Lawson
44753289f6aSNate Lawson Op->Asl.AmlOpcodeLength = 1;
4483f0275a0SJung-uk Kim TypeOp = Op->Asl.Child;
44953289f6aSNate Lawson
45053289f6aSNate Lawson /* First child is the access type */
45153289f6aSNate Lawson
4523f0275a0SJung-uk Kim TypeOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
4533f0275a0SJung-uk Kim TypeOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
45453289f6aSNate Lawson
45553289f6aSNate Lawson /* Second child is the optional access attribute */
45653289f6aSNate Lawson
4573f0275a0SJung-uk Kim AttribOp = TypeOp->Asl.Next;
4583f0275a0SJung-uk Kim if (AttribOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
45953289f6aSNate Lawson {
4603f0275a0SJung-uk Kim AttribOp->Asl.Value.Integer = 0;
46153289f6aSNate Lawson }
462f8146b88SJung-uk Kim
4633f0275a0SJung-uk Kim AttribOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
4643f0275a0SJung-uk Kim AttribOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
4653f0275a0SJung-uk Kim
4663f0275a0SJung-uk Kim /* Only a few AccessAttributes support AccessLength */
4673f0275a0SJung-uk Kim
4683f0275a0SJung-uk Kim Attribute = (UINT8) AttribOp->Asl.Value.Integer;
4696f1f1a63SJung-uk Kim if ((Attribute != AML_FIELD_ATTRIB_BYTES) &&
4703f0275a0SJung-uk Kim (Attribute != AML_FIELD_ATTRIB_RAW_BYTES) &&
4716f1f1a63SJung-uk Kim (Attribute != AML_FIELD_ATTRIB_RAW_PROCESS_BYTES))
4723f0275a0SJung-uk Kim {
4733f0275a0SJung-uk Kim return;
4743f0275a0SJung-uk Kim }
4753f0275a0SJung-uk Kim
4763f0275a0SJung-uk Kim Op->Asl.AmlOpcode = AML_FIELD_EXT_ACCESS_OP;
4773f0275a0SJung-uk Kim
4783f0275a0SJung-uk Kim /*
4793f0275a0SJung-uk Kim * Child of Attributes is the AccessLength (required for Multibyte,
4803f0275a0SJung-uk Kim * RawBytes, RawProcess.)
4813f0275a0SJung-uk Kim */
4823f0275a0SJung-uk Kim LengthOp = AttribOp->Asl.Child;
4833f0275a0SJung-uk Kim if (!LengthOp)
4843f0275a0SJung-uk Kim {
4853f0275a0SJung-uk Kim return;
4863f0275a0SJung-uk Kim }
4873f0275a0SJung-uk Kim
4883f0275a0SJung-uk Kim /* TBD: probably can remove */
4893f0275a0SJung-uk Kim
4903f0275a0SJung-uk Kim if (LengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
4913f0275a0SJung-uk Kim {
4923f0275a0SJung-uk Kim LengthOp->Asl.Value.Integer = 16;
4933f0275a0SJung-uk Kim }
4943f0275a0SJung-uk Kim
4953f0275a0SJung-uk Kim LengthOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
4963f0275a0SJung-uk Kim LengthOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
4973f0275a0SJung-uk Kim }
4983f0275a0SJung-uk Kim
4993f0275a0SJung-uk Kim
5003f0275a0SJung-uk Kim /*******************************************************************************
5013f0275a0SJung-uk Kim *
5023f0275a0SJung-uk Kim * FUNCTION: OpcDoConnection
5033f0275a0SJung-uk Kim *
5043f0275a0SJung-uk Kim * PARAMETERS: Op - Parse node
5053f0275a0SJung-uk Kim *
5063f0275a0SJung-uk Kim * RETURN: None
5073f0275a0SJung-uk Kim *
5083f0275a0SJung-uk Kim * DESCRIPTION: Implement the Connection ASL keyword.
5093f0275a0SJung-uk Kim *
5103f0275a0SJung-uk Kim ******************************************************************************/
5113f0275a0SJung-uk Kim
5123f0275a0SJung-uk Kim static void
OpcDoConnection(ACPI_PARSE_OBJECT * Op)5133f0275a0SJung-uk Kim OpcDoConnection (
5143f0275a0SJung-uk Kim ACPI_PARSE_OBJECT *Op)
5153f0275a0SJung-uk Kim {
5163f0275a0SJung-uk Kim ASL_RESOURCE_NODE *Rnode;
5173f0275a0SJung-uk Kim ACPI_PARSE_OBJECT *BufferOp;
5183f0275a0SJung-uk Kim ACPI_PARSE_OBJECT *BufferLengthOp;
5193f0275a0SJung-uk Kim ACPI_PARSE_OBJECT *BufferDataOp;
520313a0c13SJung-uk Kim ASL_RESOURCE_INFO Info;
5213f0275a0SJung-uk Kim UINT8 State;
5223f0275a0SJung-uk Kim
5233f0275a0SJung-uk Kim
5243f0275a0SJung-uk Kim Op->Asl.AmlOpcodeLength = 1;
5253f0275a0SJung-uk Kim
5263f0275a0SJung-uk Kim if (Op->Asl.Child->Asl.AmlOpcode == AML_INT_NAMEPATH_OP)
5273f0275a0SJung-uk Kim {
5283f0275a0SJung-uk Kim return;
5293f0275a0SJung-uk Kim }
5303f0275a0SJung-uk Kim
5313f0275a0SJung-uk Kim BufferOp = Op->Asl.Child;
5323f0275a0SJung-uk Kim BufferLengthOp = BufferOp->Asl.Child;
5333f0275a0SJung-uk Kim BufferDataOp = BufferLengthOp->Asl.Next;
5343f0275a0SJung-uk Kim
535313a0c13SJung-uk Kim Info.DescriptorTypeOp = BufferDataOp->Asl.Next;
536313a0c13SJung-uk Kim Info.CurrentByteOffset = 0;
5373f0275a0SJung-uk Kim State = ACPI_RSTATE_NORMAL;
538313a0c13SJung-uk Kim Rnode = RsDoOneResourceDescriptor (&Info, &State);
5393f0275a0SJung-uk Kim if (!Rnode)
5403f0275a0SJung-uk Kim {
5413f0275a0SJung-uk Kim return; /* error */
5423f0275a0SJung-uk Kim }
5433f0275a0SJung-uk Kim
5443f0275a0SJung-uk Kim /*
5453f0275a0SJung-uk Kim * Transform the nodes into the following
5463f0275a0SJung-uk Kim *
5473f0275a0SJung-uk Kim * Op -> AML_BUFFER_OP
5483f0275a0SJung-uk Kim * First Child -> BufferLength
5493f0275a0SJung-uk Kim * Second Child -> Descriptor Buffer (raw byte data)
5503f0275a0SJung-uk Kim */
5513f0275a0SJung-uk Kim BufferOp->Asl.ParseOpcode = PARSEOP_BUFFER;
5523f0275a0SJung-uk Kim BufferOp->Asl.AmlOpcode = AML_BUFFER_OP;
5535f9b24faSJung-uk Kim BufferOp->Asl.CompileFlags = OP_AML_PACKAGE | OP_IS_RESOURCE_DESC;
5543f0275a0SJung-uk Kim UtSetParseOpName (BufferOp);
5553f0275a0SJung-uk Kim
5563f0275a0SJung-uk Kim BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
5573f0275a0SJung-uk Kim BufferLengthOp->Asl.Value.Integer = Rnode->BufferLength;
5583f0275a0SJung-uk Kim (void) OpcSetOptimalIntegerSize (BufferLengthOp);
5593f0275a0SJung-uk Kim UtSetParseOpName (BufferLengthOp);
5603f0275a0SJung-uk Kim
5613f0275a0SJung-uk Kim BufferDataOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
5623f0275a0SJung-uk Kim BufferDataOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN;
5633f0275a0SJung-uk Kim BufferDataOp->Asl.AmlOpcodeLength = 0;
5643f0275a0SJung-uk Kim BufferDataOp->Asl.AmlLength = Rnode->BufferLength;
5653f0275a0SJung-uk Kim BufferDataOp->Asl.Value.Buffer = (UINT8 *) Rnode;
5663f0275a0SJung-uk Kim UtSetParseOpName (BufferDataOp);
56753289f6aSNate Lawson }
56853289f6aSNate Lawson
56953289f6aSNate Lawson
57053289f6aSNate Lawson /*******************************************************************************
57153289f6aSNate Lawson *
57253289f6aSNate Lawson * FUNCTION: OpcDoUnicode
57353289f6aSNate Lawson *
57453289f6aSNate Lawson * PARAMETERS: Op - Parse node
57553289f6aSNate Lawson *
57653289f6aSNate Lawson * RETURN: None
57753289f6aSNate Lawson *
57853289f6aSNate Lawson * DESCRIPTION: Implement the UNICODE ASL "macro". Convert the input string
57953289f6aSNate Lawson * to a unicode buffer. There is no Unicode AML opcode.
58053289f6aSNate Lawson *
58153289f6aSNate Lawson * Note: The Unicode string is 16 bits per character, no leading signature,
58253289f6aSNate Lawson * with a 16-bit terminating NULL.
58353289f6aSNate Lawson *
58453289f6aSNate Lawson ******************************************************************************/
58553289f6aSNate Lawson
586fba7fc7eSJung-uk Kim static void
OpcDoUnicode(ACPI_PARSE_OBJECT * Op)58753289f6aSNate Lawson OpcDoUnicode (
58853289f6aSNate Lawson ACPI_PARSE_OBJECT *Op)
58953289f6aSNate Lawson {
59053289f6aSNate Lawson ACPI_PARSE_OBJECT *InitializerOp;
59153289f6aSNate Lawson UINT32 Length;
59253289f6aSNate Lawson UINT32 Count;
59353289f6aSNate Lawson UINT32 i;
59453289f6aSNate Lawson UINT8 *AsciiString;
59553289f6aSNate Lawson UINT16 *UnicodeString;
59653289f6aSNate Lawson ACPI_PARSE_OBJECT *BufferLengthOp;
59753289f6aSNate Lawson
59853289f6aSNate Lawson
59953289f6aSNate Lawson /* Change op into a buffer object */
60053289f6aSNate Lawson
6015f9b24faSJung-uk Kim Op->Asl.CompileFlags &= ~OP_COMPILE_TIME_CONST;
60253289f6aSNate Lawson Op->Asl.ParseOpcode = PARSEOP_BUFFER;
60353289f6aSNate Lawson UtSetParseOpName (Op);
60453289f6aSNate Lawson
60553289f6aSNate Lawson /* Buffer Length is first, followed by the string */
60653289f6aSNate Lawson
60753289f6aSNate Lawson BufferLengthOp = Op->Asl.Child;
60853289f6aSNate Lawson InitializerOp = BufferLengthOp->Asl.Next;
60953289f6aSNate Lawson
61053289f6aSNate Lawson AsciiString = (UINT8 *) InitializerOp->Asl.Value.String;
61153289f6aSNate Lawson
61253289f6aSNate Lawson /* Create a new buffer for the Unicode string */
61353289f6aSNate Lawson
61453289f6aSNate Lawson Count = strlen (InitializerOp->Asl.Value.String) + 1;
61553289f6aSNate Lawson Length = Count * sizeof (UINT16);
61653289f6aSNate Lawson UnicodeString = UtLocalCalloc (Length);
61753289f6aSNate Lawson
61853289f6aSNate Lawson /* Convert to Unicode string (including null terminator) */
61953289f6aSNate Lawson
62053289f6aSNate Lawson for (i = 0; i < Count; i++)
62153289f6aSNate Lawson {
62253289f6aSNate Lawson UnicodeString[i] = (UINT16) AsciiString[i];
62353289f6aSNate Lawson }
62453289f6aSNate Lawson
62553289f6aSNate Lawson /*
62653289f6aSNate Lawson * Just set the buffer size node to be the buffer length, regardless
62753289f6aSNate Lawson * of whether it was previously an integer or a default_arg placeholder
62853289f6aSNate Lawson */
62953289f6aSNate Lawson BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
63053289f6aSNate Lawson BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP;
63153289f6aSNate Lawson BufferLengthOp->Asl.Value.Integer = Length;
63253289f6aSNate Lawson UtSetParseOpName (BufferLengthOp);
63353289f6aSNate Lawson
63453289f6aSNate Lawson (void) OpcSetOptimalIntegerSize (BufferLengthOp);
63553289f6aSNate Lawson
63653289f6aSNate Lawson /* The Unicode string is a raw data buffer */
63753289f6aSNate Lawson
63853289f6aSNate Lawson InitializerOp->Asl.Value.Buffer = (UINT8 *) UnicodeString;
63953289f6aSNate Lawson InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
64053289f6aSNate Lawson InitializerOp->Asl.AmlLength = Length;
64153289f6aSNate Lawson InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
64253289f6aSNate Lawson InitializerOp->Asl.Child = NULL;
64353289f6aSNate Lawson UtSetParseOpName (InitializerOp);
64453289f6aSNate Lawson }
64553289f6aSNate Lawson
64653289f6aSNate Lawson
64753289f6aSNate Lawson /*******************************************************************************
64853289f6aSNate Lawson *
64953289f6aSNate Lawson * FUNCTION: OpcDoEisaId
65053289f6aSNate Lawson *
65153289f6aSNate Lawson * PARAMETERS: Op - Parse node
65253289f6aSNate Lawson *
65353289f6aSNate Lawson * RETURN: None
65453289f6aSNate Lawson *
65553289f6aSNate Lawson * DESCRIPTION: Convert a string EISA ID to numeric representation. See the
65653289f6aSNate Lawson * Pnp BIOS Specification for details. Here is an excerpt:
65753289f6aSNate Lawson *
65853289f6aSNate Lawson * A seven character ASCII representation of the product
65953289f6aSNate Lawson * identifier compressed into a 32-bit identifier. The seven
66053289f6aSNate Lawson * character ID consists of a three character manufacturer code,
66153289f6aSNate Lawson * a three character hexadecimal product identifier, and a one
66253289f6aSNate Lawson * character hexadecimal revision number. The manufacturer code
66353289f6aSNate Lawson * is a 3 uppercase character code that is compressed into 3 5-bit
66453289f6aSNate Lawson * values as follows:
66553289f6aSNate Lawson * 1) Find hex ASCII value for each letter
66653289f6aSNate Lawson * 2) Subtract 40h from each ASCII value
6678ef1a331SJung-uk Kim * 3) Retain 5 least significant bits for each letter by
66853289f6aSNate Lawson * discarding upper 3 bits because they are always 0.
66953289f6aSNate Lawson * 4) Compressed code = concatenate 0 and the 3 5-bit values
67053289f6aSNate Lawson *
67153289f6aSNate Lawson * The format of the compressed product identifier is as follows:
67253289f6aSNate Lawson * Byte 0: Bit 7 - Reserved (0)
67353289f6aSNate Lawson * Bits 6-2: - 1st character of compressed mfg code
67453289f6aSNate Lawson * Bits 1-0 - Upper 2 bits of 2nd character of mfg code
67553289f6aSNate Lawson * Byte 1: Bits 7-5 - Lower 3 bits of 2nd character of mfg code
67653289f6aSNate Lawson * Bits 4-0 - 3rd character of mfg code
67753289f6aSNate Lawson * Byte 2: Bits 7-4 - 1st hex digit of product number
67853289f6aSNate Lawson * Bits 3-0 - 2nd hex digit of product number
679cfd1ed46SJung-uk Kim * Byte 3: Bits 7-4 - 3rd hex digit of product number
68053289f6aSNate Lawson * Bits 3-0 - Hex digit of the revision number
68153289f6aSNate Lawson *
68253289f6aSNate Lawson ******************************************************************************/
68353289f6aSNate Lawson
684fba7fc7eSJung-uk Kim static void
OpcDoEisaId(ACPI_PARSE_OBJECT * Op)68553289f6aSNate Lawson OpcDoEisaId (
68653289f6aSNate Lawson ACPI_PARSE_OBJECT *Op)
68753289f6aSNate Lawson {
68853289f6aSNate Lawson UINT32 EisaId = 0;
68953289f6aSNate Lawson UINT32 BigEndianId;
69053289f6aSNate Lawson char *InString;
69153289f6aSNate Lawson ACPI_STATUS Status = AE_OK;
692a9f12690SJung-uk Kim UINT32 i;
69353289f6aSNate Lawson
69453289f6aSNate Lawson
69553289f6aSNate Lawson InString = (char *) Op->Asl.Value.String;
69653289f6aSNate Lawson
69753289f6aSNate Lawson /*
69853289f6aSNate Lawson * The EISAID string must be exactly 7 characters and of the form
699fba7fc7eSJung-uk Kim * "UUUXXXX" -- 3 uppercase letters and 4 hex digits (e.g., "PNP0001")
70053289f6aSNate Lawson */
7015ef50723SJung-uk Kim if (strlen (InString) != 7)
70253289f6aSNate Lawson {
70353289f6aSNate Lawson Status = AE_BAD_PARAMETER;
70453289f6aSNate Lawson }
70553289f6aSNate Lawson else
70653289f6aSNate Lawson {
70753289f6aSNate Lawson /* Check all 7 characters for correct format */
70853289f6aSNate Lawson
70953289f6aSNate Lawson for (i = 0; i < 7; i++)
71053289f6aSNate Lawson {
711c8466860SMark Santcroos /* First 3 characters must be uppercase letters */
71253289f6aSNate Lawson
71353289f6aSNate Lawson if (i < 3)
71453289f6aSNate Lawson {
7159a179dd8SJung-uk Kim if (!isupper ((int) InString[i]))
71653289f6aSNate Lawson {
71753289f6aSNate Lawson Status = AE_BAD_PARAMETER;
71853289f6aSNate Lawson }
71953289f6aSNate Lawson }
72053289f6aSNate Lawson
72153289f6aSNate Lawson /* Last 4 characters must be hex digits */
72253289f6aSNate Lawson
7239a179dd8SJung-uk Kim else if (!isxdigit ((int) InString[i]))
72453289f6aSNate Lawson {
72553289f6aSNate Lawson Status = AE_BAD_PARAMETER;
72653289f6aSNate Lawson }
72753289f6aSNate Lawson }
72853289f6aSNate Lawson }
72953289f6aSNate Lawson
73053289f6aSNate Lawson if (ACPI_FAILURE (Status))
73153289f6aSNate Lawson {
73253289f6aSNate Lawson AslError (ASL_ERROR, ASL_MSG_INVALID_EISAID, Op, Op->Asl.Value.String);
73353289f6aSNate Lawson }
73453289f6aSNate Lawson else
73553289f6aSNate Lawson {
73653289f6aSNate Lawson /* Create ID big-endian first (bits are contiguous) */
73753289f6aSNate Lawson
7381a39cfb0SJung-uk Kim BigEndianId =
73942fecd12SJung-uk Kim (UINT32) ((UINT8) (InString[0] - 0x40)) << 26 |
74042fecd12SJung-uk Kim (UINT32) ((UINT8) (InString[1] - 0x40)) << 21 |
74142fecd12SJung-uk Kim (UINT32) ((UINT8) (InString[2] - 0x40)) << 16 |
74253289f6aSNate Lawson
743313a0c13SJung-uk Kim (AcpiUtAsciiCharToHex (InString[3])) << 12 |
744313a0c13SJung-uk Kim (AcpiUtAsciiCharToHex (InString[4])) << 8 |
745313a0c13SJung-uk Kim (AcpiUtAsciiCharToHex (InString[5])) << 4 |
746313a0c13SJung-uk Kim AcpiUtAsciiCharToHex (InString[6]);
74753289f6aSNate Lawson
74853289f6aSNate Lawson /* Swap to little-endian to get final ID (see function header) */
74953289f6aSNate Lawson
75053289f6aSNate Lawson EisaId = AcpiUtDwordByteSwap (BigEndianId);
75153289f6aSNate Lawson }
75253289f6aSNate Lawson
75353289f6aSNate Lawson /*
75453289f6aSNate Lawson * Morph the Op into an integer, regardless of whether there
75553289f6aSNate Lawson * was an error in the EISAID string
75653289f6aSNate Lawson */
75753289f6aSNate Lawson Op->Asl.Value.Integer = EisaId;
75853289f6aSNate Lawson
7595f9b24faSJung-uk Kim Op->Asl.CompileFlags &= ~OP_COMPILE_TIME_CONST;
76053289f6aSNate Lawson Op->Asl.ParseOpcode = PARSEOP_INTEGER;
76153289f6aSNate Lawson (void) OpcSetOptimalIntegerSize (Op);
76253289f6aSNate Lawson
76353289f6aSNate Lawson /* Op is now an integer */
76453289f6aSNate Lawson
76553289f6aSNate Lawson UtSetParseOpName (Op);
76653289f6aSNate Lawson }
76753289f6aSNate Lawson
76853289f6aSNate Lawson
76953289f6aSNate Lawson /*******************************************************************************
77053289f6aSNate Lawson *
7713f0275a0SJung-uk Kim * FUNCTION: OpcDoUuId
772c8466860SMark Santcroos *
773c8466860SMark Santcroos * PARAMETERS: Op - Parse node
774c8466860SMark Santcroos *
775c8466860SMark Santcroos * RETURN: None
776c8466860SMark Santcroos *
777fba7fc7eSJung-uk Kim * DESCRIPTION: Convert UUID string to 16-byte buffer
778c8466860SMark Santcroos *
779c8466860SMark Santcroos ******************************************************************************/
780c8466860SMark Santcroos
781fba7fc7eSJung-uk Kim static void
OpcDoUuId(ACPI_PARSE_OBJECT * Op)782c8466860SMark Santcroos OpcDoUuId (
783c8466860SMark Santcroos ACPI_PARSE_OBJECT *Op)
784c8466860SMark Santcroos {
785c8466860SMark Santcroos char *InString;
786313a0c13SJung-uk Kim UINT8 *Buffer;
787c8466860SMark Santcroos ACPI_STATUS Status = AE_OK;
788c8466860SMark Santcroos ACPI_PARSE_OBJECT *NewOp;
789c8466860SMark Santcroos
790c8466860SMark Santcroos
7911c0e1b6dSJung-uk Kim InString = ACPI_CAST_PTR (char, Op->Asl.Value.String);
792c8466860SMark Santcroos Buffer = UtLocalCalloc (16);
793c8466860SMark Santcroos
794d244b227SJung-uk Kim Status = AuValidateUuid (InString);
795c8466860SMark Santcroos if (ACPI_FAILURE (Status))
796c8466860SMark Santcroos {
797c8466860SMark Santcroos AslError (ASL_ERROR, ASL_MSG_INVALID_UUID, Op, Op->Asl.Value.String);
798c8466860SMark Santcroos }
799d244b227SJung-uk Kim else
800c8466860SMark Santcroos {
801fbde3477SJung-uk Kim /* Convert UUID string to a buffer, check for a known UUID */
802fbde3477SJung-uk Kim
803313a0c13SJung-uk Kim AcpiUtConvertStringToUuid (InString, Buffer);
804fbde3477SJung-uk Kim if (!AcpiAhMatchUuid (Buffer))
805fbde3477SJung-uk Kim {
806fbde3477SJung-uk Kim AslError (ASL_REMARK, ASL_MSG_UUID_NOT_FOUND, Op, NULL);
807fbde3477SJung-uk Kim }
808c8466860SMark Santcroos }
809c8466860SMark Santcroos
810c8466860SMark Santcroos /* Change Op to a Buffer */
811c8466860SMark Santcroos
812c8466860SMark Santcroos Op->Asl.ParseOpcode = PARSEOP_BUFFER;
813c8466860SMark Santcroos Op->Common.AmlOpcode = AML_BUFFER_OP;
814fba7fc7eSJung-uk Kim
815fba7fc7eSJung-uk Kim /* Disable further optimization */
816fba7fc7eSJung-uk Kim
8175f9b24faSJung-uk Kim Op->Asl.CompileFlags &= ~OP_COMPILE_TIME_CONST;
818c8466860SMark Santcroos UtSetParseOpName (Op);
819c8466860SMark Santcroos
820c8466860SMark Santcroos /* Child node is the buffer length */
821c8466860SMark Santcroos
8225f9b24faSJung-uk Kim NewOp = TrAllocateOp (PARSEOP_INTEGER);
823c8466860SMark Santcroos
824c8466860SMark Santcroos NewOp->Asl.AmlOpcode = AML_BYTE_OP;
825c8466860SMark Santcroos NewOp->Asl.Value.Integer = 16;
826c8466860SMark Santcroos NewOp->Asl.Parent = Op;
827c8466860SMark Santcroos
828c8466860SMark Santcroos Op->Asl.Child = NewOp;
829c8466860SMark Santcroos Op = NewOp;
830c8466860SMark Santcroos
831c8466860SMark Santcroos /* Peer to the child is the raw buffer data */
832c8466860SMark Santcroos
8335f9b24faSJung-uk Kim NewOp = TrAllocateOp (PARSEOP_RAW_DATA);
834c8466860SMark Santcroos NewOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
835c8466860SMark Santcroos NewOp->Asl.AmlLength = 16;
8361c0e1b6dSJung-uk Kim NewOp->Asl.Value.String = ACPI_CAST_PTR (char, Buffer);
837c8466860SMark Santcroos NewOp->Asl.Parent = Op->Asl.Parent;
838c8466860SMark Santcroos
839c8466860SMark Santcroos Op->Asl.Next = NewOp;
840c8466860SMark Santcroos }
841c8466860SMark Santcroos
842c8466860SMark Santcroos
843c8466860SMark Santcroos /*******************************************************************************
844c8466860SMark Santcroos *
84553289f6aSNate Lawson * FUNCTION: OpcGenerateAmlOpcode
84653289f6aSNate Lawson *
84753289f6aSNate Lawson * PARAMETERS: Op - Parse node
84853289f6aSNate Lawson *
84953289f6aSNate Lawson * RETURN: None
85053289f6aSNate Lawson *
85153289f6aSNate Lawson * DESCRIPTION: Generate the AML opcode associated with the node and its
85253289f6aSNate Lawson * parse (lex/flex) keyword opcode. Essentially implements
85353289f6aSNate Lawson * a mapping between the parse opcodes and the actual AML opcodes.
85453289f6aSNate Lawson *
85553289f6aSNate Lawson ******************************************************************************/
85653289f6aSNate Lawson
85753289f6aSNate Lawson void
OpcGenerateAmlOpcode(ACPI_PARSE_OBJECT * Op)85853289f6aSNate Lawson OpcGenerateAmlOpcode (
85953289f6aSNate Lawson ACPI_PARSE_OBJECT *Op)
86053289f6aSNate Lawson {
86153289f6aSNate Lawson UINT16 Index;
86253289f6aSNate Lawson
86353289f6aSNate Lawson
86453289f6aSNate Lawson Index = (UINT16) (Op->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
86553289f6aSNate Lawson
86653289f6aSNate Lawson Op->Asl.AmlOpcode = AslKeywordMapping[Index].AmlOpcode;
86753289f6aSNate Lawson Op->Asl.AcpiBtype = AslKeywordMapping[Index].AcpiBtype;
86853289f6aSNate Lawson Op->Asl.CompileFlags |= AslKeywordMapping[Index].Flags;
86953289f6aSNate Lawson
87053289f6aSNate Lawson if (!Op->Asl.Value.Integer)
87153289f6aSNate Lawson {
87253289f6aSNate Lawson Op->Asl.Value.Integer = AslKeywordMapping[Index].Value;
87353289f6aSNate Lawson }
87453289f6aSNate Lawson
87553289f6aSNate Lawson /* Special handling for some opcodes */
87653289f6aSNate Lawson
87753289f6aSNate Lawson switch (Op->Asl.ParseOpcode)
87853289f6aSNate Lawson {
87953289f6aSNate Lawson case PARSEOP_INTEGER:
88053289f6aSNate Lawson /*
88153289f6aSNate Lawson * Set the opcode based on the size of the integer
88253289f6aSNate Lawson */
88353289f6aSNate Lawson (void) OpcSetOptimalIntegerSize (Op);
88453289f6aSNate Lawson break;
88553289f6aSNate Lawson
88653289f6aSNate Lawson case PARSEOP_OFFSET:
88753289f6aSNate Lawson
88853289f6aSNate Lawson Op->Asl.AmlOpcodeLength = 1;
88953289f6aSNate Lawson break;
89053289f6aSNate Lawson
89153289f6aSNate Lawson case PARSEOP_ACCESSAS:
89253289f6aSNate Lawson
89353289f6aSNate Lawson OpcDoAccessAs (Op);
89453289f6aSNate Lawson break;
89553289f6aSNate Lawson
8963f0275a0SJung-uk Kim case PARSEOP_CONNECTION:
8973f0275a0SJung-uk Kim
8983f0275a0SJung-uk Kim OpcDoConnection (Op);
8993f0275a0SJung-uk Kim break;
9003f0275a0SJung-uk Kim
90153289f6aSNate Lawson case PARSEOP_EISAID:
90253289f6aSNate Lawson
90353289f6aSNate Lawson OpcDoEisaId (Op);
90453289f6aSNate Lawson break;
90553289f6aSNate Lawson
9061c0e1b6dSJung-uk Kim case PARSEOP_PRINTF:
9071c0e1b6dSJung-uk Kim
9081c0e1b6dSJung-uk Kim OpcDoPrintf (Op);
9091c0e1b6dSJung-uk Kim break;
9101c0e1b6dSJung-uk Kim
9111c0e1b6dSJung-uk Kim case PARSEOP_FPRINTF:
9121c0e1b6dSJung-uk Kim
9131c0e1b6dSJung-uk Kim OpcDoFprintf (Op);
9141c0e1b6dSJung-uk Kim break;
9151c0e1b6dSJung-uk Kim
9161c0e1b6dSJung-uk Kim case PARSEOP_TOPLD:
9171c0e1b6dSJung-uk Kim
9181c0e1b6dSJung-uk Kim OpcDoPld (Op);
9191c0e1b6dSJung-uk Kim break;
9201c0e1b6dSJung-uk Kim
921c8466860SMark Santcroos case PARSEOP_TOUUID:
922c8466860SMark Santcroos
923c8466860SMark Santcroos OpcDoUuId (Op);
924c8466860SMark Santcroos break;
925c8466860SMark Santcroos
92653289f6aSNate Lawson case PARSEOP_UNICODE:
92753289f6aSNate Lawson
92853289f6aSNate Lawson OpcDoUnicode (Op);
92953289f6aSNate Lawson break;
93053289f6aSNate Lawson
93153289f6aSNate Lawson case PARSEOP_INCLUDE:
93253289f6aSNate Lawson
9336f1f1a63SJung-uk Kim AslGbl_HasIncludeFiles = TRUE;
93453289f6aSNate Lawson break;
93553289f6aSNate Lawson
936efcc2a30SJung-uk Kim case PARSEOP_TIMER:
937efcc2a30SJung-uk Kim
938efcc2a30SJung-uk Kim if (AcpiGbl_IntegerBitWidth == 32)
939efcc2a30SJung-uk Kim {
940efcc2a30SJung-uk Kim AslError (ASL_REMARK, ASL_MSG_TRUNCATION, Op, NULL);
941efcc2a30SJung-uk Kim }
942efcc2a30SJung-uk Kim break;
943efcc2a30SJung-uk Kim
94453289f6aSNate Lawson default:
945a9d8d09cSJung-uk Kim
94653289f6aSNate Lawson /* Nothing to do for other opcodes */
947a9d8d09cSJung-uk Kim
94853289f6aSNate Lawson break;
94953289f6aSNate Lawson }
95053289f6aSNate Lawson
95153289f6aSNate Lawson return;
95253289f6aSNate Lawson }
953