From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 08949D81164 for ; Thu, 8 Aug 2024 14:21:15 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=L1o8lGNw8wudZw3IQNVF+f3MJaa5dmpkF3HS6jEQG3k=; c=relaxed/simple; d=groups.io; h=From:Date:Subject:MIME-Version:Message-Id:References:In-Reply-To:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20240206; t=1723126875; v=1; b=4zRMiyytvWLySPXdwKtermFbxTtjSFQlLnKbcv66W14K2VmrBwMboU8tHeMulW+7bBi1LzT7 o5UoZo0yWqqqohZhDO6LAfrbtaIJk5K5oHxRJDSqLDvYmVV1Q0nXzXs1ohIre6oGdPB9hAooLZx nT7ai2+vxsL6248Bli2Hsp2kD/A59RmBO30GkvFV+ELY41pU3pzhFb+WuqbNAULzrYh9ToIc4Vr Rd9rafgZ/dtdBdoGnUDd70Or/jVHeSgRi/z5vk+xvFn3VJ4HpobWqrQKL0TdM8eoG2snNFEnoGK 2OtEJAfwBvmpo90sg7bwtsryNNHPOKpC3MOG/xtu7dioA== X-Received: by 127.0.0.2 with SMTP id 66ovYY7687511xr7wJOy1mM3; Thu, 08 Aug 2024 07:21:14 -0700 X-Received: from muminek.juszkiewicz.com.pl (muminek.juszkiewicz.com.pl [213.251.184.221]) by mx.groups.io with SMTP id smtpd.web11.61230.1723126873421298883 for ; Thu, 08 Aug 2024 07:21:13 -0700 X-Received: from localhost (localhost [127.0.0.1]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTP id 362D926018C; Thu, 8 Aug 2024 16:21:10 +0200 (CEST) X-Virus-Scanned: Debian amavis at juszkiewicz.com.pl X-Received: from muminek.juszkiewicz.com.pl ([127.0.0.1]) by localhost (muminek.juszkiewicz.com.pl [127.0.0.1]) (amavis, port 10024) with ESMTP id uLA_YhC-rok6; Thu, 8 Aug 2024 16:21:09 +0200 (CEST) X-Received: from applejack.lan (83.8.56.232.ipv4.supernova.orange.pl [83.8.56.232]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTPSA id 3F2E32606CF; Thu, 8 Aug 2024 16:21:08 +0200 (CEST) From: "Marcin Juszkiewicz" Date: Thu, 08 Aug 2024 16:20:57 +0200 Subject: [edk2-devel] [PATCH edk2-platforms 1/3] SbsaQemu: move SMC calls to HardwareInfoLib MIME-Version: 1.0 Message-Id: <20240808-move-from-armsmclib-to-armmonitorlib-v1-1-de5f744a272c@linaro.org> References: <20240808-move-from-armsmclib-to-armmonitorlib-v1-0-de5f744a272c@linaro.org> In-Reply-To: <20240808-move-from-armsmclib-to-armmonitorlib-v1-0-de5f744a272c@linaro.org> To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Graeme Gregory , Marcin Juszkiewicz Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Thu, 08 Aug 2024 07:21:13 -0700 Resent-From: marcin.juszkiewicz@linaro.org Reply-To: devel@edk2.groups.io,marcin.juszkiewicz@linaro.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 04KsLkRiZiu27qtJKepKhhUyx7686176AA= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=4zRMiyyt; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linaro.org (policy=none) We now have HardwareInfo library so let move all hardware queries there. Signed-off-by: Marcin Juszkiewicz --- .../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/SbsaQemuPlat= formDxe.inf b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPla= tformDxe.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 =20 [LibraryClasses] - ArmSmcLib PcdLib DebugLib + HardwareInfoLib NonDiscoverableDeviceRegistrationLib UefiDriverEntryPoint =20 diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemu= HardwareInfoLib.inf b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib= /SbsaQemuHardwareInfoLib.inf index 2acb2a1e7c76..58a9c03f18b8 100644 --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwar= eInfoLib.inf +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwar= eInfoLib.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/Sili= con/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; =20 +typedef struct { + UINTN DistributorBase; + UINTN RedistributorBase; + UINTN ItsBase; +} GicInfo; + +typedef struct { + UINT32 Major; + UINT32 Minor; +} PlatformVersion; + /** Get CPU count from information passed by Qemu. =20 @@ -109,4 +120,24 @@ GetCpuTopology ( OUT CpuTopology *CpuTopo ); =20 +/** + 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/SbsaQemuPlat= formDxe.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatf= ormDxe.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 @@ * **/ =20 -#include #include #include +#include #include #include #include #include -#include #include =20 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; =20 DEBUG ((DEBUG_INFO, "%a: InitializeSbsaQemuPlatformDxe called\n", __FUNC= TION__)); =20 @@ -68,44 +65,18 @@ InitializeSbsaQemuPlatformDxe ( return Status; } =20 - SmcResult =3D ArmCallSmc0 (SIP_SVC_VERSION, &Arg0, &Arg1, NULL); - if (SmcResult =3D=3D SMC_ARCH_CALL_SUCCESS) { - Result =3D PcdSet32S (PcdPlatformVersionMajor, Arg0); - ASSERT_RETURN_ERROR (Result); - Result =3D PcdSet32S (PcdPlatformVersionMinor, Arg1); - ASSERT_RETURN_ERROR (Result); - } + GetPlatformVersion (&PlatVer); =20 - Arg0 =3D PcdGet32 (PcdPlatformVersionMajor); - Arg1 =3D PcdGet32 (PcdPlatformVersionMinor); + PcdSet32S (PcdPlatformVersionMajor, PlatVer.Major); + PcdSet32S (PcdPlatformVersionMinor, PlatVer.Minor); =20 - DEBUG ((DEBUG_INFO, "Platform version: %d.%d\n", Arg0, Arg1)); + DEBUG ((DEBUG_INFO, "Platform version: %d.%d\n", PlatVer.Major, PlatVer.= Minor)); =20 - SmcResult =3D ArmCallSmc0 (SIP_SVC_GET_GIC, &Arg0, &Arg1, NULL); - if (SmcResult =3D=3D SMC_ARCH_CALL_SUCCESS) { - Result =3D PcdSet64S (PcdGicDistributorBase, Arg0); - ASSERT_RETURN_ERROR (Result); - Result =3D PcdSet64S (PcdGicRedistributorsBase, Arg1); - ASSERT_RETURN_ERROR (Result); - } + GetGicInformation (&GicInfo); =20 - Arg0 =3D PcdGet64 (PcdGicDistributorBase); - - DEBUG ((DEBUG_INFO, "GICD base: 0x%x\n", Arg0)); - - Arg0 =3D PcdGet64 (PcdGicRedistributorsBase); - - DEBUG ((DEBUG_INFO, "GICR base: 0x%x\n", Arg0)); - - SmcResult =3D ArmCallSmc0 (SIP_SVC_GET_GIC_ITS, &Arg0, NULL, NULL); - if (SmcResult =3D=3D SMC_ARCH_CALL_SUCCESS) { - Result =3D PcdSet64S (PcdGicItsBase, Arg0); - ASSERT_RETURN_ERROR (Result); - } - - Arg0 =3D PcdGet64 (PcdGicItsBase); - - DEBUG ((DEBUG_INFO, "GICI base: 0x%x\n", Arg0)); + PcdSet64S (PcdGicDistributorBase, GicInfo.DistributorBase); + PcdSet64S (PcdGicRedistributorsBase, GicInfo.RedistributorBase); + PcdSet64S (PcdGicItsBase, GicInfo.ItsBase); =20 if (!PLATFORM_VERSION_LESS_THAN (0, 3)) { Base =3D (VOID *)(UINTN)PcdGet64 (PcdPlatformXhciBase); diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemu= HardwareInfoLib.c b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/S= bsaQemuHardwareInfoLib.c index b8d1abe2d0bc..1d5291cf5b28 100644 --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwar= eInfoLib.c +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwar= eInfoLib.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 =3D SIP_SVC_GET_GIC; + ArmMonitorCall (&SmcArgs); + + if (SmcArgs.Arg0 !=3D SMC_SIP_CALL_SUCCESS) { + GicInfo->DistributorBase =3D PcdGet64 (PcdGicDistributorBase); + GicInfo->RedistributorBase =3D PcdGet64 (PcdGicRedistributorsBase); + } else { + GicInfo->DistributorBase =3D SmcArgs.Arg1; + GicInfo->RedistributorBase =3D SmcArgs.Arg2; + } + + SmcArgs.Arg0 =3D SIP_SVC_GET_GIC_ITS; + ArmMonitorCall (&SmcArgs); + + if (SmcArgs.Arg0 !=3D SMC_SIP_CALL_SUCCESS) { + GicInfo->ItsBase =3D PcdGet64 (PcdGicItsBase); + } else { + GicInfo->ItsBase =3D 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 =3D SIP_SVC_VERSION; + ArmMonitorCall (&SmcArgs); + + if (SmcArgs.Arg0 !=3D SMC_SIP_CALL_SUCCESS) { + PlatVer->Major =3D 0; + PlatVer->Minor =3D 0; + } else { + PlatVer->Major =3D SmcArgs.Arg1; + PlatVer->Minor =3D SmcArgs.Arg2; + } +} --=20 2.45.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-