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