4 Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
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,
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.
17 #include <AmlNodeDefines.h>
19 #include <AmlCoreInterface.h>
20 #include <AmlInclude.h>
21 #include <Api/AmlApiHelper.h>
22 #include <String/AmlString.h>
24 /** Update the name of a DeviceOp object node.
26 @param [in] DeviceOpNode Object node representing a Device.
27 Must have an OpCode=AML_NAME_OP, SubOpCode=0.
29 DeviceOp object nodes are defined in ASL
30 using the "Device ()" function.
31 @param [in] NewNameString The new Device's name.
32 Must be a NULL-terminated ASL NameString
33 e.g.: "DEV0", "DV15.DEV0", etc.
34 The input string is copied.
36 @retval EFI_SUCCESS The function completed successfully.
37 @retval EFI_INVALID_PARAMETER Invalid parameter.
41 AmlDeviceOpUpdateName (
42 IN AML_OBJECT_NODE_HANDLE DeviceOpNode
,
43 IN CHAR8
*NewNameString
48 AML_DATA_NODE_HANDLE DeviceNameDataNode
;
49 CHAR8
*NewAmlNameString
;
50 UINT32 NewAmlNameStringSize
;
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
))
59 return EFI_INVALID_PARAMETER
;
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 (
68 if ((DeviceNameDataNode
== NULL
) ||
69 (AmlGetNodeType ((AML_NODE_HANDLE
)DeviceNameDataNode
) != EAmlNodeData
) ||
70 (!AmlNodeHasDataType (DeviceNameDataNode
, EAmlNodeDataTypeNameString
)))
73 return EFI_INVALID_PARAMETER
;
76 Status
= ConvertAslNameToAmlName (NewNameString
, &NewAmlNameString
);
77 if (EFI_ERROR (Status
)) {
82 Status
= AmlGetNameStringSize (NewAmlNameString
, &NewAmlNameStringSize
);
83 if (EFI_ERROR (Status
)) {
88 // Update the Device's name node.
89 Status
= AmlUpdateDataNode (
91 EAmlNodeDataTypeNameString
,
92 (UINT8
*)NewAmlNameString
,
95 ASSERT_EFI_ERROR (Status
);
98 FreePool (NewAmlNameString
);
102 /** Update an integer value defined by a NameOp object node.
104 For compatibility reasons, the NameOpNode must initially
107 @param [in] NameOpNode NameOp object node.
108 Must have an OpCode=AML_NAME_OP, SubOpCode=0.
109 NameOp object nodes are defined in ASL
110 using the "Name ()" function.
111 @param [in] NewInt New Integer value to assign.
114 @retval EFI_SUCCESS The function completed successfully.
115 @retval EFI_INVALID_PARAMETER Invalid parameter.
119 AmlNameOpUpdateInteger (
120 IN AML_OBJECT_NODE_HANDLE NameOpNode
,
125 AML_OBJECT_NODE_HANDLE IntegerOpNode
;
127 if ((NameOpNode
== NULL
) ||
128 (AmlGetNodeType ((AML_NODE_HANDLE
)NameOpNode
) != EAmlNodeObject
) ||
129 (!AmlNodeHasOpCode (NameOpNode
, AML_NAME_OP
, 0)))
132 return EFI_INVALID_PARAMETER
;
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.
139 IntegerOpNode
= (AML_OBJECT_NODE_HANDLE
)AmlGetFixedArgument (
143 if ((IntegerOpNode
== NULL
) ||
144 (AmlGetNodeType ((AML_NODE_HANDLE
)IntegerOpNode
) != EAmlNodeObject
))
147 return EFI_INVALID_PARAMETER
;
150 // Update the Integer value.
151 Status
= AmlUpdateInteger (IntegerOpNode
, NewInt
);
152 ASSERT_EFI_ERROR (Status
);
157 /** Update a string value defined by a NameOp object node.
159 The NameOpNode must initially contain a string.
160 The EISAID ASL macro converts a string to an integer. This, it is
163 @param [in] NameOpNode NameOp object node.
164 Must have an OpCode=AML_NAME_OP, SubOpCode=0.
165 NameOp object nodes are defined in ASL
166 using the "Name ()" function.
167 @param [in] NewName New NULL terminated string to assign to
169 The input string is copied.
171 @retval EFI_SUCCESS The function completed successfully.
172 @retval EFI_INVALID_PARAMETER Invalid parameter.
176 AmlNameOpUpdateString (
177 IN AML_OBJECT_NODE_HANDLE NameOpNode
,
178 IN CONST CHAR8
*NewName
182 AML_OBJECT_NODE_HANDLE StringOpNode
;
183 AML_DATA_NODE_HANDLE StringDataNode
;
185 if ((NameOpNode
== NULL
) ||
186 (AmlGetNodeType ((AML_NODE_HANDLE
)NameOpNode
) != EAmlNodeObject
) ||
187 (!AmlNodeHasOpCode (NameOpNode
, AML_NAME_OP
, 0)))
190 return EFI_INVALID_PARAMETER
;
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.
196 StringOpNode
= (AML_OBJECT_NODE_HANDLE
)AmlGetFixedArgument (
200 if ((StringOpNode
== NULL
) ||
201 (AmlGetNodeType ((AML_NODE_HANDLE
)StringOpNode
) != EAmlNodeObject
))
204 return EFI_INVALID_PARAMETER
;
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 (
213 if ((StringDataNode
== NULL
) ||
214 (AmlGetNodeType ((AML_NODE_HANDLE
)StringDataNode
) != EAmlNodeData
))
217 return EFI_INVALID_PARAMETER
;
220 // Update the string value.
221 Status
= AmlUpdateDataNode (
223 EAmlNodeDataTypeString
,
225 (UINT32
)AsciiStrLen (NewName
) + 1
227 ASSERT_EFI_ERROR (Status
);
232 /** Get the first Resource Data element contained in a named object.
234 In the following ASL code, the function will return the Resource Data
235 node corresponding to the "QWordMemory ()" ASL macro.
236 Name (_CRS, ResourceTemplate() {
237 QWordMemory (...) {...},
238 Interrupt (...) {...}
243 "_CRS" names defined as methods are not handled by this function.
244 They must be defined as names, using the "Name ()" statement.
246 @param [in] NameOpNode NameOp object node defining a named object.
247 Must have an OpCode=AML_NAME_OP, SubOpCode=0.
248 NameOp object nodes are defined in ASL
249 using the "Name ()" function.
250 @param [out] OutRdNode Pointer to the first Resource Data element of
251 the named object. A Resource Data element
252 is stored in a data node.
254 @retval EFI_SUCCESS The function completed successfully.
255 @retval EFI_INVALID_PARAMETER Invalid parameter.
259 AmlNameOpGetFirstRdNode (
260 IN AML_OBJECT_NODE_HANDLE NameOpNode
,
261 OUT AML_DATA_NODE_HANDLE
*OutRdNode
264 AML_OBJECT_NODE_HANDLE BufferOpNode
;
265 AML_DATA_NODE_HANDLE FirstRdNode
;
267 if ((NameOpNode
== NULL
) ||
268 (AmlGetNodeType ((AML_NODE_HANDLE
)NameOpNode
) != EAmlNodeObject
) ||
269 (!AmlNodeHasOpCode (NameOpNode
, AML_NAME_OP
, 0)) ||
273 return EFI_INVALID_PARAMETER
;
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).
280 BufferOpNode
= (AML_OBJECT_NODE_HANDLE
)AmlGetFixedArgument (
284 if ((BufferOpNode
== NULL
) ||
285 (AmlGetNodeType ((AML_NODE_HANDLE
)BufferOpNode
) != EAmlNodeObject
) ||
286 (!AmlNodeHasOpCode (BufferOpNode
, AML_BUFFER_OP
, 0)))
289 return EFI_INVALID_PARAMETER
;
292 // Get the first Resource data node in the variable list of
293 // argument of the BufferOp node.
294 FirstRdNode
= (AML_DATA_NODE_HANDLE
)AmlGetNextVariableArgument (
295 (AML_NODE_HANDLE
)BufferOpNode
,
298 if ((FirstRdNode
== NULL
) ||
299 (AmlGetNodeType ((AML_NODE_HANDLE
)FirstRdNode
) != EAmlNodeData
) ||
300 (!AmlNodeHasDataType (FirstRdNode
, EAmlNodeDataTypeResourceData
)))
303 return EFI_INVALID_PARAMETER
;
306 *OutRdNode
= FirstRdNode
;
310 /** Get the Resource Data element following the CurrRdNode Resource Data.
312 In the following ASL code, if CurrRdNode corresponds to the first
313 "QWordMemory ()" ASL macro, the function will return the Resource Data
314 node corresponding to the "Interrupt ()" ASL macro.
315 Name (_CRS, ResourceTemplate() {
316 QwordMemory (...) {...},
317 Interrupt (...) {...}
322 "_CRS" names defined as methods are not handled by this function.
323 They must be defined as names, using the "Name ()" statement.
325 @param [in] CurrRdNode Pointer to the current Resource Data element of
327 @param [out] OutRdNode Pointer to the Resource Data element following
329 Contain a NULL pointer if CurrRdNode is the
330 last Resource Data element in the list.
331 The "End Tag" is not considered as a resource
332 data element and is not returned.
334 @retval EFI_SUCCESS The function completed successfully.
335 @retval EFI_INVALID_PARAMETER Invalid parameter.
339 AmlNameOpGetNextRdNode (
340 IN AML_DATA_NODE_HANDLE CurrRdNode
,
341 OUT AML_DATA_NODE_HANDLE
*OutRdNode
344 AML_OBJECT_NODE_HANDLE NameOpNode
;
345 AML_OBJECT_NODE_HANDLE BufferOpNode
;
347 if ((CurrRdNode
== NULL
) ||
348 (AmlGetNodeType ((AML_NODE_HANDLE
)CurrRdNode
) != EAmlNodeData
) ||
349 (!AmlNodeHasDataType (CurrRdNode
, EAmlNodeDataTypeResourceData
)) ||
353 return EFI_INVALID_PARAMETER
;
358 // The parent of the CurrRdNode must be a BufferOp node.
359 BufferOpNode
= (AML_OBJECT_NODE_HANDLE
)AmlGetParent (
360 (AML_NODE_HANDLE
)CurrRdNode
362 if ((BufferOpNode
== NULL
) ||
363 (!AmlNodeHasOpCode (BufferOpNode
, AML_BUFFER_OP
, 0)))
366 return EFI_INVALID_PARAMETER
;
369 // The parent of the BufferOpNode must be a NameOp node.
370 NameOpNode
= (AML_OBJECT_NODE_HANDLE
)AmlGetParent (
371 (AML_NODE_HANDLE
)BufferOpNode
373 if ((NameOpNode
== NULL
) ||
374 (!AmlNodeHasOpCode (NameOpNode
, AML_NAME_OP
, 0)))
377 return EFI_INVALID_PARAMETER
;
380 *OutRdNode
= (AML_DATA_NODE_HANDLE
)AmlGetNextVariableArgument (
381 (AML_NODE_HANDLE
)BufferOpNode
,
382 (AML_NODE_HANDLE
)CurrRdNode
385 // If the Resource Data is an End Tag, return NULL.
386 if (AmlNodeHasRdDataType (
388 AML_RD_BUILD_SMALL_DESC_ID (ACPI_SMALL_END_TAG_DESCRIPTOR_NAME
)
398 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
402 Get the first Resource Data element contained in a "_CRS" object.
404 In the following ASL code, the function will return the Resource Data
405 node corresponding to the "QWordMemory ()" ASL macro.
406 Name (_CRS, ResourceTemplate() {
407 QWordMemory (...) {...},
408 Interrupt (...) {...}
413 - The "_CRS" object must be declared using ASL "Name (Declare Named Object)".
414 - "_CRS" declared using ASL "Method (Declare Control Method)" is not
419 @param [in] NameOpCrsNode NameOp object node defining a "_CRS" object.
420 Must have an OpCode=AML_NAME_OP, SubOpCode=0.
421 NameOp object nodes are defined in ASL
422 using the "Name ()" function.
423 @param [out] OutRdNode Pointer to the first Resource Data element of
424 the "_CRS" object. A Resource Data element
425 is stored in a data node.
427 @retval EFI_SUCCESS The function completed successfully.
428 @retval EFI_INVALID_PARAMETER Invalid parameter.
432 AmlNameOpCrsGetFirstRdNode (
433 IN AML_OBJECT_NODE_HANDLE NameOpCrsNode
,
434 OUT AML_DATA_NODE_HANDLE
*OutRdNode
437 return AmlNameOpGetFirstRdNode (NameOpCrsNode
, OutRdNode
);
442 Get the Resource Data element following the CurrRdNode Resource Data.
444 In the following ASL code, if CurrRdNode corresponds to the first
445 "QWordMemory ()" ASL macro, the function will return the Resource Data
446 node corresponding to the "Interrupt ()" ASL macro.
447 Name (_CRS, ResourceTemplate() {
448 QwordMemory (...) {...},
449 Interrupt (...) {...}
453 The CurrRdNode Resource Data node must be defined in an object named "_CRS"
454 and defined by a "Name ()" ASL function.
458 @param [in] CurrRdNode Pointer to the current Resource Data element of
460 @param [out] OutRdNode Pointer to the Resource Data element following
462 Contain a NULL pointer if CurrRdNode is the
463 last Resource Data element in the list.
464 The "End Tag" is not considered as a resource
465 data element and is not returned.
467 @retval EFI_SUCCESS The function completed successfully.
468 @retval EFI_INVALID_PARAMETER Invalid parameter.
472 AmlNameOpCrsGetNextRdNode (
473 IN AML_DATA_NODE_HANDLE CurrRdNode
,
474 OUT AML_DATA_NODE_HANDLE
*OutRdNode
477 return AmlNameOpGetNextRdNode (CurrRdNode
, OutRdNode
);
480 #endif // DISABLE_NEW_DEPRECATED_INTERFACES