blob: ef58ac4e687b8bd8f0e170647e0d2afe12abc525 [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
Len Brown4be44fc2005-08-05 00:44:28 -040097 if (ACPI_GET_OBJECT_TYPE(rgn_desc) != ACPI_TYPE_REGION) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050098 ACPI_ERROR((AE_INFO, "Needed Region, found type %X (%s)",
99 ACPI_GET_OBJECT_TYPE(rgn_desc),
100 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
Bob Mooreb229cf92006-04-21 17:15:00 -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
122 /*
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;
231 acpi_physical_address address;
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;
Robert Moore44f6c012005-04-18 22:49:35 -0400252 address = rgn_desc->region.address +
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,
269 address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 /* Invoke the appropriate address_space/op_region handler */
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 status = acpi_ev_address_space_dispatch(rgn_desc, function,
274 address,
275 ACPI_MUL_8(obj_desc->
276 common_field.
277 access_byte_width),
278 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Len Brown4be44fc2005-08-05 00:44:28 -0400280 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 if (status == AE_NOT_IMPLEMENTED) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500282 ACPI_ERROR((AE_INFO,
283 "Region %s(%X) not implemented",
284 acpi_ut_get_region_name(rgn_desc->region.
285 space_id),
286 rgn_desc->region.space_id));
Len Brown4be44fc2005-08-05 00:44:28 -0400287 } else if (status == AE_NOT_EXIST) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500288 ACPI_ERROR((AE_INFO,
289 "Region %s(%X) has no handler",
290 acpi_ut_get_region_name(rgn_desc->region.
291 space_id),
292 rgn_desc->region.space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
294 }
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299/*******************************************************************************
300 *
301 * FUNCTION: acpi_ex_register_overflow
302 *
Robert Moore44f6c012005-04-18 22:49:35 -0400303 * PARAMETERS: obj_desc - Register(Field) to be written
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 * Value - Value to be stored
305 *
306 * RETURN: TRUE if value overflows the field, FALSE otherwise
307 *
308 * DESCRIPTION: Check if a value is out of range of the field being written.
309 * Used to check if the values written to Index and Bank registers
310 * are out of range. Normally, the value is simply truncated
311 * to fit the field, but this case is most likely a serious
312 * coding error in the ASL.
313 *
314 ******************************************************************************/
315
Robert Moore44f6c012005-04-18 22:49:35 -0400316static u8
Len Brown4be44fc2005-08-05 00:44:28 -0400317acpi_ex_register_overflow(union acpi_operand_object *obj_desc,
318 acpi_integer value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
320
321 if (obj_desc->common_field.bit_length >= ACPI_INTEGER_BIT_SIZE) {
322 /*
323 * The field is large enough to hold the maximum integer, so we can
324 * never overflow it.
325 */
326 return (FALSE);
327 }
328
329 if (value >= ((acpi_integer) 1 << obj_desc->common_field.bit_length)) {
330 /*
331 * The Value is larger than the maximum value that can fit into
332 * the register.
333 */
334 return (TRUE);
335 }
336
337 /* The Value will fit into the field with no truncation */
338
339 return (FALSE);
340}
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342/*******************************************************************************
343 *
344 * FUNCTION: acpi_ex_field_datum_io
345 *
Robert Moore44f6c012005-04-18 22:49:35 -0400346 * PARAMETERS: obj_desc - Field to be read
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 * field_datum_byte_offset - Byte offset of this datum within the
348 * parent field
Robert Moore44f6c012005-04-18 22:49:35 -0400349 * Value - Where to store value (must be 64 bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 * read_write - Read or Write flag
351 *
352 * RETURN: Status
353 *
354 * DESCRIPTION: Read or Write a single datum of a field. The field_type is
355 * demultiplexed here to handle the different types of fields
356 * (buffer_field, region_field, index_field, bank_field)
357 *
358 ******************************************************************************/
359
Robert Moore44f6c012005-04-18 22:49:35 -0400360static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400361acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
362 u32 field_datum_byte_offset,
363 acpi_integer * value, u32 read_write)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Len Brown4be44fc2005-08-05 00:44:28 -0400365 acpi_status status;
366 acpi_integer local_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Bob Mooreb229cf92006-04-21 17:15:00 -0400368 ACPI_FUNCTION_TRACE_U32(ex_field_datum_io, field_datum_byte_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 if (read_write == ACPI_READ) {
371 if (!value) {
372 local_value = 0;
Robert Moore44f6c012005-04-18 22:49:35 -0400373
374 /* To support reads without saving return value */
375 value = &local_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377
378 /* Clear the entire return buffer first, [Very Important!] */
379
380 *value = 0;
381 }
382
383 /*
384 * The four types of fields are:
385 *
386 * buffer_field - Read/write from/to a Buffer
387 * region_field - Read/write from/to a Operation Region.
Robert Moore44f6c012005-04-18 22:49:35 -0400388 * bank_field - Write to a Bank Register, then read/write from/to an
389 * operation_region
390 * index_field - Write to an Index Register, then read/write from/to a
391 * Data Register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 */
Len Brown4be44fc2005-08-05 00:44:28 -0400393 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 case ACPI_TYPE_BUFFER_FIELD:
395 /*
396 * If the buffer_field arguments have not been previously evaluated,
397 * evaluate them now and save the results.
398 */
399 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400400 status = acpi_ds_get_buffer_field_arguments(obj_desc);
401 if (ACPI_FAILURE(status)) {
402 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404 }
405
406 if (read_write == ACPI_READ) {
407 /*
408 * Copy the data from the source buffer.
409 * Length is the field width in bytes.
410 */
Len Brown4be44fc2005-08-05 00:44:28 -0400411 ACPI_MEMCPY(value,
412 (obj_desc->buffer_field.buffer_obj)->buffer.
413 pointer +
414 obj_desc->buffer_field.base_byte_offset +
415 field_datum_byte_offset,
416 obj_desc->common_field.access_byte_width);
417 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /*
419 * Copy the data to the target buffer.
420 * Length is the field width in bytes.
421 */
Len Brown4be44fc2005-08-05 00:44:28 -0400422 ACPI_MEMCPY((obj_desc->buffer_field.buffer_obj)->buffer.
423 pointer +
424 obj_desc->buffer_field.base_byte_offset +
425 field_datum_byte_offset, value,
426 obj_desc->common_field.access_byte_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
428
429 status = AE_OK;
430 break;
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 case ACPI_TYPE_LOCAL_BANK_FIELD:
433
Robert Moore44f6c012005-04-18 22:49:35 -0400434 /*
435 * Ensure that the bank_value is not beyond the capacity of
436 * the register
437 */
Len Brown4be44fc2005-08-05 00:44:28 -0400438 if (acpi_ex_register_overflow(obj_desc->bank_field.bank_obj,
439 (acpi_integer) obj_desc->
440 bank_field.value)) {
441 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 }
443
444 /*
445 * For bank_fields, we must write the bank_value to the bank_register
446 * (itself a region_field) before we can access the data.
447 */
Len Brown4be44fc2005-08-05 00:44:28 -0400448 status =
449 acpi_ex_insert_into_field(obj_desc->bank_field.bank_obj,
450 &obj_desc->bank_field.value,
451 sizeof(obj_desc->bank_field.
452 value));
453 if (ACPI_FAILURE(status)) {
454 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456
457 /*
458 * Now that the Bank has been selected, fall through to the
459 * region_field case and write the datum to the Operation Region
460 */
461
462 /*lint -fallthrough */
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 case ACPI_TYPE_LOCAL_REGION_FIELD:
465 /*
466 * For simple region_fields, we just directly access the owning
467 * Operation Region.
468 */
Len Brown4be44fc2005-08-05 00:44:28 -0400469 status =
470 acpi_ex_access_region(obj_desc, field_datum_byte_offset,
471 value, read_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 break;
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 case ACPI_TYPE_LOCAL_INDEX_FIELD:
475
Robert Moore44f6c012005-04-18 22:49:35 -0400476 /*
477 * Ensure that the index_value is not beyond the capacity of
478 * the register
479 */
Len Brown4be44fc2005-08-05 00:44:28 -0400480 if (acpi_ex_register_overflow(obj_desc->index_field.index_obj,
481 (acpi_integer) obj_desc->
482 index_field.value)) {
483 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 }
485
486 /* Write the index value to the index_register (itself a region_field) */
487
488 field_datum_byte_offset += obj_desc->index_field.value;
489
Len Brown4be44fc2005-08-05 00:44:28 -0400490 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
491 "Write to Index Register: Value %8.8X\n",
492 field_datum_byte_offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Len Brown4be44fc2005-08-05 00:44:28 -0400494 status =
495 acpi_ex_insert_into_field(obj_desc->index_field.index_obj,
496 &field_datum_byte_offset,
497 sizeof(field_datum_byte_offset));
498 if (ACPI_FAILURE(status)) {
499 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (read_write == ACPI_READ) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 /* Read the datum from the data_register */
505
Bob Mooree9a8c6a2008-11-12 15:16:49 +0800506 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
507 "Read from Data Register\n"));
508
Len Brown4be44fc2005-08-05 00:44:28 -0400509 status =
510 acpi_ex_extract_from_field(obj_desc->index_field.
511 data_obj, value,
512 sizeof(acpi_integer));
513 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 /* Write the datum to the data_register */
515
Bob Mooree9a8c6a2008-11-12 15:16:49 +0800516 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
517 "Write to Data Register: Value %8.8X%8.8X\n",
518 ACPI_FORMAT_UINT64(*value)));
519
Len Brown4be44fc2005-08-05 00:44:28 -0400520 status =
521 acpi_ex_insert_into_field(obj_desc->index_field.
522 data_obj, value,
523 sizeof(acpi_integer));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 }
525 break;
526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 default:
528
Bob Mooreb8e4d892006-01-27 16:43:00 -0500529 ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %X",
530 ACPI_GET_OBJECT_TYPE(obj_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 status = AE_AML_INTERNAL;
532 break;
533 }
534
Len Brown4be44fc2005-08-05 00:44:28 -0400535 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (read_write == ACPI_READ) {
Len Brown4be44fc2005-08-05 00:44:28 -0400537 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
538 "Value Read %8.8X%8.8X, Width %d\n",
539 ACPI_FORMAT_UINT64(*value),
540 obj_desc->common_field.
541 access_byte_width));
542 } else {
543 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
544 "Value Written %8.8X%8.8X, Width %d\n",
545 ACPI_FORMAT_UINT64(*value),
546 obj_desc->common_field.
547 access_byte_width));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549 }
550
Len Brown4be44fc2005-08-05 00:44:28 -0400551 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552}
553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554/*******************************************************************************
555 *
556 * FUNCTION: acpi_ex_write_with_update_rule
557 *
Robert Moore44f6c012005-04-18 22:49:35 -0400558 * PARAMETERS: obj_desc - Field to be written
559 * Mask - bitmask within field datum
560 * field_value - Value to write
561 * field_datum_byte_offset - Offset of datum within field
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 *
563 * RETURN: Status
564 *
565 * DESCRIPTION: Apply the field update rule to a field write
566 *
567 ******************************************************************************/
568
569acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400570acpi_ex_write_with_update_rule(union acpi_operand_object *obj_desc,
571 acpi_integer mask,
572 acpi_integer field_value,
573 u32 field_datum_byte_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
Len Brown4be44fc2005-08-05 00:44:28 -0400575 acpi_status status = AE_OK;
576 acpi_integer merged_value;
577 acpi_integer current_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Bob Mooreb229cf92006-04-21 17:15:00 -0400579 ACPI_FUNCTION_TRACE_U32(ex_write_with_update_rule, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 /* Start with the new bits */
582
583 merged_value = field_value;
584
585 /* If the mask is all ones, we don't need to worry about the update rule */
586
587 if (mask != ACPI_INTEGER_MAX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 /* Decode the update rule */
590
Len Brown4be44fc2005-08-05 00:44:28 -0400591 switch (obj_desc->common_field.
592 field_flags & AML_FIELD_UPDATE_RULE_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 case AML_FIELD_UPDATE_PRESERVE:
594 /*
595 * Check if update rule needs to be applied (not if mask is all
596 * ones) The left shift drops the bits we want to ignore.
597 */
Len Brown4be44fc2005-08-05 00:44:28 -0400598 if ((~mask << (ACPI_MUL_8(sizeof(mask)) -
599 ACPI_MUL_8(obj_desc->common_field.
600 access_byte_width))) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 /*
602 * Read the current contents of the byte/word/dword containing
603 * the field, and merge with the new field value.
604 */
Len Brown4be44fc2005-08-05 00:44:28 -0400605 status =
606 acpi_ex_field_datum_io(obj_desc,
607 field_datum_byte_offset,
608 &current_value,
609 ACPI_READ);
610 if (ACPI_FAILURE(status)) {
611 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 }
613
614 merged_value |= (current_value & ~mask);
615 }
616 break;
617
618 case AML_FIELD_UPDATE_WRITE_AS_ONES:
619
620 /* Set positions outside the field to all ones */
621
622 merged_value |= ~mask;
623 break;
624
625 case AML_FIELD_UPDATE_WRITE_AS_ZEROS:
626
627 /* Set positions outside the field to all zeros */
628
629 merged_value &= mask;
630 break;
631
632 default:
633
Bob Mooreb8e4d892006-01-27 16:43:00 -0500634 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400635 "Unknown UpdateRule value: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500636 (obj_desc->common_field.
637 field_flags &
638 AML_FIELD_UPDATE_RULE_MASK)));
Len Brown4be44fc2005-08-05 00:44:28 -0400639 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641 }
642
Len Brown4be44fc2005-08-05 00:44:28 -0400643 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
Bob Mooreb229cf92006-04-21 17:15:00 -0400644 "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 -0400645 ACPI_FORMAT_UINT64(mask),
646 field_datum_byte_offset,
647 obj_desc->common_field.access_byte_width,
648 ACPI_FORMAT_UINT64(field_value),
649 ACPI_FORMAT_UINT64(merged_value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 /* Write the merged value */
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653 status = acpi_ex_field_datum_io(obj_desc, field_datum_byte_offset,
654 &merged_value, ACPI_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Len Brown4be44fc2005-08-05 00:44:28 -0400656 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659/*******************************************************************************
660 *
661 * FUNCTION: acpi_ex_extract_from_field
662 *
663 * PARAMETERS: obj_desc - Field to be read
664 * Buffer - Where to store the field data
665 * buffer_length - Length of Buffer
666 *
667 * RETURN: Status
668 *
669 * DESCRIPTION: Retrieve the current value of the given field
670 *
671 ******************************************************************************/
672
673acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400674acpi_ex_extract_from_field(union acpi_operand_object *obj_desc,
675 void *buffer, u32 buffer_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Len Brown4be44fc2005-08-05 00:44:28 -0400677 acpi_status status;
678 acpi_integer raw_datum;
679 acpi_integer merged_datum;
680 u32 field_offset = 0;
681 u32 buffer_offset = 0;
682 u32 buffer_tail_bits;
683 u32 datum_count;
684 u32 field_datum_count;
685 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Bob Mooreb229cf92006-04-21 17:15:00 -0400687 ACPI_FUNCTION_TRACE(ex_extract_from_field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
689 /* Validate target buffer and clear it */
690
Len Brown4be44fc2005-08-05 00:44:28 -0400691 if (buffer_length <
692 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500693 ACPI_ERROR((AE_INFO,
694 "Field size %X (bits) is too large for buffer (%X)",
695 obj_desc->common_field.bit_length, buffer_length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 }
Len Brown4be44fc2005-08-05 00:44:28 -0400699 ACPI_MEMSET(buffer, 0, buffer_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701 /* Compute the number of datums (access width data items) */
702
Len Brown4be44fc2005-08-05 00:44:28 -0400703 datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
704 obj_desc->common_field.access_bit_width);
705 field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
706 obj_desc->common_field.
707 start_field_bit_offset,
708 obj_desc->common_field.
709 access_bit_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711 /* Priming read from the field */
712
Len Brown4be44fc2005-08-05 00:44:28 -0400713 status =
714 acpi_ex_field_datum_io(obj_desc, field_offset, &raw_datum,
715 ACPI_READ);
716 if (ACPI_FAILURE(status)) {
717 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 }
Len Brown4be44fc2005-08-05 00:44:28 -0400719 merged_datum =
720 raw_datum >> obj_desc->common_field.start_field_bit_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 /* Read the rest of the field */
723
724 for (i = 1; i < field_datum_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 /* Get next input datum from the field */
727
728 field_offset += obj_desc->common_field.access_byte_width;
Len Brown4be44fc2005-08-05 00:44:28 -0400729 status = acpi_ex_field_datum_io(obj_desc, field_offset,
730 &raw_datum, ACPI_READ);
731 if (ACPI_FAILURE(status)) {
732 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 }
734
Bob Moore967440e32006-06-23 17:04:00 -0400735 /*
736 * Merge with previous datum if necessary.
737 *
738 * Note: Before the shift, check if the shift value will be larger than
739 * the integer size. If so, there is no need to perform the operation.
740 * This avoids the differences in behavior between different compilers
741 * concerning shift values larger than the target data width.
742 */
743 if ((obj_desc->common_field.access_bit_width -
744 obj_desc->common_field.start_field_bit_offset) <
745 ACPI_INTEGER_BIT_SIZE) {
746 merged_datum |=
747 raw_datum << (obj_desc->common_field.
748 access_bit_width -
749 obj_desc->common_field.
750 start_field_bit_offset);
751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 if (i == datum_count) {
754 break;
755 }
756
757 /* Write merged datum to target buffer */
758
Len Brown4be44fc2005-08-05 00:44:28 -0400759 ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum,
760 ACPI_MIN(obj_desc->common_field.access_byte_width,
761 buffer_length - buffer_offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 buffer_offset += obj_desc->common_field.access_byte_width;
Len Brown4be44fc2005-08-05 00:44:28 -0400764 merged_datum =
765 raw_datum >> obj_desc->common_field.start_field_bit_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 }
767
768 /* Mask off any extra bits in the last datum */
769
Robert Moore44f6c012005-04-18 22:49:35 -0400770 buffer_tail_bits = obj_desc->common_field.bit_length %
Len Brown4be44fc2005-08-05 00:44:28 -0400771 obj_desc->common_field.access_bit_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 if (buffer_tail_bits) {
Len Brown4be44fc2005-08-05 00:44:28 -0400773 merged_datum &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
775
776 /* Write the last datum to the buffer */
777
Len Brown4be44fc2005-08-05 00:44:28 -0400778 ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum,
779 ACPI_MIN(obj_desc->common_field.access_byte_width,
780 buffer_length - buffer_offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Len Brown4be44fc2005-08-05 00:44:28 -0400782 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783}
784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785/*******************************************************************************
786 *
787 * FUNCTION: acpi_ex_insert_into_field
788 *
789 * PARAMETERS: obj_desc - Field to be written
790 * Buffer - Data to be written
791 * buffer_length - Length of Buffer
792 *
793 * RETURN: Status
794 *
795 * DESCRIPTION: Store the Buffer contents into the given field
796 *
797 ******************************************************************************/
798
799acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400800acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
801 void *buffer, u32 buffer_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
Len Brown4be44fc2005-08-05 00:44:28 -0400803 acpi_status status;
804 acpi_integer mask;
Bob Moore4c90ece2006-06-08 16:29:00 -0400805 acpi_integer width_mask;
Len Brown4be44fc2005-08-05 00:44:28 -0400806 acpi_integer merged_datum;
807 acpi_integer raw_datum = 0;
808 u32 field_offset = 0;
809 u32 buffer_offset = 0;
810 u32 buffer_tail_bits;
811 u32 datum_count;
812 u32 field_datum_count;
813 u32 i;
Bob Moore9aa61692008-04-10 19:06:41 +0400814 u32 required_length;
815 void *new_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Bob Mooreb229cf92006-04-21 17:15:00 -0400817 ACPI_FUNCTION_TRACE(ex_insert_into_field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 /* Validate input buffer */
820
Bob Moore9aa61692008-04-10 19:06:41 +0400821 new_buffer = NULL;
822 required_length =
823 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length);
824 /*
825 * We must have a buffer that is at least as long as the field
826 * we are writing to. This is because individual fields are
827 * indivisible and partial writes are not supported -- as per
828 * the ACPI specification.
829 */
830 if (buffer_length < required_length) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Bob Moore9aa61692008-04-10 19:06:41 +0400832 /* We need to create a new buffer */
833
834 new_buffer = ACPI_ALLOCATE_ZEROED(required_length);
835 if (!new_buffer) {
836 return_ACPI_STATUS(AE_NO_MEMORY);
837 }
838
839 /*
840 * Copy the original data to the new buffer, starting
841 * at Byte zero. All unused (upper) bytes of the
842 * buffer will be 0.
843 */
844 ACPI_MEMCPY((char *)new_buffer, (char *)buffer, buffer_length);
845 buffer = new_buffer;
846 buffer_length = required_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
848
Bob Moore967440e32006-06-23 17:04:00 -0400849 /*
850 * Create the bitmasks used for bit insertion.
851 * Note: This if/else is used to bypass compiler differences with the
852 * shift operator
853 */
854 if (obj_desc->common_field.access_bit_width == ACPI_INTEGER_BIT_SIZE) {
855 width_mask = ACPI_INTEGER_MAX;
856 } else {
857 width_mask =
858 ACPI_MASK_BITS_ABOVE(obj_desc->common_field.
859 access_bit_width);
860 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Bob Moore967440e32006-06-23 17:04:00 -0400862 mask = width_mask &
863 ACPI_MASK_BITS_BELOW(obj_desc->common_field.start_field_bit_offset);
864
865 /* Compute the number of datums (access width data items) */
Bob Moore41195322006-05-26 16:36:00 -0400866
867 datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
868 obj_desc->common_field.access_bit_width);
869
870 field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
871 obj_desc->common_field.
872 start_field_bit_offset,
873 obj_desc->common_field.
874 access_bit_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 /* Get initial Datum from the input buffer */
877
Len Brown4be44fc2005-08-05 00:44:28 -0400878 ACPI_MEMCPY(&raw_datum, buffer,
879 ACPI_MIN(obj_desc->common_field.access_byte_width,
880 buffer_length - buffer_offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Len Brown4be44fc2005-08-05 00:44:28 -0400882 merged_datum =
883 raw_datum << obj_desc->common_field.start_field_bit_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
885 /* Write the entire field */
886
887 for (i = 1; i < field_datum_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 /* Write merged datum to the target field */
890
891 merged_datum &= mask;
Len Brown4be44fc2005-08-05 00:44:28 -0400892 status = acpi_ex_write_with_update_rule(obj_desc, mask,
893 merged_datum,
894 field_offset);
895 if (ACPI_FAILURE(status)) {
Bob Moore9aa61692008-04-10 19:06:41 +0400896 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 field_offset += obj_desc->common_field.access_byte_width;
Bob Moore967440e32006-06-23 17:04:00 -0400900
901 /*
902 * Start new output datum by merging with previous input datum
903 * if necessary.
904 *
905 * Note: Before the shift, check if the shift value will be larger than
906 * the integer size. If so, there is no need to perform the operation.
907 * This avoids the differences in behavior between different compilers
908 * concerning shift values larger than the target data width.
909 */
910 if ((obj_desc->common_field.access_bit_width -
911 obj_desc->common_field.start_field_bit_offset) <
912 ACPI_INTEGER_BIT_SIZE) {
913 merged_datum =
914 raw_datum >> (obj_desc->common_field.
915 access_bit_width -
916 obj_desc->common_field.
917 start_field_bit_offset);
918 } else {
919 merged_datum = 0;
920 }
921
Bob Moore4c90ece2006-06-08 16:29:00 -0400922 mask = width_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 if (i == datum_count) {
925 break;
926 }
927
928 /* Get the next input datum from the buffer */
929
930 buffer_offset += obj_desc->common_field.access_byte_width;
Len Brown4be44fc2005-08-05 00:44:28 -0400931 ACPI_MEMCPY(&raw_datum, ((char *)buffer) + buffer_offset,
932 ACPI_MIN(obj_desc->common_field.access_byte_width,
933 buffer_length - buffer_offset));
934 merged_datum |=
935 raw_datum << obj_desc->common_field.start_field_bit_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 }
937
938 /* Mask off any extra bits in the last datum */
939
940 buffer_tail_bits = (obj_desc->common_field.bit_length +
Len Brown4be44fc2005-08-05 00:44:28 -0400941 obj_desc->common_field.start_field_bit_offset) %
942 obj_desc->common_field.access_bit_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 if (buffer_tail_bits) {
Len Brown4be44fc2005-08-05 00:44:28 -0400944 mask &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 }
946
947 /* Write the last datum to the field */
948
949 merged_datum &= mask;
Len Brown4be44fc2005-08-05 00:44:28 -0400950 status = acpi_ex_write_with_update_rule(obj_desc,
951 mask, merged_datum,
952 field_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Bob Moore9aa61692008-04-10 19:06:41 +0400954 exit:
955 /* Free temporary buffer if we used one */
956
957 if (new_buffer) {
958 ACPI_FREE(new_buffer);
959 }
Len Brown4be44fc2005-08-05 00:44:28 -0400960 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961}