17c478bd9Sstevel@tonic-gate /******************************************************************************
27c478bd9Sstevel@tonic-gate *
37b1019a6SJerry Jelinek * Module Name: exprep - ACPI AML field prep utilities
47c478bd9Sstevel@tonic-gate *
57c478bd9Sstevel@tonic-gate *****************************************************************************/
67c478bd9Sstevel@tonic-gate
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi *
9*35786f68SRobert Mustacchi * 1. Copyright Notice
10*35786f68SRobert Mustacchi *
11*35786f68SRobert Mustacchi * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
127c478bd9Sstevel@tonic-gate * All rights reserved.
137c478bd9Sstevel@tonic-gate *
14*35786f68SRobert Mustacchi * 2. License
15*35786f68SRobert Mustacchi *
16*35786f68SRobert Mustacchi * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi * property rights.
20*35786f68SRobert Mustacchi *
21*35786f68SRobert Mustacchi * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi *
28*35786f68SRobert Mustacchi * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi *
37*35786f68SRobert Mustacchi * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi * conditions are met:
39*35786f68SRobert Mustacchi *
40*35786f68SRobert Mustacchi * 3. Conditions
41*35786f68SRobert Mustacchi *
42*35786f68SRobert Mustacchi * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi *
54*35786f68SRobert Mustacchi * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi * make.
65*35786f68SRobert Mustacchi *
66*35786f68SRobert Mustacchi * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi * distribution.
71*35786f68SRobert Mustacchi *
72*35786f68SRobert Mustacchi * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi * Intel Code.
74*35786f68SRobert Mustacchi *
75*35786f68SRobert Mustacchi * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi *
80*35786f68SRobert Mustacchi * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi *
82*35786f68SRobert Mustacchi * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi *
90*35786f68SRobert Mustacchi * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi * LIMITED REMEDY.
98*35786f68SRobert Mustacchi *
99*35786f68SRobert Mustacchi * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi * such license, approval or letter.
113*35786f68SRobert Mustacchi *
114*35786f68SRobert Mustacchi *****************************************************************************
115*35786f68SRobert Mustacchi *
116*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi * following license:
118*35786f68SRobert Mustacchi *
11926f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross * are met:
12226f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross * without modification.
12526f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross * binary redistribution.
13026f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross * from this software without specific prior written permission.
13326f3cdf0SGordon Ross *
13426f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi *
146*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi * Software Foundation.
149*35786f68SRobert Mustacchi *
150*35786f68SRobert Mustacchi *****************************************************************************/
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate #include "acpi.h"
153aa2aa9a6SDana Myers #include "accommon.h"
1547c478bd9Sstevel@tonic-gate #include "acinterp.h"
1557c478bd9Sstevel@tonic-gate #include "amlcode.h"
1567c478bd9Sstevel@tonic-gate #include "acnamesp.h"
1577b1019a6SJerry Jelinek #include "acdispat.h"
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate #define _COMPONENT ACPI_EXECUTER
1617c478bd9Sstevel@tonic-gate ACPI_MODULE_NAME ("exprep")
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate /* Local prototypes */
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate static UINT32
1667c478bd9Sstevel@tonic-gate AcpiExDecodeFieldAccess (
1677c478bd9Sstevel@tonic-gate ACPI_OPERAND_OBJECT *ObjDesc,
1687c478bd9Sstevel@tonic-gate UINT8 FieldFlags,
1697c478bd9Sstevel@tonic-gate UINT32 *ReturnByteAlignment);
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate #ifdef ACPI_UNDER_DEVELOPMENT
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate static UINT32
1757c478bd9Sstevel@tonic-gate AcpiExGenerateAccess (
1767c478bd9Sstevel@tonic-gate UINT32 FieldBitOffset,
1777c478bd9Sstevel@tonic-gate UINT32 FieldBitLength,
1787c478bd9Sstevel@tonic-gate UINT32 RegionLength);
1797c478bd9Sstevel@tonic-gate
1807b1019a6SJerry Jelinek
1817c478bd9Sstevel@tonic-gate /*******************************************************************************
1827c478bd9Sstevel@tonic-gate *
1837c478bd9Sstevel@tonic-gate * FUNCTION: AcpiExGenerateAccess
1847c478bd9Sstevel@tonic-gate *
1857c478bd9Sstevel@tonic-gate * PARAMETERS: FieldBitOffset - Start of field within parent region/buffer
1867c478bd9Sstevel@tonic-gate * FieldBitLength - Length of field in bits
1877c478bd9Sstevel@tonic-gate * RegionLength - Length of parent in bytes
1887c478bd9Sstevel@tonic-gate *
1897c478bd9Sstevel@tonic-gate * RETURN: Field granularity (8, 16, 32 or 64) and
1907c478bd9Sstevel@tonic-gate * ByteAlignment (1, 2, 3, or 4)
1917c478bd9Sstevel@tonic-gate *
1927c478bd9Sstevel@tonic-gate * DESCRIPTION: Generate an optimal access width for fields defined with the
1937c478bd9Sstevel@tonic-gate * AnyAcc keyword.
1947c478bd9Sstevel@tonic-gate *
1957c478bd9Sstevel@tonic-gate * NOTE: Need to have the RegionLength in order to check for boundary
1967b1019a6SJerry Jelinek * conditions (end-of-region). However, the RegionLength is a deferred
1977b1019a6SJerry Jelinek * operation. Therefore, to complete this implementation, the generation
1987c478bd9Sstevel@tonic-gate * of this access width must be deferred until the region length has
1997c478bd9Sstevel@tonic-gate * been evaluated.
2007c478bd9Sstevel@tonic-gate *
2017c478bd9Sstevel@tonic-gate ******************************************************************************/
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate static UINT32
AcpiExGenerateAccess(UINT32 FieldBitOffset,UINT32 FieldBitLength,UINT32 RegionLength)2047c478bd9Sstevel@tonic-gate AcpiExGenerateAccess (
2057c478bd9Sstevel@tonic-gate UINT32 FieldBitOffset,
2067c478bd9Sstevel@tonic-gate UINT32 FieldBitLength,
2077c478bd9Sstevel@tonic-gate UINT32 RegionLength)
2087c478bd9Sstevel@tonic-gate {
2097c478bd9Sstevel@tonic-gate UINT32 FieldByteLength;
2107c478bd9Sstevel@tonic-gate UINT32 FieldByteOffset;
2117c478bd9Sstevel@tonic-gate UINT32 FieldByteEndOffset;
2127c478bd9Sstevel@tonic-gate UINT32 AccessByteWidth;
2137c478bd9Sstevel@tonic-gate UINT32 FieldStartOffset;
2147c478bd9Sstevel@tonic-gate UINT32 FieldEndOffset;
2157c478bd9Sstevel@tonic-gate UINT32 MinimumAccessWidth = 0xFFFFFFFF;
2167c478bd9Sstevel@tonic-gate UINT32 MinimumAccesses = 0xFFFFFFFF;
2177c478bd9Sstevel@tonic-gate UINT32 Accesses;
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate
22027f7c583Smyers ACPI_FUNCTION_TRACE (ExGenerateAccess);
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate /* Round Field start offset and length to "minimal" byte boundaries */
2247c478bd9Sstevel@tonic-gate
2257b1019a6SJerry Jelinek FieldByteOffset = ACPI_DIV_8 (
2267b1019a6SJerry Jelinek ACPI_ROUND_DOWN (FieldBitOffset, 8));
2277b1019a6SJerry Jelinek
2287b1019a6SJerry Jelinek FieldByteEndOffset = ACPI_DIV_8 (
2297b1019a6SJerry Jelinek ACPI_ROUND_UP (FieldBitLength + FieldBitOffset, 8));
2307b1019a6SJerry Jelinek
2317b1019a6SJerry Jelinek FieldByteLength = FieldByteEndOffset - FieldByteOffset;
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
23426f3cdf0SGordon Ross "Bit length %u, Bit offset %u\n",
23526f3cdf0SGordon Ross FieldBitLength, FieldBitOffset));
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
23826f3cdf0SGordon Ross "Byte Length %u, Byte Offset %u, End Offset %u\n",
23926f3cdf0SGordon Ross FieldByteLength, FieldByteOffset, FieldByteEndOffset));
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate /*
2427c478bd9Sstevel@tonic-gate * Iterative search for the maximum access width that is both aligned
2437c478bd9Sstevel@tonic-gate * and does not go beyond the end of the region
2447c478bd9Sstevel@tonic-gate *
2457c478bd9Sstevel@tonic-gate * Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes)
2467c478bd9Sstevel@tonic-gate */
2477c478bd9Sstevel@tonic-gate for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1)
2487c478bd9Sstevel@tonic-gate {
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate * 1) Round end offset up to next access boundary and make sure that
2517c478bd9Sstevel@tonic-gate * this does not go beyond the end of the parent region.
2527c478bd9Sstevel@tonic-gate * 2) When the Access width is greater than the FieldByteLength, we
2537c478bd9Sstevel@tonic-gate * are done. (This does not optimize for the perfectly aligned
2547c478bd9Sstevel@tonic-gate * case yet).
2557c478bd9Sstevel@tonic-gate */
2567b1019a6SJerry Jelinek if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <=
2577b1019a6SJerry Jelinek RegionLength)
2587c478bd9Sstevel@tonic-gate {
2597c478bd9Sstevel@tonic-gate FieldStartOffset =
2607c478bd9Sstevel@tonic-gate ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) /
2617c478bd9Sstevel@tonic-gate AccessByteWidth;
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate FieldEndOffset =
2647c478bd9Sstevel@tonic-gate ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset),
2657c478bd9Sstevel@tonic-gate AccessByteWidth) / AccessByteWidth;
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate Accesses = FieldEndOffset - FieldStartOffset;
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
27026f3cdf0SGordon Ross "AccessWidth %u end is within region\n", AccessByteWidth));
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
27326f3cdf0SGordon Ross "Field Start %u, Field End %u -- requires %u accesses\n",
27426f3cdf0SGordon Ross FieldStartOffset, FieldEndOffset, Accesses));
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate /* Single access is optimal */
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate if (Accesses <= 1)
2797c478bd9Sstevel@tonic-gate {
2807c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
2817b1019a6SJerry Jelinek "Entire field can be accessed "
2827b1019a6SJerry Jelinek "with one operation of size %u\n",
2837c478bd9Sstevel@tonic-gate AccessByteWidth));
2847c478bd9Sstevel@tonic-gate return_VALUE (AccessByteWidth);
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate /*
2887c478bd9Sstevel@tonic-gate * Fits in the region, but requires more than one read/write.
2897c478bd9Sstevel@tonic-gate * try the next wider access on next iteration
2907c478bd9Sstevel@tonic-gate */
2917c478bd9Sstevel@tonic-gate if (Accesses < MinimumAccesses)
2927c478bd9Sstevel@tonic-gate {
2937b1019a6SJerry Jelinek MinimumAccesses = Accesses;
2947c478bd9Sstevel@tonic-gate MinimumAccessWidth = AccessByteWidth;
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate else
2987c478bd9Sstevel@tonic-gate {
2997c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
3007b1019a6SJerry Jelinek "AccessWidth %u end is NOT within region\n",
3017b1019a6SJerry Jelinek AccessByteWidth));
3027c478bd9Sstevel@tonic-gate if (AccessByteWidth == 1)
3037c478bd9Sstevel@tonic-gate {
3047c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
30526f3cdf0SGordon Ross "Field goes beyond end-of-region!\n"));
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate /* Field does not fit in the region at all */
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate return_VALUE (0);
3107c478bd9Sstevel@tonic-gate }
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate /*
3137c478bd9Sstevel@tonic-gate * This width goes beyond the end-of-region, back off to
3147c478bd9Sstevel@tonic-gate * previous access
3157c478bd9Sstevel@tonic-gate */
3167c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
31726f3cdf0SGordon Ross "Backing off to previous optimal access width of %u\n",
31826f3cdf0SGordon Ross MinimumAccessWidth));
3197c478bd9Sstevel@tonic-gate return_VALUE (MinimumAccessWidth);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate /*
3247c478bd9Sstevel@tonic-gate * Could not read/write field with one operation,
3257c478bd9Sstevel@tonic-gate * just use max access width
3267c478bd9Sstevel@tonic-gate */
3277c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
32826f3cdf0SGordon Ross "Cannot access field in one operation, using width 8\n"));
3297b1019a6SJerry Jelinek
3307c478bd9Sstevel@tonic-gate return_VALUE (8);
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate #endif /* ACPI_UNDER_DEVELOPMENT */
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate /*******************************************************************************
3367c478bd9Sstevel@tonic-gate *
3377c478bd9Sstevel@tonic-gate * FUNCTION: AcpiExDecodeFieldAccess
3387c478bd9Sstevel@tonic-gate *
3397c478bd9Sstevel@tonic-gate * PARAMETERS: ObjDesc - Field object
3407c478bd9Sstevel@tonic-gate * FieldFlags - Encoded fieldflags (contains access bits)
3417c478bd9Sstevel@tonic-gate * ReturnByteAlignment - Where the byte alignment is returned
3427c478bd9Sstevel@tonic-gate *
3437c478bd9Sstevel@tonic-gate * RETURN: Field granularity (8, 16, 32 or 64) and
3447c478bd9Sstevel@tonic-gate * ByteAlignment (1, 2, 3, or 4)
3457c478bd9Sstevel@tonic-gate *
3467c478bd9Sstevel@tonic-gate * DESCRIPTION: Decode the AccessType bits of a field definition.
3477c478bd9Sstevel@tonic-gate *
3487c478bd9Sstevel@tonic-gate ******************************************************************************/
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate static UINT32
AcpiExDecodeFieldAccess(ACPI_OPERAND_OBJECT * ObjDesc,UINT8 FieldFlags,UINT32 * ReturnByteAlignment)3517c478bd9Sstevel@tonic-gate AcpiExDecodeFieldAccess (
3527c478bd9Sstevel@tonic-gate ACPI_OPERAND_OBJECT *ObjDesc,
3537c478bd9Sstevel@tonic-gate UINT8 FieldFlags,
3547c478bd9Sstevel@tonic-gate UINT32 *ReturnByteAlignment)
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate UINT32 Access;
3577c478bd9Sstevel@tonic-gate UINT32 ByteAlignment;
3587c478bd9Sstevel@tonic-gate UINT32 BitLength;
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate
36127f7c583Smyers ACPI_FUNCTION_TRACE (ExDecodeFieldAccess);
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK);
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate switch (Access)
3677c478bd9Sstevel@tonic-gate {
3687c478bd9Sstevel@tonic-gate case AML_FIELD_ACCESS_ANY:
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate #ifdef ACPI_UNDER_DEVELOPMENT
3717c478bd9Sstevel@tonic-gate ByteAlignment =
3727c478bd9Sstevel@tonic-gate AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset,
3737c478bd9Sstevel@tonic-gate ObjDesc->CommonField.BitLength,
3747c478bd9Sstevel@tonic-gate 0xFFFFFFFF /* Temp until we pass RegionLength as parameter */);
3757c478bd9Sstevel@tonic-gate BitLength = ByteAlignment * 8;
3767c478bd9Sstevel@tonic-gate #endif
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate ByteAlignment = 1;
3797c478bd9Sstevel@tonic-gate BitLength = 8;
3807c478bd9Sstevel@tonic-gate break;
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate case AML_FIELD_ACCESS_BYTE:
3837c478bd9Sstevel@tonic-gate case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */
3847b1019a6SJerry Jelinek
3857c478bd9Sstevel@tonic-gate ByteAlignment = 1;
3867c478bd9Sstevel@tonic-gate BitLength = 8;
3877c478bd9Sstevel@tonic-gate break;
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate case AML_FIELD_ACCESS_WORD:
3907b1019a6SJerry Jelinek
3917c478bd9Sstevel@tonic-gate ByteAlignment = 2;
3927c478bd9Sstevel@tonic-gate BitLength = 16;
3937c478bd9Sstevel@tonic-gate break;
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate case AML_FIELD_ACCESS_DWORD:
3967b1019a6SJerry Jelinek
3977c478bd9Sstevel@tonic-gate ByteAlignment = 4;
3987c478bd9Sstevel@tonic-gate BitLength = 32;
3997c478bd9Sstevel@tonic-gate break;
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */
4027b1019a6SJerry Jelinek
4037c478bd9Sstevel@tonic-gate ByteAlignment = 8;
4047c478bd9Sstevel@tonic-gate BitLength = 64;
4057c478bd9Sstevel@tonic-gate break;
4067c478bd9Sstevel@tonic-gate
4077c478bd9Sstevel@tonic-gate default:
4087b1019a6SJerry Jelinek
4097c478bd9Sstevel@tonic-gate /* Invalid field access type */
4107c478bd9Sstevel@tonic-gate
41130082d0cSmyers ACPI_ERROR ((AE_INFO,
41226f3cdf0SGordon Ross "Unknown field access type 0x%X",
4137c478bd9Sstevel@tonic-gate Access));
4147b1019a6SJerry Jelinek
415186507a7Smyers return_UINT32 (0);
4167c478bd9Sstevel@tonic-gate }
4177c478bd9Sstevel@tonic-gate
418aa2aa9a6SDana Myers if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
4197c478bd9Sstevel@tonic-gate {
4207c478bd9Sstevel@tonic-gate /*
4217c478bd9Sstevel@tonic-gate * BufferField access can be on any byte boundary, so the
4227c478bd9Sstevel@tonic-gate * ByteAlignment is always 1 byte -- regardless of any ByteAlignment
4237c478bd9Sstevel@tonic-gate * implied by the field access type.
4247c478bd9Sstevel@tonic-gate */
4257c478bd9Sstevel@tonic-gate ByteAlignment = 1;
4267c478bd9Sstevel@tonic-gate }
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate *ReturnByteAlignment = ByteAlignment;
429186507a7Smyers return_UINT32 (BitLength);
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate
4337c478bd9Sstevel@tonic-gate /*******************************************************************************
4347c478bd9Sstevel@tonic-gate *
4357c478bd9Sstevel@tonic-gate * FUNCTION: AcpiExPrepCommonFieldObject
4367c478bd9Sstevel@tonic-gate *
4377c478bd9Sstevel@tonic-gate * PARAMETERS: ObjDesc - The field object
4387c478bd9Sstevel@tonic-gate * FieldFlags - Access, LockRule, and UpdateRule.
4397c478bd9Sstevel@tonic-gate * The format of a FieldFlag is described
4407c478bd9Sstevel@tonic-gate * in the ACPI specification
4417c478bd9Sstevel@tonic-gate * FieldAttribute - Special attributes (not used)
4427c478bd9Sstevel@tonic-gate * FieldBitPosition - Field start position
4437c478bd9Sstevel@tonic-gate * FieldBitLength - Field length in number of bits
4447c478bd9Sstevel@tonic-gate *
4457c478bd9Sstevel@tonic-gate * RETURN: Status
4467c478bd9Sstevel@tonic-gate *
4477c478bd9Sstevel@tonic-gate * DESCRIPTION: Initialize the areas of the field object that are common
4487b1019a6SJerry Jelinek * to the various types of fields. Note: This is very "sensitive"
4497c478bd9Sstevel@tonic-gate * code because we are solving the general case for field
4507c478bd9Sstevel@tonic-gate * alignment.
4517c478bd9Sstevel@tonic-gate *
4527c478bd9Sstevel@tonic-gate ******************************************************************************/
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiExPrepCommonFieldObject(ACPI_OPERAND_OBJECT * ObjDesc,UINT8 FieldFlags,UINT8 FieldAttribute,UINT32 FieldBitPosition,UINT32 FieldBitLength)4557c478bd9Sstevel@tonic-gate AcpiExPrepCommonFieldObject (
4567c478bd9Sstevel@tonic-gate ACPI_OPERAND_OBJECT *ObjDesc,
4577c478bd9Sstevel@tonic-gate UINT8 FieldFlags,
4587c478bd9Sstevel@tonic-gate UINT8 FieldAttribute,
4597c478bd9Sstevel@tonic-gate UINT32 FieldBitPosition,
4607c478bd9Sstevel@tonic-gate UINT32 FieldBitLength)
4617c478bd9Sstevel@tonic-gate {
4627c478bd9Sstevel@tonic-gate UINT32 AccessBitWidth;
4637c478bd9Sstevel@tonic-gate UINT32 ByteAlignment;
4647c478bd9Sstevel@tonic-gate UINT32 NearestByteAddress;
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate
46727f7c583Smyers ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject);
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate
4707c478bd9Sstevel@tonic-gate /*
4717c478bd9Sstevel@tonic-gate * Note: the structure being initialized is the
4727c478bd9Sstevel@tonic-gate * ACPI_COMMON_FIELD_INFO; No structure fields outside of the common
4737c478bd9Sstevel@tonic-gate * area are initialized by this procedure.
4747c478bd9Sstevel@tonic-gate */
4757c478bd9Sstevel@tonic-gate ObjDesc->CommonField.FieldFlags = FieldFlags;
4767c478bd9Sstevel@tonic-gate ObjDesc->CommonField.Attribute = FieldAttribute;
4777c478bd9Sstevel@tonic-gate ObjDesc->CommonField.BitLength = FieldBitLength;
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate /*
4807b1019a6SJerry Jelinek * Decode the access type so we can compute offsets. The access type gives
4817c478bd9Sstevel@tonic-gate * two pieces of information - the width of each field access and the
4827c478bd9Sstevel@tonic-gate * necessary ByteAlignment (address granularity) of the access.
4837c478bd9Sstevel@tonic-gate *
4847c478bd9Sstevel@tonic-gate * For AnyAcc, the AccessBitWidth is the largest width that is both
4857c478bd9Sstevel@tonic-gate * necessary and possible in an attempt to access the whole field in one
4867b1019a6SJerry Jelinek * I/O operation. However, for AnyAcc, the ByteAlignment is always one
4877c478bd9Sstevel@tonic-gate * byte.
4887c478bd9Sstevel@tonic-gate *
4897c478bd9Sstevel@tonic-gate * For all Buffer Fields, the ByteAlignment is always one byte.
4907c478bd9Sstevel@tonic-gate *
4917c478bd9Sstevel@tonic-gate * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is
4927c478bd9Sstevel@tonic-gate * the same (equivalent) as the ByteAlignment.
4937c478bd9Sstevel@tonic-gate */
4947b1019a6SJerry Jelinek AccessBitWidth = AcpiExDecodeFieldAccess (
4957b1019a6SJerry Jelinek ObjDesc, FieldFlags, &ByteAlignment);
4967c478bd9Sstevel@tonic-gate if (!AccessBitWidth)
4977c478bd9Sstevel@tonic-gate {
4987c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
4997c478bd9Sstevel@tonic-gate }
5007c478bd9Sstevel@tonic-gate
50126f3cdf0SGordon Ross /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate ObjDesc->CommonField.AccessByteWidth = (UINT8)
50426f3cdf0SGordon Ross ACPI_DIV_8 (AccessBitWidth);
5057c478bd9Sstevel@tonic-gate
5067c478bd9Sstevel@tonic-gate /*
5077c478bd9Sstevel@tonic-gate * BaseByteOffset is the address of the start of the field within the
5087b1019a6SJerry Jelinek * region. It is the byte address of the first *datum* (field-width data
5097c478bd9Sstevel@tonic-gate * unit) of the field. (i.e., the first datum that contains at least the
5107c478bd9Sstevel@tonic-gate * first *bit* of the field.)
5117c478bd9Sstevel@tonic-gate *
5127c478bd9Sstevel@tonic-gate * Note: ByteAlignment is always either equal to the AccessBitWidth or 8
5137c478bd9Sstevel@tonic-gate * (Byte access), and it defines the addressing granularity of the parent
5147c478bd9Sstevel@tonic-gate * region or buffer.
5157c478bd9Sstevel@tonic-gate */
5167c478bd9Sstevel@tonic-gate NearestByteAddress =
51726f3cdf0SGordon Ross ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition);
5187c478bd9Sstevel@tonic-gate ObjDesc->CommonField.BaseByteOffset = (UINT32)
51926f3cdf0SGordon Ross ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment);
5207c478bd9Sstevel@tonic-gate
5217c478bd9Sstevel@tonic-gate /*
5227c478bd9Sstevel@tonic-gate * StartFieldBitOffset is the offset of the first bit of the field within
5237c478bd9Sstevel@tonic-gate * a field datum.
5247c478bd9Sstevel@tonic-gate */
5257c478bd9Sstevel@tonic-gate ObjDesc->CommonField.StartFieldBitOffset = (UINT8)
5267c478bd9Sstevel@tonic-gate (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset));
5277c478bd9Sstevel@tonic-gate
5287c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_OK);
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate
5327c478bd9Sstevel@tonic-gate /*******************************************************************************
5337c478bd9Sstevel@tonic-gate *
5347c478bd9Sstevel@tonic-gate * FUNCTION: AcpiExPrepFieldValue
5357c478bd9Sstevel@tonic-gate *
5367c478bd9Sstevel@tonic-gate * PARAMETERS: Info - Contains all field creation info
5377c478bd9Sstevel@tonic-gate *
5387c478bd9Sstevel@tonic-gate * RETURN: Status
5397c478bd9Sstevel@tonic-gate *
5407b1019a6SJerry Jelinek * DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a
5417b1019a6SJerry Jelinek * subtype of DefField and connect it to the parent Node.
5427c478bd9Sstevel@tonic-gate *
5437c478bd9Sstevel@tonic-gate ******************************************************************************/
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiExPrepFieldValue(ACPI_CREATE_FIELD_INFO * Info)5467c478bd9Sstevel@tonic-gate AcpiExPrepFieldValue (
5477c478bd9Sstevel@tonic-gate ACPI_CREATE_FIELD_INFO *Info)
5487c478bd9Sstevel@tonic-gate {
5497c478bd9Sstevel@tonic-gate ACPI_OPERAND_OBJECT *ObjDesc;
550db2bae30SDana Myers ACPI_OPERAND_OBJECT *SecondDesc = NULL;
5517c478bd9Sstevel@tonic-gate ACPI_STATUS Status;
55226f3cdf0SGordon Ross UINT32 AccessByteWidth;
55326f3cdf0SGordon Ross UINT32 Type;
5547c478bd9Sstevel@tonic-gate
5557c478bd9Sstevel@tonic-gate
55627f7c583Smyers ACPI_FUNCTION_TRACE (ExPrepFieldValue);
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate /* Parameter validation */
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD)
5627c478bd9Sstevel@tonic-gate {
5637c478bd9Sstevel@tonic-gate if (!Info->RegionNode)
5647c478bd9Sstevel@tonic-gate {
56530082d0cSmyers ACPI_ERROR ((AE_INFO, "Null RegionNode"));
5667c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_AML_NO_OPERAND);
5677c478bd9Sstevel@tonic-gate }
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate Type = AcpiNsGetType (Info->RegionNode);
5707c478bd9Sstevel@tonic-gate if (Type != ACPI_TYPE_REGION)
5717c478bd9Sstevel@tonic-gate {
57226f3cdf0SGordon Ross ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)",
5737c478bd9Sstevel@tonic-gate Type, AcpiUtGetTypeName (Type)));
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
5767c478bd9Sstevel@tonic-gate }
5777c478bd9Sstevel@tonic-gate }
5787c478bd9Sstevel@tonic-gate
5797c478bd9Sstevel@tonic-gate /* Allocate a new field object */
5807c478bd9Sstevel@tonic-gate
5817c478bd9Sstevel@tonic-gate ObjDesc = AcpiUtCreateInternalObject (Info->FieldType);
5827c478bd9Sstevel@tonic-gate if (!ObjDesc)
5837c478bd9Sstevel@tonic-gate {
5847c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_NO_MEMORY);
5857c478bd9Sstevel@tonic-gate }
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate /* Initialize areas of the object that are common to all fields */
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate ObjDesc->CommonField.Node = Info->FieldNode;
59026f3cdf0SGordon Ross Status = AcpiExPrepCommonFieldObject (ObjDesc,
5917b1019a6SJerry Jelinek Info->FieldFlags, Info->Attribute,
5927b1019a6SJerry Jelinek Info->FieldBitPosition, Info->FieldBitLength);
5937c478bd9Sstevel@tonic-gate if (ACPI_FAILURE (Status))
5947c478bd9Sstevel@tonic-gate {
5957c478bd9Sstevel@tonic-gate AcpiUtDeleteObjectDesc (ObjDesc);
5967c478bd9Sstevel@tonic-gate return_ACPI_STATUS (Status);
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate /* Initialize areas of the object that are specific to the field type */
6007c478bd9Sstevel@tonic-gate
6017c478bd9Sstevel@tonic-gate switch (Info->FieldType)
6027c478bd9Sstevel@tonic-gate {
6037c478bd9Sstevel@tonic-gate case ACPI_TYPE_LOCAL_REGION_FIELD:
6047c478bd9Sstevel@tonic-gate
6057c478bd9Sstevel@tonic-gate ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode);
6067c478bd9Sstevel@tonic-gate
6077b1019a6SJerry Jelinek /* Fields specific to GenericSerialBus fields */
6087b1019a6SJerry Jelinek
6097b1019a6SJerry Jelinek ObjDesc->Field.AccessLength = Info->AccessLength;
6107b1019a6SJerry Jelinek
6117b1019a6SJerry Jelinek if (Info->ConnectionNode)
6127b1019a6SJerry Jelinek {
6137b1019a6SJerry Jelinek SecondDesc = Info->ConnectionNode->Object;
6147b1019a6SJerry Jelinek if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID))
6157b1019a6SJerry Jelinek {
6167b1019a6SJerry Jelinek Status = AcpiDsGetBufferArguments (SecondDesc);
6177b1019a6SJerry Jelinek if (ACPI_FAILURE (Status))
6187b1019a6SJerry Jelinek {
6197b1019a6SJerry Jelinek AcpiUtDeleteObjectDesc (ObjDesc);
6207b1019a6SJerry Jelinek return_ACPI_STATUS (Status);
6217b1019a6SJerry Jelinek }
6227b1019a6SJerry Jelinek }
6237b1019a6SJerry Jelinek
6247b1019a6SJerry Jelinek ObjDesc->Field.ResourceBuffer =
6257b1019a6SJerry Jelinek SecondDesc->Buffer.Pointer;
6267b1019a6SJerry Jelinek ObjDesc->Field.ResourceLength =
6277b1019a6SJerry Jelinek (UINT16) SecondDesc->Buffer.Length;
6287b1019a6SJerry Jelinek }
6297b1019a6SJerry Jelinek else if (Info->ResourceBuffer)
6307b1019a6SJerry Jelinek {
6317b1019a6SJerry Jelinek ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer;
6327b1019a6SJerry Jelinek ObjDesc->Field.ResourceLength = Info->ResourceLength;
6337b1019a6SJerry Jelinek }
6347b1019a6SJerry Jelinek
6357b1019a6SJerry Jelinek ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex;
6367b1019a6SJerry Jelinek
63726f3cdf0SGordon Ross /* Allow full data read from EC address space */
63826f3cdf0SGordon Ross
63926f3cdf0SGordon Ross if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
64026f3cdf0SGordon Ross (ObjDesc->CommonField.BitLength > 8))
64126f3cdf0SGordon Ross {
64226f3cdf0SGordon Ross AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES (
64326f3cdf0SGordon Ross ObjDesc->CommonField.BitLength);
64426f3cdf0SGordon Ross
64526f3cdf0SGordon Ross /* Maximum byte width supported is 255 */
64626f3cdf0SGordon Ross
64726f3cdf0SGordon Ross if (AccessByteWidth < 256)
64826f3cdf0SGordon Ross {
6497b1019a6SJerry Jelinek ObjDesc->CommonField.AccessByteWidth =
6507b1019a6SJerry Jelinek (UINT8) AccessByteWidth;
65126f3cdf0SGordon Ross }
65226f3cdf0SGordon Ross }
65326f3cdf0SGordon Ross
6547c478bd9Sstevel@tonic-gate /* An additional reference for the container */
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate AcpiUtAddReference (ObjDesc->Field.RegionObj);
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
6597c478bd9Sstevel@tonic-gate "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",
6607b1019a6SJerry Jelinek ObjDesc->Field.StartFieldBitOffset,
6617b1019a6SJerry Jelinek ObjDesc->Field.BaseByteOffset,
6627b1019a6SJerry Jelinek ObjDesc->Field.AccessByteWidth,
6637b1019a6SJerry Jelinek ObjDesc->Field.RegionObj));
6647c478bd9Sstevel@tonic-gate break;
6657c478bd9Sstevel@tonic-gate
6667c478bd9Sstevel@tonic-gate case ACPI_TYPE_LOCAL_BANK_FIELD:
6677c478bd9Sstevel@tonic-gate
66826f3cdf0SGordon Ross ObjDesc->BankField.Value = Info->BankValue;
66926f3cdf0SGordon Ross ObjDesc->BankField.RegionObj =
67026f3cdf0SGordon Ross AcpiNsGetAttachedObject (Info->RegionNode);
67126f3cdf0SGordon Ross ObjDesc->BankField.BankObj =
67226f3cdf0SGordon Ross AcpiNsGetAttachedObject (Info->RegisterNode);
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate /* An additional reference for the attached objects */
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate AcpiUtAddReference (ObjDesc->BankField.RegionObj);
6777c478bd9Sstevel@tonic-gate AcpiUtAddReference (ObjDesc->BankField.BankObj);
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
6807c478bd9Sstevel@tonic-gate "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",
6817c478bd9Sstevel@tonic-gate ObjDesc->BankField.StartFieldBitOffset,
6827c478bd9Sstevel@tonic-gate ObjDesc->BankField.BaseByteOffset,
6837c478bd9Sstevel@tonic-gate ObjDesc->Field.AccessByteWidth,
6847c478bd9Sstevel@tonic-gate ObjDesc->BankField.RegionObj,
6857c478bd9Sstevel@tonic-gate ObjDesc->BankField.BankObj));
686db2bae30SDana Myers
687db2bae30SDana Myers /*
688db2bae30SDana Myers * Remember location in AML stream of the field unit
689db2bae30SDana Myers * opcode and operands -- since the BankValue
690db2bae30SDana Myers * operands must be evaluated.
691db2bae30SDana Myers */
69226f3cdf0SGordon Ross SecondDesc = ObjDesc->Common.NextObject;
69326f3cdf0SGordon Ross SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
69426f3cdf0SGordon Ross Info->DataRegisterNode)->Named.Data;
69526f3cdf0SGordon Ross SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
69626f3cdf0SGordon Ross Info->DataRegisterNode)->Named.Length;
697db2bae30SDana Myers
6987c478bd9Sstevel@tonic-gate break;
6997c478bd9Sstevel@tonic-gate
7007c478bd9Sstevel@tonic-gate case ACPI_TYPE_LOCAL_INDEX_FIELD:
7017c478bd9Sstevel@tonic-gate
70230082d0cSmyers /* Get the Index and Data registers */
70330082d0cSmyers
70426f3cdf0SGordon Ross ObjDesc->IndexField.IndexObj =
70526f3cdf0SGordon Ross AcpiNsGetAttachedObject (Info->RegisterNode);
70626f3cdf0SGordon Ross ObjDesc->IndexField.DataObj =
70726f3cdf0SGordon Ross AcpiNsGetAttachedObject (Info->DataRegisterNode);
7087c478bd9Sstevel@tonic-gate
7097c478bd9Sstevel@tonic-gate if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj)
7107c478bd9Sstevel@tonic-gate {
71130082d0cSmyers ACPI_ERROR ((AE_INFO, "Null Index Object during field prep"));
7127c478bd9Sstevel@tonic-gate AcpiUtDeleteObjectDesc (ObjDesc);
7137c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_AML_INTERNAL);
7147c478bd9Sstevel@tonic-gate }
7157c478bd9Sstevel@tonic-gate
7167c478bd9Sstevel@tonic-gate /* An additional reference for the attached objects */
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate AcpiUtAddReference (ObjDesc->IndexField.DataObj);
7197c478bd9Sstevel@tonic-gate AcpiUtAddReference (ObjDesc->IndexField.IndexObj);
7207c478bd9Sstevel@tonic-gate
72130082d0cSmyers /*
72227f7c583Smyers * April 2006: Changed to match MS behavior
72330082d0cSmyers *
72430082d0cSmyers * The value written to the Index register is the byte offset of the
72527f7c583Smyers * target field in units of the granularity of the IndexField
72630082d0cSmyers *
72730082d0cSmyers * Previously, the value was calculated as an index in terms of the
72830082d0cSmyers * width of the Data register, as below:
72930082d0cSmyers *
73027f7c583Smyers * ObjDesc->IndexField.Value = (UINT32)
73127f7c583Smyers * (Info->FieldBitPosition / ACPI_MUL_8 (
73227f7c583Smyers * ObjDesc->Field.AccessByteWidth));
73327f7c583Smyers *
73427f7c583Smyers * February 2006: Tried value as a byte offset:
73527f7c583Smyers * ObjDesc->IndexField.Value = (UINT32)
73627f7c583Smyers * ACPI_DIV_8 (Info->FieldBitPosition);
73730082d0cSmyers */
73827f7c583Smyers ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN (
73927f7c583Smyers ACPI_DIV_8 (Info->FieldBitPosition),
74027f7c583Smyers ObjDesc->IndexField.AccessByteWidth);
74130082d0cSmyers
7427c478bd9Sstevel@tonic-gate ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
7437b1019a6SJerry Jelinek "IndexField: BitOff %X, Off %X, Value %X, "
7447b1019a6SJerry Jelinek "Gran %X, Index %p, Data %p\n",
7457c478bd9Sstevel@tonic-gate ObjDesc->IndexField.StartFieldBitOffset,
7467c478bd9Sstevel@tonic-gate ObjDesc->IndexField.BaseByteOffset,
7477c478bd9Sstevel@tonic-gate ObjDesc->IndexField.Value,
7487c478bd9Sstevel@tonic-gate ObjDesc->Field.AccessByteWidth,
7497c478bd9Sstevel@tonic-gate ObjDesc->IndexField.IndexObj,
7507c478bd9Sstevel@tonic-gate ObjDesc->IndexField.DataObj));
7517c478bd9Sstevel@tonic-gate break;
7527c478bd9Sstevel@tonic-gate
7537c478bd9Sstevel@tonic-gate default:
7547b1019a6SJerry Jelinek
7557c478bd9Sstevel@tonic-gate /* No other types should get here */
7567b1019a6SJerry Jelinek
7577c478bd9Sstevel@tonic-gate break;
7587c478bd9Sstevel@tonic-gate }
7597c478bd9Sstevel@tonic-gate
7607c478bd9Sstevel@tonic-gate /*
7617c478bd9Sstevel@tonic-gate * Store the constructed descriptor (ObjDesc) into the parent Node,
7627c478bd9Sstevel@tonic-gate * preserving the current type of that NamedObj.
7637c478bd9Sstevel@tonic-gate */
7647b1019a6SJerry Jelinek Status = AcpiNsAttachObject (
7657b1019a6SJerry Jelinek Info->FieldNode, ObjDesc, AcpiNsGetType (Info->FieldNode));
7667c478bd9Sstevel@tonic-gate
7677b1019a6SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
7687b1019a6SJerry Jelinek "Set NamedObj %p [%4.4s], ObjDesc %p\n",
76926f3cdf0SGordon Ross Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc));
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate /* Remove local reference to the object */
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate AcpiUtRemoveReference (ObjDesc);
7747c478bd9Sstevel@tonic-gate return_ACPI_STATUS (Status);
7757c478bd9Sstevel@tonic-gate }
776