We now have HardwareInfo library so let move all hardware queries there.

Signed-off-by: Marcin Juszkiewicz <marcin.juszkiew...@linaro.org>
---
 .../SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.inf      |  2 +-
 .../SbsaQemuHardwareInfoLib.inf                      |  5 ++
 .../Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h  | 31 +++++++++++
 .../SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c        | 57 +++++---------------
 .../SbsaQemuHardwareInfoLib.c                        | 57 ++++++++++++++++++++
 5 files changed, 108 insertions(+), 44 deletions(-)

diff --git 
a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.inf 
b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.inf
index 19534b7a274a..72492df11342 100644
--- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.inf
+++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.inf
@@ -28,9 +28,9 @@ [Packages]
   Silicon/Qemu/SbsaQemu/SbsaQemu.dec
 
 [LibraryClasses]
-  ArmSmcLib
   PcdLib
   DebugLib
+  HardwareInfoLib
   NonDiscoverableDeviceRegistrationLib
   UefiDriverEntryPoint
 
diff --git 
a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf
 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf
index 2acb2a1e7c76..58a9c03f18b8 100644
--- 
a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf
+++ 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf
@@ -27,3 +27,8 @@ [Packages]
 [LibraryClasses]
   ArmSmcLib
   ResetSystemLib
+
+[Pcd]
+  gArmTokenSpaceGuid.PcdGicDistributorBase
+  gArmTokenSpaceGuid.PcdGicRedistributorsBase
+  gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdGicItsBase
diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h 
b/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h
index 7e0bd962f8a9..03335609bef6 100644
--- a/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h
+++ b/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h
@@ -28,6 +28,17 @@ typedef struct {
   UINT32    Threads;
 } CpuTopology;
 
+typedef struct {
+  UINTN    DistributorBase;
+  UINTN    RedistributorBase;
+  UINTN    ItsBase;
+} GicInfo;
+
+typedef struct {
+  UINT32    Major;
+  UINT32    Minor;
+} PlatformVersion;
+
 /**
   Get CPU count from information passed by Qemu.
 
@@ -109,4 +120,24 @@ GetCpuTopology (
   OUT CpuTopology  *CpuTopo
   );
 
+/**
+  Get GIC information (base of GICD, GICR, GICI) from TF-A.
+
+  @param [out]  GicInfo     A pointer to the GIC information.
+**/
+VOID
+GetGicInformation (
+  OUT GicInfo  *GicInfo
+  );
+
+/**
+  Get Platform version from TF-A.
+
+  @param [out]  PlatVer     A pointer to the Platform version.
+**/
+VOID
+GetPlatformVersion (
+  OUT PlatformVersion  *PlatVer
+  );
+
 #endif /* HARDWARE_INFO_LIB */
diff --git 
a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c 
b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c
index 657f9700062b..a9c664e1db1f 100644
--- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c
+++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c
@@ -7,14 +7,13 @@
 *
 **/
 
-#include <Library/ArmSmcLib.h>
 #include <Library/BaseLib.h>
 #include <Library/DebugLib.h>
+#include <Library/HardwareInfoLib.h>
 #include <Library/NonDiscoverableDeviceRegistrationLib.h>
 #include <Library/PcdLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiDriverEntryPoint.h>
-#include <IndustryStandard/SbsaQemuSmc.h>
 #include <IndustryStandard/SbsaQemuPlatformVersion.h>
 
 EFI_STATUS
