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