aslxref.c revision 245582
1/******************************************************************************
2 *
3 * Module Name: aslxref - Namespace cross-reference
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions, and the following disclaimer,
16 *    without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 *    substantially similar to the "NO WARRANTY" disclaimer below
19 *    ("Disclaimer") and any redistribution must be conditioned upon
20 *    including a substantially similar Disclaimer requirement for further
21 *    binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 *    of any contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44
45#include <contrib/dev/acpica/compiler/aslcompiler.h>
46#include "aslcompiler.y.h"
47#include <contrib/dev/acpica/include/acparser.h>
48#include <contrib/dev/acpica/include/amlcode.h>
49#include <contrib/dev/acpica/include/acnamesp.h>
50#include <contrib/dev/acpica/include/acdispat.h>
51
52
53#define _COMPONENT          ACPI_COMPILER
54        ACPI_MODULE_NAME    ("aslxref")
55
56/* Local prototypes */
57
58static ACPI_STATUS
59XfNamespaceLocateBegin (
60    ACPI_PARSE_OBJECT       *Op,
61    UINT32                  Level,
62    void                    *Context);
63
64static ACPI_STATUS
65XfNamespaceLocateEnd (
66    ACPI_PARSE_OBJECT       *Op,
67    UINT32                  Level,
68    void                    *Context);
69
70static BOOLEAN
71XfObjectExists (
72    char                    *Name);
73
74static ACPI_STATUS
75XfCompareOneNamespaceObject (
76    ACPI_HANDLE             ObjHandle,
77    UINT32                  Level,
78    void                    *Context,
79    void                    **ReturnValue);
80
81static void
82XfCheckFieldRange (
83    ACPI_PARSE_OBJECT       *Op,
84    UINT32                  RegionBitLength,
85    UINT32                  FieldBitOffset,
86    UINT32                  FieldBitLength,
87    UINT32                  AccessBitWidth);
88
89
90/*******************************************************************************
91 *
92 * FUNCTION:    XfCrossReferenceNamespace
93 *
94 * PARAMETERS:  None
95 *
96 * RETURN:      Status
97 *
98 * DESCRIPTION: Perform a cross reference check of the parse tree against the
99 *              namespace. Every named referenced within the parse tree
100 *              should be get resolved with a namespace lookup. If not, the
101 *              original reference in the ASL code is invalid -- i.e., refers
102 *              to a non-existent object.
103 *
104 * NOTE:  The ASL "External" operator causes the name to be inserted into the
105 *        namespace so that references to the external name will be resolved
106 *        correctly here.
107 *
108 ******************************************************************************/
109
110ACPI_STATUS
111XfCrossReferenceNamespace (
112    void)
113{
114    ACPI_WALK_STATE         *WalkState;
115
116
117    DbgPrint (ASL_DEBUG_OUTPUT, "\nCross referencing namespace\n\n");
118
119    /*
120     * Create a new walk state for use when looking up names
121     * within the namespace (Passed as context to the callbacks)
122     */
123    WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
124    if (!WalkState)
125    {
126        return (AE_NO_MEMORY);
127    }
128
129    /* Walk the entire parse tree */
130
131    TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, XfNamespaceLocateBegin,
132                        XfNamespaceLocateEnd, WalkState);
133    return (AE_OK);
134}
135
136
137/*******************************************************************************
138 *
139 * FUNCTION:    XfObjectExists
140 *
141 * PARAMETERS:  Name            - 4 char ACPI name
142 *
143 * RETURN:      TRUE if name exists in namespace
144 *
145 * DESCRIPTION: Walk the namespace to find an object
146 *
147 ******************************************************************************/
148
149static BOOLEAN
150XfObjectExists (
151    char                    *Name)
152{
153    ACPI_STATUS             Status;
154
155
156    /* Walk entire namespace from the supplied root */
157
158    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
159                ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL,
160                Name, NULL);
161    if (Status == AE_CTRL_TRUE)
162    {
163        /* At least one instance of the name was found */
164
165        return (TRUE);
166    }
167
168    return (FALSE);
169}
170
171
172/*******************************************************************************
173 *
174 * FUNCTION:    XfCompareOneNamespaceObject
175 *
176 * PARAMETERS:  ACPI_WALK_CALLBACK
177 *
178 * RETURN:      Status
179 *
180 * DESCRIPTION: Compare name of one object.
181 *
182 ******************************************************************************/
183
184static ACPI_STATUS
185XfCompareOneNamespaceObject (
186    ACPI_HANDLE             ObjHandle,
187    UINT32                  Level,
188    void                    *Context,
189    void                    **ReturnValue)
190{
191    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
192
193
194    /* Simply check the name */
195
196    if (*((UINT32 *) (Context)) == Node->Name.Integer)
197    {
198        /* Abort walk if we found one instance */
199
200        return (AE_CTRL_TRUE);
201    }
202
203    return (AE_OK);
204}
205
206
207/*******************************************************************************
208 *
209 * FUNCTION:    XfCheckFieldRange
210 *
211 * PARAMETERS:  RegionBitLength     - Length of entire parent region
212 *              FieldBitOffset      - Start of the field unit (within region)
213 *              FieldBitLength      - Entire length of field unit
214 *              AccessBitWidth      - Access width of the field unit
215 *
216 * RETURN:      None
217 *
218 * DESCRIPTION: Check one field unit to make sure it fits in the parent
219 *              op region.
220 *
221 * Note: AccessBitWidth must be either 8,16,32, or 64
222 *
223 ******************************************************************************/
224
225static void
226XfCheckFieldRange (
227    ACPI_PARSE_OBJECT       *Op,
228    UINT32                  RegionBitLength,
229    UINT32                  FieldBitOffset,
230    UINT32                  FieldBitLength,
231    UINT32                  AccessBitWidth)
232{
233    UINT32                  FieldEndBitOffset;
234
235
236    /*
237     * Check each field unit against the region size. The entire
238     * field unit (start offset plus length) must fit within the
239     * region.
240     */
241    FieldEndBitOffset = FieldBitOffset + FieldBitLength;
242
243    if (FieldEndBitOffset > RegionBitLength)
244    {
245        /* Field definition itself is beyond the end-of-region */
246
247        AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
248        return;
249    }
250
251    /*
252     * Now check that the field plus AccessWidth doesn't go beyond
253     * the end-of-region. Assumes AccessBitWidth is a power of 2
254     */
255    FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
256
257    if (FieldEndBitOffset > RegionBitLength)
258    {
259        /* Field definition combined with the access is beyond EOR */
260
261        AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
262    }
263}
264
265/*******************************************************************************
266 *
267 * FUNCTION:    XfNamespaceLocateBegin
268 *
269 * PARAMETERS:  ASL_WALK_CALLBACK
270 *
271 * RETURN:      Status
272 *
273 * DESCRIPTION: Descending callback used during cross-reference. For named
274 *              object references, attempt to locate the name in the
275 *              namespace.
276 *
277 * NOTE: ASL references to named fields within resource descriptors are
278 *       resolved to integer values here. Therefore, this step is an
279 *       important part of the code generation. We don't know that the
280 *       name refers to a resource descriptor until now.
281 *
282 ******************************************************************************/
283
284static ACPI_STATUS
285XfNamespaceLocateBegin (
286    ACPI_PARSE_OBJECT       *Op,
287    UINT32                  Level,
288    void                    *Context)
289{
290    ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
291    ACPI_NAMESPACE_NODE     *Node;
292    ACPI_STATUS             Status;
293    ACPI_OBJECT_TYPE        ObjectType;
294    char                    *Path;
295    UINT8                   PassedArgs;
296    ACPI_PARSE_OBJECT       *NextOp;
297    ACPI_PARSE_OBJECT       *OwningOp;
298    ACPI_PARSE_OBJECT       *SpaceIdOp;
299    UINT32                  MinimumLength;
300    UINT32                  Offset;
301    UINT32                  FieldBitLength;
302    UINT32                  TagBitLength;
303    UINT8                   Message = 0;
304    const ACPI_OPCODE_INFO  *OpInfo;
305    UINT32                  Flags;
306
307
308    ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
309
310    /*
311     * If this node is the actual declaration of a name
312     * [such as the XXXX name in "Method (XXXX)"],
313     * we are not interested in it here. We only care about names that are
314     * references to other objects within the namespace and the parent objects
315     * of name declarations
316     */
317    if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
318    {
319        return (AE_OK);
320    }
321
322    /* We are only interested in opcodes that have an associated name */
323
324    OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
325
326    if ((!(OpInfo->Flags & AML_NAMED)) &&
327        (!(OpInfo->Flags & AML_CREATE)) &&
328        (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
329        (Op->Asl.ParseOpcode != PARSEOP_NAMESEG)    &&
330        (Op->Asl.ParseOpcode != PARSEOP_METHODCALL))
331    {
332        return (AE_OK);
333    }
334
335    /*
336     * One special case: CondRefOf operator - we don't care if the name exists
337     * or not at this point, just ignore it, the point of the operator is to
338     * determine if the name exists at runtime.
339     */
340    if ((Op->Asl.Parent) &&
341        (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
342    {
343        return (AE_OK);
344    }
345
346    /*
347     * We must enable the "search-to-root" for single NameSegs, but
348     * we have to be very careful about opening up scopes
349     */
350    Flags = ACPI_NS_SEARCH_PARENT;
351    if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
352        (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
353        (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
354    {
355        /*
356         * These are name references, do not push the scope stack
357         * for them.
358         */
359        Flags |= ACPI_NS_DONT_OPEN_SCOPE;
360    }
361
362    /* Get the NamePath from the appropriate place */
363
364    if (OpInfo->Flags & AML_NAMED)
365    {
366        /* For nearly all NAMED operators, the name reference is the first child */
367
368        Path = Op->Asl.Child->Asl.Value.String;
369        if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
370        {
371            /*
372             * ALIAS is the only oddball opcode, the name declaration
373             * (alias name) is the second operand
374             */
375            Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
376        }
377    }
378    else if (OpInfo->Flags & AML_CREATE)
379    {
380        /* Name must appear as the last parameter */
381
382        NextOp = Op->Asl.Child;
383        while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
384        {
385            NextOp = NextOp->Asl.Next;
386        }
387        Path = NextOp->Asl.Value.String;
388    }
389    else
390    {
391        Path = Op->Asl.Value.String;
392    }
393
394    ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
395    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
396        "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
397
398    /*
399     * Lookup the name in the namespace. Name must exist at this point, or it
400     * is an invalid reference.
401     *
402     * The namespace is also used as a lookup table for references to resource
403     * descriptors and the fields within them.
404     */
405    Gbl_NsLookupCount++;
406
407    Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
408                ACPI_IMODE_EXECUTE, Flags, WalkState, &(Node));
409    if (ACPI_FAILURE (Status))
410    {
411        if (Status == AE_NOT_FOUND)
412        {
413            /*
414             * We didn't find the name reference by path -- we can qualify this
415             * a little better before we print an error message
416             */
417            if (strlen (Path) == ACPI_NAME_SIZE)
418            {
419                /* A simple, one-segment ACPI name */
420
421                if (XfObjectExists (Path))
422                {
423                    /*
424                     * There exists such a name, but we couldn't get to it
425                     * from this scope
426                     */
427                    AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
428                        Op->Asl.ExternalName);
429                }
430                else
431                {
432                    /* The name doesn't exist, period */
433
434                    AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
435                        Op, Op->Asl.ExternalName);
436                }
437            }
438            else
439            {
440                /* Check for a fully qualified path */
441
442                if (Path[0] == AML_ROOT_PREFIX)
443                {
444                    /* Gave full path, the object does not exist */
445
446                    AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
447                        Op->Asl.ExternalName);
448                }
449                else
450                {
451                    /*
452                     * We can't tell whether it doesn't exist or just
453                     * can't be reached.
454                     */
455                    AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
456                        Op->Asl.ExternalName);
457                }
458            }
459
460            Status = AE_OK;
461        }
462        return (Status);
463    }
464
465    /* Check for a reference vs. name declaration */
466
467    if (!(OpInfo->Flags & AML_NAMED) &&
468        !(OpInfo->Flags & AML_CREATE))
469    {
470        /* This node has been referenced, mark it for reference check */
471
472        Node->Flags |= ANOBJ_IS_REFERENCED;
473    }
474
475    /* Attempt to optimize the NamePath */
476
477    OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
478
479    /*
480     * 1) Dereference an alias (A name reference that is an alias)
481     *    Aliases are not nested, the alias always points to the final object
482     */
483    if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
484        (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
485    {
486        /* This node points back to the original PARSEOP_ALIAS */
487
488        NextOp = Node->Op;
489
490        /* The first child is the alias target op */
491
492        NextOp = NextOp->Asl.Child;
493
494        /* That in turn points back to original target alias node */
495
496        if (NextOp->Asl.Node)
497        {
498            Node = NextOp->Asl.Node;
499        }
500
501        /* Else - forward reference to alias, will be resolved later */
502    }
503
504    /* 2) Check for a reference to a resource descriptor */
505
506    if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
507        (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
508    {
509        /*
510         * This was a reference to a field within a resource descriptor.
511         * Extract the associated field offset (either a bit or byte
512         * offset depending on the field type) and change the named
513         * reference into an integer for AML code generation
514         */
515        Offset = Node->Value;
516        TagBitLength = Node->Length;
517
518        /*
519         * If a field is being created, generate the length (in bits) of
520         * the field. Note: Opcodes other than CreateXxxField and Index
521         * can come through here. For other opcodes, we just need to
522         * convert the resource tag reference to an integer offset.
523         */
524        switch (Op->Asl.Parent->Asl.AmlOpcode)
525        {
526        case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
527            /*
528             * We know the length operand is an integer constant because
529             * we know that it contains a reference to a resource
530             * descriptor tag.
531             */
532            FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
533            break;
534
535        case AML_CREATE_BIT_FIELD_OP:
536            FieldBitLength = 1;
537            break;
538
539        case AML_CREATE_BYTE_FIELD_OP:
540        case AML_INDEX_OP:
541            FieldBitLength = 8;
542            break;
543
544        case AML_CREATE_WORD_FIELD_OP:
545            FieldBitLength = 16;
546            break;
547
548        case AML_CREATE_DWORD_FIELD_OP:
549            FieldBitLength = 32;
550            break;
551
552        case AML_CREATE_QWORD_FIELD_OP:
553            FieldBitLength = 64;
554            break;
555
556        default:
557            FieldBitLength = 0;
558            break;
559        }
560
561        /* Check the field length against the length of the resource tag */
562
563        if (FieldBitLength)
564        {
565            if (TagBitLength < FieldBitLength)
566            {
567                Message = ASL_MSG_TAG_SMALLER;
568            }
569            else if (TagBitLength > FieldBitLength)
570            {
571                Message = ASL_MSG_TAG_LARGER;
572            }
573
574            if (Message)
575            {
576                sprintf (MsgBuffer, "Size mismatch, Tag: %u bit%s, Field: %u bit%s",
577                    TagBitLength, (TagBitLength > 1) ? "s" : "",
578                    FieldBitLength, (FieldBitLength > 1) ? "s" : "");
579
580                AslError (ASL_WARNING, Message, Op, MsgBuffer);
581            }
582        }
583
584        /* Convert the BitOffset to a ByteOffset for certain opcodes */
585
586        switch (Op->Asl.Parent->Asl.AmlOpcode)
587        {
588        case AML_CREATE_BYTE_FIELD_OP:
589        case AML_CREATE_WORD_FIELD_OP:
590        case AML_CREATE_DWORD_FIELD_OP:
591        case AML_CREATE_QWORD_FIELD_OP:
592        case AML_INDEX_OP:
593
594            Offset = ACPI_DIV_8 (Offset);
595            break;
596
597        default:
598            break;
599        }
600
601        /* Now convert this node to an integer whose value is the field offset */
602
603        Op->Asl.AmlLength = 0;
604        Op->Asl.ParseOpcode = PARSEOP_INTEGER;
605        Op->Asl.Value.Integer = (UINT64) Offset;
606        Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
607
608        OpcGenerateAmlOpcode (Op);
609    }
610
611    /* 3) Check for a method invocation */
612
613    else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
614                (Node->Type == ACPI_TYPE_METHOD) &&
615                (Op->Asl.Parent) &&
616                (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD))   ||
617
618                (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
619    {
620
621        /*
622         * A reference to a method within one of these opcodes is not an
623         * invocation of the method, it is simply a reference to the method.
624         */
625        if ((Op->Asl.Parent) &&
626           ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF)      ||
627            (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEREFOF)    ||
628            (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
629        {
630            return (AE_OK);
631        }
632        /*
633         * There are two types of method invocation:
634         * 1) Invocation with arguments -- the parser recognizes this
635         *    as a METHODCALL.
636         * 2) Invocation with no arguments --the parser cannot determine that
637         *    this is a method invocation, therefore we have to figure it out
638         *    here.
639         */
640        if (Node->Type != ACPI_TYPE_METHOD)
641        {
642            sprintf (MsgBuffer, "%s is a %s",
643                    Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
644
645            AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, MsgBuffer);
646            return (AE_OK);
647        }
648
649        /* Save the method node in the caller's op */
650
651        Op->Asl.Node = Node;
652        if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
653        {
654            return (AE_OK);
655        }
656
657        /*
658         * This is a method invocation, with or without arguments.
659         * Count the number of arguments, each appears as a child
660         * under the parent node
661         */
662        Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
663        UtSetParseOpName (Op);
664
665        PassedArgs = 0;
666        NextOp     = Op->Asl.Child;
667
668        while (NextOp)
669        {
670            PassedArgs++;
671            NextOp = NextOp->Asl.Next;
672        }
673
674        if (Node->Value != ASL_EXTERNAL_METHOD)
675        {
676            /*
677             * Check the parsed arguments with the number expected by the
678             * method declaration itself
679             */
680            if (PassedArgs != Node->Value)
681            {
682                sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
683                            Node->Value);
684
685                if (PassedArgs < Node->Value)
686                {
687                    AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, MsgBuffer);
688                }
689                else
690                {
691                    AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, MsgBuffer);
692                }
693            }
694        }
695    }
696
697    /* 4) Check for an ASL Field definition */
698
699    else if ((Op->Asl.Parent) &&
700            ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD)     ||
701             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
702    {
703        /*
704         * Offset checking for fields. If the parent operation region has a
705         * constant length (known at compile time), we can check fields
706         * defined in that region against the region length. This will catch
707         * fields and field units that cannot possibly fit within the region.
708         *
709         * Note: Index fields do not directly reference an operation region,
710         * thus they are not included in this check.
711         */
712        if (Op == Op->Asl.Parent->Asl.Child)
713        {
714            /*
715             * This is the first child of the field node, which is
716             * the name of the region. Get the parse node for the
717             * region -- which contains the length of the region.
718             */
719            OwningOp = Node->Op;
720            Op->Asl.Parent->Asl.ExtraValue =
721                ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
722
723            /* Examine the field access width */
724
725            switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
726            {
727            case AML_FIELD_ACCESS_ANY:
728            case AML_FIELD_ACCESS_BYTE:
729            case AML_FIELD_ACCESS_BUFFER:
730            default:
731                MinimumLength = 1;
732                break;
733
734            case AML_FIELD_ACCESS_WORD:
735                MinimumLength = 2;
736                break;
737
738            case AML_FIELD_ACCESS_DWORD:
739                MinimumLength = 4;
740                break;
741
742            case AML_FIELD_ACCESS_QWORD:
743                MinimumLength = 8;
744                break;
745            }
746
747            /*
748             * Is the region at least as big as the access width?
749             * Note: DataTableRegions have 0 length
750             */
751            if (((UINT32) OwningOp->Asl.Value.Integer) &&
752                ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
753            {
754                AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
755            }
756
757            /*
758             * Check EC/CMOS/SMBUS fields to make sure that the correct
759             * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
760             */
761            SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
762            switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
763            {
764            case ACPI_ADR_SPACE_EC:
765            case ACPI_ADR_SPACE_CMOS:
766            case ACPI_ADR_SPACE_GPIO:
767
768                if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BYTE)
769                {
770                    AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
771                }
772                break;
773
774            case ACPI_ADR_SPACE_SMBUS:
775            case ACPI_ADR_SPACE_IPMI:
776            case ACPI_ADR_SPACE_GSBUS:
777
778                if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BUFFER)
779                {
780                    AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
781                }
782                break;
783
784            default:
785
786                /* Nothing to do for other address spaces */
787                break;
788            }
789        }
790        else
791        {
792            /*
793             * This is one element of the field list. Check to make sure
794             * that it does not go beyond the end of the parent operation region.
795             *
796             * In the code below:
797             *    Op->Asl.Parent->Asl.ExtraValue      - Region Length (bits)
798             *    Op->Asl.ExtraValue                  - Field start offset (bits)
799             *    Op->Asl.Child->Asl.Value.Integer32  - Field length (bits)
800             *    Op->Asl.Child->Asl.ExtraValue       - Field access width (bits)
801             */
802            if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
803            {
804                XfCheckFieldRange (Op,
805                            Op->Asl.Parent->Asl.ExtraValue,
806                            Op->Asl.ExtraValue,
807                            (UINT32) Op->Asl.Child->Asl.Value.Integer,
808                            Op->Asl.Child->Asl.ExtraValue);
809            }
810        }
811    }
812
813    Op->Asl.Node = Node;
814    return (Status);
815}
816
817
818/*******************************************************************************
819 *
820 * FUNCTION:    XfNamespaceLocateEnd
821 *
822 * PARAMETERS:  ASL_WALK_CALLBACK
823 *
824 * RETURN:      Status
825 *
826 * DESCRIPTION: Ascending callback used during cross reference. We only
827 *              need to worry about scope management here.
828 *
829 ******************************************************************************/
830
831static ACPI_STATUS
832XfNamespaceLocateEnd (
833    ACPI_PARSE_OBJECT       *Op,
834    UINT32                  Level,
835    void                    *Context)
836{
837    ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
838    const ACPI_OPCODE_INFO  *OpInfo;
839
840
841    ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
842
843
844    /* We are only interested in opcodes that have an associated name */
845
846    OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
847    if (!(OpInfo->Flags & AML_NAMED))
848    {
849        return (AE_OK);
850    }
851
852    /* Not interested in name references, we did not open a scope for them */
853
854    if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
855        (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
856        (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
857    {
858        return (AE_OK);
859    }
860
861    /* Pop the scope stack if necessary */
862
863    if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
864    {
865
866        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
867            "%s: Popping scope for Op %p\n",
868            AcpiUtGetTypeName (OpInfo->ObjectType), Op));
869
870        (void) AcpiDsScopeStackPop (WalkState);
871    }
872
873    return (AE_OK);
874}
875