@@ -24,13 +23,11 @@ InitializeSbsaQemuPlatformDxe (
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  EFI_STATUS     Status;
-  UINTN          Size;
-  VOID           *Base;
-  UINTN          Arg0;
-  UINTN          Arg1;
-  UINTN          SmcResult;
-  RETURN_STATUS  Result;
+  EFI_STATUS       Status;
+  UINTN            Size;
+  VOID             *Base;
+  GicInfo          GicInfo;
+  PlatformVersion  PlatVer;
 
   DEBUG ((DEBUG_INFO, "%a: InitializeSbsaQemuPlatformDxe called\n", 
__FUNCTION__));
 
@@ -68,44 +65,18 @@ InitializeSbsaQemuPlatformDxe (
     return Status;
   }
 
-  SmcResult = ArmCallSmc0 (SIP_SVC_VERSION, &Arg0, &Arg1, NULL);
-  if (SmcResult == SMC_ARCH_CALL_SUCCESS) {
-    Result = PcdSet32S (PcdPlatformVersionMajor, Arg0);
-    ASSERT_RETURN_ERROR (Result);
-    Result = PcdSet32S (PcdPlatformVersionMinor, Arg1);
-    ASSERT_RETURN_ERROR (Result);
-  }
+  GetPlatformVersion (&PlatVer);
 
-  Arg0 = PcdGet32 (PcdPlatformVersionMajor);
-  Arg1 = PcdGet32 (PcdPlatformVersionMinor);
+  PcdSet32S (PcdPlatformVersionMajor, PlatVer.Major);
+  PcdSet32S (PcdPlatformVersionMinor, PlatVer.Minor);
 
-  DEBUG ((DEBUG_INFO, "Platform version: %d.%d\n", Arg0, Arg1));
+  DEBUG ((DEBUG_INFO, "Platform version: %d.%d\n", PlatVer.Major, 
PlatVer.Minor));
 
-  SmcResult = ArmCallSmc0 (SIP_SVC_GET_GIC, &Arg0, &Arg1, NULL);
-  if (SmcResult == SMC_ARCH_CALL_SUCCESS) {
-    Result = PcdSet64S (PcdGicDistributorBase, Arg0);
-    ASSERT_RETURN_ERROR (Result);
-    Result = PcdSet64S (PcdGicRedistributorsBase, Arg1);
-    ASSERT_RETURN_ERROR (Result);
-  }
+  GetGicInformation (&GicInfo);
 
-  Arg0 = PcdGet64 (PcdGicDistributorBase);
-
-  DEBUG ((DEBUG_INFO, "GICD base: 0x%x\n", Arg0));
-
-  Arg0 = PcdGet64 (PcdGicRedistributorsBase);
-
-  DEBUG ((DEBUG_INFO, "GICR base: 0x%x\n", Arg0));
-
-  SmcResult = ArmCallSmc0 (SIP_SVC_GET_GIC_ITS, &Arg0, NULL, NULL);
-  if (SmcResult == SMC_ARCH_CALL_SUCCESS) {
-    Result = PcdSet64S (PcdGicItsBase, Arg0);
-    ASSERT_RETURN_ERROR (Result);
-  }
-
-  Arg0 = PcdGet64 (PcdGicItsBase);
-
-  DEBUG ((DEBUG_INFO, "GICI base: 0x%x\n", Arg0));
+  PcdSet64S (PcdGicDistributorBase, GicInfo.DistributorBase);
+  PcdSet64S (PcdGicRedistributorsBase, GicInfo.RedistributorBase);
+  PcdSet64S (PcdGicItsBase, GicInfo.ItsBase);
 
   if (!PLATFORM_VERSION_LESS_THAN (0, 3)) {
     Base = (VOID *)(UINTN)PcdGet64 (PcdPlatformXhciBase);
diff --git 
a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
index b8d1abe2d0bc..1d5291cf5b28 100644
--- 
a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
+++ 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
@@ -216,3 +216,60 @@ GetCpuTopology (
     CpuTopo->Threads
     ));
 }
+
+/**
+  Get GIC information from TF-A.
+
+  If run on old platform then use values from EDK2 configuration.
+**/
+VOID
+GetGicInformation (
+  OUT GicInfo  *GicInfo
+  )
+{
+  ARM_MONITOR_ARGS  SmcArgs;
+
+  SmcArgs.Arg0 = SIP_SVC_GET_GIC;
+  ArmMonitorCall (&SmcArgs);
+
+  if (SmcArgs.Arg0 != SMC_SIP_CALL_SUCCESS) {
+    GicInfo->DistributorBase   = PcdGet64 (PcdGicDistributorBase);
+    GicInfo->RedistributorBase = PcdGet64 (PcdGicRedistributorsBase);
+  } else {
+    GicInfo->DistributorBase   = SmcArgs.Arg1;
+    GicInfo->RedistributorBase = SmcArgs.Arg2;
+  }
+
+  SmcArgs.Arg0 = SIP_SVC_GET_GIC_ITS;
+  ArmMonitorCall (&SmcArgs);
+
+  if (SmcArgs.Arg0 != SMC_SIP_CALL_SUCCESS) {
+    GicInfo->ItsBase = PcdGet64 (PcdGicItsBase);
+  } else {
+    GicInfo->ItsBase = SmcArgs.Arg1;
+  }
+}
+
+/**
+  Get Platform version from TF-A.
+
+  If run on old platform then 0.0 value is used.
+**/
+VOID
+GetPlatformVersion (
+  OUT PlatformVersion  *PlatVer
+  )
+{
+  ARM_MONITOR_ARGS  SmcArgs;
+
+  SmcArgs.Arg0 = SIP_SVC_VERSION;
+  ArmMonitorCall (&SmcArgs);
+
+  if (SmcArgs.Arg0 != SMC_SIP_CALL_SUCCESS) {
+    PlatVer->Major = 0;
+    PlatVer->Minor = 0;
+  } else {
+    PlatVer->Major = SmcArgs.Arg1;
+    PlatVer->Minor = SmcArgs.Arg2;
+  }
+}

-- 
2.45.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120296): https://edk2.groups.io/g/devel/message/120296
Mute This Topic: https://groups.io/mt/107790446/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to