153289f6aSNate Lawson /******************************************************************************
253289f6aSNate Lawson *
30b94ba42SJung-uk Kim * Module Name: aslanalyze.c - Support functions for parse tree walks
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"
154ec0234b4SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
1550b94ba42SJung-uk Kim #include <string.h>
1560b94ba42SJung-uk Kim
15753289f6aSNate Lawson
15853289f6aSNate Lawson #define _COMPONENT ACPI_COMPILER
15953289f6aSNate Lawson ACPI_MODULE_NAME ("aslanalyze")
16053289f6aSNate Lawson
1611a39cfb0SJung-uk Kim
162f8146b88SJung-uk Kim /* Local Prototypes */
163f8146b88SJung-uk Kim
164f8146b88SJung-uk Kim static ACPI_STATUS
165f8146b88SJung-uk Kim ApDeviceSubtreeWalk (
166f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op,
167f8146b88SJung-uk Kim UINT32 Level,
168f8146b88SJung-uk Kim void *Context);
169f8146b88SJung-uk Kim
170f8146b88SJung-uk Kim
1711a39cfb0SJung-uk Kim /*******************************************************************************
1721a39cfb0SJung-uk Kim *
1731a39cfb0SJung-uk Kim * FUNCTION: AnIsInternalMethod
1741a39cfb0SJung-uk Kim *
1751a39cfb0SJung-uk Kim * PARAMETERS: Op - Current op
1761a39cfb0SJung-uk Kim *
1771a39cfb0SJung-uk Kim * RETURN: Boolean
1781a39cfb0SJung-uk Kim *
1791a39cfb0SJung-uk Kim * DESCRIPTION: Check for an internal control method.
1801a39cfb0SJung-uk Kim *
1811a39cfb0SJung-uk Kim ******************************************************************************/
1821a39cfb0SJung-uk Kim
1830b94ba42SJung-uk Kim BOOLEAN
AnIsInternalMethod(ACPI_PARSE_OBJECT * Op)1841a39cfb0SJung-uk Kim AnIsInternalMethod (
1851a39cfb0SJung-uk Kim ACPI_PARSE_OBJECT *Op)
1861a39cfb0SJung-uk Kim {
1871a39cfb0SJung-uk Kim
1885ef50723SJung-uk Kim if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
1895ef50723SJung-uk Kim (!strcmp (Op->Asl.ExternalName, "_OSI")))
1901a39cfb0SJung-uk Kim {
1911a39cfb0SJung-uk Kim return (TRUE);
1921a39cfb0SJung-uk Kim }
1931a39cfb0SJung-uk Kim
1941a39cfb0SJung-uk Kim return (FALSE);
1951a39cfb0SJung-uk Kim }
1961a39cfb0SJung-uk Kim
1971a39cfb0SJung-uk Kim
1981a39cfb0SJung-uk Kim /*******************************************************************************
1991a39cfb0SJung-uk Kim *
2001a39cfb0SJung-uk Kim * FUNCTION: AnGetInternalMethodReturnType
2011a39cfb0SJung-uk Kim *
2021a39cfb0SJung-uk Kim * PARAMETERS: Op - Current op
2031a39cfb0SJung-uk Kim *
2041a39cfb0SJung-uk Kim * RETURN: Btype
2051a39cfb0SJung-uk Kim *
2061a39cfb0SJung-uk Kim * DESCRIPTION: Get the return type of an internal method
2071a39cfb0SJung-uk Kim *
2081a39cfb0SJung-uk Kim ******************************************************************************/
2091a39cfb0SJung-uk Kim
2100b94ba42SJung-uk Kim UINT32
AnGetInternalMethodReturnType(ACPI_PARSE_OBJECT * Op)2111a39cfb0SJung-uk Kim AnGetInternalMethodReturnType (
2121a39cfb0SJung-uk Kim ACPI_PARSE_OBJECT *Op)
2131a39cfb0SJung-uk Kim {
2141a39cfb0SJung-uk Kim
2155ef50723SJung-uk Kim if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
2165ef50723SJung-uk Kim (!strcmp (Op->Asl.ExternalName, "_OSI")))
2171a39cfb0SJung-uk Kim {
2181a39cfb0SJung-uk Kim return (ACPI_BTYPE_STRING);
2191a39cfb0SJung-uk Kim }
2201a39cfb0SJung-uk Kim
2211a39cfb0SJung-uk Kim return (0);
2221a39cfb0SJung-uk Kim }
2231a39cfb0SJung-uk Kim
22453289f6aSNate Lawson
22553289f6aSNate Lawson /*******************************************************************************
22653289f6aSNate Lawson *
2273c1812acSJung-uk Kim * FUNCTION: AnCheckId
2283c1812acSJung-uk Kim *
2293c1812acSJung-uk Kim * PARAMETERS: Op - Current parse op
2303c1812acSJung-uk Kim * Type - HID or CID
2313c1812acSJung-uk Kim *
2323c1812acSJung-uk Kim * RETURN: None
2333c1812acSJung-uk Kim *
2343c1812acSJung-uk Kim * DESCRIPTION: Perform various checks on _HID and _CID strings. Only limited
2353c1812acSJung-uk Kim * checks can be performed on _CID strings.
2363c1812acSJung-uk Kim *
2373c1812acSJung-uk Kim ******************************************************************************/
2383c1812acSJung-uk Kim
2390b94ba42SJung-uk Kim void
AnCheckId(ACPI_PARSE_OBJECT * Op,ACPI_NAME Type)2403c1812acSJung-uk Kim AnCheckId (
2413c1812acSJung-uk Kim ACPI_PARSE_OBJECT *Op,
2423c1812acSJung-uk Kim ACPI_NAME Type)
2433c1812acSJung-uk Kim {
2443c1812acSJung-uk Kim UINT32 i;
2453c1812acSJung-uk Kim ACPI_SIZE Length;
2463c1812acSJung-uk Kim
2473c1812acSJung-uk Kim
2485a77b11bSJung-uk Kim /* Only care about string versions of _HID/_CID (integers are legal) */
2495a77b11bSJung-uk Kim
2503c1812acSJung-uk Kim if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
2513c1812acSJung-uk Kim {
2523c1812acSJung-uk Kim return;
2533c1812acSJung-uk Kim }
2543c1812acSJung-uk Kim
2555a77b11bSJung-uk Kim /* For both _HID and _CID, the string must be non-null */
2565a77b11bSJung-uk Kim
2573c1812acSJung-uk Kim Length = strlen (Op->Asl.Value.String);
2585a77b11bSJung-uk Kim if (!Length)
2595a77b11bSJung-uk Kim {
260f8146b88SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_NULL_STRING, Op, NULL);
2615a77b11bSJung-uk Kim return;
2625a77b11bSJung-uk Kim }
2633c1812acSJung-uk Kim
2643c1812acSJung-uk Kim /*
2655a77b11bSJung-uk Kim * One of the things we want to catch here is the use of a leading
2665a77b11bSJung-uk Kim * asterisk in the string -- an odd construct that certain platform
2675a77b11bSJung-uk Kim * manufacturers are fond of. Technically, a leading asterisk is OK
2685a77b11bSJung-uk Kim * for _CID, but a valid use of this has not been seen.
2693c1812acSJung-uk Kim */
2705a77b11bSJung-uk Kim if (*Op->Asl.Value.String == '*')
2715a77b11bSJung-uk Kim {
2725a77b11bSJung-uk Kim AslError (ASL_ERROR, ASL_MSG_LEADING_ASTERISK,
2735a77b11bSJung-uk Kim Op, Op->Asl.Value.String);
2745a77b11bSJung-uk Kim return;
2755a77b11bSJung-uk Kim }
2765a77b11bSJung-uk Kim
2775a77b11bSJung-uk Kim /* _CID strings are bus-specific, no more checks can be performed */
2785a77b11bSJung-uk Kim
2795a77b11bSJung-uk Kim if (Type == ASL_TYPE_CID)
2805a77b11bSJung-uk Kim {
2815a77b11bSJung-uk Kim return;
2825a77b11bSJung-uk Kim }
2835a77b11bSJung-uk Kim
2845a77b11bSJung-uk Kim /* For _HID, all characters must be alphanumeric */
2855a77b11bSJung-uk Kim
2863c1812acSJung-uk Kim for (i = 0; Op->Asl.Value.String[i]; i++)
2873c1812acSJung-uk Kim {
2883c1812acSJung-uk Kim if (!isalnum ((int) Op->Asl.Value.String[i]))
2893c1812acSJung-uk Kim {
2903c1812acSJung-uk Kim AslError (ASL_ERROR, ASL_MSG_ALPHANUMERIC_STRING,
2913c1812acSJung-uk Kim Op, Op->Asl.Value.String);
2923f0275a0SJung-uk Kim return;
2933c1812acSJung-uk Kim }
2943c1812acSJung-uk Kim }
2953c1812acSJung-uk Kim
2963f0275a0SJung-uk Kim /*
2973f0275a0SJung-uk Kim * _HID String must be one of these forms:
2983f0275a0SJung-uk Kim *
2993f0275a0SJung-uk Kim * "AAA####" A is an uppercase letter and # is a hex digit
3003f0275a0SJung-uk Kim * "ACPI####" # is a hex digit
3013f0275a0SJung-uk Kim * "NNNN####" N is an uppercase letter or decimal digit (0-9)
3023f0275a0SJung-uk Kim * # is a hex digit (ACPI 5.0)
3033f0275a0SJung-uk Kim */
3043c1812acSJung-uk Kim if ((Length < 7) || (Length > 8))
3053c1812acSJung-uk Kim {
3063c1812acSJung-uk Kim AslError (ASL_ERROR, ASL_MSG_HID_LENGTH,
3073c1812acSJung-uk Kim Op, Op->Asl.Value.String);
3083c1812acSJung-uk Kim return;
3093c1812acSJung-uk Kim }
3103c1812acSJung-uk Kim
311f8146b88SJung-uk Kim /* _HID Length is valid (7 or 8), now check prefix (first 3 or 4 chars) */
3123c1812acSJung-uk Kim
3133f0275a0SJung-uk Kim if (Length == 7)
3143c1812acSJung-uk Kim {
3153f0275a0SJung-uk Kim /* AAA####: Ensure the alphabetic prefix is all uppercase */
3163c1812acSJung-uk Kim
3173f0275a0SJung-uk Kim for (i = 0; i < 3; i++)
3183c1812acSJung-uk Kim {
3193c1812acSJung-uk Kim if (!isupper ((int) Op->Asl.Value.String[i]))
3203c1812acSJung-uk Kim {
3213c1812acSJung-uk Kim AslError (ASL_ERROR, ASL_MSG_UPPER_CASE,
3223c1812acSJung-uk Kim Op, &Op->Asl.Value.String[i]);
3233f0275a0SJung-uk Kim return;
3243f0275a0SJung-uk Kim }
3253f0275a0SJung-uk Kim }
3263f0275a0SJung-uk Kim }
3273f0275a0SJung-uk Kim else /* Length == 8 */
3283f0275a0SJung-uk Kim {
3293f0275a0SJung-uk Kim /*
3303f0275a0SJung-uk Kim * ACPI#### or NNNN####:
3313f0275a0SJung-uk Kim * Ensure the prefix contains only uppercase alpha or decimal digits
3323f0275a0SJung-uk Kim */
3333f0275a0SJung-uk Kim for (i = 0; i < 4; i++)
3343f0275a0SJung-uk Kim {
3353f0275a0SJung-uk Kim if (!isupper ((int) Op->Asl.Value.String[i]) &&
3363f0275a0SJung-uk Kim !isdigit ((int) Op->Asl.Value.String[i]))
3373f0275a0SJung-uk Kim {
3383f0275a0SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_HID_PREFIX,
3393f0275a0SJung-uk Kim Op, &Op->Asl.Value.String[i]);
3403f0275a0SJung-uk Kim return;
3413f0275a0SJung-uk Kim }
3423f0275a0SJung-uk Kim }
3433f0275a0SJung-uk Kim }
3443f0275a0SJung-uk Kim
3453f0275a0SJung-uk Kim /* Remaining characters (suffix) must be hex digits */
3463f0275a0SJung-uk Kim
3473f0275a0SJung-uk Kim for (; i < Length; i++)
3483f0275a0SJung-uk Kim {
3493f0275a0SJung-uk Kim if (!isxdigit ((int) Op->Asl.Value.String[i]))
3503f0275a0SJung-uk Kim {
3513f0275a0SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_HID_SUFFIX,
3523f0275a0SJung-uk Kim Op, &Op->Asl.Value.String[i]);
3533c1812acSJung-uk Kim break;
3543c1812acSJung-uk Kim }
3553c1812acSJung-uk Kim }
3563c1812acSJung-uk Kim }
3573c1812acSJung-uk Kim
3583c1812acSJung-uk Kim
3593c1812acSJung-uk Kim /*******************************************************************************
3603c1812acSJung-uk Kim *
36153289f6aSNate Lawson * FUNCTION: AnLastStatementIsReturn
36253289f6aSNate Lawson *
36353289f6aSNate Lawson * PARAMETERS: Op - A method parse node
36453289f6aSNate Lawson *
36553289f6aSNate Lawson * RETURN: TRUE if last statement is an ASL RETURN. False otherwise
36653289f6aSNate Lawson *
36753289f6aSNate Lawson * DESCRIPTION: Walk down the list of top level statements within a method
36853289f6aSNate Lawson * to find the last one. Check if that last statement is in
36953289f6aSNate Lawson * fact a RETURN statement.
37053289f6aSNate Lawson *
37153289f6aSNate Lawson ******************************************************************************/
37253289f6aSNate Lawson
3730b94ba42SJung-uk Kim BOOLEAN
AnLastStatementIsReturn(ACPI_PARSE_OBJECT * Op)37453289f6aSNate Lawson AnLastStatementIsReturn (
37553289f6aSNate Lawson ACPI_PARSE_OBJECT *Op)
37653289f6aSNate Lawson {
37753289f6aSNate Lawson ACPI_PARSE_OBJECT *Next;
37853289f6aSNate Lawson
37953289f6aSNate Lawson
3800b94ba42SJung-uk Kim /* Check if last statement is a return */
3810b94ba42SJung-uk Kim
38253289f6aSNate Lawson Next = ASL_GET_CHILD_NODE (Op);
38353289f6aSNate Lawson while (Next)
38453289f6aSNate Lawson {
38553289f6aSNate Lawson if ((!Next->Asl.Next) &&
38653289f6aSNate Lawson (Next->Asl.ParseOpcode == PARSEOP_RETURN))
38753289f6aSNate Lawson {
3880b94ba42SJung-uk Kim return (TRUE);
38953289f6aSNate Lawson }
39053289f6aSNate Lawson
39153289f6aSNate Lawson Next = ASL_GET_PEER_NODE (Next);
39253289f6aSNate Lawson }
39353289f6aSNate Lawson
3940b94ba42SJung-uk Kim return (FALSE);
39553289f6aSNate Lawson }
39653289f6aSNate Lawson
39753289f6aSNate Lawson
39853289f6aSNate Lawson /*******************************************************************************
39953289f6aSNate Lawson *
40053289f6aSNate Lawson * FUNCTION: AnCheckMethodReturnValue
40153289f6aSNate Lawson *
40253289f6aSNate Lawson * PARAMETERS: Op - Parent
40353289f6aSNate Lawson * OpInfo - Parent info
40453289f6aSNate Lawson * ArgOp - Method invocation op
40553289f6aSNate Lawson * RequiredBtypes - What caller requires
40653289f6aSNate Lawson * ThisNodeBtype - What this node returns (if anything)
40753289f6aSNate Lawson *
40853289f6aSNate Lawson * RETURN: None
40953289f6aSNate Lawson *
41053289f6aSNate Lawson * DESCRIPTION: Check a method invocation for 1) A return value and if it does
41153289f6aSNate Lawson * in fact return a value, 2) check the type of the return value.
41253289f6aSNate Lawson *
41353289f6aSNate Lawson ******************************************************************************/
41453289f6aSNate Lawson
4150b94ba42SJung-uk Kim void
AnCheckMethodReturnValue(ACPI_PARSE_OBJECT * Op,const ACPI_OPCODE_INFO * OpInfo,ACPI_PARSE_OBJECT * ArgOp,UINT32 RequiredBtypes,UINT32 ThisNodeBtype)41653289f6aSNate Lawson AnCheckMethodReturnValue (
41753289f6aSNate Lawson ACPI_PARSE_OBJECT *Op,
41853289f6aSNate Lawson const ACPI_OPCODE_INFO *OpInfo,
41953289f6aSNate Lawson ACPI_PARSE_OBJECT *ArgOp,
42053289f6aSNate Lawson UINT32 RequiredBtypes,
42153289f6aSNate Lawson UINT32 ThisNodeBtype)
42253289f6aSNate Lawson {
42353289f6aSNate Lawson ACPI_PARSE_OBJECT *OwningOp;
42453289f6aSNate Lawson ACPI_NAMESPACE_NODE *Node;
425ec0234b4SJung-uk Kim char *ExternalPath;
42653289f6aSNate Lawson
42753289f6aSNate Lawson
42853289f6aSNate Lawson Node = ArgOp->Asl.Node;
42953289f6aSNate Lawson
430f8146b88SJung-uk Kim if (!Node)
431f8146b88SJung-uk Kim {
432f8146b88SJung-uk Kim /* No error message, this can happen and is OK */
433f8146b88SJung-uk Kim
434f8146b88SJung-uk Kim return;
435f8146b88SJung-uk Kim }
43653289f6aSNate Lawson
43753289f6aSNate Lawson /* Examine the parent op of this method */
43853289f6aSNate Lawson
439fba7fc7eSJung-uk Kim OwningOp = Node->Op;
440ec0234b4SJung-uk Kim ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
441ec0234b4SJung-uk Kim
4425f9b24faSJung-uk Kim if (OwningOp->Asl.CompileFlags & OP_METHOD_NO_RETVAL)
44353289f6aSNate Lawson {
444fba7fc7eSJung-uk Kim /* Method NEVER returns a value */
445fba7fc7eSJung-uk Kim
446ec0234b4SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, ExternalPath);
44753289f6aSNate Lawson }
4485f9b24faSJung-uk Kim else if (OwningOp->Asl.CompileFlags & OP_METHOD_SOME_NO_RETVAL)
44953289f6aSNate Lawson {
450fba7fc7eSJung-uk Kim /* Method SOMETIMES returns a value, SOMETIMES not */
451fba7fc7eSJung-uk Kim
452ec0234b4SJung-uk Kim AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL, Op, ExternalPath);
45353289f6aSNate Lawson }
45453289f6aSNate Lawson else if (!(ThisNodeBtype & RequiredBtypes))
45553289f6aSNate Lawson {
456fba7fc7eSJung-uk Kim /* Method returns a value, but the type is wrong */
457fba7fc7eSJung-uk Kim
4586f1f1a63SJung-uk Kim AnFormatBtype (AslGbl_StringBuffer, ThisNodeBtype);
4596f1f1a63SJung-uk Kim AnFormatBtype (AslGbl_StringBuffer2, RequiredBtypes);
46053289f6aSNate Lawson
46153289f6aSNate Lawson /*
46253289f6aSNate Lawson * The case where the method does not return any value at all
46353289f6aSNate Lawson * was already handled in the namespace cross reference
46453289f6aSNate Lawson * -- Only issue an error if the method in fact returns a value,
46553289f6aSNate Lawson * but it is of the wrong type
46653289f6aSNate Lawson */
46753289f6aSNate Lawson if (ThisNodeBtype != 0)
46853289f6aSNate Lawson {
4696f1f1a63SJung-uk Kim sprintf (AslGbl_MsgBuffer,
470fba7fc7eSJung-uk Kim "Method returns [%s], %s operator requires [%s]",
4716f1f1a63SJung-uk Kim AslGbl_StringBuffer, OpInfo->Name, AslGbl_StringBuffer2);
47253289f6aSNate Lawson
473385fb5d9SJung-uk Kim AslError (ASL_WARNING, ASL_MSG_INVALID_TYPE, ArgOp, AslGbl_MsgBuffer);
47453289f6aSNate Lawson }
47553289f6aSNate Lawson }
476ec0234b4SJung-uk Kim
477ec0234b4SJung-uk Kim if (ExternalPath)
478ec0234b4SJung-uk Kim {
479ec0234b4SJung-uk Kim ACPI_FREE (ExternalPath);
480ec0234b4SJung-uk Kim }
48153289f6aSNate Lawson }
48253289f6aSNate Lawson
48353289f6aSNate Lawson
48453289f6aSNate Lawson /*******************************************************************************
48553289f6aSNate Lawson *
4861a39cfb0SJung-uk Kim * FUNCTION: AnIsResultUsed
4871a39cfb0SJung-uk Kim *
4881a39cfb0SJung-uk Kim * PARAMETERS: Op - Parent op for the operator
4891a39cfb0SJung-uk Kim *
4901a39cfb0SJung-uk Kim * RETURN: TRUE if result from this operation is actually consumed
4911a39cfb0SJung-uk Kim *
4921a39cfb0SJung-uk Kim * DESCRIPTION: Determine if the function result value from an operator is
4931a39cfb0SJung-uk Kim * used.
4941a39cfb0SJung-uk Kim *
4951a39cfb0SJung-uk Kim ******************************************************************************/
4961a39cfb0SJung-uk Kim
4970b94ba42SJung-uk Kim BOOLEAN
AnIsResultUsed(ACPI_PARSE_OBJECT * Op)4981a39cfb0SJung-uk Kim AnIsResultUsed (
4991a39cfb0SJung-uk Kim ACPI_PARSE_OBJECT *Op)
5001a39cfb0SJung-uk Kim {
5011a39cfb0SJung-uk Kim ACPI_PARSE_OBJECT *Parent;
5021a39cfb0SJung-uk Kim
5031a39cfb0SJung-uk Kim
5041a39cfb0SJung-uk Kim switch (Op->Asl.ParseOpcode)
5051a39cfb0SJung-uk Kim {
5061a39cfb0SJung-uk Kim case PARSEOP_INCREMENT:
5071a39cfb0SJung-uk Kim case PARSEOP_DECREMENT:
5081a39cfb0SJung-uk Kim
5091a39cfb0SJung-uk Kim /* These are standalone operators, no return value */
5101a39cfb0SJung-uk Kim
5111a39cfb0SJung-uk Kim return (TRUE);
5121a39cfb0SJung-uk Kim
5131a39cfb0SJung-uk Kim default:
514a9d8d09cSJung-uk Kim
5151a39cfb0SJung-uk Kim break;
5161a39cfb0SJung-uk Kim }
5171a39cfb0SJung-uk Kim
5181a39cfb0SJung-uk Kim /* Examine parent to determine if the return value is used */
5191a39cfb0SJung-uk Kim
5201a39cfb0SJung-uk Kim Parent = Op->Asl.Parent;
5211a39cfb0SJung-uk Kim switch (Parent->Asl.ParseOpcode)
5221a39cfb0SJung-uk Kim {
5231a39cfb0SJung-uk Kim /* If/While - check if the operator is the predicate */
5241a39cfb0SJung-uk Kim
5251a39cfb0SJung-uk Kim case PARSEOP_IF:
5261a39cfb0SJung-uk Kim case PARSEOP_WHILE:
5271a39cfb0SJung-uk Kim
5281a39cfb0SJung-uk Kim /* First child is the predicate */
5291a39cfb0SJung-uk Kim
5301a39cfb0SJung-uk Kim if (Parent->Asl.Child == Op)
5311a39cfb0SJung-uk Kim {
5321a39cfb0SJung-uk Kim return (TRUE);
5331a39cfb0SJung-uk Kim }
534f8146b88SJung-uk Kim
5351a39cfb0SJung-uk Kim return (FALSE);
5361a39cfb0SJung-uk Kim
5371a39cfb0SJung-uk Kim /* Not used if one of these is the parent */
5381a39cfb0SJung-uk Kim
5391a39cfb0SJung-uk Kim case PARSEOP_METHOD:
540f8146b88SJung-uk Kim case PARSEOP_DEFINITION_BLOCK:
5411a39cfb0SJung-uk Kim case PARSEOP_ELSE:
5421a39cfb0SJung-uk Kim
5431a39cfb0SJung-uk Kim return (FALSE);
5441a39cfb0SJung-uk Kim
5451a39cfb0SJung-uk Kim default:
546a9d8d09cSJung-uk Kim
5471a39cfb0SJung-uk Kim /* Any other type of parent means that the result is used */
5481a39cfb0SJung-uk Kim
5491a39cfb0SJung-uk Kim return (TRUE);
5501a39cfb0SJung-uk Kim }
5511a39cfb0SJung-uk Kim }
5521a39cfb0SJung-uk Kim
5531a39cfb0SJung-uk Kim
5541a39cfb0SJung-uk Kim /*******************************************************************************
5551a39cfb0SJung-uk Kim *
5560b94ba42SJung-uk Kim * FUNCTION: ApCheckForGpeNameConflict
55753289f6aSNate Lawson *
5580b94ba42SJung-uk Kim * PARAMETERS: Op - Current parse op
55953289f6aSNate Lawson *
5600b94ba42SJung-uk Kim * RETURN: None
56153289f6aSNate Lawson *
5620b94ba42SJung-uk Kim * DESCRIPTION: Check for a conflict between GPE names within this scope.
5630b94ba42SJung-uk Kim * Conflict means two GPE names with the same GPE number, but
5640b94ba42SJung-uk Kim * different types -- such as _L1C and _E1C.
56553289f6aSNate Lawson *
56653289f6aSNate Lawson ******************************************************************************/
56753289f6aSNate Lawson
5680b94ba42SJung-uk Kim void
ApCheckForGpeNameConflict(ACPI_PARSE_OBJECT * Op)5690b94ba42SJung-uk Kim ApCheckForGpeNameConflict (
5700b94ba42SJung-uk Kim ACPI_PARSE_OBJECT *Op)
57153289f6aSNate Lawson {
5720b94ba42SJung-uk Kim ACPI_PARSE_OBJECT *NextOp;
5730b94ba42SJung-uk Kim UINT32 GpeNumber;
574278f0de6SJung-uk Kim char Name[ACPI_NAMESEG_SIZE + 1];
575278f0de6SJung-uk Kim char Target[ACPI_NAMESEG_SIZE];
5761a39cfb0SJung-uk Kim
5771a39cfb0SJung-uk Kim
5780b94ba42SJung-uk Kim /* Need a null-terminated string version of NameSeg */
5790b94ba42SJung-uk Kim
580a009b7dcSJung-uk Kim ACPI_MOVE_32_TO_32 (Name, Op->Asl.NameSeg);
581278f0de6SJung-uk Kim Name[ACPI_NAMESEG_SIZE] = 0;
5821a39cfb0SJung-uk Kim
5831a39cfb0SJung-uk Kim /*
5840b94ba42SJung-uk Kim * For a GPE method:
5850b94ba42SJung-uk Kim * 1st char must be underscore
5860b94ba42SJung-uk Kim * 2nd char must be L or E
5870b94ba42SJung-uk Kim * 3rd/4th chars must be a hex number
5881a39cfb0SJung-uk Kim */
5890b94ba42SJung-uk Kim if ((Name[0] != '_') ||
5900b94ba42SJung-uk Kim ((Name[1] != 'L') && (Name[1] != 'E')))
5911a39cfb0SJung-uk Kim {
5920b94ba42SJung-uk Kim return;
5931a39cfb0SJung-uk Kim }
5941a39cfb0SJung-uk Kim
5950b94ba42SJung-uk Kim /* Verify 3rd/4th chars are a valid hex value */
5961a39cfb0SJung-uk Kim
5975ef50723SJung-uk Kim GpeNumber = strtoul (&Name[2], NULL, 16);
5980b94ba42SJung-uk Kim if (GpeNumber == ACPI_UINT32_MAX)
5991a39cfb0SJung-uk Kim {
6000b94ba42SJung-uk Kim return;
6011a39cfb0SJung-uk Kim }
6021a39cfb0SJung-uk Kim
6031a39cfb0SJung-uk Kim /*
6040b94ba42SJung-uk Kim * We are now sure we have an _Lxx or _Exx.
6050b94ba42SJung-uk Kim * Create the target name that would cause collision (Flip E/L)
6061a39cfb0SJung-uk Kim */
6070b94ba42SJung-uk Kim ACPI_MOVE_32_TO_32 (Target, Name);
6081a39cfb0SJung-uk Kim
6090b94ba42SJung-uk Kim /* Inject opposite letter ("L" versus "E") */
6100b94ba42SJung-uk Kim
6110b94ba42SJung-uk Kim if (Name[1] == 'L')
6120b94ba42SJung-uk Kim {
6130b94ba42SJung-uk Kim Target[1] = 'E';
6140b94ba42SJung-uk Kim }
6150b94ba42SJung-uk Kim else /* Name[1] == 'E' */
6160b94ba42SJung-uk Kim {
6170b94ba42SJung-uk Kim Target[1] = 'L';
6180b94ba42SJung-uk Kim }
6190b94ba42SJung-uk Kim
6200b94ba42SJung-uk Kim /* Search all peers (objects within this scope) for target match */
6210b94ba42SJung-uk Kim
6220b94ba42SJung-uk Kim NextOp = Op->Asl.Next;
6230b94ba42SJung-uk Kim while (NextOp)
6240b94ba42SJung-uk Kim {
6251a39cfb0SJung-uk Kim /*
6260b94ba42SJung-uk Kim * We mostly care about methods, but check Name() constructs also,
6270b94ba42SJung-uk Kim * even though they will get another error for not being a method.
6280b94ba42SJung-uk Kim * All GPE names must be defined as control methods.
6291a39cfb0SJung-uk Kim */
6300b94ba42SJung-uk Kim if ((NextOp->Asl.ParseOpcode == PARSEOP_METHOD) ||
6310b94ba42SJung-uk Kim (NextOp->Asl.ParseOpcode == PARSEOP_NAME))
6321a39cfb0SJung-uk Kim {
633278f0de6SJung-uk Kim if (ACPI_COMPARE_NAMESEG (Target, NextOp->Asl.NameSeg))
63453289f6aSNate Lawson {
6350b94ba42SJung-uk Kim /* Found both _Exy and _Lxy in the same scope, error */
63653289f6aSNate Lawson
6370b94ba42SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_GPE_NAME_CONFLICT, NextOp,
6380b94ba42SJung-uk Kim Name);
6390b94ba42SJung-uk Kim return;
6400b94ba42SJung-uk Kim }
64153289f6aSNate Lawson }
642fba7fc7eSJung-uk Kim
6430b94ba42SJung-uk Kim NextOp = NextOp->Asl.Next;
644fba7fc7eSJung-uk Kim }
645fba7fc7eSJung-uk Kim
6460b94ba42SJung-uk Kim /* OK, no conflict found */
647fba7fc7eSJung-uk Kim
6480b94ba42SJung-uk Kim return;
649fba7fc7eSJung-uk Kim }
650d052a1ccSJung-uk Kim
651d052a1ccSJung-uk Kim
652d052a1ccSJung-uk Kim /*******************************************************************************
653d052a1ccSJung-uk Kim *
654d052a1ccSJung-uk Kim * FUNCTION: ApCheckRegMethod
655d052a1ccSJung-uk Kim *
656d052a1ccSJung-uk Kim * PARAMETERS: Op - Current parse op
657d052a1ccSJung-uk Kim *
658d052a1ccSJung-uk Kim * RETURN: None
659d052a1ccSJung-uk Kim *
660d052a1ccSJung-uk Kim * DESCRIPTION: Ensure that a _REG method has a corresponding Operation
661d052a1ccSJung-uk Kim * Region declaration within the same scope. Note: _REG is defined
662d052a1ccSJung-uk Kim * to have two arguments and must therefore be defined as a
663d052a1ccSJung-uk Kim * control method.
664d052a1ccSJung-uk Kim *
665d052a1ccSJung-uk Kim ******************************************************************************/
666d052a1ccSJung-uk Kim
667d052a1ccSJung-uk Kim void
ApCheckRegMethod(ACPI_PARSE_OBJECT * Op)668d052a1ccSJung-uk Kim ApCheckRegMethod (
669d052a1ccSJung-uk Kim ACPI_PARSE_OBJECT *Op)
670d052a1ccSJung-uk Kim {
671d052a1ccSJung-uk Kim ACPI_PARSE_OBJECT *Next;
672d052a1ccSJung-uk Kim ACPI_PARSE_OBJECT *Parent;
673d052a1ccSJung-uk Kim
674d052a1ccSJung-uk Kim
675d052a1ccSJung-uk Kim /* We are only interested in _REG methods */
676d052a1ccSJung-uk Kim
677278f0de6SJung-uk Kim if (!ACPI_COMPARE_NAMESEG (METHOD_NAME__REG, &Op->Asl.NameSeg))
678d052a1ccSJung-uk Kim {
679d052a1ccSJung-uk Kim return;
680d052a1ccSJung-uk Kim }
681d052a1ccSJung-uk Kim
682d052a1ccSJung-uk Kim /* Get the start of the current scope */
683d052a1ccSJung-uk Kim
684d052a1ccSJung-uk Kim Parent = Op->Asl.Parent;
685d052a1ccSJung-uk Kim Next = Parent->Asl.Child;
686d052a1ccSJung-uk Kim
687d052a1ccSJung-uk Kim /* Search entire scope for an operation region declaration */
688d052a1ccSJung-uk Kim
689d052a1ccSJung-uk Kim while (Next)
690d052a1ccSJung-uk Kim {
691d052a1ccSJung-uk Kim if (Next->Asl.ParseOpcode == PARSEOP_OPERATIONREGION)
692d052a1ccSJung-uk Kim {
693d052a1ccSJung-uk Kim return; /* Found region, OK */
694d052a1ccSJung-uk Kim }
695d052a1ccSJung-uk Kim
696d052a1ccSJung-uk Kim Next = Next->Asl.Next;
697d052a1ccSJung-uk Kim }
698d052a1ccSJung-uk Kim
699d052a1ccSJung-uk Kim /* No region found, issue warning */
700d052a1ccSJung-uk Kim
701d052a1ccSJung-uk Kim AslError (ASL_WARNING, ASL_MSG_NO_REGION, Op, NULL);
702d052a1ccSJung-uk Kim }
703313a0c13SJung-uk Kim
704313a0c13SJung-uk Kim
705313a0c13SJung-uk Kim /*******************************************************************************
706313a0c13SJung-uk Kim *
707f8146b88SJung-uk Kim * FUNCTION: ApFindNameInDeviceTree
708f8146b88SJung-uk Kim *
709f8146b88SJung-uk Kim * PARAMETERS: Name - Name to search for
710f8146b88SJung-uk Kim * Op - Current parse op
711f8146b88SJung-uk Kim *
712f8146b88SJung-uk Kim * RETURN: TRUE if name found in the same scope as Op.
713f8146b88SJung-uk Kim *
714f8146b88SJung-uk Kim * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
715f8146b88SJung-uk Kim * a Method() or a Name(). "Same scope" can mean under an If or
716f8146b88SJung-uk Kim * Else statement.
717f8146b88SJung-uk Kim *
718f8146b88SJung-uk Kim * NOTE: Detects _HID/_ADR in this type of construct (legal in ACPI 6.1+)
719f8146b88SJung-uk Kim *
720f8146b88SJung-uk Kim * Scope (\_SB.PCI0)
721f8146b88SJung-uk Kim * {
722f8146b88SJung-uk Kim * Device (I2C0)
723f8146b88SJung-uk Kim * {
724f8146b88SJung-uk Kim * If (SMD0 != 4) {
725f8146b88SJung-uk Kim * Name (_HID, "INT3442")
726f8146b88SJung-uk Kim * } Else {
727f8146b88SJung-uk Kim * Name (_ADR, 0x400)
728f8146b88SJung-uk Kim * }
729f8146b88SJung-uk Kim * }
730f8146b88SJung-uk Kim * }
731f8146b88SJung-uk Kim ******************************************************************************/
732f8146b88SJung-uk Kim
733f8146b88SJung-uk Kim BOOLEAN
ApFindNameInDeviceTree(char * Name,ACPI_PARSE_OBJECT * Op)734f8146b88SJung-uk Kim ApFindNameInDeviceTree (
735f8146b88SJung-uk Kim char *Name,
736f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op)
737f8146b88SJung-uk Kim {
738f8146b88SJung-uk Kim ACPI_STATUS Status;
739f8146b88SJung-uk Kim
740f8146b88SJung-uk Kim
741f8146b88SJung-uk Kim Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
742f8146b88SJung-uk Kim ApDeviceSubtreeWalk, NULL, Name);
743f8146b88SJung-uk Kim
744f8146b88SJung-uk Kim if (Status == AE_CTRL_TRUE)
745f8146b88SJung-uk Kim {
746f8146b88SJung-uk Kim return (TRUE); /* Found a match */
747f8146b88SJung-uk Kim }
748f8146b88SJung-uk Kim
749f8146b88SJung-uk Kim return (FALSE);
750f8146b88SJung-uk Kim }
751f8146b88SJung-uk Kim
752f8146b88SJung-uk Kim
753f8146b88SJung-uk Kim /* Callback function for interface above */
754f8146b88SJung-uk Kim
755f8146b88SJung-uk Kim static ACPI_STATUS
ApDeviceSubtreeWalk(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)756f8146b88SJung-uk Kim ApDeviceSubtreeWalk (
757f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op,
758f8146b88SJung-uk Kim UINT32 Level,
759f8146b88SJung-uk Kim void *Context)
760f8146b88SJung-uk Kim {
761f8146b88SJung-uk Kim char *Name = ACPI_CAST_PTR (char, Context);
762f8146b88SJung-uk Kim
763f8146b88SJung-uk Kim
764f8146b88SJung-uk Kim switch (Op->Asl.ParseOpcode)
765f8146b88SJung-uk Kim {
766f8146b88SJung-uk Kim case PARSEOP_DEVICE:
767f8146b88SJung-uk Kim
768f8146b88SJung-uk Kim /* Level 0 is the starting device, ignore it */
769f8146b88SJung-uk Kim
770f8146b88SJung-uk Kim if (Level > 0)
771f8146b88SJung-uk Kim {
772f8146b88SJung-uk Kim /* Ignore sub-devices */
773f8146b88SJung-uk Kim
774f8146b88SJung-uk Kim return (AE_CTRL_DEPTH);
775f8146b88SJung-uk Kim }
776f8146b88SJung-uk Kim break;
777f8146b88SJung-uk Kim
778f8146b88SJung-uk Kim case PARSEOP_NAME:
779f8146b88SJung-uk Kim case PARSEOP_METHOD:
780f8146b88SJung-uk Kim
781f8146b88SJung-uk Kim /* These are what we are looking for */
782f8146b88SJung-uk Kim
783278f0de6SJung-uk Kim if (ACPI_COMPARE_NAMESEG (Name, Op->Asl.NameSeg))
784f8146b88SJung-uk Kim {
785f8146b88SJung-uk Kim return (AE_CTRL_TRUE);
786f8146b88SJung-uk Kim }
787f8146b88SJung-uk Kim return (AE_CTRL_DEPTH);
788f8146b88SJung-uk Kim
789f8146b88SJung-uk Kim case PARSEOP_SCOPE:
790f8146b88SJung-uk Kim case PARSEOP_FIELD:
791f8146b88SJung-uk Kim case PARSEOP_OPERATIONREGION:
792f8146b88SJung-uk Kim
793f8146b88SJung-uk Kim /*
794f8146b88SJung-uk Kim * We want to ignore these, because either they can be large
795f8146b88SJung-uk Kim * subtrees or open a scope to somewhere else.
796f8146b88SJung-uk Kim */
797f8146b88SJung-uk Kim return (AE_CTRL_DEPTH);
798f8146b88SJung-uk Kim
799f8146b88SJung-uk Kim default:
800f8146b88SJung-uk Kim break;
801f8146b88SJung-uk Kim }
802f8146b88SJung-uk Kim
803f8146b88SJung-uk Kim return (AE_OK);
804f8146b88SJung-uk Kim }
805f8146b88SJung-uk Kim
806f8146b88SJung-uk Kim
807f8146b88SJung-uk Kim /*******************************************************************************
808f8146b88SJung-uk Kim *
809313a0c13SJung-uk Kim * FUNCTION: ApFindNameInScope
810313a0c13SJung-uk Kim *
811313a0c13SJung-uk Kim * PARAMETERS: Name - Name to search for
812313a0c13SJung-uk Kim * Op - Current parse op
813313a0c13SJung-uk Kim *
814313a0c13SJung-uk Kim * RETURN: TRUE if name found in the same scope as Op.
815313a0c13SJung-uk Kim *
816313a0c13SJung-uk Kim * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
817313a0c13SJung-uk Kim * a Method() or a Name().
818313a0c13SJung-uk Kim *
819313a0c13SJung-uk Kim ******************************************************************************/
820313a0c13SJung-uk Kim
821313a0c13SJung-uk Kim BOOLEAN
ApFindNameInScope(char * Name,ACPI_PARSE_OBJECT * Op)822313a0c13SJung-uk Kim ApFindNameInScope (
823313a0c13SJung-uk Kim char *Name,
824313a0c13SJung-uk Kim ACPI_PARSE_OBJECT *Op)
825313a0c13SJung-uk Kim {
826313a0c13SJung-uk Kim ACPI_PARSE_OBJECT *Next;
827313a0c13SJung-uk Kim ACPI_PARSE_OBJECT *Parent;
828313a0c13SJung-uk Kim
829313a0c13SJung-uk Kim
830313a0c13SJung-uk Kim /* Get the start of the current scope */
831313a0c13SJung-uk Kim
832313a0c13SJung-uk Kim Parent = Op->Asl.Parent;
833313a0c13SJung-uk Kim Next = Parent->Asl.Child;
834313a0c13SJung-uk Kim
835313a0c13SJung-uk Kim /* Search entire scope for a match to the name */
836313a0c13SJung-uk Kim
837313a0c13SJung-uk Kim while (Next)
838313a0c13SJung-uk Kim {
839313a0c13SJung-uk Kim if ((Next->Asl.ParseOpcode == PARSEOP_METHOD) ||
840313a0c13SJung-uk Kim (Next->Asl.ParseOpcode == PARSEOP_NAME))
841313a0c13SJung-uk Kim {
842278f0de6SJung-uk Kim if (ACPI_COMPARE_NAMESEG (Name, Next->Asl.NameSeg))
843313a0c13SJung-uk Kim {
844313a0c13SJung-uk Kim return (TRUE);
845313a0c13SJung-uk Kim }
846313a0c13SJung-uk Kim }
847313a0c13SJung-uk Kim
848313a0c13SJung-uk Kim Next = Next->Asl.Next;
849313a0c13SJung-uk Kim }
850313a0c13SJung-uk Kim
851313a0c13SJung-uk Kim return (FALSE);
852313a0c13SJung-uk Kim }
853