From: "Marcin Juszkiewicz" <marcin.juszkiewicz@linaro.org>
To: devel@edk2.groups.io
Cc: Leif Lindholm <quic_llindhol@quicinc.com>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
Graeme Gregory <graeme@xora.org.uk>,
Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
Subject: [edk2-devel] [PATCH edk2-platforms 1/3] SbsaQemu: move SMC calls to HardwareInfoLib
Date: Thu, 08 Aug 2024 16:20:57 +0200 [thread overview]
Message-ID: <20240808-move-from-armsmclib-to-armmonitorlib-v1-1-de5f744a272c@linaro.org> (raw)
In-Reply-To: <20240808-move-from-armsmclib-to-armmonitorlib-v1-0-de5f744a272c@linaro.org>
We now have HardwareInfo library so let move all hardware queries there.
Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@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/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2024-08-08 14:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-08 14:20 [edk2-devel] [PATCH edk2-platforms 0/3] SbsaQemu: Move from ArmSmcLib to ArmMonitorLib Marcin Juszkiewicz
2024-08-08 14:20 ` Marcin Juszkiewicz [this message]
2024-08-08 14:20 ` [edk2-devel] [PATCH edk2-platforms 2/3] SbsaQemu: move " Marcin Juszkiewicz
2024-08-08 14:20 ` [edk2-devel] [PATCH edk2-platforms 3/3] SbsaQemu: drop not needed packages Marcin Juszkiewicz
2024-08-08 16:51 ` [edk2-devel] [PATCH edk2-platforms 0/3] SbsaQemu: Move from ArmSmcLib to ArmMonitorLib Leif Lindholm
2024-08-08 17:53 ` Marcin Juszkiewicz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240808-move-from-armsmclib-to-armmonitorlib-v1-1-de5f744a272c@linaro.org \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox