Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: exfldio - Aml Field I/O |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2005, R. Byron Moore |
| 9 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("exfldio") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 | /* Local prototypes */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 58 | |
| 59 | static u8 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 60 | acpi_ex_register_overflow(union acpi_operand_object *obj_desc, |
| 61 | acpi_integer value); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 62 | |
| 63 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 64 | acpi_ex_setup_region(union acpi_operand_object *obj_desc, |
| 65 | u32 field_datum_byte_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | /******************************************************************************* |
| 68 | * |
| 69 | * FUNCTION: acpi_ex_setup_region |
| 70 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 71 | * PARAMETERS: obj_desc - Field to be read or written |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | * field_datum_byte_offset - Byte offset of this datum within the |
| 73 | * parent field |
| 74 | * |
| 75 | * RETURN: Status |
| 76 | * |
| 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. |
| 80 | * |
| 81 | ******************************************************************************/ |
| 82 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 83 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | acpi_ex_setup_region(union acpi_operand_object *obj_desc, |
| 85 | u32 field_datum_byte_offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | acpi_status status = AE_OK; |
| 88 | union acpi_operand_object *rgn_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | ACPI_FUNCTION_TRACE_U32("ex_setup_region", field_datum_byte_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | rgn_desc = obj_desc->common_field.region_obj; |
| 93 | |
| 94 | /* We must have a valid region */ |
| 95 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | status = acpi_ds_get_region_arguments(rgn_desc); |
| 111 | if (ACPI_FAILURE(status)) { |
| 112 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | if (rgn_desc->region.space_id == ACPI_ADR_SPACE_SMBUS) { |
| 117 | /* SMBus has a non-linear address space */ |
| 118 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #ifdef ACPI_UNDER_DEVELOPMENT |
| 122 | /* |
| 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) |
| 125 | */ |
| 126 | if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | if (ACPI_FAILURE(status)) { |
| 128 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | /* |
| 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) |
| 137 | */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 138 | if (rgn_desc->region.length < (obj_desc->common_field.base_byte_offset + |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | field_datum_byte_offset + |
| 140 | obj_desc->common_field. |
| 141 | access_byte_width)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | if (acpi_gbl_enable_interpreter_slack) { |
| 143 | /* |
| 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. |
| 147 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | if (rgn_desc->region.length < |
| 159 | obj_desc->common_field.access_byte_width) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* |
| 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. |
| 164 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Offset rounded up to next multiple of field width |
| 179 | * exceeds region length, indicate an error |
| 180 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 191 | return_ACPI_STATUS(AE_AML_REGION_LIMIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | /******************************************************************************* |
| 198 | * |
| 199 | * FUNCTION: acpi_ex_access_region |
| 200 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 201 | * PARAMETERS: obj_desc - Field to be read |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | * field_datum_byte_offset - Byte offset of this datum within the |
| 203 | * parent field |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 204 | * Value - Where to store value (must at least |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | * the size of acpi_integer) |
| 206 | * Function - Read or Write flag plus other region- |
| 207 | * dependent flags |
| 208 | * |
| 209 | * RETURN: Status |
| 210 | * |
| 211 | * DESCRIPTION: Read or Write a single field datum to an Operation Region. |
| 212 | * |
| 213 | ******************************************************************************/ |
| 214 | |
| 215 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | acpi_ex_access_region(union acpi_operand_object *obj_desc, |
| 217 | u32 field_datum_byte_offset, |
| 218 | acpi_integer * value, u32 function) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | acpi_status status; |
| 221 | union acpi_operand_object *rgn_desc; |
| 222 | acpi_physical_address address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | ACPI_FUNCTION_TRACE("ex_access_region"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * Ensure that the region operands are fully evaluated and verify |
| 228 | * the validity of the request |
| 229 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | status = acpi_ex_setup_region(obj_desc, field_datum_byte_offset); |
| 231 | if (ACPI_FAILURE(status)) { |
| 232 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /* |
| 236 | * The physical address of this field datum is: |
| 237 | * |
| 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 |
| 241 | */ |
| 242 | rgn_desc = obj_desc->common_field.region_obj; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 243 | address = rgn_desc->region.address + |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | obj_desc->common_field.base_byte_offset + field_datum_byte_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | if ((function & ACPI_IO_MASK) == ACPI_READ) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 247 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[READ]")); |
| 248 | } else { |
| 249 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[WRITE]")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | /* Invoke the appropriate address_space/op_region handler */ |
| 263 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | if (status == AE_NOT_IMPLEMENTED) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /******************************************************************************* |
| 292 | * |
| 293 | * FUNCTION: acpi_ex_register_overflow |
| 294 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 295 | * PARAMETERS: obj_desc - Register(Field) to be written |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | * Value - Value to be stored |
| 297 | * |
| 298 | * RETURN: TRUE if value overflows the field, FALSE otherwise |
| 299 | * |
| 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. |
| 305 | * |
| 306 | ******************************************************************************/ |
| 307 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 308 | static u8 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | acpi_ex_register_overflow(union acpi_operand_object *obj_desc, |
| 310 | acpi_integer value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
| 312 | |
| 313 | if (obj_desc->common_field.bit_length >= ACPI_INTEGER_BIT_SIZE) { |
| 314 | /* |
| 315 | * The field is large enough to hold the maximum integer, so we can |
| 316 | * never overflow it. |
| 317 | */ |
| 318 | return (FALSE); |
| 319 | } |
| 320 | |
| 321 | if (value >= ((acpi_integer) 1 << obj_desc->common_field.bit_length)) { |
| 322 | /* |
| 323 | * The Value is larger than the maximum value that can fit into |
| 324 | * the register. |
| 325 | */ |
| 326 | return (TRUE); |
| 327 | } |
| 328 | |
| 329 | /* The Value will fit into the field with no truncation */ |
| 330 | |
| 331 | return (FALSE); |
| 332 | } |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /******************************************************************************* |
| 335 | * |
| 336 | * FUNCTION: acpi_ex_field_datum_io |
| 337 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 338 | * PARAMETERS: obj_desc - Field to be read |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | * field_datum_byte_offset - Byte offset of this datum within the |
| 340 | * parent field |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 341 | * Value - Where to store value (must be 64 bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | * read_write - Read or Write flag |
| 343 | * |
| 344 | * RETURN: Status |
| 345 | * |
| 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) |
| 349 | * |
| 350 | ******************************************************************************/ |
| 351 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 352 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | acpi_status status; |
| 358 | acpi_integer local_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 360 | ACPI_FUNCTION_TRACE_U32("ex_field_datum_io", field_datum_byte_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | if (read_write == ACPI_READ) { |
| 363 | if (!value) { |
| 364 | local_value = 0; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 365 | |
| 366 | /* To support reads without saving return value */ |
| 367 | value = &local_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /* Clear the entire return buffer first, [Very Important!] */ |
| 371 | |
| 372 | *value = 0; |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | * The four types of fields are: |
| 377 | * |
| 378 | * buffer_field - Read/write from/to a Buffer |
| 379 | * region_field - Read/write from/to a Operation Region. |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 385 | switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | case ACPI_TYPE_BUFFER_FIELD: |
| 387 | /* |
| 388 | * If the buffer_field arguments have not been previously evaluated, |
| 389 | * evaluate them now and save the results. |
| 390 | */ |
| 391 | if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | status = acpi_ds_get_buffer_field_arguments(obj_desc); |
| 393 | if (ACPI_FAILURE(status)) { |
| 394 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
| 398 | if (read_write == ACPI_READ) { |
| 399 | /* |
| 400 | * Copy the data from the source buffer. |
| 401 | * Length is the field width in bytes. |
| 402 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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 { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | /* |
| 411 | * Copy the data to the target buffer. |
| 412 | * Length is the field width in bytes. |
| 413 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | status = AE_OK; |
| 422 | break; |
| 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | case ACPI_TYPE_LOCAL_BANK_FIELD: |
| 425 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 426 | /* |
| 427 | * Ensure that the bank_value is not beyond the capacity of |
| 428 | * the register |
| 429 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /* |
| 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. |
| 439 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /* |
| 450 | * Now that the Bank has been selected, fall through to the |
| 451 | * region_field case and write the datum to the Operation Region |
| 452 | */ |
| 453 | |
| 454 | /*lint -fallthrough */ |
| 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | case ACPI_TYPE_LOCAL_REGION_FIELD: |
| 457 | /* |
| 458 | * For simple region_fields, we just directly access the owning |
| 459 | * Operation Region. |
| 460 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | status = |
| 462 | acpi_ex_access_region(obj_desc, field_datum_byte_offset, |
| 463 | value, read_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | break; |
| 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | case ACPI_TYPE_LOCAL_INDEX_FIELD: |
| 467 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 468 | /* |
| 469 | * Ensure that the index_value is not beyond the capacity of |
| 470 | * the register |
| 471 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /* Write the index value to the index_register (itself a region_field) */ |
| 479 | |
| 480 | field_datum_byte_offset += obj_desc->index_field.value; |
| 481 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 482 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, |
| 483 | "Write to Index Register: Value %8.8X\n", |
| 484 | field_datum_byte_offset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 494 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, |
| 495 | "I/O to Data Register: value_ptr %p\n", |
| 496 | value)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
| 498 | if (read_write == ACPI_READ) { |
| 499 | /* Read the datum from the data_register */ |
| 500 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 501 | status = |
| 502 | acpi_ex_extract_from_field(obj_desc->index_field. |
| 503 | data_obj, value, |
| 504 | sizeof(acpi_integer)); |
| 505 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | /* Write the datum to the data_register */ |
| 507 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 508 | status = |
| 509 | acpi_ex_insert_into_field(obj_desc->index_field. |
| 510 | data_obj, value, |
| 511 | sizeof(acpi_integer)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | break; |
| 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | default: |
| 516 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | ACPI_REPORT_ERROR(("Wrong object type in field I/O %X\n", |
| 518 | ACPI_GET_OBJECT_TYPE(obj_desc))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | status = AE_AML_INTERNAL; |
| 520 | break; |
| 521 | } |
| 522 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 523 | if (ACPI_SUCCESS(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (read_write == ACPI_READ) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 539 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /******************************************************************************* |
| 543 | * |
| 544 | * FUNCTION: acpi_ex_write_with_update_rule |
| 545 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | * |
| 551 | * RETURN: Status |
| 552 | * |
| 553 | * DESCRIPTION: Apply the field update rule to a field write |
| 554 | * |
| 555 | ******************************************************************************/ |
| 556 | |
| 557 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 563 | acpi_status status = AE_OK; |
| 564 | acpi_integer merged_value; |
| 565 | acpi_integer current_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 567 | ACPI_FUNCTION_TRACE_U32("ex_write_with_update_rule", mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | /* Start with the new bits */ |
| 570 | |
| 571 | merged_value = field_value; |
| 572 | |
| 573 | /* If the mask is all ones, we don't need to worry about the update rule */ |
| 574 | |
| 575 | if (mask != ACPI_INTEGER_MAX) { |
| 576 | /* Decode the update rule */ |
| 577 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 578 | switch (obj_desc->common_field. |
| 579 | field_flags & AML_FIELD_UPDATE_RULE_MASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | case AML_FIELD_UPDATE_PRESERVE: |
| 581 | /* |
| 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. |
| 584 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 585 | if ((~mask << (ACPI_MUL_8(sizeof(mask)) - |
| 586 | ACPI_MUL_8(obj_desc->common_field. |
| 587 | access_byte_width))) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | /* |
| 589 | * Read the current contents of the byte/word/dword containing |
| 590 | * the field, and merge with the new field value. |
| 591 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 592 | status = |
| 593 | acpi_ex_field_datum_io(obj_desc, |
| 594 | field_datum_byte_offset, |
| 595 | ¤t_value, |
| 596 | ACPI_READ); |
| 597 | if (ACPI_FAILURE(status)) { |
| 598 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | merged_value |= (current_value & ~mask); |
| 602 | } |
| 603 | break; |
| 604 | |
| 605 | case AML_FIELD_UPDATE_WRITE_AS_ONES: |
| 606 | |
| 607 | /* Set positions outside the field to all ones */ |
| 608 | |
| 609 | merged_value |= ~mask; |
| 610 | break; |
| 611 | |
| 612 | case AML_FIELD_UPDATE_WRITE_AS_ZEROS: |
| 613 | |
| 614 | /* Set positions outside the field to all zeros */ |
| 615 | |
| 616 | merged_value &= mask; |
| 617 | break; |
| 618 | |
| 619 | default: |
| 620 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
| 638 | /* Write the merged value */ |
| 639 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 640 | status = acpi_ex_field_datum_io(obj_desc, field_datum_byte_offset, |
| 641 | &merged_value, ACPI_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 643 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | /******************************************************************************* |
| 647 | * |
| 648 | * FUNCTION: acpi_ex_extract_from_field |
| 649 | * |
| 650 | * PARAMETERS: obj_desc - Field to be read |
| 651 | * Buffer - Where to store the field data |
| 652 | * buffer_length - Length of Buffer |
| 653 | * |
| 654 | * RETURN: Status |
| 655 | * |
| 656 | * DESCRIPTION: Retrieve the current value of the given field |
| 657 | * |
| 658 | ******************************************************************************/ |
| 659 | |
| 660 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 661 | acpi_ex_extract_from_field(union acpi_operand_object *obj_desc, |
| 662 | void *buffer, u32 buffer_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 674 | ACPI_FUNCTION_TRACE("ex_extract_from_field"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
| 676 | /* Validate target buffer and clear it */ |
| 677 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 685 | return_ACPI_STATUS(AE_BUFFER_OVERFLOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 687 | ACPI_MEMSET(buffer, 0, buffer_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
| 689 | /* Compute the number of datums (access width data items) */ |
| 690 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
| 699 | /* Priming read from the field */ |
| 700 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 707 | merged_datum = |
| 708 | raw_datum >> obj_desc->common_field.start_field_bit_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
| 710 | /* Read the rest of the field */ |
| 711 | |
| 712 | for (i = 1; i < field_datum_count; i++) { |
| 713 | /* Get next input datum from the field */ |
| 714 | |
| 715 | field_offset += obj_desc->common_field.access_byte_width; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /* Merge with previous datum if necessary */ |
| 723 | |
| 724 | merged_datum |= raw_datum << |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 725 | (obj_desc->common_field.access_bit_width - |
| 726 | obj_desc->common_field.start_field_bit_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
| 728 | if (i == datum_count) { |
| 729 | break; |
| 730 | } |
| 731 | |
| 732 | /* Write merged datum to target buffer */ |
| 733 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 734 | ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum, |
| 735 | ACPI_MIN(obj_desc->common_field.access_byte_width, |
| 736 | buffer_length - buffer_offset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
| 738 | buffer_offset += obj_desc->common_field.access_byte_width; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 739 | merged_datum = |
| 740 | raw_datum >> obj_desc->common_field.start_field_bit_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | /* Mask off any extra bits in the last datum */ |
| 744 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 745 | buffer_tail_bits = obj_desc->common_field.bit_length % |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 746 | obj_desc->common_field.access_bit_width; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | if (buffer_tail_bits) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 748 | merged_datum &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /* Write the last datum to the buffer */ |
| 752 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 753 | ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum, |
| 754 | ACPI_MIN(obj_desc->common_field.access_byte_width, |
| 755 | buffer_length - buffer_offset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 757 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | /******************************************************************************* |
| 761 | * |
| 762 | * FUNCTION: acpi_ex_insert_into_field |
| 763 | * |
| 764 | * PARAMETERS: obj_desc - Field to be written |
| 765 | * Buffer - Data to be written |
| 766 | * buffer_length - Length of Buffer |
| 767 | * |
| 768 | * RETURN: Status |
| 769 | * |
| 770 | * DESCRIPTION: Store the Buffer contents into the given field |
| 771 | * |
| 772 | ******************************************************************************/ |
| 773 | |
| 774 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 775 | acpi_ex_insert_into_field(union acpi_operand_object *obj_desc, |
| 776 | void *buffer, u32 buffer_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 789 | ACPI_FUNCTION_TRACE("ex_insert_into_field"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | /* Validate input buffer */ |
| 792 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 800 | return_ACPI_STATUS(AE_BUFFER_OVERFLOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | /* Compute the number of datums (access width data items) */ |
| 804 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | /* Get initial Datum from the input buffer */ |
| 816 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 817 | ACPI_MEMCPY(&raw_datum, buffer, |
| 818 | ACPI_MIN(obj_desc->common_field.access_byte_width, |
| 819 | buffer_length - buffer_offset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 821 | merged_datum = |
| 822 | raw_datum << obj_desc->common_field.start_field_bit_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | /* Write the entire field */ |
| 825 | |
| 826 | for (i = 1; i < field_datum_count; i++) { |
| 827 | /* Write merged datum to the target field */ |
| 828 | |
| 829 | merged_datum &= mask; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /* Start new output datum by merging with previous input datum */ |
| 838 | |
| 839 | field_offset += obj_desc->common_field.access_byte_width; |
| 840 | merged_datum = raw_datum >> |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 841 | (obj_desc->common_field.access_bit_width - |
| 842 | obj_desc->common_field.start_field_bit_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | mask = ACPI_INTEGER_MAX; |
| 844 | |
| 845 | if (i == datum_count) { |
| 846 | break; |
| 847 | } |
| 848 | |
| 849 | /* Get the next input datum from the buffer */ |
| 850 | |
| 851 | buffer_offset += obj_desc->common_field.access_byte_width; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | /* Mask off any extra bits in the last datum */ |
| 860 | |
| 861 | buffer_tail_bits = (obj_desc->common_field.bit_length + |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 862 | obj_desc->common_field.start_field_bit_offset) % |
| 863 | obj_desc->common_field.access_bit_width; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | if (buffer_tail_bits) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 865 | mask &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /* Write the last datum to the field */ |
| 869 | |
| 870 | merged_datum &= mask; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 871 | status = acpi_ex_write_with_update_rule(obj_desc, |
| 872 | mask, merged_datum, |
| 873 | field_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 875 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |