1
2
3
4
5
6
7
8
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acdispat.h"
13#include "acinterp.h"
14#include "amlcode.h"
15
16#define _COMPONENT ACPI_EXECUTER
17ACPI_MODULE_NAME("exserial")
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32acpi_status acpi_ex_read_gpio(union acpi_operand_object *obj_desc, void *buffer)
33{
34 acpi_status status;
35
36 ACPI_FUNCTION_TRACE_PTR(ex_read_gpio, obj_desc);
37
38
39
40
41
42
43
44 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
45 "GPIO FieldRead [FROM]: Pin %u Bits %u\n",
46 obj_desc->field.pin_number_index,
47 obj_desc->field.bit_length));
48
49
50
51 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
52
53
54
55 status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, ACPI_READ);
56
57 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
58 return_ACPI_STATUS(status);
59}
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77acpi_status
78acpi_ex_write_gpio(union acpi_operand_object *source_desc,
79 union acpi_operand_object *obj_desc,
80 union acpi_operand_object **return_buffer)
81{
82 acpi_status status;
83 void *buffer;
84
85 ACPI_FUNCTION_TRACE_PTR(ex_write_gpio, obj_desc);
86
87
88
89
90
91
92
93
94
95 if (source_desc->common.type != ACPI_TYPE_INTEGER) {
96 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
97 }
98
99 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
100 "GPIO FieldWrite [FROM]: (%s:%X), Value %.8X [TO]: Pin %u Bits %u\n",
101 acpi_ut_get_type_name(source_desc->common.type),
102 source_desc->common.type,
103 (u32)source_desc->integer.value,
104 obj_desc->field.pin_number_index,
105 obj_desc->field.bit_length));
106
107 buffer = &source_desc->integer.value;
108
109
110
111 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
112
113
114
115 status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, ACPI_WRITE);
116 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
117 return_ACPI_STATUS(status);
118}
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134acpi_status
135acpi_ex_read_serial_bus(union acpi_operand_object *obj_desc,
136 union acpi_operand_object **return_buffer)
137{
138 acpi_status status;
139 u32 buffer_length;
140 union acpi_operand_object *buffer_desc;
141 u32 function;
142 u16 accessor_type;
143
144 ACPI_FUNCTION_TRACE_PTR(ex_read_serial_bus, obj_desc);
145
146
147
148
149
150
151
152
153
154
155
156
157
158 switch (obj_desc->field.region_obj->region.space_id) {
159 case ACPI_ADR_SPACE_SMBUS:
160
161 buffer_length = ACPI_SMBUS_BUFFER_SIZE;
162 function = ACPI_READ | (obj_desc->field.attribute << 16);
163 break;
164
165 case ACPI_ADR_SPACE_IPMI:
166
167 buffer_length = ACPI_IPMI_BUFFER_SIZE;
168 function = ACPI_READ;
169 break;
170
171 case ACPI_ADR_SPACE_GSBUS:
172
173 accessor_type = obj_desc->field.attribute;
174 if (accessor_type == AML_FIELD_ATTRIB_RAW_PROCESS_BYTES) {
175 ACPI_ERROR((AE_INFO,
176 "Invalid direct read using bidirectional write-then-read protocol"));
177
178 return_ACPI_STATUS(AE_AML_PROTOCOL);
179 }
180
181 status =
182 acpi_ex_get_protocol_buffer_length(accessor_type,
183 &buffer_length);
184 if (ACPI_FAILURE(status)) {
185 ACPI_ERROR((AE_INFO,
186 "Invalid protocol ID for GSBus: 0x%4.4X",
187 accessor_type));
188
189 return_ACPI_STATUS(status);
190 }
191
192
193
194 buffer_length += ACPI_SERIAL_HEADER_SIZE;
195 function = ACPI_READ | (accessor_type << 16);
196 break;
197
198 case ACPI_ADR_SPACE_PLATFORM_RT:
199
200 buffer_length = ACPI_PRM_INPUT_BUFFER_SIZE;
201 function = ACPI_READ;
202 break;
203
204 default:
205 return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID);
206 }
207
208
209
210 buffer_desc = acpi_ut_create_buffer_object(buffer_length);
211 if (!buffer_desc) {
212 return_ACPI_STATUS(AE_NO_MEMORY);
213 }
214
215
216
217 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
218
219
220
221 status = acpi_ex_access_region(obj_desc, 0,
222 ACPI_CAST_PTR(u64,
223 buffer_desc->buffer.
224 pointer), function);
225 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
226
227 *return_buffer = buffer_desc;
228 return_ACPI_STATUS(status);
229}
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246acpi_status
247acpi_ex_write_serial_bus(union acpi_operand_object *source_desc,
248 union acpi_operand_object *obj_desc,
249 union acpi_operand_object **return_buffer)
250{
251 acpi_status status;
252 u32 buffer_length;
253 u32 data_length;
254 void *buffer;
255 union acpi_operand_object *buffer_desc;
256 u32 function;
257 u16 accessor_type;
258
259 ACPI_FUNCTION_TRACE_PTR(ex_write_serial_bus, obj_desc);
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278 if (source_desc->common.type != ACPI_TYPE_BUFFER) {
279 ACPI_ERROR((AE_INFO,
280 "SMBus/IPMI/GenericSerialBus write requires "
281 "Buffer, found type %s",
282 acpi_ut_get_object_type_name(source_desc)));
283
284 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
285 }
286
287 switch (obj_desc->field.region_obj->region.space_id) {
288 case ACPI_ADR_SPACE_SMBUS:
289
290 buffer_length = ACPI_SMBUS_BUFFER_SIZE;
291 function = ACPI_WRITE | (obj_desc->field.attribute << 16);
292 break;
293
294 case ACPI_ADR_SPACE_IPMI:
295
296 buffer_length = ACPI_IPMI_BUFFER_SIZE;
297 function = ACPI_WRITE;
298 break;
299
300 case ACPI_ADR_SPACE_GSBUS:
301
302 accessor_type = obj_desc->field.attribute;
303 status =
304 acpi_ex_get_protocol_buffer_length(accessor_type,
305 &buffer_length);
306 if (ACPI_FAILURE(status)) {
307 ACPI_ERROR((AE_INFO,
308 "Invalid protocol ID for GSBus: 0x%4.4X",
309 accessor_type));
310
311 return_ACPI_STATUS(status);
312 }
313
314
315
316 buffer_length += ACPI_SERIAL_HEADER_SIZE;
317 function = ACPI_WRITE | (accessor_type << 16);
318 break;
319
320 case ACPI_ADR_SPACE_PLATFORM_RT:
321
322 buffer_length = ACPI_PRM_INPUT_BUFFER_SIZE;
323 function = ACPI_WRITE;
324 break;
325
326 default:
327 return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID);
328 }
329
330
331
332 buffer_desc = acpi_ut_create_buffer_object(buffer_length);
333 if (!buffer_desc) {
334 return_ACPI_STATUS(AE_NO_MEMORY);
335 }
336
337
338
339 buffer = buffer_desc->buffer.pointer;
340 data_length = (buffer_length < source_desc->buffer.length ?
341 buffer_length : source_desc->buffer.length);
342 memcpy(buffer, source_desc->buffer.pointer, data_length);
343
344
345
346 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
347
348
349
350
351
352 status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, function);
353 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
354
355 *return_buffer = buffer_desc;
356 return_ACPI_STATUS(status);
357}
358