TianoCore EDK2 master
Loading...
Searching...
No Matches
Aml.c File Reference
#include <AmlEncoding/Aml.h>

Go to the source code of this file.

Functions

CONST AML_BYTE_ENCODING *EFIAPI AmlGetByteEncoding (IN CONST UINT8 *Buffer)
 
CONST AML_BYTE_ENCODING *EFIAPI AmlGetByteEncodingByOpCode (IN UINT8 OpCode, IN UINT8 SubOpCode)
 
CONST AML_BYTE_ENCODING *EFIAPI AmlGetFieldEncoding (IN CONST UINT8 *Buffer)
 
CONST AML_BYTE_ENCODING *EFIAPI AmlGetFieldEncodingByOpCode (IN UINT8 OpCode, IN UINT8 SubOpCode)
 
CONST CHAR8 * AmlGetOpCodeStr (IN UINT8 OpCode, IN UINT8 SubOpCode)
 
CONST CHAR8 * AmlGetFieldOpCodeStr (IN UINT8 OpCode, IN UINT8 SubOpCode)
 
BOOLEAN EFIAPI AmlIsOpCodeValid (IN UINT8 OpCode, IN UINT8 SubOpCode)
 
EAML_NODE_DATA_TYPE EFIAPI AmlTypeToNodeDataType (IN AML_PARSE_FORMAT AmlType)
 
UINT32 EFIAPI AmlGetPkgLength (IN CONST UINT8 *Buffer, OUT UINT32 *PkgLength)
 
UINT8 EFIAPI AmlSetPkgLength (IN UINT32 Length, OUT UINT8 *Buffer)
 
UINT8 EFIAPI AmlComputePkgLengthWidth (IN UINT32 Length)
 
EFI_STATUS EFIAPI AmlComputePkgLength (IN UINT32 Length, OUT UINT32 *PkgLen)
 

Variables

GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST AML_BYTE_ENCODING mAmlByteEncoding []
 
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST AML_BYTE_ENCODING mAmlFieldEncoding []
 
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST EAML_NODE_DATA_TYPE mAmlTypeToNodeDataType []
 

Detailed Description

AML grammar definitions.

Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Aml.c.

Function Documentation

◆ AmlComputePkgLength()

EFI_STATUS EFIAPI AmlComputePkgLength ( IN UINT32  Length,
OUT UINT32 *  PkgLen 
)

Given a length, compute the value of a PkgLen.

In AML, some object have a PkgLen, telling the size of the AML object. It can be encoded in 1 to 4 bytes. The bytes used to encode the PkgLen is itself counted in the PkgLen value. This means that if an AML object sees its size increment/decrement, the number of bytes used to encode the PkgLen value can itself increment/decrement.

For instance, the AML encoding of a DeviceOp is: DefDevice := DeviceOp PkgLength NameString TermList If:

  • sizeof (NameString) = 4 (the name is "DEV0" for instance);
  • sizeof (TermList) = (2^6-6) then the PkgLen is encoded on 1 byte. Indeed, its value is: sizeof (PkgLen) + sizeof (NameString) + sizeof (TermList) = sizeof (PkgLen) + 4 + (2^6-6) So: PkgLen = sizeof (PkgLen) + (2^6-2)

The input arguments Length and PkgLen represent, for the DefDevice: DefDevice := DeviceOp PkgLength NameString TermList |---—Length--—| |-----—*PgkLength------—|

Parameters
[in]LengthThe length to encode as a PkgLen. Length cannot exceed 2^28 - 4 (4 bytes for the PkgLen encoding). The size of the PkgLen encoding bytes should not be counted in this length value.
[out]PkgLenIf success, contains the value of the PkgLen, ready to encode in the PkgLen format. This value takes into account the size of PkgLen encoding.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.

Definition at line 862 of file Aml.c.

◆ AmlComputePkgLengthWidth()

UINT8 EFIAPI AmlComputePkgLengthWidth ( IN UINT32  Length)

Compute the number of bytes required to write a package length.

