From nobody Tue Feb 10 11:15:42 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+96254+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+96254+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1668155153; cv=none; d=zohomail.com; s=zohoarc; b=LOcCXqwL1LhrquO3lW6rH2VX+IIubKIh+gDAa7jEIlpjgruknyW84tieQgtrzl4hFylclY/++sEiwMnaTcVjbX/E5nlFeZOjXHN4+h1arTpo+87v+9fgmA/fxsG9P6euLpU/3vEujB8yGPeTkdanSMVGnRhxUvOKr+04bmZ0+xc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668155153; 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=4NGQMYNU5Ay4tRTuf2LsVTfCaKdf6n2i1RQ1SNleuhk=; b=jpPHShPIIwCvSml3+GV62dkYxIUtmIAy6ZCJC4OXDkz6sRwAUaspkxmj8r8sk9gxwK9uKjPqGLiKcboLm19mDggjVCpwJ5e8aw3cy/ntRmbjsiTas6RXPlCetQuDXpCIdWT5qyyDW0/8JZo6lPAusxmD04eVmtR9iAQQVuOXdGQ= 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+96254+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1668155153052591.168977354936; Fri, 11 Nov 2022 00:25:53 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id vAlyYY1788612xAGU0wz3Ruy; Fri, 11 Nov 2022 00:25:51 -0800 X-Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web12.3349.1668155150094739929 for ; Fri, 11 Nov 2022 00:25:50 -0800 X-Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8DxPdkMB25jew8GAA--.18932S3; Fri, 11 Nov 2022 16:25:48 +0800 (CST) X-Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxiFcGB25jisUQAA--.27843S5; Fri, 11 Nov 2022 16:25:47 +0800 (CST) From: "xianglai" To: devel@edk2.groups.io Cc: Bibo Mao , Chao Li , Leif Lindholm , Liming Gao , Michael D Kinney Subject: [edk2-devel] [edk2-platforms][PATCH V5 03/15] Platform/Loongson: Add PeiServicesTablePointerLib. Date: Fri, 11 Nov 2022 16:25:09 +0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxiFcGB25jisUQAA--.27843S5 X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBjvJXoW3ArWrWF4DuFyDJrWkXF15XFb_yoW3WFWkpr 43WFs7tr1UJrWIgryYqa15CFW5AFsrCr98Crs7XF1rC34kZry0qryjvFWFkFyrua45Aw1I gryFkw4Uu3WUXF7anT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bn8Fc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4 AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF 7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7 CjxVAFwI0_Cr1j6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E 6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6x8ErcxFaVAv8VWrMcvjeVCFs4IE7x kEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv 6cx26rWl4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42 xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF 7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvj4RC_MaUUUUU 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: ijaGtOXNhBcQZpwmAPniBZR2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1668155151; bh=LDpml15K5ngpeCmSKZsy+vQqGQB2z5X9+zueLEvJmm0=; h=Cc:Date:From:Reply-To:Subject:To; b=A8hrYjYh1Kv8gZ5qACI5nAPYMi0/vCZKBGm+EXfe2zNlOZ9l+FhGZbBttttzGF4uWGb 7egxsd0ZXCyYTbsN6nIBAtnPYERO6uF1vQsD8a8/eHaYw2P4ErUAPPg2x+zpdxgVTrix9 3AUrjkwbTa0YbpcMwXiabde93Bv51P44qw4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1668155154961100003 Content-Type: text/plain; charset="utf-8" Use a register to save PeiServicesTable pointer, This lib Provides PeiServicesTable pointer saving and retrieval services. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4054 Cc: Bibo Mao Cc: Chao Li Cc: Leif Lindholm Cc: Liming Gao Cc: Michael D Kinney Signed-off-by: xianglai li --- .../PeiServicesTablePointer.c | 79 +++++++++++++++++++ .../PeiServicesTablePointer.h | 39 +++++++++ .../PeiServicesTablePointerLib.S | 40 ++++++++++ .../PeiServicesTablePointerLib.inf | 32 ++++++++ 4 files changed, 190 insertions(+) create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesT= ablePointerLib/PeiServicesTablePointer.c create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesT= ablePointerLib/PeiServicesTablePointer.h create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesT= ablePointerLib/PeiServicesTablePointerLib.S create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesT= ablePointerLib/PeiServicesTablePointerLib.inf diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePoi= nterLib/PeiServicesTablePointer.c b/Platform/Loongson/LoongArchQemuPkg/Libr= ary/PeiServicesTablePointerLib/PeiServicesTablePointer.c new file mode 100644 index 0000000000..204def3bde --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePointerLib= /PeiServicesTablePointer.c @@ -0,0 +1,79 @@ +/** @file + PEI Services Table Pointer Library. + + Copyright (c) 2022 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include "Library/Cpu.h" +#include "PeiServicesTablePointer.h" + +/** + Caches a pointer PEI Services Table. + + Caches the pointer to the PEI Services Table specified by PeiServicesTab= lePointer + in a platform specific manner. + + If PeiServicesTablePointer is NULL, then ASSERT (). + + @param PeiServicesTablePointer The address of PeiServices pointer. +**/ +VOID +EFIAPI +SetPeiServicesTablePointer ( + IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer + ) +{ + LoongarchWriteqKs0 ((UINTN)PeiServicesTablePointer); +} + +/** + Retrieves the cached value of the PEI Services Table pointer. + + Returns the cached value of the PEI Services Table pointer in a CPU spec= ific manner + as specified in the CPU binding section of the Platform Initialization P= re-EFI + Initialization Core Interface Specification. + + If the cached PEI Services Table pointer is NULL, then ASSERT (). + + @return The pointer to PeiServices. +**/ +CONST EFI_PEI_SERVICES ** +EFIAPI +GetPeiServicesTablePointer ( + VOID + ) +{ + UINTN val; + + LoongarchReadqKs0 (&val); + + return (CONST EFI_PEI_SERVICES **)val; +} + +/** +Perform CPU specific actions required to migrate the PEI Services Table +pointer from temporary RAM to permanent RAM. + +For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes +immediately preceding the Interrupt Descriptor Table (IDT) in memory. +For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes +immediately preceding the Interrupt Descriptor Table (IDT) in memory. +For Itanium and ARM CPUs, a the PEI Services Table Pointer is stored in +a dedicated CPU register. This means that there is no memory storage +associated with storing the PEI Services Table pointer, so no additional +migration actions are required for Itanium or ARM CPUs. +*/ +VOID +EFIAPI +MigratePeiServicesTablePointer ( +VOID +) +{ + return; +} diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePoi= nterLib/PeiServicesTablePointer.h b/Platform/Loongson/LoongArchQemuPkg/Libr= ary/PeiServicesTablePointerLib/PeiServicesTablePointer.h new file mode 100644 index 0000000000..5bcbc810d0 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePointerLib= /PeiServicesTablePointer.h @@ -0,0 +1,39 @@ +/** @file + PeiServicesTablePointer + + Copyright (c) 2022 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PEISERVICESTABLEPOINTER_H_ +#define PEISERVICESTABLEPOINTER_H_ + +/** + Write Csr KS0 register. + + @param A0 The value used to write to the KS0 register + + @retval none +**/ +extern +VOID +LoongarchWriteqKs0 ( + IN UINT64 Val + ); + +/** + Read Csr KS0 register. + + @param Val Pointer to the variable used to store the KS0 register value + + @retval none +**/ +extern +VOID +LoongarchReadqKs0 ( + IN UINT64 *Val + ); + +#endif // PEISERVICESTABLEPOINTER_H_ diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePoi= nterLib/PeiServicesTablePointerLib.S b/Platform/Loongson/LoongArchQemuPkg/L= ibrary/PeiServicesTablePointerLib/PeiServicesTablePointerLib.S new file mode 100644 index 0000000000..7c6170c5d6 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePointerLib= /PeiServicesTablePointerLib.S @@ -0,0 +1,40 @@ +#-------------------------------------------------------------------------= ----- +# +# Timer Cfg for LoongArch +# +# Copyright (c) 2022 Loongson Technology Corporation Limited. All rights r= eserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- + +#ifndef __ASSEMBLY__ +#define __ASSEMBLY__ +#endif + +#include "Library/Cpu.h" + +ASM_GLOBAL ASM_PFX(LoongarchWriteqKs0) +ASM_GLOBAL ASM_PFX(LoongarchReadqKs0) + +# +# Write Csr KS0 register. +# @param A0 The value used to write to the KS0 register +# @retval none +# + +ASM_PFX(LoongarchWriteqKs0): + csrwr A0, LOONGARCH_CSR_KS0 + jirl ZERO, RA,0 + +# +# Write Csr KS0 register. +# @param A0 Pointer to the variable used to store the KS0 register value +# @retval none +# + +ASM_PFX(LoongarchReadqKs0): + csrrd T0, LOONGARCH_CSR_KS0 + stptr.d T0, A0, 0 + jirl ZERO, RA,0 + jirl ZERO, RA,0 diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePoi= nterLib/PeiServicesTablePointerLib.inf b/Platform/Loongson/LoongArchQemuPkg= /Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf new file mode 100644 index 0000000000..2ab0d53d4c --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePointerLib= /PeiServicesTablePointerLib.inf @@ -0,0 +1,32 @@ +## @file +# PEI Services Table Pointer Library. +# +# Copyright (c) 2022 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PeiServicesTablePointerLib + FILE_GUID =3D C3C9C4ED-EB8A-4548-BE1B-ABB0B6F35B1E + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PeiServicesTablePointerLib|PEIM PEI_C= ORE SEC + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources] + PeiServicesTablePointer.c + PeiServicesTablePointerLib.S + +[Packages] + Platform/Loongson/LoongArchQemuPkg/Loongson.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib + +[Pcd] --=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 (#96254): https://edk2.groups.io/g/devel/message/96254 Mute This Topic: https://groups.io/mt/94954833/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-