From nobody Mon Feb 9 23:15:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+93409+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93409+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1662550650; cv=none; d=zohomail.com; s=zohoarc; b=mCGNzML/oL3mEwXGNvozn1Q3Jxxljrrxo3g6bVBM3xc/g7watS3gVkhM6eq+saKBChXM9xleYGAjLRaqLGo1TdYvgjimWA7LtXymizl3rN8aD7D0sGh18yAfoXWDWQuQ/0pfqLQGiRpcL/vZPElGRYthdmCbvr2l2Vr9UC1JtXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662550650; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=vtYq43a0IHZpoB5qJ9XskBNQHXw2h4L2x7NffHU6gBs=; b=C8QysGxeMIt6U65vzwdSqa4T7RIFbEYXGyOUcHTO8irMsHA25GEeMaa+b8bKrX3mJptqbSV6zfEtoa4q0ptOy34SVrRzPIhe+9Pon3WU2aSuQHMw76ywRI+Dzg7BCq4dUnBh+DnlFccKIq1lL/wHla/Wqj4hnt8jtAmko42kxXM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93409+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1662550650795285.9436650724464; Wed, 7 Sep 2022 04:37:30 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2aEcYY1788612xeTcSwDyeLN; Wed, 07 Sep 2022 04:37:30 -0700 X-Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web11.6490.1662550649802323865 for ; Wed, 07 Sep 2022 04:37:29 -0700 X-Received: by mail-pf1-f172.google.com with SMTP id 14so5572469pfu.9 for ; Wed, 07 Sep 2022 04:37:29 -0700 (PDT) X-Gm-Message-State: hPR675gdM9bvT5yp1kwjAjVQx1787277AA= X-Google-Smtp-Source: AA6agR7jBuORKjujmkzHHjNWGmSHSLFNO4Wgeo1l/5t6dxOgYKIJoljR/9eXJWU3H6c/uLGkYGMS5g== X-Received: by 2002:a05:6a00:4c11:b0:53e:4f07:fce9 with SMTP id ea17-20020a056a004c1100b0053e4f07fce9mr3699957pfb.66.1662550649027; Wed, 07 Sep 2022 04:37:29 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id 8-20020a17090a000800b001fd77933fb3sm10797230pja.17.2022.09.07.04.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 04:37:28 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Eric Dong , Ray Ni , Rahul Kumar , Debkumar De , Catharine West , Daniel Schaefer , Abner Chang , Leif Lindholm , Andrew Fish , Ard Biesheuvel , Heinrich Schuchardt , Anup Patel , Sunil V L Subject: [edk2-devel] [RFC PATCH V2 11/19] MdePkg/Library: Add ResetSystemLib library Date: Wed, 7 Sep 2022 17:06:18 +0530 Message-Id: <20220907113626.540065-12-sunilvl@ventanamicro.com> In-Reply-To: <20220907113626.540065-1-sunilvl@ventanamicro.com> References: <20220907113626.540065-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1662550650; bh=6wWpK9s0yxLmtDY5oQIyptLq1R1Un3eYHMjIxq5tzzA=; h=Cc:Date:From:Reply-To:Subject:To; b=XdFk3JuPLhWkLNkY2JeWgBg7xBn1IpEzhtrzolvct9KfzW2kNTOf5gpjNUjb2IeRrb4 9aR8Qo4GrrO8dCkPflC2ezuIQrKJEXCFLioOj62hKDP0AiTfBDj5J1j6kMEQBcwfs2698 ekku/6AiEHgWsfSd2S7MwiWFlNirkE7ewbg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1662550651190100013 Content-Type: text/plain; charset="utf-8" This library implements system reset interfaces like cold reboot, warm reboot etc. On RISC-V platforms, these are implemented using SBI calls. Signed-off-by: Sunil V L --- MdePkg/Library/ResetSystemLib/ResetSystemLib.inf | 35 ++++++ MdePkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c | 128 +++++++++++++= +++++++ 2 files changed, 163 insertions(+) diff --git a/MdePkg/Library/ResetSystemLib/ResetSystemLib.inf b/MdePkg/Libr= ary/ResetSystemLib/ResetSystemLib.inf new file mode 100644 index 000000000000..7c8a7d11423d --- /dev/null +++ b/MdePkg/Library/ResetSystemLib/ResetSystemLib.inf @@ -0,0 +1,35 @@ +## @file +# Library instance for ResetSystem library class +# +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D ResetSystemLib + FILE_GUID =3D 425DC96A-BF26-4684-90F9-1B5FF43BE927 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ResetSystemLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D RISCV64 +# + +[Sources.RISCV64] + RiscV64/ResetSystemLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + DebugLib + +[LibraryClasses.RISCV64] + RiscVSbiLib diff --git a/MdePkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c b/MdePk= g/Library/ResetSystemLib/RiscV64/ResetSystemLib.c new file mode 100644 index 000000000000..c077ef6ac7f8 --- /dev/null +++ b/MdePkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c @@ -0,0 +1,128 @@ +/** @file + Reset System Library functions for RISC-V + + Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.=
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/** + This function causes a system-wide reset (cold reset), in which + all circuitry within the system returns to its initial state. This type = of reset + is asynchronous to system operation and operates without regard to + cycle boundaries. + + If this function returns, it means that the system does not support cold= reset. +**/ +VOID +EFIAPI +ResetCold ( + VOID + ) +{ + // Warm Reset via SBI ecall + SbiSystemReset (SBI_SRST_RESET_TYPE_COLD_REBOOT, SBI_SRST_RESET_REASON_N= ONE); +} + +/** + This function causes a system-wide initialization (warm reset), in which= all processors + are set to their initial state. Pending cycles are not corrupted. + + If this function returns, it means that the system does not support warm= reset. +**/ +VOID +EFIAPI +ResetWarm ( + VOID + ) +{ + // Warm Reset via SBI ecall + SbiSystemReset (SBI_SRST_RESET_TYPE_WARM_REBOOT, SBI_SRST_RESET_REASON_N= ONE); +} + +/** + This function causes the system to enter a power state equivalent + to the ACPI G2/S5 or G3 states. + + If this function returns, it means that the system does not support shut= down reset. +**/ +VOID +EFIAPI +ResetShutdown ( + VOID + ) +{ + // Shut down via SBI ecall + SbiSystemReset (SBI_SRST_RESET_TYPE_SHUTDOWN, SBI_SRST_RESET_REASON_NONE= ); +} + +/** + This function causes a systemwide reset. The exact type of the reset is + defined by the EFI_GUID that follows the Null-terminated Unicode string = passed + into ResetData. If the platform does not recognize the EFI_GUID in Reset= Data + the platform must pick a supported reset type to perform. The platform m= ay + optionally log the parameters from any non-normal reset that occurs. + + @param[in] DataSize The size, in bytes, of ResetData. + @param[in] ResetData The data buffer starts with a Null-terminated str= ing, + followed by the EFI_GUID. +**/ +VOID +EFIAPI +ResetPlatformSpecific ( + IN UINTN DataSize, + IN VOID *ResetData + ) +{ + // + // Can map to OpenSBI vendor or platform specific reset type. + // + return; +} + +/** + 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 th= e reason for the + system reset. +**/ +VOID +EFIAPI +ResetSystem ( + IN EFI_RESET_TYPE ResetType, + IN EFI_STATUS ResetStatus, + IN UINTN DataSize, + IN VOID *ResetData OPTIONAL + ) +{ + switch (ResetType) { + case EfiResetWarm: + ResetWarm (); + break; + + case EfiResetCold: + ResetCold (); + break; + + case EfiResetShutdown: + ResetShutdown (); + return; + + case EfiResetPlatformSpecific: + ResetPlatformSpecific (DataSize, ResetData); + return; + + default: + return; + } +} --=20 2.25.1 -=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 (#93409): https://edk2.groups.io/g/devel/message/93409 Mute This Topic: https://groups.io/mt/93522718/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-