1 /******************************************************************************
3 * Module Name: exfield - ACPI AML (p-code) execution - field manipulation
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #include "accommon.h"
118 #include "acdispat.h"
119 #include "acinterp.h"
123 #define _COMPONENT ACPI_EXECUTER
124 ACPI_MODULE_NAME ("exfield")
126 /* Local prototypes */
129 AcpiExGetSerialAccessLength (
131 UINT32 AccessLength
);
134 /*******************************************************************************
136 * FUNCTION: AcpiExGetSerialAccessLength
138 * PARAMETERS: AccessorType - The type of the protocol indicated by region
139 * field access attributes
140 * AccessLength - The access length of the region field
142 * RETURN: Decoded access length
144 * DESCRIPTION: This routine returns the length of the GenericSerialBus
147 ******************************************************************************/
150 AcpiExGetSerialAccessLength (
157 switch (AccessorType
)
159 case AML_FIELD_ATTRIB_QUICK
:
164 case AML_FIELD_ATTRIB_SEND_RCV
:
165 case AML_FIELD_ATTRIB_BYTE
:
170 case AML_FIELD_ATTRIB_WORD
:
171 case AML_FIELD_ATTRIB_WORD_CALL
:
176 case AML_FIELD_ATTRIB_MULTIBYTE
:
177 case AML_FIELD_ATTRIB_RAW_BYTES
:
178 case AML_FIELD_ATTRIB_RAW_PROCESS
:
180 Length
= AccessLength
;
183 case AML_FIELD_ATTRIB_BLOCK
:
184 case AML_FIELD_ATTRIB_BLOCK_CALL
:
187 Length
= ACPI_GSBUS_BUFFER_SIZE
- 2;
195 /*******************************************************************************
197 * FUNCTION: AcpiExReadDataFromField
199 * PARAMETERS: WalkState - Current execution state
200 * ObjDesc - The named field
201 * RetBufferDesc - Where the return data object is stored
205 * DESCRIPTION: Read from a named field. Returns either an Integer or a
206 * Buffer, depending on the size of the field.
208 ******************************************************************************/
211 AcpiExReadDataFromField (
212 ACPI_WALK_STATE
*WalkState
,
213 ACPI_OPERAND_OBJECT
*ObjDesc
,
214 ACPI_OPERAND_OBJECT
**RetBufferDesc
)
217 ACPI_OPERAND_OBJECT
*BufferDesc
;
224 ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField
, ObjDesc
);
227 /* Parameter validation */
231 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
235 return_ACPI_STATUS (AE_BAD_PARAMETER
);
238 if (ObjDesc
->Common
.Type
== ACPI_TYPE_BUFFER_FIELD
)
241 * If the BufferField arguments have not been previously evaluated,
242 * evaluate them now and save the results.
244 if (!(ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
246 Status
= AcpiDsGetBufferFieldArguments (ObjDesc
);
247 if (ACPI_FAILURE (Status
))
249 return_ACPI_STATUS (Status
);
253 else if ((ObjDesc
->Common
.Type
== ACPI_TYPE_LOCAL_REGION_FIELD
) &&
254 (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_SMBUS
||
255 ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GSBUS
||
256 ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_IPMI
))
259 * This is an SMBus, GSBus or IPMI read. We must create a buffer to hold
260 * the data and then directly access the region handler.
262 * Note: SMBus and GSBus protocol value is passed in upper 16-bits of Function
264 if (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_SMBUS
)
266 Length
= ACPI_SMBUS_BUFFER_SIZE
;
267 Function
= ACPI_READ
| (ObjDesc
->Field
.Attribute
<< 16);
269 else if (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GSBUS
)
271 AccessorType
= ObjDesc
->Field
.Attribute
;
272 Length
= AcpiExGetSerialAccessLength (AccessorType
,
273 ObjDesc
->Field
.AccessLength
);
276 * Add additional 2 bytes for the GenericSerialBus data buffer:
278 * Status; (Byte 0 of the data buffer)
279 * Length; (Byte 1 of the data buffer)
280 * Data[x-1]; (Bytes 2-x of the arbitrary length data buffer)
283 Function
= ACPI_READ
| (AccessorType
<< 16);
287 Length
= ACPI_IPMI_BUFFER_SIZE
;
288 Function
= ACPI_READ
;
291 BufferDesc
= AcpiUtCreateBufferObject (Length
);
294 return_ACPI_STATUS (AE_NO_MEMORY
);
297 /* Lock entire transaction if requested */
299 AcpiExAcquireGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
301 /* Call the region handler for the read */
303 Status
= AcpiExAccessRegion (ObjDesc
, 0,
304 ACPI_CAST_PTR (UINT64
, BufferDesc
->Buffer
.Pointer
),
306 AcpiExReleaseGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
311 * Allocate a buffer for the contents of the field.
313 * If the field is larger than the current integer width, create
314 * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
315 * the use of arithmetic operators on the returned value if the
316 * field size is equal or smaller than an Integer.
318 * Note: Field.length is in bits.
320 Length
= (ACPI_SIZE
) ACPI_ROUND_BITS_UP_TO_BYTES (ObjDesc
->Field
.BitLength
);
321 if (Length
> AcpiGbl_IntegerByteWidth
)
323 /* Field is too large for an Integer, create a Buffer instead */
325 BufferDesc
= AcpiUtCreateBufferObject (Length
);
328 return_ACPI_STATUS (AE_NO_MEMORY
);
330 Buffer
= BufferDesc
->Buffer
.Pointer
;
334 /* Field will fit within an Integer (normal case) */
336 BufferDesc
= AcpiUtCreateIntegerObject ((UINT64
) 0);
339 return_ACPI_STATUS (AE_NO_MEMORY
);
342 Length
= AcpiGbl_IntegerByteWidth
;
343 Buffer
= &BufferDesc
->Integer
.Value
;
346 if ((ObjDesc
->Common
.Type
== ACPI_TYPE_LOCAL_REGION_FIELD
) &&
347 (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GPIO
))
350 * For GPIO (GeneralPurposeIo), the Address will be the bit offset
351 * from the previous Connection() operator, making it effectively a
352 * pin number index. The BitLength is the length of the field, which
353 * is thus the number of pins.
355 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
356 "GPIO FieldRead [FROM]: Pin %u Bits %u\n",
357 ObjDesc
->Field
.PinNumberIndex
, ObjDesc
->Field
.BitLength
));
359 /* Lock entire transaction if requested */
361 AcpiExAcquireGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
363 /* Perform the write */
365 Status
= AcpiExAccessRegion (ObjDesc
, 0,
366 (UINT64
*) Buffer
, ACPI_READ
);
367 AcpiExReleaseGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
368 if (ACPI_FAILURE (Status
))
370 AcpiUtRemoveReference (BufferDesc
);
374 *RetBufferDesc
= BufferDesc
;
376 return_ACPI_STATUS (Status
);
379 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
380 "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n",
381 ObjDesc
, ObjDesc
->Common
.Type
, Buffer
, (UINT32
) Length
));
382 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
383 "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
384 ObjDesc
->CommonField
.BitLength
,
385 ObjDesc
->CommonField
.StartFieldBitOffset
,
386 ObjDesc
->CommonField
.BaseByteOffset
));
388 /* Lock entire transaction if requested */
390 AcpiExAcquireGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
392 /* Read from the field */
394 Status
= AcpiExExtractFromField (ObjDesc
, Buffer
, (UINT32
) Length
);
395 AcpiExReleaseGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
399 if (ACPI_FAILURE (Status
))
401 AcpiUtRemoveReference (BufferDesc
);
405 *RetBufferDesc
= BufferDesc
;
408 return_ACPI_STATUS (Status
);
412 /*******************************************************************************
414 * FUNCTION: AcpiExWriteDataToField
416 * PARAMETERS: SourceDesc - Contains data to write
417 * ObjDesc - The named field
418 * ResultDesc - Where the return value is returned, if any
422 * DESCRIPTION: Write to a named field
424 ******************************************************************************/
427 AcpiExWriteDataToField (
428 ACPI_OPERAND_OBJECT
*SourceDesc
,
429 ACPI_OPERAND_OBJECT
*ObjDesc
,
430 ACPI_OPERAND_OBJECT
**ResultDesc
)
435 ACPI_OPERAND_OBJECT
*BufferDesc
;
440 ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField
, ObjDesc
);
443 /* Parameter validation */
445 if (!SourceDesc
|| !ObjDesc
)
447 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
450 if (ObjDesc
->Common
.Type
== ACPI_TYPE_BUFFER_FIELD
)
453 * If the BufferField arguments have not been previously evaluated,
454 * evaluate them now and save the results.
456 if (!(ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
458 Status
= AcpiDsGetBufferFieldArguments (ObjDesc
);
459 if (ACPI_FAILURE (Status
))
461 return_ACPI_STATUS (Status
);
465 else if ((ObjDesc
->Common
.Type
== ACPI_TYPE_LOCAL_REGION_FIELD
) &&
466 (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_SMBUS
||
467 ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GSBUS
||
468 ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_IPMI
))
471 * This is an SMBus, GSBus or IPMI write. We will bypass the entire field
472 * mechanism and handoff the buffer directly to the handler. For
473 * these address spaces, the buffer is bi-directional; on a write,
474 * return data is returned in the same buffer.
476 * Source must be a buffer of sufficient size:
477 * ACPI_SMBUS_BUFFER_SIZE, ACPI_GSBUS_BUFFER_SIZE, or ACPI_IPMI_BUFFER_SIZE.
479 * Note: SMBus and GSBus protocol type is passed in upper 16-bits of Function
481 if (SourceDesc
->Common
.Type
!= ACPI_TYPE_BUFFER
)
483 ACPI_ERROR ((AE_INFO
,
484 "SMBus/IPMI/GenericSerialBus write requires Buffer, found type %s",
485 AcpiUtGetObjectTypeName (SourceDesc
)));
487 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
490 if (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_SMBUS
)
492 Length
= ACPI_SMBUS_BUFFER_SIZE
;
493 Function
= ACPI_WRITE
| (ObjDesc
->Field
.Attribute
<< 16);
495 else if (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GSBUS
)
497 AccessorType
= ObjDesc
->Field
.Attribute
;
498 Length
= AcpiExGetSerialAccessLength (AccessorType
,
499 ObjDesc
->Field
.AccessLength
);
502 * Add additional 2 bytes for the GenericSerialBus data buffer:
504 * Status; (Byte 0 of the data buffer)
505 * Length; (Byte 1 of the data buffer)
506 * Data[x-1]; (Bytes 2-x of the arbitrary length data buffer)
509 Function
= ACPI_WRITE
| (AccessorType
<< 16);
513 Length
= ACPI_IPMI_BUFFER_SIZE
;
514 Function
= ACPI_WRITE
;
517 if (SourceDesc
->Buffer
.Length
< Length
)
519 ACPI_ERROR ((AE_INFO
,
520 "SMBus/IPMI/GenericSerialBus write requires Buffer of length %u, found length %u",
521 Length
, SourceDesc
->Buffer
.Length
));
523 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT
);
526 /* Create the bi-directional buffer */
528 BufferDesc
= AcpiUtCreateBufferObject (Length
);
531 return_ACPI_STATUS (AE_NO_MEMORY
);
534 Buffer
= BufferDesc
->Buffer
.Pointer
;
535 memcpy (Buffer
, SourceDesc
->Buffer
.Pointer
, Length
);
537 /* Lock entire transaction if requested */
539 AcpiExAcquireGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
542 * Perform the write (returns status and perhaps data in the
545 Status
= AcpiExAccessRegion (ObjDesc
, 0,
546 (UINT64
*) Buffer
, Function
);
547 AcpiExReleaseGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
549 *ResultDesc
= BufferDesc
;
550 return_ACPI_STATUS (Status
);
552 else if ((ObjDesc
->Common
.Type
== ACPI_TYPE_LOCAL_REGION_FIELD
) &&
553 (ObjDesc
->Field
.RegionObj
->Region
.SpaceId
== ACPI_ADR_SPACE_GPIO
))
556 * For GPIO (GeneralPurposeIo), we will bypass the entire field
557 * mechanism and handoff the bit address and bit width directly to
558 * the handler. The Address will be the bit offset
559 * from the previous Connection() operator, making it effectively a
560 * pin number index. The BitLength is the length of the field, which
561 * is thus the number of pins.
563 if (SourceDesc
->Common
.Type
!= ACPI_TYPE_INTEGER
)
565 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
568 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
569 "GPIO FieldWrite [FROM]: (%s:%X), Val %.8X [TO]: Pin %u Bits %u\n",
570 AcpiUtGetTypeName (SourceDesc
->Common
.Type
),
571 SourceDesc
->Common
.Type
, (UINT32
) SourceDesc
->Integer
.Value
,
572 ObjDesc
->Field
.PinNumberIndex
, ObjDesc
->Field
.BitLength
));
574 Buffer
= &SourceDesc
->Integer
.Value
;
576 /* Lock entire transaction if requested */
578 AcpiExAcquireGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
580 /* Perform the write */
582 Status
= AcpiExAccessRegion (ObjDesc
, 0,
583 (UINT64
*) Buffer
, ACPI_WRITE
);
584 AcpiExReleaseGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
585 return_ACPI_STATUS (Status
);
588 /* Get a pointer to the data to be written */
590 switch (SourceDesc
->Common
.Type
)
592 case ACPI_TYPE_INTEGER
:
594 Buffer
= &SourceDesc
->Integer
.Value
;
595 Length
= sizeof (SourceDesc
->Integer
.Value
);
598 case ACPI_TYPE_BUFFER
:
600 Buffer
= SourceDesc
->Buffer
.Pointer
;
601 Length
= SourceDesc
->Buffer
.Length
;
604 case ACPI_TYPE_STRING
:
606 Buffer
= SourceDesc
->String
.Pointer
;
607 Length
= SourceDesc
->String
.Length
;
612 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
615 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
616 "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
617 SourceDesc
, AcpiUtGetTypeName (SourceDesc
->Common
.Type
),
618 SourceDesc
->Common
.Type
, Buffer
, Length
));
620 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD
,
621 "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
622 ObjDesc
, AcpiUtGetTypeName (ObjDesc
->Common
.Type
),
623 ObjDesc
->Common
.Type
,
624 ObjDesc
->CommonField
.BitLength
,
625 ObjDesc
->CommonField
.StartFieldBitOffset
,
626 ObjDesc
->CommonField
.BaseByteOffset
));
628 /* Lock entire transaction if requested */
630 AcpiExAcquireGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
632 /* Write to the field */
634 Status
= AcpiExInsertIntoField (ObjDesc
, Buffer
, Length
);
635 AcpiExReleaseGlobalLock (ObjDesc
->CommonField
.FieldFlags
);
637 return_ACPI_STATUS (Status
);