[edk2-devel] [edk2-platforms][PATCH V1 14/15] Platform/Loongson: Add Reset System Lib.
xianglai
lixianglai at loongson.cn
Wed Mar 2 08:44:46 UTC 2022
This library provides interfaces related to restart and shutdown.
Signed-off-by: xianglai li <lixianglai at loongson.cn>
---
.../Library/ResetSystemLib/ResetSystemLib.c | 155 ++++++++++++++++++
.../Library/ResetSystemLib/ResetSystemLib.inf | 40 +++++
2 files changed, 195 insertions(+)
create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystemLib.c
create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystemLib.inf
diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystemLib.c b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystemLib.c
new file mode 100644
index 0000000000..3adcb5193a
--- /dev/null
+++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystemLib.c
@@ -0,0 +1,155 @@
+/** @file
+ Base Reset System Library Shutdown API implementation for LoongArch.
+
+ Copyright (c) 2021 Loongson Technology Corporation Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/CacheMaintenanceLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/IoLib.h>
+#include <Library/PcdLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiRuntimeLib.h>
+#include <LoongArchQemuPlatform.h>
+/**
+ To get acpi base address.
+
+ @param VOID
+
+ @retval acpi base address.
+**/
+UINTN
+LoongArchQemuAcpiBase (VOID)
+{
+ VOID *Address = (VOID*) LS7A_ACPI_REG_BASE;
+
+ if (EfiGoneVirtual ()) {
+ /**The RTC controller address and the ResetSystem controller address are in the same page.
+ The function KVMToolRTCMapMemory has placed the entire page address in the memory mapping table,
+ do not add additional.
+ * */
+ EfiConvertPointer (0, &Address);
+ DEBUG ((DEBUG_INFO, "%a: virtual -> 0x%x\n", __FUNCTION__, Address));
+ } else {
+ DEBUG ((DEBUG_INFO, "%a: physical -> 0x%x\n", __FUNCTION__, Address));
+ }
+
+ return (UINTN) Address;
+}
+/**
+ Restart device.
+
+ @param VOID
+
+ @retval VOID
+**/
+VOID
+LoongArchQemuReset (VOID)
+{
+
+ UINTN Address;
+
+ DEBUG ((DEBUG_INFO, "%a: LoongArchQemu reset via acpi\n", __FUNCTION__));
+
+ Address = LoongArchQemuAcpiBase ();
+ MmioWrite32 (Address + LS7A_GPE0_RESET_REG, 1);
+ CpuDeadLoop ();
+}
+/**
+ Shutdown device.
+
+ @param VOID
+
+ @retval VOID
+**/
+VOID
+LoongArchQemuShutdown (VOID)
+{
+ UINTN Address;
+
+ //
+ // sleep with S5
+ //
+ Address = LoongArchQemuAcpiBase ();
+ MmioWrite16 (Address + LS7A_PM_CNT_BLK, ACPI_BITMASK_SLEEP_ENABLE);
+ CpuDeadLoop ();
+}
+
+/**
+ 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)
+{
+ LoongArchQemuReset ();
+}
+
+/**
+ 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)
+{
+ LoongArchQemuReset ();
+}
+
+/**
+ 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
+ )
+{
+ LoongArchQemuReset ();
+}
+
+/**
+ 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)
+{
+ LoongArchQemuShutdown ();
+}
+
+
+/**
+ This function causes the system to enter S3 and then wake up immediately.
+
+ If this function returns, it means that the system does not support S3 feature.
+ **/
+VOID
+EFIAPI
+EnterS3WithImmediateWake (
+ VOID
+ )
+{
+ // not implemented
+}
diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystemLib.inf b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystemLib.inf
new file mode 100644
index 0000000000..03bb479d73
--- /dev/null
+++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystemLib.inf
@@ -0,0 +1,40 @@
+## @file
+# Base Reset System Library Shutdown API implementation for LoongArch.
+#
+# Copyright (c) 2021 Loongson Technology Corporation Limited. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = ResetSystemLib
+ FILE_GUID = e8579e63-0275-42d6-b52e-0f6d3a8e3369
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = EfiResetSystemLib
+
+
+[Sources.common]
+ ResetSystemLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
+ Platform/Loongson/LoongArchQemuPkg/Loongson.dec
+
+[LibraryClasses]
+ DebugLib
+ CacheMaintenanceLib
+ MemoryAllocationLib
+ UefiRuntimeServicesTableLib
+ TimerLib
+ UefiLib
+ UefiBootServicesTableLib
+
+[Protocols]
+ gEfiPciRootBridgeIoProtocolGuid
+
+[Pcd]
+ gEmbeddedTokenSpaceGuid.PcdFlashFvMainBase
--
2.27.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#87205): https://edk2.groups.io/g/devel/message/87205
Mute This Topic: https://groups.io/mt/89497234/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list