[PATCH] W1: w1_netlink: New init/fini netlink callbacks.
[linux-2.6/verdex.git] / drivers / acpi / executer / exfldio.c
blobba6e08843c29894ee749c3f88ee6be3217ee2eab
1 /******************************************************************************
3 * Module Name: exfldio - Aml Field I/O
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 */
54 static acpi_status
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);
59 static u8
60 acpi_ex_register_overflow(union acpi_operand_object *obj_desc,
61 acpi_integer value);
63 static acpi_status
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
73 * parent field
75 * RETURN: Status
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 ******************************************************************************/
83 static acpi_status
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);
131 #endif
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->
168 common_field.
169 node),
170 obj_desc->common_field.
171 access_byte_width,
172 acpi_ut_get_node_name(rgn_desc->
173 region.node),
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.
184 node),
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
203 * parent field
204 * Value - Where to store value (must at least
205 * the size of acpi_integer)
206 * Function - Read or Write flag plus other region-
207 * dependent flags
209 * RETURN: Status
211 * DESCRIPTION: Read or Write a single field datum to an Operation Region.
213 ******************************************************************************/
215 acpi_status
216 acpi_ex_access_region(union acpi_operand_object *obj_desc,
217 u32 field_datum_byte_offset,
218 acpi_integer * value, u32 function)
220 acpi_status status;
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]"));
248 } else {
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.
255 space_id),
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,
265 address,
266 ACPI_MUL_8(obj_desc->
267 common_field.
268 access_byte_width),
269 value);
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->
276 region.
277 space_id),
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->
282 region.
283 space_id),
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 ******************************************************************************/
308 static u8
309 acpi_ex_register_overflow(union acpi_operand_object *obj_desc,
310 acpi_integer value)
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
316 * never overflow it.
318 return (FALSE);
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
324 * the register.
326 return (TRUE);
329 /* The Value will fit into the field with no truncation */
331 return (FALSE);
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
340 * parent field
341 * Value - Where to store value (must be 64 bits)
342 * read_write - Read or Write flag
344 * RETURN: Status
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 ******************************************************************************/
352 static acpi_status
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)
357 acpi_status status;
358 acpi_integer local_value;
360 ACPI_FUNCTION_TRACE_U32("ex_field_datum_io", field_datum_byte_offset);
362 if (read_write == ACPI_READ) {
363 if (!value) {
364 local_value = 0;
366 /* To support reads without saving return value */
367 value = &local_value;
370 /* Clear the entire return buffer first, [Very Important!] */
372 *value = 0;
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
381 * operation_region
382 * index_field - Write to an Index Register, then read/write from/to a
383 * Data Register
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.
403 ACPI_MEMCPY(value,
404 (obj_desc->buffer_field.buffer_obj)->buffer.
405 pointer +
406 obj_desc->buffer_field.base_byte_offset +
407 field_datum_byte_offset,
408 obj_desc->common_field.access_byte_width);
409 } else {
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.
415 pointer +
416 obj_desc->buffer_field.base_byte_offset +
417 field_datum_byte_offset, value,
418 obj_desc->common_field.access_byte_width);
421 status = AE_OK;
422 break;
424 case ACPI_TYPE_LOCAL_BANK_FIELD:
427 * Ensure that the bank_value is not beyond the capacity of
428 * the register
430 if (acpi_ex_register_overflow(obj_desc->bank_field.bank_obj,
431 (acpi_integer) obj_desc->
432 bank_field.value)) {
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.
440 status =
441 acpi_ex_insert_into_field(obj_desc->bank_field.bank_obj,
442 &obj_desc->bank_field.value,
443 sizeof(obj_desc->bank_field.
444 value));
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
459 * Operation Region.
461 status =
462 acpi_ex_access_region(obj_desc, field_datum_byte_offset,
463 value, read_write);
464 break;
466 case ACPI_TYPE_LOCAL_INDEX_FIELD:
469 * Ensure that the index_value is not beyond the capacity of
470 * the register
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));
486 status =
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",
496 value));
498 if (read_write == ACPI_READ) {
499 /* Read the datum from the data_register */
501 status =
502 acpi_ex_extract_from_field(obj_desc->index_field.
503 data_obj, value,
504 sizeof(acpi_integer));
505 } else {
506 /* Write the datum to the data_register */
508 status =
509 acpi_ex_insert_into_field(obj_desc->index_field.
510 data_obj, value,
511 sizeof(acpi_integer));
513 break;
515 default:
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;
520 break;
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.
529 access_byte_width));
530 } else {
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.
535 access_byte_width));
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
551 * RETURN: Status
553 * DESCRIPTION: Apply the field update rule to a field write
555 ******************************************************************************/
557 acpi_status
558 acpi_ex_write_with_update_rule(union acpi_operand_object *obj_desc,
559 acpi_integer mask,
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.
592 status =
593 acpi_ex_field_datum_io(obj_desc,
594 field_datum_byte_offset,
595 &current_value,
596 ACPI_READ);
597 if (ACPI_FAILURE(status)) {
598 return_ACPI_STATUS(status);
601 merged_value |= (current_value & ~mask);
603 break;
605 case AML_FIELD_UPDATE_WRITE_AS_ONES:
607 /* Set positions outside the field to all ones */
609 merged_value |= ~mask;
610 break;
612 case AML_FIELD_UPDATE_WRITE_AS_ZEROS:
614 /* Set positions outside the field to all zeros */
616 merged_value &= mask;
617 break;
619 default:
621 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
622 "write_with_update_rule: Unknown update_rule setting: %X\n",
623 (obj_desc->common_field.
624 field_flags &
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
654 * RETURN: Status
656 * DESCRIPTION: Retrieve the current value of the given field
658 ******************************************************************************/
660 acpi_status
661 acpi_ex_extract_from_field(union acpi_operand_object *obj_desc,
662 void *buffer, u32 buffer_length)
664 acpi_status status;
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;
670 u32 datum_count;
671 u32 field_datum_count;
672 u32 i;
674 ACPI_FUNCTION_TRACE("ex_extract_from_field");
676 /* Validate target buffer and clear it */
678 if (buffer_length <
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,
683 buffer_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.
697 access_bit_width);
699 /* Priming read from the field */
701 status =
702 acpi_ex_field_datum_io(obj_desc, field_offset, &raw_datum,
703 ACPI_READ);
704 if (ACPI_FAILURE(status)) {
705 return_ACPI_STATUS(status);
707 merged_datum =
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) {
729 break;
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;
739 merged_datum =
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
768 * RETURN: Status
770 * DESCRIPTION: Store the Buffer contents into the given field
772 ******************************************************************************/
774 acpi_status
775 acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
776 void *buffer, u32 buffer_length)
778 acpi_status status;
779 acpi_integer mask;
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;
785 u32 datum_count;
786 u32 field_datum_count;
787 u32 i;
789 ACPI_FUNCTION_TRACE("ex_insert_into_field");
791 /* Validate input buffer */
793 if (buffer_length <
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,
798 buffer_length));
800 return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
803 /* Compute the number of datums (access width data items) */
805 mask =
806 ACPI_MASK_BITS_BELOW(obj_desc->common_field.start_field_bit_offset);
807 datum_count =
808 ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
809 obj_desc->common_field.access_bit_width);
810 field_datum_count =
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));
821 merged_datum =
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,
831 merged_datum,
832 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) {
846 break;
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 |=
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,
872 mask, merged_datum,
873 field_offset);
875 return_ACPI_STATUS(status);