1 /******************************************************************************
3 * Module Name: exfldio - Aml Field I/O
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #include "accommon.h"
118 #include "acinterp.h"
120 #include "acevents.h"
121 #include "acdispat.h"
124 #define _COMPONENT ACPI_EXECUTER
125 ACPI_MODULE_NAME ("exfldio")
127 /* Local prototypes */
131 ACPI_OPERAND_OBJECT
*ObjDesc
,
132 UINT32 FieldDatumByteOffset
,
137 AcpiExRegisterOverflow (
138 ACPI_OPERAND_OBJECT
*ObjDesc
,
143 ACPI_OPERAND_OBJECT
*ObjDesc
,
144 UINT32 FieldDatumByteOffset
);
147 /*******************************************************************************
149 * FUNCTION: AcpiExSetupRegion
151 * PARAMETERS: ObjDesc - Field to be read or written
152 * FieldDatumByteOffset - Byte offset of this datum within the
157 * DESCRIPTION: Common processing for AcpiExExtractFromField and
158 * AcpiExInsertIntoField. Initialize the Region if necessary and
159 * validate the request.
161 ******************************************************************************/
165 ACPI_OPERAND_OBJECT
*ObjDesc
,
166 UINT32 FieldDatumByteOffset
)
168 ACPI_STATUS Status
= AE_OK
;
169 ACPI_OPERAND_OBJECT
*RgnDesc
;
173 ACPI_FUNCTION_TRACE_U32 (ExSetupRegion
, FieldDatumByteOffset
);
176 RgnDesc
= ObjDesc
->CommonField
.RegionObj
;
178 /* We must have a valid region */
180 if (RgnDesc
->Common
.Type
!= ACPI_TYPE_REGION
)
182 ACPI_ERROR ((AE_INFO
, "Needed Region, found type 0x%X (%s)",
183 RgnDesc
->Common
.Type
,
184 AcpiUtGetObjectTypeName (RgnDesc
)));
186 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
189 SpaceId
= RgnDesc
->Region
.SpaceId
;
191 /* Validate the Space ID */
193 if (!AcpiIsValidSpaceId (SpaceId
))
195 ACPI_ERROR ((AE_INFO
,
196 "Invalid/unknown Address Space ID: 0x%2.2X", SpaceId
));
197 return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID
);
201 * If the Region Address and Length have not been previously evaluated,
202 * evaluate them now and save the results.
204 if (!(RgnDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
206 Status
= AcpiDsGetRegionArguments (RgnDesc
);
207 if (ACPI_FAILURE (Status
))
209 return_ACPI_STATUS (Status
);
214 * Exit now for SMBus, GSBus or IPMI address space, it has a non-linear
215 * address space and the request cannot be directly validated
217 if (SpaceId
== ACPI_ADR_SPACE_SMBUS
||
218 SpaceId
== ACPI_ADR_SPACE_GSBUS
||
219 SpaceId
== ACPI_ADR_SPACE_IPMI
)
221 /* SMBus or IPMI has a non-linear address space */
223 return_ACPI_STATUS (AE_OK
);
226 #ifdef ACPI_UNDER_DEVELOPMENT
228 * If the Field access is AnyAcc, we can now compute the optimal
229 * access (because we know know the length of the parent region)
231 if (!(ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
233 if (ACPI_FAILURE (Status
))
235 return_ACPI_STATUS (Status
);
241 * Validate the request. The entire request from the byte offset for a
242 * length of one field datum (access width) must fit within the region.
243 * (Region length is specified in bytes)
245 if (RgnDesc
->Region
.Length
<
246 (ObjDesc
->CommonField
.BaseByteOffset
+ FieldDatumByteOffset
+
247 ObjDesc
->CommonField
.AccessByteWidth
))
249 if (AcpiGbl_EnableInterpreterSlack
)
252 * Slack mode only: We will go ahead and allow access to this
253 * field if it is within the region length rounded up to the next
254 * access width boundary. ACPI_SIZE cast for 64-bit compile.
256 if (ACPI_ROUND_UP (RgnDesc
->Region
.Length
,
257 ObjDesc
->CommonField
.AccessByteWidth
) >=
258 ((ACPI_SIZE
) ObjDesc
->CommonField
.BaseByteOffset
+
259 ObjDesc
->CommonField
.AccessByteWidth
+
260 FieldDatumByteOffset
))
262 return_ACPI_STATUS (AE_OK
);
266 if (RgnDesc
->Region
.Length
< ObjDesc
->CommonField
.AccessByteWidth
)
269 * This is the case where the AccessType (AccWord, etc.) is wider
270 * than the region itself. For example, a region of length one
271 * byte, and a field with Dword access specified.
273 ACPI_ERROR ((AE_INFO
,
274 "Field [%4.4s] access width (%u bytes) "
275 "too large for region [%4.4s] (length %u)",
276 AcpiUtGetNodeName (ObjDesc
->CommonField
.Node
),
277 ObjDesc
->CommonField
.AccessByteWidth
,
278 AcpiUtGetNodeName (RgnDesc
->Region
.Node
),
279 RgnDesc
->Region
.Length
));
283 * Offset rounded up to next multiple of field width
284 * exceeds region length, indicate an error
286 ACPI_ERROR ((AE_INFO
,
287 "Field [%4.4s] Base+Offset+Width %u+%u+%u "
288 "is beyond end of region [%4.4s] (length %u)",
289 AcpiUtGetNodeName (ObjDesc
->CommonField
.Node
),
290 ObjDesc
->CommonField
.BaseByteOffset
,
291 FieldDatumByteOffset
, ObjDesc
->CommonField
.AccessByteWidth
,
292 AcpiUtGetNodeName (RgnDesc
->Region
.Node
),
293 RgnDesc
->Region
.Length
));
295 return_ACPI_STATUS (AE_AML_REGION_LIMIT
);
298 return_ACPI_STATUS (AE_OK
);
302 /*******************************************************************************
304 * FUNCTION: AcpiExAccessRegion
306 * PARAMETERS: ObjDesc - Field to be read
307 * FieldDatumByteOffset - Byte offset of this datum within the
309 * Value - Where to store value (must at least
311 * Function - Read or Write flag plus other region-
316 * DESCRIPTION: Read or Write a single field datum to an Operation Region.
318 ******************************************************************************/
322 ACPI_OPERAND_OBJECT
*ObjDesc
,
323 UINT32 FieldDatumByteOffset
,
328 ACPI_OPERAND_OBJECT
*RgnDesc
;
332 ACPI_FUNCTION_TRACE (ExAccessRegion
);
336 * Ensure that the region operands are fully evaluated and verify
337 * the validity of the request
339 Status
= AcpiExSetupRegion (ObjDesc
, FieldDatumByteOffset
);
340 if (ACPI_FAILURE (Status
))
342 return_ACPI_STATUS (Status
);
346 * The physical address of this field datum is:
348 * 1) The base of the region, plus
349 * 2) The base offset of the field, plus
350 * 3) The current offset into the field
352 RgnDesc
= ObjDesc
->CommonField
.RegionObj
;
354 ObjDesc
->CommonField
.BaseByteOffset
+
355 FieldDatumByteOffset
;
357 if ((Function
& ACPI_IO_MASK
) == ACPI_READ
)
359 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
, "[READ]"));
363 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
, "[WRITE]"));
366 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_BFIELD
,
367 " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %8.8X%8.8X\n",
368 AcpiUtGetRegionName (RgnDesc
->Region
.SpaceId
),
369 RgnDesc
->Region
.SpaceId
,
370 ObjDesc
->CommonField
.AccessByteWidth
,
371 ObjDesc
->CommonField
.BaseByteOffset
,
372 FieldDatumByteOffset
,
373 ACPI_FORMAT_UINT64 (RgnDesc
->Region
.Address
+ RegionOffset
)));
375 /* Invoke the appropriate AddressSpace/OpRegion handler */
377 Status
= AcpiEvAddressSpaceDispatch (RgnDesc
, ObjDesc
,
378 Function
, RegionOffset
,
379 ACPI_MUL_8 (ObjDesc
->CommonField
.AccessByteWidth
), Value
);
381 if (ACPI_FAILURE (Status
))
383 if (Status
== AE_NOT_IMPLEMENTED
)
385 ACPI_ERROR ((AE_INFO
,
386 "Region %s (ID=%u) not implemented",
387 AcpiUtGetRegionName (RgnDesc
->Region
.SpaceId
),
388 RgnDesc
->Region
.SpaceId
));
390 else if (Status
== AE_NOT_EXIST
)
392 ACPI_ERROR ((AE_INFO
,
393 "Region %s (ID=%u) has no handler",
394 AcpiUtGetRegionName (RgnDesc
->Region
.SpaceId
),
395 RgnDesc
->Region
.SpaceId
));
399 return_ACPI_STATUS (Status
);
403 /*******************************************************************************
405 * FUNCTION: AcpiExRegisterOverflow
407 * PARAMETERS: ObjDesc - Register(Field) to be written
408 * Value - Value to be stored
410 * RETURN: TRUE if value overflows the field, FALSE otherwise
412 * DESCRIPTION: Check if a value is out of range of the field being written.
413 * Used to check if the values written to Index and Bank registers
414 * are out of range. Normally, the value is simply truncated
415 * to fit the field, but this case is most likely a serious
416 * coding error in the ASL.
418 ******************************************************************************/
421 AcpiExRegisterOverflow (
422 ACPI_OPERAND_OBJECT
*ObjDesc
,
426 if (ObjDesc
->CommonField
.BitLength
>= ACPI_INTEGER_BIT_SIZE
)
429 * The field is large enough to hold the maximum integer, so we can
435 if (Value
>= ((UINT64
) 1 << ObjDesc
->CommonField
.BitLength
))
438 * The Value is larger than the maximum value that can fit into
441 ACPI_ERROR ((AE_INFO
,
442 "Index value 0x%8.8X%8.8X overflows field width 0x%X",
443 ACPI_FORMAT_UINT64 (Value
),
444 ObjDesc
->CommonField
.BitLength
));
449 /* The Value will fit into the field with no truncation */
455 /*******************************************************************************
457 * FUNCTION: AcpiExFieldDatumIo
459 * PARAMETERS: ObjDesc - Field to be read
460 * FieldDatumByteOffset - Byte offset of this datum within the
462 * Value - Where to store value (must be 64 bits)
463 * ReadWrite - Read or Write flag
467 * DESCRIPTION: Read or Write a single datum of a field. The FieldType is
468 * demultiplexed here to handle the different types of fields
469 * (BufferField, RegionField, IndexField, BankField)
471 ******************************************************************************/
475 ACPI_OPERAND_OBJECT
*ObjDesc
,
476 UINT32 FieldDatumByteOffset
,
484 ACPI_FUNCTION_TRACE_U32 (ExFieldDatumIo
, FieldDatumByteOffset
);
487 if (ReadWrite
== ACPI_READ
)
493 /* To support reads without saving return value */
497 /* Clear the entire return buffer first, [Very Important!] */
503 * The four types of fields are:
505 * BufferField - Read/write from/to a Buffer
506 * RegionField - Read/write from/to a Operation Region.
507 * BankField - Write to a Bank Register, then read/write from/to an
509 * IndexField - Write to an Index Register, then read/write from/to a
512 switch (ObjDesc
->Common
.Type
)
514 case ACPI_TYPE_BUFFER_FIELD
:
516 * If the BufferField arguments have not been previously evaluated,
517 * evaluate them now and save the results.
519 if (!(ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
521 Status
= AcpiDsGetBufferFieldArguments (ObjDesc
);
522 if (ACPI_FAILURE (Status
))
524 return_ACPI_STATUS (Status
);
528 if (ReadWrite
== ACPI_READ
)
531 * Copy the data from the source buffer.
532 * Length is the field width in bytes.
535 (ObjDesc
->BufferField
.BufferObj
)->Buffer
.Pointer
+
536 ObjDesc
->BufferField
.BaseByteOffset
+
537 FieldDatumByteOffset
,
538 ObjDesc
->CommonField
.AccessByteWidth
);
543 * Copy the data to the target buffer.
544 * Length is the field width in bytes.
546 memcpy ((ObjDesc
->BufferField
.BufferObj
)->Buffer
.Pointer
+
547 ObjDesc
->BufferField
.BaseByteOffset
+
548 FieldDatumByteOffset
,
549 Value
, ObjDesc
->CommonField
.AccessByteWidth
);
555 case ACPI_TYPE_LOCAL_BANK_FIELD
:
557 * Ensure that the BankValue is not beyond the capacity of
560 if (AcpiExRegisterOverflow (ObjDesc
->BankField
.BankObj
,
561 (UINT64
) ObjDesc
->BankField
.Value
))
563 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT
);
567 * For BankFields, we must write the BankValue to the BankRegister
568 * (itself a RegionField) before we can access the data.
570 Status
= AcpiExInsertIntoField (ObjDesc
->BankField
.BankObj
,
571 &ObjDesc
->BankField
.Value
,
572 sizeof (ObjDesc
->BankField
.Value
));
573 if (ACPI_FAILURE (Status
))
575 return_ACPI_STATUS (Status
);
579 * Now that the Bank has been selected, fall through to the
580 * RegionField case and write the datum to the Operation Region
583 /*lint -fallthrough */
585 case ACPI_TYPE_LOCAL_REGION_FIELD
:
587 * For simple RegionFields, we just directly access the owning
590 Status
= AcpiExAccessRegion (
591 ObjDesc
, FieldDatumByteOffset
, Value
, ReadWrite
);
594 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
596 * Ensure that the IndexValue is not beyond the capacity of
599 if (AcpiExRegisterOverflow (ObjDesc
->IndexField
.IndexObj
,
600 (UINT64
) ObjDesc
->IndexField
.Value
))
602 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT
);
605 /* Write the index value to the IndexRegister (itself a RegionField) */
607 FieldDatumByteOffset
+= ObjDesc
->IndexField
.Value
;
609 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
610 "Write to Index Register: Value %8.8X\n",
611 FieldDatumByteOffset
));
613 Status
= AcpiExInsertIntoField (ObjDesc
->IndexField
.IndexObj
,
614 &FieldDatumByteOffset
, sizeof (FieldDatumByteOffset
));
615 if (ACPI_FAILURE (Status
))
617 return_ACPI_STATUS (Status
);
620 if (ReadWrite
== ACPI_READ
)
622 /* Read the datum from the DataRegister */
624 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
625 "Read from Data Register\n"));
627 Status
= AcpiExExtractFromField (
628 ObjDesc
->IndexField
.DataObj
, Value
, sizeof (UINT64
));
632 /* Write the datum to the DataRegister */
634 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
635 "Write to Data Register: Value %8.8X%8.8X\n",
636 ACPI_FORMAT_UINT64 (*Value
)));
638 Status
= AcpiExInsertIntoField (
639 ObjDesc
->IndexField
.DataObj
, Value
, sizeof (UINT64
));
645 ACPI_ERROR ((AE_INFO
, "Wrong object type in field I/O %u",
646 ObjDesc
->Common
.Type
));
647 Status
= AE_AML_INTERNAL
;
651 if (ACPI_SUCCESS (Status
))
653 if (ReadWrite
== ACPI_READ
)
655 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
656 "Value Read %8.8X%8.8X, Width %u\n",
657 ACPI_FORMAT_UINT64 (*Value
),
658 ObjDesc
->CommonField
.AccessByteWidth
));
662 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
663 "Value Written %8.8X%8.8X, Width %u\n",
664 ACPI_FORMAT_UINT64 (*Value
),
665 ObjDesc
->CommonField
.AccessByteWidth
));
669 return_ACPI_STATUS (Status
);
673 /*******************************************************************************
675 * FUNCTION: AcpiExWriteWithUpdateRule
677 * PARAMETERS: ObjDesc - Field to be written
678 * Mask - bitmask within field datum
679 * FieldValue - Value to write
680 * FieldDatumByteOffset - Offset of datum within field
684 * DESCRIPTION: Apply the field update rule to a field write
686 ******************************************************************************/
689 AcpiExWriteWithUpdateRule (
690 ACPI_OPERAND_OBJECT
*ObjDesc
,
693 UINT32 FieldDatumByteOffset
)
695 ACPI_STATUS Status
= AE_OK
;
700 ACPI_FUNCTION_TRACE_U32 (ExWriteWithUpdateRule
, Mask
);
703 /* Start with the new bits */
705 MergedValue
= FieldValue
;
707 /* If the mask is all ones, we don't need to worry about the update rule */
709 if (Mask
!= ACPI_UINT64_MAX
)
711 /* Decode the update rule */
713 switch (ObjDesc
->CommonField
.FieldFlags
& AML_FIELD_UPDATE_RULE_MASK
)
715 case AML_FIELD_UPDATE_PRESERVE
:
717 * Check if update rule needs to be applied (not if mask is all
718 * ones) The left shift drops the bits we want to ignore.
720 if ((~Mask
<< (ACPI_MUL_8 (sizeof (Mask
)) -
721 ACPI_MUL_8 (ObjDesc
->CommonField
.AccessByteWidth
))) != 0)
724 * Read the current contents of the byte/word/dword containing
725 * the field, and merge with the new field value.
727 Status
= AcpiExFieldDatumIo (
728 ObjDesc
, FieldDatumByteOffset
, &CurrentValue
, ACPI_READ
);
729 if (ACPI_FAILURE (Status
))
731 return_ACPI_STATUS (Status
);
734 MergedValue
|= (CurrentValue
& ~Mask
);
738 case AML_FIELD_UPDATE_WRITE_AS_ONES
:
740 /* Set positions outside the field to all ones */
742 MergedValue
|= ~Mask
;
745 case AML_FIELD_UPDATE_WRITE_AS_ZEROS
:
747 /* Set positions outside the field to all zeros */
754 ACPI_ERROR ((AE_INFO
,
755 "Unknown UpdateRule value: 0x%X",
756 (ObjDesc
->CommonField
.FieldFlags
&
757 AML_FIELD_UPDATE_RULE_MASK
)));
758 return_ACPI_STATUS (AE_AML_OPERAND_VALUE
);
762 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
763 "Mask %8.8X%8.8X, DatumOffset %X, Width %X, "
764 "Value %8.8X%8.8X, MergedValue %8.8X%8.8X\n",
765 ACPI_FORMAT_UINT64 (Mask
),
766 FieldDatumByteOffset
,
767 ObjDesc
->CommonField
.AccessByteWidth
,
768 ACPI_FORMAT_UINT64 (FieldValue
),
769 ACPI_FORMAT_UINT64 (MergedValue
)));
771 /* Write the merged value */
773 Status
= AcpiExFieldDatumIo (
774 ObjDesc
, FieldDatumByteOffset
, &MergedValue
, ACPI_WRITE
);
776 return_ACPI_STATUS (Status
);
780 /*******************************************************************************
782 * FUNCTION: AcpiExExtractFromField
784 * PARAMETERS: ObjDesc - Field to be read
785 * Buffer - Where to store the field data
786 * BufferLength - Length of Buffer
790 * DESCRIPTION: Retrieve the current value of the given field
792 ******************************************************************************/
795 AcpiExExtractFromField (
796 ACPI_OPERAND_OBJECT
*ObjDesc
,
803 UINT32 FieldOffset
= 0;
804 UINT32 BufferOffset
= 0;
805 UINT32 BufferTailBits
;
807 UINT32 FieldDatumCount
;
808 UINT32 AccessBitWidth
;
812 ACPI_FUNCTION_TRACE (ExExtractFromField
);
815 /* Validate target buffer and clear it */
818 ACPI_ROUND_BITS_UP_TO_BYTES (ObjDesc
->CommonField
.BitLength
))
820 ACPI_ERROR ((AE_INFO
,
821 "Field size %u (bits) is too large for buffer (%u)",
822 ObjDesc
->CommonField
.BitLength
, BufferLength
));
824 return_ACPI_STATUS (AE_BUFFER_OVERFLOW
);
827 memset (Buffer
, 0, BufferLength
);
828 AccessBitWidth
= ACPI_MUL_8 (ObjDesc
->CommonField
.AccessByteWidth
);
830 /* Handle the simple case here */
832 if ((ObjDesc
->CommonField
.StartFieldBitOffset
== 0) &&
833 (ObjDesc
->CommonField
.BitLength
== AccessBitWidth
))
835 if (BufferLength
>= sizeof (UINT64
))
837 Status
= AcpiExFieldDatumIo (ObjDesc
, 0, Buffer
, ACPI_READ
);
841 /* Use RawDatum (UINT64) to handle buffers < 64 bits */
843 Status
= AcpiExFieldDatumIo (ObjDesc
, 0, &RawDatum
, ACPI_READ
);
844 memcpy (Buffer
, &RawDatum
, BufferLength
);
847 return_ACPI_STATUS (Status
);
850 /* TBD: Move to common setup code */
852 /* Field algorithm is limited to sizeof(UINT64), truncate if needed */
854 if (ObjDesc
->CommonField
.AccessByteWidth
> sizeof (UINT64
))
856 ObjDesc
->CommonField
.AccessByteWidth
= sizeof (UINT64
);
857 AccessBitWidth
= sizeof (UINT64
) * 8;
860 /* Compute the number of datums (access width data items) */
862 DatumCount
= ACPI_ROUND_UP_TO (
863 ObjDesc
->CommonField
.BitLength
, AccessBitWidth
);
865 FieldDatumCount
= ACPI_ROUND_UP_TO (
866 ObjDesc
->CommonField
.BitLength
+
867 ObjDesc
->CommonField
.StartFieldBitOffset
, AccessBitWidth
);
869 /* Priming read from the field */
871 Status
= AcpiExFieldDatumIo (ObjDesc
, FieldOffset
, &RawDatum
, ACPI_READ
);
872 if (ACPI_FAILURE (Status
))
874 return_ACPI_STATUS (Status
);
876 MergedDatum
= RawDatum
>> ObjDesc
->CommonField
.StartFieldBitOffset
;
878 /* Read the rest of the field */
880 for (i
= 1; i
< FieldDatumCount
; i
++)
882 /* Get next input datum from the field */
884 FieldOffset
+= ObjDesc
->CommonField
.AccessByteWidth
;
885 Status
= AcpiExFieldDatumIo (
886 ObjDesc
, FieldOffset
, &RawDatum
, ACPI_READ
);
887 if (ACPI_FAILURE (Status
))
889 return_ACPI_STATUS (Status
);
893 * Merge with previous datum if necessary.
895 * Note: Before the shift, check if the shift value will be larger than
896 * the integer size. If so, there is no need to perform the operation.
897 * This avoids the differences in behavior between different compilers
898 * concerning shift values larger than the target data width.
900 if (AccessBitWidth
- ObjDesc
->CommonField
.StartFieldBitOffset
<
901 ACPI_INTEGER_BIT_SIZE
)
903 MergedDatum
|= RawDatum
<<
904 (AccessBitWidth
- ObjDesc
->CommonField
.StartFieldBitOffset
);
912 /* Write merged datum to target buffer */
914 memcpy (((char *) Buffer
) + BufferOffset
, &MergedDatum
,
915 ACPI_MIN(ObjDesc
->CommonField
.AccessByteWidth
,
916 BufferLength
- BufferOffset
));
918 BufferOffset
+= ObjDesc
->CommonField
.AccessByteWidth
;
919 MergedDatum
= RawDatum
>> ObjDesc
->CommonField
.StartFieldBitOffset
;
922 /* Mask off any extra bits in the last datum */
924 BufferTailBits
= ObjDesc
->CommonField
.BitLength
% AccessBitWidth
;
927 MergedDatum
&= ACPI_MASK_BITS_ABOVE (BufferTailBits
);
930 /* Write the last datum to the buffer */
932 memcpy (((char *) Buffer
) + BufferOffset
, &MergedDatum
,
933 ACPI_MIN(ObjDesc
->CommonField
.AccessByteWidth
,
934 BufferLength
- BufferOffset
));
936 return_ACPI_STATUS (AE_OK
);
940 /*******************************************************************************
942 * FUNCTION: AcpiExInsertIntoField
944 * PARAMETERS: ObjDesc - Field to be written
945 * Buffer - Data to be written
946 * BufferLength - Length of Buffer
950 * DESCRIPTION: Store the Buffer contents into the given field
952 ******************************************************************************/
955 AcpiExInsertIntoField (
956 ACPI_OPERAND_OBJECT
*ObjDesc
,
966 UINT32 FieldOffset
= 0;
967 UINT32 BufferOffset
= 0;
968 UINT32 BufferTailBits
;
970 UINT32 FieldDatumCount
;
971 UINT32 AccessBitWidth
;
972 UINT32 RequiredLength
;
976 ACPI_FUNCTION_TRACE (ExInsertIntoField
);
979 /* Validate input buffer */
982 RequiredLength
= ACPI_ROUND_BITS_UP_TO_BYTES (
983 ObjDesc
->CommonField
.BitLength
);
986 * We must have a buffer that is at least as long as the field
987 * we are writing to. This is because individual fields are
988 * indivisible and partial writes are not supported -- as per
989 * the ACPI specification.
991 if (BufferLength
< RequiredLength
)
993 /* We need to create a new buffer */
995 NewBuffer
= ACPI_ALLOCATE_ZEROED (RequiredLength
);
998 return_ACPI_STATUS (AE_NO_MEMORY
);
1002 * Copy the original data to the new buffer, starting
1003 * at Byte zero. All unused (upper) bytes of the
1006 memcpy ((char *) NewBuffer
, (char *) Buffer
, BufferLength
);
1008 BufferLength
= RequiredLength
;
1011 /* TBD: Move to common setup code */
1013 /* Algo is limited to sizeof(UINT64), so cut the AccessByteWidth */
1014 if (ObjDesc
->CommonField
.AccessByteWidth
> sizeof (UINT64
))
1016 ObjDesc
->CommonField
.AccessByteWidth
= sizeof (UINT64
);
1019 AccessBitWidth
= ACPI_MUL_8 (ObjDesc
->CommonField
.AccessByteWidth
);
1022 * Create the bitmasks used for bit insertion.
1023 * Note: This if/else is used to bypass compiler differences with the
1026 if (AccessBitWidth
== ACPI_INTEGER_BIT_SIZE
)
1028 WidthMask
= ACPI_UINT64_MAX
;
1032 WidthMask
= ACPI_MASK_BITS_ABOVE (AccessBitWidth
);
1036 ACPI_MASK_BITS_BELOW (ObjDesc
->CommonField
.StartFieldBitOffset
);
1038 /* Compute the number of datums (access width data items) */
1040 DatumCount
= ACPI_ROUND_UP_TO (ObjDesc
->CommonField
.BitLength
,
1043 FieldDatumCount
= ACPI_ROUND_UP_TO (ObjDesc
->CommonField
.BitLength
+
1044 ObjDesc
->CommonField
.StartFieldBitOffset
,
1047 /* Get initial Datum from the input buffer */
1049 memcpy (&RawDatum
, Buffer
,
1050 ACPI_MIN(ObjDesc
->CommonField
.AccessByteWidth
,
1051 BufferLength
- BufferOffset
));
1053 MergedDatum
= RawDatum
<< ObjDesc
->CommonField
.StartFieldBitOffset
;
1055 /* Write the entire field */
1057 for (i
= 1; i
< FieldDatumCount
; i
++)
1059 /* Write merged datum to the target field */
1061 MergedDatum
&= Mask
;
1062 Status
= AcpiExWriteWithUpdateRule (
1063 ObjDesc
, Mask
, MergedDatum
, FieldOffset
);
1064 if (ACPI_FAILURE (Status
))
1069 FieldOffset
+= ObjDesc
->CommonField
.AccessByteWidth
;
1072 * Start new output datum by merging with previous input datum
1075 * Note: Before the shift, check if the shift value will be larger than
1076 * the integer size. If so, there is no need to perform the operation.
1077 * This avoids the differences in behavior between different compilers
1078 * concerning shift values larger than the target data width.
1080 if ((AccessBitWidth
- ObjDesc
->CommonField
.StartFieldBitOffset
) <
1081 ACPI_INTEGER_BIT_SIZE
)
1083 MergedDatum
= RawDatum
>>
1084 (AccessBitWidth
- ObjDesc
->CommonField
.StartFieldBitOffset
);
1093 if (i
== DatumCount
)
1098 /* Get the next input datum from the buffer */
1100 BufferOffset
+= ObjDesc
->CommonField
.AccessByteWidth
;
1101 memcpy (&RawDatum
, ((char *) Buffer
) + BufferOffset
,
1102 ACPI_MIN(ObjDesc
->CommonField
.AccessByteWidth
,
1103 BufferLength
- BufferOffset
));
1105 MergedDatum
|= RawDatum
<< ObjDesc
->CommonField
.StartFieldBitOffset
;
1108 /* Mask off any extra bits in the last datum */
1110 BufferTailBits
= (ObjDesc
->CommonField
.BitLength
+
1111 ObjDesc
->CommonField
.StartFieldBitOffset
) % AccessBitWidth
;
1114 Mask
&= ACPI_MASK_BITS_ABOVE (BufferTailBits
);
1117 /* Write the last datum to the field */
1119 MergedDatum
&= Mask
;
1120 Status
= AcpiExWriteWithUpdateRule (
1121 ObjDesc
, Mask
, MergedDatum
, FieldOffset
);
1124 /* Free temporary buffer if we used one */
1128 ACPI_FREE (NewBuffer
);
1130 return_ACPI_STATUS (Status
);