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.web11.6319.1668652800602856745 for ; Wed, 16 Nov 2022 18:40:01 -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 _____8Bxnrf+nnVj9yMIAA--.18461S3; Thu, 17 Nov 2022 10:39:58 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxLeD5nnVjCpcVAA--.56818S5; Thu, 17 Nov 2022 10:39:57 +0800 (CST) From: "xianglai" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Bibo Mao , Chao Li , Leif Lindholm , Liming Gao , Michael D Kinney Subject: [edk2-platforms][PATCH V6 03/16] Platform/Loongson: Add PeiServicesTablePointerLib. Date: Thu, 17 Nov 2022 10:39:29 +0800 Message-Id: <066fe5aa785feb712a3cc00f94328f46bfa8ebe6.1668652102.git.lixianglai@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxLeD5nnVjCpcVAA--.56818S5 X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBjvJXoW3Gr1ftr17CF47Ar17KryDJrb_yoW3AFyUpr 43WFs7Kr1UJrWIgryYqa15CFW5AFsrCr98Crs7XF1rC34kZry0qryjvFWFkFyrua45Aw1I gryFkw4Uu3WUXF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bnxFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4 AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF 7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7 CjxVAFwI0_Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2 zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VCjz48v1sIEY20_WwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l42xK82IY6x8ErcxF aVAv8VWrMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxV Cjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY 6xIIjxv20xvE14v26r4j6ryUMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6x AIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY 1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7xRE6wZ7UUUUU== Content-Transfer-Encoding: 8bit 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=4054 Cc: Ard Biesheuvel Cc: Bibo Mao Cc: Chao Li Cc: Leif Lindholm Cc: Liming Gao Cc: Michael D Kinney Signed-off-by: xianglai li Reviewed-by: Chao 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/PeiServicesTablePointerLib/PeiServicesTablePointer.c create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.h create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.S create mode 100644 Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c b/Platform/Loongson/LoongArchQemuPkg/Library/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 reserved.
+ + 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 PeiServicesTablePointer + 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 specific manner + as specified in the CPU binding section of the Platform Initialization Pre-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/PeiServicesTablePointerLib/PeiServicesTablePointer.h b/Platform/Loongson/LoongArchQemuPkg/Library/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 reserved.
+ + 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/PeiServicesTablePointerLib/PeiServicesTablePointerLib.S b/Platform/Loongson/LoongArchQemuPkg/Library/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 reserved.
+# +# 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/PeiServicesTablePointerLib/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 = 0x00010005 + BASE_NAME = PeiServicesTablePointerLib + FILE_GUID = C3C9C4ED-EB8A-4548-BE1B-ABB0B6F35B1E + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = PeiServicesTablePointerLib|PEIM PEI_CORE SEC + +# +# VALID_ARCHITECTURES = LOONGARCH64 +# + +[Sources] + PeiServicesTablePointer.c + PeiServicesTablePointerLib.S + +[Packages] + Platform/Loongson/LoongArchQemuPkg/Loongson.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib + +[Pcd] -- 2.31.1