Parameters
[in]LengthThe length to convert in the AML package length encoding style. Length cannot exceed 2^28.
Returns
The number of bytes required to write the Length.

Definition at line 799 of file Aml.c.

◆ AmlGetByteEncoding()

CONST AML_BYTE_ENCODING *EFIAPI AmlGetByteEncoding ( IN CONST UINT8 *  Buffer)

Get the AML_BYTE_ENCODING entry in the AML encoding table.

Note: For Pseudo OpCodes this function returns NULL.

Parameters
[in]BufferPointer to an OpCode/SubOpCode couple. If *Buffer = 0x5b (extended OpCode), Buffer must be at least two bytes long.
Returns
The corresponding AML_BYTE_ENCODING entry. NULL if not found.

Definition at line 290 of file Aml.c.

◆ AmlGetByteEncodingByOpCode()

CONST AML_BYTE_ENCODING *EFIAPI AmlGetByteEncodingByOpCode ( IN UINT8  OpCode,
IN UINT8  SubOpCode 
)

Get the AML_BYTE_ENCODING entry in the AML encoding table by providing an OpCode/SubOpCode couple.

Parameters
[in]OpCodeOpCode.
[in]SubOpCodeSubOpCode.
Returns
The corresponding AML_BYTE_ENCODING entry. NULL if not found.

Definition at line 347 of file Aml.c.

◆ AmlGetFieldEncoding()

CONST AML_BYTE_ENCODING *EFIAPI AmlGetFieldEncoding ( IN CONST UINT8 *  Buffer)

Get the AML_BYTE_ENCODING entry in the field encoding table.

Note: For Pseudo OpCodes this function returns NULL.

Parameters
[in]BufferPointer to a field OpCode. No SubOpCode is expected.
Returns
The corresponding AML_BYTE_ENCODING entry in the field encoding table. NULL if not found.

Definition at line 383 of file Aml.c.

◆ AmlGetFieldEncodingByOpCode()

CONST AML_BYTE_ENCODING *EFIAPI AmlGetFieldEncodingByOpCode ( IN UINT8  OpCode,
IN UINT8  SubOpCode 
)

Get the AML_BYTE_ENCODING entry in the field encoding table by providing an OpCode/SubOpCode couple.

Parameters
[in]OpCodeOpCode.
[in]SubOpCodeSubOpCode.
Returns
The corresponding AML_BYTE_ENCODING entry in the field encoding table. NULL if not found.

Definition at line 434 of file Aml.c.

◆ AmlGetFieldOpCodeStr()

CONST CHAR8 * AmlGetFieldOpCodeStr ( IN UINT8  OpCode,
IN UINT8  SubOpCode 
)

Look for an OpCode/SubOpCode couple in the AML field element grammar, and return a corresponding string.

Parameters
[in]OpCodeThe OpCode.
[in]SubOpCodeThe SubOpCode. Must be zero.
Returns
A string describing the OpCode/SubOpCode couple. NULL if not found.

Definition at line 504 of file Aml.c.

◆ AmlGetOpCodeStr()

CONST CHAR8 * AmlGetOpCodeStr ( IN UINT8  OpCode,
IN UINT8  SubOpCode 
)

Look for an OpCode/SubOpCode couple in the AML grammar, and return a corresponding string.

Parameters
[in]OpCodeThe OpCode.
[in]SubOpCodeThe SubOpCode.
Returns
A string describing the OpCode/SubOpCode couple. NULL if not found.

Definition at line 470 of file Aml.c.

◆ AmlGetPkgLength()

UINT32 EFIAPI AmlGetPkgLength ( IN CONST UINT8 *  Buffer,
OUT UINT32 *  PkgLength 
)

Get the package length from the buffer.

Parameters
[in]BufferAML buffer.
[out]PkgLengthThe interpreted PkgLen value. Length cannot exceed 2^28.
Returns
The number of bytes to represent the package length. 0 if an issue occurred.

Definition at line 621 of file Aml.c.

◆ AmlIsOpCodeValid()

