From nobody Mon Feb 9 09:47:20 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+93903+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+93903+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1663299421; cv=none; d=zohomail.com; s=zohoarc; b=iDzTJSUqIKEDGszSxsd3AcMN265560rqafiAEIT/u+1HwyNDXLZnFKcf9BqAnA+1VsQ8CZrr9W4vE+8AmA39eFDyx6dT0S6ssSaT6Vx//AjS6HUgpV23Pd4Zenp1StMMplOqQQj+oeDgTAfZkJefcd6oY14wbYaIA6iUZGx3Phc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663299421; 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=yBN6gW8FbqioSWqif+11r1lsYpNvjrUiJVWhi4D2p64=; b=H3MTXYwqqQh5k86TWpgK8BAIS44EtJUIxLwIGW6Vj82521pwITook3hQSLbrxNg0PAQDKKxnR5HeeGOWBxwZvG7ZXyE1aaEazwNr63Gn3vU2YaRF3Q4Fa6yTtbwmgmQs8JIWeTAYmOqMuhrgsro9V3tdyrzRLMtG00YqwA7t3cw= 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+93903+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1663299421673237.7555820304848; Thu, 15 Sep 2022 20:37:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id cSYhYY1788612xMamPxA9JCV; Thu, 15 Sep 2022 20:37:01 -0700 X-Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web08.2163.1663299413461243947 for ; Thu, 15 Sep 2022 20:37:00 -0700 X-Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxPGtB7yNj984aAA--.41628S15; Fri, 16 Sep 2022 11:36:43 +0800 (CST) From: "xianglai" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, michael.d.kinney@intel.com, maobibo@loongson.cn Subject: [edk2-devel] [edk2-platforms][PATCH V2 13/16] Platform/Loongson: Add Reset System Lib. Date: Fri, 16 Sep 2022 11:36:30 +0800 Message-Id: <3f8acac36ae0209d4a4e738f18e179c1949affc4.1663298005.git.lixianglai@loongson.cn> In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxPGtB7yNj984aAA--.41628S15 X-Coremail-Antispam: 1UD129KBjvAXoWftr1fCw13ZF18ZrWxJFy7Wrg_yoW8uw47to W2gan7t3y8Jrs5u397Wrn3GF4IqFsYq398ZF1rJFWUJrWDZr109FWvqay8JF93tFn8XF45 GayfJ3yrJrWagF4kn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRUUUUUUUUU= 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: bvaQ5Q6lExPKvfdVvRctVVOgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1663299421; bh=LG/dSvzqif/Hiye6kltp6xTm6CIlngkV26P4/8TBqwo=; h=Cc:Date:From:Reply-To:Subject:To; b=iKWdAFpN6I29sqwiRtWMjADTj51lLaRp1M7qHIhQdr+lLbGniqaIyyzAxnP7E91l5gu 9PaSSUb+QTIOCL8WxHD3fBSN46WgoNGsusWueHBGUkrD5Q67tg74HoEd+9qtzDqv7mR2R Yn/T3BXP38ApXLDm0qhJk7opERSM5oXiN40= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1663299422354100005 Content-Type: text/plain; charset="utf-8" This library provides interfaces related to restart and shutdown. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4054 Signed-off-by: xianglai li --- .../BaseResetSystemAcpiGed.c | 155 ++++++++++ .../BaseResetSystemAcpiGedLib.inf | 42 +++ .../DxeResetSystemAcpiGed.c | 270 ++++++++++++++++++ .../DxeResetSystemAcpiGedLib.inf | 47 +++ .../ResetSystemAcpiLib/ResetSystemAcpiGed.c | 128 +++++++++ .../ResetSystemAcpiLib/ResetSystemAcpiGed.h | 20 ++ 6 files changed, 662 insertions(+) create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/BaseResetSystemAcpiGed.c create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/BaseResetSystemAcpiGedLib.inf create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/DxeResetSystemAcpiGed.c create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/DxeResetSystemAcpiGedLib.inf create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/ResetSystemAcpiGed.c create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/ResetSystemAcpiGed.h diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= BaseResetSystemAcpiGed.c b/Platform/Loongson/LoongArchQemuPkg/Library/Reset= SystemAcpiLib/BaseResetSystemAcpiGed.c new file mode 100644 index 0000000000..a50672410b --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/BaseRes= etSystemAcpiGed.c @@ -0,0 +1,155 @@ +/** @file + Base ResetSystem library implementation. + + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include "ResetSystemAcpiGed.h" +#include + +/** + Get configuration item data by the firmware configuration file name. + + @param[in] Name - Name of file to look up. + + @return VOID* The Pointer of Value of Firmware Configuration it= em read. + +**/ +VOID * +GetFwCfgData( +CONST CHAR8 *Name +) +{ + FIRMWARE_CONFIG_ITEM FwCfgItem; + EFI_STATUS Status; + UINTN FwCfgSize; + VOID *Data; + + Status =3D QemuFwCfgFindFile (Name, &FwCfgItem, &FwCfgSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a %d read %s error Status %d \n", __func__, __= LINE__, Name, Status)); + return NULL; + } + + Data =3D AllocatePool (FwCfgSize); + if (Data =3D=3D NULL) { + return NULL; + } + + QemuFwCfgSelectItem (FwCfgItem); + QemuFwCfgReadBytes (FwCfgSize, Data); + + return Data; +} + +/** + Find the power manager related info from ACPI table + + + @retval RETURN_SUCCESS Successfully find out all the required inform= ation. + @retval RETURN_NOT_FOUND Failed to find the required info. + +**/ +STATIC EFI_STATUS +GetPowerManagerByParseAcpiInfo (VOID) +{ + EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt =3D NULL; + EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp =3D NULL; + EFI_ACPI_DESCRIPTION_HEADER *Xsdt =3D NULL; + EFI_ACPI_DESCRIPTION_HEADER *Rsdt =3D NULL; + VOID *AcpiTables =3D NULL; + UINT32 *Entry32 =3D NULL; + UINTN Entry32Num; + UINT32 *Signature =3D NULL; + UINTN Idx; + + Rsdp =3D GetFwCfgData ("etc/acpi/rsdp"); + if (Rsdp =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a %d read etc/acpi/rsdp error \n", __func__, __= LINE__)); + return RETURN_NOT_FOUND; + } + + AcpiTables =3D GetFwCfgData ("etc/acpi/tables"); + if (AcpiTables =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a %d read etc/acpi/tables error \n", __func__, = __LINE__)); + FreePool (Rsdp); + return RETURN_NOT_FOUND; + } + + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)AcpiTables + Rsdp->Rsdt= Address); + Entry32 =3D (UINT32 *)(Rsdt + 1); + Entry32Num =3D (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> = 2; + for (Idx =3D 0; Idx < Entry32Num; Idx++) { + Signature =3D (UINT32 *)((UINTN)Entry32[Idx] + (UINTN)AcpiTables); + if (*Signature =3D=3D EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNAT= URE) { + Fadt =3D (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Signature; + DEBUG ((DEBUG_INFO, "Found Fadt in Rsdt\n")); + goto Done; + } + } + + + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)AcpiTables + Rsdp->Xsdt= Address); + Entry32 =3D (UINT32 *)(Xsdt + 1); + Entry32Num =3D (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> = 2; + for (Idx =3D 0; Idx < Entry32Num; Idx++) { + Signature =3D (UINT32 *)((UINTN)Entry32[Idx] + (UINTN)AcpiTables); + if (*Signature =3D=3D EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNAT= URE) { + Fadt =3D (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Signature; + DEBUG ((DEBUG_INFO, "Found Fadt in Xsdt\n")); + goto Done; + } + } + + + FreePool (Rsdp); + FreePool (AcpiTables); + DEBUG ((DEBUG_ERROR, " Fadt Not Found\n")); + return RETURN_NOT_FOUND; + +Done: + + mPowerManager.ResetRegAddr =3D Fadt->ResetReg.Address; + mPowerManager.ResetValue =3D Fadt->ResetValue; + mPowerManager.SleepControlRegAddr =3D Fadt->SleepControlReg.Address; + mPowerManager.SleepStatusRegAddr =3D Fadt->SleepStatusReg.Address; + + FreePool (Rsdp); + FreePool (AcpiTables); + + return RETURN_SUCCESS; +} + +/** + The constructor function to initialize mPowerManager. + + @retval EFI_SUCCESS initialize mPowerManager success. + @retval RETURN_NOT_FOUND Failed to initialize mPowerManager. + +**/ +EFI_STATUS +ResetSystemLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status =3D GetPowerManagerByParseAcpiInfo (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a:%d\n", __FUNCTION__, __LINE__)); + } + + ASSERT (mPowerManager.SleepControlRegAddr); + ASSERT (mPowerManager.SleepStatusRegAddr); + ASSERT (mPowerManager.ResetRegAddr); + + return Status; +} diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= BaseResetSystemAcpiGedLib.inf b/Platform/Loongson/LoongArchQemuPkg/Library/= ResetSystemAcpiLib/BaseResetSystemAcpiGedLib.inf new file mode 100644 index 0000000000..2336732e35 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/BaseRes= etSystemAcpiGedLib.inf @@ -0,0 +1,42 @@ +## @file +# Base library instance for ResetSystem library class for loongarhch +# +# Copyright (c) 2021 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D ResetSystemLib + FILE_GUID =3D 3d6faf60-804a-4ca9-a36a-1a92416919d0 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ResetSystemLib|SEC PEI_CORE PEIM DXE_= CORE + CONSTRUCTOR =3D ResetSystemLibConstructor + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + BaseResetSystemAcpiGed.c + ResetSystemAcpiGed.c + + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + QemuFwCfgLib + MemoryAllocationLib + IoLib + diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= DxeResetSystemAcpiGed.c b/Platform/Loongson/LoongArchQemuPkg/Library/ResetS= ystemAcpiLib/DxeResetSystemAcpiGed.c new file mode 100644 index 0000000000..7d2aea53f4 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/DxeRese= tSystemAcpiGed.c @@ -0,0 +1,270 @@ +/** @file + Dxe ResetSystem library implementation. + + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include // EfiConvertPointer() +#include +#include +#include "ResetSystemAcpiGed.h" +#include + +/** + Modifies the attributes to Runtime type for a page size memory region. + + @param BaseAddress Specified start address + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_INVALID_PARAMETER Length is zero. + @retval EFI_UNSUPPORTED The processor does not support one or more= bytes of the memory + resource range specified by BaseAddress an= d Length. + @retval EFI_UNSUPPORTED The bit mask of attributes is not support = for the memory resource + range specified by BaseAddress and Length. + @retval EFI_ACCESS_DEFINED The attributes for the memory resource ran= ge specified by + BaseAddress and Length cannot be modified. + @retval EFI_OUT_OF_RESOURCES There are not enough system resources to m= odify the attributes of + the memory resource range. + @retval EFI_NOT_AVAILABLE_YET The attributes cannot be set because CPU a= rchitectural protocol is + not available yet. + +**/ +EFI_STATUS +SetMemoryAttributesRunTime ( + UINTN Address + ) +{ + EFI_STATUS Status; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor; + + Address &=3D ~EFI_PAGE_MASK; + + Status =3D gDS->GetMemorySpaceDescriptor (Address, &Descriptor); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: GetMemorySpaceDescriptor failed\n", __FUNCTIO= N__)); + return Status; + } + + if (Descriptor.GcdMemoryType =3D=3D EfiGcdMemoryTypeNonExistent) { + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypeMemoryMappedIo, + Address, + EFI_PAGE_SIZE, + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: AddMemorySpace failed\n", __FUNCTION__)); + return Status; + } + + Status =3D gDS->SetMemorySpaceAttributes ( + Address, + EFI_PAGE_SIZE, + EFI_MEMORY_RUNTIME + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a:%d SetMemorySpaceAttributes failed\n", __FUN= CTION__, __LINE__)); + return Status; + } + } else if (!(Descriptor.Attributes & EFI_MEMORY_RUNTIME)) { + Status =3D gDS->SetMemorySpaceAttributes ( + Address, + EFI_PAGE_SIZE, + Descriptor.Attributes | EFI_MEMORY_RUNTIME + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a:%d SetMemorySpaceAttributes failed\n", __FUN= CTION__, __LINE__)); + return Status; + } + } + + return EFI_SUCCESS; +} + +/** + Find the power manager related info from ACPI table + + + @retval RETURN_SUCCESS Successfully find out all the required inform= ation. + @retval RETURN_NOT_FOUND Failed to find the required info. + +**/ +STATIC EFI_STATUS +GetPowerManagerByParseAcpiInfo ( + VOID +) +{ + EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt =3D NULL; + EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp =3D NULL; + EFI_ACPI_DESCRIPTION_HEADER *Xsdt =3D NULL; + EFI_ACPI_DESCRIPTION_HEADER *Rsdt =3D NULL; + UINT32 *Entry32 =3D NULL; + UINTN Entry32Num; + UINT32 *Signature =3D NULL; + UINTN Idx; + EFI_STATUS Status; + + Status =3D EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **)= &Rsdp); + if (EFI_ERROR (Status)) { + Status =3D EfiGetSystemConfigurationTable (&gEfiAcpi10TableGuid, (VOID= **)&Rsdp); + } + + if (EFI_ERROR (Status) || (Rsdp =3D=3D NULL)) { + DEBUG ((DEBUG_ERROR, "EFI_ERROR or Rsdp =3D=3D NULL\n")); + return RETURN_NOT_FOUND; + } + + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress; + Entry32 =3D (UINT32 *)(UINTN)(Rsdt + 1); + Entry32Num =3D (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> = 2; + for (Idx =3D 0; Idx < Entry32Num; Idx++) { + Signature =3D (UINT32 *)(UINTN)Entry32[Idx]; + if (*Signature =3D=3D EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNAT= URE) { + Fadt =3D (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Signature; + DEBUG ((DEBUG_INFO, "Found Fadt in Rsdt\n")); + goto Done; + } + } + + + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)Rsdp->XsdtAddress; + Entry32 =3D (UINT32 *)(Xsdt + 1); + Entry32Num =3D (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> = 2; + for (Idx =3D 0; Idx < Entry32Num; Idx++) { + Signature =3D (UINT32 *)(UINTN)Entry32[Idx]; + if (*Signature =3D=3D EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNAT= URE) { + Fadt =3D (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Signature; + DEBUG ((DEBUG_INFO, "Found Fadt in Xsdt\n")); + goto Done; + } + } + + + DEBUG ((DEBUG_ERROR, " Fadt Not Found\n")); + return RETURN_NOT_FOUND; + +Done: + + mPowerManager.ResetRegAddr =3D Fadt->ResetReg.Address; + mPowerManager.ResetValue =3D Fadt->ResetValue; + mPowerManager.SleepControlRegAddr =3D Fadt->SleepControlReg.Address; + mPowerManager.SleepStatusRegAddr =3D Fadt->SleepStatusReg.Address; + + return RETURN_SUCCESS; + +} + +/** + This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS= _CHANGE + event. It converts a pointer to a new virtual address. + + @param[in] Event Event whose notification function is being invok= ed. + @param[in] Context Pointer to the notification function's context +**/ +VOID +EFIAPI +ResetSystemLibAddressChangeEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EfiConvertPointer (0, (VOID **)&mPowerManager.SleepControlRegAddr); + EfiConvertPointer (0, (VOID **)&mPowerManager.SleepStatusRegAddr); + EfiConvertPointer (0, (VOID **)&mPowerManager.ResetRegAddr); +} + +/** + Notification function of ACPI Table change. + + This is a notification function registered on ACPI Table change event. + It saves the Century address stored in ACPI FADT table. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context. + +**/ +STATIC VOID +AcpiNotificationEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + Status =3D GetPowerManagerByParseAcpiInfo (); + if (EFI_ERROR (Status)) { + return ; + } + + DEBUG ((DEBUG_INFO, "%a: sleepControl %llx\n", __FUNCTION__, mPowerManag= er.SleepControlRegAddr)); + ASSERT (mPowerManager.SleepControlRegAddr); + Status =3D SetMemoryAttributesRunTime (mPowerManager.SleepControlRegAdd= r); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a:%d\n", __FUNCTION__, __LINE__)); + return ; + } + + DEBUG ((DEBUG_INFO, "%a: sleepStatus %llx\n", __FUNCTION__, mPowerManage= r.SleepStatusRegAddr)); + ASSERT (mPowerManager.SleepStatusRegAddr); + Status =3D SetMemoryAttributesRunTime (mPowerManager.SleepStatusRegAddr= ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a:%d\n", __FUNCTION__, __LINE__)); + return ; + } + + DEBUG ((DEBUG_INFO, "%a: ResetReg %llx\n", __FUNCTION__, mPowerManager.R= esetRegAddr)); + ASSERT (mPowerManager.ResetRegAddr); + Status =3D SetMemoryAttributesRunTime (mPowerManager.ResetRegAddr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a:%d\n", __FUNCTION__, __LINE__)); + } + + return ; +} + +/** + The constructor function to Register ACPI Table change event and Address= Change Event. + + @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +ResetSystemLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT Event; + EFI_EVENT ResetSystemVirtualNotifyEvent; + + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + AcpiNotificationEvent, + NULL, + &gEfiAcpiTableGuid, + &Event + ); + + // + // Register SetVirtualAddressMap () notify function + // + Status =3D gBS->CreateEvent ( + EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, + TPL_NOTIFY, + ResetSystemLibAddressChangeEvent, + NULL, + &ResetSystemVirtualNotifyEvent + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= DxeResetSystemAcpiGedLib.inf b/Platform/Loongson/LoongArchQemuPkg/Library/R= esetSystemAcpiLib/DxeResetSystemAcpiGedLib.inf new file mode 100644 index 0000000000..6ba78574b5 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/DxeRese= tSystemAcpiGedLib.inf @@ -0,0 +1,47 @@ +## @file +# DXE library instance for ResetSystem library class for loongarch. +# +# Copyright (c) 2021 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D ResetSystemLib + FILE_GUID =3D 3d6faf60-804a-4ca9-a36a-1a92416919d0 + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ResetSystemLib|DXE_DRIVER DXE_RUNTIME= _DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION + CONSTRUCTOR =3D ResetSystemLibConstructor + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + DxeResetSystemAcpiGed.c + ResetSystemAcpiGed.c + + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + DxeServicesTableLib + IoLib + UefiLib + +[Guids] + gEfiAcpi10TableGuid ## PRODUCES ## S= ystemTable + gEfiAcpiTableGuid ## PRODUCES ## S= ystemTable + + diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= ResetSystemAcpiGed.c b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSyst= emAcpiLib/ResetSystemAcpiGed.c new file mode 100644 index 0000000000..7f88269f13 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/ResetSy= stemAcpiGed.c @@ -0,0 +1,128 @@ +/** @file + ResetSystem library implementation. + + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include // CpuDeadLoop() +#include +#include // ResetCold() +#include +#include "ResetSystemAcpiGed.h" + +POWER_MANAGER mPowerManager; + +/** + Calling this function causes a system-wide reset. This sets + all circuitry within the system to its initial state. This type of reset + is asynchronous to system operation and operates without regard to + cycle boundaries. + + System reset should not return, if it returns, it means the system does + not support cold reset. +**/ +STATIC VOID +AcpiGedReset ( + VOID + ) +{ + MmioWrite8 ( + (UINTN)mPowerManager.ResetRegAddr, + mPowerManager.ResetValue + ); + + CpuDeadLoop (); +} + +/** + This function causes the system to enter a power state equivalent + to the ACPI S5 states. + + * */ +STATIC VOID +AcpiGedShutdown ( + VOID + ) +{ + MmioWrite8 ( + (UINTN)mPowerManager.SleepControlRegAddr, + (1 << 5) /* enable bit */ | + (5 << 2) /* typ =3D=3D S5 */ + ); + + 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 + ) +{ + AcpiGedReset (); +} + +/** + This function causes a system-wide initialization (warm reset), in which= all + processors are set to their initial state. Pending cycles are not corrup= ted. + + If this function returns, it means that the system does not support warm + reset. +**/ +VOID EFIAPI +ResetWarm ( + VOID + ) +{ + AcpiGedReset (); +} + +/** + 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 Reset= Data + 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 str= ing, + followed by the EFI_GUID. +**/ +VOID +EFIAPI +ResetPlatformSpecific ( + IN UINTN DataSize, + IN VOID *ResetData + ) +{ + AcpiGedReset (); +} + +/** + 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 shut= down + reset. +**/ +VOID EFIAPI +ResetShutdown ( + VOID + ) +{ + AcpiGedShutdown (); +} diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= ResetSystemAcpiGed.h b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSyst= emAcpiLib/ResetSystemAcpiGed.h new file mode 100644 index 0000000000..08288da1e8 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/ResetSy= stemAcpiGed.h @@ -0,0 +1,20 @@ +/** @file + ResetSystem lib head file. + + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +typedef struct { + UINT64 SleepControlRegAddr; + UINT64 SleepStatusRegAddr; + UINT64 ResetRegAddr; + UINT8 ResetValue; +} POWER_MANAGER; + +extern POWER_MANAGER mPowerManager; + --=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 (#93903): https://edk2.groups.io/g/devel/message/93903 Mute This Topic: https://groups.io/mt/93715822/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-