exprep.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer
2 1.1.1.2.2.2 bouyer /******************************************************************************
3 1.1.1.2.2.2 bouyer *
4 1.1.1.2.2.2 bouyer * Module Name: exprep - ACPI AML (p-code) execution - field prep utilities
5 1.1.1.2.2.2 bouyer *
6 1.1.1.2.2.2 bouyer *****************************************************************************/
7 1.1.1.2.2.2 bouyer
8 1.1.1.2.2.2 bouyer /*
9 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.2.2 bouyer * All rights reserved.
11 1.1.1.2.2.2 bouyer *
12 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
14 1.1.1.2.2.2 bouyer * are met:
15 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.2.2 bouyer * without modification.
18 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.2.2 bouyer * binary redistribution.
23 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
26 1.1.1.2.2.2 bouyer *
27 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.2.2 bouyer * Software Foundation.
30 1.1.1.2.2.2 bouyer *
31 1.1.1.2.2.2 bouyer * NO WARRANTY
32 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2.2.2 bouyer */
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer #define __EXPREP_C__
46 1.1.1.2.2.2 bouyer
47 1.1.1.2.2.2 bouyer #include "acpi.h"
48 1.1.1.2.2.2 bouyer #include "accommon.h"
49 1.1.1.2.2.2 bouyer #include "acinterp.h"
50 1.1.1.2.2.2 bouyer #include "amlcode.h"
51 1.1.1.2.2.2 bouyer #include "acnamesp.h"
52 1.1.1.2.2.2 bouyer
53 1.1.1.2.2.2 bouyer
54 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_EXECUTER
55 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("exprep")
56 1.1.1.2.2.2 bouyer
57 1.1.1.2.2.2 bouyer /* Local prototypes */
58 1.1.1.2.2.2 bouyer
59 1.1.1.2.2.2 bouyer static UINT32
60 1.1.1.2.2.2 bouyer AcpiExDecodeFieldAccess (
61 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc,
62 1.1.1.2.2.2 bouyer UINT8 FieldFlags,
63 1.1.1.2.2.2 bouyer UINT32 *ReturnByteAlignment);
64 1.1.1.2.2.2 bouyer
65 1.1.1.2.2.2 bouyer
66 1.1.1.2.2.2 bouyer #ifdef ACPI_UNDER_DEVELOPMENT
67 1.1.1.2.2.2 bouyer
68 1.1.1.2.2.2 bouyer static UINT32
69 1.1.1.2.2.2 bouyer AcpiExGenerateAccess (
70 1.1.1.2.2.2 bouyer UINT32 FieldBitOffset,
71 1.1.1.2.2.2 bouyer UINT32 FieldBitLength,
72 1.1.1.2.2.2 bouyer UINT32 RegionLength);
73 1.1.1.2.2.2 bouyer
74 1.1.1.2.2.2 bouyer /*******************************************************************************
75 1.1.1.2.2.2 bouyer *
76 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExGenerateAccess
77 1.1.1.2.2.2 bouyer *
78 1.1.1.2.2.2 bouyer * PARAMETERS: FieldBitOffset - Start of field within parent region/buffer
79 1.1.1.2.2.2 bouyer * FieldBitLength - Length of field in bits
80 1.1.1.2.2.2 bouyer * RegionLength - Length of parent in bytes
81 1.1.1.2.2.2 bouyer *
82 1.1.1.2.2.2 bouyer * RETURN: Field granularity (8, 16, 32 or 64) and
83 1.1.1.2.2.2 bouyer * ByteAlignment (1, 2, 3, or 4)
84 1.1.1.2.2.2 bouyer *
85 1.1.1.2.2.2 bouyer * DESCRIPTION: Generate an optimal access width for fields defined with the
86 1.1.1.2.2.2 bouyer * AnyAcc keyword.
87 1.1.1.2.2.2 bouyer *
88 1.1.1.2.2.2 bouyer * NOTE: Need to have the RegionLength in order to check for boundary
89 1.1.1.2.2.2 bouyer * conditions (end-of-region). However, the RegionLength is a deferred
90 1.1.1.2.2.2 bouyer * operation. Therefore, to complete this implementation, the generation
91 1.1.1.2.2.2 bouyer * of this access width must be deferred until the region length has
92 1.1.1.2.2.2 bouyer * been evaluated.
93 1.1.1.2.2.2 bouyer *
94 1.1.1.2.2.2 bouyer ******************************************************************************/
95 1.1.1.2.2.2 bouyer
96 1.1.1.2.2.2 bouyer static UINT32
97 1.1.1.2.2.2 bouyer AcpiExGenerateAccess (
98 1.1.1.2.2.2 bouyer UINT32 FieldBitOffset,
99 1.1.1.2.2.2 bouyer UINT32 FieldBitLength,
100 1.1.1.2.2.2 bouyer UINT32 RegionLength)
101 1.1.1.2.2.2 bouyer {
102 1.1.1.2.2.2 bouyer UINT32 FieldByteLength;
103 1.1.1.2.2.2 bouyer UINT32 FieldByteOffset;
104 1.1.1.2.2.2 bouyer UINT32 FieldByteEndOffset;
105 1.1.1.2.2.2 bouyer UINT32 AccessByteWidth;
106 1.1.1.2.2.2 bouyer UINT32 FieldStartOffset;
107 1.1.1.2.2.2 bouyer UINT32 FieldEndOffset;
108 1.1.1.2.2.2 bouyer UINT32 MinimumAccessWidth = 0xFFFFFFFF;
109 1.1.1.2.2.2 bouyer UINT32 MinimumAccesses = 0xFFFFFFFF;
110 1.1.1.2.2.2 bouyer UINT32 Accesses;
111 1.1.1.2.2.2 bouyer
112 1.1.1.2.2.2 bouyer
113 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (ExGenerateAccess);
114 1.1.1.2.2.2 bouyer
115 1.1.1.2.2.2 bouyer
116 1.1.1.2.2.2 bouyer /* Round Field start offset and length to "minimal" byte boundaries */
117 1.1.1.2.2.2 bouyer
118 1.1.1.2.2.2 bouyer FieldByteOffset = ACPI_DIV_8 (ACPI_ROUND_DOWN (FieldBitOffset, 8));
119 1.1.1.2.2.2 bouyer FieldByteEndOffset = ACPI_DIV_8 (ACPI_ROUND_UP (FieldBitLength +
120 1.1.1.2.2.2 bouyer FieldBitOffset, 8));
121 1.1.1.2.2.2 bouyer FieldByteLength = FieldByteEndOffset - FieldByteOffset;
122 1.1.1.2.2.2 bouyer
123 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
124 1.1.1.2.2.2 bouyer "Bit length %u, Bit offset %u\n",
125 1.1.1.2.2.2 bouyer FieldBitLength, FieldBitOffset));
126 1.1.1.2.2.2 bouyer
127 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
128 1.1.1.2.2.2 bouyer "Byte Length %u, Byte Offset %u, End Offset %u\n",
129 1.1.1.2.2.2 bouyer FieldByteLength, FieldByteOffset, FieldByteEndOffset));
130 1.1.1.2.2.2 bouyer
131 1.1.1.2.2.2 bouyer /*
132 1.1.1.2.2.2 bouyer * Iterative search for the maximum access width that is both aligned
133 1.1.1.2.2.2 bouyer * and does not go beyond the end of the region
134 1.1.1.2.2.2 bouyer *
135 1.1.1.2.2.2 bouyer * Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes)
136 1.1.1.2.2.2 bouyer */
137 1.1.1.2.2.2 bouyer for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1)
138 1.1.1.2.2.2 bouyer {
139 1.1.1.2.2.2 bouyer /*
140 1.1.1.2.2.2 bouyer * 1) Round end offset up to next access boundary and make sure that
141 1.1.1.2.2.2 bouyer * this does not go beyond the end of the parent region.
142 1.1.1.2.2.2 bouyer * 2) When the Access width is greater than the FieldByteLength, we
143 1.1.1.2.2.2 bouyer * are done. (This does not optimize for the perfectly aligned
144 1.1.1.2.2.2 bouyer * case yet).
145 1.1.1.2.2.2 bouyer */
146 1.1.1.2.2.2 bouyer if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <= RegionLength)
147 1.1.1.2.2.2 bouyer {
148 1.1.1.2.2.2 bouyer FieldStartOffset =
149 1.1.1.2.2.2 bouyer ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) /
150 1.1.1.2.2.2 bouyer AccessByteWidth;
151 1.1.1.2.2.2 bouyer
152 1.1.1.2.2.2 bouyer FieldEndOffset =
153 1.1.1.2.2.2 bouyer ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset),
154 1.1.1.2.2.2 bouyer AccessByteWidth) / AccessByteWidth;
155 1.1.1.2.2.2 bouyer
156 1.1.1.2.2.2 bouyer Accesses = FieldEndOffset - FieldStartOffset;
157 1.1.1.2.2.2 bouyer
158 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
159 1.1.1.2.2.2 bouyer "AccessWidth %u end is within region\n", AccessByteWidth));
160 1.1.1.2.2.2 bouyer
161 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
162 1.1.1.2.2.2 bouyer "Field Start %u, Field End %u -- requires %u accesses\n",
163 1.1.1.2.2.2 bouyer FieldStartOffset, FieldEndOffset, Accesses));
164 1.1.1.2.2.2 bouyer
165 1.1.1.2.2.2 bouyer /* Single access is optimal */
166 1.1.1.2.2.2 bouyer
167 1.1.1.2.2.2 bouyer if (Accesses <= 1)
168 1.1.1.2.2.2 bouyer {
169 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
170 1.1.1.2.2.2 bouyer "Entire field can be accessed with one operation of size %u\n",
171 1.1.1.2.2.2 bouyer AccessByteWidth));
172 1.1.1.2.2.2 bouyer return_VALUE (AccessByteWidth);
173 1.1.1.2.2.2 bouyer }
174 1.1.1.2.2.2 bouyer
175 1.1.1.2.2.2 bouyer /*
176 1.1.1.2.2.2 bouyer * Fits in the region, but requires more than one read/write.
177 1.1.1.2.2.2 bouyer * try the next wider access on next iteration
178 1.1.1.2.2.2 bouyer */
179 1.1.1.2.2.2 bouyer if (Accesses < MinimumAccesses)
180 1.1.1.2.2.2 bouyer {
181 1.1.1.2.2.2 bouyer MinimumAccesses = Accesses;
182 1.1.1.2.2.2 bouyer MinimumAccessWidth = AccessByteWidth;
183 1.1.1.2.2.2 bouyer }
184 1.1.1.2.2.2 bouyer }
185 1.1.1.2.2.2 bouyer else
186 1.1.1.2.2.2 bouyer {
187 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
188 1.1.1.2.2.2 bouyer "AccessWidth %u end is NOT within region\n", AccessByteWidth));
189 1.1.1.2.2.2 bouyer if (AccessByteWidth == 1)
190 1.1.1.2.2.2 bouyer {
191 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
192 1.1.1.2.2.2 bouyer "Field goes beyond end-of-region!\n"));
193 1.1.1.2.2.2 bouyer
194 1.1.1.2.2.2 bouyer /* Field does not fit in the region at all */
195 1.1.1.2.2.2 bouyer
196 1.1.1.2.2.2 bouyer return_VALUE (0);
197 1.1.1.2.2.2 bouyer }
198 1.1.1.2.2.2 bouyer
199 1.1.1.2.2.2 bouyer /*
200 1.1.1.2.2.2 bouyer * This width goes beyond the end-of-region, back off to
201 1.1.1.2.2.2 bouyer * previous access
202 1.1.1.2.2.2 bouyer */
203 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
204 1.1.1.2.2.2 bouyer "Backing off to previous optimal access width of %u\n",
205 1.1.1.2.2.2 bouyer MinimumAccessWidth));
206 1.1.1.2.2.2 bouyer return_VALUE (MinimumAccessWidth);
207 1.1.1.2.2.2 bouyer }
208 1.1.1.2.2.2 bouyer }
209 1.1.1.2.2.2 bouyer
210 1.1.1.2.2.2 bouyer /*
211 1.1.1.2.2.2 bouyer * Could not read/write field with one operation,
212 1.1.1.2.2.2 bouyer * just use max access width
213 1.1.1.2.2.2 bouyer */
214 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
215 1.1.1.2.2.2 bouyer "Cannot access field in one operation, using width 8\n"));
216 1.1.1.2.2.2 bouyer return_VALUE (8);
217 1.1.1.2.2.2 bouyer }
218 1.1.1.2.2.2 bouyer #endif /* ACPI_UNDER_DEVELOPMENT */
219 1.1.1.2.2.2 bouyer
220 1.1.1.2.2.2 bouyer
221 1.1.1.2.2.2 bouyer /*******************************************************************************
222 1.1.1.2.2.2 bouyer *
223 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExDecodeFieldAccess
224 1.1.1.2.2.2 bouyer *
225 1.1.1.2.2.2 bouyer * PARAMETERS: ObjDesc - Field object
226 1.1.1.2.2.2 bouyer * FieldFlags - Encoded fieldflags (contains access bits)
227 1.1.1.2.2.2 bouyer * ReturnByteAlignment - Where the byte alignment is returned
228 1.1.1.2.2.2 bouyer *
229 1.1.1.2.2.2 bouyer * RETURN: Field granularity (8, 16, 32 or 64) and
230 1.1.1.2.2.2 bouyer * ByteAlignment (1, 2, 3, or 4)
231 1.1.1.2.2.2 bouyer *
232 1.1.1.2.2.2 bouyer * DESCRIPTION: Decode the AccessType bits of a field definition.
233 1.1.1.2.2.2 bouyer *
234 1.1.1.2.2.2 bouyer ******************************************************************************/
235 1.1.1.2.2.2 bouyer
236 1.1.1.2.2.2 bouyer static UINT32
237 1.1.1.2.2.2 bouyer AcpiExDecodeFieldAccess (
238 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc,
239 1.1.1.2.2.2 bouyer UINT8 FieldFlags,
240 1.1.1.2.2.2 bouyer UINT32 *ReturnByteAlignment)
241 1.1.1.2.2.2 bouyer {
242 1.1.1.2.2.2 bouyer UINT32 Access;
243 1.1.1.2.2.2 bouyer UINT32 ByteAlignment;
244 1.1.1.2.2.2 bouyer UINT32 BitLength;
245 1.1.1.2.2.2 bouyer
246 1.1.1.2.2.2 bouyer
247 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (ExDecodeFieldAccess);
248 1.1.1.2.2.2 bouyer
249 1.1.1.2.2.2 bouyer
250 1.1.1.2.2.2 bouyer Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK);
251 1.1.1.2.2.2 bouyer
252 1.1.1.2.2.2 bouyer switch (Access)
253 1.1.1.2.2.2 bouyer {
254 1.1.1.2.2.2 bouyer case AML_FIELD_ACCESS_ANY:
255 1.1.1.2.2.2 bouyer
256 1.1.1.2.2.2 bouyer #ifdef ACPI_UNDER_DEVELOPMENT
257 1.1.1.2.2.2 bouyer ByteAlignment =
258 1.1.1.2.2.2 bouyer AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset,
259 1.1.1.2.2.2 bouyer ObjDesc->CommonField.BitLength,
260 1.1.1.2.2.2 bouyer 0xFFFFFFFF /* Temp until we pass RegionLength as parameter */);
261 1.1.1.2.2.2 bouyer BitLength = ByteAlignment * 8;
262 1.1.1.2.2.2 bouyer #endif
263 1.1.1.2.2.2 bouyer
264 1.1.1.2.2.2 bouyer ByteAlignment = 1;
265 1.1.1.2.2.2 bouyer BitLength = 8;
266 1.1.1.2.2.2 bouyer break;
267 1.1.1.2.2.2 bouyer
268 1.1.1.2.2.2 bouyer case AML_FIELD_ACCESS_BYTE:
269 1.1.1.2.2.2 bouyer case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */
270 1.1.1.2.2.2 bouyer ByteAlignment = 1;
271 1.1.1.2.2.2 bouyer BitLength = 8;
272 1.1.1.2.2.2 bouyer break;
273 1.1.1.2.2.2 bouyer
274 1.1.1.2.2.2 bouyer case AML_FIELD_ACCESS_WORD:
275 1.1.1.2.2.2 bouyer ByteAlignment = 2;
276 1.1.1.2.2.2 bouyer BitLength = 16;
277 1.1.1.2.2.2 bouyer break;
278 1.1.1.2.2.2 bouyer
279 1.1.1.2.2.2 bouyer case AML_FIELD_ACCESS_DWORD:
280 1.1.1.2.2.2 bouyer ByteAlignment = 4;
281 1.1.1.2.2.2 bouyer BitLength = 32;
282 1.1.1.2.2.2 bouyer break;
283 1.1.1.2.2.2 bouyer
284 1.1.1.2.2.2 bouyer case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */
285 1.1.1.2.2.2 bouyer ByteAlignment = 8;
286 1.1.1.2.2.2 bouyer BitLength = 64;
287 1.1.1.2.2.2 bouyer break;
288 1.1.1.2.2.2 bouyer
289 1.1.1.2.2.2 bouyer default:
290 1.1.1.2.2.2 bouyer /* Invalid field access type */
291 1.1.1.2.2.2 bouyer
292 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
293 1.1.1.2.2.2 bouyer "Unknown field access type 0x%X",
294 1.1.1.2.2.2 bouyer Access));
295 1.1.1.2.2.2 bouyer return_UINT32 (0);
296 1.1.1.2.2.2 bouyer }
297 1.1.1.2.2.2 bouyer
298 1.1.1.2.2.2 bouyer if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
299 1.1.1.2.2.2 bouyer {
300 1.1.1.2.2.2 bouyer /*
301 1.1.1.2.2.2 bouyer * BufferField access can be on any byte boundary, so the
302 1.1.1.2.2.2 bouyer * ByteAlignment is always 1 byte -- regardless of any ByteAlignment
303 1.1.1.2.2.2 bouyer * implied by the field access type.
304 1.1.1.2.2.2 bouyer */
305 1.1.1.2.2.2 bouyer ByteAlignment = 1;
306 1.1.1.2.2.2 bouyer }
307 1.1.1.2.2.2 bouyer
308 1.1.1.2.2.2 bouyer *ReturnByteAlignment = ByteAlignment;
309 1.1.1.2.2.2 bouyer return_UINT32 (BitLength);
310 1.1.1.2.2.2 bouyer }
311 1.1.1.2.2.2 bouyer
312 1.1.1.2.2.2 bouyer
313 1.1.1.2.2.2 bouyer /*******************************************************************************
314 1.1.1.2.2.2 bouyer *
315 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExPrepCommonFieldObject
316 1.1.1.2.2.2 bouyer *
317 1.1.1.2.2.2 bouyer * PARAMETERS: ObjDesc - The field object
318 1.1.1.2.2.2 bouyer * FieldFlags - Access, LockRule, and UpdateRule.
319 1.1.1.2.2.2 bouyer * The format of a FieldFlag is described
320 1.1.1.2.2.2 bouyer * in the ACPI specification
321 1.1.1.2.2.2 bouyer * FieldAttribute - Special attributes (not used)
322 1.1.1.2.2.2 bouyer * FieldBitPosition - Field start position
323 1.1.1.2.2.2 bouyer * FieldBitLength - Field length in number of bits
324 1.1.1.2.2.2 bouyer *
325 1.1.1.2.2.2 bouyer * RETURN: Status
326 1.1.1.2.2.2 bouyer *
327 1.1.1.2.2.2 bouyer * DESCRIPTION: Initialize the areas of the field object that are common
328 1.1.1.2.2.2 bouyer * to the various types of fields. Note: This is very "sensitive"
329 1.1.1.2.2.2 bouyer * code because we are solving the general case for field
330 1.1.1.2.2.2 bouyer * alignment.
331 1.1.1.2.2.2 bouyer *
332 1.1.1.2.2.2 bouyer ******************************************************************************/
333 1.1.1.2.2.2 bouyer
334 1.1.1.2.2.2 bouyer ACPI_STATUS
335 1.1.1.2.2.2 bouyer AcpiExPrepCommonFieldObject (
336 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc,
337 1.1.1.2.2.2 bouyer UINT8 FieldFlags,
338 1.1.1.2.2.2 bouyer UINT8 FieldAttribute,
339 1.1.1.2.2.2 bouyer UINT32 FieldBitPosition,
340 1.1.1.2.2.2 bouyer UINT32 FieldBitLength)
341 1.1.1.2.2.2 bouyer {
342 1.1.1.2.2.2 bouyer UINT32 AccessBitWidth;
343 1.1.1.2.2.2 bouyer UINT32 ByteAlignment;
344 1.1.1.2.2.2 bouyer UINT32 NearestByteAddress;
345 1.1.1.2.2.2 bouyer
346 1.1.1.2.2.2 bouyer
347 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject);
348 1.1.1.2.2.2 bouyer
349 1.1.1.2.2.2 bouyer
350 1.1.1.2.2.2 bouyer /*
351 1.1.1.2.2.2 bouyer * Note: the structure being initialized is the
352 1.1.1.2.2.2 bouyer * ACPI_COMMON_FIELD_INFO; No structure fields outside of the common
353 1.1.1.2.2.2 bouyer * area are initialized by this procedure.
354 1.1.1.2.2.2 bouyer */
355 1.1.1.2.2.2 bouyer ObjDesc->CommonField.FieldFlags = FieldFlags;
356 1.1.1.2.2.2 bouyer ObjDesc->CommonField.Attribute = FieldAttribute;
357 1.1.1.2.2.2 bouyer ObjDesc->CommonField.BitLength = FieldBitLength;
358 1.1.1.2.2.2 bouyer
359 1.1.1.2.2.2 bouyer /*
360 1.1.1.2.2.2 bouyer * Decode the access type so we can compute offsets. The access type gives
361 1.1.1.2.2.2 bouyer * two pieces of information - the width of each field access and the
362 1.1.1.2.2.2 bouyer * necessary ByteAlignment (address granularity) of the access.
363 1.1.1.2.2.2 bouyer *
364 1.1.1.2.2.2 bouyer * For AnyAcc, the AccessBitWidth is the largest width that is both
365 1.1.1.2.2.2 bouyer * necessary and possible in an attempt to access the whole field in one
366 1.1.1.2.2.2 bouyer * I/O operation. However, for AnyAcc, the ByteAlignment is always one
367 1.1.1.2.2.2 bouyer * byte.
368 1.1.1.2.2.2 bouyer *
369 1.1.1.2.2.2 bouyer * For all Buffer Fields, the ByteAlignment is always one byte.
370 1.1.1.2.2.2 bouyer *
371 1.1.1.2.2.2 bouyer * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is
372 1.1.1.2.2.2 bouyer * the same (equivalent) as the ByteAlignment.
373 1.1.1.2.2.2 bouyer */
374 1.1.1.2.2.2 bouyer AccessBitWidth = AcpiExDecodeFieldAccess (ObjDesc, FieldFlags,
375 1.1.1.2.2.2 bouyer &ByteAlignment);
376 1.1.1.2.2.2 bouyer if (!AccessBitWidth)
377 1.1.1.2.2.2 bouyer {
378 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
379 1.1.1.2.2.2 bouyer }
380 1.1.1.2.2.2 bouyer
381 1.1.1.2.2.2 bouyer /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */
382 1.1.1.2.2.2 bouyer
383 1.1.1.2.2.2 bouyer ObjDesc->CommonField.AccessByteWidth = (UINT8)
384 1.1.1.2.2.2 bouyer ACPI_DIV_8 (AccessBitWidth);
385 1.1.1.2.2.2 bouyer
386 1.1.1.2.2.2 bouyer /*
387 1.1.1.2.2.2 bouyer * BaseByteOffset is the address of the start of the field within the
388 1.1.1.2.2.2 bouyer * region. It is the byte address of the first *datum* (field-width data
389 1.1.1.2.2.2 bouyer * unit) of the field. (i.e., the first datum that contains at least the
390 1.1.1.2.2.2 bouyer * first *bit* of the field.)
391 1.1.1.2.2.2 bouyer *
392 1.1.1.2.2.2 bouyer * Note: ByteAlignment is always either equal to the AccessBitWidth or 8
393 1.1.1.2.2.2 bouyer * (Byte access), and it defines the addressing granularity of the parent
394 1.1.1.2.2.2 bouyer * region or buffer.
395 1.1.1.2.2.2 bouyer */
396 1.1.1.2.2.2 bouyer NearestByteAddress =
397 1.1.1.2.2.2 bouyer ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition);
398 1.1.1.2.2.2 bouyer ObjDesc->CommonField.BaseByteOffset = (UINT32)
399 1.1.1.2.2.2 bouyer ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment);
400 1.1.1.2.2.2 bouyer
401 1.1.1.2.2.2 bouyer /*
402 1.1.1.2.2.2 bouyer * StartFieldBitOffset is the offset of the first bit of the field within
403 1.1.1.2.2.2 bouyer * a field datum.
404 1.1.1.2.2.2 bouyer */
405 1.1.1.2.2.2 bouyer ObjDesc->CommonField.StartFieldBitOffset = (UINT8)
406 1.1.1.2.2.2 bouyer (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset));
407 1.1.1.2.2.2 bouyer
408 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
409 1.1.1.2.2.2 bouyer }
410 1.1.1.2.2.2 bouyer
411 1.1.1.2.2.2 bouyer
412 1.1.1.2.2.2 bouyer /*******************************************************************************
413 1.1.1.2.2.2 bouyer *
414 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExPrepFieldValue
415 1.1.1.2.2.2 bouyer *
416 1.1.1.2.2.2 bouyer * PARAMETERS: Info - Contains all field creation info
417 1.1.1.2.2.2 bouyer *
418 1.1.1.2.2.2 bouyer * RETURN: Status
419 1.1.1.2.2.2 bouyer *
420 1.1.1.2.2.2 bouyer * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type DefField and
421 1.1.1.2.2.2 bouyer * connect it to the parent Node.
422 1.1.1.2.2.2 bouyer *
423 1.1.1.2.2.2 bouyer ******************************************************************************/
424 1.1.1.2.2.2 bouyer
425 1.1.1.2.2.2 bouyer ACPI_STATUS
426 1.1.1.2.2.2 bouyer AcpiExPrepFieldValue (
427 1.1.1.2.2.2 bouyer ACPI_CREATE_FIELD_INFO *Info)
428 1.1.1.2.2.2 bouyer {
429 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc;
430 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *SecondDesc = NULL;
431 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
432 1.1.1.2.2.2 bouyer UINT32 AccessByteWidth;
433 1.1.1.2.2.2 bouyer UINT32 Type;
434 1.1.1.2.2.2 bouyer
435 1.1.1.2.2.2 bouyer
436 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (ExPrepFieldValue);
437 1.1.1.2.2.2 bouyer
438 1.1.1.2.2.2 bouyer
439 1.1.1.2.2.2 bouyer /* Parameter validation */
440 1.1.1.2.2.2 bouyer
441 1.1.1.2.2.2 bouyer if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD)
442 1.1.1.2.2.2 bouyer {
443 1.1.1.2.2.2 bouyer if (!Info->RegionNode)
444 1.1.1.2.2.2 bouyer {
445 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Null RegionNode"));
446 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_NO_OPERAND);
447 1.1.1.2.2.2 bouyer }
448 1.1.1.2.2.2 bouyer
449 1.1.1.2.2.2 bouyer Type = AcpiNsGetType (Info->RegionNode);
450 1.1.1.2.2.2 bouyer if (Type != ACPI_TYPE_REGION)
451 1.1.1.2.2.2 bouyer {
452 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)",
453 1.1.1.2.2.2 bouyer Type, AcpiUtGetTypeName (Type)));
454 1.1.1.2.2.2 bouyer
455 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
456 1.1.1.2.2.2 bouyer }
457 1.1.1.2.2.2 bouyer }
458 1.1.1.2.2.2 bouyer
459 1.1.1.2.2.2 bouyer /* Allocate a new field object */
460 1.1.1.2.2.2 bouyer
461 1.1.1.2.2.2 bouyer ObjDesc = AcpiUtCreateInternalObject (Info->FieldType);
462 1.1.1.2.2.2 bouyer if (!ObjDesc)
463 1.1.1.2.2.2 bouyer {
464 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
465 1.1.1.2.2.2 bouyer }
466 1.1.1.2.2.2 bouyer
467 1.1.1.2.2.2 bouyer /* Initialize areas of the object that are common to all fields */
468 1.1.1.2.2.2 bouyer
469 1.1.1.2.2.2 bouyer ObjDesc->CommonField.Node = Info->FieldNode;
470 1.1.1.2.2.2 bouyer Status = AcpiExPrepCommonFieldObject (ObjDesc,
471 1.1.1.2.2.2 bouyer Info->FieldFlags, Info->Attribute,
472 1.1.1.2.2.2 bouyer Info->FieldBitPosition, Info->FieldBitLength);
473 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
474 1.1.1.2.2.2 bouyer {
475 1.1.1.2.2.2 bouyer AcpiUtDeleteObjectDesc (ObjDesc);
476 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
477 1.1.1.2.2.2 bouyer }
478 1.1.1.2.2.2 bouyer
479 1.1.1.2.2.2 bouyer /* Initialize areas of the object that are specific to the field type */
480 1.1.1.2.2.2 bouyer
481 1.1.1.2.2.2 bouyer switch (Info->FieldType)
482 1.1.1.2.2.2 bouyer {
483 1.1.1.2.2.2 bouyer case ACPI_TYPE_LOCAL_REGION_FIELD:
484 1.1.1.2.2.2 bouyer
485 1.1.1.2.2.2 bouyer ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode);
486 1.1.1.2.2.2 bouyer
487 1.1.1.2.2.2 bouyer /* Allow full data read from EC address space */
488 1.1.1.2.2.2 bouyer
489 1.1.1.2.2.2 bouyer if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
490 1.1.1.2.2.2 bouyer (ObjDesc->CommonField.BitLength > 8))
491 1.1.1.2.2.2 bouyer {
492 1.1.1.2.2.2 bouyer AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES (
493 1.1.1.2.2.2 bouyer ObjDesc->CommonField.BitLength);
494 1.1.1.2.2.2 bouyer
495 1.1.1.2.2.2 bouyer /* Maximum byte width supported is 255 */
496 1.1.1.2.2.2 bouyer
497 1.1.1.2.2.2 bouyer if (AccessByteWidth < 256)
498 1.1.1.2.2.2 bouyer {
499 1.1.1.2.2.2 bouyer ObjDesc->CommonField.AccessByteWidth = (UINT8) AccessByteWidth;
500 1.1.1.2.2.2 bouyer }
501 1.1.1.2.2.2 bouyer }
502 1.1.1.2.2.2 bouyer
503 1.1.1.2.2.2 bouyer /* An additional reference for the container */
504 1.1.1.2.2.2 bouyer
505 1.1.1.2.2.2 bouyer AcpiUtAddReference (ObjDesc->Field.RegionObj);
506 1.1.1.2.2.2 bouyer
507 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
508 1.1.1.2.2.2 bouyer "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",
509 1.1.1.2.2.2 bouyer ObjDesc->Field.StartFieldBitOffset, ObjDesc->Field.BaseByteOffset,
510 1.1.1.2.2.2 bouyer ObjDesc->Field.AccessByteWidth, ObjDesc->Field.RegionObj));
511 1.1.1.2.2.2 bouyer break;
512 1.1.1.2.2.2 bouyer
513 1.1.1.2.2.2 bouyer
514 1.1.1.2.2.2 bouyer case ACPI_TYPE_LOCAL_BANK_FIELD:
515 1.1.1.2.2.2 bouyer
516 1.1.1.2.2.2 bouyer ObjDesc->BankField.Value = Info->BankValue;
517 1.1.1.2.2.2 bouyer ObjDesc->BankField.RegionObj =
518 1.1.1.2.2.2 bouyer AcpiNsGetAttachedObject (Info->RegionNode);
519 1.1.1.2.2.2 bouyer ObjDesc->BankField.BankObj =
520 1.1.1.2.2.2 bouyer AcpiNsGetAttachedObject (Info->RegisterNode);
521 1.1.1.2.2.2 bouyer
522 1.1.1.2.2.2 bouyer /* An additional reference for the attached objects */
523 1.1.1.2.2.2 bouyer
524 1.1.1.2.2.2 bouyer AcpiUtAddReference (ObjDesc->BankField.RegionObj);
525 1.1.1.2.2.2 bouyer AcpiUtAddReference (ObjDesc->BankField.BankObj);
526 1.1.1.2.2.2 bouyer
527 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
528 1.1.1.2.2.2 bouyer "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",
529 1.1.1.2.2.2 bouyer ObjDesc->BankField.StartFieldBitOffset,
530 1.1.1.2.2.2 bouyer ObjDesc->BankField.BaseByteOffset,
531 1.1.1.2.2.2 bouyer ObjDesc->Field.AccessByteWidth,
532 1.1.1.2.2.2 bouyer ObjDesc->BankField.RegionObj,
533 1.1.1.2.2.2 bouyer ObjDesc->BankField.BankObj));
534 1.1.1.2.2.2 bouyer
535 1.1.1.2.2.2 bouyer /*
536 1.1.1.2.2.2 bouyer * Remember location in AML stream of the field unit
537 1.1.1.2.2.2 bouyer * opcode and operands -- since the BankValue
538 1.1.1.2.2.2 bouyer * operands must be evaluated.
539 1.1.1.2.2.2 bouyer */
540 1.1.1.2.2.2 bouyer SecondDesc = ObjDesc->Common.NextObject;
541 1.1.1.2.2.2 bouyer SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
542 1.1.1.2.2.2 bouyer Info->DataRegisterNode)->Named.Data;
543 1.1.1.2.2.2 bouyer SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
544 1.1.1.2.2.2 bouyer Info->DataRegisterNode)->Named.Length;
545 1.1.1.2.2.2 bouyer
546 1.1.1.2.2.2 bouyer break;
547 1.1.1.2.2.2 bouyer
548 1.1.1.2.2.2 bouyer
549 1.1.1.2.2.2 bouyer case ACPI_TYPE_LOCAL_INDEX_FIELD:
550 1.1.1.2.2.2 bouyer
551 1.1.1.2.2.2 bouyer /* Get the Index and Data registers */
552 1.1.1.2.2.2 bouyer
553 1.1.1.2.2.2 bouyer ObjDesc->IndexField.IndexObj =
554 1.1.1.2.2.2 bouyer AcpiNsGetAttachedObject (Info->RegisterNode);
555 1.1.1.2.2.2 bouyer ObjDesc->IndexField.DataObj =
556 1.1.1.2.2.2 bouyer AcpiNsGetAttachedObject (Info->DataRegisterNode);
557 1.1.1.2.2.2 bouyer
558 1.1.1.2.2.2 bouyer if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj)
559 1.1.1.2.2.2 bouyer {
560 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Null Index Object during field prep"));
561 1.1.1.2.2.2 bouyer AcpiUtDeleteObjectDesc (ObjDesc);
562 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_INTERNAL);
563 1.1.1.2.2.2 bouyer }
564 1.1.1.2.2.2 bouyer
565 1.1.1.2.2.2 bouyer /* An additional reference for the attached objects */
566 1.1.1.2.2.2 bouyer
567 1.1.1.2.2.2 bouyer AcpiUtAddReference (ObjDesc->IndexField.DataObj);
568 1.1.1.2.2.2 bouyer AcpiUtAddReference (ObjDesc->IndexField.IndexObj);
569 1.1.1.2.2.2 bouyer
570 1.1.1.2.2.2 bouyer /*
571 1.1.1.2.2.2 bouyer * April 2006: Changed to match MS behavior
572 1.1.1.2.2.2 bouyer *
573 1.1.1.2.2.2 bouyer * The value written to the Index register is the byte offset of the
574 1.1.1.2.2.2 bouyer * target field in units of the granularity of the IndexField
575 1.1.1.2.2.2 bouyer *
576 1.1.1.2.2.2 bouyer * Previously, the value was calculated as an index in terms of the
577 1.1.1.2.2.2 bouyer * width of the Data register, as below:
578 1.1.1.2.2.2 bouyer *
579 1.1.1.2.2.2 bouyer * ObjDesc->IndexField.Value = (UINT32)
580 1.1.1.2.2.2 bouyer * (Info->FieldBitPosition / ACPI_MUL_8 (
581 1.1.1.2.2.2 bouyer * ObjDesc->Field.AccessByteWidth));
582 1.1.1.2.2.2 bouyer *
583 1.1.1.2.2.2 bouyer * February 2006: Tried value as a byte offset:
584 1.1.1.2.2.2 bouyer * ObjDesc->IndexField.Value = (UINT32)
585 1.1.1.2.2.2 bouyer * ACPI_DIV_8 (Info->FieldBitPosition);
586 1.1.1.2.2.2 bouyer */
587 1.1.1.2.2.2 bouyer ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN (
588 1.1.1.2.2.2 bouyer ACPI_DIV_8 (Info->FieldBitPosition),
589 1.1.1.2.2.2 bouyer ObjDesc->IndexField.AccessByteWidth);
590 1.1.1.2.2.2 bouyer
591 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
592 1.1.1.2.2.2 bouyer "IndexField: BitOff %X, Off %X, Value %X, Gran %X, Index %p, Data %p\n",
593 1.1.1.2.2.2 bouyer ObjDesc->IndexField.StartFieldBitOffset,
594 1.1.1.2.2.2 bouyer ObjDesc->IndexField.BaseByteOffset,
595 1.1.1.2.2.2 bouyer ObjDesc->IndexField.Value,
596 1.1.1.2.2.2 bouyer ObjDesc->Field.AccessByteWidth,
597 1.1.1.2.2.2 bouyer ObjDesc->IndexField.IndexObj,
598 1.1.1.2.2.2 bouyer ObjDesc->IndexField.DataObj));
599 1.1.1.2.2.2 bouyer break;
600 1.1.1.2.2.2 bouyer
601 1.1.1.2.2.2 bouyer default:
602 1.1.1.2.2.2 bouyer /* No other types should get here */
603 1.1.1.2.2.2 bouyer break;
604 1.1.1.2.2.2 bouyer }
605 1.1.1.2.2.2 bouyer
606 1.1.1.2.2.2 bouyer /*
607 1.1.1.2.2.2 bouyer * Store the constructed descriptor (ObjDesc) into the parent Node,
608 1.1.1.2.2.2 bouyer * preserving the current type of that NamedObj.
609 1.1.1.2.2.2 bouyer */
610 1.1.1.2.2.2 bouyer Status = AcpiNsAttachObject (Info->FieldNode, ObjDesc,
611 1.1.1.2.2.2 bouyer AcpiNsGetType (Info->FieldNode));
612 1.1.1.2.2.2 bouyer
613 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Set NamedObj %p [%4.4s], ObjDesc %p\n",
614 1.1.1.2.2.2 bouyer Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc));
615 1.1.1.2.2.2 bouyer
616 1.1.1.2.2.2 bouyer /* Remove local reference to the object */
617 1.1.1.2.2.2 bouyer
618 1.1.1.2.2.2 bouyer AcpiUtRemoveReference (ObjDesc);
619 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
620 1.1.1.2.2.2 bouyer }
621 1.1.1.2.2.2 bouyer
622