1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/******************************************************************************
*
* Module Name: amfield - ACPI AML (p-code) execution - field manipulation
*
*****************************************************************************/
/*
* Copyright (C) 2000 R. Byron Moore
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "acpi.h"
#include "dispatch.h"
#include "interp.h"
#include "amlcode.h"
#include "namesp.h"
#include "hardware.h"
#include "events.h"
#define _COMPONENT INTERPRETER
MODULE_NAME ("amfield");
/*******************************************************************************
*
* FUNCTION: Acpi_aml_setup_field
*
* PARAMETERS: *Obj_desc - Field to be read or written
* *Rgn_desc - Region containing field
* Field_bit_width - Field Width in bits (8, 16, or 32)
*
* RETURN: Status
*
* DESCRIPTION: Common processing for Acpi_aml_read_field and Acpi_aml_write_field
*
* ACPI SPECIFICATION REFERENCES:
* Each of the Type1_opcodes is defined as specified in in-line
* comments below. For each one, use the following definitions.
*
* Def_bit_field := Bit_field_op Src_buf Bit_idx Destination
* Def_byte_field := Byte_field_op Src_buf Byte_idx Destination
* Def_create_field := Create_field_op Src_buf Bit_idx Num_bits Name_string
* Def_dWord_field := DWord_field_op Src_buf Byte_idx Destination
* Def_word_field := Word_field_op Src_buf Byte_idx Destination
* Bit_index := Term_arg=>Integer
* Byte_index := Term_arg=>Integer
* Destination := Name_string
* Num_bits := Term_arg=>Integer
* Source_buf := Term_arg=>Buffer
*
******************************************************************************/
ACPI_STATUS
acpi_aml_setup_field (
ACPI_OBJECT_INTERNAL *obj_desc,
ACPI_OBJECT_INTERNAL *rgn_desc,
s32 field_bit_width)
{
ACPI_STATUS status = AE_OK;
s32 field_byte_width;
/* Parameter validation */
if (!obj_desc || !rgn_desc) {
return (AE_AML_NO_OPERAND);
}
if (ACPI_TYPE_REGION != rgn_desc->common.type) {
return (AE_AML_OPERAND_TYPE);
}
/*
* Init and validate Field width
* Possible values are 1, 2, 4
*/
field_byte_width = DIV_8 (field_bit_width);
if ((field_bit_width != 8) &&
(field_bit_width != 16) &&
(field_bit_width != 32))
{
return (AE_AML_OPERAND_VALUE);
}
/*
* If the address and length have not been previously evaluated,
* evaluate them and save the results.
*/
if (!(rgn_desc->region.region_flags & REGION_AGRUMENT_DATA_VALID)) {
status = acpi_ds_get_region_arguments (rgn_desc);
if (ACPI_FAILURE (status)) {
return (status);
}
}
/*
* If (offset rounded up to next multiple of field width)
* exceeds region length, indicate an error.
*/
if (rgn_desc->region.length <
(obj_desc->field.offset & ~((u32) field_byte_width - 1)) +
field_byte_width)
{
/*
* Offset rounded up to next multiple of field width
* exceeds region length, indicate an error
*/
return (AE_AML_REGION_LIMIT);
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_access_named_field
*
* PARAMETERS: Mode - ACPI_READ or ACPI_WRITE
* Named_field - Handle for field to be accessed
* *Buffer - Value(s) to be read or written
* Buffer_length - Number of bytes to transfer
*
* RETURN: Status
*
* DESCRIPTION: Read or write a named field
*
******************************************************************************/
ACPI_STATUS
acpi_aml_access_named_field (
s32 mode,
ACPI_HANDLE named_field,
void *buffer,
u32 buffer_length)
{
ACPI_OBJECT_INTERNAL *obj_desc = NULL;
ACPI_STATUS status = AE_OK;
u8 locked = FALSE;
u32 bit_granularity = 0;
u32 byte_granularity;
u32 datum_length;
u32 actual_byte_length;
u32 byte_field_length;
/* Get the attached field object */
obj_desc = acpi_ns_get_attached_object (named_field);
if (!obj_desc) {
return (AE_AML_INTERNAL);
}
/* Check the type */
if (INTERNAL_TYPE_DEF_FIELD != acpi_ns_get_type (named_field)) {
return (AE_AML_OPERAND_TYPE);
}
/* Obj_desc valid and Named_field is a defined field */
/* Double-check that the attached object is also a field */
if (INTERNAL_TYPE_DEF_FIELD != obj_desc->common.type) {
return (AE_AML_OPERAND_TYPE);
}
/*
* Granularity was decoded from the field access type
* (Any_acc will be the same as Byte_acc)
*/
bit_granularity = obj_desc->field_unit.granularity;
byte_granularity = DIV_8 (bit_granularity);
/*
* Check if request is too large for the field, and silently truncate
* if necessary
*/
/* TBD: [Errors] should an error be returned in this case? */
byte_field_length = (u32) DIV_8 (obj_desc->field_unit.length + 7);
actual_byte_length = buffer_length;
if (buffer_length > byte_field_length) {
actual_byte_length = byte_field_length;
}
/* Convert byte count to datum count, round up if necessary */
datum_length = (actual_byte_length + (byte_granularity-1)) / byte_granularity;
/* Get the global lock if needed */
locked = acpi_aml_acquire_global_lock (obj_desc->field_unit.lock_rule);
/* Perform the actual read or write of the buffer */
switch (mode)
{
case ACPI_READ:
status = acpi_aml_read_field (obj_desc, buffer, buffer_length,
actual_byte_length, datum_length,
bit_granularity, byte_granularity);
break;
case ACPI_WRITE:
status = acpi_aml_write_field (obj_desc, buffer, buffer_length,
actual_byte_length, datum_length,
bit_granularity, byte_granularity);
break;
default:
status = AE_BAD_PARAMETER;
break;
}
/* Release global lock if we acquired it earlier */
acpi_aml_release_global_lock (locked);
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_set_named_field_value
*
* PARAMETERS: Named_field - Handle for field to be set
* Buffer - Bytes to be stored
* Buffer_length - Number of bytes to be stored
*
* RETURN: Status
*
* DESCRIPTION: Store the given value into the field
*
******************************************************************************/
ACPI_STATUS
acpi_aml_set_named_field_value (
ACPI_HANDLE named_field,
void *buffer,
u32 buffer_length)
{
ACPI_STATUS status;
if (!named_field) {
return (AE_AML_INTERNAL);
}
status = acpi_aml_access_named_field (ACPI_WRITE, named_field, buffer,
buffer_length);
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_get_named_field_value
*
* PARAMETERS: Named_field - Handle for field to be read
* *Buffer - Where to store value read from field
* Buffer_length - Max length to read
*
* RETURN: Status
*
* DESCRIPTION: Retrieve the value of the given field
*
******************************************************************************/
ACPI_STATUS
acpi_aml_get_named_field_value (
ACPI_HANDLE named_field,
void *buffer,
u32 buffer_length)
{
ACPI_STATUS status;
if ((!named_field) || (!buffer)) {
return (AE_AML_INTERNAL);
}
status = acpi_aml_access_named_field (ACPI_READ, named_field, buffer,
buffer_length);
return (status);
}
|