From nobody Thu Dec 26 20:24:45 2024 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+114527+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+114527+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250496; cv=none; d=zohomail.com; s=zohoarc; b=IQic3fAf9WbSwLP3r/qbLTt8XHBIQypZapoZsmWhAZf2h53zzTlYXYxbvk5zLr8XkusbEs3xCztIZ+zNv30aI4GZowV0cqtgk8+nG6QCPgo2loHDz3dY0tzNdLr9UtHeVHbDY2dIsc/rL3q4TgmePdhEr0HOjeO6MMYTPesFgD8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250496; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=4RNMkiPbnMVqlgLVqSZWdNAlYBJfBWeXayKfUw2f778=; b=SXc/KACaS9yVhvj629Lc7R/RHfxiMCCHhvYdJF3H/U271nHobVYxdzHIfVffcjO+Nkcp0/XzHUk0wJPGVaSArCO1nBdq5rC8VhxKbBp76aj/EIa7J+KJ5SpOfrgUC//x4Q/+TJE7AzcsmJ1cUVSjj7xMamZKMl/mzlBUlIxEKDk= 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+114527+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250496113814.9473005198846; Thu, 25 Jan 2024 22:28:16 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=VVBVJlf7Yy0gyS1xzgcdehK8TPmUO03Fbtu6K6GtNpw=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250495; v=1; b=Pkd8HpAD630xadu5GXPugY9VDq9hx0oSpd2xNITbMsOByTl3dqvk3C5vEcr8MZy5S91nJMsE aRf3tzBXC+fi8oED5dNsDqTbVHZd4kTBqfixo8D4zqeQacTCWgbS0ayaIsmFRFVlW+4Q4DOmz+H KrfL36/8JBtTrd0hFl3hPef4= X-Received: by 127.0.0.2 with SMTP id fC9xYY1788612x3DVQ8L7YGy; Thu, 25 Jan 2024 22:28:15 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.9973.1706250494312923149 for ; Thu, 25 Jan 2024 22:28:15 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8DxmfD6ULNlgh0GAA--.22010S3; Fri, 26 Jan 2024 14:28:10 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxZMz5ULNlOHEbAA--.58637S2; Fri, 26 Jan 2024 14:28:09 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v8 01/37] MdePkg: Add the header file named Csr.h for LoongArch64 Date: Fri, 26 Jan 2024 14:27:51 +0800 Message-Id: <20240126062751.3100600-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxZMz5ULNlOHEbAA--.58637S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQA4sn X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: FneikWKpJl0dwG62rhP6fVasx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250498071100003 Content-Type: text/plain; charset="utf-8" Adding Csr.h for LoongArch64, it is use for accessing the CSR registers. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Acked-by: Michael D Kinney Reviewed-by: Liming Gao --- MdePkg/Include/Register/LoongArch64/Csr.h | 263 ++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 MdePkg/Include/Register/LoongArch64/Csr.h diff --git a/MdePkg/Include/Register/LoongArch64/Csr.h b/MdePkg/Include/Reg= ister/LoongArch64/Csr.h new file mode 100644 index 0000000000..aa22a26564 --- /dev/null +++ b/MdePkg/Include/Register/LoongArch64/Csr.h @@ -0,0 +1,263 @@ +/** @file + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - EXC - Exception + - CSR - CPU Status Register +**/ + +#ifndef LOONGARCH_CSR_H_ +#define LOONGARCH_CSR_H_ + +#include + +// +// CSR register numbers +// + +// +// Basic CSR registers +// +#define LOONGARCH_CSR_CRMD 0x0 +#define LOONGARCH_CSR_PRMD 0x1 +#define LOONGARCH_CSR_EUEN 0x2 +#define CSR_EUEN_LBTEN_SHIFT 3 +#define CSR_EUEN_LBTEN (0x1ULL << CSR_EUEN_LBTEN_SHIFT) +#define CSR_EUEN_LASXEN_SHIFT 2 +#define CSR_EUEN_LASXEN (0x1ULL << CSR_EUEN_LASXEN_SHIFT) +#define CSR_EUEN_LSXEN_SHIFT 1 +#define CSR_EUEN_LSXEN (0x1ULL << CSR_EUEN_LSXEN_SHIFT) +#define CSR_EUEN_FPEN_SHIFT 0 +#define CSR_EUEN_FPEN (0x1ULL << CSR_EUEN_FPEN_SHIFT) +#define LOONGARCH_CSR_MISC 0x3 +#define LOONGARCH_CSR_ECFG 0x4 + +#define LOONGARCH_CSR_ESTAT 0x5 +#define CSR_ESTAT_ESUBCODE_SHIFT 22 +#define CSR_ESTAT_ESUBCODE_WIDTH 9 +#define CSR_ESTAT_ESUBCODE (0x1ffULL << CSR_ESTAT_ESUBCODE_SHIFT) +#define CSR_ESTAT_EXC_SHIFT 16 +#define CSR_ESTAT_EXC_WIDTH 6 +#define CSR_ESTAT_EXC (0x3FULL << CSR_ESTAT_EXC_SHIFT) +#define CSR_ESTAT_IS_SHIFT 0 +#define CSR_ESTAT_IS_WIDTH 15 +#define CSR_ESTAT_IS (0x7FFFULL << CSR_ESTAT_IS_SHIFT) + +#define LOONGARCH_CSR_ERA 0x6 +#define LOONGARCH_CSR_BADV 0x7 +#define LOONGARCH_CSR_BADI 0x8 +#define LOONGARCH_CSR_EBASE 0xC // Exception entry base address + +// +// TLB related CSR registers +// +#define LOONGARCH_CSR_TLBIDX 0x10 // TLB Index, EHINV, PageSize,= NP +#define LOONGARCH_CSR_TLBEHI 0x11 // TLB EntryHi +#define LOONGARCH_CSR_TLBELO0 0x12 // TLB EntryLo0 +#define LOONGARCH_CSR_TLBELO1 0x13 // TLB EntryLo1 +#define LOONGARCH_CSR_ASID 0x18 // ASID +#define LOONGARCH_CSR_PGDL 0x19 // Page table base address whe= n VA[47] =3D 0 +#define LOONGARCH_CSR_PGDH 0x1A // Page table base address whe= n VA[47] =3D 1 +#define LOONGARCH_CSR_PGD 0x1B // Page table base +#define LOONGARCH_CSR_PWCTL0 0x1C // PWCtl0 +#define LOONGARCH_CSR_PWCTL1 0x1D // PWCtl1 +#define LOONGARCH_CSR_STLBPGSIZE 0x1E +#define LOONGARCH_CSR_RVACFG 0x1F + +/// +/// Page table property definitions +/// +#define PAGE_VALID_SHIFT 0 +#define PAGE_DIRTY_SHIFT 1 +#define PAGE_PLV_SHIFT 2 // 2~3, two bits +#define CACHE_SHIFT 4 // 4~5, two bits +#define PAGE_GLOBAL_SHIFT 6 +#define PAGE_HUGE_SHIFT 6 // HUGE is a PMD bit + +#define PAGE_HGLOBAL_SHIFT 12 // HGlobal is a PMD bit +#define PAGE_PFN_SHIFT 12 +#define PAGE_PFN_END_SHIFT 48 +#define PAGE_NO_READ_SHIFT 61 +#define PAGE_NO_EXEC_SHIFT 62 +#define PAGE_RPLV_SHIFT 63 + +/// +/// Used by TLB hardware (placed in EntryLo*) +/// +#define PAGE_VALID ((UINTN)(1) << PAGE_VALID_SHIFT) +#define PAGE_DIRTY ((UINTN)(1) << PAGE_DIRTY_SHIFT) +#define PAGE_PLV ((UINTN)(3) << PAGE_PLV_SHIFT) +#define PAGE_GLOBAL ((UINTN)(1) << PAGE_GLOBAL_SHIFT) +#define PAGE_HUGE ((UINTN)(1) << PAGE_HUGE_SHIFT) +#define PAGE_HGLOBAL ((UINTN)(1) << PAGE_HGLOBAL_SHIFT) +#define PAGE_NO_READ ((UINTN)(1) << PAGE_NO_READ_SHIFT) +#define PAGE_NO_EXEC ((UINTN)(1) << PAGE_NO_EXEC_SHIFT) +#define PAGE_RPLV ((UINTN)(1) << PAGE_RPLV_SHIFT) +#define CACHE_MASK ((UINTN)(3) << CACHE_SHIFT) +#define PFN_SHIFT (EFI_PAGE_SHIFT - 12 + PAGE_PFN_SHIFT) + +#define PLV_KERNEL 0 +#define PLV_USER 3 + +#define PAGE_USER (PLV_USER << PAGE_PLV_SHIFT) +#define PAGE_KERNEL (PLV_KERN << PAGE_PLV_SHIFT) + +#define CACHE_SUC (0 << CACHE_SHIFT) // Strong-ordered UnCached +#define CACHE_CC (1 << CACHE_SHIFT) // Coherent Cached +#define CACHE_WUC (2 << CACHE_SHIFT) // Weak-ordered UnCached + +// +// Config CSR registers +// +#define LOONGARCH_CSR_CPUNUM 0x20 // CPU core number +#define LOONGARCH_CSR_PRCFG1 0x21 // Config1 +#define LOONGARCH_CSR_PRCFG2 0x22 // Config2 +#define LOONGARCH_CSR_PRCFG3 0x23 // Config3 + +// +// Kscratch registers +// +#define LOONGARCH_CSR_KS0 0x30 +#define LOONGARCH_CSR_KS1 0x31 +#define LOONGARCH_CSR_KS2 0x32 +#define LOONGARCH_CSR_KS3 0x33 +#define LOONGARCH_CSR_KS4 0x34 +#define LOONGARCH_CSR_KS5 0x35 +#define LOONGARCH_CSR_KS6 0x36 +#define LOONGARCH_CSR_KS7 0x37 +#define LOONGARCH_CSR_KS8 0x38 + +// +// Stable timer registers +// +#define LOONGARCH_CSR_TMID 0x40 // Timer ID +#define LOONGARCH_CSR_TMCFG 0x41 +#define LOONGARCH_CSR_TMCFG_EN (1ULL << 0) +#define LOONGARCH_CSR_TMCFG_PERIOD (1ULL << 1) +#define LOONGARCH_CSR_TMCFG_TIMEVAL (0x3FFFFFFFFFFFULL << 2) +#define LOONGARCH_CSR_TVAL 0x42 // Timer value +#define LOONGARCH_CSR_CNTC 0x43 // Timer offset +#define LOONGARCH_CSR_TINTCLR 0x44 // Timer interrupt clear + +// +// TLB refill exception base address +// +#define LOONGARCH_CSR_TLBREBASE 0x88 // TLB refill exception entry +#define LOONGARCH_CSR_TLBRBADV 0x89 // TLB refill badvaddr +#define LOONGARCH_CSR_TLBRERA 0x8a // TLB refill ERA +#define LOONGARCH_CSR_TLBRSAVE 0x8b // KScratch for TLB refill except= ion +#define LOONGARCH_CSR_TLBRELO0 0x8c // TLB refill entrylo0 +#define LOONGARCH_CSR_TLBRELO1 0x8d // TLB refill entrylo1 +#define LOONGARCH_CSR_TLBREHI 0x8e // TLB refill entryhi + +// +// Direct map windows registers +// +#define LOONGARCH_CSR_DMWIN0 0x180 // 64 direct map win0: MEM & IF +#define LOONGARCH_CSR_DMWIN1 0x181 // 64 direct map win1: MEM & IF +#define LOONGARCH_CSR_DMWIN2 0x182 // 64 direct map win2: MEM +#define LOONGARCH_CSR_DMWIN3 0x183 // 64 direct map win3: MEM +// +// CSR register numbers end +// + +// +// IOCSR register numbers +// +#define LOONGARCH_IOCSR_FEATURES 0x8 +#define IOCSRF_TEMP (1ULL << 0) +#define IOCSRF_NODECNT (1ULL << 1) +#define IOCSRF_MSI (1ULL << 2) +#define IOCSRF_EXTIOI (1ULL << 3) +#define IOCSRF_CSRIPI (1ULL << 4) +#define IOCSRF_FREQCSR (1ULL << 5) +#define IOCSRF_FREQSCALE (1ULL << 6) +#define IOCSRF_DVFSV1 (1ULL << 7) +#define IOCSRF_EXTIOI_DECODE (1ULL << 9) +#define IOCSRF_FLATMODE (1ULL << 10) +#define IOCSRF_VM (1ULL << 11) + +#define LOONGARCH_IOCSR_VENDOR 0x10 + +#define LOONGARCH_IOCSR_CPUNAME 0x20 + +#define LOONGARCH_IOCSR_NODECNT 0x408 + +#define LOONGARCH_IOCSR_MISC_FUNC 0x420 +#define IOCSR_MISC_FUNC_TIMER_RESET (1ULL << 21) +#define IOCSR_MISC_FUNC_EXT_IOI_EN (1ULL << 48) + +#define LOONGARCH_IOCSR_CPUTEMP 0x428 + +// +// PerCore CSR, only accessable by local cores +// +#define LOONGARCH_IOCSR_IPI_STATUS 0x1000 +#define LOONGARCH_IOCSR_IPI_EN 0x1004 +#define LOONGARCH_IOCSR_IPI_SET 0x1008 +#define LOONGARCH_IOCSR_IPI_CLEAR 0x100c +#define LOONGARCH_IOCSR_MBUF0 0x1020 +#define LOONGARCH_IOCSR_MBUF1 0x1028 +#define LOONGARCH_IOCSR_MBUF2 0x1030 +#define LOONGARCH_IOCSR_MBUF3 0x1038 + +#define LOONGARCH_IOCSR_IPI_SEND 0x1040 +#define IOCSR_IPI_SEND_IP_SHIFT 0 +#define IOCSR_IPI_SEND_CPU_SHIFT 16 +#define IOCSR_IPI_SEND_BLOCKING (1ULL << 31) + +#define LOONGARCH_IOCSR_MBUF_SEND 0x1048 +#define IOCSR_MBUF_SEND_BLOCKING (1ULL << 31) +#define IOCSR_MBUF_SEND_BOX_SHIFT 2 +#define IOCSR_MBUF_SEND_BOX_LO(box) (box << 1) +#define IOCSR_MBUF_SEND_BOX_HI(box) ((box << 1) + 1) +#define IOCSR_MBUF_SEND_CPU_SHIFT 16 +#define IOCSR_MBUF_SEND_BUF_SHIFT 32 +#define IOCSR_MBUF_SEND_H32_MASK 0xFFFFFFFF00000000ULL + +#define LOONGARCH_IOCSR_ANY_SEND 0x1158 +#define IOCSR_ANY_SEND_BLOCKING (1ULL << 31) +#define IOCSR_ANY_SEND_CPU_SHIFT 16 +#define IOCSR_ANY_SEND_MASK_SHIFT 27 +#define IOCSR_ANY_SEND_BUF_SHIFT 32 +#define IOCSR_ANY_SEND_H32_MASK 0xFFFFFFFF00000000ULL + +// +// Register offset and bit definition for CSR access +// +#define LOONGARCH_IOCSR_TIMER_CFG 0x1060 +#define LOONGARCH_IOCSR_TIMER_TICK 0x1070 +#define IOCSR_TIMER_CFG_RESERVED BIT63 +#define IOCSR_TIMER_CFG_PERIODIC BIT62 +#define IOCSR_TIMER_CFG_EN BIT61 +#define IOCSR_TIMER_MASK 0x0FFFFFFFFFFFFULL +#define IOCSR_TIMER_INITVAL_RST (0xFFFFULL << 48) +// +// IOCSR register numbers end +// + +// +// Invalid addr with global=3D1 or matched asid in current TLB +// +#define INVTLB_ADDR_GTRUE_OR_ASID 0x6 + +// +// Bits 8 and 9 of FPU Status Register specify the rounding mode +// +#define FPU_CSR_RM 0x300 +#define FPU_CSR_RN 0x000 // nearest +#define FPU_CSR_RZ 0x100 // towards zero +#define FPU_CSR_RU 0x200 // towards +Infinity +#define FPU_CSR_RD 0x300 // towards -Infinity + +#define DEFAULT_PAGE_SIZE 0x0c +#define CSR_TLBIDX_SIZE_MASK 0x3f000000 +#define CSR_TLBIDX_PS_SHIFT 24 +#define CSR_TLBIDX_SIZE CSR_TLBIDX_PS_SHIFT +#define CSR_TLBREHI_PS_SHIFT 0x0 +#define CSR_TLBREHI_PS 0x3f + +#endif --=20 2.27.0 -=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 (#114527): https://edk2.groups.io/g/devel/message/114527 Mute This Topic: https://groups.io/mt/103971633/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- From nobody Thu Dec 26 20:24:45 2024 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+114528+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+114528+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250502; cv=none; d=zohomail.com; s=zohoarc; b=PTTFGApjWmYTNlmO5zaRtlV2nAGEDxWvN2zzMP4Brn8I79jOgNSGqWQBcSpp1pXwKn3opihFuGBbOKIsZKDayy22W7FSUB32dKSgbC62JtTUlzaZPfdMA25T3ltSl6CC3SgNWjk6YsZ4nr8FR+TbvjYTGkCv5s8ZYH9m7uh6WcU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250502; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=kgi0/RoiLpi3q6aUBu/uGSqXVyDqY2940w7GgPqSxs0=; b=grMktsmQz/EwhnYafuXRSCeET1WPytPmYlrtvMHq2h6ulwPOITM6GwTPFduYm0oSJzbl4AzfWXhPU9n9bj/IR/Z5VOd7fLCg80SB/5OpXqvKPItVfOUj91O/gjXvlwfCFhUlo0XpF5YEXF8k/StEljif6hqmau+37VnZ+QMe8rE= 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+114528+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250502008620.5269971043654; Thu, 25 Jan 2024 22:28:22 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=qo4X5xI7iMSkgeiK+eDJ0eCJc0aJfIhGgl4lnezX53c=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250501; v=1; b=mhksBt2YWLemwNCwO6Sa/iG/Nxf6iaPelzyzFvWK48r/oQZpserYyhMJMxtgF9SnquLDXmBw fST22fI4r9MuEWoCzIvojTqm/T3dBiw69K0nyzUWbdIshsnltwNRdcl+oFGYAiw34vBQbHJWHmc C9cRZzrBzI9XC/cUx+s12C84= X-Received: by 127.0.0.2 with SMTP id IAUAYY1788612xEM2MVOhFct; Thu, 25 Jan 2024 22:28:21 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10112.1706250500182668021 for ; Thu, 25 Jan 2024 22:28:21 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8AxOOgAUbNljB0GAA--.2150S3; Fri, 26 Jan 2024 14:28:16 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxRMz_ULNlR3EbAA--.44258S2; Fri, 26 Jan 2024 14:28:15 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v8 02/37] MdePkg: Add LoongArch64 FPU function set into BaseCpuLib Date: Fri, 26 Jan 2024 14:28:14 +0800 Message-Id: <20240126062814.3100910-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxRMz_ULNlR3EbAA--.44258S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQA5sm X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: XCZFVPQDryY1gc22BAaPHq88x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250504089100003 Content-Type: text/plain; charset="utf-8" Adding InitializeFloatingPointUnits, EnableFloatingPointUnits and DisableFloatingPointUnits functions for LoongArch64. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Acked-by: Michael D Kinney Reviewed-by: Liming Gao --- MdePkg/Include/Library/CpuLib.h | 43 ++++++++++++++-- MdePkg/Library/BaseCpuLib/BaseCpuLib.inf | 7 ++- .../Library/BaseCpuLib/LoongArch/DisableFpu.S | 17 +++++++ .../Library/BaseCpuLib/LoongArch/EnableFpu.S | 17 +++++++ .../BaseCpuLib/LoongArch/InitializeFpu.S | 51 +++++++++++++++++++ 5 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 MdePkg/Library/BaseCpuLib/LoongArch/DisableFpu.S create mode 100644 MdePkg/Library/BaseCpuLib/LoongArch/EnableFpu.S create mode 100644 MdePkg/Library/BaseCpuLib/LoongArch/InitializeFpu.S diff --git a/MdePkg/Include/Library/CpuLib.h b/MdePkg/Include/Library/CpuLi= b.h index 3f29937dc7..27f3f82ab9 100644 --- a/MdePkg/Include/Library/CpuLib.h +++ b/MdePkg/Include/Library/CpuLib.h @@ -8,6 +8,7 @@ As a result, these services could not be defined in the Base Library. =20 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2024, Loongson Technology Corporation Limited. All rights re= served.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -41,14 +42,16 @@ CpuFlushTlb ( VOID ); =20 -#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) || defined (MDE_CPU_LO= ONGARCH64) =20 /** + Initialize the CPU floating point units. + Initializes floating point units for requirement of UEFI specification. - This function initializes floating-point control word to 0x027F (all exc= eptions - masked,double-precision, round-to-nearest) and multimedia-extensions con= trol word - (if supported) to 0x1F80 (all exceptions masked, round-to-nearest, flush= to zero - for masked underflow). + For IA32 and X64, this function initializes floating-point control word = to 0x027F + (all exceptions masked,double-precision, round-to-nearest) and multimedi= a-extensions + control word (if supported) to 0x1F80 (all exceptions masked, round-to-n= earest, + flush to zero for masked underflow). **/ VOID EFIAPI @@ -56,6 +59,10 @@ InitializeFloatingPointUnits ( VOID ); =20 +#endif + +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) + /** Determine if the standard CPU signature is "AuthenticAMD". @retval TRUE The CPU signature matches. @@ -89,4 +96,30 @@ GetCpuSteppingId ( =20 #endif =20 +#if defined (MDE_CPU_LOONGARCH64) + +/** + Enable the CPU floating point units. + + Enable the CPU floating point units. +**/ +VOID +EFIAPI +EnableFloatingPointUnits ( + VOID + ); + +/** + Disable the CPU floating point units. + + Disable the CPU floating point units. +**/ +VOID +EFIAPI +DisableFloatingPointUnits ( + VOID + ); + +#endif + #endif diff --git a/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf b/MdePkg/Library/Base= CpuLib/BaseCpuLib.inf index 9a162afe6d..89f6272f11 100644 --- a/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf +++ b/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf @@ -65,8 +65,11 @@ RiscV/Cpu.S =20 [Sources.LOONGARCH64] - LoongArch/CpuFlushTlb.S | GCC - LoongArch/CpuSleep.S | GCC + LoongArch/CpuFlushTlb.S | GCC + LoongArch/CpuSleep.S | GCC + LoongArch/InitializeFpu.S | GCC + LoongArch/EnableFpu.S | GCC + LoongArch/DisableFpu.S | GCC =20 [Packages] MdePkg/MdePkg.dec diff --git a/MdePkg/Library/BaseCpuLib/LoongArch/DisableFpu.S b/MdePkg/Libr= ary/BaseCpuLib/LoongArch/DisableFpu.S new file mode 100644 index 0000000000..33c6bf3411 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/LoongArch/DisableFpu.S @@ -0,0 +1,17 @@ +#-------------------------------------------------------------------------= ----- +# +# DisableFloatingPointUnits() for LoongArch64 +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- +ASM_GLOBAL ASM_PFX(DisableFloatingPointUnits) + +ASM_PFX(DisableFloatingPointUnits): + li.w $t0, 0x1 + csrxchg $zero, $t0, 0x2 + + jirl $zero, $ra, 0 + .end diff --git a/MdePkg/Library/BaseCpuLib/LoongArch/EnableFpu.S b/MdePkg/Libra= ry/BaseCpuLib/LoongArch/EnableFpu.S new file mode 100644 index 0000000000..3e4f7411f1 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/LoongArch/EnableFpu.S @@ -0,0 +1,17 @@ +#-------------------------------------------------------------------------= ----- +# +# EnableFloatingPointUnits() for LoongArch64 +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- +ASM_GLOBAL ASM_PFX(EnableFloatingPointUnits) + +ASM_PFX(EnableFloatingPointUnits): + li.w $t0, 0x1 + csrxchg $t0, $t0, 0x2 + + jirl $zero, $ra, 0 + .end diff --git a/MdePkg/Library/BaseCpuLib/LoongArch/InitializeFpu.S b/MdePkg/L= ibrary/BaseCpuLib/LoongArch/InitializeFpu.S new file mode 100644 index 0000000000..2cea5558a6 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/LoongArch/InitializeFpu.S @@ -0,0 +1,51 @@ +#-------------------------------------------------------------------------= ----- +# +# InitializeFloatingPointUnits() for LoongArch64 +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- +ASM_GLOBAL ASM_PFX(InitializeFloatingPointUnits) + +ASM_PFX(InitializeFloatingPointUnits): + li.d $t0, 0x0 // RNE mode + movgr2fcsr $r0, $t0 + li.d $t1, -1 // SNaN + + movgr2fr.d $f0, $t1 + movgr2fr.d $f1, $t1 + movgr2fr.d $f2, $t1 + movgr2fr.d $f3, $t1 + movgr2fr.d $f4, $t1 + movgr2fr.d $f5, $t1 + movgr2fr.d $f6, $t1 + movgr2fr.d $f7, $t1 + movgr2fr.d $f8, $t1 + movgr2fr.d $f9, $t1 + movgr2fr.d $f10, $t1 + movgr2fr.d $f11, $t1 + movgr2fr.d $f12, $t1 + movgr2fr.d $f13, $t1 + movgr2fr.d $f14, $t1 + movgr2fr.d $f15, $t1 + movgr2fr.d $f16, $t1 + movgr2fr.d $f17, $t1 + movgr2fr.d $f18, $t1 + movgr2fr.d $f19, $t1 + movgr2fr.d $f20, $t1 + movgr2fr.d $f21, $t1 + movgr2fr.d $f22, $t1 + movgr2fr.d $f23, $t1 + movgr2fr.d $f24, $t1 + movgr2fr.d $f25, $t1 + movgr2fr.d $f26, $t1 + movgr2fr.d $f27, $t1 + movgr2fr.d $f28, $t1 + movgr2fr.d $f29, $t1 + movgr2fr.d $f30, $t1 + movgr2fr.d $f31, $t1 + + jirl $zero, $ra, 0 + .end --=20 2.27.0 -=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 (#114528): https://edk2.groups.io/g/devel/message/114528 Mute This Topic: https://groups.io/mt/103971634/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- From nobody Thu Dec 26 20:24:45 2024 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+114529+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+114529+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250505; cv=none; d=zohomail.com; s=zohoarc; b=JcOBby9sCwgOdoXKsbVQgKv2FwVC8hWXGCOAMuBWe5YU1hZ6Rax37XKUQGXBzx+m8pujE8G27yWiU9tz/iSImZrxp3o/jl41MeEiEveFn5qjQGuxA2EegpF58eGOxSTL5RSDtuxN4g5gjgYxUIWQLJNO0PK1rwDlZFVa5kvprqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250505; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=ZyV9hj2R08JZ4c/bk2fME0Acnc6aKewxSbhNDjvdzJc=; b=nnbwrcUkiTTmoq6OPGnyqfLUAc/xR4SeLin4PjdwV0riW26nJ2jMVk3ooXL0mLKXlh+257koh21WMIwRGRyBmPM5CRahQ4+Lijc8AQGepQGlkszUXvocvhXE8zhsys42mgeMDHxdaLRlFIXFrUCFJgMtmPP7XLWOaG082k3EmEw= 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+114529+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250505811369.69617939818795; Thu, 25 Jan 2024 22:28:25 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=G3Dyd40vfK7xRiKE9GY8ri9ocjTbCyPvjinZntNDhnk=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250505; v=1; b=QVx3O022hCOoZaGZE28MrMQCtszB0KSKmxKtjeh2dXabFjfKq9GcsCZPLaMelrqdlhMCUUtU LDplAdMujq3N0N9mEAtJl4ioo7rrjs8sb4wgKyvQ4xrdEE3oKRabfwlJyhnMdm+NDB0rQAdx059 0X2fDhd1P4Kbl7is6xn4kmQg= X-Received: by 127.0.0.2 with SMTP id KUUdYY1788612xgvhc14gryx; Thu, 25 Jan 2024 22:28:25 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10113.1706250504226722277 for ; Thu, 25 Jan 2024 22:28:25 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8AxuugFUbNllh0GAA--.2128S3; Fri, 26 Jan 2024 14:28:21 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxX88EUbNlVXEbAA--.53198S2; Fri, 26 Jan 2024 14:28:20 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v8 03/37] MdePkg: Add LoongArch64 exception function set into BaseLib Date: Fri, 26 Jan 2024 14:28:19 +0800 Message-Id: <20240126062819.3100971-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxX88EUbNlVXEbAA--.53198S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQA6sl X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: KObj2hDBKbmD7Xr4Vte6mig1x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250506047100005 Content-Type: text/plain; charset="utf-8" Adding SetExceptionBaseAddress and SetTlbRebaseAddress functions for LoongArch64. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Acked-by: Michael D Kinney Reviewed-by: Liming Gao --- MdePkg/Include/Library/BaseLib.h | 20 +++++++++ MdePkg/Library/BaseLib/BaseLib.inf | 1 + .../BaseLib/LoongArch64/ExceptionBase.S | 41 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 MdePkg/Library/BaseLib/LoongArch64/ExceptionBase.S diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index ca0d06c7f3..7117c4288f 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -287,6 +287,26 @@ typedef struct { =20 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8 =20 +/* + * Set the exception base address for LoongArch. + * + * @param ExceptionBaseAddress The exception base address, must be alig= ned greater than or qeual to 4K . + */ +VOID +SetExceptionBaseAddress ( + IN UINT64 + ); + +/* + * Set the TlbRebase address for LoongArch. + * + * @param TlbRebaseAddress The TlbRebase address, must be aligned great= er than or qeual to 4K . + */ +VOID +SetTlbRebaseAddress ( + IN UINT64 + ); + #endif // defined (MDE_CPU_LOONGARCH64) =20 // diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 6b46949be3..22b38b59e7 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -420,6 +420,7 @@ LoongArch64/CpuPause.S | GCC LoongArch64/SetJumpLongJump.S | GCC LoongArch64/SwitchStack.S | GCC + LoongArch64/ExceptionBase.S | GCC =20 [Packages] MdePkg/MdePkg.dec diff --git a/MdePkg/Library/BaseLib/LoongArch64/ExceptionBase.S b/MdePkg/Li= brary/BaseLib/LoongArch64/ExceptionBase.S new file mode 100644 index 0000000000..b6e90a8f28 --- /dev/null +++ b/MdePkg/Library/BaseLib/LoongArch64/ExceptionBase.S @@ -0,0 +1,41 @@ +#-------------------------------------------------------------------------= ----- +# +# LoongArch set exception base address operations +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- + +#include +#include + +ASM_GLOBAL ASM_PFX(SetExceptionBaseAddress) +ASM_GLOBAL ASM_PFX(SetTlbRebaseAddress) + +#/** +# Set the exception base address for LoongArch. +# +# @param ExceptionBaseAddress The exception base address, must be alig= ned greater than or qeual to 4K . +#**/ +ASM_PFX(SetExceptionBaseAddress): + csrrd $t0, LOONGARCH_CSR_ECFG + li.d $t1, ~(BIT16 | BIT17 | BIT18) + and $t0, $t0, $t1 + csrwr $t0, LOONGARCH_CSR_ECFG + + move $t0, $a0 + csrwr $t0, LOONGARCH_CSR_EBASE + jirl $zero, $ra, 0 + +#/** +# Set the TlbRebase address for LoongArch. +# +# @param TlbRebaseAddress The TlbRebase address, must be aligned great= er than or qeual to 4K . +#**/ +ASM_PFX(SetTlbRebaseAddress): + move $t0, $a0 + csrwr $t0, LOONGARCH_CSR_TLBREBASE + jirl $zero, $ra, 0 +.end --=20 2.27.0 -=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 (#114529): https://edk2.groups.io/g/devel/message/114529 Mute This Topic: https://groups.io/mt/103971637/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- From nobody Thu Dec 26 20:24:45 2024 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+114530+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+114530+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250509; cv=none; d=zohomail.com; s=zohoarc; b=gb2r2jvM30oin1HvzSHsaenaaDamtUWmU2FRzRPEJZR8mTt1mVDWM9GzVJ4clcws5H6XtCvTZbET3WzP+zmtuygO1RwC1UgjPoFb5AYvRmF+BMtgRbgb/wp28UIuZcCGyWKmet1nvpacDfdkI7dCeiH7+x1KAbIvNjntQhR7Tx8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250509; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=EOvbxqY4zpfqlMfUk1EP7AHVd9DvuIo8pQ/aeFF10kw=; b=hqDrcjDOuhVevp6J0sIQYIs6S0tEnEFmzicAtNIZ4vQdAehiJfbiKatG1wREIk6YHKA/qC9hvIcdMcePwPS44lEMxk0epjyO7wRIaEWH72b7lku3+1yiP22N4uD5PVFia/78DMO2jAez4XXDOEtUlWOrA5TFAG6pPhGVCl4BHoo= 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+114530+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250509132467.1987471117145; Thu, 25 Jan 2024 22:28:29 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=mcn/3j7eJwvYZgS+6l/j5PKE6f3bFB769JTzikhxsKQ=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250508; v=1; b=ke7L+09SU8mDI+muLTyIYNVw1xRs54fRYllGSuzCIYCjX+xPe8ghWibvsf5CEwLjxAdHNjKn bsCYxHjKv7XUTP6R48DqVJr72n8XyNWzYub9oJRMXXcr0qw/caGTBKh9XlfP0wF9Bm4V6yCesZs tcouMmMoiCwbAieGZLH7gSH8= X-Received: by 127.0.0.2 with SMTP id z8bzYY1788612xvylLe2kjcu; Thu, 25 Jan 2024 22:28:28 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10115.1706250507551533529 for ; Thu, 25 Jan 2024 22:28:28 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxXOkJUbNlnh0GAA--.11486S3; Fri, 26 Jan 2024 14:28:25 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxHs8IUbNlcHEbAA--.52905S2; Fri, 26 Jan 2024 14:28:24 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v8 04/37] MdePkg: Add LoongArch64 local interrupt function set into BaseLib Date: Fri, 26 Jan 2024 14:28:23 +0800 Message-Id: <20240126062823.3101033-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxHs8IUbNlcHEbAA--.52905S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQA8sj X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: R4PtN1xSaxVCl0CXsewC6lQRx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250510065100001 Content-Type: text/plain; charset="utf-8" Adding LoongArch local interrupt function set, which is used to control the opening or closing of the local interrupt when the global interrupt is enabled. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Acked-by: Michael D Kinney Reviewed-by: Liming Gao --- MdePkg/Include/Library/BaseLib.h | 20 +++++++++++++++++ .../BaseLib/LoongArch64/DisableInterrupts.S | 22 ++++++++++++++----- .../BaseLib/LoongArch64/EnableInterrupts.S | 22 ++++++++++++++----- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 7117c4288f..91322d2dfa 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -307,6 +307,26 @@ SetTlbRebaseAddress ( IN UINT64 ); =20 +/** + Enables local CPU interrupts. + + @param Needs to enable local interrupt bit. +**/ +VOID +EnableLocalInterrupts ( + IN UINT16 + ); + +/** + Disables local CPU interrupts. + + @param Needs to disable local interrupt bit. +**/ +VOID +DisableLocalInterrupts ( + IN UINT16 + ); + #endif // defined (MDE_CPU_LOONGARCH64) =20 // diff --git a/MdePkg/Library/BaseLib/LoongArch64/DisableInterrupts.S b/MdePk= g/Library/BaseLib/LoongArch64/DisableInterrupts.S index 0f228339af..8f9ee888b1 100644 --- a/MdePkg/Library/BaseLib/LoongArch64/DisableInterrupts.S +++ b/MdePkg/Library/BaseLib/LoongArch64/DisableInterrupts.S @@ -1,21 +1,33 @@ #-------------------------------------------------------------------------= ----- # -# LoongArch interrupt disable +# LoongArch interrupt disable operations # -# Copyright (c) 2022, Loongson Technology Corporation Limited. All rights = reserved.
+# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # #-------------------------------------------------------------------------= ----- =20 +#include +#include + +ASM_GLOBAL ASM_PFX(DisableLocalInterrupts) ASM_GLOBAL ASM_PFX(DisableInterrupts) =20 #/** -# Disables CPU interrupts. +# Disables local CPU interrupts. +# +# @param Needs to disable local interrupt bit. #**/ +ASM_PFX(DisableLocalInterrupts): + csrxchg $zero, $a0, LOONGARCH_CSR_ECFG + jirl $zero, $ra, 0 =20 +#/** +# Disables global CPU interrupts. +#**/ ASM_PFX(DisableInterrupts): - li.w $t0, 0x4 - csrxchg $zero, $t0, 0x0 + li.w $t0, BIT2 + csrxchg $zero, $t0, LOONGARCH_CSR_CRMD jirl $zero, $ra, 0 .end diff --git a/MdePkg/Library/BaseLib/LoongArch64/EnableInterrupts.S b/MdePkg= /Library/BaseLib/LoongArch64/EnableInterrupts.S index 3c34fb2cdd..126c7b49b3 100644 --- a/MdePkg/Library/BaseLib/LoongArch64/EnableInterrupts.S +++ b/MdePkg/Library/BaseLib/LoongArch64/EnableInterrupts.S @@ -1,21 +1,33 @@ #-------------------------------------------------------------------------= ----- # -# LoongArch interrupt enable +# LoongArch interrupt enable operations # -# Copyright (c) 2022, Loongson Technology Corporation Limited. All rights = reserved.
+# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # #-------------------------------------------------------------------------= ----- =20 +#include +#include + +ASM_GLOBAL ASM_PFX(EnableLocalInterrupts) ASM_GLOBAL ASM_PFX(EnableInterrupts) =20 #/** -# Enables CPU interrupts. +# Enables local CPU interrupts. +# +# @param Needs to enable local interrupt bit. #**/ +ASM_PFX(EnableLocalInterrupts): + csrxchg $a0, $a0, LOONGARCH_CSR_ECFG + jirl $zero, $ra, 0 =20 +#/** +# Enables global CPU interrupts. +#**/ ASM_PFX(EnableInterrupts): - li.w $t0, 0x4 - csrxchg $t0, $t0, 0x0 + li.w $t0, BIT2 + csrxchg $t0, $t0, LOONGARCH_CSR_CRMD jirl $zero, $ra, 0 .end --=20 2.27.0 -=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 (#114530): https://edk2.groups.io/g/devel/message/114530 Mute This Topic: https://groups.io/mt/103971639/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- From nobody Thu Dec 26 20:24:45 2024 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+114531+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+114531+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250515; cv=none; d=zohomail.com; s=zohoarc; b=Wc/t/vFe5bpWhGk9wVpHteHOQpYnsHUiznaTt49vt6g+SADB5Oqma7ZjPSzEelgXSusSRUHjnKlO+zVNWVq6sCPN1YVbyMeEocUYUqGWfxxo5PHlP+l7gGOEI88sWNLP1CbI4VZmREFBpzvFWWII0IJsvLlzTsOqH3k/ZuntIoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250515; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=BwHoVUiLinv/hf8qTtpJKYATDHqAbK2NNWfHclhZqQc=; b=dz28abPkpUwIK/F/c6OfNzmt9V3+LDuL35W3rGBq5SEOhRa/JcvuHPWdwRoAD1CDeJkLLBej5gE5tqnZcjQkxUa8v3sHlO0TH1wakhQFLpSDwZex5KJdwJuIjWbKmzgrZHkMt7u6rvgvdgAo+78Q/QUCxkZaVolCKKAEMWI9jYY= 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+114531+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250515860712.3624128975628; Thu, 25 Jan 2024 22:28:35 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=xHNyXj3lBYgZPRYO6nsoKLKksCh/jQXPrVEeiLmsYzw=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250515; v=1; b=UR6cZ4RWdy8psuhMz1C+3SdECMhlkG80bED+KLkDicXSC43cllQNoV0Z9BHg9XTB+5qPqgf0 LrVbJGOZShuIT6rxOqXAksIsS5tPCXVB62Z+VLpUqV8Mpe5GX/ADuQI5jmuG/tvcYYJq0VODEeJ pKJdknSxNu5iDxJOUq8VY5Ys= X-Received: by 127.0.0.2 with SMTP id 99BGYY1788612x7ZidT821Ig; Thu, 25 Jan 2024 22:28:35 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10118.1706250514467565197 for ; Thu, 25 Jan 2024 22:28:35 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8BxC+kQUbNlrB0GAA--.2078S3; Fri, 26 Jan 2024 14:28:32 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxRMwOUbNlgHEbAA--.44262S2; Fri, 26 Jan 2024 14:28:30 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v8 05/37] MdePkg: Add LoongArch Cpucfg function Date: Fri, 26 Jan 2024 14:28:29 +0800 Message-Id: <20240126062829.3101096-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxRMwOUbNlgHEbAA--.44262S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQA9si X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: S58mwE2T2TBBaa7USAvSGxVWx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250516106100001 Content-Type: text/plain; charset="utf-8" Add LoongArch AsmCpucfg function and Cpucfg definitions. Also added Include/Register/LoongArch64/Cpucfg.h to IgnoreFiles of EccCheck. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Acked-by: Michael D Kinney Reviewed-by: Liming Gao --- MdePkg/Include/Library/BaseLib.h | 12 + MdePkg/Include/Register/LoongArch64/Cpucfg.h | 565 +++++++++++++++++++ MdePkg/Library/BaseLib/BaseLib.inf | 1 + MdePkg/Library/BaseLib/LoongArch64/Cpucfg.S | 26 + MdePkg/MdePkg.ci.yaml | 3 +- 5 files changed, 606 insertions(+), 1 deletion(-) create mode 100644 MdePkg/Include/Register/LoongArch64/Cpucfg.h create mode 100644 MdePkg/Library/BaseLib/LoongArch64/Cpucfg.S diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 91322d2dfa..d64e406b7c 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -327,6 +327,18 @@ DisableLocalInterrupts ( IN UINT16 ); =20 +/** + Read CPUCFG register. + + @param Index Specifies the register number of the CPUCFG to read the d= ata. + @param Data A pointer to the variable used to store the CPUCFG regist= er value. +**/ +VOID +AsmCpucfg ( + IN UINT32 Index, + OUT UINT32 *Data + ); + #endif // defined (MDE_CPU_LOONGARCH64) =20 // diff --git a/MdePkg/Include/Register/LoongArch64/Cpucfg.h b/MdePkg/Include/= Register/LoongArch64/Cpucfg.h new file mode 100644 index 0000000000..570748b194 --- /dev/null +++ b/MdePkg/Include/Register/LoongArch64/Cpucfg.h @@ -0,0 +1,565 @@ +/** @file + CPUCFG definitions. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef CPUCFG_H_ +#define CPUCFG_H_ + +/** + CPUCFG REG0 Information + + @code + CPUCFG_REG0_INFO_DATA + **/ +#define CPUCFG_REG0_INFO 0x0 + +/** + CPUCFG REG0 Information returned data. + #CPUCFG_REG0_INFO + **/ +typedef union { + struct { + /// + /// [Bit 31:0] Processor Identity. + /// + UINT32 PRID : 32; + } Bits; + /// + /// All bit fields as a 32-bit value + /// + UINT32 Uint32; +} CPUCFG_REG0_INFO_DATA; + +/** + CPUCFG REG1 Information + + @code + CPUCFG_REG1_INFO_DATA + **/ +#define CPUCFG_REG1_INFO 0x1 + +/** + CPUCFG REG1 Information returned data. + #CPUCFG_REG1_INFO + **/ +typedef union { + struct { + /// + /// [Bit 1:0] Architecture: + /// 2'b00 indicates the implementation of simplified LoongAa= rch32; + /// 2'b01 indicates the implementation of LoongAarch32; + /// 2'b10 indicates the implementation of LoongAarch64; + /// 2'b11 reserved; + /// + UINT32 ARCH : 2; + /// + /// [Bit 2] Paging mapping mode. A value of 1 indicates the processor = MMU supports + /// page mapping mode. + /// + UINT32 PGMMU : 1; + /// + /// [Bit 3] A value of 1 indicates the processor supports the IOCSR in= struction. + /// + UINT32 IOCSR : 1; + /// + /// [Bit 11:4] Physical address bits. The supported physical address b= its PALEN value + /// minus 1. + /// + UINT32 PALEN : 8; + /// + /// [Bit 19:12] Virtual address bits. The supported virtual address bi= ts VALEN value + /// minus 1. + /// + UINT32 VALEN : 8; + /// + /// [Bit 20] Non-aligned Memory Access. A value of 1 indicates the pro= cessor supports + /// non-aligned memory access. + /// + UINT32 UAL : 1; + /// + /// [Bit 21] Page Read Inhibit. A value of 1 indicates the processor s= upports page + /// attribute of "Read Inhibit". + /// + UINT32 RI : 1; + /// + /// [Bit 22] Page Execution Protection. A value of 1 indicates the pro= cessor supports + /// page attribute of "Execution Protection". + /// + UINT32 EP : 1; + /// + /// [Bit 23] A value of 1 indicates the processor supports for page at= tributes of RPLV. + /// + UINT32 RPLV : 1; + /// + /// [Bit 24] Huge Page. A value of 1 indicates the processor supports = page attribute + /// of huge page. + /// + UINT32 HP : 1; + /// + /// [Bit 25] A value of 1 indicates that the string of processor produ= ct information + /// is recorded at address 0 of the IOCSR access space. + /// + UINT32 IOCSR_BRD : 1; + /// + /// [Bit 26] A value of 1 indicates that the external interrupt uses t= he message + /// interrupt mode, otherwise it is the level interrupt line mode. + /// + UINT32 MSG_INT : 1; + /// + /// [Bit 31:27] Reserved. + /// + UINT32 Reserved : 5; + } Bits; + /// + /// All bit fields as a 32-bit value + /// + UINT32 Uint32; +} CPUCFG_REG1_INFO_DATA; + +/** + CPUCFG REG2 Information + + @code + CPUCFG_REG2_INFO_DATA + **/ +#define CPUCFG_REG2_INFO 0x2 + +/** + CPUCFG REG2 Information returned data. + #CPUCFG_REG2_INFO + **/ +typedef union { + struct { + /// + /// [Bit 0] Basic Floating-Point. A value of 1 indicates the processor= supports basic + /// floating-point instructions. + /// + UINT32 FP : 1; + /// + /// [Bit 1] Sigle-Precision. A value of 1 indicates the processor supp= orts sigle-precision + /// floating-point numbers. + /// + UINT32 FP_SP : 1; + /// + /// [Bit 2] Double-Precision. A value of 1 indicates the processor sup= ports double-precision + /// floating-point numbers. + /// + UINT32 FP_DP : 1; + /// + /// [Bit 5:3] The version number of the floating-point arithmetic stan= dard. 1 is the initial + /// version number, indicating that it is compatible with the IEEE 754= -2008 standard. + /// + UINT32 FP_ver : 3; + /// + /// [Bit 6] 128-bit Vector Extension. A value of 1 indicates the proce= ssor supports 128-bit + /// vector extension. + /// + UINT32 LSX : 1; + /// + /// [Bit 7] 256-bit Vector Extension. A value of 1 indicates the proce= ssor supports 256-bit + /// vector extension. + /// + UINT32 LASX : 1; + /// + /// [Bit 8] Complex Vector Operation Instructions. A value of 1 indica= tes the processor supports + /// complex vector operation instructions. + /// + UINT32 COMPLEX : 1; + /// + /// [Bit 9] Encryption And Decryption Vector Instructions. A value of = 1 indicates the processor + /// supports encryption and decryption vector instructions. + /// + UINT32 CRYPTO : 1; + /// + /// [Bit 10] Virtualization Expansion. A value of 1 indicates the proc= essor supports + /// virtualization expansion. + /// + UINT32 LVZ : 1; + /// + /// [Bit 13:11] The version number of the virtualization hardware acce= leration specification. + /// 1 is the initial version number. + /// + UINT32 LVZ_ver : 3; + /// + /// [Bit 14] Constant Frequency Counter And Timer. A value of 1 indica= tes the processor supports + /// constant frequency counter and timer. + /// + UINT32 LLFTP : 1; + /// + /// [Bit 17:15] Constant frequency counter and timer version number. 1= is the initial version. + /// + UINT32 LLTP_ver : 3; + /// + /// [Bit 18] X86 Binary Translation Extension. A value of 1 indicates = the processor supports + /// X86 binary translation extension. + /// + UINT32 LBT_X86 : 1; + /// + /// [Bit 19] ARM Binary Translation Extension. A value of 1 indicates = the processor supports + /// ARM binary translation extension. + /// + UINT32 LBT_ARM : 1; + /// + /// [Bit 20] MIPS Binary Translation Extension. A value of 1 indicates= the processor supports + /// MIPS binary translation extension. + /// + UINT32 LBT_MIPS : 1; + /// + /// [Bit 21] Software Page Table Walking Instruction. A value of 1 ind= icates the processor + /// supports software page table walking instruction. + /// + UINT32 LSPW : 1; + /// + /// [Bit 22] Atomic Memory Access Instruction. A value of 1 indicates = the processor supports + /// AM* atomic memory access instruction. + /// + UINT32 LAM : 1; + /// + /// [Bit 31:23] Reserved. + /// + UINT32 Reserved : 9; + } Bits; + /// + /// All bit fields as a 32-bit value + /// + UINT32 Uint32; +} CPUCFG_REG2_INFO_DATA; + +/** + CPUCFG REG3 Information + + @code + CPUCFG_REG3_INFO_DATA + **/ +#define CPUCFG_REG3_INFO 0x3 + +/** + CPUCFG REG3 Information returned data. + #CPUCFG_REG3_INFO + **/ +typedef union { + struct { + /// + /// [Bit 0] Hardware Cache Coherent DMA. A value of 1 indicates the pr= ocessor supports + /// hardware cache coherent DMA. + /// + UINT32 CCDMA : 1; + /// + /// [Bit 1] Store Fill Buffer. A value of 1 indicates the processor su= pports store fill + /// buffer (SFB). + /// + UINT32 SFB : 1; + /// + /// [Bit 2] Uncache Accelerate. A value of 1 indicates the processor s= upports uncache + /// accelerate. + /// + UINT32 UCACC : 1; + /// + /// [Bit 3] A value of 1 indicates the processor supports LL instructi= on to fetch exclusive + /// block function. + /// + UINT32 LLEXC : 1; + /// + /// [Bit 4] A value of 1 indicates the processor supports random delay= function after SC + /// instruction. + /// + UINT32 SCDLY : 1; + /// + /// [Bit 5] A value of 1 indicates the processor supports LL automatic= with dbar function. + /// + UINT32 LLDBAR : 1; + /// + /// [Bit 6] A value of 1 indicates the processor supports the hardware= maintains the + /// consistency between ITLB and TLB. + /// + UINT32 ITLBT : 1; + /// + /// [Bit 7] A value of 1 indicates the processor supports the hardware= maintains the data + /// consistency between ICache and DCache in one processor core. + /// + UINT32 ICACHET : 1; + /// + /// [Bit 10:8] The maximum number of directory levels supported by the= page walk instruction. + /// + UINT32 SPW_LVL : 3; + /// + /// [Bit 11] A value of 1 indicates the processor supports the page wa= lk instruction fills + /// the TLB in half when it encounters a large page. + /// + UINT32 SPW_HP_HF : 1; + /// + /// [Bit 12] Virtual Address Range. A value of 1 indicates the process= or supports the software + /// configuration can be used to shorten the virtual address range. + /// + UINT32 RVA : 1; + /// + /// [Bit 16:13] The maximum configurable virtual address is shortened = by -1. + /// + UINT32 RVAMAX_1 : 4; + /// + /// [Bit 31:17] Reserved. + /// + UINT32 Reserved : 15; + } Bits; + /// + /// All bit fields as a 32-bit value + /// + UINT32 Uint32; +} CPUCFG_REG3_INFO_DATA; + +/** + CPUCFG REG4 Information + + @code + CPUCFG_REG4_INFO_DATA + **/ +#define CPUCFG_REG4_INFO 0x4 + +/** + CPUCFG REG4 Information returned data. + #CPUCFG_REG4_INFO + **/ +typedef union { + struct { + /// + /// [Bit 31:0] Constant frequency timer and the crystal frequency corr= esponding to the clock + /// used by the timer. + /// + UINT32 CC_FREQ : 32; + } Bits; + /// + /// All bit fields as a 32-bit value + /// + UINT32 Uint32; +} CPUCFG_REG4_INFO_DATA; + +/** + CPUCFG REG5 Information + + @code + CPUCFG_REG5_INFO_DATA + **/ +#define CPUCFG_REG5_INFO 0x5 + +/** + CPUCFG REG5 Information returned data. + #CPUCFG_REG5_INFO + **/ +typedef union { + struct { + /// + /// [Bit 15:0] Constant frequency timer and the corresponding multipli= cation factor of the + /// clock used by the timer. + /// + UINT32 CC_MUL : 16; + /// + /// [Bit 31:16] Constant frequency timer and the division coefficient = corresponding to the + /// clock used by the timer + /// + UINT32 CC_DIV : 16; + } Bits; + /// + /// All bit fields as a 32-bit value + /// + UINT32 Uint32; +} CPUCFG_REG5_INFO_DATA; + +/** + CPUCFG REG6 Information + + @code + CPUCFG_REG6_INFO_DATA + **/ +#define CPUCFG_REG6_INFO 0x6 + +/** + CPUCFG REG6 Information returned data. + #CPUCFG_REG6_INFO + **/ +typedef union { + struct { + /// + /// [Bit 0] Performance Counter. A value of 1 indicates the processor = supports performance + /// counter. + /// + UINT32 PMP : 1; + /// + /// [Bit 3:1] In the performance monitor, the architecture defines the= version number of the + /// event, and 1 is the initial version + /// + UINT32 PMVER : 3; + /// + /// [Bit 7:4] Number of performance monitors minus 1. + /// + UINT32 PMNUM : 4; + /// + /// [Bit 13:8] Number of bits of a performance monitor minus 1. + /// + UINT32 PMBITS : 6; + /// + /// [Bit 14] A value of 1 indicates the processor supports reading per= formance counter in user mode. + /// + UINT32 UPM : 1; + /// + /// [Bit 31:15] Reserved. + /// + UINT32 Reserved : 17; + } Bits; + /// + /// All bit fields as a 32-bit value + /// + UINT32 Uint32; +} CPUCFG_REG6_INFO_DATA; + +/** + CPUCFG REG16 Information + + @code + CPUCFG_REG16_INFO_DATA + **/ +#define CPUCFG_REG16_INFO 0x10 + +/** + CPUCFG REG16 Information returned data. + #CPUCFG_REG16_INFO + **/ +typedef union { + struct { + /// + /// [Bit 0] A value of 1 indicates the processor has a first-level ins= truction cache + /// or a first-level unified cache + /// + UINT32 L1_IU_Present : 1; + /// + /// [Bit 1] A value of 1 indicates that the cache shown by L1 IU_Prese= nt is the + /// unified cache. + /// + UINT32 L1_IU_Unify : 1; + /// + /// [Bit 2] A value of 1 indicates the processor has a first-level dat= a cache. + /// + UINT32 L1_D_Present : 1; + /// + /// [Bit 3] A value of 1 indicates the processor has a second-level in= struction cache + /// or a second-level unified cache. + /// + UINT32 L2_IU_Present : 1; + /// + /// [Bit 4] A value of 1 indicates that the cache shown by L2 IU_Prese= nt is the + /// unified cache. + /// + UINT32 L2_IU_Unify : 1; + /// + /// [Bit 5] A value of 1 indicates that the cache shown by L2 IU_Prese= nt is private + /// to each core. + /// + UINT32 L2_IU_Private : 1; + /// + /// [Bit 6] A value of 1 indicates that the cache shown by L2 IU_Prese= nt has an inclusive + /// relationship to the lower levels (L1). + /// + UINT32 L2_IU_Inclusive : 1; + /// + /// [Bit 7] A value of 1 indicates the processor has a second-level da= ta cache. + /// + UINT32 L2_D_Present : 1; + /// + /// [Bit 8] A value of 1 indicates that the second-level data cache is= private to each core. + /// + UINT32 L2_D_Private : 1; + /// + /// [Bit 9] A value of 1 indicates that the second-level data cache ha= s a containment + /// relationship to the lower level (L1). + /// + UINT32 L2_D_Inclusive : 1; + /// + /// [Bit 10] A value of 1 indicates the processor has a three-level in= struction cache + /// or a second-level unified Cache. + /// + UINT32 L3_IU_Present : 1; + /// + /// [Bit 11] A value of 1 indicates that the cache shown by L3 IU_Pres= ent is the + /// unified cache. + /// + UINT32 L3_IU_Unify : 1; + /// + /// [Bit 12] A value of 1 indicates that the cache shown by L3 IU_Pres= ent is private + /// to each core. + /// + UINT32 L3_IU_Private : 1; + /// + /// [Bit 13] A value of 1 indicates that the cache shown by L3 IU_Pres= ent has an inclusive + /// relationship to the lower levels (L1 and L2). + /// + UINT32 L3_IU_Inclusive : 1; + /// + /// [Bit 14] A value of 1 indicates the processor has a three-level da= ta cache. + /// + UINT32 L3_D_Present : 1; + /// + /// [Bit 15] A value of 1 indicates that the three-level data cache is= private to each core. + /// + UINT32 L3_D_Private : 1; + /// + /// [Bit 16] A value of 1 indicates that the three-level data cache ha= s a containment + /// relationship to the lower level (L1 and L2). + /// + UINT32 L3_D_Inclusive : 1; + /// + /// [Bit 31:17] Reserved. + /// + UINT32 Reserved : 15; + } Bits; + /// + /// All bit fields as a 32-bit value + /// + UINT32 Uint32; +} CPUCFG_REG16_INFO_DATA; + +/** + CPUCFG REG17, REG18, REG19 and REG20 Information + + @code + CPUCFG_CACHE_INFO_DATA + **/ +#define CPUCFG_REG17_INFO 0x11 /// L1 unified cache. +#define CPUCFG_REG18_INFO 0x12 /// L1 data cache. +#define CPUCFG_REG19_INFO 0x13 /// L2 unified cache. +#define CPUCFG_REG20_INFO 0x14 /// L3 unified cache. + +/** + CPUCFG CACHE Information returned data. + #CPUCFG_REG17_INFO + #CPUCFG_REG18_INFO + #CPUCFG_REG19_INFO + #CPUCFG_REG20_INFO + **/ +typedef union { + struct { + /// + /// [Bit 15:0] Number of channels minus 1. + /// + UINT32 Way_1 : 16; + /// + /// [Bit 23:16] Log2 (number of cache rows per channel). + /// + UINT32 Index_log2 : 8; + /// + /// [Bit 30:24] Log2 (cache row bytes). + /// + UINT32 Linesize_log2 : 7; + /// + /// [Bit 31] Reserved. + /// + UINT32 Reserved : 1; + } Bits; + /// + /// All bit fields as a 32-bit value + /// + UINT32 Uint32; +} CPUCFG_CACHE_INFO_DATA; +#endif diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 22b38b59e7..2f1e3b3d91 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -421,6 +421,7 @@ LoongArch64/SetJumpLongJump.S | GCC LoongArch64/SwitchStack.S | GCC LoongArch64/ExceptionBase.S | GCC + LoongArch64/Cpucfg.S | GCC =20 [Packages] MdePkg/MdePkg.dec diff --git a/MdePkg/Library/BaseLib/LoongArch64/Cpucfg.S b/MdePkg/Library/B= aseLib/LoongArch64/Cpucfg.S new file mode 100644 index 0000000000..8b3f842f9e --- /dev/null +++ b/MdePkg/Library/BaseLib/LoongArch64/Cpucfg.S @@ -0,0 +1,26 @@ +#-------------------------------------------------------------------------= ----- +# +# AsmCpucfg for LoongArch +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- + +ASM_GLOBAL ASM_PFX(AsmCpucfg) + +#/** +# Read CPUCFG register. +# +# @param a0 Specifies the register number of the CPUCFG to read the dat= a. +# @param a1 Pointer to the variable used to store the CPUCFG register v= alue. +# +#**/ + +ASM_PFX(AsmCpucfg): + cpucfg $t0, $a0 + stptr.d $t0, $a1, 0 + + jirl $zero, $ra, 0 + .end diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index 1d3d8327b1..f2d81af080 100644 --- a/MdePkg/MdePkg.ci.yaml +++ b/MdePkg/MdePkg.ci.yaml @@ -80,7 +80,8 @@ "Include/Register/Amd/SmramSaveStateMap.h", "Test/UnitTest/Library/DevicePathLib/TestDevicePathLib.c", "Test/UnitTest/Library/DevicePathLib/TestDevicePathLib.h", - "Test/UnitTest/Library/DevicePathLib/TestDevicePathStringConve= rsions.c" + "Test/UnitTest/Library/DevicePathLib/TestDevicePathStringConve= rsions.c", + "Include/Register/LoongArch64/Cpucfg.h" ] }, ## options defined ci/Plugin/CompilerPlugin --=20 2.27.0 -=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 (#114531): https://edk2.groups.io/g/devel/message/114531 Mute This Topic: https://groups.io/mt/103971641/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- From nobody Thu Dec 26 20:24:45 2024 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+114532+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+114532+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250521; cv=none; d=zohomail.com; s=zohoarc; b=GUy1xKMyyVknO+e/QuuyGPwi59h+YeObsLlNNtTww6YkRIS7lLCElv+WgSRnc87btl45w+ZqLTHCkws3yJOadXuQjt4Y++cdTnE8AWg+sBgKP5aIRhaYgCBLiEHxFhhMuBLfp/voaPvpsWOYBMINuv5Kg4/pkUVCH8tql5HI3Dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250521; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=HpwJPkKdbdQszk7F/R6Mhh0+ge/ZLhYcrqEfV20JdTM=; b=Z+lnwNlqNAEdozQG3bOO8EykZFpC56ILUQZu7cRLtm+Go6857wM3Kcr3WETDDg9RPpNcoYu1VLyBNDDn5zoUmNLxQsKcsVCkPAClzOFPyCdZ3OWyEA/kYQ2BzETZxvSr7wASko/r2Qcb0lduXAW9Re7ZNH+mgABl+YKQNMNkpFc= 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+114532+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250521040286.5329141393321; Thu, 25 Jan 2024 22:28:41 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=DsTIntPHdGMzUVdpP/ebKFsx3FAr4+H4pny2RZlqbsI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250520; v=1; b=RG1/y0iHW34pn3b9NyfH8qpeIFqCKmGKXeg0zGpUPNYjoZfosZrFpXteUJHQ6t63j5ciML3S BFs6h/gGRMB7dryqqMSsepmQ8mFMiIq6+7Zf/XwRTT9jO1j8CmSt3ZFwGNG8gmocZirTg2y0yiF xODatcuc3xDDLU6faxFM1Acw= X-Received: by 127.0.0.2 with SMTP id xT4tYY1788612xqtSxr0KJoI; Thu, 25 Jan 2024 22:28:40 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.9985.1706250519328999185 for ; Thu, 25 Jan 2024 22:28:40 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxmegUUbNlth0GAA--.2183S3; Fri, 26 Jan 2024 14:28:36 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxRMwTUbNlk3EbAA--.44265S2; Fri, 26 Jan 2024 14:28:35 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v8 06/37] MdePkg: Add read stable counter operation for LoongArch Date: Fri, 26 Jan 2024 14:28:34 +0800 Message-Id: <20240126062834.3101159-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxRMwTUbNlk3EbAA--.44265S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQA-sg X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: BHLOnl0mG2912RpMeIdQLZnMx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250522076100001 Content-Type: text/plain; charset="utf-8" Add LoongArch gets stable counter ASM function. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Acked-by: Michael D Kinney Reviewed-by: Liming Gao --- MdePkg/Include/Library/BaseLib.h | 12 ++++++++++ MdePkg/Library/BaseLib/BaseLib.inf | 1 + .../BaseLib/LoongArch64/ReadStableCounter.S | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 MdePkg/Library/BaseLib/LoongArch64/ReadStableCounter.S diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index d64e406b7c..29009adbc9 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -339,6 +339,18 @@ AsmCpucfg ( OUT UINT32 *Data ); =20 +/** + Gets the timer count value. + + @param[] VOID + @retval timer count value. + +**/ +UINTN +AsmReadStableCounter ( + VOID + ); + #endif // defined (MDE_CPU_LOONGARCH64) =20 // diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 2f1e3b3d91..1dad587b0c 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -422,6 +422,7 @@ LoongArch64/SwitchStack.S | GCC LoongArch64/ExceptionBase.S | GCC LoongArch64/Cpucfg.S | GCC + LoongArch64/ReadStableCounter.S | GCC =20 [Packages] MdePkg/MdePkg.dec diff --git a/MdePkg/Library/BaseLib/LoongArch64/ReadStableCounter.S b/MdePk= g/Library/BaseLib/LoongArch64/ReadStableCounter.S new file mode 100644 index 0000000000..aa74ff603e --- /dev/null +++ b/MdePkg/Library/BaseLib/LoongArch64/ReadStableCounter.S @@ -0,0 +1,24 @@ +#-------------------------------------------------------------------------= ----- +# +# LoongArch Read Stable Counter +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- + +ASM_GLOBAL ASM_PFX(AsmReadStableCounter) + +#/** +# Gets the timer count value. +# +# @param[] VOID +# @retval timer count value. +# +#**/ + +ASM_PFX(AsmReadStableCounter): + rdtime.d $a0, $zero + jirl $zero, $ra, 0 + .end --=20 2.27.0 -=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 (#114532): https://edk2.groups.io/g/devel/message/114532 Mute This Topic: https://groups.io/mt/103971643/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- From nobody Thu Dec 26 20:24:45 2024 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+114533+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+114533+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250524; cv=none; d=zohomail.com; s=zohoarc; b=WiQnREbAHXeIJ9SHeGabCWwdKVPc+K+DKHKrbe6flHm80wid0PwqYlVU8qb0NKFJ2/sn+yMh7anNCfTVS8j4Y8uTcYjuqrJCRwqO4J9ojFjYiu3B4mkaAa8ja1K/8T5DA8TkHCQNJD7bTf0hja9zJjoMzbqPvQWTmJOL0u1AgAo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250524; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=ETmL1grIUxckdSwtVeMQ6E8NKg0GpP6qSp+PV5ataWU=; b=MtWss0cGfToxYSXX69ZwZnKKf4PCtKb6wiwFD+QdOD+UFo8QmrIUE3BJw0be9Fz6HXG+Q2/Zt81NkKvglIrvMz2ErigEQZw0eUo99qX6Ok9xYsVdwThbMlnL7SCK3i/Bl5QhgLsSnzIolW5Hs25H32jGXK2kTY3/qQdgjiMzkyM= 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+114533+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250524770284.9515185672391; Thu, 25 Jan 2024 22:28:44 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=xTsV1Woy21GifSdGv+NK7Z65fjCKeZggzdTRffEJ5sU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250524; v=1; b=RM5UMfQMwSQ3YAx8OSGBdSJ/11/m0tSt9zC1Zyk5o/vpSh1dUuBQd7OHOdRGqs6VctxA1NZV Vv1cLTa9Ud5UMZBETMLrhKTPaqjd9G1mIrNOwbb2pKToAQiv2GLrKefP/+3meyyAwoWd287yIOr WF1rjhZmCQBtKAmbTUuZtPM0= X-Received: by 127.0.0.2 with SMTP id RIQ2YY1788612xUiR3tgHDij; Thu, 25 Jan 2024 22:28:44 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.9986.1706250523182190356 for ; Thu, 25 Jan 2024 22:28:44 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8Axz+sYUbNlwB0GAA--.21574S3; Fri, 26 Jan 2024 14:28:40 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxX88YUbNln3EbAA--.53203S2; Fri, 26 Jan 2024 14:28:40 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Bibo Mao Subject: [edk2-devel] [PATCH v8 07/37] MdePkg: Add CSR operation for LoongArch Date: Fri, 26 Jan 2024 14:28:39 +0800 Message-Id: <20240126062839.3101222-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxX88YUbNln3EbAA--.53203S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBBse X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: YhHH5Qgh88hi7bXDb7aGDkmNx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250526115100001 Content-Type: text/plain; charset="utf-8" Add CsrRead, CsrWrite and CsrXChg functions for LoongArch, and use them to operate the CSR register of LoongArch architecture. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Co-authored-by: Bibo Mao Acked-by: Michael D Kinney Reviewed-by: Liming Gao --- MdePkg/Include/Library/BaseLib.h | 45 +++ MdePkg/Library/BaseLib/BaseLib.inf | 2 + MdePkg/Library/BaseLib/LoongArch64/AsmCsr.S | 422 ++++++++++++++++++++ MdePkg/Library/BaseLib/LoongArch64/Csr.c | 81 ++++ 4 files changed, 550 insertions(+) create mode 100644 MdePkg/Library/BaseLib/LoongArch64/AsmCsr.S create mode 100644 MdePkg/Library/BaseLib/LoongArch64/Csr.c diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 29009adbc9..4e97368ae2 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -351,6 +351,51 @@ AsmReadStableCounter ( VOID ); =20 +/** + CSR read operation. + + @param[in] Select CSR read instruction select values. + + @return The return value of csrrd instruction, return -1 means no CS= R instruction + is found. +**/ +UINTN +CsrRead ( + IN UINT16 Select + ); + +/** + CSR write operation. + + @param[in] Select CSR write instruction select values. + @param[in] Value The csrwr will write the value. + + @return The return value of csrwr instruction, that is, store the ol= d value of + the register, return -1 means no CSR instruction is found. +**/ +UINTN +CsrWrite ( + IN UINT16 Select, + IN UINTN Value + ); + +/** + CSR exchange operation. + + @param[in] Select CSR exchange instruction select values. + @param[in] Value The csrxchg will write the value. + @param[in] Mask The csrxchg mask value. + + @return The return value of csrxchg instruction, that is, store the = old value of + the register, return -1 means no CSR instruction is found. +**/ +UINTN +CsrXChg ( + IN UINT16 Select, + IN UINTN Value, + IN UINTN Mask + ); + #endif // defined (MDE_CPU_LOONGARCH64) =20 // diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 1dad587b0c..7c46306883 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -410,7 +410,9 @@ [Sources.LOONGARCH64] Math64.c Unaligned.c + LoongArch64/Csr.c LoongArch64/InternalSwitchStack.c + LoongArch64/AsmCsr.S | GCC LoongArch64/GetInterruptState.S | GCC LoongArch64/EnableInterrupts.S | GCC LoongArch64/DisableInterrupts.S | GCC diff --git a/MdePkg/Library/BaseLib/LoongArch64/AsmCsr.S b/MdePkg/Library/B= aseLib/LoongArch64/AsmCsr.S new file mode 100644 index 0000000000..3a879411f5 --- /dev/null +++ b/MdePkg/Library/BaseLib/LoongArch64/AsmCsr.S @@ -0,0 +1,422 @@ +#-------------------------------------------------------------------------= ----- +# +# LoongArch ASM CSR operation functions +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- + +#include + +ASM_GLOBAL ASM_PFX (AsmCsrRead) +ASM_GLOBAL ASM_PFX (AsmCsrWrite) +ASM_GLOBAL ASM_PFX (AsmCsrXChg) + +.macro AsmCsrRd Sel + csrrd $a0, \Sel + jirl $zero, $ra, 0 +.endm + +.macro AsmCsrWr Sel + csrwr $a0, \Sel + jirl $zero, $ra, 0 +.endm + +.macro AsmCsrXChange Sel + csrxchg $a0, $a1, \Sel + jirl $zero, $ra, 0 +.endm + +ASM_PFX(AsmCsrRead): + blt $a0, $zero, ReadSelNumErr + li.w $t0, LOONGARCH_CSR_EBASE + bltu $t0, $a0, TlbCsrRd + +BasicCsrRd: + la.pcrel $t0, BasicCsrRead + alsl.d $t0, $a0, $t0, 3 + jirl $zero, $t0, 0 + +TlbCsrRd: + li.w $t0, LOONGARCH_CSR_TLBIDX + bltu $a0, $t0, ReadSelNumErr + li.w $t0, LOONGARCH_CSR_RVACFG + bltu $t0, $a0, CfgCsrRd + la.pcrel $t0, TlbCsrRead + addi.w $t1, $a0, -LOONGARCH_CSR_TLBIDX + alsl.d $t0, $t1, $t0, 3 + jirl $zero, $t0, 0 + +CfgCsrRd: + li.w $t0, LOONGARCH_CSR_CPUNUM + bltu $a0, $t0, ReadSelNumErr + li.w $t0, LOONGARCH_CSR_PRCFG3 + bltu $t0, $a0, KcsCsrRd + la.pcrel $t0, CfgCsrRead + addi.w $t1, $a0, -LOONGARCH_CSR_CPUNUM + alsl.d $t0, $t1, $t0, 3 + jirl $zero, $t0, 0 + +KcsCsrRd: + li.w $t0, LOONGARCH_CSR_KS0 + bltu $a0, $t0, ReadSelNumErr + li.w $t0, LOONGARCH_CSR_KS8 + bltu $t0, $a0, StableTimerCsrRd + la.pcrel $t0, KcsCsrRead + addi.w $t1, $a0, -LOONGARCH_CSR_KS0 + alsl.d $t0, $t1, $t0, 3 + jirl $zero, $t0, 0 + +StableTimerCsrRd: + li.w $t0, LOONGARCH_CSR_TMID + bltu $a0, $t0, ReadSelNumErr + li.w $t0, LOONGARCH_CSR_TINTCLR + bltu $t0, $a0, TlbRefillCsrRd + la.pcrel $t0, StableTimerCsrRead + addi.w $t1, $a0, -LOONGARCH_CSR_TMID + alsl.d $t0, $t1, $t0, 3 + jirl $zero, $t0, 0 + +TlbRefillCsrRd: + li.w $t0, LOONGARCH_CSR_TLBREBASE + bltu $a0, $t0, ReadSelNumErr + li.w $t0, LOONGARCH_CSR_TLBREHI + bltu $t0, $a0, DirMapCsrRd + la.pcrel $t0, TlbRefillCsrRead + addi.w $t1, $a0, -LOONGARCH_CSR_TLBREBASE + alsl.d $t0, $t1, $t0, 3 + jirl $zero, $t0, 0 + +DirMapCsrRd: + li.w $t0, LOONGARCH_CSR_DMWIN0 + bltu $a0, $t0, ReadSelNumErr + li.w $t0, LOONGARCH_CSR_DMWIN3 + bltu $t0, $a0, ReadSelNumErr + la.pcrel $t0, DirMapCsrRead + addi.w $t1, $a0, -LOONGARCH_CSR_DMWIN0 + alsl.d $t0, $t1, $t0, 3 + jirl $zero, $t0, 0 + +ReadSelNumErr: + addi.d $a0, $zero, -1 + jirl $zero, $ra, 0 + +BasicCsrRead: + CsrSel =3D LOONGARCH_CSR_CRMD + .rept LOONGARCH_CSR_EBASE - LOONGARCH_CSR_CRMD + 1 + AsmCsrRd CsrSel + CsrSel =3D CsrSel + 1 + .endr + +TlbCsrRead: + CsrSel =3D LOONGARCH_CSR_TLBIDX + .rept LOONGARCH_CSR_RVACFG - LOONGARCH_CSR_TLBIDX + 1 + AsmCsrRd CsrSel + CsrSel =3D CsrSel + 1 + .endr + +CfgCsrRead: + CsrSel =3D LOONGARCH_CSR_CPUNUM + .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUNUM + 1 + AsmCsrRd CsrSel + CsrSel =3D CsrSel + 1 + .endr + +KcsCsrRead: + CsrSel =3D LOONGARCH_CSR_KS0 + .rept LOONGARCH_CSR_KS8 - LOONGARCH_CSR_KS0 + 1 + AsmCsrRd CsrSel + CsrSel =3D CsrSel + 1 + .endr + +StableTimerCsrRead: + CsrSel =3D LOONGARCH_CSR_TMID + .rept LOONGARCH_CSR_TINTCLR - LOONGARCH_CSR_TMID + 1 + AsmCsrRd CsrSel + CsrSel =3D CsrSel + 1 + .endr + +TlbRefillCsrRead: + CsrSel =3D LOONGARCH_CSR_TLBREBASE + .rept LOONGARCH_CSR_TLBREHI - LOONGARCH_CSR_TLBREBASE + 1 + AsmCsrRd CsrSel + CsrSel =3D CsrSel + 1 + .endr + +DirMapCsrRead: + CsrSel =3D LOONGARCH_CSR_DMWIN0 + .rept LOONGARCH_CSR_DMWIN3 - LOONGARCH_CSR_DMWIN0 + 1 + AsmCsrRd CsrSel + CsrSel =3D CsrSel + 1 + .endr + +ASM_PFX(AsmCsrWrite): + blt $a0, $zero, WriteSelNumErr + li.w $t0, LOONGARCH_CSR_EBASE + bltu $t0, $a0, TlbCsrWr + +BasicCsrWr: + la.pcrel $t0, BasicCsrWrite + alsl.d $t0, $a0, $t0, 3 + move $a0, $a1 + jirl $zero, $t0, 0 + +TlbCsrWr: + li.w $t0, LOONGARCH_CSR_TLBIDX + bltu $a0, $t0, WriteSelNumErr + li.w $t0, LOONGARCH_CSR_RVACFG + bltu $t0, $a0, CfgCsrWr + la.pcrel $t0, TlbCsrWrite + addi.w $t1, $a0, -LOONGARCH_CSR_TLBIDX + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + jirl $zero, $t0, 0 + +CfgCsrWr: + li.w $t0, LOONGARCH_CSR_CPUNUM + bltu $a0, $t0, WriteSelNumErr + li.w $t0, LOONGARCH_CSR_PRCFG3 + bltu $t0, $a0, KcsCsrWr + la.pcrel $t0, CfgCsrWrite + addi.w $t1, $a0, -LOONGARCH_CSR_CPUNUM + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + jirl $zero, $t0, 0 + +KcsCsrWr: + li.w $t0, LOONGARCH_CSR_KS0 + bltu $a0, $t0, WriteSelNumErr + li.w $t0, LOONGARCH_CSR_KS8 + bltu $t0, $a0, StableTimerCsrWr + la.pcrel $t0, KcsCsrWrite + addi.w $t1, $a0, -LOONGARCH_CSR_KS0 + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + jirl $zero, $t0, 0 + +StableTimerCsrWr: + li.w $t0, LOONGARCH_CSR_TMID + bltu $a0, $t0, WriteSelNumErr + li.w $t0, LOONGARCH_CSR_TINTCLR + bltu $t0, $a0, TlbRefillCsrWr + la.pcrel $t0, StableTimerCsrWrite + addi.w $t1, $a0, -LOONGARCH_CSR_TMID + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + jirl $zero, $t0, 0 + +TlbRefillCsrWr: + li.w $t0, LOONGARCH_CSR_TLBREBASE + bltu $a0, $t0, WriteSelNumErr + li.w $t0, LOONGARCH_CSR_TLBREHI + bltu $t0, $a0, DirMapCsrWr + la.pcrel $t0, TlbRefillCsrWrite + addi.w $t1, $a0, -LOONGARCH_CSR_TLBREBASE + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + jirl $zero, $t0, 0 + +DirMapCsrWr: + li.w $t0, LOONGARCH_CSR_DMWIN0 + bltu $a0, $t0, WriteSelNumErr + li.w $t0, LOONGARCH_CSR_DMWIN3 + bltu $t0, $a0, WriteSelNumErr + la.pcrel $t0, DirMapCsrWrite + addi.w $t1, $a0, -LOONGARCH_CSR_DMWIN0 + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + jirl $zero, $t0, 0 + +WriteSelNumErr: + addi.d $a0, $zero, -1 + jirl $zero, $ra, 0 + +BasicCsrWrite: + CsrSel =3D LOONGARCH_CSR_CRMD + .rept LOONGARCH_CSR_EBASE - LOONGARCH_CSR_CRMD + 1 + AsmCsrWr CsrSel + CsrSel =3D CsrSel + 1 + .endr + +TlbCsrWrite: + CsrSel =3D LOONGARCH_CSR_TLBIDX + .rept LOONGARCH_CSR_RVACFG - LOONGARCH_CSR_TLBIDX + 1 + AsmCsrWr CsrSel + CsrSel =3D CsrSel + 1 + .endr + +CfgCsrWrite: + CsrSel =3D LOONGARCH_CSR_CPUNUM + .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUNUM + 1 + AsmCsrWr CsrSel + CsrSel =3D CsrSel + 1 + .endr + +KcsCsrWrite: + CsrSel =3D LOONGARCH_CSR_KS0 + .rept LOONGARCH_CSR_KS8 - LOONGARCH_CSR_KS0 + 1 + AsmCsrWr CsrSel + CsrSel =3D CsrSel + 1 + .endr + +StableTimerCsrWrite: + CsrSel =3D LOONGARCH_CSR_TMID + .rept LOONGARCH_CSR_TINTCLR - LOONGARCH_CSR_TMID + 1 + AsmCsrWr CsrSel + CsrSel =3D CsrSel + 1 + .endr + +TlbRefillCsrWrite: + CsrSel =3D LOONGARCH_CSR_TLBREBASE + .rept LOONGARCH_CSR_TLBREHI - LOONGARCH_CSR_TLBREBASE + 1 + AsmCsrWr CsrSel + CsrSel =3D CsrSel + 1 + .endr + +DirMapCsrWrite: + CsrSel =3D LOONGARCH_CSR_DMWIN0 + .rept LOONGARCH_CSR_DMWIN3 - LOONGARCH_CSR_DMWIN0 + 1 + AsmCsrWr CsrSel + CsrSel =3D CsrSel + 1 + .endr + + +ASM_PFX(AsmCsrXChg): + blt $a0, $zero, XchgSelNumErr + li.w $t0, LOONGARCH_CSR_EBASE + bltu $t0, $a0, TlbCsrXchg + +BasicCsrXchg: + la.pcrel $t0, BasicCsrXchange + alsl.d $t0, $a0, $t0, 3 + move $a0, $a1 + move $a1, $a2 + jirl $zero, $t0, 0 + +TlbCsrXchg: + li.w $t0, LOONGARCH_CSR_TLBIDX + bltu $a0, $t0, XchgSelNumErr + li.w $t0, LOONGARCH_CSR_RVACFG + bltu $t0, $a0, CfgCsrXchg + la.pcrel $t0, TlbCsrXchange + addi.w $t1, $a0, -LOONGARCH_CSR_TLBIDX + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + move $a1, $a2 + jirl $zero, $t0, 0 + +CfgCsrXchg: + li.w $t0, LOONGARCH_CSR_CPUNUM + bltu $a0, $t0, XchgSelNumErr + li.w $t0, LOONGARCH_CSR_PRCFG3 + bltu $t0, $a0, KcsCsrXchg + la.pcrel $t0, CfgCsrXchange + addi.w $t1, $a0, -LOONGARCH_CSR_CPUNUM + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + move $a1, $a2 + jirl $zero, $t0, 0 + +KcsCsrXchg: + li.w $t0, LOONGARCH_CSR_KS0 + bltu $a0, $t0, XchgSelNumErr + li.w $t0, LOONGARCH_CSR_KS8 + bltu $t0, $a0, StableTimerCsrXchg + la.pcrel $t0, KcsCsrXchange + addi.w $t1, $a0, -LOONGARCH_CSR_KS0 + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + move $a1, $a2 + jirl $zero, $t0, 0 + +StableTimerCsrXchg: + li.w $t0, LOONGARCH_CSR_TMID + bltu $a0, $t0, XchgSelNumErr + li.w $t0, LOONGARCH_CSR_TINTCLR + bltu $t0, $a0, TlbRefillCsrXchg + la.pcrel $t0, StableTimerCsrXchange + addi.w $t1, $a0, -LOONGARCH_CSR_TMID + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + move $a1, $a2 + jirl $zero, $t0, 0 + +TlbRefillCsrXchg: + li.w $t0, LOONGARCH_CSR_TLBREBASE + bltu $a0, $t0, XchgSelNumErr + li.w $t0, LOONGARCH_CSR_TLBREHI + bltu $t0, $a0, DirMapCsrXchg + la.pcrel $t0, TlbRefillCsrXchange + addi.w $t1, $a0, -LOONGARCH_CSR_TLBREBASE + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + move $a1, $a2 + jirl $zero, $t0, 0 + +DirMapCsrXchg: + li.w $t0, LOONGARCH_CSR_DMWIN0 + bltu $a0, $t0, XchgSelNumErr + li.w $t0, LOONGARCH_CSR_DMWIN3 + bltu $t0, $a0, XchgSelNumErr + la.pcrel $t0, DirMapCsrXchange + addi.w $t1, $a0, -LOONGARCH_CSR_DMWIN0 + alsl.d $t0, $t1, $t0, 3 + move $a0, $a1 + move $a1, $a2 + jirl $zero, $t0, 0 + +XchgSelNumErr: + addi.d $a0, $zero, -1 + jirl $zero, $ra, 0 + +BasicCsrXchange: + CsrSel =3D LOONGARCH_CSR_CRMD + .rept LOONGARCH_CSR_EBASE - LOONGARCH_CSR_CRMD + 1 + AsmCsrXChange CsrSel + CsrSel =3D CsrSel + 1 + .endr + +TlbCsrXchange: + CsrSel =3D LOONGARCH_CSR_TLBIDX + .rept LOONGARCH_CSR_RVACFG - LOONGARCH_CSR_TLBIDX + 1 + AsmCsrXChange CsrSel + CsrSel =3D CsrSel + 1 + .endr + +CfgCsrXchange: + CsrSel =3D LOONGARCH_CSR_CPUNUM + .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUNUM + 1 + AsmCsrXChange CsrSel + CsrSel =3D CsrSel + 1 + .endr + +KcsCsrXchange: + CsrSel =3D LOONGARCH_CSR_KS0 + .rept LOONGARCH_CSR_KS8 - LOONGARCH_CSR_KS0 + 1 + AsmCsrXChange CsrSel + CsrSel =3D CsrSel + 1 + .endr + +StableTimerCsrXchange: + CsrSel =3D LOONGARCH_CSR_TMID + .rept LOONGARCH_CSR_TINTCLR - LOONGARCH_CSR_TMID + 1 + AsmCsrXChange CsrSel + CsrSel =3D CsrSel + 1 + .endr + +TlbRefillCsrXchange: + CsrSel =3D LOONGARCH_CSR_TLBREBASE + .rept LOONGARCH_CSR_TLBREHI - LOONGARCH_CSR_TLBREBASE + 1 + AsmCsrXChange CsrSel + CsrSel =3D CsrSel + 1 + .endr + +DirMapCsrXchange: + CsrSel =3D LOONGARCH_CSR_DMWIN0 + .rept LOONGARCH_CSR_DMWIN3 - LOONGARCH_CSR_DMWIN0 + 1 + AsmCsrXChange CsrSel + CsrSel =3D CsrSel + 1 + .endr +.end diff --git a/MdePkg/Library/BaseLib/LoongArch64/Csr.c b/MdePkg/Library/Base= Lib/LoongArch64/Csr.c new file mode 100644 index 0000000000..f2ec80b38d --- /dev/null +++ b/MdePkg/Library/BaseLib/LoongArch64/Csr.c @@ -0,0 +1,81 @@ +/** @file + LoongArch CSR operation functions. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +UINTN +AsmCsrRead ( + IN UINT16 Select + ); + +UINTN +AsmCsrWrite ( + IN UINT16 Select, + IN UINTN Value + ); + +UINTN +AsmCsrXChg ( + IN UINT16 Select, + IN UINTN Value, + IN UINTN Mask + ); + +/** + CSR read operation. + + @param[in] Select CSR read instruction select values. + + @return The return value of csrrd instruction, return -1 means Selec= t is out of support. +**/ +UINTN +EFIAPI +CsrRead ( + IN UINT16 Select + ) +{ + return AsmCsrRead (Select); +} + +/** + CSR write operation. + + @param[in] Select CSR write instruction select values. + @param[in, out] Value The csrwr will write the value. + + @return The return value of csrwr instruction, that is, store the ol= d value of + the register, return -1 means Select is out of support. +**/ +UINTN +EFIAPI +CsrWrite ( + IN UINT16 Select, + IN OUT UINTN Value + ) +{ + return AsmCsrWrite (Select, Value); +} + +/** + CSR exchange operation. + + @param[in] Select CSR exchange instruction select values. + @param[in, out] Value The csrxchg will write the value. + @param[in] Mask The csrxchg mask value. + + @return The return value of csrxchg instruction, that is, store the = old value of + the register, return -1 means Select is out of support. +**/ +UINTN +EFIAPI +CsrXChg ( + IN UINT16 Select, + IN OUT UINTN Value, + IN UINTN Mask + ) +{ + return AsmCsrXChg (Select, Value, Mask); +} --=20 2.27.0 -=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 (#114533): https://edk2.groups.io/g/devel/message/114533 Mute This Topic: https://groups.io/mt/103971645/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- From nobody Thu Dec 26 20:24:45 2024 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+114534+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+114534+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250538; cv=none; d=zohomail.com; s=zohoarc; b=LdDKnJRWvIFW64hlp/rcnPQzgymv/gDQojUT58f1nd6+va0mt8FrmdWrkvL/7eFl73cZHJz92iW7+7A/lEZHOWVHtOeemQiRxNw5xYb4/0WAO4CyJ01zpy08iWU+Znygx/EHUbbhK09mzJ0RWgpoo9hR8IMXzD0gsJJhtV96/5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250538; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=XWH2fpF+JzG99p7VNWwLPrKUBGW9gvKSg97yjmfh0Uo=; b=dUxZJc2Qwf25nnFXNhgltX23BjcdtlEhAsauEcgQMr4Phppp1R6+bgujLHs0ka3JEC0EdvOSRI3jo1CasqnxvwOQFJAzMxAHr1SAnegf+4Z8fqyiJWkhCdNZGF9AJXLWjCYjsF+ba8NWGSC6rBNX9EP5mDChpjaOXjiEVTecPRI= 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+114534+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250538113864.6886339333474; Thu, 25 Jan 2024 22:28:58 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=b1eahRE6clZnImgKY8cbQXJ017sYKuMOQlDWggbSslU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250532; v=1; b=dc3QoMhEACgSB+kQzsAyluEOJ2xN+9Mye1ROElzipJ7rlOlLCK60kYsBXyNw2ISmH6T9ywHk MeHNt05FC/DN1s/801gD1mYqIe3aA/JIqDw+WhWXJhXjtWxfjs0OkJ73TFeaDpPetzD26wN/mZa A2J6KdHgcId4wMuFpnaMo1RM= X-Received: by 127.0.0.2 with SMTP id abXrYY1788612xyDpcxjdZZq; Thu, 25 Jan 2024 22:28:52 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.9990.1706250531502387173 for ; Thu, 25 Jan 2024 22:28:52 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8AxafAfUbNlyx0GAA--.22086S3; Fri, 26 Jan 2024 14:28:47 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxTs0dUbNlv3EbAA--.51205S2; Fri, 26 Jan 2024 14:28:45 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v8 08/37] MdePkg: Add IOCSR operation for LoongArch Date: Fri, 26 Jan 2024 14:28:44 +0800 Message-Id: <20240126062844.3101286-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxTs0dUbNlv3EbAA--.51205S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBDsc X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 3aNu3UqQRNXLLIbYkuxV3V9ux1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250540131100003 Content-Type: text/plain; charset="utf-8" Add IoCsrRead8, IoCsrRead16, IoCsrRead32, IoCsrRead64, IoCsrWrite8, IoCsrWrite16, IoCsrWrite32, IoCsrWrite64 to operate the IOCSR registers of LoongArch architecture. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Acked-by: Michael D Kinney Reviewed-by: Liming Gao --- MdePkg/Include/Library/BaseLib.h | 112 +++++++++++++++++++ MdePkg/Library/BaseLib/BaseLib.inf | 1 + MdePkg/Library/BaseLib/LoongArch64/IoCsr.S | 120 +++++++++++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 MdePkg/Library/BaseLib/LoongArch64/IoCsr.S diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 4e97368ae2..1fff0fb224 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -396,6 +396,118 @@ CsrXChg ( IN UINTN Mask ); =20 +/** + IO CSR read byte operation. + + @param[in] Select IO CSR read instruction select values. + + @return The return value of iocsrrd.b instruction. + +**/ +UINT8 +IoCsrRead8 ( + IN UINTN Select + ); + +/** + IO CSR read half word operation. + + @param[in] Select IO CSR read instruction select values. + + @return The return value of iocsrrd.h instruction. + +**/ +UINT16 +IoCsrRead16 ( + IN UINTN Select + ); + +/** + IO CSR read word operation. + + @param[in] Select IO CSR read instruction select values. + + @return The return value of iocsrrd.w instruction. + +**/ +UINT32 +IoCsrRead32 ( + IN UINTN Select + ); + +/** + IO CSR read double word operation. Only for LoongArch64. + + @param[in] Select IO CSR read instruction select values. + + @return The return value of iocsrrd.d instruction. + +**/ +UINT64 +IoCsrRead64 ( + IN UINTN Select + ); + +/** + IO CSR write byte operation. + + @param[in] Select IO CSR write instruction select values. + @param[in] Value The iocsrwr.b will write the value. + + @return VOID. + +**/ +VOID +IoCsrWrite8 ( + IN UINTN Select, + IN UINT8 Value + ); + +/** + IO CSR write half word operation. + + @param[in] Select IO CSR write instruction select values. + @param[in] Value The iocsrwr.h will write the value. + + @return VOID. + +**/ +VOID +IoCsrWrite16 ( + IN UINTN Select, + IN UINT16 Value + ); + +/** + IO CSR write word operation. + + @param[in] Select IO CSR write instruction select values. + @param[in] Value The iocsrwr.w will write the value. + + @return VOID. + +**/ +VOID +IoCsrWrite32 ( + IN UINTN Select, + IN UINT32 Value + ); + +/** + IO CSR write double word operation. Only for LoongArch64. + + @param[in] Select IO CSR write instruction select values. + @param[in] Value The iocsrwr.d will write the value. + + @return VOID. + +**/ +VOID +IoCsrWrite64 ( + IN UINTN Select, + IN UINT64 Value + ); + #endif // defined (MDE_CPU_LOONGARCH64) =20 // diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 7c46306883..4dbe94be71 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -413,6 +413,7 @@ LoongArch64/Csr.c LoongArch64/InternalSwitchStack.c LoongArch64/AsmCsr.S | GCC + LoongArch64/IoCsr.S | GCC LoongArch64/GetInterruptState.S | GCC LoongArch64/EnableInterrupts.S | GCC LoongArch64/DisableInterrupts.S | GCC diff --git a/MdePkg/Library/BaseLib/LoongArch64/IoCsr.S b/MdePkg/Library/Ba= seLib/LoongArch64/IoCsr.S new file mode 100644 index 0000000000..a659908bc4 --- /dev/null +++ b/MdePkg/Library/BaseLib/LoongArch64/IoCsr.S @@ -0,0 +1,120 @@ +#-------------------------------------------------------------------------= ----- +# +# LoongArch ASM IO CSR operation functions +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- + +ASM_GLOBAL ASM_PFX (IoCsrRead8) +ASM_GLOBAL ASM_PFX (IoCsrRead16) +ASM_GLOBAL ASM_PFX (IoCsrRead32) +ASM_GLOBAL ASM_PFX (IoCsrRead64) + +ASM_GLOBAL ASM_PFX (IoCsrWrite8) +ASM_GLOBAL ASM_PFX (IoCsrWrite16) +ASM_GLOBAL ASM_PFX (IoCsrWrite32) +ASM_GLOBAL ASM_PFX (IoCsrWrite64) + +#/** +# IO CSR read byte operation. +# +# @param[in] Select IO CSR read instruction select values. +# +# @return The return value of iocsrrd.b instruction. +# +#**/ +ASM_PFX (IoCsrRead8): + iocsrrd.b $a0, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR read half word operation. +# +# @param[in] Select IO CSR read instruction select values. +# +# @return The return value of iocsrrd.h instruction. +# +#**/ +ASM_PFX (IoCsrRead16): + iocsrrd.h $a0, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR read word operation. +# +# @param[in] Select IO CSR read instruction select values. +# +# @return The return value of iocsrrd.w instruction. +# +#**/ +ASM_PFX (IoCsrRead32): + iocsrrd.w $a0, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR read double word operation. Only for LoongArch64. +# +# @param[in] Select IO CSR read instruction select values. +# +# @return The return value of iocsrrd.d instruction. +# +#**/ +ASM_PFX (IoCsrRead64): + iocsrrd.d $a0, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR write byte operation. +# +# @param[in] Select IO CSR write instruction select values. +# @param[in] Value The iocsrwr.b will write the value. +# +# @return VOID. +# +#**/ +ASM_PFX (IoCsrWrite8): + iocsrwr.b $a1, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR write half word operation. +# +# @param[in] Select IO CSR write instruction select values. +# @param[in] Value The iocsrwr.h will write the value. +# +# @return VOID. +# +#**/ +ASM_PFX (IoCsrWrite16): + iocsrwr.h $a1, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR write word operation. +# +# @param[in] Select IO CSR write instruction select values. +# @param[in] Value The iocsrwr.w will write the value. +# +# @return VOID. +# +#**/ +ASM_PFX (IoCsrWrite32): + iocsrwr.w $a1, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR write double word operation. Only for LoongArch64. +# +# @param[in] Select IO CSR write instruction select values. +# @param[in] Value The iocsrwr.d will write the value. +# +# @return VOID. +# +#**/ +ASM_PFX (IoCsrWrite64): + iocsrwr.d $a1, $a0 + jirl $zero, $ra, 0 + .end --=20 2.27.0 -=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 (#114534): https://edk2.groups.io/g/devel/message/114534 Mute This Topic: https://groups.io/mt/103971647/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- From nobody Thu Dec 26 20:24:45 2024 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+114535+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+114535+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250538; cv=none; d=zohomail.com; s=zohoarc; b=emVzmT+5FzeY847R4zzj58bWjxrpnbGnQCsZc/jZMCy3qRk85TKkkMISpK73abYEsN9IrSP7767ovs+UK4ws3F5C2Tqi0oeFbWQHMxAb+cdNBiO15mzkkOO+uJejcK1qHZ9enLgW34BuOgN2Ei/ok+C6dE2gr4f4keuWw5JYcTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250538; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=KOFC/7oLU1bQqw98UjcNzVYIhU7385/K3iaQjADkhPs=; b=Z4j0pHqxpi3eljoMMd/sbrGrkTc243G4CocvdFzeYPtAMymkJUuDkgzLbhOR+I7PRr7iXEaVSUN2pyl/n9jNOPcvddjsGyrMBnb1a1D7TW66RqOGRuMz/y8H4wt6275QDlevy2adL+qZNfIVQvW0zbigofQowgHZcPCWL7XKNLo= 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+114535+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250538459372.4590890987756; Thu, 25 Jan 2024 22:28:58 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=ETLwnMSQl3XZrBbBiyWFT/qkDCH68XJZiSEYe23nsPo=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250538; v=1; b=ER3tj++B24nPYnoST2fQFInXdX+eY5WX9qLotT6yYmDOEJ6ObC3zSl/HXL95/q3opUGHy4OJ nYFaO5/c7rAmukgYo/xFwp1/mENRiNjIveeoTRZFL6Ho8dRT0Da6VEIpMZm2Zyc98x7RwV7nHQw DNgqUoIsWtO5kt3XY1l3WxuQ= X-Received: by 127.0.0.2 with SMTP id mzQSYY1788612xLFLKiJd0yx; Thu, 25 Jan 2024 22:28:58 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10124.1706250534602827830 for ; Thu, 25 Jan 2024 22:28:55 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8DxK+kkUbNl0h0GAA--.3085S3; Fri, 26 Jan 2024 14:28:52 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx8OQiUbNl2HEbAA--.53163S2; Fri, 26 Jan 2024 14:28:50 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Laszlo Ersek Subject: [edk2-devel] [PATCH v8 09/37] MdePkg: Add a new library named PeiServicesTablePointerLibKs0 Date: Fri, 26 Jan 2024 14:28:49 +0800 Message-Id: <20240126062849.3101358-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx8OQiUbNl2HEbAA--.53163S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBEsb X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: uCzQqtI6I5o2F6Tn7PVNQJzHx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250540152100004 Content-Type: text/plain; charset="utf-8" Adding PeiServicesTablePointerLibKs0 for LoongArch64, which provides setting and getting the PEI service table pointer through the CSR KS0 register. The idea of this library is derived from ArmPkg/Library/PeiServicesTablePointerLib/ BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Laszlo Ersek Signed-off-by: Chao Li Reviewed-by: Liming Gao --- .../Library/PeiServicesTablePointerLib.h | 9 +- .../PeiServicesTablePointer.c | 87 +++++++++++++++++++ .../PeiServicesTablePointerLibKs0.inf | 37 ++++++++ .../PeiServicesTablePointerLibKs0.uni | 20 +++++ MdePkg/MdePkg.dsc | 3 + 5 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 MdePkg/Library/PeiServicesTablePointerLibKs0/PeiService= sTablePointer.c create mode 100644 MdePkg/Library/PeiServicesTablePointerLibKs0/PeiService= sTablePointerLibKs0.inf create mode 100644 MdePkg/Library/PeiServicesTablePointerLibKs0/PeiService= sTablePointerLibKs0.uni diff --git a/MdePkg/Include/Library/PeiServicesTablePointerLib.h b/MdePkg/I= nclude/Library/PeiServicesTablePointerLib.h index 61635eff00..f85c38363c 100644 --- a/MdePkg/Include/Library/PeiServicesTablePointerLib.h +++ b/MdePkg/Include/Library/PeiServicesTablePointerLib.h @@ -52,10 +52,11 @@ SetPeiServicesTablePointer ( 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. + For Itanium, ARM and LoongArch 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, ARM and + LoongArch CPUs. =20 **/ VOID diff --git a/MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTableP= ointer.c b/MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTablePoi= nter.c new file mode 100644 index 0000000000..f9800936b2 --- /dev/null +++ b/MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTablePointer.c @@ -0,0 +1,87 @@ +/** @file + PEI Services Table Pointer Library For Reigseter Mechanism. + + This library is used for PEIM which does executed from flash device dire= ctly but + executed in memory. + + Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2011 Hewlett-Packard Corporation. All rights reserved.
+ Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +/** + 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 + ) +{ + ASSERT (PeiServicesTablePointer !=3D NULL); + CsrWrite (LOONGARCH_CSR_KS0, (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 + ) +{ + CONST EFI_PEI_SERVICES **PeiServices; + + PeiServices =3D (CONST EFI_PEI_SERVICES **)(CsrRead (LOONGARCH_CSR_KS0)); + ASSERT (PeiServices !=3D NULL); + return PeiServices; +} + +/** + 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, ARM and LoongArch 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, ARM and + LoongArch CPUs. + +**/ +VOID +EFIAPI +MigratePeiServicesTablePointer ( + VOID + ) +{ + return; +} diff --git a/MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTableP= ointerLibKs0.inf b/MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServices= TablePointerLibKs0.inf new file mode 100644 index 0000000000..513f62517d --- /dev/null +++ b/MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTablePointerL= ibKs0.inf @@ -0,0 +1,37 @@ +## @file +# Instance of PEI Services Table Pointer Library using register CSR KS0 fo= r the table pointer. +# +# PEI Services Table Pointer Library implementation that retrieves a point= er to the +# PEI Services Table from a CPU register. Applies to modules that execute = from +# read-only memory. +# +# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2011 Hewlett-Packard Corporation. All rights reserved.
+# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D PeiServicesTablePointerLib + MODULE_UNI_FILE =3D PeiServicesTablePointerLibKs0.uni + FILE_GUID =3D 619950D1-7C5F-EA1B-D6DD-2FF7B0A4A2B7 + 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 + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib diff --git a/MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTableP= ointerLibKs0.uni b/MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServices= TablePointerLibKs0.uni new file mode 100644 index 0000000000..a1db86b0b7 --- /dev/null +++ b/MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTablePointerL= ibKs0.uni @@ -0,0 +1,20 @@ +// /** @file +// Instance of PEI Services Table Pointer Library using register CSR KS0 f= or the table pointer. +// +// PEI Services Table Pointer Library implementation that retrieves a poin= ter to the +// PEI Services Table from a CPU register. Applies to modules that execute= from +// read-only memory. +// +// Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+// Copyright (c) 2011 Hewlett-Packard Corporation. All rights reserved.
+// Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Instance of PEI S= ervices Table Pointer Library using CPU register for the table pointer" + +#string STR_MODULE_DESCRIPTION #language en-US "The PEI Services = Table Pointer Library implementation that retrieves a pointer to the PEI Se= rvices Table from a CPU register. Applies to modules that execute from read= -only memory." + diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 3abd1a1e23..109224c527 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -200,4 +200,7 @@ MdePkg/Library/BaseSerialPortLibRiscVSbiLib/BaseSerialPortLibRiscVSbiLib= .inf MdePkg/Library/BaseSerialPortLibRiscVSbiLib/BaseSerialPortLibRiscVSbiLib= Ram.inf =20 +[Components.LOONGARCH64] + MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTablePointerLibK= s0.inf + [BuildOptions] --=20 2.27.0 -=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 (#114535): https://edk2.groups.io/g/devel/message/114535 Mute This Topic: https://groups.io/mt/103971648/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- From nobody Thu Dec 26 20:24:45 2024 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+114536+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+114536+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250540; cv=none; d=zohomail.com; s=zohoarc; b=jGBuvAo2ikgd15Hj7Qhfdl+fumlakxNEDwdZoWQX0Dec0iztUYjGY0ibbYQRPqPFECyZuMKLbFvCuzZky9YVHmh8bk1Zm7N9C+sAjEg0/iN8gq+aD0J9Eb0ow8emFRPMaUdaaWxpFGSKeUyn4dXfly5psgm2ye/csv9y6SYisIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250540; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=fhxPac7Bbpp2qyya5MYKUb5BL1Nj2y2L7wK1XLbG+Dc=; b=Jc22ZzMX176fd9W7jpizz4VkcQdGg1bH49+qn1ip/hnqmUONa/jFfwNTW2lfJX8UEW4A9aObxfyGCp4WwciasN6Ife2Sug2x5YSc2RNTfVXEsqgQo0L0dTfy/vsLk+Yv1Z1+M2JeL8oyWeAh0qEVPGdN/bQ9tvVYvGOeseVzI9c= 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+114536+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250540905382.44879093923; Thu, 25 Jan 2024 22:29:00 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=SDRj6q4SW9QfWIBzdl9uQTYiSjQlaOsw6420il6u+us=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250540; v=1; b=BKe/Le6NCF7Gv3aGPdFg5+P7IIAAKS2X3Mku7rzKQ0VZ5ozTpk7r4mNvxB+tSrijQAtw+6fd 5hGXzN+7iEs455Ww9GdG5oz2y39MAhZ7XLNLU/XceQ4n+JTn2cR/iYOaDoVuNa/B6i4nboF2Vqb RmML+qqYJf5ZbtGw35IrnDK8= X-Received: by 127.0.0.2 with SMTP id nPxfYY1788612xB7oyITK1QM; Thu, 25 Jan 2024 22:29:00 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.9993.1706250538958962762 for ; Thu, 25 Jan 2024 22:29:00 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8Bx3+spUbNl5R0GAA--.21497S3; Fri, 26 Jan 2024 14:28:57 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxHs8oUbNl9XEbAA--.52916S2; Fri, 26 Jan 2024 14:28:56 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v8 10/37] MdePkg: Add some comments for LoongArch exceptions Date: Fri, 26 Jan 2024 14:28:55 +0800 Message-Id: <20240126062855.3101424-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxHs8oUbNl9XEbAA--.52916S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBGsZ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: gLvmT6uColLpK5RtjEgB1Sbjx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250542115100009 Content-Type: text/plain; charset="utf-8" Added some comments for registing LoongArch exceptions. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Reviewed-by: Liming Gao --- MdePkg/Include/Protocol/DebugSupport.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MdePkg/Include/Protocol/DebugSupport.h b/MdePkg/Include/Protoc= ol/DebugSupport.h index 9742663619..06f99ba7f7 100644 --- a/MdePkg/Include/Protocol/DebugSupport.h +++ b/MdePkg/Include/Protocol/DebugSupport.h @@ -683,6 +683,20 @@ typedef struct { // // LoongArch processor exception types. // +// The exception types is located in the CSR ESTAT +// register offset 16 bits, width 6 bits. +// +// If you want to register an exception hook, you can +// shfit the number left by 16 bits, and the exception +// handler will know the types. +// +// For example: +// mCpu->CpuRegisterInterruptHandler ( +// mCpu, +// (EXCEPT_LOONGARCH_PPI << CSR_ESTAT_EXC_SHIFT), +// PpiExceptionHandler +// ); +// #define EXCEPT_LOONGARCH_INT 0 #define EXCEPT_LOONGARCH_PIL 1 #define EXCEPT_LOONGARCH_PIS 2 --=20 2.27.0 -=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 (#114536): https://edk2.groups.io/g/devel/message/114536 Mute This Topic: https://groups.io/mt/103971649/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- From nobody Thu Dec 26 20:24:45 2024 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+114537+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+114537+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250550; cv=none; d=zohomail.com; s=zohoarc; b=D7U28n8xDNdCHFIGv9DJl8GiAEPchWEst8E1xfHxyUyip678E4V3xWYoQdY1drvY8dO1e6T5m1AIZQGT2/MR6QQ/mmncEirbutaxPG3rRzrumDCgUg7H8GiRMcLvT/Va9WYOI4CY7C7OqA9A9D6AZFWAdWM837oNkeNxfThMUgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250550; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=Z+B8LY2Xo2i58p100E0ZyfwNDd+YyF4fOS/tj6DpkX8=; b=FcRDi95KaOedZCCFUbDnmasSy1Upq4+rac8fiihdJxom8PbUbZ6cu09/FPTO8tbmLQF0wdjYEV9XX2xRz5ELsFCj2QJw4W4+wcSREQvLvPstCtIlkT3KSoMXCC/9Fmo57Yzu6CmfmBK4RsqJD2zw0QCUyrpXmp2/+o9GRdHY5d0= 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+114537+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250549991417.62838746827185; Thu, 25 Jan 2024 22:29:09 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=NhWpiiCHpc+jlIMZ30yNE6HUBcw0/Vue1Op9GMMdqRk=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250549; v=1; b=SV1rCpFwxSceM5xedMU2a42dcDPr8JuCtQG3hvOAle+sk7vP1AZrbsjo1E5KRu4cRXOoROeg 52SgE70nDfq400x6Arcm9LloTkp8u1VO0+XY5irFOL6uiKSQLowK4GukxM/9J1mzy9IHgF6Myft PVaEelx0MvkfkDnbEPcjO7fs= X-Received: by 127.0.0.2 with SMTP id oXEmYY1788612xDZGHTfFUjM; Thu, 25 Jan 2024 22:29:09 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.9996.1706250548387085067 for ; Thu, 25 Jan 2024 22:29:09 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxmegwUbNl8B0GAA--.2185S3; Fri, 26 Jan 2024 14:29:04 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxRMwtUbNlEHIbAA--.44272S2; Fri, 26 Jan 2024 14:29:01 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v8 11/37] UefiCpuPkg: Add LoongArch64 CPU Timer instance Date: Fri, 26 Jan 2024 14:29:00 +0800 Message-Id: <20240126062900.3101491-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxRMwtUbNlEHIbAA--.44272S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBHsY X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: gku8esKd87mxweDaTAQbadwox1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250550268100001 Content-Type: text/plain; charset="utf-8" Add the LoongArch64 CPU Timer instance to CpuTimerLib, using CPUCFG 0x4 and 0x5 for Stable Counter frequency. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Chao Li --- .../Library/CpuTimerLib/BaseCpuTimerLib.inf | 9 +- .../CpuTimerLib/LoongArch64/CpuTimerLib.c | 251 ++++++++++++++++++ 2 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 UefiCpuPkg/Library/CpuTimerLib/LoongArch64/CpuTimerLib.c diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf b/UefiCpuPk= g/Library/CpuTimerLib/BaseCpuTimerLib.inf index de0648de91..7e6152ef7e 100644 --- a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf @@ -5,6 +5,7 @@ # counter features are provided by the processors time stamp counter. # # Copyright (c) 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights= reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -18,18 +19,22 @@ LIBRARY_CLASS =3D TimerLib MODULE_UNI_FILE =3D BaseCpuTimerLib.uni =20 -[Sources] +[Sources.IA32, Sources.X64] CpuTimerLib.c BaseCpuTimerLib.c =20 +[Sources.LOONGARCH64] + LoongArch64/CpuTimerLib.c + [Packages] MdePkg/MdePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 [LibraryClasses] BaseLib - PcdLib DebugLib + PcdLib + SafeIntLib =20 [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## CONSUMES diff --git a/UefiCpuPkg/Library/CpuTimerLib/LoongArch64/CpuTimerLib.c b/Uef= iCpuPkg/Library/CpuTimerLib/LoongArch64/CpuTimerLib.c new file mode 100644 index 0000000000..a5ae8d0185 --- /dev/null +++ b/UefiCpuPkg/Library/CpuTimerLib/LoongArch64/CpuTimerLib.c @@ -0,0 +1,251 @@ +/** @file + CPUCFG 0x4 and 0x5 for Stable Counter frequency instance of Timer Librar= y. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include + +/** + Calculate clock frequency using CPUCFG 0x4 and 0x5 registers. + + @param VOID. + + @return The frequency in Hz. + +**/ +STATIC +UINT64 +CalcConstFreq ( + VOID + ) +{ + UINT32 BaseFreq; + UINT64 ClockMultiplier; + UINT32 ClockDivide; + CPUCFG_REG4_INFO_DATA CcFreq; + CPUCFG_REG5_INFO_DATA CpucfgReg5Data; + UINT64 StableTimerFreq; + + // + // Get the the crystal frequency corresponding to the constant + // frequency timer and the clock used by the timer. + // + AsmCpucfg (CPUCFG_REG4_INFO, &CcFreq.Uint32); + + // + // Get the multiplication factor and frequency division factor + // corresponding to the constant frequency timer and the clock + // used by the timer. + // + AsmCpucfg (CPUCFG_REG5_INFO, &CpucfgReg5Data.Uint32); + + BaseFreq =3D CcFreq.Bits.CC_FREQ; + ClockMultiplier =3D CpucfgReg5Data.Bits.CC_MUL & 0xFFFF; + ClockDivide =3D CpucfgReg5Data.Bits.CC_DIV & 0xFFFF; + + if ((BaseFreq =3D=3D 0x0) || (ClockMultiplier =3D=3D 0x0) || (ClockDivid= e =3D=3D 0x0)) { + DEBUG (( + DEBUG_ERROR, + "LoongArch Stable Timer is not available in the CPU, hence this libr= ary cannot be used.\n" + )); + ASSERT (FALSE); + CpuDeadLoop (); + } + + StableTimerFreq =3D ((ClockMultiplier * BaseFreq) / ClockDivide); + + if (StableTimerFreq =3D=3D 0x0) { + ASSERT (FALSE); + } + + return StableTimerFreq; +} + +/** + Stalls the CPU for at least the given number of microseconds. + + Stalls the CPU for the number of microseconds specified by MicroSeconds. + + @param MicroSeconds The minimum number of microseconds to delay. + + @return MicroSeconds + +**/ +UINTN +EFIAPI +MicroSecondDelay ( + IN UINTN MicroSeconds + ) +{ + UINT64 CurrentTicks, ExceptedTicks, Remaining; + RETURN_STATUS Status; + + Status =3D SafeUint64Mult (MicroSeconds, CalcConstFreq (), &Remaining); + ASSERT_RETURN_ERROR (Status); + + ExceptedTicks =3D DivU64x32 (Remaining, 1000000U); + CurrentTicks =3D AsmReadStableCounter (); + ExceptedTicks +=3D CurrentTicks; + + do { + CurrentTicks =3D AsmReadStableCounter (); + } while (CurrentTicks < ExceptedTicks); + + return MicroSeconds; +} + +/** + Stalls the CPU for at least the given number of nanoseconds. + + Stalls the CPU for the number of nanoseconds specified by NanoSeconds. + + @param NanoSeconds The minimum number of nanoseconds to delay. + + @return NanoSeconds + +**/ +UINTN +EFIAPI +NanoSecondDelay ( + IN UINTN NanoSeconds + ) +{ + UINTN MicroSeconds; + + // Round up to 1us Tick Number + MicroSeconds =3D NanoSeconds / 1000; + MicroSeconds +=3D ((NanoSeconds % 1000) =3D=3D 0) ? 0 : 1; + + MicroSecondDelay (MicroSeconds); + + return NanoSeconds; +} + +/** + Retrieves the current value of a 64-bit free running Stable Counter. + + The LoongArch defines a constant frequency timer, whose main body is a + 64-bit counter called StableCounter. StableCounter is set to 0 after + reset, and then increments by 1 every counting clock cycle. When the + count reaches all 1s, it automatically wraps around to 0 and continues + to increment. + The properties of the Stable Counter can be retrieved from + GetPerformanceCounterProperties(). + + @return The current value of the Stable Counter. + +**/ +UINT64 +EFIAPI +GetPerformanceCounter ( + VOID + ) +{ + // + // Just return the value of Stable Counter. + // + return AsmReadStableCounter (); +} + +/** + Retrieves the 64-bit frequency in Hz and the range of Stable Counter + values. + + If StartValue is not NULL, then the value that the stbale counter starts + with immediately after is it rolls over is returned in StartValue. If + EndValue is not NULL, then the value that the stable counter end with + immediately before it rolls over is returned in EndValue. The 64-bit + frequency of the system frequency in Hz is always returned. + + @param StartValue The value the stable counter starts with when it + rolls over. + @param EndValue The value that the stable counter ends with before + it rolls over. + + @return The frequency in Hz. + +**/ +UINT64 +EFIAPI +GetPerformanceCounterProperties ( + OUT UINT64 *StartValue OPTIONAL, + OUT UINT64 *EndValue OPTIONAL + ) +{ + if (StartValue !=3D NULL) { + *StartValue =3D 0; + } + + if (EndValue !=3D NULL) { + *EndValue =3D 0xFFFFFFFFFFFFFFFFULL; + } + + return CalcConstFreq (); +} + +/** + Converts elapsed ticks of performance counter to time in nanoseconds. + + This function converts the elapsed ticks of running performance counter = to + time value in unit of nanoseconds. + + @param Ticks The number of elapsed ticks of running performance cou= nter. + + @return The elapsed time in nanoseconds. + +**/ +UINT64 +EFIAPI +GetTimeInNanoSecond ( + IN UINT64 Ticks + ) +{ + UINT64 Frequency; + UINT64 NanoSeconds; + UINT64 Remainder; + INTN Shift; + RETURN_STATUS Status; + + Frequency =3D GetPerformanceCounterProperties (NULL, NULL); + + // + // Ticks + // Time =3D --------- x 1,000,000,000 + // Frequency + // + Status =3D SafeUint64Mult ( + DivU64x64Remainder (Ticks, Frequency, &Remainder), + 1000000000u, + &NanoSeconds + ); + + // + // Ensure (Remainder * 1,000,000,000) will not overflow 64-bit. + // Since 2^29 < 1,000,000,000 =3D 0x3B9ACA00 < 2^30, Remainder should < = 2^(64-30) =3D 2^34, + // i.e. highest bit set in Remainder should <=3D 33. + // + Shift =3D MAX (0, HighBitSet64 (Remainder) - 33); + Remainder =3D RShiftU64 (Remainder, (UINTN)Shift); + Frequency =3D RShiftU64 (Frequency, (UINTN)Shift); + + Status =3D SafeUint64Add ( + NanoSeconds, + DivU64x64Remainder ( + MultU64x32 (Remainder, 1000000000u), + Frequency, + NULL + ), + &NanoSeconds + ); + ASSERT_RETURN_ERROR (Status); + + return NanoSeconds; +} --=20 2.27.0 -=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 (#114537): https://edk2.groups.io/g/devel/message/114537 Mute This Topic: https://groups.io/mt/103971650/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- From nobody Thu Dec 26 20:24:45 2024 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+114538+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+114538+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250556; cv=none; d=zohomail.com; s=zohoarc; b=Dcli7JvTfo7+pnr2iK0dgkRgGDNj8LD3VwPJ2fkz6xbA81qKiiwwqlwv5y+emHwUhr25mKEwTxejFPRq3G82Y5S1LlsyWqDNivfJjlhYD4qoQXEKtvHl8bGCjMXdB/zWhoSG6fxRAUmADsJ/jtGXr8kzolnBxbQs4DE8H/E1a/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250556; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=hZkfCBt9Hwq4AjlpJXrgSe1y1W5hvSsUsIk6keJz2K8=; b=C45NlwwdMzTwoXQQhaJo8Bh/ray0ycXtRPyXY9kUYJv679fictxOl3kUZifHckGUD6cVDgNImwaocwI9zMWALSzy7GgkPs+E+H7Gd3lDWL5Nk4ZouKVfcTlT75TqRS+lyw9Fa5+pVyLQ+oU8ahRfDsTJjNuAdwFF6WyEjdx7pbw= 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+114538+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250556041278.0961887349631; Thu, 25 Jan 2024 22:29:16 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Nip+lZFUgzdkTT7aaZcpyFWLWX6vG3fXJ3E5BoyuLGI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250555; v=1; b=HsvryFPyELDQ6Phk+ySuU2ZZuAZ0qebGUAw3AS7p2t7DGb2HAfWQTCwHGCBNZiL+p5sjJih1 4GprriV5UCt2CDE0txkogalUEcxCtbJWYAgr3sK+EnYg4Zqrau96PoqkqxZ0HxxpVwzBMw0VoHF pVxIW0YLUedyjRv9JQGX74Nc= X-Received: by 127.0.0.2 with SMTP id LvF7YY1788612xGEhdOBY1U0; Thu, 25 Jan 2024 22:29:15 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.9999.1706250553903603803 for ; Thu, 25 Jan 2024 22:29:15 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxXOk2UbNl_h0GAA--.11490S3; Fri, 26 Jan 2024 14:29:10 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxXs01UbNlMXIbAA--.49748S2; Fri, 26 Jan 2024 14:29:09 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Baoqi Zhang Subject: [edk2-devel] [PATCH v8 12/37] UefiCpuPkg: Add CPU exception library for LoongArch Date: Fri, 26 Jan 2024 14:29:07 +0800 Message-Id: <20240126062907.3101558-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxXs01UbNlMXIbAA--.49748S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBIsX X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Z5AoqEKe7k4jtGA6WIrA4hVsx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250558331100007 Content-Type: text/plain; charset="utf-8" Added LoongArch exception handler into CpuExceptionHandlerLib. Adjust the file order in INF of CpuExceptionHandlerLib with alphabetical order. Adjust files order in CpuExceptionHandlerLib INF in alphabetical order. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Chao Li Co-authored-by: Baoqi Zhang --- .../DxeCpuExceptionHandlerLib.inf | 34 +- .../LoongArch/DxeExceptionLib.c | 198 ++++++++++ .../LoongArch/ExceptionCommon.c | 171 ++++++++ .../LoongArch/ExceptionCommon.h | 131 +++++++ .../LoongArch64/ArchExceptionHandler.c | 268 +++++++++++++ .../LoongArch64/ExceptionHandlerAsm.S | 366 ++++++++++++++++++ .../LoongArch/SecPeiExceptionLib.c | 102 +++++ .../SecPeiCpuExceptionHandlerLib.inf | 29 +- UefiCpuPkg/UefiCpuPkg.dec | 5 + 9 files changed, 1283 insertions(+), 21 deletions(-) create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/Dxe= ExceptionLib.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/Exc= eptionCommon.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/Exc= eptionCommon.h create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/Loo= ngArch64/ArchExceptionHandler.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/Loo= ngArch64/ExceptionHandlerAsm.S create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/Sec= PeiExceptionLib.c diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandle= rLib.inf index fdbebadab9..f5bacbe2bc 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf @@ -18,25 +18,32 @@ # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 +# VALID_ARCHITECTURES =3D IA32 X64 LOONGARCH64 # =20 [Sources.Ia32] - Ia32/ExceptionHandlerAsm.nasm - Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/ExceptionHandlerAsm.nasm + Ia32/ExceptionTssEntryAsm.nasm =20 [Sources.X64] - X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/ExceptionHandlerAsm.nasm =20 -[Sources.common] +[Sources.Ia32, Sources.X64] CpuExceptionCommon.h CpuExceptionCommon.c - PeiDxeSmmCpuException.c DxeException.c + PeiDxeSmmCpuException.c + +[Sources.LoongArch64] + LoongArch/DxeExceptionLib.c + LoongArch/ExceptionCommon.h + LoongArch/ExceptionCommon.c + LoongArch/LoongArch64/ArchExceptionHandler.c + LoongArch/LoongArch64/ExceptionHandlerAsm.S | GCC =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard @@ -51,16 +58,19 @@ MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 -[LibraryClasses] +[LibraryClasses.common] BaseLib - SerialPortLib + CpuLib + DebugLib + MemoryAllocationLib + PeCoffGetEntryPointLib PrintLib + SerialPortLib SynchronizationLib - LocalApicLib - PeCoffGetEntryPointLib - MemoryAllocationLib - DebugLib + +[LibraryClasses.Ia32, LibraryClasses.X64] CcExitLib + LocalApicLib =20 [BuildOptions] XCODE:*_*_X64_NASM_FLAGS =3D -D NO_ABSOLUTE_RELOCS_IN_TEXT diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/DxeExcepti= onLib.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/DxeExceptionL= ib.c new file mode 100644 index 0000000000..2c5d202b33 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/DxeExceptionLib.c @@ -0,0 +1,198 @@ +/** @file DxeExceptionLib.c + + LoongArch exception library implemenation for DXE modules. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ExceptionCommon.h" + +EFI_EXCEPTION_CALLBACK ExternalInterruptHandler[MAX_LOONGARCH_INTERRUPT += 1] =3D { 0 }; +EFI_EXCEPTION_CALLBACK ExceptionHandler[MAX_LOONGARCH_EXCEPTION + 1] = =3D { 0 }; + +/** + Registers a function to be called from the processor interrupt or except= ion handler. + + This function registers and enables the handler specified by InterruptHa= ndler for a processor + interrupt or exception type specified by InterruptType. If InterruptHand= ler is NULL, then the + handler for the processor interrupt or exception type specified by Inter= ruptType is uninstalled. + The installed handler is called once for each processor interrupt or exc= eption. + + @param InterruptType A pointer to the processor's current interrupt = state. Set to TRUE if interrupts + are enabled and FALSE if interrupts are disable= d. + @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRU= PT_HANDLER that is called + when a processor interrupt occurs. If this para= meter is NULL, then the handler + will be uninstalled. + + @retval EFI_SUCCESS The handler for the processor interrupt wa= s successfully installed or uninstalled. + @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handle= r for InterruptType was + previously installed. + @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler fo= r InterruptType was not + previously installed. + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType i= s not supported. + +**/ +EFI_STATUS +RegisterCpuInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ) +{ + EFI_EXCEPTION_TYPE ExceptionType; + + ExceptionType =3D InterruptType & CSR_ESTAT_EXC; + + if (ExceptionType !=3D 0) { + // + // Exception + // + if (ExceptionType > EXCEPT_LOONGARCH_FPE) { + return EFI_UNSUPPORTED; + } + + ExceptionType >>=3D CSR_ESTAT_EXC_SHIFT; + + if ((InterruptHandler =3D=3D NULL) && (ExceptionHandler[InterruptType]= =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if ((InterruptHandler !=3D NULL) && (ExceptionHandler[ExceptionType] != =3D NULL)) { + return EFI_ALREADY_STARTED; + } + + ExceptionHandler[ExceptionType] =3D InterruptHandler; + } else { + // + // Interrupt + // + if (InterruptType > MAX_LOONGARCH_INTERRUPT) { + return EFI_UNSUPPORTED; + } + + if ((InterruptHandler =3D=3D NULL) && (ExternalInterruptHandler[Interr= uptType] =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if ((InterruptHandler !=3D NULL) && (ExternalInterruptHandler[Interrup= tType] !=3D NULL)) { + return EFI_ALREADY_STARTED; + } + + ExternalInterruptHandler[InterruptType] =3D InterruptHandler; + } + + return EFI_SUCCESS; +} + +/** + Common exception handler. + + @param ExceptionType Exception type. + @param SystemContext Pointer to EFI_SYSTEM_CONTEXT. + +**/ +VOID +EFIAPI +CommonExceptionHandler ( + IN EFI_EXCEPTION_TYPE ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + EFI_EXCEPTION_TYPE InterruptType; + + if (ExceptionType =3D=3D EXCEPT_LOONGARCH_INT) { + // + // Interrupt + // + InterruptType =3D GetInterruptType (SystemContext); + if (InterruptType =3D=3D 0xFF) { + ExceptionType =3D InterruptType; + } else { + if ((ExternalInterruptHandler !=3D NULL) && (ExternalInterruptHandle= r[InterruptType] !=3D NULL)) { + ExternalInterruptHandler[InterruptType](InterruptType, SystemConte= xt); + return; + } + } + } else if (ExceptionType =3D=3D EXCEPT_LOONGARCH_FPD) { + EnableFloatingPointUnits (); + InitializeFloatingPointUnits (); + return; + } else { + // + // Exception + // + ExceptionType >>=3D CSR_ESTAT_EXC_SHIFT; + if ((ExceptionHandler !=3D NULL) && (ExceptionHandler[ExceptionType] != =3D NULL)) { + ExceptionHandler[ExceptionType](ExceptionType, SystemContext); + return; + } + } + + // + // Only the TLB refill exception use the same entry point as normal exce= ptions. + // + if (CsrRead (LOONGARCH_CSR_TLBRERA) & 0x1) { + ExceptionType =3D mExceptionKnownNameNum - 1; // Use only to dump the = exception context. + } + + DefaultExceptionHandler (ExceptionType, SystemContext); +} + +/** + Initializes all CPU exceptions entries and provides the default exceptio= n handlers. + + Caller should try to get an array of interrupt and/or exception vectors = that are in use and need to + persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification. + If caller cannot get reserved vector list or it does not exists, set Vec= torInfo to NULL. + If VectorInfo is not NULL, the exception vectors will be initialized per= vector attribute accordingly. + + @param[in] VectorInfo Pointer to reserved vector list. + + @retval EFI_SUCCESS CPU Exception Entries have been successful= ly initialized + with default exception handlers. + @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if= VectorInfo is not NULL. + @retval EFI_UNSUPPORTED This function is not supported. + +**/ +EFI_STATUS +EFIAPI +InitializeCpuExceptionHandlers ( + IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL + ) +{ + return EFI_SUCCESS; +} + +/** + Setup separate stacks for certain exception handlers. + If the input Buffer and BufferSize are both NULL, use global variable if= possible. + + @param[in] Buffer Point to buffer used to separate exceptio= n stack. + @param[in, out] BufferSize On input, it indicates the byte size of B= uffer. + If the size is not enough, the return sta= tus will + be EFI_BUFFER_TOO_SMALL, and output Buffe= rSize + will be the size it needs. + + @retval EFI_SUCCESS The stacks are assigned successfully. + @retval EFI_UNSUPPORTED This function is not supported. + @retval EFI_BUFFER_TOO_SMALL This BufferSize is too small. +**/ +EFI_STATUS +EFIAPI +InitializeSeparateExceptionStacks ( + IN VOID *Buffer, + IN OUT UINTN *BufferSize + ) +{ + return EFI_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/ExceptionC= ommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/ExceptionComm= on.c new file mode 100644 index 0000000000..801c8393e8 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/ExceptionCommon.c @@ -0,0 +1,171 @@ +/** @file DxeExceptionLib.c + + CPU Exception Handler Library common functions. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include "ExceptionCommon.h" + +CONST CHAR8 mExceptionReservedStr[] =3D "Reserved"; +CONST CHAR8 *mExceptionNameStr[] =3D { + "#INT - Interrupt(CSR.ECFG.VS=3D0)", + "#PIL - Page invalid exception for Load option", + "#PIS - Page invalid exception for Store operation", + "#PIF - Page invalid exception for Fetch operation", + "#PME - Page modification exception", + "#PNR - Page non-readable exception", + "#PNX - Page non-executable exception", + "#PPI - Page privilege level illegal exception", + "#ADE - Address error exception", + "#ALE - Address alignment fault exception", + "#BCE - Bound check exception", + "#SYS - System call exception", + "#BRK - Beeakpoint exception", + "#INE - Instruction non-defined exception", + "#IPE - Instruction privilege error exception", + "#FPD - Floating-point instruction disable exception", + "#SXD - 128-bit vector (SIMD instructions) expansion instruction disable= exception", + "#ASXD - 256-bit vector (Advanced SIMD instructions) expansion instructi= on disable exception", + "#FPE - Floating-Point error exception", + "#WPE - WatchPoint Exception for Fetch watchpoint or Memory load/store w= atchpoint", + "#BTD - Binary Translation expansion instruction Disable exception", + "#BTE - Binary Translation related exceptions", + "#GSPR - Guest Sensitive Privileged Resource exception", + "#HVC - HyperVisor Call exception", + "#GCXC - Guest CSR Software/Hardware Change exception", + "#TBR - TLB refill exception" // !!! NOTICE: Because the TLB refill exce= ption is not instructed in ECODE, so the TLB refill exception must be the l= ast one! +}; + +INTN mExceptionKnownNameNum =3D (sizeof (mExceptionNameStr) / sizeof (CHA= R8 *)); + +/** + Get ASCII format string exception name by exception type. + + @param ExceptionType Exception type. + + @return ASCII format string exception name. + +**/ +CONST CHAR8 * +GetExceptionNameStr ( + IN EFI_EXCEPTION_TYPE ExceptionType + ) +{ + if ((UINTN)ExceptionType < mExceptionKnownNameNum) { + return mExceptionNameStr[ExceptionType]; + } else { + return mExceptionReservedStr; + } +} + +/** + Prints a message to the serial port. + + @param Format Format string for the message to print. + @param ... Variable argument list whose contents are accessed + based on the format string specified by Format. + +**/ +VOID +EFIAPI +InternalPrintMessage ( + IN CONST CHAR8 *Format, + ... + ) +{ + CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; + VA_LIST Marker; + + // + // Convert the message to an ASCII String + // + VA_START (Marker, Format); + AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); + VA_END (Marker); + + // + // Send the print string to a Serial Port + // + SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer)); +} + +/** + Find and display image base address and return image base and its entry = point. + + @param CurrentEra Current instruction pointer. + +**/ +VOID +DumpModuleImageInfo ( + IN UINTN CurrentEra + ) +{ + EFI_STATUS Status; + UINTN Pe32Data; + VOID *PdbPointer; + VOID *EntryPoint; + + Pe32Data =3D PeCoffSearchImageBase (CurrentEra); + if (Pe32Data =3D=3D 0) { + InternalPrintMessage ("!!!! Can't find image information. !!!!\n"); + } else { + // + // Find Image Base entry point + // + Status =3D PeCoffLoaderGetEntryPoint ((VOID *)Pe32Data, &EntryPoint); + if (EFI_ERROR (Status)) { + EntryPoint =3D NULL; + } + + InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEra= ); + PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)Pe32Data); + if (PdbPointer !=3D NULL) { + InternalPrintMessage ("%a", PdbPointer); + } else { + InternalPrintMessage ("(No PDB) "); + } + + InternalPrintMessage ( + " (ImageBase=3D%016lp, EntryPoint=3D%016p) !!!!\n", + (VOID *)Pe32Data, + EntryPoint + ); + } +} + +/** + Default exception handler. + + @param ExceptionType Exception type. + @param SystemContext Pointer to EFI_SYSTEM_CONTEXT. + +**/ +VOID +EFIAPI +DefaultExceptionHandler ( + IN EFI_EXCEPTION_TYPE ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + // + // Initialize the serial port before dumping. + // + SerialPortInitialize (); + // + // Display ExceptionType, CPU information and Image information + // + DumpImageAndCpuContent (ExceptionType, SystemContext); + + // + // Enter a dead loop. + // + CpuDeadLoop (); +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/ExceptionC= ommon.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/ExceptionComm= on.h new file mode 100644 index 0000000000..e326b73e3f --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/ExceptionCommon.h @@ -0,0 +1,131 @@ +/** @file DxeExceptionLib.h + + Common header file for CPU Exception Handler Library. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef EXCEPTION_COMMON_H_ +#define EXCEPTION_COMMON_H_ + +#define MAX_DEBUG_MESSAGE_LENGTH 0x100 + +// +// For coding convenience, define the maximum valid +// LoongArch exception. +// Since UEFI V2.11, it will be present in DebugSupport.h. +// +#define MAX_LOONGARCH_EXCEPTION 64 + +extern INTN mExceptionKnownNameNum; + +/** + Get ASCII format string exception name by exception type. + + @param[in] ExceptionType Exception type. + + @return ASCII format string exception name. + +**/ +CONST CHAR8 * +GetExceptionNameStr ( + IN EFI_EXCEPTION_TYPE ExceptionType + ); + +/** + Prints a message to the serial port. + + @param[in] Format Format string for the message to print. + @param[in] ... Variable argument list whose contents are access= ed + based on the format string specified by Format. + +**/ +VOID +EFIAPI +InternalPrintMessage ( + IN CONST CHAR8 *Format, + ... + ); + +/** + Find and display image base address and return image base and its entry = point. + + @param[in] CurrentEip Current instruction pointer. + +**/ +VOID +DumpModuleImageInfo ( + IN UINTN CurrentEip + ); + +/** + IPI Interrupt Handler. + + @param InterruptType The type of interrupt that occurred + @param SystemContext A pointer to the system context when the interru= pt occurred +**/ +VOID +EFIAPI +IpiInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_SYSTEM_CONTEXT SystemContext + ); + +/** + Default exception handler. + + @param[in] ExceptionType Exception type. + @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT. + +**/ +VOID +EFIAPI +DefaultExceptionHandler ( + IN EFI_EXCEPTION_TYPE ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ); + +/** + Display CPU information. + + @param[in] ExceptionType Exception type. + @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT. + +**/ +VOID +DumpImageAndCpuContent ( + IN EFI_EXCEPTION_TYPE ExceptionType, + IN EFI_SYSTEM_CONTEXT SystemContext + ); + +/** + Get exception types + + @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT. + + @return Exception type. + +**/ +EFI_EXCEPTION_TYPE +EFIAPI +GetExceptionType ( + IN EFI_SYSTEM_CONTEXT SystemContext + ); + +/** + Get Common interrupt types + + @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT. + + @return Interrupt type. + +**/ +EFI_EXCEPTION_TYPE +EFIAPI +GetInterruptType ( + IN EFI_SYSTEM_CONTEXT SystemContext + ); + +#endif diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/LoongArch6= 4/ArchExceptionHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongA= rch/LoongArch64/ArchExceptionHandler.c new file mode 100644 index 0000000000..c0219deba5 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/LoongArch64/ArchE= xceptionHandler.c @@ -0,0 +1,268 @@ +/** @file ArchExceptionHandler.c + + LoongArch64 CPU Exception Handler. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include "ExceptionCommon.h" + +/** + Get Exception Type + + @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT. + + @return LoongArch64 exception type. + +**/ +EFI_EXCEPTION_TYPE +EFIAPI +GetExceptionType ( + IN EFI_SYSTEM_CONTEXT SystemContext + ) +{ + EFI_EXCEPTION_TYPE ExceptionType; + + ExceptionType =3D (SystemContext.SystemContextLoongArch64->ESTAT & CSR_E= STAT_EXC); + return ExceptionType; +} + +/** + Get Interrupt Type + + @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT. + + @return LoongArch64 intrrupt type. + +**/ +EFI_EXCEPTION_TYPE +EFIAPI +GetInterruptType ( + IN EFI_SYSTEM_CONTEXT SystemContext + ) +{ + EFI_EXCEPTION_TYPE InterruptType; + + for (InterruptType =3D 0; InterruptType <=3D EXCEPT_LOONGARCH_INT_IPI; I= nterruptType++) { + if (SystemContext.SystemContextLoongArch64->ESTAT & (1 << InterruptTyp= e)) { + // + // 0 - EXCEPT_LOONGARCH_INT_SIP0 + // 1 - EXCEPT_LOONGARCH_INT_SIP1 + // 2 - EXCEPT_LOONGARCH_INT_IP0 + // 3 - EXCEPT_LOONGARCH_INT_IP1 + // 4 - EXCEPT_LOONGARCH_INT_IP2 + // 5 - EXCEPT_LOONGARCH_INT_IP3 + // 6 - EXCEPT_LOONGARCH_INT_IP4 + // 7 - EXCEPT_LOONGARCH_INT_IP5 + // 8 - EXCEPT_LOONGARCH_INT_IP6 + // 9 - EXCEPT_LOONGARCH_INT_IP7 + // 10 - EXCEPT_LOONGARCH_INT_PMC + // 11 - EXCEPT_LOONGARCH_INT_TIMER + // 12 - EXCEPT_LOONGARCH_INT_IPI + // Greater than EXCEPT_LOONGARCH_INI_IPI is currently invalid. + // + return InterruptType; + } + } + + // + // Invalid IRQ + // + return 0xFF; +} + +/** + Display CPU information. + + @param ExceptionType Exception type. + @param SystemContext Pointer to EFI_SYSTEM_CONTEXT. + +**/ +VOID +EFIAPI +DumpCpuContext ( + IN EFI_EXCEPTION_TYPE ExceptionType, + IN EFI_SYSTEM_CONTEXT SystemContext + ) +{ + InternalPrintMessage ( + "\n!!!! LoongArch64 Exception Type - %02x(%a) !!!!\n", + ExceptionType, + GetExceptionNameStr (ExceptionType) + ); + + // + // Dump TLB refill ERA and BADV + // + if (ExceptionType =3D=3D (mExceptionKnownNameNum - 1)) { + InternalPrintMessage ("TLB refill ERA 0x%llx\n", (CsrRead (LOONGARCH_= CSR_TLBRERA) & (~0x3ULL))); + InternalPrintMessage ("TLB refill BADV 0x%llx\n", CsrRead (LOONGARCH_= CSR_TLBRBADV)); + } + + // + // Dump the general registers + // + InternalPrintMessage ( + "Zero - 0x%016lx, RA - 0x%016lx, TP - 0x%016lx, SP - 0x%016lx\n", + SystemContext.SystemContextLoongArch64->R0, + SystemContext.SystemContextLoongArch64->R1, + SystemContext.SystemContextLoongArch64->R2, + SystemContext.SystemContextLoongArch64->R3 + ); + InternalPrintMessage ( + " A0 - 0x%016lx, A1 - 0x%016lx, A2 - 0x%016lx, A3 - 0x%016lx\n", + SystemContext.SystemContextLoongArch64->R4, + SystemContext.SystemContextLoongArch64->R5, + SystemContext.SystemContextLoongArch64->R6, + SystemContext.SystemContextLoongArch64->R7 + ); + InternalPrintMessage ( + " A4 - 0x%016lx, A5 - 0x%016lx, A6 - 0x%016lx, A7 - 0x%016lx\n", + SystemContext.SystemContextLoongArch64->R8, + SystemContext.SystemContextLoongArch64->R9, + SystemContext.SystemContextLoongArch64->R10, + SystemContext.SystemContextLoongArch64->R11 + ); + InternalPrintMessage ( + " T0 - 0x%016lx, T1 - 0x%016lx, T2 - 0x%016lx, T3 - 0x%016lx\n", + SystemContext.SystemContextLoongArch64->R12, + SystemContext.SystemContextLoongArch64->R13, + SystemContext.SystemContextLoongArch64->R14, + SystemContext.SystemContextLoongArch64->R15 + ); + InternalPrintMessage ( + " T4 - 0x%016lx, T5 - 0x%016lx, T6 - 0x%016lx, T7 - 0x%016lx\n", + SystemContext.SystemContextLoongArch64->R16, + SystemContext.SystemContextLoongArch64->R17, + SystemContext.SystemContextLoongArch64->R18, + SystemContext.SystemContextLoongArch64->R19 + ); + InternalPrintMessage ( + " T8 - 0x%016lx, R21 - 0x%016lx, FP - 0x%016lx, S0 - 0x%016lx\n", + SystemContext.SystemContextLoongArch64->R20, + SystemContext.SystemContextLoongArch64->R21, + SystemContext.SystemContextLoongArch64->R22, + SystemContext.SystemContextLoongArch64->R23 + ); + InternalPrintMessage ( + " S1 - 0x%016lx, S2 - 0x%016lx, S3 - 0x%016lx, S4 - 0x%016lx\n", + SystemContext.SystemContextLoongArch64->R24, + SystemContext.SystemContextLoongArch64->R25, + SystemContext.SystemContextLoongArch64->R26, + SystemContext.SystemContextLoongArch64->R27 + ); + InternalPrintMessage ( + " S5 - 0x%016lx, S6 - 0x%016lx, S7 - 0x%016lx, S8 - 0x%016lx\n", + SystemContext.SystemContextLoongArch64->R28, + SystemContext.SystemContextLoongArch64->R29, + SystemContext.SystemContextLoongArch64->R30, + SystemContext.SystemContextLoongArch64->R31 + ); + InternalPrintMessage ("\n"); + + // + // Dump the CSR registers + // + InternalPrintMessage ( + "CRMD - 0x%016lx, PRMD - 0x%016lx, EUEN - 0x%016lx, MISC - 0x%016lx\= n", + SystemContext.SystemContextLoongArch64->CRMD, + SystemContext.SystemContextLoongArch64->PRMD, + SystemContext.SystemContextLoongArch64->EUEN, + SystemContext.SystemContextLoongArch64->MISC + ); + InternalPrintMessage ( + "ECFG - 0x%016lx, ESTAT - 0x%016lx, ERA - 0x%016lx, BADV - 0x%016lx\= n", + SystemContext.SystemContextLoongArch64->ECFG, + SystemContext.SystemContextLoongArch64->ESTAT, + SystemContext.SystemContextLoongArch64->ERA, + SystemContext.SystemContextLoongArch64->BADV + ); + InternalPrintMessage ( + "BADI - 0x%016lx\n", + SystemContext.SystemContextLoongArch64->BADI + ); +} + +/** + Display CPU information. + + @param ExceptionType Exception type. + @param SystemContext Pointer to EFI_SYSTEM_CONTEXT. + +**/ +VOID +DumpImageAndCpuContent ( + IN EFI_EXCEPTION_TYPE ExceptionType, + IN EFI_SYSTEM_CONTEXT SystemContext + ) +{ + DumpCpuContext (ExceptionType, SystemContext); + + if (ExceptionType =3D=3D (mExceptionKnownNameNum - 1)) { + // + // Dump TLB refill image info + // + DumpModuleImageInfo ((CsrRead (LOONGARCH_CSR_TLBRERA) & (~0x3ULL))); + } else { + DumpModuleImageInfo (SystemContext.SystemContextLoongArch64->ERA); + } +} + +/** + IPI Interrupt Handler. + + @param InterruptType The type of interrupt that occurred + @param SystemContext A pointer to the system context when the interru= pt occurred +**/ +VOID +EFIAPI +IpiInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_SYSTEM_CONTEXT SystemContext + ) +{ + UINTN ResumeVector; + UINTN Parameter; + + // + // Clear interrupt. + // + IoCsrWrite32 (LOONGARCH_IOCSR_IPI_CLEAR, IoCsrRead32 (LOONGARCH_IOCSR_IP= I_STATUS)); + + // + // Get the resume vector and parameter if populated. + // + ResumeVector =3D IoCsrRead64 (LOONGARCH_IOCSR_MBUF0); + Parameter =3D IoCsrRead64 (LOONGARCH_IOCSR_MBUF3); + + // + // Clean up current processor mailbox 0 and mailbox 3. + // + IoCsrWrite64 (LOONGARCH_IOCSR_MBUF0, 0x0); + IoCsrWrite64 (LOONGARCH_IOCSR_MBUF3, 0x0); + + // + // If mailbox 0 is non-NULL, it means that the BSP or other cores called= the IPI to wake + // up the current core and let it use the resume vector stored in mailbo= x 0. + // + // If both the resume vector and parameter are non-NULL, it means that t= he IPI was + // called in the BIOS. + // + // The situation where the resume vector is non-NULL and the parameter i= s NULL has been + // processed after the exception entry is pushed onto the stack. + // + if ((ResumeVector !=3D 0) && (Parameter !=3D 0)) { + SystemContext.SystemContextLoongArch64->ERA =3D ResumeVector; + // + // Set $a0 as APIC ID and $a1 as parameter value. + // + SystemContext.SystemContextLoongArch64->R4 =3D CsrRead (LOONGARCH_CSR_= CPUNUM); + SystemContext.SystemContextLoongArch64->R5 =3D Parameter; + } + + MemoryFence (); +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/LoongArch6= 4/ExceptionHandlerAsm.S b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongAr= ch/LoongArch64/ExceptionHandlerAsm.S new file mode 100644 index 0000000000..7c692e01c1 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/LoongArch64/Excep= tionHandlerAsm.S @@ -0,0 +1,366 @@ +#-------------------------------------------------------------------------= ----- +# +# LoongArch64 ASM exception handler +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- + +#include +#include +#include + +#define RSIZE 8 // 64 bit mode register size +#define GP_REG_CONTEXT_SIZE 32 * RSIZE // General-purpose registers size +#define FP_REG_CONTEXT_SIZE 34 * RSIZE // Floating-point registers size +#define CSR_REG_CONTEXT_SIZE 9 * RSIZE // CSR registers size + +ASM_GLOBAL ASM_PFX(ExceptionEntry) +ASM_GLOBAL ASM_PFX(ExceptionEntryStart) +ASM_GLOBAL ASM_PFX(ExceptionEntryEnd) + +ASM_PFX(ExceptionEntry): + move $s0, $a0 + bl GetExceptionType // Exception type stored in register a0 + move $a1, $s0 // SystemContxt + bl CommonExceptionHandler + +PopContext: + // + // Not sure if interrupts are turned on during the exception handler, an= yway disable interrupts here. + // It will be turned on when the instruction 'ertn' is executed. + // + bl DisableInterrupts + + bl GetExceptionType // Get current exception type, and store= d in register a0 + + // Check whether the FPE is changed during interrupt handler, if ture re= store it. + ld.d $t1, $sp, (LOONGARCH_CSR_EUEN * RSIZE + GP_REG_CONTEXT_SIZE) + csrrd $t0, LOONGARCH_CSR_EUEN // Current EUEN + andi $t0, $t0, CSR_EUEN_FPEN + andi $t1, $t1, CSR_EUEN_FPEN + li.d $t2, EXCEPT_LOONGARCH_INT + bne $a0, $t2, PopRegs + beq $t0, $t1, PopRegs + beqz $t1, CloseFP + bl EnableFloatingPointUnits + b PopRegs + +CloseFP: + bl DisableFloatingPointUnits + +PopRegs: + // + // Pop CSR reigsters + // + addi.d $sp, $sp, GP_REG_CONTEXT_SIZE + + ld.d $t0, $sp, LOONGARCH_CSR_CRMD * RSIZE + csrwr $t0, LOONGARCH_CSR_CRMD + ld.d $t0, $sp, LOONGARCH_CSR_PRMD * RSIZE + csrwr $t0, LOONGARCH_CSR_PRMD + ld.d $t0, $sp, LOONGARCH_CSR_ECFG * RSIZE + csrwr $t0, LOONGARCH_CSR_ECFG + ld.d $t0, $sp, LOONGARCH_CSR_ERA * RSIZE + csrwr $t0, LOONGARCH_CSR_ERA + + addi.d $sp, $sp, CSR_REG_CONTEXT_SIZE // Fource change the stack point= er befor pop the FP registers. + + beqz $t1, PopGP // If the FPE not set, only pop = the GP registers. + + // + // Pop FP registers + // + fld.d $fa0, $sp, 0 * RSIZE + fld.d $fa1, $sp, 1 * RSIZE + fld.d $fa2, $sp, 2 * RSIZE + fld.d $fa3, $sp, 3 * RSIZE + fld.d $fa4, $sp, 4 * RSIZE + fld.d $fa5, $sp, 5 * RSIZE + fld.d $fa6, $sp, 6 * RSIZE + fld.d $fa7, $sp, 7 * RSIZE + fld.d $ft0, $sp, 8 * RSIZE + fld.d $ft1, $sp, 9 * RSIZE + fld.d $ft2, $sp, 10 * RSIZE + fld.d $ft3, $sp, 11 * RSIZE + fld.d $ft4, $sp, 12 * RSIZE + fld.d $ft5, $sp, 13 * RSIZE + fld.d $ft6, $sp, 14 * RSIZE + fld.d $ft7, $sp, 15 * RSIZE + fld.d $ft8, $sp, 16 * RSIZE + fld.d $ft9, $sp, 17 * RSIZE + fld.d $ft10, $sp, 18 * RSIZE + fld.d $ft11, $sp, 19 * RSIZE + fld.d $ft12, $sp, 20 * RSIZE + fld.d $ft13, $sp, 21 * RSIZE + fld.d $ft14, $sp, 22 * RSIZE + fld.d $ft15, $sp, 23 * RSIZE + fld.d $fs0, $sp, 24 * RSIZE + fld.d $fs1, $sp, 25 * RSIZE + fld.d $fs2, $sp, 26 * RSIZE + fld.d $fs3, $sp, 27 * RSIZE + fld.d $fs4, $sp, 28 * RSIZE + fld.d $fs5, $sp, 29 * RSIZE + fld.d $fs6, $sp, 30 * RSIZE + fld.d $fs7, $sp, 31 * RSIZE + + ld.d $t0, $sp, 32 * RSIZE + movgr2fcsr $r0, $t0 // Pop the fcsr0 register. + + // + // Pop the fcc0-fcc7 registers. + // + ld.d $t0, $sp, 33 * RSIZE + bstrpick.d $t1, $t0, 7, 0 + movgr2cf $fcc0, $t1 + bstrpick.d $t1, $t0, 15, 8 + movgr2cf $fcc1, $t1 + bstrpick.d $t1, $t0, 23, 16 + movgr2cf $fcc2, $t1 + bstrpick.d $t1, $t0, 31, 24 + movgr2cf $fcc3, $t1 + bstrpick.d $t1, $t0, 39, 32 + movgr2cf $fcc4, $t1 + bstrpick.d $t1, $t0, 47, 40 + movgr2cf $fcc5, $t1 + bstrpick.d $t1, $t0, 55, 48 + movgr2cf $fcc6, $t1 + bstrpick.d $t1, $t0, 63, 56 + movgr2cf $fcc7, $t1 + +PopGP: + // + // Pop GP registers + // + addi.d $sp, $sp, -(GP_REG_CONTEXT_SIZE + CSR_REG_CONTEXT_SIZE) + ld.d $ra, $sp, 1 * RSIZE + ld.d $tp, $sp, 2 * RSIZE + ld.d $a0, $sp, 4 * RSIZE + ld.d $a1, $sp, 5 * RSIZE + ld.d $a2, $sp, 6 * RSIZE + ld.d $a3, $sp, 7 * RSIZE + ld.d $a4, $sp, 8 * RSIZE + ld.d $a5, $sp, 9 * RSIZE + ld.d $a6, $sp, 10 * RSIZE + ld.d $a7, $sp, 11 * RSIZE + ld.d $t0, $sp, 12 * RSIZE + ld.d $t1, $sp, 13 * RSIZE + ld.d $t2, $sp, 14 * RSIZE + ld.d $t3, $sp, 15 * RSIZE + ld.d $t4, $sp, 16 * RSIZE + ld.d $t5, $sp, 17 * RSIZE + ld.d $t6, $sp, 18 * RSIZE + ld.d $t7, $sp, 19 * RSIZE + ld.d $t8, $sp, 20 * RSIZE + ld.d $r21, $sp, 21 * RSIZE + ld.d $fp, $sp, 22 * RSIZE + ld.d $s0, $sp, 23 * RSIZE + ld.d $s1, $sp, 24 * RSIZE + ld.d $s2, $sp, 25 * RSIZE + ld.d $s3, $sp, 26 * RSIZE + ld.d $s4, $sp, 27 * RSIZE + ld.d $s5, $sp, 28 * RSIZE + ld.d $s6, $sp, 29 * RSIZE + ld.d $s7, $sp, 30 * RSIZE + ld.d $s8, $sp, 31 * RSIZE + ld.d $sp, $sp, 3 * RSIZE + + ertn // Returen from exception. +// +// End of ExceptionEntry +// + +ASM_PFX(ExceptionEntryStart): + // + // Store the old stack pointer in preparation for pushing the exception = context onto the new stack. + // + csrwr $sp, LOONGARCH_CSR_KS0 + + csrrd $sp, LOONGARCH_CSR_KS0 + + // + // Push GP registers + // + addi.d $sp, $sp, -(GP_REG_CONTEXT_SIZE + FP_REG_CONTEXT_SIZE + CSR_REG_= CONTEXT_SIZE) + st.d $zero, $sp, 0 * RSIZE + st.d $ra, $sp, 1 * RSIZE + st.d $tp, $sp, 2 * RSIZE + st.d $a0, $sp, 4 * RSIZE + st.d $a1, $sp, 5 * RSIZE + st.d $a2, $sp, 6 * RSIZE + st.d $a3, $sp, 7 * RSIZE + st.d $a4, $sp, 8 * RSIZE + st.d $a5, $sp, 9 * RSIZE + st.d $a6, $sp, 10 * RSIZE + st.d $a7, $sp, 11 * RSIZE + st.d $t0, $sp, 12 * RSIZE + st.d $t1, $sp, 13 * RSIZE + st.d $t2, $sp, 14 * RSIZE + st.d $t3, $sp, 15 * RSIZE + st.d $t4, $sp, 16 * RSIZE + st.d $t5, $sp, 17 * RSIZE + st.d $t6, $sp, 18 * RSIZE + st.d $t7, $sp, 19 * RSIZE + st.d $t8, $sp, 20 * RSIZE + st.d $r21, $sp, 21 * RSIZE + st.d $fp, $sp, 22 * RSIZE + st.d $s0, $sp, 23 * RSIZE + st.d $s1, $sp, 24 * RSIZE + st.d $s2, $sp, 25 * RSIZE + st.d $s3, $sp, 26 * RSIZE + st.d $s4, $sp, 27 * RSIZE + st.d $s5, $sp, 28 * RSIZE + st.d $s6, $sp, 29 * RSIZE + st.d $s7, $sp, 30 * RSIZE + st.d $s8, $sp, 31 * RSIZE + csrrd $t0, LOONGARCH_CSR_KS0 // Read the old stack pointer. + st.d $t0, $sp, 3 * RSIZE + + // + // Push CSR registers + // + addi.d $sp, $sp, GP_REG_CONTEXT_SIZE + + csrrd $t0, LOONGARCH_CSR_CRMD + st.d $t0, $sp, LOONGARCH_CSR_CRMD * RSIZE + csrrd $t0, LOONGARCH_CSR_PRMD + st.d $t0, $sp, LOONGARCH_CSR_PRMD * RSIZE + csrrd $t0, LOONGARCH_CSR_EUEN + st.d $t0, $sp, LOONGARCH_CSR_EUEN * RSIZE + csrrd $t0, LOONGARCH_CSR_MISC + st.d $t0, $sp, LOONGARCH_CSR_MISC * RSIZE + csrrd $t0, LOONGARCH_CSR_ECFG + st.d $t0, $sp, LOONGARCH_CSR_ECFG * RSIZE + csrrd $t0, LOONGARCH_CSR_ESTAT + st.d $t0, $sp, LOONGARCH_CSR_ESTAT * RSIZE + csrrd $t0, LOONGARCH_CSR_ERA + st.d $t0, $sp, LOONGARCH_CSR_ERA * RSIZE + csrrd $t0, LOONGARCH_CSR_BADV + st.d $t0, $sp, LOONGARCH_CSR_BADV * RSIZE + csrrd $t0, LOONGARCH_CSR_BADI + st.d $t0, $sp, LOONGARCH_CSR_BADI * RSIZE + + // + // Push FP registers + // + addi.d $sp, $sp, CSR_REG_CONTEXT_SIZE + + csrrd $t0, LOONGARCH_CSR_EUEN + andi $t0, $t0, CSR_EUEN_FPEN + beqz $t0, PushRegDone + + fst.d $fa0, $sp, 0 * RSIZE + fst.d $fa1, $sp, 1 * RSIZE + fst.d $fa2, $sp, 2 * RSIZE + fst.d $fa3, $sp, 3 * RSIZE + fst.d $fa4, $sp, 4 * RSIZE + fst.d $fa5, $sp, 5 * RSIZE + fst.d $fa6, $sp, 6 * RSIZE + fst.d $fa7, $sp, 7 * RSIZE + fst.d $ft0, $sp, 8 * RSIZE + fst.d $ft1, $sp, 9 * RSIZE + fst.d $ft2, $sp, 10 * RSIZE + fst.d $ft3, $sp, 11 * RSIZE + fst.d $ft4, $sp, 12 * RSIZE + fst.d $ft5, $sp, 13 * RSIZE + fst.d $ft6, $sp, 14 * RSIZE + fst.d $ft7, $sp, 15 * RSIZE + fst.d $ft8, $sp, 16 * RSIZE + fst.d $ft9, $sp, 17 * RSIZE + fst.d $ft10, $sp, 18 * RSIZE + fst.d $ft11, $sp, 19 * RSIZE + fst.d $ft12, $sp, 20 * RSIZE + fst.d $ft13, $sp, 21 * RSIZE + fst.d $ft14, $sp, 22 * RSIZE + fst.d $ft15, $sp, 23 * RSIZE + fst.d $fs0, $sp, 24 * RSIZE + fst.d $fs1, $sp, 25 * RSIZE + fst.d $fs2, $sp, 26 * RSIZE + fst.d $fs3, $sp, 27 * RSIZE + fst.d $fs4, $sp, 28 * RSIZE + fst.d $fs5, $sp, 29 * RSIZE + fst.d $fs6, $sp, 30 * RSIZE + fst.d $fs7, $sp, 31 * RSIZE + + movfcsr2gr $t3, $r0 + st.d $t3, $sp, 32 * RSIZE // Push the FCSR0 register. + + // + // Push the fcc0-fcc7 registers. + // + movcf2gr $t3, $fcc0 + or $t2, $t3, $zero + movcf2gr $t3, $fcc1 + bstrins.d $t2, $t3, 0xf, 0x8 + movcf2gr $t3, $fcc2 + bstrins.d $t2, $t3, 0x17, 0x10 + movcf2gr $t3, $fcc3 + bstrins.d $t2, $t3, 0x1f, 0x18 + movcf2gr $t3, $fcc4 + bstrins.d $t2, $t3, 0x27, 0x20 + movcf2gr $t3, $fcc5 + bstrins.d $t2, $t3, 0x2f, 0x28 + movcf2gr $t3, $fcc6 + bstrins.d $t2, $t3, 0x37, 0x30 + movcf2gr $t3, $fcc7 + bstrins.d $t2, $t3, 0x3f, 0x38 + st.d $t2, $sp, 33 * RSIZE + // + // Push exception context down + // + +PushRegDone: + // + // Process IPI only when mailbox3 is NULL and mailbox0 is no-NULL. + // + li.d $t0, LOONGARCH_IOCSR_MBUF0 + iocsrrd.d $a0, $t0 + beqz $a0, EntryConmmonHanlder + + li.d $t0, LOONGARCH_IOCSR_MBUF3 + iocsrrd.d $t1, $t0 + bnez $t1, EntryConmmonHanlder + + csrrd $t0, LOONGARCH_CSR_ESTAT + srli.d $t0, $t0, 12 + andi $t0, $t0, 0x1 + beqz $t0, EntryConmmonHanlder + + // + // Clean up current processor mailbox 0 and mailbox 3. + // + li.d $t0, LOONGARCH_IOCSR_MBUF0 + iocsrwr.d $zero, $t0 + li.d $t0, LOONGARCH_IOCSR_MBUF3 + iocsrwr.d $zero, $t0 + + // + // Clear IPI interrupt. + // + li.d $t0, LOONGARCH_IOCSR_IPI_STATUS + iocsrrd.w $t1, $t0 + li.d $t0, LOONGARCH_IOCSR_IPI_CLEAR + iocsrwr.w $t1, $t0 + + // + // Only kernel stage BSP calls IPI without parameters. Clean up the PIE = and make sure + // global interrupts are turned off for the current processor when jumpi= ng to the kernel. + // + csrwr $a0, LOONGARCH_CSR_ERA // Update ERA + li.w $t0, BIT2 // IE + csrxchg $zero, $t0, LOONGARCH_CSR_PRMD // Clean PIE + + // + // Return this exception and jump to kernel using ERA. + // + ertn + +EntryConmmonHanlder: + addi.d $sp, $sp, -(GP_REG_CONTEXT_SIZE + CSR_REG_CONTEXT_SIZE) + move $a0, $sp + la.abs $ra, ExceptionEntry + jirl $zero, $ra, 0 +ASM_PFX(ExceptionEntryEnd): +.end diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/SecPeiExce= ptionLib.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/SecPeiExce= ptionLib.c new file mode 100644 index 0000000000..7588d2050b --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/SecPeiExceptionLi= b.c @@ -0,0 +1,102 @@ +/** @file SecPeiExceptionLib.c + + LoongArch exception library implemenation for PEI and SEC modules. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include + +#include "ExceptionCommon.h" + +/** + Registers a function to be called from the processor interrupt or except= ion handler. + + Always return EFI_UNSUPPORTED in the SEC exception initialization module. + + @param InterruptType A pointer to the processor's current interrupt = state. Set to TRUE if interrupts + are enabled and FALSE if interrupts are disable= d. + @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRU= PT_HANDLER that is called + when a processor interrupt occurs. If this para= meter is NULL, then the handler + will be uninstalled. + + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not= supported. + +**/ +EFI_STATUS +RegisterCpuInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Common exception handler. + + @param ExceptionType Exception type. + @param SystemContext Pointer to EFI_SYSTEM_CONTEXT. + +**/ +VOID +EFIAPI +CommonExceptionHandler ( + IN EFI_EXCEPTION_TYPE ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + EFI_EXCEPTION_TYPE InterruptType; + + if (ExceptionType =3D=3D EXCEPT_LOONGARCH_INT) { + // + // Interrupt + // + InterruptType =3D GetInterruptType (SystemContext); + if (InterruptType =3D=3D EXCEPT_LOONGARCH_INT_IPI) { + // + // APs may wake up via IPI IRQ during the SEC or PEI phase, clear th= e IPI interrupt and + // perform the remaining work. + // + IpiInterruptHandler (InterruptType, SystemContext); + return; + } else { + ExceptionType =3D InterruptType; + } + } else { + // + // Exception + // + ExceptionType >>=3D CSR_ESTAT_EXC_SHIFT; + } + + DefaultExceptionHandler (ExceptionType, SystemContext); +} + +/** + Initializes all CPU exceptions entries and provides the default exceptio= n handlers. + + Always return EFI_SUCCESS in the SEC exception initialization module. + + @param[in] VectorInfo Pointer to reserved vector list. + + @retval EFI_SUCCESS CPU Exception Entries have been successfully i= nitialized + with default exception handlers. + +**/ +EFI_STATUS +EFIAPI +InitializeCpuExceptionHandlers ( + IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL + ) +{ + return EFI_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHa= ndlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException= HandlerLib.inf index e7b1144f69..6bb194ea77 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf @@ -2,6 +2,7 @@ # CPU Exception Handler library instance for SEC/PEI modules. # # Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.
+# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights= reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -18,37 +19,47 @@ # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 +# VALID_ARCHITECTURES =3D IA32 X64 LOONGARCH64 # =20 [Sources.Ia32] - Ia32/ExceptionHandlerAsm.nasm - Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/ExceptionHandlerAsm.nasm + Ia32/ExceptionTssEntryAsm.nasm =20 [Sources.X64] - X64/SecPeiExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/SecPeiExceptionHandlerAsm.nasm =20 -[Sources.common] +[Sources.Ia32, Sources.X64] CpuExceptionCommon.h CpuExceptionCommon.c SecPeiCpuException.c =20 +[Sources.LoongArch64] + LoongArch/ExceptionCommon.h + LoongArch/ExceptionCommon.c + LoongArch/SecPeiExceptionLib.c + LoongArch/LoongArch64/ArchExceptionHandler.c + LoongArch/LoongArch64/ExceptionHandlerAsm.S | GCC + [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 -[LibraryClasses] +[LibraryClasses.common] BaseLib - SerialPortLib - PrintLib - LocalApicLib + CpuLib PeCoffGetEntryPointLib + PrintLib + SerialPortLib + +[LibraryClasses.Ia32, LibraryClasses.X64] CcExitLib + LocalApicLib =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 571b59b36f..f5febe46ba 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -3,6 +3,7 @@ # # Copyright (c) 2007 - 2023, Intel Corporation. All rights reserved.
# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -385,6 +386,10 @@ # @Prompt Enable performance collecting when processor trace is enabled. gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTracePerformanceCollecting|FALSE|BOO= LEAN|0x60000020 =20 + ## This PCD Contains the pointer to a CPU exception vector base address. + # @Prompt The pointer to a CPU exception vector base address. + gUefiCpuPkgTokenSpaceGuid.PcdCpuExceptionVectorBaseAddress|0x0|UINT64|0x= 60000022 + [PcdsFixedAtBuild.X64, PcdsPatchableInModule.X64, PcdsDynamic.X64, PcdsDyn= amicEx.X64] ## Indicate access to non-SMRAM memory is restricted to reserved, runtim= e and ACPI NVS type after SmmReadyToLock. # MMIO access is always allowed regardless of the value of this PCD. --=20 2.27.0 -=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 (#114538): https://edk2.groups.io/g/devel/message/114538 Mute This Topic: https://groups.io/mt/103971651/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- From nobody Thu Dec 26 20:24:45 2024 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+114539+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+114539+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250559; cv=none; d=zohomail.com; s=zohoarc; b=Tm5KwgQcuzUAiqAIvxqom8CH2VdRo8tA0fMWPNUSoTM+h8HHNFuU0bzcjt8J91SDIi3WMYj8GDU+lnYI8ZPcuTTLB0z0iCyaKgQbtNUqLSLwCSADZ9boBZzHKq7JZVf4FP1UX4gGtoRqnFfDPMxS1ACHGY1+VIPkwohhHMfoFLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250559; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=Wn5vWINPru6mc+cjqA/eCe7Y2DB7RRnP8+97utV1p6I=; b=LPso3d3XxMILMtTYGm9+u2wgMvMuCKNDDFrG85ZQULxBMA/wKlJGYiHsRSFeaqRPHAIswG3GKv4ioUCprYT8bIgXs1N43KYfzkG6uPl7STYkUHgzPmomBXRmRunkrxWSZZf0iU3uATK7Mnz4HIcZ3tmyKrLZhJo5Cw8iuNqVAJg= 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+114539+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250559675147.8769369691331; Thu, 25 Jan 2024 22:29:19 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=CcFTbbmFqhqHPszYDAzrfEatOgYAZzC71vWoCvsOqv0=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250559; v=1; b=A5z7vAkgmlB93r6WDhWw/lfutLgk43YPAGNO4P70j+znRH6Mh7AQ4UBmDvoprWu2CDmAWKNo EXDJLyGPLSuRW7BAQxmB9Dt5kHjeS0oLww8ar9uYWTysKnnQZBVbKjKmu5eyplTntm1eqpPQB/J STpzAqDEBJaL7TITbw47m2QI= X-Received: by 127.0.0.2 with SMTP id x8ULYY1788612xQmVwwW3NE1; Thu, 25 Jan 2024 22:29:19 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10132.1706250558268462608 for ; Thu, 25 Jan 2024 22:29:18 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8Axeeg7UbNlDh4GAA--.2132S3; Fri, 26 Jan 2024 14:29:15 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx_c46UbNlPnIbAA--.53339S2; Fri, 26 Jan 2024 14:29:14 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Laszlo Ersek , Rahul Kumar , Gerd Hoffmann , Leif Lindholm , Ard Biesheuvel , Sami Mujawar , Sunil V L , Andrei Warkentin Subject: [edk2-devel] [PATCH v8 13/37] UefiCpuPkg: Add CpuMmuLib.h to UefiCpuPkg Date: Fri, 26 Jan 2024 14:29:13 +0800 Message-Id: <20240126062913.3101629-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cx_c46UbNlPnIbAA--.53339S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBKsV X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: MjDjZLpHO46zZREGHal6FWFMx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250560266100009 Content-Type: text/plain; charset="utf-8" Add a new header file CpuMmuLib.h, whitch is referenced from ArmPkg/Include/Library/ArmMmuLib.h. Currently, only support for LoongArch64 is added, and more architectures can be accommodated in the future. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Sunil V L Cc: Andrei Warkentin Signed-off-by: Chao Li Reviewed-by: Andrei Warkentin Reviewed-by: Ray Ni --- UefiCpuPkg/Include/Library/CpuMmuLib.h | 62 ++++++++++++++++++++++++++ UefiCpuPkg/UefiCpuPkg.dec | 4 ++ 2 files changed, 66 insertions(+) create mode 100644 UefiCpuPkg/Include/Library/CpuMmuLib.h diff --git a/UefiCpuPkg/Include/Library/CpuMmuLib.h b/UefiCpuPkg/Include/Li= brary/CpuMmuLib.h new file mode 100644 index 0000000000..f88ec4eb2e --- /dev/null +++ b/UefiCpuPkg/Include/Library/CpuMmuLib.h @@ -0,0 +1,62 @@ +/** @file + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef CPU_MMU_LIB_H_ +#define CPU_MMU_LIB_H_ + +#include + +typedef struct { + EFI_PHYSICAL_ADDRESS PhysicalBase; + EFI_VIRTUAL_ADDRESS VirtualBase; + UINTN Length; + UINTN Attributes; +} MEMORY_REGION_DESCRIPTOR; + +/** + Finds the first of the length and memory properties of the memory region= corresponding + to the specified base address. + + @param[in] BaseAddress To find the base address of the memor= y region. + @param[in, out] RegionLength Pointer holding: + - At entry, the length of the memory= region + expected to be found. + - At exit, the length of the memory = region found. + @param[out] RegionAttributes Properties of the memory region found. + + @retval EFI_SUCCESS The corresponding memory area was successfully f= ound + EFI_NOT_FOUND No memory area found +**/ +EFI_STATUS +EFIAPI +GetMemoryRegionAttributes ( + IN UINTN BaseAddress, + IN OUT UINTN *RegionLength, + OUT UINTN *RegionAttributes + ); + +/** + Sets the Attributes of the specified memory region. + + @param[in] BaseAddress The base address of the memory region to set = the Attributes. + @param[in] Length The length of the memory region to set the At= tributes. + @param[in] Attributes The Attributes to be set. + @param[in] AttributeMask Mask of memory attributes to take into accoun= t. + + @retval EFI_SUCCESS The Attributes was set successfully +**/ +EFI_STATUS +EFIAPI +SetMemoryRegionAttributes ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINTN Length, + IN UINTN Attributes, + IN UINT64 AttributeMask + ); + +#endif // CPU_MMU_LIB_H_ diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index f5febe46ba..9992626e62 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -62,6 +62,10 @@ ## @libraryclass Provides function for manipulating x86 paging structu= res. CpuPageTableLib|Include/Library/CpuPageTableLib.h =20 +[LibraryClasses.LoongArch64] + ## @libraryclass Provides macros and functions for the memory manageme= nt unit. + CpuMmuLib|Include/Library/CpuMmuLib.h + ## @libraryclass Provides functions for manipulating smram savestate r= egisters. MmSaveStateLib|Include/Library/MmSaveStateLib.h =20 --=20 2.27.0 -=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 (#114539): https://edk2.groups.io/g/devel/message/114539 Mute This Topic: https://groups.io/mt/103971652/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- From nobody Thu Dec 26 20:24:45 2024 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+114540+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+114540+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250567; cv=none; d=zohomail.com; s=zohoarc; b=V9wVYiQtoN5KPfoKYhz1uqH4k5Mn1ZcInn7/xwU82uM/RXDvIkkAPsX5RFWDt+XK6UqYKpDzzIr/Ipy0zkl2wAba2PP9Yrz0tQFps4OK8g7D7OVTueIOh2B58k1R6a6NWvaafnQzSLf2cm9nCRfyRXxELLbS91hZSHvrvnyXxc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250567; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=OJx1HAqCpLcaO8LD7k/hrko9XGH842FiCvvxZk3O9io=; b=nVJ1rJ95PMJCFkOpJfwe6fKhfg+vk52+IYoC+cLd+D5cHPJncSffAwyFSQiyQEmcPIVncqjQgWKPBg1FfjeH/mgFbi5gO7BjTU+u/p5BDsgRVCRbeagjljrBuuxWc9f5N5kzEfajeSQRIsGl1RkUqLi7PftPGdk0Oh9WklIl2fQ= 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+114540+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250567972424.2956116281123; Thu, 25 Jan 2024 22:29:27 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=0OgStR2Ot6VmSloLdKTMAocXil+gBOnm67JB8PB+5aA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250567; v=1; b=PZrMSWCLvy4S7OlxZDjcYFdEbOfsrKtxfZSPfP4R5wM/eGCfq4t1B3aeYzE+yZ9Q+P6ftCsV 0iMALxRZgiSaTCu9nrG7Duec/vHsrXfD5GkDetgjelVfHxPx1OFDTTl8bQOpvnBE80sA86FkzXl yrA/SyMet1bh9HnF8PDDsfZY= X-Received: by 127.0.0.2 with SMTP id ZRdlYY1788612xCxFv17RkrW; Thu, 25 Jan 2024 22:29:27 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10134.1706250565583432027 for ; Thu, 25 Jan 2024 22:29:27 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxWOhCUbNlHR4GAA--.2174S3; Fri, 26 Jan 2024 14:29:22 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxRMxAUbNlUXIbAA--.44278S2; Fri, 26 Jan 2024 14:29:20 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Laszlo Ersek , Rahul Kumar , Gerd Hoffmann , Baoqi Zhang , Dongyan Qian , Xianglai Li , Bibo Mao Subject: [edk2-devel] [PATCH v8 14/37] UefiCpuPkg: Add CpuMmuLib to UefiCpuPkg Date: Fri, 26 Jan 2024 14:29:19 +0800 Message-Id: <20240126062919.3101691-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxRMxAUbNlUXIbAA--.44278S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBLsU X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 8ueUNKc4zii2ZpJ7a51R1MUax1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250568312100003 Content-Type: text/plain; charset="utf-8" Add a new library named CpuMmuLib and add a LoongArch64 instance with in the library. It provides two-stage MMU libraryinstances, PEI and DXE. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Chao Li Co-authored-by: Baoqi Zhang Co-authored-by: Dongyan Qian Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao --- UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.inf | 36 + UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.uni | 14 + .../CpuMmuLib/LoongArch64/CommonMmuLib.c | 988 ++++++++++++++++++ .../CpuMmuLib/LoongArch64/CommonMmuLib.h | 43 + .../Library/CpuMmuLib/LoongArch64/Page.h | 279 +++++ .../CpuMmuLib/LoongArch64/PeiCpuMmuLib.c | 178 ++++ .../Library/CpuMmuLib/LoongArch64/Tlb.h | 48 + .../CpuMmuLib/LoongArch64/TlbOperation.S | 44 + UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.inf | 44 + UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.uni | 14 + UefiCpuPkg/UefiCpuPkg.dsc | 4 + 11 files changed, 1692 insertions(+) create mode 100644 UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.inf create mode 100644 UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.uni create mode 100644 UefiCpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.c create mode 100644 UefiCpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.h create mode 100644 UefiCpuPkg/Library/CpuMmuLib/LoongArch64/Page.h create mode 100644 UefiCpuPkg/Library/CpuMmuLib/LoongArch64/PeiCpuMmuLib.c create mode 100644 UefiCpuPkg/Library/CpuMmuLib/LoongArch64/Tlb.h create mode 100644 UefiCpuPkg/Library/CpuMmuLib/LoongArch64/TlbOperation.S create mode 100644 UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.inf create mode 100644 UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.uni diff --git a/UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.inf b/UefiCpuPkg/Lib= rary/CpuMmuLib/DxeCpuMmuLib.inf new file mode 100644 index 0000000000..bfce3ce96d --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.inf @@ -0,0 +1,36 @@ +## @file +# CPU Memory Map Unit DXE phase driver. +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D DxeCpuMmuLib + MODULE_UNI_FILE =3D DxeCpuMmuLib.uni + FILE_GUID =3D DA8F0232-FB14-42F0-922C-63104D2C70BE + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D CpuMmuLib | DXE_DRIVER + CONSTRUCTOR =3D MmuInitialize + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources.LoongArch64] + LoongArch64/TlbOperation.S | GCC + LoongArch64/CommonMmuLib.c + LoongArch64/Page.h + LoongArch64/Tlb.h + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + DebugLib + MemoryAllocationLib diff --git a/UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.uni b/UefiCpuPkg/Lib= rary/CpuMmuLib/DxeCpuMmuLib.uni new file mode 100644 index 0000000000..7342249516 --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.uni @@ -0,0 +1,14 @@ +// /** @file +// CPU Memory Manager Unit library instance for DXE modules. +// +// CPU Memory Manager Unit library instance for DXE modules. +// +// Copyright (c) 2024, Loongson Technology Corporation Limited. All rights= reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "CPU Memory Manage= r Unit library instance for DXE modules." + +#string STR_MODULE_DESCRIPTION #language en-US "CPU Memory Manage= r Unit library instance for DXE modules." diff --git a/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.c b/Uefi= CpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.c new file mode 100644 index 0000000000..2e852c3371 --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.c @@ -0,0 +1,988 @@ +/** @file + + CPU Memory Map Unit Handler Library common functions. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Pgd or Pgd or PGD - Page Global Directory + - Pud or Pud or PUD - Page Upper Directory + - Pmd or Pmd or PMD - Page Middle Directory + - Pte or pte or PTE - Page Table Entry + - Val or VAL or val - Value + - Dir - Directory +**/ +#include +#include +#include +#include +#include +#include +#include +#include "Tlb.h" +#include "Page.h" + +#define SWAP_PAGE_DIR CsrRead(LOONGARCH_CSR_PGDL) +#define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | \ + EFI_MEMORY_WC | \ + EFI_MEMORY_WT | \ + EFI_MEMORY_WB | \ + EFI_MEMORY_UCE \ + ) + +BOOLEAN mMmuInited =3D FALSE; + +/** + Check to see if mmu successfully initializes. + + @param VOID. + + @retval TRUE Initialization has been completed. + FALSE Initialization did not complete. +**/ +STATIC +BOOLEAN +MmuIsInit ( + VOID + ) +{ + if (mMmuInited || (SWAP_PAGE_DIR !=3D 0)) { + return TRUE; + } + + return FALSE; +} + +/** + Iterates through the page directory to initialize it. + + @param Dst A pointer to the directory of the page to initialize. + @param Num The number of page directories to initialize. + @param Src A pointer to the data used to initialize the page directory. + + @return VOID. +**/ +STATIC +VOID +PageDirInit ( + IN VOID *Dst, + IN UINTN Num, + IN VOID *Src + ) +{ + UINTN *Ptr; + UINTN *End; + UINTN Entry; + + Entry =3D (UINTN)Src; + Ptr =3D (UINTN *)Dst; + End =3D Ptr + Num; + + for ( ; Ptr < End; Ptr++) { + *Ptr =3D Entry; + } + + return; +} + +/** + Gets the virtual address corresponding to the page global directory tabl= e entry. + + @param Address the virtual address for the table entry. + + @retval PGD A pointer to get the table item. +**/ +STATIC +PGD * +PgdOffset ( + IN UINTN Address + ) +{ + return (PGD *)(SWAP_PAGE_DIR) + PGD_INDEX (Address); +} + +/** + Gets the virtual address corresponding to the page upper directory table= entry. + + @param Pgd A pointer to a page global directory table entry. + @param Address the virtual address for the table entry. + + @retval PUD A pointer to get the table item. +**/ +STATIC +PUD * +PudOffset ( + IN PGD *Pgd, + IN UINTN Address + ) +{ + UINTN PgdVal; + + PgdVal =3D (UINTN)PGD_VAL (*Pgd); + + return (PUD *)PgdVal + PUD_INDEX (Address); +} + +/** + Gets the virtual address corresponding to the page middle directory tabl= e entry. + + @param Pud A pointer to a page upper directory table entry. + @param Address the virtual address for the table entry. + + @retval PMD A pointer to get the table item. +**/ +STATIC +PMD * +PmdOffset ( + IN PUD *Pud, + IN UINTN Address + ) +{ + UINTN PudVal; + + PudVal =3D PUD_VAL (*Pud); + + return (PMD *)PudVal + PMD_INDEX (Address); +} + +/** + Gets the virtual address corresponding to the page table entry. + + @param Pmd A pointer to a page middle directory table entry. + @param Address the virtual address for the table entry. + + @retval PTE A pointer to get the table item. +**/ +STATIC +PTE * +PteOffset ( + IN PMD *Pmd, + IN UINTN Address + ) +{ + UINTN PmdVal; + + PmdVal =3D (UINTN)PMD_VAL (*Pmd); + + return (PTE *)PmdVal + PTE_INDEX (Address); +} + +/** + Sets the value of the page table entry. + + @param Pte A pointer to a page table entry. + @param PteVal The value of the page table entry to set. + +**/ +STATIC +VOID +SetPte ( + IN PTE *Pte, + IN PTE PteVal + ) +{ + *Pte =3D PteVal; +} + +/** + Sets the value of the page global directory. + + @param Pgd A pointer to a page global directory. + @param Pud The value of the page global directory to set. + +**/ +STATIC +VOID +SetPgd ( + IN PGD *Pgd, + IN PUD *Pud + ) +{ + *Pgd =3D (PGD) { + ((UINTN)Pud) + }; +} + +/** + Sets the value of the page upper directory. + + @param Pud A pointer to a page upper directory. + @param Pmd The value of the page upper directory to set. + +**/ +STATIC +VOID +SetPud ( + IN PUD *Pud, + IN PMD *Pmd + ) +{ + *Pud =3D (PUD) { + ((UINTN)Pmd) + }; +} + +/** + Sets the value of the page middle directory. + + @param Pmd A pointer to a page middle directory. + @param Pte The value of the page middle directory to set. + +**/ +STATIC +VOID +SetPmd ( + IN PMD *Pmd, + IN PTE *Pte + ) +{ + *Pmd =3D (PMD) { + ((UINTN)Pte) + }; +} + +/** + Free up memory space occupied by page tables. + + @param Pte A pointer to the page table. + +**/ +VOID +PteFree ( + IN PTE *Pte + ) +{ + FreePages ((VOID *)Pte, 1); +} + +/** + Free up memory space occupied by page middle directory. + + @param Pmd A pointer to the page middle directory. + +**/ +VOID +PmdFree ( + IN PMD *Pmd + ) +{ + FreePages ((VOID *)Pmd, 1); +} + +/** + Free up memory space occupied by page upper directory. + + @param Pud A pointer to the page upper directory. + +**/ +VOID +PudFree ( + IN PUD *Pud + ) +{ + FreePages ((VOID *)Pud, 1); +} + +/** + Requests the memory space required for the page upper directory, + initializes it, and places it in the specified page global directory + + @param Pgd A pointer to the page global directory. + + @retval EFI_SUCCESS Memory request successful. + @retval EFI_OUT_OF_RESOURCES Resource exhaustion cannot be requested t= o memory. +**/ +STATIC +EFI_STATUS +PudAlloc ( + IN PGD *Pgd + ) +{ + PUD *Pud; + + Pud =3D (PUD *)AllocatePages (1); + if (Pud =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + PageDirInit ((VOID *)Pud, ENTRYS_PER_PUD, (VOID *)INVALID_PAGE); + + SetPgd (Pgd, Pud); + + return EFI_SUCCESS; +} + +/** + Requests the memory space required for the page middle directory, + initializes it, and places it in the specified page upper directory + + @param Pud A pointer to the page upper directory. + + @retval EFI_SUCCESS Memory request successful. + @retval EFI_OUT_OF_RESOURCES Resource exhaustion cannot be requested t= o memory. +**/ +STATIC +EFI_STATUS +PmdAlloc ( + IN PUD *Pud + ) +{ + PMD *Pmd; + + Pmd =3D (PMD *)AllocatePages (1); + if (!Pmd) { + return EFI_OUT_OF_RESOURCES; + } + + PageDirInit ((VOID *)Pmd, ENTRYS_PER_PMD, (VOID *)INVALID_PAGE); + + SetPud (Pud, Pmd); + + return EFI_SUCCESS; +} + +/** + Requests the memory space required for the page table, + initializes it, and places it in the specified page middle directory + + @param Pmd A pointer to the page middle directory. + + @retval EFI_SUCCESS Memory request successful. + @retval EFI_OUT_OF_RESOURCES Resource exhaustion cannot be requested t= o memory. +**/ +STATIC +EFI_STATUS +PteAlloc ( + IN PMD *Pmd + ) +{ + PTE *Pte; + + Pte =3D (PTE *)AllocatePages (1); + if (!Pte) { + return EFI_OUT_OF_RESOURCES; + } + + Pte =3D ZeroMem (Pte, EFI_PAGE_SIZE); + + SetPmd (Pmd, Pte); + + return EFI_SUCCESS; +} + +/** + Requests the memory space required for the page upper directory, + initializes it, and places it in the specified page global directory, + and get the page upper directory entry corresponding to the virtual addr= ess. + + @param Pgd A pointer to the page global directory. + @param Address The corresponding virtual address of the page table ent= ry. + + @retval A pointer to the page upper directory entry. Return NUL= L, if + allocate the memory buffer is fail. +**/ +STATIC +PUD * +PudAllocGet ( + IN PGD *Pgd, + IN UINTN Address + ) +{ + EFI_STATUS Status; + + if (PGD_IS_EMPTY (*Pgd)) { + Status =3D PudAlloc (Pgd); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } + } + + return PudOffset (Pgd, Address); +} + +/** + Requests the memory space required for the page middle directory, + initializes it, and places it in the specified page upper directory, + and get the page middle directory entry corresponding to the virtual add= ress. + + @param Pud A pointer to the page upper directory. + @param Address The corresponding virtual address of the page table ent= ry. + + @retval A pointer to the page middle directory entry. Return NU= LL, if + allocate the memory buffer is fail. +**/ +STATIC +PMD * +PmdAllocGet ( + IN PUD *Pud, + IN UINTN Address + ) +{ + EFI_STATUS Status; + + if (PUD_IS_EMPTY (*Pud)) { + Status =3D PmdAlloc (Pud); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } + } + + return PmdOffset (Pud, Address); +} + +/** + Requests the memory space required for the page table, + initializes it, and places it in the specified page middle directory, + and get the page table entry corresponding to the virtual address. + + @param Pmd A pointer to the page upper directory. + @param Address The corresponding virtual address of the page table ent= ry. + + @retval A pointer to the page table entry. Return NULL, if allo= cate + the memory buffer is fail. +**/ +STATIC +PTE * +PteAllocGet ( + IN PMD *Pmd, + IN UINTN Address + ) +{ + EFI_STATUS Status; + + if (PMD_IS_EMPTY (*Pmd)) { + Status =3D PteAlloc (Pmd); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } + } + + return PteOffset (Pmd, Address); +} + +/** + Gets the physical address of the page table entry corresponding to the s= pecified virtual address. + + @param Address The corresponding virtual address of the page table ent= ry. + + @retval A pointer to the page table entry. + @retval NULL +**/ +STATIC +PTE * +GetPteAddress ( + IN UINTN Address + ) +{ + PGD *Pgd; + PUD *Pud; + PMD *Pmd; + + Pgd =3D PgdOffset (Address); + + if (PGD_IS_EMPTY (*Pgd)) { + return NULL; + } + + Pud =3D PudOffset (Pgd, Address); + + if (PUD_IS_EMPTY (*Pud)) { + return NULL; + } + + Pmd =3D PmdOffset (Pud, Address); + if (PMD_IS_EMPTY (*Pmd)) { + return NULL; + } + + if (IS_HUGE_PAGE (Pmd->PmdVal)) { + return ((PTE *)Pmd); + } + + return PteOffset (Pmd, Address); +} + +/** + Gets the Attributes of Huge Page. + + @param Pmd A pointer to the page middle directory. + + @retval Value of Attributes. +**/ +STATIC +UINTN +GetHugePageAttributes ( + IN PMD *Pmd + ) +{ + UINTN Attributes; + UINTN GlobalFlag; + UINTN HugeVal; + + HugeVal =3D PMD_VAL (*Pmd); + Attributes =3D HugeVal & (~HUGEP_PAGE_MASK); + GlobalFlag =3D ((Attributes & (1 << PAGE_HGLOBAL_SHIFT)) >> PAGE_HGLOBA= L_SHIFT) << PAGE_GLOBAL_SHIFT; + Attributes &=3D ~(1 << PAGE_HGLOBAL_SHIFT); + Attributes |=3D GlobalFlag; + return Attributes; +} + +/** + Establishes a page table entry based on the specified memory region. + + @param Pmd A pointer to the page middle directory. + @param Address The memory space start address. + @param End The end address of the memory space. + @param Attributes Memory space Attributes. + + @retval EFI_SUCCESS The page table entry was created successfully. + @retval EFI_OUT_OF_RESOURCES Page table entry establishment failed = due to resource exhaustion. +**/ +STATIC +EFI_STATUS +MemoryMapPteRange ( + IN PMD *Pmd, + IN UINTN Address, + IN UINTN End, + IN UINTN Attributes + ) +{ + PTE *Pte; + PTE PteVal; + BOOLEAN UpDate; + + Pte =3D PteAllocGet (Pmd, Address); + if (!Pte) { + return EFI_OUT_OF_RESOURCES; + } + + DEBUG (( + DEBUG_INFO, + "%a %d Address %p End %p Attributes %llx\n", + __func__, + __LINE__, + Address, + End, + Attributes + )); + + do { + UpDate =3D FALSE; + PteVal =3D MAKE_PTE (Address, Attributes); + + if ((!PTE_IS_EMPTY (*Pte)) && + (PTE_VAL (*Pte) !=3D PTE_VAL (PteVal))) + { + UpDate =3D TRUE; + } + + SetPte (Pte, PteVal); + if (UpDate) { + InvalidTlb (Address); + } + } while (Pte++, Address +=3D EFI_PAGE_SIZE, Address !=3D End); + + return EFI_SUCCESS; +} + +/** + Convert Huge Page to Page. + + @param Pmd A pointer to the page middle directory. + @param Address The memory space start address. + @param End The end address of the memory space. + @param Attributes Memory space Attributes. + + @retval EFI_SUCCESS The page table entry was created successfully. + @retval EFI_OUT_OF_RESOURCES Page table entry establishment failed due= to resource exhaustion. +**/ +STATIC +EFI_STATUS +ConvertHugePageToPage ( + IN PMD *Pmd, + IN UINTN Address, + IN UINTN End, + IN UINTN Attributes + ) +{ + UINTN OldAttributes; + UINTN HugePageEnd; + UINTN HugePageStart; + EFI_STATUS Status; + + Status =3D EFI_SUCCESS; + + if ((PMD_IS_EMPTY (*Pmd)) || + (!IS_HUGE_PAGE (Pmd->PmdVal))) + { + Status |=3D MemoryMapPteRange (Pmd, Address, End, Attributes); + } else { + OldAttributes =3D GetHugePageAttributes (Pmd); + if (Attributes =3D=3D OldAttributes) { + return Status; + } + + SetPmd (Pmd, (PTE *)(INVALID_PAGE)); + HugePageStart =3D Address & PMD_MASK; + HugePageEnd =3D HugePageStart + HUGE_PAGE_SIZE; + ASSERT (HugePageEnd >=3D End); + + if (Address > HugePageStart) { + Status |=3D MemoryMapPteRange (Pmd, HugePageStart, Address, OldAttri= butes); + } + + Status |=3D MemoryMapPteRange (Pmd, Address, End, Attributes); + + if (End < HugePageEnd) { + Status |=3D MemoryMapPteRange (Pmd, End, HugePageEnd, OldAttributes); + } + } + + return Status; +} + +/** + Establishes a page middle directory based on the specified memory region. + + @param Pud A pointer to the page upper directory. + @param Address The memory space start address. + @param End The end address of the memory space. + @param Attributes Memory space Attributes. + + @retval EFI_SUCCESS The page middle directory was created successf= ully. + @retval EFI_OUT_OF_RESOURCES Page middle directory establishment fa= iled due to resource exhaustion. +**/ +STATIC +EFI_STATUS +MemoryMapPmdRange ( + IN PUD *Pud, + IN UINTN Address, + IN UINTN End, + IN UINTN Attributes + ) +{ + PMD *Pmd; + UINTN Next; + PTE PteVal; + BOOLEAN UpDate; + + Pmd =3D PmdAllocGet (Pud, Address); + if (Pmd =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + do { + Next =3D PMD_ADDRESS_END (Address, End); + if (((Address & (~PMD_MASK)) =3D=3D 0) && + ((Next & (~PMD_MASK)) =3D=3D 0) && + (PMD_IS_EMPTY (*Pmd) || IS_HUGE_PAGE (Pmd->PmdVal))) + { + UpDate =3D FALSE; + PteVal =3D MAKE_HUGE_PTE (Address, Attributes); + + if ((!PMD_IS_EMPTY (*Pmd)) && + (PMD_VAL (*Pmd) !=3D PTE_VAL (PteVal))) + { + UpDate =3D TRUE; + } + + SetPmd (Pmd, (PTE *)PteVal.PteVal); + if (UpDate) { + InvalidTlb (Address); + } + } else { + ConvertHugePageToPage (Pmd, Address, Next, Attributes); + } + } while (Pmd++, Address =3D Next, Address !=3D End); + + return EFI_SUCCESS; +} + +/** + Establishes a page upper directory based on the specified memory region. + + @param Pgd A pointer to the page global directory. + @param Address The memory space start address. + @param End The end address of the memory space. + @param Attributes Memory space Attributes. + + @retval EFI_SUCCESS The page upper directory was created successfu= lly. + @retval EFI_OUT_OF_RESOURCES Page upper directory establishment fai= led due to resource exhaustion. +**/ +STATIC +EFI_STATUS +MemoryMapPudRange ( + IN PGD *Pgd, + IN UINTN Address, + IN UINTN End, + IN UINTN Attributes + ) +{ + PUD *Pud; + UINTN Next; + + Pud =3D PudAllocGet (Pgd, Address); + if (Pud =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + do { + Next =3D PUD_ADDRESS_END (Address, End); + if (EFI_ERROR (MemoryMapPmdRange (Pud, Address, Next, Attributes))) { + return EFI_OUT_OF_RESOURCES; + } + } while (Pud++, Address =3D Next, Address !=3D End); + + return EFI_SUCCESS; +} + +/** + Establishes a page global directory based on the specified memory region. + + @param Start The memory space start address. + @param End The end address of the memory space. + @param Attributes Memory space Attributes. + + @retval EFI_SUCCESS The page global directory was created successf= ully. + @retval EFI_OUT_OF_RESOURCES Page global directory establishment fa= iled due to resource exhaustion. +**/ +STATIC +EFI_STATUS +MemoryMapPageRange ( + IN UINTN Start, + IN UINTN End, + IN UINTN Attributes + ) +{ + PGD *Pgd; + UINTN Next; + UINTN Address; + EFI_STATUS Err; + + Address =3D Start; + + /* Get PGD(PTE PMD PUD PGD) in PageTables */ + Pgd =3D PgdOffset (Address); + do { + Next =3D PGD_ADDRESS_END (Address, End); + /* Get Next Align Page to Map */ + Err =3D MemoryMapPudRange (Pgd, Address, Next, Attributes); + if (Err) { + return Err; + } + } while (Pgd++, Address =3D Next, Address !=3D End); + + return EFI_SUCCESS; +} + +/** + Page tables are established from memory-mapped tables. + + @param MemoryRegion A pointer to a memory-mapped table entry. + + @retval EFI_SUCCESS The page table was created successfully. + @retval EFI_OUT_OF_RESOURCES Page table establishment failed due t= o resource exhaustion. +**/ +EFI_STATUS +FillTranslationTable ( + IN MEMORY_REGION_DESCRIPTOR *MemoryRegion + ) +{ + return MemoryMapPageRange ( + MemoryRegion->VirtualBase, + (MemoryRegion->Length + MemoryRegion->VirtualBase), + MemoryRegion->Attributes + ); +} + +/** + Convert EFI Attributes to Loongarch Attributes. + + @param[in] EfiAttributes Efi Attributes. + + @retval Corresponding architecture attributes. +**/ +UINTN +EFIAPI +EfiAttributeConverse ( + IN UINTN EfiAttributes + ) +{ + UINTN LoongArchAttributes; + + LoongArchAttributes =3D PAGE_VALID | PAGE_DIRTY | PLV_KERNEL | PAGE_GLOB= AL; + + switch (EfiAttributes & EFI_MEMORY_CACHETYPE_MASK) { + case EFI_MEMORY_UC: + LoongArchAttributes |=3D CACHE_SUC; + break; + case EFI_MEMORY_WC: + LoongArchAttributes |=3D CACHE_WUC; + break; + case EFI_MEMORY_WT: + case EFI_MEMORY_WB: + LoongArchAttributes |=3D CACHE_CC; + break; + default: + LoongArchAttributes |=3D CACHE_CC; + break; + } + + // Write protection attributes + if (((EfiAttributes & EFI_MEMORY_RO) !=3D 0) || + ((EfiAttributes & EFI_MEMORY_WP) !=3D 0)) + { + LoongArchAttributes &=3D ~PAGE_DIRTY; + } + + if ((EfiAttributes & EFI_MEMORY_RP) !=3D 0) { + LoongArchAttributes |=3D PAGE_NO_READ; + } + + // eXecute protection attribute + if ((EfiAttributes & EFI_MEMORY_XP) !=3D 0) { + LoongArchAttributes |=3D PAGE_NO_EXEC; + } + + return LoongArchAttributes; +} + +/** + Finds the first of the length and memory properties of the memory region= corresponding + to the specified base address. + + @param[in] BaseAddress To find the base address of the memor= y region. + @param[in, out] RegionLength Pointer holding: + - At entry, the length of the memory= region + expected to be found. + - At exit, the length of the memory = region found. + @param[out] RegionAttributes Properties of the memory region found. + + @retval EFI_SUCCESS The corresponding memory area was success= fully found + EFI_NOT_FOUND No memory area found + EFI_OUT_OF_RESOURCES Base address or expected memory region ex= ceeds the maximum + address. +**/ +EFI_STATUS +EFIAPI +GetMemoryRegionAttributes ( + IN UINTN BaseAddress, + IN OUT UINTN *RegionLength, + OUT UINTN *RegionAttributes + ) +{ + PTE *Pte; + UINTN Attributes; + UINTN AttributesTmp; + UINTN MaxAddress; + UINTN EndAddress; + UINTN AddSize; + + if (!MmuIsInit ()) { + return EFI_UNSUPPORTED; + } + + EndAddress =3D BaseAddress + *RegionLength; + MaxAddress =3D LShiftU64 (1ULL, MAX_VA_BITS) - 1; + + // Clean the value to prepare output to find region size. + *RegionLength =3D 0x0; + + if ((BaseAddress >=3D MaxAddress) || (EndAddress >=3D MaxAddress)) { + return EFI_OUT_OF_RESOURCES; + } + + Pte =3D GetPteAddress (BaseAddress); + + if (Pte =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + Attributes =3D GET_PAGE_ATTRIBUTES (*Pte); + if (IS_HUGE_PAGE (Pte->PteVal)) { + *RegionAttributes =3D Attributes & (~(PAGE_HUGE)); + } else { + *RegionAttributes =3D Attributes; + } + + do { + Pte =3D GetPteAddress (BaseAddress); + if (Pte =3D=3D NULL) { + return EFI_SUCCESS; + } + + AttributesTmp =3D GET_PAGE_ATTRIBUTES (*Pte); + if (AttributesTmp =3D=3D Attributes) { + if (IS_HUGE_PAGE (Pte->PteVal)) { + AddSize =3D HUGE_PAGE_SIZE; + } else { + AddSize =3D EFI_PAGE_SIZE; + } + + *RegionLength +=3D AddSize; + BaseAddress +=3D AddSize; + } else { + return EFI_SUCCESS; + } + } while (BaseAddress <=3D EndAddress); + + return EFI_SUCCESS; +} + +/** + Sets the Attributes of the specified memory region + + @param[in] BaseAddress The base address of the memory region to set = the Attributes. + @param[in] Length The length of the memory region to set the At= tributes. + @param[in] Attributes The Attributes to be set. + @param[in] AttributeMask Mask of memory attributes to take into accoun= t. + + @retval EFI_SUCCESS The Attributes was set successfully +**/ +EFI_STATUS +EFIAPI +SetMemoryRegionAttributes ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINTN Length, + IN UINTN Attributes, + IN UINT64 AttributeMask + ) +{ + EFI_STATUS Status; + + if (!MmuIsInit ()) { + return EFI_UNSUPPORTED; + } + + Attributes =3D EfiAttributeConverse (Attributes); + Status =3D MemoryMapPageRange (BaseAddress, BaseAddress + Length, At= tributes); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** + Check to see if mmu successfully initializes and saves the result. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval RETURN_SUCCESS Initialization succeeded. +**/ +RETURN_STATUS +MmuInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + if (SWAP_PAGE_DIR !=3D 0) { + mMmuInited =3D TRUE; + } + + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.h b/Uefi= CpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.h new file mode 100644 index 0000000000..d8c922c8fa --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.h @@ -0,0 +1,43 @@ +/** @file + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Dir - Directory +**/ + +#ifndef MMU_LIB_CORE_H_ +#define MMU_LIB_CORE_H_ + +/** + Iterates through the page directory to initialize it. + + @param Dst A pointer to the directory of the page to initialize. + @param Num The number of page directories to initialize. + @param Src A pointer to the data used to initialize the page directory. + + @retval VOID. +**/ +VOID +PageDirInit ( + IN VOID *dest, + IN UINTN Count, + IN VOID *src + ); + +/** + Page tables are established from memory-mapped tables. + + @param MemoryRegion A pointer to a memory-mapped table entry. + + @retval EFI_SUCCESS The page table was created successfully. + @retval EFI_OUT_OF_RESOURCES Page table establishment failed due t= o resource exhaustion. +**/ +EFI_STATUS +FillTranslationTable ( + IN MEMORY_REGION_DESCRIPTOR *MemoryRegion + ); + +#endif // MMU_LIB_CORE_H_ diff --git a/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/Page.h b/UefiCpuPkg/L= ibrary/CpuMmuLib/LoongArch64/Page.h new file mode 100644 index 0000000000..bac4f52327 --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/Page.h @@ -0,0 +1,279 @@ +/** @file + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Pgd or Pgd or PGD - Page Global Directory + - Pud or Pud or PUD - Page Upper Directory + - Pmd or Pmd or PMD - Page Middle Directory + - Pte or pte or PTE - Page Table Entry + - Val or VAL or val - Value + - Dir - Directory +**/ + +#ifndef PAGE_H_ +#define PAGE_H_ + +#include + +#define MAX_VA_BITS 47 +#define PGD_WIDE (8) +#define PUD_WIDE (9) +#define PMD_WIDE (9) +#define PTE_WIDE (9) + +#define ENTRYS_PER_PGD (1 << PGD_WIDE) +#define ENTRYS_PER_PUD (1 << PUD_WIDE) +#define ENTRYS_PER_PMD (1 << PMD_WIDE) +#define ENTRYS_PER_PTE (1 << PTE_WIDE) + +#define PGD_SHIFT (PUD_SHIFT + PUD_WIDE) +#define PUD_SHIFT (PMD_SHIFT + PMD_WIDE) +#define PMD_SHIFT (EFI_PAGE_SHIFT + PTE_WIDE) +#define PTE_SHIFT (EFI_PAGE_SHIFT) + +#define PGD_SIZE (1UL << PGD_SHIFT) +#define PUD_SIZE (1UL << PUD_SHIFT) +#define PMD_SIZE (1UL << PMD_SHIFT) + +#define PGD_MASK (~(PGD_SIZE-1)) +#define PUD_MASK (~(PUD_SIZE-1)) +#define PMD_MASK (~(PMD_SIZE-1)) +#define PAGE_MASK (~(EFI_PAGE_SIZE - 1)) +#define PFN_MASK (~(((UINTN)(1) << (EFI_PAGE_SHIFT)) - 1) & \ + (((UINTN)(1) << (PAGE_PFN_END_SHIFT)) - 1)) + +#define HUGEP_PAGE_MASK (~(((UINTN)(1) << (PMD_SHIFT)) - 1) & \ + (((UINTN)(1) << (PAGE_PFN_END_SHIFT)) - 1)) + +#define INVALID_PAGE 0 + +typedef struct { + UINTN PgdVal; +} PGD; +typedef struct { + UINTN PudVal; +} PUD; +typedef struct { + UINTN PmdVal; +} PMD; +typedef struct { + UINTN PteVal; +} PTE; + +/** + Gets the value of the page global directory table entry. + + @param x Page global directory struct variables. + + @retval the value of the page global directory table entry. + **/ +#define PGD_VAL(x) ((x).PgdVal) + +/** + Gets the value of the page upper directory table entry. + + @param x Page upper directory struct variables. + + @retval the value of the page upper directory table entry. + **/ +#define PUD_VAL(x) ((x).PudVal) + +/** + Gets the value of the page middle directory table entry. + + @param x Page middle directory struct variables. + + @retval the value of the page middle directory table entry. + **/ +#define PMD_VAL(x) ((x).PmdVal) + +/** + Gets the value of the page table entry. + + @param x Page table entry struct variables. + + @retval the value of the page table entry. + **/ +#define PTE_VAL(x) ((x).PteVal) + +#define PGD_TABLE_SIZE (ENTRYS_PER_PGD * sizeof(PGD)) +#define PUD_TABLE_SIZE (ENTRYS_PER_PUD * sizeof(PUD)) +#define PMD_TABLE_SIZE (ENTRYS_PER_PMD * sizeof(PMD)) +#define PTE_TABLE_SIZE (ENTRYS_PER_PTE * sizeof(PTE)) + +/** + Gets the physical address of the record in the page table entry. + + @param x Page table entry struct variables. + + @retval the value of the physical address. + **/ +#define GET_PAGE_ATTRIBUTES(x) (UINTN) {(PTE_VAL(x) & ~PFN_MASK)} + +/** + Gets the virtual address of the next block of the specified virtual addr= ess + that is aligned with the size of the global page directory mapping. + + @param Address Specifies the virtual address. + @param End The end address of the memory region. + + @retval the specified virtual address of the next block. + **/ +#define PGD_ADDRESS_END(Address, End) \ +({ \ + UINTN Boundary =3D ((Address) + PGD_SIZE) & PGD_MASK; \ + (Boundary - 1 < (End) - 1)? Boundary: (End); \ +}) + +/** + Gets the virtual address of the next block of the specified virtual addr= ess + that is aligned with the size of the page upper directory mapping. + + @param Address Specifies the virtual address. + @param End The end address of the memory region. + + @retval the specified virtual address of the next block. + **/ +#define PUD_ADDRESS_END(Address, End) \ +({ \ + UINTN Boundary =3D ((Address) + PUD_SIZE) & PUD_MASK; \ + (Boundary - 1 < (End) - 1)? Boundary: (End); \ +}) + +/** + Gets the virtual address of the next block of the specified virtual addr= ess + that is aligned with the size of the page middle directory mapping. + + @param Address Specifies the virtual address. + @param End The end address of the memory region. + + @retval the specified virtual address of the next block. + **/ +#define PMD_ADDRESS_END(Address, End) \ +({ \ + UINTN Boundary =3D ((Address) + PMD_SIZE) & PMD_MASK; \ + (Boundary - 1 < (End) - 1)? Boundary: (End); \ +}) + +/** + Get Specifies the virtual address corresponding to the index of the page= global directory table entry. + + @param Address Specifies the virtual address. + + @retval the index of the page global directory table entry. + **/ +#define PGD_INDEX(Address) (((Address) >> PGD_SHIFT) & (ENTRYS_PER_PGD-1)) + +/** + Get Specifies the virtual address corresponding to the index of the page= upper directory table entry. + + @param Address Specifies the virtual address. + @param End The end address of the memory region. + + @retval the index of the page upper directory table entry. + **/ +#define PUD_INDEX(Address) (((Address) >> PUD_SHIFT) & (ENTRYS_PER_PUD - = 1)) + +/** + Get Specifies the virtual address corresponding to the index of the page= middle directory table entry. + + @param Address Specifies the virtual address. + + @retval the index of the page middle directory table entry. + **/ +#define PMD_INDEX(Address) (((Address) >> PMD_SHIFT) & (ENTRYS_PER_PMD - = 1)) + +/** + Get Specifies the virtual address corresponding to the index of the page= table entry. + + @param Address Specifies the virtual address. + + @retval the index of the page table entry. + **/ +#define PTE_INDEX(Address) (((Address) >> EFI_PAGE_SHIFT) & (ENTRYS_PER_P= TE - 1)) + +/** + Calculates the value of the page table entry based on the specified virt= ual address and properties. + + @param Address Specifies the virtual address. + @param Attributes Specifies the Attributes. + + @retval the value of the page table entry. + **/ +#define MAKE_PTE(Address, Attributes) (PTE){((((Address) >> EFI_PAGE_SHIF= T) << 12) | (Attributes))} + +/** + Get Global bit from Attributes + + @param Attributes Specifies the Attributes. + * */ +#define GET_GLOBALBIT(Attributes) ((Attributes & PAGE_GLOBAL) >> PAGE_GLO= BAL_SHIFT) + +/** + Calculates the value of the Huge page table entry based on the specified= virtual address and properties. + + @param Address Specifies the virtual address. + @param Attributes Specifies the Attributes. + + @retval the value of the HUGE page table entry. + **/ +#define MAKE_HUGE_PTE(Address, Attributes) (PTE){(((((Address) >> PMD_SHI= FT) << PMD_SHIFT) | \ + ((Attributes) | (GET_GLOBALBI= T(Attributes) << PAGE_HGLOBAL_SHIFT) | \ + PAGE_HUGE)))} + +/** + Check whether the large page table entry is. + + @param Val The value of the page table entry. + + @retval 1 Is huge page table entry. + @retval 0 Isn't huge page table entry. +**/ +#define IS_HUGE_PAGE(Val) ((((Val) & PAGE_HUGE) =3D=3D PAGE_HUGE) && \ + (((Val) & PAGE_HGLOBAL) =3D=3D PAGE_HGLOBAL)) + +#define HUGE_PAGE_SIZE (PMD_SIZE) + +/** + Check that the global page directory table entry is empty. + + @param pgd the global page directory struct variables. + + @retval 1 The page table is invalid. + @retval 0 The page table is valid. +**/ +#define PGD_IS_EMPTY(Val) (PGD_VAL(Val) =3D=3D INVALID_PAGE) + +/** + Check that the page upper directory table entry is empty. + + @param pud Page upper directory struct variables. + + @retval 1 The page table is invalid. + @retval 0 The page table is valid. +**/ +#define PUD_IS_EMPTY(Val) (PUD_VAL(Val) =3D=3D INVALID_PAGE) + +/** + Check that the page middle directory table entry is empty. + + @param pmd Page middle directory struct variables. + + @retval 1 The page table is invalid. + @retval 0 The page table is valid. +**/ +#define PMD_IS_EMPTY(Val) (PMD_VAL(Val) =3D=3D INVALID_PAGE) + +/** + Check that the page the page table entry is empty. + + @param pte Page table entry struct variables. + + @retval 1 The page table is invalid. + @retval 0 The page table is valid. +**/ +#define PTE_IS_EMPTY(Val) (!(PTE_VAL(Val) & (~PAGE_VALID))) +#endif // PAGE_H_ diff --git a/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/PeiCpuMmuLib.c b/Uefi= CpuPkg/Library/CpuMmuLib/LoongArch64/PeiCpuMmuLib.c new file mode 100644 index 0000000000..c214e8d847 --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/PeiCpuMmuLib.c @@ -0,0 +1,178 @@ +/** @file + CPU Memory Map Unit PEI phase driver. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Tlb - Translation Lookaside Buffer +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Page.h" +#include "Tlb.h" +#include "CommonMmuLib.h" + +// +// For coding convenience, define the maximum valid +// LoongArch exception. +// Since UEFI V2.11, it will be present in DebugSupport.h. +// +#define MAX_LOONGARCH_EXCEPTION 64 + +/** + Create a page table and initialize the memory management unit(MMU). + + @param[in] MemoryTable A pointer to a memory ragion table. + @param[out] TranslationTableBase A pointer to a translation table base= address. + @param[out] TranslationTableSize A pointer to a translation table base= size. + + @retval EFI_SUCCESS Configure MMU successfully. + EFI_INVALID_PARAMETER MemoryTable is NULL. + EFI_UNSUPPORTED Out of memory space or size not alig= ned. +**/ +EFI_STATUS +EFIAPI +ConfigureMemoryManagementUnit ( + IN MEMORY_REGION_DESCRIPTOR *MemoryTable, + OUT VOID **TranslationTableBase OPTIONAL, + OUT UINTN *TranslationTableSize OPTIONAL + ) +{ + PGD *SwapperPageDir; + UINTN PgdShift; + UINTN PgdWide; + UINTN PudShift; + UINTN PudWide; + UINTN PmdShift; + UINTN PmdWide; + UINTN PteShift; + UINTN PteWide; + UINTN Length; + UINTN TlbReEntry; + UINTN TlbReEntryOffset; + UINTN Remaining; + RETURN_STATUS Status; + + SwapperPageDir =3D NULL; + PgdShift =3D PGD_SHIFT; + PgdWide =3D PGD_WIDE; + PudShift =3D PUD_SHIFT; + PudWide =3D PUD_WIDE; + PmdShift =3D PMD_SHIFT; + PmdWide =3D PMD_WIDE; + PteShift =3D PTE_SHIFT; + PteWide =3D PTE_WIDE; + + if (MemoryTable =3D=3D NULL) { + ASSERT (MemoryTable !=3D NULL); + return EFI_INVALID_PARAMETER; + } + + SwapperPageDir =3D AllocatePages (EFI_SIZE_TO_PAGES (PGD_TABLE_SIZE)); + ZeroMem (SwapperPageDir, PGD_TABLE_SIZE); + + if (SwapperPageDir =3D=3D NULL) { + goto FreeTranslationTable; + } + + CsrWrite (LOONGARCH_CSR_PGDL, (UINTN)SwapperPageDir); + + while (MemoryTable->Length !=3D 0) { + DEBUG (( + DEBUG_INFO, + "%a %d VirtualBase %p VirtualEnd %p Attributes %p .\n", + __func__, + __LINE__, + MemoryTable->VirtualBase, + (MemoryTable->Length + MemoryTable->VirtualBase), + MemoryTable->Attributes + )); + + Status =3D FillTranslationTable (MemoryTable); + if (EFI_ERROR (Status)) { + goto FreeTranslationTable; + } + + MemoryTable++; + } + + // + // TLB Re-entry address at the end of exception vector, a vector is up t= o 512 bytes, + // so the starting address is: total exception vector size + total inter= rupt vector size + base. + // The total size of TLB handler and exception vector size and interrupt= vector size should not + // be lager than 64KB. + // + Length =3D (UINTN)HandleTlbRefillEnd - (UINTN)HandleTlbRefillS= tart; + TlbReEntryOffset =3D (MAX_LOONGARCH_EXCEPTION + MAX_LOONGARCH_INTERRUPT)= * 512; + Remaining =3D TlbReEntryOffset % SIZE_4KB; + if (Remaining !=3D 0x0) { + TlbReEntryOffset +=3D (SIZE_4KB - Remaining); + } + + TlbReEntry =3D PcdGet64 (PcdCpuExceptionVectorBaseAddress) + TlbReEntryO= ffset; + if ((TlbReEntryOffset + Length) > SIZE_64KB) { + goto FreeTranslationTable; + } + + // + // Ensure that TLB refill exception base address alignment is equals to = 4KB and is valid. + // + if (TlbReEntry & (SIZE_4KB - 1)) { + goto FreeTranslationTable; + } + + CopyMem ((VOID *)TlbReEntry, HandleTlbRefillStart, Length); + InvalidateInstructionCacheRange ((VOID *)(UINTN)HandleTlbRefillStart, Le= ngth); + + DEBUG (( + DEBUG_INFO, + "%a %d PteShift %d PteWide %d PmdShift %d PmdWide %d PudShift %d PudW= ide %d PgdShift %d PgdWide %d.\n", + __func__, + __LINE__, + PteShift, + PteWide, + PmdShift, + PmdWide, + PudShift, + PudWide, + PgdShift, + PgdWide + )); + + // + // Set the address of TLB refill exception handler + // + SetTlbRebaseAddress ((UINTN)TlbReEntry); + + // + // Set page size + // + CsrXChg (LOONGARCH_CSR_TLBIDX, (DEFAULT_PAGE_SIZE << CSR_TLBIDX_SIZE), C= SR_TLBIDX_SIZE_MASK); + CsrWrite (LOONGARCH_CSR_STLBPGSIZE, DEFAULT_PAGE_SIZE); + CsrXChg (LOONGARCH_CSR_TLBREHI, (DEFAULT_PAGE_SIZE << CSR_TLBREHI_PS_SHI= FT), CSR_TLBREHI_PS); + + CsrWrite (LOONGARCH_CSR_PWCTL0, (PteShift | PteWide << 5 | PmdShift << 1= 0 | PmdWide << 15 | PudShift << 20 | PudWide << 25)); + CsrWrite (LOONGARCH_CSR_PWCTL1, (PgdShift | PgdWide << 6)); + + DEBUG ((DEBUG_INFO, "%a %d Enable Mmu Start PageBassAddress %p.\n", __fu= nc__, __LINE__, SwapperPageDir)); + + return EFI_SUCCESS; + +FreeTranslationTable: + if (SwapperPageDir !=3D NULL) { + FreePages (SwapperPageDir, EFI_SIZE_TO_PAGES (PGD_TABLE_SIZE)); + } + + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/Tlb.h b/UefiCpuPkg/Li= brary/CpuMmuLib/LoongArch64/Tlb.h new file mode 100644 index 0000000000..9a681ce8e1 --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/Tlb.h @@ -0,0 +1,48 @@ +/** @file + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef TLB_H_ +#define TLB_H_ + +/** + Invalid corresponding TLB entries are based on the address given + + @param Address The address corresponding to the invalid page table entry + + @retval none +**/ +VOID +InvalidTlb ( + UINTN Address + ); + +/** + TLB refill handler start. + + @param none + + @retval none +**/ +VOID +HandleTlbRefillStart ( + VOID + ); + +/** + TLB refill handler end. + + @param none + + @retval none +**/ +VOID +HandleTlbRefillEnd ( + VOID + ); + +#endif // TLB_H_ diff --git a/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/TlbOperation.S b/Uefi= CpuPkg/Library/CpuMmuLib/LoongArch64/TlbOperation.S new file mode 100644 index 0000000000..c9a8c16336 --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/TlbOperation.S @@ -0,0 +1,44 @@ +#-------------------------------------------------------------------------= ----- +# +# TLB operation functions +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ---- + +#include + +ASM_GLOBAL ASM_PFX(HandleTlbRefillStart) +ASM_GLOBAL ASM_PFX(HandleTlbRefillEnd) +ASM_GLOBAL ASM_PFX(InvalidTlb) + +# +# Refill the page table. +# @param VOID +# @retval VOID +# +ASM_PFX(HandleTlbRefillStart): + csrwr $t0, LOONGARCH_CSR_TLBRSAVE + csrrd $t0, LOONGARCH_CSR_PGD + lddir $t0, $t0, 3 #Put pud BaseAddress into T0 + lddir $t0, $t0, 2 #Put pmd BaseAddress into T0 + lddir $t0, $t0, 1 #Put pte BaseAddress into T0 + ldpte $t0, 0 + ldpte $t0, 1 + tlbfill // refill hi,lo0,lo1 + csrrd $t0, LOONGARCH_CSR_TLBRSAVE + ertn +ASM_PFX(HandleTlbRefillEnd): + +# +# Invalid corresponding TLB entries are based on the address given +# @param a0 The address corresponding to the invalid page table entry +# @retval none +# +ASM_PFX(InvalidTlb): + invtlb INVTLB_ADDR_GTRUE_OR_ASID, $zero, $a0 + jirl $zero, $ra, 0 + + .end diff --git a/UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.inf b/UefiCpuPkg/Lib= rary/CpuMmuLib/PeiCpuMmuLib.inf new file mode 100644 index 0000000000..45b15db4c9 --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.inf @@ -0,0 +1,44 @@ +## @file +# CPU Memory Map Unit PEI phase driver. +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D PeiCpuMmuLib + MODULE_UNI_FILE =3D PeiCpuMmuLib.uni + FILE_GUID =3D F67EB983-AC2A-7550-AB69-3BC51A1C895B + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D CpuMmuLib | SEC PEIM + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources.LoongArch64] + LoongArch64/TlbOperation.S | GCC + LoongArch64/CommonMmuLib.c + LoongArch64/PeiCpuMmuLib.c + LoongArch64/CommonMmuLib.h + LoongArch64/Tlb.h + LoongArch64/Page.h + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[PCD] + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask + gUefiCpuPkgTokenSpaceGuid.PcdCpuExceptionVectorBaseAddress + +[LibraryClasses] + CacheMaintenanceLib + DebugLib + MemoryAllocationLib + PcdLib diff --git a/UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.uni b/UefiCpuPkg/Lib= rary/CpuMmuLib/PeiCpuMmuLib.uni new file mode 100644 index 0000000000..3e21334f3e --- /dev/null +++ b/UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.uni @@ -0,0 +1,14 @@ +// /** @file +// CPU Memory Manager Unit library instance for PEI modules. +// +// CPU Memory Manager Unit library instance for PEI modules. +// +// Copyright (c) 2024, Loongson Technology Corporation Limited. All rights= reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "CPU Memory Manage= r Unit library instance for PEI modules." + +#string STR_MODULE_DESCRIPTION #language en-US "CPU Memory Manage= r Unit library instance for PEI modules." diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 28eed85bce..178dc3c0f9 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -207,5 +207,9 @@ UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf =20 +[Components.LOONGARCH64] + UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.inf + UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.inf + [BuildOptions] *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES --=20 2.27.0 -=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 (#114540): https://edk2.groups.io/g/devel/message/114540 Mute This Topic: https://groups.io/mt/103971653/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- From nobody Thu Dec 26 20:24:45 2024 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+114541+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+114541+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250574; cv=none; d=zohomail.com; s=zohoarc; b=jQRR3kU54IzXM6NaIZJ2ZzpcgqGIXm4wOXmS5SrfrV4+fWa9s8KvQ7e33ssMx5lcl6CfqrHmTq7IEL/3+zDUdAncz9WmdTKJQkExScZQAhtSRIkMUkP+s0JL/SwYbcoP91oD29ZFobs2NKxbAon79qvxXVVvhAehw4P6pgZ0P5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250574; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=M6BLS7xGO8L5ikK1VV+b8a7G8akmOF1aej+XiMFntPg=; b=Nq1/KdBPC+WHnjhjEm/FMupAs4DAYTqn7f8IVL8c7WnWjNdMwjLdr9TfcF38Ke4QbJdrXYCrQzNMEQAFB1rFWeHNwXElL/0J+G5QYDyxIx8nPhI1J2w6o+UepifvgFQCZ7xC4BFXlww4ETr9mU8jgEmMDzo+K6XvksPaNCz8SdI= 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+114541+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250574739408.2313320005335; Thu, 25 Jan 2024 22:29:34 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=82eMDvgpIg1AWIJWIqG/7K2cx62oL3EimGDZzpBdb+4=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250574; v=1; b=U+6oShcknSoTyDmjlmnGvW9bcp74CN3hVw+J1o9j2vkusv9Rh68u3MYk5iWLMHXHJGHzzNTC WVMhYdAgqEir6iRND87KSNOxdO0GfqQUrRoUR77/17gqD3aKvuz2gCfYxc4mEk1R0qvpLqnlDrG kb9+vR785xhDZo8iO8n2sBKw= X-Received: by 127.0.0.2 with SMTP id avUVYY1788612xrkboufsj0x; Thu, 25 Jan 2024 22:29:34 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10004.1706250572188675447 for ; Thu, 25 Jan 2024 22:29:33 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8Bx3+tIUbNlKh4GAA--.21500S3; Fri, 26 Jan 2024 14:29:28 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxVMxGUbNlbnIbAA--.58037S2; Fri, 26 Jan 2024 14:29:26 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v8 15/37] UefiCpuPkg: Add multiprocessor library for LoongArch64 Date: Fri, 26 Jan 2024 14:29:26 +0800 Message-Id: <20240126062926.3101757-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxVMxGUbNlbnIbAA--.58037S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBOsR X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Svm8FOpX49r5qYKMS0MCXbI0x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250576412100003 Content-Type: text/plain; charset="utf-8" Added LoongArch multiprocessor initialization instance into MpInitLib. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Chao Li --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 27 +- .../Library/MpInitLib/LoongArch64/DxeMpLib.c | 480 +++++ .../Library/MpInitLib/LoongArch64/MpLib.c | 1621 +++++++++++++++++ .../Library/MpInitLib/LoongArch64/MpLib.h | 361 ++++ .../Library/MpInitLib/LoongArch64/PeiMpLib.c | 404 ++++ UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 27 +- 6 files changed, 2902 insertions(+), 18 deletions(-) create mode 100644 UefiCpuPkg/Library/MpInitLib/LoongArch64/DxeMpLib.c create mode 100644 UefiCpuPkg/Library/MpInitLib/LoongArch64/MpLib.c create mode 100644 UefiCpuPkg/Library/MpInitLib/LoongArch64/MpLib.h create mode 100644 UefiCpuPkg/Library/MpInitLib/LoongArch64/PeiMpLib.c diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 55e46d4a1f..6db26f5fec 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -2,6 +2,7 @@ # MP Initialize Library instance for DXE driver. # # Copyright (c) 2016 - 2023, Intel Corporation. All rights reserved.
+# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights= reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -18,7 +19,7 @@ # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 +# VALID_ARCHITECTURES =3D IA32 X64 LOONGARCH64 # =20 [Sources.IA32] @@ -31,7 +32,7 @@ X64/MpFuncs.nasm X64/CreatePageTable.c =20 -[Sources.common] +[Sources.IA32, Sources.X64] AmdSev.c MpEqu.inc DxeMpLib.c @@ -40,24 +41,32 @@ Microcode.c MpHandOff.h =20 +[Sources.LoongArch64] + LoongArch64/DxeMpLib.c + LoongArch64/MpLib.c + LoongArch64/MpLib.h + [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 -[LibraryClasses] +[LibraryClasses.common] BaseLib - LocalApicLib - MemoryAllocationLib - HobLib - MtrrLib CpuLib - UefiBootServicesTableLib DebugAgentLib - SynchronizationLib + HobLib + MemoryAllocationLib PcdLib + UefiBootServicesTableLib + SynchronizationLib + +[LibraryClasses.IA32, LibraryClasses.X64] CcExitLib + LocalApicLib MicrocodeLib + MtrrLib + [LibraryClasses.X64] CpuPageTableLib =20 diff --git a/UefiCpuPkg/Library/MpInitLib/LoongArch64/DxeMpLib.c b/UefiCpuP= kg/Library/MpInitLib/LoongArch64/DxeMpLib.c new file mode 100644 index 0000000000..739da77e32 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/LoongArch64/DxeMpLib.c @@ -0,0 +1,480 @@ +/** @file + LoongArch64 MP initialize support functions for DXE phase. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" + +#include +#include +#include + +#include + +CPU_MP_DATA *mCpuMpData =3D NULL; +EFI_EVENT mCheckAllApsEvent =3D NULL; +volatile BOOLEAN mStopCheckAllApsStatus =3D TRUE; + +/** + Enable Debug Agent to support source debugging on AP function. + +**/ +VOID +EnableDebugAgent ( + VOID + ) +{ + // + // Initialize Debug Agent to support source level debug in DXE phase + // + InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_AP, NULL, NULL); +} + +/** + Get the pointer to CPU MP Data structure. + + @return The pointer to CPU MP Data structure. +**/ +CPU_MP_DATA * +GetCpuMpData ( + VOID + ) +{ + ASSERT (mCpuMpData !=3D NULL); + return mCpuMpData; +} + +/** + Save the pointer to CPU MP Data structure. + + @param[in] CpuMpData The pointer to CPU MP Data structure will be saved. +**/ +VOID +SaveCpuMpData ( + IN CPU_MP_DATA *CpuMpData + ) +{ + mCpuMpData =3D CpuMpData; +} + +/** + Get available EfiBootServicesCode memory below 4GB by specified size. + + This buffer is required to safely transfer AP from real address mode to + protected mode or long mode, due to the fact that the buffer returned by + GetWakeupBuffer() may be marked as non-executable. + + @param[in] BufferSize Wakeup transition buffer size. + + @retval other Return wakeup transition buffer address below 4GB. + @retval 0 Cannot find free memory below 4GB. +**/ +UINTN +GetModeTransitionBuffer ( + IN UINTN BufferSize + ) +{ + return 0; +} + +/** + Checks APs status and updates APs status if needed. + +**/ +VOID +CheckAndUpdateApsStatus ( + VOID + ) +{ + UINTN ProcessorNumber; + EFI_STATUS Status; + CPU_MP_DATA *CpuMpData; + + CpuMpData =3D GetCpuMpData (); + + // + // First, check whether pending StartupAllAPs() exists. + // + if (CpuMpData->WaitEvent !=3D NULL) { + Status =3D CheckAllAPs (); + // + // If all APs finish for StartupAllAPs(), signal the WaitEvent for it. + // + if (Status !=3D EFI_NOT_READY) { + Status =3D gBS->SignalEvent (CpuMpData->WaitEvent); + CpuMpData->WaitEvent =3D NULL; + } + } + + // + // Second, check whether pending StartupThisAPs() callings exist. + // + for (ProcessorNumber =3D 0; ProcessorNumber < CpuMpData->CpuCount; Proce= ssorNumber++) { + if (CpuMpData->CpuData[ProcessorNumber].WaitEvent =3D=3D NULL) { + continue; + } + + Status =3D CheckThisAP (ProcessorNumber); + + if (Status !=3D EFI_NOT_READY) { + gBS->SignalEvent (CpuMpData->CpuData[ProcessorNumber].WaitEvent); + CpuMpData->CpuData[ProcessorNumber].WaitEvent =3D NULL; + } + } +} + +/** + Checks APs' status periodically. + + This function is triggered by timer periodically to check the + state of APs for StartupAllAPs() and StartupThisAP() executed + in non-blocking mode. + + @param[in] Event Event triggered. + @param[in] Context Parameter passed with the event. + +**/ +VOID +EFIAPI +CheckApsStatus ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // If CheckApsStatus() is not stopped, otherwise return immediately. + // + if (!mStopCheckAllApsStatus) { + CheckAndUpdateApsStatus (); + } +} + +/** + Initialize global data for MP support. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +InitMpGlobalData ( + IN CPU_MP_DATA *CpuMpData + ) +{ + EFI_STATUS Status; + + SaveCpuMpData (CpuMpData); + + Status =3D gBS->CreateEvent ( + EVT_TIMER | EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + CheckApsStatus, + NULL, + &mCheckAllApsEvent + ); + ASSERT_EFI_ERROR (Status); + + // + // Set timer to check all APs status. + // + Status =3D gBS->SetTimer ( + mCheckAllApsEvent, + TimerPeriodic, + EFI_TIMER_PERIOD_MICROSECONDS ( + PcdGet32 (PcdCpuApStatusCheckIntervalInMicroSeconds) + ) + ); + ASSERT_EFI_ERROR (Status); +} + +/** + This service executes a caller provided function on all enabled APs. + + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. See type + EFI_AP_PROCEDURE. + @param[in] SingleThread If TRUE, then all the enabled APs ex= ecute + the function specified by Procedure = one by + one, in ascending order of processor= handle + number. If FALSE, then all the enab= led APs + execute the function specified by Pr= ocedure + simultaneously. + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. If it is NULL, then execut= e in + blocking mode. BSP waits until all A= Ps finish + or TimeoutInMicroSeconds expires. I= f it's + not NULL, then execute in non-blocki= ng mode. + BSP requests the function specified = by + Procedure to be started on all the e= nabled + APs, and go on executing immediately= . If + all return from Procedure, or Timeou= tInMicroSeconds + expires, this event is signaled. The= BSP + can use the CheckEvent() or WaitForE= vent() + services to check the state of event= . Type + EFI_EVENT is defined in CreateEvent(= ) in + the Unified Extensible Firmware Inte= rface + Specification. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + APs to return from Procedure, either= for + blocking or non-blocking mode. Zero = means + infinity. If the timeout expires be= fore + all APs return from Procedure, then = Procedure + on the failed APs is terminated. All= enabled + APs are available for next function = assigned + by MpInitLibStartupAllAPs() or + MPInitLibStartupThisAP(). + If the timeout expires in blocking m= ode, + BSP returns EFI_TIMEOUT. If the tim= eout + expires in non-blocking mode, WaitEv= ent + is signaled with SignalEvent(). + @param[in] ProcedureArgument The parameter passed into Procedure = for + all APs. + @param[out] FailedCpuList If NULL, this parameter is ignored. = Otherwise, + if all APs finish successfully, then= its + content is set to NULL. If not all A= Ps + finish before timeout expires, then = its + content is set to address of the buf= fer + holding handle numbers of the failed= APs. + The buffer is allocated by MP Initia= lization + library, and it's the caller's respo= nsibility to + free the buffer with FreePool() serv= ice. + In blocking mode, it is ready for co= nsumption + when the call returns. In non-blocki= ng mode, + it is ready when WaitEvent is signal= ed. The + list of failed CPU is terminated by + END_OF_CPU_LIST. + + @retval EFI_SUCCESS In blocking mode, all APs have finished = before + the timeout expired. + @retval EFI_SUCCESS In non-blocking mode, function has been = dispatched + to all enabled APs. + @retval EFI_UNSUPPORTED A non-blocking mode request was made aft= er the + UEFI event EFI_EVENT_GROUP_READY_TO_BOOT= was + signaled. + @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mo= de is not + supported. + @retval EFI_DEVICE_ERROR Caller processor is AP. + @retval EFI_NOT_STARTED No enabled APs exist in the system. + @retval EFI_NOT_READY Any enabled APs are busy. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + @retval EFI_TIMEOUT In blocking mode, the timeout expired be= fore + all enabled APs have finished. + @retval EFI_INVALID_PARAMETER Procedure is NULL. + +**/ +EFI_STATUS +EFIAPI +MpInitLibStartupAllAPs ( + IN EFI_AP_PROCEDURE Procedure, + IN BOOLEAN SingleThread, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT UINTN **FailedCpuList OPTIONAL + ) +{ + EFI_STATUS Status; + + // + // Temporarily stop checkAllApsStatus for avoid resource dead-lock. + // + mStopCheckAllApsStatus =3D TRUE; + + Status =3D StartupAllCPUsWorker ( + Procedure, + SingleThread, + TRUE, + WaitEvent, + TimeoutInMicroseconds, + ProcedureArgument, + FailedCpuList + ); + + // + // Start checkAllApsStatus + // + mStopCheckAllApsStatus =3D FALSE; + + return Status; +} + +/** + This service lets the caller get one enabled AP to execute a caller-prov= ided + function. + + @param[in] Procedure A pointer to the function to be run = on the + designated AP of the system. See type + EFI_AP_PROCEDURE. + @param[in] ProcessorNumber The handle number of the AP. The ran= ge is + from 0 to the total number of logical + processors minus 1. The total number= of + logical processors can be retrieved = by + MpInitLibGetNumberOfProcessors(). + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. If it is NULL, then execut= e in + blocking mode. BSP waits until this = AP finish + or TimeoutInMicroSeconds expires. I= f it's + not NULL, then execute in non-blocki= ng mode. + BSP requests the function specified = by + Procedure to be started on this AP, + and go on executing immediately. If = this AP + return from Procedure or TimeoutInMi= croSeconds + expires, this event is signaled. The= BSP + can use the CheckEvent() or WaitForE= vent() + services to check the state of event= . Type + EFI_EVENT is defined in CreateEvent(= ) in + the Unified Extensible Firmware Inte= rface + Specification. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + this AP to finish this Procedure, ei= ther for + blocking or non-blocking mode. Zero = means + infinity. If the timeout expires be= fore + this AP returns from Procedure, then= Procedure + on the AP is terminated. The + AP is available for next function as= signed + by MpInitLibStartupAllAPs() or + MpInitLibStartupThisAP(). + If the timeout expires in blocking m= ode, + BSP returns EFI_TIMEOUT. If the tim= eout + expires in non-blocking mode, WaitEv= ent + is signaled with SignalEvent(). + @param[in] ProcedureArgument The parameter passed into Procedure = on the + specified AP. + @param[out] Finished If NULL, this parameter is ignored. = In + blocking mode, this parameter is ign= ored. + In non-blocking mode, if AP returns = from + Procedure before the timeout expires= , its + content is set to TRUE. Otherwise, t= he + value is set to FALSE. The caller can + determine if the AP returned from Pr= ocedure + by evaluating this value. + + @retval EFI_SUCCESS In blocking mode, specified AP finished = before + the timeout expires. + @retval EFI_SUCCESS In non-blocking mode, the function has b= een + dispatched to specified AP. + @retval EFI_UNSUPPORTED A non-blocking mode request was made aft= er the + UEFI event EFI_EVENT_GROUP_READY_TO_BOOT= was + signaled. + @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mo= de is not + supported. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_TIMEOUT In blocking mode, the timeout expired be= fore + the specified AP has finished. + @retval EFI_NOT_READY The specified AP is busy. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist. + @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or dis= abled AP. + @retval EFI_INVALID_PARAMETER Procedure is NULL. + +**/ +EFI_STATUS +EFIAPI +MpInitLibStartupThisAP ( + IN EFI_AP_PROCEDURE Procedure, + IN UINTN ProcessorNumber, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT BOOLEAN *Finished OPTIONAL + ) +{ + EFI_STATUS Status; + + // + // temporarily stop checkAllApsStatus for avoid resource dead-lock. + // + mStopCheckAllApsStatus =3D TRUE; + + Status =3D StartupThisAPWorker ( + Procedure, + ProcessorNumber, + WaitEvent, + TimeoutInMicroseconds, + ProcedureArgument, + Finished + ); + + mStopCheckAllApsStatus =3D FALSE; + + return Status; +} + +/** + This service switches the requested AP to be the BSP from that point onw= ard. + This service changes the BSP for all purposes. This call can only be per= formed + by the current BSP. + + @param[in] ProcessorNumber The handle number of AP that is to become t= he new + BSP. The range is from 0 to the total numbe= r of + logical processors minus 1. The total numbe= r of + logical processors can be retrieved by + MpInitLibGetNumberOfProcessors(). + @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as= an + enabled AP. Otherwise, it will be disabled. + + @retval EFI_SUCCESS BSP successfully switched. + @retval EFI_UNSUPPORTED Switching the BSP cannot be completed pr= ior to + this service returning. + @retval EFI_UNSUPPORTED Switching the BSP is not supported. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist. + @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BS= P or + a disabled AP. + @retval EFI_NOT_READY The specified AP is busy. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +EFIAPI +MpInitLibSwitchBSP ( + IN UINTN ProcessorNumber, + IN BOOLEAN EnableOldBSP + ) +{ + return EFI_UNSUPPORTED; +} + +/** + This service lets the caller enable or disable an AP from this point onw= ard. + This service may only be called from the BSP. + + @param[in] ProcessorNumber The handle number of AP. + The range is from 0 to the total number of + logical processors minus 1. The total numbe= r of + logical processors can be retrieved by + MpInitLibGetNumberOfProcessors(). + @param[in] EnableAP Specifies the new state for the processor f= or + enabled, FALSE for disabled. + @param[in] HealthFlag If not NULL, a pointer to a value that spec= ifies + the new health status of the AP. This flag + corresponds to StatusFlag defined in + EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo()= . Only + the PROCESSOR_HEALTH_STATUS_BIT is used. Al= l other + bits are ignored. If it is NULL, this para= meter + is ignored. + + @retval EFI_SUCCESS The specified AP was enabled or disabled= successfully. + @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be co= mpleted + prior to this service returning. + @retval EFI_UNSUPPORTED Enabling or disabling an AP is not suppo= rted. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_NOT_FOUND Processor with the handle specified by P= rocessorNumber + does not exist. + @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +EFIAPI +MpInitLibEnableDisableAP ( + IN UINTN ProcessorNumber, + IN BOOLEAN EnableAP, + IN UINT32 *HealthFlag OPTIONAL + ) +{ + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/MpInitLib/LoongArch64/MpLib.c b/UefiCpuPkg/= Library/MpInitLib/LoongArch64/MpLib.c new file mode 100644 index 0000000000..930d34aa3d --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/LoongArch64/MpLib.c @@ -0,0 +1,1621 @@ +/** @file + LoongArch64 CPU MP Initialize Library common functions. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" + +#include +#include + +#define INVALID_APIC_ID 0xFFFFFFFF + +EFI_GUID mCpuInitMpLibHobGuid =3D CPU_INIT_MP_LIB_HOB_GUID; +EFI_GUID mProcessorResourceHobGuid =3D PROCESSOR_RESOURCE_HOB_GUID; + +/** + Get the Application Processors state. + + @param[in] CpuData The pointer to CPU_AP_DATA of specified AP + + @return The AP status +**/ +CPU_STATE +GetApState ( + IN CPU_AP_DATA *CpuData + ) +{ + return CpuData->State; +} + +/** + Set the Application Processors state. + + @param[in] CpuData The pointer to CPU_AP_DATA of specified AP + @param[in] State The AP status +**/ +VOID +SetApState ( + IN CPU_AP_DATA *CpuData, + IN CPU_STATE State + ) +{ + AcquireSpinLock (&CpuData->ApLock); + CpuData->State =3D State; + ReleaseSpinLock (&CpuData->ApLock); +} + +/** + Get APIC ID of the executing processor. + + @return 32-bit APIC ID of the executing processor. +**/ +UINT32 +GetApicId ( + VOID + ) +{ + UINTN CpuNum; + + CpuNum =3D CsrRead (LOONGARCH_CSR_CPUNUM); + + return CpuNum & 0x3ff; +} + +/** + Find the current Processor number by APIC ID. + + @param[in] CpuMpData Pointer to PEI CPU MP Data + @param[out] ProcessorNumber Return the pocessor number found + + @retval EFI_SUCCESS ProcessorNumber is found and returned. + @retval EFI_NOT_FOUND ProcessorNumber is not found. +**/ +EFI_STATUS +GetProcessorNumber ( + IN CPU_MP_DATA *CpuMpData, + OUT UINTN *ProcessorNumber + ) +{ + UINTN TotalProcessorNumber; + UINTN Index; + CPU_INFO_IN_HOB *CpuInfoInHob; + + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + + TotalProcessorNumber =3D CpuMpData->CpuCount; + for (Index =3D 0; Index < TotalProcessorNumber; Index++) { + if (CpuInfoInHob[Index].ApicId =3D=3D GetApicId ()) { + *ProcessorNumber =3D Index; + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** + Sort the APIC ID of all processors. + + This function sorts the APIC ID of all processors so that processor numb= er is + assigned in the ascending order of APIC ID which eases MP debugging. + + @param[in] CpuMpData Pointer to PEI CPU MP Data +**/ +VOID +SortApicId ( + IN CPU_MP_DATA *CpuMpData + ) +{ + UINTN Index1; + UINTN Index2; + UINTN Index3; + UINT32 ApicId; + CPU_INFO_IN_HOB CpuInfo; + UINT32 ApCount; + CPU_INFO_IN_HOB *CpuInfoInHob; + volatile UINT32 *StartupApSignal; + + ApCount =3D CpuMpData->CpuCount - 1; + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + if (ApCount !=3D 0) { + Index2 =3D 0; + for (Index1 =3D (PcdGet32 (PcdCpuMaxLogicalProcessorNumber) - 1); Inde= x1 > 0; Index1--) { + if (CpuInfoInHob[Index1].ApicId !=3D INVALID_APIC_ID) { + if (Index1 =3D=3D ApCount) { + break; + } else { + for ( ; Index2 <=3D ApCount; Index2++) { + if (CpuInfoInHob[Index2].ApicId =3D=3D INVALID_APIC_ID) { + CopyMem (&CpuInfoInHob[Index2], &CpuInfoInHob[Index1], sizeo= f (CPU_INFO_IN_HOB)); + CpuMpData->CpuData[Index2] =3D CpuMpData->CpuData[Index1]; + CpuInfoInHob[Index1].ApicId =3D INVALID_APIC_ID; + break; + } + } + } + } else { + continue; + } + } + + for (Index1 =3D 0; Index1 < ApCount; Index1++) { + Index3 =3D Index1; + // + // Sort key is the hardware default APIC ID + // + ApicId =3D CpuInfoInHob[Index1].ApicId; + for (Index2 =3D Index1 + 1; Index2 <=3D ApCount; Index2++) { + if (ApicId > CpuInfoInHob[Index2].ApicId) { + Index3 =3D Index2; + ApicId =3D CpuInfoInHob[Index2].ApicId; + } + } + + if (Index3 !=3D Index1) { + CopyMem (&CpuInfo, &CpuInfoInHob[Index3], sizeof (CPU_INFO_IN_HOB)= ); + CopyMem ( + &CpuInfoInHob[Index3], + &CpuInfoInHob[Index1], + sizeof (CPU_INFO_IN_HOB) + ); + CopyMem (&CpuInfoInHob[Index1], &CpuInfo, sizeof (CPU_INFO_IN_HOB)= ); + + // + // Also exchange the StartupApSignal. + // + StartupApSignal =3D CpuMpData->CpuData[= Index3].StartupApSignal; + CpuMpData->CpuData[Index3].StartupApSignal =3D + CpuMpData->CpuData[Index1].StartupApSignal; + CpuMpData->CpuData[Index1].StartupApSignal =3D StartupApSignal; + } + } + + // + // Get the processor number for the BSP + // + ApicId =3D GetApicId (); + for (Index1 =3D 0; Index1 < CpuMpData->CpuCount; Index1++) { + if (CpuInfoInHob[Index1].ApicId =3D=3D ApicId) { + CpuMpData->BspNumber =3D (UINT32)Index1; + break; + } + } + } +} + +/** + Get pointer to Processor Resource Data structure from GUIDd HOB. + + @return The pointer to Processor Resource Data structure. +**/ +PROCESSOR_RESOURCE_DATA * +GetProcessorResourceDataFromGuidedHob ( + VOID + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + VOID *DataInHob; + PROCESSOR_RESOURCE_DATA *ResourceData; + + ResourceData =3D NULL; + GuidHob =3D GetFirstGuidHob (&mProcessorResourceHobGuid); + if (GuidHob !=3D NULL) { + DataInHob =3D GET_GUID_HOB_DATA (GuidHob); + ResourceData =3D (PROCESSOR_RESOURCE_DATA *)(*(UINTN *)DataInHob); + } + + return ResourceData; +} + +/** + This function will get CPU count in the system. + + @param[in] CpuMpData Pointer to PEI CPU MP Data + + @return CPU count detected +**/ +UINTN +CollectProcessorCount ( + IN CPU_MP_DATA *CpuMpData + ) +{ + PROCESSOR_RESOURCE_DATA *ProcessorResourceData; + + ProcessorResourceData =3D NULL; + + // + // Set the default loop mode for APs. + // + CpuMpData->ApLoopMode =3D ApInRunLoop; + + // + // Beacuse LoongArch does not have SIPI now, the APIC ID must be obtaine= d before + // calling IPI to wake up the APs. If NULL is obtained, NODE0 Core0 Mail= box0 is used + // as the first broadcast method to wake up all APs, and all of APs will= read NODE0 + // Core0 Mailbox0 in an infinit loop. + // + ProcessorResourceData =3D GetProcessorResourceDataFromGuidedHob (); + + if (ProcessorResourceData !=3D NULL) { + CpuMpData->ApLoopMode =3D ApInHltLoop; + CpuMpData->CpuCount =3D ProcessorResourceData->CpuCount; + CpuMpData->CpuInfoInHob =3D (UINTN)(ProcessorResourceData->CpuInfoInHo= b); + } + + // + // Send 1st broadcast IPI to APs to wakeup APs + // + CpuMpData->InitFlag =3D ApInitConfig; + WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, FALSE); + CpuMpData->InitFlag =3D ApInitDone; + + // + // When InitFlag =3D=3D ApInitConfig, WakeUpAP () guarantees all APs are= checked in. + // FinishedCount is the number of check-in APs. + // + CpuMpData->CpuCount =3D CpuMpData->FinishedCount + 1; + ASSERT (CpuMpData->CpuCount <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumb= er)); + + // + // Wait for all APs finished the initialization + // + while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { + CpuPause (); + } + + // + // Sort BSP/Aps by CPU APIC ID in ascending order + // + SortApicId (CpuMpData); + + DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", CpuMpD= ata->CpuCount)); + + return CpuMpData->CpuCount; +} + +/** + Initialize CPU AP Data when AP is wakeup at the first time. + + @param[in, out] CpuMpData Pointer to PEI CPU MP Data + @param[in] ProcessorNumber The handle number of processor + @param[in] BistData Processor BIST data + +**/ +VOID +InitializeApData ( + IN OUT CPU_MP_DATA *CpuMpData, + IN UINTN ProcessorNumber, + IN UINT32 BistData + ) +{ + CPU_INFO_IN_HOB *CpuInfoInHob; + + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)(CpuMpData->CpuInfoInHob); + + CpuInfoInHob[ProcessorNumber].ApicId =3D GetApicId (); + CpuInfoInHob[ProcessorNumber].Health =3D BistData; + + CpuMpData->CpuData[ProcessorNumber].Waiting =3D FALSE; + CpuMpData->CpuData[ProcessorNumber].CpuHealthy =3D (BistData =3D=3D 0) ?= TRUE : FALSE; + + InitializeSpinLock (&CpuMpData->CpuData[ProcessorNumber].ApLock); + SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); +} + +/** + Ap wake up function. + + Ap will wait for scheduling here, and if the IPI or wake-up signal is en= abled, + Ap will preform the corresponding functions. + + @param[in] ApIndex Number of current executing AP + @param[in] ExchangeInfo Pointer to the MP exchange info buffer +**/ +VOID +EFIAPI +ApWakeupFunction ( + IN UINTN ApIndex, + IN MP_CPU_EXCHANGE_INFO *ExchangeInfo + ) +{ + CPU_MP_DATA *CpuMpData; + UINTN ProcessorNumber; + volatile UINT32 *ApStartupSignalBuffer; + EFI_AP_PROCEDURE Procedure; + VOID *Parameter; + + CpuMpData =3D ExchangeInfo->CpuMpData; + + while (TRUE) { + if (CpuMpData->InitFlag =3D=3D ApInitConfig) { + ProcessorNumber =3D ApIndex; + // + // If the AP can running to here, then the BIST must be zero. + // + InitializeApData (CpuMpData, ProcessorNumber, 0); + ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Startu= pApSignal; + } else { + // + // Execute AP function if AP is ready + // + GetProcessorNumber (CpuMpData, &ProcessorNumber); + + // + // Clear AP start-up signal when AP waken up + // + ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Startu= pApSignal; + InterlockedCompareExchange32 ( + (UINT32 *)ApStartupSignalBuffer, + WAKEUP_AP_SIGNAL, + 0 + ); + + // + // Invoke AP function here + // + if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) =3D=3D CpuStat= eReady) { + Procedure =3D (EFI_AP_PROCEDURE)CpuMpData->CpuData[ProcessorNumber= ].ApFunction; + Parameter =3D (VOID *)CpuMpData->CpuData[ProcessorNumber].ApFuncti= onArgument; + if (Procedure !=3D NULL) { + SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateBusy); + Procedure (Parameter); + } + + SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished= ); + } + } + + // + // Updates the finished count + // + InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount); + + while (TRUE) { + // + // Clean per-core mail box registers. + // + IoCsrWrite64 (LOONGARCH_IOCSR_MBUF0, 0x0); + IoCsrWrite64 (LOONGARCH_IOCSR_MBUF1, 0x0); + IoCsrWrite64 (LOONGARCH_IOCSR_MBUF2, 0x0); + IoCsrWrite64 (LOONGARCH_IOCSR_MBUF3, 0x0); + + // + // Enable IPI interrupt and global interrupt + // + EnableLocalInterrupts (BIT12); + IoCsrWrite32 (LOONGARCH_IOCSR_IPI_EN, 0xFFFFFFFFU); + EnableInterrupts (); + + // + // Ap entry HLT mode + // + CpuSleep (); + + // + // Disable global interrupts when wake up + // + DisableInterrupts (); + + // + // Update CpuMpData + // + if (CpuMpData !=3D ExchangeInfo->CpuMpData) { + CpuMpData =3D ExchangeInfo->CpuMpData; + GetProcessorNumber (CpuMpData, &ProcessorNumber); + ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Star= tupApSignal; + } + + // + // Break out of the loop if wake up signal is not NULL. + // + if (*ApStartupSignalBuffer =3D=3D WAKEUP_AP_SIGNAL) { + break; + } + } + } +} + +/** + Calculate timeout value and return the current performance counter value. + + Calculate the number of performance counter ticks required for a timeout. + If TimeoutInMicroseconds is 0, return value is also 0, which is recogniz= ed + as infinity. + + @param[in] TimeoutInMicroseconds Timeout value in microseconds. + @param[out] CurrentTime Returns the current value of the per= formance counter. + + @return Expected time stamp counter for timeout. + If TimeoutInMicroseconds is 0, return value is also 0, which is = recognized + as infinity. + +**/ +UINT64 +CalculateTimeout ( + IN UINTN TimeoutInMicroseconds, + OUT UINT64 *CurrentTime + ) +{ + UINT64 TimeoutInSeconds; + UINT64 TimestampCounterFreq; + + // + // Read the current value of the performance counter + // + *CurrentTime =3D GetPerformanceCounter (); + + // + // If TimeoutInMicroseconds is 0, return value is also 0, which is recog= nized + // as infinity. + // + if (TimeoutInMicroseconds =3D=3D 0) { + return 0; + } + + // + // GetPerformanceCounterProperties () returns the timestamp counter's fr= equency + // in Hz. + // + TimestampCounterFreq =3D GetPerformanceCounterProperties (NULL, NULL); + + // + // Check the potential overflow before calculate the number of ticks for= the timeout value. + // + if (DivU64x64Remainder (MAX_UINT64, TimeoutInMicroseconds, NULL) < Times= tampCounterFreq) { + // + // Convert microseconds into seconds if direct multiplication overflows + // + TimeoutInSeconds =3D DivU64x32 (TimeoutInMicroseconds, 1000000); + // + // Assertion if the final tick count exceeds MAX_UINT64 + // + ASSERT (DivU64x64Remainder (MAX_UINT64, TimeoutInSeconds, NULL) >=3D T= imestampCounterFreq); + return MultU64x64 (TimestampCounterFreq, TimeoutInSeconds); + } else { + // + // No overflow case, multiply the return value with TimeoutInMicroseco= nds and then divide + // it by 1,000,000, to get the number of ticks for the timeout value. + // + return DivU64x32 ( + MultU64x64 ( + TimestampCounterFreq, + TimeoutInMicroseconds + ), + 1000000 + ); + } +} + +/** + Checks whether timeout expires. + + Check whether the number of elapsed performance counter ticks required f= or + a timeout condition has been reached. + If Timeout is zero, which means infinity, return value is always FALSE. + + @param[in, out] PreviousTime On input, the value of the performance = counter + when it was last read. + On output, the current value of the perf= ormance + counter + @param[in] TotalTime The total amount of elapsed time in perf= ormance + counter ticks. + @param[in] Timeout The number of performance counter ticks = required + to reach a timeout condition. + + @retval TRUE A timeout condition has been reached. + @retval FALSE A timeout condition has not been reached. + +**/ +BOOLEAN +CheckTimeout ( + IN OUT UINT64 *PreviousTime, + IN UINT64 *TotalTime, + IN UINT64 Timeout + ) +{ + UINT64 Start; + UINT64 End; + UINT64 CurrentTime; + INT64 Delta; + INT64 Cycle; + + if (Timeout =3D=3D 0) { + return FALSE; + } + + GetPerformanceCounterProperties (&Start, &End); + Cycle =3D End - Start; + if (Cycle < 0) { + Cycle =3D -Cycle; + } + + Cycle++; + CurrentTime =3D GetPerformanceCounter (); + Delta =3D (INT64)(CurrentTime - *PreviousTime); + if (Start > End) { + Delta =3D -Delta; + } + + if (Delta < 0) { + Delta +=3D Cycle; + } + + *TotalTime +=3D Delta; + *PreviousTime =3D CurrentTime; + if (*TotalTime > Timeout) { + return TRUE; + } + + return FALSE; +} + +/** + Helper function that waits until the finished AP count reaches the speci= fied + limit, or the specified timeout elapses (whichever comes first). + + @param[in] CpuMpData Pointer to CPU MP Data. + @param[in] FinishedApLimit The number of finished APs to wait for. + @param[in] TimeLimit The number of microseconds to wait for. +**/ +VOID +TimedWaitForApFinish ( + IN CPU_MP_DATA *CpuMpData, + IN UINT32 FinishedApLimit, + IN UINT32 TimeLimit + ) +{ + // + // CalculateTimeout() and CheckTimeout() consider a TimeLimit of 0 + // "infinity", so check for (TimeLimit =3D=3D 0) explicitly. + // + if (TimeLimit =3D=3D 0) { + return; + } + + CpuMpData->TotalTime =3D 0; + CpuMpData->ExpectedTime =3D CalculateTimeout ( + TimeLimit, + &CpuMpData->CurrentTime + ); + while (CpuMpData->FinishedCount < FinishedApLimit && + !CheckTimeout ( + &CpuMpData->CurrentTime, + &CpuMpData->TotalTime, + CpuMpData->ExpectedTime + )) + { + CpuPause (); + } + + if (CpuMpData->FinishedCount >=3D FinishedApLimit) { + DEBUG (( + DEBUG_VERBOSE, + "%a: reached FinishedApLimit=3D%u in %Lu microseconds\n", + __func__, + FinishedApLimit, + DivU64x64Remainder ( + MultU64x32 (CpuMpData->TotalTime, 1000000), + GetPerformanceCounterProperties (NULL, NULL), + NULL + ) + )); + } +} + +/** + Wait for AP wakeup and write AP start-up signal till AP is waken up. + + @param[in] ApStartupSignalBuffer Pointer to AP wakeup signal +**/ +VOID +WaitApWakeup ( + IN volatile UINT32 *ApStartupSignalBuffer + ) +{ + // + // If AP is waken up, StartupApSignal should be cleared. + // Otherwise, write StartupApSignal again till AP waken up. + // + while (InterlockedCompareExchange32 ( + (UINT32 *)ApStartupSignalBuffer, + WAKEUP_AP_SIGNAL, + WAKEUP_AP_SIGNAL + ) !=3D 0) + { + CpuPause (); + } +} + +/** + This function will fill the exchange info structure. + + @param[in] CpuMpData Pointer to CPU MP Data + +**/ +VOID +FillExchangeInfoData ( + IN CPU_MP_DATA *CpuMpData + ) +{ + volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo; + + if (!CpuMpData->MpCpuExchangeInfo) { + CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *)AllocatePool = (sizeof (MP_CPU_EXCHANGE_INFO)); + } + + ExchangeInfo =3D CpuMpData->MpCpuExchangeInfo; + ExchangeInfo->CpuMpData =3D CpuMpData; +} + +/** + This function will be called by BSP to wakeup AP. + + @param[in] CpuMpData Pointer to CPU MP Data + @param[in] Broadcast TRUE: Send broadcast IPI to all APs + FALSE: Send IPI to AP by ApicId + @param[in] ProcessorNumber The handle number of specified processor + @param[in] Procedure The function to be invoked by AP + @param[in] ProcedureArgument The argument to be passed into AP function + @param[in] WakeUpDisabledAps Whether need to wake up disabled APs in br= oadcast mode. Currently not used on LoongArch. +**/ +VOID +WakeUpAP ( + IN CPU_MP_DATA *CpuMpData, + IN BOOLEAN Broadcast, + IN UINTN ProcessorNumber, + IN EFI_AP_PROCEDURE Procedure OPTIONAL, + IN VOID *ProcedureArgument OPTIONAL, + IN BOOLEAN WakeUpDisabledAps + ) +{ + volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo; + UINTN Index; + CPU_AP_DATA *CpuData; + CPU_INFO_IN_HOB *CpuInfoInHob; + + CpuMpData->FinishedCount =3D 0; + + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + + if (CpuMpData->InitFlag !=3D ApInitDone) { + FillExchangeInfoData (CpuMpData); + } + + ExchangeInfo =3D CpuMpData->MpCpuExchangeInfo; + // + // If InitFlag is ApInitConfig, broadcasts all APs to initize themselves. + // + if (CpuMpData->InitFlag =3D=3D ApInitConfig) { + DEBUG ((DEBUG_INFO, "%a: func 0x%llx, ExchangeInfo 0x%llx\n", __func__= , ApWakeupFunction, (UINTN)ExchangeInfo)); + if (CpuMpData->ApLoopMode =3D=3D ApInHltLoop) { + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + if (Index !=3D CpuMpData->BspNumber) { + IoCsrWrite64 ( + LOONGARCH_IOCSR_MBUF_SEND, + (IOCSR_MBUF_SEND_BLOCKING | + (IOCSR_MBUF_SEND_BOX_HI (0x3) << IOCSR_MBUF_SEND_BOX_SHIFT) | + (CpuInfoInHob[Index].ApicId << IOCSR_MBUF_SEND_CPU_SHIFT) | + ((UINTN)(ExchangeInfo) & IOCSR_MBUF_SEND_H32_MASK)) + ); + IoCsrWrite64 ( + LOONGARCH_IOCSR_MBUF_SEND, + (IOCSR_MBUF_SEND_BLOCKING | + (IOCSR_MBUF_SEND_BOX_LO (0x3) << IOCSR_MBUF_SEND_BOX_SHIFT) | + (CpuInfoInHob[Index].ApicId << IOCSR_MBUF_SEND_CPU_SHIFT) | + ((UINTN)ExchangeInfo) << IOCSR_MBUF_SEND_BUF_SHIFT) + ); + + IoCsrWrite64 ( + LOONGARCH_IOCSR_MBUF_SEND, + (IOCSR_MBUF_SEND_BLOCKING | + (IOCSR_MBUF_SEND_BOX_HI (0x0) << IOCSR_MBUF_SEND_BOX_SHIFT) | + (CpuInfoInHob[Index].ApicId << IOCSR_MBUF_SEND_CPU_SHIFT) | + ((UINTN)(ApWakeupFunction) & IOCSR_MBUF_SEND_H32_MASK)) + ); + IoCsrWrite64 ( + LOONGARCH_IOCSR_MBUF_SEND, + (IOCSR_MBUF_SEND_BLOCKING | + (IOCSR_MBUF_SEND_BOX_LO (0x0) << IOCSR_MBUF_SEND_BOX_SHIFT) | + (CpuInfoInHob[Index].ApicId << IOCSR_MBUF_SEND_CPU_SHIFT) | + ((UINTN)ApWakeupFunction) << IOCSR_MBUF_SEND_BUF_SHIFT) + ); + + // + // Send IPI 4 interrupt to wake up APs. + // + IoCsrWrite64 ( + LOONGARCH_IOCSR_IPI_SEND, + (IOCSR_MBUF_SEND_BLOCKING | + (CpuInfoInHob[Index].ApicId << IOCSR_MBUF_SEND_CPU_SHIFT) | + 0x2 // Bit 2 + ) + ); + } + } + } else { + IoCsrWrite64 (LOONGARCH_IOCSR_MBUF3, (UINTN)ExchangeInfo); + IoCsrWrite64 (LOONGARCH_IOCSR_MBUF0, (UINTN)ApWakeupFunction); + } + + TimedWaitForApFinish ( + CpuMpData, + PcdGet32 (PcdCpuMaxLogicalProcessorNumber) - 1, + PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds) + ); + } else { + if (Broadcast) { + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + if (Index !=3D CpuMpData->BspNumber) { + CpuData =3D &CpuMpData->CpuData[Index]; + if ((GetApState (CpuData) =3D=3D CpuStateDisabled) && !WakeUpDis= abledAps) { + continue; + } + + CpuData->ApFunction =3D (UINTN)Procedure; + CpuData->ApFunctionArgument =3D (UINTN)ProcedureArgument; + SetApState (CpuData, CpuStateReady); + *(UINT32 *)CpuData->StartupApSignal =3D WAKEUP_AP_SIGNAL; + + // + // Send IPI 4 interrupt to wake up APs. + // + IoCsrWrite64 ( + LOONGARCH_IOCSR_IPI_SEND, + (IOCSR_MBUF_SEND_BLOCKING | + (CpuInfoInHob[Index].ApicId << IOCSR_MBUF_SEND_CPU_SHIFT) | + 0x2 // Bit 2 + ) + ); + } + } + + // + // Wait all APs waken up. + // + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + CpuData =3D &CpuMpData->CpuData[Index]; + if (Index !=3D CpuMpData->BspNumber) { + WaitApWakeup (CpuData->StartupApSignal); + } + } + } else { + CpuData =3D &CpuMpData->CpuData[ProcessorNumber]; + CpuData->ApFunction =3D (UINTN)Procedure; + CpuData->ApFunctionArgument =3D (UINTN)ProcedureArgument; + SetApState (CpuData, CpuStateReady); + // + // Wakeup specified AP + // + *(UINT32 *)CpuData->StartupApSignal =3D WAKEUP_AP_SIGNAL; + + // + // Send IPI 4 interrupt to wake up APs. + // + IoCsrWrite64 ( + LOONGARCH_IOCSR_IPI_SEND, + (IOCSR_MBUF_SEND_BLOCKING | + (CpuInfoInHob[ProcessorNumber].ApicId << IOCSR_MBUF_SEND_CPU_SHIF= T) | + 0x2 // Bit 2 + ) + ); + + // + // Wait specified AP waken up + // + WaitApWakeup (CpuData->StartupApSignal); + } + } +} + +/** + Searches for the next waiting AP. + + Search for the next AP that is put in waiting state by single-threaded S= tartupAllAPs(). + + @param[out] NextProcessorNumber Pointer to the processor number of the= next waiting AP. + + @retval EFI_SUCCESS The next waiting AP has been found. + @retval EFI_NOT_FOUND No waiting AP exists. + +**/ +EFI_STATUS +GetNextWaitingProcessorNumber ( + OUT UINTN *NextProcessorNumber + ) +{ + UINTN ProcessorNumber; + CPU_MP_DATA *CpuMpData; + + CpuMpData =3D GetCpuMpData (); + + for (ProcessorNumber =3D 0; ProcessorNumber < CpuMpData->CpuCount; Proce= ssorNumber++) { + if (CpuMpData->CpuData[ProcessorNumber].Waiting) { + *NextProcessorNumber =3D ProcessorNumber; + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** Checks status of specified AP. + + This function checks whether the specified AP has finished the task assi= gned + by StartupThisAP(), and whether timeout expires. + + @param[in] ProcessorNumber The handle number of processor. + + @retval EFI_SUCCESS Specified AP has finished task assigned by= StartupThisAPs(). + @retval EFI_TIMEOUT The timeout expires. + @retval EFI_NOT_READY Specified AP has not finished task and tim= eout has not expired. +**/ +EFI_STATUS +CheckThisAP ( + IN UINTN ProcessorNumber + ) +{ + CPU_MP_DATA *CpuMpData; + CPU_AP_DATA *CpuData; + + CpuMpData =3D GetCpuMpData (); + CpuData =3D &CpuMpData->CpuData[ProcessorNumber]; + + // + // If the AP finishes for StartupThisAP(), return EFI_SUCCESS. + // + if (GetApState (CpuData) =3D=3D CpuStateFinished) { + if (CpuData->Finished !=3D NULL) { + *(CpuData->Finished) =3D TRUE; + } + + SetApState (CpuData, CpuStateIdle); + return EFI_SUCCESS; + } else { + // + // If timeout expires for StartupThisAP(), report timeout. + // + if (CheckTimeout (&CpuData->CurrentTime, &CpuData->TotalTime, CpuData-= >ExpectedTime)) { + if (CpuData->Finished !=3D NULL) { + *(CpuData->Finished) =3D FALSE; + } + + return EFI_TIMEOUT; + } + } + + return EFI_NOT_READY; +} + +/** + Checks status of all APs. + + This function checks whether all APs have finished task assigned by Star= tupAllAPs(), + and whether timeout expires. + + @retval EFI_SUCCESS All APs have finished task assigned by Sta= rtupAllAPs(). + @retval EFI_TIMEOUT The timeout expires. + @retval EFI_NOT_READY APs have not finished task and timeout has= not expired. +**/ +EFI_STATUS +CheckAllAPs ( + VOID + ) +{ + UINTN ProcessorNumber; + UINTN NextProcessorNumber; + EFI_STATUS Status; + CPU_MP_DATA *CpuMpData; + CPU_AP_DATA *CpuData; + + CpuMpData =3D GetCpuMpData (); + + NextProcessorNumber =3D 0; + + // + // Go through all APs that are responsible for the StartupAllAPs(). + // + for (ProcessorNumber =3D 0; ProcessorNumber < CpuMpData->CpuCount; Proce= ssorNumber++) { + if (!CpuMpData->CpuData[ProcessorNumber].Waiting) { + continue; + } + + CpuData =3D &CpuMpData->CpuData[ProcessorNumber]; + // + // Check the CPU state of AP. If it is CpuStateIdle, then the AP has f= inished its task. + // Only BSP and corresponding AP access this unit of CPU Data. This me= ans the AP will not modify the + // value of state after setting the it to CpuStateIdle, so BSP can saf= ely make use of its value. + // + if (GetApState (CpuData) =3D=3D CpuStateFinished) { + CpuMpData->RunningCount--; + CpuMpData->CpuData[ProcessorNumber].Waiting =3D FALSE; + SetApState (CpuData, CpuStateIdle); + + // + // If in Single Thread mode, then search for the next waiting AP for= execution. + // + if (CpuMpData->SingleThread) { + Status =3D GetNextWaitingProcessorNumber (&NextProcessorNumber); + + if (!EFI_ERROR (Status)) { + WakeUpAP ( + CpuMpData, + FALSE, + (UINT32)NextProcessorNumber, + CpuMpData->Procedure, + CpuMpData->ProcArguments, + TRUE + ); + } + } + } + } + + // + // If all APs finish, return EFI_SUCCESS. + // + if (CpuMpData->RunningCount =3D=3D 0) { + return EFI_SUCCESS; + } + + // + // If timeout expires, report timeout. + // + if (CheckTimeout ( + &CpuMpData->CurrentTime, + &CpuMpData->TotalTime, + CpuMpData->ExpectedTime + ) + ) + { + return EFI_TIMEOUT; + } + + return EFI_NOT_READY; +} + +/** + Worker function to execute a caller provided function on all enabled APs. + + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. + @param[in] SingleThread If TRUE, then all the enabled APs ex= ecute + the function specified by Procedure = one by + one, in ascending order of processor= handle + number. If FALSE, then all the enab= led APs + execute the function specified by Pr= ocedure + simultaneously. + @param[in] ExcludeBsp Whether let BSP also trig this task. + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + APs to return from Procedure, either= for + blocking or non-blocking mode. + @param[in] ProcedureArgument The parameter passed into Procedure = for + all APs. + @param[out] FailedCpuList If all APs finish successfully, then= its + content is set to NULL. If not all A= Ps + finish before timeout expires, then = its + content is set to address of the buf= fer + holding handle numbers of the failed= APs. + + @retval EFI_SUCCESS In blocking mode, all APs have finished = before + the timeout expired. + @retval EFI_SUCCESS In non-blocking mode, function has been = dispatched + to all enabled APs. + @retval others Failed to Startup all APs. + +**/ +EFI_STATUS +StartupAllCPUsWorker ( + IN EFI_AP_PROCEDURE Procedure, + IN BOOLEAN SingleThread, + IN BOOLEAN ExcludeBsp, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT UINTN **FailedCpuList OPTIONAL + ) +{ + EFI_STATUS Status; + CPU_MP_DATA *CpuMpData; + UINTN ProcessorCount; + UINTN ProcessorNumber; + UINTN CallerNumber; + CPU_AP_DATA *CpuData; + BOOLEAN HasEnabledAp; + CPU_STATE ApState; + + CpuMpData =3D GetCpuMpData (); + + if (FailedCpuList !=3D NULL) { + *FailedCpuList =3D NULL; + } + + if ((CpuMpData->CpuCount =3D=3D 1) && ExcludeBsp) { + return EFI_NOT_STARTED; + } + + if (Procedure =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Check whether caller processor is BSP + // + MpInitLibWhoAmI (&CallerNumber); + if (CallerNumber !=3D CpuMpData->BspNumber) { + return EFI_DEVICE_ERROR; + } + + // + // Update AP state + // + CheckAndUpdateApsStatus (); + + ProcessorCount =3D CpuMpData->CpuCount; + HasEnabledAp =3D FALSE; + // + // Check whether all enabled APs are idle. + // If any enabled AP is not idle, return EFI_NOT_READY. + // + for (ProcessorNumber =3D 0; ProcessorNumber < ProcessorCount; ProcessorN= umber++) { + CpuData =3D &CpuMpData->CpuData[ProcessorNumber]; + if (ProcessorNumber !=3D CpuMpData->BspNumber) { + ApState =3D GetApState (CpuData); + if (ApState !=3D CpuStateDisabled) { + HasEnabledAp =3D TRUE; + if (ApState !=3D CpuStateIdle) { + // + // If any enabled APs are busy, return EFI_NOT_READY. + // + return EFI_NOT_READY; + } + } + } + } + + if (!HasEnabledAp && ExcludeBsp) { + // + // If no enabled AP exists and not include Bsp to do the procedure, re= turn EFI_NOT_STARTED. + // + return EFI_NOT_STARTED; + } + + CpuMpData->RunningCount =3D 0; + for (ProcessorNumber =3D 0; ProcessorNumber < ProcessorCount; ProcessorN= umber++) { + CpuData =3D &CpuMpData->CpuData[ProcessorNumber]; + CpuData->Waiting =3D FALSE; + if (ProcessorNumber !=3D CpuMpData->BspNumber) { + if (CpuData->State =3D=3D CpuStateIdle) { + // + // Mark this processor as responsible for current calling. + // + CpuData->Waiting =3D TRUE; + CpuMpData->RunningCount++; + } + } + } + + CpuMpData->Procedure =3D Procedure; + CpuMpData->ProcArguments =3D ProcedureArgument; + CpuMpData->SingleThread =3D SingleThread; + CpuMpData->FinishedCount =3D 0; + CpuMpData->ExpectedTime =3D CalculateTimeout ( + TimeoutInMicroseconds, + &CpuMpData->CurrentTime + ); + CpuMpData->TotalTime =3D 0; + CpuMpData->WaitEvent =3D WaitEvent; + + if (!SingleThread) { + WakeUpAP (CpuMpData, TRUE, 0, Procedure, ProcedureArgument, FALSE); + } else { + for (ProcessorNumber =3D 0; ProcessorNumber < ProcessorCount; Processo= rNumber++) { + if (ProcessorNumber =3D=3D CallerNumber) { + continue; + } + + if (CpuMpData->CpuData[ProcessorNumber].Waiting) { + WakeUpAP (CpuMpData, FALSE, ProcessorNumber, Procedure, ProcedureA= rgument, TRUE); + break; + } + } + } + + if (!ExcludeBsp) { + // + // Start BSP. + // + Procedure (ProcedureArgument); + } + + Status =3D EFI_SUCCESS; + if (WaitEvent =3D=3D NULL) { + do { + Status =3D CheckAllAPs (); + } while (Status =3D=3D EFI_NOT_READY); + } + + return Status; +} + +/** + Worker function to let the caller get one enabled AP to execute a caller= -provided + function. + + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. + @param[in] ProcessorNumber The handle number of the AP. + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + APs to return from Procedure, either= for + blocking or non-blocking mode. + @param[in] ProcedureArgument The parameter passed into Procedure = for + all APs. + @param[out] Finished If AP returns from Procedure before = the + timeout expires, its content is set = to TRUE. + Otherwise, the value is set to FALSE. + + @retval EFI_SUCCESS In blocking mode, specified AP finished = before + the timeout expires. + @retval others Failed to Startup AP. + +**/ +EFI_STATUS +StartupThisAPWorker ( + IN EFI_AP_PROCEDURE Procedure, + IN UINTN ProcessorNumber, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT BOOLEAN *Finished OPTIONAL + ) +{ + EFI_STATUS Status; + CPU_MP_DATA *CpuMpData; + CPU_AP_DATA *CpuData; + UINTN CallerNumber; + + CpuMpData =3D GetCpuMpData (); + + if (Finished !=3D NULL) { + *Finished =3D FALSE; + } + + // + // Check whether caller processor is BSP + // + MpInitLibWhoAmI (&CallerNumber); + if (CallerNumber !=3D CpuMpData->BspNumber) { + return EFI_DEVICE_ERROR; + } + + // + // Check whether processor with the handle specified by ProcessorNumber = exists + // + if (ProcessorNumber >=3D CpuMpData->CpuCount) { + return EFI_NOT_FOUND; + } + + // + // Check whether specified processor is BSP + // + if (ProcessorNumber =3D=3D CpuMpData->BspNumber) { + return EFI_INVALID_PARAMETER; + } + + // + // Check parameter Procedure + // + if (Procedure =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Update AP state + // + CheckAndUpdateApsStatus (); + + // + // Check whether specified AP is disabled + // + if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) =3D=3D CpuStateDis= abled) { + return EFI_INVALID_PARAMETER; + } + + CpuData =3D &CpuMpData->CpuData[ProcessorNumber]; + CpuData->WaitEvent =3D WaitEvent; + CpuData->Finished =3D Finished; + CpuData->ExpectedTime =3D CalculateTimeout (TimeoutInMicroseconds, &CpuD= ata->CurrentTime); + CpuData->TotalTime =3D 0; + + WakeUpAP (CpuMpData, FALSE, ProcessorNumber, Procedure, ProcedureArgumen= t, FALSE); + + // + // If WaitEvent is NULL, execute in blocking mode. + // BSP checks AP's state until it finishes or TimeoutInMicrosecsond expi= res. + // + Status =3D EFI_SUCCESS; + if (WaitEvent =3D=3D NULL) { + do { + Status =3D CheckThisAP (ProcessorNumber); + } while (Status =3D=3D EFI_NOT_READY); + } + + return Status; +} + +/** + This service executes a caller provided function on all enabled CPUs. + + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. See type + EFI_AP_PROCEDURE. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + APs to return from Procedure, either= for + blocking or non-blocking mode. Zero = means + infinity. TimeoutInMicroseconds is i= gnored + for BSP. + @param[in] ProcedureArgument The parameter passed into Procedure = for + all APs. + + @retval EFI_SUCCESS In blocking mode, all CPUs have finished= before + the timeout expired. + @retval EFI_SUCCESS In non-blocking mode, function has been = dispatched + to all enabled CPUs. + @retval EFI_DEVICE_ERROR Caller processor is AP. + @retval EFI_NOT_READY Any enabled APs are busy. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + @retval EFI_TIMEOUT In blocking mode, the timeout expired be= fore + all enabled APs have finished. + @retval EFI_INVALID_PARAMETER Procedure is NULL. + +**/ +EFI_STATUS +EFIAPI +MpInitLibStartupAllCPUs ( + IN EFI_AP_PROCEDURE Procedure, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL + ) +{ + return StartupAllCPUsWorker ( + Procedure, + TRUE, + FALSE, + NULL, + TimeoutInMicroseconds, + ProcedureArgument, + NULL + ); +} + +/** + MP Initialize Library initialization. + + This service will allocate AP reset vector and wakeup all APs to do APs + initialization. + + This service must be invoked before all other MP Initialize Library + service are invoked. + + @retval EFI_SUCCESS MP initialization succeeds. + @retval Others MP initialization fails. + +**/ +EFI_STATUS +EFIAPI +MpInitLibInitialize ( + VOID + ) +{ + CPU_MP_DATA *OldCpuMpData; + CPU_INFO_IN_HOB *CpuInfoInHob; + UINT32 MaxLogicalProcessorNumber; + UINTN BufferSize; + UINTN MonitorBufferSize; + VOID *MpBuffer; + CPU_MP_DATA *CpuMpData; + UINTN Index; + + OldCpuMpData =3D GetCpuMpDataFromGuidedHob (); + if (OldCpuMpData =3D=3D NULL) { + MaxLogicalProcessorNumber =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumbe= r); + } else { + MaxLogicalProcessorNumber =3D OldCpuMpData->CpuCount; + } + + ASSERT (MaxLogicalProcessorNumber !=3D 0); + + MonitorBufferSize =3D sizeof (WAKEUP_AP_SIGNAL) * MaxLogicalProcessorNum= ber; + + BufferSize =3D 0; + BufferSize +=3D MonitorBufferSize; + BufferSize +=3D sizeof (CPU_MP_DATA); + BufferSize +=3D (sizeof (CPU_AP_DATA) + sizeof (CPU_INFO_IN_HOB))* MaxLo= gicalProcessorNumber; + MpBuffer =3D AllocatePages (EFI_SIZE_TO_PAGES (BufferSize)); + ASSERT (MpBuffer !=3D NULL); + ZeroMem (MpBuffer, BufferSize); + + CpuMpData =3D (CPU_MP_DATA *)MpBuffer; + + CpuMpData->CpuCount =3D 1; + CpuMpData->BspNumber =3D 0; + CpuMpData->CpuData =3D (CPU_AP_DATA *)(CpuMpData + 1); + CpuMpData->CpuInfoInHob =3D (UINT64)(UINTN)(CpuMpData->CpuData + MaxLogi= calProcessorNumber); + + InitializeSpinLock (&CpuMpData->MpLock); + + // + // Set BSP basic information + // + InitializeApData (CpuMpData, 0, 0); + + // + // Set up APs wakeup signal buffer and initialization APs ApicId status. + // + for (Index =3D 0; Index < MaxLogicalProcessorNumber; Index++) { + CpuMpData->CpuData[Index].StartupApSignal =3D + (UINT32 *)((MpBuffer + BufferSize - MonitorBufferSize) + (sizeof (WA= KEUP_AP_SIGNAL) * Index)); + if ((OldCpuMpData =3D=3D NULL) && (Index !=3D CpuMpData->BspNumber)) { + ((CPU_INFO_IN_HOB *)CpuMpData->CpuInfoInHob)[Index].ApicId =3D INVA= LID_APIC_ID; + } + } + + if (OldCpuMpData =3D=3D NULL) { + if (MaxLogicalProcessorNumber > 1) { + // + // Wakeup all APs and calculate the processor count in system + // + CollectProcessorCount (CpuMpData); + } + } else { + // + // APs have been wakeup before, just get the CPU Information + // from HOB + // + CpuMpData->CpuCount =3D OldCpuMpData->CpuCount; + CpuMpData->BspNumber =3D OldCpuMpData->BspNumber; + CpuMpData->CpuInfoInHob =3D OldCpuMpData->CpuInfoInHob; + CpuMpData->MpCpuExchangeInfo =3D OldCpuMpData->MpCpuExchangeInfo; + + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + InitializeSpinLock (&CpuMpData->CpuData[Index].ApLock); + CpuMpData->CpuData[Index].CpuHealthy =3D (CpuInfoInHob[Index].Health= =3D=3D 0) ? TRUE : FALSE; + } + + if (CpuMpData->CpuCount > 1) { + // + // Only needs to use this flag for DXE phase to update the wake up + // buffer. Wakeup buffer allocated in PEI phase is no longer valid + // in DXE. + // + CpuMpData->InitFlag =3D ApInitReconfig; + WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE); + + // + // Wait for all APs finished initialization + // + while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { + CpuPause (); + } + + CpuMpData->InitFlag =3D ApInitDone; + } + + if (MaxLogicalProcessorNumber > 1) { + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); + } + } + } + + // + // Initialize global data for MP support + // + InitMpGlobalData (CpuMpData); + + return EFI_SUCCESS; +} + +/** + Gets detailed MP-related information on the requested processor at the + instant this call is made. This service may only be called from the BSP. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + @param[out] HealthData Return processor health data. + + @retval EFI_SUCCESS Processor information was returned. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist in the pl= atform. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +EFIAPI +MpInitLibGetProcessorInfo ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer, + OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL + ) +{ + CPU_MP_DATA *CpuMpData; + UINTN CallerNumber; + CPU_INFO_IN_HOB *CpuInfoInHob; + + CpuMpData =3D GetCpuMpData (); + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + + // + // Check whether caller processor is BSP + // + MpInitLibWhoAmI (&CallerNumber); + if (CallerNumber !=3D CpuMpData->BspNumber) { + return EFI_DEVICE_ERROR; + } + + if (ProcessorInfoBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (ProcessorNumber >=3D CpuMpData->CpuCount) { + return EFI_NOT_FOUND; + } + + ProcessorInfoBuffer->ProcessorId =3D (UINT64)CpuInfoInHob[ProcessorNumbe= r].ApicId; + ProcessorInfoBuffer->StatusFlag =3D 0; + if (ProcessorNumber =3D=3D CpuMpData->BspNumber) { + ProcessorInfoBuffer->StatusFlag |=3D PROCESSOR_AS_BSP_BIT; + } + + if (CpuMpData->CpuData[ProcessorNumber].CpuHealthy) { + ProcessorInfoBuffer->StatusFlag |=3D PROCESSOR_HEALTH_STATUS_BIT; + } + + if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) =3D=3D CpuStateDis= abled) { + ProcessorInfoBuffer->StatusFlag &=3D ~PROCESSOR_ENABLED_BIT; + } else { + ProcessorInfoBuffer->StatusFlag |=3D PROCESSOR_ENABLED_BIT; + } + + if (HealthData !=3D NULL) { + HealthData->Uint32 =3D CpuInfoInHob[ProcessorNumber].Health; + } + + return EFI_SUCCESS; +} + +/** + This return the handle number for the calling processor. This service m= ay be + called from the BSP and APs. + + @param[out] ProcessorNumber Pointer to the handle number of AP. + The range is from 0 to the total number of + logical processors minus 1. The total numbe= r of + logical processors can be retrieved by + MpInitLibGetNumberOfProcessors(). + + @retval EFI_SUCCESS The current processor handle number was = returned + in ProcessorNumber. + @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +EFIAPI +MpInitLibWhoAmI ( + OUT UINTN *ProcessorNumber + ) +{ + CPU_MP_DATA *CpuMpData; + + if (ProcessorNumber =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + CpuMpData =3D GetCpuMpData (); + + return GetProcessorNumber (CpuMpData, ProcessorNumber); +} + +/** + Retrieves the number of logical processor in the platform and the number= of + those logical processors that are enabled on this boot. This service may= only + be called from the BSP. + + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. + + @retval EFI_SUCCESS The number of logical processors and ena= bled + logical processors was retrieved. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfE= nabledProcessors + is NULL. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +EFIAPI +MpInitLibGetNumberOfProcessors ( + OUT UINTN *NumberOfProcessors OPTIONAL, + OUT UINTN *NumberOfEnabledProcessors OPTIONAL + ) +{ + CPU_MP_DATA *CpuMpData; + UINTN CallerNumber; + UINTN ProcessorNumber; + UINTN EnabledProcessorNumber; + UINTN Index; + + CpuMpData =3D GetCpuMpData (); + + if ((NumberOfProcessors =3D=3D NULL) && (NumberOfEnabledProcessors =3D= =3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + // + // Check whether caller processor is BSP + // + MpInitLibWhoAmI (&CallerNumber); + if (CallerNumber !=3D CpuMpData->BspNumber) { + return EFI_DEVICE_ERROR; + } + + ProcessorNumber =3D CpuMpData->CpuCount; + EnabledProcessorNumber =3D 0; + for (Index =3D 0; Index < ProcessorNumber; Index++) { + if (GetApState (&CpuMpData->CpuData[Index]) !=3D CpuStateDisabled) { + EnabledProcessorNumber++; + } + } + + if (NumberOfProcessors !=3D NULL) { + *NumberOfProcessors =3D ProcessorNumber; + } + + if (NumberOfEnabledProcessors !=3D NULL) { + *NumberOfEnabledProcessors =3D EnabledProcessorNumber; + } + + return EFI_SUCCESS; +} + +/** + Get pointer to CPU MP Data structure from GUIDed HOB. + + @return The pointer to CPU MP Data structure. +**/ +CPU_MP_DATA * +GetCpuMpDataFromGuidedHob ( + VOID + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + VOID *DataInHob; + CPU_MP_DATA *CpuMpData; + + CpuMpData =3D NULL; + GuidHob =3D GetFirstGuidHob (&mCpuInitMpLibHobGuid); + + if (GuidHob !=3D NULL) { + DataInHob =3D GET_GUID_HOB_DATA (GuidHob); + CpuMpData =3D (CPU_MP_DATA *)(*(UINTN *)DataInHob); + } + + return CpuMpData; +} diff --git a/UefiCpuPkg/Library/MpInitLib/LoongArch64/MpLib.h b/UefiCpuPkg/= Library/MpInitLib/LoongArch64/MpLib.h new file mode 100644 index 0000000000..b9c6c55b41 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/LoongArch64/MpLib.h @@ -0,0 +1,361 @@ +/** @file + Common header file for LoongArch MP Initialize Library. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MP_LIB_H_ +#define MP_LIB_H_ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P') + +#define CPU_INIT_MP_LIB_HOB_GUID \ + { \ + 0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad= , 0x4a } \ + } + +#define PROCESSOR_RESOURCE_HOB_GUID \ + { \ + 0xb855c7fe, 0xa758, 0x701f, { 0xa7, 0x30, 0x87, 0xf3, 0x9c, 0x03, 0x46= , 0x7e } \ + } + +// +// AP loop state when APs are in idle state +// It's value is the same with PcdCpuApLoopMode +// +typedef enum { + ApInHltLoop =3D 1, + ApInRunLoop =3D 2 +} AP_LOOP_MODE; + +// +// AP initialization state during APs wakeup +// +typedef enum { + ApInitConfig =3D 1, + ApInitReconfig =3D 2, + ApInitDone =3D 3 +} AP_INIT_STATE; + +// +// AP state +// +typedef enum { + CpuStateIdle, + CpuStateReady, + CpuStateBusy, + CpuStateFinished, + CpuStateDisabled +} CPU_STATE; + +// +// AP related data +// +typedef struct { + SPIN_LOCK ApLock; + volatile UINT32 *StartupApSignal; + volatile UINTN ApFunction; + volatile UINTN ApFunctionArgument; + BOOLEAN CpuHealthy; + volatile CPU_STATE State; + BOOLEAN Waiting; + BOOLEAN *Finished; + UINT64 ExpectedTime; + UINT64 CurrentTime; + UINT64 TotalTime; + EFI_EVENT WaitEvent; +} CPU_AP_DATA; + +// +// Basic CPU information saved in Guided HOB. +// Because the contents will be shard between PEI and DXE, +// we need to make sure the each fields offset same in different +// architecture. +// +#pragma pack (1) +typedef struct { + UINT32 ApicId; + UINT32 Health; +} CPU_INFO_IN_HOB; +#pragma pack () + +typedef struct MP_CPU_DATA CPU_MP_DATA; + +#pragma pack(1) + +// +// MP CPU exchange information for AP reset code +// This structure is required to be packed because fixed field offsets +// into this structure are used in assembly code in this module +// +typedef struct { + CPU_MP_DATA *CpuMpData; +} MP_CPU_EXCHANGE_INFO; + +#pragma pack() + +typedef struct { + SPIN_LOCK Lock; + UINT32 CpuCount; + UINT64 CpuInfoInHob; +} PROCESSOR_RESOURCE_DATA; + +// +// CPU MP Data save in memory +// +struct MP_CPU_DATA { + UINT64 CpuInfoInHob; + UINT32 CpuCount; + UINT32 BspNumber; + // + // The above fields data will be passed from PEI to DXE + // Please make sure the fields offset same in the different + // architecture. + // + SPIN_LOCK MpLock; + + volatile UINT32 FinishedCount; + UINT32 RunningCount; + BOOLEAN SingleThread; + EFI_AP_PROCEDURE Procedure; + VOID *ProcArguments; + BOOLEAN *Finished; + UINT64 ExpectedTime; + UINT64 CurrentTime; + UINT64 TotalTime; + EFI_EVENT WaitEvent; + + AP_INIT_STATE InitFlag; + UINT8 ApLoopMode; + CPU_AP_DATA *CpuData; + volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo; +}; + +extern EFI_GUID mCpuInitMpLibHobGuid; +extern EFI_GUID mProcessorResourceHobGuid; + +/** + Get the pointer to CPU MP Data structure. + + @return The pointer to CPU MP Data structure. +**/ +CPU_MP_DATA * +GetCpuMpData ( + VOID + ); + +/** + Save the pointer to CPU MP Data structure. + + @param[in] CpuMpData The pointer to CPU MP Data structure will be saved. +**/ +VOID +SaveCpuMpData ( + IN CPU_MP_DATA *CpuMpData + ); + +/** + This function will be called by BSP to wakeup AP. + + @param[in] CpuMpData Pointer to CPU MP Data + @param[in] Broadcast TRUE: Send broadcast IPI to all APs + FALSE: Send IPI to AP by ApicId + @param[in] ProcessorNumber The handle number of specified processor + @param[in] Procedure The function to be invoked by AP + @param[in] ProcedureArgument The argument to be passed into AP function + @param[in] WakeUpDisabledAps Whether need to wake up disabled APs in br= oadcast mode. +**/ +VOID +WakeUpAP ( + IN CPU_MP_DATA *CpuMpData, + IN BOOLEAN Broadcast, + IN UINTN ProcessorNumber, + IN EFI_AP_PROCEDURE Procedure OPTIONAL, + IN VOID *ProcedureArgument OPTIONAL, + IN BOOLEAN WakeUpDisabledAps + ); + +/** + Initialize global data for MP support. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +InitMpGlobalData ( + IN CPU_MP_DATA *CpuMpData + ); + +/** + Worker function to execute a caller provided function on all enabled APs. + + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. + @param[in] SingleThread If TRUE, then all the enabled APs ex= ecute + the function specified by Procedure = one by + one, in ascending order of processor= handle + number. If FALSE, then all the enab= led APs + execute the function specified by Pr= ocedure + simultaneously. + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + APs to return from Procedure, either= for + blocking or non-blocking mode. + @param[in] ProcedureArgument The parameter passed into Procedure = for + all APs. + @param[out] FailedCpuList If all APs finish successfully, then= its + content is set to NULL. If not all A= Ps + finish before timeout expires, then = its + content is set to address of the buf= fer + holding handle numbers of the failed= APs. + + @retval EFI_SUCCESS In blocking mode, all APs have finished = before + the timeout expired. + @retval EFI_SUCCESS In non-blocking mode, function has been = dispatched + to all enabled APs. + @retval others Failed to Startup all APs. + +**/ +EFI_STATUS +StartupAllCPUsWorker ( + IN EFI_AP_PROCEDURE Procedure, + IN BOOLEAN SingleThread, + IN BOOLEAN ExcludeBsp, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT UINTN **FailedCpuList OPTIONAL + ); + +/** + Worker function to let the caller get one enabled AP to execute a caller= -provided + function. + + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. + @param[in] ProcessorNumber The handle number of the AP. + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + APs to return from Procedure, either= for + blocking or non-blocking mode. + @param[in] ProcedureArgument The parameter passed into Procedure = for + all APs. + @param[out] Finished If AP returns from Procedure before = the + timeout expires, its content is set = to TRUE. + Otherwise, the value is set to FALSE. + + @retval EFI_SUCCESS In blocking mode, specified AP finished = before + the timeout expires. + @retval others Failed to Startup AP. + +**/ +EFI_STATUS +StartupThisAPWorker ( + IN EFI_AP_PROCEDURE Procedure, + IN UINTN ProcessorNumber, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT BOOLEAN *Finished OPTIONAL + ); + +/** + Worker function to let the caller enable or disable an AP from this poin= t onward. + This service may only be called from the BSP. + This instance will be added in the future. + + @param[in] ProcessorNumber The handle number of AP. + @param[in] EnableAP Specifies the new state for the processor f= or + enabled, FALSE for disabled. + @param[in] HealthFlag If not NULL, a pointer to a value that spec= ifies + the new health status of the AP. + + @retval EFI_SUCCESS The specified AP was enabled or disabled su= ccessfully. + @retval others Failed to Enable/Disable AP. + +**/ +EFI_STATUS +EnableDisableApWorker ( + IN UINTN ProcessorNumber, + IN BOOLEAN EnableAP, + IN UINT32 *HealthFlag OPTIONAL + ); + +/** + Get pointer to CPU MP Data structure from GUIDed HOB. + + @return The pointer to CPU MP Data structure. +**/ +CPU_MP_DATA * +GetCpuMpDataFromGuidedHob ( + VOID + ); + +/** Checks status of specified AP. + + This function checks whether the specified AP has finished the task assi= gned + by StartupThisAP(), and whether timeout expires. + + @param[in] ProcessorNumber The handle number of processor. + + @retval EFI_SUCCESS Specified AP has finished task assigned by= StartupThisAPs(). + @retval EFI_TIMEOUT The timeout expires. + @retval EFI_NOT_READY Specified AP has not finished task and tim= eout has not expired. +**/ +EFI_STATUS +CheckThisAP ( + IN UINTN ProcessorNumber + ); + +/** + Checks status of all APs. + + This function checks whether all APs have finished task assigned by Star= tupAllAPs(), + and whether timeout expires. + + @retval EFI_SUCCESS All APs have finished task assigned by Sta= rtupAllAPs(). + @retval EFI_TIMEOUT The timeout expires. + @retval EFI_NOT_READY APs have not finished task and timeout has= not expired. +**/ +EFI_STATUS +CheckAllAPs ( + VOID + ); + +/** + Checks APs status and updates APs status if needed. + +**/ +VOID +CheckAndUpdateApsStatus ( + VOID + ); + +/** + Enable Debug Agent to support source debugging on AP function. + This instance will added in the future. + +**/ +VOID +EnableDebugAgent ( + VOID + ); + +#endif diff --git a/UefiCpuPkg/Library/MpInitLib/LoongArch64/PeiMpLib.c b/UefiCpuP= kg/Library/MpInitLib/LoongArch64/PeiMpLib.c new file mode 100644 index 0000000000..d1c5e55b57 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/LoongArch64/PeiMpLib.c @@ -0,0 +1,404 @@ +/** @file + LoongArch64 MP initialize support functions for PEI phase. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" + +/** + Enable Debug Agent to support source debugging on AP function. + +**/ +VOID +EnableDebugAgent ( + VOID + ) +{ +} + +/** + Get pointer to CPU MP Data structure. + + @return The pointer to CPU MP Data structure. +**/ +CPU_MP_DATA * +GetCpuMpData ( + VOID + ) +{ + CPU_MP_DATA *CpuMpData; + + CpuMpData =3D GetCpuMpDataFromGuidedHob (); + ASSERT (CpuMpData !=3D NULL); + return CpuMpData; +} + +/** + Save the pointer to CPU MP Data structure. + + @param[in] CpuMpData The pointer to CPU MP Data structure will be saved. +**/ +VOID +SaveCpuMpData ( + IN CPU_MP_DATA *CpuMpData + ) +{ + UINT64 Data64; + + // + // Build location of CPU MP DATA buffer in HOB + // + Data64 =3D (UINT64)(UINTN)CpuMpData; + BuildGuidDataHob ( + &mCpuInitMpLibHobGuid, + (VOID *)&Data64, + sizeof (UINT64) + ); +} + +/** + Save the Processor Resource Data. + + @param[in] ResourceData The pointer to Processor Resource Data structur= e will be saved. +**/ +VOID +SaveProcessorResourceData ( + IN PROCESSOR_RESOURCE_DATA *ResourceData + ) +{ + UINT64 Data64; + + // + // Build location of Processor Resource Data buffer in HOB + // + Data64 =3D (UINT64)(UINTN)ResourceData; + BuildGuidDataHob ( + &mProcessorResourceHobGuid, + (VOID *)&Data64, + sizeof (UINT64) + ); +} + +/** + Get available EfiBootServicesCode memory below 4GB by specified size. + + This buffer is required to safely transfer AP from real address mode to + protected mode or long mode, due to the fact that the buffer returned by + GetWakeupBuffer() may be marked as non-executable. + + @param[in] BufferSize Wakeup transition buffer size. + + @retval other Return wakeup transition buffer address below 4GB. + @retval 0 Cannot find free memory below 4GB. +**/ +UINTN +GetModeTransitionBuffer ( + IN UINTN BufferSize + ) +{ + // + // PEI phase doesn't need to do such transition. So simply return 0. + // + return 0; +} + +/** + Checks APs status and updates APs status if needed. + +**/ +VOID +CheckAndUpdateApsStatus ( + VOID + ) +{ +} + +/** + Initialize global data for MP support. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +InitMpGlobalData ( + IN CPU_MP_DATA *CpuMpData + ) +{ + SaveCpuMpData (CpuMpData); +} + +/** + This service executes a caller provided function on all enabled APs. + + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. See type + EFI_AP_PROCEDURE. + @param[in] SingleThread If TRUE, then all the enabled APs ex= ecute + the function specified by Procedure = one by + one, in ascending order of processor= handle + number. If FALSE, then all the enab= led APs + execute the function specified by Pr= ocedure + simultaneously. + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. If it is NULL, then execut= e in + blocking mode. BSP waits until all A= Ps finish + or TimeoutInMicroSeconds expires. I= f it's + not NULL, then execute in non-blocki= ng mode. + BSP requests the function specified = by + Procedure to be started on all the e= nabled + APs, and go on executing immediately= . If + all return from Procedure, or Timeou= tInMicroSeconds + expires, this event is signaled. The= BSP + can use the CheckEvent() or WaitForE= vent() + services to check the state of event= . Type + EFI_EVENT is defined in CreateEvent(= ) in + the Unified Extensible Firmware Inte= rface + Specification. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + APs to return from Procedure, either= for + blocking or non-blocking mode. Zero = means + infinity. If the timeout expires be= fore + all APs return from Procedure, then = Procedure + on the failed APs is terminated. All= enabled + APs are available for next function = assigned + by MpInitLibStartupAllAPs() or + MPInitLibStartupThisAP(). + If the timeout expires in blocking m= ode, + BSP returns EFI_TIMEOUT. If the tim= eout + expires in non-blocking mode, WaitEv= ent + is signaled with SignalEvent(). + @param[in] ProcedureArgument The parameter passed into Procedure = for + all APs. + @param[out] FailedCpuList If NULL, this parameter is ignored. = Otherwise, + if all APs finish successfully, then= its + content is set to NULL. If not all A= Ps + finish before timeout expires, then = its + content is set to address of the buf= fer + holding handle numbers of the failed= APs. + The buffer is allocated by MP Initia= lization + library, and it's the caller's respo= nsibility to + free the buffer with FreePool() serv= ice. + In blocking mode, it is ready for co= nsumption + when the call returns. In non-blocki= ng mode, + it is ready when WaitEvent is signal= ed. The + list of failed CPU is terminated by + END_OF_CPU_LIST. + + @retval EFI_SUCCESS In blocking mode, all APs have finished = before + the timeout expired. + @retval EFI_SUCCESS In non-blocking mode, function has been = dispatched + to all enabled APs. + @retval EFI_UNSUPPORTED A non-blocking mode request was made aft= er the + UEFI event EFI_EVENT_GROUP_READY_TO_BOOT= was + signaled. + @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mo= de is not + supported. + @retval EFI_DEVICE_ERROR Caller processor is AP. + @retval EFI_NOT_STARTED No enabled APs exist in the system. + @retval EFI_NOT_READY Any enabled APs are busy. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + @retval EFI_TIMEOUT In blocking mode, the timeout expired be= fore + all enabled APs have finished. + @retval EFI_INVALID_PARAMETER Procedure is NULL. + +**/ +EFI_STATUS +EFIAPI +MpInitLibStartupAllAPs ( + IN EFI_AP_PROCEDURE Procedure, + IN BOOLEAN SingleThread, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT UINTN **FailedCpuList OPTIONAL + ) +{ + if (WaitEvent !=3D NULL) { + return EFI_UNSUPPORTED; + } + + return StartupAllCPUsWorker ( + Procedure, + SingleThread, + TRUE, + NULL, + TimeoutInMicroseconds, + ProcedureArgument, + FailedCpuList + ); +} + +/** + This service lets the caller get one enabled AP to execute a caller-prov= ided + function. + + @param[in] Procedure A pointer to the function to be run = on the + designated AP of the system. See type + EFI_AP_PROCEDURE. + @param[in] ProcessorNumber The handle number of the AP. The ran= ge is + from 0 to the total number of logical + processors minus 1. The total number= of + logical processors can be retrieved = by + MpInitLibGetNumberOfProcessors(). + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. If it is NULL, then execut= e in + blocking mode. BSP waits until this = AP finish + or TimeoutInMicroSeconds expires. I= f it's + not NULL, then execute in non-blocki= ng mode. + BSP requests the function specified = by + Procedure to be started on this AP, + and go on executing immediately. If = this AP + return from Procedure or TimeoutInMi= croSeconds + expires, this event is signaled. The= BSP + can use the CheckEvent() or WaitForE= vent() + services to check the state of event= . Type + EFI_EVENT is defined in CreateEvent(= ) in + the Unified Extensible Firmware Inte= rface + Specification. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + this AP to finish this Procedure, ei= ther for + blocking or non-blocking mode. Zero = means + infinity. If the timeout expires be= fore + this AP returns from Procedure, then= Procedure + on the AP is terminated. The + AP is available for next function as= signed + by MpInitLibStartupAllAPs() or + MpInitLibStartupThisAP(). + If the timeout expires in blocking m= ode, + BSP returns EFI_TIMEOUT. If the tim= eout + expires in non-blocking mode, WaitEv= ent + is signaled with SignalEvent(). + @param[in] ProcedureArgument The parameter passed into Procedure = on the + specified AP. + @param[out] Finished If NULL, this parameter is ignored. = In + blocking mode, this parameter is ign= ored. + In non-blocking mode, if AP returns = from + Procedure before the timeout expires= , its + content is set to TRUE. Otherwise, t= he + value is set to FALSE. The caller can + determine if the AP returned from Pr= ocedure + by evaluating this value. + + @retval EFI_SUCCESS In blocking mode, specified AP finished = before + the timeout expires. + @retval EFI_SUCCESS In non-blocking mode, the function has b= een + dispatched to specified AP. + @retval EFI_UNSUPPORTED A non-blocking mode request was made aft= er the + UEFI event EFI_EVENT_GROUP_READY_TO_BOOT= was + signaled. + @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mo= de is not + supported. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_TIMEOUT In blocking mode, the timeout expired be= fore + the specified AP has finished. + @retval EFI_NOT_READY The specified AP is busy. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist. + @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or dis= abled AP. + @retval EFI_INVALID_PARAMETER Procedure is NULL. + +**/ +EFI_STATUS +EFIAPI +MpInitLibStartupThisAP ( + IN EFI_AP_PROCEDURE Procedure, + IN UINTN ProcessorNumber, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT BOOLEAN *Finished OPTIONAL + ) +{ + if (WaitEvent !=3D NULL) { + return EFI_UNSUPPORTED; + } + + return StartupThisAPWorker ( + Procedure, + ProcessorNumber, + NULL, + TimeoutInMicroseconds, + ProcedureArgument, + Finished + ); +} + +/** + This service switches the requested AP to be the BSP from that point onw= ard. + This service changes the BSP for all purposes. This call can only be per= formed + by the current BSP. + + @param[in] ProcessorNumber The handle number of AP that is to become t= he new + BSP. The range is from 0 to the total numbe= r of + logical processors minus 1. The total numbe= r of + logical processors can be retrieved by + MpInitLibGetNumberOfProcessors(). + @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as= an + enabled AP. Otherwise, it will be disabled. + + @retval EFI_SUCCESS BSP successfully switched. + @retval EFI_UNSUPPORTED Switching the BSP cannot be completed pr= ior to + this service returning. + @retval EFI_UNSUPPORTED Switching the BSP is not supported. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist. + @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BS= P or + a disabled AP. + @retval EFI_NOT_READY The specified AP is busy. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +EFIAPI +MpInitLibSwitchBSP ( + IN UINTN ProcessorNumber, + IN BOOLEAN EnableOldBSP + ) +{ + return EFI_UNSUPPORTED; +} + +/** + This service lets the caller enable or disable an AP from this point onw= ard. + This service may only be called from the BSP. + + @param[in] ProcessorNumber The handle number of AP. + The range is from 0 to the total number of + logical processors minus 1. The total numbe= r of + logical processors can be retrieved by + MpInitLibGetNumberOfProcessors(). + @param[in] EnableAP Specifies the new state for the processor f= or + enabled, FALSE for disabled. + @param[in] HealthFlag If not NULL, a pointer to a value that spec= ifies + the new health status of the AP. This flag + corresponds to StatusFlag defined in + EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo()= . Only + the PROCESSOR_HEALTH_STATUS_BIT is used. Al= l other + bits are ignored. If it is NULL, this para= meter + is ignored. + + @retval EFI_SUCCESS The specified AP was enabled or disabled= successfully. + @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be co= mpleted + prior to this service returning. + @retval EFI_UNSUPPORTED Enabling or disabling an AP is not suppo= rted. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_NOT_FOUND Processor with the handle specified by P= rocessorNumber + does not exist. + @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +EFIAPI +MpInitLibEnableDisableAP ( + IN UINTN ProcessorNumber, + IN BOOLEAN EnableAP, + IN UINT32 *HealthFlag OPTIONAL + ) +{ + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index bc3d716aa9..36ee6b9c29 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -2,6 +2,7 @@ # MP Initialize Library instance for PEI driver. # # Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights= reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -18,7 +19,7 @@ # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 +# VALID_ARCHITECTURES =3D IA32 X64 LOONGARCH64 # =20 [Sources.IA32] @@ -29,7 +30,7 @@ X64/AmdSev.c X64/MpFuncs.nasm =20 -[Sources.common] +[Sources.IA32, Sources.X64] AmdSev.c MpEqu.inc PeiMpLib.c @@ -37,23 +38,31 @@ MpLib.h Microcode.c MpHandOff.h + +[Sources.LoongArch64] + LoongArch64/PeiMpLib.c + LoongArch64/MpLib.c + LoongArch64/MpLib.h + [Packages] MdePkg/MdePkg.dec UefiCpuPkg/UefiCpuPkg.dec MdeModulePkg/MdeModulePkg.dec =20 -[LibraryClasses] +[LibraryClasses.common] BaseLib - LocalApicLib - MemoryAllocationLib - HobLib - MtrrLib CpuLib - SynchronizationLib - PeiServicesLib + HobLib + MemoryAllocationLib PcdLib + PeiServicesLib + SynchronizationLib + +[LibraryClasses.IA32, LibraryClasses.X64] CcExitLib + LocalApicLib MicrocodeLib + MtrrLib =20 [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## CONS= UMES --=20 2.27.0 -=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 (#114541): https://edk2.groups.io/g/devel/message/114541 Mute This Topic: https://groups.io/mt/103971654/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- From nobody Thu Dec 26 20:24:45 2024 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+114542+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+114542+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250580; cv=none; d=zohomail.com; s=zohoarc; b=BYVdBJQcOZ3IzYoSdoTXBMfx7rHQ8vRJT0VYG79bmp1NuXaBNAkt+F/7Xr89h3UHE43/7BAh7avLFlws68jS8RzzLCqu2XB9Bsk8tc1ynFUN6nKbfqx7yObJR03+ea4HKiu+hLpgBFT1VpnWCdrU3DPDAPXVzHldfhE40uQuuxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250580; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=vN9SIMSSBLlr9NBNmHqJiq3yxvICsk2NmQkfKiUF4b8=; b=iZfraRLH0Lj/oq+8iqPvAE4yP1KtMb9VfdDCx9sCQoZRnfTKHdvQs/BLo+MJGu265BN6nKObz5UougaGrG2VoTJFwGJKUVxpOjVkiopuT3GzZpy/vzEZf+3aONmpPeZt910+UryrZIwYE3eep6kDFbv8euA2+MFY6/Em6dCZZwE= 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+114542+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 17062505806851.8994987576908215; Thu, 25 Jan 2024 22:29:40 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=wIk8QDTbiLAVDSU4iHzI8cT/gtY+9Jd8njTRAZ+Q43U=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250580; v=1; b=KlryY30O8J0wWeMFtK6NmBTyOlzpZlqujKycmYZq72EHH8HzgUSIBs/bxmm5DtLepiQk3gpR 0tjCPItz2r7+RDn60eVHA0rO2vHgN0OhqgPgjYfudHSln2WDMgQAJ2T7dgrHVtEpsEiFGR4eZcZ IovgZAlyQm/vDE+H5gs66+Gw= X-Received: by 127.0.0.2 with SMTP id AvipYY1788612xd06HTq6lop; Thu, 25 Jan 2024 22:29:40 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10137.1706250577992269008 for ; Thu, 25 Jan 2024 22:29:39 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8Cx2uhOUbNlMh4GAA--.2189S3; Fri, 26 Jan 2024 14:29:34 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx7c5NUbNlkXIbAA--.52917S2; Fri, 26 Jan 2024 14:29:33 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Baoqi Zhang , Dongyan Qian Subject: [edk2-devel] [PATCH v8 16/37] UefiCpuPkg: Add CpuDxe driver for LoongArch64 Date: Fri, 26 Jan 2024 14:29:32 +0800 Message-Id: <20240126062932.3101824-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx7c5NUbNlkXIbAA--.52917S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBQsP X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 5jmuTefMKpkijONk68emoouGx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250582367100001 Content-Type: text/plain; charset="utf-8" Added LoongArch64 CPU driver into CpuDxe. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Chao Li Co-authored-by: Baoqi Zhang Co-authored-by: Dongyan Qian --- UefiCpuPkg/CpuDxe/CpuDxe.inf | 23 +- UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.c | 454 ++++++++++++++++++ UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.h | 288 ++++++++++++ UefiCpuPkg/CpuDxe/LoongArch64/CpuMp.c | 544 ++++++++++++++++++++++ UefiCpuPkg/CpuDxe/LoongArch64/Exception.c | 159 +++++++ 5 files changed, 1464 insertions(+), 4 deletions(-) create mode 100644 UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.c create mode 100644 UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.h create mode 100644 UefiCpuPkg/CpuDxe/LoongArch64/CpuMp.c create mode 100644 UefiCpuPkg/CpuDxe/LoongArch64/Exception.c diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf index 1d3e9f8cdb..18ebd2eb2c 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.inf +++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf @@ -3,6 +3,7 @@ # # Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
# Copyright (c) 2017, AMD Incorporated. All rights reserved.
+# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights= reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -22,17 +23,16 @@ MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 -[LibraryClasses] +[LibraryClasses.common] BaseLib BaseMemoryLib CpuLib + CacheMaintenanceLib DebugLib DxeServicesTableLib MemoryAllocationLib - MtrrLib UefiBootServicesTableLib UefiDriverEntryPoint - LocalApicLib UefiLib CpuExceptionHandlerLib HobLib @@ -41,7 +41,14 @@ TimerLib PeCoffGetEntryPointLib =20 -[Sources] +[LibraryClasses.IA32, LibraryClasses.X64] + LocalApicLib + MtrrLib + +[LibraryClasses.LoongArch64] + CpuMmuLib + +[Sources.IA32, Sources.X64] CpuDxe.c CpuDxe.h CpuGdt.c @@ -59,6 +66,13 @@ X64/CpuAsm.nasm X64/PagingAttribute.c =20 +[Sources.LoongArch64] + CpuMp.h + LoongArch64/CpuDxe.c + LoongArch64/CpuMp.c + LoongArch64/Exception.c + LoongArch64/CpuDxe.h + [Protocols] gEfiCpuArchProtocolGuid ## PRODUCES gEfiMpServiceProtocolGuid ## PRODUCES @@ -77,6 +91,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuExceptionVectorBaseAddress ##= CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList ##= CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask ##= CONSUMES diff --git a/UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.c b/UefiCpuPkg/CpuDxe/Loo= ngArch64/CpuDxe.c new file mode 100644 index 0000000000..65ed0b3913 --- /dev/null +++ b/UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.c @@ -0,0 +1,454 @@ +/** @file CpuDxe.c + + CPU DXE Module to produce CPU ARCH Protocol. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "CpuDxe.h" +#include "CpuMp.h" +#include +#include +#include +#include + +UINT64 mTimerPeriod =3D 0; + +/** + IPI Interrupt Handler. + + @param InterruptType The type of interrupt that occurred + @param SystemContext A pointer to the system context when the interru= pt occurred +**/ +VOID +EFIAPI +IpiInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_SYSTEM_CONTEXT SystemContext + ); + +// +// Globals used to initialize the protocol +// +EFI_HANDLE mCpuHandle =3D NULL; +EFI_CPU_ARCH_PROTOCOL gCpu =3D { + CpuFlushCpuDataCache, + CpuEnableInterrupt, + CpuDisableInterrupt, + CpuGetInterruptState, + CpuInit, + CpuRegisterInterruptHandler, + CpuGetTimerValue, + CpuSetMemoryAttributes, + 0, // NumberOfTimers + 4, // DmaBufferAlignment +}; + +/** + This function flushes the range of addresses from Start to Start+Length + from the processor's data cache. If Start is not aligned to a cache line + boundary, then the bytes before Start to the preceding cache line bounda= ry + are also flushed. If Start+Length is not aligned to a cache line boundar= y, + then the bytes past Start+Length to the end of the next cache line bound= ary + are also flushed. The FlushType of EfiCpuFlushTypeWriteBackInvalidate mu= st be + supported. If the data cache is fully coherent with all DMA operations, = then + this function can just return EFI_SUCCESS. If the processor does not sup= port + flushing a range of the data cache, then the entire data cache can be fl= ushed. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param Start The beginning physical address to flush from th= e processor's data + cache. + @param Length The number of bytes to flush from the processor= 's data cache. This + function may flush more bytes than Length speci= fies depending upon + the granularity of the flush operation that the= processor supports. + @param FlushType Specifies the type of flush operation to perfor= m. + + @retval EFI_SUCCESS The address range from Start to Start+Leng= th was flushed from + the processor's data cache. + @retval EFI_INVALID_PARAMETER The processor does not support the cache f= lush type specified + by FlushType. + +**/ +EFI_STATUS +EFIAPI +CpuFlushCpuDataCache ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_CPU_FLUSH_TYPE FlushType + ) +{ + switch (FlushType) { + case EfiCpuFlushTypeWriteBack: + WriteBackDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length); + break; + case EfiCpuFlushTypeInvalidate: + InvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length); + break; + case EfiCpuFlushTypeWriteBackInvalidate: + WriteBackInvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Leng= th); + break; + default: + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** + This function enables interrupt processing by the processor. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + + @retval EFI_SUCCESS Interrupts are enabled on the processor. + @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the pro= cessor. + +**/ +EFI_STATUS +EFIAPI +CpuEnableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ) +{ + EnableInterrupts (); + + return EFI_SUCCESS; +} + +/** + This function disables interrupt processing by the processor. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + + @retval EFI_SUCCESS Interrupts are disabled on the processor. + @retval EFI_DEVICE_ERROR Interrupts could not be disabled on the pr= ocessor. + +**/ +EFI_STATUS +EFIAPI +CpuDisableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ) +{ + DisableInterrupts (); + + return EFI_SUCCESS; +} + +/** + This function retrieves the processor's current interrupt state a return= s it in + State. If interrupts are currently enabled, then TRUE is returned. If in= terrupts + are currently disabled, then FALSE is returned. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param State A pointer to the processor's current interrupt = state. Set to TRUE if + interrupts are enabled and FALSE if interrupts = are disabled. + + @retval EFI_SUCCESS The processor's current interrupt state wa= s returned in State. + @retval EFI_INVALID_PARAMETER State is NULL. + +**/ +EFI_STATUS +EFIAPI +CpuGetInterruptState ( + IN EFI_CPU_ARCH_PROTOCOL *This, + OUT BOOLEAN *State + ) +{ + if (State =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + *State =3D GetInterruptState (); + return EFI_SUCCESS; +} + +/** + This function generates an INIT on the processor. If this function succe= eds, then the + processor will be reset, and control will not be returned to the caller.= If InitType is + not supported by this processor, or the processor cannot programmaticall= y generate an + INIT without help from external hardware, then EFI_UNSUPPORTED is return= ed. If an error + occurs attempting to generate an INIT, then EFI_DEVICE_ERROR is returned. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param InitType The type of processor INIT to perform. + + @retval EFI_SUCCESS The processor INIT was performed. This ret= urn code should never be seen. + @retval EFI_UNSUPPORTED The processor INIT operation specified by = InitType is not supported + by this processor. + @retval EFI_DEVICE_ERROR The processor INIT failed. + +**/ +EFI_STATUS +EFIAPI +CpuInit ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_CPU_INIT_TYPE InitType + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Registers a function to be called from the CPU interrupt handler. + + @param This Protocol instance structure + @param InterruptType Defines which interrupt to hook. IA-32 + valid range is 0x00 through 0xFF + @param InterruptHandler A pointer to a function of type + EFI_CPU_INTERRUPT_HANDLER that is called + when a processor interrupt occurs. A null + pointer is an error condition. + + @retval EFI_SUCCESS If handler installed or uninstalled. + @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handl= er + for InterruptType was previously installe= d. + @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler f= or + InterruptType was not previously installe= d. + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType + is not supported. + +**/ +EFI_STATUS +EFIAPI +CpuRegisterInterruptHandler ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ) +{ + return RegisterInterruptHandler (InterruptType, InterruptHandler); +} + +/** + Returns a timer value from one of the CPU's internal timers. There is no + inherent time interval between ticks but is a function of the CPU freque= ncy. + + @param This - Protocol instance structure. + @param TimerIndex - Specifies which CPU timer is requested. + @param TimerValue - Pointer to the returned timer value. + @param TimerPeriod - A pointer to the amount of time that passes + in femtoseconds (10-15) for each increment + of TimerValue. If TimerValue does not + increment at a predictable rate, then 0 is + returned. The amount of time that has + passed between two calls to GetTimerValue() + can be calculated with the formula + (TimerValue2 - TimerValue1) * TimerPeriod. + This parameter is optional and may be NULL. + + @retval EFI_SUCCESS - If the CPU timer count was returned. + @retval EFI_UNSUPPORTED - If the CPU does not have any readable ti= mers. + @retval EFI_DEVICE_ERROR - If an error occurred while reading the t= imer. + @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is= NULL. + +**/ +EFI_STATUS +EFIAPI +CpuGetTimerValue ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN UINT32 TimerIndex, + OUT UINT64 *TimerValue, + OUT UINT64 *TimerPeriod OPTIONAL + ) +{ + UINT64 BeginValue; + UINT64 EndValue; + + if (TimerValue =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (TimerIndex !=3D 0) { + return EFI_INVALID_PARAMETER; + } + + *TimerValue =3D AsmReadStableCounter (); + + if (TimerPeriod !=3D NULL) { + if (mTimerPeriod =3D=3D 0) { + // + // Read time stamp counter before and after delay of 100 microseconds + // + BeginValue =3D AsmReadStableCounter (); + MicroSecondDelay (100); + EndValue =3D AsmReadStableCounter (); + // + // Calculate the actual frequency + // + mTimerPeriod =3D DivU64x64Remainder ( + MultU64x32 ( + 1000 * 1000 * 1000, + 100 + ), + EndValue - BeginValue, + NULL + ); + } + + *TimerPeriod =3D mTimerPeriod; + } + + return EFI_SUCCESS; +} + +/** + This function modifies the attributes for the memory region specified by= BaseAddress and + Length from their current attributes to the attributes specified by Attr= ibutes. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param BaseAddress The physical address that is the start address = of a memory region. + @param Length The size in bytes of the memory region. + @param EfiAttributes The bit mask of attributes to set for the memor= y region. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_ACCESS_DENIED The attributes for the memory resource ran= ge specified by + BaseAddress and Length cannot be modified. + @retval EFI_INVALID_PARAMETER Length is zero. + @retval EFI_OUT_OF_RESOURCES There are not enough system resources to m= odify the attributes of + the memory resource range. + @retval EFI_UNSUPPORTED The processor does not support one or more= bytes of the memory + resource range specified by BaseAddress an= d Length. + The bit mask of attributes is not support = for the memory resource + range specified by BaseAddress and Length. + +**/ +EFI_STATUS +EFIAPI +CpuSetMemoryAttributes ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 EfiAttributes + ) +{ + EFI_STATUS Status; + UINTN LoongArchAttributes; + UINTN RegionBaseAddress; + UINTN RegionLength; + UINTN RegionLoongArchAttributes; + + RegionLength =3D Length; + Status =3D EFI_SUCCESS; + + if ((BaseAddress & (EFI_PAGE_SIZE - 1)) !=3D 0) { + // + // Minimum granularity is SIZE_4KB. + // + DEBUG (( + DEBUG_INFO, + "CpuSetMemoryAttributes(%lx, %lx, %lx): Minimum granularity is SIZE_= 4KB\n", + BaseAddress, + Length, + EfiAttributes + )); + + Status =3D EFI_UNSUPPORTED; + + return Status; + } + + // + // Convert the 'Attribute' into LoongArch Attribute + // + LoongArchAttributes =3D EfiAttributeConverse (EfiAttributes); + + // + // Get the region starting from 'BaseAddress' and its 'Attribute' + // + RegionBaseAddress =3D BaseAddress; + Status =3D GetMemoryRegionAttributes ( + RegionBaseAddress, + &RegionLength, + &RegionLoongArchAttributes + ); + + // + // Data & Instruction Caches are flushed when we set new memory attribut= es. + // So, we only set the attributes if the new region is different. + // + if ((Status =3D=3D EFI_NOT_FOUND) || (RegionLoongArchAttributes !=3D Loo= ngArchAttributes) || + ((BaseAddress + Length) > (RegionBaseAddress + RegionLength))) + { + Status =3D SetMemoryRegionAttributes (BaseAddress, Length, EfiAttribut= es, 0x0); + } + + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** + Callback function for idle events. + + @param Event Event whose notification function is being= invoked. + @param Context The pointer to the notification function's= context, + which is implementation-dependent. + +**/ +VOID +EFIAPI +IdleLoopEventCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + CpuSleep (); +} + +/** + Initialize the state information for the CPU Architectural Protocol. + + @param ImageHandle Image handle this driver. + @param SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS Thread can be successfully created + @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure + @retval EFI_DEVICE_ERROR Cannot create the thread + +**/ +EFI_STATUS +InitializeCpu ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT IdleLoopEvent; + + InitializeExceptions (&gCpu); + + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &mCpuHandle, + &gEfiCpuArchProtocolGuid, + &gCpu, + NULL + ); + ASSERT_EFI_ERROR (Status); + + Status =3D gCpu.RegisterInterruptHandler ( + &gCpu, + EXCEPT_LOONGARCH_INT_IPI, + IpiInterruptHandler + ); + ASSERT_EFI_ERROR (Status); + + // + // Setup a callback for idle events + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + IdleLoopEventCallback, + NULL, + &gIdleLoopEventGuid, + &IdleLoopEvent + ); + ASSERT_EFI_ERROR (Status); + + InitializeMpSupport (); + + return Status; +} diff --git a/UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.h b/UefiCpuPkg/CpuDxe/Loo= ngArch64/CpuDxe.h new file mode 100644 index 0000000000..8bfbfa3442 --- /dev/null +++ b/UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.h @@ -0,0 +1,288 @@ +/** @file CpuDxe.c + + CPU DXE Module to produce CPU ARCH Protocol. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef CPU_DXE_H_ +#define CPU_DXE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +// +// For coding convenience, define the maximum valid +// LoongArch exception. +// Since UEFI V2.11, it will be present in DebugSupport.h. +// +#define MAX_LOONGARCH_EXCEPTION 64 + +/* + This function flushes the range of addresses from Start to Start+Length + from the processor's data cache. If Start is not aligned to a cache line + boundary, then the bytes before Start to the preceding cache line bounda= ry + are also flushed. If Start+Length is not aligned to a cache line boundar= y, + then the bytes past Start+Length to the end of the next cache line bound= ary + are also flushed. The FlushType of EfiCpuFlushTypeWriteBackInvalidate mu= st be + supported. If the data cache is fully coherent with all DMA operations, = then + this function can just return EFI_SUCCESS. If the processor does not sup= port + flushing a range of the data cache, then the entire data cache can be fl= ushed. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param Start The beginning physical address to flush from th= e processor's data + cache. + @param Length The number of bytes to flush from the processor= 's data cache. This + function may flush more bytes than Length speci= fies depending upon + the granularity of the flush operation that the= processor supports. + @param FlushType Specifies the type of flush operation to perfor= m. + + @retval EFI_SUCCESS The address range from Start to Start+Leng= th was flushed from + the processor's data cache. + @retval EFI_UNSUPPORTEDT The processor does not support the cache f= lush type specified + by FlushType. + @retval EFI_DEVICE_ERROR The address range from Start to Start+Leng= th could not be flushed + from the processor's data cache. + +**/ +EFI_STATUS +EFIAPI +CpuFlushCpuDataCache ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_CPU_FLUSH_TYPE FlushType + ); + +/** + This function enables interrupt processing by the processor. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + + @retval EFI_SUCCESS Interrupts are enabled on the processor. + @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the pro= cessor. + +**/ +EFI_STATUS +EFIAPI +CpuEnableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ); + +/** + This function disables interrupt processing by the processor. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + + @retval EFI_SUCCESS Interrupts are disabled on the processor. + @retval EFI_DEVICE_ERROR Interrupts could not be disabled on the pr= ocessor. + +**/ +EFI_STATUS +EFIAPI +CpuDisableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ); + +/** + This function retrieves the processor's current interrupt state a return= s it in + State. If interrupts are currently enabled, then TRUE is returned. If in= terrupts + are currently disabled, then FALSE is returned. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param State A pointer to the processor's current interrupt = state. Set to TRUE if + interrupts are enabled and FALSE if interrupts = are disabled. + + @retval EFI_SUCCESS The processor's current interrupt state wa= s returned in State. + @retval EFI_INVALID_PARAMETER State is NULL. + +**/ +EFI_STATUS +EFIAPI +CpuGetInterruptState ( + IN EFI_CPU_ARCH_PROTOCOL *This, + OUT BOOLEAN *State + ); + +/** + This function generates an INIT on the processor. If this function succe= eds, then the + processor will be reset, and control will not be returned to the caller.= If InitType is + not supported by this processor, or the processor cannot programmaticall= y generate an + INIT without help from external hardware, then EFI_UNSUPPORTED is return= ed. If an error + occurs attempting to generate an INIT, then EFI_DEVICE_ERROR is returned. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param InitType The type of processor INIT to perform. + + @retval EFI_SUCCESS The processor INIT was performed. This ret= urn code should never be seen. + @retval EFI_UNSUPPORTED The processor INIT operation specified by = InitType is not supported + by this processor. + @retval EFI_DEVICE_ERROR The processor INIT failed. + +**/ +EFI_STATUS +EFIAPI +CpuInit ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_CPU_INIT_TYPE InitType + ); + +/** + Registers a function to be called from the CPU interrupt handler. + + @param This Protocol instance structure + @param InterruptType Defines which interrupt to hook. IA-32 + valid range is 0x00 through 0xFF + @param InterruptHandler A pointer to a function of type + EFI_CPU_INTERRUPT_HANDLER that is called + when a processor interrupt occurs. A null + pointer is an error condition. + + @retval EFI_SUCCESS If handler installed or uninstalled. + @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handl= er + for InterruptType was previously installe= d. + @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler f= or + InterruptType was not previously installe= d. + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType + is not supported. + +**/ +EFI_STATUS +EFIAPI +CpuRegisterInterruptHandler ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ); + +/** + Returns a timer value from one of the CPU's internal timers. There is no + inherent time interval between ticks but is a function of the CPU freque= ncy. + + @param This - Protocol instance structure. + @param TimerIndex - Specifies which CPU timer is requested. + @param TimerValue - Pointer to the returned timer value. + @param TimerPeriod - A pointer to the amount of time that passes + in femtoseconds (10-15) for each increment + of TimerValue. If TimerValue does not + increment at a predictable rate, then 0 is + returned. The amount of time that has + passed between two calls to GetTimerValue() + can be calculated with the formula + (TimerValue2 - TimerValue1) * TimerPeriod. + This parameter is optional and may be NULL. + + @retval EFI_SUCCESS - If the CPU timer count was returned. + @retval EFI_UNSUPPORTED - If the CPU does not have any readable ti= mers. + @retval EFI_DEVICE_ERROR - If an error occurred while reading the t= imer. + @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is= NULL. + +**/ +EFI_STATUS +EFIAPI +CpuGetTimerValue ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN UINT32 TimerIndex, + OUT UINT64 *TimerValue, + OUT UINT64 *TimerPeriod OPTIONAL + ); + +/** + This function registers and enables the handler specified by InterruptHa= ndler for a processor + interrupt or exception type specified by InterruptType. If InterruptHand= ler is NULL, then the + handler for the processor interrupt or exception type specified by Inter= ruptType is uninstalled. + The installed handler is called once for each processor interrupt or exc= eption. + + @param InterruptType A pointer to the processor's current interrupt = state. Set to TRUE if interrupts + are enabled and FALSE if interrupts are disable= d. + @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRU= PT_HANDLER that is called + when a processor interrupt occurs. If this para= meter is NULL, then the handler + will be uninstalled. + + @retval EFI_SUCCESS The handler for the processor interrupt wa= s successfully installed or uninstalled. + @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handle= r for InterruptType was + previously installed. + @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler fo= r InterruptType was not + previously installed. + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType i= s not supported. + +**/ +EFI_STATUS +RegisterInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ); + +/** + This function modifies the attributes for the memory region specified by= BaseAddress and + Length from their current attributes to the attributes specified by Attr= ibutes. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param BaseAddress The physical address that is the start address = of a memory region. + @param Length The size in bytes of the memory region. + @param Attributes The bit mask of attributes to set for the memor= y region. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_ACCESS_DENIED The attributes for the memory resource ran= ge specified by + BaseAddress and Length cannot be modified. + @retval EFI_INVALID_PARAMETER Length is zero. + @retval EFI_OUT_OF_RESOURCES There are not enough system resources to m= odify the attributes of + the memory resource range. + @retval EFI_UNSUPPORTED The processor does not support one or more= bytes of the memory + resource range specified by BaseAddress an= d Length. + The bit mask of attributes is not support = for the memory resource + range specified by BaseAddress and Length. + +**/ +EFI_STATUS +EFIAPI +CpuSetMemoryAttributes ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ); + +/** + Initialize interrupt handling for DXE phase. + + @param Cpu A pointer of EFI_CPU_ARCH_PROTOCOL instance. + + @return VOID. + +**/ +VOID +InitializeExceptions ( + IN EFI_CPU_ARCH_PROTOCOL *gCpu + ); + +/** + Converts EFI Attributes to corresponding architecture Attributes. + + @param[in] EfiAttributes Efi Attributes. + + @retval Corresponding architecture attributes. +**/ +UINTN +EFIAPI +EfiAttributeConverse ( + IN UINTN EfiAttributes + ); + +#endif // CPU_DXE_H_ diff --git a/UefiCpuPkg/CpuDxe/LoongArch64/CpuMp.c b/UefiCpuPkg/CpuDxe/Loon= gArch64/CpuMp.c new file mode 100644 index 0000000000..3325914e53 --- /dev/null +++ b/UefiCpuPkg/CpuDxe/LoongArch64/CpuMp.c @@ -0,0 +1,544 @@ +/** @file + CPU DXE Module to produce CPU MP Protocol. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "CpuDxe.h" +#include "CpuMp.h" + +EFI_HANDLE mMpServiceHandle =3D NULL; +UINTN mNumberOfProcessors =3D 1; + +EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate =3D { + GetNumberOfProcessors, + GetProcessorInfo, + StartupAllAPs, + StartupThisAP, + SwitchBSP, + EnableDisableAP, + WhoAmI +}; + +/** + This service retrieves the number of logical processor in the platform + and the number of those logical processors that are enabled on this boot. + This service may only be called from the BSP. + + This function is used to retrieve the following information: + - The number of logical processors that are present in the system. + - The number of enabled logical processors in the system at the instant + this call is made. + + Because MP Service Protocol provides services to enable and disable proc= essors + dynamically, the number of enabled logical processors may vary during the + course of a boot session. + + If this service is called from an AP, then EFI_DEVICE_ERROR is returned. + If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then + EFI_INVALID_PARAMETER is returned. Otherwise, the total number of proces= sors + is returned in NumberOfProcessors, the number of currently enabled proce= ssor + is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned. + + @param[in] This A pointer to the EFI_MP_SERVICES= _PROTOCOL + instance. + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. + + @retval EFI_SUCCESS The number of logical processors and ena= bled + logical processors was retrieved. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL. + @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL. + +**/ +EFI_STATUS +EFIAPI +GetNumberOfProcessors ( + IN EFI_MP_SERVICES_PROTOCOL *This, + OUT UINTN *NumberOfProcessors, + OUT UINTN *NumberOfEnabledProcessors + ) +{ + if ((NumberOfProcessors =3D=3D NULL) || (NumberOfEnabledProcessors =3D= =3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + return MpInitLibGetNumberOfProcessors ( + NumberOfProcessors, + NumberOfEnabledProcessors + ); +} + +/** + Gets detailed MP-related information on the requested processor at the + instant this call is made. This service may only be called from the BSP. + + This service retrieves detailed MP-related information about any process= or + on the platform. Note the following: + - The processor information may change during the course of a boot ses= sion. + - The information presented here is entirely MP related. + + Information regarding the number of caches and their sizes, frequency of= operation, + slot numbers is all considered platform-related information and is not p= rovided + by this service. + + @param[in] This A pointer to the EFI_MP_SERVICES_PROTO= COL + instance. + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + + @retval EFI_SUCCESS Processor information was returned. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist in the pl= atform. + +**/ +EFI_STATUS +EFIAPI +GetProcessorInfo ( + IN EFI_MP_SERVICES_PROTOCOL *This, + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer + ) +{ + return MpInitLibGetProcessorInfo (ProcessorNumber, ProcessorInfoBuffer, = NULL); +} + +/** + This service executes a caller provided function on all enabled APs. APs= can + run either simultaneously or one at a time in sequence. This service sup= ports + both blocking and non-blocking requests. The non-blocking requests use E= FI + events so the BSP can detect when the APs have finished. This service ma= y only + be called from the BSP. + + This function is used to dispatch all the enabled APs to the function sp= ecified + by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned + immediately and Procedure is not started on any AP. + + If SingleThread is TRUE, all the enabled APs execute the function specif= ied by + Procedure one by one, in ascending order of processor handle number. Oth= erwise, + all the enabled APs execute the function specified by Procedure simultan= eously. + + If WaitEvent is NULL, execution is in blocking mode. The BSP waits until= all + APs finish or TimeoutInMicroseconds expires. Otherwise, execution is in = non-blocking + mode, and the BSP returns from this service without waiting for APs. If a + non-blocking mode is requested after the UEFI Event EFI_EVENT_GROUP_READ= Y_TO_BOOT + is signaled, then EFI_UNSUPPORTED must be returned. + + If the timeout specified by TimeoutInMicroseconds expires before all APs= return + from Procedure, then Procedure on the failed APs is terminated. All enab= led APs + are always available for further calls to EFI_MP_SERVICES_PROTOCOL.Start= upAllAPs() + and EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). If FailedCpuList is not NU= LL, its + content points to the list of processor handle numbers in which Procedur= e was + terminated. + + Note: It is the responsibility of the consumer of the EFI_MP_SERVICES_PR= OTOCOL.StartupAllAPs() + to make sure that the nature of the code that is executed on the BSP and= the + dispatched APs is well controlled. The MP Services Protocol does not gua= rantee + that the Procedure function is MP-safe. Hence, the tasks that can be run= in + parallel are limited to certain independent tasks and well-controlled ex= clusive + code. EFI services and protocols may not be called by APs unless otherwi= se + specified. + + In blocking execution mode, BSP waits until all APs finish or + TimeoutInMicroseconds expires. + + In non-blocking execution mode, BSP is freed to return to the caller and= then + proceed to the next task without having to wait for APs. The following + sequence needs to occur in a non-blocking execution mode: + + -# The caller that intends to use this MP Services Protocol in non-blo= cking + mode creates WaitEvent by calling the EFI CreateEvent() service. T= he caller + invokes EFI_MP_SERVICES_PROTOCOL.StartupAllAPs(). If the parameter = WaitEvent + is not NULL, then StartupAllAPs() executes in non-blocking mode. It= requests + the function specified by Procedure to be started on all the enable= d APs, + and releases the BSP to continue with other tasks. + -# The caller can use the CheckEvent() and WaitForEvent() services to = check + the state of the WaitEvent created in step 1. + -# When the APs complete their task or TimeoutInMicroSecondss expires,= the MP + Service signals WaitEvent by calling the EFI SignalEvent() function= . If + FailedCpuList is not NULL, its content is available when WaitEvent = is + signaled. If all APs returned from Procedure prior to the timeout, = then + FailedCpuList is set to NULL. If not all APs return from Procedure = before + the timeout, then FailedCpuList is filled in with the list of the f= ailed + APs. The buffer is allocated by MP Service Protocol using AllocateP= ool(). + It is the caller's responsibility to free the buffer with FreePool(= ) service. + -# This invocation of SignalEvent() function informs the caller that i= nvoked + EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() that either all the APs co= mpleted + the specified task or a timeout occurred. The contents of FailedCpu= List + can be examined to determine which APs did not complete the specifi= ed task + prior to the timeout. + + @param[in] This A pointer to the EFI_MP_SERVICES_PRO= TOCOL + instance. + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. See type + EFI_AP_PROCEDURE. + @param[in] SingleThread If TRUE, then all the enabled APs ex= ecute + the function specified by Procedure = one by + one, in ascending order of processor= handle + number. If FALSE, then all the enab= led APs + execute the function specified by Pr= ocedure + simultaneously. + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. If it is NULL, then execut= e in + blocking mode. BSP waits until all A= Ps finish + or TimeoutInMicroseconds expires. I= f it's + not NULL, then execute in non-blocki= ng mode. + BSP requests the function specified = by + Procedure to be started on all the e= nabled + APs, and go on executing immediately= . If + all return from Procedure, or Timeou= tInMicroseconds + expires, this event is signaled. The= BSP + can use the CheckEvent() or WaitForE= vent() + services to check the state of event= . Type + EFI_EVENT is defined in CreateEvent(= ) in + the Unified Extensible Firmware Inte= rface + Specification. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + APs to return from Procedure, either= for + blocking or non-blocking mode. Zero = means + infinity. If the timeout expires be= fore + all APs return from Procedure, then = Procedure + on the failed APs is terminated. All= enabled + APs are available for next function = assigned + by EFI_MP_SERVICES_PROTOCOL.StartupA= llAPs() + or EFI_MP_SERVICES_PROTOCOL.StartupT= hisAP(). + If the timeout expires in blocking m= ode, + BSP returns EFI_TIMEOUT. If the tim= eout + expires in non-blocking mode, WaitEv= ent + is signaled with SignalEvent(). + @param[in] ProcedureArgument The parameter passed into Procedure = for + all APs. + @param[out] FailedCpuList If NULL, this parameter is ignored. = Otherwise, + if all APs finish successfully, then= its + content is set to NULL. If not all A= Ps + finish before timeout expires, then = its + content is set to address of the buf= fer + holding handle numbers of the failed= APs. + The buffer is allocated by MP Servic= e Protocol, + and it's the caller's responsibility= to + free the buffer with FreePool() serv= ice. + In blocking mode, it is ready for co= nsumption + when the call returns. In non-blocki= ng mode, + it is ready when WaitEvent is signal= ed. The + list of failed CPU is terminated by + END_OF_CPU_LIST. + + @retval EFI_SUCCESS In blocking mode, all APs have finished = before + the timeout expired. + @retval EFI_SUCCESS In non-blocking mode, function has been = dispatched + to all enabled APs. + @retval EFI_UNSUPPORTED A non-blocking mode request was made aft= er the + UEFI event EFI_EVENT_GROUP_READY_TO_BOOT= was + signaled. + @retval EFI_DEVICE_ERROR Caller processor is AP. + @retval EFI_NOT_STARTED No enabled APs exist in the system. + @retval EFI_NOT_READY Any enabled APs are busy. + @retval EFI_TIMEOUT In blocking mode, the timeout expired be= fore + all enabled APs have finished. + @retval EFI_INVALID_PARAMETER Procedure is NULL. + +**/ +EFI_STATUS +EFIAPI +StartupAllAPs ( + IN EFI_MP_SERVICES_PROTOCOL *This, + IN EFI_AP_PROCEDURE Procedure, + IN BOOLEAN SingleThread, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT UINTN **FailedCpuList OPTIONAL + ) +{ + return MpInitLibStartupAllAPs ( + Procedure, + SingleThread, + WaitEvent, + TimeoutInMicroseconds, + ProcedureArgument, + FailedCpuList + ); +} + +/** + This service lets the caller get one enabled AP to execute a caller-prov= ided + function. The caller can request the BSP to either wait for the completi= on + of the AP or just proceed with the next task by using the EFI event mech= anism. + See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blo= cking + execution support. This service may only be called from the BSP. + + This function is used to dispatch one enabled AP to the function specifi= ed by + Procedure passing in the argument specified by ProcedureArgument. If Wa= itEvent + is NULL, execution is in blocking mode. The BSP waits until the AP finis= hes or + TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking = mode. + BSP proceeds to the next task without waiting for the AP. If a non-block= ing mode + is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signa= led, + then EFI_UNSUPPORTED must be returned. + + If the timeout specified by TimeoutInMicroseconds expires before the AP = returns + from Procedure, then execution of Procedure by the AP is terminated. The= AP is + available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs= () and + EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). + + @param[in] This A pointer to the EFI_MP_SERVICES_PRO= TOCOL + instance. + @param[in] Procedure A pointer to the function to be run = on the + designated AP of the system. See type + EFI_AP_PROCEDURE. + @param[in] ProcessorNumber The handle number of the AP. The ran= ge is + from 0 to the total number of logical + processors minus 1. The total number= of + logical processors can be retrieved = by + EFI_MP_SERVICES_PROTOCOL.GetNumberOf= Processors(). + @param[in] WaitEvent The event created by the caller with= CreateEvent() + service. If it is NULL, then execut= e in + blocking mode. BSP waits until this = AP finish + or TimeoutInMicroSeconds expires. I= f it's + not NULL, then execute in non-blocki= ng mode. + BSP requests the function specified = by + Procedure to be started on this AP, + and go on executing immediately. If = this AP + return from Procedure or TimeoutInMi= croSeconds + expires, this event is signaled. The= BSP + can use the CheckEvent() or WaitForE= vent() + services to check the state of event= . Type + EFI_EVENT is defined in CreateEvent(= ) in + the Unified Extensible Firmware Inte= rface + Specification. + @param[in] TimeoutInMicroseconds Indicates the time limit in microsec= onds for + this AP to finish this Procedure, ei= ther for + blocking or non-blocking mode. Zero = means + infinity. If the timeout expires be= fore + this AP returns from Procedure, then= Procedure + on the AP is terminated. The + AP is available for next function as= signed + by EFI_MP_SERVICES_PROTOCOL.StartupA= llAPs() + or EFI_MP_SERVICES_PROTOCOL.StartupT= hisAP(). + If the timeout expires in blocking m= ode, + BSP returns EFI_TIMEOUT. If the tim= eout + expires in non-blocking mode, WaitEv= ent + is signaled with SignalEvent(). + @param[in] ProcedureArgument The parameter passed into Procedure = on the + specified AP. + @param[out] Finished If NULL, this parameter is ignored. = In + blocking mode, this parameter is ign= ored. + In non-blocking mode, if AP returns = from + Procedure before the timeout expires= , its + content is set to TRUE. Otherwise, t= he + value is set to FALSE. The caller can + determine if the AP returned from Pr= ocedure + by evaluating this value. + + @retval EFI_SUCCESS In blocking mode, specified AP finished = before + the timeout expires. + @retval EFI_SUCCESS In non-blocking mode, the function has b= een + dispatched to specified AP. + @retval EFI_UNSUPPORTED A non-blocking mode request was made aft= er the + UEFI event EFI_EVENT_GROUP_READY_TO_BOOT= was + signaled. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_TIMEOUT In blocking mode, the timeout expired be= fore + the specified AP has finished. + @retval EFI_NOT_READY The specified AP is busy. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist. + @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or dis= abled AP. + @retval EFI_INVALID_PARAMETER Procedure is NULL. + +**/ +EFI_STATUS +EFIAPI +StartupThisAP ( + IN EFI_MP_SERVICES_PROTOCOL *This, + IN EFI_AP_PROCEDURE Procedure, + IN UINTN ProcessorNumber, + IN EFI_EVENT WaitEvent OPTIONAL, + IN UINTN TimeoutInMicroseconds, + IN VOID *ProcedureArgument OPTIONAL, + OUT BOOLEAN *Finished OPTIONAL + ) +{ + return MpInitLibStartupThisAP ( + Procedure, + ProcessorNumber, + WaitEvent, + TimeoutInMicroseconds, + ProcedureArgument, + Finished + ); +} + +/** + This service switches the requested AP to be the BSP from that point onw= ard. + This service changes the BSP for all purposes. This call can only be p= erformed + by the current BSP. + + This service switches the requested AP to be the BSP from that point onw= ard. + This service changes the BSP for all purposes. The new BSP can take over= the + execution of the old BSP and continue seamlessly from where the old one = left + off. This service may not be supported after the UEFI Event EFI_EVENT_GR= OUP_READY_TO_BOOT + is signaled. + + If the BSP cannot be switched prior to the return from this service, then + EFI_UNSUPPORTED must be returned. + + @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL i= nstance. + @param[in] ProcessorNumber The handle number of AP that is to become t= he new + BSP. The range is from 0 to the total numbe= r of + logical processors minus 1. The total numbe= r of + logical processors can be retrieved by + EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcess= ors(). + @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as= an + enabled AP. Otherwise, it will be disabled. + + @retval EFI_SUCCESS BSP successfully switched. + @retval EFI_UNSUPPORTED Switching the BSP cannot be completed pr= ior to + this service returning. + @retval EFI_UNSUPPORTED Switching the BSP is not supported. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist. + @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BS= P or + a disabled AP. + @retval EFI_NOT_READY The specified AP is busy. + +**/ +EFI_STATUS +EFIAPI +SwitchBSP ( + IN EFI_MP_SERVICES_PROTOCOL *This, + IN UINTN ProcessorNumber, + IN BOOLEAN EnableOldBSP + ) +{ + return MpInitLibSwitchBSP (ProcessorNumber, EnableOldBSP); +} + +/** + This service lets the caller enable or disable an AP from this point onw= ard. + This service may only be called from the BSP. + + This service allows the caller enable or disable an AP from this point o= nward. + The caller can optionally specify the health status of the AP by Health.= If + an AP is being disabled, then the state of the disabled AP is implementa= tion + dependent. If an AP is enabled, then the implementation must guarantee t= hat a + complete initialization sequence is performed on the AP, so the AP is in= a state + that is compatible with an MP operating system. This service may not be = supported + after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled. + + If the enable or disable AP operation cannot be completed prior to the r= eturn + from this service, then EFI_UNSUPPORTED must be returned. + + @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL i= nstance. + @param[in] ProcessorNumber The handle number of AP. + The range is from 0 to the total number of + logical processors minus 1. The total numbe= r of + logical processors can be retrieved by + EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcess= ors(). + @param[in] EnableAP Specifies the new state for the processor f= or + enabled, FALSE for disabled. + @param[in] HealthFlag If not NULL, a pointer to a value that spec= ifies + the new health status of the AP. This flag + corresponds to StatusFlag defined in + EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo()= . Only + the PROCESSOR_HEALTH_STATUS_BIT is used. Al= l other + bits are ignored. If it is NULL, this para= meter + is ignored. + + @retval EFI_SUCCESS The specified AP was enabled or disabled= successfully. + @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be co= mpleted + prior to this service returning. + @retval EFI_UNSUPPORTED Enabling or disabling an AP is not suppo= rted. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_NOT_FOUND Processor with the handle specified by P= rocessorNumber + does not exist. + @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP. + +**/ +EFI_STATUS +EFIAPI +EnableDisableAP ( + IN EFI_MP_SERVICES_PROTOCOL *This, + IN UINTN ProcessorNumber, + IN BOOLEAN EnableAP, + IN UINT32 *HealthFlag OPTIONAL + ) +{ + return MpInitLibEnableDisableAP (ProcessorNumber, EnableAP, HealthFlag); +} + +/** + This return the handle number for the calling processor. This service m= ay be + called from the BSP and APs. + + This service returns the processor handle number for the calling process= or. + The returned value is in the range from 0 to the total number of logical + processors minus 1. The total number of logical processors can be retrie= ved + with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may = be + called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALI= D_PARAMETER + is returned. Otherwise, the current processors handle number is returned= in + ProcessorNumber, and EFI_SUCCESS is returned. + + @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL i= nstance. + @param[out] ProcessorNumber Pointer to the handle number of AP. + The range is from 0 to the total number of + logical processors minus 1. The total numbe= r of + logical processors can be retrieved by + EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcess= ors(). + + @retval EFI_SUCCESS The current processor handle number was = returned + in ProcessorNumber. + @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL. + +**/ +EFI_STATUS +EFIAPI +WhoAmI ( + IN EFI_MP_SERVICES_PROTOCOL *This, + OUT UINTN *ProcessorNumber + ) +{ + return MpInitLibWhoAmI (ProcessorNumber); +} + +/** + Initialize Multi-processor support. +**/ +VOID +InitializeMpSupport ( + VOID + ) +{ + EFI_STATUS Status; + UINTN NumberOfProcessors; + UINTN NumberOfEnabledProcessors; + + // + // Wakeup APs to do initialization + // + Status =3D MpInitLibInitialize (); + ASSERT_EFI_ERROR (Status); + + MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledPro= cessors); + mNumberOfProcessors =3D NumberOfProcessors; + DEBUG ((DEBUG_INFO, "Detect CPU count: %d\n", mNumberOfProcessors)); + + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &mMpServiceHandle, + &gEfiMpServiceProtocolGuid, + &mMpServicesTemplate, + NULL + ); + ASSERT_EFI_ERROR (Status); +} diff --git a/UefiCpuPkg/CpuDxe/LoongArch64/Exception.c b/UefiCpuPkg/CpuDxe/= LoongArch64/Exception.c new file mode 100644 index 0000000000..96def89936 --- /dev/null +++ b/UefiCpuPkg/CpuDxe/LoongArch64/Exception.c @@ -0,0 +1,159 @@ +/** @file Exception.c + + CPU DXE Module initialization exception instance. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "CpuDxe.h" +#include +#include +#include + +VOID +ExceptionEntryStart ( + VOID + ); + +VOID +ExceptionEntryEnd ( + VOID + ); + +/** + This function registers and enables the handler specified by InterruptHa= ndler for a processor + interrupt or exception type specified by InterruptType. If InterruptHand= ler is NULL, then the + handler for the processor interrupt or exception type specified by Inter= ruptType is uninstalled. + The installed handler is called once for each processor interrupt or exc= eption. + + @param InterruptType A pointer to the processor's current interrupt = state. Set to TRUE if interrupts + are enabled and FALSE if interrupts are disable= d. + @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRU= PT_HANDLER that is called + when a processor interrupt occurs. If this para= meter is NULL, then the handler + will be uninstalled. + + @retval EFI_SUCCESS The handler for the processor interrupt wa= s successfully installed or uninstalled. + @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handle= r for InterruptType was + previously installed. + @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler fo= r InterruptType was not + previously installed. + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType i= s not supported. + +**/ +EFI_STATUS +RegisterInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ) +{ + return (EFI_STATUS)RegisterCpuInterruptHandler (InterruptType, Interrupt= Handler); +} + +/** + Update the exception start entry code. + + @retval EFI_SUCCESS Update the exception start entry code down. + @retval EFI_OUT_OF_RESOURCES The start entry code size out of bounds. + +**/ +EFI_STATUS +EFIAPI +UpdateExceptionStartEntry ( + VOID + ) +{ + EFI_PHYSICAL_ADDRESS ExceptionStartEntry; + UINTN VectorLength; + UINTN MaxLength; + UINTN MaxSizeOfVector; + + VectorLength =3D (UINTN)ExceptionEntryEnd - (UINTN)ExceptionEntryStart; + + // + // A vector is up to 512 bytes. + // + MaxSizeOfVector =3D 512; + MaxLength =3D (MAX_LOONGARCH_EXCEPTION + MAX_LOONGARCH_INTERRUPT) = * MaxSizeOfVector; + + if (VectorLength > MaxLength) { + return EFI_OUT_OF_RESOURCES; + } + + ExceptionStartEntry =3D PcdGet64 (PcdCpuExceptionVectorBaseAddress); + + InvalidateInstructionCacheRange ((VOID *)ExceptionStartEntry, VectorLeng= th); + CopyMem ((VOID *)ExceptionStartEntry, (VOID *)ExceptionEntryStart, Vecto= rLength); + InvalidateInstructionCacheRange ((VOID *)ExceptionStartEntry, VectorLeng= th); + InvalidateDataCache (); + + // + // If PcdCpuExceptionVectorBaseAddress is not used during SEC and PEI st= ages, the exception + // base addres is set to PcdCpuExceptionVectorBaseAddress. + // + if (CsrRead (LOONGARCH_CSR_EBASE) !=3D ExceptionStartEntry) { + SetExceptionBaseAddress (ExceptionStartEntry); + } + + return EFI_SUCCESS; +} + +/** + Initialize interrupt handling for DXE phase. + + @param Cpu A pointer of EFI_CPU_ARCH_PROTOCOL instance. + + @return VOID. + +**/ +VOID +InitializeExceptions ( + IN EFI_CPU_ARCH_PROTOCOL *Cpu + ) +{ + EFI_STATUS Status; + EFI_VECTOR_HANDOFF_INFO *VectorInfoList; + EFI_VECTOR_HANDOFF_INFO *VectorInfo; + BOOLEAN IrqEnabled; + + VectorInfo =3D (EFI_VECTOR_HANDOFF_INFO *)NULL; + Status =3D EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGu= id, (VOID **)&VectorInfoList); + + if ((Status =3D=3D EFI_SUCCESS) && (VectorInfoList !=3D NULL)) { + VectorInfo =3D VectorInfoList; + } + + // + // Disable interrupts + // + Cpu->GetInterruptState (Cpu, &IrqEnabled); + if (IrqEnabled) { + Cpu->DisableInterrupt (Cpu); + } + + // + // Update the Exception Start Entry code to point into CpuDxe. + // + Status =3D UpdateExceptionStartEntry (); + if (EFI_ERROR (Status)) { + DebugPrint (EFI_D_ERROR, "[%a]: Exception start entry code out of boun= ds!\n", __func__); + ASSERT_EFI_ERROR (Status); + } + + // + // Intialize the CpuExceptionHandlerLib so we take over the exception ve= ctor table from the DXE Core + // + Status =3D InitializeCpuExceptionHandlers (VectorInfo); + ASSERT_EFI_ERROR (Status); + + // + // Enable interrupts + // + DebugPrint (EFI_D_INFO, "InitializeExceptions,IrqEnabled =3D %x\n", IrqE= nabled); + if (!IrqEnabled) { + Status =3D Cpu->EnableInterrupt (Cpu); + } + + ASSERT_EFI_ERROR (Status); +} --=20 2.27.0 -=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 (#114542): https://edk2.groups.io/g/devel/message/114542 Mute This Topic: https://groups.io/mt/103971655/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- From nobody Thu Dec 26 20:24:45 2024 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+114543+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+114543+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250585; cv=none; d=zohomail.com; s=zohoarc; b=JEFEw7r3oYQGvVpxKHgAt0AO5y/02F7Diw3JVLLfH6i+ljdqd6/olhyuLUvkOuthliiEAZGSr5grbHhQgKH4kZ+L53H1H+JNnGMrEtPgg0XIbwnrTjYAdo68zeFd4/6n67rAWf2B+bLMnrj42J+VRL28bVztIl9oxMHLSbtDUFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250585; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=LJYJsDzBedGO0LfcM5z19dgNIiWIzy+Mj1UZ8k8TRQg=; b=Lq4TLJPi7xvLzcfuA4WNNX7GIPXxtOVe8x6l7+QbUBGJ+1b0spI571LSq7Rq3zFelUQfg4fLyA4wuROg9EsdEpZGB+5ZchiGxAeKrf/cb6uabk/rUCt0EF3ipNBtr6L853Jr61I/jK6STpo1r1t09y5UWTW/eMzX8twwjQK/Rls= 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+114543+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250585059891.7712736775536; Thu, 25 Jan 2024 22:29:45 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=GIBzJ4CZQs6iwa+hacYA+3aipc2uGqW+hk8HYJMx+24=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250584; v=1; b=kxqFfuB/BW0LH/iRRBOus6nEAuOk3e7u8jEmm6X4kWinZfHml7cZKkpFaEtvv8uYR0qD1BPz nyQ5bqYVZZL1doyRmIfJrA8te08g8WibwtxsgCF2IyMHrOxM5X9mvnWUtfLr4U6mP22R6I4856x 5QRAo+FKGCbs28MGh1Fzq4Y8= X-Received: by 127.0.0.2 with SMTP id tGshYY1788612xEchtzqXNf2; Thu, 25 Jan 2024 22:29:44 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10006.1706250582870608579 for ; Thu, 25 Jan 2024 22:29:44 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8BxTOlUUbNlPh4GAA--.11593S3; Fri, 26 Jan 2024 14:29:40 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxf89TUbNlpXIbAA--.53073S2; Fri, 26 Jan 2024 14:29:39 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Abner Chang , Daniel Schaefer Subject: [edk2-devel] [PATCH v8 17/37] EmbeddedPkg: Add PcdPrePiCpuIoSize width for LOONGARCH64 Date: Fri, 26 Jan 2024 14:29:38 +0800 Message-Id: <20240126062938.3101886-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxf89TUbNlpXIbAA--.53073S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBRsO X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 2GpKgH7syX0q0Ey0395YHMAqx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250586306100009 Content-Type: text/plain; charset="utf-8" Added LoongArch64 architecture CPU IO width. https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Abner Chang Cc: Daniel Schaefer Signed-off-by: Chao Li Reviewed-by: Leif Lindholm --- EmbeddedPkg/EmbeddedPkg.dec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec index b4834e8b4f..5dfbbc2933 100644 --- a/EmbeddedPkg/EmbeddedPkg.dec +++ b/EmbeddedPkg/EmbeddedPkg.dec @@ -166,6 +166,9 @@ [PcdsFixedAtBuild.X64] gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16|UINT8|0x00000011 =20 +[PcdsFixedAtBuild.LOONGARCH64] + gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16|UINT8|0x00000011 + [PcdsFixedAtBuild.common, PcdsDynamic.common] # # Value to add to a host address to obtain a device address, using --=20 2.27.0 -=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 (#114543): https://edk2.groups.io/g/devel/message/114543 Mute This Topic: https://groups.io/mt/103971656/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- From nobody Thu Dec 26 20:24:45 2024 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+114544+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+114544+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250592; cv=none; d=zohomail.com; s=zohoarc; b=Y6KwW+W1PPXOQfSEsjGuL1lYKBYMJh/YYMKvSBScgzFpq1chR6p5h8jMZ04L2nLnAwcvyCfWg+ycsUh5D/u2cq36sa+X/2fpSjgWTxija4p8Tjub6Ulw7hXe+FtPMoktEmOrdsyGT83N5ThSpKN4FweRS5qlZwxAITP0r8kX00E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250592; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=hOWpi+ukNnC+d9rHF+nDLRJcTh9dmvhxS9kNTdV9Ufk=; b=F5JlAxp9tKq3z0cfyL8O7hfK/51uP5L6pnUP/pyxGmg5Sy+4CrOezjIqt1ubl+Htv18x7sJDC3zZ55JcpZetveKvWkVCp/L43qc/lzsd+2ZX2xv1p4aR6q4g7xeAOUphoFWpJKh1UwarmutQJ2L20D6w935txkpSlvFRCCozeXc= 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+114544+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250592036784.7192074789264; Thu, 25 Jan 2024 22:29:52 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=O8mJrHVxvLXpvjHtaBM64faVYiMF4/ewazF7b/JRdcM=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250591; v=1; b=hjbm7VdiA3kDDRdfvKjBUqAV2UteW62vzFH1DShZJzeISoIopFUAHlbs9sZPx+znNQojkq8v DJjuL8SiZAcPbAn2gfP96FlzIilmrXVs2oYocTC3WcLRgxnq6KnGQ9g5YkxIWy4LDmknR9wwv0O ENZqUfEqL90l5zjHSWpaHkm8= X-Received: by 127.0.0.2 with SMTP id PS4aYY1788612xR8vJN0HFqI; Thu, 25 Jan 2024 22:29:51 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10007.1706250589634290285 for ; Thu, 25 Jan 2024 22:29:51 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxLOtZUbNlRh4GAA--.11413S3; Fri, 26 Jan 2024 14:29:45 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxDc9XUbNltnIbAA--.53281S2; Fri, 26 Jan 2024 14:29:43 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Leif Lindholm , Sami Mujawar , Gerd Hoffmann , Jiewen Yao , Jordan Justen Subject: [edk2-devel] [PATCH v8 18/37] ArmVirtPkg: Move PCD of FDT base address and FDT padding to OvmfPkg Date: Fri, 26 Jan 2024 14:29:43 +0800 Message-Id: <20240126062943.3101946-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxDc9XUbNltnIbAA--.53281S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBTsM X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: zyT3KTDNkS3cBUmDnKojPOiBx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250592398100005 Content-Type: text/plain; charset="utf-8" Moved PcdDeviceTreeInitialBaseAddress and PcdDeviceTreeAllocationPadding to OvmfPkg for easier use by other architectures. Build-tested only (with "ArmVirtQemu.dsc"). BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Cc: Jiewen Yao Cc: Jordan Justen Signed-off-by: Chao Li Acked-by: Gerd Hoffmann Reviewed-by: Sami Mujawar --- ArmVirtPkg/ArmVirtCloudHv.dsc | 2 +- ArmVirtPkg/ArmVirtKvmTool.dsc | 2 +- ArmVirtPkg/ArmVirtPkg.dec | 14 -------------- ArmVirtPkg/ArmVirtQemu.dsc | 2 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +- ArmVirtPkg/ArmVirtXen.dsc | 2 +- .../ArmVirtPsciResetSystemPeiLib.inf | 3 ++- .../CloudHvVirtMemInfoPeiLib.inf | 3 ++- .../DebugLibFdtPL011UartFlash.inf | 3 ++- .../EarlyFdt16550SerialPortHookLib.inf | 3 ++- .../EarlyFdtPL011SerialPortLib.inf | 3 ++- .../KvmtoolPlatformPeiLib.inf | 5 +++-- .../Library/PlatformPeiLib/PlatformPeiLib.inf | 10 +++++----- .../QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf | 3 ++- .../PrePi/ArmVirtPrePiUniCoreRelocatable.inf | 3 ++- OvmfPkg/OvmfPkg.dec | 15 +++++++++++++++ 16 files changed, 42 insertions(+), 33 deletions(-) diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index 2cb89ce10c..76c0d28544 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -129,7 +129,7 @@ gArmTokenSpaceGuid.PcdSystemMemoryBase|0x40000000 =20 # initial location of the device tree blob passed by Cloud Hypervisor --= base of DRAM - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x40000000 + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x40000000 =20 gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index f50d53bf15..cac4fe06d3 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -179,7 +179,7 @@ # We are booting from RAM using the Linux kernel boot protocol, # x0 will point to the DTB image in memory. # - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0 + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0 =20 gArmTokenSpaceGuid.PcdFdBaseAddress|0x0 gArmTokenSpaceGuid.PcdFvBaseAddress|0x0 diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec index 313aebda90..05d2d36c1d 100644 --- a/ArmVirtPkg/ArmVirtPkg.dec +++ b/ArmVirtPkg/ArmVirtPkg.dec @@ -42,20 +42,6 @@ gArmVirtTokenSpaceGuid.PcdTpm2SupportEnabled|FALSE|BOOLEAN|0x00000004 =20 [PcdsFixedAtBuild, PcdsPatchableInModule] - # - # This is the physical address where the device tree is expected to be s= tored - # upon first entry into UEFI. This needs to be a FixedAtBuild PCD, so th= at we - # can do a first pass over the device tree in the SEC phase to discover = the - # UART base address. - # - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0|UINT64|0x0000= 0001 - - # - # Padding in bytes to add to the device tree allocation, so that the DTB= can - # be modified in place (default: 256 bytes) - # - gArmVirtTokenSpaceGuid.PcdDeviceTreeAllocationPadding|256|UINT32|0x00000= 002 - # # Binary representation of the GUID that determines the terminal type. T= he # size must be exactly 16 bytes. The default value corresponds to diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 30e3cfc8b9..cf306cac08 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -201,7 +201,7 @@ gArmTokenSpaceGuid.PcdSystemMemoryBase|0x40000000 =20 # initial location of the device tree blob passed by QEMU -- base of DRAM - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x40000000 + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x40000000 =20 gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index b50f8e84a3..c0d079e28d 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -198,7 +198,7 @@ # Define a default initial address for the device tree. # Ignored if x0 !=3D 0 at entry. # - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x40000000 + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x40000000 =20 gArmTokenSpaceGuid.PcdFdBaseAddress|0x0 gArmTokenSpaceGuid.PcdFvBaseAddress|0x0 diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc index f0d15b823b..5809832e66 100644 --- a/ArmVirtPkg/ArmVirtXen.dsc +++ b/ArmVirtPkg/ArmVirtXen.dsc @@ -115,7 +115,7 @@ # gArmTokenSpaceGuid.PcdSystemMemoryBase|0x0 gArmTokenSpaceGuid.PcdSystemMemorySize|0x0 - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0 + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0 =20 gArmTokenSpaceGuid.PcdFdBaseAddress|0x0 gArmTokenSpaceGuid.PcdFvBaseAddress|0x0 diff --git a/ArmVirtPkg/Library/ArmVirtPsciResetSystemPeiLib/ArmVirtPsciRes= etSystemPeiLib.inf b/ArmVirtPkg/Library/ArmVirtPsciResetSystemPeiLib/ArmVir= tPsciResetSystemPeiLib.inf index 3a65706e8d..79217d296d 100644 --- a/ArmVirtPkg/Library/ArmVirtPsciResetSystemPeiLib/ArmVirtPsciResetSyste= mPeiLib.inf +++ b/ArmVirtPkg/Library/ArmVirtPsciResetSystemPeiLib/ArmVirtPsciResetSyste= mPeiLib.inf @@ -26,6 +26,7 @@ EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] ArmSmcLib @@ -36,4 +37,4 @@ HobLib =20 [Pcd] - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress diff --git a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPei= Lib.inf b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib= .inf index 666b5d9711..6df26ccd64 100644 --- a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf +++ b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf @@ -26,6 +26,7 @@ EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] ArmLib @@ -44,4 +45,4 @@ [FixedPcd] gArmTokenSpaceGuid.PcdFdSize gArmTokenSpaceGuid.PcdFvSize - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFl= ash.inf b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash= .inf index 7870ca2ae4..f35a0913f0 100644 --- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf +++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf @@ -30,6 +30,7 @@ ArmPlatformPkg/ArmPlatformPkg.dec ArmVirtPkg/ArmVirtPkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] BaseLib @@ -41,7 +42,7 @@ PrintLib =20 [Pcd] - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress # Flash.c + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress # Flash.c gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550Seri= alPortHookLib.inf b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16= 550SerialPortHookLib.inf index 22aba53d9b..3e2303b7f4 100644 --- a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortH= ookLib.inf +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortH= ookLib.inf @@ -29,7 +29,8 @@ ArmVirtPkg/ArmVirtPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [Pcd] - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase diff --git a/ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPo= rtLib.inf b/ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPor= tLib.inf index f47692f06a..e677f1d9e7 100644 --- a/ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.i= nf +++ b/ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.i= nf @@ -28,9 +28,10 @@ MdePkg/MdePkg.dec ArmPlatformPkg/ArmPlatformPkg.dec ArmVirtPkg/ArmVirtPkg.dec + OvmfPkg/OvmfPkg.dec =20 [Pcd] - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate diff --git a/ArmVirtPkg/Library/KvmtoolPlatformPeiLib/KvmtoolPlatformPeiLib= .inf b/ArmVirtPkg/Library/KvmtoolPlatformPeiLib/KvmtoolPlatformPeiLib.inf index f201aee50c..77c0b923bd 100644 --- a/ArmVirtPkg/Library/KvmtoolPlatformPeiLib/KvmtoolPlatformPeiLib.inf +++ b/ArmVirtPkg/Library/KvmtoolPlatformPeiLib/KvmtoolPlatformPeiLib.inf @@ -24,6 +24,7 @@ EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] DebugLib @@ -34,12 +35,12 @@ =20 [FixedPcd] gArmTokenSpaceGuid.PcdFvSize - gArmVirtTokenSpaceGuid.PcdDeviceTreeAllocationPadding + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeAllocationPadding =20 [Pcd] gArmTokenSpaceGuid.PcdFvBaseAddress - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress =20 [Guids] gFdtHobGuid diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf b/ArmVirt= Pkg/Library/PlatformPeiLib/PlatformPeiLib.inf index b867d8bb89..e9a34b6e2e 100644 --- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf +++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf @@ -41,16 +41,16 @@ =20 [FixedPcd] gArmTokenSpaceGuid.PcdFvSize - gArmVirtTokenSpaceGuid.PcdDeviceTreeAllocationPadding + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeAllocationPadding =20 [Pcd] gArmTokenSpaceGuid.PcdFvBaseAddress - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress - gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## SOMETIMES_PRO= DUCES + gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## SOMETIMES= _PRODUCES + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress =20 [Ppis] - gOvmfTpmDiscoveredPpiGuid ## SOMETIMES_PRO= DUCES - gPeiTpmInitializationDonePpiGuid ## SOMETIMES_PRO= DUCES + gOvmfTpmDiscoveredPpiGuid ## SOMETIMES= _PRODUCES + gPeiTpmInitializationDonePpiGuid ## SOMETIMES= _PRODUCES =20 [Guids] gEarlyPL011BaseAddressGuid diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.in= f b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf index f045e39a41..76c3c5d3c8 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf @@ -26,6 +26,7 @@ EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] ArmLib @@ -44,4 +45,4 @@ gArmTokenSpaceGuid.PcdSystemMemorySize gArmTokenSpaceGuid.PcdFdSize gArmTokenSpaceGuid.PcdFvSize - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress diff --git a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf b/ArmVirtP= kg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf index 7edf501808..6b9244bd1a 100755 --- a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf +++ b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf @@ -35,6 +35,7 @@ ArmPkg/ArmPkg.dec ArmPlatformPkg/ArmPlatformPkg.dec ArmVirtPkg/ArmVirtPkg.dec + OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] BaseLib @@ -93,6 +94,6 @@ [Pcd] gArmTokenSpaceGuid.PcdSystemMemoryBase gArmTokenSpaceGuid.PcdSystemMemorySize - gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress gArmTokenSpaceGuid.PcdFdBaseAddress gArmTokenSpaceGuid.PcdFvBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index b44fa039f7..7bc2bf1674 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -386,6 +386,21 @@ # gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|0x0|BOOLEAN|0x69 =20 +[PcdsFixedAtBuild, PcdsPatchableInModule] + # + # This is the physical address where the device tree is expected to be s= tored + # upon first entry into UEFI. This needs to be a FixedAtBuild PCD, so th= at we + # can do a first pass over the device tree in the SEC phase to discover = the + # UART base address. + # + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0|UINT64|0x= 6e + + # + # Padding in bytes to add to the device tree allocation, so that the DTB= can + # be modified in place (default: 256 bytes) + # + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeAllocationPadding|256|UINT32|0x6f + [PcdsFeatureFlag] gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0= x1c gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN= |0x1d --=20 2.27.0 -=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 (#114544): https://edk2.groups.io/g/devel/message/114544 Mute This Topic: https://groups.io/mt/103971659/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- From nobody Thu Dec 26 20:24:45 2024 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+114545+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+114545+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250595; cv=none; d=zohomail.com; s=zohoarc; b=UfR8KpsHCz02q5ENvDYDaYSjq+YcaCntXFwVLyDezqL4UJ2yevvIpq5dg0BivphCN6kjEujrFJBRrdi05dwL/N03kPpMOUjMQxLjwhahsWy6yUvbxST6C7XeiroIe6/Y3tW9rhDNPCDom47W72HCO7VWHluKbKz+6JII83eZw5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250595; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=Y3NXLImMijsE06RJ3Aau/RZp4jfAf+aixYR4JwQ4TFc=; b=MrCt9a0laTb59t+x8oQNDOU0BqVOg6lanqVRCUqVsj1rQafeVBfaxZbynTi22T/0IqhDxeUxSQPd1N6KxYxRRP4Xq2ny5aUNXgGwmuDdXwB+7RnQdFh7MXfphLR/G7rfXh8wlNIMoSHUsporkf9bTv+rqJwWPNruUqk2hRybwPg= 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+114545+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250595534772.2412890275531; Thu, 25 Jan 2024 22:29:55 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=5Na5l/MX9k7L3aGfGAZBA6I8qI735757cDVPUIlKEHU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250595; v=1; b=aC/OJlfdeZ6CEFEIvcNjuVyqlN9LS021ZvfFCVmPCwK8CG9thuRi2v66HTKUo1y2MrdRMXnZ sMSGxSxDJBov8oUnWurGePWqfQi8VsWcjtip86Wsm7BwfzxdQ5GCidZq3MWYHXp82CO6qlFXfTD W93/4QJKSsK4d9nv1Y9QOM1U= X-Received: by 127.0.0.2 with SMTP id hAeqYY1788612xpBD0ZYgFnB; Thu, 25 Jan 2024 22:29:55 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10009.1706250593818234686 for ; Thu, 25 Jan 2024 22:29:54 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxbetfUbNlUx4GAA--.21778S3; Fri, 26 Jan 2024 14:29:51 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxZMxeUbNlxnIbAA--.58665S2; Fri, 26 Jan 2024 14:29:50 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ray Ni , Laszlo Ersek , Rahul Kumar , Gerd Hoffmann , Leif Lindholm , Ard Biesheuvel , Sami Mujawar Subject: [edk2-devel] [PATCH v8 19/37] UefiCpuPkg: Add a new CPU IO 2 driver named CpuMmio2Dxe Date: Fri, 26 Jan 2024 14:29:48 +0800 Message-Id: <20240126062948.3102012-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxZMxeUbNlxnIbAA--.58665S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBUsL X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: pSy499Nyg384gxQ9dKY50h1Vx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250596357100001 Content-Type: text/plain; charset="utf-8" CpuIo2Dxe only supports IO to access to CPU IO. Some ARCHs that do not implement ports for CPU IO require MMIO to access PCI IO, and they pretty much put the IO devices under the LPC bus, which is usually under the PCIe/PCI bus. CpuMmio2Dxe was added to meet these needs. CpuMmio2Dxe depends on PcdPciIoTranslation. The code is copied from ArmPkg. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sami Mujawar Signed-off-by: Chao Li Reviewed-by: Ray Ni --- UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.c | 557 +++++++++++++++++++++++++ UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf | 48 +++ UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.uni | 18 + UefiCpuPkg/UefiCpuPkg.dsc | 2 + 4 files changed, 625 insertions(+) create mode 100644 UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.c create mode 100644 UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf create mode 100644 UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.uni diff --git a/UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.c b/UefiCpuPkg/CpuMmio2Dxe/= CpuMmio2Dxe.c new file mode 100644 index 0000000000..32ccac1cc6 --- /dev/null +++ b/UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.c @@ -0,0 +1,557 @@ +/** @file + Produces the CPU I/O 2 Protocol. + +Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2016, Linaro Ltd. All rights reserved.
+Copyright (c) 2024 Loongson Technology Corporation Limited. All rights res= erved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include + +#include +#include +#include +#include +#include + +#define MAX_IO_PORT_ADDRESS 0xFFFF + +// +// Handle for the CPU I/O 2 Protocol +// +STATIC EFI_HANDLE mHandle =3D NULL; + +// +// Lookup table for increment values based on transfer widths +// +STATIC CONST UINT8 mInStride[] =3D { + 1, // EfiCpuIoWidthUint8 + 2, // EfiCpuIoWidthUint16 + 4, // EfiCpuIoWidthUint32 + 8, // EfiCpuIoWidthUint64 + 0, // EfiCpuIoWidthFifoUint8 + 0, // EfiCpuIoWidthFifoUint16 + 0, // EfiCpuIoWidthFifoUint32 + 0, // EfiCpuIoWidthFifoUint64 + 1, // EfiCpuIoWidthFillUint8 + 2, // EfiCpuIoWidthFillUint16 + 4, // EfiCpuIoWidthFillUint32 + 8 // EfiCpuIoWidthFillUint64 +}; + +// +// Lookup table for increment values based on transfer widths +// +STATIC CONST UINT8 mOutStride[] =3D { + 1, // EfiCpuIoWidthUint8 + 2, // EfiCpuIoWidthUint16 + 4, // EfiCpuIoWidthUint32 + 8, // EfiCpuIoWidthUint64 + 1, // EfiCpuIoWidthFifoUint8 + 2, // EfiCpuIoWidthFifoUint16 + 4, // EfiCpuIoWidthFifoUint32 + 8, // EfiCpuIoWidthFifoUint64 + 0, // EfiCpuIoWidthFillUint8 + 0, // EfiCpuIoWidthFillUint16 + 0, // EfiCpuIoWidthFillUint32 + 0 // EfiCpuIoWidthFillUint64 +}; + +/** + Check parameters to a CPU I/O 2 Protocol service request. + + The I/O operations are carried out exactly as requested. The caller is r= esponsible + for satisfying any alignment and I/O width restrictions that a PI System= on a + platform might require. For example on some platforms, width requests of + EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will + be handled by the driver. + + @param[in] MmioOperation TRUE for an MMIO operation, FALSE for I/O Port= operation. + @param[in] Width Signifies the width of the I/O or Memory opera= tion. + @param[in] Address The base address of the I/O operation. + @param[in] Count The number of I/O operations to perform. The n= umber of + bytes moved is Width size * Count, starting at= Address. + @param[in] Buffer For read operations, the destination buffer to= store the results. + For write operations, the source buffer from w= hich to write data. + + @retval EFI_SUCCESS The parameters for this request pass the = checks. + @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. + @retval EFI_INVALID_PARAMETER Buffer is NULL. + @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. + @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, + and Count is not valid for this PI system. + +**/ +STATIC +EFI_STATUS +CpuIoCheckParameter ( + IN BOOLEAN MmioOperation, + IN EFI_CPU_IO_PROTOCOL_WIDTH Width, + IN UINT64 Address, + IN UINTN Count, + IN VOID *Buffer + ) +{ + UINT64 MaxCount; + UINT64 Limit; + + // + // Check to see if Buffer is NULL + // + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Check to see if Width is in the valid range + // + if ((UINT32)Width >=3D EfiCpuIoWidthMaximum) { + return EFI_INVALID_PARAMETER; + } + + // + // For FIFO type, the target address won't increase during the access, + // so treat Count as 1 + // + if ((Width >=3D EfiCpuIoWidthFifoUint8) && (Width <=3D EfiCpuIoWidthFifo= Uint64)) { + Count =3D 1; + } + + // + // Check to see if Width is in the valid range for I/O Port operations + // + Width =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); + if (!MmioOperation && (Width =3D=3D EfiCpuIoWidthUint64)) { + return EFI_INVALID_PARAMETER; + } + + // + // Check to see if Address is aligned + // + if ((Address & (UINT64)(mInStride[Width] - 1)) !=3D 0) { + return EFI_UNSUPPORTED; + } + + // + // Check to see if any address associated with this transfer exceeds the= maximum + // allowed address. The maximum address implied by the parameters passe= d in is + // Address + Size * Count. If the following condition is met, then the = transfer + // is not supported. + // + // Address + Size * Count > (MmioOperation ? MAX_ADDRESS : MAX_IO_POR= T_ADDRESS) + 1 + // + // Since MAX_ADDRESS can be the maximum integer value supported by the C= PU and Count + // can also be the maximum integer value supported by the CPU, this range + // check must be adjusted to avoid all overflow conditions. + // + // The following form of the range check is equivalent but assumes that + // MAX_ADDRESS and MAX_IO_PORT_ADDRESS are of the form (2^n - 1). + // + Limit =3D (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS); + if (Count =3D=3D 0) { + if (Address > Limit) { + return EFI_UNSUPPORTED; + } + } else { + MaxCount =3D RShiftU64 (Limit, Width); + if (MaxCount < (Count - 1)) { + return EFI_UNSUPPORTED; + } + + if (Address > LShiftU64 (MaxCount - Count + 1, Width)) { + return EFI_UNSUPPORTED; + } + } + + // + // Check to see if Buffer is aligned + // + if (((UINTN)Buffer & ((MIN (sizeof (UINTN), mInStride[Width]) - 1))) != =3D 0) { + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} + +/** + Reads memory-mapped registers. + + The I/O operations are carried out exactly as requested. The caller is r= esponsible + for satisfying any alignment and I/O width restrictions that a PI System= on a + platform might require. For example on some platforms, width requests of + EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will + be handled by the driver. + + If Width is EfiCpuIoWidthUint8, EfiCpuIoWidthUint16, EfiCpuIoWidthUint32, + or EfiCpuIoWidthUint64, then both Address and Buffer are incremented for + each of the Count operations that is performed. + + If Width is EfiCpuIoWidthFifoUint8, EfiCpuIoWidthFifoUint16, + EfiCpuIoWidthFifoUint32, or EfiCpuIoWidthFifoUint64, then only Buffer is + incremented for each of the Count operations that is performed. The read= or + write operation is performed Count times on the same Address. + + If Width is EfiCpuIoWidthFillUint8, EfiCpuIoWidthFillUint16, + EfiCpuIoWidthFillUint32, or EfiCpuIoWidthFillUint64, then only Address is + incremented for each of the Count operations that is performed. The read= or + write operation is performed Count times from the first element of Buffe= r. + + @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance. + @param[in] Width Signifies the width of the I/O or Memory operation. + @param[in] Address The base address of the I/O operation. + @param[in] Count The number of I/O operations to perform. The number= of + bytes moved is Width size * Count, starting at Addr= ess. + @param[out] Buffer For read operations, the destination buffer to stor= e the results. + For write operations, the source buffer from which = to write data. + + @retval EFI_SUCCESS The data was read from or written to the = PI system. + @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. + @retval EFI_INVALID_PARAMETER Buffer is NULL. + @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. + @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, + and Count is not valid for this PI system. + +**/ +STATIC +EFI_STATUS +EFIAPI +CpuMemoryServiceRead ( + IN EFI_CPU_IO2_PROTOCOL *This, + IN EFI_CPU_IO_PROTOCOL_WIDTH Width, + IN UINT64 Address, + IN UINTN Count, + OUT VOID *Buffer + ) +{ + EFI_STATUS Status; + UINT8 InStride; + UINT8 OutStride; + EFI_CPU_IO_PROTOCOL_WIDTH OperationWidth; + UINT8 *Uint8Buffer; + + Status =3D CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Select loop based on the width of the transfer + // + InStride =3D mInStride[Width]; + OutStride =3D mOutStride[Width]; + OperationWidth =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); + for (Uint8Buffer =3D Buffer; Count > 0; Address +=3D InStride, Uint8Buff= er +=3D OutStride, Count--) { + if (OperationWidth =3D=3D EfiCpuIoWidthUint8) { + *Uint8Buffer =3D MmioRead8 ((UINTN)Address); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint16) { + *((UINT16 *)Uint8Buffer) =3D MmioRead16 ((UINTN)Address); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint32) { + *((UINT32 *)Uint8Buffer) =3D MmioRead32 ((UINTN)Address); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint64) { + *((UINT64 *)Uint8Buffer) =3D MmioRead64 ((UINTN)Address); + } + } + + return EFI_SUCCESS; +} + +/** + Writes memory-mapped registers. + + The I/O operations are carried out exactly as requested. The caller is r= esponsible + for satisfying any alignment and I/O width restrictions that a PI System= on a + platform might require. For example on some platforms, width requests of + EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will + be handled by the driver. + + If Width is EfiCpuIoWidthUint8, EfiCpuIoWidthUint16, EfiCpuIoWidthUint32, + or EfiCpuIoWidthUint64, then both Address and Buffer are incremented for + each of the Count operations that is performed. + + If Width is EfiCpuIoWidthFifoUint8, EfiCpuIoWidthFifoUint16, + EfiCpuIoWidthFifoUint32, or EfiCpuIoWidthFifoUint64, then only Buffer is + incremented for each of the Count operations that is performed. The read= or + write operation is performed Count times on the same Address. + + If Width is EfiCpuIoWidthFillUint8, EfiCpuIoWidthFillUint16, + EfiCpuIoWidthFillUint32, or EfiCpuIoWidthFillUint64, then only Address is + incremented for each of the Count operations that is performed. The read= or + write operation is performed Count times from the first element of Buffe= r. + + @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance. + @param[in] Width Signifies the width of the I/O or Memory operation. + @param[in] Address The base address of the I/O operation. + @param[in] Count The number of I/O operations to perform. The number= of + bytes moved is Width size * Count, starting at Addr= ess. + @param[in] Buffer For read operations, the destination buffer to stor= e the results. + For write operations, the source buffer from which = to write data. + + @retval EFI_SUCCESS The data was read from or written to the = PI system. + @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. + @retval EFI_INVALID_PARAMETER Buffer is NULL. + @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. + @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, + and Count is not valid for this PI system. + +**/ +STATIC +EFI_STATUS +EFIAPI +CpuMemoryServiceWrite ( + IN EFI_CPU_IO2_PROTOCOL *This, + IN EFI_CPU_IO_PROTOCOL_WIDTH Width, + IN UINT64 Address, + IN UINTN Count, + IN VOID *Buffer + ) +{ + EFI_STATUS Status; + UINT8 InStride; + UINT8 OutStride; + EFI_CPU_IO_PROTOCOL_WIDTH OperationWidth; + UINT8 *Uint8Buffer; + + Status =3D CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Select loop based on the width of the transfer + // + InStride =3D mInStride[Width]; + OutStride =3D mOutStride[Width]; + OperationWidth =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); + for (Uint8Buffer =3D Buffer; Count > 0; Address +=3D InStride, Uint8Buff= er +=3D OutStride, Count--) { + if (OperationWidth =3D=3D EfiCpuIoWidthUint8) { + MmioWrite8 ((UINTN)Address, *Uint8Buffer); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint16) { + MmioWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer)); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint32) { + MmioWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer)); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint64) { + MmioWrite64 ((UINTN)Address, *((UINT64 *)Uint8Buffer)); + } + } + + return EFI_SUCCESS; +} + +/** + Reads I/O registers. + + The I/O operations are carried out exactly as requested. The caller is r= esponsible + for satisfying any alignment and I/O width restrictions that a PI System= on a + platform might require. For example on some platforms, width requests of + EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will + be handled by the driver. + + If Width is EfiCpuIoWidthUint8, EfiCpuIoWidthUint16, EfiCpuIoWidthUint32, + or EfiCpuIoWidthUint64, then both Address and Buffer are incremented for + each of the Count operations that is performed. + + If Width is EfiCpuIoWidthFifoUint8, EfiCpuIoWidthFifoUint16, + EfiCpuIoWidthFifoUint32, or EfiCpuIoWidthFifoUint64, then only Buffer is + incremented for each of the Count operations that is performed. The read= or + write operation is performed Count times on the same Address. + + If Width is EfiCpuIoWidthFillUint8, EfiCpuIoWidthFillUint16, + EfiCpuIoWidthFillUint32, or EfiCpuIoWidthFillUint64, then only Address is + incremented for each of the Count operations that is performed. The read= or + write operation is performed Count times from the first element of Buffe= r. + + @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance. + @param[in] Width Signifies the width of the I/O or Memory operation. + @param[in] Address The base address of the I/O operation. + @param[in] Count The number of I/O operations to perform. The number= of + bytes moved is Width size * Count, starting at Addr= ess. + @param[out] Buffer For read operations, the destination buffer to stor= e the results. + For write operations, the source buffer from which = to write data. + + @retval EFI_SUCCESS The data was read from or written to the = PI system. + @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. + @retval EFI_INVALID_PARAMETER Buffer is NULL. + @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. + @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, + and Count is not valid for this PI system. + +**/ +STATIC +EFI_STATUS +EFIAPI +CpuIoServiceRead ( + IN EFI_CPU_IO2_PROTOCOL *This, + IN EFI_CPU_IO_PROTOCOL_WIDTH Width, + IN UINT64 Address, + IN UINTN Count, + OUT VOID *Buffer + ) +{ + EFI_STATUS Status; + UINT8 InStride; + UINT8 OutStride; + EFI_CPU_IO_PROTOCOL_WIDTH OperationWidth; + UINT8 *Uint8Buffer; + + Status =3D CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer); + if (EFI_ERROR (Status)) { + return Status; + } + + Address +=3D PcdGet64 (PcdPciIoTranslation); + + // + // Select loop based on the width of the transfer + // + InStride =3D mInStride[Width]; + OutStride =3D mOutStride[Width]; + OperationWidth =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); + + for (Uint8Buffer =3D Buffer; Count > 0; Address +=3D InStride, Uint8Buff= er +=3D OutStride, Count--) { + if (OperationWidth =3D=3D EfiCpuIoWidthUint8) { + *Uint8Buffer =3D MmioRead8 ((UINTN)Address); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint16) { + *((UINT16 *)Uint8Buffer) =3D MmioRead16 ((UINTN)Address); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint32) { + *((UINT32 *)Uint8Buffer) =3D MmioRead32 ((UINTN)Address); + } + } + + return EFI_SUCCESS; +} + +/** + Write I/O registers. + + The I/O operations are carried out exactly as requested. The caller is r= esponsible + for satisfying any alignment and I/O width restrictions that a PI System= on a + platform might require. For example on some platforms, width requests of + EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will + be handled by the driver. + + If Width is EfiCpuIoWidthUint8, EfiCpuIoWidthUint16, EfiCpuIoWidthUint32, + or EfiCpuIoWidthUint64, then both Address and Buffer are incremented for + each of the Count operations that is performed. + + If Width is EfiCpuIoWidthFifoUint8, EfiCpuIoWidthFifoUint16, + EfiCpuIoWidthFifoUint32, or EfiCpuIoWidthFifoUint64, then only Buffer is + incremented for each of the Count operations that is performed. The read= or + write operation is performed Count times on the same Address. + + If Width is EfiCpuIoWidthFillUint8, EfiCpuIoWidthFillUint16, + EfiCpuIoWidthFillUint32, or EfiCpuIoWidthFillUint64, then only Address is + incremented for each of the Count operations that is performed. The read= or + write operation is performed Count times from the first element of Buffe= r. + + @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance. + @param[in] Width Signifies the width of the I/O or Memory operation. + @param[in] Address The base address of the I/O operation. + @param[in] Count The number of I/O operations to perform. The number= of + bytes moved is Width size * Count, starting at Addr= ess. + @param[in] Buffer For read operations, the destination buffer to stor= e the results. + For write operations, the source buffer from which = to write data. + + @retval EFI_SUCCESS The data was read from or written to the = PI system. + @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. + @retval EFI_INVALID_PARAMETER Buffer is NULL. + @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. + @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, + and Count is not valid for this PI system. + +**/ +STATIC +EFI_STATUS +EFIAPI +CpuIoServiceWrite ( + IN EFI_CPU_IO2_PROTOCOL *This, + IN EFI_CPU_IO_PROTOCOL_WIDTH Width, + IN UINT64 Address, + IN UINTN Count, + IN VOID *Buffer + ) +{ + EFI_STATUS Status; + UINT8 InStride; + UINT8 OutStride; + EFI_CPU_IO_PROTOCOL_WIDTH OperationWidth; + UINT8 *Uint8Buffer; + + // + // Make sure the parameters are valid + // + Status =3D CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer); + if (EFI_ERROR (Status)) { + return Status; + } + + Address +=3D PcdGet64 (PcdPciIoTranslation); + + // + // Select loop based on the width of the transfer + // + InStride =3D mInStride[Width]; + OutStride =3D mOutStride[Width]; + OperationWidth =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); + + for (Uint8Buffer =3D (UINT8 *)Buffer; Count > 0; Address +=3D InStride, = Uint8Buffer +=3D OutStride, Count--) { + if (OperationWidth =3D=3D EfiCpuIoWidthUint8) { + MmioWrite8 ((UINTN)Address, *Uint8Buffer); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint16) { + MmioWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer)); + } else if (OperationWidth =3D=3D EfiCpuIoWidthUint32) { + MmioWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer)); + } + } + + return EFI_SUCCESS; +} + +// +// CPU I/O 2 Protocol instance +// +STATIC EFI_CPU_IO2_PROTOCOL mCpuMmio2 =3D { + { + CpuMemoryServiceRead, + CpuMemoryServiceWrite + }, + { + CpuIoServiceRead, + CpuIoServiceWrite + } +}; + +/** + The user Entry Point for module CpuIo2Dxe. The user code starts with thi= s function. + + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry po= int. + +**/ +EFI_STATUS +EFIAPI +CpuMmio2Initialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiCpuIo2ProtocolGuid); + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &mHandle, + &gEfiCpuIo2ProtocolGuid, + &mCpuMmio2, + NULL + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf b/UefiCpuPkg/CpuMmio2Dx= e/CpuMmio2Dxe.inf new file mode 100644 index 0000000000..32577be7ea --- /dev/null +++ b/UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf @@ -0,0 +1,48 @@ +## @file +# Produces the CPU I/O 2 Protocol by using the services of the I/O Librar= y. +# +# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2016, Linaro Ltd. All rights reserved.
+# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D CpuMmio2Dxe + MODULE_UNI_FILE =3D CpuMmio2Dxe.uni + FILE_GUID =3D FBC36D76-CF22-2584-DBD8-85FF765BAEF1 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D CpuMmio2Initialize + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D ARM AARCH64 LOONGARCH64 RISCV64 +# + +[Sources] + CpuMmio2Dxe.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + BaseLib + DebugLib + IoLib + PcdLib + UefiBootServicesTableLib + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation + +[Protocols] + gEfiCpuIo2ProtocolGuid ## PRODUCES + +[Depex] + TRUE diff --git a/UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.uni b/UefiCpuPkg/CpuMmio2Dx= e/CpuMmio2Dxe.uni new file mode 100644 index 0000000000..af3b1a656f --- /dev/null +++ b/UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.uni @@ -0,0 +1,18 @@ +// /** @file +// Produces the CPU I/O 2 Protocol by using the services of the I/O Librar= y. +// +// Produces the CPU I/O 2 Protocol by using the services of the I/O Librar= y. +// +// Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+// Copyright (c) 2016, Linaro Ltd. All rights reserved.
+// Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Produces the CPU = I/O 2 Protocol by using the services of the I/O Library" + +#string STR_MODULE_DESCRIPTION #language en-US "Produces the CPU = I/O 2 Protocol by using the services of the I/O Library." + diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 178dc3c0f9..4aa1fd218b 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -206,8 +206,10 @@ UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf + UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf =20 [Components.LOONGARCH64] + UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.inf UefiCpuPkg/Library/CpuMmuLib/PeiCpuMmuLib.inf =20 --=20 2.27.0 -=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 (#114545): https://edk2.groups.io/g/devel/message/114545 Mute This Topic: https://groups.io/mt/103971663/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- From nobody Thu Dec 26 20:24:45 2024 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+114546+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+114546+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250603; cv=none; d=zohomail.com; s=zohoarc; b=Ul1r3/0L67FFAIQgaI7sjEhDwNOe8c5B6m1I8/JsNCiq1w3v+dBY7CRrE2cZ/EUVGXw6mdib4+wcOY6mFeGYnkeABTufpoVij5lPIusHDEKebe9qEzOQGu2nuHA/BJ4Twuueh1dEk8GbzknW8pzGFIpdkufic45zBzENE0Y3h4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250603; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=R5lm5rQNmSuTU7jxeEIDzKyJr+91BXJk6XUWeJAy/g4=; b=jbOtrYq/JYRVo5B2lNxzVzCqlH8KRK4234NlOPc6JHy6Oxc+/ECb/SEWzqBn6Gr006Me5Rc3/TCBhkyi7Pjj7kF0RugUNEdu4jy07WlY0TE4OxDmGjtNne8kgxF/LCC7fZ6SSe1ivqFtG8suwhNxHJXbkAZJmB1MmtN3GoinjRk= 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+114546+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 170625060305793.47092504961495; Thu, 25 Jan 2024 22:30:03 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=BR2B0Q6H9cid63pdsFAyOA6nDbO8BK4XL2a31u+E64s=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250602; v=1; b=hvg5B6ev0+o+abvxAI43YuADChbX/W3Ic0xxJrdSA25gIkvhoOHOvvF9PoUy0iXXP3X8Qmsl Wdc47L2q/ba0aFQhx2IQ4hxMsNCAvc6jKLtm6SKMQ3i1XYpdljhONTXeuoP0+Q8knkCo2NqNjSh yskqq7XI8GiyXW2c17vNMl+g= X-Received: by 127.0.0.2 with SMTP id dg82YY1788612xw6pMHPeqND; Thu, 25 Jan 2024 22:30:02 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10010.1706250600631202290 for ; Thu, 25 Jan 2024 22:30:02 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxWOhmUbNlZR4GAA--.2182S3; Fri, 26 Jan 2024 14:29:58 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxf89kUbNl4HIbAA--.53078S2; Fri, 26 Jan 2024 14:29:56 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Leif Lindholm , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v8 20/37] ArmVirtPkg: Enable CpuMmio2Dxe Date: Fri, 26 Jan 2024 14:29:55 +0800 Message-Id: <20240126062955.3102084-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxf89kUbNl4HIbAA--.53078S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBWsJ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: mSLTZHVQ0I6NUOZUMH2gComEx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250604435100001 Content-Type: text/plain; charset="utf-8" CpuMmio2Dxe is supports MMIO, enable it. Build-tested only (with "ArmVirtQemu.dsc"). BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Signed-off-by: Chao Li --- ArmVirtPkg/ArmVirtCloudHv.dsc | 2 +- ArmVirtPkg/ArmVirtCloudHv.fdf | 2 +- ArmVirtPkg/ArmVirtKvmTool.dsc | 2 +- ArmVirtPkg/ArmVirtKvmTool.fdf | 2 +- ArmVirtPkg/ArmVirtQemu.dsc | 2 +- ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 2 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index 76c0d28544..5cb2a609b1 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -341,7 +341,7 @@ # # PCI support # - ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf { + UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf { NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } diff --git a/ArmVirtPkg/ArmVirtCloudHv.fdf b/ArmVirtPkg/ArmVirtCloudHv.fdf index 56d1ea6e8c..8554efc294 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.fdf +++ b/ArmVirtPkg/ArmVirtCloudHv.fdf @@ -201,7 +201,7 @@ READ_LOCK_STATUS =3D TRUE # # PCI support # - INF ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf + INF UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index cac4fe06d3..20da331966 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -372,7 +372,7 @@ # # PCI support # - ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf { + UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf { NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf NULL|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressL= ib.inf diff --git a/ArmVirtPkg/ArmVirtKvmTool.fdf b/ArmVirtPkg/ArmVirtKvmTool.fdf index 82aff47673..cdf756c112 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.fdf +++ b/ArmVirtPkg/ArmVirtKvmTool.fdf @@ -195,7 +195,7 @@ READ_LOCK_STATUS =3D TRUE # # PCI support # - INF ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf + INF UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index cf306cac08..dbd2396c78 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -526,7 +526,7 @@ # # PCI support # - ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf { + UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf { NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuF= vMain.fdf.inc index 9b3e37d5c9..c5d097ffb9 100644 --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc @@ -153,7 +153,7 @@ READ_LOCK_STATUS =3D TRUE # # PCI support # - INF ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf + INF UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index c0d079e28d..6a6ecfc12a 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -431,7 +431,7 @@ # # PCI support # - ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf { + UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf { NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } --=20 2.27.0 -=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 (#114546): https://edk2.groups.io/g/devel/message/114546 Mute This Topic: https://groups.io/mt/103971664/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- From nobody Thu Dec 26 20:24:45 2024 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+114547+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+114547+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250606; cv=none; d=zohomail.com; s=zohoarc; b=Ep16xuiuCx5EGBDJ10PrQMWAi00gowItTvZiKPZtM6vSPEahZ7+38FcnNc5JYv3BaGrFQkrCCkpvl2ogdwuTutTq05PwWiPnzNaCWBvphzGxjphGc8BN9qN+Ef5LX61QLBCQX5KD8qbUjl4ypao2TCBImyuoUANrMiLnrCBths4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250606; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=L98Va+PKCPcO4MMm1BbBEX6O9TfublTLRnHfuo8/m0k=; b=Ma/nIw6c8W1J8WQVnihvxRjd6Vhe7QvLHD81yl+pknDP1so0OOCD1rMUrc1rNFte9qLe/wK33QpjZquOFv4Eg3544Ofkzq7+4fP3+g9MBsl54+ElVYLf1cQXstmgt+VDWZoGJV4X19gIGLqX2DoO93K42iFDM96Au247FwJAdtA= 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+114547+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250606265437.1816559812331; Thu, 25 Jan 2024 22:30:06 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=4xnjmUvZRmMm3+g1GbJHYAVzeTL9fmG59YZ7zTZXm8I=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250605; v=1; b=hUPV7WcAw8wQMyq/KdCVHX/H6qc9sXQdqQArj3un6zzdYWar5gMdUYBiJoqk+Rc9BleIoan1 n6CpMJYoC7hdHtCXHEh/DReVqozj2HDPBLNsQoCMfdEtrT/70+tiiRDD5BpE/9faxe3YmmCuVih o15YXlMihMTrOf/sbjR7Uwsw= X-Received: by 127.0.0.2 with SMTP id 3nGIYY1788612xabxgEoCYPD; Thu, 25 Jan 2024 22:30:05 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10012.1706250604477736663 for ; Thu, 25 Jan 2024 22:30:05 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8Bx3+tpUbNlbx4GAA--.21504S3; Fri, 26 Jan 2024 14:30:01 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxXs1pUbNl7XIbAA--.49765S2; Fri, 26 Jan 2024 14:30:01 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Sunil V L , Andrei Warkentin Subject: [edk2-devel] [PATCH v8 21/37] OvmfPkg/RiscVVirt: Enable CpuMmio2Dxe Date: Fri, 26 Jan 2024 14:30:00 +0800 Message-Id: <20240126063000.3102147-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxXs1pUbNl7XIbAA--.49765S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBYsH X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: DVp873ANEiA72JGtplZqaeisx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250608370100003 Content-Type: text/plain; charset="utf-8" CpuMmio2Dxe is supports MMIO, enable it. Build-tested only (with "RiscVVirtQemu.dsc"). BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Sunil V L Cc: Andrei Warkentin Signed-off-by: Chao Li Reviewed-by: Sunil V L --- OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 2 +- OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVV= irtQemu.dsc index 774dc81840..27f24648e8 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc @@ -433,7 +433,7 @@ # # PCI support # - OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf { + UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf { NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf b/OvmfPkg/RiscVVirt/RiscVV= irtQemu.fdf index 8121b9e579..e579f5b9b7 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf @@ -184,7 +184,7 @@ INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf # # PCI support # -INF OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf +INF UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf --=20 2.27.0 -=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 (#114547): https://edk2.groups.io/g/devel/message/114547 Mute This Topic: https://groups.io/mt/103971665/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- From nobody Thu Dec 26 20:24:45 2024 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+114548+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+114548+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250612; cv=none; d=zohomail.com; s=zohoarc; b=MYCQ0O+QMR9nNJm4GSTUXQFX8yR5OycpxMWPT6NapFVIbQWQZSSL8JRHG7Ttr0intRO5c4HUD5mmbfy94FsQWj7KX0LnFi/zgK8dohoSoO/zit3IdFt7wXXMIzheI/DVO4bmESo2UP0k39QHtLvtkDtP8OjpJ0Jbu/xeXNvWzuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250612; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=8e7azaRzEVZxCK+yMdUdQpeBRYHC86pau7G62oIDbLk=; b=LEO0zEY/tRHxQ38CBlPl7eys9sJVssDOOsg/1ZBq29NO994VmzZR8fW1RKFXMRSIDfEPlTdV8dofHfyxWTSYST7+qFZ05WT1Vp3S1PJX8ReeihWP2IcgkPOmIgu9fAEvsfEF3A3Rdo7aOnS8tjXTWHoRW6ZOfH2cHPl3mnDVyis= 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+114548+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250612678908.6386721115831; Thu, 25 Jan 2024 22:30:12 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=PesVmmPFp7cDcdt6Q3m8OBN/9A5g2DDFcE9vV/gyhgM=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250612; v=1; b=Az2omRLEeZAYVdj/82IzQVQyrff0zgP0p1sPZMs4+H2MVA0ETM81JUc1BmOHjXAGcIESYMvy ZxwcRurD0P4W5PQ/qtcWM0MKru9RY2OAEhANgs9EFEtR3QYtvPukWL/+n+T5Ifp+GFmI1q1/Gqf JQDkjBzHotEBm3eJCF2c/h5o= X-Received: by 127.0.0.2 with SMTP id ZKqyYY1788612xm4NZox5xDi; Thu, 25 Jan 2024 22:30:12 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10150.1706250611044203176 for ; Thu, 25 Jan 2024 22:30:11 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8DxdfFvUbNlfB4GAA--.21914S3; Fri, 26 Jan 2024 14:30:07 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dxfs1tUbNl+3IbAA--.51151S2; Fri, 26 Jan 2024 14:30:05 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Sunil V L , Andrei Warkentin Subject: [edk2-devel] [PATCH v8 22/37] OvmfPkg/RiscVVirt: Remove PciCpuIo2Dxe from RiscVVirt Date: Fri, 26 Jan 2024 14:30:04 +0800 Message-Id: <20240126063004.3102213-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dxfs1tUbNl+3IbAA--.51151S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBasF X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: VrRsYhD5udQWNJVJFHv3dIhix1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250614408100003 Content-Type: text/plain; charset="utf-8" CpuIo2Dxe is already used by RiscVVirt, so remove it. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Sunil V L Cc: Andrei Warkentin Signed-off-by: Chao Li Reviewed-by: Sunil V L --- OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.c | 557 ------------------ .../RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf | 48 -- 2 files changed, 605 deletions(-) delete mode 100644 OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.c delete mode 100644 OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf diff --git a/OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.c b/OvmfPkg/RiscVV= irt/PciCpuIo2Dxe/PciCpuIo2Dxe.c deleted file mode 100644 index f3bf07e631..0000000000 --- a/OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.c +++ /dev/null @@ -1,557 +0,0 @@ -/** @file - Produces the CPU I/O 2 Protocol. - -Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
-Copyright (c) 2016, Linaro Ltd. All rights reserved.
-Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
- -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include - -#include - -#include -#include -#include -#include -#include - -#define MAX_IO_PORT_ADDRESS 0xFFFF - -// -// Handle for the CPU I/O 2 Protocol -// -STATIC EFI_HANDLE mHandle =3D NULL; - -// -// Lookup table for increment values based on transfer widths -// -STATIC CONST UINT8 mInStride[] =3D { - 1, // EfiCpuIoWidthUint8 - 2, // EfiCpuIoWidthUint16 - 4, // EfiCpuIoWidthUint32 - 8, // EfiCpuIoWidthUint64 - 0, // EfiCpuIoWidthFifoUint8 - 0, // EfiCpuIoWidthFifoUint16 - 0, // EfiCpuIoWidthFifoUint32 - 0, // EfiCpuIoWidthFifoUint64 - 1, // EfiCpuIoWidthFillUint8 - 2, // EfiCpuIoWidthFillUint16 - 4, // EfiCpuIoWidthFillUint32 - 8 // EfiCpuIoWidthFillUint64 -}; - -// -// Lookup table for increment values based on transfer widths -// -STATIC CONST UINT8 mOutStride[] =3D { - 1, // EfiCpuIoWidthUint8 - 2, // EfiCpuIoWidthUint16 - 4, // EfiCpuIoWidthUint32 - 8, // EfiCpuIoWidthUint64 - 1, // EfiCpuIoWidthFifoUint8 - 2, // EfiCpuIoWidthFifoUint16 - 4, // EfiCpuIoWidthFifoUint32 - 8, // EfiCpuIoWidthFifoUint64 - 0, // EfiCpuIoWidthFillUint8 - 0, // EfiCpuIoWidthFillUint16 - 0, // EfiCpuIoWidthFillUint32 - 0 // EfiCpuIoWidthFillUint64 -}; - -/** - Check parameters to a CPU I/O 2 Protocol service request. - - The I/O operations are carried out exactly as requested. The caller is r= esponsible - for satisfying any alignment and I/O width restrictions that a PI System= on a - platform might require. For example on some platforms, width requests of - EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will - be handled by the driver. - - @param[in] MmioOperation TRUE for an MMIO operation, FALSE for I/O Port= operation. - @param[in] Width Signifies the width of the I/O or Memory opera= tion. - @param[in] Address The base address of the I/O operation. - @param[in] Count The number of I/O operations to perform. The n= umber of - bytes moved is Width size * Count, starting at= Address. - @param[in] Buffer For read operations, the destination buffer to= store the results. - For write operations, the source buffer from w= hich to write data. - - @retval EFI_SUCCESS The parameters for this request pass the = checks. - @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. - @retval EFI_INVALID_PARAMETER Buffer is NULL. - @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. - @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, - and Count is not valid for this PI system. - -**/ -STATIC -EFI_STATUS -CpuIoCheckParameter ( - IN BOOLEAN MmioOperation, - IN EFI_CPU_IO_PROTOCOL_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - IN VOID *Buffer - ) -{ - UINT64 MaxCount; - UINT64 Limit; - - // - // Check to see if Buffer is NULL - // - if (Buffer =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Check to see if Width is in the valid range - // - if ((UINT32)Width >=3D EfiCpuIoWidthMaximum) { - return EFI_INVALID_PARAMETER; - } - - // - // For FIFO type, the target address won't increase during the access, - // so treat Count as 1 - // - if ((Width >=3D EfiCpuIoWidthFifoUint8) && (Width <=3D EfiCpuIoWidthFifo= Uint64)) { - Count =3D 1; - } - - // - // Check to see if Width is in the valid range for I/O Port operations - // - Width =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); - if (!MmioOperation && (Width =3D=3D EfiCpuIoWidthUint64)) { - return EFI_INVALID_PARAMETER; - } - - // - // Check to see if Address is aligned - // - if ((Address & (UINT64)(mInStride[Width] - 1)) !=3D 0) { - return EFI_UNSUPPORTED; - } - - // - // Check to see if any address associated with this transfer exceeds the= maximum - // allowed address. The maximum address implied by the parameters passe= d in is - // Address + Size * Count. If the following condition is met, then the = transfer - // is not supported. - // - // Address + Size * Count > (MmioOperation ? MAX_ADDRESS : MAX_IO_POR= T_ADDRESS) + 1 - // - // Since MAX_ADDRESS can be the maximum integer value supported by the C= PU and Count - // can also be the maximum integer value supported by the CPU, this range - // check must be adjusted to avoid all overflow conditions. - // - // The following form of the range check is equivalent but assumes that - // MAX_ADDRESS and MAX_IO_PORT_ADDRESS are of the form (2^n - 1). - // - Limit =3D (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS); - if (Count =3D=3D 0) { - if (Address > Limit) { - return EFI_UNSUPPORTED; - } - } else { - MaxCount =3D RShiftU64 (Limit, Width); - if (MaxCount < (Count - 1)) { - return EFI_UNSUPPORTED; - } - - if (Address > LShiftU64 (MaxCount - Count + 1, Width)) { - return EFI_UNSUPPORTED; - } - } - - // - // Check to see if Buffer is aligned - // - if (((UINTN)Buffer & ((MIN (sizeof (UINTN), mInStride[Width]) - 1))) != =3D 0) { - return EFI_UNSUPPORTED; - } - - return EFI_SUCCESS; -} - -/** - Reads memory-mapped registers. - - The I/O operations are carried out exactly as requested. The caller is r= esponsible - for satisfying any alignment and I/O width restrictions that a PI System= on a - platform might require. For example on some platforms, width requests of - EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will - be handled by the driver. - - If Width is EfiCpuIoWidthUint8, EfiCpuIoWidthUint16, EfiCpuIoWidthUint32, - or EfiCpuIoWidthUint64, then both Address and Buffer are incremented for - each of the Count operations that is performed. - - If Width is EfiCpuIoWidthFifoUint8, EfiCpuIoWidthFifoUint16, - EfiCpuIoWidthFifoUint32, or EfiCpuIoWidthFifoUint64, then only Buffer is - incremented for each of the Count operations that is performed. The read= or - write operation is performed Count times on the same Address. - - If Width is EfiCpuIoWidthFillUint8, EfiCpuIoWidthFillUint16, - EfiCpuIoWidthFillUint32, or EfiCpuIoWidthFillUint64, then only Address is - incremented for each of the Count operations that is performed. The read= or - write operation is performed Count times from the first element of Buffe= r. - - @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance. - @param[in] Width Signifies the width of the I/O or Memory operation. - @param[in] Address The base address of the I/O operation. - @param[in] Count The number of I/O operations to perform. The number= of - bytes moved is Width size * Count, starting at Addr= ess. - @param[out] Buffer For read operations, the destination buffer to stor= e the results. - For write operations, the source buffer from which = to write data. - - @retval EFI_SUCCESS The data was read from or written to the = PI system. - @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. - @retval EFI_INVALID_PARAMETER Buffer is NULL. - @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. - @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, - and Count is not valid for this PI system. - -**/ -STATIC -EFI_STATUS -EFIAPI -CpuMemoryServiceRead ( - IN EFI_CPU_IO2_PROTOCOL *This, - IN EFI_CPU_IO_PROTOCOL_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - OUT VOID *Buffer - ) -{ - EFI_STATUS Status; - UINT8 InStride; - UINT8 OutStride; - EFI_CPU_IO_PROTOCOL_WIDTH OperationWidth; - UINT8 *Uint8Buffer; - - Status =3D CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Select loop based on the width of the transfer - // - InStride =3D mInStride[Width]; - OutStride =3D mOutStride[Width]; - OperationWidth =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); - for (Uint8Buffer =3D Buffer; Count > 0; Address +=3D InStride, Uint8Buff= er +=3D OutStride, Count--) { - if (OperationWidth =3D=3D EfiCpuIoWidthUint8) { - *Uint8Buffer =3D MmioRead8 ((UINTN)Address); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint16) { - *((UINT16 *)Uint8Buffer) =3D MmioRead16 ((UINTN)Address); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint32) { - *((UINT32 *)Uint8Buffer) =3D MmioRead32 ((UINTN)Address); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint64) { - *((UINT64 *)Uint8Buffer) =3D MmioRead64 ((UINTN)Address); - } - } - - return EFI_SUCCESS; -} - -/** - Writes memory-mapped registers. - - The I/O operations are carried out exactly as requested. The caller is r= esponsible - for satisfying any alignment and I/O width restrictions that a PI System= on a - platform might require. For example on some platforms, width requests of - EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will - be handled by the driver. - - If Width is EfiCpuIoWidthUint8, EfiCpuIoWidthUint16, EfiCpuIoWidthUint32, - or EfiCpuIoWidthUint64, then both Address and Buffer are incremented for - each of the Count operations that is performed. - - If Width is EfiCpuIoWidthFifoUint8, EfiCpuIoWidthFifoUint16, - EfiCpuIoWidthFifoUint32, or EfiCpuIoWidthFifoUint64, then only Buffer is - incremented for each of the Count operations that is performed. The read= or - write operation is performed Count times on the same Address. - - If Width is EfiCpuIoWidthFillUint8, EfiCpuIoWidthFillUint16, - EfiCpuIoWidthFillUint32, or EfiCpuIoWidthFillUint64, then only Address is - incremented for each of the Count operations that is performed. The read= or - write operation is performed Count times from the first element of Buffe= r. - - @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance. - @param[in] Width Signifies the width of the I/O or Memory operation. - @param[in] Address The base address of the I/O operation. - @param[in] Count The number of I/O operations to perform. The number= of - bytes moved is Width size * Count, starting at Addr= ess. - @param[in] Buffer For read operations, the destination buffer to stor= e the results. - For write operations, the source buffer from which = to write data. - - @retval EFI_SUCCESS The data was read from or written to the = PI system. - @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. - @retval EFI_INVALID_PARAMETER Buffer is NULL. - @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. - @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, - and Count is not valid for this PI system. - -**/ -STATIC -EFI_STATUS -EFIAPI -CpuMemoryServiceWrite ( - IN EFI_CPU_IO2_PROTOCOL *This, - IN EFI_CPU_IO_PROTOCOL_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - IN VOID *Buffer - ) -{ - EFI_STATUS Status; - UINT8 InStride; - UINT8 OutStride; - EFI_CPU_IO_PROTOCOL_WIDTH OperationWidth; - UINT8 *Uint8Buffer; - - Status =3D CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Select loop based on the width of the transfer - // - InStride =3D mInStride[Width]; - OutStride =3D mOutStride[Width]; - OperationWidth =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); - for (Uint8Buffer =3D Buffer; Count > 0; Address +=3D InStride, Uint8Buff= er +=3D OutStride, Count--) { - if (OperationWidth =3D=3D EfiCpuIoWidthUint8) { - MmioWrite8 ((UINTN)Address, *Uint8Buffer); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint16) { - MmioWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer)); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint32) { - MmioWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer)); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint64) { - MmioWrite64 ((UINTN)Address, *((UINT64 *)Uint8Buffer)); - } - } - - return EFI_SUCCESS; -} - -/** - Reads I/O registers. - - The I/O operations are carried out exactly as requested. The caller is r= esponsible - for satisfying any alignment and I/O width restrictions that a PI System= on a - platform might require. For example on some platforms, width requests of - EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will - be handled by the driver. - - If Width is EfiCpuIoWidthUint8, EfiCpuIoWidthUint16, EfiCpuIoWidthUint32, - or EfiCpuIoWidthUint64, then both Address and Buffer are incremented for - each of the Count operations that is performed. - - If Width is EfiCpuIoWidthFifoUint8, EfiCpuIoWidthFifoUint16, - EfiCpuIoWidthFifoUint32, or EfiCpuIoWidthFifoUint64, then only Buffer is - incremented for each of the Count operations that is performed. The read= or - write operation is performed Count times on the same Address. - - If Width is EfiCpuIoWidthFillUint8, EfiCpuIoWidthFillUint16, - EfiCpuIoWidthFillUint32, or EfiCpuIoWidthFillUint64, then only Address is - incremented for each of the Count operations that is performed. The read= or - write operation is performed Count times from the first element of Buffe= r. - - @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance. - @param[in] Width Signifies the width of the I/O or Memory operation. - @param[in] Address The base address of the I/O operation. - @param[in] Count The number of I/O operations to perform. The number= of - bytes moved is Width size * Count, starting at Addr= ess. - @param[out] Buffer For read operations, the destination buffer to stor= e the results. - For write operations, the source buffer from which = to write data. - - @retval EFI_SUCCESS The data was read from or written to the = PI system. - @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. - @retval EFI_INVALID_PARAMETER Buffer is NULL. - @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. - @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, - and Count is not valid for this PI system. - -**/ -STATIC -EFI_STATUS -EFIAPI -CpuIoServiceRead ( - IN EFI_CPU_IO2_PROTOCOL *This, - IN EFI_CPU_IO_PROTOCOL_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - OUT VOID *Buffer - ) -{ - EFI_STATUS Status; - UINT8 InStride; - UINT8 OutStride; - EFI_CPU_IO_PROTOCOL_WIDTH OperationWidth; - UINT8 *Uint8Buffer; - - Status =3D CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer); - if (EFI_ERROR (Status)) { - return Status; - } - - Address +=3D PcdGet64 (PcdPciIoTranslation); - - // - // Select loop based on the width of the transfer - // - InStride =3D mInStride[Width]; - OutStride =3D mOutStride[Width]; - OperationWidth =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); - - for (Uint8Buffer =3D Buffer; Count > 0; Address +=3D InStride, Uint8Buff= er +=3D OutStride, Count--) { - if (OperationWidth =3D=3D EfiCpuIoWidthUint8) { - *Uint8Buffer =3D MmioRead8 ((UINTN)Address); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint16) { - *((UINT16 *)Uint8Buffer) =3D MmioRead16 ((UINTN)Address); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint32) { - *((UINT32 *)Uint8Buffer) =3D MmioRead32 ((UINTN)Address); - } - } - - return EFI_SUCCESS; -} - -/** - Write I/O registers. - - The I/O operations are carried out exactly as requested. The caller is r= esponsible - for satisfying any alignment and I/O width restrictions that a PI System= on a - platform might require. For example on some platforms, width requests of - EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, = will - be handled by the driver. - - If Width is EfiCpuIoWidthUint8, EfiCpuIoWidthUint16, EfiCpuIoWidthUint32, - or EfiCpuIoWidthUint64, then both Address and Buffer are incremented for - each of the Count operations that is performed. - - If Width is EfiCpuIoWidthFifoUint8, EfiCpuIoWidthFifoUint16, - EfiCpuIoWidthFifoUint32, or EfiCpuIoWidthFifoUint64, then only Buffer is - incremented for each of the Count operations that is performed. The read= or - write operation is performed Count times on the same Address. - - If Width is EfiCpuIoWidthFillUint8, EfiCpuIoWidthFillUint16, - EfiCpuIoWidthFillUint32, or EfiCpuIoWidthFillUint64, then only Address is - incremented for each of the Count operations that is performed. The read= or - write operation is performed Count times from the first element of Buffe= r. - - @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance. - @param[in] Width Signifies the width of the I/O or Memory operation. - @param[in] Address The base address of the I/O operation. - @param[in] Count The number of I/O operations to perform. The number= of - bytes moved is Width size * Count, starting at Addr= ess. - @param[in] Buffer For read operations, the destination buffer to stor= e the results. - For write operations, the source buffer from which = to write data. - - @retval EFI_SUCCESS The data was read from or written to the = PI system. - @retval EFI_INVALID_PARAMETER Width is invalid for this PI system. - @retval EFI_INVALID_PARAMETER Buffer is NULL. - @retval EFI_UNSUPPORTED The Buffer is not aligned for the given W= idth. - @retval EFI_UNSUPPORTED The address range specified by Address, W= idth, - and Count is not valid for this PI system. - -**/ -STATIC -EFI_STATUS -EFIAPI -CpuIoServiceWrite ( - IN EFI_CPU_IO2_PROTOCOL *This, - IN EFI_CPU_IO_PROTOCOL_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - IN VOID *Buffer - ) -{ - EFI_STATUS Status; - UINT8 InStride; - UINT8 OutStride; - EFI_CPU_IO_PROTOCOL_WIDTH OperationWidth; - UINT8 *Uint8Buffer; - - // - // Make sure the parameters are valid - // - Status =3D CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer); - if (EFI_ERROR (Status)) { - return Status; - } - - Address +=3D PcdGet64 (PcdPciIoTranslation); - - // - // Select loop based on the width of the transfer - // - InStride =3D mInStride[Width]; - OutStride =3D mOutStride[Width]; - OperationWidth =3D (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03); - - for (Uint8Buffer =3D (UINT8 *)Buffer; Count > 0; Address +=3D InStride, = Uint8Buffer +=3D OutStride, Count--) { - if (OperationWidth =3D=3D EfiCpuIoWidthUint8) { - MmioWrite8 ((UINTN)Address, *Uint8Buffer); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint16) { - MmioWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer)); - } else if (OperationWidth =3D=3D EfiCpuIoWidthUint32) { - MmioWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer)); - } - } - - return EFI_SUCCESS; -} - -// -// CPU I/O 2 Protocol instance -// -STATIC EFI_CPU_IO2_PROTOCOL mCpuIo2 =3D { - { - CpuMemoryServiceRead, - CpuMemoryServiceWrite - }, - { - CpuIoServiceRead, - CpuIoServiceWrite - } -}; - -/** - The user Entry Point for module CpuIo2Dxe. The user code starts with thi= s function. - - @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. - @param[in] SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The entry point is executed successfully. - @retval other Some error occurs when executing this entry po= int. - -**/ -EFI_STATUS -EFIAPI -PciCpuIo2Initialize ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_STATUS Status; - - ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiCpuIo2ProtocolGuid); - Status =3D gBS->InstallMultipleProtocolInterfaces ( - &mHandle, - &gEfiCpuIo2ProtocolGuid, - &mCpuIo2, - NULL - ); - ASSERT_EFI_ERROR (Status); - - return Status; -} diff --git a/OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf b/OvmfPkg/Risc= VVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf deleted file mode 100644 index 4f78cfa406..0000000000 --- a/OvmfPkg/RiscVVirt/PciCpuIo2Dxe/PciCpuIo2Dxe.inf +++ /dev/null @@ -1,48 +0,0 @@ -## @file -# Produces the CPU I/O 2 Protocol by using the services of the I/O Librar= y. -# -# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
-# Copyright (c) 2016, Linaro Ltd. All rights reserved.
-# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
-# -# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -[Defines] - INF_VERSION =3D 0x0001001B - BASE_NAME =3D PciCpuIo2Dxe - FILE_GUID =3D 9BD3C765-2579-4CF0-9349-D77205565030 - MODULE_TYPE =3D DXE_DRIVER - VERSION_STRING =3D 1.0 - ENTRY_POINT =3D PciCpuIo2Initialize - -# -# The following information is for reference only and not required by the = build tools. -# -# VALID_ARCHITECTURES =3D RISCV64 -# - -[Sources] - PciCpuIo2Dxe.c - -[Packages] - OvmfPkg/OvmfPkg.dec - MdePkg/MdePkg.dec - -[LibraryClasses] - UefiDriverEntryPoint - BaseLib - DebugLib - IoLib - PcdLib - UefiBootServicesTableLib - -[Pcd] - gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation - -[Protocols] - gEfiCpuIo2ProtocolGuid ## PRODUCES - -[Depex] - TRUE --=20 2.27.0 -=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 (#114548): https://edk2.groups.io/g/devel/message/114548 Mute This Topic: https://groups.io/mt/103971666/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- From nobody Thu Dec 26 20:24:45 2024 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+114549+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+114549+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250621; cv=none; d=zohomail.com; s=zohoarc; b=S6vAYew5EtILLZDKhR3hMX8sHSuEylzhv8/CxmVcG4vwsoTt/IuxBVdHjGk4gZbLvpO01ARCEgmEcz5X+YUdH16uAHZSPjQgHETXaZY7C2ORZfXDwOioZoouJ0vspu8Bc+tJLPEcd74/5VKTn13J0mhnBgTxgC7V2xO0FunEe+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250621; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=9RLyxg9i/i7sOvSWILQY+tJDyRxA3m9G7V2qBZ/rgdg=; b=myl/35/O2eRR6P/uwhOE4jr4BWSBHAj4EfJSZRhtcd9JZimcJtAp34iXp/hcB1nFwrpahjJfWgLwp+cXEzzdMA+cKs5nnZSYaaSJp02qBCsR5S8Kobe+W/RR++e1GtNvc5Yq5BKGQ+GAGmfbAQ9IDWW88JLN7+UjTFOCqJpYE0Y= 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+114549+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250621140454.08078240349505; Thu, 25 Jan 2024 22:30:21 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=24HrPJsS6AWzaYQe1Wd81O19KqLaf7Oo0kHUqx+pd9Y=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250620; v=1; b=IrYB6MZKn+uJDO/udsli/Kqsde00siI91APqYHfUOLccuUwpQ4YX2AWSG6yuRgGi6sTkj4qS V2wbu9m/XTEZgfyD/TRjUbrB6JUwXTrnI23AiqnWPbSk8gQ/nGgpLTGdrL7SW8jBxm+aolLD0XL D9/4sxwgsDHQZaKq6vU9ZAlA= X-Received: by 127.0.0.2 with SMTP id lwFVYY1788612xQ4fzCoMVn8; Thu, 25 Jan 2024 22:30:20 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10018.1706250619341554196 for ; Thu, 25 Jan 2024 22:30:20 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8Dxfet2UbNlih4GAA--.21336S3; Fri, 26 Jan 2024 14:30:14 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxX890UbNlCnMbAA--.53216S2; Fri, 26 Jan 2024 14:30:12 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Leif Lindholm , Sami Mujawar , Gerd Hoffmann , Jiewen Yao Subject: [edk2-devel] [PATCH v8 23/37] ArmVirtPkg: Move the FdtSerialPortAddressLib to OvmfPkg Date: Fri, 26 Jan 2024 14:30:12 +0800 Message-Id: <20240126063012.3102286-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxX890UbNlCnMbAA--.53216S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBcsD X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: n67M5V9AJzTEkzGDH4sMlpmQx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250622394100001 Content-Type: text/plain; charset="utf-8" Move the FdtSerialPortAddressLib to Ovmfpkg so that other ARCH can easily use it. Build-tested only (with "ArmVirtQemu.dsc and OvmfPkgX64.dsc"). BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Cc: Jiewen Yao Cc: Laszlo Ersek Signed-off-by: Chao Li --- ArmVirtPkg/ArmVirt.dsc.inc | 2 +- ArmVirtPkg/ArmVirtPkg.dec | 1 - .../Include/Library/FdtSerialPortAddressLib.h | 0 .../Library/FdtSerialPortAddressLib/FdtSerialPortAddressLib.c | 0 .../FdtSerialPortAddressLib/FdtSerialPortAddressLib.inf | 2 +- OvmfPkg/OvmfPkg.dec | 4 ++++ 6 files changed, 6 insertions(+), 3 deletions(-) rename {ArmVirtPkg =3D> OvmfPkg}/Include/Library/FdtSerialPortAddressLib.h= (100%) rename {ArmVirtPkg =3D> OvmfPkg}/Library/FdtSerialPortAddressLib/FdtSerial= PortAddressLib.c (100%) rename {ArmVirtPkg =3D> OvmfPkg}/Library/FdtSerialPortAddressLib/FdtSerial= PortAddressLib.inf (90%) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 9b23ef97ec..2bc6a29eb1 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -122,7 +122,7 @@ # ARM PL011 UART Driver PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf SerialPortLib|ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPor= tLib.inf - FdtSerialPortAddressLib|ArmVirtPkg/Library/FdtSerialPortAddressLib/FdtSe= rialPortAddressLib.inf + FdtSerialPortAddressLib|OvmfPkg/Library/FdtSerialPortAddressLib/FdtSeria= lPortAddressLib.inf =20 PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCof= fExtraActionLib.inf #PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePe= CoffExtraActionLibNull.inf diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec index 05d2d36c1d..a658c91031 100644 --- a/ArmVirtPkg/ArmVirtPkg.dec +++ b/ArmVirtPkg/ArmVirtPkg.dec @@ -27,7 +27,6 @@ =20 [LibraryClasses] ArmVirtMemInfoLib|Include/Library/ArmVirtMemInfoLib.h - FdtSerialPortAddressLib|Include/Library/FdtSerialPortAddressLib.h =20 [Guids.common] gArmVirtTokenSpaceGuid =3D { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0= x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } } diff --git a/ArmVirtPkg/Include/Library/FdtSerialPortAddressLib.h b/OvmfPkg= /Include/Library/FdtSerialPortAddressLib.h similarity index 100% rename from ArmVirtPkg/Include/Library/FdtSerialPortAddressLib.h rename to OvmfPkg/Include/Library/FdtSerialPortAddressLib.h diff --git a/ArmVirtPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddres= sLib.c b/OvmfPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddressLib.c similarity index 100% rename from ArmVirtPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddress= Lib.c rename to OvmfPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddressLib.c diff --git a/ArmVirtPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddres= sLib.inf b/OvmfPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddressLib.= inf similarity index 90% rename from ArmVirtPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddress= Lib.inf rename to OvmfPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddressLib.i= nf index ae6d0d374b..e27742e9fa 100644 --- a/ArmVirtPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddressLib.inf +++ b/OvmfPkg/Library/FdtSerialPortAddressLib/FdtSerialPortAddressLib.inf @@ -18,9 +18,9 @@ FdtSerialPortAddressLib.c =20 [Packages] - ArmVirtPkg/ArmVirtPkg.dec EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] BaseLib diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 7bc2bf1674..13e69e6648 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -29,6 +29,10 @@ ## @libraryclass Verify blobs read from the VMM BlobVerifierLib|Include/Library/BlobVerifierLib.h =20 + ## @libraryclass FdtSerialPortAddressLib + # + FdtSerialPortAddressLib|Include/Library/FdtSerialPortAddressLib.h + ## @libraryclass Loads and boots a Linux kernel image # LoadLinuxLib|Include/Library/LoadLinuxLib.h --=20 2.27.0 -=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 (#114549): https://edk2.groups.io/g/devel/message/114549 Mute This Topic: https://groups.io/mt/103971668/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- From nobody Thu Dec 26 20:24:45 2024 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+114550+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+114550+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250621; cv=none; d=zohomail.com; s=zohoarc; b=FIffW0KmRG691KzSSETrWHumWz1leMX/pASXWfnLJu2vkqEKKwQc3GwlRKyTNdR4BYOpAozs54ZsbcFZwAHm/iGV8gpV1XeAaOoHPJv+TIV127SCuorpgWNQeCTeg14xXE8JqO1IekV149sY9uIu4nrY5YEy3/4SyaKF+zcw3uM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250621; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=DkiXvqueV+Gu7XhqwOFzqbShjLs+WTBBI92RxjbN8EQ=; b=Tlben9UXyBt/UnSQxaPn4nJfRmlLf8BMpwKZvDOltCpE9106EBMba1hN2djhGcMhyOsFmPo19VaZ/SdRz5Hzi3IViJQvQu9WP83SeTDTsvZddYU2yOkcYL2jzXg6rh2admdrf9i4xvKY5VbqNJF6SaHF2AyVSnOvgDHWuwxz2a8= 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+114550+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250621517878.5310085346882; Thu, 25 Jan 2024 22:30:21 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=RSpVWXZbozrXyZjP3TIwtXEkTJvOSTuLh5q+/4AFcG8=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250621; v=1; b=k5r9kBjSi//Y1dag7v6efDqFWuMmq2Brwmh0MeZj8fHZjB+0D6Rkuqxem/I34bCJt4/ER2HX vwhNTcC/uAx+ghxdz5yYOZSEvmmZrIJSugSCUdNg6CxXFDVPEYDz1MNey/xSbO9OWw0uS+fU36x /Bt0Dg8JYWpxNKFMnqm8pwSc= X-Received: by 127.0.0.2 with SMTP id setCYY1788612xhbp3UUwSi1; Thu, 25 Jan 2024 22:30:21 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10155.1706250619634367361 for ; Thu, 25 Jan 2024 22:30:20 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxXOl6UbNllh4GAA--.11496S3; Fri, 26 Jan 2024 14:30:18 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx_c55UbNlF3MbAA--.53357S2; Fri, 26 Jan 2024 14:30:17 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Leif Lindholm , Sami Mujawar , Gerd Hoffmann , Jiewen Yao Subject: [edk2-devel] [PATCH v8 24/37] ArmVirtPkg: Move two PCD variables into OvmfPkg Date: Fri, 26 Jan 2024 14:30:17 +0800 Message-Id: <20240126063017.3102349-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cx_c55UbNlF3MbAA--.53357S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBdsC X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 1XDVoaSY5YRpQO6FFqYplkuOx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250622434100002 Content-Type: text/plain; charset="utf-8" Move the PcdTerminalTypeGuidBuffer and PcdUninstallMemAttrProtocol into OvmfPkg so other ARCH can easily use it. Build-tested only (with "ArmVirtQemu.dsc and OvmfPkgX64.dsc"). BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Cc: Jiewen Yao Signed-off-by: Chao Li --- ArmVirtPkg/ArmVirtPkg.dec | 13 ------------- ArmVirtPkg/ArmVirtQemu.dsc | 2 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +- .../PlatformBootManagerLib.inf | 5 ++--- OvmfPkg/OvmfPkg.dec | 13 +++++++++++++ 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec index a658c91031..6aa5ea05f4 100644 --- a/ArmVirtPkg/ArmVirtPkg.dec +++ b/ArmVirtPkg/ArmVirtPkg.dec @@ -41,21 +41,8 @@ gArmVirtTokenSpaceGuid.PcdTpm2SupportEnabled|FALSE|BOOLEAN|0x00000004 =20 [PcdsFixedAtBuild, PcdsPatchableInModule] - # - # Binary representation of the GUID that determines the terminal type. T= he - # size must be exactly 16 bytes. The default value corresponds to - # EFI_VT_100_GUID. - # - gArmVirtTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x65, 0x60, 0xA6, 0xDF= , 0x19, 0xB4, 0xD3, 0x11, 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D}|V= OID*|0x00000007 - ## # This is the physical address of Rsdp which is the core struct of Acpi. # Cloud Hypervisor has no other way to pass Rsdp address to the guest ex= cept use a PCD. # gArmVirtTokenSpaceGuid.PcdCloudHvAcpiRsdpBaseAddress|0x0|UINT64|0x000000= 05 - - ## - # Whether the EFI memory attributes protocol should be uninstalled before - # invoking the OS loader. This may be needed to work around problematic - # builds of shim that use the protocol incorrectly. - gArmVirtTokenSpaceGuid.PcdUninstallMemAttrProtocol|FALSE|BOOLEAN|0x00000= 006 diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index dbd2396c78..147180f645 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -182,7 +182,7 @@ !if $(TTY_TERMINAL) =3D=3D TRUE gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 # Set terminal type to TtyTerm, the value encoded is EFI_TTY_TERM_GUID - gArmVirtTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x80, 0x6d, 0x91, 0x7d= , 0xb1, 0x5b, 0x8c, 0x45, 0xa4, 0x8f, 0xe2, 0x5f, 0xdd, 0x51, 0xef, 0x94} + gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x80, 0x6d, 0x91, = 0x7d, 0xb1, 0x5b, 0x8c, 0x45, 0xa4, 0x8f, 0xe2, 0x5f, 0xdd, 0x51, 0xef, 0x9= 4} !else gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|1 !endif diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index 6a6ecfc12a..c22a422353 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -147,7 +147,7 @@ !if $(TTY_TERMINAL) =3D=3D TRUE gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 # Set terminal type to TtyTerm, the value encoded is EFI_TTY_TERM_GUID - gArmVirtTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x80, 0x6d, 0x91, 0x7d= , 0xb1, 0x5b, 0x8c, 0x45, 0xa4, 0x8f, 0xe2, 0x5f, 0xdd, 0x51, 0xef, 0x94} + gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x80, 0x6d, 0x91, = 0x7d, 0xb1, 0x5b, 0x8c, 0x45, 0xa4, 0x8f, 0xe2, 0x5f, 0xdd, 0x51, 0xef, 0x9= 4} !else gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|1 !endif diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerL= ib.inf b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.i= nf index 70e4ebf94a..8e7cd5605f 100644 --- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -29,7 +29,6 @@ QemuKernel.c =20 [Packages] - ArmVirtPkg/ArmVirtPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec @@ -56,15 +55,15 @@ UefiRuntimeServicesTableLib =20 [FixedPcd] - gArmVirtTokenSpaceGuid.PcdUninstallMemAttrProtocol gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits + gUefiOvmfPkgTokenSpaceGuid.PcdUninstallMemAttrProtocol =20 [Pcd] - gArmVirtTokenSpaceGuid.PcdTerminalTypeGuidBuffer gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut + gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer =20 [Guids] gEfiEndOfDxeEventGroupGuid diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 13e69e6648..fbc81e4c80 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -405,6 +405,19 @@ # gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeAllocationPadding|256|UINT32|0x6f =20 + # + # Binary representation of the GUID that determines the terminal type. T= he + # size must be exactly 16 bytes. The default value corresponds to + # EFI_VT_100_GUID. + # + gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x65, 0x60, 0xA6, = 0xDF, 0x19, 0xB4, 0xD3, 0x11, 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4= D}|VOID*|0x66 + + ## + # Whether the EFI memory attributes protocol should be uninstalled before + # invoking the OS loader. This may be needed to work around problematic + # builds of shim that use the protocol incorrectly. + gUefiOvmfPkgTokenSpaceGuid.PcdUninstallMemAttrProtocol|FALSE|BOOLEAN|0x67 + [PcdsFeatureFlag] gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0= x1c gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN= |0x1d --=20 2.27.0 -=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 (#114550): https://edk2.groups.io/g/devel/message/114550 Mute This Topic: https://groups.io/mt/103971670/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- From nobody Thu Dec 26 20:24:45 2024 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+114551+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+114551+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250626; cv=none; d=zohomail.com; s=zohoarc; b=PQc6hZBZqf1el1wVnW+TSGFoqypwPYwDYQ2X2xerTqq260lTcpiXxT4VkNO52zlQD4FBO3bdQz8ITQk+5KltXK/OChKgRUDop3xsPMx8G4aG3WBR+Ts9Bi9uylk/G6VO3CZQSHkTvtzR/pxJkPaRxx1AAS7rOfmaQC3r9mcjfWQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250626; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=wKLVho+VXaYlGaR0LtAuN+hSAwOnR58OQ8huUQm8Zek=; b=IiJcomjSw5FxUgv7cWC/6LM6gIiykvy5sNq0s+vPJ1afzauMZZqSIpLdxAu0hwj0TglHgIKkZefIPbiSpBrnVFA4VNf4CDZcIO+VeHm5ZV7FjjPxA1MJrITSb+6IUaKLzHEhVjduj3qduHPf5lG+LR8lY/fy+yWLOd7PPZcQE1E= 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+114551+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250626645547.8216456416652; Thu, 25 Jan 2024 22:30:26 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=ZMj8K4LqDmiz8NGwkquOKccPhIR6UJ2YPkYisH0cXV8=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250626; v=1; b=ltr247J0Lezod5Vk9SoIAk5DFlIT4RQzCdf2Ed77p5qjAejGtygWvjs21n6UeO41AVuf0oUy b2dqYb3eLj40O0ZDlyNtJTGjin0YQVKNSkfnpPBke1QK7+s5VuYrfVqRhbMT+21ia1BUHQ1xjo9 wC3cgEBGSwCy9oDGNBWBEQ5M= X-Received: by 127.0.0.2 with SMTP id iMyPYY1788612xP300iyp4mQ; Thu, 25 Jan 2024 22:30:26 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10158.1706250625255461032 for ; Thu, 25 Jan 2024 22:30:25 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8DxWPB_UbNloh4GAA--.21761S3; Fri, 26 Jan 2024 14:30:23 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dxfs1+UbNlHHMbAA--.51153S2; Fri, 26 Jan 2024 14:30:22 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Leif Lindholm , Sami Mujawar , Gerd Hoffmann , Jiewen Yao Subject: [edk2-devel] [PATCH v8 25/37] ArmVirtPkg: Move PlatformBootManagerLib to OvmfPkg Date: Fri, 26 Jan 2024 14:30:21 +0800 Message-Id: <20240126063021.3102412-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dxfs1+UbNlHHMbAA--.51153S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBfsA X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: y1e5XCV6bJne8HLlTKkOW6hyx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250628391100003 Content-Type: text/plain; charset="utf-8" Moved the PlatformBootManagerLib to OvmfPkg and renamed to PlatformBootManagerLibLight for easy use by other ARCH. Build-tested only (with "ArmVirtQemu.dsc and OvmfPkgX64.dsc"). BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Cc: Jiewen Yao Cc: Lazlo Ersek Signed-off-by: Chao Li --- ArmVirtPkg/ArmVirtPkg.ci.yaml | 1 - ArmVirtPkg/ArmVirtQemu.dsc | 2 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +- .../Library/PlatformBootManagerLibLight}/PlatformBm.c | 0 .../Library/PlatformBootManagerLibLight}/PlatformBm.h | 0 .../PlatformBootManagerLibLight}/PlatformBootManagerLib.inf | 2 +- .../Library/PlatformBootManagerLibLight}/QemuKernel.c | 0 7 files changed, 3 insertions(+), 4 deletions(-) rename {ArmVirtPkg/Library/PlatformBootManagerLib =3D> OvmfPkg/Library/Pla= tformBootManagerLibLight}/PlatformBm.c (100%) rename {ArmVirtPkg/Library/PlatformBootManagerLib =3D> OvmfPkg/Library/Pla= tformBootManagerLibLight}/PlatformBm.h (100%) rename {ArmVirtPkg/Library/PlatformBootManagerLib =3D> OvmfPkg/Library/Pla= tformBootManagerLibLight}/PlatformBootManagerLib.inf (93%) rename {ArmVirtPkg/Library/PlatformBootManagerLib =3D> OvmfPkg/Library/Pla= tformBootManagerLibLight}/QemuKernel.c (100%) diff --git a/ArmVirtPkg/ArmVirtPkg.ci.yaml b/ArmVirtPkg/ArmVirtPkg.ci.yaml index 506b0e72f0..b186d4eb42 100644 --- a/ArmVirtPkg/ArmVirtPkg.ci.yaml +++ b/ArmVirtPkg/ArmVirtPkg.ci.yaml @@ -24,7 +24,6 @@ ], ## Both file path and directory path are accepted. "IgnoreFiles": [ - "Library/PlatformBootManagerLib/PlatformBm.c" ] }, ## options defined .pytool/Plugin/CompilerPlugin diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 147180f645..e48c75b5e9 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -70,7 +70,7 @@ =20 CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf - PlatformBootManagerLib|ArmVirtPkg/Library/PlatformBootManagerLib/Platfor= mBootManagerLib.inf + PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLibLight/Platf= ormBootManagerLib.inf PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrin= tScLib.inf CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index c22a422353..668a65ba64 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -69,7 +69,7 @@ =20 CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf - PlatformBootManagerLib|ArmVirtPkg/Library/PlatformBootManagerLib/Platfor= mBootManagerLib.inf + PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLibLight/Platf= ormBootManagerLib.inf PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrin= tScLib.inf CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c b/OvmfP= kg/Library/PlatformBootManagerLibLight/PlatformBm.c similarity index 100% rename from ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c rename to OvmfPkg/Library/PlatformBootManagerLibLight/PlatformBm.c diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.h b/OvmfP= kg/Library/PlatformBootManagerLibLight/PlatformBm.h similarity index 100% rename from ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.h rename to OvmfPkg/Library/PlatformBootManagerLibLight/PlatformBm.h diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerL= ib.inf b/OvmfPkg/Library/PlatformBootManagerLibLight/PlatformBootManagerLib= .inf similarity index 93% rename from ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLi= b.inf rename to OvmfPkg/Library/PlatformBootManagerLibLight/PlatformBootManagerLi= b.inf index 8e7cd5605f..f2fb69bd3c 100644 --- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/OvmfPkg/Library/PlatformBootManagerLibLight/PlatformBootManagerLib.inf @@ -20,7 +20,7 @@ # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D ARM AARCH64 +# VALID_ARCHITECTURES =3D ARM AARCH64 LOONGARCH64 # =20 [Sources] diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c b/OvmfP= kg/Library/PlatformBootManagerLibLight/QemuKernel.c similarity index 100% rename from ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c rename to OvmfPkg/Library/PlatformBootManagerLibLight/QemuKernel.c --=20 2.27.0 -=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 (#114551): https://edk2.groups.io/g/devel/message/114551 Mute This Topic: https://groups.io/mt/103971673/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- From nobody Thu Dec 26 20:24:45 2024 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+114552+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+114552+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250635; cv=none; d=zohomail.com; s=zohoarc; b=aeXz55qgHK6qAAo8UeblVfXuBQAuuNlA2cJiBTqcvTXwf3KgtklrnVrmLCljOqO4tHZZ/pUtV+U1mx25C4Np3ZgPYHyFyX7LAXcYayYrCYXl1knRIVp10MLvgC6hjx8V7CloblwqRc7wdZUE+zGpo/y4blVbt2aX5Soi409L/4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250635; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=9CRORqVhiqDRIjuMcIY8RnzeQLCnbCfH/xVOLupd8mA=; b=iUy9NIr21ebBtth+nme0GzuNggBps4KAEazas47wOBbXQZ5R2SihLBeNDqat/4Uvj+OhI0OQIjJJEwqI1DVdU6yv4D3BX6gb3/rUw4zglPENzLOOWrZrXRa8Q655B5U+c/W/8zyMfTtLdnJOBqyczm876Y5uQe0DS48O7j+c6Zs= 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+114552+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250635056741.9791387360921; Thu, 25 Jan 2024 22:30:35 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Z9Ubhcu26/w6z5UqXGHfjBVrOwQcsTqFqKMhyB9kxQo=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250634; v=1; b=lM8VDhH7dr40nmM8szppcBB4E50XIe81fUYQunkK5zVD9WZAdMKkZqRNIuYxUiFXfyCviUhh YAGcrrWW7fV7eq4KLS4ls9HEnUh6uY3lsQFPmVuqF5PY+Qyb+10ZnA6WxHEeZM1Pz3DTAyKI60x w1uPt9G2cJl+tyrkyKpPo6lE= X-Received: by 127.0.0.2 with SMTP id YffgYY1788612xOrJlRuSVdh; Thu, 25 Jan 2024 22:30:34 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10160.1706250633280311760 for ; Thu, 25 Jan 2024 22:30:34 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8AxqvCEUbNlrx4GAA--.22046S3; Fri, 26 Jan 2024 14:30:28 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxHs+DUbNlKnMbAA--.52940S2; Fri, 26 Jan 2024 14:30:27 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Baoqi Zhang Subject: [edk2-devel] [PATCH v8 26/37] OvmfPkg/LoongArchVirt: Add stable timer driver Date: Fri, 26 Jan 2024 14:30:26 +0800 Message-Id: <20240126063026.3102474-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxHs+DUbNlKnMbAA--.52940S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBgs- X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: pIjIRRAZLJyUIG7dpF5Wewjox1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250636414100002 Content-Type: text/plain; charset="utf-8" Add a CPU timer driver named StableTimerDxe, which proviedes EFI_TIMER_ARCH_PROTOCOL for LoongArch. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Baoqi Zhang Reviewed-by: Bibo Mao --- .../Drivers/StableTimerDxe/Timer.c | 381 ++++++++++++++++++ .../Drivers/StableTimerDxe/Timer.h | 127 ++++++ .../Drivers/StableTimerDxe/TimerDxe.inf | 41 ++ 3 files changed, 549 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.c create mode 100644 OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.h create mode 100644 OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/TimerDxe.i= nf diff --git a/OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.c b/OvmfPkg= /LoongArchVirt/Drivers/StableTimerDxe/Timer.c new file mode 100644 index 0000000000..0e0f10970a --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.c @@ -0,0 +1,381 @@ +/** @file + Timer Architectural Protocol as defined in the DXE CIS + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include "Timer.h" + +// +// The handle onto which the Timer Architectural Protocol will be installed +// +EFI_HANDLE mTimerHandle =3D NULL; +EFI_EVENT EfiExitBootServicesEvent =3D (EFI_EVENT)NULL; + +// +// The Timer Architectural Protocol that this driver produces +// +EFI_TIMER_ARCH_PROTOCOL mTimer =3D { + TimerDriverRegisterHandler, + TimerDriverSetTimerPeriod, + TimerDriverGetTimerPeriod, + TimerDriverGenerateSoftInterrupt +}; + +// +// Pointer to the CPU Architectural Protocol instance +// +EFI_CPU_ARCH_PROTOCOL *mCpu; + +// +// The notification function to call on every timer interrupt. +// A bug in the compiler prevents us from initializing this here. +// +EFI_TIMER_NOTIFY mTimerNotifyFunction; + +/** + Sets the counter value for timer. + + @param Count The 16-bit counter value to program into stable timer. + + @retval VOID +**/ +VOID +SetPitCount ( + IN UINT64 Count + ) +{ + if (Count <=3D 4) { + return; + } + + Count &=3D LOONGARCH_CSR_TMCFG_TIMEVAL; + Count |=3D LOONGARCH_CSR_TMCFG_EN | LOONGARCH_CSR_TMCFG_PERIOD; + CsrWrite (LOONGARCH_CSR_TMCFG, Count); +} + +/** + Timer Interrupt Handler. + + @param InterruptType The type of interrupt that occurred + @param SystemContext A pointer to the system context when the interru= pt occurred + + @retval VOID +**/ +VOID +EFIAPI +TimerInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_SYSTEM_CONTEXT SystemContext + ) +{ + EFI_TPL OriginalTPL; + + OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); + + // + // Clear interrupt. + // + CsrWrite (LOONGARCH_CSR_TINTCLR, 0x1); + + if (mTimerNotifyFunction !=3D NULL) { + // + // @bug : This does not handle missed timer interrupts + // + mTimerNotifyFunction (mTimerPeriod); + } + + gBS->RestoreTPL (OriginalTPL); +} + +/** + This function registers the handler NotifyFunction so it is called every= time + the timer interrupt fires. It also passes the amount of time since the = last + handler call to the NotifyFunction. If NotifyFunction is NULL, then the + handler is unregistered. If the handler is registered, then EFI_SUCCESS= is + returned. If the CPU does not support registering a timer interrupt han= dler, + then EFI_UNSUPPORTED is returned. If an attempt is made to register a h= andler + when a handler is already registered, then EFI_ALREADY_STARTED is return= ed. + If an attempt is made to unregister a handler when a handler is not regi= stered, + then EFI_INVALID_PARAMETER is returned. If an error occurs attempting to + register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ER= ROR + is returned. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param NotifyFunction The function to call when a timer interrupt fire= s. This + function executes at TPL_HIGH_LEVEL. The DXE Co= re will + register a handler for the timer interrupt, so i= t can know + how much time has passed. This information is u= sed to + signal timer based events. NULL will unregister= the handler. + + @retval EFI_SUCCESS The timer handler was registered. + @retval EFI_UNSUPPORTED The platform does not support time= r interrupts. + @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a = handler is already + registered. + @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a hand= ler was not + previously registered. + @retval EFI_DEVICE_ERROR The timer handler could not be reg= istered. +**/ +EFI_STATUS +EFIAPI +TimerDriverRegisterHandler ( + IN EFI_TIMER_ARCH_PROTOCOL *This, + IN EFI_TIMER_NOTIFY NotifyFunction + ) +{ + // + // Check for invalid parameters + // + if ((NotifyFunction =3D=3D NULL) && (mTimerNotifyFunction =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if ((NotifyFunction !=3D NULL) && (mTimerNotifyFunction !=3D NULL)) { + return EFI_ALREADY_STARTED; + } + + mTimerNotifyFunction =3D NotifyFunction; + + return EFI_SUCCESS; +} + +/** + This function adjusts the period of timer interrupts to the value specif= ied + by TimerPeriod. If the timer period is updated, then the selected timer + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. = If + the timer hardware is not programmable, then EFI_UNSUPPORTED is returned. + If an error occurs while attempting to update the timer period, then the + timer hardware will be put back in its state prior to this call, and + EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer inter= rupt + is disabled. This is not the same as disabling the CPU's interrupts. + Instead, it must either turn off the timer hardware, or it must adjust t= he + interrupt controller so that a CPU interrupt is not generated when the t= imer + interrupt fires. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param TimerPeriod The rate to program the timer interrupt in 100 nS= units. If + the timer hardware is not programmable, then EFI_= UNSUPPORTED is + returned. If the timer is programmable, then the= timer period + will be rounded up to the nearest timer period th= at is supported + by the timer hardware. If TimerPeriod is set to = 0, then the + timer interrupts will be disabled. + + @retval EFI_SUCCESS The timer period was changed. + @retval EFI_UNSUPPORTED The platform cannot change the period o= f the timer interrupt. + @retval EFI_DEVICE_ERROR The timer period could not be changed d= ue to a device error. +**/ +EFI_STATUS +EFIAPI +TimerDriverSetTimerPeriod ( + IN EFI_TIMER_ARCH_PROTOCOL *This, + IN UINT64 TimerPeriod + ) +{ + UINT64 TimerCount; + + if (TimerPeriod =3D=3D 0) { + // + // Disable timer interrupt for a TimerPeriod of 0 + // + mCpu->DisableInterrupt (mCpu); + } else { + TimerCount =3D TimerPeriod * GetPerformanceCounterProperties (NULL, NU= LL) / 10000000ULL; + + if (TimerCount >=3D BIT48) { + TimerCount =3D 0; + } + + // + // Program the stable timer with the new count value + // + mTimerTicks =3D TimerCount; + SetPitCount (TimerCount); + + // + // Enable timer interrupt + // + mCpu->EnableInterrupt (mCpu); + } + + // + // Save the new timer period + // + mTimerPeriod =3D TimerPeriod; + + return EFI_SUCCESS; +} + +/** + This function retrieves the period of timer interrupts in 100 ns units, + returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPer= iod + is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 = is + returned, then the timer is currently disabled. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param TimerPeriod A pointer to the timer period to retrieve in 100 = ns units. If + 0 is returned, then the timer is currently disabl= ed. + + @retval EFI_SUCCESS The timer period was returned in TimerPer= iod. + @retval EFI_INVALID_PARAMETER TimerPeriod is NULL. +**/ +EFI_STATUS +EFIAPI +TimerDriverGetTimerPeriod ( + IN EFI_TIMER_ARCH_PROTOCOL *This, + OUT UINT64 *TimerPeriod + ) +{ + if (TimerPeriod =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + *TimerPeriod =3D mTimerPeriod; + + return EFI_SUCCESS; +} + +/** + Disable the timer + DXE Core will disable the timer after all the event handlers have run. + + @param[in] Event The Event that is being processed + @param[in] Context Event Context +**/ +VOID +EFIAPI +ExitBootServicesEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + /* + * Disable timer interrupt when exiting boot service + */ + CsrWrite (LOONGARCH_CSR_TMCFG, 0x0); +} + +/** + This function generates a soft timer interrupt. If the platform does not= support soft + timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCE= SS is returned. + If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.Reg= isterHandler () + service, then a soft timer interrupt will be generated. If the timer int= errupt is + enabled when this service is called, then the registered handler will be= invoked. The + registered handler should not be able to distinguish a hardware-generate= d timer + interrupt from a software-generated timer interrupt. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + + @retval EFI_SUCCESS The soft timer interrupt was generated. + @retval EFI_UNSUPPORTED The platform does not support the generation o= f soft timer interrupts. +**/ +EFI_STATUS +EFIAPI +TimerDriverGenerateSoftInterrupt ( + IN EFI_TIMER_ARCH_PROTOCOL *This + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Initialize the Timer Architectural Protocol driver + + @param ImageHandle ImageHandle of the loaded driver + @param SystemTable Pointer to the System Table + + @retval EFI_SUCCESS Timer Architectural Protocol created + @retval EFI_OUT_OF_RESOURCES Not enough resources available to initial= ize driver. + @retval EFI_DEVICE_ERROR A device error occurred attempting to ini= tialize the driver. +**/ +EFI_STATUS +EFIAPI +StableTimerDriverInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UINT32 TimerVector; + + // + // Initialize the pointer to our notify function. + // + mTimerNotifyFunction =3D NULL; + + // + // Make sure the Timer Architectural Protocol is not already installed i= n the system + // + ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiTimerArchProtocolGuid); + + // + // Find the CPU architectural protocol. + // + Status =3D gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **= )&mCpu); + ASSERT_EFI_ERROR (Status); + + // + // Force the timer to be disabled + // + Status =3D TimerDriverSetTimerPeriod (&mTimer, 0); + ASSERT_EFI_ERROR (Status); + + // + // Calculate const frequence + // + DEBUG (( + DEBUG_INFO, + "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3DStable timer freq %d Hz=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D\n", + GetPerformanceCounterProperties (NULL, NULL) + )); + + // + // Install interrupt handler for Stable Timer #0 (ISA IRQ0) + // + TimerVector =3D EXCEPT_LOONGARCH_INT_TIMER; + Status =3D mCpu->RegisterInterruptHandler (mCpu, TimerVector, Timer= InterruptHandler); + ASSERT_EFI_ERROR (Status); + + // + // Enable TI local timer interrupt + // + EnableLocalInterrupts (1 << EXCEPT_LOONGARCH_INT_TIMER); + + // + // Force the timer to be enabled at its default period + // + Status =3D TimerDriverSetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATI= ON); + ASSERT_EFI_ERROR (Status); + + // + // Install the Timer Architectural Protocol onto a new handle + // + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &mTimerHandle, + &gEfiTimerArchProtocolGuid, + &mTimer, + NULL + ); + + ASSERT_EFI_ERROR (Status); + + // Register for an ExitBootServicesEvent + Status =3D gBS->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, + TPL_NOTIFY, + ExitBootServicesEvent, + NULL, + &EfiExitBootServicesEvent + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.h b/OvmfPkg= /LoongArchVirt/Drivers/StableTimerDxe/Timer.h new file mode 100644 index 0000000000..5efccdfa44 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/Timer.h @@ -0,0 +1,127 @@ +/** @file + Private data structures + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef TIMER_H_ +#define TIMER_H_ + +#include + +#define DEFAULT_TIMER_TICK_DURATION 100000 // 10ms =3D 100000 100 ns units + +// +// The current period of the timer interrupt +// +volatile UINT64 mTimerPeriod =3D 0; +volatile UINT64 mTimerTicks =3D 0; + +/** + This function adjusts the period of timer interrupts to the value specif= ied + by TimerPeriod. If the timer period is updated, then the selected timer + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. = If + the timer hardware is not programmable, then EFI_UNSUPPORTED is returned. + If an error occurs while attempting to update the timer period, then the + timer hardware will be put back in its state prior to this call, and + EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer inter= rupt + is disabled. This is not the same as disabling the CPU's interrupts. + Instead, it must either turn off the timer hardware, or it must adjust t= he + interrupt controller so that a CPU interrupt is not generated when the t= imer + interrupt fires. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param NotifyFunction The rate to program the timer interrupt in 100 nS= units. If + the timer hardware is not programmable, then EFI_= UNSUPPORTED is + returned. If the timer is programmable, then the= timer period + will be rounded up to the nearest timer period th= at is supported + by the timer hardware. If TimerPeriod is set to = 0, then the + timer interrupts will be disabled. + + @retval EFI_SUCCESS The timer period was changed. + @retval EFI_UNSUPPORTED The platform cannot change the period o= f the timer interrupt. + @retval EFI_DEVICE_ERROR The timer period could not be changed d= ue to a device error. +**/ +EFI_STATUS +EFIAPI +TimerDriverRegisterHandler ( + IN EFI_TIMER_ARCH_PROTOCOL *This, + IN EFI_TIMER_NOTIFY NotifyFunction + ); + +/** + This function adjusts the period of timer interrupts to the value specif= ied + by TimerPeriod. If the timer period is updated, then the selected timer + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. = If + the timer hardware is not programmable, then EFI_UNSUPPORTED is returned. + If an error occurs while attempting to update the timer period, then the + timer hardware will be put back in its state prior to this call, and + EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer inter= rupt + is disabled. This is not the same as disabling the CPU's interrupts. + Instead, it must either turn off the timer hardware, or it must adjust t= he + interrupt controller so that a CPU interrupt is not generated when the t= imer + interrupt fires. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param TimerPeriod The rate to program the timer interrupt in 100 nS= units. If + the timer hardware is not programmable, then EFI_= UNSUPPORTED is + returned. If the timer is programmable, then the= timer period + will be rounded up to the nearest timer period th= at is supported + by the timer hardware. If TimerPeriod is set to = 0, then the + timer interrupts will be disabled. + + @retval EFI_SUCCESS The timer period was changed. + @retval EFI_UNSUPPORTED The platform cannot change the period o= f the timer interrupt. + @retval EFI_DEVICE_ERROR The timer period could not be changed d= ue to a device error. +**/ +EFI_STATUS +EFIAPI +TimerDriverSetTimerPeriod ( + IN EFI_TIMER_ARCH_PROTOCOL *This, + IN UINT64 TimerPeriod + ); + +/** + This function retrieves the period of timer interrupts in 100 ns units, + returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPer= iod + is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 = is + returned, then the timer is currently disabled. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param TimerPeriod A pointer to the timer period to retrieve in 100 = ns units. If + 0 is returned, then the timer is currently disabl= ed. + + @retval EFI_SUCCESS The timer period was returned in TimerPer= iod. + @retval EFI_INVALID_PARAMETER TimerPeriod is NULL. +**/ +EFI_STATUS +EFIAPI +TimerDriverGetTimerPeriod ( + IN EFI_TIMER_ARCH_PROTOCOL *This, + OUT UINT64 *TimerPeriod + ); + +/** + This function generates a soft timer interrupt. If the platform does not= support soft + timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCE= SS is returned. + If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.Reg= isterHandler() + service, then a soft timer interrupt will be generated. If the timer int= errupt is + enabled when this service is called, then the registered handler will be= invoked. The + registered handler should not be able to distinguish a hardware-generate= d timer + interrupt from a software-generated timer interrupt. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + + @retval EFI_SUCCESS The soft timer interrupt was generated. + @retval EFI_UNSUPPORTED The platform does not support the generation o= f soft timer interrupts. +**/ +EFI_STATUS +EFIAPI +TimerDriverGenerateSoftInterrupt ( + IN EFI_TIMER_ARCH_PROTOCOL *This + ); + +#endif // TIMER_H_ diff --git a/OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/TimerDxe.inf b/Ov= mfPkg/LoongArchVirt/Drivers/StableTimerDxe/TimerDxe.inf new file mode 100644 index 0000000000..7548a1df46 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/TimerDxe.inf @@ -0,0 +1,41 @@ +## @file +# Stable timer driver that provides Timer Arch protocol. +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D Timer + MODULE_UNI_FILE =3D Timer.uni + FILE_GUID =3D AEBE2648-47A9-40FA-83FD-06AA88443BB2 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D StableTimerDriverInitialize + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources] + Timer.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + IoLib + TimerLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEfiCpuArchProtocolGuid ## CONSUMES + gEfiTimerArchProtocolGuid ## PRODUCES + +[depex] + gEfiCpuArchProtocolGuid --=20 2.27.0 -=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 (#114552): https://edk2.groups.io/g/devel/message/114552 Mute This Topic: https://groups.io/mt/103971676/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- From nobody Thu Dec 26 20:24:45 2024 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+114553+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+114553+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250636; cv=none; d=zohomail.com; s=zohoarc; b=C7GOlFbFQsfAfvgKi6YzGB5xiQpV5B45rwKmqJ1uUMQi3Y5WmloFv5TsEcquT2N2wf6g/s4HpIFu6XKCv8Rlgg2VXEf2/oW98jpFnC+cf+GImg8Qu3mAcpGv5RY3u6B6duZTY3bvunqsK6D/e0GaHORLFwqRtIN0TXN0VZ6yX7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250636; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=SCmD1UogbCH9DlleiA8+1GqfCQ4bM3IOZitR7J3buK8=; b=mHJshHa1XpwxRYtCLCWZENGF1Zxf9YEJnfw2ePqa62Otp8+Fky2vz8jQNfqCoovdE0Plh7Fw86ALMyTptBNwzweKdLdToS+EsH15EgwjOtVRy9UHJkacyGPGa3l+th3PX1RYNmm33iDuKOKK8qDhnokQ8WOIf6bIghnGVzycKyQ= 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+114553+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250636018898.3557168769496; Thu, 25 Jan 2024 22:30:36 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=LhCRvsZEoQjG1oDjobYVTk5Rx+2Y3YI+1Je6nkjRODs=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250635; v=1; b=pFDVsIAY0tOUOVbWfahNrU9cPzY1GTUHlnYzhzBdUawKHC1GhGTxaWB6jEPsEnZb2dO/kK3T o1YWKF4BWx2T5AfCUUKruGv3LcGQxA/llrXa0MkPfrwqWpd9kBkboUsp6gFsDQvfe+Q0JqyBxjt EZ/CDBbymiXPo01/2rs6p4BU= X-Received: by 127.0.0.2 with SMTP id Ud7WYY1788612xTXQxXJuTCc; Thu, 25 Jan 2024 22:30:35 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10023.1706250634515194303 for ; Thu, 25 Jan 2024 22:30:35 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8BxOPCJUbNluR4GAA--.21896S3; Fri, 26 Jan 2024 14:30:33 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxXs2IUbNlNHMbAA--.49773S2; Fri, 26 Jan 2024 14:30:32 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian Subject: [edk2-devel] [PATCH v8 27/37] OvmfPkg/LoongArchVirt: Add a NULL library named CollectApResouceLibNull Date: Fri, 26 Jan 2024 14:30:31 +0800 Message-Id: <20240126063031.3102535-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxXs2IUbNlNHMbAA--.49773S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBhs+ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: hryKZkYR1eOoAPriPvNxH8C6x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250636408100001 Content-Type: text/plain; charset="utf-8" This Library is used to collect APs resources, but is currently NULL for OvmfPkg, because it is not used by the LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Reviewed-by: Bibo Mao --- .../CollectApResourceLibNull.c | 38 +++++++++++++++++++ .../CollectApResourceLibNull.inf | 31 +++++++++++++++ .../CollectApResourceLibNull.uni | 9 +++++ 3 files changed, 78 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/C= ollectApResourceLibNull.c create mode 100644 OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/C= ollectApResourceLibNull.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/C= ollectApResourceLibNull.uni diff --git a/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectA= pResourceLibNull.c b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/= CollectApResourceLibNull.c new file mode 100644 index 0000000000..471418f11e --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResour= ceLibNull.c @@ -0,0 +1,38 @@ +/** @file + LoongArch64 CPU Collect AP resource NULL Library functions. + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include "../../../UefiCpuPkg/Library/MpInitLib/LoongArch64/MpLib.h" + +VOID +SaveProcessorResourceData ( + IN PROCESSOR_RESOURCE_DATA * + ); + +VOID +EFIAPI +SaveProcessorResource ( + PROCESSOR_RESOURCE_DATA *mProcessorResource + ) +{ + SaveProcessorResourceData (mProcessorResource); +} + +VOID +EFIAPI +CollectAllProcessorResource ( + VOID + ) +{ + return; +} diff --git a/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectA= pResourceLibNull.inf b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNul= l/CollectApResourceLibNull.inf new file mode 100644 index 0000000000..c166df6bbd --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResour= ceLibNull.inf @@ -0,0 +1,31 @@ +## @file +# LoongArch64 CPU Collect AP resource NULL Library. +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights= reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D CollectApResourceLibNull + MODULE_UNI_FILE =3D CollectApResourceLibNull.uni + FILE_GUID =3D 8C3B54BF-6A9F-E8B4-4D57-67B3AB578DD6 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.1 + LIBRARY_CLASS =3D PEIM + +[Sources.common] + CollectApResourceLibNull.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + HobLib + MemoryAllocationLib + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber diff --git a/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectA= pResourceLibNull.uni b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNul= l/CollectApResourceLibNull.uni new file mode 100644 index 0000000000..d1638ab11e --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/CollectApResouceLibNull/CollectApResour= ceLibNull.uni @@ -0,0 +1,9 @@ +// @file +// LoongArch64 CPU Collect AP resource NULL Library. +// +// Copyright (c) 2024, Loongson Technology Corporation Limited. All right= s reserved.
+// SPDX-License-Identifier: BSD-2-Clause-Patent + +#string STR_MODULE_ABSTRACT #language en-US "CPU Collect AP re= source NULL Library." + +#string STR_MODULE_DESCRIPTION #language en-US "CPU Collect AP re= source NULL Library." --=20 2.27.0 -=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 (#114553): https://edk2.groups.io/g/devel/message/114553 Mute This Topic: https://groups.io/mt/103971677/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- From nobody Thu Dec 26 20:24:45 2024 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+114554+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+114554+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250641; cv=none; d=zohomail.com; s=zohoarc; b=X9AESXHhyEwbEqnVqmNWxrNJ9aLI4bmy/WAjIBKJBq7kgMyqsDKHdn/rV+5y67oxk7Lx7sMKpKxtndPRgf0oMU/RnPQ1OwaBvBQBC31Lri8+skpsGunQ3serwoO/7fjDvT77stm673GQrpiZflAM4CiUatXFi5DQT/xI0AyY+Tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250641; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=3M+Tn6r7CrGcagEaUf+A18oaA0ZGXZKfkCeOWPverWk=; b=fxEwzCRL66VzobncDszrH7HC92GLXMuqx3RT2+pah2SALYWTPVDe3wVG+jcPCsv1W5yrTepO28NoyrkwHT9lZTGYB3++dPfKgwOEJEZ188OdTqaWfXMtHdn6iytiU6v15+iFFe6O7NSNOotOIwBCE9g0IDtKozQG4L7RVrLaS2w= 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+114554+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250641691951.6924269743347; Thu, 25 Jan 2024 22:30:41 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=lc6tFhttxO3eSaEOySjpxJlV6sKblaigNJ5s2bVfWAg=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250641; v=1; b=T2iWx7RMs1CQ8pCgaVpxm2kWSYYvbaqec4+eRONibcxplrKH4ZH3TLQVeBIv10cZnqkB+wSV GH0m4ANdk0o7SJRYab21ivg+YG/qfK/e6mOTbTwywQB2uDN15Mw+ufu2eHER+wf3wBf4GfDtNz7 v4uq9gz0uqlyho038/R2j9BM= X-Received: by 127.0.0.2 with SMTP id i8UPYY1788612xzwu8G46rm0; Thu, 25 Jan 2024 22:30:41 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10164.1706250639872881260 for ; Thu, 25 Jan 2024 22:30:40 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8BxieiOUbNlwR4GAA--.2167S3; Fri, 26 Jan 2024 14:30:38 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Ax3c6NUbNlQHMbAA--.52845S2; Fri, 26 Jan 2024 14:30:37 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian Subject: [edk2-devel] [PATCH v8 28/37] OvmfPkg/LoongArchVirt: Add serial port hook library Date: Fri, 26 Jan 2024 14:30:36 +0800 Message-Id: <20240126063036.3102596-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Ax3c6NUbNlQHMbAA--.52845S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBis9 X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: vcIa9GCo0XOLRfDpWlSSZqjXx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250642503100001 Content-Type: text/plain; charset="utf-8" Add a serial port hook library in LoongArchVirt named Fdt16550SerialProtHookLib, this library is referenced from ArmVirtPkg. LoongArch QEMU virtual machine uses register of LOONGARCH_CSR_KS1 to transfer serial port base addres from the PEI phase to the DXE phase. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Reviewed-by: Bibo Mao --- .../EarlyFdt16550SerialPortHookLib.c | 52 +++++++++++++++++++ .../EarlyFdt16550SerialPortHookLib.inf | 37 +++++++++++++ .../Fdt16550SerialPortHookLib.c | 39 ++++++++++++++ .../Fdt16550SerialPortHookLib.inf | 33 ++++++++++++ .../Fdt16550SerialPortHookLib.uni | 14 +++++ 5 files changed, 175 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib= /EarlyFdt16550SerialPortHookLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib= /EarlyFdt16550SerialPortHookLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib= /Fdt16550SerialPortHookLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib= /Fdt16550SerialPortHookLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib= /Fdt16550SerialPortHookLib.uni diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyF= dt16550SerialPortHookLib.c b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPo= rtHookLib/EarlyFdt16550SerialPortHookLib.c new file mode 100644 index 0000000000..9f1fcc970a --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550= SerialPortHookLib.c @@ -0,0 +1,52 @@ +/** @file + PEI Phase Early Platform Hook Library instance for 16550 Uart. + + Copyright (c) 2020 - 2023, Arm Ltd. All rights reserved.
+ Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** Platform hook to retrieve the 16550 UART base address from the platform + Device tree and store it in the reigster LOONGARCH_CSR_KS1. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter was invalid. + @retval RETURN_NOT_FOUND Serial port information not found. + +**/ +RETURN_STATUS +EFIAPI +PlatformHookSerialPortInitialize ( + VOID + ) +{ + RETURN_STATUS Status; + VOID *DeviceTreeBase; + UINT64 SerialConsoleAddress; + + if (PcdGet64 (PcdSerialRegisterBase) !=3D 0) { + return RETURN_SUCCESS; + } + + DeviceTreeBase =3D (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddr= ess); + if (DeviceTreeBase =3D=3D NULL) { + return RETURN_NOT_FOUND; + } + + Status =3D FdtSerialGetConsolePort (DeviceTreeBase, &SerialConsoleAddres= s); + if (RETURN_ERROR (Status)) { + return Status; + } + + CsrWrite (LOONGARCH_CSR_KS1, (UINTN)SerialConsoleAddress); + + return RETURN_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyF= dt16550SerialPortHookLib.inf b/OvmfPkg/LoongArchVirt/Library/Fdt16550Serial= PortHookLib/EarlyFdt16550SerialPortHookLib.inf new file mode 100644 index 0000000000..55b0c03a01 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550= SerialPortHookLib.inf @@ -0,0 +1,37 @@ +## @file +# PEI Phase Early Platform Hook Library instance for 16550 Uart. +# +# Copyright (c) 2020, ARM Ltd. All rights reserved.
+# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D EarlyFdt16550SerialPortHookLib + MODULE_UNI_FILE =3D Fdt16550SerialPortHookLib.uni + FILE_GUID =3D 6A5FEBCB-C676-A7C1-A96C-B79D4860EEC5 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PlatformHookLib|SEC PEI_CORE PEIM + +[Sources] + EarlyFdt16550SerialPortHookLib.c + +[LibraryClasses] + BaseLib + PcdLib + FdtLib + FdtSerialPortAddressLib + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt165= 50SerialPortHookLib.c b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHoo= kLib/Fdt16550SerialPortHookLib.c new file mode 100644 index 0000000000..fd188f75b8 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550Seria= lPortHookLib.c @@ -0,0 +1,39 @@ +/** @file + Platform Hook Library instance for 16550 Uart. + + Copyright (c) 2020, ARM Ltd. All rights reserved.
+ Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +/** Platform hook to retrieve the 16550 UART base address from register + LOONGARCH_CSR_KS1 that caches the UART base address from early boot + stage and store it in PcdSerialRegisterBase. + + @retval RETURN_SUCCESS Success. + @retval RETURN_NOT_FOUND Serial Port information not found. + +**/ +RETURN_STATUS +EFIAPI +PlatformHookSerialPortInitialize ( + VOID + ) +{ + UINT64 *UartBase; + + if (PcdGet64 (PcdSerialRegisterBase) !=3D 0) { + return RETURN_SUCCESS; + } + + *UartBase =3D CsrRead (LOONGARCH_CSR_KS1); + + return (RETURN_STATUS)PcdSet64S (PcdSerialRegisterBase, (UINTN)*UartBase= ); +} diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt165= 50SerialPortHookLib.inf b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortH= ookLib/Fdt16550SerialPortHookLib.inf new file mode 100644 index 0000000000..b5fc03a284 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550Seria= lPortHookLib.inf @@ -0,0 +1,33 @@ +## @file +# Platform Hook Library instance for 16550 Uart. +# +# Copyright (c) 2020, ARM Ltd. All rights reserved.
+# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D Fdt16550SerialPortHookLib + MODULE_UNI_FILE =3D Fdt16550SerialPortHookLib.uni + FILE_GUID =3D 808335DB-220E-A353-887C-9AA1B7D433A1 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PlatformHookLib|DXE_CORE DXE_DRIVER U= EFI_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION + CONSTRUCTOR =3D PlatformHookSerialPortInitialize + +[Sources] + Fdt16550SerialPortHookLib.c + +[LibraryClasses] + BaseLib + PcdLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase diff --git a/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt165= 50SerialPortHookLib.uni b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortH= ookLib/Fdt16550SerialPortHookLib.uni new file mode 100644 index 0000000000..92eb2ed0b4 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/Fdt16550Seria= lPortHookLib.uni @@ -0,0 +1,14 @@ +// /** @file +// Platform Hook Library instance for 16550 Uart. +// +// +// Copyright (c) 2020, ARM Ltd. All rights reserved.
+// Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Platform Hook Library ins= tance for 16550 Uart." + +#string STR_MODULE_DESCRIPTION #language en-US "Platform Hook Library ins= tance for 16550 Uart." --=20 2.27.0 -=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 (#114554): https://edk2.groups.io/g/devel/message/114554 Mute This Topic: https://groups.io/mt/103971678/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- From nobody Thu Dec 26 20:24:45 2024 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+114555+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+114555+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250647; cv=none; d=zohomail.com; s=zohoarc; b=iBNR4KPHGBqzUMstBKlTwLr+XVJLHdFhULvH6l58HRXfBOlybO5yAA7usayc3Zo5o+SWhdEU4ehpabt/TFH8fEjaBWcD6sO/ZtyR59tTlW0LN76zVA4nfWJjEsgmj973wX8QJWYmejDlA+9lIXbI4bQxSh1djDx3dIf4IOwbBwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250647; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=y4NbGgUACYUPs3h9MmINpuHKDyEMmcPRLtmgTxd0qQU=; b=mtAlK3oCJC9Yg6T0TUqoZ81Q7le6x2zM81XSWKrHSWDUc/lwA7rQKtVnkoCOnkJHs0fM/VxNYAX+XeZ4X8FRKBXty1LLWZjppdIhZkaVJPwy2nQLVOP7j3Toob0twYfnjL9XRa+X9olXPNAxnb5e5EBcp7dvjSHKKnkMixD7w0o= 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+114555+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250647193359.0864996069457; Thu, 25 Jan 2024 22:30:47 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=TNOp1jkt4/tPU7O4EmWQHoFjYIXGvyoBtBIUCneketU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250646; v=1; b=Hay/aErIe1DsEd1QG0unPxNxOE7j3nm5llc6UjB7woCauh+BNqHqbRvVnVl+fOx70+T+lbdc VF+Ua2O/WtS6tXHyGZWm+KwKiBQOzTS6wK+XbxWy0ZOXyF3pIeXuRMSqZ42lG4v+9JgvXxlzymy 39NM4svtwrw5xAEMh1XahiSU= X-Received: by 127.0.0.2 with SMTP id sn1JYY1788612xO4tfPaYoI3; Thu, 25 Jan 2024 22:30:46 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10030.1706250645478246773 for ; Thu, 25 Jan 2024 22:30:46 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8BxTOmSUbNlyx4GAA--.11600S3; Fri, 26 Jan 2024 14:30:42 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxdMyRUbNlTXMbAA--.4753S2; Fri, 26 Jan 2024 14:30:41 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Xianglai Li Subject: [edk2-devel] [PATCH v8 29/37] OvmfPkg/LoongArchVirt: Add the early serial port output library Date: Fri, 26 Jan 2024 14:30:40 +0800 Message-Id: <20240126063040.3102656-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxdMyRUbNlTXMbAA--.4753S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBjs8 X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ht951aPNs9jQy7QsFHQbnIExx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250648503100001 Content-Type: text/plain; charset="utf-8" Add a early serial port output library into LoongArchVirt that named EarlyFdtSerialPortLib16550, this library is referenced from MdeModulePkg. This library is used in the PEI phase. Since the serial port address can not be saved in memory of the LoongArch QEMU virtual machine in the PEI phase, the serial prot base address will be obtained from the FDT before each output. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Reviewed-by: Bibo Mao --- .../EarlyFdtSerialPortLib16550.c | 815 ++++++++++++++++++ .../EarlyFdtSerialPortLib16550.inf | 46 + 2 files changed, 861 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib1655= 0/EarlyFdtSerialPortLib16550.c create mode 100644 OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib1655= 0/EarlyFdtSerialPortLib16550.inf diff --git a/OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib16550/Early= FdtSerialPortLib16550.c b/OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortL= ib16550/EarlyFdtSerialPortLib16550.c new file mode 100644 index 0000000000..8cc108501c --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib16550/EarlyFdtSeri= alPortLib16550.c @@ -0,0 +1,815 @@ +/** @file + 16550 UART Serial Port library functions + + Copyright (c) 2024, Loongson Technology Corporation Limited. All rights = reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +// +// PCI Defintions. +// +#define PCI_BRIDGE_32_BIT_IO_SPACE 0x01 + +// +// 16550 UART register offsets and bitfields +// +#define R_UART_RXBUF 0 // LCR_DLAB =3D 0 +#define R_UART_TXBUF 0 // LCR_DLAB =3D 0 +#define R_UART_BAUD_LOW 0 // LCR_DLAB =3D 1 +#define R_UART_BAUD_HIGH 1 // LCR_DLAB =3D 1 +#define R_UART_IER 1 // LCR_DLAB =3D 0 +#define R_UART_FCR 2 +#define B_UART_FCR_FIFOE BIT0 +#define B_UART_FCR_FIFO64 BIT5 +#define R_UART_LCR 3 +#define B_UART_LCR_DLAB BIT7 +#define R_UART_MCR 4 +#define B_UART_MCR_DTRC BIT0 +#define B_UART_MCR_RTS BIT1 +#define R_UART_LSR 5 +#define B_UART_LSR_RXRDY BIT0 +#define B_UART_LSR_TXRDY BIT5 +#define B_UART_LSR_TEMT BIT6 +#define R_UART_MSR 6 +#define B_UART_MSR_CTS BIT4 +#define B_UART_MSR_DSR BIT5 +#define B_UART_MSR_RI BIT6 +#define B_UART_MSR_DCD BIT7 + +/** + Read an 8-bit 16550 register. If PcdSerialUseMmio is TRUE, then the val= ue is read from + MMIO space. If PcdSerialUseMmio is FALSE, then the value is read from I= /O space. The + parameter Offset is added to the base address of the 16550 registers tha= t is specified + by PcdSerialRegisterBase. PcdSerialRegisterAccessWidth specifies the MMI= O space access + width and defaults to 8 bit access, and supports 8 or 32 bit access. + + @param Base The base address register of UART device. + @param Offset The offset of the 16550 register to read. + + @return The value read from the 16550 register. +**/ +UINT8 +SerialPortReadRegister ( + UINTN Base, + UINTN Offset + ) +{ + if (PcdGetBool (PcdSerialUseMmio)) { + if (PcdGet8 (PcdSerialRegisterAccessWidth) =3D=3D 32) { + return (UINT8)MmioRead32 (Base + Offset * PcdGet32 (PcdSerialRegiste= rStride)); + } + + return MmioRead8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride)); + } else { + return IoRead8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride)); + } +} + +/** + Write an 8-bit 16550 register. If PcdSerialUseMmio is TRUE, then the va= lue is written to + MMIO space. If PcdSerialUseMmio is FALSE, then the value is written to = I/O space. The + parameter Offset is added to the base address of the 16550 registers tha= t is specified + by PcdSerialRegisterBase. PcdSerialRegisterAccessWidth specifies the MMI= O space access + width and defaults to 8 bit access, and supports 8 or 32 bit access. + + @param Base The base address register of UART device. + @param Offset The offset of the 16550 register to write. + @param Value The value to write to the 16550 register specified by Of= fset. + + @return The value written to the 16550 register. +**/ +UINT8 +SerialPortWriteRegister ( + UINTN Base, + UINTN Offset, + UINT8 Value + ) +{ + if (PcdGetBool (PcdSerialUseMmio)) { + if (PcdGet8 (PcdSerialRegisterAccessWidth) =3D=3D 32) { + return (UINT8)MmioWrite32 (Base + Offset * PcdGet32 (PcdSerialRegist= erStride), (UINT8)Value); + } + + return MmioWrite8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride),= Value); + } else { + return IoWrite8 (Base + Offset * PcdGet32 (PcdSerialRegisterStride), V= alue); + } +} + +/** + Retrieve the I/O or MMIO base address register for the PCI UART device. + + This function assumes Root Bus Numer is Zero, and enables I/O and MMIO i= n PCI UART + Device if they are not already enabled. + + @return The base address register of the UART device. +**/ +UINTN +GetSerialRegisterBase ( + VOID + ) +{ + VOID *Base; + RETURN_STATUS Status; + UINT64 SerialConsoleAddress; + + Base =3D (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress); + Status =3D FdtSerialGetConsolePort (Base, &SerialConsoleAddress); + if (RETURN_ERROR (Status)) { + return (UINTN)0; + } + + return SerialConsoleAddress; +} + +/** + Return whether the hardware flow control signal allows writing. + + @param SerialRegisterBase The base address register of UART device. + + @retval TRUE The serial port is writable. + @retval FALSE The serial port is not writable. +**/ +BOOLEAN +SerialPortWritable ( + UINTN SerialRegisterBase + ) +{ + if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { + if (PcdGetBool (PcdSerialDetectCable)) { + // + // Wait for both DSR and CTS to be set + // DSR is set if a cable is connected. + // CTS is set if it is ok to transmit data + // + // DSR CTS Description Action + // =3D=3D=3D =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D + // 0 0 No cable connected. Wait + // 0 1 No cable connected. Wait + // 1 0 Cable connected, but not clear to send. Wait + // 1 1 Cable connected, and clear to send. Transmit + // + return (BOOLEAN)((SerialPortReadRegister (SerialRegisterBase, R_UART= _MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) =3D=3D (B_UART_MSR_DSR | B_UART_= MSR_CTS)); + } else { + // + // Wait for both DSR and CTS to be set OR for DSR to be clear. + // DSR is set if a cable is connected. + // CTS is set if it is ok to transmit data + // + // DSR CTS Description Action + // =3D=3D=3D =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D + // 0 0 No cable connected. Transmit + // 0 1 No cable connected. Transmit + // 1 0 Cable connected, but not clear to send. Wait + // 1 1 Cable connected, and clar to send. Transmit + // + return (BOOLEAN)((SerialPortReadRegister (SerialRegisterBase, R_UART= _MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) !=3D (B_UART_MSR_DSR)); + } + } + + return TRUE; +} + +/** + Initialize the serial device hardware. + + If no initialization is required, then return RETURN_SUCCESS. + If the serial device was successfully initialized, then return RETURN_SU= CCESS. + If the serial device could not be initialized, then return RETURN_DEVICE= _ERROR. + + @retval RETURN_SUCCESS The serial device was initialized. + @retval RETURN_DEVICE_ERROR The serial device could not be initialized. +**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + UINTN SerialRegisterBase; + UINT32 Divisor; + UINT32 CurrentDivisor; + BOOLEAN Initialized; + + // + // Calculate divisor for baud generator + // Ref_Clk_Rate / Baud_Rate / 16 + // + Divisor =3D PcdGet32 (PcdSerialClockRate) / (PcdGet32 (PcdSerialBaudRate= ) * 16); + if ((PcdGet32 (PcdSerialClockRate) % (PcdGet32 (PcdSerialBaudRate) * 16)= ) >=3D PcdGet32 (PcdSerialBaudRate) * 8) { + Divisor++; + } + + // + // Get the base address of the serial port in either I/O or MMIO space + // + SerialRegisterBase =3D GetSerialRegisterBase (); + if (SerialRegisterBase =3D=3D 0) { + return RETURN_DEVICE_ERROR; + } + + // + // See if the serial port is already initialized + // + Initialized =3D TRUE; + if ((SerialPortReadRegister (SerialRegisterBase, R_UART_LCR) & 0x3F) != =3D (PcdGet8 (PcdSerialLineControl) & 0x3F)) { + Initialized =3D FALSE; + } + + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(SerialP= ortReadRegister (SerialRegisterBase, R_UART_LCR) | B_UART_LCR_DLAB)); + CurrentDivisor =3D SerialPortReadRegister (SerialRegisterBase, R_UART_= BAUD_HIGH) << 8; + CurrentDivisor |=3D (UINT32)SerialPortReadRegister (SerialRegisterBase, = R_UART_BAUD_LOW); + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(SerialP= ortReadRegister (SerialRegisterBase, R_UART_LCR) & ~B_UART_LCR_DLAB)); + if (CurrentDivisor !=3D Divisor) { + Initialized =3D FALSE; + } + + if (Initialized) { + return RETURN_SUCCESS; + } + + // + // Wait for the serial port to be ready. + // Verify that both the transmit FIFO and the shift register are empty. + // + while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B_UAR= T_LSR_TEMT | B_UART_LSR_TXRDY)) !=3D (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) { + } + + // + // Configure baud rate + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, B_UART_LCR_DLAB= ); + SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_HIGH, (UINT8)(D= ivisor >> 8)); + SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_LOW, (UINT8)(Di= visor & 0xff)); + + // + // Clear DLAB and configure Data Bits, Parity, and Stop Bits. + // Strip reserved bits from PcdSerialLineControl + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(PcdGet8= (PcdSerialLineControl) & 0x3F)); + + // + // Enable and reset FIFOs + // Strip reserved bits from PcdSerialFifoControl + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, 0x00); + SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, (UINT8)(PcdGet8= (PcdSerialFifoControl) & (B_UART_FCR_FIFOE | B_UART_FCR_FIFO64))); + + // + // Set FIFO Polled Mode by clearing IER after setting FCR + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_IER, 0x00); + + // + // Put Modem Control Register(MCR) into its reset state of 0x00. + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00); + + return RETURN_SUCCESS; +} + +/** + Write data from buffer to serial device. + + Writes NumberOfBytes data bytes from Buffer to the serial device. + The number of bytes actually written to the serial device is returned. + If the return value is less than NumberOfBytes, then the write operation= failed. + + If Buffer is NULL, then ASSERT(). + + If NumberOfBytes is zero, then return 0. + + @param Buffer Pointer to the data buffer to be written. + @param NumberOfBytes Number of bytes to written to the serial device. + + @retval 0 NumberOfBytes is 0. + @retval >0 The number of bytes written to the serial devic= e. + If this value is less than NumberOfBytes, then = the write operation failed. + +**/ +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + UINTN SerialRegisterBase; + UINTN Result; + UINTN Index; + UINTN FifoSize; + + if (Buffer =3D=3D NULL) { + return 0; + } + + SerialRegisterBase =3D GetSerialRegisterBase (); + if (SerialRegisterBase =3D=3D 0) { + return 0; + } + + if (NumberOfBytes =3D=3D 0) { + // + // Flush the hardware + // + + // + // Wait for both the transmit FIFO and shift register empty. + // + while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B_U= ART_LSR_TEMT | B_UART_LSR_TXRDY)) !=3D (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)= ) { + } + + // + // Wait for the hardware flow control signal + // + while (!SerialPortWritable (SerialRegisterBase)) { + } + + return 0; + } + + // + // Compute the maximum size of the Tx FIFO + // + FifoSize =3D 1; + if ((PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFOE) !=3D 0) { + if ((PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFO64) =3D=3D 0) { + FifoSize =3D 16; + } else { + FifoSize =3D PcdGet32 (PcdSerialExtendedTxFifoSize); + } + } + + Result =3D NumberOfBytes; + while (NumberOfBytes !=3D 0) { + // + // Wait for the serial port to be ready, to make sure both the transmi= t FIFO + // and shift register empty. + // + while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B_U= ART_LSR_TEMT | B_UART_LSR_TXRDY)) !=3D (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)= ) { + } + + // + // Fill then entire Tx FIFO + // + for (Index =3D 0; Index < FifoSize && NumberOfBytes !=3D 0; Index++, N= umberOfBytes--, Buffer++) { + // + // Wait for the hardware flow control signal + // + while (!SerialPortWritable (SerialRegisterBase)) { + } + + // + // Write byte to the transmit buffer. + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_TXBUF, *Buffer); + } + } + + return Result; +} + +/** + Reads data from a serial device into a buffer. + + @param Buffer Pointer to the data buffer to store the data re= ad from the serial device. + @param NumberOfBytes Number of bytes to read from the serial device. + + @retval 0 NumberOfBytes is 0. + @retval >0 The number of bytes read from the serial device. + If this value is less than NumberOfBytes, then = the read operation failed. +**/ +UINTN +EFIAPI +SerialPortRead ( + OUT UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + UINTN SerialRegisterBase; + UINTN Result; + UINT8 Mcr; + + if (NULL =3D=3D Buffer) { + return 0; + } + + SerialRegisterBase =3D GetSerialRegisterBase (); + if (SerialRegisterBase =3D=3D 0) { + return 0; + } + + Mcr =3D (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_MCR) = & ~B_UART_MCR_RTS); + + for (Result =3D 0; NumberOfBytes-- !=3D 0; Result++, Buffer++) { + // + // Wait for the serial port to have some data. + // + while ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & B_UA= RT_LSR_RXRDY) =3D=3D 0) { + if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { + // + // Set RTS to let the peer send some data + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, (UINT8)(M= cr | B_UART_MCR_RTS)); + } + } + + if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { + // + // Clear RTS to prevent peer from sending data + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, Mcr); + } + + // + // Read byte from the receive buffer. + // + *Buffer =3D SerialPortReadRegister (SerialRegisterBase, R_UART_RXBUF); + } + + return Result; +} + +/** + Polls a serial device to see if there is any data waiting to be read. + + Polls aserial device to see if there is any data waiting to be read. + If there is data waiting to be read from the serial device, then TRUE is= returned. + If there is no data waiting to be read from the serial device, then FALS= E is returned. + + @retval TRUE Data is waiting to be read from the serial devi= ce. + @retval FALSE There is no data waiting to be read from the se= rial device. +**/ +BOOLEAN +EFIAPI +SerialPortPoll ( + VOID + ) +{ + UINTN SerialRegisterBase; + + SerialRegisterBase =3D GetSerialRegisterBase (); + if (SerialRegisterBase =3D=3D 0) { + return FALSE; + } + + // + // Read the serial port status + // + if ((SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & B_UART_LS= R_RXRDY) !=3D 0) { + if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { + // + // Clear RTS to prevent peer from sending data + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, (UINT8)(Ser= ialPortReadRegister (SerialRegisterBase, R_UART_MCR) & ~B_UART_MCR_RTS)); + } + + return TRUE; + } + + if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { + // + // Set RTS to let the peer send some data + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, (UINT8)(Seria= lPortReadRegister (SerialRegisterBase, R_UART_MCR) | B_UART_MCR_RTS)); + } + + return FALSE; +} + +/** + Sets the control bits on a serial device. + + @param Control Sets the bits of Control that are settable. + + @retval RETURN_SUCCESS The new control bits were set on the seria= l device. + @retval RETURN_UNSUPPORTED The serial device does not support this op= eration. + @retval RETURN_DEVICE_ERROR The serial device is not functioning corre= ctly. +**/ +RETURN_STATUS +EFIAPI +SerialPortSetControl ( + IN UINT32 Control + ) +{ + UINTN SerialRegisterBase; + UINT8 Mcr; + + // + // First determine the parameter is invalid. + // + if ((Control & (~(EFI_SERIAL_REQUEST_TO_SEND | EFI_SERIAL_DATA_TERMINAL_= READY | + EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE))) !=3D 0) + { + return RETURN_UNSUPPORTED; + } + + SerialRegisterBase =3D GetSerialRegisterBase (); + if (SerialRegisterBase =3D=3D 0) { + return RETURN_UNSUPPORTED; + } + + // + // Read the Modem Control Register. + // + Mcr =3D SerialPortReadRegister (SerialRegisterBase, R_UART_MCR); + Mcr &=3D (~(B_UART_MCR_DTRC | B_UART_MCR_RTS)); + + if ((Control & EFI_SERIAL_DATA_TERMINAL_READY) =3D=3D EFI_SERIAL_DATA_TE= RMINAL_READY) { + Mcr |=3D B_UART_MCR_DTRC; + } + + if ((Control & EFI_SERIAL_REQUEST_TO_SEND) =3D=3D EFI_SERIAL_REQUEST_TO_= SEND) { + Mcr |=3D B_UART_MCR_RTS; + } + + // + // Write the Modem Control Register. + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, Mcr); + + return RETURN_SUCCESS; +} + +/** + Retrieve the status of the control bits on a serial device. + + @param Control A pointer to return the current control si= gnals from the serial device. + + @retval RETURN_SUCCESS The control bits were read from the serial= device. + @retval RETURN_UNSUPPORTED The serial device does not support this op= eration. + @retval RETURN_DEVICE_ERROR The serial device is not functioning corre= ctly. +**/ +RETURN_STATUS +EFIAPI +SerialPortGetControl ( + OUT UINT32 *Control + ) +{ + UINTN SerialRegisterBase; + UINT8 Msr; + UINT8 Mcr; + UINT8 Lsr; + + SerialRegisterBase =3D GetSerialRegisterBase (); + if (SerialRegisterBase =3D=3D 0) { + return RETURN_UNSUPPORTED; + } + + *Control =3D 0; + + // + // Read the Modem Status Register. + // + Msr =3D SerialPortReadRegister (SerialRegisterBase, R_UART_MSR); + + if ((Msr & B_UART_MSR_CTS) =3D=3D B_UART_MSR_CTS) { + *Control |=3D EFI_SERIAL_CLEAR_TO_SEND; + } + + if ((Msr & B_UART_MSR_DSR) =3D=3D B_UART_MSR_DSR) { + *Control |=3D EFI_SERIAL_DATA_SET_READY; + } + + if ((Msr & B_UART_MSR_RI) =3D=3D B_UART_MSR_RI) { + *Control |=3D EFI_SERIAL_RING_INDICATE; + } + + if ((Msr & B_UART_MSR_DCD) =3D=3D B_UART_MSR_DCD) { + *Control |=3D EFI_SERIAL_CARRIER_DETECT; + } + + // + // Read the Modem Control Register. + // + Mcr =3D SerialPortReadRegister (SerialRegisterBase, R_UART_MCR); + + if ((Mcr & B_UART_MCR_DTRC) =3D=3D B_UART_MCR_DTRC) { + *Control |=3D EFI_SERIAL_DATA_TERMINAL_READY; + } + + if ((Mcr & B_UART_MCR_RTS) =3D=3D B_UART_MCR_RTS) { + *Control |=3D EFI_SERIAL_REQUEST_TO_SEND; + } + + if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { + *Control |=3D EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE; + } + + // + // Read the Line Status Register. + // + Lsr =3D SerialPortReadRegister (SerialRegisterBase, R_UART_LSR); + + if ((Lsr & (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) =3D=3D (B_UART_LSR_TEMT= | B_UART_LSR_TXRDY)) { + *Control |=3D EFI_SERIAL_OUTPUT_BUFFER_EMPTY; + } + + if ((Lsr & B_UART_LSR_RXRDY) =3D=3D 0) { + *Control |=3D EFI_SERIAL_INPUT_BUFFER_EMPTY; + } + + return RETURN_SUCCESS; +} + +/** + Sets the baud rate, receive FIFO depth, transmit/receice time out, parit= y, + data bits, and stop bits on a serial device. + + @param BaudRate The requested baud rate. A BaudRate value of 0= will use the + device's default interface speed. + On output, the value actually set. + @param ReveiveFifoDepth The requested depth of the FIFO on the receive= side of the + serial interface. A ReceiveFifoDepth value of = 0 will use + the device's default FIFO depth. + On output, the value actually set. + @param Timeout The requested time out for a single character = in microseconds. + This timeout applies to both the transmit and = receive side of the + interface. A Timeout value of 0 will use the d= evice's default time + out value. + On output, the value actually set. + @param Parity The type of parity to use on this serial devic= e. A Parity value of + DefaultParity will use the device's default pa= rity value. + On output, the value actually set. + @param DataBits The number of data bits to use on the serial d= evice. A DataBits + vaule of 0 will use the device's default data = bit setting. + On output, the value actually set. + @param StopBits The number of stop bits to use on this serial = device. A StopBits + value of DefaultStopBits will use the device's= default number of + stop bits. + On output, the value actually set. + + @retval RETURN_SUCCESS The new attributes were set on the ser= ial device. + @retval RETURN_UNSUPPORTED The serial device does not support thi= s operation. + @retval RETURN_INVALID_PARAMETER One or more of the attributes has an u= nsupported value. + @retval RETURN_DEVICE_ERROR The serial device is not functioning c= orrectly. +**/ +RETURN_STATUS +EFIAPI +SerialPortSetAttributes ( + IN OUT UINT64 *BaudRate, + IN OUT UINT32 *ReceiveFifoDepth, + IN OUT UINT32 *Timeout, + IN OUT EFI_PARITY_TYPE *Parity, + IN OUT UINT8 *DataBits, + IN OUT EFI_STOP_BITS_TYPE *StopBits + ) +{ + UINTN SerialRegisterBase; + UINT32 SerialBaudRate; + UINTN Divisor; + UINT8 Lcr; + UINT8 LcrData; + UINT8 LcrParity; + UINT8 LcrStop; + + SerialRegisterBase =3D GetSerialRegisterBase (); + if (SerialRegisterBase =3D=3D 0) { + return RETURN_UNSUPPORTED; + } + + // + // Check for default settings and fill in actual values. + // + if (*BaudRate =3D=3D 0) { + *BaudRate =3D PcdGet32 (PcdSerialBaudRate); + } + + SerialBaudRate =3D (UINT32)*BaudRate; + + if (*DataBits =3D=3D 0) { + LcrData =3D (UINT8)(PcdGet8 (PcdSerialLineControl) & 0x3); + *DataBits =3D LcrData + 5; + } else { + if ((*DataBits < 5) || (*DataBits > 8)) { + return RETURN_INVALID_PARAMETER; + } + + // + // Map 5..8 to 0..3 + // + LcrData =3D (UINT8)(*DataBits - (UINT8)5); + } + + if (*Parity =3D=3D DefaultParity) { + LcrParity =3D (UINT8)((PcdGet8 (PcdSerialLineControl) >> 3) & 0x7); + switch (LcrParity) { + case 0: + *Parity =3D NoParity; + break; + + case 3: + *Parity =3D EvenParity; + break; + + case 1: + *Parity =3D OddParity; + break; + + case 7: + *Parity =3D SpaceParity; + break; + + case 5: + *Parity =3D MarkParity; + break; + + default: + break; + } + } else { + switch (*Parity) { + case NoParity: + LcrParity =3D 0; + break; + + case EvenParity: + LcrParity =3D 3; + break; + + case OddParity: + LcrParity =3D 1; + break; + + case SpaceParity: + LcrParity =3D 7; + break; + + case MarkParity: + LcrParity =3D 5; + break; + + default: + return RETURN_INVALID_PARAMETER; + } + } + + if (*StopBits =3D=3D DefaultStopBits) { + LcrStop =3D (UINT8)((PcdGet8 (PcdSerialLineControl) >> 2) & 0x1); + switch (LcrStop) { + case 0: + *StopBits =3D OneStopBit; + break; + + case 1: + if (*DataBits =3D=3D 5) { + *StopBits =3D OneFiveStopBits; + } else { + *StopBits =3D TwoStopBits; + } + + break; + + default: + break; + } + } else { + switch (*StopBits) { + case OneStopBit: + LcrStop =3D 0; + break; + + case OneFiveStopBits: + case TwoStopBits: + LcrStop =3D 1; + break; + + default: + return RETURN_INVALID_PARAMETER; + } + } + + // + // Calculate divisor for baud generator + // Ref_Clk_Rate / Baud_Rate / 16 + // + Divisor =3D PcdGet32 (PcdSerialClockRate) / (SerialBaudRate * 16); + if ((PcdGet32 (PcdSerialClockRate) % (SerialBaudRate * 16)) >=3D SerialB= audRate * 8) { + Divisor++; + } + + // + // Configure baud rate + // + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, B_UART_LCR_DLAB= ); + SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_HIGH, (UINT8)(D= ivisor >> 8)); + SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_LOW, (UINT8)(Di= visor & 0xff)); + + // + // Clear DLAB and configure Data Bits, Parity, and Stop Bits. + // Strip reserved bits from line control value + // + Lcr =3D (UINT8)((LcrParity << 3) | (LcrStop << 2) | LcrData); + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(Lcr & 0= x3F)); + + return RETURN_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib16550/Early= FdtSerialPortLib16550.inf b/OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPor= tLib16550/EarlyFdtSerialPortLib16550.inf new file mode 100644 index 0000000000..e6a805be6e --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/EarlyFdtSerialPortLib16550/EarlyFdtSeri= alPortLib16550.inf @@ -0,0 +1,46 @@ +## @file +# SerialPortLib instance for 16550 UART. +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights= reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D EarlySerialPortLib16550 + FILE_GUID =3D f4fb883d-8138-4f29-bb0c-c574e9312c74 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.1 + LIBRARY_CLASS =3D SerialPortLib + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + FdtSerialPortAddressLib + IoLib + PcdLib + +[Sources] + EarlyFdtSerialPortLib16550.c + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterAccessWidth ## SOMET= IMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable ## SOMET= IMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSU= MES + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress ## CONSU= MES --=20 2.27.0 -=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 (#114555): https://edk2.groups.io/g/devel/message/114555 Mute This Topic: https://groups.io/mt/103971679/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- From nobody Thu Dec 26 20:24:45 2024 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+114556+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+114556+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250652; cv=none; d=zohomail.com; s=zohoarc; b=krflHZ5chZ9j15aXnhovBGqRVvpRwrBwho4BfE6MAA7QuEBYy/U735GWNv9Y7ud2mXdY4B/HZAWMsW0YkkAgJw6yYWC93fHUr3yBeyK20f4G5xBkSxM27EmmhZsbnffoZo+IAtKYmO2ZjtBMa5xT1JniSAkHL/nHeh76A08v5gI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250652; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=NZYC26pkEHFqhT5cf6ajx0ASUpbYA2mIT7mjI1mvkpg=; b=YAMaa7qBTb9PJv0TUneL+SVeNSdr0PLvAmkRQjQlFq+E1HUD9ybPeKTP3oOwR3uWjybq2CUP9h1QbofYzZiNZohu7N599YH1vbRQyzAWEpzDqMYkOAHiELaf/e6R/x87uo97cbxZwcxf7IwemTB+PdvyrSm2+pSuQ5gY5R5MCGQ= 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+114556+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250652603948.3131591014508; Thu, 25 Jan 2024 22:30:52 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Qv2ypQTaJrfLgO5LBtJI9S9VNHiAgbAHVofmO1s2bzw=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250652; v=1; b=GktAInQWmrmM6l7fyciC9bIkbSv37l+zsZNEuZA+5aEz4G0WCZWDqg2rCBCHgHAnXNVjJAhw f2s1IFEqGcnQV+xh4iWfVgwTA1zjWIuu8C3cL6KSs0gycaHbszyeLbUy5OBgNhNyOTYbIN3N2BX Ww+rZ/g488iDdujipZ+Ibyfw= X-Received: by 127.0.0.2 with SMTP id HCyLYY1788612xIDH7qJsURI; Thu, 25 Jan 2024 22:30:52 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10166.1706250651014647045 for ; Thu, 25 Jan 2024 22:30:51 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxruuYUbNl1x4GAA--.21489S3; Fri, 26 Jan 2024 14:30:48 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxHs+WUbNlWnMbAA--.52944S2; Fri, 26 Jan 2024 14:30:46 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Baoqi Zhang , Xianglai Li Subject: [edk2-devel] [PATCH v8 30/37] OvmfPkg/LoongArchVirt: Add real time clock library Date: Fri, 26 Jan 2024 14:30:45 +0800 Message-Id: <20240126063045.3102720-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxHs+WUbNlWnMbAA--.52944S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+AOvAAAsf X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: k5WSxwHVeXwik0lwrSnMwDfgx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250654452100003 Content-Type: text/plain; charset="utf-8" This library is provides real time clock for LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Baoqi Zhang Co-authored-by: Xianglai Li Reviewed-by: Bibo Mao --- .../DxeLsRealTimeClockLib.c | 327 ++++++++++++++++++ .../DxeLsRealTimeClockLib.inf | 41 +++ .../LsRealTimeClockLib/LsRealTimeClock.h | 47 +++ .../PeiLsRealTimeClockLib.c | 31 ++ .../PeiLsRealTimeClockLib.inf | 29 ++ 5 files changed, 475 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsR= ealTimeClockLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsR= ealTimeClockLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/LsReal= TimeClock.h create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsR= ealTimeClockLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsR= ealTimeClockLib.inf diff --git a/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTime= ClockLib.c b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTime= ClockLib.c new file mode 100644 index 0000000000..e990728069 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTimeClockLi= b.c @@ -0,0 +1,327 @@ +/** @file + Implement EFI RealTimeClock runtime services via RTC Lib. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "LsRealTimeClock.h" + +STATIC BOOLEAN mInitialized =3D FALSE; +STATIC EFI_EVENT mRtcVirtualAddrChangeEvent; +STATIC UINTN mRtcBase; + +/* + Enable Real-time clock. + + @param VOID + + @retval VOID + */ +VOID +InitRtc ( + VOID + ) +{ + UINTN Val; + EFI_HOB_GUID_TYPE *GuidHob =3D NULL; + VOID *DataInHob =3D NULL; + + if (!mInitialized) { + /* Enable rtc */ + GuidHob =3D GetFirstGuidHob (&mRtcRegisterBaseAddressGuid); + if (GuidHob) { + DataInHob =3D GET_GUID_HOB_DATA (GuidHob); + mRtcBase =3D (UINT64)(*(UINTN *)DataInHob); + Val =3D MmioRead32 (mRtcBase + RTC_CTRL_REG); + Val |=3D TOY_ENABLE_BIT | OSC_ENABLE_BIT; + MmioWrite32 (mRtcBase + RTC_CTRL_REG, Val); + mInitialized =3D TRUE; + } else { + DebugPrint (EFI_D_INFO, "RTC register address not found!\n"); + ASSERT (FALSE); + } + } +} + +/** + Returns the current time and date information, and the time-keeping capa= bilities + of the hardware platform. + + @param Time A pointer to storage to receive a snapsho= t of the current time. + @param Capabilities An optional pointer to a buffer to receiv= e the real time clock + device's capabilities. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to ha= rdware error. + @retval EFI_SECURITY_VIOLATION The time could not be retrieved due to an= authentication failure. +**/ +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + UINT32 Val; + + // Ensure Time is a valid pointer + if (Time =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Val =3D MmioRead32 (mRtcBase + TOY_READ1_REG); + Time->Year =3D Val + 1900; + + Val =3D MmioRead32 (mRtcBase + TOY_READ0_REG); + Time->Month =3D (Val >> TOY_MON_SHIFT) & TOY_MON_MASK; + Time->Day =3D (Val >> TOY_DAY_SHIFT) & TOY_DAY_MASK; + Time->Hour =3D (Val >> TOY_HOUR_SHIFT) & TOY_HOUR_MASK; + Time->Minute =3D (Val >> TOY_MIN_SHIFT) & TOY_MIN_MASK; + Time->Second =3D (Val >> TOY_SEC_SHIFT) & TOY_SEC_MASK; + Time->Nanosecond =3D 0; + return EFI_SUCCESS; +} + +/** + Sets the current local time and date information. + + @param Time A pointer to the current time. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The time could not be set due due to hardw= are error. +**/ +EFI_STATUS +EFIAPI +LibSetTime ( + IN EFI_TIME *Time + ) +{ + UINT32 Val; + + // Initialize the hardware if not already done + + Val =3D 0; + Val |=3D (Time->Second << TOY_SEC_SHIFT); + Val |=3D (Time->Minute << TOY_MIN_SHIFT); + Val |=3D (Time->Hour << TOY_HOUR_SHIFT); + Val |=3D (Time->Day << TOY_DAY_SHIFT); + Val |=3D (Time->Month << TOY_MON_SHIFT); + MmioWrite32 (mRtcBase + TOY_WRITE0_REG, Val); + + Val =3D Time->Year - 1900; + MmioWrite32 (mRtcBase + TOY_WRITE1_REG, Val); + return EFI_SUCCESS; +} + +/** + Returns the current wakeup alarm clock setting. + + @param Enabled Indicates if the alarm is currently enable= d or disabled. + @param Pending Indicates if the alarm signal is pending a= nd requires acknowledgement. + @param Time The current alarm setting. + + @retval EFI_SUCCESS The alarm settings were returned. + @retval EFI_INVALID_PARAMETER Any parameter is NULL. + @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due= to a hardware error. +**/ +EFI_STATUS +EFIAPI +LibGetWakeupTime ( + OUT BOOLEAN *Enabled, + OUT BOOLEAN *Pending, + OUT EFI_TIME *Time + ) +{ + // Not a required feature + return EFI_UNSUPPORTED; +} + +/** + Sets the system wakeup alarm clock time. + + @param Enabled Enable or disable the wakeup alarm. + @param Time If Enable is TRUE, the time to set the wak= eup alarm for. + + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm w= as enabled. If + Enable is FALSE, then the wakeup alarm was= disabled. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a = hardware error. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this pl= atform. +**/ +EFI_STATUS +EFIAPI +LibSetWakeupTime ( + IN BOOLEAN Enabled, + OUT EFI_TIME *Time + ) +{ + // Not a required feature + return EFI_UNSUPPORTED; +} + +/** + Fixup internal data so that EFI can be call in virtual mode. + Call the passed in Child Notify event and convert any pointers in + lib to virtual mode. + + @param[in] Event The Event that is being processed + @param[in] Context Event Context +**/ +STATIC +VOID +EFIAPI +VirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // Only needed if you are going to support the OS calling RTC functions = in virtual mode. + // You will need to call EfiConvertPointer (). To convert any stored phy= sical addresses + // to virtual address. After the OS transitions to calling in virtual mo= de, all future + // runtime calls will be made in virtual mode. + // + EfiConvertPointer (0x0, (VOID **)&mRtcBase); + return; +} + +/** Add the RTC controller address range to the memory map. + + @param [in] ImageHandle The handle to the image. + @param [in] RtcPageBase Base address of the RTC controller. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Flash device not found. +**/ +EFI_STATUS +KvmtoolRtcMapMemory ( + IN EFI_HANDLE ImageHandle, + IN EFI_PHYSICAL_ADDRESS RtcPageBase + ) +{ + EFI_STATUS Status; + + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypeMemoryMappedIo, + RtcPageBase, + EFI_PAGE_SIZE, + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Failed to add memory space. Status =3D %r\n", + Status + )); + return Status; + } + + Status =3D gDS->AllocateMemorySpace ( + EfiGcdAllocateAddress, + EfiGcdMemoryTypeMemoryMappedIo, + 0, + EFI_PAGE_SIZE, + &RtcPageBase, + ImageHandle, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Failed to allocate memory space. Status =3D %r\n", + Status + )); + gDS->RemoveMemorySpace ( + RtcPageBase, + EFI_PAGE_SIZE + ); + return Status; + } + + Status =3D gDS->SetMemorySpaceAttributes ( + RtcPageBase, + EFI_PAGE_SIZE, + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Failed to set memory attributes. Status =3D %r\n", + Status + )); + + gDS->FreeMemorySpace ( + RtcPageBase, + EFI_PAGE_SIZE + ); + + gDS->RemoveMemorySpace ( + RtcPageBase, + EFI_PAGE_SIZE + ); + } + + return Status; +} + +/** + This is the declaration of an EFI image entry point. This can be the ent= ry point to an application + written to this specification, an EFI boot service driver, or an EFI run= time driver. + + @param ImageHandle Handle that identifies the loaded image. + @param SystemTable System Table for this image. + + @retval EFI_SUCCESS The operation completed successfully. +**/ +EFI_STATUS +EFIAPI +LibRtcInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + InitRtc (); + Status =3D KvmtoolRtcMapMemory (ImageHandle, (mRtcBase & ~EFI_PAGE_MASK)= ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Failed to map memory for loongson 7A RTC. Status =3D %r\n", + Status + )); + return Status; + } + + // + // Register for the virtual address change event + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + VirtualNotifyEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &mRtcVirtualAddrChangeEvent + ); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTime= ClockLib.inf b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTi= meClockLib.inf new file mode 100644 index 0000000000..4da0fa9f04 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/DxeLsRealTimeClockLi= b.inf @@ -0,0 +1,41 @@ +## @file +# LoongArch64 CPU Real Time Clock DXE Phase Library. +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D LsRealTimeClockLib + FILE_GUID =3D 9793a3da-1869-4fdf-88b1-c6484341f50b + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RealTimeClockLib + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources] + DxeLsRealTimeClockLib.c + +[Packages] + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + DebugLib + DxeServicesTableLib + HobLib + IoLib + PcdLib + UefiRuntimeLib + +[Guids] + gEfiEventVirtualAddressChangeGuid + +[Depex] + TRUE diff --git a/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/LsRealTimeClo= ck.h b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/LsRealTimeClock.h new file mode 100644 index 0000000000..dcd8438c1f --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/LsRealTimeClock.h @@ -0,0 +1,47 @@ +/** @file + Implement EFI RealTimeClock runtime services via RTC Lib. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef LS_REAL_TIME_CLOCK_H_ +#define LS_REAL_TIME_CLOCK_H_ + +#define TOY_WRITE0_REG 0x24 +#define TOY_WRITE1_REG 0x28 +#define TOY_READ0_REG 0x2c +#define TOY_READ1_REG 0x30 +#define RTC_CTRL_REG 0x40 + +/* TOY Enable bits */ +#define RTC_ENABLE_BIT (1UL << 13) +#define TOY_ENABLE_BIT (1UL << 11) +#define OSC_ENABLE_BIT (1UL << 8) + +/* + * shift bits and filed mask + */ +#define TOY_MON_MASK 0x3f +#define TOY_DAY_MASK 0x1f +#define TOY_HOUR_MASK 0x1f +#define TOY_MIN_MASK 0x3f +#define TOY_SEC_MASK 0x3f +#define TOY_MSEC_MASK 0xf + +#define TOY_MON_SHIFT 26 +#define TOY_DAY_SHIFT 21 +#define TOY_HOUR_SHIFT 16 +#define TOY_MIN_SHIFT 10 +#define TOY_SEC_SHIFT 4 + +#define RTC_REGISTER_ADDRESS_HOB_GUID \ + { \ + 0x0d7c012b, 0x79c1, 0xfa58, { 0x6f, 0x91, 0xbe, 0x3e, 0xee, 0x46, 0x5f= , 0x71 } \ + } + +EFI_GUID mRtcRegisterBaseAddressGuid =3D RTC_REGISTER_ADDRESS_HOB_GUID; + +#endif // LS_REAL_TIME_CLOCK_H_ diff --git a/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsRealTime= ClockLib.c b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsRealTime= ClockLib.c new file mode 100644 index 0000000000..6929fb15e4 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsRealTimeClockLi= b.c @@ -0,0 +1,31 @@ +/** @file + Implement EFI RealTimeClock PEI phase RTC Lib. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include "LsRealTimeClock.h" + +VOID +SaveRtcRegisterAddressHob ( + UINT64 RtcRegisterBase + ) +{ + UINT64 Data64; + + // + // Build location of RTC register base address buffer in HOB + // + Data64 =3D (UINT64)(UINTN)RtcRegisterBase; + + BuildGuidDataHob ( + &mRtcRegisterBaseAddressGuid, + (VOID *)&Data64, + sizeof (UINT64) + ); +} diff --git a/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsRealTime= ClockLib.inf b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsRealTi= meClockLib.inf new file mode 100644 index 0000000000..05ed6b2429 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/LsRealTimeClockLib/PeiLsRealTimeClockLi= b.inf @@ -0,0 +1,29 @@ +## @file +# LoongArch64 CPU Real Time Clock PEI Phase Library. +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D PeiLsRealTimeClockLib + FILE_GUID =3D d4358430-15ec-9358-1b12-26dab955e9c6 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RealTimeClockLib|PEIM + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources] + PeiLsRealTimeClockLib.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + HobLib --=20 2.27.0 -=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 (#114556): https://edk2.groups.io/g/devel/message/114556 Mute This Topic: https://groups.io/mt/103971680/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- From nobody Thu Dec 26 20:24:45 2024 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+114557+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+114557+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250658; cv=none; d=zohomail.com; s=zohoarc; b=I6O4TisI3Na14W8W8CSi8xtZNe+9UUv+t1zjJ29ZiUmdkKKRuz6vDrsqUa9fTL8AwbKSQHubSDMYwH8kbVTckx8vwdWxEwHIJ6yMOJf0XEBvuT6O5rvWOa7uOKwkynWFpzZ9Drt8SbnvMyICkh0adUgPUake46Ay0pfB1NwNVXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250658; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=HOyTn2Lt5X05C8fdxbDiVW/I2xJXeZnPjSgZ06ou6T4=; b=hAIcIxXssXVL+hfMcqYRavyHPXHZMM7Grdcl2/btfbSNN26hvnxm4wo3gxJu52uZqoSp8bcla6RGH7naUcnldz0xEtzAQSYlmy7D4FE0lXvi84tcABXh1GVxzi3SOV1i1jx1GH8GvK9UwQHBdi+ynnKGdHuac3rviX6ft4EQDI4= 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+114557+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 170625065801050.922215852505474; Thu, 25 Jan 2024 22:30:58 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=iKZIRLXqJQB8QgSMnzEMt/O0dwkxQUmsY2QmpX7v6xU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250657; v=1; b=CrDigVBKKqPQUCAGlqul4kJ7eGqaPQgOr+dKb32/+Rh/Dltd7ejlUO8p9tKLRIR23cgwnsqE LfRk1Kuf35V0bbHH4//CrlWs4YNKbbBSDoj9hZd6XXrLsknbXJXYZ3dTHFFUVpupAQnD092V7R2 UOQnd8oQr6tgAAgxLX+s4cIA= X-Received: by 127.0.0.2 with SMTP id bscTYY1788612xw08tf3fCSr; Thu, 25 Jan 2024 22:30:57 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10033.1706250656605864590 for ; Thu, 25 Jan 2024 22:30:57 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxF+idUbNl4R4GAA--.2094S3; Fri, 26 Jan 2024 14:30:53 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxXs2cUbNlaHMbAA--.49777S2; Fri, 26 Jan 2024 14:30:52 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Xianglai Li Subject: [edk2-devel] [PATCH v8 31/37] OvmfPkg/LoongArchVirt: Add NorFlashQemuLib Date: Fri, 26 Jan 2024 14:30:51 +0800 Message-Id: <20240126063051.3102784-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxXs2cUbNlaHMbAA--.49777S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+AOvAABse X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: DYvXWGEv7z3h53Aki21au5Jdx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250658537100001 Content-Type: text/plain; charset="utf-8" Add NorFlashQemuLib for LoongArch, it is referenced from ArmVirtPkg. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao Reviewed-by: Bibo Mao --- .../Library/NorFlashQemuLib/NorFlashQemuLib.c | 140 ++++++++++++++++++ .../NorFlashQemuLib/NorFlashQemuLib.inf | 43 ++++++ 2 files changed, 183 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQ= emuLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQ= emuLib.inf diff --git a/OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.= c b/OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.c new file mode 100644 index 0000000000..ae9af09c4c --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.c @@ -0,0 +1,140 @@ +/** @file + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +#include + +#define QEMU_NOR_BLOCK_SIZE SIZE_128KB + +EFI_STATUS +VirtNorFlashPlatformInitialization ( + VOID + ) +{ + return EFI_SUCCESS; +} + +STATIC VIRT_NOR_FLASH_DESCRIPTION mNorFlashDevices; + +EFI_STATUS +VirtNorFlashPlatformGetDevices ( + OUT VIRT_NOR_FLASH_DESCRIPTION **NorFlashDescriptions, + OUT UINT32 *Count + ) +{ + FDT_CLIENT_PROTOCOL *FdtClient; + INT32 Node; + EFI_STATUS Status; + EFI_STATUS FindNodeStatus; + CONST UINT32 *Reg; + UINT32 PropSize; + UINT64 Base; + UINT64 Size; + + Status =3D gBS->LocateProtocol ( + &gFdtClientProtocolGuid, + NULL, + (VOID **)&FdtClient + ); + ASSERT_EFI_ERROR (Status); + + FindNodeStatus =3D FdtClient->FindCompatibleNode ( + FdtClient, + "cfi-flash", + &Node + ); + ASSERT_EFI_ERROR (FindNodeStatus); + + Status =3D FdtClient->GetNodeProperty ( + FdtClient, + Node, + "reg", + (CONST VOID **)&Reg, + &PropSize + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: GetNodeProperty () failed (Status =3D=3D %r)\n", + __func__, + Status + )); + return Status; + } + + ASSERT ((PropSize % (4 * sizeof (UINT32))) =3D=3D 0); + + if (PropSize < (4 * sizeof (UINT32))) { + DEBUG (( + DEBUG_ERROR, + "%a: reg node size(%d) is too small \n", + __func__, + PropSize + )); + return EFI_NOT_FOUND; + } + + Base =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0])); + Size =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2])); + + mNorFlashDevices.DeviceBaseAddress =3D (UINTN)Base; + mNorFlashDevices.RegionBaseAddress =3D (UINTN)Base; + mNorFlashDevices.Size =3D (UINTN)Size; + mNorFlashDevices.BlockSize =3D QEMU_NOR_BLOCK_SIZE; + + Status =3D PcdSet32S (PcdFlashNvStorageVariableBase, Base); + ASSERT_EFI_ERROR (Status); + + /* + * Base is the value of PcdFlashNvStorageVariableBase, + * PcdFlashNvStorageFtwWorkingBase can be got by + * PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize + */ + Base +=3D PcdGet32 (PcdFlashNvStorageVariableSize); + Status =3D PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base); + ASSERT_EFI_ERROR (Status); + + /* + * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase, + * PcdFlashNvStorageFtwSpareBase can be got by + * PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSize. + */ + Base +=3D PcdGet32 (PcdFlashNvStorageFtwWorkingSize); + Status =3D PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base); + ASSERT_EFI_ERROR (Status); + + // + // UEFI takes ownership of the NOR flash, and exposes its functionality + // through the UEFI Runtime Services GetVariable, SetVariable, etc. This + // means we need to disable it in the device tree to prevent the OS from + // attaching its device driver as well. + // Note that this also hides other flash banks, but the only other flash + // bank we expect to encounter is the one that carries the UEFI executab= le + // code, which is not intended to be guest updatable, and is usually bac= ked + // in a readonly manner by QEMU anyway. + // + Status =3D FdtClient->SetNodeProperty ( + FdtClient, + Node, + "status", + "disabled", + sizeof ("disabled") + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "Failed to set NOR flash status to 'disabled'\n")); + } + + *NorFlashDescriptions =3D &mNorFlashDevices; + *Count =3D 1; + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.= inf b/OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.inf new file mode 100644 index 0000000000..671684e738 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/NorFlashQemuLib/NorFlashQemuLib.inf @@ -0,0 +1,43 @@ +## @file +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D NorFlashQemuLib + FILE_GUID =3D E225C90F-6CB9-8AF3-095B-2668FC633A57 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D VirtNorFlashPlatformLib + +[Sources] + NorFlashQemuLib.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiBootServicesTableLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Depex] + gFdtClientProtocolGuid + +[Pcd] +gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize +gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize +gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize +gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase +gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase +gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase --=20 2.27.0 -=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 (#114557): https://edk2.groups.io/g/devel/message/114557 Mute This Topic: https://groups.io/mt/103971681/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- From nobody Thu Dec 26 20:24:45 2024 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+114558+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+114558+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250661; cv=none; d=zohomail.com; s=zohoarc; b=gQx34ACrLvMvQ1SqTYt6ItLis4ZKUrTUpLZYpp45iUzhRv4kjD09Dn2+fzSwm3kGDScR+jnAfw92vzbhsuvRiIrC2QRoV9+7vJ8t2optT4xLpltfec2ft1fvOo1FvIksDNh6HXTYPeTCsRmat+LNyieHyqOlW2+W7vFH52kRNGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250661; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=qmFWJstmHXtv65ZPlzX+b5Gba0PEub4kozBwLxFkIDg=; b=HyreqrtDGmMJ2Z1ZhYjar/3c4Zu9o3kdolrTjc0f/nBQ7lb5N8bA3AnRf6RK2iSAbVgY2sXvQS2Q4ZDxpU1bN3E/0G/TT6lgnmgsxQwg03oE4/wPAVELrk9DlOonekD87S0WJzKiocgrcWNEXtSalMhYYKC4Eh0uhLgMqFi3ML4= 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+114558+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250661387125.02715032672188; Thu, 25 Jan 2024 22:31:01 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=hdqNEMu4+WTDwvJG6hM7hMNP59Xege0VX2kS0LKeqHs=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250661; v=1; b=a0+1LGQHhGQGzShefjvm2N2bxhGdbOSarkxlr79w3i9OkO6G1ibNzq10tk4pa+wSDv3wJObt 0UblZYXNizXqv0qOa8jHpUBKBqrOjEj5VJ3qiU9DxH5IV1TWvZVPIjf0YsTNFg1e8ChTV7h7+u8 USQSJpTFWwtQKl/Hb+hPdSP8= X-Received: by 127.0.0.2 with SMTP id MupAYY1788612xmj2WlJZogK; Thu, 25 Jan 2024 22:31:01 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10170.1706250659795913893 for ; Thu, 25 Jan 2024 22:31:00 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxifCiUbNl7x4GAA--.21854S3; Fri, 26 Jan 2024 14:30:58 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxbs2hUbNle3MbAA--.50697S2; Fri, 26 Jan 2024 14:30:57 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Xianglai Li Subject: [edk2-devel] [PATCH v8 32/37] OvmfPkg/LoongArchVirt: Add FdtQemuFwCfgLib Date: Fri, 26 Jan 2024 14:30:56 +0800 Message-Id: <20240126063056.3102853-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxbs2hUbNle3MbAA--.50697S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+AOvAAEsb X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: DQjsoQLMd9P9PQ2NEVMktKUmx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250662494100001 Content-Type: text/plain; charset="utf-8" This library for PEI phase, and obtains the QemuFwCfg base address by directly parsing the FDT, reads and writes the data in QemuFwCfg by operating on the QemuFwCfg base address. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao Reviewed-by: Bibo Mao --- .../FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.c | 504 ++++++++++++++++++ .../FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.inf | 42 ++ .../FdtQemuFwCfgLib/QemuFwCfgLibInternal.h | 73 +++ .../Library/FdtQemuFwCfgLib/QemuFwCfgPei.c | 117 ++++ 4 files changed, 736 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFw= CfgPeiLib.c create mode 100644 OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFw= CfgPeiLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfg= LibInternal.h create mode 100644 OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfg= Pei.c diff --git a/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiL= ib.c b/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.c new file mode 100644 index 0000000000..a1f114b327 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.c @@ -0,0 +1,504 @@ +/** @file + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - FwCfg - firmWare Configure + - CTL - Control +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "QemuFwCfgLibInternal.h" + +EFI_GUID mFwCfgSelectorAddressGuid =3D FW_CONFIG_SELECTOR_ADDRESS_HOB_GUI= D; +EFI_GUID mFwCfgDataAddressGuid =3D FW_CONFIG_DATA_ADDRESS_HOB_GUID; + +STATIC UINTN mFwCfgSelectorAddress; +STATIC UINTN mFwCfgDataAddress; + +/** + To get firmware configure selector address. + + @param VOID + + @retval firmware configure selector address +**/ +UINTN +EFIAPI +QemuGetFwCfgSelectorAddress ( + VOID + ) +{ + UINTN FwCfgSelectorAddress; + EFI_HOB_GUID_TYPE *GuidHob; + VOID *DataInHob; + + FwCfgSelectorAddress =3D mFwCfgSelectorAddress; + GuidHob =3D NULL; + DataInHob =3D NULL; + + if (FwCfgSelectorAddress =3D=3D 0) { + GuidHob =3D GetFirstGuidHob (&mFwCfgSelectorAddressGuid); + DataInHob =3D GET_GUID_HOB_DATA (GuidHob); + FwCfgSelectorAddress =3D (UINT64)(*(UINTN *)DataInHob); + } + + return FwCfgSelectorAddress; +} + +/** + To get firmware configure Data address. + + @param VOID + + @retval firmware configure data address +**/ +UINTN +EFIAPI +QemuGetFwCfgDataAddress ( + VOID + ) +{ + UINTN FwCfgDataAddress; + EFI_HOB_GUID_TYPE *GuidHob; + VOID *DataInHob; + + FwCfgDataAddress =3D mFwCfgDataAddress; + GuidHob =3D NULL; + DataInHob =3D NULL; + + if (FwCfgDataAddress =3D=3D 0) { + GuidHob =3D GetFirstGuidHob (&mFwCfgDataAddressGuid); + DataInHob =3D GET_GUID_HOB_DATA (GuidHob); + FwCfgDataAddress =3D (UINT64)(*(UINTN *)DataInHob); + } + + return FwCfgDataAddress; +} + +/** + Selects a firmware configuration item for reading. + + Following this call, any data read from this item will start from + the beginning of the configuration item's data. + + @param[in] QemuFwCfgItem - Firmware Configuration item to read +**/ +VOID +EFIAPI +QemuFwCfgSelectItem ( + IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem + ) +{ + UINTN FwCfgSelectorAddress; + + FwCfgSelectorAddress =3D QemuGetFwCfgSelectorAddress (); + MmioWrite16 (FwCfgSelectorAddress, SwapBytes16 ((UINT16)(UINTN)QemuFwCfg= Item)); +} + +/** + Slow READ_BYTES_FUNCTION. + + @param[in] The size of the data to be read. + @param[in] Buffer The buffer that stores the readout data. +**/ +VOID +EFIAPI +MmioReadBytes ( + IN UINTN Size, + IN VOID *Buffer OPTIONAL + ) +{ + UINTN Left; + UINT8 *Ptr; + UINT8 *End; + UINTN FwCfgDataAddress; + + Left =3D Size & 7; + + Size -=3D Left; + Ptr =3D Buffer; + End =3D Ptr + Size; + + FwCfgDataAddress =3D QemuGetFwCfgDataAddress (); + while (Ptr < End) { + *(UINT64 *)Ptr =3D MmioRead64 (FwCfgDataAddress); + Ptr +=3D 8; + } + + if (Left & 4) { + *(UINT32 *)Ptr =3D MmioRead32 (FwCfgDataAddress); + Ptr +=3D 4; + } + + if (Left & 2) { + *(UINT16 *)Ptr =3D MmioRead16 (FwCfgDataAddress); + Ptr +=3D 2; + } + + if (Left & 1) { + *Ptr =3D MmioRead8 (FwCfgDataAddress); + } +} + +/** + Slow WRITE_BYTES_FUNCTION. + + @param[in] The size of the data to be write. + @param[in] Buffer The buffer that stores the writein data. +**/ +VOID +EFIAPI +MmioWriteBytes ( + IN UINTN Size, + IN VOID *Buffer OPTIONAL + ) +{ + UINTN Idx; + UINTN FwCfgDataAddress; + + FwCfgDataAddress =3D QemuGetFwCfgDataAddress (); + for (Idx =3D 0; Idx < Size; ++Idx) { + MmioWrite8 (FwCfgDataAddress, ((UINT8 *)Buffer)[Idx]); + } +} + +/** + Reads firmware configuration bytes into a buffer + + @param[in] Size - Size in bytes to read + @param[in] Buffer - Buffer to store data into (OPTIONAL if Size is 0) +**/ +VOID +EFIAPI +InternalQemuFwCfgReadBytes ( + IN UINTN Size, + IN VOID *Buffer OPTIONAL + ) +{ + if ((InternalQemuFwCfgDmaIsAvailable ()) && + (Size <=3D MAX_UINT32)) + { + InternalQemuFwCfgDmaBytes ((UINT32)Size, Buffer, FW_CFG_DMA_CTL_READ); + return; + } + + MmioReadBytes (Size, Buffer); +} + +/** + Reads firmware configuration bytes into a buffer + + If called multiple times, then the data read will + continue at the offset of the firmware configuration + item where the previous read ended. + + @param[in] Size - Size in bytes to read + @param[in] Buffer - Buffer to store data into +**/ +VOID +EFIAPI +QemuFwCfgReadBytes ( + IN UINTN Size, + IN VOID *Buffer + ) +{ + if (InternalQemuFwCfgIsAvailable ()) { + InternalQemuFwCfgReadBytes (Size, Buffer); + } else { + ZeroMem (Buffer, Size); + } +} + +/** + Write firmware configuration bytes from a buffer + + If called multiple times, then the data written will + continue at the offset of the firmware configuration + item where the previous write ended. + + @param[in] Size - Size in bytes to write + @param[in] Buffer - Buffer to read data from +**/ +VOID +EFIAPI +QemuFwCfgWriteBytes ( + IN UINTN Size, + IN VOID *Buffer + ) +{ + if (InternalQemuFwCfgIsAvailable ()) { + if ((InternalQemuFwCfgDmaIsAvailable ()) && + (Size <=3D MAX_UINT32)) + { + InternalQemuFwCfgDmaBytes ((UINT32)Size, Buffer, FW_CFG_DMA_CTL_WRIT= E); + return; + } + + MmioWriteBytes (Size, Buffer); + } +} + +/** + Skip bytes in the firmware configuration item. + + Increase the offset of the firmware configuration item without transferr= ing + bytes between the item and a caller-provided buffer. Subsequent read, wr= ite + or skip operations will commence at the increased offset. + + @param[in] Size Number of bytes to skip. +**/ +VOID +EFIAPI +QemuFwCfgSkipBytes ( + IN UINTN Size + ) +{ + UINTN ChunkSize; + UINT8 SkipBuffer[256]; + + if (!InternalQemuFwCfgIsAvailable ()) { + return; + } + + if ((InternalQemuFwCfgDmaIsAvailable ()) && + (Size <=3D MAX_UINT32)) + { + InternalQemuFwCfgDmaBytes ((UINT32)Size, NULL, FW_CFG_DMA_CTL_SKIP); + return; + } + + // + // Emulate the skip by reading data in chunks, and throwing it away. The + // implementation below is suitable even for phases where RAM or dynamic + // allocation is not available or appropriate. It also doesn't affect the + // static data footprint for client modules. Large skips are not expecte= d, + // therefore this fallback is not performance critical. The size of + // SkipBuffer is thought not to exert a large pressure on the stack in a= ny + // phase. + // + while (Size > 0) { + ChunkSize =3D MIN (Size, sizeof SkipBuffer); + MmioReadBytes (ChunkSize, SkipBuffer); + Size -=3D ChunkSize; + } +} + +/** + Reads a UINT8 firmware configuration value + + @return Value of Firmware Configuration item read +**/ +UINT8 +EFIAPI +QemuFwCfgRead8 ( + VOID + ) +{ + UINT8 Result; + + QemuFwCfgReadBytes (sizeof (Result), &Result); + + return Result; +} + +/** + Reads a UINT16 firmware configuration value + + @return Value of Firmware Configuration item read +**/ +UINT16 +EFIAPI +QemuFwCfgRead16 ( + VOID + ) +{ + UINT16 Result; + + QemuFwCfgReadBytes (sizeof (Result), &Result); + + return Result; +} + +/** + Reads a UINT32 firmware configuration value + + @return Value of Firmware Configuration item read +**/ +UINT32 +EFIAPI +QemuFwCfgRead32 ( + VOID + ) +{ + UINT32 Result; + + QemuFwCfgReadBytes (sizeof (Result), &Result); + + return Result; +} + +/** + Reads a UINT64 firmware configuration value + + @return Value of Firmware Configuration item read +**/ +UINT64 +EFIAPI +QemuFwCfgRead64 ( + VOID + ) +{ + UINT64 Result; + + QemuFwCfgReadBytes (sizeof (Result), &Result); + + return Result; +} + +/** + Find the configuration item corresponding to the firmware configuration = file. + + @param[in] Name - Name of file to look up. + @param[out] Item - Configuration item corresponding to the file, to be p= assed + to QemuFwCfgSelectItem (). + @param[out] Size - Number of bytes in the file. + + @return RETURN_SUCCESS If file is found. + RETURN_NOT_FOUND If file is not found. + RETURN_UNSUPPORTED If firmware configuration is unavailable. +**/ +RETURN_STATUS +EFIAPI +QemuFwCfgFindFile ( + IN CONST CHAR8 *Name, + OUT FIRMWARE_CONFIG_ITEM *Item, + OUT UINTN *Size + ) +{ + UINT32 Count; + UINT32 Idx; + + if (!InternalQemuFwCfgIsAvailable ()) { + return RETURN_UNSUPPORTED; + } + + QemuFwCfgSelectItem (QemuFwCfgItemFileDir); + Count =3D SwapBytes32 (QemuFwCfgRead32 ()); + + for (Idx =3D 0; Idx < Count; ++Idx) { + UINT32 FileSize; + UINT16 FileSelect; + CHAR8 FileName[QEMU_FW_CFG_FNAME_SIZE]; + + FileSize =3D QemuFwCfgRead32 (); + FileSelect =3D QemuFwCfgRead16 (); + QemuFwCfgRead16 (); // skip the field called "reserved" + InternalQemuFwCfgReadBytes (sizeof (FileName), FileName); + + if (AsciiStrCmp (Name, FileName) =3D=3D 0) { + *Item =3D SwapBytes16 (FileSelect); + *Size =3D SwapBytes32 (FileSize); + return RETURN_SUCCESS; + } + } + + return RETURN_NOT_FOUND; +} + +/** + firmware config initialize. + + @param VOID + + @return RETURN_SUCCESS Initialization succeeded. +**/ +RETURN_STATUS +EFIAPI +FdtQemuFwCfgInitialize ( + VOID + ) +{ + VOID *DeviceTreeBase; + INT32 Node; + INT32 Prev; + CONST CHAR8 *Type; + INT32 Len; + CONST UINT64 *RegProp; + UINT64 FwCfgSelectorAddress; + UINT64 FwCfgDataAddress; + UINT64 FwCfgDataSize; + + DeviceTreeBase =3D (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddr= ess); + ASSERT (DeviceTreeBase !=3D NULL); + // + // Make sure we have a valid device tree blob + // + ASSERT (fdt_check_header (DeviceTreeBase) =3D=3D 0); + + for (Prev =3D 0; ; Prev =3D Node) { + Node =3D fdt_next_node (DeviceTreeBase, Prev, NULL); + if (Node < 0) { + break; + } + + // + // Check for memory node + // + Type =3D fdt_getprop (DeviceTreeBase, Node, "compatible", &Len); + if ((Type) && + (AsciiStrnCmp (Type, "qemu,fw-cfg-mmio", Len) =3D=3D 0)) + { + // + // Get the 'reg' property of this node. For now, we will assume + // two 8 byte quantities for base and size, respectively. + // + RegProp =3D fdt_getprop (DeviceTreeBase, Node, "reg", &Len); + if ((RegProp !=3D 0) && + (Len =3D=3D (2 * sizeof (UINT64)))) + { + FwCfgDataAddress =3D SwapBytes64 (RegProp[0]); + FwCfgDataSize =3D 8; + FwCfgSelectorAddress =3D FwCfgDataAddress + FwCfgDataSize; + + mFwCfgSelectorAddress =3D FwCfgSelectorAddress; + mFwCfgDataAddress =3D FwCfgDataAddress; + + BuildGuidDataHob ( + &mFwCfgSelectorAddressGuid, + (VOID *)&FwCfgSelectorAddress, + sizeof (UINT64) + ); + + BuildGuidDataHob ( + &mFwCfgDataAddressGuid, + (VOID *)&FwCfgDataAddress, + sizeof (UINT64) + ); + break; + } else { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to parse FDT QemuCfg node\n", + __func__ + )); + break; + } + } + } + + return RETURN_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiL= ib.inf b/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.i= nf new file mode 100644 index 0000000000..930933ce7d --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/FdtQemuFwCfgPeiLib.inf @@ -0,0 +1,42 @@ +## @file +# initialized fw_cfg library. +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D FdtQemuFwCfgPeiLib + FILE_GUID =3D cdf9a9d5-7422-4dcb-b41d-607151ad320b + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D FtdQemuFwCfgLib|PEIM + CONSTRUCTOR =3D FdtQemuFwCfgInitialize + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources] + FdtQemuFwCfgPeiLib.c + QemuFwCfgPei.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + FdtLib + HobLib + IoLib + MemoryAllocationLib + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress diff --git a/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfgLibInte= rnal.h b/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfgLibInternal= .h new file mode 100644 index 0000000000..983d1f4849 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfgLibInternal.h @@ -0,0 +1,73 @@ +/** @file + fw_cfg library implementation. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - FwCfg - firmWare Configure +**/ + +#ifndef QEMU_FW_CFG_LIB_INTERNAL_H_ +#define QEMU_FW_CFG_LIB_INTERNAL_H_ + +#define FW_CONFIG_SELECTOR_ADDRESS_HOB_GUID \ + { \ + 0x3cc47b04, 0x0d3e, 0xaa64, { 0x06, 0xa6, 0x4b, 0xdc, 0x9a, 0x2c, 0x61= , 0x19 } \ + } + +#define FW_CONFIG_DATA_ADDRESS_HOB_GUID \ + { \ + 0xef854788, 0x10f3, 0x8e7a, { 0x3e, 0xd0, 0x4d, 0x16, 0xc1, 0x79, 0x55= , 0x2f } \ + } + +/** + Returns a boolean indicating if the firmware configuration interface is + available for library-internal purposes. + + This function never changes fw_cfg state. + + @retval TRUE The interface is available internally. + @retval FALSE The interface is not available internally. +**/ +BOOLEAN +InternalQemuFwCfgIsAvailable ( + VOID + ); + +/** + Returns a boolean indicating whether QEMU provides the DMA-like access m= ethod + for fw_cfg. + + @retval TRUE The DMA-like access method is available. + @retval FALSE The DMA-like access method is unavailable. +**/ +BOOLEAN +InternalQemuFwCfgDmaIsAvailable ( + VOID + ); + +/** + Transfer an array of bytes, or skip a number of bytes, using the DMA + interface. + + @param[in] Size Size in bytes to transfer or skip. + + @param[in,out] Buffer Buffer to read data into or write data from. Ign= ored, + and may be NULL, if Size is zero, or Control is + FW_CFG_DMA_CTL_SKIP. + + @param[in] Control One of the following: + FW_CFG_DMA_CTL_WRITE - write to fw_cfg from Buff= er. + FW_CFG_DMA_CTL_READ - read from fw_cfg into Buf= fer. + FW_CFG_DMA_CTL_SKIP - skip bytes in fw_cfg. +**/ +VOID +InternalQemuFwCfgDmaBytes ( + IN UINT32 Size, + IN OUT VOID *Buffer OPTIONAL, + IN UINT32 Control + ); + +#endif // QEMU_FW_CFG_LIB_INTERNAL_H_ diff --git a/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfgPei.c b= /OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfgPei.c new file mode 100644 index 0000000000..74e778aac7 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/FdtQemuFwCfgLib/QemuFwCfgPei.c @@ -0,0 +1,117 @@ +/** @file + fw_cfg library implementation. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - FwCfg - firmWare Configure +**/ + +#include +#include +#include + +#include "QemuFwCfgLibInternal.h" + +/** + Returns a boolean indicating if the firmware configuration interface + is available or not. + + This function may change fw_cfg state. + + @retval TRUE The interface is available + @retval FALSE The interface is not available +**/ +BOOLEAN +EFIAPI +QemuFwCfgIsAvailable ( + VOID + ) +{ + UINT32 Signature; + UINT32 Revision; + + QemuFwCfgSelectItem (QemuFwCfgItemSignature); + Signature =3D QemuFwCfgRead32 (); + DEBUG ((DEBUG_INFO, "FW CFG Signature: 0x%x\n", Signature)); + QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion); + Revision =3D QemuFwCfgRead32 (); + DEBUG ((DEBUG_INFO, "FW CFG Revision: 0x%x\n", Revision)); + if ((Signature !=3D SIGNATURE_32 ('Q', 'E', 'M', 'U')) || + (Revision < 1)) + { + DEBUG ((DEBUG_INFO, "QemuFwCfg interface not supported.\n")); + return FALSE; + } + + DEBUG ((DEBUG_INFO, "QemuFwCfg interface is supported.\n")); + return TRUE; +} + +/** + Returns a boolean indicating if the firmware configuration interface is + available for library-internal purposes. + + This function never changes fw_cfg state. + + @retval TRUE The interface is available internally. + @retval FALSE The interface is not available internally. +**/ +BOOLEAN +InternalQemuFwCfgIsAvailable ( + VOID + ) +{ + // + // We always return TRUE, because the consumer of this library ought to = have + // called QemuFwCfgIsAvailable before making other calls which would hit= this + // path. + // + return TRUE; +} + +/** + Returns a boolean indicating whether QEMU provides the DMA-like access m= ethod + for fw_cfg. + + @retval TRUE The DMA-like access method is available. + @retval FALSE The DMA-like access method is unavailable. +**/ +BOOLEAN +InternalQemuFwCfgDmaIsAvailable ( + VOID + ) +{ + return FALSE; +} + +/** + Transfer an array of bytes, or skip a number of bytes, using the DMA + interface. + + @param[in] Size Size in bytes to transfer or skip. + + @param[in, out] Buffer Buffer to read data into or write data from. Ig= nored, + and may be NULL, if Size is zero, or Control is + FW_CFG_DMA_CTL_SKIP. + + @param[in] Control One of the following: + FW_CFG_DMA_CTL_WRITE - write to fw_cfg from Buff= er. + FW_CFG_DMA_CTL_READ - read from fw_cfg into Buf= fer. + FW_CFG_DMA_CTL_SKIP - skip bytes in fw_cfg. +**/ +VOID +InternalQemuFwCfgDmaBytes ( + IN UINT32 Size, + IN OUT VOID *Buffer OPTIONAL, + IN UINT32 Control + ) +{ + // + // We should never reach here + // + ASSERT (FALSE); + CpuDeadLoop (); +} --=20 2.27.0 -=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 (#114558): https://edk2.groups.io/g/devel/message/114558 Mute This Topic: https://groups.io/mt/103971682/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- From nobody Thu Dec 26 20:24:45 2024 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+114559+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+114559+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250669; cv=none; d=zohomail.com; s=zohoarc; b=iOKhuIgN3xQD8+vvLqFt7y8Kff9sXdfB8U4SK9QOC+3h6EAWQNzhiF3Vgi3Q7z903LAPtF5DSXIM/p8AncwHZBLgdSGnmY0gsWPT2799Lc0mluzXVdEv10xXH0ujLupDKrKQ5d4zbsjekM1w+vP/HORNrfCn5nykq1RaLJIXRRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250669; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=t0H3zO9xxPtItZMcakP5oPqshFiCrp4J3z0IbT3l/GQ=; b=b7OO+hbZNlTAFtQ8Bj6isLXjvdmduE3W7UllX5RNeJxlErHDtvPGivRft2cNDCcVHKoDKDTa2zuCrqJ0M+YIgBvFqgDW3rlQZfTgYcE2oIrDSMPLrbBOyfyyvnuymAx6y9LuDltsJGpY0Q/QOkQ5YMJKstoe+0O+yB2xd7gYNzA= 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+114559+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250669786508.47959086952415; Thu, 25 Jan 2024 22:31:09 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=5ccBFfTtJM/zj6wXb9ZxCTQki+IYtCz6LILWfnqF/0A=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250669; v=1; b=Ne7WAMw9YZVtPjz79BKVJvxiwqUHYQFW3eLzAtZAT04u3kmYX/4yE8CIU0gN2Ih5aGXIluav QSUIQaSMEarRoUiX1ER0JPk6pvu0bIX9fsD+NuAWvb9veR2KIkKO9gy6QECaN78jR9lSfFA4IEC R8lzBLHN8/DicaRXjsNoWH58= X-Received: by 127.0.0.2 with SMTP id NLyVYY1788612xtS3bPRs9kz; Thu, 25 Jan 2024 22:31:09 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10172.1706250668045398151 for ; Thu, 25 Jan 2024 22:31:08 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8BxieinUbNl+h4GAA--.2171S3; Fri, 26 Jan 2024 14:31:03 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxTs2lUbNliXMbAA--.51221S2; Fri, 26 Jan 2024 14:31:01 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Xianglai Li Subject: [edk2-devel] [PATCH v8 33/37] OvmfPkg/LoongArchVirt: Add reset system library Date: Fri, 26 Jan 2024 14:31:00 +0800 Message-Id: <20240126063100.3102914-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxTs2lUbNliXMbAA--.51221S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+AOvAAFsa X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 7FqLfZmQ3E2Sv3DufzeS8SBXx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250670614100001 Content-Type: text/plain; charset="utf-8" This library provides interface related to restart and shudown the LoongArch64 virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao Reviewed-by: Bibo Mao --- .../BaseResetSystemAcpiGed.c | 148 ++++++++++ .../BaseResetSystemAcpiGedLib.inf | 36 +++ .../DxeResetSystemAcpiGed.c | 259 ++++++++++++++++++ .../DxeResetSystemAcpiGedLib.inf | 41 +++ .../ResetSystemAcpiLib/ResetSystemAcpiGed.c | 125 +++++++++ .../ResetSystemAcpiLib/ResetSystemAcpiGed.h | 23 ++ 6 files changed, 632 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseRe= setSystemAcpiGed.c create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseRe= setSystemAcpiGedLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeRes= etSystemAcpiGed.c create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeRes= etSystemAcpiGedLib.inf create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetS= ystemAcpiGed.c create mode 100644 OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetS= ystemAcpiGed.h diff --git a/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSyst= emAcpiGed.c b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSys= temAcpiGed.c new file mode 100644 index 0000000000..0d94a62a38 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiG= ed.c @@ -0,0 +1,148 @@ +/** @file + Base ResetSystem library implementation. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include "ResetSystemAcpiGed.h" + +/** + 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= ->RsdtAddress); + 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= ->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] + (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", __func__, __LINE__)); + } + + ASSERT (mPowerManager.SleepControlRegAddr); + ASSERT (mPowerManager.SleepStatusRegAddr); + ASSERT (mPowerManager.ResetRegAddr); + return Status; +} diff --git a/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSyst= emAcpiGedLib.inf b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseRes= etSystemAcpiGedLib.inf new file mode 100644 index 0000000000..e163b09284 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiG= edLib.inf @@ -0,0 +1,36 @@ +## @file +# Base library instance for ResetSystem library class for LoongArch +# +# Copyright (c) 2024 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 BA521997-9016-32B5-65DF-EA5F560A3837 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ResetSystemLib|SEC PEI_CORE PEIM DXE_= CORE + CONSTRUCTOR =3D ResetSystemLibConstructor + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources] + BaseResetSystemAcpiGed.c + ResetSystemAcpiGed.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + DebugLib + IoLib + MemoryAllocationLib + QemuFwCfgLib diff --git a/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeResetSyste= mAcpiGed.c b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeResetSyste= mAcpiGed.c new file mode 100644 index 0000000000..c3256ee4ec --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeResetSystemAcpiGe= d.c @@ -0,0 +1,259 @@ +/** @file + Dxe ResetSystem library implementation. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include // EfiConvertPointer() +#include "ResetSystemAcpiGed.h" + +/** + 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", __func__)= ); + 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", __func__)); + 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= c__, __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= c__, __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", __func__, mPowerManager.S= leepControlRegAddr)); + ASSERT (mPowerManager.SleepControlRegAddr); + Status =3D SetMemoryAttributesRunTime (mPowerManager.SleepControlRegAdd= r); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a:%d\n", __func__, __LINE__)); + return; + } + + DEBUG ((DEBUG_INFO, "%a: sleepStatus %llx\n", __func__, mPowerManager.Sl= eepStatusRegAddr)); + ASSERT (mPowerManager.SleepStatusRegAddr); + Status =3D SetMemoryAttributesRunTime (mPowerManager.SleepStatusRegAddr= ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a:%d\n", __func__, __LINE__)); + return; + } + + DEBUG ((DEBUG_INFO, "%a: ResetReg %llx\n", __func__, mPowerManager.Reset= RegAddr)); + ASSERT (mPowerManager.ResetRegAddr); + Status =3D SetMemoryAttributesRunTime (mPowerManager.ResetRegAddr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a:%d\n", __func__, __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/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeResetSyste= mAcpiGedLib.inf b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeReset= SystemAcpiGedLib.inf new file mode 100644 index 0000000000..9815e2f6e7 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/DxeResetSystemAcpiGe= dLib.inf @@ -0,0 +1,41 @@ +## @file +# DXE library instance for ResetSystem library class for LoongArch. +# +# Copyright (c) 2024 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 F05197D5-5827-AA61-FB2D-BC69259F17A9 + 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 + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources] + DxeResetSystemAcpiGed.c + ResetSystemAcpiGed.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + DebugLib + DxeServicesTableLib + UefiBootServicesTableLib + UefiLib + UefiRuntimeLib + +[Guids] + gEfiAcpi10TableGuid ## PRODUCES ## S= ystemTable + gEfiAcpiTableGuid ## PRODUCES ## S= ystemTable diff --git a/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetSystemAc= piGed.c b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetSystemAcpiG= ed.c new file mode 100644 index 0000000000..105382da35 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetSystemAcpiGed.c @@ -0,0 +1,125 @@ +/** @file + ResetSystem library implementation. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include // CpuDeadLoop() +#include +#include +#include // ResetCold() +#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/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetSystemAc= piGed.h b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetSystemAcpiG= ed.h new file mode 100644 index 0000000000..06e2572db0 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/ResetSystemAcpiGed.h @@ -0,0 +1,23 @@ +/** @file + ResetSystem lib head file. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef RESET_SYSTEM_ACPI_GED_H_ +#define RESET_SYSTEM_ACPI_GED_H_ + +#include + +typedef struct { + UINT64 SleepControlRegAddr; + UINT64 SleepStatusRegAddr; + UINT64 ResetRegAddr; + UINT8 ResetValue; +} POWER_MANAGER; + +extern POWER_MANAGER mPowerManager; +#endif // RESET_SYSTEM_ACPI_GED_H_ --=20 2.27.0 -=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 (#114559): https://edk2.groups.io/g/devel/message/114559 Mute This Topic: https://groups.io/mt/103971684/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- From nobody Thu Dec 26 20:24:45 2024 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+114560+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+114560+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250671; cv=none; d=zohomail.com; s=zohoarc; b=c7NR4PYTtGzJcZWCkuiVU5p62szFaNlYfm6k96La/yVXQgxPkbRjm7KUYHfnPhE5WtPj75g4RDjPyPuXjHs/RHLkhuB3vQqNfe/Mu4A+qqUA5Irygvmt/Jkn27s6Bpgq4k1JuLAEX0U08fL9wx+MEmtlD0nHfXxEV8jVa1YnoCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250671; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=dopeF5XgNN/DB3QjtDzk2Or3BQD3/NkoVhTNT3OUeaA=; b=lS/CiOX4UTN7gZOPElphGiMytdWOGDSRZkhD1MHVFDrE1CUH1WNhYLYog64f3/VOmW3WMrU73u/O61Hr1IhR5K+FlPypcXh+M+V+cW2d4134NU51DuBtwhYODcByRkGyEIe7MJe+8pRNzxAJUJRyKwllLX1lSqcTVPz92nZO+F4= 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+114560+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250671831327.6920212949957; Thu, 25 Jan 2024 22:31:11 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=hThhEnqtHKd60tlgy9uOkXlRnJCP7p7F+FF/2jQzI6o=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250671; v=1; b=aV0iUJiYaiaP6Z32d95lgopIZRTsDqmdp5UEOIkB9IY5f26ilkmXcxNCYS47l12i0foVExSj edMkMzr6SxweKizuXVXp/uA3je7Zqu35X3xAuXGFmAyyjEbtdk7jQ4xhY7FwF3c9qSfgal9rKNU hwuHBK15DhlyQrIfH6Gu08E8= X-Received: by 127.0.0.2 with SMTP id NzyvYY1788612xAclqRSQvD8; Thu, 25 Jan 2024 22:31:11 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10173.1706250669419515699 for ; Thu, 25 Jan 2024 22:31:11 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxSPCqUbNlAh8GAA--.22255S3; Fri, 26 Jan 2024 14:31:06 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx7c6qUbNll3MbAA--.52931S2; Fri, 26 Jan 2024 14:31:06 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Xianglai Li Subject: [edk2-devel] [PATCH v8 34/37] OvmfPkg/LoongArchVirt: Support SEC phase Date: Fri, 26 Jan 2024 14:31:05 +0800 Message-Id: <20240126063105.3102978-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx7c6qUbNll3MbAA--.52931S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+AOvAAGsZ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: F2ygHRuW1u87Ekq0SYiESaNix1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250672518100005 Content-Type: text/plain; charset="utf-8" Add SEC code for LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao Reviewed-by: Bibo Mao --- OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S | 184 +++++++ OvmfPkg/LoongArchVirt/Sec/SecMain.c | 507 ++++++++++++++++++ OvmfPkg/LoongArchVirt/Sec/SecMain.inf | 53 ++ 3 files changed, 744 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S create mode 100644 OvmfPkg/LoongArchVirt/Sec/SecMain.c create mode 100644 OvmfPkg/LoongArchVirt/Sec/SecMain.inf diff --git a/OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S b/OvmfPkg/LoongA= rchVirt/Sec/LoongArch64/Start.S new file mode 100644 index 0000000000..f3fa79289d --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Sec/LoongArch64/Start.S @@ -0,0 +1,184 @@ +#-------------------------------------------------------------------------= ----- +# +# Start for Loongson LoongArch processor +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# @par Glossary: +# - CSR - CPU Status Register +# - EBASE - Exception Base Address +#-------------------------------------------------------------------------= ----- +#ifndef __ASSEMBLY__ +#define __ASSEMBLY__ +#endif + +#include +#include +#include + +#define BOOTCORE_ID 0 +// +// For coding convenience, define the maximum valid +// LoongArch exception. +// Since UEFI V2.11, it will be present in DebugSupport.h. +// +#define MAX_LOONGARCH_EXCEPTION 64 + +ASM_GLOBAL ASM_PFX(_ModuleEntryPoint) +ASM_PFX(_ModuleEntryPoint): + /* Disable global interrupt */ + bl DisableInterrupts + + /* Disable all local interrupt */ + li.w $a0, 0x1FFF + bl DisableLocalInterrupts + + /* Read physical cpu number id */ + bl GetApicId + li.d $t0, BOOTCORE_ID //0 + bne $a0, $t0, SlaveMain + + /* Set BSP stack */ + li.d $t0, FixedPcdGet64(PcdOvmfSecPeiTempRamBase) + FixedPcdGet32(Pc= dOvmfSecPeiTempRamSize) # stack base + move $sp, $t0 + addi.d $sp, $sp, -0x8 + + /* Load the exception vector base address */ + li.d $s0, FixedPcdGet64(PcdCpuExceptionVectorBaseAddress) + + /* Construct SEC and PEI step exception environment */ + la.pcrel $a1, ExceptionEntryStart + la.pcrel $t0, ExceptionEntryEnd + sub.d $a2, $t0, $a1 + li.w $t0, (MAX_LOONGARCH_EXCEPTION + MAX_LOONGARCH_INTERRUPT) * 512 + bgeu $a2, $t0, DeadLoop + move $a0, $s0 + bl CopyMem + + /* Configure BSP reset ebase */ + move $a0, $s0 + bl SetExceptionBaseAddress + +CallEntry: + /* Call C function make sure parameter true */ + li.d $a0, FixedPcdGet64(PcdOvmfFdBaseAddress) # FW base + addi.d $a1, $sp, 0x8 + bl SecCoreStartupWithStack +# End of _ModuleEntryPoint + +ASM_PFX(ClearMailBox): + /* Clear mailbox */ + li.d $t1, LOONGARCH_IOCSR_MBUF3 + iocsrwr.d $zero, $t1 + li.d $t1, LOONGARCH_IOCSR_MBUF2 + iocsrwr.d $zero, $t1 + li.d $t1, LOONGARCH_IOCSR_MBUF1 + iocsrwr.d $zero, $t1 + li.d $t1, LOONGARCH_IOCSR_MBUF0 + iocsrwr.d $zero, $t1 + jirl $zero, $ra, 0 +# End of ClearMailBox + +ASM_PFX(EnableIPI): + /* Enable IPI interrupt */ + li.w $t1, BIT12 + csrxchg $t1, $t1, LOONGARCH_CSR_ECFG + + li.w $t2, 0xFFFFFFFFU + li.d $t1, LOONGARCH_IOCSR_IPI_EN + iocsrwr.w $t2, $t1 + jirl $zero, $ra, 0 +# End of EeableIPI + +#/** +# Get APIC ID for every CPU. +# +# @param NULL +# @return APICID +# +# UINTN +# EFI_API +# GetApicId ( +# VOID +# ) +#**/ +ASM_PFX(GetApicId): + csrrd $a0, LOONGARCH_CSR_CPUNUM + andi $a0, $a0, 0x3ff + jirl $zero, $ra, 0 +# End of GetApicId + +ASM_PFX(ApInitStack): + li.d $t1, SIZE_1KB + csrrd $t0, LOONGARCH_CSR_TMID + mul.d $t1, $t0, $t1 + li.d $t2, FixedPcdGet32(PcdCpuMaxLogicalProcessorNumber) + bgeu $t0, $t2, DeadLoop + li.d $t0, FixedPcdGet64(PcdOvmfSecPeiTempRamBase) + FixedPcdGet32(PcdO= vmfSecPeiTempRamSize) - SIZE_64KB + sub.d $sp, $t0, $t1 + addi.d $sp, $sp, -0x8 + jirl $zero, $ra, 0 +# End of ApInitStack + +ASM_PFX(SlaveMain): + /* Set AP exception handle in flash */ + la.pcrel $a0, ApException + bl SetExceptionBaseAddress + + /* Clean up local mail box and open INT */ + bl ClearMailBox + bl EnableIPI + bl EnableInterrupts + +WaitForWake: + /* Wait for wakeup */ + bl CpuSleep + b WaitForWake +# End of SlaveMain + +.align 12 +ASM_PFX(ApException): + csrrd $t0, LOONGARCH_CSR_ESTAT + srli.d $t0, $t0, 12 + andi $t0, $t0, 0x1 + beqz $t0, DeadLoop + + li.d $t0, LOONGARCH_IOCSR_IPI_STATUS + iocsrrd.w $t1, $t0 + li.d $t0, LOONGARCH_IOCSR_IPI_CLEAR + iocsrwr.w $t1, $t0 + + /* Read mail buf and jump to specified entry */ + li.d $t1, LOONGARCH_IOCSR_MBUF0 + iocsrrd.d $t0, $t1 + beqz $t0, OutOfException + csrwr $t0, LOONGARCH_CSR_ERA + li.d $t0, LOONGARCH_IOCSR_MBUF3 + iocsrrd.d $a1, $t0 + bl ClearMailBox + beqz $a1, NoParameterCall + + // + // If the parameters are not NULL, then calling happened in FW ENV. + // Set the EBASE to be the same as BSP. + // + li.d $a0, FixedPcdGet64(PcdCpuExceptionVectorBaseAddress) + bl SetExceptionBaseAddress + + bl ApInitStack + bl GetApicId + b OutOfException +NoParameterCall: + li.w $t0, BIT2 // IE + csrxchg $zero, $t0, LOONGARCH_CSR_PRMD // Clean PIE + +OutOfException: + ertn +# End of ApException + +ASM_PFX(DeadLoop): + b DeadLoop +# End of DeadLoop +.end diff --git a/OvmfPkg/LoongArchVirt/Sec/SecMain.c b/OvmfPkg/LoongArchVirt/Se= c/SecMain.c new file mode 100644 index 0000000000..a7f4324811 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Sec/SecMain.c @@ -0,0 +1,507 @@ +/** @file + Main SEC phase code. Transitions to PEI. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/** + temporary memory to permanent memory and do stack switching. + + @param[in] PeiServices Pointer to the PEI Services Table. + @param[in] TemporaryMemoryBase Temporary Memory Base address. + @param[in] PermanentMemoryBase Permanent Memory Base address. + @param[in] CopySize The size of memory that needs to be migrated. + + @retval EFI_SUCCESS Migration successful. +**/ +EFI_STATUS +EFIAPI +TemporaryRamMigration ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, + IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, + IN UINTN CopySize + ); + +EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi =3D { + TemporaryRamMigration +}; + +EFI_PEI_PPI_DESCRIPTOR mPrivateDispatchTable[] =3D { + { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiTemporaryRamSupportPpiGuid, + &mTemporaryRamSupportPpi + }, +}; + +/** + Locates a section within a series of sections + with the specified section type. + + The Instance parameter indicates which instance of the section + type to return. (0 is first instance, 1 is second...) + + @param[in] Sections The sections to search + @param[in] SizeOfSections Total size of all sections + @param[in] SectionType The section type to locate + @param[in] Instance The section instance number + @param[out] FoundSection The FFS section if found + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted +**/ +EFI_STATUS +FindFfsSectionInstance ( + IN VOID *Sections, + IN UINTN SizeOfSections, + IN EFI_SECTION_TYPE SectionType, + IN UINTN Instance, + OUT EFI_COMMON_SECTION_HEADER **FoundSection + ) +{ + EFI_PHYSICAL_ADDRESS CurrentAddress; + UINT32 Size; + EFI_PHYSICAL_ADDRESS EndOfSections; + EFI_COMMON_SECTION_HEADER *Section; + EFI_PHYSICAL_ADDRESS EndOfSection; + + // + // Loop through the FFS file sections within the PEI Core FFS file + // + EndOfSection =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Sections; + EndOfSections =3D EndOfSection + SizeOfSections; + for ( ; ; ) { + if (EndOfSection =3D=3D EndOfSections) { + break; + } + + CurrentAddress =3D (EndOfSection + 3) & ~(3ULL); + if (CurrentAddress >=3D EndOfSections) { + return EFI_VOLUME_CORRUPTED; + } + + Section =3D (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddress; + + Size =3D SECTION_SIZE (Section); + if (Size < sizeof (*Section)) { + return EFI_VOLUME_CORRUPTED; + } + + EndOfSection =3D CurrentAddress + Size; + if (EndOfSection > EndOfSections) { + return EFI_VOLUME_CORRUPTED; + } + + // + // Look for the requested section type + // + if (Section->Type =3D=3D SectionType) { + if (Instance =3D=3D 0) { + *FoundSection =3D Section; + return EFI_SUCCESS; + } else { + Instance--; + } + } + } + + return EFI_NOT_FOUND; +} + +/** + Locates a section within a series of sections + with the specified section type. + + @param[in] Sections The sections to search + @param[in] SizeOfSections Total size of all sections + @param[in] SectionType The section type to locate + @param[out] FoundSection The FFS section if found + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted +**/ +EFI_STATUS +FindFfsSectionInSections ( + IN VOID *Sections, + IN UINTN SizeOfSections, + IN EFI_SECTION_TYPE SectionType, + OUT EFI_COMMON_SECTION_HEADER **FoundSection + ) +{ + return FindFfsSectionInstance ( + Sections, + SizeOfSections, + SectionType, + 0, + FoundSection + ); +} + +/** + Locates a FFS file with the specified file type and a section + within that file with the specified section type. + + @param[in] Fv The firmware volume to search + @param[in] FileType The file type to locate + @param[in] SectionType The section type to locate + @param[out] FoundSection The FFS section if found + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted +**/ +EFI_STATUS +FindFfsFileAndSection ( + IN EFI_FIRMWARE_VOLUME_HEADER *Fv, + IN EFI_FV_FILETYPE FileType, + IN EFI_SECTION_TYPE SectionType, + OUT EFI_COMMON_SECTION_HEADER **FoundSection + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS CurrentAddress; + EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume; + EFI_FFS_FILE_HEADER *File; + UINT32 Size; + EFI_PHYSICAL_ADDRESS EndOfFile; + + if (Fv->Signature !=3D EFI_FVH_SIGNATURE) { + DEBUG ((DEBUG_ERROR, "FV at %p does not have FV header signature\n", F= v)); + return EFI_VOLUME_CORRUPTED; + } + + CurrentAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Fv; + EndOfFirmwareVolume =3D CurrentAddress + Fv->FvLength; + + // + // Loop through the FFS files in the Boot Firmware Volume + // + for (EndOfFile =3D CurrentAddress + Fv->HeaderLength; ; ) { + CurrentAddress =3D (EndOfFile + 7) & ~(7ULL); + if (CurrentAddress > EndOfFirmwareVolume) { + return EFI_VOLUME_CORRUPTED; + } + + File =3D (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress; + Size =3D *(UINT32 *)File->Size & 0xffffff; + if (Size < (sizeof (*File) + sizeof (EFI_COMMON_SECTION_HEADER))) { + return EFI_VOLUME_CORRUPTED; + } + + EndOfFile =3D CurrentAddress + Size; + if (EndOfFile > EndOfFirmwareVolume) { + return EFI_VOLUME_CORRUPTED; + } + + // + // Look for the request file type + // + if (File->Type !=3D FileType) { + continue; + } + + Status =3D FindFfsSectionInSections ( + (VOID *)(File + 1), + (UINTN)EndOfFile - (UINTN)(File + 1), + SectionType, + FoundSection + ); + if (!EFI_ERROR (Status) || + (Status =3D=3D EFI_VOLUME_CORRUPTED)) + { + return Status; + } + } +} + +/** + Locates the PEI Core entry point address + + @param[in] Fv The firmware volume to search + @param[out] PeiCoreEntryPoint The entry point of the PEI Core image + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted +**/ +EFI_STATUS +FindPeiCoreImageBaseInFv ( + IN EFI_FIRMWARE_VOLUME_HEADER *Fv, + OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase + ) +{ + EFI_STATUS Status; + EFI_COMMON_SECTION_HEADER *Section; + + Status =3D FindFfsFileAndSection ( + Fv, + EFI_FV_FILETYPE_PEI_CORE, + EFI_SECTION_PE32, + &Section + ); + if (EFI_ERROR (Status)) { + Status =3D FindFfsFileAndSection ( + Fv, + EFI_FV_FILETYPE_PEI_CORE, + EFI_SECTION_TE, + &Section + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to find PEI Core image\n")); + return Status; + } + } + + *PeiCoreImageBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)(Section + 1); + return EFI_SUCCESS; +} + +/** + Find and return Pei Core entry point. + + It also find SEC and PEI Core file debug information. It will report the= m if + remote debug is enabled. +**/ +VOID +FindAndReportEntryPoints ( + IN EFI_FIRMWARE_VOLUME_HEADER **BootFirmwareVolumePtr, + OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS PeiCoreImageBase =3D 0; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + + Status =3D FindPeiCoreImageBaseInFv (*BootFirmwareVolumePtr, &PeiCoreIma= geBase); + ASSERT (Status =3D=3D EFI_SUCCESS); + + ZeroMem ((VOID *)&ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT)); + + // + // Report PEI Core debug information when remote debug is enabled + // + ImageContext.ImageAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN)PeiCoreImageB= ase; + ImageContext.PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)= ImageContext.ImageAddress); + PeCoffLoaderRelocateImageExtraAction (&ImageContext); + + // + // Find PEI Core entry point + // + Status =3D PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)PeiCoreImageBase, (= VOID **)PeiCoreEntryPoint); + if (EFI_ERROR (Status)) { + *PeiCoreEntryPoint =3D 0; + } + + return; +} + +/** + Find the peicore entry point and jump to the entry point to execute. + + @param[in] Context The first input parameter of InitializeDebugAgent(= ). +**/ +VOID +EFIAPI +SecStartupPhase2 ( + IN VOID *Context + ) +{ + EFI_SEC_PEI_HAND_OFF *SecCoreData; + EFI_FIRMWARE_VOLUME_HEADER *BootFv; + EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint; + + SecCoreData =3D (EFI_SEC_PEI_HAND_OFF *)Context; + + // + // Find PEI Core entry point. It will report SEC and Pei Core debug info= rmation if remote debug + // is enabled. + // + BootFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolume= Base; + FindAndReportEntryPoints (&BootFv, &PeiCoreEntryPoint); + SecCoreData->BootFirmwareVolumeBase =3D BootFv; + SecCoreData->BootFirmwareVolumeSize =3D (UINTN)BootFv->FvLength; + + DEBUG ((DEBUG_INFO, "Find Pei EntryPoint=3D%p\n", PeiCoreEntryPoint)); + + // + // Transfer the control to the PEI core + // + DEBUG ((DEBUG_INFO, "SecStartupPhase2 %p\n", PeiCoreEntryPoint)); + + (*PeiCoreEntryPoint)(SecCoreData, (EFI_PEI_PPI_DESCRIPTOR *)&mPrivateDis= patchTable); + + // + // If we get here then the PEI Core returned, which is not recoverable. + // + ASSERT (FALSE); + CpuDeadLoop (); +} + +/** + Entry point to the C language phase of SEC. initialize some temporary me= mory and set up the stack, + the control is transferred to this function. + + @param[in] BootFv The pointer to the PEI FV in memory. + @param[in] TopOfCurrentStack Top of Current Stack. +**/ +VOID +EFIAPI +SecCoreStartupWithStack ( + IN EFI_FIRMWARE_VOLUME_HEADER *BootFv, + IN VOID *TopOfCurrentStack + ) +{ + EFI_SEC_PEI_HAND_OFF SecCoreData; + EFI_FIRMWARE_VOLUME_HEADER *BootPeiFv =3D (EFI_FIRMWARE_VOLUME_HEADER *= )BootFv; + + DEBUG ((DEBUG_INFO, "Entering C environment\n")); + + ProcessLibraryConstructorList (NULL, NULL); + + DEBUG (( + DEBUG_INFO, + "SecCoreStartupWithStack (0x%lx, 0x%lx)\n", + (UINTN)BootFv, + (UINTN)TopOfCurrentStack + )); + DEBUG (( + DEBUG_INFO, + "(0x%lx, 0x%lx)\n", + (UINTN)(FixedPcdGet64 (PcdOvmfSecPeiTempRamBase)), + (UINTN)(FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) + )); + + // |-------------| <-- TopOfCurrentStack + // | BSP Stack | 32k + // |-------------| + // | BSP Heap | 32k + // |-------------| <-- SecCoreData.TemporaryRamBase + // | Ap Stack | 384k + // |-------------| + // | Exception | 64k + // |-------------| <-- PcdOvmfSecPeiTempRamBase + + ASSERT ( + (UINTN)(FixedPcdGet64 (PcdOvmfSecPeiTempRamBase) + + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) =3D=3D + (UINTN)TopOfCurrentStack + ); + + // + // Initialize SEC hand-off state + // + SecCoreData.DataSize =3D sizeof (EFI_SEC_PEI_HAND_OFF); + + SecCoreData.TemporaryRamSize =3D (UINTN)SIZE_64KB; + SecCoreData.TemporaryRamBase =3D (VOID *)(FixedPcdGet64 (PcdOvmfSecPeiTe= mpRamBase) + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize) - SecCoreData.Tempora= ryRamSize); + + SecCoreData.PeiTemporaryRamBase =3D SecCoreData.TemporaryRamBase; + SecCoreData.PeiTemporaryRamSize =3D SecCoreData.TemporaryRamSize >> 1; + + SecCoreData.StackBase =3D (UINT8 *)SecCoreData.TemporaryRamBase + SecCor= eData.PeiTemporaryRamSize; + SecCoreData.StackSize =3D SecCoreData.TemporaryRamSize >> 1; + + SecCoreData.BootFirmwareVolumeBase =3D BootPeiFv; + SecCoreData.BootFirmwareVolumeSize =3D (UINTN)BootPeiFv->FvLength; + + DEBUG (( + DEBUG_INFO, + "&SecCoreData.BootFirmwareVolumeBase=3D%lx SecCoreData.BootFirmwareVol= umeBase=3D%lx\n", + (UINT64)&(SecCoreData.BootFirmwareVolumeBase), + (UINT64)(SecCoreData.BootFirmwareVolumeBase) + )); + DEBUG (( + DEBUG_INFO, + "&SecCoreData.BootFirmwareVolumeSize=3D%lx SecCoreData.BootFirmwareVol= umeSize=3D%lx\n", + (UINT64)&(SecCoreData.BootFirmwareVolumeSize), + (UINT64)(SecCoreData.BootFirmwareVolumeSize) + )); + + // + // Initialize Debug Agent to support source level debug in SEC/PEI phase= s before memory ready. + // + InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL); + SecStartupPhase2 (&SecCoreData); +} + +/** + temporary memory to permanent memory and do stack switching. + + @param[in] PeiServices Pointer to the PEI Services Table. + @param[in] TemporaryMemoryBase Temporary Memory Base address. + @param[in] PermanentMemoryBase Permanent Memory Base address. + @param[in] CopySize The size of memory that needs to be migrated. + + @retval EFI_SUCCESS Migration successful. +**/ +EFI_STATUS +EFIAPI +TemporaryRamMigration ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, + IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, + IN UINTN CopySize + ) +{ + VOID *OldHeap; + VOID *NewHeap; + VOID *OldStack; + VOID *NewStack; + BASE_LIBRARY_JUMP_BUFFER JumpBuffer; + + DEBUG (( + DEBUG_INFO, + "TemporaryRamMigration (0x%Lx, 0x%Lx, 0x%Lx)\n", + TemporaryMemoryBase, + PermanentMemoryBase, + (UINT64)CopySize + )); + + OldHeap =3D (VOID *)(UINTN)TemporaryMemoryBase; + NewHeap =3D (VOID *)((UINTN)PermanentMemoryBase + (CopySize >> 1)); + + OldStack =3D (VOID *)((UINTN)TemporaryMemoryBase + (CopySize >> 1)); + NewStack =3D (VOID *)(UINTN)PermanentMemoryBase; + + // + // Migrate Heap + // + CopyMem (NewHeap, OldHeap, CopySize >> 1); + + // + // Migrate Stack + // + CopyMem (NewStack, OldStack, CopySize >> 1); + + // Use SetJump ()/LongJump () to switch to a new stack. + // + if (SetJump (&JumpBuffer) =3D=3D 0) { + JumpBuffer.SP =3D JumpBuffer.SP - (UINTN)OldStack + (UINTN)NewStack; + LongJump (&JumpBuffer, (UINTN)-1); + } + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/Sec/SecMain.inf b/OvmfPkg/LoongArchVirt/= Sec/SecMain.inf new file mode 100644 index 0000000000..49264ebbab --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Sec/SecMain.inf @@ -0,0 +1,53 @@ +## @file +# SEC Driver +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D SecMain + FILE_GUID =3D 57d02d4f-5a5d-4bfa-b7d6-ba0a4d2c72ce + MODULE_TYPE =3D SEC + VERSION_STRING =3D 1.0 + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources] + LoongArch64/Start.S + SecMain.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + CpuExceptionHandlerLib + DebugAgentLib + DebugLib + IoLib + PcdLib + PeCoffLib + PeCoffGetEntryPointLib + PeCoffExtraActionLib + +[Ppis] + gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED + +[FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize + + gUefiCpuPkgTokenSpaceGuid.PcdCpuExceptionVectorBaseAddress + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber + + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress --=20 2.27.0 -=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 (#114560): https://edk2.groups.io/g/devel/message/114560 Mute This Topic: https://groups.io/mt/103971685/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- From nobody Thu Dec 26 20:24:45 2024 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+114561+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+114561+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250678; cv=none; d=zohomail.com; s=zohoarc; b=eEjeR9JxP05IW9LpX12tGl+/ta4yT263cLMX48LyGXgWeN30cwyNCkpMgNhytY2QX3NeFLi9DklnA0SBaDHXClsrHbYvFlMSoLyS/Vj2uOE7gijheUGB5A1l1d4FOd8NbULM6OnG1JWhusOZZwYKo38wn17QTcEdjgPbX7AZQqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250678; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=0DwLVRTZjtHO7fCX876RujMz9aqiEJjQq5Y67kfhncs=; b=MZx6+0LHTHg8pZprwoYUxnZ5mPjePa1BertuwYz8lODn9eNlVwA6K1cUN8dru6FO4TmFIv+OTZBvC/nI0OmXVT/toO7DLd8ARxmvXvRjY7XUNxAj2hghhpVPI899n/T5GTB2ryBO5vvEYL7WIRtXvAT8sMxli8zzoFlaER6A47c= 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+114561+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 170625067823779.1041927324336; Thu, 25 Jan 2024 22:31:18 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=ZNpud4xIU1T+DenS93fkE0hf72+UPsYABliAxLtYCR0=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250677; v=1; b=nd/S+YtZc155/hkLpOX5NPZWaZmtO/GTxImuNctqjaUDLjGxEnPriVpnDgABI/j/LvZjS3fB UCR2tKMQ2xhDwenb0c7odzEzieUtQcARkCKOSGLpXDPKMLXhbqSTOTRYakw8gjuCO3s25J2s6y6 6ZSoz9z12t3WR9qX7JaDJ7NM= X-Received: by 127.0.0.2 with SMTP id 95rrYY1788612x8xDSXDGdOv; Thu, 25 Jan 2024 22:31:17 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.10041.1706250676584219036 for ; Thu, 25 Jan 2024 22:31:17 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8AxjuuwUbNlDR8GAA--.21396S3; Fri, 26 Jan 2024 14:31:12 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx7c6uUbNlqnMbAA--.52933S2; Fri, 26 Jan 2024 14:31:10 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Xianglai Li Subject: [edk2-devel] [PATCH v8 35/37] OvmfPkg/LoongArchVirt: Support PEI phase Date: Fri, 26 Jan 2024 14:31:09 +0800 Message-Id: <20240126063109.3103040-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx7c6uUbNlqnMbAA--.52933S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+AOvAAIsX X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 4cPkwtWdd6mMtOq7ZhIFART4x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250678513100001 Content-Type: text/plain; charset="utf-8" Platfrom PEI module for LoongArch platfrom initialization. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao Reviewed-by: Bibo Mao --- OvmfPkg/LoongArchVirt/PlatformPei/Fv.c | 39 ++ OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c | 201 +++++++++ OvmfPkg/LoongArchVirt/PlatformPei/Platform.c | 393 ++++++++++++++++++ OvmfPkg/LoongArchVirt/PlatformPei/Platform.h | 146 +++++++ .../LoongArchVirt/PlatformPei/PlatformPei.inf | 72 ++++ 5 files changed, 851 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/Fv.c create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/Platform.c create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/Platform.h create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/Fv.c b/OvmfPkg/LoongArchVirt= /PlatformPei/Fv.c new file mode 100644 index 0000000000..d46326f135 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/Fv.c @@ -0,0 +1,39 @@ +/** @file + Build FV related hobs for platform. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include "Platform.h" + +/** + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI + and DXE know about them. + + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully. +**/ +EFI_STATUS +PeiFvInitialization ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Platform PEI Firmware Volume Initialization\n")); + + // + // Create a memory allocation HOB for the PEI FV. + // + BuildMemoryAllocationHob ( + FixedPcdGet64 (PcdOvmfSecPeiTempRamBase), + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize), + EfiBootServicesData + ); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c b/OvmfPkg/LoongA= rchVirt/PlatformPei/MemDetect.c new file mode 100644 index 0000000000..9c90413524 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c @@ -0,0 +1,201 @@ +/** @file + Memory Detection for Virtual Machines. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// +// The package level header files this module uses +// +#include + +// +// The Library classes this module consumes +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Platform.h" + +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS (128) +#define LOONGARCH_FW_RAM_TOP BASE_256MB + +/** + Publish PEI core memory + + @return EFI_SUCCESS The PEIM initialized successfully. +**/ +EFI_STATUS +PublishPeiMemory ( + VOID + ) +{ + EFI_STATUS Status; + UINT64 Base; + UINT64 Size; + UINT64 RamTop; + + // + // Determine the range of memory to use during PEI + // + Base =3D FixedPcdGet64 (PcdOvmfSecPeiTempRamBase) + FixedPcdGet32 (Pcd= OvmfSecPeiTempRamSize); + RamTop =3D LOONGARCH_FW_RAM_TOP; + Size =3D RamTop - Base; + + // + // Publish this memory to the PEI Core + // + Status =3D PublishSystemMemory (Base, Size); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INFO, "Publish Memory Initialize done.\n")); + return Status; +} + +/** + Peform Memory Detection + Publish system RAM and reserve memory regions +**/ +VOID +InitializeRamRegions ( + VOID + ) +{ + EFI_STATUS Status; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + MEMMAP_ENTRY MemoryMapEntry; + MEMMAP_ENTRY *StartEntry; + MEMMAP_ENTRY *pEntry; + UINTN Processed; + + Status =3D QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a %d read etc/memmap error Status %d \n", __fun= c__, __LINE__, Status)); + return; + } + + if (FwCfgSize % sizeof MemoryMapEntry !=3D 0) { + DEBUG ((DEBUG_ERROR, "no MemoryMapEntry FwCfgSize:%d\n", FwCfgSize)); + return; + } + + QemuFwCfgSelectItem (FwCfgItem); + StartEntry =3D AllocatePages (EFI_SIZE_TO_PAGES (FwCfgSize)); + QemuFwCfgReadBytes (FwCfgSize, StartEntry); + for (Processed =3D 0; Processed < (FwCfgSize / sizeof MemoryMapEntry); P= rocessed++) { + pEntry =3D StartEntry + Processed; + if (pEntry->Length =3D=3D 0) { + continue; + } + + DEBUG ((DEBUG_INFO, "MemmapEntry Base %p length %p type %d\n", pEntry= ->BaseAddr, pEntry->Length, pEntry->Type)); + if (pEntry->Type !=3D EfiAcpiAddressRangeMemory) { + continue; + } + + AddMemoryRangeHob (pEntry->BaseAddr, pEntry->BaseAddr + pEntry->Length= ); + } + + // + // When 0 address protection is enabled, + // 0-4k memory needs to be preallocated to prevent UEFI applications fro= m allocating use, + // such as grub + // + if (PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) { + BuildMemoryAllocationHob ( + 0, + EFI_PAGE_SIZE, + EfiBootServicesData + ); + } +} + +/** + Gets the Virtual Memory Map of corresponding platforms. + + This Virtual Memory Map is used by initialize the MMU on corresponding + platforms. + + @param[out] MemoryTable Array of MEMORY_REGION_DESCRIPTOR + describing a Physical-to-Virtual Memory + mapping. This array must be ended by a + zero-filled entry. The allocated memory + will not be freed. +**/ +VOID +EFIAPI +GetMemoryMapPolicy ( + OUT MEMORY_REGION_DESCRIPTOR **MemoryTable + ) +{ + EFI_STATUS Status; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + MEMMAP_ENTRY MemoryMapEntry; + MEMMAP_ENTRY *StartEntry; + MEMMAP_ENTRY *pEntry; + UINTN Processed; + MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable; + UINTN Index =3D 0; + + ASSERT (MemoryTable !=3D NULL); + + VirtualMemoryTable =3D AllocatePool ( + sizeof (MEMORY_REGION_DESCRIPTOR) * + MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS + ); + + // + // Add the 0x10000000-0x20000000. In the virtual machine, this area use = for CPU UART, flash, PIC etc. + // + VirtualMemoryTable[Index].PhysicalBase =3D 0x10000000; + VirtualMemoryTable[Index].VirtualBase =3D VirtualMemoryTable[Index].Phy= sicalBase; + VirtualMemoryTable[Index].Length =3D 0x10000000; + VirtualMemoryTable[Index].Attributes =3D PAGE_VALID | PLV_KERNEL | CA= CHE_SUC | PAGE_DIRTY | PAGE_GLOBAL; + ++Index; + + Status =3D QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a %d read etc/memmap error Status %d \n", __fun= c__, __LINE__, Status)); + ZeroMem (&VirtualMemoryTable[Index], sizeof (MEMORY_REGION_DESCRIPTOR)= ); + *MemoryTable =3D VirtualMemoryTable; + return; + } + + if (FwCfgSize % sizeof MemoryMapEntry !=3D 0) { + DEBUG ((DEBUG_ERROR, "no MemoryMapEntry FwCfgSize:%d\n", FwCfgSize)); + } + + QemuFwCfgSelectItem (FwCfgItem); + StartEntry =3D AllocatePages (EFI_SIZE_TO_PAGES (FwCfgSize)); + QemuFwCfgReadBytes (FwCfgSize, StartEntry); + for (Processed =3D 0; Processed < (FwCfgSize / sizeof MemoryMapEntry); P= rocessed++) { + pEntry =3D StartEntry + Processed; + if (pEntry->Length =3D=3D 0) { + continue; + } + + DEBUG ((DEBUG_INFO, "MemmapEntry Base %p length %p type %d\n", pEntry= ->BaseAddr, pEntry->Length, pEntry->Type)); + VirtualMemoryTable[Index].PhysicalBase =3D pEntry->BaseAddr; + VirtualMemoryTable[Index].VirtualBase =3D VirtualMemoryTable[Index].P= hysicalBase; + VirtualMemoryTable[Index].Length =3D pEntry->Length; + VirtualMemoryTable[Index].Attributes =3D PAGE_VALID | PLV_KERNEL | = CACHE_CC | PAGE_DIRTY | PAGE_GLOBAL; + ++Index; + } + + FreePages (StartEntry, EFI_SIZE_TO_PAGES (FwCfgSize)); + // End of Table + ZeroMem (&VirtualMemoryTable[Index], sizeof (MEMORY_REGION_DESCRIPTOR)); + *MemoryTable =3D VirtualMemoryTable; +} diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/Platform.c b/OvmfPkg/LoongAr= chVirt/PlatformPei/Platform.c new file mode 100644 index 0000000000..10719c4459 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/Platform.c @@ -0,0 +1,393 @@ +/** @file + Platform PEI driver + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Mem - Memory +**/ + +// +// The package level header files this module uses +// +#include +// +// The Library classes this module consumes +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Platform.h" + +VOID +SaveRtcRegisterAddressHob ( + UINT64 RtcRegisterBase + ); + +/* TODO */ +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] =3D { + { EfiReservedMemoryType, 0x004 }, + { EfiRuntimeServicesData, 0x024 }, + { EfiRuntimeServicesCode, 0x030 }, + { EfiBootServicesCode, 0x180 }, + { EfiBootServicesData, 0xF00 }, + { EfiMaxMemoryType, 0x000 } +}; + +// +// Module globals +// +CONST EFI_PEI_PPI_DESCRIPTOR mPpiListBootMode =3D { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiMasterBootModePpiGuid, + NULL +}; + +STATIC EFI_BOOT_MODE mBootMode =3D BOOT_WITH_FULL_CONFIGURATION; + +/** + Create Reserved type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddReservedMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ) +{ + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_RESERVED, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + MemoryBase, + MemorySize + ); +} + +/** + Create system type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ) +{ + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + MemoryBase, + MemorySize + ); +} + +/** + Create memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ) +{ + AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase)); +} + +/** + Create memory type information hand off block. + + @param VOID + + @return VOID +**/ +VOID +MemMapInitialization ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "=3D=3D%a=3D=3D\n", __func__)); + // + // Create Memory Type Information HOB + // + BuildGuidDataHob ( + &gEfiMemoryTypeInformationGuid, + mDefaultMemoryTypeInformation, + sizeof (mDefaultMemoryTypeInformation) + ); +} + +/** Get the Rtc base address from the DT. + + This function fetches the node referenced in the "loongson,ls7a-rtc" + property of the "reg" node and returns the base address of + the RTC. + + @param [in] Fdt Pointer to a Flattened Device Tree (= Fdt). + @param [out] RtcBaseAddress If success, contains the base address + of the Rtc. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND RTC info not found in DT. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GetRtcAddress ( + IN CONST VOID *Fdt, + OUT UINT64 *RtcBaseAddress + ) +{ + INT32 Node; + INT32 Prev; + CONST CHAR8 *Type; + INT32 Len; + CONST UINT64 *RegProp; + EFI_STATUS Status; + + if ((Fdt =3D=3D NULL) || (fdt_check_header (Fdt) !=3D 0)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D EFI_NOT_FOUND; + for (Prev =3D 0; ; Prev =3D Node) { + Node =3D fdt_next_node (Fdt, Prev, NULL); + if (Node < 0) { + break; + } + + // + // Check for memory node + // + Type =3D fdt_getprop (Fdt, Node, "compatible", &Len); + if ((Type) && (AsciiStrnCmp (Type, "loongson,ls7a-rtc", Len) =3D=3D 0)= ) { + // + // Get the 'reg' property of this node. For now, we will assume + // two 8 byte quantities for base and size, respectively. + // + RegProp =3D fdt_getprop (Fdt, Node, "reg", &Len); + if ((RegProp !=3D 0) && (Len =3D=3D (2 * sizeof (UINT64)))) { + *RtcBaseAddress =3D SwapBytes64 (RegProp[0]); + Status =3D RETURN_SUCCESS; + DEBUG ((DEBUG_INFO, "%a Len %d RtcBase %llx\n", __func__, Len, *Rt= cBaseAddress)); + break; + } else { + DEBUG ((DEBUG_ERROR, "%a: Failed to parse FDT rtc node\n", __func_= _)); + break; + } + } + } + + return Status; +} + +/** + Misc Initialization. + + @param VOID + + @return VOID +**/ +VOID +MiscInitialization ( + VOID + ) +{ + CPUCFG_REG1_INFO_DATA CpucfgReg1Data; + UINT8 CpuPhysMemAddressWidth; + + DEBUG ((DEBUG_INFO, "=3D=3D%a=3D=3D\n", __func__)); + + // + // Get the the CPU physical memory address width. + // + AsmCpucfg (CPUCFG_REG1_INFO, &CpucfgReg1Data.Uint32); + + CpuPhysMemAddressWidth =3D (UINT8)(CpucfgReg1Data.Bits.PALEN + 1); + + // + // Creat CPU HOBs. + // + BuildCpuHob (CpuPhysMemAddressWidth, FixedPcdGet8 (PcdPrePiCpuIoSize)); +} + +/** + add fdt hand off block. + + @param VOID + + @return VOID +**/ +VOID +AddFdtHob ( + VOID + ) +{ + VOID *Base; + VOID *NewBase; + UINTN FdtSize; + UINTN FdtPages; + UINT64 *FdtHobData; + UINT64 RtcBaseAddress; + RETURN_STATUS Status; + + Base =3D (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress); + ASSERT (Base !=3D NULL); + + Status =3D GetRtcAddress (Base, &RtcBaseAddress); + if (RETURN_ERROR (Status)) { + return; + } + + SaveRtcRegisterAddressHob (RtcBaseAddress); + + FdtSize =3D fdt_totalsize (Base) + PcdGet32 (PcdDeviceTreeAllocationPad= ding); + FdtPages =3D EFI_SIZE_TO_PAGES (FdtSize); + NewBase =3D AllocatePages (FdtPages); + ASSERT (NewBase !=3D NULL); + fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages)); + + FdtHobData =3D BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData); + ASSERT (FdtHobData !=3D NULL); + *FdtHobData =3D (UINTN)NewBase; +} + +/** + Fetch the size of system memory from QEMU. + + @param VOID + + @return VOID +**/ +VOID +ReportSystemMemorySize ( + VOID + ) +{ + UINT64 RamSize; + + QemuFwCfgSelectItem (QemuFwCfgItemRamSize); + RamSize =3D QemuFwCfgRead64 (); + DEBUG (( + DEBUG_INFO, + "%a: QEMU reports %dM system memory\n", + __func__, + RamSize/1024/1024 + )); + + // + // Assert false if QEMU report system memory size is less then 256M. + // + if (RamSize <=3D SIZE_256MB) { + ASSERT (FALSE); + } +} + +/** + Perform Platform PEI initialization. + + @param FileHandle Handle of the file being invoked. + @param PeiServices Describes the list of possible PEI Services. + + @return EFI_SUCCESS The PEIM initialized successfully. +**/ +EFI_STATUS +EFIAPI +InitializePlatform ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + UINTN TranslationTableSize; + MEMORY_REGION_DESCRIPTOR *MemoryTable; + + DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n")); + + Status =3D PeiServicesSetBootMode (mBootMode); + ASSERT_EFI_ERROR (Status); + + Status =3D PeiServicesInstallPpi (&mPpiListBootMode); + ASSERT_EFI_ERROR (Status); + + ReportSystemMemorySize (); + + PublishPeiMemory (); + + PeiFvInitialization (); + InitializeRamRegions (); + MemMapInitialization (); + + Status =3D PlatformHookSerialPortInitialize (); + ASSERT_EFI_ERROR (Status); + + // + // Collect numbers of on line processors and all of APs APIC ID + // TODO: Current, the NULL library is used, this library will be populat= ed in the future. + // + CollectAllProcessorResource (); + + MiscInitialization (); + + AddFdtHob (); + + GetMemoryMapPolicy (&MemoryTable); + Status =3D ConfigureMemoryManagementUnit ( + MemoryTable, + NULL, + &TranslationTableSize + ); + ASSERT_EFI_ERROR (Status); + + // + // Open MMU. + // + DEBUG ((DEBUG_INFO, "Open MMU start.\n")); + CsrXChg (LOONGARCH_CSR_CRMD, BIT4, BIT4|BIT3); + DEBUG ((DEBUG_INFO, "Open MMU done.\n")); + + MpInitLibInitialize (); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/Platform.h b/OvmfPkg/LoongAr= chVirt/PlatformPei/Platform.h new file mode 100644 index 0000000000..0774b0e54a --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/Platform.h @@ -0,0 +1,146 @@ +/** @file + Platform PEI module include file. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PLATFORM_H_ +#define PLATFORM_H_ + +#include +#include +#include + +typedef struct { + UINT64 BaseAddr; + UINT64 Length; + UINT32 Type; + UINT32 Reserved; +} MEMMAP_ENTRY; + +VOID +EFIAPI +CollectAllProcessorResource ( + VOID + ); + +VOID +EFIAPI +SaveProcessorResource ( + VOID + ); + +/** + Create system type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); + +/** + Create memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ); + +/** + Create Reserved type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddReservedMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); + +/** + Publish PEI core memory + + @return EFI_SUCCESS The PEIM initialized successfully. +**/ +EFI_STATUS +PublishPeiMemory ( + VOID + ); + +/** + Publish system RAM and reserve memory regions + + @return VOID +**/ +VOID +InitializeRamRegions ( + VOID + ); + +/** + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI + and DXE know about them. + + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully. +**/ +EFI_STATUS +PeiFvInitialization ( + VOID + ); + +/** + Gets the Virtual Memory Map of corresponding platforms. + + This Virtual Memory Map is used by initialize the MMU on corresponding + platforms. + + @param[out] MemoryTable Array of MEMORY_REGION_DESCRIPTOR + describing a Physical-to-Virtual Memory + mapping. This array must be ended by a + zero-filled entry. The allocated memory + will not be freed. +**/ +VOID +EFIAPI +GetMemoryMapPolicy ( + OUT MEMORY_REGION_DESCRIPTOR **MemoryTable + ); + +/** + Create a page table and initialize the memory management unit(MMU). + + @param[in] MemoryTable A pointer to a memory ragion table. + @param[out] TranslationTableBase A pointer to a translation table base = address. + @param[out] TranslationTableSize A pointer to a translation table base = size. + + @retval EFI_SUCCESS Configure MMU successfully. + EFI_INVALID_PARAMETER MemoryTable is NULL. + EFI_UNSUPPORTED Out of memory space or size not alig= ned. +**/ +EFI_STATUS +EFIAPI +ConfigureMemoryManagementUnit ( + IN MEMORY_REGION_DESCRIPTOR *MemoryTable, + OUT VOID **TranslationTableBase OPTIONAL, + OUT UINTN *TranslationTableSize OPTIONAL + ); + +#endif // PLATFORM_H_ diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf b/OvmfPkg/Lo= ongArchVirt/PlatformPei/PlatformPei.inf new file mode 100644 index 0000000000..e793a4da85 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf @@ -0,0 +1,72 @@ +## @file +# Platform PEI driver +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D PlatformPei + FILE_GUID =3D 4c0e81e5-e8e3-4eef-b24b-19b686e9ab53 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InitializePlatform + +# +# VALID_ARCHITECTURES =3D LOONGARCH64 +# + +[Sources] + Fv.c + MemDetect.c + Platform.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Ppis] + gEfiPeiMasterBootModePpiGuid + +[Guids] + gEfiMemoryTypeInformationGuid + gFdtHobGuid + +[LibraryClasses] + BaseMemoryLib + CollectApResourceLib + CpuMmuLib + DebugLib + HobLib + IoLib + MemoryAllocationLib + MpInitLib + PcdLib + PeiResourcePublicationLib + PeiServicesLib + PeiServicesTablePointerLib + PeimEntryPoint + PlatformHookLib + QemuFwCfgLib + RealTimeClockLib + TimerLib + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeAllocationPadding + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask + +[FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize + gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize + gUefiCpuPkgTokenSpaceGuid.PcdCpuExceptionVectorBaseAddress + +[Depex] + TRUE --=20 2.27.0 -=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 (#114561): https://edk2.groups.io/g/devel/message/114561 Mute This Topic: https://groups.io/mt/103971687/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- From nobody Thu Dec 26 20:24:45 2024 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+114562+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+114562+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250683; cv=none; d=zohomail.com; s=zohoarc; b=TnZNX9CKRjsnw8KJQ2BjRFcCLmfPIbxpoGn3GRwIDGA4rdA2C3zGhuj/qzpswDtanHCUkl3RJHAmPVsAtSxWXIoIgmiH7Kx0Lr6rMUcRdGU3BtVtG0e+4kwLg1+VWTPtFazDCcCddh2GpYn9uYguFcpVY6WDD2g3ir5eo7/jI2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250683; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=MPy0uFmKARjgq9X/a/XkzAvs+uHD07b38RpocS/keYM=; b=D1d5xKxOc18uJGXwjRYHdCjUJkur4PjnHvDKOafSbX8o6k0BF7T9xGCxvP0+dEdGZpaIQvEOYoNNsCQpJxQ1iouEA73tyJSAMKcdope+ZW+pdAbWPGzmVl6wl4ydAWN+6n20et180bPqzWdimFpOSHalDC3BwBW0PRTCT0TSEEs= 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+114562+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250683954574.8516388400424; Thu, 25 Jan 2024 22:31:23 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=5fGgmKQ9EGVy2/yxMXxBywEZWEtX0eW1v5MQg4Hk5pc=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250683; v=1; b=ilnt6h/5W6TORuvlLZj+eHJgQJh1BG5dT9iKkRqX2CBBeNbW8Ftm7Kvmgu0saLy9IqjnCyT7 CK17TBNOixCUMrE/NypQL5jCeCdbrX52kzsIo9dEJbr2JYfT23BumZyrhYamoNk+4vBSythnzHt iaWRHtbm6K8Sz/FUKn4TtW7o= X-Received: by 127.0.0.2 with SMTP id pfc0YY1788612xd9Q76t1rLU; Thu, 25 Jan 2024 22:31:23 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10177.1706250681008350625 for ; Thu, 25 Jan 2024 22:31:23 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8DxWPC1UbNlER8GAA--.21768S3; Fri, 26 Jan 2024 14:31:17 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx_c60UbNlwHMbAA--.53367S2; Fri, 26 Jan 2024 14:31:16 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Xianglai Li Subject: [edk2-devel] [PATCH v8 36/37] OvmfPkg/LoongArchVirt: Add build file Date: Fri, 26 Jan 2024 14:31:15 +0800 Message-Id: <20240126063115.3103106-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cx_c60UbNlwHMbAA--.53367S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+AOvAAJsW X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: euxFWQou6nuZ7PUlF2VxOWaYx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250684619100001 Content-Type: text/plain; charset="utf-8" Add infrastructure files to build edk2 for LoongArch QEMU virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao Reviewed-by: Bibo Mao --- OvmfPkg/LoongArchVirt/LoongArchVirt.fdf.inc | 34 + OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc | 679 ++++++++++++++++++++ OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf | 313 +++++++++ OvmfPkg/LoongArchVirt/VarStore.fdf.inc | 67 ++ 4 files changed, 1093 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/LoongArchVirt.fdf.inc create mode 100644 OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc create mode 100644 OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf create mode 100644 OvmfPkg/LoongArchVirt/VarStore.fdf.inc diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirt.fdf.inc b/OvmfPkg/LoongArc= hVirt/LoongArchVirt.fdf.inc new file mode 100644 index 0000000000..22373bec6a --- /dev/null +++ b/OvmfPkg/LoongArchVirt/LoongArchVirt.fdf.inc @@ -0,0 +1,34 @@ +## @file +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +DEFINE BLOCK_SIZE =3D 0x1000 + +##########################################################################= ## +# FW total +DEFINE FW_BASE_ADDRESS =3D 0x1c000000 +DEFINE FW_BLOCKS =3D 0x400 +DEFINE FW_SIZE =3D 0x400000 + +##########################################################################= ## +#Flash code layout +#Set Sec size in flash +DEFINE SECFV_SIZE =3D 0x00010000 + +#Set Pei size in flash +DEFINE PEIFV_SIZE =3D 0x00040000 + +#Set Dxe size in flash +DEFINE DXEFV_SIZE =3D 0x00350000 + +#Set FVMAIN size +DEFINE FVMAIN_SIZE =3D $(SECFV_SIZE) + $(PEIFV_SIZE) +$(DXE= FV_SIZE) + +#Set Memory layout +DEFINE SEC_PEI_TEMP_RAM_BASE =3D 0x10000 +DEFINE SEC_PEI_TEMP_RAM_SIZE =3D 0x80000 +DEFINE DEVICE_TREE_RAM_BASE =3D 0x100000 diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc b/OvmfPkg/LoongArc= hVirt/LoongArchVirtQemu.dsc new file mode 100644 index 0000000000..f1cb36edae --- /dev/null +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc @@ -0,0 +1,679 @@ +## @file +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +##########################################################################= ###### +# +# Defines Section - statements that will be processed to create a Makefile. +# +##########################################################################= ##### +[Defines] + PLATFORM_NAME =3D LoongArchVirtQemu + PLATFORMPKG_NAME =3D LoongArchVirtQemu + PLATFORM_GUID =3D 7926ea52-b0dc-4ee8-ac63-341eebd84ed4 + PLATFORM_VERSION =3D 0.1 + DSC_SPECIFICATION =3D 1.29 + OUTPUT_DIRECTORY =3D Build/$(PLATFORM_NAME) + SUPPORTED_ARCHITECTURES =3D LOONGARCH64 + BUILD_TARGETS =3D DEBUG|RELEASE + SKUID_IDENTIFIER =3D DEFAULT + FLASH_DEFINITION =3D OvmfPkg/LoongArchVirt/LoongArchVirtQe= mu.fdf + TTY_TERMINAL =3D FALSE + +!include LoongArchVirt.fdf.inc + + # + # Defines for default states. These can be changed on the command line. + # -D FLAG=3DVALUE + DEFINE TTY_TERMINAL =3D FALSE + DEFINE SECURE_BOOT_ENABLE =3D FALSE + DEFINE TPM2_ENABLE =3D FALSE + DEFINE TPM2_CONFIG_ENABLE =3D FALSE + + # + # Network definition + # + DEFINE NETWORK_IP6_ENABLE =3D FALSE + DEFINE NETWORK_HTTP_BOOT_ENABLE =3D FALSE + DEFINE NETWORK_SNP_ENABLE =3D FALSE + DEFINE NETWORK_TLS_ENABLE =3D FALSE + DEFINE NETWORK_ALLOW_HTTP_CONNECTIONS =3D TRUE + DEFINE NETWORK_ISCSI_ENABLE =3D FALSE + +!include NetworkPkg/NetworkDefines.dsc.inc +##########################################################################= ## +# +# Defines for default states. These can be changed on the command line. +# -D FLAG=3DVALUE +##########################################################################= ## +[BuildOptions] + GCC:RELEASE_*_*_CC_FLAGS =3D -DSPEEDUP + + # + # Disable deprecated APIs. + # + GCC:*_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES + +!include NetworkPkg/NetworkBuildOptions.dsc.inc + +[BuildOptions.LOONGARCH64.EDKII.SEC] + *_*_*_CC_FLAGS =3D + +# +# Default page size is 16K for loongarch qemu tcg +# code section separated with data section with 16K page alignment, else d= ata +# write operation in the same page with code section will cause qemu TB fl= ush. +# +[BuildOptions.common.EDKII.DXE_CORE,BuildOptions.common.EDKII.DXE_DRIVER,B= uildOptions.common.EDKII.UEFI_DRIVER,BuildOptions.common.EDKII.UEFI_APPLICA= TION] + GCC:*_*_*_DLINK_FLAGS =3D -z common-page-size=3D0x4000 + +[BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] + GCC:*_*_LOONGARCH64_DLINK_FLAGS =3D -z common-page-size=3D0x10000 + +##########################################################################= ###### +# +# SKU Identification section - list of all SKU IDs supported by this Platf= orm. +# +##########################################################################= ###### +[SkuIds] + 0|DEFAULT + +##########################################################################= ###### +# +# Library Class section - list of all Library Classes needed by this Platf= orm. +# +##########################################################################= ###### + +!include MdePkg/MdeLibs.dsc.inc + +[LibraryClasses.common] + PcdLib | MdePkg/Library/DxePcdLib/DxePcdLib.inf + TimerLib | UefiCpuPkg/Library/CpuTimerLib/BaseCp= uTimerLib.inf + PrintLib | MdePkg/Library/BasePrintLib/BasePrint= Lib.inf + BaseMemoryLib | MdePkg/Library/BaseMemoryLib/BaseMemo= ryLib.inf + + # Networking Requirements +!include NetworkPkg/NetworkLibs.dsc.inc +!if $(NETWORK_TLS_ENABLE) =3D=3D TRUE + TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf +!endif + + # For stack protector support + NULL | MdePkg/Library/BaseStackCheckLib/Base= StackCheckLib.inf + + BaseLib | MdePkg/Library/BaseLib/BaseLib.inf + SafeIntLib | MdePkg/Library/BaseSafeIntLib/BaseSaf= eIntLib.inf + TimeBaseLib | EmbeddedPkg/Library/TimeBaseLib/TimeB= aseLib.inf + BmpSupportLib | MdeModulePkg/Library/BaseBmpSupportLi= b/BaseBmpSupportLib.inf + SynchronizationLib | MdePkg/Library/BaseSynchronizationLib= /BaseSynchronizationLib.inf + CpuLib | MdePkg/Library/BaseCpuLib/BaseCpuLib.= inf + PerformanceLib | MdePkg/Library/BasePerformanceLibNull= /BasePerformanceLibNull.inf + PeCoffLib | MdePkg/Library/BasePeCoffLib/BasePeCo= ffLib.inf + CacheMaintenanceLib | MdePkg/Library/BaseCacheMaintenanceLi= b/BaseCacheMaintenanceLib.inf + UefiDecompressLib | MdePkg/Library/BaseUefiDecompressLib/= BaseUefiDecompressLib.inf + UefiHiiServicesLib | MdeModulePkg/Library/UefiHiiServicesL= ib/UefiHiiServicesLib.inf + HiiLib | MdeModulePkg/Library/UefiHiiLib/UefiH= iiLib.inf + CapsuleLib | MdeModulePkg/Library/DxeCapsuleLibNul= l/DxeCapsuleLibNull.inf + DxeServicesLib | MdePkg/Library/DxeServicesLib/DxeServ= icesLib.inf + DxeServicesTableLib | MdePkg/Library/DxeServicesTableLib/Dx= eServicesTableLib.inf + PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf + PciLib | MdePkg/Library/BasePciLibPciExpress/B= asePciLibPciExpress.inf + PciExpressLib | OvmfPkg/Library/BaseCachingPciExpress= Lib/BaseCachingPciExpressLib.inf + PciCapLib | OvmfPkg/Library/BasePciCapLib/BasePci= CapLib.inf + PciCapPciSegmentLib | OvmfPkg/Library/BasePciCapPciSegmentL= ib/BasePciCapPciSegmentLib.inf + PciCapPciIoLib | OvmfPkg/Library/UefiPciCapPciIoLib/Ue= fiPciCapPciIoLib.inf + DxeHardwareInfoLib | OvmfPkg/Library/HardwareInfoLib/DxeHa= rdwareInfoLib.inf + IoLib | MdePkg/Library/BaseIoLibIntrinsic/Bas= eIoLibIntrinsic.inf + FdtSerialPortAddressLib | OvmfPkg/Library/FdtSerialPortAddressL= ib/FdtSerialPortAddressLib.inf + PlatformHookLib | OvmfPkg/LoongArchVirt/Library/Fdt1655= 0SerialPortHookLib/Fdt16550SerialPortHookLib.inf + SerialPortLib | MdeModulePkg/Library/BaseSerialPortLi= b16550/BaseSerialPortLib16550.inf + EfiResetSystemLib | OvmfPkg/LoongArchVirt/Library/ResetSy= stemAcpiLib/BaseResetSystemAcpiGedLib.inf + ResetSystemLib | OvmfPkg/LoongArchVirt/Library/ResetSy= stemAcpiLib/BaseResetSystemAcpiGedLib.inf + + UefiLib | MdePkg/Library/UefiLib/UefiLib.inf + UefiBootServicesTableLib | MdePkg/Library/UefiBootServicesTableL= ib/UefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib | MdePkg/Library/UefiRuntimeServicesTab= leLib/UefiRuntimeServicesTableLib.inf + UefiDriverEntryPoint | MdePkg/Library/UefiDriverEntryPoint/U= efiDriverEntryPoint.inf + UefiApplicationEntryPoint | MdePkg/Library/UefiApplicationEntryPo= int/UefiApplicationEntryPoint.inf + DevicePathLib | MdePkg/Library/UefiDevicePathLibDevic= ePathProtocol/UefiDevicePathLibDevicePathProtocol.inf + FileHandleLib | MdePkg/Library/UefiFileHandleLib/Uefi= FileHandleLib.inf + SecurityManagementLib | MdeModulePkg/Library/DxeSecurityManag= ementLib/DxeSecurityManagementLib.inf + UefiUsbLib | MdePkg/Library/UefiUsbLib/UefiUsbLib.= inf + SerializeVariablesLib | OvmfPkg/Library/SerializeVariablesLib= /SerializeVariablesLib.inf + CustomizedDisplayLib | MdeModulePkg/Library/CustomizedDispla= yLib/CustomizedDisplayLib.inf + DebugPrintErrorLevelLib | MdePkg/Library/BaseDebugPrintErrorLev= elLib/BaseDebugPrintErrorLevelLib.inf + TpmMeasurementLib | MdeModulePkg/Library/TpmMeasurementLi= bNull/TpmMeasurementLibNull.inf + AuthVariableLib | MdeModulePkg/Library/AuthVariableLibN= ull/AuthVariableLibNull.inf + VarCheckLib | MdeModulePkg/Library/VarCheckLib/VarC= heckLib.inf + VariablePolicyLib | MdeModulePkg/Library/VariablePolicyLi= b/VariablePolicyLib.inf + VariablePolicyHelperLib | MdeModulePkg/Library/VariablePolicyHe= lperLib/VariablePolicyHelperLib.inf + SortLib | MdeModulePkg/Library/UefiSortLib/Uefi= SortLib.inf + FdtLib | EmbeddedPkg/Library/FdtLib/FdtLib.inf + PciSegmentLib | MdePkg/Library/BasePciSegmentLibPci/B= asePciSegmentLibPci.inf + PciHostBridgeLib | OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPc= iHostBridgeLib.inf + PciHostBridgeUtilityLib | OvmfPkg/Library/PciHostBridgeUtilityL= ib/PciHostBridgeUtilityLib.inf + FileExplorerLib | MdeModulePkg/Library/FileExplorerLib/= FileExplorerLib.inf + ImagePropertiesRecordLib | MdeModulePkg/Library/ImagePropertiesR= ecordLib/ImagePropertiesRecordLib.inf + +!if $(HTTP_BOOT_ENABLE) =3D=3D TRUE + HttpLib | MdeModulePkg/Library/DxeHttpLib/DxeHt= tpLib.inf +!endif + UefiBootManagerLib | MdeModulePkg/Library/UefiBootManagerL= ib/UefiBootManagerLib.inf + OrderedCollectionLib | MdePkg/Library/BaseOrderedCollectionR= edBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf + ReportStatusCodeLib | MdePkg/Library/BaseReportStatusCodeLi= bNull/BaseReportStatusCodeLibNull.inf + + PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf + PeCoffExtraActionLib | MdePkg/Library/BasePeCoffExtraActionL= ibNull/BasePeCoffExtraActionLibNull.inf + DebugAgentLib | MdeModulePkg/Library/DebugAgentLibNul= l/DebugAgentLibNull.inf + + TpmPlatformHierarchyLib | SecurityPkg/Library/PeiDxeTpmPlatform= HierarchyLibNull/PeiDxeTpmPlatformHierarchyLib.inf + PlatformBmPrintScLib | OvmfPkg/Library/PlatformBmPrintScLib/= PlatformBmPrintScLib.inf + PlatformBootManagerLib | OvmfPkg/Library/PlatformBootManagerLi= bLight/PlatformBootManagerLib.inf + BootLogoLib | MdeModulePkg/Library/BootLogoLib/Boot= LogoLib.inf + QemuBootOrderLib | OvmfPkg/Library/QemuBootOrderLib/Qemu= BootOrderLib.inf + QemuFwCfgSimpleParserLib | OvmfPkg/Library/QemuFwCfgSimpleParser= Lib/QemuFwCfgSimpleParserLib.inf + QemuLoadImageLib | OvmfPkg/Library/GenericQemuLoadImageL= ib/GenericQemuLoadImageLib.inf + + # + # Virtio Support + # + VirtioLib | OvmfPkg/Library/VirtioLib/VirtioLib.i= nf + FrameBufferBltLib | MdeModulePkg/Library/FrameBufferBltLi= b/FrameBufferBltLib.inf + QemuFwCfgLib | OvmfPkg/Library/QemuFwCfgLib/QemuFwCf= gLibMmio.inf + DebugLib | MdePkg/Library/BaseDebugLibSerialPort= /BaseDebugLibSerialPort.inf + PeiServicesLib | MdePkg/Library/PeiServicesLib/PeiServ= icesLib.inf + VariableFlashInfoLib | MdeModulePkg/Library/BaseVariableFlas= hInfoLib/BaseVariableFlashInfoLib.inf + VirtNorFlashPlatformLib | OvmfPkg/LoongArchVirt/Library/NorFlas= hQemuLib/NorFlashQemuLib.inf + CollectApResourceLib | OvmfPkg/LoongArchVirt/Library/Collect= ApResouceLibNull/CollectApResourceLibNull.inf + +[LibraryClasses.common.SEC] + PcdLib | MdePkg/Library/BasePcdLibNull/BasePcd= LibNull.inf + ReportStatusCodeLib | MdeModulePkg/Library/PeiReportStatusC= odeLib/PeiReportStatusCodeLib.inf + HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.inf + MemoryAllocationLib | MdePkg/Library/PeiMemoryAllocationLib= /PeiMemoryAllocationLib.inf + PeiServicesTablePointerLib | MdePkg/Library/PeiServicesTablePointe= rLibKs0/PeiServicesTablePointerLibKs0.inf + PlatformHookLib | OvmfPkg/LoongArchVirt/Library/Fdt1655= 0SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf + SerialPortLib | OvmfPkg/LoongArchVirt/Library/EarlyFd= tSerialPortLib16550/EarlyFdtSerialPortLib16550.inf + CpuExceptionHandlerLib | UefiCpuPkg/Library/CpuExceptionHandle= rLib/SecPeiCpuExceptionHandlerLib.inf + +[LibraryClasses.common.PEI_CORE] + PcdLib | MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.inf + PeiServicesTablePointerLib | MdePkg/Library/PeiServicesTablePointe= rLibKs0/PeiServicesTablePointerLibKs0.inf + MemoryAllocationLib | MdePkg/Library/PeiMemoryAllocationLib= /PeiMemoryAllocationLib.inf + PeiCoreEntryPoint | MdePkg/Library/PeiCoreEntryPoint/PeiC= oreEntryPoint.inf + ReportStatusCodeLib | MdeModulePkg/Library/PeiReportStatusC= odeLib/PeiReportStatusCodeLib.inf + OemHookStatusCodeLib | MdeModulePkg/Library/OemHookStatusCod= eLibNull/OemHookStatusCodeLibNull.inf + PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf + QemuFwCfgLib | OvmfPkg/LoongArchVirt/Library/FdtQemu= FwCfgLib/FdtQemuFwCfgPeiLib.inf + PlatformHookLib | OvmfPkg/LoongArchVirt/Library/Fdt1655= 0SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf + SerialPortLib | OvmfPkg/LoongArchVirt/Library/EarlyFd= tSerialPortLib16550/EarlyFdtSerialPortLib16550.inf + +[LibraryClasses.common.PEIM] + HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.inf + PeiServicesTablePointerLib | MdePkg/Library/PeiServicesTablePointe= rLibKs0/PeiServicesTablePointerLibKs0.inf + MemoryAllocationLib | MdePkg/Library/PeiMemoryAllocationLib= /PeiMemoryAllocationLib.inf + PeimEntryPoint | MdePkg/Library/PeimEntryPoint/PeimEnt= ryPoint.inf + ReportStatusCodeLib | MdeModulePkg/Library/PeiReportStatusC= odeLib/PeiReportStatusCodeLib.inf + OemHookStatusCodeLib | MdeModulePkg/Library/OemHookStatusCod= eLibNull/OemHookStatusCodeLibNull.inf + PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf + PeiResourcePublicationLib | MdePkg/Library/PeiResourcePublication= Lib/PeiResourcePublicationLib.inf + ExtractGuidedSectionLib | MdePkg/Library/PeiExtractGuidedSectio= nLib/PeiExtractGuidedSectionLib.inf + PcdLib | MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + QemuFwCfgS3Lib | OvmfPkg/Library/QemuFwCfgS3Lib/PeiQem= uFwCfgS3LibFwCfg.inf + QemuFwCfgLib | OvmfPkg/LoongArchVirt/Library/FdtQemu= FwCfgLib/FdtQemuFwCfgPeiLib.inf + CpuMmuLib | UefiCpuPkg/Library/CpuMmuLib/PeiCpuMm= uLib.inf + MpInitLib | UefiCpuPkg/Library/MpInitLib/PeiMpIni= tLib.inf + PlatformHookLib | OvmfPkg/LoongArchVirt/Library/Fdt1655= 0SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf + SerialPortLib | OvmfPkg/LoongArchVirt/Library/EarlyFd= tSerialPortLib16550/EarlyFdtSerialPortLib16550.inf + RealTimeClockLib | OvmfPkg/LoongArchVirt/Library/LsRealT= imeClockLib/PeiLsRealTimeClockLib.inf + +[LibraryClasses.common.DXE_CORE] + HobLib | MdePkg/Library/DxeCoreHobLib/DxeCoreH= obLib.inf + DxeCoreEntryPoint | MdePkg/Library/DxeCoreEntryPoint/DxeC= oreEntryPoint.inf + MemoryAllocationLib | MdeModulePkg/Library/DxeCoreMemoryAll= ocationLib/DxeCoreMemoryAllocationLib.inf + ReportStatusCodeLib | MdeModulePkg/Library/DxeReportStatusC= odeLib/DxeReportStatusCodeLib.inf + PciExpressLib | MdePkg/Library/BasePciExpressLib/Base= PciExpressLib.inf + PciPcdProducerLib | OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtP= ciPcdProducerLib.inf + CpuExceptionHandlerLib | UefiCpuPkg/Library/CpuExceptionHandle= rLib/DxeCpuExceptionHandlerLib.inf + +[LibraryClasses.common.DXE_RUNTIME_DRIVER] + PcdLib | MdePkg/Library/DxePcdLib/DxePcdLib.inf + HobLib | MdePkg/Library/DxeHobLib/DxeHobLib.inf + DxeCoreEntryPoint | MdePkg/Library/DxeCoreEntryPoint/DxeC= oreEntryPoint.inf + MemoryAllocationLib | MdePkg/Library/UefiMemoryAllocationLi= b/UefiMemoryAllocationLib.inf + ReportStatusCodeLib | MdeModulePkg/Library/RuntimeDxeReport= StatusCodeLib/RuntimeDxeReportStatusCodeLib.inf + UefiRuntimeLib | MdePkg/Library/UefiRuntimeLib/UefiRun= timeLib.inf + ExtractGuidedSectionLib | MdePkg/Library/PeiExtractGuidedSectio= nLib/PeiExtractGuidedSectionLib.inf + QemuFwCfgS3Lib | OvmfPkg/Library/QemuFwCfgS3Lib/DxeQem= uFwCfgS3LibFwCfg.inf + RealTimeClockLib | OvmfPkg/LoongArchVirt/Library/LsRealT= imeClockLib/DxeLsRealTimeClockLib.inf + VariablePolicyLib | MdeModulePkg/Library/VariablePolicyLi= b/VariablePolicyLibRuntimeDxe.inf + QemuFwCfgLib | OvmfPkg/Library/QemuFwCfgLib/QemuFwCf= gLibMmio.inf + EfiResetSystemLib | OvmfPkg/LoongArchVirt/Library/ResetSy= stemAcpiLib/DxeResetSystemAcpiGedLib.inf + ResetSystemLib | OvmfPkg/LoongArchVirt/Library/ResetSy= stemAcpiLib/DxeResetSystemAcpiGedLib.inf + PciExpressLib | MdePkg/Library/BasePciExpressLib/Base= PciExpressLib.inf +!if $(TARGET) !=3D RELEASE + DebugLib | MdePkg/Library/DxeRuntimeDebugLibSeri= alPort/DxeRuntimeDebugLibSerialPort.inf +!endif + +[LibraryClasses.common.UEFI_DRIVER] + PcdLib | MdePkg/Library/DxePcdLib/DxePcdLib.inf + HobLib | MdePkg/Library/DxeHobLib/DxeHobLib.inf + DxeCoreEntryPoint | MdePkg/Library/DxeCoreEntryPoint/DxeC= oreEntryPoint.inf + MemoryAllocationLib | MdePkg/Library/UefiMemoryAllocationLi= b/UefiMemoryAllocationLib.inf + ReportStatusCodeLib | MdeModulePkg/Library/DxeReportStatusC= odeLib/DxeReportStatusCodeLib.inf + UefiScsiLib | MdePkg/Library/UefiScsiLib/UefiScsiLi= b.inf + ExtractGuidedSectionLib | MdePkg/Library/PeiExtractGuidedSectio= nLib/PeiExtractGuidedSectionLib.inf + QemuFwCfgLib | OvmfPkg/Library/QemuFwCfgLib/QemuFwCf= gLibMmio.inf + PciPcdProducerLib | OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtP= ciPcdProducerLib.inf + +[LibraryClasses.common.DXE_DRIVER] + PcdLib | MdePkg/Library/DxePcdLib/DxePcdLib.inf + HobLib | MdePkg/Library/DxeHobLib/DxeHobLib.inf + MemoryAllocationLib | MdePkg/Library/UefiMemoryAllocationLi= b/UefiMemoryAllocationLib.inf + ReportStatusCodeLib | MdeModulePkg/Library/DxeReportStatusC= odeLib/DxeReportStatusCodeLib.inf + UefiScsiLib | MdePkg/Library/UefiScsiLib/UefiScsiLi= b.inf + CpuExceptionHandlerLib | UefiCpuPkg/Library/CpuExceptionHandle= rLib/DxeCpuExceptionHandlerLib.inf + ExtractGuidedSectionLib | MdePkg/Library/DxeExtractGuidedSectio= nLib/DxeExtractGuidedSectionLib.inf + QemuFwCfgS3Lib | OvmfPkg/Library/QemuFwCfgS3Lib/DxeQem= uFwCfgS3LibFwCfg.inf + QemuFwCfgLib | OvmfPkg/Library/QemuFwCfgLib/QemuFwCf= gLibMmio.inf + PciPcdProducerLib | OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtP= ciPcdProducerLib.inf + PciExpressLib | MdePkg/Library/BasePciExpressLib/Base= PciExpressLib.inf + AcpiPlatformLib | OvmfPkg/Library/AcpiPlatformLib/DxeAc= piPlatformLib.inf + MpInitLib | UefiCpuPkg/Library/MpInitLib/DxeMpIni= tLib.inf + +[LibraryClasses.common.UEFI_APPLICATION] + PcdLib | MdePkg/Library/DxePcdLib/DxePcdLib.inf + HobLib | MdePkg/Library/DxeHobLib/DxeHobLib.inf + MemoryAllocationLib | MdePkg/Library/UefiMemoryAllocationLi= b/UefiMemoryAllocationLib.inf + ExtractGuidedSectionLib | MdePkg/Library/DxeExtractGuidedSectio= nLib/DxeExtractGuidedSectionLib.inf + PciPcdProducerLib | OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtP= ciPcdProducerLib.inf + PciExpressLib | MdePkg/Library/BasePciExpressLib/Base= PciExpressLib.inf + +##########################################################################= ###### +# +# Pcd Section - list of all EDK II PCD Entries defined by this Platform. +# +##########################################################################= ###### +[PcdsFeatureFlag] + gEfiMdeModulePkgTokenSpaceGuid.PcdHiiOsRuntimeSupport | F= ALSE +# gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial | T= RUE +# gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory | T= RUE + gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportUefiDecompress | T= RUE + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport | T= RUE + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport | F= ALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdPciBusHotplugDeviceSupport | F= ALSE + gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation | T= RUE + gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation | T= RUE +[PcdsFixedAtBuild] +## BaseLib ## + gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength | 1= 000000 + gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength | 1= 000000 + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength | 1= 000000 + gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout | 1= 0000000 + + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress | $= (FW_BASE_ADDRESS) + + gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize | 1 + gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange | F= ALSE + gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler | 0= x10 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize | 0= x2000 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize | 0= x8000 + gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress | 0= x0 + gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask | 0= x07 + + # Use MMIO for accessing Serial port registers. + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio | T= RUE + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo | {= 0xFF} + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate | 1= 15200 + + # DEBUG_INIT 0x00000001 // Initialization + # DEBUG_WARN 0x00000002 // Warnings + # DEBUG_LOAD 0x00000004 // Load events + # DEBUG_FS 0x00000008 // EFI File system + # DEBUG_POOL 0x00000010 // Alloc & Free (pool) + # DEBUG_PAGE 0x00000020 // Alloc & Free (page) + # DEBUG_INFO 0x00000040 // Informational debug messages + # DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers + # DEBUG_VARIABLE 0x00000100 // Variable + # DEBUG_BM 0x00000400 // Boot Manager + # DEBUG_BLKIO 0x00001000 // BlkIo Driver + # DEBUG_NET 0x00004000 // Network Io Driver + # DEBUG_UNDI 0x00010000 // UNDI Driver + # DEBUG_LOADFILE 0x00020000 // LoadFile + # DEBUG_EVENT 0x00080000 // Event messages + # DEBUG_GCD 0x00100000 // Global Coherency Database changes + # DEBUG_CACHE 0x00200000 // Memory range cachability changes + # DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may + # DEBUG_ERROR 0x80000000 // Error + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel | 0= x8000004F + + # DEBUG_ASSERT_ENABLED 0x01 + # DEBUG_PRINT_ENABLED 0x02 + # DEBUG_CODE_ENABLED 0x04 + # CLEAR_MEMORY_ENABLED 0x08 + # ASSERT_BREAKPOINT_ENABLED 0x10 + # ASSERT_DEADLOOP_ENABLED 0x20 +!if $(TARGET) =3D=3D RELEASE + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask | 0= x21 +!else + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask | 0= x2f +!endif + +##########################################################################= ############# + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase | $= (SEC_PEI_TEMP_RAM_BASE) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize | $= (SEC_PEI_TEMP_RAM_SIZE) + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress | $= (DEVICE_TREE_RAM_BASE) + + gUefiCpuPkgTokenSpaceGuid.PcdCpuExceptionVectorBaseAddress | g= UefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase + + # + # minimal memory for uefi bios should be 512M + # 0x00000000 - 0x10000000 + # 0x90000000 - 0xA0000000 + # + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions | 0= x06 + + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile | {= 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0x= f4, 0x66, 0x23, 0x31 } + + # + # Network Pcds + # +!include NetworkPkg/NetworkPcds.dsc.inc + + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize | 0= x40000 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize | 0= x40000 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize | 0= x40000 + + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask | 1 + +##########################################################################= ###### +# +# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Pla= tform +# +##########################################################################= ###### +[PcdsDynamicDefault] + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase | 0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 | 0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 | 0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase | 0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase | 0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 | 0 + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved | 0 + gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration | F= ALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution | 8= 00 + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution | 6= 00 + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut | 2 + + # Set video resolution for text setup. + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution | 6= 40 + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution | 4= 80 + + gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion | 0= x0300 + gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev | 0= x0 + + ## If TRUE, OvmfPkg/AcpiPlatformDxe will not wait for PCI + # enumeration to complete before installing ACPI tables. + gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration |TR= UE + gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation |0x0 + # set PcdPciExpressBaseAddress to MAX_UINT64, which signifies that this + # PCD and PcdPciDisableBusEnumeration above have not been assigned yet + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress |0x= FFFFFFFFFFFFFFFF + + # + # IPv4 and IPv6 PXE Boot support. + # + gEfiNetworkPkgTokenSpaceGuid.PcdIPv4PXESupport | 0= x01 + gEfiNetworkPkgTokenSpaceGuid.PcdIPv6PXESupport | 0= x01 + + # + # SMBIOS entry point version + # + gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion|0x0300 + gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 + gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|TRUE + +[PcdsPatchableInModule.common] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x0 + +[Components] + + # + # SEC Phase modules + # + OvmfPkg/LoongArchVirt/Sec/SecMain.inf + + # + # PEI Phase modules + # + MdeModulePkg/Core/Pei/PeiMain.inf + MdeModulePkg/Universal/PCD/Pei/Pcd.inf { + + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf + MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf { + + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompre= ssLib.inf + } + + OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf { + + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + } + + # + # DXE Phase modules + # + MdeModulePkg/Core/Dxe/DxeMain.inf { + + NULL | MdeModulePkg/Library/LzmaCustomDe= compressLib/LzmaCustomDecompressLib.inf + DevicePathLib | MdePkg/Library/UefiDevicePathLib/= UefiDevicePathLib.inf + ExtractGuidedSectionLib | MdePkg/Library/DxeExtractGuidedSe= ctionLib/DxeExtractGuidedSectionLib.inf + } + + MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCod= eRouterRuntimeDxe.inf + MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRun= timeDxe.inf + MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { + + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + + MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf + UefiCpuPkg/CpuDxe/CpuDxe.inf { + + CpuMmuLib | UefiCpuPkg/Library/CpuMmuLib/DxeCpuMmuLib.inf + } + MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf + MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntim= eDxe.inf + MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf + OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/TimerDxe.inf + MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf + MdeModulePkg/Universal/Metronome/Metronome.inf + EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf + + # + # Variable + # + OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { + + NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf + NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedL= ib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + } + + # + # Platform Driver + # + OvmfPkg/VirtioBlkDxe/VirtioBlk.inf + OvmfPkg/VirtioScsiDxe/VirtioScsi.inf + OvmfPkg/VirtioRngDxe/VirtioRng.inf + + # + # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs + # + MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf + MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf + MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf + FatPkg/EnhancedFatDxe/Fat.inf + MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf + + # + #BDS + # + MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf { + + DevicePathLib | MdePkg/Library/UefiDevicePathLib/= UefiDevicePathLib.inf + PcdLib | MdePkg/Library/BasePcdLibNull/Bas= ePcdLibNull.inf + } + MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf + MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf + MdeModulePkg/Logo/LogoDxe.inf + MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf + MdeModulePkg/Application/UiApp/UiApp.inf { + + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc= eManagerUiLib.inf + } + + OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf { + + NULL|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf + } + + # + # Network Support + # +#!include NetworkPkg/NetworkComponents.dsc.inc + +# NetworkPkg/UefiPxeBcDxe/UefiPxeBcDxe.inf { +# +# NULL|OvmfPkg/Library/PxeBcPcdProducerLib/PxeBcPcdProducerLib.inf +# } + +!if $(NETWORK_TLS_ENABLE) =3D=3D TRUE + NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf { + + NULL|OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf + } +!endif + OvmfPkg/VirtioNetDxe/VirtioNet.inf + + # + # IDE/SCSI + # + MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.inf + MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf + MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf + + # + # NVME Driver + # + MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf + + # + # SMBIOS Support + # + MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf { + + NULL | OvmfPkg/Library/SmbiosVersionLib/= DetectSmbiosVersionLib.inf + } + OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf + + # + # PCI + # + UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf { + + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressL= ib.inf + } + EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf + MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { + + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressL= ib.inf + } + MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { + + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressL= ib.inf + } + OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf + OvmfPkg/Virtio10Dxe/Virtio10.inf + + # + # Console + # + MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf + MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf + MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf + MdeModulePkg/Universal/PrintDxe/PrintDxe.inf + MdeModulePkg/Universal/SerialDxe/SerialDxe.inf + MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf= { + + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + } + + # + # Video + # + OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf + OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf + OvmfPkg/VirtioGpuDxe/VirtioGpu.inf + OvmfPkg/PlatformDxe/Platform.inf + + # + # Usb Support + # + MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf + MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf + MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf + MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf + MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf + MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf + + # + # ACPI Support + # + MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf + MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsRes= ourceTableDxe.inf + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf { + + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + } + + # + #app + # + ShellPkg/Application/Shell/Shell.inf { + + ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellComman= dLib.inf + NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2Comm= andsLib.inf + NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1Comm= andsLib.inf + NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3Comm= andsLib.inf + NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1Co= mmandsLib.inf + NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comm= andsLib.inf + NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1= CommandsLib.inf + NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1= CommandsLib.inf + HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandlePar= singLib.inf + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcf= gCommandLib.inf + + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|8000 + } diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf b/OvmfPkg/LoongArc= hVirt/LoongArchVirtQemu.fdf new file mode 100644 index 0000000000..6fc52173e8 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf @@ -0,0 +1,313 @@ +## @file +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +##########################################################################= ########################### +[Defines] +!include LoongArchVirt.fdf.inc + +##########################################################################= ########################### +[FD.QEMU_EFI] +BaseAddress =3D $(FW_BASE_ADDRESS) +Size =3D $(FW_SIZE) +ErasePolarity =3D 1 +BlockSize =3D $(BLOCK_SIZE) +NumBlocks =3D $(FW_BLOCKS) + +0x0|$(FVMAIN_SIZE) +FV =3D FVMAIN_COMPACT + +!include VarStore.fdf.inc + +##########################################################################= ########################### +[FV.DXEFV] +FvNameGuid =3D 5d19a5b3-130f-459b-a292-9270a9e6bc62 +BlockSize =3D $(BLOCK_SIZE) +FvAlignment =3D 16 +ERASE_POLARITY =3D 1 +MEMORY_MAPPED =3D TRUE +STICKY_WRITE =3D TRUE +LOCK_CAP =3D TRUE +LOCK_STATUS =3D TRUE +READ_DISABLED_CAP =3D TRUE +READ_ENABLED_CAP =3D TRUE +READ_STATUS =3D TRUE +READ_LOCK_CAP =3D TRUE +READ_LOCK_STATUS =3D TRUE +WRITE_DISABLED_CAP =3D TRUE +WRITE_ENABLED_CAP =3D TRUE +WRITE_STATUS =3D TRUE +WRITE_LOCK_CAP =3D TRUE +WRITE_LOCK_STATUS =3D TRUE + +APRIORI DXE { + INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf +} + +# +# DXE Phase modules +# +INF MdeModulePkg/Core/Dxe/DxeMain.inf + +INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatus= CodeRouterRuntimeDxe.inf +INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandler= RuntimeDxe.inf +INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf +INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf +INF UefiCpuPkg/CpuDxe/CpuDxe.inf +INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf +INF OvmfPkg/LoongArchVirt/Drivers/StableTimerDxe/TimerDxe.inf +INF MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf +INF MdeModulePkg/Universal/Metronome/Metronome.inf +INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf +INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRun= timeDxe.inf +INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf +INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + +# +# Variable +# +INF OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf +INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf +INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf +# +# PCI +# +INF UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf +INF EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf +INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf +INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf +INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf +INF OvmfPkg/Virtio10Dxe/Virtio10.inf + +# +# Platform Driver +# +INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf +INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf +INF OvmfPkg/VirtioRngDxe/VirtioRng.inf +INF OvmfPkg/VirtioNetDxe/VirtioNet.inf + +# +# Console +# +INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf +INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf +INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf +INF MdeModulePkg/Universal/PrintDxe/PrintDxe.inf +INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf +INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.= inf + +# +#Video +# +INF OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf +INF OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf +INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf +INF OvmfPkg/PlatformDxe/Platform.inf + +# +# SATA/SCSI +# +INF MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.inf +INF MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf +INF MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf + +# +# NVME +# +INF MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf + +# +# Usb Support +# +INF MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf +INF MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf +INF MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf +INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf +INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf +INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf + +# +#BDS +# +INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf +INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf +INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf +INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +INF MdeModulePkg/Logo/LogoDxe.inf +INF MdeModulePkg/Application/UiApp/UiApp.inf +INF OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf + +# +#Smbios +# +INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf +INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf + +# +#Acpi +# +INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf +INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphics= ResourceTableDxe.inf +INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf + +# +# Network modules +#!include NetworkPkg/Network.fdf.inc + +# +# File system +# +INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf +INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf +INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf +INF FatPkg/EnhancedFatDxe/Fat.inf +INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf + +# +#Boot OS +# +INF ShellPkg/Application/Shell/Shell.inf + +##########################################################################= ########################### +[FV.FVMAIN_COMPACT] +FvNameGuid =3D af8c3fe8-9ce8-4548-884a-e3f4dd91f040 +FvAlignment =3D 16 +ERASE_POLARITY =3D 1 +MEMORY_MAPPED =3D TRUE +STICKY_WRITE =3D TRUE +LOCK_CAP =3D TRUE +LOCK_STATUS =3D TRUE +WRITE_DISABLED_CAP =3D TRUE +WRITE_ENABLED_CAP =3D TRUE +WRITE_STATUS =3D TRUE +WRITE_LOCK_CAP =3D TRUE +WRITE_LOCK_STATUS =3D TRUE +READ_DISABLED_CAP =3D TRUE +READ_ENABLED_CAP =3D TRUE +READ_STATUS =3D TRUE +READ_LOCK_CAP =3D TRUE +READ_LOCK_STATUS =3D TRUE + +# +# +# PEI Phase priori modules +# +APRIORI PEI { + INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf +} + +# +# SEC Phase modules +# +INF OvmfPkg/LoongArchVirt/Sec/SecMain.inf + +# +# PEI Phase modules +# +INF MdeModulePkg/Core/Pei/PeiMain.inf +INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf +INF OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf +INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf + +# +# DXE Phase modules +# +FILE FV_IMAGE =3D 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 { + SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED= =3D TRUE { + SECTION FV_IMAGE =3D DXEFV + } + } + +##########################################################################= ########################### +[Rule.Common.SEC] + FILE SEC =3D $(NAMED_GUID) { + TE TE Align =3D Auto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING =3D"$(MODULE_NAME)" Optional + } + +##########################################################################= ########################### +[Rule.Common.PEI_CORE] + FILE PEI_CORE =3D $(NAMED_GUID) { + TE TE Align=3DAuto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING =3D"$(MODULE_NAME)" Optional + } + +##########################################################################= ########################### +[Rule.Common.PEIM] + FILE PEIM =3D $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align=3DAuto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + } + +##########################################################################= ########################### +[Rule.Common.DXE_CORE] + FILE DXE_CORE =3D $(NAMED_GUID) { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + } + +##########################################################################= ########################### +[Rule.Common.DXE_DRIVER] + FILE DRIVER =3D $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + RAW ACPI Optional |.acpi + RAW ASL Optional |.aml + } + +##########################################################################= ########################### +[Rule.Common.DXE_RUNTIME_DRIVER] + FILE DRIVER =3D $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + } + +##########################################################################= ########################### +[Rule.Common.UEFI_DRIVER] + FILE DRIVER =3D $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + } + +##########################################################################= ########################### +[Rule.Common.UEFI_DRIVER.BINARY] + FILE DRIVER =3D $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional |.depex + PE32 PE32 |.efi + UI STRING=3D"$(MODULE_NAME)" Optional + VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBE= R) + } + +##########################################################################= ########################### +[Rule.Common.UEFI_APPLICATION] + FILE APPLICATION =3D $(NAMED_GUID) { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + } + +##########################################################################= ########################### +[Rule.Common.UEFI_APPLICATION.BINARY] + FILE APPLICATION =3D $(NAMED_GUID) { + PE32 PE32 |.efi + UI STRING=3D"$(MODULE_NAME)" Optional + VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBE= R) + } + +##########################################################################= ########################### +[Rule.Common.USER_DEFINED.ACPITABLE] + FILE FREEFORM =3D $(NAMED_GUID) { + RAW ACPI |.acpi + RAW ASL |.aml + } diff --git a/OvmfPkg/LoongArchVirt/VarStore.fdf.inc b/OvmfPkg/LoongArchVirt= /VarStore.fdf.inc new file mode 100644 index 0000000000..52ef0d482e --- /dev/null +++ b/OvmfPkg/LoongArchVirt/VarStore.fdf.inc @@ -0,0 +1,67 @@ +## @file +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[FD.QEMU_VARS] +BaseAddress =3D 0x0 +Size =3D 0x1000000 +ErasePolarity =3D 1 +BlockSize =3D 0x20000 +NumBlocks =3D 128 + +0x00000000|0x00040000 +#NV_VARIABLE_STORE +DATA =3D { + ## This is the EFI_FIRMWARE_VOLUME_HEADER + # ZeroVector [] + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + # FileSystemGuid: gEfiSystemNvDataFvGuid =3D + # { 0xFFF12B8D, 0x7696, 0x4C8B, + # { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }} + 0x8D, 0x2B, 0xF1, 0xFF, 0x96, 0x76, 0x8B, 0x4C, + 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50, + # FvLength: 0xC0000 + 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, + # Signature "_FVH" # Attributes + 0x5f, 0x46, 0x56, 0x48, 0xff, 0xfe, 0x04, 0x00, + # HeaderLength # CheckSum # ExtHeaderOffset #Reserved #Revision + 0x48, 0x00, 0x28, 0x09, 0x00, 0x00, 0x00, 0x02, + # Blockmap[0]: 0x3 Blocks * 0x40000 Bytes / Block + 0x3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + # Blockmap[1]: End + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ## This is the VARIABLE_STORE_HEADER + # It is compatible with SECURE_BOOT_ENABLE =3D=3D FALSE as well. + # Signature: gEfiAuthenticatedVariableGuid =3D + # { 0xaaf32c78, 0x947b, 0x439a, + # { 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92 }} + 0x78, 0x2c, 0xf3, 0xaa, 0x7b, 0x94, 0x9a, 0x43, + 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92, + # Size: 0x40000 (gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariabl= eSize) - + # 0x48 (size of EFI_FIRMWARE_VOLUME_HEADER) =3D 0x3ffb8 + # This can speed up the Variable Dispatch a bit. + 0xB8, 0xFF, 0x03, 0x00, + # FORMATTED: 0x5A #HEALTHY: 0xFE #Reserved: UINT16 #Reserved1: UINT32 + 0x5A, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +} + +0x00040000|0x00040000 +#NV_FTW_WORKING +DATA =3D { + # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature =3D gEdkiiWorkingBl= ockSignatureGuid =3D + # { 0x9e58292b, 0x7c68, 0x497d, { 0xa0, 0xce, 0x65, 0x0, 0xfd, 0x9f, 0= x1b, 0x95 }} + 0x2b, 0x29, 0x58, 0x9e, 0x68, 0x7c, 0x7d, 0x49, + 0xa0, 0xce, 0x65, 0x0, 0xfd, 0x9f, 0x1b, 0x95, + # Crc:UINT32 #WorkingBlockValid:1, WorkingBlockInvalid:1, Res= erved + 0x5b, 0xe7, 0xc6, 0x86, 0xFE, 0xFF, 0xFF, 0xFF, + # WriteQueueSize: UINT64 + 0xE0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 +} + +0x00080000|0x00040000 +#NV_FTW_SPARE --=20 2.27.0 -=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 (#114562): https://edk2.groups.io/g/devel/message/114562 Mute This Topic: https://groups.io/mt/103971688/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- From nobody Thu Dec 26 20:24:45 2024 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+114563+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+114563+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706250692; cv=none; d=zohomail.com; s=zohoarc; b=OJF5Ien/yEbgzY/krrIMO+HMNsnKwDc62TStB3PDg2sZAKEXlH/jrCv/Nv4cC9+HjYrJQaouvWH+m2wFB26DQ8K+2d/c/7tpUDTCfJeXEfYGX6qE01AOoorD9g/52xZZcm7Ou6K8pwRYnMJTOy5GFQjP9oWG/u7Uh1shjT3tltU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706250692; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=B5kidCIG4VR8lumkc7T5JDLwbOwexJOkLe7qAL6xmCs=; b=B9jygMms8fuehYq+VQzBTi9Re12l2l9ukqx/UqLJR37/IseL6walDs1ZwB5uw6Geuc71YrI5dWQyNX9uwsgBromXL0B0nEWrHKYr84FHrkK6TVU11Y0twoe0VDwJxcn+ZbURmUAob0wcQVl5zLekDGEig/C5inuoA2MF4m4Op0I= 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+114563+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706250692929756.3003139893978; Thu, 25 Jan 2024 22:31:32 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Rlf8xQLiSiwRV/U1hG+x4ef6uXQiNE0WcCNGtetZ53g=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250692; v=1; b=UcRbIF56QldIf1AmDY5N7DYt0QP0aVMEgsmNgH6u1IHOiCSYDV/npLil6gF2YyGCLc59gLWb nVW6Y+IxYvI5Vs+oKtj6x4n3Km8xhecy3WW2c2udPiu/OG2B0X2U5OgGAfWs8r4MotkwRRsVBv6 vfCeunuTWQYA62Y3u069sGJE= X-Received: by 127.0.0.2 with SMTP id fnoLYY1788612xvW43D6hjwz; Thu, 25 Jan 2024 22:31:32 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.10178.1706250691126847771 for ; Thu, 25 Jan 2024 22:31:31 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxifDAUbNlIB8GAA--.21859S3; Fri, 26 Jan 2024 14:31:28 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx8OS9UbNl2nMbAA--.53207S2; Fri, 26 Jan 2024 14:31:25 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian Subject: [edk2-devel] [PATCH v8 37/37] OvmfPkg/LoongArchVirt: Add self introduction file Date: Fri, 26 Jan 2024 14:31:21 +0800 Message-Id: <20240126063121.3103167-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx8OS9UbNl2nMbAA--.53207S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+AOvAALsU X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk 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,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: FcEJHmGSocOPFXED9f8nEftvx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706250694530100003 Content-Type: text/plain; charset="utf-8" Add self introduction file for LoongArch virtual machine. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4584 Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Reviewed-by: Bibo Mao --- OvmfPkg/LoongArchVirt/Readme.md | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/Readme.md diff --git a/OvmfPkg/LoongArchVirt/Readme.md b/OvmfPkg/LoongArchVirt/Readme= .md new file mode 100644 index 0000000000..57fc74c296 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/Readme.md @@ -0,0 +1,67 @@ +# LoongArch QEMU virt platform + +## Overview + + LoongArch QEMU virt is a generic platform that dose not require any actu= al hardware. + The minimum required QEMU version is [8.1](https://gitlab.com/qemu-proje= ct/qemu/-/tags), the minimum required GCC version is [GCC13](https://gcc.gn= u.org/gcc-13/), the minimum required Binutils version is [2.40](https://ftp= .gnu.org/gnu/binutils/). + +## Prepare (X86 Linux Environment) + +### Fedora39 +Install LoongArch64 cross compiler, LoongArch system QEMU. + + yum install gcc-loongarch64-linux-gnu + yum install qemu-system-loongarch64 + +### Others X86 OS ENV +#### Configure cross-tools + +**Download:** + + wget https://github.com/loongson/build-tools/releases/download/2023.08= .08/x86_64-cross-tools-loongarch64-binutils_2.41-gcc_13.2.0.tar.xz + +**Configure the cross-tools environment:** + + mkdir /opt/loongarch64_cross-toolchain/ + tar -vxf x86_64-cross-tools-loongarch64-binutils_2.41-gcc_13.2.0.tar.x= z -C /opt/loongarch64_cross-toolchain/ + export PATH=3D/opt/loongarch64_cross-toolchain/cross-tools/bin:$PATH + +Note: Please obtain [the latest cross-compilation](https://github.com/loon= gson/build-tools) toolchains. + +#### Build QEMU + + git clone https://gitlab.com/qemu-project/qemu.git + +Note: Please refer to QEMU compilation rules, located in qemu/doc/system/l= oongarch/virt.rst. + + +## Build LoongArch QEMU virtual machine firmware +#### Get edk2 resouces + + git clone --recurse-submodule https://github.com/tianocore/edk2.git + +#### Building LoongArch QEMU virt FW with GCC + + export WORKSPACE=3D`pwd` + export GCC5_LOONGARCH64_PREFIX=3Dloongarch64-unknown-linux-gnu- + export PACKAGES_PATH=3D$WORKSPACE/edk2 + export EDK_TOOLS_PATH=3D$WORKSPACE/edk2/BaseTools + source edk2/edksetup.sh --reconfig + make -C edk2/BaseTools + source edk2/edksetup.sh BaseTools + build -b RELEASE -t GCC5 -a LOONGARCH64 -p OvmfPkg/LoongArchVirt/Loong= ArchVirtQemu.dsc + +## Test LoongArch QEMU virtual machine firmware + qemu-system-loongarch64 \ + -m 4G \ + -M virt \ + -smp 2 \ + -cpu la464 \ + -bios Build/LoongArchVirtQemu/RELEASE_GCC5/FV/QEMU_EFI.fd \ + -serial stdio + +## Test LoongArch QEMU virtual machine OS + +* Download ArchLinux QCOW [images](https://mirrors.pku.edu.cn/loongarch/ar= chlinux/images) for LoongArch. + +* [Running LoongArch ArchLinux on virtual machine](https://mirrors.pku.edu= .cn/loongarch/archlinux/images/README.html). --=20 2.27.0 -=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 (#114563): https://edk2.groups.io/g/devel/message/114563 Mute This Topic: https://groups.io/mt/103971689/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-