blob: 6687be167f5f67c6d6b30c5c6b24d3cfd19a7346 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: exfldio - Aml Field I/O
4 *
5 *****************************************************************************/
6
7/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
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.
25 *
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.
29 *
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.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acinterp.h"
47#include "amlcode.h"
48#include "acevents.h"
49#include "acdispat.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("exfldio")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Robert Moore44f6c012005-04-18 22:49:35 -040054/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040055static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040056acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
57 u32 field_datum_byte_offset,
58 acpi_integer * value, u32 read_write);
Robert Moore44f6c012005-04-18 22:49:35 -040059
60static u8
Len Brown4be44fc2005-08-05 00:44:28 -040061acpi_ex_register_overflow(union acpi_operand_object *obj_desc,
62 acpi_integer value);
Robert Moore44f6c012005-04-18 22:49:35 -040063
64static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040065acpi_ex_setup_region(union acpi_operand_object *obj_desc,
66 u32 field_datum_byte_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/*******************************************************************************
69 *
70 * FUNCTION: acpi_ex_setup_region
71 *
Robert Moore44f6c012005-04-18 22:49:35 -040072 * PARAMETERS: obj_desc - Field to be read or written
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 * field_datum_byte_offset - Byte offset of this datum within the
74 * parent field
75 *
76 * RETURN: Status
77 *
78 * DESCRIPTION: Common processing for acpi_ex_extract_from_field and
79 * acpi_ex_insert_into_field. Initialize the Region if necessary and
80 * validate the request.
81 *
82 ******************************************************************************/
83
Robert Moore44f6c012005-04-18 22:49:35 -040084static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040085acpi_ex_setup_region(union acpi_operand_object *obj_desc,
86 u32 field_datum_byte_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Len Brown4be44fc2005-08-05 00:44:28 -040088 acpi_status status = AE_OK;
89 union acpi_operand_object *rgn_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Bob Mooreb229cf92006-04-21 17:15:00 -040091 ACPI_FUNCTION_TRACE_U32(ex_setup_region, field_datum_byte_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 rgn_desc = obj_desc->common_field.region_obj;
94
95 /* We must have a valid region */
96
Bob Moore3371c192009-02-18 14:44:03 +080097 if (rgn_desc->common.type != ACPI_TYPE_REGION) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050098 ACPI_ERROR((AE_INFO, "Needed Region, found type %X (%s)",
Bob Moore3371c192009-02-18 14:44:03 +080099 rgn_desc->common.type,
Bob Mooreb8e4d892006-01-27 16:43:00 -0500100 acpi_ut_get_object_type_name(rgn_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Len Brown4be44fc2005-08-05 00:44:28 -0400102 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
104
105 /*
106 * If the Region Address and Length have not been previously evaluated,
107 * evaluate them now and save the results.
108 */
109 if (!(rgn_desc->common.flags & AOPOBJ_DATA_VALID)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400110 status = acpi_ds_get_region_arguments(rgn_desc);
111 if (ACPI_FAILURE(status)) {
112 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
114 }
115
Len Brown7cb7f452009-07-27 18:42:38 -0400116 /* Exit if Address/Length have been disallowed by the host OS */
117
118 if (rgn_desc->common.flags & AOPOBJ_INVALID) {
119 return_ACPI_STATUS(AE_AML_ILLEGAL_ADDRESS);
120 }
121
Bob Mooreb229cf92006-04-21 17:15:00 -0400122 /*
123 * Exit now for SMBus address space, it has a non-linear address space
124 * and the request cannot be directly validated
125 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 if (rgn_desc->region.space_id == ACPI_ADR_SPACE_SMBUS) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* SMBus has a non-linear address space */
129
Len Brown4be44fc2005-08-05 00:44:28 -0400130 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#ifdef ACPI_UNDER_DEVELOPMENT
133 /*
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)
136 */
137 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400138 if (ACPI_FAILURE(status)) {
139 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141 }
142#endif
143
144 /*
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)
148 */
Bob Moore41195322006-05-26 16:36:00 -0400149 if (rgn_desc->region.length <
150 (obj_desc->common_field.base_byte_offset +
151 field_datum_byte_offset +
152 obj_desc->common_field.access_byte_width)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 if (acpi_gbl_enable_interpreter_slack) {
154 /*
155 * Slack mode only: We will go ahead and allow access to this
156 * field if it is within the region length rounded up to the next
Bob Moore67a119f2008-06-10 13:42:13 +0800157 * access width boundary. acpi_size cast for 64-bit compile.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 */
Len Brown4be44fc2005-08-05 00:44:28 -0400159 if (ACPI_ROUND_UP(rgn_desc->region.length,
160 obj_desc->common_field.
161 access_byte_width) >=
Bob Moore67a119f2008-06-10 13:42:13 +0800162 ((acpi_size) obj_desc->common_field.
163 base_byte_offset +
164 obj_desc->common_field.access_byte_width +
165 field_datum_byte_offset)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400166 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 }
168 }
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170 if (rgn_desc->region.length <
171 obj_desc->common_field.access_byte_width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /*
173 * This is the case where the access_type (acc_word, etc.) is wider
174 * than the region itself. For example, a region of length one
175 * byte, and a field with Dword access specified.
176 */
Bob Mooreb8e4d892006-01-27 16:43:00 -0500177 ACPI_ERROR((AE_INFO,
178 "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)",
179 acpi_ut_get_node_name(obj_desc->
180 common_field.node),
181 obj_desc->common_field.access_byte_width,
182 acpi_ut_get_node_name(rgn_desc->region.
183 node),
184 rgn_desc->region.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186
187 /*
188 * Offset rounded up to next multiple of field width
189 * exceeds region length, indicate an error
190 */
Bob Mooreb8e4d892006-01-27 16:43:00 -0500191 ACPI_ERROR((AE_INFO,
192 "Field [%4.4s] Base+Offset+Width %X+%X+%X is beyond end of region [%4.4s] (length %X)",
193 acpi_ut_get_node_name(obj_desc->common_field.node),
194 obj_desc->common_field.base_byte_offset,
195 field_datum_byte_offset,
196 obj_desc->common_field.access_byte_width,
197 acpi_ut_get_node_name(rgn_desc->region.node),
198 rgn_desc->region.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Len Brown4be44fc2005-08-05 00:44:28 -0400200 return_ACPI_STATUS(AE_AML_REGION_LIMIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/*******************************************************************************
207 *
208 * FUNCTION: acpi_ex_access_region
209 *
Robert Moore44f6c012005-04-18 22:49:35 -0400210 * PARAMETERS: obj_desc - Field to be read
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 * field_datum_byte_offset - Byte offset of this datum within the
212 * parent field
Robert Moore44f6c012005-04-18 22:49:35 -0400213 * Value - Where to store value (must at least
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 * the size of acpi_integer)
215 * Function - Read or Write flag plus other region-
216 * dependent flags
217 *
218 * RETURN: Status
219 *
220 * DESCRIPTION: Read or Write a single field datum to an Operation Region.
221 *
222 ******************************************************************************/
223
224acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400225acpi_ex_access_region(union acpi_operand_object *obj_desc,
226 u32 field_datum_byte_offset,
227 acpi_integer * value, u32 function)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
Len Brown4be44fc2005-08-05 00:44:28 -0400229 acpi_status status;
230 union acpi_operand_object *rgn_desc;
Bob Mooref5407af2009-05-21 10:56:52 +0800231 u32 region_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Bob Mooreb229cf92006-04-21 17:15:00 -0400233 ACPI_FUNCTION_TRACE(ex_access_region);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /*
236 * Ensure that the region operands are fully evaluated and verify
237 * the validity of the request
238 */
Len Brown4be44fc2005-08-05 00:44:28 -0400239 status = acpi_ex_setup_region(obj_desc, field_datum_byte_offset);
240 if (ACPI_FAILURE(status)) {
241 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
243
244 /*
245 * The physical address of this field datum is:
246 *
247 * 1) The base of the region, plus
248 * 2) The base offset of the field, plus
249 * 3) The current offset into the field
250 */
251 rgn_desc = obj_desc->common_field.region_obj;
Bob Mooref5407af2009-05-21 10:56:52 +0800252 region_offset =
Len Brown4be44fc2005-08-05 00:44:28 -0400253 obj_desc->common_field.base_byte_offset + field_datum_byte_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 if ((function & ACPI_IO_MASK) == ACPI_READ) {
Len Brown4be44fc2005-08-05 00:44:28 -0400256 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[READ]"));
257 } else {
258 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[WRITE]"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 }
260
Len Brown4be44fc2005-08-05 00:44:28 -0400261 ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD,
Bob Mooref3d2e782007-02-02 19:48:18 +0300262 " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400263 acpi_ut_get_region_name(rgn_desc->region.
264 space_id),
265 rgn_desc->region.space_id,
266 obj_desc->common_field.access_byte_width,
267 obj_desc->common_field.base_byte_offset,
Bob Mooreb7f9f042008-04-10 19:06:40 +0400268 field_datum_byte_offset, ACPI_CAST_PTR(void,
Bob Mooref5407af2009-05-21 10:56:52 +0800269 (rgn_desc->
270 region.
271 address +
272 region_offset))));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 /* Invoke the appropriate address_space/op_region handler */
275
Bob Mooref5407af2009-05-21 10:56:52 +0800276 status =
277 acpi_ev_address_space_dispatch(rgn_desc, function, region_offset,
278 ACPI_MUL_8(obj_desc->common_field.
279 access_byte_width),
280 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Len Brown4be44fc2005-08-05 00:44:28 -0400282 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (status == AE_NOT_IMPLEMENTED) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500284 ACPI_ERROR((AE_INFO,
285 "Region %s(%X) not implemented",
286 acpi_ut_get_region_name(rgn_desc->region.
287 space_id),
288 rgn_desc->region.space_id));
Len Brown4be44fc2005-08-05 00:44:28 -0400289 } else if (status == AE_NOT_EXIST) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500290 ACPI_ERROR((AE_INFO,
291 "Region %s(%X) has no handler",
292 acpi_ut_get_region_name(rgn_desc->region.
293 space_id),
294 rgn_desc->region.space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296 }
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301/*******************************************************************************
302 *
303 * FUNCTION: acpi_ex_register_overflow
304 *
Robert Moore44f6c012005-04-18 22:49:35 -0400305 * PARAMETERS: obj_desc - Register(Field) to be written
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 * Value - Value to be stored
307 *
308 * RETURN: TRUE if value overflows the field, FALSE otherwise
309 *
310 * DESCRIPTION: Check if a value is out of range of the field being written.
311 * Used to check if the values written to Index and Bank registers
312 * are out of range. Normally, the value is simply truncated
313 * to fit the field, but this case is most likely a serious
314 * coding error in the ASL.
315 *
316 ******************************************************************************/
317
Robert Moore44f6c012005-04-18 22:49:35 -0400318static u8
Len Brown4be44fc2005-08-05 00:44:28 -0400319acpi_ex_register_overflow(union acpi_operand_object *obj_desc,
320 acpi_integer value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322
323 if (obj_desc->common_field.bit_length >= ACPI_INTEGER_BIT_SIZE) {
324 /*
325 * The field is large enough to hold the maximum integer, so we can
326 * never overflow it.
327 */
328 return (FALSE);
329 }
330
331 if (value >= ((acpi_integer) 1 << obj_desc->common_field.bit_length)) {
332 /*
333 * The Value is larger than the maximum value that can fit into
334 * the register.
335 */
336 return (TRUE);
337 }
338
339 /* The Value will fit into the field with no truncation */
340
341 return (FALSE);
342}
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344/*******************************************************************************
345 *
346 * FUNCTION: acpi_ex_field_datum_io
347 *
Robert Moore44f6c012005-04-18 22:49:35 -0400348 * PARAMETERS: obj_desc - Field to be read
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 * field_datum_byte_offset - Byte offset of this datum within the
350 * parent field
Robert Moore44f6c012005-04-18 22:49:35 -0400351 * Value - Where to store value (must be 64 bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 * read_write - Read or Write flag
353 *
354 * RETURN: Status
355 *
356 * DESCRIPTION: Read or Write a single datum of a field. The field_type is
357 * demultiplexed here to handle the different types of fields
358 * (buffer_field, region_field, index_field, bank_field)
359 *
360 ******************************************************************************/
361
Robert Moore44f6c012005-04-18 22:49:35 -0400362static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400363acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
364 u32 field_datum_byte_offset,
365 acpi_integer * value, u32 read_write)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Len Brown4be44fc2005-08-05 00:44:28 -0400367 acpi_status status;
368 acpi_integer local_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Bob Mooreb229cf92006-04-21 17:15:00 -0400370 ACPI_FUNCTION_TRACE_U32(ex_field_datum_io, field_datum_byte_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 if (read_write == ACPI_READ) {
373 if (!value) {
374 local_value = 0;
Robert Moore44f6c012005-04-18 22:49:35 -0400375
376 /* To support reads without saving return value */
377 value = &local_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 }
379
380 /* Clear the entire return buffer first, [Very Important!] */
381
382 *value = 0;
383 }
384
385 /*
386 * The four types of fields are:
387 *
388 * buffer_field - Read/write from/to a Buffer
389 * region_field - Read/write from/to a Operation Region.
Robert Moore44f6c012005-04-18 22:49:35 -0400390 * bank_field - Write to a Bank Register, then read/write from/to an
391 * operation_region
392 * index_field - Write to an Index Register, then read/write from/to a
393 * Data Register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 */
Bob Moore3371c192009-02-18 14:44:03 +0800395 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 case ACPI_TYPE_BUFFER_FIELD:
397 /*
398 * If the buffer_field arguments have not been previously evaluated,
399 * evaluate them now and save the results.
400 */
401 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400402 status = acpi_ds_get_buffer_field_arguments(obj_desc);
403 if (ACPI_FAILURE(status)) {
404 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 }
406 }
407
408 if (read_write == ACPI_READ) {
409 /*
410 * Copy the data from the source buffer.
411 * Length is the field width in bytes.
412 */
Len Brown4be44fc2005-08-05 00:44:28 -0400413 ACPI_MEMCPY(value,
414 (obj_desc->buffer_field.buffer_obj)->buffer.
415 pointer +
416 obj_desc->buffer_field.base_byte_offset +
417 field_datum_byte_offset,
418 obj_desc->common_field.access_byte_width);
419 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 /*
421 * Copy the data to the target buffer.
422 * Length is the field width in bytes.
423 */
Len Brown4be44fc2005-08-05 00:44:28 -0400424 ACPI_MEMCPY((obj_desc->buffer_field.buffer_obj)->buffer.
425 pointer +
426 obj_desc->buffer_field.base_byte_offset +
427 field_datum_byte_offset, value,
428 obj_desc->common_field.access_byte_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
430
431 status = AE_OK;
432 break;
433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 case ACPI_TYPE_LOCAL_BANK_FIELD:
435
Robert Moore44f6c012005-04-18 22:49:35 -0400436 /*
437 * Ensure that the bank_value is not beyond the capacity of
438 * the register
439 */
Len Brown4be44fc2005-08-05 00:44:28 -0400440 if (acpi_ex_register_overflow(obj_desc->bank_field.bank_obj,
441 (acpi_integer) obj_desc->
442 bank_field.value)) {
443 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 }
445
446 /*
447 * For bank_fields, we must write the bank_value to the bank_register
448 * (itself a region_field) before we can access the data.
449 */
Len Brown4be44fc2005-08-05 00:44:28 -0400450 status =
451 acpi_ex_insert_into_field(obj_desc->bank_field.bank_obj,
452 &obj_desc->bank_field.value,
453 sizeof(obj_desc->bank_field.
454 value));
455 if (ACPI_FAILURE(status)) {
456 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458
459 /*
460 * Now that the Bank has been selected, fall through to the
461 * region_field case and write the datum to the Operation Region
462 */
463
464 /*lint -fallthrough */
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 case ACPI_TYPE_LOCAL_REGION_FIELD:
467 /*
468 * For simple region_fields, we just directly access the owning
469 * Operation Region.
470 */
Len Brown4be44fc2005-08-05 00:44:28 -0400471 status =
472 acpi_ex_access_region(obj_desc, field_datum_byte_offset,
473 value, read_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 break;
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 case ACPI_TYPE_LOCAL_INDEX_FIELD:
477
Robert Moore44f6c012005-04-18 22:49:35 -0400478 /*
479 * Ensure that the index_value is not beyond the capacity of
480 * the register
481 */
Len Brown4be44fc2005-08-05 00:44:28 -0400482 if (acpi_ex_register_overflow(obj_desc->index_field.index_obj,
483 (acpi_integer) obj_desc->
484 index_field.value)) {
485 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
487
488 /* Write the index value to the index_register (itself a region_field) */
489
490 field_datum_byte_offset += obj_desc->index_field.value;
491
Len Brown4be44fc2005-08-05 00:44:28 -0400492 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
493 "Write to Index Register: Value %8.8X\n",
494 field_datum_byte_offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Len Brown4be44fc2005-08-05 00:44:28 -0400496 status =
497 acpi_ex_insert_into_field(obj_desc->index_field.index_obj,
498 &field_datum_byte_offset,
499 sizeof(field_datum_byte_offset));
500 if (ACPI_FAILURE(status)) {
501 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (read_write == ACPI_READ) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 /* Read the datum from the data_register */
507
Bob Mooree9a8c6a2008-11-12 15:16:49 +0800508 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
509 "Read from Data Register\n"));
510
Len Brown4be44fc2005-08-05 00:44:28 -0400511 status =
512 acpi_ex_extract_from_field(obj_desc->index_field.
513 data_obj, value,
514 sizeof(acpi_integer));
515 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 /* Write the datum to the data_register */
517
Bob Mooree9a8c6a2008-11-12 15:16:49 +0800518 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
519 "Write to Data Register: Value %8.8X%8.8X\n",
520 ACPI_FORMAT_UINT64(*value)));
521
Len Brown4be44fc2005-08-05 00:44:28 -0400522 status =
523 acpi_ex_insert_into_field(obj_desc->index_field.
524 data_obj, value,
525 sizeof(acpi_integer));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
527 break;
528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 default:
530
Bob Mooreb8e4d892006-01-27 16:43:00 -0500531 ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %X",
Bob Moore3371c192009-02-18 14:44:03 +0800532 obj_desc->common.type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 status = AE_AML_INTERNAL;
534 break;
535 }
536
Len Brown4be44fc2005-08-05 00:44:28 -0400537 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (read_write == ACPI_READ) {
Len Brown4be44fc2005-08-05 00:44:28 -0400539 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
540 "Value Read %8.8X%8.8X, Width %d\n",
541 ACPI_FORMAT_UINT64(*value),
542 obj_desc->common_field.
543 access_byte_width));
544 } else {
545 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
546 "Value Written %8.8X%8.8X, Width %d\n",
547 ACPI_FORMAT_UINT64(*value),
548 obj_desc->common_field.
549 access_byte_width));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 }
551 }
552
Len Brown4be44fc2005-08-05 00:44:28 -0400553 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556/*******************************************************************************
557 *
558 * FUNCTION: acpi_ex_write_with_update_rule
559 *
Robert Moore44f6c012005-04-18 22:49:35 -0400560 * PARAMETERS: obj_desc - Field to be written
561 * Mask - bitmask within field datum
562 * field_value - Value to write
563 * field_datum_byte_offset - Offset of datum within field
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 *
565 * RETURN: Status
566 *
567 * DESCRIPTION: Apply the field update rule to a field write
568 *
569 ******************************************************************************/
570
571acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400572acpi_ex_write_with_update_rule(union acpi_operand_object *obj_desc,
573 acpi_integer mask,
574 acpi_integer field_value,
575 u32 field_datum_byte_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Len Brown4be44fc2005-08-05 00:44:28 -0400577 acpi_status status = AE_OK;
578 acpi_integer merged_value;
579 acpi_integer current_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Bob Mooreb229cf92006-04-21 17:15:00 -0400581 ACPI_FUNCTION_TRACE_U32(ex_write_with_update_rule, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 /* Start with the new bits */
584
585 merged_value = field_value;
586
587 /* If the mask is all ones, we don't need to worry about the update rule */
588
589 if (mask != ACPI_INTEGER_MAX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 /* Decode the update rule */
592
Len Brown4be44fc2005-08-05 00:44:28 -0400593 switch (obj_desc->common_field.
594 field_flags & AML_FIELD_UPDATE_RULE_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 case AML_FIELD_UPDATE_PRESERVE:
596 /*
597 * Check if update rule needs to be applied (not if mask is all
598 * ones) The left shift drops the bits we want to ignore.
599 */
Len Brown4be44fc2005-08-05 00:44:28 -0400600 if ((~mask << (ACPI_MUL_8(sizeof(mask)) -
601 ACPI_MUL_8(obj_desc->common_field.
602 access_byte_width))) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 /*
604 * Read the current contents of the byte/word/dword containing
605 * the field, and merge with the new field value.
606 */
Len Brown4be44fc2005-08-05 00:44:28 -0400607 status =
608 acpi_ex_field_datum_io(obj_desc,
609 field_datum_byte_offset,
610 &current_value,
611 ACPI_READ);
612 if (ACPI_FAILURE(status)) {
613 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
615
616 merged_value |= (current_value & ~mask);
617 }
618 break;
619
620 case AML_FIELD_UPDATE_WRITE_AS_ONES:
621
622 /* Set positions outside the field to all ones */
623
624 merged_value |= ~mask;
625 break;
626
627 case AML_FIELD_UPDATE_WRITE_AS_ZEROS:
628
629 /* Set positions outside the field to all zeros */
630
631 merged_value &= mask;
632 break;
633
634 default:
635
Bob Mooreb8e4d892006-01-27 16:43:00 -0500636 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400637 "Unknown UpdateRule value: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500638 (obj_desc->common_field.
639 field_flags &
640 AML_FIELD_UPDATE_RULE_MASK)));
Len Brown4be44fc2005-08-05 00:44:28 -0400641 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643 }
644
Len Brown4be44fc2005-08-05 00:44:28 -0400645 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
Bob Mooreb229cf92006-04-21 17:15:00 -0400646 "Mask %8.8X%8.8X, DatumOffset %X, Width %X, Value %8.8X%8.8X, MergedValue %8.8X%8.8X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400647 ACPI_FORMAT_UINT64(mask),
648 field_datum_byte_offset,
649 obj_desc->common_field.access_byte_width,
650 ACPI_FORMAT_UINT64(field_value),
651 ACPI_FORMAT_UINT64(merged_value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 /* Write the merged value */
654
Len Brown4be44fc2005-08-05 00:44:28 -0400655 status = acpi_ex_field_datum_io(obj_desc, field_datum_byte_offset,
656 &merged_value, ACPI_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Len Brown4be44fc2005-08-05 00:44:28 -0400658 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659}
660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661/*******************************************************************************
662 *
663 * FUNCTION: acpi_ex_extract_from_field
664 *
665 * PARAMETERS: obj_desc - Field to be read
666 * Buffer - Where to store the field data
667 * buffer_length - Length of Buffer
668 *
669 * RETURN: Status
670 *
671 * DESCRIPTION: Retrieve the current value of the given field
672 *
673 ******************************************************************************/
674
675acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400676acpi_ex_extract_from_field(union acpi_operand_object *obj_desc,
677 void *buffer, u32 buffer_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
Len Brown4be44fc2005-08-05 00:44:28 -0400679 acpi_status status;
680 acpi_integer raw_datum;
681 acpi_integer merged_datum;
682 u32 field_offset = 0;
683 u32 buffer_offset = 0;
684 u32 buffer_tail_bits;
685 u32 datum_count;
686 u32 field_datum_count;
687 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Bob Mooreb229cf92006-04-21 17:15:00 -0400689 ACPI_FUNCTION_TRACE(ex_extract_from_field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 /* Validate target buffer and clear it */
692
Len Brown4be44fc2005-08-05 00:44:28 -0400693 if (buffer_length <
694 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500695 ACPI_ERROR((AE_INFO,
696 "Field size %X (bits) is too large for buffer (%X)",
697 obj_desc->common_field.bit_length, buffer_length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Len Brown4be44fc2005-08-05 00:44:28 -0400699 return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
Len Brown4be44fc2005-08-05 00:44:28 -0400701 ACPI_MEMSET(buffer, 0, buffer_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 /* Compute the number of datums (access width data items) */
704
Len Brown4be44fc2005-08-05 00:44:28 -0400705 datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
706 obj_desc->common_field.access_bit_width);
707 field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
708 obj_desc->common_field.
709 start_field_bit_offset,
710 obj_desc->common_field.
711 access_bit_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 /* Priming read from the field */
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715 status =
716 acpi_ex_field_datum_io(obj_desc, field_offset, &raw_datum,
717 ACPI_READ);
718 if (ACPI_FAILURE(status)) {
719 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
Len Brown4be44fc2005-08-05 00:44:28 -0400721 merged_datum =
722 raw_datum >> obj_desc->common_field.start_field_bit_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 /* Read the rest of the field */
725
726 for (i = 1; i < field_datum_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 /* Get next input datum from the field */
729
730 field_offset += obj_desc->common_field.access_byte_width;
Len Brown4be44fc2005-08-05 00:44:28 -0400731 status = acpi_ex_field_datum_io(obj_desc, field_offset,
732 &raw_datum, ACPI_READ);
733 if (ACPI_FAILURE(status)) {
734 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 }
736
Bob Moore967440e2006-06-23 17:04:00 -0400737 /*
738 * Merge with previous datum if necessary.
739 *
740 * Note: Before the shift, check if the shift value will be larger than
741 * the integer size. If so, there is no need to perform the operation.
742 * This avoids the differences in behavior between different compilers
743 * concerning shift values larger than the target data width.
744 */
745 if ((obj_desc->common_field.access_bit_width -
746 obj_desc->common_field.start_field_bit_offset) <
747 ACPI_INTEGER_BIT_SIZE) {
748 merged_datum |=
749 raw_datum << (obj_desc->common_field.
750 access_bit_width -
751 obj_desc->common_field.
752 start_field_bit_offset);
753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 if (i == datum_count) {
756 break;
757 }
758
759 /* Write merged datum to target buffer */
760
Len Brown4be44fc2005-08-05 00:44:28 -0400761 ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum,
762 ACPI_MIN(obj_desc->common_field.access_byte_width,
763 buffer_length - buffer_offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 buffer_offset += obj_desc->common_field.access_byte_width;
Len Brown4be44fc2005-08-05 00:44:28 -0400766 merged_datum =
767 raw_datum >> obj_desc->common_field.start_field_bit_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 }
769
770 /* Mask off any extra bits in the last datum */
771
Robert Moore44f6c012005-04-18 22:49:35 -0400772 buffer_tail_bits = obj_desc->common_field.bit_length %
Len Brown4be44fc2005-08-05 00:44:28 -0400773 obj_desc->common_field.access_bit_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 if (buffer_tail_bits) {
Len Brown4be44fc2005-08-05 00:44:28 -0400775 merged_datum &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 }
777
778 /* Write the last datum to the buffer */
779
Len Brown4be44fc2005-08-05 00:44:28 -0400780 ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum,
781 ACPI_MIN(obj_desc->common_field.access_byte_width,
782 buffer_length - buffer_offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Len Brown4be44fc2005-08-05 00:44:28 -0400784 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787/*******************************************************************************
788 *
789 * FUNCTION: acpi_ex_insert_into_field
790 *
791 * PARAMETERS: obj_desc - Field to be written
792 * Buffer - Data to be written
793 * buffer_length - Length of Buffer
794 *
795 * RETURN: Status
796 *
797 * DESCRIPTION: Store the Buffer contents into the given field
798 *
799 ******************************************************************************/
800
801acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400802acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
803 void *buffer, u32 buffer_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
Len Brown4be44fc2005-08-05 00:44:28 -0400805 acpi_status status;
806 acpi_integer mask;
Bob Moore4c90ece2006-06-08 16:29:00 -0400807 acpi_integer width_mask;
Len Brown4be44fc2005-08-05 00:44:28 -0400808 acpi_integer merged_datum;
809 acpi_integer raw_datum = 0;
810 u32 field_offset = 0;
811 u32 buffer_offset = 0;
812 u32 buffer_tail_bits;
813 u32 datum_count;
814 u32 field_datum_count;
815 u32 i;
Bob Moore9aa61692008-04-10 19:06:41 +0400816 u32 required_length;
817 void *new_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Bob Mooreb229cf92006-04-21 17:15:00 -0400819 ACPI_FUNCTION_TRACE(ex_insert_into_field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821 /* Validate input buffer */
822
Bob Moore9aa61692008-04-10 19:06:41 +0400823 new_buffer = NULL;
824 required_length =
825 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length);
826 /*
827 * We must have a buffer that is at least as long as the field
828 * we are writing to. This is because individual fields are
829 * indivisible and partial writes are not supported -- as per
830 * the ACPI specification.
831 */
832 if (buffer_length < required_length) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Bob Moore9aa61692008-04-10 19:06:41 +0400834 /* We need to create a new buffer */
835
836 new_buffer = ACPI_ALLOCATE_ZEROED(required_length);
837 if (!new_buffer) {
838 return_ACPI_STATUS(AE_NO_MEMORY);
839 }
840
841 /*
842 * Copy the original data to the new buffer, starting
843 * at Byte zero. All unused (upper) bytes of the
844 * buffer will be 0.
845 */
846 ACPI_MEMCPY((char *)new_buffer, (char *)buffer, buffer_length);
847 buffer = new_buffer;
848 buffer_length = required_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850
Bob Moore967440e2006-06-23 17:04:00 -0400851 /*
852 * Create the bitmasks used for bit insertion.
853 * Note: This if/else is used to bypass compiler differences with the
854 * shift operator
855 */
856 if (obj_desc->common_field.access_bit_width == ACPI_INTEGER_BIT_SIZE) {
857 width_mask = ACPI_INTEGER_MAX;
858 } else {
859 width_mask =
860 ACPI_MASK_BITS_ABOVE(obj_desc->common_field.
861 access_bit_width);
862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Bob Moore967440e2006-06-23 17:04:00 -0400864 mask = width_mask &
865 ACPI_MASK_BITS_BELOW(obj_desc->common_field.start_field_bit_offset);
866
867 /* Compute the number of datums (access width data items) */
Bob Moore41195322006-05-26 16:36:00 -0400868
869 datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
870 obj_desc->common_field.access_bit_width);
871
872 field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
873 obj_desc->common_field.
874 start_field_bit_offset,
875 obj_desc->common_field.
876 access_bit_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 /* Get initial Datum from the input buffer */
879
Len Brown4be44fc2005-08-05 00:44:28 -0400880 ACPI_MEMCPY(&raw_datum, buffer,
881 ACPI_MIN(obj_desc->common_field.access_byte_width,
882 buffer_length - buffer_offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Len Brown4be44fc2005-08-05 00:44:28 -0400884 merged_datum =
885 raw_datum << obj_desc->common_field.start_field_bit_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 /* Write the entire field */
888
889 for (i = 1; i < field_datum_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 /* Write merged datum to the target field */
892
893 merged_datum &= mask;
Len Brown4be44fc2005-08-05 00:44:28 -0400894 status = acpi_ex_write_with_update_rule(obj_desc, mask,
895 merged_datum,
896 field_offset);
897 if (ACPI_FAILURE(status)) {
Bob Moore9aa61692008-04-10 19:06:41 +0400898 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 }
900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 field_offset += obj_desc->common_field.access_byte_width;
Bob Moore967440e2006-06-23 17:04:00 -0400902
903 /*
904 * Start new output datum by merging with previous input datum
905 * if necessary.
906 *
907 * Note: Before the shift, check if the shift value will be larger than
908 * the integer size. If so, there is no need to perform the operation.
909 * This avoids the differences in behavior between different compilers
910 * concerning shift values larger than the target data width.
911 */
912 if ((obj_desc->common_field.access_bit_width -
913 obj_desc->common_field.start_field_bit_offset) <
914 ACPI_INTEGER_BIT_SIZE) {
915 merged_datum =
916 raw_datum >> (obj_desc->common_field.
917 access_bit_width -
918 obj_desc->common_field.
919 start_field_bit_offset);
920 } else {
921 merged_datum = 0;
922 }
923
Bob Moore4c90ece2006-06-08 16:29:00 -0400924 mask = width_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 if (i == datum_count) {
927 break;
928 }
929
930 /* Get the next input datum from the buffer */
931
932 buffer_offset += obj_desc->common_field.access_byte_width;
Len Brown4be44fc2005-08-05 00:44:28 -0400933 ACPI_MEMCPY(&raw_datum, ((char *)buffer) + buffer_offset,
934 ACPI_MIN(obj_desc->common_field.access_byte_width,
935 buffer_length - buffer_offset));
936 merged_datum |=
937 raw_datum << obj_desc->common_field.start_field_bit_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 }
939
940 /* Mask off any extra bits in the last datum */
941
942 buffer_tail_bits = (obj_desc->common_field.bit_length +
Len Brown4be44fc2005-08-05 00:44:28 -0400943 obj_desc->common_field.start_field_bit_offset) %
944 obj_desc->common_field.access_bit_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 if (buffer_tail_bits) {
Len Brown4be44fc2005-08-05 00:44:28 -0400946 mask &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948
949 /* Write the last datum to the field */
950
951 merged_datum &= mask;
Len Brown4be44fc2005-08-05 00:44:28 -0400952 status = acpi_ex_write_with_update_rule(obj_desc,
953 mask, merged_datum,
954 field_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Bob Moore9aa61692008-04-10 19:06:41 +0400956 exit:
957 /* Free temporary buffer if we used one */
958
959 if (new_buffer) {
960 ACPI_FREE(new_buffer);
961 }
Len Brown4be44fc2005-08-05 00:44:28 -0400962 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}