From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web12.5453.1646210708179956314 for ; Wed, 02 Mar 2022 00:45:08 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: loongson.cn, ip: 114.242.206.163, mailfrom: lixianglai@loongson.cn) Received: from localhost.localdomain (unknown [10.2.5.185]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxn89_Lh9i7TkBAA--.6283S16; Wed, 02 Mar 2022 16:44:55 +0800 (CST) From: "xianglai" 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 Message-Id: <20220302084447.2991355-15-lixianglai@loongson.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220302084447.2991355-1-lixianglai@loongson.cn> References: <20220302084447.2991355-1-lixianglai@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf9Dxn89_Lh9i7TkBAA--.6283S16 X-Coremail-Antispam: 1UD129KBjvJXoW3GF1kKFyUXF4rXw4UZF47urg_yoW7Kr4Upr 48uF47Kr1UJw4aqw4fKa48uFn5Cwn0k345JrWjyw1Uuw15tr1kC3yUtr40q39rKry3C34F vayj93yxZa4DXr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ Content-Transfer-Encoding: quoted-printable This library provides interfaces related to restart and shutdown. Signed-off-by: xianglai li --- .../Library/ResetSystemLib/ResetSystemLib.c | 155 ++++++++++++++++++ .../Library/ResetSystemLib/ResetSystemLib.inf | 40 +++++ 2 files changed, 195 insertions(+) create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemL= ib/ResetSystemLib.c create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemL= ib/ResetSystemLib.inf diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/Rese= tSystemLib.c b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/Re= setSystemLib.c new file mode 100644 index 0000000000..3adcb5193a --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystem= Lib.c @@ -0,0 +1,155 @@ +/** @file=0D + Base Reset System Library Shutdown API implementation for LoongArch.=0D +=0D + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +/**=0D + To get acpi base address.=0D +=0D + @param VOID=0D +=0D + @retval acpi base address.=0D +**/=0D +UINTN=0D +LoongArchQemuAcpiBase (VOID)=0D +{=0D + VOID *Address =3D (VOID*) LS7A_ACPI_REG_BASE;=0D +=0D + if (EfiGoneVirtual ()) {=0D + /**The RTC controller address and the ResetSystem controller address a= re in the same page.=0D + The function KVMToolRTCMapMemory has placed the entire page address= in the memory mapping table,=0D + do not add additional.=0D + * */=0D + EfiConvertPointer (0, &Address);=0D + DEBUG ((DEBUG_INFO, "%a: virtual -> 0x%x\n", __FUNCTION__, Address));= =0D + } else {=0D + DEBUG ((DEBUG_INFO, "%a: physical -> 0x%x\n", __FUNCTION__, Address));= =0D + }=0D +=0D + return (UINTN) Address;=0D +}=0D +/**=0D + Restart device.=0D +=0D + @param VOID=0D +=0D + @retval VOID=0D +**/=0D +VOID=0D +LoongArchQemuReset (VOID)=0D +{=0D +=0D + UINTN Address;=0D +=0D + DEBUG ((DEBUG_INFO, "%a: LoongArchQemu reset via acpi\n", __FUNCTION__))= ;=0D +=0D + Address =3D LoongArchQemuAcpiBase ();=0D + MmioWrite32 (Address + LS7A_GPE0_RESET_REG, 1);=0D + CpuDeadLoop ();=0D +}=0D +/**=0D + Shutdown device.=0D +=0D + @param VOID=0D +=0D + @retval VOID=0D +**/=0D +VOID=0D +LoongArchQemuShutdown (VOID)=0D +{=0D + UINTN Address;=0D +=0D + //=0D + // sleep with S5=0D + //=0D + Address =3D LoongArchQemuAcpiBase ();=0D + MmioWrite16 (Address + LS7A_PM_CNT_BLK, ACPI_BITMASK_SLEEP_ENABLE);=0D + CpuDeadLoop ();=0D +}=0D +=0D +/**=0D + This function causes a system-wide reset (cold reset), in which=0D + all circuitry within the system returns to its initial state. This type o= f reset=0D + is asynchronous to system operation and operates without regard to=0D + cycle boundaries.=0D +=0D + If this function returns, it means that the system does not support cold = reset.=0D +**/=0D +VOID=0D +EFIAPI ResetCold (VOID)=0D +{=0D + LoongArchQemuReset ();=0D +}=0D +=0D +/**=0D + This function causes a system-wide initialization (warm reset), in which = all processors=0D + are set to their initial state. Pending cycles are not corrupted.=0D +=0D + If this function returns, it means that the system does not support warm = reset.=0D +**/=0D +VOID=0D +EFIAPI ResetWarm (VOID)=0D +{=0D + LoongArchQemuReset ();=0D +}=0D +=0D +/**=0D + This function causes a systemwide reset. The exact type of the reset is=0D + defined by the EFI_GUID that follows the Null-terminated Unicode string p= assed=0D + into ResetData. If the platform does not recognize the EFI_GUID in ResetD= ata=0D + the platform must pick a supported reset type to perform.The platform may= =0D + optionally log the parameters from any non-normal reset that occurs.=0D +=0D + @param[in] DataSize The size, in bytes, of ResetData.=0D + @param[in] ResetData The data buffer starts with a Null-terminated stri= ng,=0D + followed by the EFI_GUID.=0D + **/=0D +VOID=0D +EFIAPI=0D +ResetPlatformSpecific (=0D + IN UINTN DataSize,=0D + IN VOID *ResetData=0D + )=0D +{=0D + LoongArchQemuReset ();=0D +}=0D +=0D +/**=0D + This function causes the system to enter a power state equivalent=0D + to the ACPI G2/S5 or G3 states.=0D +=0D + If this function returns, it means that the system does not support shutd= own reset.=0D +**/=0D +VOID=0D +EFIAPI ResetShutdown (VOID)=0D +{=0D + LoongArchQemuShutdown ();=0D +}=0D +=0D +=0D +/**=0D + This function causes the system to enter S3 and then wake up immediately= .=0D +=0D + If this function returns, it means that the system does not support S3 f= eature.=0D + **/=0D +VOID=0D +EFIAPI=0D +EnterS3WithImmediateWake (=0D + VOID=0D + )=0D +{=0D + // not implemented=0D +}=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/Rese= tSystemLib.inf b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/= ResetSystemLib.inf new file mode 100644 index 0000000000..03bb479d73 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemLib/ResetSystem= Lib.inf @@ -0,0 +1,40 @@ +## @file=0D +# Base Reset System Library Shutdown API implementation for LoongArch.=0D +#=0D +# Copyright (c) 2021 Loongson Technology Corporation Limited. All rights = reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D ResetSystemLib=0D + FILE_GUID =3D e8579e63-0275-42d6-b52e-0f6d3a8e3369= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D EfiResetSystemLib=0D +=0D +=0D +[Sources.common]=0D + ResetSystemLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + EmbeddedPkg/EmbeddedPkg.dec=0D + Platform/Loongson/LoongArchQemuPkg/Loongson.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + CacheMaintenanceLib=0D + MemoryAllocationLib=0D + UefiRuntimeServicesTableLib=0D + TimerLib=0D + UefiLib=0D + UefiBootServicesTableLib=0D +=0D +[Protocols]=0D + gEfiPciRootBridgeIoProtocolGuid=0D +=0D +[Pcd]=0D + gEmbeddedTokenSpaceGuid.PcdFlashFvMainBase=0D --=20 2.27.0