Cc: Daniel Schaefer <daniel.schae...@hpe.com>
Cc: Abner Chang <abner.ch...@hpe.com>
Cc: Sunil V L <suni...@ventanamicro.com>

Signed-off-by: Daniel Schaefer <daniel.schae...@hpe.com>
---
 Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.c   | 128 
++++++++++++++++++++
 Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.inf |  33 
+++++
 Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc            |  12 +-
 Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc  |  12 +-
 Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h         |  38 
+++++-
 Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c |  44 
++++++-
 Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi           |   2 +-
 7 files changed, 256 insertions(+), 13 deletions(-)

diff --git 
a/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.c 
b/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.c
new file mode 100644
index 0000000000..646073c106
--- /dev/null
+++ b/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.c
@@ -0,0 +1,128 @@
+/** @file
+  Reset System Library functions for RISC-V
+
+  Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/ResetSystemLib.h>
+#include <Library/RiscVEdk2SbiLib.h>
+
+/**
+  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;
+  }
+}
diff --git 
a/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.inf 
b/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.inf
new file mode 100644
index 0000000000..33db9fb6d8
--- /dev/null
+++ b/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.inf
@@ -0,0 +1,33 @@
+## @file
+#  Library instance for ResetSystem library class for RISC-V using SBI ecalls
+#
+#  Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights 
reserved.<BR>
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = ResetSystemLib
+  FILE_GUID                      = 3eff6057-1116-4dcb-837e-c0ef1a120ab1
+  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]
+  ResetSystemLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec
+
+[LibraryClasses]
+  DebugLib
+  RiscVEdk2SbiLib
diff --git a/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc 
b/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc
index 1dc6405a20..f14511120e 100644
--- a/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc
+++ b/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc
@@ -237,12 +237,13 @@
   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

   
ReportStatusCodeLib|MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf

-!ifdef $(DEBUG_ON_SERIAL_PORT)

-  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

-!else

-  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf

-!endif

+  
ResetSystemLib|Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.inf

   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf

+!ifdef $(DEBUG_ON_SERIAL_PORT)

+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

+!else

+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf

+!endif

 !if $(SECURE_BOOT_ENABLE) == TRUE

   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf

 !endif

@@ -452,6 +453,7 @@
   #

   Silicon/RISC-V/ProcessorPkg/Universal/CpuDxe/CpuDxe.inf

   Silicon/RISC-V/ProcessorPkg/Universal/SmbiosDxe/RiscVSmbiosDxe.inf

+  MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf

 

   MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf {

diff --git 
a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc 
b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc
index cc62ad0521..18a482aba6 100644
--- a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc
+++ b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc
@@ -244,12 +244,13 @@
   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

   
ReportStatusCodeLib|MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf

-!ifdef $(DEBUG_ON_SERIAL_PORT)

-  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

-!else

-  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf

-!endif

+  
ResetSystemLib|Platform/RISC-V/PlatformPkg/Library/ResetSystemLib/ResetSystemLib.inf

   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf

+!ifdef $(DEBUG_ON_SERIAL_PORT)

+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

+!else

+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf

+!endif

 !if $(SECURE_BOOT_ENABLE) == TRUE

   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf

 !endif

@@ -458,6 +459,7 @@
   #

   Silicon/RISC-V/ProcessorPkg/Universal/CpuDxe/CpuDxe.inf

   Silicon/RISC-V/ProcessorPkg/Universal/SmbiosDxe/RiscVSmbiosDxe.inf

+  MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf

 

   MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf {

diff --git a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h 
b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h
index 66a87cb8c3..88d957f002 100644
--- a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h
+++ b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h
@@ -1,7 +1,7 @@
 /** @file

   Library to call the RISC-V SBI ecalls

 

-  Copyright (c) 2020, Hewlett Packard Development LP. All rights reserved.<BR>

+  Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.<BR>

 

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

@@ -474,6 +474,42 @@ SbiRemoteHfenceVvma (
   IN  UINTN                          Size

   );

 

+///

+/// Firmware System Reset (SRST) Extension

+///

+

+/**

+  Reset the system

+

+  The System Reset Extension provides a function that allow the supervisor

+  software to request system-level reboot or shutdown. The term "system" refers

+  to the world-view of supervisor software and the underlying SBI

+  implementation could be machine mode firmware or hypervisor.

+

+  Valid parameters for ResetType and ResetReason are defined in 
sbi_ecall_interface.h

+

+  #define SBI_SRST_RESET_TYPE_SHUTDOWN    0x0

+  #define SBI_SRST_RESET_TYPE_COLD_REBOOT 0x1

+  #define SBI_SRST_RESET_TYPE_WARM_REBOOT 0x2

+

+  #define SBI_SRST_RESET_REASON_NONE      0x0

+  #define SBI_SRST_RESET_REASON_SYSFAIL   0x1

+

+  When the call is successful, it will not return.

+

+  @param[in]  ResetType            Typ of reset: Shutdown, cold-, or 
warm-reset.

+  @param[in]  ResetReason          Why the system resets. No reason or system 
failure.

+  @retval EFI_INVALID_PARAMETER    Either ResetType or ResetReason is invalid.

+  @retval EFI_UNSUPPORTED          ResetType is valid but not implemented on 
the platform.

+  @retval EFI_DEVICE_ERROR         Unknown error.

+**/