BOOLEAN EFIAPI AmlIsOpCodeValid ( IN UINT8  OpCode,
IN UINT8  SubOpCode 
)

Check whether the OpCode/SubOpcode couple is a valid entry in the AML grammar encoding table.

Parameters
[in]OpCodeOpCode to check.
[in]SubOpCodeSubOpCode to check.
Return values
TRUEThe OpCode/SubOpCode couple is valid.
FALSEOtherwise.

Definition at line 543 of file Aml.c.

◆ AmlSetPkgLength()

UINT8 EFIAPI AmlSetPkgLength ( IN UINT32  Length,
OUT UINT8 *  Buffer 
)

Convert the Length to the AML PkgLen encoding, then and write it in the Buffer.

Parameters
[in]LengthLength to convert. Length cannot exceed 2^28.
[out]BufferWrite the result in this Buffer.
Returns
The number of bytes used to write the Length.

Definition at line 724 of file Aml.c.

◆ AmlTypeToNodeDataType()

EAML_NODE_DATA_TYPE EFIAPI AmlTypeToNodeDataType ( IN AML_PARSE_FORMAT  AmlType)

Convert an AML_PARSE_FORMAT to its corresponding EAML_NODE_DATA_TYPE.

Parameters
[in]AmlTypeInput AML Type.
Returns
The corresponding EAML_NODE_DATA_TYPE. EAmlNodeDataTypeNone if not found.

Definition at line 596 of file Aml.c.

Variable Documentation

◆ mAmlByteEncoding

AML grammar encoding table.

The ASL language is a description language, used to define abstract objects, like devices, thermal zones, etc. and their place in a hierarchical tree. The following table stores the AML grammar definition. It can be used to parse an AML bytestream. Each line corresponds to the definition of an opcode and what is expected to be found with this opcode. See table 20-440 in the ACPI 6.3 specification s20.3, and the AML grammar definitions in s20.2.

  • OpCode/SubOpCode: An OpCode/SubOpCode couple allows to identify an object type. The OpCode and SubOpCode are one byte each. The SubOpCode is used when the Opcode value is 0x5B (extended OpCode). Otherwise the SubOpcode is set to 0. If the SubOpCode is 0 in the table below, there is no SubOpCode in the AML bytestream, only the OpCode is used to identify the object.
  • Fixed arguments: The fixed arguments follow the OpCode and SubOpCode. Their number and type can be found in the table below. There can be at the most 6 fixed arguments for an object. Fixed arguments's type allow to know what is expected in the AML bytestream. Knowing the size of the incoming element, AML bytes can be packed and parsed accordingly. These types can be found in the same table 20-440 in the ACPI 6.3, s20.3 specification. E.g.: An AML object, a UINT8, a NULL terminated string, etc.

-Attributes: The attribute field gives additional information on each object. This can be the presence of a variable list of arguments, the presence of a PkgLen, etc.

In summary, an AML object is described as: OpCode [SubOpcode] [PkgLen] [FixedArgs] [VarArgs]

