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