dsfield.c revision 245582
180028Stakawata/******************************************************************************
280028Stakawata *
380028Stakawata * Module Name: dsfield - Dispatcher field routines
480028Stakawata *
580028Stakawata *****************************************************************************/
680028Stakawata
780028Stakawata/*
880028Stakawata * Copyright (C) 2000 - 2013, Intel Corp.
980028Stakawata * All rights reserved.
1080028Stakawata *
1180028Stakawata * Redistribution and use in source and binary forms, with or without
1280028Stakawata * modification, are permitted provided that the following conditions
1380028Stakawata * are met:
1480028Stakawata * 1. Redistributions of source code must retain the above copyright
1580028Stakawata *    notice, this list of conditions, and the following disclaimer,
1680028Stakawata *    without modification.
1780028Stakawata * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1880028Stakawata *    substantially similar to the "NO WARRANTY" disclaimer below
1980028Stakawata *    ("Disclaimer") and any redistribution must be conditioned upon
2080028Stakawata *    including a substantially similar Disclaimer requirement for further
2180028Stakawata *    binary redistribution.
2280028Stakawata * 3. Neither the names of the above-listed copyright holders nor the names
2380028Stakawata *    of any contributors may be used to endorse or promote products derived
2480028Stakawata *    from this software without specific prior written permission.
2580028Stakawata *
2680028Stakawata * Alternatively, this software may be distributed under the terms of the
2780028Stakawata * GNU General Public License ("GPL") version 2 as published by the Free
28115681Sobrien * Software Foundation.
29115681Sobrien *
30115681Sobrien * NO WARRANTY
3180028Stakawata * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3280028Stakawata * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33121830Snjl * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3480028Stakawata * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3580028Stakawata * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3680028Stakawata * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3780028Stakawata * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3880028Stakawata * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3980028Stakawata * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4080028Stakawata * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4180028Stakawata * POSSIBILITY OF SUCH DAMAGES.
42121830Snjl */
43121830Snjl
44121830Snjl#define __DSFIELD_C__
45121830Snjl
4680028Stakawata#include <contrib/dev/acpica/include/acpi.h>
4780028Stakawata#include <contrib/dev/acpica/include/accommon.h>
4880028Stakawata#include <contrib/dev/acpica/include/amlcode.h>
49121830Snjl#include <contrib/dev/acpica/include/acdispat.h>
50121830Snjl#include <contrib/dev/acpica/include/acinterp.h>
51121830Snjl#include <contrib/dev/acpica/include/acnamesp.h>
52121830Snjl#include <contrib/dev/acpica/include/acparser.h>
53121830Snjl
54121830Snjl
55121830Snjl#define _COMPONENT          ACPI_DISPATCHER
56121603Snjl        ACPI_MODULE_NAME    ("dsfield")
57121830Snjl
58121830Snjl/* Local prototypes */
59121603Snjl
60121830Snjl#ifdef ACPI_ASL_COMPILER
61121830Snjl#include <contrib/dev/acpica/include/acdisasm.h>
62121830Snjl
6380028Stakawatastatic ACPI_STATUS
64121743SiwasakiAcpiDsCreateExternalRegion (
6580028Stakawata    ACPI_STATUS             LookupStatus,
6680028Stakawata    ACPI_PARSE_OBJECT       *Op,
6780028Stakawata    char                    *Path,
6880028Stakawata    ACPI_WALK_STATE         *WalkState,
6980028Stakawata    ACPI_NAMESPACE_NODE     **Node);
7080028Stakawata#endif
7180028Stakawata
7280028Stakawatastatic ACPI_STATUS
7380028StakawataAcpiDsGetFieldNames (
7480028Stakawata    ACPI_CREATE_FIELD_INFO  *Info,
7580028Stakawata    ACPI_WALK_STATE         *WalkState,
7680028Stakawata    ACPI_PARSE_OBJECT       *Arg);
7780028Stakawata
7880028Stakawata
7980028Stakawata#ifdef ACPI_ASL_COMPILER
8080028Stakawata/*******************************************************************************
8180028Stakawata *
8280028Stakawata * FUNCTION:    AcpiDsCreateExternalRegion (iASL Disassembler only)
8380028Stakawata *
8480028Stakawata * PARAMETERS:  LookupStatus    - Status from NsLookup operation
8580028Stakawata *              Op              - Op containing the Field definition and args
8680028Stakawata *              Path            - Pathname of the region
8780028Stakawata *  `           WalkState       - Current method state
8880028Stakawata *              Node            - Where the new region node is returned
8980028Stakawata *
9080028Stakawata * RETURN:      Status
9180028Stakawata *
9280028Stakawata * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
9380028Stakawata *              region node/object.
9480028Stakawata *
9580028Stakawata ******************************************************************************/
9680028Stakawata
9780028Stakawatastatic ACPI_STATUS
9880028StakawataAcpiDsCreateExternalRegion (
9980028Stakawata    ACPI_STATUS             LookupStatus,
10080028Stakawata    ACPI_PARSE_OBJECT       *Op,
10180028Stakawata    char                    *Path,
10280028Stakawata    ACPI_WALK_STATE         *WalkState,
10380028Stakawata    ACPI_NAMESPACE_NODE     **Node)
10480028Stakawata{
10580028Stakawata    ACPI_STATUS             Status;
10680028Stakawata    ACPI_OPERAND_OBJECT     *ObjDesc;
10780028Stakawata
10880028Stakawata
10980028Stakawata    if (LookupStatus != AE_NOT_FOUND)
11080028Stakawata    {
11180028Stakawata        return (LookupStatus);
11280028Stakawata    }
11380028Stakawata
11480028Stakawata    /*
11580028Stakawata     * Table disassembly:
11680028Stakawata     * OperationRegion not found. Generate an External for it, and
11780028Stakawata     * insert the name into the namespace.
11880028Stakawata     */
11980028Stakawata    AcpiDmAddToExternalList (Op, Path, ACPI_TYPE_REGION, 0);
12080028Stakawata    Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,
12180028Stakawata       ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);
12280028Stakawata    if (ACPI_FAILURE (Status))
12380028Stakawata    {
12480028Stakawata        return (Status);
12580028Stakawata    }
12680028Stakawata
12780028Stakawata    /* Must create and install a region object for the new node */
12880028Stakawata
12980028Stakawata    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
13080028Stakawata    if (!ObjDesc)
13180028Stakawata    {
13280028Stakawata        return (AE_NO_MEMORY);
13380028Stakawata    }
13480028Stakawata
13580028Stakawata    ObjDesc->Region.Node = *Node;
13680028Stakawata    Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);
13780028Stakawata    return (Status);
13880028Stakawata}
13980028Stakawata#endif
14080028Stakawata
14180028Stakawata
14280028Stakawata/*******************************************************************************
14380028Stakawata *
14480028Stakawata * FUNCTION:    AcpiDsCreateBufferField
14580028Stakawata *
14680028Stakawata * PARAMETERS:  Op                  - Current parse op (CreateXXField)
14780028Stakawata *              WalkState           - Current state
14880028Stakawata *
14980028Stakawata * RETURN:      Status
15080028Stakawata *
15180028Stakawata * DESCRIPTION: Execute the CreateField operators:
15280028Stakawata *              CreateBitFieldOp,
15380028Stakawata *              CreateByteFieldOp,
15480028Stakawata *              CreateWordFieldOp,
15580028Stakawata *              CreateDwordFieldOp,
15680028Stakawata *              CreateQwordFieldOp,
15780028Stakawata *              CreateFieldOp       (all of which define a field in a buffer)
15880028Stakawata *
15980028Stakawata ******************************************************************************/
16080028Stakawata
16180028StakawataACPI_STATUS
16280028StakawataAcpiDsCreateBufferField (
16380028Stakawata    ACPI_PARSE_OBJECT       *Op,
16480028Stakawata    ACPI_WALK_STATE         *WalkState)
16580028Stakawata{
16680028Stakawata    ACPI_PARSE_OBJECT       *Arg;
16780028Stakawata    ACPI_NAMESPACE_NODE     *Node;
16880028Stakawata    ACPI_STATUS             Status;
16980028Stakawata    ACPI_OPERAND_OBJECT     *ObjDesc;
17080028Stakawata    ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
17180028Stakawata    UINT32                  Flags;
17280028Stakawata
17380028Stakawata
17480028Stakawata    ACPI_FUNCTION_TRACE (DsCreateBufferField);
17580028Stakawata
17680028Stakawata
17780028Stakawata    /*
17880028Stakawata     * Get the NameString argument (name of the new BufferField)
17980028Stakawata     */
18080028Stakawata    if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
18180028Stakawata    {
18280028Stakawata        /* For CreateField, name is the 4th argument */
18380028Stakawata
18480028Stakawata        Arg = AcpiPsGetArg (Op, 3);
18580028Stakawata    }
18680028Stakawata    else
18780028Stakawata    {
18880028Stakawata        /* For all other CreateXXXField operators, name is the 3rd argument */
18980028Stakawata
19080028Stakawata        Arg = AcpiPsGetArg (Op, 2);
19180028Stakawata    }
19280028Stakawata
19380028Stakawata    if (!Arg)
19480028Stakawata    {
19580028Stakawata        return_ACPI_STATUS (AE_AML_NO_OPERAND);
19680028Stakawata    }
19780028Stakawata
19880028Stakawata    if (WalkState->DeferredNode)
19980028Stakawata    {
20080028Stakawata        Node = WalkState->DeferredNode;
20180028Stakawata        Status = AE_OK;
20280028Stakawata    }
20380028Stakawata    else
20480028Stakawata    {
20580028Stakawata        /* Execute flag should always be set when this function is entered */
20680028Stakawata
20780028Stakawata        if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
20880028Stakawata        {
20980028Stakawata            return_ACPI_STATUS (AE_AML_INTERNAL);
21080028Stakawata        }
21180028Stakawata
21280028Stakawata        /* Creating new namespace node, should not already exist */
21380028Stakawata
21480028Stakawata        Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
21580028Stakawata                ACPI_NS_ERROR_IF_FOUND;
21680028Stakawata
21780028Stakawata        /*
21880028Stakawata         * Mark node temporary if we are executing a normal control
21980028Stakawata         * method. (Don't mark if this is a module-level code method)
22080028Stakawata         */
22180028Stakawata        if (WalkState->MethodNode &&
222121830Snjl            !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
22380028Stakawata        {
22480028Stakawata            Flags |= ACPI_NS_TEMPORARY;
22580028Stakawata        }
22680028Stakawata
22780028Stakawata        /* Enter the NameString into the namespace */
22880028Stakawata
22980028Stakawata        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
23080028Stakawata                    ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
23180028Stakawata                    Flags, WalkState, &Node);
23280028Stakawata        if (ACPI_FAILURE (Status))
23380028Stakawata        {
23480028Stakawata            ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
23580028Stakawata            return_ACPI_STATUS (Status);
23680028Stakawata        }
23780028Stakawata    }
23880028Stakawata
239    /*
240     * We could put the returned object (Node) on the object stack for later,
241     * but for now, we will put it in the "op" object that the parser uses,
242     * so we can get it again at the end of this scope.
243     */
244    Op->Common.Node = Node;
245
246    /*
247     * If there is no object attached to the node, this node was just created
248     * and we need to create the field object. Otherwise, this was a lookup
249     * of an existing node and we don't want to create the field object again.
250     */
251    ObjDesc = AcpiNsGetAttachedObject (Node);
252    if (ObjDesc)
253    {
254        return_ACPI_STATUS (AE_OK);
255    }
256
257    /*
258     * The Field definition is not fully parsed at this time.
259     * (We must save the address of the AML for the buffer and index operands)
260     */
261
262    /* Create the buffer field object */
263
264    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
265    if (!ObjDesc)
266    {
267        Status = AE_NO_MEMORY;
268        goto Cleanup;
269    }
270
271    /*
272     * Remember location in AML stream of the field unit opcode and operands --
273     * since the buffer and index operands must be evaluated.
274     */
275    SecondDesc                  = ObjDesc->Common.NextObject;
276    SecondDesc->Extra.AmlStart  = Op->Named.Data;
277    SecondDesc->Extra.AmlLength = Op->Named.Length;
278    ObjDesc->BufferField.Node   = Node;
279
280    /* Attach constructed field descriptors to parent node */
281
282    Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
283    if (ACPI_FAILURE (Status))
284    {
285        goto Cleanup;
286    }
287
288
289Cleanup:
290
291    /* Remove local reference to the object */
292
293    AcpiUtRemoveReference (ObjDesc);
294    return_ACPI_STATUS (Status);
295}
296
297
298/*******************************************************************************
299 *
300 * FUNCTION:    AcpiDsGetFieldNames
301 *
302 * PARAMETERS:  Info            - CreateField info structure
303 *  `           WalkState       - Current method state
304 *              Arg             - First parser arg for the field name list
305 *
306 * RETURN:      Status
307 *
308 * DESCRIPTION: Process all named fields in a field declaration. Names are
309 *              entered into the namespace.
310 *
311 ******************************************************************************/
312
313static ACPI_STATUS
314AcpiDsGetFieldNames (
315    ACPI_CREATE_FIELD_INFO  *Info,
316    ACPI_WALK_STATE         *WalkState,
317    ACPI_PARSE_OBJECT       *Arg)
318{
319    ACPI_STATUS             Status;
320    UINT64                  Position;
321    ACPI_PARSE_OBJECT       *Child;
322
323
324    ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
325
326
327    /* First field starts at bit zero */
328
329    Info->FieldBitPosition = 0;
330
331    /* Process all elements in the field list (of parse nodes) */
332
333    while (Arg)
334    {
335        /*
336         * Four types of field elements are handled:
337         * 1) Name - Enters a new named field into the namespace
338         * 2) Offset - specifies a bit offset
339         * 3) AccessAs - changes the access mode/attributes
340         * 4) Connection - Associate a resource template with the field
341         */
342        switch (Arg->Common.AmlOpcode)
343        {
344        case AML_INT_RESERVEDFIELD_OP:
345
346            Position = (UINT64) Info->FieldBitPosition
347                        + (UINT64) Arg->Common.Value.Size;
348
349            if (Position > ACPI_UINT32_MAX)
350            {
351                ACPI_ERROR ((AE_INFO,
352                    "Bit offset within field too large (> 0xFFFFFFFF)"));
353                return_ACPI_STATUS (AE_SUPPORT);
354            }
355
356            Info->FieldBitPosition = (UINT32) Position;
357            break;
358
359        case AML_INT_ACCESSFIELD_OP:
360        case AML_INT_EXTACCESSFIELD_OP:
361            /*
362             * Get new AccessType, AccessAttribute, and AccessLength fields
363             * -- to be used for all field units that follow, until the
364             * end-of-field or another AccessAs keyword is encountered.
365             * NOTE. These three bytes are encoded in the integer value
366             * of the parseop for convenience.
367             *
368             * In FieldFlags, preserve the flag bits other than the
369             * ACCESS_TYPE bits.
370             */
371
372            /* AccessType (ByteAcc, WordAcc, etc.) */
373
374            Info->FieldFlags = (UINT8)
375                ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
376                ((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));
377
378            /* AccessAttribute (AttribQuick, AttribByte, etc.) */
379
380            Info->Attribute = (UINT8) ((Arg->Common.Value.Integer >> 8) & 0xFF);
381
382            /* AccessLength (for serial/buffer protocols) */
383
384            Info->AccessLength = (UINT8) ((Arg->Common.Value.Integer >> 16) & 0xFF);
385            break;
386
387        case AML_INT_CONNECTION_OP:
388            /*
389             * Clear any previous connection. New connection is used for all
390             * fields that follow, similar to AccessAs
391             */
392            Info->ResourceBuffer = NULL;
393            Info->ConnectionNode = NULL;
394
395            /*
396             * A Connection() is either an actual resource descriptor (buffer)
397             * or a named reference to a resource template
398             */
399            Child = Arg->Common.Value.Arg;
400            if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)
401            {
402                Info->ResourceBuffer = Child->Named.Data;
403                Info->ResourceLength = (UINT16) Child->Named.Value.Integer;
404            }
405            else
406            {
407                /* Lookup the Connection() namepath, it should already exist */
408
409                Status = AcpiNsLookup (WalkState->ScopeInfo,
410                            Child->Common.Value.Name, ACPI_TYPE_ANY,
411                            ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
412                            WalkState, &Info->ConnectionNode);
413                if (ACPI_FAILURE (Status))
414                {
415                    ACPI_ERROR_NAMESPACE (Child->Common.Value.Name, Status);
416                    return_ACPI_STATUS (Status);
417                }
418            }
419            break;
420
421        case AML_INT_NAMEDFIELD_OP:
422
423            /* Lookup the name, it should already exist */
424
425            Status = AcpiNsLookup (WalkState->ScopeInfo,
426                        (char *) &Arg->Named.Name, Info->FieldType,
427                        ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
428                        WalkState, &Info->FieldNode);
429            if (ACPI_FAILURE (Status))
430            {
431                ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
432                return_ACPI_STATUS (Status);
433            }
434            else
435            {
436                Arg->Common.Node = Info->FieldNode;
437                Info->FieldBitLength = Arg->Common.Value.Size;
438
439                /*
440                 * If there is no object attached to the node, this node was
441                 * just created and we need to create the field object.
442                 * Otherwise, this was a lookup of an existing node and we
443                 * don't want to create the field object again.
444                 */
445                if (!AcpiNsGetAttachedObject (Info->FieldNode))
446                {
447                    Status = AcpiExPrepFieldValue (Info);
448                    if (ACPI_FAILURE (Status))
449                    {
450                        return_ACPI_STATUS (Status);
451                    }
452                }
453            }
454
455            /* Keep track of bit position for the next field */
456
457            Position = (UINT64) Info->FieldBitPosition
458                        + (UINT64) Arg->Common.Value.Size;
459
460            if (Position > ACPI_UINT32_MAX)
461            {
462                ACPI_ERROR ((AE_INFO,
463                    "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
464                    ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
465                return_ACPI_STATUS (AE_SUPPORT);
466            }
467
468            Info->FieldBitPosition += Info->FieldBitLength;
469            break;
470
471        default:
472
473            ACPI_ERROR ((AE_INFO,
474                "Invalid opcode in field list: 0x%X", Arg->Common.AmlOpcode));
475            return_ACPI_STATUS (AE_AML_BAD_OPCODE);
476        }
477
478        Arg = Arg->Common.Next;
479    }
480
481    return_ACPI_STATUS (AE_OK);
482}
483
484
485/*******************************************************************************
486 *
487 * FUNCTION:    AcpiDsCreateField
488 *
489 * PARAMETERS:  Op              - Op containing the Field definition and args
490 *              RegionNode      - Object for the containing Operation Region
491 *  `           WalkState       - Current method state
492 *
493 * RETURN:      Status
494 *
495 * DESCRIPTION: Create a new field in the specified operation region
496 *
497 ******************************************************************************/
498
499ACPI_STATUS
500AcpiDsCreateField (
501    ACPI_PARSE_OBJECT       *Op,
502    ACPI_NAMESPACE_NODE     *RegionNode,
503    ACPI_WALK_STATE         *WalkState)
504{
505    ACPI_STATUS             Status;
506    ACPI_PARSE_OBJECT       *Arg;
507    ACPI_CREATE_FIELD_INFO  Info;
508
509
510    ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
511
512
513    /* First arg is the name of the parent OpRegion (must already exist) */
514
515    Arg = Op->Common.Value.Arg;
516
517    if (!RegionNode)
518    {
519        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
520                        ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
521                        ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
522#ifdef ACPI_ASL_COMPILER
523        Status = AcpiDsCreateExternalRegion (Status, Arg,
524            Arg->Common.Value.Name, WalkState, &RegionNode);
525#endif
526        if (ACPI_FAILURE (Status))
527        {
528            ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
529            return_ACPI_STATUS (Status);
530        }
531    }
532
533    ACPI_MEMSET (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));
534
535    /* Second arg is the field flags */
536
537    Arg = Arg->Common.Next;
538    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
539    Info.Attribute = 0;
540
541    /* Each remaining arg is a Named Field */
542
543    Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
544    Info.RegionNode = RegionNode;
545
546    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
547    return_ACPI_STATUS (Status);
548}
549
550
551/*******************************************************************************
552 *
553 * FUNCTION:    AcpiDsInitFieldObjects
554 *
555 * PARAMETERS:  Op              - Op containing the Field definition and args
556 *  `           WalkState       - Current method state
557 *
558 * RETURN:      Status
559 *
560 * DESCRIPTION: For each "Field Unit" name in the argument list that is
561 *              part of the field declaration, enter the name into the
562 *              namespace.
563 *
564 ******************************************************************************/
565
566ACPI_STATUS
567AcpiDsInitFieldObjects (
568    ACPI_PARSE_OBJECT       *Op,
569    ACPI_WALK_STATE         *WalkState)
570{
571    ACPI_STATUS             Status;
572    ACPI_PARSE_OBJECT       *Arg = NULL;
573    ACPI_NAMESPACE_NODE     *Node;
574    UINT8                   Type = 0;
575    UINT32                  Flags;
576
577
578    ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
579
580
581    /* Execute flag should always be set when this function is entered */
582
583    if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
584    {
585        if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
586        {
587            /* BankField Op is deferred, just return OK */
588
589            return_ACPI_STATUS (AE_OK);
590        }
591
592        return_ACPI_STATUS (AE_AML_INTERNAL);
593    }
594
595    /*
596     * Get the FieldList argument for this opcode. This is the start of the
597     * list of field elements.
598     */
599    switch (WalkState->Opcode)
600    {
601    case AML_FIELD_OP:
602        Arg = AcpiPsGetArg (Op, 2);
603        Type = ACPI_TYPE_LOCAL_REGION_FIELD;
604        break;
605
606    case AML_BANK_FIELD_OP:
607        Arg = AcpiPsGetArg (Op, 4);
608        Type = ACPI_TYPE_LOCAL_BANK_FIELD;
609        break;
610
611    case AML_INDEX_FIELD_OP:
612        Arg = AcpiPsGetArg (Op, 3);
613        Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
614        break;
615
616    default:
617        return_ACPI_STATUS (AE_BAD_PARAMETER);
618    }
619
620    /* Creating new namespace node(s), should not already exist */
621
622    Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
623            ACPI_NS_ERROR_IF_FOUND;
624
625    /*
626     * Mark node(s) temporary if we are executing a normal control
627     * method. (Don't mark if this is a module-level code method)
628     */
629    if (WalkState->MethodNode &&
630        !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
631    {
632        Flags |= ACPI_NS_TEMPORARY;
633    }
634
635    /*
636     * Walk the list of entries in the FieldList
637     * Note: FieldList can be of zero length. In this case, Arg will be NULL.
638     */
639    while (Arg)
640    {
641        /*
642         * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
643         * in the field names in order to enter them into the namespace.
644         */
645        if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
646        {
647            Status = AcpiNsLookup (WalkState->ScopeInfo,
648                        (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
649                        Flags, WalkState, &Node);
650            if (ACPI_FAILURE (Status))
651            {
652                ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
653                if (Status != AE_ALREADY_EXISTS)
654                {
655                    return_ACPI_STATUS (Status);
656                }
657
658                /* Name already exists, just ignore this error */
659
660                Status = AE_OK;
661            }
662
663            Arg->Common.Node = Node;
664        }
665
666        /* Get the next field element in the list */
667
668        Arg = Arg->Common.Next;
669    }
670
671    return_ACPI_STATUS (AE_OK);
672}
673
674
675/*******************************************************************************
676 *
677 * FUNCTION:    AcpiDsCreateBankField
678 *
679 * PARAMETERS:  Op              - Op containing the Field definition and args
680 *              RegionNode      - Object for the containing Operation Region
681 *              WalkState       - Current method state
682 *
683 * RETURN:      Status
684 *
685 * DESCRIPTION: Create a new bank field in the specified operation region
686 *
687 ******************************************************************************/
688
689ACPI_STATUS
690AcpiDsCreateBankField (
691    ACPI_PARSE_OBJECT       *Op,
692    ACPI_NAMESPACE_NODE     *RegionNode,
693    ACPI_WALK_STATE         *WalkState)
694{
695    ACPI_STATUS             Status;
696    ACPI_PARSE_OBJECT       *Arg;
697    ACPI_CREATE_FIELD_INFO  Info;
698
699
700    ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
701
702
703    /* First arg is the name of the parent OpRegion (must already exist) */
704
705    Arg = Op->Common.Value.Arg;
706    if (!RegionNode)
707    {
708        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
709                        ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
710                        ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
711#ifdef ACPI_ASL_COMPILER
712        Status = AcpiDsCreateExternalRegion (Status, Arg,
713            Arg->Common.Value.Name, WalkState, &RegionNode);
714#endif
715        if (ACPI_FAILURE (Status))
716        {
717            ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
718            return_ACPI_STATUS (Status);
719        }
720    }
721
722    /* Second arg is the Bank Register (Field) (must already exist) */
723
724    Arg = Arg->Common.Next;
725    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
726                    ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
727                    ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
728    if (ACPI_FAILURE (Status))
729    {
730        ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
731        return_ACPI_STATUS (Status);
732    }
733
734    /*
735     * Third arg is the BankValue
736     * This arg is a TermArg, not a constant
737     * It will be evaluated later, by AcpiDsEvalBankFieldOperands
738     */
739    Arg = Arg->Common.Next;
740
741    /* Fourth arg is the field flags */
742
743    Arg = Arg->Common.Next;
744    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
745
746    /* Each remaining arg is a Named Field */
747
748    Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
749    Info.RegionNode = RegionNode;
750
751    /*
752     * Use Info.DataRegisterNode to store BankField Op
753     * It's safe because DataRegisterNode will never be used when create bank field
754     * We store AmlStart and AmlLength in the BankField Op for late evaluation
755     * Used in AcpiExPrepFieldValue(Info)
756     *
757     * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like "void *ParentOp"?
758     */
759    Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
760
761    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
762    return_ACPI_STATUS (Status);
763}
764
765
766/*******************************************************************************
767 *
768 * FUNCTION:    AcpiDsCreateIndexField
769 *
770 * PARAMETERS:  Op              - Op containing the Field definition and args
771 *              RegionNode      - Object for the containing Operation Region
772 *  `           WalkState       - Current method state
773 *
774 * RETURN:      Status
775 *
776 * DESCRIPTION: Create a new index field in the specified operation region
777 *
778 ******************************************************************************/
779
780ACPI_STATUS
781AcpiDsCreateIndexField (
782    ACPI_PARSE_OBJECT       *Op,
783    ACPI_NAMESPACE_NODE     *RegionNode,
784    ACPI_WALK_STATE         *WalkState)
785{
786    ACPI_STATUS             Status;
787    ACPI_PARSE_OBJECT       *Arg;
788    ACPI_CREATE_FIELD_INFO  Info;
789
790
791    ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
792
793
794    /* First arg is the name of the Index register (must already exist) */
795
796    Arg = Op->Common.Value.Arg;
797    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
798                    ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
799                    ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
800    if (ACPI_FAILURE (Status))
801    {
802        ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
803        return_ACPI_STATUS (Status);
804    }
805
806    /* Second arg is the data register (must already exist) */
807
808    Arg = Arg->Common.Next;
809    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
810                    ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
811                    ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
812    if (ACPI_FAILURE (Status))
813    {
814        ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
815        return_ACPI_STATUS (Status);
816    }
817
818    /* Next arg is the field flags */
819
820    Arg = Arg->Common.Next;
821    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
822
823    /* Each remaining arg is a Named Field */
824
825    Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
826    Info.RegionNode = RegionNode;
827
828    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
829    return_ACPI_STATUS (Status);
830}
831