1 /******************************************************************************
3 * Module Name: exfield - AML execution - FieldUnit read/write
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2019, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
51 #define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME ("exfield")
56 * This table maps the various Attrib protocols to the byte transfer
57 * length. Used for the generic serial bus.
59 #define ACPI_INVALID_PROTOCOL_ID 0x80
60 #define ACPI_MAX_PROTOCOL_ID 0x0F
62 const UINT8 AcpiProtocolLengths
[] =
64 ACPI_INVALID_PROTOCOL_ID
, /* 0 - reserved */
65 ACPI_INVALID_PROTOCOL_ID
, /* 1 - reserved */
66 0x00, /* 2 - ATTRIB_QUICK */
67 ACPI_INVALID_PROTOCOL_ID
, /* 3 - reserved */
68 0x01, /* 4 - ATTRIB_SEND_RECEIVE */
69 ACPI_INVALID_PROTOCOL_ID
, /* 5 - reserved */
70 0x01, /* 6 - ATTRIB_BYTE */
71 ACPI_INVALID_PROTOCOL_ID
, /* 7 - reserved */
72 0x02, /* 8 - ATTRIB_WORD */
73 ACPI_INVALID_PROTOCOL_ID
, /* 9 - reserved */
74 0xFF, /* A - ATTRIB_BLOCK */
75 0xFF, /* B - ATTRIB_BYTES */
76 0x02, /* C - ATTRIB_PROCESS_CALL */
77 0xFF, /* D - ATTRIB_BLOCK_PROCESS_CALL */
78 0xFF, /* E - ATTRIB_RAW_BYTES */
79 0xFF /* F - ATTRIB_RAW_PROCESS_BYTES */
83 /*******************************************************************************
85 * FUNCTION: AcpiExGetProtocolBufferLength
87 * PARAMETERS: ProtocolId - The type of the protocol indicated by region
88 * field access attributes
89 * ReturnLength - Where the protocol byte transfer length is
92 * RETURN: Status and decoded byte transfer length
94 * DESCRIPTION: This routine returns the length of the GenericSerialBus
97 ******************************************************************************/
100 AcpiExGetProtocolBufferLength (
102 UINT32
*ReturnLength
)
105 if ((ProtocolId
> ACPI_MAX_PROTOCOL_ID
) ||
106 (AcpiProtocolLengths
[ProtocolId
] == ACPI_INVALID_PROTOCOL_ID
))
108 ACPI_ERROR ((AE_INFO
,
109 "Invalid Field/AccessAs protocol ID: 0x%4.4X", ProtocolId
));
111 return (AE_AML_PROTOCOL
);
114 *ReturnLength
= AcpiProtocolLengths
[ProtocolId
];
119 /*******************************************************************************
121 * FUNCTION: AcpiExReadDataFromField
123 * PARAMETERS: WalkState - Current execution state
124 * ObjDesc - The named field
125 * RetBufferDesc - Where the return data object is stored
129 * DESCRIPTION: Read from a named field. Returns either an Integer or a
130 * Buffer, depending on the size of the field.
132 ******************************************************************************/
135 AcpiExReadDataFromField (
136 ACPI_WALK_STATE
*WalkState
,
137 ACPI_OPERAND_OBJECT
*ObjDesc
,
138 ACPI_OPERAND_OBJECT
**RetBufferDesc
)
141 ACPI_OPERAND_OBJECT
*BufferDesc
;
146 ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField
, ObjDesc
);
149 /* Parameter validation */
153 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
157 return_ACPI_STATUS (AE_BAD_PARAMETER
);
160 if (ObjDesc
->Common
.Type
== ACPI_TYPE_BUFFER_FIELD
)
163 * If the BufferField arguments have not been previously evaluated,
164 * evaluate them now and save the results.
166 if (!(ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
168 Status
= AcpiDsGetBufferFieldArguments (ObjDesc
);
169 if (ACPI_FAILURE (Status
))
171 return_ACPI_STATUS (Status
);
175 else if ((ObjDesc
->Common
.Type
== ACPI_TYPE_LOCAL_REGION_FIELD
) &&
176 (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_SMBUS
||
177 ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GSBUS
||
178 ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_IPMI
))
180 /* SMBus, GSBus, IPMI serial */
182 Status
= AcpiExReadSerialBus (ObjDesc
, RetBufferDesc
);
183 return_ACPI_STATUS (Status
);
187 * Allocate a buffer for the contents of the field.
189 * If the field is larger than the current integer width, create
190 * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
191 * the use of arithmetic operators on the returned value if the
192 * field size is equal or smaller than an Integer.
194 * Note: Field.length is in bits.
196 BufferLength
= (ACPI_SIZE
) ACPI_ROUND_BITS_UP_TO_BYTES (
197 ObjDesc
->Field
.BitLength
);
199 if (BufferLength
> AcpiGbl_IntegerByteWidth
)
201 /* Field is too large for an Integer, create a Buffer instead */
203 BufferDesc
= AcpiUtCreateBufferObject (BufferLength
);
206 return_ACPI_STATUS (AE_NO_MEMORY
);
208 Buffer
= BufferDesc
->Buffer
.Pointer
;
212 /* Field will fit within an Integer (normal case) */
214 BufferDesc
= AcpiUtCreateIntegerObject ((UINT64
) 0);
217 return_ACPI_STATUS (AE_NO_MEMORY
);
220 BufferLength
= AcpiGbl_IntegerByteWidth
;
221 Buffer
= &BufferDesc
->Integer
.Value
;
224 if ((ObjDesc
->Common
.Type
== ACPI_TYPE_LOCAL_REGION_FIELD
) &&
225 (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GPIO
))
227 /* General Purpose I/O */
229 Status
= AcpiExReadGpio (ObjDesc
, Buffer
);
233 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
234 "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n",
235 ObjDesc
, ObjDesc
->Common
.Type
, Buffer
, BufferLength
));
236 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
237 "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
238 ObjDesc
->CommonField
.BitLength
,
239 ObjDesc
->CommonField
.StartFieldBitOffset
,
240 ObjDesc
->CommonField
.BaseByteOffset
));
242 /* Lock entire transaction if requested */
244 AcpiExAcquireGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
246 /* Read from the field */
248 Status
= AcpiExExtractFromField (ObjDesc
, Buffer
, BufferLength
);
249 AcpiExReleaseGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
253 if (ACPI_FAILURE (Status
))
255 AcpiUtRemoveReference (BufferDesc
);
259 *RetBufferDesc
= BufferDesc
;
262 return_ACPI_STATUS (Status
);
266 /*******************************************************************************
268 * FUNCTION: AcpiExWriteDataToField
270 * PARAMETERS: SourceDesc - Contains data to write
271 * ObjDesc - The named field
272 * ResultDesc - Where the return value is returned, if any
276 * DESCRIPTION: Write to a named field
278 ******************************************************************************/
281 AcpiExWriteDataToField (
282 ACPI_OPERAND_OBJECT
*SourceDesc
,
283 ACPI_OPERAND_OBJECT
*ObjDesc
,
284 ACPI_OPERAND_OBJECT
**ResultDesc
)
291 ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField
, ObjDesc
);
294 /* Parameter validation */
296 if (!SourceDesc
|| !ObjDesc
)
298 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
301 if (ObjDesc
->Common
.Type
== ACPI_TYPE_BUFFER_FIELD
)
304 * If the BufferField arguments have not been previously evaluated,
305 * evaluate them now and save the results.
307 if (!(ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
309 Status
= AcpiDsGetBufferFieldArguments (ObjDesc
);
310 if (ACPI_FAILURE (Status
))
312 return_ACPI_STATUS (Status
);
316 else if ((ObjDesc
->Common
.Type
== ACPI_TYPE_LOCAL_REGION_FIELD
) &&
317 (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GPIO
))
319 /* General Purpose I/O */
321 Status
= AcpiExWriteGpio (SourceDesc
, ObjDesc
, ResultDesc
);
322 return_ACPI_STATUS (Status
);
324 else if ((ObjDesc
->Common
.Type
== ACPI_TYPE_LOCAL_REGION_FIELD
) &&
325 (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_SMBUS
||
326 ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GSBUS
||
327 ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_IPMI
))
329 /* SMBus, GSBus, IPMI serial */
331 Status
= AcpiExWriteSerialBus (SourceDesc
, ObjDesc
, ResultDesc
);
332 return_ACPI_STATUS (Status
);
335 /* Get a pointer to the data to be written */
337 switch (SourceDesc
->Common
.Type
)
339 case ACPI_TYPE_INTEGER
:
341 Buffer
= &SourceDesc
->Integer
.Value
;
342 BufferLength
= sizeof (SourceDesc
->Integer
.Value
);
345 case ACPI_TYPE_BUFFER
:
347 Buffer
= SourceDesc
->Buffer
.Pointer
;
348 BufferLength
= SourceDesc
->Buffer
.Length
;
351 case ACPI_TYPE_STRING
:
353 Buffer
= SourceDesc
->String
.Pointer
;
354 BufferLength
= SourceDesc
->String
.Length
;
358 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
361 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
362 "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
363 SourceDesc
, AcpiUtGetTypeName (SourceDesc
->Common
.Type
),
364 SourceDesc
->Common
.Type
, Buffer
, BufferLength
));
366 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
367 "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
368 ObjDesc
, AcpiUtGetTypeName (ObjDesc
->Common
.Type
),
369 ObjDesc
->Common
.Type
,
370 ObjDesc
->CommonField
.BitLength
,
371 ObjDesc
->CommonField
.StartFieldBitOffset
,
372 ObjDesc
->CommonField
.BaseByteOffset
));
374 /* Lock entire transaction if requested */
376 AcpiExAcquireGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
378 /* Write to the field */
380 Status
= AcpiExInsertIntoField (ObjDesc
, Buffer
, BufferLength
);
381 AcpiExReleaseGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
382 return_ACPI_STATUS (Status
);