From nobody Mon Feb 9 21:40:28 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+88005+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+88005+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1648174618; cv=none; d=zohomail.com; s=zohoarc; b=atQLtM4PenrJyzamMEgohwFIB/WEWPiQDY0hNy57HvXW1Mwmb3lhEEAdCoRHij7klWgSgTFTw6s7m+4mIF4fPfakKjpwjbgtQNiyUyah3hHktLiVZmWNWGm84aCp1456ibN3fmxsnSl8Y4pRERY+VPpISRd5Ky8XVFtzfra73LY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648174618; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=t7mdpT6BRw9MXfimp4UYWtYqXrOPdomOC9kNWCSvIqI=; b=atE+XIQR7E+q+Ke8FKD584E2GxzoMEWh0G7Z8akYeLTgLzBpdlGPJsJauKMuWfBO/yNzpxBDBuMLaQku4+07UtBR62xtjBpJPZfV6FHPHdnj8QIpNPNmvoxzMw2osOxHS7Nw0Vu9do2MlBLajJN4qiG4kpFjQvzej3Uoezl90b8= 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+88005+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16481746188341014.9910043388021; Thu, 24 Mar 2022 19:16:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id rpnfYY1788612x37xYeqIrHb; Thu, 24 Mar 2022 19:16:58 -0700 X-Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web08.420.1648174617246854271 for ; Thu, 24 Mar 2022 19:16:57 -0700 X-Received: from localhost.localdomain (unknown [10.2.10.197]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx3xMIJj1irWAPAA--.15467S15; Fri, 25 Mar 2022 10:16:55 +0800 (CST) From: "xianglai" To: devel@edk2.groups.io Cc: maobibo@loongson.cn Subject: [edk2-devel] [edk2-platforms][PATCH V2 13/16] Platform/Loongson: Add Reset System Lib. Date: Fri, 25 Mar 2022 10:16:17 +0800 Message-Id: <883740eb566ec14dca251c23f32c3bf24ef5b1d6.1648171285.git.lixianglai@loongson.cn> In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: AQAAf9Dx3xMIJj1irWAPAA--.15467S15 X-Coremail-Antispam: 1UD129KBjvJXoW3GF1kKFyUXF4rXw4UZF47urg_yoW7Kr4Upr 48uF47Kr1UJw4aqw4fKa48CFn5Cwn0k345JrWjyw1Uuw15tr1kC3yUtr40q39rKry3C34F vayj93yxZa4DXr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBv14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr1j 6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6x IIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVCm-wCF04 k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18 MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr4 1lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1l IxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4 A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQSdkUUUUU= 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: liKQtrpTFsMdzjXYnA4byp4ax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1648174618; bh=Mu7Xy1OLdDdp6WTPpyFn8wGSppx+G6chdQ4CmFQgqYI=; h=Cc:Date:From:Reply-To:Subject:To; b=sMquSk03oQIdezBdbnQ5T+D5xp6yYAIE43GQ87MtzIW8VDcMk+ElhNcTPjZjImCl9n8 XU5Dd+H+wOHFKaky5euzWCMYE2L5FmHdxkM2Wh7QVQD8oYR/tGgn3gOOutYNE+A25/A5r Iis/SjBqAtsDbF44Y5bBJBcJN6+8rqNwXLQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1648174620191100044 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.31.1 -=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 (#88005): https://edk2.groups.io/g/devel/message/88005 Mute This Topic: https://groups.io/mt/90014678/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-