OpCode {1 byte} [SubOpCode] {1 byte. Only relevant if the OpCode value is 0x5B (extended OpCode prefix). Otherwise 0. Most objects don't have one.} [PkgLen] {Size of the object. It has a special encoding, cf. ACPI 6.3 specification, s20.2.4 "Package Length Encoding". Most objects don't have one.} [FixedArgs[0..X]] {Fixed list of arguments. (where X <= 5) Can be other objects or data (a byte, a string, etc.). They belong to the current AML object. The number of fixed arguments varies according to the object, but it is fixed for each kind of object.} [VarArgs] {Variable list of arguments. They also belong to the current object and can be objects or data. Most objects don't have one.} [ByteList] {This is a sub-type of a variable list of arguments. It can only be found in buffer objects. A ByteList is either a list of bytes or a list of resource data elements. Resource data elements have specific opcodes.} [FieldList] {This is a sub-type of a variable list of arguments. It can only be found in Fields, IndexFields and BankFields. A FieldList is made of FieldElements. FieldElements have specific opcodes.}

Definition at line 84 of file Aml.c.

◆ mAmlFieldEncoding

Initial value:
= {
{ AML_OPCODE_DEF ("FieldReservedOp", AML_FIELD_RESERVED_OP), 0, 0, 0, { EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone }, AML_IS_FIELD_ELEMENT | AML_HAS_PKG_LENGTH },
{ AML_OPCODE_DEF ("FieldAccessOp", AML_FIELD_ACCESS_OP), 0, 2, 0, { EAmlUInt8, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone, EAmlNone }, AML_IS_FIELD_ELEMENT },
{ AML_OPCODE_DEF ("FieldConnectionOp", AML_FIELD_CONNECTION_OP), 0, 1, 0, { EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone }, AML_IS_FIELD_ELEMENT },
{ AML_OPCODE_DEF ("FieldExtAccessOp", AML_FIELD_EXT_ACCESS_OP), 0, 3, 0, { EAmlUInt8, EAmlUInt8, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone }, AML_IS_FIELD_ELEMENT },
}
#define AML_IS_FIELD_ELEMENT
Definition: Aml.h:93
#define AML_HAS_PKG_LENGTH
Definition: Aml.h:64
#define AML_IN_NAMESPACE
Definition: Aml.h:98
@ EAmlName
Definition: Aml.h:44
@ EAmlObject
Definition: Aml.h:39
@ EAmlUInt8
One byte value evaluated as a UINT8.
Definition: Aml.h:35
@ EAmlFieldPkgLen
Definition: Aml.h:47
@ EAmlNone
No data expected.
Definition: Aml.h:34
#define AML_IS_PSEUDO_OPCODE
Definition: Aml.h:103
#define AML_FIELD_NAMED_OP
Definition: AmlDefines.h:139

AML grammar encoding for field elements.

Some AML objects are expecting a FieldList. They are referred in this library as field nodes. These objects have the following opcodes:

  • FieldOp;
  • IndexFieldOp;
  • BankFieldOp. In the AML grammar encoding table, they have the AML_HAS_FIELD_LIST attribute.

A field list is made of field elements. According to the ACPI 6.3 specification, s20.2.5.2 "Named Objects Encoding", field elements can be:

  • NamedField := NameSeg PkgLength;
  • ReservedField := 0x00 PkgLength;
  • AccessField := 0x01 AccessType AccessAttrib;
  • ConnectField := <0x02 NameString> | <0x02 BufferData>;
  • ExtendedAccessField := 0x03 AccessType ExtendedAccessAttrib AccessLength.

A small set of opcodes describes field elements. They are referred in this library as field opcodes. The NamedField field element doesn't have a field opcode. A pseudo OpCode/SubOpCode couple has been created for it.

Field elements:

  • don't have a SubOpCode;
  • have at most 3 fixed arguments (6 for object opcodes, 8 for method invocations);
  • don't have variable list of arguments;
  • are not part of the AML namespace, except NamedField field elements.

Definition at line 267 of file Aml.c.

◆ mAmlTypeToNodeDataType

Initial value:
= {
}
@ EAmlNodeDataTypeNone
EAmlNone, not accessible.
Definition: AmlDefines.h:31
@ EAmlNodeDataTypeReserved5
EAmlObject, not accessible.
Definition: AmlDefines.h:36
@ EAmlNodeDataTypeString
EAmlString, NULL terminated string.
Definition: AmlDefines.h:40
@ EAmlNodeDataTypeUInt
Definition: AmlDefines.h:41
@ EAmlNodeDataTypeFieldPkgLen
Definition: AmlDefines.h:45
@ EAmlNodeDataTypeNameString
Definition: AmlDefines.h:37

AML_PARSE_FORMAT to EAML_NODE_DATA_TYPE translation table.

AML_PARSE_FORMAT describes an internal set of values identifying the types that can be found while parsing an AML bytestream. EAML_NODE_DATA_TYPE describes an external set of values allowing to identify what type of data can be found in data nodes.

Definition at line 575 of file Aml.c.