xref: /illumos-gate/usr/src/cmd/acpi/iasl/aslxref.c (revision 35786f68)
1bc36eafdSMike Gerdts /******************************************************************************
2bc36eafdSMike Gerdts  *
3bc36eafdSMike Gerdts  * Module Name: aslxref - Namespace cross-reference
4bc36eafdSMike Gerdts  *
5bc36eafdSMike Gerdts  *****************************************************************************/
6bc36eafdSMike Gerdts 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12bc36eafdSMike Gerdts  * All rights reserved.
13bc36eafdSMike Gerdts  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
119bc36eafdSMike Gerdts  * Redistribution and use in source and binary forms, with or without
120bc36eafdSMike Gerdts  * modification, are permitted provided that the following conditions
121bc36eafdSMike Gerdts  * are met:
122bc36eafdSMike Gerdts  * 1. Redistributions of source code must retain the above copyright
123bc36eafdSMike Gerdts  *    notice, this list of conditions, and the following disclaimer,
124bc36eafdSMike Gerdts  *    without modification.
125bc36eafdSMike Gerdts  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126bc36eafdSMike Gerdts  *    substantially similar to the "NO WARRANTY" disclaimer below
127bc36eafdSMike Gerdts  *    ("Disclaimer") and any redistribution must be conditioned upon
128bc36eafdSMike Gerdts  *    including a substantially similar Disclaimer requirement for further
129bc36eafdSMike Gerdts  *    binary redistribution.
130bc36eafdSMike Gerdts  * 3. Neither the names of the above-listed copyright holders nor the names
131bc36eafdSMike Gerdts  *    of any contributors may be used to endorse or promote products derived
132bc36eafdSMike Gerdts  *    from this software without specific prior written permission.
133bc36eafdSMike Gerdts  *
134bc36eafdSMike Gerdts  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135bc36eafdSMike Gerdts  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137bc36eafdSMike Gerdts  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi  * Software Foundation.
149*35786f68SRobert Mustacchi  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
151bc36eafdSMike Gerdts 
152bc36eafdSMike Gerdts #include "aslcompiler.h"
153bc36eafdSMike Gerdts #include "aslcompiler.y.h"
154bc36eafdSMike Gerdts #include "acparser.h"
155bc36eafdSMike Gerdts #include "amlcode.h"
156bc36eafdSMike Gerdts #include "acnamesp.h"
157bc36eafdSMike Gerdts #include "acdispat.h"
158bc36eafdSMike Gerdts 
159bc36eafdSMike Gerdts 
160bc36eafdSMike Gerdts #define _COMPONENT          ACPI_COMPILER
161bc36eafdSMike Gerdts         ACPI_MODULE_NAME    ("aslxref")
162bc36eafdSMike Gerdts 
163bc36eafdSMike Gerdts /* Local prototypes */
164bc36eafdSMike Gerdts 
165bc36eafdSMike Gerdts static ACPI_STATUS
166bc36eafdSMike Gerdts XfNamespaceLocateBegin (
167bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
168bc36eafdSMike Gerdts     UINT32                  Level,
169bc36eafdSMike Gerdts     void                    *Context);
170bc36eafdSMike Gerdts 
171bc36eafdSMike Gerdts static ACPI_STATUS
172bc36eafdSMike Gerdts XfNamespaceLocateEnd (
173bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
174bc36eafdSMike Gerdts     UINT32                  Level,
175bc36eafdSMike Gerdts     void                    *Context);
176bc36eafdSMike Gerdts 
177bc36eafdSMike Gerdts static ACPI_PARSE_OBJECT *
178bc36eafdSMike Gerdts XfGetParentMethod (
179bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op);
180bc36eafdSMike Gerdts 
181bc36eafdSMike Gerdts static BOOLEAN
182bc36eafdSMike Gerdts XfObjectExists (
183bc36eafdSMike Gerdts     char                    *Name);
184bc36eafdSMike Gerdts 
185bc36eafdSMike Gerdts static ACPI_STATUS
186bc36eafdSMike Gerdts XfCompareOneNamespaceObject (
187bc36eafdSMike Gerdts     ACPI_HANDLE             ObjHandle,
188bc36eafdSMike Gerdts     UINT32                  Level,
189bc36eafdSMike Gerdts     void                    *Context,
190bc36eafdSMike Gerdts     void                    **ReturnValue);
191bc36eafdSMike Gerdts 
192bc36eafdSMike Gerdts static void
193bc36eafdSMike Gerdts XfCheckFieldRange (
194bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
195bc36eafdSMike Gerdts     UINT32                  RegionBitLength,
196bc36eafdSMike Gerdts     UINT32                  FieldBitOffset,
197bc36eafdSMike Gerdts     UINT32                  FieldBitLength,
198bc36eafdSMike Gerdts     UINT32                  AccessBitWidth);
199bc36eafdSMike Gerdts 
200bc36eafdSMike Gerdts 
201bc36eafdSMike Gerdts /*******************************************************************************
202bc36eafdSMike Gerdts  *
203bc36eafdSMike Gerdts  * FUNCTION:    XfCrossReferenceNamespace
204bc36eafdSMike Gerdts  *
205bc36eafdSMike Gerdts  * PARAMETERS:  None
206bc36eafdSMike Gerdts  *
207bc36eafdSMike Gerdts  * RETURN:      Status
208bc36eafdSMike Gerdts  *
209bc36eafdSMike Gerdts  * DESCRIPTION: Perform a cross reference check of the parse tree against the
210bc36eafdSMike Gerdts  *              namespace. Every named referenced within the parse tree
211bc36eafdSMike Gerdts  *              should be get resolved with a namespace lookup. If not, the
212bc36eafdSMike Gerdts  *              original reference in the ASL code is invalid -- i.e., refers
213bc36eafdSMike Gerdts  *              to a non-existent object.
214bc36eafdSMike Gerdts  *
215bc36eafdSMike Gerdts  * NOTE:  The ASL "External" operator causes the name to be inserted into the
216bc36eafdSMike Gerdts  *        namespace so that references to the external name will be resolved
217bc36eafdSMike Gerdts  *        correctly here.
218bc36eafdSMike Gerdts  *
219bc36eafdSMike Gerdts  ******************************************************************************/
220bc36eafdSMike Gerdts 
221bc36eafdSMike Gerdts ACPI_STATUS
XfCrossReferenceNamespace(void)222bc36eafdSMike Gerdts XfCrossReferenceNamespace (
223bc36eafdSMike Gerdts     void)
224bc36eafdSMike Gerdts {
225bc36eafdSMike Gerdts     ACPI_WALK_STATE         *WalkState;
226bc36eafdSMike Gerdts 
227bc36eafdSMike Gerdts 
228bc36eafdSMike Gerdts     /*
229bc36eafdSMike Gerdts      * Create a new walk state for use when looking up names
230bc36eafdSMike Gerdts      * within the namespace (Passed as context to the callbacks)
231bc36eafdSMike Gerdts      */
232bc36eafdSMike Gerdts     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
233bc36eafdSMike Gerdts     if (!WalkState)
234bc36eafdSMike Gerdts     {
235bc36eafdSMike Gerdts         return (AE_NO_MEMORY);
236bc36eafdSMike Gerdts     }
237bc36eafdSMike Gerdts 
238bc36eafdSMike Gerdts     /* Walk the entire parse tree */
239bc36eafdSMike Gerdts 
240bc36eafdSMike Gerdts     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
241bc36eafdSMike Gerdts         XfNamespaceLocateBegin, XfNamespaceLocateEnd, WalkState);
242bc36eafdSMike Gerdts 
243bc36eafdSMike Gerdts     ACPI_FREE (WalkState);
244bc36eafdSMike Gerdts     return (AE_OK);
245bc36eafdSMike Gerdts }
246bc36eafdSMike Gerdts 
247bc36eafdSMike Gerdts 
248bc36eafdSMike Gerdts /*******************************************************************************
249bc36eafdSMike Gerdts  *
250bc36eafdSMike Gerdts  * FUNCTION:    XfObjectExists
251bc36eafdSMike Gerdts  *
252bc36eafdSMike Gerdts  * PARAMETERS:  Name            - 4 char ACPI name
253bc36eafdSMike Gerdts  *
254bc36eafdSMike Gerdts  * RETURN:      TRUE if name exists in namespace
255bc36eafdSMike Gerdts  *
256bc36eafdSMike Gerdts  * DESCRIPTION: Walk the namespace to find an object
257bc36eafdSMike Gerdts  *
258bc36eafdSMike Gerdts  ******************************************************************************/
259bc36eafdSMike Gerdts 
260bc36eafdSMike Gerdts static BOOLEAN
XfObjectExists(char * Name)261bc36eafdSMike Gerdts XfObjectExists (
262bc36eafdSMike Gerdts     char                    *Name)
263bc36eafdSMike Gerdts {
264bc36eafdSMike Gerdts     ACPI_STATUS             Status;
265bc36eafdSMike Gerdts 
266bc36eafdSMike Gerdts 
267bc36eafdSMike Gerdts     /* Walk entire namespace from the supplied root */
268bc36eafdSMike Gerdts 
269bc36eafdSMike Gerdts     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
270bc36eafdSMike Gerdts         ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL,
271bc36eafdSMike Gerdts         Name, NULL);
272bc36eafdSMike Gerdts     if (Status == AE_CTRL_TRUE)
273bc36eafdSMike Gerdts     {
274bc36eafdSMike Gerdts         /* At least one instance of the name was found */
275bc36eafdSMike Gerdts 
276bc36eafdSMike Gerdts         return (TRUE);
277bc36eafdSMike Gerdts     }
278bc36eafdSMike Gerdts 
279bc36eafdSMike Gerdts     return (FALSE);
280bc36eafdSMike Gerdts }
281bc36eafdSMike Gerdts 
282bc36eafdSMike Gerdts 
283bc36eafdSMike Gerdts /*******************************************************************************
284bc36eafdSMike Gerdts  *
285bc36eafdSMike Gerdts  * FUNCTION:    XfCompareOneNamespaceObject
286bc36eafdSMike Gerdts  *
287bc36eafdSMike Gerdts  * PARAMETERS:  ACPI_WALK_CALLBACK
288bc36eafdSMike Gerdts  *
289bc36eafdSMike Gerdts  * RETURN:      Status
290bc36eafdSMike Gerdts  *
291bc36eafdSMike Gerdts  * DESCRIPTION: Compare name of one object.
292bc36eafdSMike Gerdts  *
293bc36eafdSMike Gerdts  ******************************************************************************/
294bc36eafdSMike Gerdts 
295bc36eafdSMike Gerdts static ACPI_STATUS
XfCompareOneNamespaceObject(ACPI_HANDLE ObjHandle,UINT32 Level,void * Context,void ** ReturnValue)296bc36eafdSMike Gerdts XfCompareOneNamespaceObject (
297bc36eafdSMike Gerdts     ACPI_HANDLE             ObjHandle,
298bc36eafdSMike Gerdts     UINT32                  Level,
299bc36eafdSMike Gerdts     void                    *Context,
300bc36eafdSMike Gerdts     void                    **ReturnValue)
301bc36eafdSMike Gerdts {
302bc36eafdSMike Gerdts     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
303bc36eafdSMike Gerdts 
304bc36eafdSMike Gerdts 
305bc36eafdSMike Gerdts     /* Simply check the name */
306bc36eafdSMike Gerdts 
307bc36eafdSMike Gerdts     if (*((UINT32 *) (Context)) == Node->Name.Integer)
308bc36eafdSMike Gerdts     {
309bc36eafdSMike Gerdts         /* Abort walk if we found one instance */
310bc36eafdSMike Gerdts 
311bc36eafdSMike Gerdts         return (AE_CTRL_TRUE);
312bc36eafdSMike Gerdts     }
313bc36eafdSMike Gerdts 
314bc36eafdSMike Gerdts     return (AE_OK);
315bc36eafdSMike Gerdts }
316bc36eafdSMike Gerdts 
317bc36eafdSMike Gerdts 
318bc36eafdSMike Gerdts /*******************************************************************************
319bc36eafdSMike Gerdts  *
320bc36eafdSMike Gerdts  * FUNCTION:    XfCheckFieldRange
321bc36eafdSMike Gerdts  *
322bc36eafdSMike Gerdts  * PARAMETERS:  RegionBitLength     - Length of entire parent region
323bc36eafdSMike Gerdts  *              FieldBitOffset      - Start of the field unit (within region)
324bc36eafdSMike Gerdts  *              FieldBitLength      - Entire length of field unit
325bc36eafdSMike Gerdts  *              AccessBitWidth      - Access width of the field unit
326bc36eafdSMike Gerdts  *
327bc36eafdSMike Gerdts  * RETURN:      None
328bc36eafdSMike Gerdts  *
329bc36eafdSMike Gerdts  * DESCRIPTION: Check one field unit to make sure it fits in the parent
330bc36eafdSMike Gerdts  *              op region.
331bc36eafdSMike Gerdts  *
332bc36eafdSMike Gerdts  * Note: AccessBitWidth must be either 8,16,32, or 64
333bc36eafdSMike Gerdts  *
334bc36eafdSMike Gerdts  ******************************************************************************/
335bc36eafdSMike Gerdts 
336bc36eafdSMike Gerdts static void
XfCheckFieldRange(ACPI_PARSE_OBJECT * Op,UINT32 RegionBitLength,UINT32 FieldBitOffset,UINT32 FieldBitLength,UINT32 AccessBitWidth)337bc36eafdSMike Gerdts XfCheckFieldRange (
338bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
339bc36eafdSMike Gerdts     UINT32                  RegionBitLength,
340bc36eafdSMike Gerdts     UINT32                  FieldBitOffset,
341bc36eafdSMike Gerdts     UINT32                  FieldBitLength,
342bc36eafdSMike Gerdts     UINT32                  AccessBitWidth)
343bc36eafdSMike Gerdts {
344bc36eafdSMike Gerdts     UINT32                  FieldEndBitOffset;
345bc36eafdSMike Gerdts 
346bc36eafdSMike Gerdts 
347bc36eafdSMike Gerdts     /*
348bc36eafdSMike Gerdts      * Check each field unit against the region size. The entire
349bc36eafdSMike Gerdts      * field unit (start offset plus length) must fit within the
350bc36eafdSMike Gerdts      * region.
351bc36eafdSMike Gerdts      */
352bc36eafdSMike Gerdts     FieldEndBitOffset = FieldBitOffset + FieldBitLength;
353bc36eafdSMike Gerdts 
354bc36eafdSMike Gerdts     if (FieldEndBitOffset > RegionBitLength)
355bc36eafdSMike Gerdts     {
356bc36eafdSMike Gerdts         /* Field definition itself is beyond the end-of-region */
357bc36eafdSMike Gerdts 
358bc36eafdSMike Gerdts         AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
359bc36eafdSMike Gerdts         return;
360bc36eafdSMike Gerdts     }
361bc36eafdSMike Gerdts 
362bc36eafdSMike Gerdts     /*
363bc36eafdSMike Gerdts      * Now check that the field plus AccessWidth doesn't go beyond
364bc36eafdSMike Gerdts      * the end-of-region. Assumes AccessBitWidth is a power of 2
365bc36eafdSMike Gerdts      */
366bc36eafdSMike Gerdts     FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
367bc36eafdSMike Gerdts 
368bc36eafdSMike Gerdts     if (FieldEndBitOffset > RegionBitLength)
369bc36eafdSMike Gerdts     {
370bc36eafdSMike Gerdts         /* Field definition combined with the access is beyond EOR */
371bc36eafdSMike Gerdts 
372bc36eafdSMike Gerdts         AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
373bc36eafdSMike Gerdts     }
374bc36eafdSMike Gerdts }
375bc36eafdSMike Gerdts 
376bc36eafdSMike Gerdts 
377bc36eafdSMike Gerdts /*******************************************************************************
378bc36eafdSMike Gerdts  *
379bc36eafdSMike Gerdts  * FUNCTION:    XfGetParentMethod
380bc36eafdSMike Gerdts  *
381bc36eafdSMike Gerdts  * PARAMETERS:  Op                      - Parse Op to be checked
382bc36eafdSMike Gerdts  *
383bc36eafdSMike Gerdts  * RETURN:      Control method Op if found. NULL otherwise
384bc36eafdSMike Gerdts  *
385bc36eafdSMike Gerdts  * DESCRIPTION: Find the control method parent of a parse op. Returns NULL if
386bc36eafdSMike Gerdts  *              the input Op is not within a control method.
387bc36eafdSMike Gerdts  *
388bc36eafdSMike Gerdts  ******************************************************************************/
389bc36eafdSMike Gerdts 
390bc36eafdSMike Gerdts static ACPI_PARSE_OBJECT *
XfGetParentMethod(ACPI_PARSE_OBJECT * Op)391bc36eafdSMike Gerdts XfGetParentMethod (
392bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op)
393bc36eafdSMike Gerdts {
394bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *NextOp;
395bc36eafdSMike Gerdts 
396bc36eafdSMike Gerdts 
397bc36eafdSMike Gerdts     NextOp = Op->Asl.Parent;
398bc36eafdSMike Gerdts     while (NextOp)
399bc36eafdSMike Gerdts     {
400bc36eafdSMike Gerdts         if (NextOp->Asl.AmlOpcode == AML_METHOD_OP)
401bc36eafdSMike Gerdts         {
402bc36eafdSMike Gerdts             return (NextOp);
403bc36eafdSMike Gerdts         }
404bc36eafdSMike Gerdts 
405bc36eafdSMike Gerdts         NextOp = NextOp->Asl.Parent;
406bc36eafdSMike Gerdts     }
407bc36eafdSMike Gerdts 
408bc36eafdSMike Gerdts     return (NULL); /* No parent method found */
409bc36eafdSMike Gerdts }
410bc36eafdSMike Gerdts 
411bc36eafdSMike Gerdts /*******************************************************************************
412bc36eafdSMike Gerdts  *
413bc36eafdSMike Gerdts  * FUNCTION:    XfNamespaceLocateBegin
414bc36eafdSMike Gerdts  *
415bc36eafdSMike Gerdts  * PARAMETERS:  ASL_WALK_CALLBACK
416bc36eafdSMike Gerdts  *
417bc36eafdSMike Gerdts  * RETURN:      Status
418bc36eafdSMike Gerdts  *
419bc36eafdSMike Gerdts  * DESCRIPTION: Descending callback used during cross-reference. For named
420bc36eafdSMike Gerdts  *              object references, attempt to locate the name in the
421bc36eafdSMike Gerdts  *              namespace.
422bc36eafdSMike Gerdts  *
423bc36eafdSMike Gerdts  * NOTE: ASL references to named fields within resource descriptors are
424bc36eafdSMike Gerdts  *       resolved to integer values here. Therefore, this step is an
425bc36eafdSMike Gerdts  *       important part of the code generation. We don't know that the
426bc36eafdSMike Gerdts  *       name refers to a resource descriptor until now.
427bc36eafdSMike Gerdts  *
428bc36eafdSMike Gerdts  ******************************************************************************/
429bc36eafdSMike Gerdts 
430bc36eafdSMike Gerdts static ACPI_STATUS
XfNamespaceLocateBegin(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)431bc36eafdSMike Gerdts XfNamespaceLocateBegin (
432bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
433bc36eafdSMike Gerdts     UINT32                  Level,
434bc36eafdSMike Gerdts     void                    *Context)
435bc36eafdSMike Gerdts {
436bc36eafdSMike Gerdts     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
437bc36eafdSMike Gerdts     ACPI_NAMESPACE_NODE     *Node;
438bc36eafdSMike Gerdts     ACPI_STATUS             Status;
439bc36eafdSMike Gerdts     ACPI_OBJECT_TYPE        ObjectType;
440bc36eafdSMike Gerdts     char                    *Path;
441bc36eafdSMike Gerdts     UINT8                   PassedArgs;
442bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *NextOp;
443bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *OwningOp;
444bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *SpaceIdOp;
445bc36eafdSMike Gerdts     UINT32                  MinimumLength;
446bc36eafdSMike Gerdts     UINT32                  Offset;
447bc36eafdSMike Gerdts     UINT32                  FieldBitLength;
448bc36eafdSMike Gerdts     UINT32                  TagBitLength;
449bc36eafdSMike Gerdts     UINT8                   Message = 0;
450bc36eafdSMike Gerdts     const ACPI_OPCODE_INFO  *OpInfo;
451bc36eafdSMike Gerdts     UINT32                  Flags;
452bc36eafdSMike Gerdts     ASL_METHOD_LOCAL        *MethodLocals = NULL;
453bc36eafdSMike Gerdts     ASL_METHOD_LOCAL        *MethodArgs = NULL;
454bc36eafdSMike Gerdts     int                     RegisterNumber;
455bc36eafdSMike Gerdts     UINT32                  i;
456bc36eafdSMike Gerdts 
457bc36eafdSMike Gerdts 
458bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
459bc36eafdSMike Gerdts 
460bc36eafdSMike Gerdts 
461bc36eafdSMike Gerdts     if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node)
462bc36eafdSMike Gerdts     {
463bc36eafdSMike Gerdts         Node = Op->Asl.Node;
464bc36eafdSMike Gerdts 
465bc36eafdSMike Gerdts         /* Support for method LocalX/ArgX analysis */
466bc36eafdSMike Gerdts 
467bc36eafdSMike Gerdts         if (!Node->MethodLocals)
468bc36eafdSMike Gerdts         {
469bc36eafdSMike Gerdts             /* Create local/arg info blocks */
470bc36eafdSMike Gerdts 
471bc36eafdSMike Gerdts             MethodLocals = UtLocalCalloc (
472bc36eafdSMike Gerdts                 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS);
473bc36eafdSMike Gerdts             Node->MethodLocals = MethodLocals;
474bc36eafdSMike Gerdts 
475bc36eafdSMike Gerdts             MethodArgs = UtLocalCalloc (
476bc36eafdSMike Gerdts                 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS);
477bc36eafdSMike Gerdts             Node->MethodArgs = MethodArgs;
478bc36eafdSMike Gerdts 
479bc36eafdSMike Gerdts             /*
480bc36eafdSMike Gerdts              * Get the method argument count
481bc36eafdSMike Gerdts              * First, get the name node
482bc36eafdSMike Gerdts              */
483bc36eafdSMike Gerdts             NextOp = Op->Asl.Child;
484bc36eafdSMike Gerdts 
485bc36eafdSMike Gerdts             /* Get the NumArguments node */
486bc36eafdSMike Gerdts 
487bc36eafdSMike Gerdts             NextOp = NextOp->Asl.Next;
488bc36eafdSMike Gerdts             Node->ArgCount = (UINT8)
489bc36eafdSMike Gerdts                 (((UINT8) NextOp->Asl.Value.Integer) & 0x07);
490bc36eafdSMike Gerdts 
491bc36eafdSMike Gerdts             /* We will track all posible ArgXs */
492bc36eafdSMike Gerdts 
493bc36eafdSMike Gerdts             for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
494bc36eafdSMike Gerdts             {
495bc36eafdSMike Gerdts                 if (i < Node->ArgCount)
496bc36eafdSMike Gerdts                 {
497bc36eafdSMike Gerdts                     /* Real Args are always "initialized" */
498bc36eafdSMike Gerdts 
499bc36eafdSMike Gerdts                     MethodArgs[i].Flags = ASL_ARG_INITIALIZED;
500bc36eafdSMike Gerdts                 }
501bc36eafdSMike Gerdts                 else
502bc36eafdSMike Gerdts                 {
503bc36eafdSMike Gerdts                     /* Other ArgXs can be used as locals */
504bc36eafdSMike Gerdts 
505bc36eafdSMike Gerdts                     MethodArgs[i].Flags = ASL_ARG_IS_LOCAL;
506bc36eafdSMike Gerdts                 }
507bc36eafdSMike Gerdts 
508bc36eafdSMike Gerdts                 MethodArgs[i].Op = Op;
509bc36eafdSMike Gerdts             }
510bc36eafdSMike Gerdts         }
511bc36eafdSMike Gerdts     }
512bc36eafdSMike Gerdts 
513bc36eafdSMike Gerdts     /*
514bc36eafdSMike Gerdts      * If this node is the actual declaration of a name
515bc36eafdSMike Gerdts      * [such as the XXXX name in "Method (XXXX)"],
516bc36eafdSMike Gerdts      * we are not interested in it here. We only care about names that are
517bc36eafdSMike Gerdts      * references to other objects within the namespace and the parent objects
518bc36eafdSMike Gerdts      * of name declarations
519bc36eafdSMike Gerdts      */
520*35786f68SRobert Mustacchi     if (Op->Asl.CompileFlags & OP_IS_NAME_DECLARATION)
521bc36eafdSMike Gerdts     {
522bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_OK);
523bc36eafdSMike Gerdts     }
524bc36eafdSMike Gerdts 
525bc36eafdSMike Gerdts     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
526bc36eafdSMike Gerdts 
527bc36eafdSMike Gerdts     /* Check method LocalX variables */
528bc36eafdSMike Gerdts 
529bc36eafdSMike Gerdts     if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE)
530bc36eafdSMike Gerdts     {
531bc36eafdSMike Gerdts         /* Find parent method Op */
532bc36eafdSMike Gerdts 
533bc36eafdSMike Gerdts         NextOp = XfGetParentMethod (Op);
534bc36eafdSMike Gerdts         if (!NextOp)
535bc36eafdSMike Gerdts         {
536bc36eafdSMike Gerdts             return_ACPI_STATUS (AE_OK);
537bc36eafdSMike Gerdts         }
538bc36eafdSMike Gerdts 
539bc36eafdSMike Gerdts         /* Get method node */
540bc36eafdSMike Gerdts 
541bc36eafdSMike Gerdts         Node = NextOp->Asl.Node;
542bc36eafdSMike Gerdts 
543bc36eafdSMike Gerdts         RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */
544bc36eafdSMike Gerdts         MethodLocals = Node->MethodLocals;
545bc36eafdSMike Gerdts 
546*35786f68SRobert Mustacchi         if (Op->Asl.CompileFlags & OP_IS_TARGET)
547bc36eafdSMike Gerdts         {
548bc36eafdSMike Gerdts             /* Local is being initialized */
549bc36eafdSMike Gerdts 
550bc36eafdSMike Gerdts             MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED;
551bc36eafdSMike Gerdts             MethodLocals[RegisterNumber].Op = Op;
552bc36eafdSMike Gerdts 
553bc36eafdSMike Gerdts             return_ACPI_STATUS (AE_OK);
554bc36eafdSMike Gerdts         }
555bc36eafdSMike Gerdts 
556bc36eafdSMike Gerdts         /* Mark this Local as referenced */
557bc36eafdSMike Gerdts 
558bc36eafdSMike Gerdts         MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED;
559bc36eafdSMike Gerdts         MethodLocals[RegisterNumber].Op = Op;
560bc36eafdSMike Gerdts 
561bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_OK);
562bc36eafdSMike Gerdts     }
563bc36eafdSMike Gerdts 
564bc36eafdSMike Gerdts     /* Check method ArgX variables */
565bc36eafdSMike Gerdts 
566bc36eafdSMike Gerdts     if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT)
567bc36eafdSMike Gerdts     {
568bc36eafdSMike Gerdts         /* Find parent method Op */
569bc36eafdSMike Gerdts 
570bc36eafdSMike Gerdts         NextOp = XfGetParentMethod (Op);
571bc36eafdSMike Gerdts         if (!NextOp)
572bc36eafdSMike Gerdts         {
573bc36eafdSMike Gerdts             return_ACPI_STATUS (AE_OK);
574bc36eafdSMike Gerdts         }
575bc36eafdSMike Gerdts 
576bc36eafdSMike Gerdts         /* Get method node */
577bc36eafdSMike Gerdts 
578bc36eafdSMike Gerdts         Node = NextOp->Asl.Node;
579bc36eafdSMike Gerdts 
580bc36eafdSMike Gerdts         /* Get Arg # */
581bc36eafdSMike Gerdts 
582bc36eafdSMike Gerdts         RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */
583bc36eafdSMike Gerdts         MethodArgs = Node->MethodArgs;
584bc36eafdSMike Gerdts 
585*35786f68SRobert Mustacchi         /* Mark this Arg as referenced */
586*35786f68SRobert Mustacchi 
587*35786f68SRobert Mustacchi         MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED;
588*35786f68SRobert Mustacchi         MethodArgs[RegisterNumber].Op = Op;
589*35786f68SRobert Mustacchi 
590*35786f68SRobert Mustacchi         if (Op->Asl.CompileFlags & OP_IS_TARGET)
591bc36eafdSMike Gerdts         {
592bc36eafdSMike Gerdts             /* Arg is being initialized */
593bc36eafdSMike Gerdts 
594bc36eafdSMike Gerdts             MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED;
595bc36eafdSMike Gerdts         }
596bc36eafdSMike Gerdts 
597bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_OK);
598bc36eafdSMike Gerdts     }
599bc36eafdSMike Gerdts 
600bc36eafdSMike Gerdts     /*
601bc36eafdSMike Gerdts      * After method ArgX and LocalX, we are only interested in opcodes
602bc36eafdSMike Gerdts      * that have an associated name
603bc36eafdSMike Gerdts      */
604bc36eafdSMike Gerdts     if ((!(OpInfo->Flags & AML_NAMED)) &&
605bc36eafdSMike Gerdts         (!(OpInfo->Flags & AML_CREATE)) &&
606bc36eafdSMike Gerdts         (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
607bc36eafdSMike Gerdts         (Op->Asl.ParseOpcode != PARSEOP_NAMESEG)    &&
608*35786f68SRobert Mustacchi         (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
609*35786f68SRobert Mustacchi         (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
610bc36eafdSMike Gerdts     {
611bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_OK);
612bc36eafdSMike Gerdts     }
613bc36eafdSMike Gerdts 
614bc36eafdSMike Gerdts     /*
615bc36eafdSMike Gerdts      * One special case: CondRefOf operator - we don't care if the name exists
616bc36eafdSMike Gerdts      * or not at this point, just ignore it, the point of the operator is to
617bc36eafdSMike Gerdts      * determine if the name exists at runtime.
618bc36eafdSMike Gerdts      */
619bc36eafdSMike Gerdts     if ((Op->Asl.Parent) &&
620bc36eafdSMike Gerdts         (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
621bc36eafdSMike Gerdts     {
622bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_OK);
623bc36eafdSMike Gerdts     }
624bc36eafdSMike Gerdts 
625bc36eafdSMike Gerdts     /*
626bc36eafdSMike Gerdts      * We must enable the "search-to-root" for single NameSegs, but
627bc36eafdSMike Gerdts      * we have to be very careful about opening up scopes
628bc36eafdSMike Gerdts      */
629bc36eafdSMike Gerdts     Flags = ACPI_NS_SEARCH_PARENT;
630bc36eafdSMike Gerdts     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
631bc36eafdSMike Gerdts         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
632*35786f68SRobert Mustacchi         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
633*35786f68SRobert Mustacchi         (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
634bc36eafdSMike Gerdts     {
635bc36eafdSMike Gerdts         /*
636bc36eafdSMike Gerdts          * These are name references, do not push the scope stack
637bc36eafdSMike Gerdts          * for them.
638bc36eafdSMike Gerdts          */
639bc36eafdSMike Gerdts         Flags |= ACPI_NS_DONT_OPEN_SCOPE;
640bc36eafdSMike Gerdts     }
641bc36eafdSMike Gerdts 
642bc36eafdSMike Gerdts     /* Get the NamePath from the appropriate place */
643bc36eafdSMike Gerdts 
644bc36eafdSMike Gerdts     if (OpInfo->Flags & AML_NAMED)
645bc36eafdSMike Gerdts     {
646bc36eafdSMike Gerdts         /* For nearly all NAMED operators, the name reference is the first child */
647bc36eafdSMike Gerdts 
648bc36eafdSMike Gerdts         Path = Op->Asl.Child->Asl.Value.String;
649bc36eafdSMike Gerdts         if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
650bc36eafdSMike Gerdts         {
651bc36eafdSMike Gerdts             /*
652bc36eafdSMike Gerdts              * ALIAS is the only oddball opcode, the name declaration
653bc36eafdSMike Gerdts              * (alias name) is the second operand
654bc36eafdSMike Gerdts              */
655bc36eafdSMike Gerdts             Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
656bc36eafdSMike Gerdts         }
657bc36eafdSMike Gerdts     }
658bc36eafdSMike Gerdts     else if (OpInfo->Flags & AML_CREATE)
659bc36eafdSMike Gerdts     {
660bc36eafdSMike Gerdts         /* Name must appear as the last parameter */
661bc36eafdSMike Gerdts 
662bc36eafdSMike Gerdts         NextOp = Op->Asl.Child;
663*35786f68SRobert Mustacchi         while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
664bc36eafdSMike Gerdts         {
665bc36eafdSMike Gerdts             NextOp = NextOp->Asl.Next;
666bc36eafdSMike Gerdts         }
667bc36eafdSMike Gerdts 
668bc36eafdSMike Gerdts         Path = NextOp->Asl.Value.String;
669bc36eafdSMike Gerdts     }
670bc36eafdSMike Gerdts     else
671bc36eafdSMike Gerdts     {
672bc36eafdSMike Gerdts         Path = Op->Asl.Value.String;
673bc36eafdSMike Gerdts     }
674bc36eafdSMike Gerdts 
675bc36eafdSMike Gerdts     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
676bc36eafdSMike Gerdts     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
677bc36eafdSMike Gerdts         "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
678bc36eafdSMike Gerdts 
679bc36eafdSMike Gerdts     /*
680bc36eafdSMike Gerdts      * Lookup the name in the namespace. Name must exist at this point, or it
681bc36eafdSMike Gerdts      * is an invalid reference.
682bc36eafdSMike Gerdts      *
683bc36eafdSMike Gerdts      * The namespace is also used as a lookup table for references to resource
684bc36eafdSMike Gerdts      * descriptors and the fields within them.
685bc36eafdSMike Gerdts      */
686bc36eafdSMike Gerdts     Gbl_NsLookupCount++;
687bc36eafdSMike Gerdts 
688bc36eafdSMike Gerdts     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
689*35786f68SRobert Mustacchi         ACPI_IMODE_EXECUTE, Flags, WalkState, &Node);
690bc36eafdSMike Gerdts     if (ACPI_FAILURE (Status))
691bc36eafdSMike Gerdts     {
692bc36eafdSMike Gerdts         if (Status == AE_NOT_FOUND)
693bc36eafdSMike Gerdts         {
694bc36eafdSMike Gerdts             /*
695bc36eafdSMike Gerdts              * We didn't find the name reference by path -- we can qualify this
696bc36eafdSMike Gerdts              * a little better before we print an error message
697bc36eafdSMike Gerdts              */
698bc36eafdSMike Gerdts             if (strlen (Path) == ACPI_NAME_SIZE)
699bc36eafdSMike Gerdts             {
700bc36eafdSMike Gerdts                 /* A simple, one-segment ACPI name */
701bc36eafdSMike Gerdts 
702bc36eafdSMike Gerdts                 if (XfObjectExists (Path))
703bc36eafdSMike Gerdts                 {
704bc36eafdSMike Gerdts                     /*
705bc36eafdSMike Gerdts                      * There exists such a name, but we couldn't get to it
706bc36eafdSMike Gerdts                      * from this scope
707bc36eafdSMike Gerdts                      */
708bc36eafdSMike Gerdts                     AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
709bc36eafdSMike Gerdts                         Op->Asl.ExternalName);
710bc36eafdSMike Gerdts                 }
711bc36eafdSMike Gerdts                 else
712bc36eafdSMike Gerdts                 {
713bc36eafdSMike Gerdts                     /* The name doesn't exist, period */
714bc36eafdSMike Gerdts 
715bc36eafdSMike Gerdts                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
716bc36eafdSMike Gerdts                         Op, Op->Asl.ExternalName);
717bc36eafdSMike Gerdts                 }
718bc36eafdSMike Gerdts             }
719bc36eafdSMike Gerdts             else
720bc36eafdSMike Gerdts             {
721bc36eafdSMike Gerdts                 /* Check for a fully qualified path */
722bc36eafdSMike Gerdts 
723bc36eafdSMike Gerdts                 if (Path[0] == AML_ROOT_PREFIX)
724bc36eafdSMike Gerdts                 {
725bc36eafdSMike Gerdts                     /* Gave full path, the object does not exist */
726bc36eafdSMike Gerdts 
727bc36eafdSMike Gerdts                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
728bc36eafdSMike Gerdts                         Op->Asl.ExternalName);
729bc36eafdSMike Gerdts                 }
730bc36eafdSMike Gerdts                 else
731bc36eafdSMike Gerdts                 {
732bc36eafdSMike Gerdts                     /*
733bc36eafdSMike Gerdts                      * We can't tell whether it doesn't exist or just
734bc36eafdSMike Gerdts                      * can't be reached.
735bc36eafdSMike Gerdts                      */
736bc36eafdSMike Gerdts                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
737bc36eafdSMike Gerdts                         Op->Asl.ExternalName);
738bc36eafdSMike Gerdts                 }
739bc36eafdSMike Gerdts             }
740bc36eafdSMike Gerdts 
741bc36eafdSMike Gerdts             Status = AE_OK;
742bc36eafdSMike Gerdts         }
743bc36eafdSMike Gerdts 
744bc36eafdSMike Gerdts         return_ACPI_STATUS (Status);
745bc36eafdSMike Gerdts     }
746bc36eafdSMike Gerdts 
747*35786f68SRobert Mustacchi     /* Object was found above, check for an illegal forward reference */
748*35786f68SRobert Mustacchi 
749*35786f68SRobert Mustacchi     if (Op->Asl.CompileFlags & OP_NOT_FOUND_DURING_LOAD)
750*35786f68SRobert Mustacchi     {
751*35786f68SRobert Mustacchi         /*
752*35786f68SRobert Mustacchi          * During the load phase, this Op was flagged as a possible
753*35786f68SRobert Mustacchi          * illegal forward reference
754*35786f68SRobert Mustacchi          *
755*35786f68SRobert Mustacchi          * Note: Allow "forward references" from within a method to an
756*35786f68SRobert Mustacchi          * object that is not within any method (module-level code)
757*35786f68SRobert Mustacchi          */
758*35786f68SRobert Mustacchi         if (!WalkState->ScopeInfo || (UtGetParentMethod (Node) &&
759*35786f68SRobert Mustacchi             !UtNodeIsDescendantOf (WalkState->ScopeInfo->Scope.Node,
760*35786f68SRobert Mustacchi                 UtGetParentMethod (Node))))
761*35786f68SRobert Mustacchi         {
762*35786f68SRobert Mustacchi             AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
763*35786f68SRobert Mustacchi                 Op->Asl.ExternalName);
764*35786f68SRobert Mustacchi         }
765*35786f68SRobert Mustacchi     }
766*35786f68SRobert Mustacchi 
767bc36eafdSMike Gerdts     /* Check for a reference vs. name declaration */
768bc36eafdSMike Gerdts 
769bc36eafdSMike Gerdts     if (!(OpInfo->Flags & AML_NAMED) &&
770bc36eafdSMike Gerdts         !(OpInfo->Flags & AML_CREATE))
771bc36eafdSMike Gerdts     {
772bc36eafdSMike Gerdts         /* This node has been referenced, mark it for reference check */
773bc36eafdSMike Gerdts 
774bc36eafdSMike Gerdts         Node->Flags |= ANOBJ_IS_REFERENCED;
775bc36eafdSMike Gerdts     }
776bc36eafdSMike Gerdts 
777bc36eafdSMike Gerdts     /* Attempt to optimize the NamePath */
778bc36eafdSMike Gerdts 
779bc36eafdSMike Gerdts     OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
780bc36eafdSMike Gerdts 
781bc36eafdSMike Gerdts     /*
782bc36eafdSMike Gerdts      * 1) Dereference an alias (A name reference that is an alias)
783bc36eafdSMike Gerdts      *    Aliases are not nested, the alias always points to the final object
784bc36eafdSMike Gerdts      */
785bc36eafdSMike Gerdts     if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
786bc36eafdSMike Gerdts         (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
787bc36eafdSMike Gerdts     {
788bc36eafdSMike Gerdts         /* This node points back to the original PARSEOP_ALIAS */
789bc36eafdSMike Gerdts 
790bc36eafdSMike Gerdts         NextOp = Node->Op;
791bc36eafdSMike Gerdts 
792bc36eafdSMike Gerdts         /* The first child is the alias target op */
793bc36eafdSMike Gerdts 
794bc36eafdSMike Gerdts         NextOp = NextOp->Asl.Child;
795bc36eafdSMike Gerdts 
796bc36eafdSMike Gerdts         /* That in turn points back to original target alias node */
797bc36eafdSMike Gerdts 
798bc36eafdSMike Gerdts         if (NextOp->Asl.Node)
799bc36eafdSMike Gerdts         {
800bc36eafdSMike Gerdts             Node = NextOp->Asl.Node;
801bc36eafdSMike Gerdts         }
802bc36eafdSMike Gerdts 
803bc36eafdSMike Gerdts         /* Else - forward reference to alias, will be resolved later */
804bc36eafdSMike Gerdts     }
805bc36eafdSMike Gerdts 
806bc36eafdSMike Gerdts     /* 2) Check for a reference to a resource descriptor */
807bc36eafdSMike Gerdts 
808bc36eafdSMike Gerdts     if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
809bc36eafdSMike Gerdts         (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
810bc36eafdSMike Gerdts     {
811bc36eafdSMike Gerdts         /*
812bc36eafdSMike Gerdts          * This was a reference to a field within a resource descriptor.
813bc36eafdSMike Gerdts          * Extract the associated field offset (either a bit or byte
814bc36eafdSMike Gerdts          * offset depending on the field type) and change the named
815bc36eafdSMike Gerdts          * reference into an integer for AML code generation
816bc36eafdSMike Gerdts          */
817bc36eafdSMike Gerdts         Offset = Node->Value;
818bc36eafdSMike Gerdts         TagBitLength = Node->Length;
819bc36eafdSMike Gerdts 
820bc36eafdSMike Gerdts         /*
821bc36eafdSMike Gerdts          * If a field is being created, generate the length (in bits) of
822bc36eafdSMike Gerdts          * the field. Note: Opcodes other than CreateXxxField and Index
823bc36eafdSMike Gerdts          * can come through here. For other opcodes, we just need to
824bc36eafdSMike Gerdts          * convert the resource tag reference to an integer offset.
825bc36eafdSMike Gerdts          */
826bc36eafdSMike Gerdts         switch (Op->Asl.Parent->Asl.AmlOpcode)
827bc36eafdSMike Gerdts         {
828bc36eafdSMike Gerdts         case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
829bc36eafdSMike Gerdts             /*
830bc36eafdSMike Gerdts              * We know the length operand is an integer constant because
831bc36eafdSMike Gerdts              * we know that it contains a reference to a resource
832bc36eafdSMike Gerdts              * descriptor tag.
833bc36eafdSMike Gerdts              */
834bc36eafdSMike Gerdts             FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
835bc36eafdSMike Gerdts             break;
836bc36eafdSMike Gerdts 
837bc36eafdSMike Gerdts         case AML_CREATE_BIT_FIELD_OP:
838bc36eafdSMike Gerdts 
839bc36eafdSMike Gerdts             FieldBitLength = 1;
840bc36eafdSMike Gerdts             break;
841bc36eafdSMike Gerdts 
842bc36eafdSMike Gerdts         case AML_CREATE_BYTE_FIELD_OP:
843bc36eafdSMike Gerdts         case AML_INDEX_OP:
844bc36eafdSMike Gerdts 
845bc36eafdSMike Gerdts             FieldBitLength = 8;
846bc36eafdSMike Gerdts             break;
847bc36eafdSMike Gerdts 
848bc36eafdSMike Gerdts         case AML_CREATE_WORD_FIELD_OP:
849bc36eafdSMike Gerdts 
850bc36eafdSMike Gerdts             FieldBitLength = 16;
851bc36eafdSMike Gerdts             break;
852bc36eafdSMike Gerdts 
853bc36eafdSMike Gerdts         case AML_CREATE_DWORD_FIELD_OP:
854bc36eafdSMike Gerdts 
855bc36eafdSMike Gerdts             FieldBitLength = 32;
856bc36eafdSMike Gerdts             break;
857bc36eafdSMike Gerdts 
858bc36eafdSMike Gerdts         case AML_CREATE_QWORD_FIELD_OP:
859bc36eafdSMike Gerdts 
860bc36eafdSMike Gerdts             FieldBitLength = 64;
861bc36eafdSMike Gerdts             break;
862bc36eafdSMike Gerdts 
863bc36eafdSMike Gerdts         default:
864bc36eafdSMike Gerdts 
865bc36eafdSMike Gerdts             FieldBitLength = 0;
866bc36eafdSMike Gerdts             break;
867bc36eafdSMike Gerdts         }
868bc36eafdSMike Gerdts 
869bc36eafdSMike Gerdts         /* Check the field length against the length of the resource tag */
870bc36eafdSMike Gerdts 
871bc36eafdSMike Gerdts         if (FieldBitLength)
872bc36eafdSMike Gerdts         {
873bc36eafdSMike Gerdts             if (TagBitLength < FieldBitLength)
874bc36eafdSMike Gerdts             {
875bc36eafdSMike Gerdts                 Message = ASL_MSG_TAG_SMALLER;
876bc36eafdSMike Gerdts             }
877bc36eafdSMike Gerdts             else if (TagBitLength > FieldBitLength)
878bc36eafdSMike Gerdts             {
879bc36eafdSMike Gerdts                 Message = ASL_MSG_TAG_LARGER;
880bc36eafdSMike Gerdts             }
881bc36eafdSMike Gerdts 
882bc36eafdSMike Gerdts             if (Message)
883bc36eafdSMike Gerdts             {
884bc36eafdSMike Gerdts                 sprintf (MsgBuffer,
885bc36eafdSMike Gerdts                     "Size mismatch, Tag: %u bit%s, Field: %u bit%s",
886bc36eafdSMike Gerdts                     TagBitLength, (TagBitLength > 1) ? "s" : "",
887bc36eafdSMike Gerdts                     FieldBitLength, (FieldBitLength > 1) ? "s" : "");
888bc36eafdSMike Gerdts 
889bc36eafdSMike Gerdts                 AslError (ASL_WARNING, Message, Op, MsgBuffer);
890bc36eafdSMike Gerdts             }
891bc36eafdSMike Gerdts         }
892bc36eafdSMike Gerdts 
893bc36eafdSMike Gerdts         /* Convert the BitOffset to a ByteOffset for certain opcodes */
894bc36eafdSMike Gerdts 
895bc36eafdSMike Gerdts         switch (Op->Asl.Parent->Asl.AmlOpcode)
896bc36eafdSMike Gerdts         {
897bc36eafdSMike Gerdts         case AML_CREATE_BYTE_FIELD_OP:
898bc36eafdSMike Gerdts         case AML_CREATE_WORD_FIELD_OP:
899bc36eafdSMike Gerdts         case AML_CREATE_DWORD_FIELD_OP:
900bc36eafdSMike Gerdts         case AML_CREATE_QWORD_FIELD_OP:
901bc36eafdSMike Gerdts         case AML_INDEX_OP:
902bc36eafdSMike Gerdts 
903bc36eafdSMike Gerdts             Offset = ACPI_DIV_8 (Offset);
904bc36eafdSMike Gerdts             break;
905bc36eafdSMike Gerdts 
906bc36eafdSMike Gerdts         default:
907bc36eafdSMike Gerdts 
908bc36eafdSMike Gerdts             break;
909bc36eafdSMike Gerdts         }
910bc36eafdSMike Gerdts 
911bc36eafdSMike Gerdts         /* Now convert this node to an integer whose value is the field offset */
912bc36eafdSMike Gerdts 
913bc36eafdSMike Gerdts         Op->Asl.AmlLength = 0;
914bc36eafdSMike Gerdts         Op->Asl.ParseOpcode = PARSEOP_INTEGER;
915bc36eafdSMike Gerdts         Op->Asl.Value.Integer = (UINT64) Offset;
916*35786f68SRobert Mustacchi         Op->Asl.CompileFlags |= OP_IS_RESOURCE_FIELD;
917bc36eafdSMike Gerdts 
918bc36eafdSMike Gerdts         OpcGenerateAmlOpcode (Op);
919bc36eafdSMike Gerdts     }
920bc36eafdSMike Gerdts 
921bc36eafdSMike Gerdts     /* 3) Check for a method invocation */
922bc36eafdSMike Gerdts 
923bc36eafdSMike Gerdts     else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
924bc36eafdSMike Gerdts                 (Node->Type == ACPI_TYPE_METHOD) &&
925bc36eafdSMike Gerdts                 (Op->Asl.Parent) &&
926bc36eafdSMike Gerdts                 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD))   ||
927bc36eafdSMike Gerdts 
928bc36eafdSMike Gerdts                 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
929bc36eafdSMike Gerdts     {
930bc36eafdSMike Gerdts         /*
931bc36eafdSMike Gerdts          * A reference to a method within one of these opcodes is not an
932bc36eafdSMike Gerdts          * invocation of the method, it is simply a reference to the method.
933*35786f68SRobert Mustacchi          *
934*35786f68SRobert Mustacchi          * September 2016: Removed DeRefOf from this list
935bc36eafdSMike Gerdts          */
936bc36eafdSMike Gerdts         if ((Op->Asl.Parent) &&
937*35786f68SRobert Mustacchi             ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF)     ||
938bc36eafdSMike Gerdts             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_PACKAGE)    ||
939bc36eafdSMike Gerdts             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)||
940bc36eafdSMike Gerdts             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
941bc36eafdSMike Gerdts         {
942bc36eafdSMike Gerdts             return_ACPI_STATUS (AE_OK);
943bc36eafdSMike Gerdts         }
944*35786f68SRobert Mustacchi 
945bc36eafdSMike Gerdts         /*
946bc36eafdSMike Gerdts          * There are two types of method invocation:
947bc36eafdSMike Gerdts          * 1) Invocation with arguments -- the parser recognizes this
948bc36eafdSMike Gerdts          *    as a METHODCALL.
949bc36eafdSMike Gerdts          * 2) Invocation with no arguments --the parser cannot determine that
950bc36eafdSMike Gerdts          *    this is a method invocation, therefore we have to figure it out
951bc36eafdSMike Gerdts          *    here.
952bc36eafdSMike Gerdts          */
953bc36eafdSMike Gerdts         if (Node->Type != ACPI_TYPE_METHOD)
954bc36eafdSMike Gerdts         {
955bc36eafdSMike Gerdts             sprintf (MsgBuffer, "%s is a %s",
956bc36eafdSMike Gerdts                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
957bc36eafdSMike Gerdts 
958bc36eafdSMike Gerdts             AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, MsgBuffer);
959bc36eafdSMike Gerdts             return_ACPI_STATUS (AE_OK);
960bc36eafdSMike Gerdts         }
961bc36eafdSMike Gerdts 
962bc36eafdSMike Gerdts         /* Save the method node in the caller's op */
963bc36eafdSMike Gerdts 
964bc36eafdSMike Gerdts         Op->Asl.Node = Node;
965bc36eafdSMike Gerdts         if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
966bc36eafdSMike Gerdts         {
967bc36eafdSMike Gerdts             return_ACPI_STATUS (AE_OK);
968bc36eafdSMike Gerdts         }
969bc36eafdSMike Gerdts 
970bc36eafdSMike Gerdts         /*
971bc36eafdSMike Gerdts          * This is a method invocation, with or without arguments.
972bc36eafdSMike Gerdts          * Count the number of arguments, each appears as a child
973bc36eafdSMike Gerdts          * under the parent node
974bc36eafdSMike Gerdts          */
975bc36eafdSMike Gerdts         Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
976bc36eafdSMike Gerdts         UtSetParseOpName (Op);
977bc36eafdSMike Gerdts 
978bc36eafdSMike Gerdts         PassedArgs = 0;
979bc36eafdSMike Gerdts         NextOp = Op->Asl.Child;
980bc36eafdSMike Gerdts 
981bc36eafdSMike Gerdts         while (NextOp)
982bc36eafdSMike Gerdts         {
983bc36eafdSMike Gerdts             PassedArgs++;
984bc36eafdSMike Gerdts             NextOp = NextOp->Asl.Next;
985bc36eafdSMike Gerdts         }
986bc36eafdSMike Gerdts 
987bc36eafdSMike Gerdts         if (Node->Value != ASL_EXTERNAL_METHOD &&
988bc36eafdSMike Gerdts             Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL)
989bc36eafdSMike Gerdts         {
990bc36eafdSMike Gerdts             /*
991bc36eafdSMike Gerdts              * Check the parsed arguments with the number expected by the
992bc36eafdSMike Gerdts              * method declaration itself
993bc36eafdSMike Gerdts              */
994bc36eafdSMike Gerdts             if (PassedArgs != Node->Value)
995bc36eafdSMike Gerdts             {
996bc36eafdSMike Gerdts                 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
997bc36eafdSMike Gerdts                             Node->Value);
998bc36eafdSMike Gerdts 
999bc36eafdSMike Gerdts                 if (PassedArgs < Node->Value)
1000bc36eafdSMike Gerdts                 {
1001bc36eafdSMike Gerdts                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, MsgBuffer);
1002bc36eafdSMike Gerdts                 }
1003bc36eafdSMike Gerdts                 else
1004bc36eafdSMike Gerdts                 {
1005bc36eafdSMike Gerdts                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, MsgBuffer);
1006bc36eafdSMike Gerdts                 }
1007bc36eafdSMike Gerdts             }
1008bc36eafdSMike Gerdts         }
1009bc36eafdSMike Gerdts     }
1010bc36eafdSMike Gerdts 
1011bc36eafdSMike Gerdts     /* 4) Check for an ASL Field definition */
1012bc36eafdSMike Gerdts 
1013bc36eafdSMike Gerdts     else if ((Op->Asl.Parent) &&
1014bc36eafdSMike Gerdts             ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD)     ||
1015bc36eafdSMike Gerdts              (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
1016bc36eafdSMike Gerdts     {
1017bc36eafdSMike Gerdts         /*
1018bc36eafdSMike Gerdts          * Offset checking for fields. If the parent operation region has a
1019bc36eafdSMike Gerdts          * constant length (known at compile time), we can check fields
1020bc36eafdSMike Gerdts          * defined in that region against the region length. This will catch
1021bc36eafdSMike Gerdts          * fields and field units that cannot possibly fit within the region.
1022bc36eafdSMike Gerdts          *
1023bc36eafdSMike Gerdts          * Note: Index fields do not directly reference an operation region,
1024bc36eafdSMike Gerdts          * thus they are not included in this check.
1025bc36eafdSMike Gerdts          */
1026bc36eafdSMike Gerdts         if (Op == Op->Asl.Parent->Asl.Child)
1027bc36eafdSMike Gerdts         {
1028bc36eafdSMike Gerdts             /*
1029bc36eafdSMike Gerdts              * This is the first child of the field node, which is
1030bc36eafdSMike Gerdts              * the name of the region. Get the parse node for the
1031bc36eafdSMike Gerdts              * region -- which contains the length of the region.
1032bc36eafdSMike Gerdts              */
1033bc36eafdSMike Gerdts             OwningOp = Node->Op;
1034bc36eafdSMike Gerdts             Op->Asl.Parent->Asl.ExtraValue =
1035bc36eafdSMike Gerdts                 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
1036bc36eafdSMike Gerdts 
1037bc36eafdSMike Gerdts             /* Examine the field access width */
1038bc36eafdSMike Gerdts 
1039bc36eafdSMike Gerdts             switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
1040bc36eafdSMike Gerdts             {
1041bc36eafdSMike Gerdts             case AML_FIELD_ACCESS_ANY:
1042bc36eafdSMike Gerdts             case AML_FIELD_ACCESS_BYTE:
1043bc36eafdSMike Gerdts             case AML_FIELD_ACCESS_BUFFER:
1044bc36eafdSMike Gerdts             default:
1045bc36eafdSMike Gerdts 
1046bc36eafdSMike Gerdts                 MinimumLength = 1;
1047bc36eafdSMike Gerdts                 break;
1048bc36eafdSMike Gerdts 
1049bc36eafdSMike Gerdts             case AML_FIELD_ACCESS_WORD:
1050bc36eafdSMike Gerdts 
1051bc36eafdSMike Gerdts                 MinimumLength = 2;
1052bc36eafdSMike Gerdts                 break;
1053bc36eafdSMike Gerdts 
1054bc36eafdSMike Gerdts             case AML_FIELD_ACCESS_DWORD:
1055bc36eafdSMike Gerdts 
1056bc36eafdSMike Gerdts                 MinimumLength = 4;
1057bc36eafdSMike Gerdts                 break;
1058bc36eafdSMike Gerdts 
1059bc36eafdSMike Gerdts             case AML_FIELD_ACCESS_QWORD:
1060bc36eafdSMike Gerdts 
1061bc36eafdSMike Gerdts                 MinimumLength = 8;
1062bc36eafdSMike Gerdts                 break;
1063bc36eafdSMike Gerdts             }
1064bc36eafdSMike Gerdts 
1065bc36eafdSMike Gerdts             /*
1066bc36eafdSMike Gerdts              * Is the region at least as big as the access width?
1067bc36eafdSMike Gerdts              * Note: DataTableRegions have 0 length
1068bc36eafdSMike Gerdts              */
1069bc36eafdSMike Gerdts             if (((UINT32) OwningOp->Asl.Value.Integer) &&
1070bc36eafdSMike Gerdts                 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
1071bc36eafdSMike Gerdts             {
1072bc36eafdSMike Gerdts                 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
1073bc36eafdSMike Gerdts             }
1074bc36eafdSMike Gerdts 
1075bc36eafdSMike Gerdts             /*
1076bc36eafdSMike Gerdts              * Check EC/CMOS/SMBUS fields to make sure that the correct
1077bc36eafdSMike Gerdts              * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
1078bc36eafdSMike Gerdts              */
1079bc36eafdSMike Gerdts             SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
1080bc36eafdSMike Gerdts             switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
1081bc36eafdSMike Gerdts             {
1082bc36eafdSMike Gerdts             case ACPI_ADR_SPACE_EC:
1083bc36eafdSMike Gerdts             case ACPI_ADR_SPACE_CMOS:
1084bc36eafdSMike Gerdts             case ACPI_ADR_SPACE_GPIO:
1085bc36eafdSMike Gerdts 
1086bc36eafdSMike Gerdts                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1087bc36eafdSMike Gerdts                     AML_FIELD_ACCESS_BYTE)
1088bc36eafdSMike Gerdts                 {
1089bc36eafdSMike Gerdts                     AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
1090bc36eafdSMike Gerdts                 }
1091bc36eafdSMike Gerdts                 break;
1092bc36eafdSMike Gerdts 
1093bc36eafdSMike Gerdts             case ACPI_ADR_SPACE_SMBUS:
1094bc36eafdSMike Gerdts             case ACPI_ADR_SPACE_IPMI:
1095bc36eafdSMike Gerdts             case ACPI_ADR_SPACE_GSBUS:
1096bc36eafdSMike Gerdts 
1097bc36eafdSMike Gerdts                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1098bc36eafdSMike Gerdts                     AML_FIELD_ACCESS_BUFFER)
1099bc36eafdSMike Gerdts                 {
1100bc36eafdSMike Gerdts                     AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
1101bc36eafdSMike Gerdts                 }
1102bc36eafdSMike Gerdts                 break;
1103bc36eafdSMike Gerdts 
1104bc36eafdSMike Gerdts             default:
1105bc36eafdSMike Gerdts 
1106bc36eafdSMike Gerdts                 /* Nothing to do for other address spaces */
1107bc36eafdSMike Gerdts 
1108bc36eafdSMike Gerdts                 break;
1109bc36eafdSMike Gerdts             }
1110bc36eafdSMike Gerdts         }
1111bc36eafdSMike Gerdts         else
1112bc36eafdSMike Gerdts         {
1113bc36eafdSMike Gerdts             /*
1114bc36eafdSMike Gerdts              * This is one element of the field list. Check to make sure
1115bc36eafdSMike Gerdts              * that it does not go beyond the end of the parent operation region.
1116bc36eafdSMike Gerdts              *
1117bc36eafdSMike Gerdts              * In the code below:
1118bc36eafdSMike Gerdts              *    Op->Asl.Parent->Asl.ExtraValue      - Region Length (bits)
1119bc36eafdSMike Gerdts              *    Op->Asl.ExtraValue                  - Field start offset (bits)
1120bc36eafdSMike Gerdts              *    Op->Asl.Child->Asl.Value.Integer32  - Field length (bits)
1121bc36eafdSMike Gerdts              *    Op->Asl.Child->Asl.ExtraValue       - Field access width (bits)
1122bc36eafdSMike Gerdts              */
1123bc36eafdSMike Gerdts             if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1124bc36eafdSMike Gerdts             {
1125bc36eafdSMike Gerdts                 XfCheckFieldRange (Op,
1126bc36eafdSMike Gerdts                     Op->Asl.Parent->Asl.ExtraValue,
1127bc36eafdSMike Gerdts                     Op->Asl.ExtraValue,
1128bc36eafdSMike Gerdts                     (UINT32) Op->Asl.Child->Asl.Value.Integer,
1129bc36eafdSMike Gerdts                     Op->Asl.Child->Asl.ExtraValue);
1130bc36eafdSMike Gerdts             }
1131bc36eafdSMike Gerdts         }
1132bc36eafdSMike Gerdts     }
1133bc36eafdSMike Gerdts 
1134bc36eafdSMike Gerdts     /* 5) Check for a connection object */
1135bc36eafdSMike Gerdts #if 0
1136bc36eafdSMike Gerdts     else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1137bc36eafdSMike Gerdts     {
1138bc36eafdSMike Gerdts         return_ACPI_STATUS (Status);
1139bc36eafdSMike Gerdts     }
1140bc36eafdSMike Gerdts #endif
1141bc36eafdSMike Gerdts 
1142bc36eafdSMike Gerdts     Op->Asl.Node = Node;
1143bc36eafdSMike Gerdts     return_ACPI_STATUS (Status);
1144bc36eafdSMike Gerdts }
1145bc36eafdSMike Gerdts 
1146bc36eafdSMike Gerdts 
1147bc36eafdSMike Gerdts /*******************************************************************************
1148bc36eafdSMike Gerdts  *
1149bc36eafdSMike Gerdts  * FUNCTION:    XfNamespaceLocateEnd
1150bc36eafdSMike Gerdts  *
1151bc36eafdSMike Gerdts  * PARAMETERS:  ASL_WALK_CALLBACK
1152bc36eafdSMike Gerdts  *
1153bc36eafdSMike Gerdts  * RETURN:      Status
1154bc36eafdSMike Gerdts  *
1155bc36eafdSMike Gerdts  * DESCRIPTION: Ascending callback used during cross reference. We only
1156bc36eafdSMike Gerdts  *              need to worry about scope management here.
1157bc36eafdSMike Gerdts  *
1158bc36eafdSMike Gerdts  ******************************************************************************/
1159bc36eafdSMike Gerdts 
1160bc36eafdSMike Gerdts static ACPI_STATUS
XfNamespaceLocateEnd(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)1161bc36eafdSMike Gerdts XfNamespaceLocateEnd (
1162bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
1163bc36eafdSMike Gerdts     UINT32                  Level,
1164bc36eafdSMike Gerdts     void                    *Context)
1165bc36eafdSMike Gerdts {
1166bc36eafdSMike Gerdts     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1167bc36eafdSMike Gerdts     const ACPI_OPCODE_INFO  *OpInfo;
1168bc36eafdSMike Gerdts 
1169bc36eafdSMike Gerdts 
1170bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
1171bc36eafdSMike Gerdts 
1172bc36eafdSMike Gerdts 
1173bc36eafdSMike Gerdts     /* We are only interested in opcodes that have an associated name */
1174bc36eafdSMike Gerdts 
1175bc36eafdSMike Gerdts     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1176bc36eafdSMike Gerdts     if (!(OpInfo->Flags & AML_NAMED))
1177bc36eafdSMike Gerdts     {
1178bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_OK);
1179bc36eafdSMike Gerdts     }
1180bc36eafdSMike Gerdts 
1181bc36eafdSMike Gerdts     /* Not interested in name references, we did not open a scope for them */
1182bc36eafdSMike Gerdts 
1183bc36eafdSMike Gerdts     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1184bc36eafdSMike Gerdts         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
1185*35786f68SRobert Mustacchi         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
1186*35786f68SRobert Mustacchi         (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1187bc36eafdSMike Gerdts     {
1188bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_OK);
1189bc36eafdSMike Gerdts     }
1190bc36eafdSMike Gerdts 
1191bc36eafdSMike Gerdts     /* Pop the scope stack if necessary */
1192bc36eafdSMike Gerdts 
1193bc36eafdSMike Gerdts     if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1194bc36eafdSMike Gerdts     {
1195bc36eafdSMike Gerdts 
1196bc36eafdSMike Gerdts         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1197bc36eafdSMike Gerdts             "%s: Popping scope for Op %p\n",
1198bc36eafdSMike Gerdts             AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1199bc36eafdSMike Gerdts 
1200bc36eafdSMike Gerdts         (void) AcpiDsScopeStackPop (WalkState);
1201bc36eafdSMike Gerdts     }
1202bc36eafdSMike Gerdts 
1203bc36eafdSMike Gerdts     return_ACPI_STATUS (AE_OK);
1204bc36eafdSMike Gerdts }
1205