1 /******************************************************************************
3 * Module Name: exfldio - Aml Field I/O
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
45 #include <acpi/acinterp.h>
46 #include <acpi/amlcode.h>
47 #include <acpi/acevents.h>
48 #include <acpi/acdispat.h>
50 #define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME("exfldio")
53 /* Local prototypes */
55 acpi_ex_field_datum_io(union acpi_operand_object
*obj_desc
,
56 u32 field_datum_byte_offset
,
57 acpi_integer
* value
, u32 read_write
);
60 acpi_ex_register_overflow(union acpi_operand_object
*obj_desc
,
64 acpi_ex_setup_region(union acpi_operand_object
*obj_desc
,
65 u32 field_datum_byte_offset
);
67 /*******************************************************************************
69 * FUNCTION: acpi_ex_setup_region
71 * PARAMETERS: obj_desc - Field to be read or written
72 * field_datum_byte_offset - Byte offset of this datum within the
77 * DESCRIPTION: Common processing for acpi_ex_extract_from_field and
78 * acpi_ex_insert_into_field. Initialize the Region if necessary and
79 * validate the request.
81 ******************************************************************************/
84 acpi_ex_setup_region(union acpi_operand_object
*obj_desc
,
85 u32 field_datum_byte_offset
)
87 acpi_status status
= AE_OK
;
88 union acpi_operand_object
*rgn_desc
;
90 ACPI_FUNCTION_TRACE_U32("ex_setup_region", field_datum_byte_offset
);
92 rgn_desc
= obj_desc
->common_field
.region_obj
;
94 /* We must have a valid region */
96 if (ACPI_GET_OBJECT_TYPE(rgn_desc
) != ACPI_TYPE_REGION
) {
97 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
98 "Needed Region, found type %X (%s)\n",
99 ACPI_GET_OBJECT_TYPE(rgn_desc
),
100 acpi_ut_get_object_type_name(rgn_desc
)));
102 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
106 * If the Region Address and Length have not been previously evaluated,
107 * evaluate them now and save the results.
109 if (!(rgn_desc
->common
.flags
& AOPOBJ_DATA_VALID
)) {
110 status
= acpi_ds_get_region_arguments(rgn_desc
);
111 if (ACPI_FAILURE(status
)) {
112 return_ACPI_STATUS(status
);
116 if (rgn_desc
->region
.space_id
== ACPI_ADR_SPACE_SMBUS
) {
117 /* SMBus has a non-linear address space */
119 return_ACPI_STATUS(AE_OK
);
121 #ifdef ACPI_UNDER_DEVELOPMENT
123 * If the Field access is any_acc, we can now compute the optimal
124 * access (because we know know the length of the parent region)
126 if (!(obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
)) {
127 if (ACPI_FAILURE(status
)) {
128 return_ACPI_STATUS(status
);
134 * Validate the request. The entire request from the byte offset for a
135 * length of one field datum (access width) must fit within the region.
136 * (Region length is specified in bytes)
138 if (rgn_desc
->region
.length
< (obj_desc
->common_field
.base_byte_offset
+
139 field_datum_byte_offset
+
140 obj_desc
->common_field
.
141 access_byte_width
)) {
142 if (acpi_gbl_enable_interpreter_slack
) {
144 * Slack mode only: We will go ahead and allow access to this
145 * field if it is within the region length rounded up to the next
146 * access width boundary.
148 if (ACPI_ROUND_UP(rgn_desc
->region
.length
,
149 obj_desc
->common_field
.
150 access_byte_width
) >=
151 (obj_desc
->common_field
.base_byte_offset
+
152 (acpi_native_uint
) obj_desc
->common_field
.
153 access_byte_width
+ field_datum_byte_offset
)) {
154 return_ACPI_STATUS(AE_OK
);
158 if (rgn_desc
->region
.length
<
159 obj_desc
->common_field
.access_byte_width
) {
161 * This is the case where the access_type (acc_word, etc.) is wider
162 * than the region itself. For example, a region of length one
163 * byte, and a field with Dword access specified.
165 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
166 "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)\n",
167 acpi_ut_get_node_name(obj_desc
->
170 obj_desc
->common_field
.
172 acpi_ut_get_node_name(rgn_desc
->
174 rgn_desc
->region
.length
));
178 * Offset rounded up to next multiple of field width
179 * exceeds region length, indicate an error
181 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
182 "Field [%4.4s] Base+Offset+Width %X+%X+%X is beyond end of region [%4.4s] (length %X)\n",
183 acpi_ut_get_node_name(obj_desc
->common_field
.
185 obj_desc
->common_field
.base_byte_offset
,
186 field_datum_byte_offset
,
187 obj_desc
->common_field
.access_byte_width
,
188 acpi_ut_get_node_name(rgn_desc
->region
.node
),
189 rgn_desc
->region
.length
));
191 return_ACPI_STATUS(AE_AML_REGION_LIMIT
);
194 return_ACPI_STATUS(AE_OK
);
197 /*******************************************************************************
199 * FUNCTION: acpi_ex_access_region
201 * PARAMETERS: obj_desc - Field to be read
202 * field_datum_byte_offset - Byte offset of this datum within the
204 * Value - Where to store value (must at least
205 * the size of acpi_integer)
206 * Function - Read or Write flag plus other region-
211 * DESCRIPTION: Read or Write a single field datum to an Operation Region.
213 ******************************************************************************/
216 acpi_ex_access_region(union acpi_operand_object
*obj_desc
,
217 u32 field_datum_byte_offset
,
218 acpi_integer
* value
, u32 function
)
221 union acpi_operand_object
*rgn_desc
;
222 acpi_physical_address address
;
224 ACPI_FUNCTION_TRACE("ex_access_region");
227 * Ensure that the region operands are fully evaluated and verify
228 * the validity of the request
230 status
= acpi_ex_setup_region(obj_desc
, field_datum_byte_offset
);
231 if (ACPI_FAILURE(status
)) {
232 return_ACPI_STATUS(status
);
236 * The physical address of this field datum is:
238 * 1) The base of the region, plus
239 * 2) The base offset of the field, plus
240 * 3) The current offset into the field
242 rgn_desc
= obj_desc
->common_field
.region_obj
;
243 address
= rgn_desc
->region
.address
+
244 obj_desc
->common_field
.base_byte_offset
+ field_datum_byte_offset
;
246 if ((function
& ACPI_IO_MASK
) == ACPI_READ
) {
247 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD
, "[READ]"));
249 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD
, "[WRITE]"));
252 ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD
,
253 " Region [%s:%X], Width %X, byte_base %X, Offset %X at %8.8X%8.8X\n",
254 acpi_ut_get_region_name(rgn_desc
->region
.
256 rgn_desc
->region
.space_id
,
257 obj_desc
->common_field
.access_byte_width
,
258 obj_desc
->common_field
.base_byte_offset
,
259 field_datum_byte_offset
,
260 ACPI_FORMAT_UINT64(address
)));
262 /* Invoke the appropriate address_space/op_region handler */
264 status
= acpi_ev_address_space_dispatch(rgn_desc
, function
,
266 ACPI_MUL_8(obj_desc
->
271 if (ACPI_FAILURE(status
)) {
272 if (status
== AE_NOT_IMPLEMENTED
) {
273 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
274 "Region %s(%X) not implemented\n",
275 acpi_ut_get_region_name(rgn_desc
->
278 rgn_desc
->region
.space_id
));
279 } else if (status
== AE_NOT_EXIST
) {
280 ACPI_REPORT_ERROR(("Region %s(%X) has no handler\n",
281 acpi_ut_get_region_name(rgn_desc
->
284 rgn_desc
->region
.space_id
));
288 return_ACPI_STATUS(status
);
291 /*******************************************************************************
293 * FUNCTION: acpi_ex_register_overflow
295 * PARAMETERS: obj_desc - Register(Field) to be written
296 * Value - Value to be stored
298 * RETURN: TRUE if value overflows the field, FALSE otherwise
300 * DESCRIPTION: Check if a value is out of range of the field being written.
301 * Used to check if the values written to Index and Bank registers
302 * are out of range. Normally, the value is simply truncated
303 * to fit the field, but this case is most likely a serious
304 * coding error in the ASL.
306 ******************************************************************************/
309 acpi_ex_register_overflow(union acpi_operand_object
*obj_desc
,
313 if (obj_desc
->common_field
.bit_length
>= ACPI_INTEGER_BIT_SIZE
) {
315 * The field is large enough to hold the maximum integer, so we can
321 if (value
>= ((acpi_integer
) 1 << obj_desc
->common_field
.bit_length
)) {
323 * The Value is larger than the maximum value that can fit into
329 /* The Value will fit into the field with no truncation */
334 /*******************************************************************************
336 * FUNCTION: acpi_ex_field_datum_io
338 * PARAMETERS: obj_desc - Field to be read
339 * field_datum_byte_offset - Byte offset of this datum within the
341 * Value - Where to store value (must be 64 bits)
342 * read_write - Read or Write flag
346 * DESCRIPTION: Read or Write a single datum of a field. The field_type is
347 * demultiplexed here to handle the different types of fields
348 * (buffer_field, region_field, index_field, bank_field)
350 ******************************************************************************/
353 acpi_ex_field_datum_io(union acpi_operand_object
*obj_desc
,
354 u32 field_datum_byte_offset
,
355 acpi_integer
* value
, u32 read_write
)
358 acpi_integer local_value
;
360 ACPI_FUNCTION_TRACE_U32("ex_field_datum_io", field_datum_byte_offset
);
362 if (read_write
== ACPI_READ
) {
366 /* To support reads without saving return value */
367 value
= &local_value
;
370 /* Clear the entire return buffer first, [Very Important!] */
376 * The four types of fields are:
378 * buffer_field - Read/write from/to a Buffer
379 * region_field - Read/write from/to a Operation Region.
380 * bank_field - Write to a Bank Register, then read/write from/to an
382 * index_field - Write to an Index Register, then read/write from/to a
385 switch (ACPI_GET_OBJECT_TYPE(obj_desc
)) {
386 case ACPI_TYPE_BUFFER_FIELD
:
388 * If the buffer_field arguments have not been previously evaluated,
389 * evaluate them now and save the results.
391 if (!(obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
)) {
392 status
= acpi_ds_get_buffer_field_arguments(obj_desc
);
393 if (ACPI_FAILURE(status
)) {
394 return_ACPI_STATUS(status
);
398 if (read_write
== ACPI_READ
) {
400 * Copy the data from the source buffer.
401 * Length is the field width in bytes.
404 (obj_desc
->buffer_field
.buffer_obj
)->buffer
.
406 obj_desc
->buffer_field
.base_byte_offset
+
407 field_datum_byte_offset
,
408 obj_desc
->common_field
.access_byte_width
);
411 * Copy the data to the target buffer.
412 * Length is the field width in bytes.
414 ACPI_MEMCPY((obj_desc
->buffer_field
.buffer_obj
)->buffer
.
416 obj_desc
->buffer_field
.base_byte_offset
+
417 field_datum_byte_offset
, value
,
418 obj_desc
->common_field
.access_byte_width
);
424 case ACPI_TYPE_LOCAL_BANK_FIELD
:
427 * Ensure that the bank_value is not beyond the capacity of
430 if (acpi_ex_register_overflow(obj_desc
->bank_field
.bank_obj
,
431 (acpi_integer
) obj_desc
->
433 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT
);
437 * For bank_fields, we must write the bank_value to the bank_register
438 * (itself a region_field) before we can access the data.
441 acpi_ex_insert_into_field(obj_desc
->bank_field
.bank_obj
,
442 &obj_desc
->bank_field
.value
,
443 sizeof(obj_desc
->bank_field
.
445 if (ACPI_FAILURE(status
)) {
446 return_ACPI_STATUS(status
);
450 * Now that the Bank has been selected, fall through to the
451 * region_field case and write the datum to the Operation Region
454 /*lint -fallthrough */
456 case ACPI_TYPE_LOCAL_REGION_FIELD
:
458 * For simple region_fields, we just directly access the owning
462 acpi_ex_access_region(obj_desc
, field_datum_byte_offset
,
466 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
469 * Ensure that the index_value is not beyond the capacity of
472 if (acpi_ex_register_overflow(obj_desc
->index_field
.index_obj
,
473 (acpi_integer
) obj_desc
->
474 index_field
.value
)) {
475 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT
);
478 /* Write the index value to the index_register (itself a region_field) */
480 field_datum_byte_offset
+= obj_desc
->index_field
.value
;
482 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD
,
483 "Write to Index Register: Value %8.8X\n",
484 field_datum_byte_offset
));
487 acpi_ex_insert_into_field(obj_desc
->index_field
.index_obj
,
488 &field_datum_byte_offset
,
489 sizeof(field_datum_byte_offset
));
490 if (ACPI_FAILURE(status
)) {
491 return_ACPI_STATUS(status
);
494 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD
,
495 "I/O to Data Register: value_ptr %p\n",
498 if (read_write
== ACPI_READ
) {
499 /* Read the datum from the data_register */
502 acpi_ex_extract_from_field(obj_desc
->index_field
.
504 sizeof(acpi_integer
));
506 /* Write the datum to the data_register */
509 acpi_ex_insert_into_field(obj_desc
->index_field
.
511 sizeof(acpi_integer
));
517 ACPI_REPORT_ERROR(("Wrong object type in field I/O %X\n",
518 ACPI_GET_OBJECT_TYPE(obj_desc
)));
519 status
= AE_AML_INTERNAL
;
523 if (ACPI_SUCCESS(status
)) {
524 if (read_write
== ACPI_READ
) {
525 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD
,
526 "Value Read %8.8X%8.8X, Width %d\n",
527 ACPI_FORMAT_UINT64(*value
),
528 obj_desc
->common_field
.
531 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD
,
532 "Value Written %8.8X%8.8X, Width %d\n",
533 ACPI_FORMAT_UINT64(*value
),
534 obj_desc
->common_field
.
539 return_ACPI_STATUS(status
);
542 /*******************************************************************************
544 * FUNCTION: acpi_ex_write_with_update_rule
546 * PARAMETERS: obj_desc - Field to be written
547 * Mask - bitmask within field datum
548 * field_value - Value to write
549 * field_datum_byte_offset - Offset of datum within field
553 * DESCRIPTION: Apply the field update rule to a field write
555 ******************************************************************************/
558 acpi_ex_write_with_update_rule(union acpi_operand_object
*obj_desc
,
560 acpi_integer field_value
,
561 u32 field_datum_byte_offset
)
563 acpi_status status
= AE_OK
;
564 acpi_integer merged_value
;
565 acpi_integer current_value
;
567 ACPI_FUNCTION_TRACE_U32("ex_write_with_update_rule", mask
);
569 /* Start with the new bits */
571 merged_value
= field_value
;
573 /* If the mask is all ones, we don't need to worry about the update rule */
575 if (mask
!= ACPI_INTEGER_MAX
) {
576 /* Decode the update rule */
578 switch (obj_desc
->common_field
.
579 field_flags
& AML_FIELD_UPDATE_RULE_MASK
) {
580 case AML_FIELD_UPDATE_PRESERVE
:
582 * Check if update rule needs to be applied (not if mask is all
583 * ones) The left shift drops the bits we want to ignore.
585 if ((~mask
<< (ACPI_MUL_8(sizeof(mask
)) -
586 ACPI_MUL_8(obj_desc
->common_field
.
587 access_byte_width
))) != 0) {
589 * Read the current contents of the byte/word/dword containing
590 * the field, and merge with the new field value.
593 acpi_ex_field_datum_io(obj_desc
,
594 field_datum_byte_offset
,
597 if (ACPI_FAILURE(status
)) {
598 return_ACPI_STATUS(status
);
601 merged_value
|= (current_value
& ~mask
);
605 case AML_FIELD_UPDATE_WRITE_AS_ONES
:
607 /* Set positions outside the field to all ones */
609 merged_value
|= ~mask
;
612 case AML_FIELD_UPDATE_WRITE_AS_ZEROS
:
614 /* Set positions outside the field to all zeros */
616 merged_value
&= mask
;
621 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
622 "write_with_update_rule: Unknown update_rule setting: %X\n",
623 (obj_desc
->common_field
.
625 AML_FIELD_UPDATE_RULE_MASK
)));
626 return_ACPI_STATUS(AE_AML_OPERAND_VALUE
);
630 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD
,
631 "Mask %8.8X%8.8X, datum_offset %X, Width %X, Value %8.8X%8.8X, merged_value %8.8X%8.8X\n",
632 ACPI_FORMAT_UINT64(mask
),
633 field_datum_byte_offset
,
634 obj_desc
->common_field
.access_byte_width
,
635 ACPI_FORMAT_UINT64(field_value
),
636 ACPI_FORMAT_UINT64(merged_value
)));
638 /* Write the merged value */
640 status
= acpi_ex_field_datum_io(obj_desc
, field_datum_byte_offset
,
641 &merged_value
, ACPI_WRITE
);
643 return_ACPI_STATUS(status
);
646 /*******************************************************************************
648 * FUNCTION: acpi_ex_extract_from_field
650 * PARAMETERS: obj_desc - Field to be read
651 * Buffer - Where to store the field data
652 * buffer_length - Length of Buffer
656 * DESCRIPTION: Retrieve the current value of the given field
658 ******************************************************************************/
661 acpi_ex_extract_from_field(union acpi_operand_object
*obj_desc
,
662 void *buffer
, u32 buffer_length
)
665 acpi_integer raw_datum
;
666 acpi_integer merged_datum
;
667 u32 field_offset
= 0;
668 u32 buffer_offset
= 0;
669 u32 buffer_tail_bits
;
671 u32 field_datum_count
;
674 ACPI_FUNCTION_TRACE("ex_extract_from_field");
676 /* Validate target buffer and clear it */
679 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc
->common_field
.bit_length
)) {
680 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
681 "Field size %X (bits) is too large for buffer (%X)\n",
682 obj_desc
->common_field
.bit_length
,
685 return_ACPI_STATUS(AE_BUFFER_OVERFLOW
);
687 ACPI_MEMSET(buffer
, 0, buffer_length
);
689 /* Compute the number of datums (access width data items) */
691 datum_count
= ACPI_ROUND_UP_TO(obj_desc
->common_field
.bit_length
,
692 obj_desc
->common_field
.access_bit_width
);
693 field_datum_count
= ACPI_ROUND_UP_TO(obj_desc
->common_field
.bit_length
+
694 obj_desc
->common_field
.
695 start_field_bit_offset
,
696 obj_desc
->common_field
.
699 /* Priming read from the field */
702 acpi_ex_field_datum_io(obj_desc
, field_offset
, &raw_datum
,
704 if (ACPI_FAILURE(status
)) {
705 return_ACPI_STATUS(status
);
708 raw_datum
>> obj_desc
->common_field
.start_field_bit_offset
;
710 /* Read the rest of the field */
712 for (i
= 1; i
< field_datum_count
; i
++) {
713 /* Get next input datum from the field */
715 field_offset
+= obj_desc
->common_field
.access_byte_width
;
716 status
= acpi_ex_field_datum_io(obj_desc
, field_offset
,
717 &raw_datum
, ACPI_READ
);
718 if (ACPI_FAILURE(status
)) {
719 return_ACPI_STATUS(status
);
722 /* Merge with previous datum if necessary */
724 merged_datum
|= raw_datum
<<
725 (obj_desc
->common_field
.access_bit_width
-
726 obj_desc
->common_field
.start_field_bit_offset
);
728 if (i
== datum_count
) {
732 /* Write merged datum to target buffer */
734 ACPI_MEMCPY(((char *)buffer
) + buffer_offset
, &merged_datum
,
735 ACPI_MIN(obj_desc
->common_field
.access_byte_width
,
736 buffer_length
- buffer_offset
));
738 buffer_offset
+= obj_desc
->common_field
.access_byte_width
;
740 raw_datum
>> obj_desc
->common_field
.start_field_bit_offset
;
743 /* Mask off any extra bits in the last datum */
745 buffer_tail_bits
= obj_desc
->common_field
.bit_length
%
746 obj_desc
->common_field
.access_bit_width
;
747 if (buffer_tail_bits
) {
748 merged_datum
&= ACPI_MASK_BITS_ABOVE(buffer_tail_bits
);
751 /* Write the last datum to the buffer */
753 ACPI_MEMCPY(((char *)buffer
) + buffer_offset
, &merged_datum
,
754 ACPI_MIN(obj_desc
->common_field
.access_byte_width
,
755 buffer_length
- buffer_offset
));
757 return_ACPI_STATUS(AE_OK
);
760 /*******************************************************************************
762 * FUNCTION: acpi_ex_insert_into_field
764 * PARAMETERS: obj_desc - Field to be written
765 * Buffer - Data to be written
766 * buffer_length - Length of Buffer
770 * DESCRIPTION: Store the Buffer contents into the given field
772 ******************************************************************************/
775 acpi_ex_insert_into_field(union acpi_operand_object
*obj_desc
,
776 void *buffer
, u32 buffer_length
)
780 acpi_integer merged_datum
;
781 acpi_integer raw_datum
= 0;
782 u32 field_offset
= 0;
783 u32 buffer_offset
= 0;
784 u32 buffer_tail_bits
;
786 u32 field_datum_count
;
789 ACPI_FUNCTION_TRACE("ex_insert_into_field");
791 /* Validate input buffer */
794 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc
->common_field
.bit_length
)) {
795 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
796 "Field size %X (bits) is too large for buffer (%X)\n",
797 obj_desc
->common_field
.bit_length
,
800 return_ACPI_STATUS(AE_BUFFER_OVERFLOW
);
803 /* Compute the number of datums (access width data items) */
806 ACPI_MASK_BITS_BELOW(obj_desc
->common_field
.start_field_bit_offset
);
808 ACPI_ROUND_UP_TO(obj_desc
->common_field
.bit_length
,
809 obj_desc
->common_field
.access_bit_width
);
811 ACPI_ROUND_UP_TO(obj_desc
->common_field
.bit_length
+
812 obj_desc
->common_field
.start_field_bit_offset
,
813 obj_desc
->common_field
.access_bit_width
);
815 /* Get initial Datum from the input buffer */
817 ACPI_MEMCPY(&raw_datum
, buffer
,
818 ACPI_MIN(obj_desc
->common_field
.access_byte_width
,
819 buffer_length
- buffer_offset
));
822 raw_datum
<< obj_desc
->common_field
.start_field_bit_offset
;
824 /* Write the entire field */
826 for (i
= 1; i
< field_datum_count
; i
++) {
827 /* Write merged datum to the target field */
829 merged_datum
&= mask
;
830 status
= acpi_ex_write_with_update_rule(obj_desc
, mask
,
833 if (ACPI_FAILURE(status
)) {
834 return_ACPI_STATUS(status
);
837 /* Start new output datum by merging with previous input datum */
839 field_offset
+= obj_desc
->common_field
.access_byte_width
;
840 merged_datum
= raw_datum
>>
841 (obj_desc
->common_field
.access_bit_width
-
842 obj_desc
->common_field
.start_field_bit_offset
);
843 mask
= ACPI_INTEGER_MAX
;
845 if (i
== datum_count
) {
849 /* Get the next input datum from the buffer */
851 buffer_offset
+= obj_desc
->common_field
.access_byte_width
;
852 ACPI_MEMCPY(&raw_datum
, ((char *)buffer
) + buffer_offset
,
853 ACPI_MIN(obj_desc
->common_field
.access_byte_width
,
854 buffer_length
- buffer_offset
));
856 raw_datum
<< obj_desc
->common_field
.start_field_bit_offset
;
859 /* Mask off any extra bits in the last datum */
861 buffer_tail_bits
= (obj_desc
->common_field
.bit_length
+
862 obj_desc
->common_field
.start_field_bit_offset
) %
863 obj_desc
->common_field
.access_bit_width
;
864 if (buffer_tail_bits
) {
865 mask
&= ACPI_MASK_BITS_ABOVE(buffer_tail_bits
);
868 /* Write the last datum to the field */
870 merged_datum
&= mask
;
871 status
= acpi_ex_write_with_update_rule(obj_desc
,
875 return_ACPI_STATUS(status
);