TianoCore EDK2 master
Loading...
Searching...
No Matches
AmlApi.c
Go to the documentation of this file.
1
9/* Even though this file has access to the internal Node definition,
10 i.e. AML_ROOT_NODE, AML_OBJECT_NODE, etc. Only the external node
11 handle types should be used, i.e. AML_NODE_HANDLE, AML_ROOT_NODE_HANDLE,
12 etc.
13 Indeed, the functions in the "Api" folder should be implemented only
14 using the "safe" functions available in the "Include" folder. This
15 makes the functions available in the "Api" folder easy to export.
16*/
17#include <AmlNodeDefines.h>
18
19#include <AmlCoreInterface.h>
20#include <AmlInclude.h>
21#include <Api/AmlApiHelper.h>
22#include <String/AmlString.h>
23
40EFIAPI
42 IN AML_OBJECT_NODE_HANDLE DeviceOpNode,
43 IN CONST CHAR8 *NewNameString
44 )
45{
46 EFI_STATUS Status;
47
48 AML_DATA_NODE_HANDLE DeviceNameDataNode;
49 CHAR8 *NewAmlNameString;
50 UINT32 NewAmlNameStringSize;
51
52 // Check the input node is an object node.
53 if ((DeviceOpNode == NULL) ||
54 (AmlGetNodeType ((AML_NODE_HANDLE)DeviceOpNode) != EAmlNodeObject) ||
55 (!AmlNodeHasOpCode (DeviceOpNode, AML_EXT_OP, AML_EXT_DEVICE_OP)) ||
56 (NewNameString == NULL))
57 {
58 ASSERT (0);
59 return EFI_INVALID_PARAMETER;
60 }
61
62 // Get the Device's name, being a data node
63 // which is the 1st fixed argument (i.e. index 0).
64 DeviceNameDataNode = (AML_DATA_NODE_HANDLE)AmlGetFixedArgument (
65 DeviceOpNode,
67 );
68 if ((DeviceNameDataNode == NULL) ||
69 (AmlGetNodeType ((AML_NODE_HANDLE)DeviceNameDataNode) != EAmlNodeData) ||
70 (!AmlNodeHasDataType (DeviceNameDataNode, EAmlNodeDataTypeNameString)))
71 {
72 ASSERT (0);
73 return EFI_INVALID_PARAMETER;
74 }
75
76 Status = ConvertAslNameToAmlName (NewNameString, &NewAmlNameString);
77 if (EFI_ERROR (Status)) {
78 ASSERT (0);
79 return Status;
80 }
81
82 Status = AmlGetNameStringSize (NewAmlNameString, &NewAmlNameStringSize);
83 if (EFI_ERROR (Status)) {
84 ASSERT (0);
85 goto exit_handler;
86 }
87
88 // Update the Device's name node.
89 Status = AmlUpdateDataNode (
90 DeviceNameDataNode,
92 (UINT8 *)NewAmlNameString,
93 NewAmlNameStringSize
94 );
95 ASSERT_EFI_ERROR (Status);
96
97exit_handler:
98 FreePool (NewAmlNameString);
99 return Status;
100}
101
118EFIAPI
120 IN AML_OBJECT_NODE_HANDLE NameOpNode,
121 IN UINT64 NewInt
122 )
123{
124 EFI_STATUS Status;
125 AML_OBJECT_NODE_HANDLE IntegerOpNode;
126
127 if ((NameOpNode == NULL) ||
128 (AmlGetNodeType ((AML_NODE_HANDLE)NameOpNode) != EAmlNodeObject) ||
129 (!AmlNodeHasOpCode (NameOpNode, AML_NAME_OP, 0)))
130 {
131 ASSERT (0);
132 return EFI_INVALID_PARAMETER;
133 }
134
135 // Get the Integer object node defined by the "Name ()" function:
136 // it must have an Integer OpCode (Byte/Word/DWord/QWord).
137 // It is the 2nd fixed argument (i.e. index 1) of the NameOp node.
138 // This can also be a ZeroOp or OneOp node.
140 NameOpNode,
142 );
143 if ((IntegerOpNode == NULL) ||
144 (AmlGetNodeType ((AML_NODE_HANDLE)IntegerOpNode) != EAmlNodeObject))
145 {
146 ASSERT (0);
147 return EFI_INVALID_PARAMETER;
148 }
149
150 // Update the Integer value.
151 Status = AmlUpdateInteger (IntegerOpNode, NewInt);
152 ASSERT_EFI_ERROR (Status);
153
154 return Status;
155}
156
175EFIAPI
177 IN AML_OBJECT_NODE_HANDLE NameOpNode,
178 IN CONST CHAR8 *NewName
179 )
180{
181 EFI_STATUS Status;
182 AML_OBJECT_NODE_HANDLE StringOpNode;
183 AML_DATA_NODE_HANDLE StringDataNode;
184
185 if ((NameOpNode == NULL) ||
186 (AmlGetNodeType ((AML_NODE_HANDLE)NameOpNode) != EAmlNodeObject) ||
187 (!AmlNodeHasOpCode (NameOpNode, AML_NAME_OP, 0)))
188 {
189 ASSERT (0);
190 return EFI_INVALID_PARAMETER;
191 }
192
193 // Get the String object node defined by the "Name ()" function:
194 // it must have a string OpCode.
195 // It is the 2nd fixed argument (i.e. index 1) of the NameOp node.
197 NameOpNode,
199 );
200 if ((StringOpNode == NULL) ||
201 (AmlGetNodeType ((AML_NODE_HANDLE)StringOpNode) != EAmlNodeObject))
202 {
203 ASSERT (0);
204 return EFI_INVALID_PARAMETER;
205 }
206
207 // Get the string data node.
208 // It is the 1st fixed argument (i.e. index 0) of the StringOpNode node.
209 StringDataNode = (AML_DATA_NODE_HANDLE)AmlGetFixedArgument (
210 StringOpNode,
212 );
213 if ((StringDataNode == NULL) ||
214 (AmlGetNodeType ((AML_NODE_HANDLE)StringDataNode) != EAmlNodeData))
215 {
216 ASSERT (0);
217 return EFI_INVALID_PARAMETER;
218 }
219
220 // Update the string value.
221 Status = AmlUpdateDataNode (
222 StringDataNode,
224 (UINT8 *)NewName,
225 (UINT32)AsciiStrLen (NewName) + 1
226 );
227 ASSERT_EFI_ERROR (Status);
228
229 return Status;
230}
231
258EFIAPI
260 IN AML_OBJECT_NODE_HANDLE NameOpNode,
261 OUT AML_DATA_NODE_HANDLE *OutRdNode
262 )
263{
264 AML_OBJECT_NODE_HANDLE BufferOpNode;
265 AML_DATA_NODE_HANDLE FirstRdNode;
266
267 if ((NameOpNode == NULL) ||
268 (AmlGetNodeType ((AML_NODE_HANDLE)NameOpNode) != EAmlNodeObject) ||
269 (!AmlNodeHasOpCode (NameOpNode, AML_NAME_OP, 0)) ||
270 (OutRdNode == NULL))
271 {
272 ASSERT (0);
273 return EFI_INVALID_PARAMETER;
274 }
275
276 *OutRdNode = NULL;
277
278 // Get the value of the variable which is represented as a BufferOp object
279 // node which is the 2nd fixed argument (i.e. index 1).
281 NameOpNode,
283 );
284 if ((BufferOpNode == NULL) ||
285 (AmlGetNodeType ((AML_NODE_HANDLE)BufferOpNode) != EAmlNodeObject) ||
286 (!AmlNodeHasOpCode (BufferOpNode, AML_BUFFER_OP, 0)))
287 {
288 ASSERT (0);
289 return EFI_INVALID_PARAMETER;
290 }
291
292 // Get the first Resource data node in the variable list of
293 // argument of the BufferOp node.
295 (AML_NODE_HANDLE)BufferOpNode,
296 NULL
297 );
298 if ((FirstRdNode == NULL) ||
299 (AmlGetNodeType ((AML_NODE_HANDLE)FirstRdNode) != EAmlNodeData) ||
301 {
302 ASSERT (0);
303 return EFI_INVALID_PARAMETER;
304 }
305
306 *OutRdNode = FirstRdNode;
307 return EFI_SUCCESS;
308}
309
338EFIAPI
340 IN AML_DATA_NODE_HANDLE CurrRdNode,
341 OUT AML_DATA_NODE_HANDLE *OutRdNode
342 )
343{
344 AML_OBJECT_NODE_HANDLE NameOpNode;
345 AML_OBJECT_NODE_HANDLE BufferOpNode;
346
347 if ((CurrRdNode == NULL) ||
348 (AmlGetNodeType ((AML_NODE_HANDLE)CurrRdNode) != EAmlNodeData) ||
350 (OutRdNode == NULL))
351 {
352 ASSERT (0);
353 return EFI_INVALID_PARAMETER;
354 }
355
356 *OutRdNode = NULL;
357
358 // The parent of the CurrRdNode must be a BufferOp node.
359 BufferOpNode = (AML_OBJECT_NODE_HANDLE)AmlGetParent (
360 (AML_NODE_HANDLE)CurrRdNode
361 );
362 if ((BufferOpNode == NULL) ||
363 (!AmlNodeHasOpCode (BufferOpNode, AML_BUFFER_OP, 0)))
364 {
365 ASSERT (0);
366 return EFI_INVALID_PARAMETER;
367 }
368
369 // The parent of the BufferOpNode must be a NameOp node.
371 (AML_NODE_HANDLE)BufferOpNode
372 );
373 if ((NameOpNode == NULL) ||
374 (!AmlNodeHasOpCode (NameOpNode, AML_NAME_OP, 0)))
375 {
376 ASSERT (0);
377 return EFI_INVALID_PARAMETER;
378 }
379
381 (AML_NODE_HANDLE)BufferOpNode,
382 (AML_NODE_HANDLE)CurrRdNode
383 );
384
385 // If the Resource Data is an End Tag, return NULL.
387 *OutRdNode,
388 AML_RD_BUILD_SMALL_DESC_ID (ACPI_SMALL_END_TAG_DESCRIPTOR_NAME)
389 ))
390 {
391 *OutRdNode = NULL;
392 }
393
394 return EFI_SUCCESS;
395}
396
424EFIAPI
426 IN AML_NODE_HANDLE ParentNode,
427 IN AML_NODE_HANDLE NewNode
428 )
429{
430 return AmlVarListAddTail (ParentNode, NewNode);
431}
EFI_STATUS EFIAPI AmlAttachNode(IN AML_NODE_HANDLE ParentNode, IN AML_NODE_HANDLE NewNode)
Definition: AmlApi.c:425
BOOLEAN EFIAPI AmlNodeHasDataType(IN AML_DATA_NODE_HANDLE DataNode, IN EAML_NODE_DATA_TYPE DataType)
Definition: AmlApiHelper.c:168
BOOLEAN EFIAPI AmlNodeHasOpCode(IN AML_OBJECT_NODE_HANDLE ObjectNode, IN UINT8 OpCode, IN UINT8 SubOpCode)
Definition: AmlApiHelper.c:124
BOOLEAN EFIAPI AmlNodeHasRdDataType(IN AML_DATA_NODE_HANDLE RdNode, IN AML_RD_HEADER RdDataType)
Definition: AmlApiHelper.c:202
EFI_STATUS EFIAPI AmlUpdateInteger(IN AML_OBJECT_NODE_HANDLE IntegerOpNode, IN UINT64 NewInteger)
void * AML_DATA_NODE_HANDLE
Definition: AmlLib.h:59
void * AML_OBJECT_NODE_HANDLE
Definition: AmlLib.h:55
void * AML_NODE_HANDLE
Definition: AmlLib.h:47
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
EFI_STATUS EFIAPI AmlGetNameStringSize(IN CONST CHAR8 *AmlPath, OUT UINT32 *AmlPathSizePtr)
Definition: AmlString.c:547
EFI_STATUS EFIAPI ConvertAslNameToAmlName(IN CONST CHAR8 *AslPath, OUT CHAR8 **OutAmlPath)
Definition: AmlString.c:598
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
AML_NODE_HANDLE EFIAPI AmlGetParent(IN AML_NODE_HANDLE Node)
AML_NODE_HANDLE EFIAPI AmlGetFixedArgument(IN AML_OBJECT_NODE_HANDLE ObjectNode, IN EAML_PARSE_INDEX Index)
AML_NODE_HANDLE EFIAPI AmlGetNextVariableArgument(IN AML_NODE_HANDLE Node, IN AML_NODE_HANDLE CurrVarArg)
EFI_STATUS EFIAPI AmlUpdateDataNode(IN AML_DATA_NODE_HANDLE DataNode, IN EAML_NODE_DATA_TYPE DataType, IN UINT8 *Buffer, IN UINT32 Size)
EAML_NODE_TYPE EFIAPI AmlGetNodeType(IN AML_NODE_HANDLE Node)
#define AML_RD_BUILD_SMALL_DESC_ID(Id)
EFI_STATUS EFIAPI AmlVarListAddTail(IN AML_NODE_HANDLE ParentNode, IN AML_NODE_HANDLE NewNode)
@ EAmlParseIndexTerm1
Second fixed argument index.
Definition: AmlDefines.h:66
@ EAmlParseIndexTerm0
First fixed argument index.
Definition: AmlDefines.h:65
@ EAmlNodeData
Definition: AmlDefines.h:176
@ EAmlNodeObject
Definition: AmlDefines.h:174
@ EAmlNodeDataTypeString
EAmlString, NULL terminated string.
Definition: AmlDefines.h:40
@ EAmlNodeDataTypeResourceData
Resource data element.
Definition: AmlDefines.h:44
@ EAmlNodeDataTypeNameString
Definition: AmlDefines.h:37
EFI_STATUS EFIAPI AmlNameOpGetNextRdNode(IN AML_DATA_NODE_HANDLE CurrRdNode, OUT AML_DATA_NODE_HANDLE *OutRdNode)
Definition: AmlApi.c:339
EFI_STATUS EFIAPI AmlNameOpGetFirstRdNode(IN AML_OBJECT_NODE_HANDLE NameOpNode, OUT AML_DATA_NODE_HANDLE *OutRdNode)
Definition: AmlApi.c:259
EFI_STATUS EFIAPI AmlDeviceOpUpdateName(IN AML_OBJECT_NODE_HANDLE DeviceOpNode, IN CONST CHAR8 *NewNameString)
Definition: AmlApi.c:41
EFI_STATUS EFIAPI AmlNameOpUpdateInteger(IN AML_OBJECT_NODE_HANDLE NameOpNode, IN UINT64 NewInt)
Definition: AmlApi.c:119
EFI_STATUS EFIAPI AmlNameOpUpdateString(IN AML_OBJECT_NODE_HANDLE NameOpNode, IN CONST CHAR8 *NewName)
Definition: AmlApi.c:176