From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web09.6414.1662549166217641271 for ; Wed, 07 Sep 2022 04:12:46 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=pDPqI1xW; spf=pass (domain: ventanamicro.com, ip: 209.85.210.170, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pf1-f170.google.com with SMTP id c198so4407337pfc.13 for ; Wed, 07 Sep 2022 04:12:46 -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=AFGk/HhX8CkdTGT4DPk4zij68g7a/bHmgQlBaekbYRY=; b=pDPqI1xWmjPxqR47Mlb6kbXJWmCvZuJqGUpV8pxK1/OTbgMov+BFgdadADDaFdPVYl uoFBXMlK9ml2xZLqKSp8yAyzkgvFRp1t1YWgQ9WrC9Mqm07HRuhc1R0qidw0R1n8HyCR NZGV5tXk56lnNNCMjDa2+ZpS47ElftV3/x0BF6XC5/+MEyq//EIRaNTLAngMFr9yAajZ CgnjfX8Le1Y0ww+rtVh9b40CLC1cvs1oQ1dQjHoA6TOEqGthhSzI0htqCirUYjDDmUE3 O8SxJIIuYwzWfuS+u127PT8mEunBAWGy7PBZeAaTV9GT4ON9M1J1uNPC80PUV3mjrHq0 863w== 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=AFGk/HhX8CkdTGT4DPk4zij68g7a/bHmgQlBaekbYRY=; b=jOMdtpRHxYQlVVxWTG2P2pri7tBea1AtpgpbTnyd0FprMdpO8taZJGPjBuN4lc5AGz zASH6SWBZmvlhfo0z6+LGEL457c5bX+s0Bn4fiwrG22UwB9BUdriyN3MO4jTgdAbi952 ytpL9s8mhL4cap/YdGTW3/D10X2SGQyAWy783b4eEtn9is2BV33fQoighqQlnRmE4cLQ geJct/2pMBxs+I3FOJ6zHO46vZQU2p7T4Wtq9TJ172YK/j+RpC33dvxrOTBU7G7JxAzq /PUtJk8aLWeCtuRJdn69owz98DSTfM3T8DXINhFLh8Ty2ZeLuNBG/T+uU67qwbuZ51cY HqpQ== X-Gm-Message-State: ACgBeo3kJqmIeGrOVju11s33qHiBPhbvsmVXLU6GI5F39do3aWGWznX9 Rl9NwmaTlSnztR7hyT5O0nlRXuB8PeokE8w4 X-Google-Smtp-Source: AA6agR66JhcUj7amgTN29d3QCzjnfy21WVA9IL55JGA9NlQ/XUTlDybjR9zz+77oOxW2SBkuE3VmbA== X-Received: by 2002:a65:6b95:0:b0:420:2cb1:68e5 with SMTP id d21-20020a656b95000000b004202cb168e5mr2889716pgw.220.1662549164878; Wed, 07 Sep 2022 04:12:44 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id y5-20020aa79ae5000000b0052b84ca900csm12208518pfp.62.2022.09.07.04.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 04:12:44 -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 16:41:17 +0530 Message-Id: <20220907111125.539698-12-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220907111125.539698-1-sunilvl@ventanamicro.com> References: <20220907111125.539698-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=0D +# Library instance for ResetSystem library class=0D +#=0D +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
= =0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D ResetSystemLib=0D + FILE_GUID =3D 425DC96A-BF26-4684-90F9-1B5FF43BE927= =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.RISCV64]=0D + RiscV64/ResetSystemLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D +=0D +[LibraryClasses.RISCV64]=0D + RiscVSbiLib=0D 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=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 --=20 2.25.1