| 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 | /* | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 97 | ACPI_ERROR((AE_INFO, "Needed Region, found type %X (%s)", | 
|  | 98 | ACPI_GET_OBJECT_TYPE(rgn_desc), | 
|  | 99 | acpi_ut_get_object_type_name(rgn_desc))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } | 
|  | 103 |  | 
|  | 104 | /* | 
|  | 105 | * If the Region Address and Length have not been previously evaluated, | 
|  | 106 | * evaluate them now and save the results. | 
|  | 107 | */ | 
|  | 108 | if (!(rgn_desc->common.flags & AOPOBJ_DATA_VALID)) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | status = acpi_ds_get_region_arguments(rgn_desc); | 
|  | 110 | if (ACPI_FAILURE(status)) { | 
|  | 111 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | if (rgn_desc->region.space_id == ACPI_ADR_SPACE_SMBUS) { | 
|  | 116 | /* SMBus has a non-linear address space */ | 
|  | 117 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | #ifdef ACPI_UNDER_DEVELOPMENT | 
|  | 121 | /* | 
|  | 122 | * If the Field access is any_acc, we can now compute the optimal | 
|  | 123 | * access (because we know know the length of the parent region) | 
|  | 124 | */ | 
|  | 125 | if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | if (ACPI_FAILURE(status)) { | 
|  | 127 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } | 
|  | 129 | } | 
|  | 130 | #endif | 
|  | 131 |  | 
|  | 132 | /* | 
|  | 133 | * Validate the request.  The entire request from the byte offset for a | 
|  | 134 | * length of one field datum (access width) must fit within the region. | 
|  | 135 | * (Region length is specified in bytes) | 
|  | 136 | */ | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 137 | if (rgn_desc->region.length < (obj_desc->common_field.base_byte_offset + | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | field_datum_byte_offset + | 
|  | 139 | obj_desc->common_field. | 
|  | 140 | access_byte_width)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | if (acpi_gbl_enable_interpreter_slack) { | 
|  | 142 | /* | 
|  | 143 | * Slack mode only:  We will go ahead and allow access to this | 
|  | 144 | * field if it is within the region length rounded up to the next | 
|  | 145 | * access width boundary. | 
|  | 146 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | if (ACPI_ROUND_UP(rgn_desc->region.length, | 
|  | 148 | obj_desc->common_field. | 
|  | 149 | access_byte_width) >= | 
|  | 150 | (obj_desc->common_field.base_byte_offset + | 
|  | 151 | (acpi_native_uint) obj_desc->common_field. | 
|  | 152 | access_byte_width + field_datum_byte_offset)) { | 
|  | 153 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } | 
|  | 155 | } | 
|  | 156 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | if (rgn_desc->region.length < | 
|  | 158 | obj_desc->common_field.access_byte_width) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* | 
|  | 160 | * This is the case where the access_type (acc_word, etc.) is wider | 
|  | 161 | * than the region itself.  For example, a region of length one | 
|  | 162 | * byte, and a field with Dword access specified. | 
|  | 163 | */ | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 164 | ACPI_ERROR((AE_INFO, | 
|  | 165 | "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)", | 
|  | 166 | acpi_ut_get_node_name(obj_desc-> | 
|  | 167 | common_field.node), | 
|  | 168 | obj_desc->common_field.access_byte_width, | 
|  | 169 | acpi_ut_get_node_name(rgn_desc->region. | 
|  | 170 | node), | 
|  | 171 | rgn_desc->region.length)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
|  | 174 | /* | 
|  | 175 | * Offset rounded up to next multiple of field width | 
|  | 176 | * exceeds region length, indicate an error | 
|  | 177 | */ | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 178 | ACPI_ERROR((AE_INFO, | 
|  | 179 | "Field [%4.4s] Base+Offset+Width %X+%X+%X is beyond end of region [%4.4s] (length %X)", | 
|  | 180 | acpi_ut_get_node_name(obj_desc->common_field.node), | 
|  | 181 | obj_desc->common_field.base_byte_offset, | 
|  | 182 | field_datum_byte_offset, | 
|  | 183 | obj_desc->common_field.access_byte_width, | 
|  | 184 | acpi_ut_get_node_name(rgn_desc->region.node), | 
|  | 185 | rgn_desc->region.length)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 187 | return_ACPI_STATUS(AE_AML_REGION_LIMIT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } | 
|  | 192 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | /******************************************************************************* | 
|  | 194 | * | 
|  | 195 | * FUNCTION:    acpi_ex_access_region | 
|  | 196 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 197 | * PARAMETERS:  obj_desc                - Field to be read | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | *              field_datum_byte_offset - Byte offset of this datum within the | 
|  | 199 | *                                        parent field | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 200 | *              Value                   - Where to store value (must at least | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | *                                        the size of acpi_integer) | 
|  | 202 | *              Function                - Read or Write flag plus other region- | 
|  | 203 | *                                        dependent flags | 
|  | 204 | * | 
|  | 205 | * RETURN:      Status | 
|  | 206 | * | 
|  | 207 | * DESCRIPTION: Read or Write a single field datum to an Operation Region. | 
|  | 208 | * | 
|  | 209 | ******************************************************************************/ | 
|  | 210 |  | 
|  | 211 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | acpi_ex_access_region(union acpi_operand_object *obj_desc, | 
|  | 213 | u32 field_datum_byte_offset, | 
|  | 214 | acpi_integer * value, u32 function) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | acpi_status status; | 
|  | 217 | union acpi_operand_object *rgn_desc; | 
|  | 218 | acpi_physical_address address; | 
| 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_FUNCTION_TRACE("ex_access_region"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 |  | 
|  | 222 | /* | 
|  | 223 | * Ensure that the region operands are fully evaluated and verify | 
|  | 224 | * the validity of the request | 
|  | 225 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 226 | status = acpi_ex_setup_region(obj_desc, field_datum_byte_offset); | 
|  | 227 | if (ACPI_FAILURE(status)) { | 
|  | 228 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } | 
|  | 230 |  | 
|  | 231 | /* | 
|  | 232 | * The physical address of this field datum is: | 
|  | 233 | * | 
|  | 234 | * 1) The base of the region, plus | 
|  | 235 | * 2) The base offset of the field, plus | 
|  | 236 | * 3) The current offset into the field | 
|  | 237 | */ | 
|  | 238 | rgn_desc = obj_desc->common_field.region_obj; | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 239 | address = rgn_desc->region.address + | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | obj_desc->common_field.base_byte_offset + field_datum_byte_offset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 |  | 
|  | 242 | if ((function & ACPI_IO_MASK) == ACPI_READ) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[READ]")); | 
|  | 244 | } else { | 
|  | 245 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[WRITE]")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } | 
|  | 247 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD, | 
|  | 249 | " Region [%s:%X], Width %X, byte_base %X, Offset %X at %8.8X%8.8X\n", | 
|  | 250 | acpi_ut_get_region_name(rgn_desc->region. | 
|  | 251 | space_id), | 
|  | 252 | rgn_desc->region.space_id, | 
|  | 253 | obj_desc->common_field.access_byte_width, | 
|  | 254 | obj_desc->common_field.base_byte_offset, | 
|  | 255 | field_datum_byte_offset, | 
|  | 256 | ACPI_FORMAT_UINT64(address))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 |  | 
|  | 258 | /* Invoke the appropriate address_space/op_region handler */ | 
|  | 259 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | status = acpi_ev_address_space_dispatch(rgn_desc, function, | 
|  | 261 | address, | 
|  | 262 | ACPI_MUL_8(obj_desc-> | 
|  | 263 | common_field. | 
|  | 264 | access_byte_width), | 
|  | 265 | value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (status == AE_NOT_IMPLEMENTED) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 269 | ACPI_ERROR((AE_INFO, | 
|  | 270 | "Region %s(%X) not implemented", | 
|  | 271 | acpi_ut_get_region_name(rgn_desc->region. | 
|  | 272 | space_id), | 
|  | 273 | rgn_desc->region.space_id)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | } else if (status == AE_NOT_EXIST) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 275 | ACPI_ERROR((AE_INFO, | 
|  | 276 | "Region %s(%X) has no handler", | 
|  | 277 | acpi_ut_get_region_name(rgn_desc->region. | 
|  | 278 | space_id), | 
|  | 279 | rgn_desc->region.space_id)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } | 
|  | 281 | } | 
|  | 282 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 283 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } | 
|  | 285 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | /******************************************************************************* | 
|  | 287 | * | 
|  | 288 | * FUNCTION:    acpi_ex_register_overflow | 
|  | 289 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 290 | * PARAMETERS:  obj_desc                - Register(Field) to be written | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | *              Value                   - Value to be stored | 
|  | 292 | * | 
|  | 293 | * RETURN:      TRUE if value overflows the field, FALSE otherwise | 
|  | 294 | * | 
|  | 295 | * DESCRIPTION: Check if a value is out of range of the field being written. | 
|  | 296 | *              Used to check if the values written to Index and Bank registers | 
|  | 297 | *              are out of range.  Normally, the value is simply truncated | 
|  | 298 | *              to fit the field, but this case is most likely a serious | 
|  | 299 | *              coding error in the ASL. | 
|  | 300 | * | 
|  | 301 | ******************************************************************************/ | 
|  | 302 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 303 | static u8 | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 304 | acpi_ex_register_overflow(union acpi_operand_object *obj_desc, | 
|  | 305 | acpi_integer value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { | 
|  | 307 |  | 
|  | 308 | if (obj_desc->common_field.bit_length >= ACPI_INTEGER_BIT_SIZE) { | 
|  | 309 | /* | 
|  | 310 | * The field is large enough to hold the maximum integer, so we can | 
|  | 311 | * never overflow it. | 
|  | 312 | */ | 
|  | 313 | return (FALSE); | 
|  | 314 | } | 
|  | 315 |  | 
|  | 316 | if (value >= ((acpi_integer) 1 << obj_desc->common_field.bit_length)) { | 
|  | 317 | /* | 
|  | 318 | * The Value is larger than the maximum value that can fit into | 
|  | 319 | * the register. | 
|  | 320 | */ | 
|  | 321 | return (TRUE); | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | /* The Value will fit into the field with no truncation */ | 
|  | 325 |  | 
|  | 326 | return (FALSE); | 
|  | 327 | } | 
|  | 328 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | /******************************************************************************* | 
|  | 330 | * | 
|  | 331 | * FUNCTION:    acpi_ex_field_datum_io | 
|  | 332 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 333 | * PARAMETERS:  obj_desc                - Field to be read | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | *              field_datum_byte_offset - Byte offset of this datum within the | 
|  | 335 | *                                        parent field | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 336 | *              Value                   - Where to store value (must be 64 bits) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | *              read_write              - Read or Write flag | 
|  | 338 | * | 
|  | 339 | * RETURN:      Status | 
|  | 340 | * | 
|  | 341 | * DESCRIPTION: Read or Write a single datum of a field.  The field_type is | 
|  | 342 | *              demultiplexed here to handle the different types of fields | 
|  | 343 | *              (buffer_field, region_field, index_field, bank_field) | 
|  | 344 | * | 
|  | 345 | ******************************************************************************/ | 
|  | 346 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 347 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | acpi_ex_field_datum_io(union acpi_operand_object *obj_desc, | 
|  | 349 | u32 field_datum_byte_offset, | 
|  | 350 | acpi_integer * value, u32 read_write) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 352 | acpi_status status; | 
|  | 353 | acpi_integer local_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 355 | ACPI_FUNCTION_TRACE_U32("ex_field_datum_io", field_datum_byte_offset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 |  | 
|  | 357 | if (read_write == ACPI_READ) { | 
|  | 358 | if (!value) { | 
|  | 359 | local_value = 0; | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 360 |  | 
|  | 361 | /* To support reads without saving return value */ | 
|  | 362 | value = &local_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } | 
|  | 364 |  | 
|  | 365 | /* Clear the entire return buffer first, [Very Important!] */ | 
|  | 366 |  | 
|  | 367 | *value = 0; | 
|  | 368 | } | 
|  | 369 |  | 
|  | 370 | /* | 
|  | 371 | * The four types of fields are: | 
|  | 372 | * | 
|  | 373 | * buffer_field - Read/write from/to a Buffer | 
|  | 374 | * region_field - Read/write from/to a Operation Region. | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 375 | * bank_field  - Write to a Bank Register, then read/write from/to an | 
|  | 376 | *               operation_region | 
|  | 377 | * index_field - Write to an Index Register, then read/write from/to a | 
|  | 378 | *               Data Register | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 380 | switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | case ACPI_TYPE_BUFFER_FIELD: | 
|  | 382 | /* | 
|  | 383 | * If the buffer_field arguments have not been previously evaluated, | 
|  | 384 | * evaluate them now and save the results. | 
|  | 385 | */ | 
|  | 386 | if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 387 | status = acpi_ds_get_buffer_field_arguments(obj_desc); | 
|  | 388 | if (ACPI_FAILURE(status)) { | 
|  | 389 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } | 
|  | 391 | } | 
|  | 392 |  | 
|  | 393 | if (read_write == ACPI_READ) { | 
|  | 394 | /* | 
|  | 395 | * Copy the data from the source buffer. | 
|  | 396 | * Length is the field width in bytes. | 
|  | 397 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 398 | ACPI_MEMCPY(value, | 
|  | 399 | (obj_desc->buffer_field.buffer_obj)->buffer. | 
|  | 400 | pointer + | 
|  | 401 | obj_desc->buffer_field.base_byte_offset + | 
|  | 402 | field_datum_byte_offset, | 
|  | 403 | obj_desc->common_field.access_byte_width); | 
|  | 404 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | /* | 
|  | 406 | * Copy the data to the target buffer. | 
|  | 407 | * Length is the field width in bytes. | 
|  | 408 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 409 | ACPI_MEMCPY((obj_desc->buffer_field.buffer_obj)->buffer. | 
|  | 410 | pointer + | 
|  | 411 | obj_desc->buffer_field.base_byte_offset + | 
|  | 412 | field_datum_byte_offset, value, | 
|  | 413 | obj_desc->common_field.access_byte_width); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } | 
|  | 415 |  | 
|  | 416 | status = AE_OK; | 
|  | 417 | break; | 
|  | 418 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | case ACPI_TYPE_LOCAL_BANK_FIELD: | 
|  | 420 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 421 | /* | 
|  | 422 | * Ensure that the bank_value is not beyond the capacity of | 
|  | 423 | * the register | 
|  | 424 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | if (acpi_ex_register_overflow(obj_desc->bank_field.bank_obj, | 
|  | 426 | (acpi_integer) obj_desc-> | 
|  | 427 | bank_field.value)) { | 
|  | 428 | return_ACPI_STATUS(AE_AML_REGISTER_LIMIT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } | 
|  | 430 |  | 
|  | 431 | /* | 
|  | 432 | * For bank_fields, we must write the bank_value to the bank_register | 
|  | 433 | * (itself a region_field) before we can access the data. | 
|  | 434 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 435 | status = | 
|  | 436 | acpi_ex_insert_into_field(obj_desc->bank_field.bank_obj, | 
|  | 437 | &obj_desc->bank_field.value, | 
|  | 438 | sizeof(obj_desc->bank_field. | 
|  | 439 | value)); | 
|  | 440 | if (ACPI_FAILURE(status)) { | 
|  | 441 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } | 
|  | 443 |  | 
|  | 444 | /* | 
|  | 445 | * Now that the Bank has been selected, fall through to the | 
|  | 446 | * region_field case and write the datum to the Operation Region | 
|  | 447 | */ | 
|  | 448 |  | 
|  | 449 | /*lint -fallthrough */ | 
|  | 450 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | case ACPI_TYPE_LOCAL_REGION_FIELD: | 
|  | 452 | /* | 
|  | 453 | * For simple region_fields, we just directly access the owning | 
|  | 454 | * Operation Region. | 
|  | 455 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | status = | 
|  | 457 | acpi_ex_access_region(obj_desc, field_datum_byte_offset, | 
|  | 458 | value, read_write); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | break; | 
|  | 460 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | case ACPI_TYPE_LOCAL_INDEX_FIELD: | 
|  | 462 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 463 | /* | 
|  | 464 | * Ensure that the index_value is not beyond the capacity of | 
|  | 465 | * the register | 
|  | 466 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 467 | if (acpi_ex_register_overflow(obj_desc->index_field.index_obj, | 
|  | 468 | (acpi_integer) obj_desc-> | 
|  | 469 | index_field.value)) { | 
|  | 470 | return_ACPI_STATUS(AE_AML_REGISTER_LIMIT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } | 
|  | 472 |  | 
|  | 473 | /* Write the index value to the index_register (itself a region_field) */ | 
|  | 474 |  | 
|  | 475 | field_datum_byte_offset += obj_desc->index_field.value; | 
|  | 476 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 477 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, | 
|  | 478 | "Write to Index Register: Value %8.8X\n", | 
|  | 479 | field_datum_byte_offset)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 481 | status = | 
|  | 482 | acpi_ex_insert_into_field(obj_desc->index_field.index_obj, | 
|  | 483 | &field_datum_byte_offset, | 
|  | 484 | sizeof(field_datum_byte_offset)); | 
|  | 485 | if (ACPI_FAILURE(status)) { | 
|  | 486 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } | 
|  | 488 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 489 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, | 
|  | 490 | "I/O to Data Register: value_ptr %p\n", | 
|  | 491 | value)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 |  | 
|  | 493 | if (read_write == ACPI_READ) { | 
|  | 494 | /* Read the datum from the data_register */ | 
|  | 495 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | status = | 
|  | 497 | acpi_ex_extract_from_field(obj_desc->index_field. | 
|  | 498 | data_obj, value, | 
|  | 499 | sizeof(acpi_integer)); | 
|  | 500 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | /* Write the datum to the data_register */ | 
|  | 502 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 503 | status = | 
|  | 504 | acpi_ex_insert_into_field(obj_desc->index_field. | 
|  | 505 | data_obj, value, | 
|  | 506 | sizeof(acpi_integer)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } | 
|  | 508 | break; | 
|  | 509 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | default: | 
|  | 511 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 512 | ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %X", | 
|  | 513 | ACPI_GET_OBJECT_TYPE(obj_desc))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | status = AE_AML_INTERNAL; | 
|  | 515 | break; | 
|  | 516 | } | 
|  | 517 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 518 | if (ACPI_SUCCESS(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (read_write == ACPI_READ) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 520 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, | 
|  | 521 | "Value Read %8.8X%8.8X, Width %d\n", | 
|  | 522 | ACPI_FORMAT_UINT64(*value), | 
|  | 523 | obj_desc->common_field. | 
|  | 524 | access_byte_width)); | 
|  | 525 | } else { | 
|  | 526 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, | 
|  | 527 | "Value Written %8.8X%8.8X, Width %d\n", | 
|  | 528 | ACPI_FORMAT_UINT64(*value), | 
|  | 529 | obj_desc->common_field. | 
|  | 530 | access_byte_width)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } | 
|  | 532 | } | 
|  | 533 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 534 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } | 
|  | 536 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /******************************************************************************* | 
|  | 538 | * | 
|  | 539 | * FUNCTION:    acpi_ex_write_with_update_rule | 
|  | 540 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 541 | * PARAMETERS:  obj_desc                - Field to be written | 
|  | 542 | *              Mask                    - bitmask within field datum | 
|  | 543 | *              field_value             - Value to write | 
|  | 544 | *              field_datum_byte_offset - Offset of datum within field | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | * | 
|  | 546 | * RETURN:      Status | 
|  | 547 | * | 
|  | 548 | * DESCRIPTION: Apply the field update rule to a field write | 
|  | 549 | * | 
|  | 550 | ******************************************************************************/ | 
|  | 551 |  | 
|  | 552 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 553 | acpi_ex_write_with_update_rule(union acpi_operand_object *obj_desc, | 
|  | 554 | acpi_integer mask, | 
|  | 555 | acpi_integer field_value, | 
|  | 556 | u32 field_datum_byte_offset) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 558 | acpi_status status = AE_OK; | 
|  | 559 | acpi_integer merged_value; | 
|  | 560 | acpi_integer current_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 562 | ACPI_FUNCTION_TRACE_U32("ex_write_with_update_rule", mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 |  | 
|  | 564 | /* Start with the new bits  */ | 
|  | 565 |  | 
|  | 566 | merged_value = field_value; | 
|  | 567 |  | 
|  | 568 | /* If the mask is all ones, we don't need to worry about the update rule */ | 
|  | 569 |  | 
|  | 570 | if (mask != ACPI_INTEGER_MAX) { | 
|  | 571 | /* Decode the update rule */ | 
|  | 572 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | switch (obj_desc->common_field. | 
|  | 574 | field_flags & AML_FIELD_UPDATE_RULE_MASK) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | case AML_FIELD_UPDATE_PRESERVE: | 
|  | 576 | /* | 
|  | 577 | * Check if update rule needs to be applied (not if mask is all | 
|  | 578 | * ones)  The left shift drops the bits we want to ignore. | 
|  | 579 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 580 | if ((~mask << (ACPI_MUL_8(sizeof(mask)) - | 
|  | 581 | ACPI_MUL_8(obj_desc->common_field. | 
|  | 582 | access_byte_width))) != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | /* | 
|  | 584 | * Read the current contents of the byte/word/dword containing | 
|  | 585 | * the field, and merge with the new field value. | 
|  | 586 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 587 | status = | 
|  | 588 | acpi_ex_field_datum_io(obj_desc, | 
|  | 589 | field_datum_byte_offset, | 
|  | 590 | ¤t_value, | 
|  | 591 | ACPI_READ); | 
|  | 592 | if (ACPI_FAILURE(status)) { | 
|  | 593 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | } | 
|  | 595 |  | 
|  | 596 | merged_value |= (current_value & ~mask); | 
|  | 597 | } | 
|  | 598 | break; | 
|  | 599 |  | 
|  | 600 | case AML_FIELD_UPDATE_WRITE_AS_ONES: | 
|  | 601 |  | 
|  | 602 | /* Set positions outside the field to all ones */ | 
|  | 603 |  | 
|  | 604 | merged_value |= ~mask; | 
|  | 605 | break; | 
|  | 606 |  | 
|  | 607 | case AML_FIELD_UPDATE_WRITE_AS_ZEROS: | 
|  | 608 |  | 
|  | 609 | /* Set positions outside the field to all zeros */ | 
|  | 610 |  | 
|  | 611 | merged_value &= mask; | 
|  | 612 | break; | 
|  | 613 |  | 
|  | 614 | default: | 
|  | 615 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 616 | ACPI_ERROR((AE_INFO, | 
|  | 617 | "Unknown update_rule value: %X", | 
|  | 618 | (obj_desc->common_field. | 
|  | 619 | field_flags & | 
|  | 620 | AML_FIELD_UPDATE_RULE_MASK))); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 621 | return_ACPI_STATUS(AE_AML_OPERAND_VALUE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } | 
|  | 623 | } | 
|  | 624 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 625 | ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, | 
|  | 626 | "Mask %8.8X%8.8X, datum_offset %X, Width %X, Value %8.8X%8.8X, merged_value %8.8X%8.8X\n", | 
|  | 627 | ACPI_FORMAT_UINT64(mask), | 
|  | 628 | field_datum_byte_offset, | 
|  | 629 | obj_desc->common_field.access_byte_width, | 
|  | 630 | ACPI_FORMAT_UINT64(field_value), | 
|  | 631 | ACPI_FORMAT_UINT64(merged_value))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 |  | 
|  | 633 | /* Write the merged value */ | 
|  | 634 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 635 | status = acpi_ex_field_datum_io(obj_desc, field_datum_byte_offset, | 
|  | 636 | &merged_value, ACPI_WRITE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 638 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } | 
|  | 640 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | /******************************************************************************* | 
|  | 642 | * | 
|  | 643 | * FUNCTION:    acpi_ex_extract_from_field | 
|  | 644 | * | 
|  | 645 | * PARAMETERS:  obj_desc            - Field to be read | 
|  | 646 | *              Buffer              - Where to store the field data | 
|  | 647 | *              buffer_length       - Length of Buffer | 
|  | 648 | * | 
|  | 649 | * RETURN:      Status | 
|  | 650 | * | 
|  | 651 | * DESCRIPTION: Retrieve the current value of the given field | 
|  | 652 | * | 
|  | 653 | ******************************************************************************/ | 
|  | 654 |  | 
|  | 655 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 656 | acpi_ex_extract_from_field(union acpi_operand_object *obj_desc, | 
|  | 657 | void *buffer, u32 buffer_length) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 659 | acpi_status status; | 
|  | 660 | acpi_integer raw_datum; | 
|  | 661 | acpi_integer merged_datum; | 
|  | 662 | u32 field_offset = 0; | 
|  | 663 | u32 buffer_offset = 0; | 
|  | 664 | u32 buffer_tail_bits; | 
|  | 665 | u32 datum_count; | 
|  | 666 | u32 field_datum_count; | 
|  | 667 | u32 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 669 | ACPI_FUNCTION_TRACE("ex_extract_from_field"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 |  | 
|  | 671 | /* Validate target buffer and clear it */ | 
|  | 672 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 673 | if (buffer_length < | 
|  | 674 | ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 675 | ACPI_ERROR((AE_INFO, | 
|  | 676 | "Field size %X (bits) is too large for buffer (%X)", | 
|  | 677 | obj_desc->common_field.bit_length, buffer_length)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 679 | return_ACPI_STATUS(AE_BUFFER_OVERFLOW); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 681 | ACPI_MEMSET(buffer, 0, buffer_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 |  | 
|  | 683 | /* Compute the number of datums (access width data items) */ | 
|  | 684 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 685 | datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length, | 
|  | 686 | obj_desc->common_field.access_bit_width); | 
|  | 687 | field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length + | 
|  | 688 | obj_desc->common_field. | 
|  | 689 | start_field_bit_offset, | 
|  | 690 | obj_desc->common_field. | 
|  | 691 | access_bit_width); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 |  | 
|  | 693 | /* Priming read from the field */ | 
|  | 694 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 695 | status = | 
|  | 696 | acpi_ex_field_datum_io(obj_desc, field_offset, &raw_datum, | 
|  | 697 | ACPI_READ); | 
|  | 698 | if (ACPI_FAILURE(status)) { | 
|  | 699 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 701 | merged_datum = | 
|  | 702 | raw_datum >> obj_desc->common_field.start_field_bit_offset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 |  | 
|  | 704 | /* Read the rest of the field */ | 
|  | 705 |  | 
|  | 706 | for (i = 1; i < field_datum_count; i++) { | 
|  | 707 | /* Get next input datum from the field */ | 
|  | 708 |  | 
|  | 709 | field_offset += obj_desc->common_field.access_byte_width; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 710 | status = acpi_ex_field_datum_io(obj_desc, field_offset, | 
|  | 711 | &raw_datum, ACPI_READ); | 
|  | 712 | if (ACPI_FAILURE(status)) { | 
|  | 713 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | } | 
|  | 715 |  | 
|  | 716 | /* Merge with previous datum if necessary */ | 
|  | 717 |  | 
|  | 718 | merged_datum |= raw_datum << | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 719 | (obj_desc->common_field.access_bit_width - | 
|  | 720 | obj_desc->common_field.start_field_bit_offset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 |  | 
|  | 722 | if (i == datum_count) { | 
|  | 723 | break; | 
|  | 724 | } | 
|  | 725 |  | 
|  | 726 | /* Write merged datum to target buffer */ | 
|  | 727 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 728 | ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum, | 
|  | 729 | ACPI_MIN(obj_desc->common_field.access_byte_width, | 
|  | 730 | buffer_length - buffer_offset)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 |  | 
|  | 732 | buffer_offset += obj_desc->common_field.access_byte_width; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 733 | merged_datum = | 
|  | 734 | raw_datum >> obj_desc->common_field.start_field_bit_offset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } | 
|  | 736 |  | 
|  | 737 | /* Mask off any extra bits in the last datum */ | 
|  | 738 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 739 | buffer_tail_bits = obj_desc->common_field.bit_length % | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 740 | obj_desc->common_field.access_bit_width; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | if (buffer_tail_bits) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 742 | merged_datum &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } | 
|  | 744 |  | 
|  | 745 | /* Write the last datum to the buffer */ | 
|  | 746 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 747 | ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum, | 
|  | 748 | ACPI_MIN(obj_desc->common_field.access_byte_width, | 
|  | 749 | buffer_length - buffer_offset)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 751 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } | 
|  | 753 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | /******************************************************************************* | 
|  | 755 | * | 
|  | 756 | * FUNCTION:    acpi_ex_insert_into_field | 
|  | 757 | * | 
|  | 758 | * PARAMETERS:  obj_desc            - Field to be written | 
|  | 759 | *              Buffer              - Data to be written | 
|  | 760 | *              buffer_length       - Length of Buffer | 
|  | 761 | * | 
|  | 762 | * RETURN:      Status | 
|  | 763 | * | 
|  | 764 | * DESCRIPTION: Store the Buffer contents into the given field | 
|  | 765 | * | 
|  | 766 | ******************************************************************************/ | 
|  | 767 |  | 
|  | 768 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 769 | acpi_ex_insert_into_field(union acpi_operand_object *obj_desc, | 
|  | 770 | void *buffer, u32 buffer_length) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 772 | acpi_status status; | 
|  | 773 | acpi_integer mask; | 
|  | 774 | acpi_integer merged_datum; | 
|  | 775 | acpi_integer raw_datum = 0; | 
|  | 776 | u32 field_offset = 0; | 
|  | 777 | u32 buffer_offset = 0; | 
|  | 778 | u32 buffer_tail_bits; | 
|  | 779 | u32 datum_count; | 
|  | 780 | u32 field_datum_count; | 
|  | 781 | u32 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 783 | ACPI_FUNCTION_TRACE("ex_insert_into_field"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 |  | 
|  | 785 | /* Validate input buffer */ | 
|  | 786 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 787 | if (buffer_length < | 
|  | 788 | ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 789 | ACPI_ERROR((AE_INFO, | 
|  | 790 | "Field size %X (bits) is too large for buffer (%X)", | 
|  | 791 | obj_desc->common_field.bit_length, buffer_length)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 793 | return_ACPI_STATUS(AE_BUFFER_OVERFLOW); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } | 
|  | 795 |  | 
|  | 796 | /* Compute the number of datums (access width data items) */ | 
|  | 797 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 798 | mask = | 
|  | 799 | ACPI_MASK_BITS_BELOW(obj_desc->common_field.start_field_bit_offset); | 
|  | 800 | datum_count = | 
|  | 801 | ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length, | 
|  | 802 | obj_desc->common_field.access_bit_width); | 
|  | 803 | field_datum_count = | 
|  | 804 | ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length + | 
|  | 805 | obj_desc->common_field.start_field_bit_offset, | 
|  | 806 | obj_desc->common_field.access_bit_width); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 |  | 
|  | 808 | /* Get initial Datum from the input buffer */ | 
|  | 809 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 810 | ACPI_MEMCPY(&raw_datum, buffer, | 
|  | 811 | ACPI_MIN(obj_desc->common_field.access_byte_width, | 
|  | 812 | buffer_length - buffer_offset)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 814 | merged_datum = | 
|  | 815 | raw_datum << obj_desc->common_field.start_field_bit_offset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 |  | 
|  | 817 | /* Write the entire field */ | 
|  | 818 |  | 
|  | 819 | for (i = 1; i < field_datum_count; i++) { | 
|  | 820 | /* Write merged datum to the target field */ | 
|  | 821 |  | 
|  | 822 | merged_datum &= mask; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 823 | status = acpi_ex_write_with_update_rule(obj_desc, mask, | 
|  | 824 | merged_datum, | 
|  | 825 | field_offset); | 
|  | 826 | if (ACPI_FAILURE(status)) { | 
|  | 827 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | } | 
|  | 829 |  | 
|  | 830 | /* Start new output datum by merging with previous input datum */ | 
|  | 831 |  | 
|  | 832 | field_offset += obj_desc->common_field.access_byte_width; | 
|  | 833 | merged_datum = raw_datum >> | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 834 | (obj_desc->common_field.access_bit_width - | 
|  | 835 | obj_desc->common_field.start_field_bit_offset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | mask = ACPI_INTEGER_MAX; | 
|  | 837 |  | 
|  | 838 | if (i == datum_count) { | 
|  | 839 | break; | 
|  | 840 | } | 
|  | 841 |  | 
|  | 842 | /* Get the next input datum from the buffer */ | 
|  | 843 |  | 
|  | 844 | buffer_offset += obj_desc->common_field.access_byte_width; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 845 | ACPI_MEMCPY(&raw_datum, ((char *)buffer) + buffer_offset, | 
|  | 846 | ACPI_MIN(obj_desc->common_field.access_byte_width, | 
|  | 847 | buffer_length - buffer_offset)); | 
|  | 848 | merged_datum |= | 
|  | 849 | raw_datum << obj_desc->common_field.start_field_bit_offset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } | 
|  | 851 |  | 
|  | 852 | /* Mask off any extra bits in the last datum */ | 
|  | 853 |  | 
|  | 854 | buffer_tail_bits = (obj_desc->common_field.bit_length + | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 855 | obj_desc->common_field.start_field_bit_offset) % | 
|  | 856 | obj_desc->common_field.access_bit_width; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | if (buffer_tail_bits) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 858 | mask &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } | 
|  | 860 |  | 
|  | 861 | /* Write the last datum to the field */ | 
|  | 862 |  | 
|  | 863 | merged_datum &= mask; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 864 | status = acpi_ex_write_with_update_rule(obj_desc, | 
|  | 865 | mask, merged_datum, | 
|  | 866 | field_offset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 868 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | } |