TianoCore EDK2 master
Loading...
Searching...
No Matches
AmlParser.c File Reference

Go to the source code of this file.

Typedefs

typedef EFI_STATUS(EFIAPI * AML_PARSE_FUNCTION) (IN CONST AML_NODE_HEADER *Node, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
 

Functions

STATIC EFI_STATUS EFIAPI AmlParseStream (IN AML_NODE_HEADER *Node, IN OUT AML_STREAM *FStream, IN OUT LIST_ENTRY *NameSpaceRefList)
 
STATIC EFI_STATUS EFIAPI AmlParseUIntX (IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
 
STATIC EFI_STATUS EFIAPI AmlParseNameString (IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
 
STATIC EFI_STATUS EFIAPI AmlParseString (IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
 
STATIC EFI_STATUS EFIAPI AmlParseObject (IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
 
STATIC EFI_STATUS EFIAPI AmlParseFieldPkgLen (IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
 
STATIC EFI_STATUS EFIAPI AmlCheckAndParseMethodInvoc (IN CONST AML_NODE_HEADER *ParentNode, IN AML_DATA_NODE *DataNode, IN OUT LIST_ENTRY *NameSpaceRefList, OUT AML_OBJECT_NODE **OutNode)
 
STATIC EFI_STATUS EFIAPI AmlParseArgument (IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, IN OUT LIST_ENTRY *NameSpaceRefList, OUT AML_NODE_HEADER **OutNode)
 
STATIC EFI_STATUS EFIAPI AmlParseByteList (IN AML_OBJECT_NODE *BufferNode, IN OUT AML_STREAM *FStream)
 
EFI_STATUS EFIAPI AmlParseFixedArguments (IN AML_OBJECT_NODE *ObjectNode, IN AML_STREAM *FStream, IN LIST_ENTRY *NameSpaceRefList)
 
EFI_STATUS EFIAPI AmlParseVariableArguments (IN AML_NODE_HEADER *Node, IN AML_STREAM *FStream, IN LIST_ENTRY *NameSpaceRefList)
 
STATIC EFI_STATUS EFIAPI AmlPopulateRootNode (IN AML_ROOT_NODE *RootNode, IN OUT AML_STREAM *FStream, IN OUT LIST_ENTRY *NameSpaceRefList)
 
STATIC EFI_STATUS EFIAPI AmlPopulateObjectNode (IN AML_OBJECT_NODE *ObjectNode, IN OUT AML_STREAM *FStream, IN OUT LIST_ENTRY *NameSpaceRefList)
 
STATIC EFI_STATUS EFIAPI AmlParseStream (IN AML_NODE_HEADER *Node, IN AML_STREAM *FStream, IN LIST_ENTRY *NameSpaceRefList)
 
EFI_STATUS EFIAPI AmlParseDefinitionBlock (IN CONST EFI_ACPI_DESCRIPTION_HEADER *DefinitionBlock, OUT AML_ROOT_NODE **RootPtr)
 

Variables

AML_PARSE_FUNCTION mParseType [EAmlParseFormatMax]
 

Detailed Description

AML Parser.

Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.

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

Definition in file AmlParser.c.

Typedef Documentation

◆ AML_PARSE_FUNCTION

typedef EFI_STATUS(EFIAPI * AML_PARSE_FUNCTION) (IN CONST AML_NODE_HEADER *Node, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)

Function pointer to parse an AML construct.

The expected format of the AML construct is passed in the ExpectedFormat argument. The available formats are available in the AML_PARSE_FORMAT enum definition.

An object node or a data node is created in the function, and returned through the OutNode parameter. This node should be attached after this function returns.

Parameters
[in]ParentNodeParent node to which the parsed AML construct will be attached.
[in]ExpectedFormatFormat of the AML construct to parse.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[out]OutNodePointer holding the node created from the parsed AML bytecode.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 102 of file AmlParser.c.

Function Documentation

◆ AmlCheckAndParseMethodInvoc()

STATIC EFI_STATUS EFIAPI AmlCheckAndParseMethodInvoc ( IN CONST AML_NODE_HEADER ParentNode,
IN AML_DATA_NODE DataNode,
IN OUT LIST_ENTRY NameSpaceRefList,
OUT AML_OBJECT_NODE **  OutNode 
)

Check whether the NameString stored in the data node is a method invocation. If so, create a method invocation node and return it.

Parameters
[in]ParentNodeNode to which the parsed AML construct will be attached.
[in]DataNodeData node containing a NameString, potentially being a method invocation.
[in,out]NameSpaceRefListList of namespace reference nodes.
[out]OutNodePointer holding the method invocation node if the NameString contained in the data node is a method invocation. NULL otherwise.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 622 of file AmlParser.c.

◆ AmlParseArgument()

STATIC EFI_STATUS EFIAPI AmlParseArgument ( IN CONST AML_NODE_HEADER ParentNode,
IN AML_PARSE_FORMAT  ExpectedFormat,
IN OUT AML_STREAM FStream,
IN OUT LIST_ENTRY NameSpaceRefList,
OUT AML_NODE_HEADER **  OutNode 
)

Call the appropriate function to parse the AML construct in the stream.

The ExpectedFormat parameter allows to choose the right parsing function. An object node or a data node is created according to format.

Parameters
[in]ParentNodeNode to which the parsed AML construct will be attached.
[in]ExpectedFormatFormat of the AML construct to parse.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[in,out]NameSpaceRefListList of namespace reference nodes.
[out]OutNodePointer holding the node created from the parsed AML bytecode.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 713 of file AmlParser.c.

◆ AmlParseByteList()

STATIC EFI_STATUS EFIAPI AmlParseByteList ( IN AML_OBJECT_NODE BufferNode,
IN OUT AML_STREAM FStream 
)

Parse the Bytelist in the stream. According to the content of the stream, create data node(s) and add them to the variable list of arguments. The byte list may be a list of resource data element or a simple byte list.

Parameters
[in]BufferNodeObject node having a byte list.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 804 of file AmlParser.c.

◆ AmlParseDefinitionBlock()

EFI_STATUS EFIAPI AmlParseDefinitionBlock ( IN CONST EFI_ACPI_DESCRIPTION_HEADER DefinitionBlock,
OUT AML_ROOT_NODE **  RootPtr 
)

Parse the definition block.

This function parses the whole AML blob. It starts with the ACPI DSDT/SSDT header and then parses the AML bytestream. A tree structure is returned via the RootPtr. The tree must be deleted with the AmlDeleteTree function.

Parameters
[in]DefinitionBlockPointer to the definition block.
[out]RootPtrPointer to the root node of the tree.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 1370 of file AmlParser.c.

◆ AmlParseFieldPkgLen()

STATIC EFI_STATUS EFIAPI AmlParseFieldPkgLen ( IN CONST AML_NODE_HEADER ParentNode,
IN AML_PARSE_FORMAT  ExpectedFormat,
IN OUT AML_STREAM FStream,
OUT AML_NODE_HEADER **  OutNode 
)

Parse a FieldPkgLen.

A FieldPkgLen can only be found in a field list, i.e. in a NamedField field element. The PkgLen is otherwise part of the object node structure. A data node is created and returned through the OutNode parameter.

Parameters
[in]ParentNodeParent node to which the parsed AML construct will be attached.
[in]ExpectedFormatFormat of the AML construct to parse.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[out]OutNodePointer holding the node created from the parsed AML bytecode.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 523 of file AmlParser.c.

◆ AmlParseFixedArguments()

EFI_STATUS EFIAPI AmlParseFixedArguments ( IN AML_OBJECT_NODE ObjectNode,
IN AML_STREAM FStream,
IN LIST_ENTRY NameSpaceRefList 
)

Parse the list of fixed arguments of the input ObjectNode.

For each argument, create a node and add it to the fixed argument list of the Node. If a fixed argument has children, parse them.

Parameters
[in]ObjectNodeObject node to parse the fixed arguments from.
[in]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[in]NameSpaceRefListList of namespace reference nodes.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 893 of file AmlParser.c.

◆ AmlParseNameString()

STATIC EFI_STATUS EFIAPI AmlParseNameString ( IN CONST AML_NODE_HEADER ParentNode,
IN AML_PARSE_FORMAT  ExpectedFormat,
IN OUT AML_STREAM FStream,
OUT AML_NODE_HEADER **  OutNode 
)

Parse an AML NameString.

A data node is created and returned through the OutNode parameter.

Parameters
[in]ParentNodeParent node to which the parsed AML construct will be attached.
[in]ExpectedFormatFormat of the AML construct to parse.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[out]OutNodePointer holding the node created from the parsed AML bytecode.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 218 of file AmlParser.c.

◆ AmlParseObject()

STATIC EFI_STATUS EFIAPI AmlParseObject ( IN CONST AML_NODE_HEADER ParentNode,
IN AML_PARSE_FORMAT  ExpectedFormat,
IN OUT AML_STREAM FStream,
OUT AML_NODE_HEADER **  OutNode 
)

Parse an AML object.

An object can be resolved as an AML object with an OpCode, or a NameString. An object node or a data node is created and returned through the OutNode parameter.

Parameters
[in]ParentNodeParent node to which the parsed AML construct will be attached.
[in]ExpectedFormatFormat of the AML construct to parse.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[out]OutNodePointer holding the node created from the parsed AML bytecode.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 379 of file AmlParser.c.

◆ AmlParseStream()

STATIC EFI_STATUS EFIAPI AmlParseStream ( IN AML_NODE_HEADER Node,
IN AML_STREAM FStream,
IN LIST_ENTRY NameSpaceRefList 
)

Invoke the appropriate parsing functions based on the Node type.

Parameters
[in]NodeNode from which the children are parsed. Must be a root node or an object node.
[in]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[in]NameSpaceRefListList of namespace reference nodes.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 1318 of file AmlParser.c.

◆ AmlParseString()

STATIC EFI_STATUS EFIAPI AmlParseString ( IN CONST AML_NODE_HEADER ParentNode,
IN AML_PARSE_FORMAT  ExpectedFormat,
IN OUT AML_STREAM FStream,
OUT AML_NODE_HEADER **  OutNode 
)

Parse an AML String.

A data node is created and returned through the OutNode parameter.

Parameters
[in]ParentNodeParent node to which the parsed AML construct will be attached.
[in]ExpectedFormatFormat of the AML construct to parse.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[out]OutNodePointer holding the node created from the parsed AML bytecode.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 305 of file AmlParser.c.

◆ AmlParseUIntX()

STATIC EFI_STATUS EFIAPI AmlParseUIntX ( IN CONST AML_NODE_HEADER ParentNode,
IN AML_PARSE_FORMAT  ExpectedFormat,
IN OUT AML_STREAM FStream,
OUT AML_NODE_HEADER **  OutNode 
)

Parse a UInt<X> (where X=8, 16, 32 or 64).

A data node is created and returned through the OutNode parameter.

Parameters
[in]ParentNodeParent node to which the parsed AML construct will be attached.
[in]ExpectedFormatFormat of the AML construct to parse.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[out]OutNodePointer holding the node created from the parsed AML bytecode.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 131 of file AmlParser.c.

◆ AmlParseVariableArguments()

EFI_STATUS EFIAPI AmlParseVariableArguments ( IN AML_NODE_HEADER Node,
IN AML_STREAM FStream,
IN LIST_ENTRY NameSpaceRefList 
)

Parse the variable list of arguments of the input ObjectNode.

For each variable argument, create a node and add it to the variable list of arguments of the Node. If a variable argument has children, parse them recursively.

The arguments of method invocation nodes are added to the variable list of arguments of the method invocation node. It is necessary to first get the number of arguments to parse for this kind of node. A method invocation can have at most 7 fixed arguments.

Parameters
[in]NodeNode to parse the variable arguments from.
[in]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[in]NameSpaceRefListList of namespace reference nodes.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 1031 of file AmlParser.c.

◆ AmlPopulateObjectNode()

STATIC EFI_STATUS EFIAPI AmlPopulateObjectNode ( IN AML_OBJECT_NODE ObjectNode,
IN OUT AML_STREAM FStream,
IN OUT LIST_ENTRY NameSpaceRefList 
)

Parse the AML stream an populate the object node.

Parameters
[in]ObjectNodeObjectNode to which the children are added.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[in,out]NameSpaceRefListList of namespace reference nodes.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 1207 of file AmlParser.c.

◆ AmlPopulateRootNode()

STATIC EFI_STATUS EFIAPI AmlPopulateRootNode ( IN AML_ROOT_NODE RootNode,
IN OUT AML_STREAM FStream,
IN OUT LIST_ENTRY NameSpaceRefList 
)

Parse the AML stream and populate the root node.

Parameters
[in]RootNodeRootNode to which the children are added.
[in,out]FStreamForward stream containing the AML bytecode to parse. The stream must not be at its end.
[in,out]NameSpaceRefListList of namespace reference nodes.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_OUT_OF_RESOURCESCould not allocate memory.

Definition at line 1161 of file AmlParser.c.

Variable Documentation

◆ mParseType

Initial value:
= {
NULL,
}
STATIC EFI_STATUS EFIAPI AmlParseString(IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
Definition: AmlParser.c:305
STATIC EFI_STATUS EFIAPI AmlParseNameString(IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
Definition: AmlParser.c:218
STATIC EFI_STATUS EFIAPI AmlParseUIntX(IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
Definition: AmlParser.c:131
STATIC EFI_STATUS EFIAPI AmlParseObject(IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
Definition: AmlParser.c:379
STATIC EFI_STATUS EFIAPI AmlParseFieldPkgLen(IN CONST AML_NODE_HEADER *ParentNode, IN AML_PARSE_FORMAT ExpectedFormat, IN OUT AML_STREAM *FStream, OUT AML_NODE_HEADER **OutNode)
Definition: AmlParser.c:523
#define NULL
Definition: Base.h:319

Array of functions pointers to parse the AML constructs.

The AML Byte encoding tables in Aml.c describe the format of the AML statements. The AML_PARSE_FORMAT enum definition lists these constructs and the corresponding parsing functions.

Definition at line 589 of file AmlParser.c.