From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by mx.groups.io with SMTP id smtpd.web10.3754.1578390489481954515 for ; Tue, 07 Jan 2020 01:48:09 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=l0PTrveO; spf=pass (domain: linaro.org, ip: 209.85.221.65, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wr1-f65.google.com with SMTP id c14so53130377wrn.7 for ; Tue, 07 Jan 2020 01:48:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9cFJo0nM5tfz22k2iR/FkqACc3EeHGvKr/b/k6lHA9c=; b=l0PTrveOcqPqL9Gm4Bci74LUehdlxEHYy3UTjepTSXHw3OZ7bcdEjM2Fi8QIvQWZ5D Vy4d+gUZSFIDdmVic94W0QNqOvGVGW+EmW10HmG3Cy+tllhiB/M3cydbsbg1CAbkv5tp hT5234xg3T8ntSJQ7wSQ68oTPG/zqHQ+09kstYFFBIDBiVlNvzMEHrnNGgtjiT0EO4Nn lSSqol2NLi4BooaHOm+jAWTXcjcClPTlnaYppVzCkRnWOO/U+skw1i1Y4Mx41chXV3Na y6/nXLiJGkoSoThBUigMiPqeQFOwjbpeBe35mMUoT9kA7zmcXr8WZA8C2CDrGu7QTiIG mbHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9cFJo0nM5tfz22k2iR/FkqACc3EeHGvKr/b/k6lHA9c=; b=D08KdC5dN8vcacS9QW4FLeZ2JU46b6kudybTQtIh3324g7+p7xlSbFkeRdJ3ectHHX zwu7ImRBvewjiW0/FpBvBIZ+zatGI7HcwgtnJvAP/20gdGBJEmUUq/MZXTjxg4HLGTBq kv4Auq9t6Va6KjQ+HnZd4opYL327qI70RwpWgpofn93fbyfk+mE5eTTW6xdIQDcX/MLN foYzijWIDcy72U7zAL0gEu1LVR/PIpZoLRdQznsz3WAjzPmfbi0bDteKGpx8ZqU6XXaE Sv7Y1S1oKOGbWyelbktZDlSBgYkHJofOQI7Exh9c0nn5DPoFvffxKIq2ELgBeS9+Fqw0 VTSA== X-Gm-Message-State: APjAAAVG8qtimZwTGlCf1Tgm4d0ss99nYsDImzT6Pq9qPK0K0ASp/e7f 1esfmTpR2XmvlM1EWDUkT4fHuie+a0uXlw== X-Google-Smtp-Source: APXvYqzaJmEALjiQPLxFUCwQPCHIV/k8yeC/BQXEgFHrj9GrlT6xPQRwvf1GvxOxoLpj46RHumvENQ== X-Received: by 2002:adf:ebd0:: with SMTP id v16mr3931545wrn.146.1578390487704; Tue, 07 Jan 2020 01:48:07 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2a01:cb1d:112:6f00:cc7e:d2b6:8b0c:cb36]) by smtp.gmail.com with ESMTPSA id u1sm25870210wmc.5.2020.01.07.01.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 01:48:06 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [PATCH 3/4] ArmVirtPkg/PlatformPeiLib: implement Reset2 PPI based on PSCI Date: Tue, 7 Jan 2020 10:47:59 +0100 Message-Id: <20200107094800.4488-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200107094800.4488-1-ard.biesheuvel@linaro.org> References: <20200107094800.4488-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 +#include +#include #include #include #include @@ -16,15 +18,113 @@ #include #include +#include + #include #include +#include + 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