From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mx.groups.io with SMTP id smtpd.web08.1934.1662484181498725806 for ; Tue, 06 Sep 2022 10:09:41 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=mDnE+Jz0; spf=pass (domain: ventanamicro.com, ip: 209.85.215.169, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pg1-f169.google.com with SMTP id v4so11174212pgi.10 for ; Tue, 06 Sep 2022 10:09:41 -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=hXHz0BlNZgMFPJgWVNhnXhlUrpWSyiE2ZaCw28x20NQ=; b=mDnE+Jz0LWMCZUFbbO7/cc5A6/UHrsbO0Gh5WE44dFvSjgRj7wMZG6ikJjYWv4Sqsf 4rEuXCCNek1PJbo/vMMZs5EVwT9KfK6fUJ8fjw1R6yLwTFOeQ02hO6E0tBsTshB2SqZb cslTP0pxCQSM94TUrPTnts9Q2vC5kttzWnnMBFvpb4Y+Nc6pRH1NqnkH2AaXMSfS7+YK sDVDE8cXwYyhCsJvoXEBAQ8iWh99dP9jOK9rAA5AwRgJML4K9eUlwawxSyj7gRfTebca 57H+r59TfixQetypBndG2YJdu70pWqBOAL2wLzfCcR990b7DaJ5y8ojMXI+EYIiUc+EV eRmQ== 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=hXHz0BlNZgMFPJgWVNhnXhlUrpWSyiE2ZaCw28x20NQ=; b=c8Cj/W/4b1DVBqelRdoqqE8o1D69Q5TIlzgYkhr8onQ6C0VEgGyXnU5/1nqqoVz7i/ 5SjoPSLA+BA6Cq1pR6tCBN3Hm7z0lUYo10XwQforYe0qzA1yBjGyZphN6lOlYqgl8efz bBjawSOdDHuUsqkpy0Zbdu/AIgZQDlGlhbFAHAVY4K3IYXlXLW0W8+rmmm3Ot1wtyPI3 btr+hweuBrrhd/hpr2FASb3HK/P3fnvzczmwHBtMDSGH9+PiyP/YkecAXiC3aWNSC2EJ relXMnCvVIWL4z1XQlMM2QpcK5wdNPBjM/bqFIMNr6wzUtEXStKtXF+mCmONs8H3nub8 dWZw== X-Gm-Message-State: ACgBeo21/yhf4ri2FEv4t1VXDTqGkdoTI1lsqJ4+ayyAR2ig03W1tGsZ vxu2TwLPhImqoDb0iiGmSoCzFTErcRS8taUc X-Google-Smtp-Source: AA6agR6EpoKH6fWSwgTkmdNm54uANp8zUImysl+pT7862rWnreqEL/rzekl9q1bZUenObvXY8f8oBA== X-Received: by 2002:a05:6a00:1586:b0:537:f5f:11d0 with SMTP id u6-20020a056a00158600b005370f5f11d0mr57049325pfk.64.1662484180378; Tue, 06 Sep 2022 10:09:40 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id b17-20020a170903229100b00176be258f41sm3806567plh.91.2022.09.06.10.09.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 10:09:39 -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 , Ard Biesheuvel , Heinrich Schuchardt , Anup Patel , Sunil V L Subject: [RFC PATCH 11/17] MdePkg/Library: Add ResetSystemLib library Date: Tue, 6 Sep 2022 22:38:31 +0530 Message-Id: <20220906170837.491525-12-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906170837.491525-1-sunilvl@ventanamicro.com> References: <20220906170837.491525-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 --- .../Library/ResetSystemLib/ResetSystemLib.inf | 35 +++++ .../ResetSystemLib/RiscV64/ResetSystemLib.c | 128 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 MdePkg/Library/ResetSystemLib/ResetSystemLib.inf create mode 100644 MdePkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c diff --git a/MdePkg/Library/ResetSystemLib/ResetSystemLib.inf b/MdePkg/Libr= ary/ResetSystemLib/ResetSystemLib.inf new file mode 100644 index 0000000000..7c8a7d1142 --- /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 0000000000..c077ef6ac7 --- /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