]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/RiscVVirt: Add ResetSystemLib library
authorSunil V L <sunilvl@ventanamicro.com>
Sat, 28 Jan 2023 18:01:13 +0000 (23:31 +0530)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 16 Feb 2023 05:53:28 +0000 (05:53 +0000)
RISC-V Qemu virt uses SBI calls to implement the reset.
Add the base class library.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
Acked-by: Abner Chang <abner.chang@amd.com>
Reviewed-by: Andrei Warkentin <andrei.warkentin@intel.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
OvmfPkg/RiscVVirt/Library/ResetSystemLib/BaseResetSystemLib.inf [new file with mode: 0644]
OvmfPkg/RiscVVirt/Library/ResetSystemLib/ResetSystemLib.c [new file with mode: 0644]

diff --git a/OvmfPkg/RiscVVirt/Library/ResetSystemLib/BaseResetSystemLib.inf b/OvmfPkg/RiscVVirt/Library/ResetSystemLib/BaseResetSystemLib.inf
new file mode 100644 (file)
index 0000000..c3fa6bd
--- /dev/null
@@ -0,0 +1,38 @@
+## @file\r
+#  Base library instance for ResetSystem library class for RISC-V\r
+#\r
+#  Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x0001001B\r
+  BASE_NAME                      = BaseResetSystemLib\r
+  FILE_GUID                      = AB45A200-769D-4C10-B0D6-5E1FF5EEBF31\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ResetSystemLib\r
+\r
+#\r
+# The following information is for reference only and not required by the build\r
+# tools.\r
+#\r
+#  VALID_ARCHITECTURES           = RISCV64\r
+#\r
+\r
+[Sources]\r
+  ResetSystemLib.c\r
+\r
+[Packages]\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  MdePkg/MdePkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  IoLib\r
+  TimerLib\r
+  RiscVSbiLib\r
diff --git a/OvmfPkg/RiscVVirt/Library/ResetSystemLib/ResetSystemLib.c b/OvmfPkg/RiscVVirt/Library/ResetSystemLib/ResetSystemLib.c
new file mode 100644 (file)
index 0000000..14f7653
--- /dev/null
@@ -0,0 +1,128 @@
+/** @file\r
+  Reset System Library functions for RISC-V\r
+\r
+  Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/ResetSystemLib.h>\r
+#include <Library/BaseRiscVSbiLib.h>\r
+\r
+/**\r
+  This function causes a system-wide reset (cold reset), in which\r
+  all circuitry within the system returns to its initial state. This type of reset\r
+  is asynchronous to system operation and operates without regard to\r
+  cycle boundaries.\r
+\r
+  If this function returns, it means that the system does not support cold reset.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetCold (\r
+  VOID\r
+  )\r
+{\r
+  // Warm Reset via SBI ecall\r
+  SbiSystemReset (SBI_SRST_RESET_TYPE_COLD_REBOOT, SBI_SRST_RESET_REASON_NONE);\r
+}\r
+\r
+/**\r
+  This function causes a system-wide initialization (warm reset), in which all processors\r
+  are set to their initial state. Pending cycles are not corrupted.\r
+\r
+  If this function returns, it means that the system does not support warm reset.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetWarm (\r
+  VOID\r
+  )\r
+{\r
+  // Warm Reset via SBI ecall\r
+  SbiSystemReset (SBI_SRST_RESET_TYPE_WARM_REBOOT, SBI_SRST_RESET_REASON_NONE);\r
+}\r
+\r
+/**\r
+  This function causes the system to enter a power state equivalent\r
+  to the ACPI G2/S5 or G3 states.\r
+\r
+  If this function returns, it means that the system does not support shutdown reset.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetShutdown (\r
+  VOID\r
+  )\r
+{\r
+  // Shut down via SBI ecall\r
+  SbiSystemReset (SBI_SRST_RESET_TYPE_SHUTDOWN, SBI_SRST_RESET_REASON_NONE);\r
+}\r
+\r
+/**\r
+  This function causes a systemwide reset. The exact type of the reset is\r
+  defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r
+  into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r
+  the platform must pick a supported reset type to perform. The platform may\r
+  optionally log the parameters from any non-normal reset that occurs.\r
+\r
+  @param[in]  DataSize   The size, in bytes, of ResetData.\r
+  @param[in]  ResetData  The data buffer starts with a Null-terminated string,\r
+                         followed by the EFI_GUID.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetPlatformSpecific (\r
+  IN UINTN  DataSize,\r
+  IN VOID   *ResetData\r
+  )\r
+{\r
+  //\r
+  // Can map to OpenSBI vendor or platform specific reset type.\r
+  //\r
+  return;\r
+}\r
+\r
+/**\r
+  The ResetSystem function resets the entire platform.\r
+\r
+  @param[in] ResetType      The type of reset to perform.\r
+  @param[in] ResetStatus    The status code for the reset.\r
+  @param[in] DataSize       The size, in bytes, of ResetData.\r
+  @param[in] ResetData      For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown\r
+                            the data buffer starts with a Null-terminated string, optionally\r
+                            followed by additional binary data. The string is a description\r
+                            that the caller may use to further indicate the reason for the\r
+                            system reset.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetSystem (\r
+  IN EFI_RESET_TYPE  ResetType,\r
+  IN EFI_STATUS      ResetStatus,\r
+  IN UINTN           DataSize,\r
+  IN VOID            *ResetData OPTIONAL\r
+  )\r
+{\r
+  switch (ResetType) {\r
+    case EfiResetWarm:\r
+      ResetWarm ();\r
+      break;\r
+\r
+    case EfiResetCold:\r
+      ResetCold ();\r
+      break;\r
+\r
+    case EfiResetShutdown:\r
+      ResetShutdown ();\r
+      return;\r
+\r
+    case EfiResetPlatformSpecific:\r
+      ResetPlatformSpecific (DataSize, ResetData);\r
+      return;\r
+\r
+    default:\r
+      return;\r
+  }\r
+}\r