From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=dorYvRQE; spf=pass (domain: ventanamicro.com, ip: 209.85.210.172, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pf1-f172.google.com with SMTP id 14so5572469pfu.9 for ; Wed, 07 Sep 2022 04:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=03HEpOcBFGdYP0v5E6KTqZAlxSt0uB5OwQL54V/uDSw=; b=dorYvRQELR3lm/8o0o+W+Qj3FFKndIgLnV6G2fe1HSdpjW58CVQaVK3/X1RWfrwuRm 246DtudLp3b7x6xsDfRWkrDCxDqcNdcKabuGxBgCSWFlaVgWfDeJvpSw076MKVyBdGXU FoFnxOnF1MZo4zUvwBOak8SaylzZ7MdS0lin20SIgueidN1MCS13wby07JmgCK54w3fR XU2BEZr41xID1zNQ9pcFyTNd2VJ341y6HbIoDZtSpWuMs1bWIm7vJhCqmjFLiwg+CC38 cpU7XvN7AC3CgEW7O+36RlEgasHZSNsr5TBtrZbAOx3msKmh8fnU/CBma3b3uCgaaZbl oe1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=03HEpOcBFGdYP0v5E6KTqZAlxSt0uB5OwQL54V/uDSw=; b=itNHawMD204JFc7QRRFYi06CYUB9AQ8kXGs6uC4w7uKCj6CiKMoyd+BJJ4q0vDAKF3 BaxhNIg/mw1cuIM55GwiGvYmooYLy5EdhNohi8mFNXACr66jC+dj26xqXTeBkhhK2J1a DH1Z2/NMCBR1ii7x4r0DpJ1lCVa9cKTs6toRzl37XCKJFLFRtM0lIAjiPoR33zTft7g2 2mJybGSp3ZT7QZxVyGmKs1gPz9QtsuKfLDcDmfFRDgRJq92Ji6CC3/hnCdW1canH5ViY g7oYXyRsu5fxKlxyBoGnQTqAn3MntqK79fr5s+QORUAWMGI7Wa1NZvVcLKKadRSWG0fe O76w== X-Gm-Message-State: ACgBeo14Y9hlsm3Xs2wwSfluRjmg4pdHreohO/uELcaNqPSSbo0hWVl6 iU+O031rIYgjr0jUYdUSa27n8sh90mrnVkL0 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220907113626.540065-1-sunilvl@ventanamicro.com> References: <20220907113626.540065-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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/Library/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 rights reserved.
+# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = ResetSystemLib + FILE_GUID = 425DC96A-BF26-4684-90F9-1B5FF43BE927 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ResetSystemLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = 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/MdePkg/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_NONE); +} + +/** + 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_NONE); +} + +/** + 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 shutdown 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 ResetData + the platform must pick a supported reset type to perform. The platform may + 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 string, + 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 the 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; + } +} -- 2.25.1