+EFI_STATUS

+EFIAPI

+SbiSystemReset (

+  IN  UINTN                          ResetType,

+  IN  UINTN                          ResetReason

+  );

+

 ///

 /// Vendor Specific extension space: Extension Ids 0x09000000 through 
0x09FFFFFF

 ///

diff --git 
a/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c 
b/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c
index 9bbeaaec3f..319526ed8f 100644
--- a/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c
+++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c
@@ -15,7 +15,7 @@
   - SbiLegacyRemoteSfenceVmaAsid -> Use SbiRemoteSfenceVmaAsid

   - SbiLegacyShutdown            -> Wait for new System Reset extension

 

-  Copyright (c) 2020, Hewlett Packard Development LP. All rights reserved.<BR>

+  Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.<BR>

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

   @par Revision Reference:

@@ -715,6 +715,48 @@ SbiRemoteHFenceVvma (
   return TranslateError (Ret.Error);

 }

 

+/**

+  Reset the system

+

+  The System Reset Extension provides a function that allow the supervisor

+  software to request system-level reboot or shutdown. The term "system" refers

+  to the world-view of supervisor software and the underlying SBI

+  implementation could be machine mode firmware or hypervisor.

+

+  Valid parameters for ResetType and ResetReason are defined in 
sbi_ecall_interface.h

+

+  #define SBI_SRST_RESET_TYPE_SHUTDOWN    0x0

+  #define SBI_SRST_RESET_TYPE_COLD_REBOOT 0x1

+  #define SBI_SRST_RESET_TYPE_WARM_REBOOT 0x2

+

+  #define SBI_SRST_RESET_REASON_NONE      0x0

+  #define SBI_SRST_RESET_REASON_SYSFAIL   0x1

+

+  When the call is successful, it will not return.

+

+  @param[in]  ResetType            Typ of reset: Shutdown, cold-, or 
warm-reset.

+  @param[in]  ResetReason          Why the system resets. No reason or system 
failure.

+  @retval EFI_INVALID_PARAMETER    Either ResetType or ResetReason is invalid.

+  @retval EFI_UNSUPPORTED          ResetType is valid but not implemented on 
the platform.

+  @retval EFI_DEVICE_ERROR         Unknown error.

+**/

+EFI_STATUS

+EFIAPI

+SbiSystemReset (

+  IN  UINTN                          ResetType,

+  IN  UINTN                          ResetReason

+  )

+{

+  SbiRet Ret = SbiCall (

+                 SBI_EXT_SRST,

+                 SBI_EXT_SRST_RESET,

+                 2,

+                 ResetType,

+                 ResetReason

+                 );

+  return TranslateError (Ret.Error);

+}

+

 //

 // SBI interface function for the vendor extension

 //

diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi 
b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi
index a731c7e369..937caee083 160000
--- a/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi
+++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi
@@ -1 +1 @@
-Subproject commit a731c7e36988c3308e1978ecde491f2f6182d490
+Subproject commit 937caee0833115f69d697ca190001ba0aa5c7368
-- 
2.33.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#81547): https://edk2.groups.io/g/devel/message/81547
Mute This Topic: https://groups.io/mt/86117331/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to