Skip to content

Commit

Permalink
DynamicTablesPkg: Correct _PSD package format
Browse files Browse the repository at this point in the history
The _PSD structure should have nested packages.

The current implementation generates

Name (_PSD, Package()
   {
   NumEntries             // Integer
   Revision               // Integer (BYTE)
   Domain                 // Integer (DWORD)
   CoordType              // Integer (DWORD)
   NumProcessors          // Integer (DWORD)
})

when this should be

Name (_PSD, Package()
   {
    Package()
    {
    NumEntries             // Integer
    Revision               // Integer (BYTE)
    Domain                 // Integer (DWORD)
    CoordType              // Integer (DWORD)
    NumProcessors          // Integer (DWORD)
    }
})

REF: https://uefi.org/specs/ACPI/6.5/08_Processor_Configuration_and_Control.html#psd-p-state-dependency
Signed-off-by: Jeff Brasen <[email protected]>
  • Loading branch information
jbrasen authored and mergify[bot] committed Oct 4, 2024
1 parent 54469a6 commit 8cce048
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c
Original file line number Diff line number Diff line change
Expand Up @@ -4183,11 +4183,13 @@ AmlCodeGenInvokeMethod (
Creates and optionally adds the following node
Name(_PSD, Package()
{
NumEntries, // Integer
Revision, // Integer
Domain, // Integer
CoordType, // Integer
NumProc, // Integer
Package () {
NumEntries, // Integer
Revision, // Integer
Domain, // Integer
CoordType, // Integer
NumProc, // Integer
}
})
Cf. ACPI 6.5, s8.4.5.5 _PSD (P-State Dependency)
Expand All @@ -4213,10 +4215,14 @@ AmlCreatePsdNode (
{
EFI_STATUS Status;
AML_OBJECT_NODE_HANDLE PsdNode;
AML_OBJECT_NODE_HANDLE PsdParentPackage;
AML_OBJECT_NODE_HANDLE PsdPackage;
AML_OBJECT_NODE_HANDLE IntegerNode;
UINT32 NumberOfEntries;

PsdParentPackage = NULL;
PsdPackage = NULL;

if ((PsdInfo == NULL) ||
((ParentNode == NULL) && (NewPsdNode == NULL)))
{
Expand Down Expand Up @@ -4253,19 +4259,25 @@ AmlCreatePsdNode (

// Get the Package object node of the _PSD node,
// which is the 2nd fixed argument (i.e. index 1).
PsdPackage = (AML_OBJECT_NODE_HANDLE)AmlGetFixedArgument (
PsdNode,
EAmlParseIndexTerm1
);
if ((PsdPackage == NULL) ||
(AmlGetNodeType ((AML_NODE_HANDLE)PsdPackage) != EAmlNodeObject) ||
(!AmlNodeHasOpCode (PsdPackage, AML_PACKAGE_OP, 0)))
PsdParentPackage = (AML_OBJECT_NODE_HANDLE)AmlGetFixedArgument (
PsdNode,
EAmlParseIndexTerm1
);
if ((PsdParentPackage == NULL) ||
(AmlGetNodeType ((AML_NODE_HANDLE)PsdParentPackage) != EAmlNodeObject) ||
(!AmlNodeHasOpCode (PsdParentPackage, AML_PACKAGE_OP, 0)))
{
Status = EFI_INVALID_PARAMETER;
ASSERT_EFI_ERROR (Status);
goto error_handler;
}

Status = AmlCodeGenPackage (&PsdPackage);
if (EFI_ERROR (Status)) {
ASSERT_EFI_ERROR (Status);
goto error_handler;
}

// NumEntries
Status = AmlCodeGenInteger (NumberOfEntries, &IntegerNode);
if (EFI_ERROR (Status)) {
Expand Down Expand Up @@ -4351,6 +4363,17 @@ AmlCreatePsdNode (
goto error_handler;
}

Status = AmlVarListAddTail (
(AML_NODE_HANDLE)PsdParentPackage,
(AML_NODE_HANDLE)PsdPackage
);
if (EFI_ERROR (Status)) {
ASSERT_EFI_ERROR (Status);
goto error_handler;
}

PsdPackage = NULL; // Prevent double free if error occurs after this point

Status = LinkNode (PsdNode, ParentNode, NewPsdNode);
if (EFI_ERROR (Status)) {
ASSERT_EFI_ERROR (Status);
Expand All @@ -4360,6 +4383,13 @@ AmlCreatePsdNode (
return Status;

error_handler:
AmlDeleteTree ((AML_NODE_HANDLE)PsdNode);
if (PsdPackage != NULL) {
AmlDeleteTree ((AML_NODE_HANDLE)PsdPackage);
}

if (PsdParentPackage != NULL) {
AmlDeleteTree ((AML_NODE_HANDLE)PsdParentPackage);
}

return Status;
}

0 comments on commit 8cce048

Please sign in to comment.