From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mx.groups.io with SMTP id smtpd.web11.132938.1671109045010538374 for ; Thu, 15 Dec 2022 04:57:25 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=AISm+4Tx; spf=pass (domain: ventanamicro.com, ip: 209.85.210.173, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pf1-f173.google.com with SMTP id 21so6641721pfw.4 for ; Thu, 15 Dec 2022 04:57:24 -0800 (PST) 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 :message-id:reply-to; bh=Xp7aqSuMfw5VnS0geWRZL4/xwTOv0n8tFE1/7VOsMK4=; b=AISm+4Txrr8KCiYngrSNNGe3fiS59XdZDydlXX2/qXFYf1xypwCnk++unDGniKc45Z yZzlnd31VGlfc0oY3+d+3TQOmEKELCUyUYtWC5y0itdLdoB1hMB/+vMT3geXvxFFPR8U D6BfXYWP9FZkRjZCMWSGOXAIjna8VOFojsdbY8UHz4Vk29APTek/bE+MSbPmxKFw94Ui grYdRaAlSDGAfreGe78stxMG1ClivrjxhSZy7R1hvHIGc9xBhCD6LJHnqb20I++NqF64 NEk+ZHa2JqHeCFguv+i6gUFTE1HIpIq+J19IufdMM5QeLFCO8NhwbMLm1FtePlYE6jse ckjg== 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:message-id:reply-to; bh=Xp7aqSuMfw5VnS0geWRZL4/xwTOv0n8tFE1/7VOsMK4=; b=oA9AiCGQTcGwTEcIw61bzhnO946J4vO/EcUGB8I3yV46mHof0T7dkOrYe4hQBfYwYD vE4I3RpIVFDo2BdaXDW4OzQL4dlh9qudjQk46E/imYl92zkIIhNuj6a7INNyaTkgpyTS f2gQPeu9xDK3/xRM5Liq5mcMytNCBpFqec0ud79U+FvNm+w9T7mhMRrjlZTPUTXnYFVJ LOwPQIDZy3piB/2aXWHxZJSmO7Z2wJ0zAfK//UaZAYW9GmVavsWjw1YB38x8A90AB919 fTxOm6d2lK4GjkolTaVdU+P790Vvd+zEXca3Bke2cC/eZf18FJz/Q2hUDo9xwVZfIKR/ dvmQ== X-Gm-Message-State: ANoB5pmsKWfuO60Q7UPF60/VVKuW8K/Ssi6wvL6HjSl7lyPs8pa1xiA4 sG9u2VKxGC2fB4Vj/NNJk7Xh8rEbxv7jSuhAWno= X-Google-Smtp-Source: AA0mqf4D3SVfC6cT8mmWk+0qZwjQe/aJARjnpMlpzrwa2E/R8+0MMeDEl5QQ8n5id2tba1GjkR02uQ== X-Received: by 2002:a05:6a00:1d09:b0:578:128b:3a3f with SMTP id a9-20020a056a001d0900b00578128b3a3fmr26769854pfx.15.1671109044325; Thu, 15 Dec 2022 04:57:24 -0800 (PST) Return-Path: Received: from localhost.localdomain ([49.206.11.246]) by smtp.gmail.com with ESMTPSA id j2-20020a625502000000b005762905c89asm1674384pfb.66.2022.12.15.04.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 04:57:23 -0800 (PST) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Rebecca Cran , Peter Grehan , Daniel Schaefer Subject: [edk2-staging/RiscV64QemuVirt PATCH V6 19/23] OvmfPkg/ResetSystemLib: Add RISC-V instance Date: Thu, 15 Dec 2022 18:26:22 +0530 Message-Id: <20221215125626.545372-20-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221215125626.545372-1-sunilvl@ventanamicro.com> References: <20221215125626.545372-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076 This is mostly copied from edk2-platforms/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Rebecca Cran Cc: Peter Grehan Cc: Daniel Schaefer Signed-off-by: Sunil V L --- OvmfPkg/Library/ResetSystemLib/BaseRiscV64ResetSystemLib.inf | 38 ++++++ OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c | 20 +++ OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c | 128 ++++++++++++++++++++ 3 files changed, 186 insertions(+) diff --git a/OvmfPkg/Library/ResetSystemLib/BaseRiscV64ResetSystemLib.inf b/OvmfPkg/Library/ResetSystemLib/BaseRiscV64ResetSystemLib.inf new file mode 100644 index 000000000000..f26ddf682625 --- /dev/null +++ b/OvmfPkg/Library/ResetSystemLib/BaseRiscV64ResetSystemLib.inf @@ -0,0 +1,38 @@ +## @file +# Base library instance for ResetSystem library class for RISC-V +# +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = BaseRiscV64ResetSystemLib + FILE_GUID = AB45A200-769D-4C10-B0D6-5E1FF5EEBF31 + 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/ResetSystemLib.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + IoLib + TimerLib + RiscVSbiLib diff --git a/OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c b/OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c new file mode 100644 index 000000000000..027e235cad11 --- /dev/null +++ b/OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c @@ -0,0 +1,20 @@ +/** @file + DXE Reset System Library Shutdown API implementation for OVMF. + + Copyright (C) 2020, Red Hat, Inc. + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // CpuDeadLoop() +#include // ResetShutdown() + +EFI_STATUS +EFIAPI +DxeResetInit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return EFI_SUCCESS; +} diff --git a/OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c b/OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c new file mode 100644 index 000000000000..14f7653aa8de --- /dev/null +++ b/OvmfPkg/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.38.0