1 /******************************************************************************
3 * Module Name: exfldio - Aml Field I/O
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2006, 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_ERROR((AE_INFO, "Needed Region, found type %X (%s)",
98 ACPI_GET_OBJECT_TYPE(rgn_desc),
99 acpi_ut_get_object_type_name(rgn_desc)));
101 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
105 * If the Region Address and Length have not been previously evaluated,
106 * evaluate them now and save the results.
108 if (!(rgn_desc->common.flags & AOPOBJ_DATA_VALID)) {
109 status = acpi_ds_get_region_arguments(rgn_desc);
110 if (ACPI_FAILURE(status)) {
111 return_ACPI_STATUS(status);
115 if (rgn_desc->region.space_id == ACPI_ADR_SPACE_SMBUS) {
116 /* SMBus has a non-linear address space */
118 return_ACPI_STATUS(AE_OK);
120 #ifdef ACPI_UNDER_DEVELOPMENT
122 * If the Field access is any_acc, we can now compute the optimal
123 * access (because we know know the length of the parent region)
125 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
126 if (ACPI_FAILURE(status)) {
127 return_ACPI_STATUS(status);
133 * Validate the request. The entire request from the byte offset for a
134 * length of one field datum (access width) must fit within the region.
135 * (Region length is specified in bytes)
137 if (rgn_desc->region.length < (obj_desc->common_field.base_byte_offset +
138 field_datum_byte_offset +
139 obj_desc->common_field.
140 access_byte_width)) {
141 if (acpi_gbl_enable_interpreter_slack) {
143 * Slack mode only: We will go ahead and allow access to this
144 * field if it is within the region length rounded up to the next
145 * access width boundary.
147 if (ACPI_ROUND_UP(rgn_desc->region.length,
148 obj_desc->common_field.
149 access_byte_width) >=
150 (obj_desc->common_field.base_byte_offset +
151 (acpi_native_uint) obj_desc->common_field.
152 access_byte_width + field_datum_byte_offset)) {
153 return_ACPI_STATUS(AE_OK);
157 if (rgn_desc->region.length <
158 obj_desc->common_field.access_byte_width) {
160 * This is the case where the access_type (acc_word, etc.) is wider
161 * than the region itself. For example, a region of length one
162 * byte, and a field with Dword access specified.
165 "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)",
166 acpi_ut_get_node_name(obj_desc->
168 obj_desc->common_field.access_byte_width,
169 acpi_ut_get_node_name(rgn_desc->region.
171 rgn_desc->region.length));
175 * Offset rounded up to next multiple of field width
176 * exceeds region length, indicate an error
179 "Field [%4.4s] Base+Offset+Width %X+%X+%X is beyond end of region [%4.4s] (length %X)",
180 acpi_ut_get_node_name(obj_desc->common_field.node),
181 obj_desc->common_field.base_byte_offset,
182 field_datum_byte_offset,
183 obj_desc->common_field.access_byte_width,
184 acpi_ut_get_node_name(rgn_desc->region.node),
185 rgn_desc->region.length));
187 return_ACPI_STATUS(AE_AML_REGION_LIMIT);
190 return_ACPI_STATUS(AE_OK);
193 /*******************************************************************************
195 * FUNCTION: acpi_ex_access_region
197 * PARAMETERS: obj_desc - Field to be read
198 * field_datum_byte_offset - Byte offset of this datum within the
200 * Value - Where to store value (must at least
201 * the size of acpi_integer)
202 * Function - Read or Write flag plus other region-
207 * DESCRIPTION: Read or Write a single field datum to an Operation Region.
209 ******************************************************************************/
212 acpi_ex_access_region(union acpi_operand_object *obj_desc,
213 u32 field_datum_byte_offset,
214 acpi_integer * value, u32 function)
217 union acpi_operand_object *rgn_desc;
218 acpi_physical_address address;
220 ACPI_FUNCTION_TRACE("ex_access_region");
223 * Ensure that the region operands are fully evaluated and verify
224 * the validity of the request
226 status = acpi_ex_setup_region(obj_desc, field_datum_byte_offset);
227 if (ACPI_FAILURE(status)) {
228 return_ACPI_STATUS(status);
232 * The physical address of this field datum is:
234 * 1) The base of the region, plus
235 * 2) The base offset of the field, plus
236 * 3) The current offset into the field
238 rgn_desc = obj_desc->common_field.region_obj;
239 address = rgn_desc->region.address +
240 obj_desc->common_field.base_byte_offset + field_datum_byte_offset;
242 if ((function & ACPI_IO_MASK) == ACPI_READ) {
243 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[READ]"));
245 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[WRITE]"));
248 ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD,
249 " Region [%s:%X], Width %X, byte_base %X, Offset %X at %8.8X%8.8X\n",
250 acpi_ut_get_region_name(rgn_desc->region.
252 rgn_desc->region.space_id,
253 obj_desc->common_field.access_byte_width,
254 obj_desc->common_field.base_byte_offset,
255 field_datum_byte_offset,
256 ACPI_FORMAT_UINT64(address)));
258 /* Invoke the appropriate address_space/op_region handler */
260 status = acpi_ev_address_space_dispatch(rgn_desc, function,
262 ACPI_MUL_8(obj_desc->
267 if (ACPI_FAILURE(status)) {
268 if (status == AE_NOT_IMPLEMENTED) {
270 "Region %s(%X) not implemented",
271 acpi_ut_get_region_name(rgn_desc->region.
273 rgn_desc->region.space_id));
274 } else if (status == AE_NOT_EXIST) {
276 "Region %s(%X) has no handler",
277 acpi_ut_get_region_name(rgn_desc->region.
279 rgn_desc->region.space_id));
283 return_ACPI_STATUS(status);
286 /*******************************************************************************
288 * FUNCTION: acpi_ex_register_overflow
290 * PARAMETERS: obj_desc - Register(Field) to be written
291 * Value - Value to be stored
293 * RETURN: TRUE if value overflows the field, FALSE otherwise
295 * DESCRIPTION: Check if a value is out of range of the field being written.
296 * Used to check if the values written to Index and Bank registers
297 * are out of range. Normally, the value is simply truncated
298 * to fit the field, but this case is most likely a serious
299 * coding error in the ASL.
301 ******************************************************************************/
304 acpi_ex_register_overflow(union acpi_operand_object *obj_desc,
308 if (obj_desc->common_field.bit_length >= ACPI_INTEGER_BIT_SIZE) {
310 * The field is large enough to hold the maximum integer, so we can
316 if (value >= ((acpi_integer) 1 << obj_desc->common_field.bit_length)) {
318 * The Value is larger than the maximum value that can fit into
324 /* The Value will fit into the field with no truncation */
329 /*******************************************************************************
331 * FUNCTION: acpi_ex_field_datum_io
333 * PARAMETERS: obj_desc - Field to be read
334 * field_datum_byte_offset - Byte offset of this datum within the
336 * Value - Where to store value (must be 64 bits)
337 * read_write - Read or Write flag
341 * DESCRIPTION: Read or Write a single datum of a field. The field_type is
342 * demultiplexed here to handle the different types of fields
343 * (buffer_field, region_field, index_field, bank_field)
345 ******************************************************************************/
348 acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
349 u32 field_datum_byte_offset,
350 acpi_integer * value, u32 read_write)
353 acpi_integer local_value;
355 ACPI_FUNCTION_TRACE_U32("ex_field_datum_io", field_datum_byte_offset);
357 if (read_write == ACPI_READ) {
361 /* To support reads without saving return value */
362 value = &local_value;
365 /* Clear the entire return buffer first, [Very Important!] */
371 * The four types of fields are:
373 * buffer_field - Read/write from/to a Buffer
374 * region_field - Read/write from/to a Operation Region.
375 * bank_field - Write to a Bank Register, then read/write from/to an
377 * index_field - Write to an Index Register, then read/write from/to a
380 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
381 case ACPI_TYPE_BUFFER_FIELD:
383 * If the buffer_field arguments have not been previously evaluated,
384 * evaluate them now and save the results.
386 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
387 status = acpi_ds_get_buffer_field_arguments(obj_desc);
388 if (ACPI_FAILURE(status)) {
389 return_ACPI_STATUS(status);
393 if (read_write == ACPI_READ) {
395 * Copy the data from the source buffer.
396 * Length is the field width in bytes.
399 (obj_desc->buffer_field.buffer_obj)->buffer.
401 obj_desc->buffer_field.base_byte_offset +
402 field_datum_byte_offset,
403 obj_desc->common_field.access_byte_width);
406 * Copy the data to the target buffer.
407 * Length is the field width in bytes.
409 ACPI_MEMCPY((obj_desc->buffer_field.buffer_obj)->buffer.
411 obj_desc->buffer_field.base_byte_offset +
412 field_datum_byte_offset, value,
413 obj_desc->common_field.access_byte_width);
419 case ACPI_TYPE_LOCAL_BANK_FIELD:
422 * Ensure that the bank_value is not beyond the capacity of
425 if (acpi_ex_register_overflow(obj_desc->bank_field.bank_obj,
426 (acpi_integer) obj_desc->
428 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
432 * For bank_fields, we must write the bank_value to the bank_register
433 * (itself a region_field) before we can access the data.
436 acpi_ex_insert_into_field(obj_desc->bank_field.bank_obj,
437 &obj_desc->bank_field.value,
438 sizeof(obj_desc->bank_field.
440 if (ACPI_FAILURE(status)) {
441 return_ACPI_STATUS(status);
445 * Now that the Bank has been selected, fall through to the
446 * region_field case and write the datum to the Operation Region
449 /*lint -fallthrough */
451 case ACPI_TYPE_LOCAL_REGION_FIELD:
453 * For simple region_fields, we just directly access the owning
457 acpi_ex_access_region(obj_desc, field_datum_byte_offset,
461 case ACPI_TYPE_LOCAL_INDEX_FIELD:
464 * Ensure that the index_value is not beyond the capacity of
467 if (acpi_ex_register_overflow(obj_desc->index_field.index_obj,
468 (acpi_integer) obj_desc->
469 index_field.value)) {
470 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
473 /* Write the index value to the index_register (itself a region_field) */
475 field_datum_byte_offset += obj_desc->index_field.value;
477 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
478 "Write to Index Register: Value %8.8X\n",
479 field_datum_byte_offset));
482 acpi_ex_insert_into_field(obj_desc->index_field.index_obj,
483 &field_datum_byte_offset,
484 sizeof(field_datum_byte_offset));
485 if (ACPI_FAILURE(status)) {
486 return_ACPI_STATUS(status);
489 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
490 "I/O to Data Register: value_ptr %p\n",
493 if (read_write == ACPI_READ) {
494 /* Read the datum from the data_register */
497 acpi_ex_extract_from_field(obj_desc->index_field.
499 sizeof(acpi_integer));
501 /* Write the datum to the data_register */
504 acpi_ex_insert_into_field(obj_desc->index_field.
506 sizeof(acpi_integer));
512 ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %X",
513 ACPI_GET_OBJECT_TYPE(obj_desc)));
514 status = AE_AML_INTERNAL;
518 if (ACPI_SUCCESS(status)) {
519 if (read_write == ACPI_READ) {
520 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
521 "Value Read %8.8X%8.8X, Width %d\n",
522 ACPI_FORMAT_UINT64(*value),
523 obj_desc->common_field.
526 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
527 "Value Written %8.8X%8.8X, Width %d\n",
528 ACPI_FORMAT_UINT64(*value),
529 obj_desc->common_field.
534 return_ACPI_STATUS(status);
537 /*******************************************************************************
539 * FUNCTION: acpi_ex_write_with_update_rule
541 * PARAMETERS: obj_desc - Field to be written
542 * Mask - bitmask within field datum
543 * field_value - Value to write
544 * field_datum_byte_offset - Offset of datum within field
548 * DESCRIPTION: Apply the field update rule to a field write
550 ******************************************************************************/
553 acpi_ex_write_with_update_rule(union acpi_operand_object *obj_desc,
555 acpi_integer field_value,
556 u32 field_datum_byte_offset)
558 acpi_status status = AE_OK;
559 acpi_integer merged_value;
560 acpi_integer current_value;
562 ACPI_FUNCTION_TRACE_U32("ex_write_with_update_rule", mask);
564 /* Start with the new bits */
566 merged_value = field_value;
568 /* If the mask is all ones, we don't need to worry about the update rule */
570 if (mask != ACPI_INTEGER_MAX) {
571 /* Decode the update rule */
573 switch (obj_desc->common_field.
574 field_flags & AML_FIELD_UPDATE_RULE_MASK) {
575 case AML_FIELD_UPDATE_PRESERVE:
577 * Check if update rule needs to be applied (not if mask is all
578 * ones) The left shift drops the bits we want to ignore.
580 if ((~mask << (ACPI_MUL_8(sizeof(mask)) -
581 ACPI_MUL_8(obj_desc->common_field.
582 access_byte_width))) != 0) {
584 * Read the current contents of the byte/word/dword containing
585 * the field, and merge with the new field value.
588 acpi_ex_field_datum_io(obj_desc,
589 field_datum_byte_offset,
592 if (ACPI_FAILURE(status)) {
593 return_ACPI_STATUS(status);
596 merged_value |= (current_value & ~mask);
600 case AML_FIELD_UPDATE_WRITE_AS_ONES:
602 /* Set positions outside the field to all ones */
604 merged_value |= ~mask;
607 case AML_FIELD_UPDATE_WRITE_AS_ZEROS:
609 /* Set positions outside the field to all zeros */
611 merged_value &= mask;
617 "Unknown update_rule value: %X",
618 (obj_desc->common_field.
620 AML_FIELD_UPDATE_RULE_MASK)));
621 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
625 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
626 "Mask %8.8X%8.8X, datum_offset %X, Width %X, Value %8.8X%8.8X, merged_value %8.8X%8.8X\n",
627 ACPI_FORMAT_UINT64(mask),
628 field_datum_byte_offset,
629 obj_desc->common_field.access_byte_width,
630 ACPI_FORMAT_UINT64(field_value),
631 ACPI_FORMAT_UINT64(merged_value)));
633 /* Write the merged value */
635 status = acpi_ex_field_datum_io(obj_desc, field_datum_byte_offset,
636 &merged_value, ACPI_WRITE);
638 return_ACPI_STATUS(status);
641 /*******************************************************************************
643 * FUNCTION: acpi_ex_extract_from_field
645 * PARAMETERS: obj_desc - Field to be read
646 * Buffer - Where to store the field data
647 * buffer_length - Length of Buffer
651 * DESCRIPTION: Retrieve the current value of the given field
653 ******************************************************************************/
656 acpi_ex_extract_from_field(union acpi_operand_object *obj_desc,
657 void *buffer, u32 buffer_length)
660 acpi_integer raw_datum;
661 acpi_integer merged_datum;
662 u32 field_offset = 0;
663 u32 buffer_offset = 0;
664 u32 buffer_tail_bits;
666 u32 field_datum_count;
669 ACPI_FUNCTION_TRACE("ex_extract_from_field");
671 /* Validate target buffer and clear it */
674 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) {
676 "Field size %X (bits) is too large for buffer (%X)",
677 obj_desc->common_field.bit_length, buffer_length));
679 return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
681 ACPI_MEMSET(buffer, 0, buffer_length);
683 /* Compute the number of datums (access width data items) */
685 datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
686 obj_desc->common_field.access_bit_width);
687 field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
688 obj_desc->common_field.
689 start_field_bit_offset,
690 obj_desc->common_field.
693 /* Priming read from the field */
696 acpi_ex_field_datum_io(obj_desc, field_offset, &raw_datum,
698 if (ACPI_FAILURE(status)) {
699 return_ACPI_STATUS(status);
702 raw_datum >> obj_desc->common_field.start_field_bit_offset;
704 /* Read the rest of the field */
706 for (i = 1; i < field_datum_count; i++) {
707 /* Get next input datum from the field */
709 field_offset += obj_desc->common_field.access_byte_width;
710 status = acpi_ex_field_datum_io(obj_desc, field_offset,
711 &raw_datum, ACPI_READ);
712 if (ACPI_FAILURE(status)) {
713 return_ACPI_STATUS(status);
716 /* Merge with previous datum if necessary */
718 merged_datum |= raw_datum <<
719 (obj_desc->common_field.access_bit_width -
720 obj_desc->common_field.start_field_bit_offset);
722 if (i == datum_count) {
726 /* Write merged datum to target buffer */
728 ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum,
729 ACPI_MIN(obj_desc->common_field.access_byte_width,
730 buffer_length - buffer_offset));
732 buffer_offset += obj_desc->common_field.access_byte_width;
734 raw_datum >> obj_desc->common_field.start_field_bit_offset;
737 /* Mask off any extra bits in the last datum */
739 buffer_tail_bits = obj_desc->common_field.bit_length %
740 obj_desc->common_field.access_bit_width;
741 if (buffer_tail_bits) {
742 merged_datum &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
745 /* Write the last datum to the buffer */
747 ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum,
748 ACPI_MIN(obj_desc->common_field.access_byte_width,
749 buffer_length - buffer_offset));
751 return_ACPI_STATUS(AE_OK);
754 /*******************************************************************************
756 * FUNCTION: acpi_ex_insert_into_field
758 * PARAMETERS: obj_desc - Field to be written
759 * Buffer - Data to be written
760 * buffer_length - Length of Buffer
764 * DESCRIPTION: Store the Buffer contents into the given field
766 ******************************************************************************/
769 acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
770 void *buffer, u32 buffer_length)
774 acpi_integer merged_datum;
775 acpi_integer raw_datum = 0;
776 u32 field_offset = 0;
777 u32 buffer_offset = 0;
778 u32 buffer_tail_bits;
780 u32 field_datum_count;
783 ACPI_FUNCTION_TRACE("ex_insert_into_field");
785 /* Validate input buffer */
788 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) {
790 "Field size %X (bits) is too large for buffer (%X)",
791 obj_desc->common_field.bit_length, buffer_length));
793 return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
796 /* Compute the number of datums (access width data items) */
799 ACPI_MASK_BITS_BELOW(obj_desc->common_field.start_field_bit_offset);
801 ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
802 obj_desc->common_field.access_bit_width);
804 ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
805 obj_desc->common_field.start_field_bit_offset,
806 obj_desc->common_field.access_bit_width);
808 /* Get initial Datum from the input buffer */
810 ACPI_MEMCPY(&raw_datum, buffer,
811 ACPI_MIN(obj_desc->common_field.access_byte_width,
812 buffer_length - buffer_offset));
815 raw_datum << obj_desc->common_field.start_field_bit_offset;
817 /* Write the entire field */
819 for (i = 1; i < field_datum_count; i++) {
820 /* Write merged datum to the target field */
822 merged_datum &= mask;
823 status = acpi_ex_write_with_update_rule(obj_desc, mask,
826 if (ACPI_FAILURE(status)) {
827 return_ACPI_STATUS(status);
830 /* Start new output datum by merging with previous input datum */
832 field_offset += obj_desc->common_field.access_byte_width;
833 merged_datum = raw_datum >>
834 (obj_desc->common_field.access_bit_width -
835 obj_desc->common_field.start_field_bit_offset);
836 mask = ACPI_INTEGER_MAX;
838 if (i == datum_count) {
842 /* Get the next input datum from the buffer */
844 buffer_offset += obj_desc->common_field.access_byte_width;
845 ACPI_MEMCPY(&raw_datum, ((char *)buffer) + buffer_offset,
846 ACPI_MIN(obj_desc->common_field.access_byte_width,
847 buffer_length - buffer_offset));
849 raw_datum << obj_desc->common_field.start_field_bit_offset;
852 /* Mask off any extra bits in the last datum */
854 buffer_tail_bits = (obj_desc->common_field.bit_length +
855 obj_desc->common_field.start_field_bit_offset) %
856 obj_desc->common_field.access_bit_width;
857 if (buffer_tail_bits) {
858 mask &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
861 /* Write the last datum to the field */
863 merged_datum &= mask;
864 status = acpi_ex_write_with_update_rule(obj_desc,
868 return_ACPI_STATUS(status);