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.
45 #include <acpi/acpi.h>
46 #include <acpi/acinterp.h>
47 #include <acpi/amlcode.h>
48 #include <acpi/acevents.h>
49 #include <acpi/acdispat.h>
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exfldio")
55 /* Local prototypes */
58 acpi_ex_field_datum_io (
59 union acpi_operand_object
*obj_desc
,
60 u32 field_datum_byte_offset
,
65 acpi_ex_register_overflow (
66 union acpi_operand_object
*obj_desc
,
70 acpi_ex_setup_region (
71 union acpi_operand_object
*obj_desc
,
72 u32 field_datum_byte_offset
);
75 /*******************************************************************************
77 * FUNCTION: acpi_ex_setup_region
79 * PARAMETERS: obj_desc - Field to be read or written
80 * field_datum_byte_offset - Byte offset of this datum within the
85 * DESCRIPTION: Common processing for acpi_ex_extract_from_field and
86 * acpi_ex_insert_into_field. Initialize the Region if necessary and
87 * validate the request.
89 ******************************************************************************/
92 acpi_ex_setup_region (
93 union acpi_operand_object
*obj_desc
,
94 u32 field_datum_byte_offset
)
96 acpi_status status
= AE_OK
;
97 union acpi_operand_object
*rgn_desc
;
100 ACPI_FUNCTION_TRACE_U32 ("ex_setup_region", field_datum_byte_offset
);
103 rgn_desc
= obj_desc
->common_field
.region_obj
;
105 /* We must have a valid region */
107 if (ACPI_GET_OBJECT_TYPE (rgn_desc
) != ACPI_TYPE_REGION
) {
108 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Needed Region, found type %X (%s)\n",
109 ACPI_GET_OBJECT_TYPE (rgn_desc
),
110 acpi_ut_get_object_type_name (rgn_desc
)));
112 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
116 * If the Region Address and Length have not been previously evaluated,
117 * evaluate them now and save the results.
119 if (!(rgn_desc
->common
.flags
& AOPOBJ_DATA_VALID
)) {
120 status
= acpi_ds_get_region_arguments (rgn_desc
);
121 if (ACPI_FAILURE (status
)) {
122 return_ACPI_STATUS (status
);
126 if (rgn_desc
->region
.space_id
== ACPI_ADR_SPACE_SMBUS
) {
127 /* SMBus has a non-linear address space */
129 return_ACPI_STATUS (AE_OK
);
132 #ifdef ACPI_UNDER_DEVELOPMENT
134 * If the Field access is any_acc, we can now compute the optimal
135 * access (because we know know the length of the parent region)
137 if (!(obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
)) {
138 if (ACPI_FAILURE (status
)) {
139 return_ACPI_STATUS (status
);
145 * Validate the request. The entire request from the byte offset for a
146 * length of one field datum (access width) must fit within the region.
147 * (Region length is specified in bytes)
149 if (rgn_desc
->region
.length
< (obj_desc
->common_field
.base_byte_offset
+
150 field_datum_byte_offset
+
151 obj_desc
->common_field
.access_byte_width
)) {
152 if (acpi_gbl_enable_interpreter_slack
) {
154 * Slack mode only: We will go ahead and allow access to this
155 * field if it is within the region length rounded up to the next
156 * access width boundary.
158 if (ACPI_ROUND_UP (rgn_desc
->region
.length
,
159 obj_desc
->common_field
.access_byte_width
) >=
160 (obj_desc
->common_field
.base_byte_offset
+
161 (acpi_native_uint
) obj_desc
->common_field
.access_byte_width
+
162 field_datum_byte_offset
)) {
163 return_ACPI_STATUS (AE_OK
);
167 if (rgn_desc
->region
.length
< obj_desc
->common_field
.access_byte_width
) {
169 * This is the case where the access_type (acc_word, etc.) is wider
170 * than the region itself. For example, a region of length one
171 * byte, and a field with Dword access specified.
173 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
174 "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)\n",
175 acpi_ut_get_node_name (obj_desc
->common_field
.node
),
176 obj_desc
->common_field
.access_byte_width
,
177 acpi_ut_get_node_name (rgn_desc
->region
.node
),
178 rgn_desc
->region
.length
));
182 * Offset rounded up to next multiple of field width
183 * exceeds region length, indicate an error
185 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
186 "Field [%4.4s] Base+Offset+Width %X+%X+%X is beyond end of region [%4.4s] (length %X)\n",
187 acpi_ut_get_node_name (obj_desc
->common_field
.node
),
188 obj_desc
->common_field
.base_byte_offset
,
189 field_datum_byte_offset
, obj_desc
->common_field
.access_byte_width
,
190 acpi_ut_get_node_name (rgn_desc
->region
.node
),
191 rgn_desc
->region
.length
));
193 return_ACPI_STATUS (AE_AML_REGION_LIMIT
);
196 return_ACPI_STATUS (AE_OK
);
200 /*******************************************************************************
202 * FUNCTION: acpi_ex_access_region
204 * PARAMETERS: obj_desc - Field to be read
205 * field_datum_byte_offset - Byte offset of this datum within the
207 * Value - Where to store value (must at least
208 * the size of acpi_integer)
209 * Function - Read or Write flag plus other region-
214 * DESCRIPTION: Read or Write a single field datum to an Operation Region.
216 ******************************************************************************/
219 acpi_ex_access_region (
220 union acpi_operand_object
*obj_desc
,
221 u32 field_datum_byte_offset
,
226 union acpi_operand_object
*rgn_desc
;
227 acpi_physical_address address
;
230 ACPI_FUNCTION_TRACE ("ex_access_region");
234 * Ensure that the region operands are fully evaluated and verify
235 * the validity of the request
237 status
= acpi_ex_setup_region (obj_desc
, field_datum_byte_offset
);
238 if (ACPI_FAILURE (status
)) {
239 return_ACPI_STATUS (status
);
243 * The physical address of this field datum is:
245 * 1) The base of the region, plus
246 * 2) The base offset of the field, plus
247 * 3) The current offset into the field
249 rgn_desc
= obj_desc
->common_field
.region_obj
;
250 address
= rgn_desc
->region
.address
+
251 obj_desc
->common_field
.base_byte_offset
+
252 field_datum_byte_offset
;
254 if ((function
& ACPI_IO_MASK
) == ACPI_READ
) {
255 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
, "[READ]"));
258 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
, "[WRITE]"));
261 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_BFIELD
,
262 " Region [%s:%X], Width %X, byte_base %X, Offset %X at %8.8X%8.8X\n",
263 acpi_ut_get_region_name (rgn_desc
->region
.space_id
),
264 rgn_desc
->region
.space_id
,
265 obj_desc
->common_field
.access_byte_width
,
266 obj_desc
->common_field
.base_byte_offset
,
267 field_datum_byte_offset
,
268 ACPI_FORMAT_UINT64 (address
)));
270 /* Invoke the appropriate address_space/op_region handler */
272 status
= acpi_ev_address_space_dispatch (rgn_desc
, function
,
274 ACPI_MUL_8 (obj_desc
->common_field
.access_byte_width
), value
);
276 if (ACPI_FAILURE (status
)) {
277 if (status
== AE_NOT_IMPLEMENTED
) {
278 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
279 "Region %s(%X) not implemented\n",
280 acpi_ut_get_region_name (rgn_desc
->region
.space_id
),
281 rgn_desc
->region
.space_id
));
283 else if (status
== AE_NOT_EXIST
) {
285 "Region %s(%X) has no handler\n",
286 acpi_ut_get_region_name (rgn_desc
->region
.space_id
),
287 rgn_desc
->region
.space_id
));
291 return_ACPI_STATUS (status
);
295 /*******************************************************************************
297 * FUNCTION: acpi_ex_register_overflow
299 * PARAMETERS: obj_desc - Register(Field) to be written
300 * Value - Value to be stored
302 * RETURN: TRUE if value overflows the field, FALSE otherwise
304 * DESCRIPTION: Check if a value is out of range of the field being written.
305 * Used to check if the values written to Index and Bank registers
306 * are out of range. Normally, the value is simply truncated
307 * to fit the field, but this case is most likely a serious
308 * coding error in the ASL.
310 ******************************************************************************/
313 acpi_ex_register_overflow (
314 union acpi_operand_object
*obj_desc
,
318 if (obj_desc
->common_field
.bit_length
>= ACPI_INTEGER_BIT_SIZE
) {
320 * The field is large enough to hold the maximum integer, so we can
326 if (value
>= ((acpi_integer
) 1 << obj_desc
->common_field
.bit_length
)) {
328 * The Value is larger than the maximum value that can fit into
334 /* The Value will fit into the field with no truncation */
340 /*******************************************************************************
342 * FUNCTION: acpi_ex_field_datum_io
344 * PARAMETERS: obj_desc - Field to be read
345 * field_datum_byte_offset - Byte offset of this datum within the
347 * Value - Where to store value (must be 64 bits)
348 * read_write - Read or Write flag
352 * DESCRIPTION: Read or Write a single datum of a field. The field_type is
353 * demultiplexed here to handle the different types of fields
354 * (buffer_field, region_field, index_field, bank_field)
356 ******************************************************************************/
359 acpi_ex_field_datum_io (
360 union acpi_operand_object
*obj_desc
,
361 u32 field_datum_byte_offset
,
366 acpi_integer local_value
;
369 ACPI_FUNCTION_TRACE_U32 ("ex_field_datum_io", field_datum_byte_offset
);
372 if (read_write
== ACPI_READ
) {
376 /* To support reads without saving return value */
377 value
= &local_value
;
380 /* Clear the entire return buffer first, [Very Important!] */
386 * The four types of fields are:
388 * buffer_field - Read/write from/to a Buffer
389 * region_field - Read/write from/to a Operation Region.
390 * bank_field - Write to a Bank Register, then read/write from/to an
392 * index_field - Write to an Index Register, then read/write from/to a
395 switch (ACPI_GET_OBJECT_TYPE (obj_desc
)) {
396 case ACPI_TYPE_BUFFER_FIELD
:
398 * If the buffer_field arguments have not been previously evaluated,
399 * evaluate them now and save the results.
401 if (!(obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
)) {
402 status
= acpi_ds_get_buffer_field_arguments (obj_desc
);
403 if (ACPI_FAILURE (status
)) {
404 return_ACPI_STATUS (status
);
408 if (read_write
== ACPI_READ
) {
410 * Copy the data from the source buffer.
411 * Length is the field width in bytes.
414 (obj_desc
->buffer_field
.buffer_obj
)->buffer
.pointer
+
415 obj_desc
->buffer_field
.base_byte_offset
+
416 field_datum_byte_offset
,
417 obj_desc
->common_field
.access_byte_width
);
421 * Copy the data to the target buffer.
422 * Length is the field width in bytes.
424 ACPI_MEMCPY ((obj_desc
->buffer_field
.buffer_obj
)->buffer
.pointer
+
425 obj_desc
->buffer_field
.base_byte_offset
+
426 field_datum_byte_offset
,
427 value
, obj_desc
->common_field
.access_byte_width
);
434 case ACPI_TYPE_LOCAL_BANK_FIELD
:
437 * Ensure that the bank_value is not beyond the capacity of
440 if (acpi_ex_register_overflow (obj_desc
->bank_field
.bank_obj
,
441 (acpi_integer
) obj_desc
->bank_field
.value
)) {
442 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT
);
446 * For bank_fields, we must write the bank_value to the bank_register
447 * (itself a region_field) before we can access the data.
449 status
= acpi_ex_insert_into_field (obj_desc
->bank_field
.bank_obj
,
450 &obj_desc
->bank_field
.value
,
451 sizeof (obj_desc
->bank_field
.value
));
452 if (ACPI_FAILURE (status
)) {
453 return_ACPI_STATUS (status
);
457 * Now that the Bank has been selected, fall through to the
458 * region_field case and write the datum to the Operation Region
461 /*lint -fallthrough */
464 case ACPI_TYPE_LOCAL_REGION_FIELD
:
466 * For simple region_fields, we just directly access the owning
469 status
= acpi_ex_access_region (obj_desc
, field_datum_byte_offset
, value
,
474 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
478 * Ensure that the index_value is not beyond the capacity of
481 if (acpi_ex_register_overflow (obj_desc
->index_field
.index_obj
,
482 (acpi_integer
) obj_desc
->index_field
.value
)) {
483 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT
);
486 /* Write the index value to the index_register (itself a region_field) */
488 field_datum_byte_offset
+= obj_desc
->index_field
.value
;
490 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
491 "Write to Index Register: Value %8.8X\n",
492 field_datum_byte_offset
));
494 status
= acpi_ex_insert_into_field (obj_desc
->index_field
.index_obj
,
495 &field_datum_byte_offset
,
496 sizeof (field_datum_byte_offset
));
497 if (ACPI_FAILURE (status
)) {
498 return_ACPI_STATUS (status
);
501 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
502 "I/O to Data Register: value_ptr %p\n",
505 if (read_write
== ACPI_READ
) {
506 /* Read the datum from the data_register */
508 status
= acpi_ex_extract_from_field (obj_desc
->index_field
.data_obj
,
509 value
, sizeof (acpi_integer
));
512 /* Write the datum to the data_register */
514 status
= acpi_ex_insert_into_field (obj_desc
->index_field
.data_obj
,
515 value
, sizeof (acpi_integer
));
522 ACPI_REPORT_ERROR (("Wrong object type in field I/O %X\n",
523 ACPI_GET_OBJECT_TYPE (obj_desc
)));
524 status
= AE_AML_INTERNAL
;
528 if (ACPI_SUCCESS (status
)) {
529 if (read_write
== ACPI_READ
) {
530 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
531 "Value Read %8.8X%8.8X, Width %d\n",
532 ACPI_FORMAT_UINT64 (*value
),
533 obj_desc
->common_field
.access_byte_width
));
536 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
537 "Value Written %8.8X%8.8X, Width %d\n",
538 ACPI_FORMAT_UINT64 (*value
),
539 obj_desc
->common_field
.access_byte_width
));
543 return_ACPI_STATUS (status
);
547 /*******************************************************************************
549 * FUNCTION: acpi_ex_write_with_update_rule
551 * PARAMETERS: obj_desc - Field to be written
552 * Mask - bitmask within field datum
553 * field_value - Value to write
554 * field_datum_byte_offset - Offset of datum within field
558 * DESCRIPTION: Apply the field update rule to a field write
560 ******************************************************************************/
563 acpi_ex_write_with_update_rule (
564 union acpi_operand_object
*obj_desc
,
566 acpi_integer field_value
,
567 u32 field_datum_byte_offset
)
569 acpi_status status
= AE_OK
;
570 acpi_integer merged_value
;
571 acpi_integer current_value
;
574 ACPI_FUNCTION_TRACE_U32 ("ex_write_with_update_rule", mask
);
577 /* Start with the new bits */
579 merged_value
= field_value
;
581 /* If the mask is all ones, we don't need to worry about the update rule */
583 if (mask
!= ACPI_INTEGER_MAX
) {
584 /* Decode the update rule */
586 switch (obj_desc
->common_field
.field_flags
& AML_FIELD_UPDATE_RULE_MASK
) {
587 case AML_FIELD_UPDATE_PRESERVE
:
589 * Check if update rule needs to be applied (not if mask is all
590 * ones) The left shift drops the bits we want to ignore.
592 if ((~mask
<< (ACPI_MUL_8 (sizeof (mask
)) -
593 ACPI_MUL_8 (obj_desc
->common_field
.access_byte_width
))) != 0) {
595 * Read the current contents of the byte/word/dword containing
596 * the field, and merge with the new field value.
598 status
= acpi_ex_field_datum_io (obj_desc
, field_datum_byte_offset
,
599 ¤t_value
, ACPI_READ
);
600 if (ACPI_FAILURE (status
)) {
601 return_ACPI_STATUS (status
);
604 merged_value
|= (current_value
& ~mask
);
608 case AML_FIELD_UPDATE_WRITE_AS_ONES
:
610 /* Set positions outside the field to all ones */
612 merged_value
|= ~mask
;
615 case AML_FIELD_UPDATE_WRITE_AS_ZEROS
:
617 /* Set positions outside the field to all zeros */
619 merged_value
&= mask
;
624 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
625 "write_with_update_rule: Unknown update_rule setting: %X\n",
626 (obj_desc
->common_field
.field_flags
& AML_FIELD_UPDATE_RULE_MASK
)));
627 return_ACPI_STATUS (AE_AML_OPERAND_VALUE
);
631 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
632 "Mask %8.8X%8.8X, datum_offset %X, Width %X, Value %8.8X%8.8X, merged_value %8.8X%8.8X\n",
633 ACPI_FORMAT_UINT64 (mask
),
634 field_datum_byte_offset
,
635 obj_desc
->common_field
.access_byte_width
,
636 ACPI_FORMAT_UINT64 (field_value
),
637 ACPI_FORMAT_UINT64 (merged_value
)));
639 /* Write the merged value */
641 status
= acpi_ex_field_datum_io (obj_desc
, field_datum_byte_offset
,
642 &merged_value
, ACPI_WRITE
);
644 return_ACPI_STATUS (status
);
648 /*******************************************************************************
650 * FUNCTION: acpi_ex_extract_from_field
652 * PARAMETERS: obj_desc - Field to be read
653 * Buffer - Where to store the field data
654 * buffer_length - Length of Buffer
658 * DESCRIPTION: Retrieve the current value of the given field
660 ******************************************************************************/
663 acpi_ex_extract_from_field (
664 union acpi_operand_object
*obj_desc
,
669 acpi_integer raw_datum
;
670 acpi_integer merged_datum
;
671 u32 field_offset
= 0;
672 u32 buffer_offset
= 0;
673 u32 buffer_tail_bits
;
675 u32 field_datum_count
;
679 ACPI_FUNCTION_TRACE ("ex_extract_from_field");
682 /* Validate target buffer and clear it */
684 if (buffer_length
< ACPI_ROUND_BITS_UP_TO_BYTES (
685 obj_desc
->common_field
.bit_length
)) {
686 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
687 "Field size %X (bits) is too large for buffer (%X)\n",
688 obj_desc
->common_field
.bit_length
, buffer_length
));
690 return_ACPI_STATUS (AE_BUFFER_OVERFLOW
);
692 ACPI_MEMSET (buffer
, 0, buffer_length
);
694 /* Compute the number of datums (access width data items) */
696 datum_count
= ACPI_ROUND_UP_TO (
697 obj_desc
->common_field
.bit_length
,
698 obj_desc
->common_field
.access_bit_width
);
699 field_datum_count
= ACPI_ROUND_UP_TO (
700 obj_desc
->common_field
.bit_length
+
701 obj_desc
->common_field
.start_field_bit_offset
,
702 obj_desc
->common_field
.access_bit_width
);
704 /* Priming read from the field */
706 status
= acpi_ex_field_datum_io (obj_desc
, field_offset
, &raw_datum
, ACPI_READ
);
707 if (ACPI_FAILURE (status
)) {
708 return_ACPI_STATUS (status
);
710 merged_datum
= raw_datum
>> obj_desc
->common_field
.start_field_bit_offset
;
712 /* Read the rest of the field */
714 for (i
= 1; i
< field_datum_count
; i
++) {
715 /* Get next input datum from the field */
717 field_offset
+= obj_desc
->common_field
.access_byte_width
;
718 status
= acpi_ex_field_datum_io (obj_desc
, field_offset
,
719 &raw_datum
, ACPI_READ
);
720 if (ACPI_FAILURE (status
)) {
721 return_ACPI_STATUS (status
);
724 /* Merge with previous datum if necessary */
726 merged_datum
|= raw_datum
<<
727 (obj_desc
->common_field
.access_bit_width
-
728 obj_desc
->common_field
.start_field_bit_offset
);
730 if (i
== datum_count
) {
734 /* Write merged datum to target buffer */
736 ACPI_MEMCPY (((char *) buffer
) + buffer_offset
, &merged_datum
,
737 ACPI_MIN(obj_desc
->common_field
.access_byte_width
,
738 buffer_length
- buffer_offset
));
740 buffer_offset
+= obj_desc
->common_field
.access_byte_width
;
741 merged_datum
= raw_datum
>> obj_desc
->common_field
.start_field_bit_offset
;
744 /* Mask off any extra bits in the last datum */
746 buffer_tail_bits
= obj_desc
->common_field
.bit_length
%
747 obj_desc
->common_field
.access_bit_width
;
748 if (buffer_tail_bits
) {
749 merged_datum
&= ACPI_MASK_BITS_ABOVE (buffer_tail_bits
);
752 /* Write the last datum to the buffer */
754 ACPI_MEMCPY (((char *) buffer
) + buffer_offset
, &merged_datum
,
755 ACPI_MIN(obj_desc
->common_field
.access_byte_width
,
756 buffer_length
- buffer_offset
));
758 return_ACPI_STATUS (AE_OK
);
762 /*******************************************************************************
764 * FUNCTION: acpi_ex_insert_into_field
766 * PARAMETERS: obj_desc - Field to be written
767 * Buffer - Data to be written
768 * buffer_length - Length of Buffer
772 * DESCRIPTION: Store the Buffer contents into the given field
774 ******************************************************************************/
777 acpi_ex_insert_into_field (
778 union acpi_operand_object
*obj_desc
,
784 acpi_integer merged_datum
;
785 acpi_integer raw_datum
= 0;
786 u32 field_offset
= 0;
787 u32 buffer_offset
= 0;
788 u32 buffer_tail_bits
;
790 u32 field_datum_count
;
794 ACPI_FUNCTION_TRACE ("ex_insert_into_field");
797 /* Validate input buffer */
799 if (buffer_length
< ACPI_ROUND_BITS_UP_TO_BYTES (
800 obj_desc
->common_field
.bit_length
)) {
801 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
802 "Field size %X (bits) is too large for buffer (%X)\n",
803 obj_desc
->common_field
.bit_length
, buffer_length
));
805 return_ACPI_STATUS (AE_BUFFER_OVERFLOW
);
808 /* Compute the number of datums (access width data items) */
810 mask
= ACPI_MASK_BITS_BELOW (obj_desc
->common_field
.start_field_bit_offset
);
811 datum_count
= ACPI_ROUND_UP_TO (obj_desc
->common_field
.bit_length
,
812 obj_desc
->common_field
.access_bit_width
);
813 field_datum_count
= ACPI_ROUND_UP_TO (obj_desc
->common_field
.bit_length
+
814 obj_desc
->common_field
.start_field_bit_offset
,
815 obj_desc
->common_field
.access_bit_width
);
817 /* Get initial Datum from the input buffer */
819 ACPI_MEMCPY (&raw_datum
, buffer
,
820 ACPI_MIN(obj_desc
->common_field
.access_byte_width
,
821 buffer_length
- buffer_offset
));
823 merged_datum
= raw_datum
<< obj_desc
->common_field
.start_field_bit_offset
;
825 /* Write the entire field */
827 for (i
= 1; i
< field_datum_count
; i
++) {
828 /* Write merged datum to the target field */
830 merged_datum
&= mask
;
831 status
= acpi_ex_write_with_update_rule (obj_desc
, mask
,
832 merged_datum
, field_offset
);
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
));
855 merged_datum
|= raw_datum
<< obj_desc
->common_field
.start_field_bit_offset
;
858 /* Mask off any extra bits in the last datum */
860 buffer_tail_bits
= (obj_desc
->common_field
.bit_length
+
861 obj_desc
->common_field
.start_field_bit_offset
) %
862 obj_desc
->common_field
.access_bit_width
;
863 if (buffer_tail_bits
) {
864 mask
&= ACPI_MASK_BITS_ABOVE (buffer_tail_bits
);
867 /* Write the last datum to the field */
869 merged_datum
&= mask
;
870 status
= acpi_ex_write_with_update_rule (obj_desc
,
871 mask
, merged_datum
, field_offset
);
873 return_ACPI_STATUS (status
);