From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web08.2749.1641618780172515526 for ; Fri, 07 Jan 2022 21:13:00 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=lMr68g7I; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=000704d8ca=abner.chang@hpe.com) Received: from pps.filterd (m0150241.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 208325EC027376 for ; Sat, 8 Jan 2022 05:13:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pps0720; bh=JrBpJZ04PSJqr1Mv8ASMUF2xr2H+aHKPzQcgkObIIFI=; b=lMr68g7I9acDkYKCuIbyWy8/TBkeC9G4v9/da8wA/EiAvUlX4lu8dCIp4f+oU+pl/5MX CMTRFnR/Ka3p1UXbd0FrvPEdopETBLTd7KvhqG/Cl7nDcxyVKYnhdIX7g6y5kkk7nSG9 aUNqWCc6JYfjW8K7W5Hl80/iqa23JnAN5GcEUIDAcn+tND1GvQeGD+DMZZphtHhAqvBu MflwJ+X1mlgwfwldUHwe9seFslCET4gSlPoUZIkMeGLV69rM/NRHRPKwbkUIxNMwh9Us Loqc0ZHpAjL4UGFw/y4aSVwBeYFgqrrXilvg4VkND1Zi37Tr0C2OLsrB3p148B9WmiFs AQ== Received: from g2t2352.austin.hpe.com (g2t2352.austin.hpe.com [15.233.44.25]) by mx0a-002e3701.pphosted.com (PPS) with ESMTPS id 3df15pgqve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 08 Jan 2022 05:12:59 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2352.austin.hpe.com (Postfix) with ESMTP id DC05D85 for ; Sat, 8 Jan 2022 05:12:58 +0000 (UTC) Received: from UB16Abner.asiapacific.hpqcorp.net (ub16abner.asiapacific.hpqcorp.net [15.119.209.229]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id 314CE37; Sat, 8 Jan 2022 05:12:58 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com Subject: [PATCH 37/79] RISC-V: Implement ResetSystem RT call Date: Sat, 8 Jan 2022 12:10:57 +0800 Message-Id: <20220108041121.16005-36-abner.chang@hpe.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220108041121.16005-1-abner.chang@hpe.com> References: <20220108041121.16005-1-abner.chang@hpe.com> MIME-Version: 1.0 X-Proofpoint-GUID: nuUyUqtihyDSkghBE-ncFtCbauUjN_Qv X-Proofpoint-ORIG-GUID: nuUyUqtihyDSkghBE-ncFtCbauUjN_Qv X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-08_01,2022-01-07_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 suspectscore=0 priorityscore=1501 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201080036 Content-Transfer-Encoding: quoted-printable (This is migrated from edk2-platforms) Cc: Daniel Schaefer Cc: Abner Chang Cc: Sunil V L Reviewed-by: Abner Chang Signed-off-by: Daniel Schaefer --- .../Library/ResetSystemLib/ResetSystemLib.inf | 33 +++++ .../Include/Library/RiscVEdk2SbiLib.h | 38 +++++- .../Library/ResetSystemLib/ResetSystemLib.c | 128 ++++++++++++++++++ .../Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c | 44 +++++- 4 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/Rese= tSystemLib.inf create mode 100644 Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/Rese= tSystemLib.c diff --git a/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystem= Lib.inf b/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib= .inf new file mode 100644 index 0000000000..f876ae2056 --- /dev/null +++ b/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.inf @@ -0,0 +1,33 @@ +## @file=0D +# Library instance for ResetSystem library class for RISC-V using SBI eca= lls=0D +#=0D +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D ResetSystemLib=0D + FILE_GUID =3D 3eff6057-1116-4dcb-837e-c0ef1a120ab1= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D ResetSystemLib=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D RISCV64=0D +#=0D +=0D +[Sources]=0D + ResetSystemLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + RiscVEdk2SbiLib=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h = b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h index 66a87cb8c3..88d957f002 100644 --- a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h +++ b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h @@ -1,7 +1,7 @@ /** @file=0D Library to call the RISC-V SBI ecalls=0D =0D - Copyright (c) 2020, Hewlett Packard Development LP. All rights reserved.=
=0D + Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.=
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -474,6 +474,42 @@ SbiRemoteHfenceVvma ( IN UINTN Size=0D );=0D =0D +///=0D +/// Firmware System Reset (SRST) Extension=0D +///=0D +=0D +/**=0D + Reset the system=0D +=0D + The System Reset Extension provides a function that allow the supervisor= =0D + software to request system-level reboot or shutdown. The term "system" r= efers=0D + to the world-view of supervisor software and the underlying SBI=0D + implementation could be machine mode firmware or hypervisor.=0D +=0D + Valid parameters for ResetType and ResetReason are defined in sbi_ecall_= interface.h=0D +=0D + #define SBI_SRST_RESET_TYPE_SHUTDOWN 0x0=0D + #define SBI_SRST_RESET_TYPE_COLD_REBOOT 0x1=0D + #define SBI_SRST_RESET_TYPE_WARM_REBOOT 0x2=0D +=0D + #define SBI_SRST_RESET_REASON_NONE 0x0=0D + #define SBI_SRST_RESET_REASON_SYSFAIL 0x1=0D +=0D + When the call is successful, it will not return.=0D +=0D + @param[in] ResetType Typ of reset: Shutdown, cold-, or warm-= reset.=0D + @param[in] ResetReason Why the system resets. No reason or sys= tem failure.=0D + @retval EFI_INVALID_PARAMETER Either ResetType or ResetReason is inva= lid.=0D + @retval EFI_UNSUPPORTED ResetType is valid but not implemented = on the platform.=0D + @retval EFI_DEVICE_ERROR Unknown error.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +SbiSystemReset (=0D + IN UINTN ResetType,=0D + IN UINTN ResetReason=0D + );=0D +=0D ///=0D /// Vendor Specific extension space: Extension Ids 0x09000000 through 0x09= FFFFFF=0D ///=0D diff --git a/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystem= Lib.c b/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.c new file mode 100644 index 0000000000..67e40151d1 --- /dev/null +++ b/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.c @@ -0,0 +1,128 @@ +/** @file=0D + Reset System Library functions for RISC-V=0D +=0D + Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.=
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + This function causes a system-wide reset (cold reset), in which=0D + all circuitry within the system returns to its initial state. This type = of reset=0D + is asynchronous to system operation and operates without regard to=0D + cycle boundaries.=0D +=0D + If this function returns, it means that the system does not support cold= reset.=0D +**/=0D +VOID=0D +EFIAPI=0D +ResetCold (=0D + VOID=0D + )=0D +{=0D + // Warm Reset via SBI ecall=0D + SbiSystemReset (SBI_SRST_RESET_TYPE_COLD_REBOOT, SBI_SRST_RESET_REASON_N= ONE);=0D +}=0D +=0D +/**=0D + This function causes a system-wide initialization (warm reset), in which= all processors=0D + are set to their initial state. Pending cycles are not corrupted.=0D +=0D + If this function returns, it means that the system does not support warm= reset.=0D +**/=0D +VOID=0D +EFIAPI=0D +ResetWarm (=0D + VOID=0D + )=0D +{=0D + // Warm Reset via SBI ecall=0D + SbiSystemReset (SBI_SRST_RESET_TYPE_WARM_REBOOT, SBI_SRST_RESET_REASON_N= ONE);=0D +}=0D +=0D +/**=0D + This function causes the system to enter a power state equivalent=0D + to the ACPI G2/S5 or G3 states.=0D +=0D + If this function returns, it means that the system does not support shut= down reset.=0D +**/=0D +VOID=0D +EFIAPI=0D +ResetShutdown (=0D + VOID=0D + )=0D +{=0D + // Shut down via SBI ecall=0D + SbiSystemReset (SBI_SRST_RESET_TYPE_SHUTDOWN, SBI_SRST_RESET_REASON_NONE= );=0D +}=0D +=0D +/**=0D + This function causes a systemwide reset. The exact type of the reset is= =0D + defined by the EFI_GUID that follows the Null-terminated Unicode string = passed=0D + into ResetData. If the platform does not recognize the EFI_GUID in Reset= Data=0D + the platform must pick a supported reset type to perform. The platform m= ay=0D + optionally log the parameters from any non-normal reset that occurs.=0D +=0D + @param[in] DataSize The size, in bytes, of ResetData.=0D + @param[in] ResetData The data buffer starts with a Null-terminated str= ing,=0D + followed by the EFI_GUID.=0D +**/=0D +VOID=0D +EFIAPI=0D +ResetPlatformSpecific (=0D + IN UINTN DataSize,=0D + IN VOID *ResetData=0D + )=0D +{=0D + //=0D + // Can map to OpenSBI vendor or platform specific reset type.=0D + //=0D + return;=0D +}=0D +=0D +/**=0D + The ResetSystem function resets the entire platform.=0D +=0D + @param[in] ResetType The type of reset to perform.=0D + @param[in] ResetStatus The status code for the reset.=0D + @param[in] DataSize The size, in bytes, of ResetData.=0D + @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm,= or EfiResetShutdown=0D + the data buffer starts with a Null-terminated = string, optionally=0D + followed by additional binary data. The string= is a description=0D + that the caller may use to further indicate th= e reason for the=0D + system reset.=0D +**/=0D +VOID=0D +EFIAPI=0D +ResetSystem (=0D + IN EFI_RESET_TYPE ResetType,=0D + IN EFI_STATUS ResetStatus,=0D + IN UINTN DataSize,=0D + IN VOID *ResetData OPTIONAL=0D + )=0D +{=0D + switch (ResetType) {=0D + case EfiResetWarm:=0D + ResetWarm ();=0D + break;=0D +=0D + case EfiResetCold:=0D + ResetCold ();=0D + break;=0D +=0D + case EfiResetShutdown:=0D + ResetShutdown ();=0D + return;=0D +=0D + case EfiResetPlatformSpecific:=0D + ResetPlatformSpecific (DataSize, ResetData);=0D + return;=0D +=0D + default:=0D + return;=0D + }=0D +}=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2S= biLib.c b/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiL= ib.c index 9bbeaaec3f..319526ed8f 100644 --- a/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c @@ -15,7 +15,7 @@ - SbiLegacyRemoteSfenceVmaAsid -> Use SbiRemoteSfenceVmaAsid=0D - SbiLegacyShutdown -> Wait for new System Reset extension=0D =0D - Copyright (c) 2020, Hewlett Packard Development LP. All rights reserved.=
=0D + Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.=
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @par Revision Reference:=0D @@ -715,6 +715,48 @@ SbiRemoteHFenceVvma ( return TranslateError (Ret.Error);=0D }=0D =0D +/**=0D + Reset the system=0D +=0D + The System Reset Extension provides a function that allow the supervisor= =0D + software to request system-level reboot or shutdown. The term "system" r= efers=0D + to the world-view of supervisor software and the underlying SBI=0D + implementation could be machine mode firmware or hypervisor.=0D +=0D + Valid parameters for ResetType and ResetReason are defined in sbi_ecall_= interface.h=0D +=0D + #define SBI_SRST_RESET_TYPE_SHUTDOWN 0x0=0D + #define SBI_SRST_RESET_TYPE_COLD_REBOOT 0x1=0D + #define SBI_SRST_RESET_TYPE_WARM_REBOOT 0x2=0D +=0D + #define SBI_SRST_RESET_REASON_NONE 0x0=0D + #define SBI_SRST_RESET_REASON_SYSFAIL 0x1=0D +=0D + When the call is successful, it will not return.=0D +=0D + @param[in] ResetType Typ of reset: Shutdown, cold-, or warm-= reset.=0D + @param[in] ResetReason Why the system resets. No reason or sys= tem failure.=0D + @retval EFI_INVALID_PARAMETER Either ResetType or ResetReason is inva= lid.=0D + @retval EFI_UNSUPPORTED ResetType is valid but not implemented = on the platform.=0D + @retval EFI_DEVICE_ERROR Unknown error.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +SbiSystemReset (=0D + IN UINTN ResetType,=0D + IN UINTN ResetReason=0D + )=0D +{=0D + SbiRet Ret =3D SbiCall (=0D + SBI_EXT_SRST,=0D + SBI_EXT_SRST_RESET,=0D + 2,=0D + ResetType,=0D + ResetReason=0D + );=0D + return TranslateError (Ret.Error);=0D +}=0D +=0D //=0D // SBI interface function for the vendor extension=0D //=0D --=20 2.31.1