diff mbox

[edk2,08/21] ArmVirtPkg/ArmVirtPsciResetSystemLib: move to FDT client protocol

Message ID 1459959319-19293-9-git-send-email-ard.biesheuvel@linaro.org
State Superseded
Headers show

Commit Message

Ard Biesheuvel April 6, 2016, 4:15 p.m. UTC
Instead of relying on VirtFdtDxe to detect the PSCI method, move our
EfiResetSystemLib to the FDT client protocol to interrogate the device
tree directly.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.c   | 38 +++++++++++++++++---
 ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.inf | 11 +++---
 2 files changed, 41 insertions(+), 8 deletions(-)

-- 
2.5.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox

Patch

diff --git a/ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.c b/ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.c
index 88332f56fd9c..1cedb943d841 100644
--- a/ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.c
+++ b/ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.c
@@ -26,19 +26,49 @@ 
 #include <Library/EfiResetSystemLib.h>
 #include <Library/ArmSmcLib.h>
 #include <Library/ArmHvcLib.h>
+#include <Library/UefiBootServicesTableLib.h>
 
 #include <IndustryStandard/ArmStdSmc.h>
 
+#include <Protocol/FdtClient.h>
+
 STATIC UINT32 mArmPsciMethod;
 
-RETURN_STATUS
+EFI_STATUS
 EFIAPI
 ArmPsciResetSystemLibConstructor (
-  VOID
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  mArmPsciMethod = PcdGet32 (PcdArmPsciMethod);
-  return RETURN_SUCCESS;
+  EFI_STATUS            Status;
+  FDT_CLIENT_PROTOCOL   *FdtClient;
+  CONST VOID            *Prop;
+
+  Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, (VOID **)&FdtClient);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = FdtClient->FindCompatibleNodeProperty (FdtClient,
+                                                  "arm,psci-0.2",
+                                                  "method",
+                                                  &Prop,
+                                                  NULL);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  if (AsciiStrnCmp (Prop, "hvc", 3) == 0) {
+    mArmPsciMethod = 1;
+  } else if (AsciiStrnCmp (Prop, "smc", 3) == 0) {
+    mArmPsciMethod = 2;
+  } else {
+        DEBUG ((EFI_D_ERROR, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__,
+          Prop));
+        return EFI_NOT_FOUND;
+  }
+  return EFI_SUCCESS;
 }
 
 /**
diff --git a/ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.inf b/ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.inf
index 86d6104ca258..4b1668f54e8f 100644
--- a/ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.inf
+++ b/ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.inf
@@ -18,9 +18,9 @@  [Defines]
   INF_VERSION                    = 0x00010005
   BASE_NAME                      = ArmVirtPsciResetSystemLib
   FILE_GUID                      = c81d76ed-66fa-44a3-ac4a-f163120187a9
-  MODULE_TYPE                    = BASE
+  MODULE_TYPE                    = DXE_DRIVER
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = EfiResetSystemLib
+  LIBRARY_CLASS                  = EfiResetSystemLib|DXE_DRIVER DXE_RUNTIME_DRIVER
   CONSTRUCTOR                    = ArmPsciResetSystemLibConstructor
 
 [Sources]
@@ -38,5 +38,8 @@  [LibraryClasses]
   ArmSmcLib
   ArmHvcLib
 
-[Pcd]
-  gArmVirtTokenSpaceGuid.PcdArmPsciMethod
+[Protocols]
+  gFdtClientProtocolGuid
+
+[Depex]
+  gFdtClientProtocolGuid