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.web08.420.1648174617246854271 for ; Thu, 24 Mar 2022 19:16:57 -0700 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.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-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> X-Mailer: git-send-email 2.31.1 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/ 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.31.1