From: "Ard Biesheuvel" <ard.biesheuvel@linaro.org>
To: devel@edk2.groups.io
Cc: lersek@redhat.com, Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH 3/4] ArmVirtPkg/PlatformPeiLib: implement Reset2 PPI based on PSCI
Date: Tue, 7 Jan 2020 10:47:59 +0100 [thread overview]
Message-ID: <20200107094800.4488-4-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20200107094800.4488-1-ard.biesheuvel@linaro.org>
Extend the existing DT traversal routine in PlatformPeiLib with
discovery of the PSCI method, and expose an implementation of the
Reset2 PPI based on the method found.
This satisfies a dependency of Tcg2Pei, which needs to reset the
platform in some cases. Since there are no other uses for system
reset in PEI on ArmVirtQemu, simply expose the PPI directly rather
than using the generic ResetSystemPei and the associated plumbing.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf | 3 +
ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c | 123 ++++++++++++++++++++
2 files changed, 126 insertions(+)
diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
index c41ee22c9767..72ed2413a768 100644
--- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
+++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
@@ -28,6 +28,8 @@ [Packages]
SecurityPkg/SecurityPkg.dec
[LibraryClasses]
+ ArmSmcLib
+ ArmHvcLib
DebugLib
HobLib
FdtLib
@@ -44,6 +46,7 @@ [Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## SOMETIMES_PRODUCES
[Ppis]
+ gEfiPeiReset2PpiGuid ## SOMETIMES_PRODUCES
gOvmfTpmDiscoveredPpiGuid ## SOMETIMES_PRODUCES
[Guids]
diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
index 249e45c04624..7af351eda003 100644
--- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
+++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
@@ -9,6 +9,8 @@
#include <PiPei.h>
+#include <Library/ArmHvcLib.h>
+#include <Library/ArmSmcLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
@@ -16,15 +18,113 @@
#include <Library/PeiServicesLib.h>
#include <libfdt.h>
+#include <IndustryStandard/ArmStdSmc.h>
+
#include <Guid/EarlyPL011BaseAddress.h>
#include <Guid/FdtHob.h>
+#include <Ppi/Reset2.h>
+
STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpm2DiscoveredPpi = {
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gOvmfTpmDiscoveredPpiGuid,
NULL
};
+/**
+ The ResetSystem function resets the entire platform.
+
+ @param[in] ResetType The type of reset to perform.
+ @param[in] ResetStatus The status code for the reset.
+ @param[in] DataSize The size, in bytes, of ResetData.
+ @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
+ EfiResetShutdown the data buffer starts with a
+ Null-terminated string, optionally followed by
+ additional binary data. The string is a description
+ that the caller may use to further indicate the
+ reason for the system reset.
+**/
+STATIC
+VOID
+EFIAPI
+ResetSystemHvc (
+ IN EFI_RESET_TYPE ResetType,
+ IN EFI_STATUS ResetStatus,
+ IN UINTN DataSize,
+ IN VOID *ResetData OPTIONAL
+ )
+{
+ ARM_HVC_ARGS ArmHvcArgs;
+
+ switch (ResetType) {
+ case EfiResetWarm:
+ case EfiResetCold:
+ case EfiResetPlatformSpecific:
+ // Send a PSCI 0.2 SYSTEM_RESET command
+ ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;
+ break;
+
+ case EfiResetShutdown:
+ // Send a PSCI 0.2 SYSTEM_OFF command
+ ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;
+ break;
+
+ default:
+ ASSERT (FALSE);
+ return;
+ }
+ ArmCallHvc (&ArmHvcArgs);
+}
+
+STATIC
+VOID
+EFIAPI
+ResetSystemSmc (
+ IN EFI_RESET_TYPE ResetType,
+ IN EFI_STATUS ResetStatus,
+ IN UINTN DataSize,
+ IN VOID *ResetData OPTIONAL
+ )
+{
+ ARM_SMC_ARGS ArmSmcArgs;
+
+ switch (ResetType) {
+ case EfiResetWarm:
+ case EfiResetCold:
+ case EfiResetPlatformSpecific:
+ // Send a PSCI 0.2 SYSTEM_RESET command
+ ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;
+ break;
+
+ case EfiResetShutdown:
+ // Send a PSCI 0.2 SYSTEM_OFF command
+ ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;
+ break;
+
+ default:
+ ASSERT (FALSE);
+ return;
+ }
+ ArmCallSmc (&ArmSmcArgs);
+}
+
+STATIC CONST EFI_PEI_RESET2_PPI mPpiReset[] = {
+ { ResetSystemHvc },
+ { ResetSystemSmc },
+};
+
+STATIC CONST EFI_PEI_PPI_DESCRIPTOR mPlatformHvcResetPpi = {
+ EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gEfiPeiReset2PpiGuid,
+ (EFI_PEI_RESET2_PPI *)&mPpiReset[0]
+};
+
+STATIC CONST EFI_PEI_PPI_DESCRIPTOR mPlatformSmcResetPpi = {
+ EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gEfiPeiReset2PpiGuid,
+ (EFI_PEI_RESET2_PPI *)&mPpiReset[1]
+};
+
EFI_STATUS
EFIAPI
PlatformPeim (
@@ -47,6 +147,7 @@ PlatformPeim (
INT32 StatusLen;
CONST UINT64 *RegProp;
CONST UINT32 *RangesProp;
+ CONST VOID *MethodProp;
UINT64 UartBase;
UINT64 TpmBase;
EFI_STATUS Status;
@@ -155,6 +256,28 @@ PlatformPeim (
Status = PeiServicesInstallPpi (&mTpm2DiscoveredPpi);
ASSERT_EFI_ERROR (Status);
break;
+ } else if (AsciiStrCmp (CompItem, "arm,psci-0.2") == 0) {
+ MethodProp = fdt_getprop (Base, Node, "method", &Len);
+ if (MethodProp == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Missing PSCI method property\n",
+ __FUNCTION__));
+ break;
+ }
+
+ if (AsciiStrnCmp (MethodProp, "hvc", 3) == 0) {
+ Status = PeiServicesInstallPpi (&mPlatformHvcResetPpi);
+ ASSERT_EFI_ERROR (Status);
+ } else if (AsciiStrnCmp (MethodProp, "smc", 3) == 0) {
+ Status = PeiServicesInstallPpi (&mPlatformSmcResetPpi);
+ ASSERT_EFI_ERROR (Status);
+ } else {
+ DEBUG ((DEBUG_ERROR, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__,
+ MethodProp));
+ break;
+ }
+ DEBUG ((DEBUG_INFO, "%a: Detected PSCI method \"%a\"\n", __FUNCTION__,
+ MethodProp));
+ break;
}
}
}
--
2.20.1
next prev parent reply other threads:[~2020-01-07 9:48 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-07 9:47 [PATCH 0/4] ArmVirtPkg: implement measured boot for ArmVirtQemu Ard Biesheuvel
2020-01-07 9:47 ` [PATCH 1/4] OvmfPkg/Tcg2ConfigPei: introduce a signalling PPI to depex on Ard Biesheuvel
2020-01-07 11:58 ` Laszlo Ersek
2020-01-07 9:47 ` [PATCH 2/4] ArmVirtPkg/PlatformPeiLib: discover the TPM base address from the DT Ard Biesheuvel
2020-01-07 15:42 ` Laszlo Ersek
2020-01-08 14:41 ` Ard Biesheuvel
2020-01-09 13:04 ` Laszlo Ersek
2020-01-07 9:47 ` Ard Biesheuvel [this message]
2020-01-07 16:50 ` [PATCH 3/4] ArmVirtPkg/PlatformPeiLib: implement Reset2 PPI based on PSCI Laszlo Ersek
2020-01-07 16:55 ` [edk2-devel] " Ard Biesheuvel
2020-01-07 18:47 ` Laszlo Ersek
2020-01-08 9:59 ` Ard Biesheuvel
2020-01-07 9:48 ` [PATCH 4/4] ArmVirtPkg/ArmVirtQemu: add optional support for TPM2 measured boot Ard Biesheuvel
2020-01-07 17:37 ` Laszlo Ersek
2020-01-08 14:13 ` Ard Biesheuvel
2020-01-08 14:45 ` Laszlo Ersek
2020-01-09 0:51 ` Yao, Jiewen
2020-01-09 13:07 ` Laszlo Ersek
2020-01-10 0:32 ` Yao, Jiewen
2020-01-13 1:55 ` [edk2-devel] " Gary Lin
2020-01-13 15:56 ` Laszlo Ersek
2020-01-07 11:55 ` [PATCH 0/4] ArmVirtPkg: implement measured boot for ArmVirtQemu Laszlo Ersek
2020-01-07 12:04 ` Ard Biesheuvel
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=20200107094800.4488-4-ard.biesheuvel@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