public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "xianglai" <lixianglai@loongson.cn>
To: devel@edk2.groups.io
Subject: [edk2-platforms][PATCH V1 14/15] Platform/Loongson: Add Reset System Lib.
Date: Wed,  2 Mar 2022 03:44:46 -0500	[thread overview]
Message-ID: <20220302084447.2991355-15-lixianglai@loongson.cn> (raw)
In-Reply-To: <20220302084447.2991355-1-lixianglai@loongson.cn>

This library provides interfaces related to restart and shutdown.

Signed-off-by: xianglai li <lixianglai@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


  parent reply	other threads:[~2022-03-02  8:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02  8:44 [edk2-platforms][PATCH V1 00/15] Platform: Add Loongson support xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 01/15] Platform/Loongson: Add Serial Port library xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 02/15] Platform/Loongson: Support SEC And Add Readme.md xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 03/15] Platform/Loongson: Add PeiServicesTablePointerLib xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 04/15] Platform/Loongson: Add QemuFwCfgLib xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 05/15] Platform/Loongson: Add BpiLib xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 06/15] Platform/Loongson: Add MmuLib xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 07/15] Platform/Loongson: Add StableTimerLib xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 08/15] Platform/Loongson: Support PEI phase xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 09/15] Platform/Loongson: Add CPU DXE driver xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 10/15] Platform/Loongson: Add PciCpuIoDxe driver xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 11/15] Platform/Loongson: Add timer Dxe driver xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 12/15] Platform/Loongson: Add RealTime Clock lib xianglai
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 13/15] Platform/Loongson: Add Platform Boot Manager Lib xianglai
2022-03-02  8:44 ` xianglai [this message]
2022-03-02  8:44 ` [edk2-platforms][PATCH V1 15/15] Platform/Loongson: Support Dxe xianglai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220302084447.2991355-15-lixianglai@loongson.cn \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox