aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/executer/exfield.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/executer/exfield.c')
-rw-r--r--drivers/acpi/executer/exfield.c252
1 files changed, 126 insertions, 126 deletions
diff --git a/drivers/acpi/executer/exfield.c b/drivers/acpi/executer/exfield.c
index a690c9250990..ab1ba399aa28 100644
--- a/drivers/acpi/executer/exfield.c
+++ b/drivers/acpi/executer/exfield.c
@@ -41,15 +41,12 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44
45#include <acpi/acpi.h> 44#include <acpi/acpi.h>
46#include <acpi/acdispat.h> 45#include <acpi/acdispat.h>
47#include <acpi/acinterp.h> 46#include <acpi/acinterp.h>
48 47
49
50#define _COMPONENT ACPI_EXECUTER 48#define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("exfield") 49ACPI_MODULE_NAME("exfield")
52
53 50
54/******************************************************************************* 51/*******************************************************************************
55 * 52 *
@@ -65,67 +62,70 @@
65 * Buffer, depending on the size of the field. 62 * Buffer, depending on the size of the field.
66 * 63 *
67 ******************************************************************************/ 64 ******************************************************************************/
68
69acpi_status 65acpi_status
70acpi_ex_read_data_from_field ( 66acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
71 struct acpi_walk_state *walk_state, 67 union acpi_operand_object *obj_desc,
72 union acpi_operand_object *obj_desc, 68 union acpi_operand_object **ret_buffer_desc)
73 union acpi_operand_object **ret_buffer_desc)
74{ 69{
75 acpi_status status; 70 acpi_status status;
76 union acpi_operand_object *buffer_desc; 71 union acpi_operand_object *buffer_desc;
77 acpi_size length; 72 acpi_size length;
78 void *buffer; 73 void *buffer;
79 u8 locked; 74 u8 locked;
80
81
82 ACPI_FUNCTION_TRACE_PTR ("ex_read_data_from_field", obj_desc);
83 75
76 ACPI_FUNCTION_TRACE_PTR("ex_read_data_from_field", obj_desc);
84 77
85 /* Parameter validation */ 78 /* Parameter validation */
86 79
87 if (!obj_desc) { 80 if (!obj_desc) {
88 return_ACPI_STATUS (AE_AML_NO_OPERAND); 81 return_ACPI_STATUS(AE_AML_NO_OPERAND);
89 } 82 }
90 if (!ret_buffer_desc) { 83 if (!ret_buffer_desc) {
91 return_ACPI_STATUS (AE_BAD_PARAMETER); 84 return_ACPI_STATUS(AE_BAD_PARAMETER);
92 } 85 }
93 86
94 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_BUFFER_FIELD) { 87 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_BUFFER_FIELD) {
95 /* 88 /*
96 * If the buffer_field arguments have not been previously evaluated, 89 * If the buffer_field arguments have not been previously evaluated,
97 * evaluate them now and save the results. 90 * evaluate them now and save the results.
98 */ 91 */
99 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { 92 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
100 status = acpi_ds_get_buffer_field_arguments (obj_desc); 93 status = acpi_ds_get_buffer_field_arguments(obj_desc);
101 if (ACPI_FAILURE (status)) { 94 if (ACPI_FAILURE(status)) {
102 return_ACPI_STATUS (status); 95 return_ACPI_STATUS(status);
103 } 96 }
104 } 97 }
105 } 98 } else
106 else if ((ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD) && 99 if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD)
107 (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_SMBUS)) { 100 && (obj_desc->field.region_obj->region.space_id ==
101 ACPI_ADR_SPACE_SMBUS)) {
108 /* 102 /*
109 * This is an SMBus read. We must create a buffer to hold the data 103 * This is an SMBus read. We must create a buffer to hold the data
110 * and directly access the region handler. 104 * and directly access the region handler.
111 */ 105 */
112 buffer_desc = acpi_ut_create_buffer_object (ACPI_SMBUS_BUFFER_SIZE); 106 buffer_desc =
107 acpi_ut_create_buffer_object(ACPI_SMBUS_BUFFER_SIZE);
113 if (!buffer_desc) { 108 if (!buffer_desc) {
114 return_ACPI_STATUS (AE_NO_MEMORY); 109 return_ACPI_STATUS(AE_NO_MEMORY);
115 } 110 }
116 111
117 /* Lock entire transaction if requested */ 112 /* Lock entire transaction if requested */
118 113
119 locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); 114 locked =
115 acpi_ex_acquire_global_lock(obj_desc->common_field.
116 field_flags);
120 117
121 /* 118 /*
122 * Perform the read. 119 * Perform the read.
123 * Note: Smbus protocol value is passed in upper 16-bits of Function 120 * Note: Smbus protocol value is passed in upper 16-bits of Function
124 */ 121 */
125 status = acpi_ex_access_region (obj_desc, 0, 122 status = acpi_ex_access_region(obj_desc, 0,
126 ACPI_CAST_PTR (acpi_integer, buffer_desc->buffer.pointer), 123 ACPI_CAST_PTR(acpi_integer,
127 ACPI_READ | (obj_desc->field.attribute << 16)); 124 buffer_desc->
128 acpi_ex_release_global_lock (locked); 125 buffer.pointer),
126 ACPI_READ | (obj_desc->field.
127 attribute << 16));
128 acpi_ex_release_global_lock(locked);
129 goto exit; 129 goto exit;
130 } 130 }
131 131
@@ -139,22 +139,22 @@ acpi_ex_read_data_from_field (
139 * 139 *
140 * Note: Field.length is in bits. 140 * Note: Field.length is in bits.
141 */ 141 */
142 length = (acpi_size) ACPI_ROUND_BITS_UP_TO_BYTES (obj_desc->field.bit_length); 142 length =
143 (acpi_size) ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->field.bit_length);
143 if (length > acpi_gbl_integer_byte_width) { 144 if (length > acpi_gbl_integer_byte_width) {
144 /* Field is too large for an Integer, create a Buffer instead */ 145 /* Field is too large for an Integer, create a Buffer instead */
145 146
146 buffer_desc = acpi_ut_create_buffer_object (length); 147 buffer_desc = acpi_ut_create_buffer_object(length);
147 if (!buffer_desc) { 148 if (!buffer_desc) {
148 return_ACPI_STATUS (AE_NO_MEMORY); 149 return_ACPI_STATUS(AE_NO_MEMORY);
149 } 150 }
150 buffer = buffer_desc->buffer.pointer; 151 buffer = buffer_desc->buffer.pointer;
151 } 152 } else {
152 else {
153 /* Field will fit within an Integer (normal case) */ 153 /* Field will fit within an Integer (normal case) */
154 154
155 buffer_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); 155 buffer_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
156 if (!buffer_desc) { 156 if (!buffer_desc) {
157 return_ACPI_STATUS (AE_NO_MEMORY); 157 return_ACPI_STATUS(AE_NO_MEMORY);
158 } 158 }
159 159
160 length = acpi_gbl_integer_byte_width; 160 length = acpi_gbl_integer_byte_width;
@@ -162,37 +162,36 @@ acpi_ex_read_data_from_field (
162 buffer = &buffer_desc->integer.value; 162 buffer = &buffer_desc->integer.value;
163 } 163 }
164 164
165 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 165 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
166 "field_read [TO]: Obj %p, Type %X, Buf %p, byte_len %X\n", 166 "field_read [TO]: Obj %p, Type %X, Buf %p, byte_len %X\n",
167 obj_desc, ACPI_GET_OBJECT_TYPE (obj_desc), buffer, (u32) length)); 167 obj_desc, ACPI_GET_OBJECT_TYPE(obj_desc), buffer,
168 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 168 (u32) length));
169 "field_read [FROM]: bit_len %X, bit_off %X, byte_off %X\n", 169 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
170 obj_desc->common_field.bit_length, 170 "field_read [FROM]: bit_len %X, bit_off %X, byte_off %X\n",
171 obj_desc->common_field.start_field_bit_offset, 171 obj_desc->common_field.bit_length,
172 obj_desc->common_field.base_byte_offset)); 172 obj_desc->common_field.start_field_bit_offset,
173 obj_desc->common_field.base_byte_offset));
173 174
174 /* Lock entire transaction if requested */ 175 /* Lock entire transaction if requested */
175 176
176 locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); 177 locked =
178 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
177 179
178 /* Read from the field */ 180 /* Read from the field */
179 181
180 status = acpi_ex_extract_from_field (obj_desc, buffer, (u32) length); 182 status = acpi_ex_extract_from_field(obj_desc, buffer, (u32) length);
181 acpi_ex_release_global_lock (locked); 183 acpi_ex_release_global_lock(locked);
182
183 184
184exit: 185 exit:
185 if (ACPI_FAILURE (status)) { 186 if (ACPI_FAILURE(status)) {
186 acpi_ut_remove_reference (buffer_desc); 187 acpi_ut_remove_reference(buffer_desc);
187 } 188 } else {
188 else {
189 *ret_buffer_desc = buffer_desc; 189 *ret_buffer_desc = buffer_desc;
190 } 190 }
191 191
192 return_ACPI_STATUS (status); 192 return_ACPI_STATUS(status);
193} 193}
194 194
195
196/******************************************************************************* 195/*******************************************************************************
197 * 196 *
198 * FUNCTION: acpi_ex_write_data_to_field 197 * FUNCTION: acpi_ex_write_data_to_field
@@ -208,97 +207,96 @@ exit:
208 ******************************************************************************/ 207 ******************************************************************************/
209 208
210acpi_status 209acpi_status
211acpi_ex_write_data_to_field ( 210acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
212 union acpi_operand_object *source_desc, 211 union acpi_operand_object *obj_desc,
213 union acpi_operand_object *obj_desc, 212 union acpi_operand_object **result_desc)
214 union acpi_operand_object **result_desc)
215{ 213{
216 acpi_status status; 214 acpi_status status;
217 u32 length; 215 u32 length;
218 u32 required_length; 216 u32 required_length;
219 void *buffer; 217 void *buffer;
220 void *new_buffer; 218 void *new_buffer;
221 u8 locked; 219 u8 locked;
222 union acpi_operand_object *buffer_desc; 220 union acpi_operand_object *buffer_desc;
223
224
225 ACPI_FUNCTION_TRACE_PTR ("ex_write_data_to_field", obj_desc);
226 221
222 ACPI_FUNCTION_TRACE_PTR("ex_write_data_to_field", obj_desc);
227 223
228 /* Parameter validation */ 224 /* Parameter validation */
229 225
230 if (!source_desc || !obj_desc) { 226 if (!source_desc || !obj_desc) {
231 return_ACPI_STATUS (AE_AML_NO_OPERAND); 227 return_ACPI_STATUS(AE_AML_NO_OPERAND);
232 } 228 }
233 229
234 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_BUFFER_FIELD) { 230 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_BUFFER_FIELD) {
235 /* 231 /*
236 * If the buffer_field arguments have not been previously evaluated, 232 * If the buffer_field arguments have not been previously evaluated,
237 * evaluate them now and save the results. 233 * evaluate them now and save the results.
238 */ 234 */
239 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { 235 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
240 status = acpi_ds_get_buffer_field_arguments (obj_desc); 236 status = acpi_ds_get_buffer_field_arguments(obj_desc);
241 if (ACPI_FAILURE (status)) { 237 if (ACPI_FAILURE(status)) {
242 return_ACPI_STATUS (status); 238 return_ACPI_STATUS(status);
243 } 239 }
244 } 240 }
245 } 241 } else
246 else if ((ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD) && 242 if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD)
247 (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_SMBUS)) { 243 && (obj_desc->field.region_obj->region.space_id ==
244 ACPI_ADR_SPACE_SMBUS)) {
248 /* 245 /*
249 * This is an SMBus write. We will bypass the entire field mechanism 246 * This is an SMBus write. We will bypass the entire field mechanism
250 * and handoff the buffer directly to the handler. 247 * and handoff the buffer directly to the handler.
251 * 248 *
252 * Source must be a buffer of sufficient size (ACPI_SMBUS_BUFFER_SIZE). 249 * Source must be a buffer of sufficient size (ACPI_SMBUS_BUFFER_SIZE).
253 */ 250 */
254 if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) { 251 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) {
255 ACPI_REPORT_ERROR (("SMBus write requires Buffer, found type %s\n", 252 ACPI_REPORT_ERROR(("SMBus write requires Buffer, found type %s\n", acpi_ut_get_object_type_name(source_desc)));
256 acpi_ut_get_object_type_name (source_desc)));
257 253
258 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 254 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
259 } 255 }
260 256
261 if (source_desc->buffer.length < ACPI_SMBUS_BUFFER_SIZE) { 257 if (source_desc->buffer.length < ACPI_SMBUS_BUFFER_SIZE) {
262 ACPI_REPORT_ERROR (( 258 ACPI_REPORT_ERROR(("SMBus write requires Buffer of length %X, found length %X\n", ACPI_SMBUS_BUFFER_SIZE, source_desc->buffer.length));
263 "SMBus write requires Buffer of length %X, found length %X\n",
264 ACPI_SMBUS_BUFFER_SIZE, source_desc->buffer.length));
265 259
266 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); 260 return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
267 } 261 }
268 262
269 buffer_desc = acpi_ut_create_buffer_object (ACPI_SMBUS_BUFFER_SIZE); 263 buffer_desc =
264 acpi_ut_create_buffer_object(ACPI_SMBUS_BUFFER_SIZE);
270 if (!buffer_desc) { 265 if (!buffer_desc) {
271 return_ACPI_STATUS (AE_NO_MEMORY); 266 return_ACPI_STATUS(AE_NO_MEMORY);
272 } 267 }
273 268
274 buffer = buffer_desc->buffer.pointer; 269 buffer = buffer_desc->buffer.pointer;
275 ACPI_MEMCPY (buffer, source_desc->buffer.pointer, 270 ACPI_MEMCPY(buffer, source_desc->buffer.pointer,
276 ACPI_SMBUS_BUFFER_SIZE); 271 ACPI_SMBUS_BUFFER_SIZE);
277 272
278 /* Lock entire transaction if requested */ 273 /* Lock entire transaction if requested */
279 274
280 locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); 275 locked =
276 acpi_ex_acquire_global_lock(obj_desc->common_field.
277 field_flags);
281 278
282 /* 279 /*
283 * Perform the write (returns status and perhaps data in the 280 * Perform the write (returns status and perhaps data in the
284 * same buffer) 281 * same buffer)
285 * Note: SMBus protocol type is passed in upper 16-bits of Function. 282 * Note: SMBus protocol type is passed in upper 16-bits of Function.
286 */ 283 */
287 status = acpi_ex_access_region (obj_desc, 0, 284 status = acpi_ex_access_region(obj_desc, 0,
288 (acpi_integer *) buffer, 285 (acpi_integer *) buffer,
289 ACPI_WRITE | (obj_desc->field.attribute << 16)); 286 ACPI_WRITE | (obj_desc->field.
290 acpi_ex_release_global_lock (locked); 287 attribute << 16));
288 acpi_ex_release_global_lock(locked);
291 289
292 *result_desc = buffer_desc; 290 *result_desc = buffer_desc;
293 return_ACPI_STATUS (status); 291 return_ACPI_STATUS(status);
294 } 292 }
295 293
296 /* Get a pointer to the data to be written */ 294 /* Get a pointer to the data to be written */
297 295
298 switch (ACPI_GET_OBJECT_TYPE (source_desc)) { 296 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
299 case ACPI_TYPE_INTEGER: 297 case ACPI_TYPE_INTEGER:
300 buffer = &source_desc->integer.value; 298 buffer = &source_desc->integer.value;
301 length = sizeof (source_desc->integer.value); 299 length = sizeof(source_desc->integer.value);
302 break; 300 break;
303 301
304 case ACPI_TYPE_BUFFER: 302 case ACPI_TYPE_BUFFER:
@@ -312,7 +310,7 @@ acpi_ex_write_data_to_field (
312 break; 310 break;
313 311
314 default: 312 default:
315 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 313 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
316 } 314 }
317 315
318 /* 316 /*
@@ -322,15 +320,15 @@ acpi_ex_write_data_to_field (
322 * the ACPI specification. 320 * the ACPI specification.
323 */ 321 */
324 new_buffer = NULL; 322 new_buffer = NULL;
325 required_length = ACPI_ROUND_BITS_UP_TO_BYTES ( 323 required_length =
326 obj_desc->common_field.bit_length); 324 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length);
327 325
328 if (length < required_length) { 326 if (length < required_length) {
329 /* We need to create a new buffer */ 327 /* We need to create a new buffer */
330 328
331 new_buffer = ACPI_MEM_CALLOCATE (required_length); 329 new_buffer = ACPI_MEM_CALLOCATE(required_length);
332 if (!new_buffer) { 330 if (!new_buffer) {
333 return_ACPI_STATUS (AE_NO_MEMORY); 331 return_ACPI_STATUS(AE_NO_MEMORY);
334 } 332 }
335 333
336 /* 334 /*
@@ -338,40 +336,42 @@ acpi_ex_write_data_to_field (
338 * at Byte zero. All unused (upper) bytes of the 336 * at Byte zero. All unused (upper) bytes of the
339 * buffer will be 0. 337 * buffer will be 0.
340 */ 338 */
341 ACPI_MEMCPY ((char *) new_buffer, (char *) buffer, length); 339 ACPI_MEMCPY((char *)new_buffer, (char *)buffer, length);
342 buffer = new_buffer; 340 buffer = new_buffer;
343 length = required_length; 341 length = required_length;
344 } 342 }
345 343
346 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 344 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
347 "field_write [FROM]: Obj %p (%s:%X), Buf %p, byte_len %X\n", 345 "field_write [FROM]: Obj %p (%s:%X), Buf %p, byte_len %X\n",
348 source_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (source_desc)), 346 source_desc,
349 ACPI_GET_OBJECT_TYPE (source_desc), buffer, length)); 347 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE
350 348 (source_desc)),
351 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 349 ACPI_GET_OBJECT_TYPE(source_desc), buffer, length));
352 "field_write [TO]: Obj %p (%s:%X), bit_len %X, bit_off %X, byte_off %X\n", 350
353 obj_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (obj_desc)), 351 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
354 ACPI_GET_OBJECT_TYPE (obj_desc), 352 "field_write [TO]: Obj %p (%s:%X), bit_len %X, bit_off %X, byte_off %X\n",
355 obj_desc->common_field.bit_length, 353 obj_desc,
356 obj_desc->common_field.start_field_bit_offset, 354 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE(obj_desc)),
357 obj_desc->common_field.base_byte_offset)); 355 ACPI_GET_OBJECT_TYPE(obj_desc),
356 obj_desc->common_field.bit_length,
357 obj_desc->common_field.start_field_bit_offset,
358 obj_desc->common_field.base_byte_offset));
358 359
359 /* Lock entire transaction if requested */ 360 /* Lock entire transaction if requested */
360 361
361 locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); 362 locked =
363 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
362 364
363 /* Write to the field */ 365 /* Write to the field */
364 366
365 status = acpi_ex_insert_into_field (obj_desc, buffer, length); 367 status = acpi_ex_insert_into_field(obj_desc, buffer, length);
366 acpi_ex_release_global_lock (locked); 368 acpi_ex_release_global_lock(locked);
367 369
368 /* Free temporary buffer if we used one */ 370 /* Free temporary buffer if we used one */
369 371
370 if (new_buffer) { 372 if (new_buffer) {
371 ACPI_MEM_FREE (new_buffer); 373 ACPI_MEM_FREE(new_buffer);
372 } 374 }
373 375
374 return_ACPI_STATUS (status); 376 return_ACPI_STATUS(status);
375} 377}
376
377