exfield.c revision 1.1.1.4 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: exfield - ACPI AML (p-code) execution - field manipulation
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.4 christos * Copyright (C) 2000 - 2014, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #define __EXFIELD_C__
45 1.1 jruoho
46 1.1 jruoho #include "acpi.h"
47 1.1 jruoho #include "accommon.h"
48 1.1 jruoho #include "acdispat.h"
49 1.1 jruoho #include "acinterp.h"
50 1.1.1.4 christos #include "amlcode.h"
51 1.1 jruoho
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_EXECUTER
54 1.1 jruoho ACPI_MODULE_NAME ("exfield")
55 1.1 jruoho
56 1.1.1.4 christos /* Local prototypes */
57 1.1.1.4 christos
58 1.1.1.4 christos static UINT32
59 1.1.1.4 christos AcpiExGetSerialAccessLength (
60 1.1.1.4 christos UINT32 AccessorType,
61 1.1.1.4 christos UINT32 AccessLength);
62 1.1.1.4 christos
63 1.1.1.4 christos
64 1.1.1.4 christos /*******************************************************************************
65 1.1.1.4 christos *
66 1.1.1.4 christos * FUNCTION: AcpiExGetSerialAccessLength
67 1.1.1.4 christos *
68 1.1.1.4 christos * PARAMETERS: AccessorType - The type of the protocol indicated by region
69 1.1.1.4 christos * field access attributes
70 1.1.1.4 christos * AccessLength - The access length of the region field
71 1.1.1.4 christos *
72 1.1.1.4 christos * RETURN: Decoded access length
73 1.1.1.4 christos *
74 1.1.1.4 christos * DESCRIPTION: This routine returns the length of the GenericSerialBus
75 1.1.1.4 christos * protocol bytes
76 1.1.1.4 christos *
77 1.1.1.4 christos ******************************************************************************/
78 1.1.1.4 christos
79 1.1.1.4 christos static UINT32
80 1.1.1.4 christos AcpiExGetSerialAccessLength (
81 1.1.1.4 christos UINT32 AccessorType,
82 1.1.1.4 christos UINT32 AccessLength)
83 1.1.1.4 christos {
84 1.1.1.4 christos UINT32 Length;
85 1.1.1.4 christos
86 1.1.1.4 christos
87 1.1.1.4 christos switch (AccessorType)
88 1.1.1.4 christos {
89 1.1.1.4 christos case AML_FIELD_ATTRIB_QUICK:
90 1.1.1.4 christos
91 1.1.1.4 christos Length = 0;
92 1.1.1.4 christos break;
93 1.1.1.4 christos
94 1.1.1.4 christos case AML_FIELD_ATTRIB_SEND_RCV:
95 1.1.1.4 christos case AML_FIELD_ATTRIB_BYTE:
96 1.1.1.4 christos
97 1.1.1.4 christos Length = 1;
98 1.1.1.4 christos break;
99 1.1.1.4 christos
100 1.1.1.4 christos case AML_FIELD_ATTRIB_WORD:
101 1.1.1.4 christos case AML_FIELD_ATTRIB_WORD_CALL:
102 1.1.1.4 christos
103 1.1.1.4 christos Length = 2;
104 1.1.1.4 christos break;
105 1.1.1.4 christos
106 1.1.1.4 christos case AML_FIELD_ATTRIB_MULTIBYTE:
107 1.1.1.4 christos case AML_FIELD_ATTRIB_RAW_BYTES:
108 1.1.1.4 christos case AML_FIELD_ATTRIB_RAW_PROCESS:
109 1.1.1.4 christos
110 1.1.1.4 christos Length = AccessLength;
111 1.1.1.4 christos break;
112 1.1.1.4 christos
113 1.1.1.4 christos case AML_FIELD_ATTRIB_BLOCK:
114 1.1.1.4 christos case AML_FIELD_ATTRIB_BLOCK_CALL:
115 1.1.1.4 christos default:
116 1.1.1.4 christos
117 1.1.1.4 christos Length = ACPI_GSBUS_BUFFER_SIZE - 2;
118 1.1.1.4 christos break;
119 1.1.1.4 christos }
120 1.1.1.4 christos
121 1.1.1.4 christos return (Length);
122 1.1.1.4 christos }
123 1.1.1.4 christos
124 1.1 jruoho
125 1.1 jruoho /*******************************************************************************
126 1.1 jruoho *
127 1.1 jruoho * FUNCTION: AcpiExReadDataFromField
128 1.1 jruoho *
129 1.1 jruoho * PARAMETERS: WalkState - Current execution state
130 1.1 jruoho * ObjDesc - The named field
131 1.1 jruoho * RetBufferDesc - Where the return data object is stored
132 1.1 jruoho *
133 1.1 jruoho * RETURN: Status
134 1.1 jruoho *
135 1.1.1.3 christos * DESCRIPTION: Read from a named field. Returns either an Integer or a
136 1.1 jruoho * Buffer, depending on the size of the field.
137 1.1 jruoho *
138 1.1 jruoho ******************************************************************************/
139 1.1 jruoho
140 1.1 jruoho ACPI_STATUS
141 1.1 jruoho AcpiExReadDataFromField (
142 1.1 jruoho ACPI_WALK_STATE *WalkState,
143 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
144 1.1 jruoho ACPI_OPERAND_OBJECT **RetBufferDesc)
145 1.1 jruoho {
146 1.1 jruoho ACPI_STATUS Status;
147 1.1 jruoho ACPI_OPERAND_OBJECT *BufferDesc;
148 1.1 jruoho ACPI_SIZE Length;
149 1.1 jruoho void *Buffer;
150 1.1 jruoho UINT32 Function;
151 1.1.1.4 christos UINT16 AccessorType;
152 1.1 jruoho
153 1.1 jruoho
154 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc);
155 1.1 jruoho
156 1.1 jruoho
157 1.1 jruoho /* Parameter validation */
158 1.1 jruoho
159 1.1 jruoho if (!ObjDesc)
160 1.1 jruoho {
161 1.1 jruoho return_ACPI_STATUS (AE_AML_NO_OPERAND);
162 1.1 jruoho }
163 1.1 jruoho if (!RetBufferDesc)
164 1.1 jruoho {
165 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
166 1.1 jruoho }
167 1.1 jruoho
168 1.1 jruoho if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
169 1.1 jruoho {
170 1.1 jruoho /*
171 1.1 jruoho * If the BufferField arguments have not been previously evaluated,
172 1.1 jruoho * evaluate them now and save the results.
173 1.1 jruoho */
174 1.1 jruoho if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
175 1.1 jruoho {
176 1.1 jruoho Status = AcpiDsGetBufferFieldArguments (ObjDesc);
177 1.1 jruoho if (ACPI_FAILURE (Status))
178 1.1 jruoho {
179 1.1 jruoho return_ACPI_STATUS (Status);
180 1.1 jruoho }
181 1.1 jruoho }
182 1.1 jruoho }
183 1.1 jruoho else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
184 1.1 jruoho (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
185 1.1.1.3 christos ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
186 1.1 jruoho ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
187 1.1 jruoho {
188 1.1 jruoho /*
189 1.1.1.3 christos * This is an SMBus, GSBus or IPMI read. We must create a buffer to hold
190 1.1 jruoho * the data and then directly access the region handler.
191 1.1 jruoho *
192 1.1.1.3 christos * Note: SMBus and GSBus protocol value is passed in upper 16-bits of Function
193 1.1 jruoho */
194 1.1 jruoho if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS)
195 1.1 jruoho {
196 1.1 jruoho Length = ACPI_SMBUS_BUFFER_SIZE;
197 1.1 jruoho Function = ACPI_READ | (ObjDesc->Field.Attribute << 16);
198 1.1 jruoho }
199 1.1.1.3 christos else if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS)
200 1.1.1.3 christos {
201 1.1.1.4 christos AccessorType = ObjDesc->Field.Attribute;
202 1.1.1.4 christos Length = AcpiExGetSerialAccessLength (AccessorType,
203 1.1.1.4 christos ObjDesc->Field.AccessLength);
204 1.1.1.4 christos
205 1.1.1.4 christos /*
206 1.1.1.4 christos * Add additional 2 bytes for the GenericSerialBus data buffer:
207 1.1.1.4 christos *
208 1.1.1.4 christos * Status; (Byte 0 of the data buffer)
209 1.1.1.4 christos * Length; (Byte 1 of the data buffer)
210 1.1.1.4 christos * Data[x-1]; (Bytes 2-x of the arbitrary length data buffer)
211 1.1.1.4 christos */
212 1.1.1.4 christos Length += 2;
213 1.1.1.4 christos Function = ACPI_READ | (AccessorType << 16);
214 1.1.1.3 christos }
215 1.1 jruoho else /* IPMI */
216 1.1 jruoho {
217 1.1 jruoho Length = ACPI_IPMI_BUFFER_SIZE;
218 1.1 jruoho Function = ACPI_READ;
219 1.1 jruoho }
220 1.1 jruoho
221 1.1 jruoho BufferDesc = AcpiUtCreateBufferObject (Length);
222 1.1 jruoho if (!BufferDesc)
223 1.1 jruoho {
224 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
225 1.1 jruoho }
226 1.1 jruoho
227 1.1 jruoho /* Lock entire transaction if requested */
228 1.1 jruoho
229 1.1 jruoho AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
230 1.1 jruoho
231 1.1 jruoho /* Call the region handler for the read */
232 1.1 jruoho
233 1.1 jruoho Status = AcpiExAccessRegion (ObjDesc, 0,
234 1.1 jruoho ACPI_CAST_PTR (UINT64, BufferDesc->Buffer.Pointer),
235 1.1 jruoho Function);
236 1.1 jruoho AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
237 1.1 jruoho goto Exit;
238 1.1 jruoho }
239 1.1 jruoho
240 1.1 jruoho /*
241 1.1 jruoho * Allocate a buffer for the contents of the field.
242 1.1 jruoho *
243 1.1 jruoho * If the field is larger than the current integer width, create
244 1.1.1.3 christos * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
245 1.1 jruoho * the use of arithmetic operators on the returned value if the
246 1.1 jruoho * field size is equal or smaller than an Integer.
247 1.1 jruoho *
248 1.1 jruoho * Note: Field.length is in bits.
249 1.1 jruoho */
250 1.1 jruoho Length = (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (ObjDesc->Field.BitLength);
251 1.1 jruoho if (Length > AcpiGbl_IntegerByteWidth)
252 1.1 jruoho {
253 1.1 jruoho /* Field is too large for an Integer, create a Buffer instead */
254 1.1 jruoho
255 1.1 jruoho BufferDesc = AcpiUtCreateBufferObject (Length);
256 1.1 jruoho if (!BufferDesc)
257 1.1 jruoho {
258 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
259 1.1 jruoho }
260 1.1 jruoho Buffer = BufferDesc->Buffer.Pointer;
261 1.1 jruoho }
262 1.1 jruoho else
263 1.1 jruoho {
264 1.1 jruoho /* Field will fit within an Integer (normal case) */
265 1.1 jruoho
266 1.1 jruoho BufferDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
267 1.1 jruoho if (!BufferDesc)
268 1.1 jruoho {
269 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
270 1.1 jruoho }
271 1.1 jruoho
272 1.1 jruoho Length = AcpiGbl_IntegerByteWidth;
273 1.1 jruoho Buffer = &BufferDesc->Integer.Value;
274 1.1 jruoho }
275 1.1 jruoho
276 1.1.1.4 christos if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
277 1.1.1.4 christos (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO))
278 1.1.1.4 christos {
279 1.1.1.4 christos /*
280 1.1.1.4 christos * For GPIO (GeneralPurposeIo), the Address will be the bit offset
281 1.1.1.4 christos * from the previous Connection() operator, making it effectively a
282 1.1.1.4 christos * pin number index. The BitLength is the length of the field, which
283 1.1.1.4 christos * is thus the number of pins.
284 1.1.1.4 christos */
285 1.1.1.4 christos ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
286 1.1.1.4 christos "GPIO FieldRead [FROM]: Pin %u Bits %u\n",
287 1.1.1.4 christos ObjDesc->Field.PinNumberIndex, ObjDesc->Field.BitLength));
288 1.1.1.4 christos
289 1.1.1.4 christos /* Lock entire transaction if requested */
290 1.1.1.4 christos
291 1.1.1.4 christos AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
292 1.1.1.4 christos
293 1.1.1.4 christos /* Perform the write */
294 1.1.1.4 christos
295 1.1.1.4 christos Status = AcpiExAccessRegion (ObjDesc, 0,
296 1.1.1.4 christos (UINT64 *) Buffer, ACPI_READ);
297 1.1.1.4 christos AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
298 1.1.1.4 christos if (ACPI_FAILURE (Status))
299 1.1.1.4 christos {
300 1.1.1.4 christos AcpiUtRemoveReference (BufferDesc);
301 1.1.1.4 christos }
302 1.1.1.4 christos else
303 1.1.1.4 christos {
304 1.1.1.4 christos *RetBufferDesc = BufferDesc;
305 1.1.1.4 christos }
306 1.1.1.4 christos return_ACPI_STATUS (Status);
307 1.1.1.4 christos }
308 1.1.1.4 christos
309 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
310 1.1 jruoho "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n",
311 1.1 jruoho ObjDesc, ObjDesc->Common.Type, Buffer, (UINT32) Length));
312 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
313 1.1 jruoho "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
314 1.1 jruoho ObjDesc->CommonField.BitLength,
315 1.1 jruoho ObjDesc->CommonField.StartFieldBitOffset,
316 1.1 jruoho ObjDesc->CommonField.BaseByteOffset));
317 1.1 jruoho
318 1.1 jruoho /* Lock entire transaction if requested */
319 1.1 jruoho
320 1.1 jruoho AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
321 1.1 jruoho
322 1.1 jruoho /* Read from the field */
323 1.1 jruoho
324 1.1 jruoho Status = AcpiExExtractFromField (ObjDesc, Buffer, (UINT32) Length);
325 1.1 jruoho AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
326 1.1 jruoho
327 1.1 jruoho
328 1.1 jruoho Exit:
329 1.1 jruoho if (ACPI_FAILURE (Status))
330 1.1 jruoho {
331 1.1 jruoho AcpiUtRemoveReference (BufferDesc);
332 1.1 jruoho }
333 1.1 jruoho else
334 1.1 jruoho {
335 1.1 jruoho *RetBufferDesc = BufferDesc;
336 1.1 jruoho }
337 1.1 jruoho
338 1.1 jruoho return_ACPI_STATUS (Status);
339 1.1 jruoho }
340 1.1 jruoho
341 1.1 jruoho
342 1.1 jruoho /*******************************************************************************
343 1.1 jruoho *
344 1.1 jruoho * FUNCTION: AcpiExWriteDataToField
345 1.1 jruoho *
346 1.1 jruoho * PARAMETERS: SourceDesc - Contains data to write
347 1.1 jruoho * ObjDesc - The named field
348 1.1 jruoho * ResultDesc - Where the return value is returned, if any
349 1.1 jruoho *
350 1.1 jruoho * RETURN: Status
351 1.1 jruoho *
352 1.1 jruoho * DESCRIPTION: Write to a named field
353 1.1 jruoho *
354 1.1 jruoho ******************************************************************************/
355 1.1 jruoho
356 1.1 jruoho ACPI_STATUS
357 1.1 jruoho AcpiExWriteDataToField (
358 1.1 jruoho ACPI_OPERAND_OBJECT *SourceDesc,
359 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
360 1.1 jruoho ACPI_OPERAND_OBJECT **ResultDesc)
361 1.1 jruoho {
362 1.1 jruoho ACPI_STATUS Status;
363 1.1 jruoho UINT32 Length;
364 1.1 jruoho void *Buffer;
365 1.1 jruoho ACPI_OPERAND_OBJECT *BufferDesc;
366 1.1 jruoho UINT32 Function;
367 1.1.1.4 christos UINT16 AccessorType;
368 1.1 jruoho
369 1.1 jruoho
370 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc);
371 1.1 jruoho
372 1.1 jruoho
373 1.1 jruoho /* Parameter validation */
374 1.1 jruoho
375 1.1 jruoho if (!SourceDesc || !ObjDesc)
376 1.1 jruoho {
377 1.1 jruoho return_ACPI_STATUS (AE_AML_NO_OPERAND);
378 1.1 jruoho }
379 1.1 jruoho
380 1.1 jruoho if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
381 1.1 jruoho {
382 1.1 jruoho /*
383 1.1 jruoho * If the BufferField arguments have not been previously evaluated,
384 1.1 jruoho * evaluate them now and save the results.
385 1.1 jruoho */
386 1.1 jruoho if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
387 1.1 jruoho {
388 1.1 jruoho Status = AcpiDsGetBufferFieldArguments (ObjDesc);
389 1.1 jruoho if (ACPI_FAILURE (Status))
390 1.1 jruoho {
391 1.1 jruoho return_ACPI_STATUS (Status);
392 1.1 jruoho }
393 1.1 jruoho }
394 1.1 jruoho }
395 1.1 jruoho else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
396 1.1 jruoho (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
397 1.1.1.3 christos ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
398 1.1 jruoho ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
399 1.1 jruoho {
400 1.1 jruoho /*
401 1.1.1.3 christos * This is an SMBus, GSBus or IPMI write. We will bypass the entire field
402 1.1 jruoho * mechanism and handoff the buffer directly to the handler. For
403 1.1 jruoho * these address spaces, the buffer is bi-directional; on a write,
404 1.1 jruoho * return data is returned in the same buffer.
405 1.1 jruoho *
406 1.1 jruoho * Source must be a buffer of sufficient size:
407 1.1.1.3 christos * ACPI_SMBUS_BUFFER_SIZE, ACPI_GSBUS_BUFFER_SIZE, or ACPI_IPMI_BUFFER_SIZE.
408 1.1 jruoho *
409 1.1.1.3 christos * Note: SMBus and GSBus protocol type is passed in upper 16-bits of Function
410 1.1 jruoho */
411 1.1 jruoho if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)
412 1.1 jruoho {
413 1.1 jruoho ACPI_ERROR ((AE_INFO,
414 1.1.1.3 christos "SMBus/IPMI/GenericSerialBus write requires Buffer, found type %s",
415 1.1 jruoho AcpiUtGetObjectTypeName (SourceDesc)));
416 1.1 jruoho
417 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
418 1.1 jruoho }
419 1.1 jruoho
420 1.1 jruoho if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS)
421 1.1 jruoho {
422 1.1 jruoho Length = ACPI_SMBUS_BUFFER_SIZE;
423 1.1 jruoho Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16);
424 1.1 jruoho }
425 1.1.1.3 christos else if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS)
426 1.1.1.3 christos {
427 1.1.1.4 christos AccessorType = ObjDesc->Field.Attribute;
428 1.1.1.4 christos Length = AcpiExGetSerialAccessLength (AccessorType,
429 1.1.1.4 christos ObjDesc->Field.AccessLength);
430 1.1.1.4 christos
431 1.1.1.4 christos /*
432 1.1.1.4 christos * Add additional 2 bytes for the GenericSerialBus data buffer:
433 1.1.1.4 christos *
434 1.1.1.4 christos * Status; (Byte 0 of the data buffer)
435 1.1.1.4 christos * Length; (Byte 1 of the data buffer)
436 1.1.1.4 christos * Data[x-1]; (Bytes 2-x of the arbitrary length data buffer)
437 1.1.1.4 christos */
438 1.1.1.4 christos Length += 2;
439 1.1.1.4 christos Function = ACPI_WRITE | (AccessorType << 16);
440 1.1.1.3 christos }
441 1.1 jruoho else /* IPMI */
442 1.1 jruoho {
443 1.1 jruoho Length = ACPI_IPMI_BUFFER_SIZE;
444 1.1 jruoho Function = ACPI_WRITE;
445 1.1 jruoho }
446 1.1 jruoho
447 1.1 jruoho if (SourceDesc->Buffer.Length < Length)
448 1.1 jruoho {
449 1.1 jruoho ACPI_ERROR ((AE_INFO,
450 1.1.1.3 christos "SMBus/IPMI/GenericSerialBus write requires Buffer of length %u, found length %u",
451 1.1 jruoho Length, SourceDesc->Buffer.Length));
452 1.1 jruoho
453 1.1 jruoho return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
454 1.1 jruoho }
455 1.1 jruoho
456 1.1 jruoho /* Create the bi-directional buffer */
457 1.1 jruoho
458 1.1 jruoho BufferDesc = AcpiUtCreateBufferObject (Length);
459 1.1 jruoho if (!BufferDesc)
460 1.1 jruoho {
461 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
462 1.1 jruoho }
463 1.1 jruoho
464 1.1 jruoho Buffer = BufferDesc->Buffer.Pointer;
465 1.1 jruoho ACPI_MEMCPY (Buffer, SourceDesc->Buffer.Pointer, Length);
466 1.1 jruoho
467 1.1 jruoho /* Lock entire transaction if requested */
468 1.1 jruoho
469 1.1 jruoho AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
470 1.1 jruoho
471 1.1 jruoho /*
472 1.1 jruoho * Perform the write (returns status and perhaps data in the
473 1.1 jruoho * same buffer)
474 1.1 jruoho */
475 1.1 jruoho Status = AcpiExAccessRegion (ObjDesc, 0,
476 1.1 jruoho (UINT64 *) Buffer, Function);
477 1.1 jruoho AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
478 1.1 jruoho
479 1.1 jruoho *ResultDesc = BufferDesc;
480 1.1 jruoho return_ACPI_STATUS (Status);
481 1.1 jruoho }
482 1.1.1.4 christos else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
483 1.1.1.4 christos (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO))
484 1.1.1.4 christos {
485 1.1.1.4 christos /*
486 1.1.1.4 christos * For GPIO (GeneralPurposeIo), we will bypass the entire field
487 1.1.1.4 christos * mechanism and handoff the bit address and bit width directly to
488 1.1.1.4 christos * the handler. The Address will be the bit offset
489 1.1.1.4 christos * from the previous Connection() operator, making it effectively a
490 1.1.1.4 christos * pin number index. The BitLength is the length of the field, which
491 1.1.1.4 christos * is thus the number of pins.
492 1.1.1.4 christos */
493 1.1.1.4 christos if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER)
494 1.1.1.4 christos {
495 1.1.1.4 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
496 1.1.1.4 christos }
497 1.1.1.4 christos
498 1.1.1.4 christos ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
499 1.1.1.4 christos "GPIO FieldWrite [FROM]: (%s:%X), Val %.8X [TO]: Pin %u Bits %u\n",
500 1.1.1.4 christos AcpiUtGetTypeName (SourceDesc->Common.Type),
501 1.1.1.4 christos SourceDesc->Common.Type, (UINT32) SourceDesc->Integer.Value,
502 1.1.1.4 christos ObjDesc->Field.PinNumberIndex, ObjDesc->Field.BitLength));
503 1.1.1.4 christos
504 1.1.1.4 christos Buffer = &SourceDesc->Integer.Value;
505 1.1.1.4 christos
506 1.1.1.4 christos /* Lock entire transaction if requested */
507 1.1.1.4 christos
508 1.1.1.4 christos AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
509 1.1.1.4 christos
510 1.1.1.4 christos /* Perform the write */
511 1.1.1.4 christos
512 1.1.1.4 christos Status = AcpiExAccessRegion (ObjDesc, 0,
513 1.1.1.4 christos (UINT64 *) Buffer, ACPI_WRITE);
514 1.1.1.4 christos AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
515 1.1.1.4 christos return_ACPI_STATUS (Status);
516 1.1.1.4 christos }
517 1.1 jruoho
518 1.1 jruoho /* Get a pointer to the data to be written */
519 1.1 jruoho
520 1.1 jruoho switch (SourceDesc->Common.Type)
521 1.1 jruoho {
522 1.1 jruoho case ACPI_TYPE_INTEGER:
523 1.1.1.3 christos
524 1.1 jruoho Buffer = &SourceDesc->Integer.Value;
525 1.1 jruoho Length = sizeof (SourceDesc->Integer.Value);
526 1.1 jruoho break;
527 1.1 jruoho
528 1.1 jruoho case ACPI_TYPE_BUFFER:
529 1.1.1.3 christos
530 1.1 jruoho Buffer = SourceDesc->Buffer.Pointer;
531 1.1 jruoho Length = SourceDesc->Buffer.Length;
532 1.1 jruoho break;
533 1.1 jruoho
534 1.1 jruoho case ACPI_TYPE_STRING:
535 1.1.1.3 christos
536 1.1 jruoho Buffer = SourceDesc->String.Pointer;
537 1.1 jruoho Length = SourceDesc->String.Length;
538 1.1 jruoho break;
539 1.1 jruoho
540 1.1 jruoho default:
541 1.1.1.3 christos
542 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
543 1.1 jruoho }
544 1.1 jruoho
545 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
546 1.1 jruoho "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
547 1.1 jruoho SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type),
548 1.1 jruoho SourceDesc->Common.Type, Buffer, Length));
549 1.1 jruoho
550 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
551 1.1 jruoho "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
552 1.1 jruoho ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type),
553 1.1 jruoho ObjDesc->Common.Type,
554 1.1 jruoho ObjDesc->CommonField.BitLength,
555 1.1 jruoho ObjDesc->CommonField.StartFieldBitOffset,
556 1.1 jruoho ObjDesc->CommonField.BaseByteOffset));
557 1.1 jruoho
558 1.1 jruoho /* Lock entire transaction if requested */
559 1.1 jruoho
560 1.1 jruoho AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
561 1.1 jruoho
562 1.1 jruoho /* Write to the field */
563 1.1 jruoho
564 1.1 jruoho Status = AcpiExInsertIntoField (ObjDesc, Buffer, Length);
565 1.1 jruoho AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
566 1.1 jruoho
567 1.1 jruoho return_ACPI_STATUS (Status);
568 1.1 jruoho }
569