exprep.c revision 250838
1178479Sjb/******************************************************************************
2178479Sjb *
3178479Sjb * Module Name: exprep - ACPI AML (p-code) execution - field prep utilities
4178479Sjb *
5178479Sjb *****************************************************************************/
6178479Sjb
7178479Sjb/*
8178479Sjb * Copyright (C) 2000 - 2013, Intel Corp.
9178479Sjb * All rights reserved.
10178479Sjb *
11178479Sjb * Redistribution and use in source and binary forms, with or without
12178479Sjb * modification, are permitted provided that the following conditions
13178479Sjb * are met:
14178479Sjb * 1. Redistributions of source code must retain the above copyright
15178479Sjb *    notice, this list of conditions, and the following disclaimer,
16178479Sjb *    without modification.
17178479Sjb * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18178479Sjb *    substantially similar to the "NO WARRANTY" disclaimer below
19178479Sjb *    ("Disclaimer") and any redistribution must be conditioned upon
20178479Sjb *    including a substantially similar Disclaimer requirement for further
21178479Sjb *    binary redistribution.
22178479Sjb * 3. Neither the names of the above-listed copyright holders nor the names
23178479Sjb *    of any contributors may be used to endorse or promote products derived
24178479Sjb *    from this software without specific prior written permission.
25178479Sjb *
26178479Sjb * Alternatively, this software may be distributed under the terms of the
27296816Spfg * GNU General Public License ("GPL") version 2 as published by the Free
28296816Spfg * Software Foundation.
29296816Spfg *
30296816Spfg * NO WARRANTY
31178479Sjb * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32178479Sjb * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33178479Sjb * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34178479Sjb * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35178479Sjb * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36178479Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37178479Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38178479Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39178479Sjb * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40178479Sjb * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41178479Sjb * POSSIBILITY OF SUCH DAMAGES.
42178479Sjb */
43178479Sjb
44178479Sjb#define __EXPREP_C__
45178479Sjb
46178479Sjb#include <contrib/dev/acpica/include/acpi.h>
47178479Sjb#include <contrib/dev/acpica/include/accommon.h>
48178479Sjb#include <contrib/dev/acpica/include/acinterp.h>
49178479Sjb#include <contrib/dev/acpica/include/amlcode.h>
50178479Sjb#include <contrib/dev/acpica/include/acnamesp.h>
51178479Sjb#include <contrib/dev/acpica/include/acdispat.h>
52178479Sjb
53178479Sjb
54178479Sjb#define _COMPONENT          ACPI_EXECUTER
55178479Sjb        ACPI_MODULE_NAME    ("exprep")
56178479Sjb
57178479Sjb/* Local prototypes */
58178479Sjb
59178479Sjbstatic UINT32
60178479SjbAcpiExDecodeFieldAccess (
61178479Sjb    ACPI_OPERAND_OBJECT     *ObjDesc,
62178479Sjb    UINT8                   FieldFlags,
63178479Sjb    UINT32                  *ReturnByteAlignment);
64178479Sjb
65178479Sjb
66178479Sjb#ifdef ACPI_UNDER_DEVELOPMENT
67178479Sjb
68178479Sjbstatic UINT32
69178479SjbAcpiExGenerateAccess (
70178479Sjb    UINT32                  FieldBitOffset,
71178479Sjb    UINT32                  FieldBitLength,
72178479Sjb    UINT32                  RegionLength);
73178479Sjb
74178479Sjb/*******************************************************************************
75178479Sjb *
76178479Sjb * FUNCTION:    AcpiExGenerateAccess
77296816Spfg *
78178479Sjb * PARAMETERS:  FieldBitOffset      - Start of field within parent region/buffer
79178479Sjb *              FieldBitLength      - Length of field in bits
80178479Sjb *              RegionLength        - Length of parent in bytes
81178479Sjb *
82178479Sjb * RETURN:      Field granularity (8, 16, 32 or 64) and
83178479Sjb *              ByteAlignment (1, 2, 3, or 4)
84178479Sjb *
85178479Sjb * DESCRIPTION: Generate an optimal access width for fields defined with the
86178479Sjb *              AnyAcc keyword.
87178479Sjb *
88178479Sjb * NOTE: Need to have the RegionLength in order to check for boundary
89178479Sjb *       conditions (end-of-region). However, the RegionLength is a deferred
90178479Sjb *       operation. Therefore, to complete this implementation, the generation
91178479Sjb *       of this access width must be deferred until the region length has
92178479Sjb *       been evaluated.
93178479Sjb *
94178479Sjb ******************************************************************************/
95178479Sjb
96178479Sjbstatic UINT32
97178479SjbAcpiExGenerateAccess (
98178479Sjb    UINT32                  FieldBitOffset,
99178479Sjb    UINT32                  FieldBitLength,
100178479Sjb    UINT32                  RegionLength)
101178479Sjb{
102178479Sjb    UINT32                  FieldByteLength;
103178479Sjb    UINT32                  FieldByteOffset;
104178479Sjb    UINT32                  FieldByteEndOffset;
105178479Sjb    UINT32                  AccessByteWidth;
106178479Sjb    UINT32                  FieldStartOffset;
107178479Sjb    UINT32                  FieldEndOffset;
108178479Sjb    UINT32                  MinimumAccessWidth = 0xFFFFFFFF;
109178479Sjb    UINT32                  MinimumAccesses = 0xFFFFFFFF;
110178479Sjb    UINT32                  Accesses;
111178479Sjb
112178479Sjb
113178479Sjb    ACPI_FUNCTION_TRACE (ExGenerateAccess);
114178479Sjb
115178479Sjb
116178479Sjb    /* Round Field start offset and length to "minimal" byte boundaries */
117178479Sjb
118178479Sjb    FieldByteOffset    = ACPI_DIV_8 (ACPI_ROUND_DOWN (FieldBitOffset, 8));
119178479Sjb    FieldByteEndOffset = ACPI_DIV_8 (ACPI_ROUND_UP   (FieldBitLength +
120178479Sjb                                                      FieldBitOffset, 8));
121178479Sjb    FieldByteLength    = FieldByteEndOffset - FieldByteOffset;
122178479Sjb
123178479Sjb    ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
124178479Sjb        "Bit length %u, Bit offset %u\n",
125178479Sjb        FieldBitLength, FieldBitOffset));
126178479Sjb
127178479Sjb    ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
128178479Sjb        "Byte Length %u, Byte Offset %u, End Offset %u\n",
129178479Sjb        FieldByteLength, FieldByteOffset, FieldByteEndOffset));
130178479Sjb
131178479Sjb    /*
132178479Sjb     * Iterative search for the maximum access width that is both aligned
133178479Sjb     * and does not go beyond the end of the region
134178479Sjb     *
135178479Sjb     * Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes)
136178479Sjb     */
137178479Sjb    for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1)
138178479Sjb    {
139178479Sjb        /*
140178479Sjb         * 1) Round end offset up to next access boundary and make sure that
141178479Sjb         *    this does not go beyond the end of the parent region.
142178479Sjb         * 2) When the Access width is greater than the FieldByteLength, we
143178479Sjb         *    are done. (This does not optimize for the perfectly aligned
144178479Sjb         *    case yet).
145178479Sjb         */
146178479Sjb        if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <= RegionLength)
147178479Sjb        {
148178479Sjb            FieldStartOffset =
149178479Sjb                ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) /
150178479Sjb                AccessByteWidth;
151178479Sjb
152178479Sjb            FieldEndOffset =
153178479Sjb                ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset),
154178479Sjb                    AccessByteWidth) / AccessByteWidth;
155178479Sjb
156178479Sjb            Accesses = FieldEndOffset - FieldStartOffset;
157178479Sjb
158178479Sjb            ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
159178479Sjb                "AccessWidth %u end is within region\n", AccessByteWidth));
160178479Sjb
161178479Sjb            ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
162178479Sjb                "Field Start %u, Field End %u -- requires %u accesses\n",
163178479Sjb                FieldStartOffset, FieldEndOffset, Accesses));
164178479Sjb
165178479Sjb            /* Single access is optimal */
166178479Sjb
167178479Sjb            if (Accesses <= 1)
168178479Sjb            {
169178479Sjb                ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
170178479Sjb                    "Entire field can be accessed with one operation of size %u\n",
171178479Sjb                    AccessByteWidth));
172178479Sjb                return_VALUE (AccessByteWidth);
173178479Sjb            }
174178479Sjb
175178479Sjb            /*
176178479Sjb             * Fits in the region, but requires more than one read/write.
177178479Sjb             * try the next wider access on next iteration
178178479Sjb             */
179178479Sjb            if (Accesses < MinimumAccesses)
180178479Sjb            {
181178479Sjb                MinimumAccesses    = Accesses;
182178479Sjb                MinimumAccessWidth = AccessByteWidth;
183178479Sjb            }
184178479Sjb        }
185178479Sjb        else
186178479Sjb        {
187178479Sjb            ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
188178479Sjb                "AccessWidth %u end is NOT within region\n", AccessByteWidth));
189178479Sjb            if (AccessByteWidth == 1)
190178479Sjb            {
191178479Sjb                ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
192178479Sjb                    "Field goes beyond end-of-region!\n"));
193178479Sjb
194178479Sjb                /* Field does not fit in the region at all */
195178479Sjb
196178479Sjb                return_VALUE (0);
197178479Sjb            }
198178479Sjb
199178479Sjb            /*
200178479Sjb             * This width goes beyond the end-of-region, back off to
201178479Sjb             * previous access
202178479Sjb             */
203178479Sjb            ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
204178479Sjb                "Backing off to previous optimal access width of %u\n",
205178479Sjb                MinimumAccessWidth));
206178479Sjb            return_VALUE (MinimumAccessWidth);
207178479Sjb        }
208178479Sjb    }
209178479Sjb
210178479Sjb    /*
211178479Sjb     * Could not read/write field with one operation,
212178479Sjb     * just use max access width
213178479Sjb     */
214178479Sjb    ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
215178479Sjb        "Cannot access field in one operation, using width 8\n"));
216178479Sjb    return_VALUE (8);
217178479Sjb}
218178479Sjb#endif /* ACPI_UNDER_DEVELOPMENT */
219178479Sjb
220178479Sjb
221178479Sjb/*******************************************************************************
222178479Sjb *
223178479Sjb * FUNCTION:    AcpiExDecodeFieldAccess
224178479Sjb *
225178479Sjb * PARAMETERS:  ObjDesc             - Field object
226178479Sjb *              FieldFlags          - Encoded fieldflags (contains access bits)
227178479Sjb *              ReturnByteAlignment - Where the byte alignment is returned
228178479Sjb *
229178479Sjb * RETURN:      Field granularity (8, 16, 32 or 64) and
230178479Sjb *              ByteAlignment (1, 2, 3, or 4)
231178479Sjb *
232178479Sjb * DESCRIPTION: Decode the AccessType bits of a field definition.
233178479Sjb *
234178479Sjb ******************************************************************************/
235178479Sjb
236178479Sjbstatic UINT32
237178479SjbAcpiExDecodeFieldAccess (
238178479Sjb    ACPI_OPERAND_OBJECT     *ObjDesc,
239178479Sjb    UINT8                   FieldFlags,
240178479Sjb    UINT32                  *ReturnByteAlignment)
241178479Sjb{
242178479Sjb    UINT32                  Access;
243178479Sjb    UINT32                  ByteAlignment;
244178479Sjb    UINT32                  BitLength;
245178479Sjb
246178479Sjb
247178479Sjb    ACPI_FUNCTION_TRACE (ExDecodeFieldAccess);
248178479Sjb
249178479Sjb
250178479Sjb    Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK);
251178479Sjb
252178479Sjb    switch (Access)
253178479Sjb    {
254178479Sjb    case AML_FIELD_ACCESS_ANY:
255178479Sjb
256178479Sjb#ifdef ACPI_UNDER_DEVELOPMENT
257178479Sjb        ByteAlignment =
258178479Sjb            AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset,
259178479Sjb                ObjDesc->CommonField.BitLength,
260178479Sjb                0xFFFFFFFF /* Temp until we pass RegionLength as parameter */);
261178479Sjb        BitLength = ByteAlignment * 8;
262178479Sjb#endif
263178479Sjb
264178479Sjb        ByteAlignment = 1;
265178479Sjb        BitLength = 8;
266178479Sjb        break;
267178479Sjb
268178479Sjb    case AML_FIELD_ACCESS_BYTE:
269178479Sjb    case AML_FIELD_ACCESS_BUFFER:   /* ACPI 2.0 (SMBus Buffer) */
270178479Sjb
271178479Sjb        ByteAlignment = 1;
272178479Sjb        BitLength     = 8;
273178479Sjb        break;
274178479Sjb
275178479Sjb    case AML_FIELD_ACCESS_WORD:
276178479Sjb
277178479Sjb        ByteAlignment = 2;
278178479Sjb        BitLength     = 16;
279178479Sjb        break;
280178479Sjb
281178479Sjb    case AML_FIELD_ACCESS_DWORD:
282178479Sjb
283178479Sjb        ByteAlignment = 4;
284178479Sjb        BitLength     = 32;
285178479Sjb        break;
286178479Sjb
287178479Sjb    case AML_FIELD_ACCESS_QWORD:    /* ACPI 2.0 */
288178479Sjb
289178479Sjb        ByteAlignment = 8;
290178479Sjb        BitLength     = 64;
291178479Sjb        break;
292178479Sjb
293178479Sjb    default:
294178479Sjb
295178479Sjb        /* Invalid field access type */
296178479Sjb
297        ACPI_ERROR ((AE_INFO,
298            "Unknown field access type 0x%X",
299            Access));
300        return_UINT32 (0);
301    }
302
303    if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
304    {
305        /*
306         * BufferField access can be on any byte boundary, so the
307         * ByteAlignment is always 1 byte -- regardless of any ByteAlignment
308         * implied by the field access type.
309         */
310        ByteAlignment = 1;
311    }
312
313    *ReturnByteAlignment = ByteAlignment;
314    return_UINT32 (BitLength);
315}
316
317
318/*******************************************************************************
319 *
320 * FUNCTION:    AcpiExPrepCommonFieldObject
321 *
322 * PARAMETERS:  ObjDesc             - The field object
323 *              FieldFlags          - Access, LockRule, and UpdateRule.
324 *                                    The format of a FieldFlag is described
325 *                                    in the ACPI specification
326 *              FieldAttribute      - Special attributes (not used)
327 *              FieldBitPosition    - Field start position
328 *              FieldBitLength      - Field length in number of bits
329 *
330 * RETURN:      Status
331 *
332 * DESCRIPTION: Initialize the areas of the field object that are common
333 *              to the various types of fields. Note: This is very "sensitive"
334 *              code because we are solving the general case for field
335 *              alignment.
336 *
337 ******************************************************************************/
338
339ACPI_STATUS
340AcpiExPrepCommonFieldObject (
341    ACPI_OPERAND_OBJECT     *ObjDesc,
342    UINT8                   FieldFlags,
343    UINT8                   FieldAttribute,
344    UINT32                  FieldBitPosition,
345    UINT32                  FieldBitLength)
346{
347    UINT32                  AccessBitWidth;
348    UINT32                  ByteAlignment;
349    UINT32                  NearestByteAddress;
350
351
352    ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject);
353
354
355    /*
356     * Note: the structure being initialized is the
357     * ACPI_COMMON_FIELD_INFO;  No structure fields outside of the common
358     * area are initialized by this procedure.
359     */
360    ObjDesc->CommonField.FieldFlags = FieldFlags;
361    ObjDesc->CommonField.Attribute  = FieldAttribute;
362    ObjDesc->CommonField.BitLength  = FieldBitLength;
363
364    /*
365     * Decode the access type so we can compute offsets. The access type gives
366     * two pieces of information - the width of each field access and the
367     * necessary ByteAlignment (address granularity) of the access.
368     *
369     * For AnyAcc, the AccessBitWidth is the largest width that is both
370     * necessary and possible in an attempt to access the whole field in one
371     * I/O operation. However, for AnyAcc, the ByteAlignment is always one
372     * byte.
373     *
374     * For all Buffer Fields, the ByteAlignment is always one byte.
375     *
376     * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is
377     * the same (equivalent) as the ByteAlignment.
378     */
379    AccessBitWidth = AcpiExDecodeFieldAccess (ObjDesc, FieldFlags,
380                        &ByteAlignment);
381    if (!AccessBitWidth)
382    {
383        return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
384    }
385
386    /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */
387
388    ObjDesc->CommonField.AccessByteWidth = (UINT8)
389        ACPI_DIV_8 (AccessBitWidth);
390
391    /*
392     * BaseByteOffset is the address of the start of the field within the
393     * region. It is the byte address of the first *datum* (field-width data
394     * unit) of the field. (i.e., the first datum that contains at least the
395     * first *bit* of the field.)
396     *
397     * Note: ByteAlignment is always either equal to the AccessBitWidth or 8
398     * (Byte access), and it defines the addressing granularity of the parent
399     * region or buffer.
400     */
401    NearestByteAddress =
402        ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition);
403    ObjDesc->CommonField.BaseByteOffset = (UINT32)
404        ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment);
405
406    /*
407     * StartFieldBitOffset is the offset of the first bit of the field within
408     * a field datum.
409     */
410    ObjDesc->CommonField.StartFieldBitOffset = (UINT8)
411        (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset));
412
413    return_ACPI_STATUS (AE_OK);
414}
415
416
417/*******************************************************************************
418 *
419 * FUNCTION:    AcpiExPrepFieldValue
420 *
421 * PARAMETERS:  Info    - Contains all field creation info
422 *
423 * RETURN:      Status
424 *
425 * DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a
426 *              subtype of DefField and connect it to the parent Node.
427 *
428 ******************************************************************************/
429
430ACPI_STATUS
431AcpiExPrepFieldValue (
432    ACPI_CREATE_FIELD_INFO  *Info)
433{
434    ACPI_OPERAND_OBJECT     *ObjDesc;
435    ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
436    ACPI_STATUS             Status;
437    UINT32                  AccessByteWidth;
438    UINT32                  Type;
439
440
441    ACPI_FUNCTION_TRACE (ExPrepFieldValue);
442
443
444    /* Parameter validation */
445
446    if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD)
447    {
448        if (!Info->RegionNode)
449        {
450            ACPI_ERROR ((AE_INFO, "Null RegionNode"));
451            return_ACPI_STATUS (AE_AML_NO_OPERAND);
452        }
453
454        Type = AcpiNsGetType (Info->RegionNode);
455        if (Type != ACPI_TYPE_REGION)
456        {
457            ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)",
458                Type, AcpiUtGetTypeName (Type)));
459
460            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
461        }
462    }
463
464    /* Allocate a new field object */
465
466    ObjDesc = AcpiUtCreateInternalObject (Info->FieldType);
467    if (!ObjDesc)
468    {
469        return_ACPI_STATUS (AE_NO_MEMORY);
470    }
471
472    /* Initialize areas of the object that are common to all fields */
473
474    ObjDesc->CommonField.Node = Info->FieldNode;
475    Status = AcpiExPrepCommonFieldObject (ObjDesc,
476                Info->FieldFlags, Info->Attribute,
477                Info->FieldBitPosition, Info->FieldBitLength);
478    if (ACPI_FAILURE (Status))
479    {
480        AcpiUtDeleteObjectDesc (ObjDesc);
481        return_ACPI_STATUS (Status);
482    }
483
484    /* Initialize areas of the object that are specific to the field type */
485
486    switch (Info->FieldType)
487    {
488    case ACPI_TYPE_LOCAL_REGION_FIELD:
489
490        ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode);
491
492        /* Fields specific to GenericSerialBus fields */
493
494        ObjDesc->Field.AccessLength = Info->AccessLength;
495
496        if (Info->ConnectionNode)
497        {
498            SecondDesc = Info->ConnectionNode->Object;
499            if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID))
500            {
501                Status = AcpiDsGetBufferArguments (SecondDesc);
502                if (ACPI_FAILURE (Status))
503                {
504                    AcpiUtDeleteObjectDesc (ObjDesc);
505                    return_ACPI_STATUS (Status);
506                }
507            }
508
509            ObjDesc->Field.ResourceBuffer = SecondDesc->Buffer.Pointer;
510            ObjDesc->Field.ResourceLength = (UINT16) SecondDesc->Buffer.Length;
511        }
512        else if (Info->ResourceBuffer)
513        {
514            ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer;
515            ObjDesc->Field.ResourceLength = Info->ResourceLength;
516        }
517
518        /* Allow full data read from EC address space */
519
520        if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
521            (ObjDesc->CommonField.BitLength > 8))
522        {
523            AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES (
524                ObjDesc->CommonField.BitLength);
525
526            /* Maximum byte width supported is 255 */
527
528            if (AccessByteWidth < 256)
529            {
530                ObjDesc->CommonField.AccessByteWidth = (UINT8) AccessByteWidth;
531            }
532        }
533
534        /* An additional reference for the container */
535
536        AcpiUtAddReference (ObjDesc->Field.RegionObj);
537
538        ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
539            "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",
540            ObjDesc->Field.StartFieldBitOffset, ObjDesc->Field.BaseByteOffset,
541            ObjDesc->Field.AccessByteWidth, ObjDesc->Field.RegionObj));
542        break;
543
544    case ACPI_TYPE_LOCAL_BANK_FIELD:
545
546        ObjDesc->BankField.Value = Info->BankValue;
547        ObjDesc->BankField.RegionObj =
548            AcpiNsGetAttachedObject (Info->RegionNode);
549        ObjDesc->BankField.BankObj =
550            AcpiNsGetAttachedObject (Info->RegisterNode);
551
552        /* An additional reference for the attached objects */
553
554        AcpiUtAddReference (ObjDesc->BankField.RegionObj);
555        AcpiUtAddReference (ObjDesc->BankField.BankObj);
556
557        ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
558            "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",
559            ObjDesc->BankField.StartFieldBitOffset,
560            ObjDesc->BankField.BaseByteOffset,
561            ObjDesc->Field.AccessByteWidth,
562            ObjDesc->BankField.RegionObj,
563            ObjDesc->BankField.BankObj));
564
565        /*
566         * Remember location in AML stream of the field unit
567         * opcode and operands -- since the BankValue
568         * operands must be evaluated.
569         */
570        SecondDesc = ObjDesc->Common.NextObject;
571        SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
572            Info->DataRegisterNode)->Named.Data;
573        SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
574            Info->DataRegisterNode)->Named.Length;
575
576        break;
577
578    case ACPI_TYPE_LOCAL_INDEX_FIELD:
579
580        /* Get the Index and Data registers */
581
582        ObjDesc->IndexField.IndexObj =
583            AcpiNsGetAttachedObject (Info->RegisterNode);
584        ObjDesc->IndexField.DataObj =
585            AcpiNsGetAttachedObject (Info->DataRegisterNode);
586
587        if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj)
588        {
589            ACPI_ERROR ((AE_INFO, "Null Index Object during field prep"));
590            AcpiUtDeleteObjectDesc (ObjDesc);
591            return_ACPI_STATUS (AE_AML_INTERNAL);
592        }
593
594        /* An additional reference for the attached objects */
595
596        AcpiUtAddReference (ObjDesc->IndexField.DataObj);
597        AcpiUtAddReference (ObjDesc->IndexField.IndexObj);
598
599        /*
600         * April 2006: Changed to match MS behavior
601         *
602         * The value written to the Index register is the byte offset of the
603         * target field in units of the granularity of the IndexField
604         *
605         * Previously, the value was calculated as an index in terms of the
606         * width of the Data register, as below:
607         *
608         *      ObjDesc->IndexField.Value = (UINT32)
609         *          (Info->FieldBitPosition / ACPI_MUL_8 (
610         *              ObjDesc->Field.AccessByteWidth));
611         *
612         * February 2006: Tried value as a byte offset:
613         *      ObjDesc->IndexField.Value = (UINT32)
614         *          ACPI_DIV_8 (Info->FieldBitPosition);
615         */
616        ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN (
617            ACPI_DIV_8 (Info->FieldBitPosition),
618            ObjDesc->IndexField.AccessByteWidth);
619
620        ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
621            "IndexField: BitOff %X, Off %X, Value %X, Gran %X, Index %p, Data %p\n",
622            ObjDesc->IndexField.StartFieldBitOffset,
623            ObjDesc->IndexField.BaseByteOffset,
624            ObjDesc->IndexField.Value,
625            ObjDesc->Field.AccessByteWidth,
626            ObjDesc->IndexField.IndexObj,
627            ObjDesc->IndexField.DataObj));
628        break;
629
630    default:
631
632        /* No other types should get here */
633
634        break;
635    }
636
637    /*
638     * Store the constructed descriptor (ObjDesc) into the parent Node,
639     * preserving the current type of that NamedObj.
640     */
641    Status = AcpiNsAttachObject (Info->FieldNode, ObjDesc,
642                AcpiNsGetType (Info->FieldNode));
643
644    ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Set NamedObj %p [%4.4s], ObjDesc %p\n",
645        Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc));
646
647    /* Remove local reference to the object */
648
649    AcpiUtRemoveReference (ObjDesc);
650    return_ACPI_STATUS (Status);
651}
652