xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/executer/exprep.c (revision 97dfeb96704e5dbc5bec32ad7b21379d0125e031)
1 /******************************************************************************
2  *
3  * Module Name: exprep - ACPI AML field prep utilities
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2016, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115 
116 #include "acpi.h"
117 #include "accommon.h"
118 #include "acinterp.h"
119 #include "amlcode.h"
120 #include "acnamesp.h"
121 #include "acdispat.h"
122 
123 
124 #define _COMPONENT          ACPI_EXECUTER
125         ACPI_MODULE_NAME    ("exprep")
126 
127 /* Local prototypes */
128 
129 static UINT32
130 AcpiExDecodeFieldAccess (
131     ACPI_OPERAND_OBJECT     *ObjDesc,
132     UINT8                   FieldFlags,
133     UINT32                  *ReturnByteAlignment);
134 
135 
136 #ifdef ACPI_UNDER_DEVELOPMENT
137 
138 static UINT32
139 AcpiExGenerateAccess (
140     UINT32                  FieldBitOffset,
141     UINT32                  FieldBitLength,
142     UINT32                  RegionLength);
143 
144 
145 /*******************************************************************************
146  *
147  * FUNCTION:    AcpiExGenerateAccess
148  *
149  * PARAMETERS:  FieldBitOffset      - Start of field within parent region/buffer
150  *              FieldBitLength      - Length of field in bits
151  *              RegionLength        - Length of parent in bytes
152  *
153  * RETURN:      Field granularity (8, 16, 32 or 64) and
154  *              ByteAlignment (1, 2, 3, or 4)
155  *
156  * DESCRIPTION: Generate an optimal access width for fields defined with the
157  *              AnyAcc keyword.
158  *
159  * NOTE: Need to have the RegionLength in order to check for boundary
160  *       conditions (end-of-region). However, the RegionLength is a deferred
161  *       operation. Therefore, to complete this implementation, the generation
162  *       of this access width must be deferred until the region length has
163  *       been evaluated.
164  *
165  ******************************************************************************/
166 
167 static UINT32
168 AcpiExGenerateAccess (
169     UINT32                  FieldBitOffset,
170     UINT32                  FieldBitLength,
171     UINT32                  RegionLength)
172 {
173     UINT32                  FieldByteLength;
174     UINT32                  FieldByteOffset;
175     UINT32                  FieldByteEndOffset;
176     UINT32                  AccessByteWidth;
177     UINT32                  FieldStartOffset;
178     UINT32                  FieldEndOffset;
179     UINT32                  MinimumAccessWidth = 0xFFFFFFFF;
180     UINT32                  MinimumAccesses = 0xFFFFFFFF;
181     UINT32                  Accesses;
182 
183 
184     ACPI_FUNCTION_TRACE (ExGenerateAccess);
185 
186 
187     /* Round Field start offset and length to "minimal" byte boundaries */
188 
189     FieldByteOffset = ACPI_DIV_8 (
190         ACPI_ROUND_DOWN (FieldBitOffset, 8));
191 
192     FieldByteEndOffset = ACPI_DIV_8 (
193         ACPI_ROUND_UP (FieldBitLength + FieldBitOffset, 8));
194 
195     FieldByteLength = FieldByteEndOffset - FieldByteOffset;
196 
197     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
198         "Bit length %u, Bit offset %u\n",
199         FieldBitLength, FieldBitOffset));
200 
201     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
202         "Byte Length %u, Byte Offset %u, End Offset %u\n",
203         FieldByteLength, FieldByteOffset, FieldByteEndOffset));
204 
205     /*
206      * Iterative search for the maximum access width that is both aligned
207      * and does not go beyond the end of the region
208      *
209      * Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes)
210      */
211     for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1)
212     {
213         /*
214          * 1) Round end offset up to next access boundary and make sure that
215          *    this does not go beyond the end of the parent region.
216          * 2) When the Access width is greater than the FieldByteLength, we
217          *    are done. (This does not optimize for the perfectly aligned
218          *    case yet).
219          */
220         if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <=
221             RegionLength)
222         {
223             FieldStartOffset =
224                 ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) /
225                 AccessByteWidth;
226 
227             FieldEndOffset =
228                 ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset),
229                     AccessByteWidth) / AccessByteWidth;
230 
231             Accesses = FieldEndOffset - FieldStartOffset;
232 
233             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
234                 "AccessWidth %u end is within region\n", AccessByteWidth));
235 
236             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
237                 "Field Start %u, Field End %u -- requires %u accesses\n",
238                 FieldStartOffset, FieldEndOffset, Accesses));
239 
240             /* Single access is optimal */
241 
242             if (Accesses <= 1)
243             {
244                 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
245                     "Entire field can be accessed "
246                     "with one operation of size %u\n",
247                     AccessByteWidth));
248                 return_VALUE (AccessByteWidth);
249             }
250 
251             /*
252              * Fits in the region, but requires more than one read/write.
253              * try the next wider access on next iteration
254              */
255             if (Accesses < MinimumAccesses)
256             {
257                 MinimumAccesses = Accesses;
258                 MinimumAccessWidth = AccessByteWidth;
259             }
260         }
261         else
262         {
263             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
264                 "AccessWidth %u end is NOT within region\n",
265                 AccessByteWidth));
266             if (AccessByteWidth == 1)
267             {
268                 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
269                     "Field goes beyond end-of-region!\n"));
270 
271                 /* Field does not fit in the region at all */
272 
273                 return_VALUE (0);
274             }
275 
276             /*
277              * This width goes beyond the end-of-region, back off to
278              * previous access
279              */
280             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
281                 "Backing off to previous optimal access width of %u\n",
282                 MinimumAccessWidth));
283             return_VALUE (MinimumAccessWidth);
284         }
285     }
286 
287     /*
288      * Could not read/write field with one operation,
289      * just use max access width
290      */
291     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
292         "Cannot access field in one operation, using width 8\n"));
293 
294     return_VALUE (8);
295 }
296 #endif /* ACPI_UNDER_DEVELOPMENT */
297 
298 
299 /*******************************************************************************
300  *
301  * FUNCTION:    AcpiExDecodeFieldAccess
302  *
303  * PARAMETERS:  ObjDesc             - Field object
304  *              FieldFlags          - Encoded fieldflags (contains access bits)
305  *              ReturnByteAlignment - Where the byte alignment is returned
306  *
307  * RETURN:      Field granularity (8, 16, 32 or 64) and
308  *              ByteAlignment (1, 2, 3, or 4)
309  *
310  * DESCRIPTION: Decode the AccessType bits of a field definition.
311  *
312  ******************************************************************************/
313 
314 static UINT32
315 AcpiExDecodeFieldAccess (
316     ACPI_OPERAND_OBJECT     *ObjDesc,
317     UINT8                   FieldFlags,
318     UINT32                  *ReturnByteAlignment)
319 {
320     UINT32                  Access;
321     UINT32                  ByteAlignment;
322     UINT32                  BitLength;
323 
324 
325     ACPI_FUNCTION_TRACE (ExDecodeFieldAccess);
326 
327 
328     Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK);
329 
330     switch (Access)
331     {
332     case AML_FIELD_ACCESS_ANY:
333 
334 #ifdef ACPI_UNDER_DEVELOPMENT
335         ByteAlignment =
336             AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset,
337                 ObjDesc->CommonField.BitLength,
338                 0xFFFFFFFF /* Temp until we pass RegionLength as parameter */);
339         BitLength = ByteAlignment * 8;
340 #endif
341 
342         ByteAlignment = 1;
343         BitLength = 8;
344         break;
345 
346     case AML_FIELD_ACCESS_BYTE:
347     case AML_FIELD_ACCESS_BUFFER:   /* ACPI 2.0 (SMBus Buffer) */
348 
349         ByteAlignment = 1;
350         BitLength     = 8;
351         break;
352 
353     case AML_FIELD_ACCESS_WORD:
354 
355         ByteAlignment = 2;
356         BitLength     = 16;
357         break;
358 
359     case AML_FIELD_ACCESS_DWORD:
360 
361         ByteAlignment = 4;
362         BitLength     = 32;
363         break;
364 
365     case AML_FIELD_ACCESS_QWORD:    /* ACPI 2.0 */
366 
367         ByteAlignment = 8;
368         BitLength     = 64;
369         break;
370 
371     default:
372 
373         /* Invalid field access type */
374 
375         ACPI_ERROR ((AE_INFO,
376             "Unknown field access type 0x%X",
377             Access));
378 
379         return_UINT32 (0);
380     }
381 
382     if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
383     {
384         /*
385          * BufferField access can be on any byte boundary, so the
386          * ByteAlignment is always 1 byte -- regardless of any ByteAlignment
387          * implied by the field access type.
388          */
389         ByteAlignment = 1;
390     }
391 
392     *ReturnByteAlignment = ByteAlignment;
393     return_UINT32 (BitLength);
394 }
395 
396 
397 /*******************************************************************************
398  *
399  * FUNCTION:    AcpiExPrepCommonFieldObject
400  *
401  * PARAMETERS:  ObjDesc             - The field object
402  *              FieldFlags          - Access, LockRule, and UpdateRule.
403  *                                    The format of a FieldFlag is described
404  *                                    in the ACPI specification
405  *              FieldAttribute      - Special attributes (not used)
406  *              FieldBitPosition    - Field start position
407  *              FieldBitLength      - Field length in number of bits
408  *
409  * RETURN:      Status
410  *
411  * DESCRIPTION: Initialize the areas of the field object that are common
412  *              to the various types of fields. Note: This is very "sensitive"
413  *              code because we are solving the general case for field
414  *              alignment.
415  *
416  ******************************************************************************/
417 
418 ACPI_STATUS
419 AcpiExPrepCommonFieldObject (
420     ACPI_OPERAND_OBJECT     *ObjDesc,
421     UINT8                   FieldFlags,
422     UINT8                   FieldAttribute,
423     UINT32                  FieldBitPosition,
424     UINT32                  FieldBitLength)
425 {
426     UINT32                  AccessBitWidth;
427     UINT32                  ByteAlignment;
428     UINT32                  NearestByteAddress;
429 
430 
431     ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject);
432 
433 
434     /*
435      * Note: the structure being initialized is the
436      * ACPI_COMMON_FIELD_INFO;  No structure fields outside of the common
437      * area are initialized by this procedure.
438      */
439     ObjDesc->CommonField.FieldFlags = FieldFlags;
440     ObjDesc->CommonField.Attribute  = FieldAttribute;
441     ObjDesc->CommonField.BitLength  = FieldBitLength;
442 
443     /*
444      * Decode the access type so we can compute offsets. The access type gives
445      * two pieces of information - the width of each field access and the
446      * necessary ByteAlignment (address granularity) of the access.
447      *
448      * For AnyAcc, the AccessBitWidth is the largest width that is both
449      * necessary and possible in an attempt to access the whole field in one
450      * I/O operation. However, for AnyAcc, the ByteAlignment is always one
451      * byte.
452      *
453      * For all Buffer Fields, the ByteAlignment is always one byte.
454      *
455      * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is
456      * the same (equivalent) as the ByteAlignment.
457      */
458     AccessBitWidth = AcpiExDecodeFieldAccess (
459         ObjDesc, FieldFlags, &ByteAlignment);
460     if (!AccessBitWidth)
461     {
462         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
463     }
464 
465     /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */
466 
467     ObjDesc->CommonField.AccessByteWidth = (UINT8)
468         ACPI_DIV_8 (AccessBitWidth);
469 
470     /*
471      * BaseByteOffset is the address of the start of the field within the
472      * region. It is the byte address of the first *datum* (field-width data
473      * unit) of the field. (i.e., the first datum that contains at least the
474      * first *bit* of the field.)
475      *
476      * Note: ByteAlignment is always either equal to the AccessBitWidth or 8
477      * (Byte access), and it defines the addressing granularity of the parent
478      * region or buffer.
479      */
480     NearestByteAddress =
481         ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition);
482     ObjDesc->CommonField.BaseByteOffset = (UINT32)
483         ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment);
484 
485     /*
486      * StartFieldBitOffset is the offset of the first bit of the field within
487      * a field datum.
488      */
489     ObjDesc->CommonField.StartFieldBitOffset = (UINT8)
490         (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset));
491 
492     return_ACPI_STATUS (AE_OK);
493 }
494 
495 
496 /*******************************************************************************
497  *
498  * FUNCTION:    AcpiExPrepFieldValue
499  *
500  * PARAMETERS:  Info    - Contains all field creation info
501  *
502  * RETURN:      Status
503  *
504  * DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a
505  *              subtype of DefField and connect it to the parent Node.
506  *
507  ******************************************************************************/
508 
509 ACPI_STATUS
510 AcpiExPrepFieldValue (
511     ACPI_CREATE_FIELD_INFO  *Info)
512 {
513     ACPI_OPERAND_OBJECT     *ObjDesc;
514     ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
515     ACPI_STATUS             Status;
516     UINT32                  AccessByteWidth;
517     UINT32                  Type;
518 
519 
520     ACPI_FUNCTION_TRACE (ExPrepFieldValue);
521 
522 
523     /* Parameter validation */
524 
525     if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD)
526     {
527         if (!Info->RegionNode)
528         {
529             ACPI_ERROR ((AE_INFO, "Null RegionNode"));
530             return_ACPI_STATUS (AE_AML_NO_OPERAND);
531         }
532 
533         Type = AcpiNsGetType (Info->RegionNode);
534         if (Type != ACPI_TYPE_REGION)
535         {
536             ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)",
537                 Type, AcpiUtGetTypeName (Type)));
538 
539             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
540         }
541     }
542 
543     /* Allocate a new field object */
544 
545     ObjDesc = AcpiUtCreateInternalObject (Info->FieldType);
546     if (!ObjDesc)
547     {
548         return_ACPI_STATUS (AE_NO_MEMORY);
549     }
550 
551     /* Initialize areas of the object that are common to all fields */
552 
553     ObjDesc->CommonField.Node = Info->FieldNode;
554     Status = AcpiExPrepCommonFieldObject (ObjDesc,
555         Info->FieldFlags, Info->Attribute,
556         Info->FieldBitPosition, Info->FieldBitLength);
557     if (ACPI_FAILURE (Status))
558     {
559         AcpiUtDeleteObjectDesc (ObjDesc);
560         return_ACPI_STATUS (Status);
561     }
562 
563     /* Initialize areas of the object that are specific to the field type */
564 
565     switch (Info->FieldType)
566     {
567     case ACPI_TYPE_LOCAL_REGION_FIELD:
568 
569         ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode);
570 
571         /* Fields specific to GenericSerialBus fields */
572 
573         ObjDesc->Field.AccessLength = Info->AccessLength;
574 
575         if (Info->ConnectionNode)
576         {
577             SecondDesc = Info->ConnectionNode->Object;
578             if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID))
579             {
580                 Status = AcpiDsGetBufferArguments (SecondDesc);
581                 if (ACPI_FAILURE (Status))
582                 {
583                     AcpiUtDeleteObjectDesc (ObjDesc);
584                     return_ACPI_STATUS (Status);
585                 }
586             }
587 
588             ObjDesc->Field.ResourceBuffer =
589                 SecondDesc->Buffer.Pointer;
590             ObjDesc->Field.ResourceLength =
591                 (UINT16) SecondDesc->Buffer.Length;
592         }
593         else if (Info->ResourceBuffer)
594         {
595             ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer;
596             ObjDesc->Field.ResourceLength = Info->ResourceLength;
597         }
598 
599         ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex;
600 
601         /* Allow full data read from EC address space */
602 
603         if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
604             (ObjDesc->CommonField.BitLength > 8))
605         {
606             AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES (
607                 ObjDesc->CommonField.BitLength);
608 
609             /* Maximum byte width supported is 255 */
610 
611             if (AccessByteWidth < 256)
612             {
613                 ObjDesc->CommonField.AccessByteWidth =
614                     (UINT8) AccessByteWidth;
615             }
616         }
617 
618         /* An additional reference for the container */
619 
620         AcpiUtAddReference (ObjDesc->Field.RegionObj);
621 
622         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
623             "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",
624             ObjDesc->Field.StartFieldBitOffset,
625             ObjDesc->Field.BaseByteOffset,
626             ObjDesc->Field.AccessByteWidth,
627             ObjDesc->Field.RegionObj));
628         break;
629 
630     case ACPI_TYPE_LOCAL_BANK_FIELD:
631 
632         ObjDesc->BankField.Value = Info->BankValue;
633         ObjDesc->BankField.RegionObj =
634             AcpiNsGetAttachedObject (Info->RegionNode);
635         ObjDesc->BankField.BankObj =
636             AcpiNsGetAttachedObject (Info->RegisterNode);
637 
638         /* An additional reference for the attached objects */
639 
640         AcpiUtAddReference (ObjDesc->BankField.RegionObj);
641         AcpiUtAddReference (ObjDesc->BankField.BankObj);
642 
643         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
644             "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",
645             ObjDesc->BankField.StartFieldBitOffset,
646             ObjDesc->BankField.BaseByteOffset,
647             ObjDesc->Field.AccessByteWidth,
648             ObjDesc->BankField.RegionObj,
649             ObjDesc->BankField.BankObj));
650 
651         /*
652          * Remember location in AML stream of the field unit
653          * opcode and operands -- since the BankValue
654          * operands must be evaluated.
655          */
656         SecondDesc = ObjDesc->Common.NextObject;
657         SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
658             Info->DataRegisterNode)->Named.Data;
659         SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
660             Info->DataRegisterNode)->Named.Length;
661 
662         break;
663 
664     case ACPI_TYPE_LOCAL_INDEX_FIELD:
665 
666         /* Get the Index and Data registers */
667 
668         ObjDesc->IndexField.IndexObj =
669             AcpiNsGetAttachedObject (Info->RegisterNode);
670         ObjDesc->IndexField.DataObj =
671             AcpiNsGetAttachedObject (Info->DataRegisterNode);
672 
673         if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj)
674         {
675             ACPI_ERROR ((AE_INFO, "Null Index Object during field prep"));
676             AcpiUtDeleteObjectDesc (ObjDesc);
677             return_ACPI_STATUS (AE_AML_INTERNAL);
678         }
679 
680         /* An additional reference for the attached objects */
681 
682         AcpiUtAddReference (ObjDesc->IndexField.DataObj);
683         AcpiUtAddReference (ObjDesc->IndexField.IndexObj);
684 
685         /*
686          * April 2006: Changed to match MS behavior
687          *
688          * The value written to the Index register is the byte offset of the
689          * target field in units of the granularity of the IndexField
690          *
691          * Previously, the value was calculated as an index in terms of the
692          * width of the Data register, as below:
693          *
694          *      ObjDesc->IndexField.Value = (UINT32)
695          *          (Info->FieldBitPosition / ACPI_MUL_8 (
696          *              ObjDesc->Field.AccessByteWidth));
697          *
698          * February 2006: Tried value as a byte offset:
699          *      ObjDesc->IndexField.Value = (UINT32)
700          *          ACPI_DIV_8 (Info->FieldBitPosition);
701          */
702         ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN (
703             ACPI_DIV_8 (Info->FieldBitPosition),
704             ObjDesc->IndexField.AccessByteWidth);
705 
706         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
707             "IndexField: BitOff %X, Off %X, Value %X, "
708             "Gran %X, Index %p, Data %p\n",
709             ObjDesc->IndexField.StartFieldBitOffset,
710             ObjDesc->IndexField.BaseByteOffset,
711             ObjDesc->IndexField.Value,
712             ObjDesc->Field.AccessByteWidth,
713             ObjDesc->IndexField.IndexObj,
714             ObjDesc->IndexField.DataObj));
715         break;
716 
717     default:
718 
719         /* No other types should get here */
720 
721         break;
722     }
723 
724     /*
725      * Store the constructed descriptor (ObjDesc) into the parent Node,
726      * preserving the current type of that NamedObj.
727      */
728     Status = AcpiNsAttachObject (
729         Info->FieldNode, ObjDesc, AcpiNsGetType (Info->FieldNode));
730 
731     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
732         "Set NamedObj %p [%4.4s], ObjDesc %p\n",
733         Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc));
734 
735     /* Remove local reference to the object */
736 
737     AcpiUtRemoveReference (ObjDesc);
738     return_ACPI_STATUS (Status);
739 }
740