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.web10.3567.1668157966596114244 for ; Fri, 11 Nov 2022 01:12:47 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: loongson.cn, ip: 114.242.206.163, mailfrom: lixianglai@loongson.cn) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxDdkMEm5jqhMGAA--.18781S3; Fri, 11 Nov 2022 17:12:44 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxFlcAEm5jXc0QAA--.27651S15; Fri, 11 Nov 2022 17:12:44 +0800 (CST) From: "xianglai" To: devel@edk2.groups.io Cc: Bibo Mao , Chao Li , Leif Lindholm , Liming Gao , Michael D Kinney Subject: [edk2-platforms][PATCH V5 13/15] Platform/Loongson: Add Reset System Lib. Date: Fri, 11 Nov 2022 17:12:28 +0800 Message-Id: <90ac987751d215263e4c4a4d8c27652b5dc52981.1668157715.git.lixianglai@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxFlcAEm5jXc0QAA--.27651S15 X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBjvAXoWftr1fCw13ZF18ZrWxJFy7Wrg_yoW8tr1xuo W2gan7t3y8Jrs5u3yxWrn3GF4IqFsYq398ZF1rJFWDJrWDZr109FWkXa48JF9aqF15XF45 GayfJ3yrJrZIgF4kn29KB7ZKAUJUUUU3529EdanIXcx71UUUUU7KY7ZEXasCq-sGcSsGvf J3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnRJU UUkC1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64 kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY 1x0267AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6x kF7I0E14v26F4UJVW0owAaw2AFwI0_JF0_Jw1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAq jxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E74AGY7Cv6c x26rWlOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r12 6r1DMxAIw28IcxkI7VAKI48JMxAIw28IcVCjz48v1sIEY20_WwCFx2IqxVCFs4IE7xkEbV WUJVW8JwCFI7km07C267AKxVWUAVWUtwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVW7JVWDJwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvj4RKpBTUUUUU Content-Transfer-Encoding: quoted-printable This library provides interfaces related to restart and shutdown.=0D =0D REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4054=0D =0D Cc: Bibo Mao =0D Cc: Chao Li =0D Cc: Leif Lindholm =0D Cc: Liming Gao =0D Cc: Michael D Kinney =0D Signed-off-by: xianglai li =0D ---=0D .../BaseResetSystemAcpiGed.c | 146 ++++++++++=0D .../BaseResetSystemAcpiGedLib.inf | 37 +++=0D .../DxeResetSystemAcpiGed.c | 257 ++++++++++++++++++=0D .../DxeResetSystemAcpiGedLib.inf | 41 +++=0D .../ResetSystemAcpiLib/ResetSystemAcpiGed.c | 128 +++++++++=0D .../ResetSystemAcpiLib/ResetSystemAcpiGed.h | 23 ++=0D 6 files changed, 632 insertions(+)=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/BaseResetSystemAcpiGed.c=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/BaseResetSystemAcpiGedLib.inf=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/DxeResetSystemAcpiGed.c=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/DxeResetSystemAcpiGedLib.inf=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/ResetSystemAcpiGed.c=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemA= cpiLib/ResetSystemAcpiGed.h=0D =0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= BaseResetSystemAcpiGed.c b/Platform/Loongson/LoongArchQemuPkg/Library/Reset= SystemAcpiLib/BaseResetSystemAcpiGed.c=0D new file mode 100644=0D index 0000000000..0df629ffcd=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/BaseRes= etSystemAcpiGed.c=0D @@ -0,0 +1,146 @@=0D +/** @file=0D + Base ResetSystem library implementation.=0D +=0D + Copyright (c) 2022 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 "ResetSystemAcpiGed.h"=0D +#include =0D +=0D +/**=0D + Get configuration item data by the firmware configuration file name.=0D +=0D + @param[in] Name - Name of file to look up.=0D +=0D + @return VOID* The Pointer of Value of Firmware Configuration it= em read.=0D +**/=0D +VOID *=0D +GetFwCfgData(=0D +CONST CHAR8 *Name=0D +)=0D +{=0D + FIRMWARE_CONFIG_ITEM FwCfgItem;=0D + EFI_STATUS Status;=0D + UINTN FwCfgSize;=0D + VOID *Data;=0D +=0D + Status =3D QemuFwCfgFindFile (Name, &FwCfgItem, &FwCfgSize);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a %d read %s error Status %d \n", __func__, __= LINE__, Name, Status));=0D + return NULL;=0D + }=0D +=0D + Data =3D AllocatePool (FwCfgSize);=0D + if (Data =3D=3D NULL) {=0D + return NULL;=0D + }=0D +=0D + QemuFwCfgSelectItem (FwCfgItem);=0D + QemuFwCfgReadBytes (FwCfgSize, Data);=0D +=0D + return Data;=0D +}=0D +=0D +/**=0D + Find the power manager related info from ACPI table=0D +=0D + @retval RETURN_SUCCESS Successfully find out all the required inform= ation.=0D + @retval RETURN_NOT_FOUND Failed to find the required info.=0D +**/=0D +STATIC EFI_STATUS=0D +GetPowerManagerByParseAcpiInfo (VOID)=0D +{=0D + EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt =3D NULL;=0D + EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp =3D NULL;=0D + EFI_ACPI_DESCRIPTION_HEADER *Xsdt =3D NULL;=0D + EFI_ACPI_DESCRIPTION_HEADER *Rsdt =3D NULL;=0D + VOID *AcpiTables =3D NULL;=0D + UINT32 *Entry32 =3D NULL;=0D + UINTN Entry32Num;=0D + UINT32 *Signature =3D NULL;=0D + UINTN Idx;=0D +=0D + Rsdp =3D GetFwCfgData ("etc/acpi/rsdp");=0D + if (Rsdp =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "%a %d read etc/acpi/rsdp error \n", __func__, __= LINE__));=0D + return RETURN_NOT_FOUND;=0D + }=0D +=0D + AcpiTables =3D GetFwCfgData ("etc/acpi/tables");=0D + if (AcpiTables =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "%a %d read etc/acpi/tables error \n", __func__, = __LINE__));=0D + FreePool (Rsdp);=0D + return RETURN_NOT_FOUND;=0D + }=0D +=0D + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)AcpiTables + Rsdp->Rsdt= Address);=0D + Entry32 =3D (UINT32 *)(Rsdt + 1);=0D + Entry32Num =3D (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> = 2;=0D + for (Idx =3D 0; Idx < Entry32Num; Idx++) {=0D + Signature =3D (UINT32 *)((UINTN)Entry32[Idx] + (UINTN)AcpiTables);=0D + if (*Signature =3D=3D EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNAT= URE) {=0D + Fadt =3D (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Signature;=0D + DEBUG ((DEBUG_INFO, "Found Fadt in Rsdt\n"));=0D + goto Done;=0D + }=0D + }=0D +=0D + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)AcpiTables + Rsdp->Xsdt= Address);=0D + Entry32 =3D (UINT32 *)(Xsdt + 1);=0D + Entry32Num =3D (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> = 2;=0D + for (Idx =3D 0; Idx < Entry32Num; Idx++) {=0D + Signature =3D (UINT32 *)((UINTN)Entry32[Idx] + (UINTN)AcpiTables);=0D + if (*Signature =3D=3D EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNAT= URE) {=0D + Fadt =3D (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Signature;=0D + DEBUG ((DEBUG_INFO, "Found Fadt in Xsdt\n"));=0D + goto Done;=0D + }=0D + }=0D +=0D + FreePool (Rsdp);=0D + FreePool (AcpiTables);=0D + DEBUG ((DEBUG_ERROR, " Fadt Not Found\n"));=0D + return RETURN_NOT_FOUND;=0D +=0D +Done:=0D + mPowerManager.ResetRegAddr =3D Fadt->ResetReg.Address;=0D + mPowerManager.ResetValue =3D Fadt->ResetValue;=0D + mPowerManager.SleepControlRegAddr =3D Fadt->SleepControlReg.Address;=0D + mPowerManager.SleepStatusRegAddr =3D Fadt->SleepStatusReg.Address;=0D +=0D + FreePool (Rsdp);=0D + FreePool (AcpiTables);=0D + return RETURN_SUCCESS;=0D +}=0D +=0D +/**=0D + The constructor function to initialize mPowerManager.=0D +=0D + @retval EFI_SUCCESS initialize mPowerManager success.=0D + @retval RETURN_NOT_FOUND Failed to initialize mPowerManager.=0D +**/=0D +EFI_STATUS=0D +ResetSystemLibConstructor (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D GetPowerManagerByParseAcpiInfo ();=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_INFO, "%a:%d\n", __FUNCTION__, __LINE__));=0D + }=0D +=0D + ASSERT (mPowerManager.SleepControlRegAddr);=0D + ASSERT (mPowerManager.SleepStatusRegAddr);=0D + ASSERT (mPowerManager.ResetRegAddr);=0D + return Status;=0D +}=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= BaseResetSystemAcpiGedLib.inf b/Platform/Loongson/LoongArchQemuPkg/Library/= ResetSystemAcpiLib/BaseResetSystemAcpiGedLib.inf=0D new file mode 100644=0D index 0000000000..120dd7dcff=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/BaseRes= etSystemAcpiGedLib.inf=0D @@ -0,0 +1,37 @@=0D +## @file=0D +# Base library instance for ResetSystem library class for loongarhch=0D +#=0D +# Copyright (c) 2022 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 1.29=0D + BASE_NAME =3D ResetSystemLib=0D + FILE_GUID =3D 3d6faf60-804a-4ca9-a36a-1a92416919d0= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D ResetSystemLib|SEC PEI_CORE PEIM DXE_= CORE=0D + CONSTRUCTOR =3D ResetSystemLibConstructor=0D +=0D +#=0D +# VALID_ARCHITECTURES =3D LOONGARCH64=0D +#=0D +=0D +[Sources]=0D + BaseResetSystemAcpiGed.c=0D + ResetSystemAcpiGed.c=0D +=0D +[Packages]=0D + MdeModulePkg/MdeModulePkg.dec=0D + MdePkg/MdePkg.dec=0D + OvmfPkg/OvmfPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + DebugLib=0D + QemuFwCfgLib=0D + MemoryAllocationLib=0D + IoLib=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= DxeResetSystemAcpiGed.c b/Platform/Loongson/LoongArchQemuPkg/Library/ResetS= ystemAcpiLib/DxeResetSystemAcpiGed.c=0D new file mode 100644=0D index 0000000000..ef48946ae4=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/DxeRese= tSystemAcpiGed.c=0D @@ -0,0 +1,257 @@=0D +/** @file=0D + Dxe ResetSystem library implementation.=0D +=0D + Copyright (c) 2022 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 // EfiConvertPointer()=0D +#include =0D +#include =0D +#include "ResetSystemAcpiGed.h"=0D +#include =0D +=0D +/**=0D + Modifies the attributes to Runtime type for a page size memory region.=0D +=0D + @param BaseAddress Specified start address=0D +=0D + @retval EFI_SUCCESS The attributes were set for the memory reg= ion.=0D + @retval EFI_INVALID_PARAMETER Length is zero.=0D + @retval EFI_UNSUPPORTED The processor does not support one or more= bytes of the memory=0D + resource range specified by BaseAddress an= d Length.=0D + @retval EFI_UNSUPPORTED The bit mask of attributes is not support = for the memory resource=0D + range specified by BaseAddress and Length.= =0D + @retval EFI_ACCESS_DEFINED The attributes for the memory resource ran= ge specified by=0D + BaseAddress and Length cannot be modified.= =0D + @retval EFI_OUT_OF_RESOURCES There are not enough system resources to m= odify the attributes of=0D + the memory resource range.=0D + @retval EFI_NOT_AVAILABLE_YET The attributes cannot be set because CPU a= rchitectural protocol is=0D + not available yet.=0D +**/=0D +EFI_STATUS=0D +SetMemoryAttributesRunTime (=0D + UINTN Address=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;=0D +=0D + Address &=3D ~EFI_PAGE_MASK;=0D +=0D + Status =3D gDS->GetMemorySpaceDescriptor (Address, &Descriptor);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_INFO, "%a: GetMemorySpaceDescriptor failed\n", __FUNCTIO= N__));=0D + return Status;=0D + }=0D +=0D + if (Descriptor.GcdMemoryType =3D=3D EfiGcdMemoryTypeNonExistent) {=0D + Status =3D gDS->AddMemorySpace (=0D + EfiGcdMemoryTypeMemoryMappedIo,=0D + Address,=0D + EFI_PAGE_SIZE,=0D + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_INFO, "%a: AddMemorySpace failed\n", __FUNCTION__));=0D + return Status;=0D + }=0D +=0D + Status =3D gDS->SetMemorySpaceAttributes (=0D + Address,=0D + EFI_PAGE_SIZE,=0D + EFI_MEMORY_RUNTIME=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_INFO, "%a:%d SetMemorySpaceAttributes failed\n", __FUN= CTION__, __LINE__));=0D + return Status;=0D + }=0D + } else if (!(Descriptor.Attributes & EFI_MEMORY_RUNTIME)) {=0D + Status =3D gDS->SetMemorySpaceAttributes (=0D + Address,=0D + EFI_PAGE_SIZE,=0D + Descriptor.Attributes | EFI_MEMORY_RUNTIME=0D + );=0D +=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_INFO, "%a:%d SetMemorySpaceAttributes failed\n", __FUN= CTION__, __LINE__));=0D + return Status;=0D + }=0D + }=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + Find the power manager related info from ACPI table=0D +=0D + @retval RETURN_SUCCESS Successfully find out all the required inform= ation.=0D + @retval RETURN_NOT_FOUND Failed to find the required info.=0D +**/=0D +STATIC EFI_STATUS=0D +GetPowerManagerByParseAcpiInfo (=0D + VOID=0D +)=0D +{=0D + EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt =3D NULL;=0D + EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp =3D NULL;=0D + EFI_ACPI_DESCRIPTION_HEADER *Xsdt =3D NULL;=0D + EFI_ACPI_DESCRIPTION_HEADER *Rsdt =3D NULL;=0D + UINT32 *Entry32 =3D NULL;=0D + UINTN Entry32Num;=0D + UINT32 *Signature =3D NULL;=0D + UINTN Idx;=0D + EFI_STATUS Status;=0D +=0D + Status =3D EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **)= &Rsdp);=0D + if (EFI_ERROR (Status)) {=0D + Status =3D EfiGetSystemConfigurationTable (&gEfiAcpi10TableGuid, (VOID= **)&Rsdp);=0D + }=0D +=0D + if (EFI_ERROR (Status) || (Rsdp =3D=3D NULL)) {=0D + DEBUG ((DEBUG_ERROR, "EFI_ERROR or Rsdp =3D=3D NULL\n"));=0D + return RETURN_NOT_FOUND;=0D + }=0D +=0D + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress;=0D + Entry32 =3D (UINT32 *)(UINTN)(Rsdt + 1);=0D + Entry32Num =3D (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> = 2;=0D + for (Idx =3D 0; Idx < Entry32Num; Idx++) {=0D + Signature =3D (UINT32 *)(UINTN)Entry32[Idx];=0D + if (*Signature =3D=3D EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNAT= URE) {=0D + Fadt =3D (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Signature;=0D + DEBUG ((DEBUG_INFO, "Found Fadt in Rsdt\n"));=0D + goto Done;=0D + }=0D + }=0D +=0D + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)Rsdp->XsdtAddress;=0D + Entry32 =3D (UINT32 *)(Xsdt + 1);=0D + Entry32Num =3D (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> = 2;=0D + for (Idx =3D 0; Idx < Entry32Num; Idx++) {=0D + Signature =3D (UINT32 *)(UINTN)Entry32[Idx];=0D + if (*Signature =3D=3D EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNAT= URE) {=0D + Fadt =3D (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Signature;=0D + DEBUG ((DEBUG_INFO, "Found Fadt in Xsdt\n"));=0D + goto Done;=0D + }=0D + }=0D +=0D + DEBUG ((DEBUG_ERROR, " Fadt Not Found\n"));=0D + return RETURN_NOT_FOUND;=0D +=0D +Done:=0D + mPowerManager.ResetRegAddr =3D Fadt->ResetReg.Address;=0D + mPowerManager.ResetValue =3D Fadt->ResetValue;=0D + mPowerManager.SleepControlRegAddr =3D Fadt->SleepControlReg.Address;=0D + mPowerManager.SleepStatusRegAddr =3D Fadt->SleepStatusReg.Address;=0D + return RETURN_SUCCESS;=0D +}=0D +=0D +/**=0D + This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS= _CHANGE=0D + event. It converts a pointer to a new virtual address.=0D +=0D + @param[in] Event Event whose notification function is being invok= ed.=0D + @param[in] Context Pointer to the notification function's context=0D +**/=0D +VOID=0D +EFIAPI=0D +ResetSystemLibAddressChangeEvent (=0D + IN EFI_EVENT Event,=0D + IN VOID *Context=0D + )=0D +{=0D + EfiConvertPointer (0, (VOID **)&mPowerManager.SleepControlRegAddr);=0D + EfiConvertPointer (0, (VOID **)&mPowerManager.SleepStatusRegAddr);=0D + EfiConvertPointer (0, (VOID **)&mPowerManager.ResetRegAddr);=0D +}=0D +=0D +/**=0D + Notification function of ACPI Table change.=0D +=0D + This is a notification function registered on ACPI Table change event.=0D + It saves the Century address stored in ACPI FADT table.=0D +=0D + @param Event Event whose notification function is being invoked.= =0D + @param Context Pointer to the notification function's context.=0D +**/=0D +STATIC VOID=0D +AcpiNotificationEvent (=0D + IN EFI_EVENT Event,=0D + IN VOID *Context=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D GetPowerManagerByParseAcpiInfo ();=0D + if (EFI_ERROR (Status)) {=0D + return ;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "%a: sleepControl %llx\n", __FUNCTION__, mPowerManag= er.SleepControlRegAddr));=0D + ASSERT (mPowerManager.SleepControlRegAddr);=0D + Status =3D SetMemoryAttributesRunTime (mPowerManager.SleepControlRegAdd= r);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_INFO, "%a:%d\n", __FUNCTION__, __LINE__));=0D + return ;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "%a: sleepStatus %llx\n", __FUNCTION__, mPowerManage= r.SleepStatusRegAddr));=0D + ASSERT (mPowerManager.SleepStatusRegAddr);=0D + Status =3D SetMemoryAttributesRunTime (mPowerManager.SleepStatusRegAddr= );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_INFO, "%a:%d\n", __FUNCTION__, __LINE__));=0D + return ;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "%a: ResetReg %llx\n", __FUNCTION__, mPowerManager.R= esetRegAddr));=0D + ASSERT (mPowerManager.ResetRegAddr);=0D + Status =3D SetMemoryAttributesRunTime (mPowerManager.ResetRegAddr);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_INFO, "%a:%d\n", __FUNCTION__, __LINE__));=0D + }=0D + return ;=0D +}=0D +=0D +/**=0D + The constructor function to Register ACPI Table change event and Address= Change Event.=0D +=0D + @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +ResetSystemLibConstructor (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_EVENT Event;=0D + EFI_EVENT ResetSystemVirtualNotifyEvent;=0D +=0D + Status =3D gBS->CreateEventEx (=0D + EVT_NOTIFY_SIGNAL,=0D + TPL_CALLBACK,=0D + AcpiNotificationEvent,=0D + NULL,=0D + &gEfiAcpiTableGuid,=0D + &Event=0D + );=0D +=0D + //=0D + // Register SetVirtualAddressMap () notify function=0D + //=0D + Status =3D gBS->CreateEvent (=0D + EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,=0D + TPL_NOTIFY,=0D + ResetSystemLibAddressChangeEvent,=0D + NULL,=0D + &ResetSystemVirtualNotifyEvent=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D + return Status;=0D +}=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= DxeResetSystemAcpiGedLib.inf b/Platform/Loongson/LoongArchQemuPkg/Library/R= esetSystemAcpiLib/DxeResetSystemAcpiGedLib.inf=0D new file mode 100644=0D index 0000000000..48c7ea2dc3=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/DxeRese= tSystemAcpiGedLib.inf=0D @@ -0,0 +1,41 @@=0D +## @file=0D +# DXE library instance for ResetSystem library class for loongarch.=0D +#=0D +# Copyright (c) 2022 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 1.29=0D + BASE_NAME =3D ResetSystemLib=0D + FILE_GUID =3D 3d6faf60-804a-4ca9-a36a-1a92416919d0= =0D + MODULE_TYPE =3D DXE_RUNTIME_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D ResetSystemLib|DXE_DRIVER DXE_RUNTIME= _DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION=0D + CONSTRUCTOR =3D ResetSystemLibConstructor=0D +=0D +#=0D +# VALID_ARCHITECTURES =3D LOONGARCH64=0D +#=0D +=0D +[Sources]=0D + DxeResetSystemAcpiGed.c=0D + ResetSystemAcpiGed.c=0D +=0D +[Packages]=0D + MdeModulePkg/MdeModulePkg.dec=0D + MdePkg/MdePkg.dec=0D + OvmfPkg/OvmfPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + DebugLib=0D + DxeServicesTableLib=0D + IoLib=0D + UefiLib=0D +=0D +[Guids]=0D + gEfiAcpi10TableGuid ## PRODUCES ## S= ystemTable=0D + gEfiAcpiTableGuid ## PRODUCES ## S= ystemTable=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= ResetSystemAcpiGed.c b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSyst= emAcpiLib/ResetSystemAcpiGed.c=0D new file mode 100644=0D index 0000000000..d15cc70b4b=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/ResetSy= stemAcpiGed.c=0D @@ -0,0 +1,128 @@=0D +/** @file=0D + ResetSystem library implementation.=0D +=0D + Copyright (c) 2022 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 // CpuDeadLoop()=0D +#include =0D +#include // ResetCold()=0D +#include =0D +#include "ResetSystemAcpiGed.h"=0D +=0D +POWER_MANAGER mPowerManager;=0D +=0D +/**=0D + Calling this function causes a system-wide reset. This sets=0D + all circuitry within the system to its initial state. This type of reset= =0D + is asynchronous to system operation and operates without regard to=0D + cycle boundaries.=0D +=0D + System reset should not return, if it returns, it means the system does= =0D + not support cold reset.=0D +**/=0D +STATIC VOID=0D +AcpiGedReset (=0D + VOID=0D + )=0D +{=0D + MmioWrite8 (=0D + (UINTN)mPowerManager.ResetRegAddr,=0D + mPowerManager.ResetValue=0D + );=0D +=0D + CpuDeadLoop ();=0D +}=0D +=0D +/**=0D + This function causes the system to enter a power state equivalent=0D + to the ACPI S5 states.=0D +=0D + * */=0D +STATIC VOID=0D +AcpiGedShutdown (=0D + VOID=0D + )=0D +{=0D + MmioWrite8 (=0D + (UINTN)mPowerManager.SleepControlRegAddr,=0D + (1 << 5) /* enable bit */ |=0D + (5 << 2) /* typ =3D=3D S5 */=0D + );=0D +=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 = of=0D + reset 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= =0D + reset.=0D +**/=0D +VOID EFIAPI=0D +ResetCold (=0D + VOID=0D + )=0D +{=0D + AcpiGedReset ();=0D +}=0D +=0D +/**=0D + This function causes a system-wide initialization (warm reset), in which= all=0D + processors are set to their initial state. Pending cycles are not corrup= ted.=0D +=0D + If this function returns, it means that the system does not support warm= =0D + reset.=0D +**/=0D +VOID EFIAPI=0D +ResetWarm (=0D + VOID=0D + )=0D +{=0D + AcpiGedReset ();=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 = passed=0D + into ResetData. If the platform does not recognize the EFI_GUID in Reset= Data=0D + the platform must pick a supported reset type to perform.The platform ma= y=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 str= ing,=0D + followed by the EFI_GUID.=0D +**/=0D +VOID=0D +EFIAPI=0D +ResetPlatformSpecific (=0D + IN UINTN DataSize,=0D + IN VOID *ResetData=0D + )=0D +{=0D + AcpiGedReset ();=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 shut= down=0D + reset.=0D +**/=0D +VOID EFIAPI=0D +ResetShutdown (=0D + VOID=0D + )=0D +{=0D + AcpiGedShutdown ();=0D +}=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/= ResetSystemAcpiGed.h b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSyst= emAcpiLib/ResetSystemAcpiGed.h=0D new file mode 100644=0D index 0000000000..e504e870f9=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/Library/ResetSystemAcpiLib/ResetSy= stemAcpiGed.h=0D @@ -0,0 +1,23 @@=0D +/** @file=0D + ResetSystem lib head file.=0D +=0D + Copyright (c) 2022 Loongson Technology Corporation Limited. All rights r= eserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef RESET_SYSTEM_ACPI_GED_H_=0D +#define RESET_SYSTEM_ACPI_GED_H_=0D +=0D +#include =0D +=0D +typedef struct {=0D + UINT64 SleepControlRegAddr;=0D + UINT64 SleepStatusRegAddr;=0D + UINT64 ResetRegAddr;=0D + UINT8 ResetValue;=0D +} POWER_MANAGER;=0D +=0D +extern POWER_MANAGER mPowerManager;=0D +#endif // RESET_SYSTEM_ACPI_GED_H_=0D -- =0D 2.31.1=0D =0D