From nobody Tue Feb 10 17:45:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+87205+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87205+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1646210714; cv=none; d=zohomail.com; s=zohoarc; b=EfJhY74kvPLiRUQNU8riTtThE1ZU9nRwCTC+KRUW1jw4+kUmGzUQ9LqPlQj1B7t5uO8tos3gtq7PukaG7XHWKpw1YpkFDB/pJYcLOa1M6Z5AEZJIbA7EStMPzot4scYxFh8mv1x7i5rjdvEyTgbv4TsRnxxeTU18l2iA0+Zz5eQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646210714; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=kjMBILqPQNwHdlawo0VKx82Z2dlWCGJkRV6oCUSNyv4=; b=B+HMy6iPkb5tMO0RyOJR51GbHu1gO3Ibl16vz2DfNhdSzdkDsuhI1menBUH4SMthKHme5L80PyVp4PSO7V8Wy4cxu1QCkxlqzrN379JqUXIAqepDL4kGY+SoNbffW994rw2uOQvQYBwuziczfIGECo0kKKUoqoHTcBgGNrdwYq4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87205+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1646210714059608.8309762032105; Wed, 2 Mar 2022 00:45:14 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id M0X5YY1788612xVRk8Fou99b; Wed, 02 Mar 2022 00:45:14 -0800 X-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 X-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-devel] [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> 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/ Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lixianglai@loongson.cn X-Gm-Message-State: kuSe6SghyIMJVfIyoq0ptTjJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1646210714; bh=/zFTM+KopHqE1Jl+4niUQXcteJWuqpEIzJSgYrSTU4U=; h=Date:From:Reply-To:Subject:To; b=g8ldNfc4kWwulBrR4CDLOL+l1QiUVmfVUkaK7YZCW7lg9hyhVIz4Zn6dRx+XX1WLn/i miucetYzSrxcgA9lvyBijmGiOovnlwHIv1TAk3p0LxYBQnjUWW2TekR6PDRDMe7w6z49x yF8sDm/TZ/fxCxIcuzlv+w4y5gAWgkKq8qE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1646210733077100001 Content-Type: text/plain; charset="utf-8" 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 + Base Reset System Library Shutdown API implementation for LoongArch. + + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +/** + To get acpi base address. + + @param VOID + + @retval acpi base address. +**/ +UINTN +LoongArchQemuAcpiBase (VOID) +{ + VOID *Address =3D (VOID*) LS7A_ACPI_REG_BASE; + + if (EfiGoneVirtual ()) { + /**The RTC controller address and the ResetSystem controller address a= re 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 =3D LoongArchQemuAcpiBase (); + MmioWrite32 (Address + LS7A_GPE0_RESET_REG, 1); + CpuDeadLoop (); +} +/** + Shutdown device. + + @param VOID + + @retval VOID +**/ +VOID +LoongArchQemuShutdown (VOID) +{ + UINTN Address; + + // + // sleep with S5 + // + Address =3D 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 o= f 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 p= assed + into ResetData. If the platform does not recognize the EFI_GUID in ResetD= ata + 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 stri= ng, + 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 shutd= own 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 f= eature. + **/ +VOID +EFIAPI +EnterS3WithImmediateWake ( + VOID + ) +{ + // not implemented +} 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 +# Base Reset System Library Shutdown API implementation for LoongArch. +# +# Copyright (c) 2021 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D ResetSystemLib + FILE_GUID =3D e8579e63-0275-42d6-b52e-0f6d3a8e3369 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D 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 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-