From nobody Sat May 18 17:16:06 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+95112+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+95112+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655123; cv=none; d=zohomail.com; s=zohoarc; b=IKRk0wm9KOKWTlyE8Au6A0WCfkj1otwDZwtO1ZL58qQy44syOS5pkaMZP1P7E8591XSvZKR/q67XC+J4+a7kz0vf9mnhQ1KG/LZr1Biv9on/MYdvusDudJrY2k1Y7JwMgwxWFX+67rklcY/vKJ/jJlXEmsaQOzwpBdCpQGpczgE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655123; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=QA7jfQ8YySt4mfk1yv6YR18SpBsP9m9GpAZGX/cv10g=; b=dk+5iBkoloN7inHjJQYuzq1UB8ugsoELRYiScSTN1Qcg4CTThjfIJLb2ZZCNy36RStVcQy6aw7CAlJPrNu/4RphrFPn3RCr9KqPUInXM/Sst+F40QVGrlSY/tDmIJnGEsPkBZ2AjsTf0heiTQ1UVUi4krsT+FAZEzQWodmUfDpE= 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+95112+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655123725953.105857727954; Thu, 13 Oct 2022 02:58:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id xuR4YY1788612x9BVmsFQA4S; Thu, 13 Oct 2022 02:58:43 -0700 X-Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mx.groups.io with SMTP id smtpd.web11.5663.1665655122634116013 for ; Thu, 13 Oct 2022 02:58:42 -0700 X-Received: by mail-pl1-f178.google.com with SMTP id k9so925903pll.11 for ; Thu, 13 Oct 2022 02:58:42 -0700 (PDT) X-Gm-Message-State: rTh0II9oS2Kr6e0fpPrC0alax1787277AA= X-Google-Smtp-Source: AMsMyM5BwFKD6vFLl2FkqisrhFV+SGPOHO+MQRSuItFpccYqse/AJQt5vi6LfwLpPgUsVb8mF7C4MA== X-Received: by 2002:a17:90b:4a11:b0:20d:382d:3994 with SMTP id kk17-20020a17090b4a1100b0020d382d3994mr10130495pjb.173.1665655121672; Thu, 13 Oct 2022 02:58:41 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:58:41 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Daniel Schaefer , Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 01/34] MdePkg/Register: Add register definition header files for RISC-V Date: Thu, 13 Oct 2022 15:27:56 +0530 Message-Id: <20221013095829.1454581-2-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655123; bh=H83ijuR4Fssp5dCHtxPxv/fYeWuZZwJaRAHtA4SUdNo=; h=Cc:Date:From:Reply-To:Subject:To; b=g1BBgTwkGhWXfoq5ee8iG/UCYd9Gvc2PtGoSNST4yMNtpmq52zHelB2HYmNmBPQbFuo oL7ajvpGpPgJuMee0XGttR/PT95fTHCRehoz5xpQzHFcRv3xmQLOmkaleLj6C+lQV3mSq idiWqVN4B/3hOoQDX6M/XTVTDkfbwz/kgIo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655125670100005 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Add register definitions and access routines for RISC-V. These headers are leveraged from opensbi repo. Cc: Daniel Schaefer Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Sunil V L --- .../Include/Register/RiscV64/RiscVEncoding.h | 125 ++++++++++++++++++ MdePkg/Include/Register/RiscV64/RiscVImpl.h | 25 ++++ 2 files changed, 150 insertions(+) create mode 100644 MdePkg/Include/Register/RiscV64/RiscVEncoding.h create mode 100644 MdePkg/Include/Register/RiscV64/RiscVImpl.h diff --git a/MdePkg/Include/Register/RiscV64/RiscVEncoding.h b/MdePkg/Inclu= de/Register/RiscV64/RiscVEncoding.h new file mode 100644 index 000000000000..434436b37fcf --- /dev/null +++ b/MdePkg/Include/Register/RiscV64/RiscVEncoding.h @@ -0,0 +1,125 @@ +/** @file + RISC-V CSR encodings + + Copyright (c) 2019, Western Digital Corporation or its affiliates. All r= ights reserved.
+ Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef RISCV_ENCODING_H_ +#define RISCV_ENCODING_H_ + +/* clang-format off */ +#define MSTATUS_SIE 0x00000002UL +#define MSTATUS_MIE 0x00000008UL +#define MSTATUS_SPIE_SHIFT 5 +#define MSTATUS_SPIE (1UL << MSTATUS_SPIE_SHIFT) +#define MSTATUS_UBE 0x00000040UL +#define MSTATUS_MPIE 0x00000080UL +#define MSTATUS_SPP_SHIFT 8 +#define MSTATUS_SPP (1UL << MSTATUS_SPP_SHIFT) +#define MSTATUS_MPP_SHIFT 11 +#define MSTATUS_MPP (3UL << MSTATUS_MPP_SHIFT) + +#define SSTATUS_SIE MSTATUS_SIE +#define SSTATUS_SPIE_SHIFT MSTATUS_SPIE_SHIFT +#define SSTATUS_SPIE MSTATUS_SPIE +#define SSTATUS_SPP_SHIFT MSTATUS_SPP_SHIFT +#define SSTATUS_SPP MSTATUS_SPP + +#define IRQ_S_SOFT 1 +#define IRQ_VS_SOFT 2 +#define IRQ_M_SOFT 3 +#define IRQ_S_TIMER 5 +#define IRQ_VS_TIMER 6 +#define IRQ_M_TIMER 7 +#define IRQ_S_EXT 9 +#define IRQ_VS_EXT 10 +#define IRQ_M_EXT 11 +#define IRQ_S_GEXT 12 +#define IRQ_PMU_OVF 13 + +#define MIP_SSIP (1UL << IRQ_S_SOFT) +#define MIP_VSSIP (1UL << IRQ_VS_SOFT) +#define MIP_MSIP (1UL << IRQ_M_SOFT) +#define MIP_STIP (1UL << IRQ_S_TIMER) +#define MIP_VSTIP (1UL << IRQ_VS_TIMER) +#define MIP_MTIP (1UL << IRQ_M_TIMER) +#define MIP_SEIP (1UL << IRQ_S_EXT) +#define MIP_VSEIP (1UL << IRQ_VS_EXT) +#define MIP_MEIP (1UL << IRQ_M_EXT) +#define MIP_SGEIP (1UL << IRQ_S_GEXT) +#define MIP_LCOFIP (1UL << IRQ_PMU_OVF) + +#define SIP_SSIP MIP_SSIP +#define SIP_STIP MIP_STIP + +#define PRV_U 0UL +#define PRV_S 1UL +#define PRV_M 3UL + +#define SATP64_MODE 0xF000000000000000ULL +#define SATP64_ASID 0x0FFFF00000000000ULL +#define SATP64_PPN 0x00000FFFFFFFFFFFULL + +#define SATP_MODE_OFF 0UL +#define SATP_MODE_SV32 1UL +#define SATP_MODE_SV39 8UL +#define SATP_MODE_SV48 9UL +#define SATP_MODE_SV57 10UL +#define SATP_MODE_SV64 11UL + +#define SATP_MODE SATP64_MODE + +/* =3D=3D=3D=3D=3D User-level CSRs =3D=3D=3D=3D=3D */ + +/* User Counters/Timers */ +#define CSR_CYCLE 0xc00 +#define CSR_TIME 0xc01 + +/* =3D=3D=3D=3D=3D Supervisor-level CSRs =3D=3D=3D=3D=3D */ + +/* Supervisor Trap Setup */ +#define CSR_SSTATUS 0x100 +#define CSR_SEDELEG 0x102 +#define CSR_SIDELEG 0x103 +#define CSR_SIE 0x104 +#define CSR_STVEC 0x105 + +/* Supervisor Configuration */ +#define CSR_SENVCFG 0x10a + +/* Supervisor Trap Handling */ +#define CSR_SSCRATCH 0x140 +#define CSR_SEPC 0x141 +#define CSR_SCAUSE 0x142 +#define CSR_STVAL 0x143 +#define CSR_SIP 0x144 + +/* Supervisor Protection and Translation */ +#define CSR_SATP 0x180 + +/* =3D=3D=3D=3D=3D Trap/Exception Causes =3D=3D=3D=3D=3D */ + +#define CAUSE_MISALIGNED_FETCH 0x0 +#define CAUSE_FETCH_ACCESS 0x1 +#define CAUSE_ILLEGAL_INSTRUCTION 0x2 +#define CAUSE_BREAKPOINT 0x3 +#define CAUSE_MISALIGNED_LOAD 0x4 +#define CAUSE_LOAD_ACCESS 0x5 +#define CAUSE_MISALIGNED_STORE 0x6 +#define CAUSE_STORE_ACCESS 0x7 +#define CAUSE_USER_ECALL 0x8 +#define CAUSE_SUPERVISOR_ECALL 0x9 +#define CAUSE_VIRTUAL_SUPERVISOR_ECALL 0xa +#define CAUSE_MACHINE_ECALL 0xb +#define CAUSE_FETCH_PAGE_FAULT 0xc +#define CAUSE_LOAD_PAGE_FAULT 0xd +#define CAUSE_STORE_PAGE_FAULT 0xf +#define CAUSE_FETCH_GUEST_PAGE_FAULT 0x14 +#define CAUSE_LOAD_GUEST_PAGE_FAULT 0x15 +#define CAUSE_VIRTUAL_INST_FAULT 0x16 +#define CAUSE_STORE_GUEST_PAGE_FAULT 0x17 + +#endif diff --git a/MdePkg/Include/Register/RiscV64/RiscVImpl.h b/MdePkg/Include/R= egister/RiscV64/RiscVImpl.h new file mode 100644 index 000000000000..ee5c2ba60377 --- /dev/null +++ b/MdePkg/Include/Register/RiscV64/RiscVImpl.h @@ -0,0 +1,25 @@ +/** @file + RISC-V package definitions. + + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef RISCV_IMPL_H_ +#define RISCV_IMPL_H_ + +#include + +#define _ASM_FUNC(Name, Section) \ + .global Name ; \ + .section #Section, "ax" ; \ + .type Name, %function ; \ + .p2align 2 ; \ + Name: + +#define ASM_FUNC(Name) _ASM_FUNC(ASM_PFX(Name), .text. ## Name) +#define RISCV_TIMER_COMPARE_BITS 32 + +#endif --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95112): https://edk2.groups.io/g/devel/message/95112 Mute This Topic: https://groups.io/mt/94300380/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 Sat May 18 17:16:06 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+95113+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+95113+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655125; cv=none; d=zohomail.com; s=zohoarc; b=nSSQVJ1fbzasZyTGp4J3d8Xk8jB4Q2WleYLwg7LpRm37NHikPS/sVJqnE4izEhPQGAED9O03RhtfRlNk+745dmWRW91DyV/SzmnvK36mStY6TR3OsElsyx6RJe4cm9mYlrrkKZog1mUykhgJwxmrdrIqAzi51JvnqIqIXTAJ1Tg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655125; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=j2QX6XyaqZTWPkmnMaMR6HrCUbXsJlhxEnDU9OLGihs=; b=HxcR+PDisc8QB9ZA1Siam8xVQhZ2eUigSr/ZFIaaAhZvFGSZIHUHicudYJavjatstT3iBfdUBAYrvGZepQH0WEkMqeSS37H+9hYFgyWR/MJKkCb40BJRLdHi7gCJFtCtXfZHrMG79MkhOPYm6v/H6AkRGLN8RNChBqJmNfUN1Dw= 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+95113+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655125568559.7692632208227; Thu, 13 Oct 2022 02:58:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id k4VOYY1788612xrcdaYZXnfL; Thu, 13 Oct 2022 02:58:45 -0700 X-Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by mx.groups.io with SMTP id smtpd.web09.5753.1665655124596681512 for ; Thu, 13 Oct 2022 02:58:44 -0700 X-Received: by mail-pg1-f182.google.com with SMTP id 128so1151429pga.1 for ; Thu, 13 Oct 2022 02:58:44 -0700 (PDT) X-Gm-Message-State: URKNuPOSMcvpjLuaQ4UtBbPyx1787277AA= X-Google-Smtp-Source: AMsMyM6TceT26C/CwTdEt6VVlZVRYdZ4B0q03Ah6Xz5Zvvhs4yjjMR0XBkZ1PD/BqUb80Al5cX7yMg== X-Received: by 2002:a63:5761:0:b0:43c:5940:9176 with SMTP id h33-20020a635761000000b0043c59409176mr28890173pgm.65.1665655123884; Thu, 13 Oct 2022 02:58:43 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:58:43 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 02/34] MdePkg: Add RISCV_EFI_BOOT_PROTOCOL related definitions Date: Thu, 13 Oct 2022 15:27:57 +0530 Message-Id: <20221013095829.1454581-3-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655125; bh=u2+vC9f2816AR8G6JfRKgIC9IJTRcTqZF/MUKHKXQeo=; h=Cc:Date:From:Reply-To:Subject:To; b=RIIW1eoePb2v580sDL2U/x23YrIwpUW5evxWMKQElfSYhR9oev1bW2AQdgK/A8u4sUb 6rfSg7Rcw+3VyL/LMbNwgBsRRAWBvZclse0x49BA+M+4APUS1trLIMkxYersWt9OzKF5J MY0sktX0ZTjJLtuu25WGcLNkwhttsLAmuw0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655127679100010 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 RISC-V UEFI based platforms need to support RISCV_EFI_BOOT_PROTOCOL. Add this protocol GUID definition and the header file required. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Sunil V L --- MdePkg/MdePkg.dec | 6 ++++ MdePkg/Include/Protocol/RiscVBootProtocol.h | 32 +++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 MdePkg/Include/Protocol/RiscVBootProtocol.h diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index f1ebf9e251c1..8f1bcfdc3e97 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -1915,6 +1915,12 @@ [Protocols] ## Include/Protocol/ShellDynamicCommand.h gEfiShellDynamicCommandProtocolGuid =3D { 0x3c7200e9, 0x005f, 0x4ea4, {= 0x87, 0xde, 0xa3, 0xdf, 0xac, 0x8a, 0x27, 0xc3 }} =20 + # + # Protocols defined for RISC-V systems + # + ## Include/Protocol/RiscVBootProtocol.h + gRiscVEfiBootProtocolGuid =3D { 0xccd15fec, 0x6f73, 0x4eec, { 0x83, 0x9= 5, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf }} + # # [Error.gEfiMdePkgTokenSpaceGuid] # 0x80000001 | Invalid value provided. diff --git a/MdePkg/Include/Protocol/RiscVBootProtocol.h b/MdePkg/Include/P= rotocol/RiscVBootProtocol.h new file mode 100644 index 000000000000..cb94f61cd46c --- /dev/null +++ b/MdePkg/Include/Protocol/RiscVBootProtocol.h @@ -0,0 +1,32 @@ +/** @file + RISC-V Boot Protocol mandatory for RISC-V UEFI platforms. + + Specification available at + https://github.com/riscv-non-isa/riscv-uefi + + Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef RISCV_BOOT_PROTOCOL_H_ +#define RISCV_BOOT_PROTOCOL_H_ + +typedef struct _RISCV_EFI_BOOT_PROTOCOL RISCV_EFI_BOOT_PROTOCOL; + +#define RISCV_EFI_BOOT_PROTOCOL_REVISION 0x00010000 +#define RISCV_EFI_BOOT_PROTOCOL_LATEST_VERSION \ + RISCV_EFI_BOOT_PROTOCOL_REVISION + +typedef EFI_STATUS +(EFIAPI *EFI_GET_BOOT_HARTID)( + IN RISCV_EFI_BOOT_PROTOCOL *This, + OUT UINTN *BootHartId + ); + +typedef struct _RISCV_EFI_BOOT_PROTOCOL { + UINT64 Revision; + EFI_GET_BOOT_HARTID GetBootHartId; +} RISCV_EFI_BOOT_PROTOCOL; + +#endif --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95113): https://edk2.groups.io/g/devel/message/95113 Mute This Topic: https://groups.io/mt/94300382/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 Sat May 18 17:16:06 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+95114+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+95114+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655128; cv=none; d=zohomail.com; s=zohoarc; b=U0mEo89zcVcqP6DHXVmmhJ/DlO4isQ4sSQeKhZ01NcLKArIw+j+J8OvHVdYrpxT2UfInhEoTUDeTalit3QbixItvAkw+l6AC0BQ+cOHEAAMuOfEqrlkyeEJhrkpMpC6kpZEVeMEMA9CWmcEFdROQjXqwjj60UC7wx7wFKiB5/OY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655128; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=PTt4Z5zhDAsBuIJpoI+xSW6UC7wuqIWRelVuE0YeMTc=; b=JiQVc7QfSlBw/qAr5mcfquProVZBa/9H+gRfyIBtk18t/NOAbTyZvT01FWNE7aGY+wy7bMVXZ1zSh86WzPJS3fluhSuqYh2U6FEbt4+mXrAGOdM2vxmTkBx9QHKaPq36cuzR0gDc6hIMQmBvRUq0xkqevdNyAvmLZTxlHkPP+jQ= 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+95114+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655128939656.5871430469084; Thu, 13 Oct 2022 02:58:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9Sd2YY1788612xMBnvov20Mi; Thu, 13 Oct 2022 02:58:47 -0700 X-Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mx.groups.io with SMTP id smtpd.web09.5754.1665655127045175099 for ; Thu, 13 Oct 2022 02:58:47 -0700 X-Received: by mail-pf1-f177.google.com with SMTP id y8so1466502pfp.13 for ; Thu, 13 Oct 2022 02:58:47 -0700 (PDT) X-Gm-Message-State: CbMT9MSJXewXyP2ivzlRLCgex1787277AA= X-Google-Smtp-Source: AMsMyM5wf0hU1d/97d75SlzmRBVm0QhYSJuo5uJEYqz1+qeWCj7VMnWk/gWiVtY28RdKvX7SWCeWQA== X-Received: by 2002:a63:4c5f:0:b0:439:49b4:809f with SMTP id m31-20020a634c5f000000b0043949b4809fmr28434932pgl.382.1665655126204; Thu, 13 Oct 2022 02:58:46 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:58:45 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 03/34] MdePkg/BaseLib: RISC-V: Add few more helper functions Date: Thu, 13 Oct 2022 15:27:58 +0530 Message-Id: <20221013095829.1454581-4-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655127; bh=JDuOYjWlKNUOaH0fnFbo3t+AF9k4EbiaO/N7sGzCkiQ=; h=Cc:Date:From:Reply-To:Subject:To; b=aqn9VCwFftLh/bBIJ4Zq0vKCZjnAez6YLxk/s/aSp0kbxwHGWTwthT3/qCIXKBishxC obNhHubWY3BPs/8ITcm55/V3zb4Xaodui6gndKmQLXv64TWHqhHMLY8DdZM1f3b1zfL2w 4oqGOBLOHH24DUOwMgydyQvL8Y2aib9rJfg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655129715100014 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Few of the basic helper functions required for any RISC-V CPU were added in edk2-platforms. To support qemu virt, they need to be added in BaseLib. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Daniel Schaefer Signed-off-by: Sunil V L --- MdePkg/Library/BaseLib/BaseLib.inf | 2 + MdePkg/Include/Library/BaseLib.h | 50 +++++++++++++++++ MdePkg/Library/BaseLib/RiscV64/CpuScratch.S | 31 +++++++++++ MdePkg/Library/BaseLib/RiscV64/ReadTimer.S | 24 +++++++++ .../Library/BaseLib/RiscV64/RiscVInterrupt.S | 53 +++++++++++++++++-- 5 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 MdePkg/Library/BaseLib/RiscV64/CpuScratch.S create mode 100644 MdePkg/Library/BaseLib/RiscV64/ReadTimer.S diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 6be5be9428f2..86d7bb080971 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -401,6 +401,8 @@ [Sources.RISCV64] RiscV64/RiscVCpuPause.S | GCC RiscV64/RiscVInterrupt.S | GCC RiscV64/FlushCache.S | GCC + RiscV64/CpuScratch.S | GCC + RiscV64/ReadTimer.S | GCC =20 [Packages] MdePkg/MdePkg.dec diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index a6f9a194ef1c..9724b84eef89 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -150,6 +150,56 @@ typedef struct { =20 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8 =20 +VOID + RiscVSetSupervisorScratch ( + UINT64 + ); + +UINT64 +RiscVGetSupervisorScratch ( + VOID + ); + +VOID + RiscVSetSupervisorStvec ( + UINT64 + ); + +UINT64 +RiscVGetSupervisorStvec ( + VOID + ); + +UINT64 +RiscVGetSupervisorTrapCause ( + VOID + ); + +VOID + RiscVSetSupervisorAddressTranslationRegister ( + UINT64 + ); + +UINT64 +RiscVReadTimer ( + VOID + ); + +VOID +RiscVEnableTimerInterrupt ( + VOID + ); + +VOID +RiscVDisableTimerInterrupt ( + VOID + ); + +VOID +RiscVClearPendingTimerInterrupt ( + VOID + ); + #endif // defined (MDE_CPU_RISCV64) =20 // diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuScratch.S b/MdePkg/Library/B= aseLib/RiscV64/CpuScratch.S new file mode 100644 index 000000000000..dd7adc21eb07 --- /dev/null +++ b/MdePkg/Library/BaseLib/RiscV64/CpuScratch.S @@ -0,0 +1,31 @@ +//------------------------------------------------------------------------= ------ +// +// CPU scratch register related functions for RISC-V +// +// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +//------------------------------------------------------------------------= ------ + +#include + +.data +.align 3 +.section .text + +// +// Set Supervisor mode scratch. +// @param a0 : Value set to Supervisor mode scratch +// +ASM_FUNC (RiscVSetSupervisorScratch) + csrrw a1, CSR_SSCRATCH, a0 + ret + +// +// Get Supervisor mode scratch. +// @retval a0 : Value in Supervisor mode scratch +// +ASM_FUNC (RiscVGetSupervisorScratch) + csrr a0, CSR_SSCRATCH + ret diff --git a/MdePkg/Library/BaseLib/RiscV64/ReadTimer.S b/MdePkg/Library/Ba= seLib/RiscV64/ReadTimer.S new file mode 100644 index 000000000000..bdddb67618ab --- /dev/null +++ b/MdePkg/Library/BaseLib/RiscV64/ReadTimer.S @@ -0,0 +1,24 @@ +//------------------------------------------------------------------------= ------ +// +// Read CPU timer +// +// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+// Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +//------------------------------------------------------------------------= ------ + +#include + +.data +.align 3 +.section .text + +// +// Read TIME CSR. +// @retval a0 : 64-bit timer. +// +ASM_FUNC (RiscVReadTimer) + csrr a0, CSR_TIME + ret diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S b/MdePkg/Libra= ry/BaseLib/RiscV64/RiscVInterrupt.S index 87b3468fc7fd..6a1b90a7e45c 100644 --- a/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S @@ -8,13 +8,13 @@ // //------------------------------------------------------------------------= ------ =20 +#include + ASM_GLOBAL ASM_PFX(RiscVDisableSupervisorModeInterrupts) ASM_GLOBAL ASM_PFX(RiscVEnableSupervisorModeInterrupt) ASM_GLOBAL ASM_PFX(RiscVGetSupervisorModeInterrupts) =20 -#define SSTATUS_SIE 0x00000002 -#define CSR_SSTATUS 0x100 - #define SSTATUS_SPP_BIT_POSITION 8 +#define SSTATUS_SPP_BIT_POSITION 8 =20 // // This routine disables supervisor mode interrupt @@ -53,11 +53,56 @@ InTrap: ret =20 // +// Set Supervisor mode trap vector. +// @param a0 : Value set to Supervisor mode trap vector +// +ASM_FUNC (RiscVSetSupervisorStvec) + csrrw a1, CSR_STVEC, a0 + ret + +// +// Get Supervisor mode trap vector. +// @retval a0 : Value in Supervisor mode trap vector +// +ASM_FUNC (RiscVGetSupervisorStvec) + csrr a0, CSR_STVEC + ret + +// +// Get Supervisor trap cause CSR. +// +ASM_FUNC (RiscVGetSupervisorTrapCause) + csrrs a0, CSR_SCAUSE, 0 + ret +// // This routine returns supervisor mode interrupt // status. // -ASM_PFX(RiscVGetSupervisorModeInterrupts): +ASM_FUNC (RiscVGetSupervisorModeInterrupts) csrr a0, CSR_SSTATUS andi a0, a0, SSTATUS_SIE ret =20 +// +// This routine disables supervisor mode timer interrupt +// +ASM_FUNC (RiscVDisableTimerInterrupt) + li a0, SIP_STIP + csrc CSR_SIE, a0 + ret + +// +// This routine enables supervisor mode timer interrupt +// +ASM_FUNC (RiscVEnableTimerInterrupt) + li a0, SIP_STIP + csrs CSR_SIE, a0 + ret + +// +// This routine clears pending supervisor mode timer interrupt +// +ASM_FUNC (RiscVClearPendingTimerInterrupt) + li a0, SIP_STIP + csrc CSR_SIP, a0 + ret --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95114): https://edk2.groups.io/g/devel/message/95114 Mute This Topic: https://groups.io/mt/94300383/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 Sat May 18 17:16:06 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+95118+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+95118+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655141; cv=none; d=zohomail.com; s=zohoarc; b=OpDJH9ZbZdckWigdxjSP6GhM36tm4msSqsEi3yFweYr4e2gDWBjrS/nAKuQt7/xdxNlMvTz6+z1DPYhxQnl7Yr0lFdX0SHn/0cxeoW1hIvlb6EBCY0IPDPEs9uX7YF/VPZGaGnw1HuDFb2uWTjVhWWtmW+qqFWnGJy/hEgjGqno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655141; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=RywC/DoOjgiJywI3aATigwQ1iJ9XTIyYQLGE7gsy+QE=; b=d1npiHS9JgKTOfgywm0JoiKCg0xfcMZ99AXyPeVnc2qHa37JdwMPxQGuZJUy8Qt+/J6QwLL3usYwPYuqh8TBQy+U1MFMARnFMnl2MG9684EIy7NqHAoKBtywou+LvrdFLiVskPys1aV+ADIoOLyHzkCuoLue1lj8mCeQ6IgSHp4= 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+95118+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655141932952.0974077396102; Thu, 13 Oct 2022 02:59:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8o2rYY1788612xZVk7wcTijI; Thu, 13 Oct 2022 02:59:01 -0700 X-Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mx.groups.io with SMTP id smtpd.web09.5756.1665655140370362743 for ; Thu, 13 Oct 2022 02:59:00 -0700 X-Received: by mail-pl1-f174.google.com with SMTP id i6so1320418pli.12 for ; Thu, 13 Oct 2022 02:59:00 -0700 (PDT) X-Gm-Message-State: hWVsJjmf9IxxDdJuhKeRDBSCx1787277AA= X-Google-Smtp-Source: AMsMyM4gMzcs5Tvn6Rg2CzOUXdbdtVM1aRIUZm1ebx7MzzkqxmGW/7EtGmNxv8IavTVzNbKbuh4Iqg== X-Received: by 2002:a17:902:7296:b0:180:1330:b3c0 with SMTP id d22-20020a170902729600b001801330b3c0mr30742319pll.170.1665655128779; Thu, 13 Oct 2022 02:58:48 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:58:48 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 04/34] MdePkg: Add BaseRiscVSbiLib Library for RISC-V Date: Thu, 13 Oct 2022 15:27:59 +0530 Message-Id: <20221013095829.1454581-5-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655141; bh=9VHMyv1WSQEqZz+jk1Ad6JrSgW8zz6rSQzN5K9rw9UA=; h=Cc:Date:From:Reply-To:Subject:To; b=QQszPzRRvFegNv2SLcbCLAest4rPZxso9thh9FZhvDoVU6SaOL/rfnUJJ2m2bXWQ/03 2BqkfhkzLr9/3X/uOReSWBSb3zNy3KHQrPAbIB3RYHcKg+a/jEjgAmxvLPMiXb/wMP0jS YB/eVe1g7xYm1mAEzhUqaIhZqvq1ouaTc9s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655143815100003 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This library is required to make SBI ecalls from the S-mode EDK2. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Sunil V L Acked-by: Abner Chang --- MdePkg/MdePkg.dec | 4 + MdePkg/MdePkg.dsc | 3 + .../BaseRiscVSbiLib/BaseRiscVSbiLib.inf | 25 ++ MdePkg/Include/Library/BaseRiscVSbiLib.h | 127 ++++++++++ .../Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c | 227 ++++++++++++++++++ 5 files changed, 386 insertions(+) create mode 100644 MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf create mode 100644 MdePkg/Include/Library/BaseRiscVSbiLib.h create mode 100644 MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 8f1bcfdc3e97..1762068ffad7 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -307,6 +307,10 @@ [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Provides function to support TDX processing. TdxLib|Include/Library/TdxLib.h =20 +[LibraryClasses.RISCV64] + ## @libraryclass Provides function to make ecalls to SBI + BaseRiscVSbiLib|Include/Library/BaseRiscVSbiLib.h + [Guids] # # GUID defined in UEFI2.1/UEFI2.0/EFI1.1 diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index cc1ac196a931..fd08122f441d 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -188,4 +188,7 @@ [Components.ARM, Components.AARCH64] MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicArmVirt.inf MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf =20 +[Components.RISCV64] + MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf + [BuildOptions] diff --git a/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf b/MdePkg/Li= brary/BaseRiscVSbiLib/BaseRiscVSbiLib.inf new file mode 100644 index 000000000000..d03132bf01c1 --- /dev/null +++ b/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf @@ -0,0 +1,25 @@ +## @file +# RISC-V Library to call SBI ecalls +# +# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001b + BASE_NAME =3D BaseRiscVSbiLib + FILE_GUID =3D D742CF3D-E600-4009-8FB5-318073008508 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RiscVSbiLib + +[Sources] + BaseRiscVSbiLib.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib diff --git a/MdePkg/Include/Library/BaseRiscVSbiLib.h b/MdePkg/Include/Libr= ary/BaseRiscVSbiLib.h new file mode 100644 index 000000000000..e9886187526a --- /dev/null +++ b/MdePkg/Include/Library/BaseRiscVSbiLib.h @@ -0,0 +1,127 @@ +/** @file + Library to call the RISC-V SBI ecalls + + Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights rese= rved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Hart - Hardware Thread, similar to a CPU core + + Currently, EDK2 needs to call SBI only to set the time and to do system = reset. + +**/ + +#ifndef RISCV_SBI_LIB_H_ +#define RISCV_SBI_LIB_H_ + +#include + +/* SBI Extension IDs */ +#define SBI_EXT_TIME 0x54494D45 +#define SBI_EXT_SRST 0x53525354 + +/* SBI function IDs for TIME extension*/ +#define SBI_EXT_TIME_SET_TIMER 0x0 + +/* SBI function IDs for SRST extension */ +#define SBI_EXT_SRST_RESET 0x0 + +#define SBI_SRST_RESET_TYPE_SHUTDOWN 0x0 +#define SBI_SRST_RESET_TYPE_COLD_REBOOT 0x1 +#define SBI_SRST_RESET_TYPE_WARM_REBOOT 0x2 +#define SBI_SRST_RESET_TYPE_LAST SBI_SRST_RESET_TYPE_WARM_REBOOT + +#define SBI_SRST_RESET_REASON_NONE 0x0 +#define SBI_SRST_RESET_REASON_SYSFAIL 0x1 + +/* SBI return error codes */ +#define SBI_SUCCESS 0 +#define SBI_ERR_FAILED -1 +#define SBI_ERR_NOT_SUPPORTED -2 +#define SBI_ERR_INVALID_PARAM -3 +#define SBI_ERR_DENIED -4 +#define SBI_ERR_INVALID_ADDRESS -5 +#define SBI_ERR_ALREADY_AVAILABLE -6 +#define SBI_ERR_ALREADY_STARTED -7 +#define SBI_ERR_ALREADY_STOPPED -8 + +#define SBI_LAST_ERR SBI_ERR_ALREADY_STOPPED + +typedef struct { + UINT64 BootHartId; + VOID *PeiServiceTable; // PEI Service table + UINT64 FlattenedDeviceTree; // Pointer to Flattened Device tree +} EFI_RISCV_FIRMWARE_CONTEXT; + +// +// EDK2 OpenSBI firmware extension return status. +// +typedef struct { + UINTN Error; ///< SBI status code + UINTN Value; ///< Value returned +} SBI_RET; + +VOID +EFIAPI +SbiSetTimer ( + IN UINT64 Time + ); + +EFI_STATUS +EFIAPI +SbiSystemReset ( + IN UINTN ResetType, + IN UINTN ResetReason + ); + +/** + Get firmware context of the calling hart. + + @param[out] FirmwareContext The firmware context pointer. +**/ +VOID +EFIAPI +GetFirmwareContext ( + OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContext + ); + +/** + Set firmware context of the calling hart. + + @param[in] FirmwareContext The firmware context pointer. +**/ +VOID +EFIAPI +SetFirmwareContext ( + IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext + ); + +/** + Get pointer to OpenSBI Firmware Context + + Get the pointer of firmware context. + + @param FirmwareContextPtr Pointer to retrieve pointer to the + Firmware Context. +**/ +VOID +EFIAPI +GetFirmwareContextPointer ( + IN OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContextPtr + ); + +/** + Set pointer to OpenSBI Firmware Context + + Set the pointer of firmware context. + + @param FirmwareContextPtr Pointer to Firmware Context. +**/ +VOID +EFIAPI +SetFirmwareContextPointer ( + IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContextPtr + ); + +#endif diff --git a/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c b/MdePkg/Libr= ary/BaseRiscVSbiLib/BaseRiscVSbiLib.c new file mode 100644 index 000000000000..5db95a008069 --- /dev/null +++ b/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c @@ -0,0 +1,227 @@ +/** @file + Instance of the SBI ecall library. + + It allows calling an SBI function via an ecall from S-Mode. + + Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights rese= rved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +// +// Maximum arguments for SBI ecall +// It's possible to pass more but no SBI call uses more as of SBI 0.2. +// The additional arguments would have to be passed on the stack instead o= f as +// registers, like it's done now. +// +#define SBI_CALL_MAX_ARGS 6 + +/** + Call SBI call using ecall instruction. + + Asserts when NumArgs exceeds SBI_CALL_MAX_ARGS. + + @param[in] ExtId SBI extension ID. + @param[in] FuncId SBI function ID. + @param[in] NumArgs Number of arguments to pass to the ecall. + @param[in] ... Argument list for the ecall. + + @retval Returns SBI_RET structure with value and error code. + +**/ +STATIC +SBI_RET +EFIAPI +SbiCall ( + IN UINTN ExtId, + IN UINTN FuncId, + IN UINTN NumArgs, + ... + ) +{ + UINTN I; + SBI_RET Ret; + UINTN Args[SBI_CALL_MAX_ARGS]; + VA_LIST ArgList; + + VA_START (ArgList, NumArgs); + + ASSERT (NumArgs <=3D SBI_CALL_MAX_ARGS); + + for (I =3D 0; I < SBI_CALL_MAX_ARGS; I++) { + if (I < NumArgs) { + Args[I] =3D VA_ARG (ArgList, UINTN); + } else { + // Default to 0 for all arguments that are not given + Args[I] =3D 0; + } + } + + VA_END (ArgList); + + register UINTN a0 asm ("a0") =3D Args[0]; + register UINTN a1 asm ("a1") =3D Args[1]; + register UINTN a2 asm ("a2") =3D Args[2]; + register UINTN a3 asm ("a3") =3D Args[3]; + register UINTN a4 asm ("a4") =3D Args[4]; + register UINTN a5 asm ("a5") =3D Args[5]; + register UINTN a6 asm ("a6") =3D (UINTN)(FuncId); + register UINTN a7 asm ("a7") =3D (UINTN)(ExtId); + + asm volatile ("ecall" \ + : "+r" (a0), "+r" (a1) \ + : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) \ + : "memory"); \ + Ret.Error =3D a0; + Ret.Value =3D a1; + return Ret; +} + +/** + Translate SBI error code to EFI status. + + @param[in] SbiError SBI error code + @retval EFI_STATUS +**/ +STATIC +EFI_STATUS +EFIAPI +TranslateError ( + IN UINTN SbiError + ) +{ + switch (SbiError) { + case SBI_SUCCESS: + return EFI_SUCCESS; + case SBI_ERR_FAILED: + return EFI_DEVICE_ERROR; + break; + case SBI_ERR_NOT_SUPPORTED: + return EFI_UNSUPPORTED; + break; + case SBI_ERR_INVALID_PARAM: + return EFI_INVALID_PARAMETER; + break; + case SBI_ERR_DENIED: + return EFI_ACCESS_DENIED; + break; + case SBI_ERR_INVALID_ADDRESS: + return EFI_LOAD_ERROR; + break; + case SBI_ERR_ALREADY_AVAILABLE: + return EFI_ALREADY_STARTED; + break; + default: + // + // Reaches here only if SBI has defined a new error type + // + ASSERT (FALSE); + return EFI_UNSUPPORTED; + break; + } +} + +/** + Clear pending timer interrupt bit and set timer for next event after Tim= e. + + To clear the timer without scheduling a timer event, set Time to a + practically infinite value or mask the timer interrupt by clearing sie.S= TIE. + + @param[in] Time The time offset to the next scheduled t= imer interrupt. +**/ +VOID +EFIAPI +SbiSetTimer ( + IN UINT64 Time + ) +{ + SbiCall (SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, 1, Time); +} + +EFI_STATUS +EFIAPI +SbiSystemReset ( + IN UINTN ResetType, + IN UINTN ResetReason + ) +{ + SBI_RET Ret; + + Ret =3D SbiCall ( + SBI_EXT_SRST, + SBI_EXT_SRST_RESET, + 2, + ResetType, + ResetReason + ); + + return TranslateError (Ret.Error); +} + +/** + Get firmware context of the calling hart. + + @param[out] FirmwareContext The firmware context pointer. + @retval EFI_SUCCESS The operation succeeds. +**/ +VOID +EFIAPI +GetFirmwareContext ( + OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContext + ) +{ + *FirmwareContext =3D (EFI_RISCV_FIRMWARE_CONTEXT *)RiscVGetSupervisorScr= atch (); +} + +/** + Set firmware context of the calling hart. + + @param[in] FirmwareContext The firmware context pointer. +**/ +VOID +EFIAPI +SetFirmwareContext ( + IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext + ) +{ + RiscVSetSupervisorScratch ((UINT64)FirmwareContext); +} + +/** + Get pointer to OpenSBI Firmware Context + + Get the pointer of firmware context through OpenSBI FW Extension SBI. + + @param FirmwareContextPtr Pointer to retrieve pointer to the + Firmware Context. +**/ +VOID +EFIAPI +GetFirmwareContextPointer ( + IN OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContextPtr + ) +{ + GetFirmwareContext (FirmwareContextPtr); +} + +/** + Set the pointer to OpenSBI Firmware Context + + Set the pointer of firmware context through OpenSBI FW Extension SBI. + + @param FirmwareContextPtr Pointer to Firmware Context. +**/ +VOID +EFIAPI +SetFirmwareContextPointer ( + IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContextPtr + ) +{ + SetFirmwareContext (FirmwareContextPtr); +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95118): https://edk2.groups.io/g/devel/message/95118 Mute This Topic: https://groups.io/mt/94300390/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 Sat May 18 17:16:06 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+95115+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+95115+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655133; cv=none; d=zohomail.com; s=zohoarc; b=XHV3fJUffecNT53PkAeVPD63EW+sF13RWYLFViY09YL8Q0woPvTkU8d8gWA17oPNRUYq+qv4l6sx0EIlHRf2y6/dUgrD26rcHz2325z4UWTi/HAGpWNKcslf4K51CdVEn+RbPu6Uo7DLK1RMwp2Mshyjdd5J9LdkpmE6cloT86g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655133; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=7wdAxToP4sfTpfG5tnE4kJS4aorKyTfypL17mF6S8Xo=; b=bG5K9vPB71Ex3iHbcMeFy7To8Ri3gB15NOKRe8jVrkLjAAhJdL1usPQUQ/47zOrLhIcamsrjfgZU8nTIWmQGjTIwpDe9ay720j9DIY+9V9vWpMTlPETFN8zM0ZZp1eUbR/GbGG9FGn1yNgOTLDf25oZXLjq3pzwPsqeK9MeYYgs= 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+95115+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655133252581.8564876374289; Thu, 13 Oct 2022 02:58:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HLxkYY1788612xwJRlrxIWX6; Thu, 13 Oct 2022 02:58:52 -0700 X-Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mx.groups.io with SMTP id smtpd.web08.5675.1665655132153386756 for ; Thu, 13 Oct 2022 02:58:52 -0700 X-Received: by mail-pg1-f169.google.com with SMTP id s206so1144577pgs.3 for ; Thu, 13 Oct 2022 02:58:52 -0700 (PDT) X-Gm-Message-State: htQiwwwaGXMWTyH5LmejzhkDx1787277AA= X-Google-Smtp-Source: AMsMyM4p1jYNVBCGpc4BiRvuva3srheFuUVL3OX5c+9p+rqR13aHdiFCr+UpsTnIdy93iU58NT+fkw== X-Received: by 2002:a05:6a00:4214:b0:562:67d0:77e7 with SMTP id cd20-20020a056a00421400b0056267d077e7mr36552536pfb.62.1665655131364; Thu, 13 Oct 2022 02:58:51 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:58:50 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 05/34] OvmfPkg/PlatformInitLib: Refactor to allow other architectures Date: Thu, 13 Oct 2022 15:28:00 +0530 Message-Id: <20221013095829.1454581-6-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655132; bh=OCLqOPtA3GU3mzMWKNI42k+9/rQLxy4MXonmcDUS9bo=; h=Cc:Date:From:Reply-To:Subject:To; b=ZuPRBXOeB9FqWC/YkiQ3g0H5MDKNGitynikLqTUhPXm7L54nhvQMXhiPB+jd3xYQM4y VD38DSu1Jwk4wBH2JXyH0GLBe+UPDD5DfTHbW1KStxWrzD8CwrE6HZhWcWLCZMJZa3cei hIuygDNLa+fdk8CoLUWm8c17ZElzeFFPYU8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655133731100001 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Currently, PlatformInitLib supports only X86 architecture. So, refactor to allow adding other architectures like RISC-V. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Sunil V L --- .../PlatformInitLib/PlatformInitLib.inf | 22 ++++++++++--------- .../PlatformInitLib/{ =3D> Ia32_X64}/Cmos.c | 0 .../PlatformInitLib/{ =3D> Ia32_X64}/IntelTdx.c | 0 .../{ =3D> Ia32_X64}/IntelTdxNull.c | 0 .../{ =3D> Ia32_X64}/MemDetect.c | 0 .../PlatformInitLib/{ =3D> Ia32_X64}/Platform.c | 0 6 files changed, 12 insertions(+), 10 deletions(-) rename OvmfPkg/Library/PlatformInitLib/{ =3D> Ia32_X64}/Cmos.c (100%) rename OvmfPkg/Library/PlatformInitLib/{ =3D> Ia32_X64}/IntelTdx.c (100%) rename OvmfPkg/Library/PlatformInitLib/{ =3D> Ia32_X64}/IntelTdxNull.c (10= 0%) rename OvmfPkg/Library/PlatformInitLib/{ =3D> Ia32_X64}/MemDetect.c (100%) rename OvmfPkg/Library/PlatformInitLib/{ =3D> Ia32_X64}/Platform.c (100%) diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/= Library/PlatformInitLib/PlatformInitLib.inf index 86a82ad3e084..d4449e40af61 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -22,16 +22,16 @@ [Defines] # VALID_ARCHITECTURES =3D IA32 X64 EBC # =20 -[Sources] - Cmos.c - MemDetect.c - Platform.c +[Sources.IA32, Sources.X64] + Ia32_X64/Cmos.c + Ia32_X64/MemDetect.c + Ia32_X64/Platform.c =20 [Sources.IA32] - IntelTdxNull.c + Ia32_X64/IntelTdxNull.c =20 [Sources.X64] - IntelTdx.c + Ia32_X64/IntelTdx.c =20 [Packages] EmbeddedPkg/EmbeddedPkg.dec @@ -45,12 +45,14 @@ [LibraryClasses] DebugLib IoLib HobLib + PcdLib + PciLib + +[LibraryClasses.IA32, LibraryClasses.X64] + MtrrLib QemuFwCfgLib QemuFwCfgSimpleParserLib MemoryAllocationLib - MtrrLib - PcdLib - PciLib PeiHardwareInfoLib =20 [LibraryClasses.X64] @@ -100,5 +102,5 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase gUefiOvmfPkgTokenSpaceGuid.PcdCfvRawDataSize =20 -[FeaturePcd] +[FeaturePcd.IA32, FeaturePcd.X64] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode diff --git a/OvmfPkg/Library/PlatformInitLib/Cmos.c b/OvmfPkg/Library/Platf= ormInitLib/Ia32_X64/Cmos.c similarity index 100% rename from OvmfPkg/Library/PlatformInitLib/Cmos.c rename to OvmfPkg/Library/PlatformInitLib/Ia32_X64/Cmos.c diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/P= latformInitLib/Ia32_X64/IntelTdx.c similarity index 100% rename from OvmfPkg/Library/PlatformInitLib/IntelTdx.c rename to OvmfPkg/Library/PlatformInitLib/Ia32_X64/IntelTdx.c diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdxNull.c b/OvmfPkg/Libra= ry/PlatformInitLib/Ia32_X64/IntelTdxNull.c similarity index 100% rename from OvmfPkg/Library/PlatformInitLib/IntelTdxNull.c rename to OvmfPkg/Library/PlatformInitLib/Ia32_X64/IntelTdxNull.c diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/Ia32_X64/MemDetect.c similarity index 100% rename from OvmfPkg/Library/PlatformInitLib/MemDetect.c rename to OvmfPkg/Library/PlatformInitLib/Ia32_X64/MemDetect.c diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/Ia32_X64/Platform.c similarity index 100% rename from OvmfPkg/Library/PlatformInitLib/Platform.c rename to OvmfPkg/Library/PlatformInitLib/Ia32_X64/Platform.c --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95115): https://edk2.groups.io/g/devel/message/95115 Mute This Topic: https://groups.io/mt/94300385/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 Sat May 18 17:16:06 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+95116+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+95116+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655135; cv=none; d=zohomail.com; s=zohoarc; b=RfvJeLTjp7lj03A8fLV+yupGIEfNMLexk9JrKRz9IJL1wD67AQtdxO+FDHA7WSwZanjN+TK2t1ynVam6ICAUVrAmz8kPO/n50QQgEk37slXhzVIJwvtn8q1acdtUkOOD3nTMeZfLunY/OdKW0oOIJ6d8gA9D3/HGgAbWL3Qu8MQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655135; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ApCJsqH+DkotQ8LjnuA00tsTCj272pPY5vT+3+4KiqM=; b=ODa8Yw+UrfVeQy5mWKawL8r68C6OShX3sfUB1V+0yFhtuYw8WuLRUWdUJebU9kDPv66F145zXl6ucEwuBFaiQgqiXPfPy+kMKKT3Dt0dqUx199OF18DikX15d+lS4Gi+WmMXtjKLa81wEZRumgMXH0q1ud3ERs5T1h2TTiipmkE= 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+95116+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655135647442.487187986412; Thu, 13 Oct 2022 02:58:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FIUgYY1788612xZjkHarADSk; Thu, 13 Oct 2022 02:58:55 -0700 X-Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mx.groups.io with SMTP id smtpd.web12.5667.1665655134797578039 for ; Thu, 13 Oct 2022 02:58:54 -0700 X-Received: by mail-pg1-f169.google.com with SMTP id 129so1139328pgc.5 for ; Thu, 13 Oct 2022 02:58:54 -0700 (PDT) X-Gm-Message-State: 5Xpnf9DYKUnvuHi05lnJ8atOx1787277AA= X-Google-Smtp-Source: AMsMyM4HkScdFSX9LmW5zESjqcJC3EnlW+vV16PQfIOX/l3ULgGuV9SWJzldlxo7xRWvJ8HzBQKIDg== X-Received: by 2002:a05:6a00:408c:b0:565:fc2c:8c71 with SMTP id bw12-20020a056a00408c00b00565fc2c8c71mr980730pfb.82.1665655134095; Thu, 13 Oct 2022 02:58:54 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:58:53 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 06/34] OvmfPkg/PlatformInitLib: Add support for RISC-V Date: Thu, 13 Oct 2022 15:28:01 +0530 Message-Id: <20221013095829.1454581-7-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655135; bh=euRTbFoOZl9Ff+LyHKIQk/1bmxz9qjPtASziMMVAG2k=; h=Cc:Date:From:Reply-To:Subject:To; b=U4ghDiEuGXeamCxnx5XgD8JeSayE1e8Q4KzEprm5lgiuLKaMXb4iqjs3dqBiICgbHgs 3+h7TmBO/F05iqn5+Fz79mp6Jt8UOPqo6jDGNt587GBaghvddEATMHDocoK5TCyVhUbSI VmT6XMLhx2nn2oV6E91dPL2aGv49JqIj2LE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655137752100006 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This is copied from edk2-platforms/Platform/RISC-V/PlatformPkg/Universal/FdtPeim but added as part of library instead of a separate module. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Daniel Schaefer Signed-off-by: Sunil V L --- .../PlatformInitLib/PlatformInitLib.inf | 9 ++- OvmfPkg/Include/Library/PlatformInitLib.h | 6 ++ .../PlatformInitLib/RiscV64/PlatformPeiLib.c | 73 +++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/Library/PlatformInitLib/RiscV64/PlatformPeiLib.c diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/= Library/PlatformInitLib/PlatformInitLib.inf index d4449e40af61..ef8675999583 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -19,7 +19,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 EBC +# VALID_ARCHITECTURES =3D IA32 X64 EBC RISCV64 # =20 [Sources.IA32, Sources.X64] @@ -33,6 +33,9 @@ [Sources.IA32] [Sources.X64] Ia32_X64/IntelTdx.c =20 +[Sources.RISCV64] + RiscV64/PlatformPeiLib.c + [Packages] EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec @@ -58,6 +61,10 @@ [LibraryClasses.IA32, LibraryClasses.X64] [LibraryClasses.X64] TdxLib =20 +[LibraryClasses.RISCV64] + RiscVSbiLib + FdtLib + [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress =20 diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Li= brary/PlatformInitLib.h index c5234bf26d45..1b8d1fad3b49 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -285,4 +285,10 @@ PlatformInitEmuVariableNvStore ( IN VOID *EmuVariableNvStore ); =20 +EFI_STATUS +EFIAPI +PlatformPeim ( + VOID + ); + #endif // PLATFORM_INIT_LIB_H_ diff --git a/OvmfPkg/Library/PlatformInitLib/RiscV64/PlatformPeiLib.c b/Ovm= fPkg/Library/PlatformInitLib/RiscV64/PlatformPeiLib.c new file mode 100644 index 000000000000..c5db7777c849 --- /dev/null +++ b/OvmfPkg/Library/PlatformInitLib/RiscV64/PlatformPeiLib.c @@ -0,0 +1,73 @@ +/** @file +The library call to pass the device tree to DXE via HOB. + +Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights = reserved.
+Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// +//// The package level header files this module uses +//// +#include + +#include +#include +#include +#include + +#include + +#include + +/** + @retval EFI_SUCCESS The address of FDT is passed in HOB. + EFI_UNSUPPORTED Can't locate FDT. +**/ +EFI_STATUS +EFIAPI +PlatformPeim ( + VOID + ) +{ + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext; + VOID *FdtPointer; + VOID *Base; + VOID *NewBase; + UINTN FdtSize; + UINTN FdtPages; + UINT64 *FdtHobData; + + FirmwareContext =3D NULL; + GetFirmwareContextPointer (&FirmwareContext); + + if (FirmwareContext =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Firmware Context is NULL\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + FdtPointer =3D (VOID *)FirmwareContext->FlattenedDeviceTree; + if (FdtPointer =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Invalid FDT pointer\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + DEBUG ((DEBUG_INFO, "%a: Build FDT HOB - FDT at address: 0x%x \n", __FUN= CTION__, FdtPointer)); + Base =3D FdtPointer; + ASSERT (Base !=3D NULL); + ASSERT (fdt_check_header (Base) =3D=3D 0); + + FdtSize =3D fdt_totalsize (Base); + 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; + + return EFI_SUCCESS; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95116): https://edk2.groups.io/g/devel/message/95116 Mute This Topic: https://groups.io/mt/94300386/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 Sat May 18 17:16:06 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+95117+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+95117+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655138; cv=none; d=zohomail.com; s=zohoarc; b=iVGH52JVqgINJU0xPfDXVp0RsMM5gNYrKryI3+zSuyFUZqpHVJDxlocZen7D1YBkTcvpbKtkK1aYT033W2nR6rPMwUBaBk+jG2W04WCkeZLv08Xxqurelr4cXd/BFVx2VHADXPFhkK3kreDE8Yn3yblKdOtDqH7b9qoMNfvVE3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655138; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=m5/sRZrEhFKWpL4IndqaK1x6mrbLgSwREEkrInyWY74=; b=SD2lRhRKHzor5yzRRzFalhIDEIGAUAo/xedpNor4La3t2mbPB29nFG2DCKkyf7pK6u2WfPoVmvlZP+1F8htXpEfBxQfTHRJyyqfmtP9NY7w7iAa9i+5wCKSng3cftuDrYsqDMKZk21BuVxHcg3PJLGFMOJ3QNt933Dwa3hzF7Sw= 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+95117+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655138543387.6530894687669; Thu, 13 Oct 2022 02:58:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hWDvYY1788612xW1ipnI80q5; Thu, 13 Oct 2022 02:58:58 -0700 X-Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mx.groups.io with SMTP id smtpd.web12.5668.1665655137628991631 for ; Thu, 13 Oct 2022 02:58:57 -0700 X-Received: by mail-pf1-f175.google.com with SMTP id m6so1543455pfb.0 for ; Thu, 13 Oct 2022 02:58:57 -0700 (PDT) X-Gm-Message-State: ioVSiDn8oW4bsLHTRMJy7vcIx1787277AA= X-Google-Smtp-Source: AMsMyM4aEqnKIUowKPBP5PvShRwAwun+aLCjRTGJkizfXOAGv0lfHGj1QyVIY10H6l7vf7XnXkrQsQ== X-Received: by 2002:a63:534e:0:b0:44e:12bf:2df8 with SMTP id t14-20020a63534e000000b0044e12bf2df8mr29081508pgl.143.1665655136877; Thu, 13 Oct 2022 02:58:56 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:58:56 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Rebecca Cran , Peter Grehan Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 07/34] OvmfPkg/ResetSystemLib: Refactor to allow other architectures. Date: Thu, 13 Oct 2022 15:28:02 +0530 Message-Id: <20221013095829.1454581-8-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655138; bh=znjsGK4Zfr3c/m7XX3D3diSurIH69m41xI+FP74ZLC8=; h=Cc:Date:From:Reply-To:Subject:To; b=CDA3YZuG332IcTlZGAsC7Gh7lIZQwQpM97OL3xfcafELify9Y+dVQG0GNyexP4qSD1u x82tmxwWNft3Ved5Og3J1k7n/SCkKsh7FVT2hl3yRan9mjF8av24xyOzR47JbuOtCWai3 0+H/PbFl6bQPfmbKjHaOGq01ntdl690UWv0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655139763100010 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Currently, the ResetSystemLib library supports only X86 architecture. Refactor it to allow adding other CPU architectures like RISC-V. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Rebecca Cran Cc: Peter Grehan Signed-off-by: Sunil V L --- OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf | 6 +++--- OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf | 4 ++-- .../Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf | 2 +- OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf | 6 +++--- OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf | 4 ++-- .../ResetSystemLib/{ =3D> Ia32_X64}/BaseResetShutdown.c | 0 .../ResetSystemLib/{ =3D> Ia32_X64}/BaseResetShutdownBhyve.c | 0 .../ResetSystemLib/{ =3D> Ia32_X64}/DxeResetShutdown.c | 0 .../{ =3D> Ia32_X64}/DxeResetSystemLibMicrovm.c | 0 .../Library/ResetSystemLib/{ =3D> Ia32_X64}/ResetSystemLib.c | 0 .../ResetSystemLib/{ =3D> Ia32_X64}/ResetSystemLibMicrovm.c | 0 11 files changed, 11 insertions(+), 11 deletions(-) rename OvmfPkg/Library/ResetSystemLib/{ =3D> Ia32_X64}/BaseResetShutdown.c= (100%) rename OvmfPkg/Library/ResetSystemLib/{ =3D> Ia32_X64}/BaseResetShutdownBh= yve.c (100%) rename OvmfPkg/Library/ResetSystemLib/{ =3D> Ia32_X64}/DxeResetShutdown.c = (100%) rename OvmfPkg/Library/ResetSystemLib/{ =3D> Ia32_X64}/DxeResetSystemLibMi= crovm.c (100%) rename OvmfPkg/Library/ResetSystemLib/{ =3D> Ia32_X64}/ResetSystemLib.c (1= 00%) rename OvmfPkg/Library/ResetSystemLib/{ =3D> Ia32_X64}/ResetSystemLibMicro= vm.c (100%) diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf b/OvmfPk= g/Library/ResetSystemLib/BaseResetSystemLib.inf index 35d317f1e0b3..4397f90a24dd 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf @@ -21,9 +21,9 @@ [Defines] # VALID_ARCHITECTURES =3D IA32 X64 # =20 -[Sources] - BaseResetShutdown.c - ResetSystemLib.c +[Sources.IA32, Sources.X64] + Ia32_X64/BaseResetShutdown.c + Ia32_X64/ResetSystemLib.c =20 [Packages] MdeModulePkg/MdeModulePkg.dec diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf b/O= vmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf index 74124aed38e8..3e52a9e3d7f9 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf @@ -25,8 +25,8 @@ [Defines] # =20 [Sources] - BaseResetShutdownBhyve.c - ResetSystemLib.c + Ia32_X64/BaseResetShutdownBhyve.c + Ia32_X64/ResetSystemLib.c =20 [Packages] MdeModulePkg/MdeModulePkg.dec diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf b= /OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf index 564b1d3022a6..c66720771d82 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf @@ -23,7 +23,7 @@ [Defines] # =20 [Sources] - ResetSystemLibMicrovm.c + Ia32_X64/ResetSystemLibMicrovm.c =20 [Packages] MdeModulePkg/MdeModulePkg.dec diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf b/OvmfPkg= /Library/ResetSystemLib/DxeResetSystemLib.inf index a9b4ce90000a..79478453d7cb 100644 --- a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf @@ -23,9 +23,9 @@ [Defines] # VALID_ARCHITECTURES =3D IA32 X64 # =20 -[Sources] - DxeResetShutdown.c - ResetSystemLib.c +[Sources.IA32, Sources.X64] + Ia32_X64/DxeResetShutdown.c + Ia32_X64/ResetSystemLib.c =20 [Packages] MdeModulePkg/MdeModulePkg.dec diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf b/= OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf index ac9c2599642c..6c79492f816b 100644 --- a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf @@ -24,8 +24,8 @@ [Defines] # =20 [Sources] - ResetSystemLibMicrovm.c - DxeResetSystemLibMicrovm.c + Ia32_X64/ResetSystemLibMicrovm.c + Ia32_X64/DxeResetSystemLibMicrovm.c =20 [Packages] MdeModulePkg/MdeModulePkg.dec diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c b/OvmfPkg/L= ibrary/ResetSystemLib/Ia32_X64/BaseResetShutdown.c similarity index 100% rename from OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c rename to OvmfPkg/Library/ResetSystemLib/Ia32_X64/BaseResetShutdown.c diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdownBhyve.c b/Ovmf= Pkg/Library/ResetSystemLib/Ia32_X64/BaseResetShutdownBhyve.c similarity index 100% rename from OvmfPkg/Library/ResetSystemLib/BaseResetShutdownBhyve.c rename to OvmfPkg/Library/ResetSystemLib/Ia32_X64/BaseResetShutdownBhyve.c diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c b/OvmfPkg/Li= brary/ResetSystemLib/Ia32_X64/DxeResetShutdown.c similarity index 100% rename from OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c rename to OvmfPkg/Library/ResetSystemLib/Ia32_X64/DxeResetShutdown.c diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c b/Ov= mfPkg/Library/ResetSystemLib/Ia32_X64/DxeResetSystemLibMicrovm.c similarity index 100% rename from OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c rename to OvmfPkg/Library/ResetSystemLib/Ia32_X64/DxeResetSystemLibMicrovm.c diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c b/OvmfPkg/Libr= ary/ResetSystemLib/Ia32_X64/ResetSystemLib.c similarity index 100% rename from OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c rename to OvmfPkg/Library/ResetSystemLib/Ia32_X64/ResetSystemLib.c diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLibMicrovm.c b/OvmfP= kg/Library/ResetSystemLib/Ia32_X64/ResetSystemLibMicrovm.c similarity index 100% rename from OvmfPkg/Library/ResetSystemLib/ResetSystemLibMicrovm.c rename to OvmfPkg/Library/ResetSystemLib/Ia32_X64/ResetSystemLibMicrovm.c --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95117): https://edk2.groups.io/g/devel/message/95117 Mute This Topic: https://groups.io/mt/94300388/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 Sat May 18 17:16:06 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+95119+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+95119+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655141; cv=none; d=zohomail.com; s=zohoarc; b=ZbjFzwMspM7xFwFiMt9CGn6QX/WhLKlrTqgbB442BQyrgf9YZMXniJynXUOwlxXNqFA8ysr/Vk9owR2WtioaK/vM3o7lJHOYT/cDemSnlrp8r3gpIWIGLAw75drbZODSZLWe7CPqRWGmHE6KG7FZDama3MaobFaQT7GniQmZFZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655141; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=TYK83+SPGXiYlPIudCdp0dOOmyqCv5vbO9tjvNaIhqY=; b=mpG5PltHNGuW/uHSkjFQCuJ07hkIbelyqq5YGlobPSzC2EkpW7Joxa2tPvXRe7SUsGJUklBxe9R4XlK5elLjJJ4XMjNbg995g7n4eEra+YJPmU+g9amfF4qIf7UGfGFrTJVSJVJLDBZ9g2AQW/fevZ3RNWjbJbuD2kpXuD/e/GQ= 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+95119+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655141894611.1076153738763; Thu, 13 Oct 2022 02:59:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id WwSsYY1788612xOVTXIAuw3b; Thu, 13 Oct 2022 02:59:01 -0700 X-Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by mx.groups.io with SMTP id smtpd.web11.5664.1665655140872101978 for ; Thu, 13 Oct 2022 02:59:01 -0700 X-Received: by mail-pj1-f53.google.com with SMTP id fw14so1508342pjb.3 for ; Thu, 13 Oct 2022 02:59:00 -0700 (PDT) X-Gm-Message-State: UnSMqSt28xgmRCTTew3pkwCpx1787277AA= X-Google-Smtp-Source: AMsMyM7PnxDhJduYtA0EXwAKHvTjr6NLv1KW+sN/KNrhZUgcwZTJ/KpppuqQfDLwXQlTPuqcBIlwLQ== X-Received: by 2002:a17:90b:33cd:b0:20d:9da6:56e3 with SMTP id lk13-20020a17090b33cd00b0020d9da656e3mr5302473pjb.143.1665655140032; Thu, 13 Oct 2022 02:59:00 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:58:59 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Rebecca Cran , Peter Grehan , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 08/34] OvmfPkg/ResetSystemLib: Add support for RISC-V Date: Thu, 13 Oct 2022 15:28:03 +0530 Message-Id: <20221013095829.1454581-9-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655141; bh=hwCJddLsiF7R8FbfZEQBOzkbO1ZILkX3EXjROOnG6jc=; h=Cc:Date:From:Reply-To:Subject:To; b=WHO0VbCjJ0jC/DnMbFJ/9MgnG6hK9eIKbDmGRf+asAEJHYS//bhIWu4xY9CVmJn9HUL oCAyqbHyvXxE6JBf9bCNibAc1RPCUHA4MWMmjovJfgGdU6DV18RT/vXv+2P/ldLE9P8Cn Fpdz/I+Mc3zwJJvh4Cx7cO2EvOnXOUZrLQw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655143815100002 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This is mostly copied from edk2-platforms/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Rebecca Cran Cc: Peter Grehan Cc: Daniel Schaefer Signed-off-by: Sunil V L Acked-by: Abner Chang --- .../ResetSystemLib/BaseResetSystemLib.inf | 6 + .../ResetSystemLib/DxeResetSystemLib.inf | 9 +- .../ResetSystemLib/RiscV64/DxeResetShutdown.c | 20 +++ .../ResetSystemLib/RiscV64/ResetSystemLib.c | 128 ++++++++++++++++++ 4 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown= .c create mode 100644 OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf b/OvmfPk= g/Library/ResetSystemLib/BaseResetSystemLib.inf index 4397f90a24dd..83cebb45b3db 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf @@ -25,6 +25,9 @@ [Sources.IA32, Sources.X64] Ia32_X64/BaseResetShutdown.c Ia32_X64/ResetSystemLib.c =20 +[Sources.RISCV64] + RiscV64/ResetSystemLib.c + [Packages] MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec @@ -36,3 +39,6 @@ [LibraryClasses] IoLib PciLib TimerLib + +[LibraryClasses.RISCV64] + RiscVSbiLib diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf b/OvmfPkg= /Library/ResetSystemLib/DxeResetSystemLib.inf index 79478453d7cb..abab573f2f06 100644 --- a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf @@ -20,13 +20,17 @@ [Defines] # The following information is for reference only and not required by the = build # tools. # -# VALID_ARCHITECTURES =3D IA32 X64 +# VALID_ARCHITECTURES =3D IA32 X64 RISCV64 # =20 [Sources.IA32, Sources.X64] Ia32_X64/DxeResetShutdown.c Ia32_X64/ResetSystemLib.c =20 +[Sources.RISCV64] + RiscV64/ResetSystemLib.c + RiscV64/DxeResetShutdown.c + [Packages] MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec @@ -39,5 +43,8 @@ [LibraryClasses] PcdLib TimerLib =20 +[LibraryClasses.RISCV64] + RiscVSbiLib + [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId ## CONSUMES diff --git a/OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c b/Ov= mfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c new file mode 100644 index 000000000000..027e235cad11 --- /dev/null +++ b/OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c @@ -0,0 +1,20 @@ +/** @file + DXE Reset System Library Shutdown API implementation for OVMF. + + Copyright (C) 2020, Red Hat, Inc. + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // CpuDeadLoop() +#include // ResetShutdown() + +EFI_STATUS +EFIAPI +DxeResetInit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return EFI_SUCCESS; +} diff --git a/OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c b/Ovmf= Pkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c new file mode 100644 index 000000000000..14f7653aa8de --- /dev/null +++ b/OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c @@ -0,0 +1,128 @@ +/** @file + Reset System Library functions for RISC-V + + Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.=
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/** + 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 + ) +{ + // Warm Reset via SBI ecall + SbiSystemReset (SBI_SRST_RESET_TYPE_COLD_REBOOT, SBI_SRST_RESET_REASON_N= ONE); +} + +/** + This function causes a system-wide initialization (warm reset), in which= all processors + are set to their initial state. Pending cycles are not corrupted. + + If this function returns, it means that the system does not support warm= reset. +**/ +VOID +EFIAPI +ResetWarm ( + VOID + ) +{ + // Warm Reset via SBI ecall + SbiSystemReset (SBI_SRST_RESET_TYPE_WARM_REBOOT, SBI_SRST_RESET_REASON_N= ONE); +} + +/** + 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 + ) +{ + // Shut down via SBI ecall + SbiSystemReset (SBI_SRST_RESET_TYPE_SHUTDOWN, SBI_SRST_RESET_REASON_NONE= ); +} + +/** + 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 m= ay + 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 + ) +{ + // + // Can map to OpenSBI vendor or platform specific reset type. + // + return; +} + +/** + The ResetSystem function resets the entire platform. + + @param[in] ResetType The type of reset to perform. + @param[in] ResetStatus The status code for the reset. + @param[in] DataSize The size, in bytes, of ResetData. + @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm,= or EfiResetShutdown + the data buffer starts with a Null-terminated = string, optionally + followed by additional binary data. The string= is a description + that the caller may use to further indicate th= e reason for the + system reset. +**/ +VOID +EFIAPI +ResetSystem ( + IN EFI_RESET_TYPE ResetType, + IN EFI_STATUS ResetStatus, + IN UINTN DataSize, + IN VOID *ResetData OPTIONAL + ) +{ + switch (ResetType) { + case EfiResetWarm: + ResetWarm (); + break; + + case EfiResetCold: + ResetCold (); + break; + + case EfiResetShutdown: + ResetShutdown (); + return; + + case EfiResetPlatformSpecific: + ResetPlatformSpecific (DataSize, ResetData); + return; + + default: + return; + } +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95119): https://edk2.groups.io/g/devel/message/95119 Mute This Topic: https://groups.io/mt/94300391/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 Sat May 18 17:16:06 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+95121+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+95121+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655157; cv=none; d=zohomail.com; s=zohoarc; b=DdxehRyp0laCUUcKnW6vNFhYcef0DNAF56GLtuDfpz0hxcWh7g27SXax/IvwQ/NhZKqfgzCkHW221z/6Ebi7ghxREdiDp9t37M9iEfpumSWV9WFnzN5Gb9vFlfQEprnQLq9rQA8zOXyGhtIOhrS1temdVeVUoqeN2TMVTG8RdUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655157; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=4oSbgap7kaMiaFqLMh/Q+ZdcU0Nln089OjweOCFqje8=; b=EKCpqytKbJ13NbJwRNmvGP7BJmaxUq+1ECgDUMXemY8DeNeFUPvy3q+PpvP9eBsjL9ZrpGDks3YilL0NVt3nWeGQSsTi3hze6ehMniJY4QhpnuRaboM9buFXvE+rnsu2/a1cxbepcu1WuSojAzu1r1Fe2ZayhHxh0YM539flGZ4= 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+95121+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16656551569971023.8051757528309; Thu, 13 Oct 2022 02:59:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bhufYY1788612x3JfIsw0iWf; Thu, 13 Oct 2022 02:59:16 -0700 X-Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mx.groups.io with SMTP id smtpd.web08.5680.1665655155993744076 for ; Thu, 13 Oct 2022 02:59:16 -0700 X-Received: by mail-pl1-f169.google.com with SMTP id l1so1316228pld.13 for ; Thu, 13 Oct 2022 02:59:15 -0700 (PDT) X-Gm-Message-State: crgkbj7IZKk6g6EjaMgKkQHSx1787277AA= X-Google-Smtp-Source: AMsMyM5ZcvMQKNa/1xGPN4yskE6VuVwjRIJmvutr+7z7TYUMgZfl8Vn26L0W/8URFHLMZ41wK2bNaQ== X-Received: by 2002:a05:6a00:80e:b0:563:4ad2:9d39 with SMTP id m14-20020a056a00080e00b005634ad29d39mr21983625pfk.66.1665655143856; Thu, 13 Oct 2022 02:59:03 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:03 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Brijesh Singh , Erdem Aktas , James Bottomley , Min Xu , Tom Lendacky Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 09/34] OvmfPkg/Sec: Refactor to allow other architectures Date: Thu, 13 Oct 2022 15:28:04 +0530 Message-Id: <20221013095829.1454581-10-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655156; bh=80WwmmXmODzKx63qSVOz2Rr0ytM/jGoY+UPi3/zd3eg=; h=Cc:Date:From:Reply-To:Subject:To; b=sKJQC86qEAmFvMk48Mif2ey7+y5NjXnvPVfHdQDMVo2SQ2at9LLsoHTE/JHGg62iwTe 0ikop6AJWferhJxCLbtpaKzbZ43W6FdrMJFHeTtfS2QZP/8faJvZIw+txcykp/ZumWMSU 2x+WHnbg7+30l/B9TiQw8f3UeaqYsb20OdU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655158120100007 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Currently, the Sec module supports only X86 architecture. Refactor the module to allow other CPU architectures. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Min Xu Cc: Tom Lendacky Signed-off-by: Sunil V L --- OvmfPkg/Sec/SecMain.inf | 18 +- OvmfPkg/Sec/{ =3D> Ia32_X64}/AmdSev.h | 0 OvmfPkg/Sec/SecMainCommon.h | 73 ++++++++ OvmfPkg/Sec/{ =3D> Ia32_X64}/AmdSev.c | 0 OvmfPkg/Sec/{ =3D> Ia32_X64}/SecMain.c | 227 +------------------------ OvmfPkg/Sec/SecMainCommon.c | 238 +++++++++++++++++++++++++++ 6 files changed, 323 insertions(+), 233 deletions(-) rename OvmfPkg/Sec/{ =3D> Ia32_X64}/AmdSev.h (100%) create mode 100644 OvmfPkg/Sec/SecMainCommon.h rename OvmfPkg/Sec/{ =3D> Ia32_X64}/AmdSev.c (100%) rename OvmfPkg/Sec/{ =3D> Ia32_X64}/SecMain.c (75%) create mode 100644 OvmfPkg/Sec/SecMainCommon.c diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 561a840f29c5..7c80ecaaf49b 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -21,10 +21,12 @@ [Defines] # VALID_ARCHITECTURES =3D IA32 X64 EBC # =20 -[Sources] - SecMain.c - AmdSev.c - AmdSev.h +[Sources.IA32, Sources.X64] + SecMainCommon.c + SecMainCommon.h + Ia32_X64/SecMain.c + Ia32_X64/AmdSev.c + Ia32_X64/AmdSev.h =20 [Sources.IA32] Ia32/SecEntry.nasm @@ -42,19 +44,21 @@ [LibraryClasses] BaseLib DebugLib BaseMemoryLib - PeiServicesLib PcdLib CpuLib - UefiCpuLib DebugAgentLib IoLib PeCoffLib PeCoffGetEntryPointLib PeCoffExtraActionLib ExtractGuidedSectionLib + CpuExceptionHandlerLib + +[LibraryClasses.IA32, LibraryClasses.X64] + UefiCpuLib LocalApicLib MemEncryptSevLib - CpuExceptionHandlerLib + PeiServicesLib CcProbeLib =20 [Ppis] diff --git a/OvmfPkg/Sec/AmdSev.h b/OvmfPkg/Sec/Ia32_X64/AmdSev.h similarity index 100% rename from OvmfPkg/Sec/AmdSev.h rename to OvmfPkg/Sec/Ia32_X64/AmdSev.h diff --git a/OvmfPkg/Sec/SecMainCommon.h b/OvmfPkg/Sec/SecMainCommon.h new file mode 100644 index 000000000000..c3cc16e2c8cf --- /dev/null +++ b/OvmfPkg/Sec/SecMainCommon.h @@ -0,0 +1,73 @@ +/** @file + Header file for common functions of Sec. + + Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +/** + 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 + ); + +/** + 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 + ); + +/** + 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 + ); diff --git a/OvmfPkg/Sec/AmdSev.c b/OvmfPkg/Sec/Ia32_X64/AmdSev.c similarity index 100% rename from OvmfPkg/Sec/AmdSev.c rename to OvmfPkg/Sec/Ia32_X64/AmdSev.c diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/Ia32_X64/SecMain.c similarity index 75% rename from OvmfPkg/Sec/SecMain.c rename to OvmfPkg/Sec/Ia32_X64/SecMain.c index 1167d22a68cc..096bab074f35 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/Ia32_X64/SecMain.c @@ -32,6 +32,7 @@ #include #include #include "AmdSev.h" +#include "SecMainCommon.h" =20 #define SEC_IDT_ENTRY_COUNT 34 =20 @@ -143,189 +144,6 @@ FindMainFv ( } while (TRUE); } =20 -/** - 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 FFS_FILE_SIZE (File); - 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 compressed main firmware volume and decompresses it. =20 @@ -474,49 +292,6 @@ DecompressMemFvs ( return EFI_SUCCESS; } =20 -/** - 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; -} - /** Reads 8-bits of CMOS data. =20 diff --git a/OvmfPkg/Sec/SecMainCommon.c b/OvmfPkg/Sec/SecMainCommon.c new file mode 100644 index 000000000000..f360e63a7c26 --- /dev/null +++ b/OvmfPkg/Sec/SecMainCommon.c @@ -0,0 +1,238 @@ +/** @file + Locate the entry point for the PEI Core + + Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include + +/** + 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 FFS_FILE_SIZE (File); + 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; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95121): https://edk2.groups.io/g/devel/message/95121 Mute This Topic: https://groups.io/mt/94300393/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 Sat May 18 17:16:06 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+95124+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+95124+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655161; cv=none; d=zohomail.com; s=zohoarc; b=S1erXOvyi71BRBulnEo7wPWbLMUm+IvpZ3HBOTxY8Tg0Sx1JvpwScqMVJ0XKVP2wV0mx6to0PZ9XMv/2j0Bpk0mbinUE5FSAoaqjx3Z5G1ZxDTGIUMNzfhA36Khrua+HCyEh7qWE7qd5doj8AzSUHC0x61c3ISZd0HFomHTND14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655161; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=W+SFcFzwvRpTGFKA6PPuBu0/42tTpB1IXpjvT88w3JI=; b=D1qJxjZ5HkPvBV2fXpjk/NbgmD5qj1KuRQ86njiPENPsHa3uRUTi0iePY9GYj6EFfgNulXPTn9zzGjhMAOr7picqmOjEvRABI7kWpBDkKPcP/gmXZ1H85fUP1EC4J9oF0w3HLjo7OJ+NQZHCB+bD+M3o3dXjB0GeQaGz7kIixQQ= 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+95124+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655161028287.137766108308; Thu, 13 Oct 2022 02:59:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id U2tkYY1788612xwEdwvybwPV; Thu, 13 Oct 2022 02:59:20 -0700 X-Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by mx.groups.io with SMTP id smtpd.web09.5762.1665655159910720636 for ; Thu, 13 Oct 2022 02:59:20 -0700 X-Received: by mail-qv1-f47.google.com with SMTP id df9so936437qvb.9 for ; Thu, 13 Oct 2022 02:59:19 -0700 (PDT) X-Gm-Message-State: hw7Q356KyhtJgNmHOwG0biD9x1787277AA= X-Google-Smtp-Source: AMsMyM4HgTJZxzlSD2yhRsOa93rGidbtvfMZq1Zycc7IG4AMj2Cjrozo1vaWk/fJKqhGPVDkIn3K/Q== X-Received: by 2002:a17:902:ccc2:b0:178:29f9:5c5e with SMTP id z2-20020a170902ccc200b0017829f95c5emr32365976ple.21.1665655147718; Thu, 13 Oct 2022 02:59:07 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:07 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Brijesh Singh , Erdem Aktas , James Bottomley , Min Xu , Tom Lendacky , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 10/34] OvmfPkg/Sec: Add RISC-V support Date: Thu, 13 Oct 2022 15:28:05 +0530 Message-Id: <20221013095829.1454581-11-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655160; bh=TIhlYq3us7lF+zrXjy+TvRyLguE45FBbIscewv1CGlk=; h=Cc:Date:From:Reply-To:Subject:To; b=w/y081A+wLQ2nAkK2xYr2ZYXP5IznMaOMhEO5xnxOaFkmQpunhYfJFBYg6UmuTQJeQV E5n9csPWxw7U/wskT2N4phaVSZcGOXCO8NELq6huwyR7of1RN3fwmscSfxoocSBagD+I8 fq6PoXw3PqUFKubi9an+2tL73MD7P8Rm9f8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655162118100003 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Add the SEC module for RISC-V. EDK2 is launched as the payload for machine mode firmware in RISC-V. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Min Xu Cc: Tom Lendacky Cc: Daniel Schaefer Signed-off-by: Sunil V L --- OvmfPkg/Sec/SecMain.inf | 16 +- OvmfPkg/Sec/RiscV64/SecMain.h | 65 ++++ OvmfPkg/Sec/RiscV64/SecMain.c | 573 +++++++++++++++++++++++++++++++++ OvmfPkg/Sec/RiscV64/SecEntry.S | 23 ++ 4 files changed, 676 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/Sec/RiscV64/SecMain.h create mode 100644 OvmfPkg/Sec/RiscV64/SecMain.c create mode 100644 OvmfPkg/Sec/RiscV64/SecEntry.S diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 7c80ecaaf49b..76c47778ce8c 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -18,7 +18,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 EBC +# VALID_ARCHITECTURES =3D IA32 X64 EBC RISCV64 # =20 [Sources.IA32, Sources.X64] @@ -34,6 +34,13 @@ [Sources.IA32] [Sources.X64] X64/SecEntry.nasm =20 +[Sources.RISCV64] + SecMainCommon.c + SecMainCommon.h + RiscV64/SecEntry.S + RiscV64/SecMain.c + RiscV64/SecMain.h + [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec @@ -61,11 +68,17 @@ [LibraryClasses.IA32, LibraryClasses.X64] PeiServicesLib CcProbeLib =20 +[LibraryClasses.RISCV64] + RiscVSbiLib + [Ppis] gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED gEfiPeiMpInitLibMpDepPpiGuid gEfiPeiMpInitLibUpDepPpiGuid =20 +[Ppis.RISCV64] + gEfiTemporaryRamDonePpiGuid ## PRODUCES + [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase @@ -88,6 +101,7 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire diff --git a/OvmfPkg/Sec/RiscV64/SecMain.h b/OvmfPkg/Sec/RiscV64/SecMain.h new file mode 100644 index 000000000000..11e3daa090b5 --- /dev/null +++ b/OvmfPkg/Sec/RiscV64/SecMain.h @@ -0,0 +1,65 @@ +/** @file + Master header file for SecCore. + + Copyright (c) 2019-2022, Hewlett Packard Enterprise Development LP. All = rights reserved.
+ Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _SEC_MAIN_H_ +#define _SEC_MAIN_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SecMainCommon.h" + +/** + Entry point to the C language phase of SEC. After the SEC assembly + code has initialized some temporary memory and set up the stack, + the control is transferred to this function. + + @param SizeOfRam Size of the temporary memory available for us= e. + @param TempRamBase Base address of temporary ram + @param BootFirmwareVolume Base address of the Boot Firmware Volume. +**/ +VOID +NORETURN +EFIAPI +SecStartup ( + IN UINTN BootHartId, + IN VOID *DeviceTreeAddress + ); + +/** + Auto-generated function that calls the library constructors for all of t= he module's + dependent libraries. This function must be called by the SEC Core once = a stack has + been established. + +**/ +VOID +EFIAPI +ProcessLibraryConstructorList ( + VOID + ); + +#endif diff --git a/OvmfPkg/Sec/RiscV64/SecMain.c b/OvmfPkg/Sec/RiscV64/SecMain.c new file mode 100644 index 000000000000..c8c852714a32 --- /dev/null +++ b/OvmfPkg/Sec/RiscV64/SecMain.c @@ -0,0 +1,573 @@ +/** @file + RISC-V SEC phase module. + + Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "SecMain.h" + +EFI_STATUS +EFIAPI +TemporaryRamMigration ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, + IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, + IN UINTN CopySize + ); + +EFI_STATUS +EFIAPI +TemporaryRamDone ( + VOID + ); + +STATIC EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi =3D { + TemporaryRamMigration +}; + +STATIC EFI_PEI_TEMPORARY_RAM_DONE_PPI mTemporaryRamDonePpi =3D { + TemporaryRamDone +}; + +STATIC EFI_PEI_PPI_DESCRIPTOR mPrivateDispatchTable[] =3D { + { + EFI_PEI_PPI_DESCRIPTOR_PPI, + &gEfiTemporaryRamSupportPpiGuid, + &mTemporaryRamSupportPpi + }, + { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiTemporaryRamDonePpiGuid, + &mTemporaryRamDonePpi + }, +}; + +/** Temporary RAM migration function. + + This function migrates the data from temporary RAM to permanent + memory. + + @param[in] PeiServices PEI service + @param[in] TemporaryMemoryBase Temporary memory base address + @param[in] PermanentMemoryBase Permanent memory base address + @param[in] CopySize Size to copy + +**/ +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; + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext; + + DEBUG (( + DEBUG_INFO, + "%a: Temp Mem Base:0x%Lx, Permanent Mem Base:0x%Lx, CopySize:0x%Lx\n", + __FUNCTION__, + 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; + + CopyMem (NewHeap, OldHeap, CopySize >> 1); // Migrate Heap + CopyMem (NewStack, OldStack, CopySize >> 1); // Migrate Stack + + // + // Reset firmware context pointer + // + GetFirmwareContextPointer (&FirmwareContext); + FirmwareContext =3D (VOID *)FirmwareContext + (unsigned long)((UINTN)New= Stack - (UINTN)OldStack); + SetFirmwareContextPointer (FirmwareContext); + + DEBUG ((DEBUG_INFO, "%a: Firmware Context is relocated to 0x%x\n", __FUN= CTION__, FirmwareContext)); + + register UINTN a0 asm ("a0") =3D (UINTN)((UINTN)NewStack - (UINTN)OldSt= ack); + + asm volatile ("add sp, sp, a0"::"r"(a0):); + return EFI_SUCCESS; +} + +/** Temprary RAM done function. + +**/ +EFI_STATUS EFIAPI +TemporaryRamDone ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "%a: 2nd time PEI core, temporary ram done.\n", __FU= NCTION__)); + return EFI_SUCCESS; +} + +/** Return platform SEC PPI before PEI Core + + @param[in,out] ThisPpiList Pointer to retrieve EFI_PEI_PPI_DESCRIPTOR. + +**/ +STATIC EFI_STATUS +GetPlatformPrePeiCorePpiDescriptor ( + IN OUT EFI_PEI_PPI_DESCRIPTOR **ThisPpiList + ) +{ + *ThisPpiList =3D mPrivateDispatchTable; + return EFI_SUCCESS; +} + +/** + Locates the main boot firmware volume. + + @param[in,out] BootFv On input, the base of the BootFv + On output, the decompressed main firmware volume + + @retval EFI_SUCCESS The main firmware volume was located and decompre= ssed + @retval EFI_NOT_FOUND The main firmware volume was not found + +**/ +EFI_STATUS +FindMainFv ( + IN OUT EFI_FIRMWARE_VOLUME_HEADER **BootFv + ) +{ + EFI_FIRMWARE_VOLUME_HEADER *Fv; + UINTN Distance; + + ASSERT (((UINTN)*BootFv & EFI_PAGE_MASK) =3D=3D 0); + + Fv =3D *BootFv; + Distance =3D (UINTN)(*BootFv)->FvLength; + do { + Fv =3D (EFI_FIRMWARE_VOLUME_HEADER *)((UINT8 *)Fv + EFI_PAGE_SI= ZE); + Distance +=3D EFI_PAGE_SIZE; + if (Distance > SIZE_32MB) { + return EFI_NOT_FOUND; + } + + if (Fv->Signature !=3D EFI_FVH_SIGNATURE) { + continue; + } + + if ((UINTN)Fv->FvLength < Distance) { + continue; + } + + *BootFv =3D Fv; + return EFI_SUCCESS; + } while (TRUE); +} + +/** + Locates the compressed main firmware volume and decompresses it. + + @param[in,out] Fv On input, the firmware volume to search + On output, the decompressed BOOT/PEI FV + + @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 +DecompressMemFvs ( + IN OUT EFI_FIRMWARE_VOLUME_HEADER **Fv + ) +{ + EFI_STATUS Status; + EFI_GUID_DEFINED_SECTION *Section; + UINT32 OutputBufferSize; + UINT32 ScratchBufferSize; + UINT16 SectionAttribute; + UINT32 AuthenticationStatus; + VOID *OutputBuffer; + VOID *ScratchBuffer; + EFI_COMMON_SECTION_HEADER *FvSection; + EFI_FIRMWARE_VOLUME_HEADER *PeiMemFv; + EFI_FIRMWARE_VOLUME_HEADER *DxeMemFv; + UINT32 FvHeaderSize; + UINT32 FvSectionSize; + + FvSection =3D (EFI_COMMON_SECTION_HEADER *)NULL; + + Status =3D FindFfsFileAndSection ( + *Fv, + EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, + EFI_SECTION_GUID_DEFINED, + (EFI_COMMON_SECTION_HEADER **)&Section + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to find GUID defined section\n")); + return Status; + } + + Status =3D ExtractGuidedSectionGetInfo ( + Section, + &OutputBufferSize, + &ScratchBufferSize, + &SectionAttribute + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to GetInfo for GUIDed section\n")); + return Status; + } + + OutputBuffer =3D (VOID *)((UINT8 *)(UINTN)PcdGet32 (PcdOvmfDxeMemFvBase= ) + SIZE_1MB); + ScratchBuffer =3D ALIGN_POINTER ((UINT8 *)OutputBuffer + OutputBufferSiz= e, SIZE_1MB); + + Status =3D ExtractGuidedSectionDecode ( + Section, + &OutputBuffer, + ScratchBuffer, + &AuthenticationStatus + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Error during GUID section decode\n")); + return Status; + } + + Status =3D FindFfsSectionInstance ( + OutputBuffer, + OutputBufferSize, + EFI_SECTION_FIRMWARE_VOLUME_IMAGE, + 0, + &FvSection + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to find PEI FV section\n")); + return Status; + } + + ASSERT ( + SECTION_SIZE (FvSection) =3D=3D + (PcdGet32 (PcdOvmfPeiMemFvSize) + sizeof (*FvSection)) + ); + ASSERT (FvSection->Type =3D=3D EFI_SECTION_FIRMWARE_VOLUME_IMAGE); + + PeiMemFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdOvmfPeiMe= mFvBase); + CopyMem (PeiMemFv, (VOID *)(FvSection + 1), PcdGet32 (PcdOvmfPeiMemFvSiz= e)); + + if (PeiMemFv->Signature !=3D EFI_FVH_SIGNATURE) { + DEBUG ((DEBUG_ERROR, "Extracted FV at %p does not have FV header signa= ture\n", PeiMemFv)); + CpuDeadLoop (); + return EFI_VOLUME_CORRUPTED; + } + + Status =3D FindFfsSectionInstance ( + OutputBuffer, + OutputBufferSize, + EFI_SECTION_FIRMWARE_VOLUME_IMAGE, + 1, + &FvSection + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to find DXE FV section\n")); + return Status; + } + + ASSERT (FvSection->Type =3D=3D EFI_SECTION_FIRMWARE_VOLUME_IMAGE); + + if (IS_SECTION2 (FvSection)) { + FvSectionSize =3D SECTION2_SIZE (FvSection); + FvHeaderSize =3D sizeof (EFI_COMMON_SECTION_HEADER2); + } else { + FvSectionSize =3D SECTION_SIZE (FvSection); + FvHeaderSize =3D sizeof (EFI_COMMON_SECTION_HEADER); + } + + ASSERT (FvSectionSize =3D=3D (PcdGet32 (PcdOvmfDxeMemFvSize) + FvHeaderS= ize)); + + DxeMemFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdOvmfDxeMe= mFvBase); + CopyMem (DxeMemFv, (VOID *)((UINTN)FvSection + FvHeaderSize), PcdGet32 (= PcdOvmfDxeMemFvSize)); + + if (DxeMemFv->Signature !=3D EFI_FVH_SIGNATURE) { + DEBUG ((DEBUG_ERROR, "Extracted FV at %p does not have FV header signa= ture\n", DxeMemFv)); + CpuDeadLoop (); + return EFI_VOLUME_CORRUPTED; + } + + *Fv =3D PeiMemFv; + return EFI_SUCCESS; +} + +/** + Locates the PEI Core entry point address + + @param[in,out] 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 + +**/ +VOID +FindPeiCoreImageBase ( + IN OUT EFI_FIRMWARE_VOLUME_HEADER **BootFv, + OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase + ) +{ + *PeiCoreImageBase =3D 0; + + FindMainFv (BootFv); + + DecompressMemFvs (BootFv); + + FindPeiCoreImageBaseInFv (*BootFv, PeiCoreImageBase); +} + +/** + Find core image base. + +**/ +EFI_STATUS +FindImageBase ( + IN EFI_FIRMWARE_VOLUME_HEADER *BootFirmwareVolumePtr, + OUT EFI_PHYSICAL_ADDRESS *SecCoreImageBase + ) +{ + EFI_PHYSICAL_ADDRESS CurrentAddress; + EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume; + EFI_FFS_FILE_HEADER *File; + UINT32 Size; + EFI_PHYSICAL_ADDRESS EndOfFile; + EFI_COMMON_SECTION_HEADER *Section; + EFI_PHYSICAL_ADDRESS EndOfSection; + + *SecCoreImageBase =3D 0; + + CurrentAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN)BootFirmwareVolumeP= tr; + EndOfFirmwareVolume =3D CurrentAddress + BootFirmwareVolumePtr->FvLength; + + // + // Loop through the FFS files in the Boot Firmware Volume + // + for (EndOfFile =3D CurrentAddress + BootFirmwareVolumePtr->HeaderLength;= ; ) { + CurrentAddress =3D (EndOfFile + 7) & 0xfffffffffffffff8ULL; + if (CurrentAddress > EndOfFirmwareVolume) { + return EFI_NOT_FOUND; + } + + File =3D (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress; + Size =3D FFS_FILE_SIZE (File); + if (Size < sizeof (*File)) { + return EFI_NOT_FOUND; + } + + EndOfFile =3D CurrentAddress + Size; + if (EndOfFile > EndOfFirmwareVolume) { + return EFI_NOT_FOUND; + } + + // + // Look for SEC Core + // + if (File->Type !=3D EFI_FV_FILETYPE_SECURITY_CORE) { + continue; + } + + // + // Loop through the FFS file sections within the FFS file + // + EndOfSection =3D (EFI_PHYSICAL_ADDRESS)(UINTN)(File + 1); + for ( ; ;) { + CurrentAddress =3D (EndOfSection + 3) & 0xfffffffffffffffcULL; + Section =3D (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddres= s; + + Size =3D SECTION_SIZE (Section); + if (Size < sizeof (*Section)) { + return EFI_NOT_FOUND; + } + + EndOfSection =3D CurrentAddress + Size; + if (EndOfSection > EndOfFile) { + return EFI_NOT_FOUND; + } + + // + // Look for executable sections + // + if ((Section->Type =3D=3D EFI_SECTION_PE32) || (Section->Type =3D=3D= EFI_SECTION_TE)) { + if (File->Type =3D=3D EFI_FV_FILETYPE_SECURITY_CORE) { + *SecCoreImageBase =3D (PHYSICAL_ADDRESS)(UINTN)(Section + 1); + } + + break; + } + } + + // + // SEC Core image found + // + if (*SecCoreImageBase !=3D 0) { + 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 SecCoreImageBase; + EFI_PHYSICAL_ADDRESS PeiCoreImageBase; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + + // + // Find SEC Core and PEI Core image base + // + Status =3D FindImageBase (*BootFirmwareVolumePtr, &SecCoreImageBase); + ASSERT_EFI_ERROR (Status); + + FindPeiCoreImageBase (BootFirmwareVolumePtr, &PeiCoreImageBase); + + ZeroMem ((VOID *)&ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT)); + // + // Report SEC Core debug information when remote debug is enabled + // + ImageContext.ImageAddress =3D SecCoreImageBase; + ImageContext.PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)= ImageContext.ImageAddress); + PeCoffLoaderRelocateImageExtraAction (&ImageContext); + + // + // 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; +} + +/** + + Entry point to the C language phase of SEC. After the SEC assembly + code has initialized some temporary memory and set up the stack, + the control is transferred to this function. + + + @param[in] BootHartId Hardware thread ID of boot hart. + @param[in] DeviceTreeAddress Pointer to Device Tree (DTB) +**/ +VOID +NORETURN +EFIAPI +SecStartup ( + IN UINTN BootHartId, + IN VOID *DeviceTreeAddress + ) +{ + EFI_RISCV_FIRMWARE_CONTEXT FirmwareContext; + EFI_FIRMWARE_VOLUME_HEADER *BootFv; + EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint; + EFI_PEI_PPI_DESCRIPTOR *PpiList; + EFI_SEC_PEI_HAND_OFF SecCoreData; + EFI_STATUS Status; + + // + // Report Status Code to indicate entering SEC core + // + DEBUG (( + DEBUG_INFO, + "%a() BootHartId: 0x%x, DeviceTreeAddress=3D0x%x\n", + __FUNCTION__, + BootHartId, + DeviceTreeAddress + )); + + // + // Process all libraries constructor function linked to SecCore. + // + ProcessLibraryConstructorList (); + + BootFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)FixedPcdGet32 (PcdOvmfFdBaseAdd= ress); + + ASSERT (BootFv !=3D NULL); + SecCoreData.DataSize =3D (UINT16)sizeof (EFI_SEC_PEI_HAND_= OFF); + SecCoreData.BootFirmwareVolumeBase =3D BootFv; + SecCoreData.BootFirmwareVolumeSize =3D (UINTN)BootFv->FvLength; + SecCoreData.TemporaryRamBase =3D (VOID *)(UINT64)FixedPcdGet32 (Pc= dOvmfSecPeiTempRamBase); + SecCoreData.TemporaryRamSize =3D (UINTN)FixedPcdGet32 (PcdOvmfSecP= eiTempRamSize); + SecCoreData.PeiTemporaryRamBase =3D SecCoreData.TemporaryRamBase; + SecCoreData.PeiTemporaryRamSize =3D SecCoreData.TemporaryRamSize >> 1; + SecCoreData.StackBase =3D (UINT8 *)SecCoreData.TemporaryRam= Base + (SecCoreData.TemporaryRamSize >> 1); + SecCoreData.StackSize =3D SecCoreData.TemporaryRamSize >> 1; + + DEBUG (( + DEBUG_INFO, + "%a() BFV Base: 0x%x, BFV Size: 0x%x, TempRAM Base: 0x%x, TempRAM Size= : 0x%x, PeiTempRamBase: 0x%x, PeiTempRamSize: 0x%x, StackBase: 0x%x, StackS= ize: 0x%x\n", + __FUNCTION__, + SecCoreData.BootFirmwareVolumeBase, + SecCoreData.BootFirmwareVolumeSize, + SecCoreData.TemporaryRamBase, + SecCoreData.TemporaryRamSize, + SecCoreData.PeiTemporaryRamBase, + SecCoreData.PeiTemporaryRamSize, + SecCoreData.StackBase, + SecCoreData.StackSize + )); + + FindAndReportEntryPoints ( + &BootFv, + &PeiCoreEntryPoint + ); + if (PeiCoreEntryPoint =3D=3D NULL) { + CpuDeadLoop (); + } + + SecCoreData.BootFirmwareVolumeBase =3D BootFv; + SecCoreData.BootFirmwareVolumeSize =3D (UINTN)BootFv->FvLength; + + Status =3D GetPlatformPrePeiCorePpiDescriptor (&PpiList); + if (EFI_ERROR (Status)) { + PpiList =3D NULL; + } + + FirmwareContext.BootHartId =3D BootHartId; + FirmwareContext.FlattenedDeviceTree =3D (UINT64)DeviceTreeAddress; + SetFirmwareContextPointer (&FirmwareContext); + + // + // Transfer the control to the PEI core + // + ASSERT (PeiCoreEntryPoint !=3D NULL); + (*PeiCoreEntryPoint)(&SecCoreData, PpiList); + + // + // Should not come here. + // + UNREACHABLE (); +} diff --git a/OvmfPkg/Sec/RiscV64/SecEntry.S b/OvmfPkg/Sec/RiscV64/SecEntry.S new file mode 100644 index 000000000000..d201e9f8a608 --- /dev/null +++ b/OvmfPkg/Sec/RiscV64/SecEntry.S @@ -0,0 +1,23 @@ +/* + Copyright (c) 2021-2022 , Hewlett Packard Enterprise Development LP. All= rights reserved. + Copyright (c) 2019 Western Digital Corporation or its affiliates. + Copyright (c) 2022 Ventana Micro Systems Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent + + */ + +#include "SecMain.h" + +.text +.align 3 + +ASM_FUNC (_ModuleEntryPoint) + /* Use Temp memory as the stack for calling to C code */ + li a4, FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) + li a5, FixedPcdGet32 (PcdOvmfSecPeiTempRamSize) + + /* Use Temp memory as the stack for calling to C code */ + add sp, a4, a5 + + call SecStartup --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95124): https://edk2.groups.io/g/devel/message/95124 Mute This Topic: https://groups.io/mt/94300396/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 Sat May 18 17:16:06 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+95145+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+95145+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655239; cv=none; d=zohomail.com; s=zohoarc; b=kYMzvA3J8FZWXtoFXhyg/XSqUWgeE6s3O3M8iIqkM198Xth0CIhDX7gXXzERCDMnNvDiTPAnd9y5nh7seQn7Sju+8nlyoZ1cYlECzxHtqxux/yvFhTVJXryhw9QLz94KxXnVK3mYHO1KrWrrTtSZeiPynJEmh7h3mE6+4ALwfoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655239; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=J/o+KhN3XqAFHdiDGz5fnEsydOwbIImVNv8LmHyc3Vo=; b=kv01gXZPUMrT6sCM5BcnJvODO58pMAMD1h1aR/XiwGx6Ic/2ytZ/Fy6ys3yAV58FR3eoNyOrES97KcGBFp2dFJ7kMzz4UB0AT2L0Uma3Q30WQMR2A3XnqC0uAlDfO/h6jBYX/m4FFbClyiPbPqTJ4n9WTQaNLv9wDPm7d2dPFPw= 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+95145+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655239113781.5931626814818; Thu, 13 Oct 2022 03:00:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id zPtCYY1788612x5dCjGS8Pw9; Thu, 13 Oct 2022 03:00:37 -0700 X-Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) by mx.groups.io with SMTP id smtpd.web08.5694.1665655233564332104 for ; Thu, 13 Oct 2022 03:00:33 -0700 X-Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-1322d768ba7so1700457fac.5 for ; Thu, 13 Oct 2022 03:00:33 -0700 (PDT) X-Gm-Message-State: dJXCLPU160FaiNHY45yeQfarx1787277AA= X-Google-Smtp-Source: AMsMyM5D5Nq/FF4NjxJ9wcjWPtdJdHDDKhmDyCHa92aR9ch/uzXxQuQvg528oWPWoR+VNh2C0gHDbA== X-Received: by 2002:a17:90b:3901:b0:20b:210d:d5d9 with SMTP id ob1-20020a17090b390100b0020b210dd5d9mr9728986pjb.83.1665655150253; Thu, 13 Oct 2022 02:59:10 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:09 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 11/34] OvmfPkg/PlatformPei: Refactor to allow other architectures Date: Thu, 13 Oct 2022 15:28:06 +0530 Message-Id: <20221013095829.1454581-12-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655237; bh=dVvLoAN+aPUWnu5LdGoTfUBLqSZI96bx8u7zoCBYdM8=; h=Cc:Date:From:Reply-To:Subject:To; b=oiqeQVqJy0pIy0VQlgVmtFCYnHmOvEyBTqLQyFXlJgomiKUztKzinFEEaTH5ID1S09q CcD8y3zIj1y7lSt5eB364ujEaxsdLN4BCzsllGs9c3vhladGx7SqLuZpO5bi97rddHLtx QRWCtbRLqTZNYHXOAJzk4n8EN+ctsr7Jz8c= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655240522100003 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Currently, PlatformPei supports only X86 architecture. So, refactor it to allow other CPU architectures. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Sunil V L --- OvmfPkg/PlatformPei/PlatformPei.inf | 34 +++++++++++-------- OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/Platform.h | 0 OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/AmdSev.c | 0 .../PlatformPei/{ =3D> Ia32_X64}/ClearCache.c | 0 .../{ =3D> Ia32_X64}/FeatureControl.c | 0 OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/Fv.c | 0 OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/IntelTdx.c | 0 .../PlatformPei/{ =3D> Ia32_X64}/MemDetect.c | 0 .../PlatformPei/{ =3D> Ia32_X64}/MemTypeInfo.c | 0 OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/Platform.c | 0 10 files changed, 19 insertions(+), 15 deletions(-) rename OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/Platform.h (100%) rename OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/AmdSev.c (100%) rename OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/ClearCache.c (100%) rename OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/FeatureControl.c (100%) rename OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/Fv.c (100%) rename OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/IntelTdx.c (100%) rename OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/MemDetect.c (100%) rename OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/MemTypeInfo.c (100%) rename OvmfPkg/PlatformPei/{ =3D> Ia32_X64}/Platform.c (100%) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 3cd83e6ec3e5..683ebf1a440a 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -22,16 +22,16 @@ [Defines] # VALID_ARCHITECTURES =3D IA32 X64 EBC # =20 -[Sources] - AmdSev.c - ClearCache.c - FeatureControl.c - Fv.c - MemDetect.c - MemTypeInfo.c - Platform.c - Platform.h - IntelTdx.c +[Sources.IA32, Sources.X64] + Ia32_X64/AmdSev.c + Ia32_X64/ClearCache.c + Ia32_X64/FeatureControl.c + Ia32_X64/Fv.c + Ia32_X64/MemDetect.c + Ia32_X64/MemTypeInfo.c + Ia32_X64/Platform.c + Ia32_X64/Platform.h + Ia32_X64/IntelTdx.c =20 [Packages] EmbeddedPkg/EmbeddedPkg.dec @@ -57,14 +57,16 @@ [LibraryClasses] PeiServicesLib PeiServicesTablePointerLib PeimEntryPoint + PcdLib + PlatformInitLib + +[LibraryClasses.IA32, LibraryClasses.X64] + MtrrLib + VmgExitLib QemuFwCfgLib QemuFwCfgS3Lib QemuFwCfgSimpleParserLib - MtrrLib MemEncryptSevLib - PcdLib - VmgExitLib - PlatformInitLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase @@ -99,7 +101,6 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable @@ -116,6 +117,9 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask =20 +[Pcd.IA32, Pcd.X64] + gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode + [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Ia32_X64/= Platform.h similarity index 100% rename from OvmfPkg/PlatformPei/Platform.h rename to OvmfPkg/PlatformPei/Ia32_X64/Platform.h diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/Ia32_X64/Am= dSev.c similarity index 100% rename from OvmfPkg/PlatformPei/AmdSev.c rename to OvmfPkg/PlatformPei/Ia32_X64/AmdSev.c diff --git a/OvmfPkg/PlatformPei/ClearCache.c b/OvmfPkg/PlatformPei/Ia32_X6= 4/ClearCache.c similarity index 100% rename from OvmfPkg/PlatformPei/ClearCache.c rename to OvmfPkg/PlatformPei/Ia32_X64/ClearCache.c diff --git a/OvmfPkg/PlatformPei/FeatureControl.c b/OvmfPkg/PlatformPei/Ia3= 2_X64/FeatureControl.c similarity index 100% rename from OvmfPkg/PlatformPei/FeatureControl.c rename to OvmfPkg/PlatformPei/Ia32_X64/FeatureControl.c diff --git a/OvmfPkg/PlatformPei/Fv.c b/OvmfPkg/PlatformPei/Ia32_X64/Fv.c similarity index 100% rename from OvmfPkg/PlatformPei/Fv.c rename to OvmfPkg/PlatformPei/Ia32_X64/Fv.c diff --git a/OvmfPkg/PlatformPei/IntelTdx.c b/OvmfPkg/PlatformPei/Ia32_X64/= IntelTdx.c similarity index 100% rename from OvmfPkg/PlatformPei/IntelTdx.c rename to OvmfPkg/PlatformPei/Ia32_X64/IntelTdx.c diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/Ia32_X64= /MemDetect.c similarity index 100% rename from OvmfPkg/PlatformPei/MemDetect.c rename to OvmfPkg/PlatformPei/Ia32_X64/MemDetect.c diff --git a/OvmfPkg/PlatformPei/MemTypeInfo.c b/OvmfPkg/PlatformPei/Ia32_X= 64/MemTypeInfo.c similarity index 100% rename from OvmfPkg/PlatformPei/MemTypeInfo.c rename to OvmfPkg/PlatformPei/Ia32_X64/MemTypeInfo.c diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Ia32_X64/= Platform.c similarity index 100% rename from OvmfPkg/PlatformPei/Platform.c rename to OvmfPkg/PlatformPei/Ia32_X64/Platform.c --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95145): https://edk2.groups.io/g/devel/message/95145 Mute This Topic: https://groups.io/mt/94300425/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 Sat May 18 17:16:06 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+95120+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+95120+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655154; cv=none; d=zohomail.com; s=zohoarc; b=fgPoGFLulNSi+MhsFpO1pSiiB9pfe3vD+r7YWJ+PuwGPW45yMgHqP440j2ASH0baPEh7vzFvPWUoMVUp/cceZ5mLkrOKV884/QnwLSSRUKvZTNhtlPjNCpaFyDcyhGo/hIocrlhXb42W0W91+G7LPyc6PBOMedJeJjRHr5aGYIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655154; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=CfgGu1uKT4lmkqgzSvIwebjwRU5CCjXCkU4ylMyP4Xc=; b=JRPtrsjRfCHHV+XIQuLA6CKJdI+qHqwOogy5V37TVUHaCJ/m6zmjIsH9GPdJfE8i31OYxOxqklbJ5NpbbWiKGGauUk8cgyYc8+2pai7n5ffMIzMotdxaFDsNOUnL8BEaEAv7dgu31vuqJ9EGroIoByclt/lEgs4aXNnAFk7UTFo= 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+95120+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655154976155.93142870818372; Thu, 13 Oct 2022 02:59:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id zIiKYY1788612xnydlV4rrr3; Thu, 13 Oct 2022 02:59:14 -0700 X-Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by mx.groups.io with SMTP id smtpd.web09.5759.1665655154040422465 for ; Thu, 13 Oct 2022 02:59:14 -0700 X-Received: by mail-pj1-f44.google.com with SMTP id a6-20020a17090abe0600b0020d7c0c6650so4508856pjs.0 for ; Thu, 13 Oct 2022 02:59:13 -0700 (PDT) X-Gm-Message-State: 74cXIkdC6aMRQqtYZzvbtN2yx1787277AA= X-Google-Smtp-Source: AMsMyM6xuABF+bu2LtTvhCi3nPOhil67ii4gHAJ5eJC7jdIMfp1SdQBLOF1SYVujBIPA4xPwDdYzUQ== X-Received: by 2002:a17:90b:1c11:b0:20c:d721:8813 with SMTP id oc17-20020a17090b1c1100b0020cd7218813mr10239664pjb.244.1665655153166; Thu, 13 Oct 2022 02:59:13 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:12 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 12/34] OvmfPkg/PlatformPei: Add support for RISC-V Date: Thu, 13 Oct 2022 15:28:07 +0530 Message-Id: <20221013095829.1454581-13-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655154; bh=IfwbG+TUmBX8ZQ6hVhrq4/NalsFWicsMsGCxGzKLGJk=; h=Cc:Date:From:Reply-To:Subject:To; b=MowDQR640GazVa3ow3X4K57xI2at2IxV5tIPKi7bckp8YdpBs+m0npZiWHuFjjwRRQA 02GQdaBNUy9FYcXrmNBeA98zs3+j0Yoc0pgXF+DGDRoMyDymEPKRHFZm7CjTnRDbhSuCJ 8wquQonSRNAqOolY5HxWUZoT6SvrKq+YleM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655156154100002 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This is mostly copied from edk2-platforms/Platform/RISC-V/PlatformPkg/Universal/Pei/PlatformPei Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Daniel Schaefer Signed-off-by: Sunil V L --- OvmfPkg/PlatformPei/PlatformPei.inf | 9 + OvmfPkg/PlatformPei/RiscV64/Platform.h | 97 ++++++ OvmfPkg/PlatformPei/RiscV64/Fv.c | 81 ++++++ OvmfPkg/PlatformPei/RiscV64/MemDetect.c | 212 ++++++++++++++ OvmfPkg/PlatformPei/RiscV64/Platform.c | 372 ++++++++++++++++++++++++ 5 files changed, 771 insertions(+) create mode 100644 OvmfPkg/PlatformPei/RiscV64/Platform.h create mode 100644 OvmfPkg/PlatformPei/RiscV64/Fv.c create mode 100644 OvmfPkg/PlatformPei/RiscV64/MemDetect.c create mode 100644 OvmfPkg/PlatformPei/RiscV64/Platform.c diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 683ebf1a440a..0bae88f6d01b 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -33,6 +33,12 @@ [Sources.IA32, Sources.X64] Ia32_X64/Platform.h Ia32_X64/IntelTdx.c =20 +[Sources.RISCV64] + RiscV64/Fv.c + RiscV64/MemDetect.c + RiscV64/Platform.c + RiscV64/Platform.h + [Packages] EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec @@ -68,6 +74,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] QemuFwCfgSimpleParserLib MemEncryptSevLib =20 +[LibraryClasses.RISCV64] + RiscVSbiLib + [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize diff --git a/OvmfPkg/PlatformPei/RiscV64/Platform.h b/OvmfPkg/PlatformPei/R= iscV64/Platform.h new file mode 100644 index 000000000000..6c23c722a360 --- /dev/null +++ b/OvmfPkg/PlatformPei/RiscV64/Platform.h @@ -0,0 +1,97 @@ +/** @file + Platform PEI module include file. + + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
+ Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PLATFORM_PEI_H_INCLUDED_ +#define PLATFORM_PEI_H_INCLUDED_ + +VOID +AddIoMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); + +VOID +AddIoMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ); + +VOID +AddMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); + +VOID +AddMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ); + +VOID +AddUntestedMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); + +VOID +AddReservedMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); + +VOID +AddUntestedMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ); + +VOID +AddressWidthInitialization ( + VOID + ); + +EFI_STATUS +PublishPeiMemory ( + VOID + ); + +UINT32 +GetSystemMemorySizeBelow4gb ( + VOID + ); + +VOID +InitializeRamRegions ( + VOID + ); + +EFI_STATUS +PeiFvInitialization ( + VOID + ); + +EFI_STATUS +InitializeXen ( + VOID + ); + +/** + Build processor and platform information for the U5 platform + + @return EFI_SUCCESS Status. + +**/ +EFI_STATUS +BuildRiscVSmbiosHobs ( + VOID + ); + +#endif // _PLATFORM_PEI_H_INCLUDED_ diff --git a/OvmfPkg/PlatformPei/RiscV64/Fv.c b/OvmfPkg/PlatformPei/RiscV64= /Fv.c new file mode 100644 index 000000000000..ff99c1432935 --- /dev/null +++ b/OvmfPkg/PlatformPei/RiscV64/Fv.c @@ -0,0 +1,81 @@ +/** @file + Build FV related hobs for platform. + + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
+ Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "PiPei.h" +#include "Platform.h" +#include +#include +#include +#include + +/** + 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 DXE FV. + // + // If "secure" S3 is needed, then SEC will decompress both PEI and DXE + // firmware volumes at S3 resume too, hence we need to keep away the OS = from + // DXEFV as well. Otherwise we only need to keep away DXE itself from the + // DXEFV area. + // + BuildMemoryAllocationHob ( + PcdGet32 (PcdOvmfPeiMemFvBase), + PcdGet32 (PcdOvmfPeiMemFvSize), + EfiBootServicesData + ); + + // + // Let DXE know about the DXE FV + // + BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSiz= e)); + DEBUG (( + DEBUG_INFO, + "Platform builds DXE FV at %x, size %x.\n", + PcdGet32 (PcdOvmfDxeMemFvBase), + PcdGet32 (PcdOvmfDxeMemFvSize) + )); + + // Create a memory allocation HOB for the DXE FV. + // + // If "secure" S3 is needed, then SEC will decompress both PEI and DXE + // firmware volumes at S3 resume too, hence we need to keep away the OS = from + // DXEFV as well. Otherwise we only need to keep away DXE itself from the + // DXEFV area. + // + BuildMemoryAllocationHob ( + PcdGet32 (PcdOvmfDxeMemFvBase), + PcdGet32 (PcdOvmfDxeMemFvSize), + EfiBootServicesData + ); + + // + // Let PEI know about the DXE FV so it can find the DXE Core + // + PeiServicesInstallFvInfoPpi ( + NULL, + (VOID *)(UINTN)PcdGet32 (PcdOvmfDxeMemFvBase), + PcdGet32 (PcdOvmfDxeMemFvSize), + NULL, + NULL + ); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/PlatformPei/RiscV64/MemDetect.c b/OvmfPkg/PlatformPei/= RiscV64/MemDetect.c new file mode 100644 index 000000000000..eb9d24581f8d --- /dev/null +++ b/OvmfPkg/PlatformPei/RiscV64/MemDetect.c @@ -0,0 +1,212 @@ +/** @file + Memory Detection for Virtual Machines. + + Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All right= s reserved.
+ Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +Module Name: + + MemDetect.c + +**/ + +// +// 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" + +STATIC EFI_PHYSICAL_ADDRESS SystemMemoryBase; +STATIC UINT64 SystemMemorySize; +STATIC EFI_PHYSICAL_ADDRESS MmodeResvBase; +STATIC UINT64 MmodeResvSize; + +/** + Publish PEI core memory. + + @return EFI_SUCCESS The PEIM initialized successfully. + +**/ +EFI_STATUS +PublishPeiMemory ( + VOID + ) +{ + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext; + EFI_PHYSICAL_ADDRESS MemoryBase; + CONST UINT64 *RegProp; + CONST CHAR8 *Type; + EFI_STATUS Status; + UINT64 CurBase, CurSize; + UINT64 NewBase =3D 0, NewSize =3D 0; + UINT64 MemorySize; + INT32 Node, Prev; + INT32 Len; + VOID *FdtPointer; + + FirmwareContext =3D NULL; + GetFirmwareContextPointer (&FirmwareContext); + + if (FirmwareContext =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Firmware Context is NULL\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + FdtPointer =3D (VOID *)FirmwareContext->FlattenedDeviceTree; + if (FdtPointer =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Invalid FDT pointer\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + // Look for the lowest memory node + for (Prev =3D 0; ; Prev =3D Node) { + Node =3D fdt_next_node (FdtPointer, Prev, NULL); + if (Node < 0) { + break; + } + + // Check for memory node + Type =3D fdt_getprop (FdtPointer, Node, "device_type", &Len); + if (Type && (AsciiStrnCmp (Type, "memory", 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 (FdtPointer, Node, "reg", &Len); + if ((RegProp !=3D 0) && (Len =3D=3D (2 * sizeof (UINT64)))) { + CurBase =3D fdt64_to_cpu (ReadUnaligned64 (RegProp)); + CurSize =3D fdt64_to_cpu (ReadUnaligned64 (RegProp + 1)); + + DEBUG (( + DEBUG_INFO, + "%a: System RAM @ 0x%lx - 0x%lx\n", + __FUNCTION__, + CurBase, + CurBase + CurSize - 1 + )); + + if ((NewBase > CurBase) || (NewBase =3D=3D 0)) { + NewBase =3D CurBase; + NewSize =3D CurSize; + } + } else { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to parse FDT memory node\n", + __FUNCTION__ + )); + } + } + } + + SystemMemoryBase =3D NewBase; + SystemMemorySize =3D NewSize; + + /* try to locate the reserved memory opensbi node */ + Node =3D fdt_path_offset (FdtPointer, "/reserved-memory/mmode_resv0"); + if (Node >=3D 0) { + RegProp =3D fdt_getprop (FdtPointer, Node, "reg", &Len); + if ((RegProp !=3D 0) && (Len =3D=3D (2 * sizeof (UINT64)))) { + NewBase =3D fdt64_to_cpu (ReadUnaligned64 (RegProp)); + NewSize =3D fdt64_to_cpu (ReadUnaligned64 (RegProp + 1)); + DEBUG (( + DEBUG_INFO, + "%a: M-mode Base =3D 0x%lx, M-mode Size =3D 0x%lx\n", + __FUNCTION__, + NewBase, + NewSize + )); + MmodeResvBase =3D NewBase; + MmodeResvSize =3D NewSize; + } + } + + DEBUG (( + DEBUG_INFO, + "%a: SystemMemoryBase:0x%x SystemMemorySize:%x\n", + __FUNCTION__, + SystemMemoryBase, + SystemMemorySize + )); + + // + // Initial 16MB needs to be reserved + // + MemoryBase =3D SystemMemoryBase + SIZE_16MB; + MemorySize =3D SystemMemorySize - SIZE_16MB; + + // + // Publish this memory to the PEI Core + // + Status =3D PublishSystemMemory (MemoryBase, MemorySize); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** + Publish system RAM and reserve memory regions. + +**/ +VOID +InitializeRamRegions ( + VOID + ) +{ + /* + * M-mode FW can be loaded anywhere in memory but should not overlap + * with the EDK2. This can happen if some other boot code loads the + * M-mode firmware. + * + * The M-mode firmware memory should be marked as reserved memory + * so that OS doesn't use it. + */ + DEBUG (( + DEBUG_INFO, + "%a: M-mode FW Memory Start:0x%lx End:0x%lx\n", + __FUNCTION__, + MmodeResvBase, + MmodeResvBase + MmodeResvSize + )); + AddReservedMemoryBaseSizeHob (MmodeResvBase, MmodeResvSize); + + if (MmodeResvBase > SystemMemoryBase) { + DEBUG (( + DEBUG_INFO, + "%a: Free Memory Start:0x%lx End:0x%lx\n", + __FUNCTION__, + SystemMemoryBase, + MmodeResvBase + )); + AddMemoryRangeHob (SystemMemoryBase, MmodeResvBase); + } + + DEBUG (( + DEBUG_INFO, + "%a: Free Memory Start:0x%lx End:0x%lx\n", + __FUNCTION__, + MmodeResvBase + MmodeResvSize, + SystemMemoryBase + SystemMemorySize + )); + AddMemoryRangeHob ( + MmodeResvBase + MmodeResvSize, + SystemMemoryBase + SystemMemorySize + ); +} diff --git a/OvmfPkg/PlatformPei/RiscV64/Platform.c b/OvmfPkg/PlatformPei/R= iscV64/Platform.c new file mode 100644 index 000000000000..45a2f44d9cca --- /dev/null +++ b/OvmfPkg/PlatformPei/RiscV64/Platform.c @@ -0,0 +1,372 @@ +/** @file + Platform PEI driver + + Copyright (c) 2019-2022, Hewlett Packard Enterprise Development LP. All = rights reserved.
+ Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2011, Andrei Warkentin + + 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 +#include +#include + +#include "Platform.h" + +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] =3D { + { EfiACPIMemoryNVS, 0x004 }, + { EfiACPIReclaimMemory, 0x008 }, + { EfiReservedMemoryType, 0x004 }, + { EfiRuntimeServicesData, 0x024 }, + { EfiRuntimeServicesCode, 0x030 }, + { EfiBootServicesCode, 0x180 }, + { EfiBootServicesData, 0xF00 }, + { EfiMaxMemoryType, 0x000 } +}; + +EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] =3D { + { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gEfiPeiMasterBootModePpiGuid, + NULL + } +}; + +STATIC EFI_BOOT_MODE mBootMode =3D BOOT_WITH_FULL_CONFIGURATION; + +/** + Build memory map I/O range resource HOB using the + base address and size. + + @param MemoryBase Memory map I/O base. + @param MemorySize Memory map I/O size. + +**/ +VOID +AddIoMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ) +{ + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + MemoryBase, + MemorySize + ); +} + +/** + Build reserved memory range resource HOB. + + @param MemoryBase Reserved memory range base address. + @param MemorySize Reserved memory range size. + +**/ +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 + ); +} + +/** + Build memory map I/O resource using the base address + and the top address of memory range. + + @param MemoryBase Memory map I/O range base address. + @param MemoryLimit The top address of memory map I/O range + +**/ +VOID +AddIoMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ) +{ + AddIoMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase)); +} + +/** + Create memory range resource HOB using the memory base + address and size. + + @param MemoryBase Memory range base address. + @param MemorySize Memory range size. + +**/ +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 resource HOB using memory base + address and top address of the memory range. + + @param MemoryBase Memory range base address. + @param MemoryLimit Memory range size. + +**/ +VOID +AddMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ) +{ + AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase)); +} + +/** + Create untested memory range resource HOB using memory base + address and top address of the memory range. + + @param MemoryBase Memory range base address. + @param MemorySize Memory range size. + +**/ +VOID +AddUntestedMemoryBaseSizeHob ( + 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, + MemoryBase, + MemorySize + ); +} + +/** + Create untested memory range resource HOB using memory base + address and top address of the memory range. + + @param MemoryBase Memory range base address. + @param MemoryLimit Memory range size. + +**/ +VOID +AddUntestedMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ) +{ + AddUntestedMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryB= ase)); +} + +/** + Add PCI resource. + +**/ +VOID +AddPciResource ( + VOID + ) +{ + // + // Platform-specific + // +} + +/** + Platform memory map initialization. + +**/ +VOID +MemMapInitialization ( + VOID + ) +{ + // + // Create Memory Type Information HOB + // + BuildGuidDataHob ( + &gEfiMemoryTypeInformationGuid, + mDefaultMemoryTypeInformation, + sizeof (mDefaultMemoryTypeInformation) + ); + + // + // Add PCI IO Port space available for PCI resource allocations. + // + AddPciResource (); +} + +/** + Platform misc initialization. + +**/ +VOID +MiscInitialization ( + VOID + ) +{ + // + // Build the CPU HOB with guest RAM size dependent address width and 16-= bits + // of IO space. (Side note: unlike other HOBs, the CPU HOB is needed dur= ing + // S3 resume as well, so we build it unconditionally.) + // + // TODO: Determine this dynamically from the platform + // setting or the HART configuration. + // + BuildCpuHob (56, 32); +} + +/** + Check if system returns from S3. + + @return BOOLEAN TRUE, system returned from S3 + FALSE, system is not returned from S3 + +**/ +BOOLEAN +CheckResumeFromS3 ( + VOID + ) +{ + // + // Platform implementation-specific + // + return FALSE; +} + +/** + Platform boot mode initialization. + +**/ +VOID +BootModeInitialization ( + VOID + ) +{ + EFI_STATUS Status; + + if (CheckResumeFromS3 ()) { + DEBUG ((DEBUG_INFO, "This is wake from S3\n")); + } else { + DEBUG ((DEBUG_INFO, "This is normal boot\n")); + } + + Status =3D PeiServicesSetBootMode (mBootMode); + ASSERT_EFI_ERROR (Status); + + Status =3D PeiServicesInstallPpi (mPpiBootMode); + ASSERT_EFI_ERROR (Status); +} + +/** + Build processor information for U54 Coreplex processor. + + @return EFI_SUCCESS Status. + +**/ +EFI_STATUS +BuildCoreInformationHob ( + VOID + ) +{ + // return BuildRiscVSmbiosHobs (); + return EFI_SUCCESS; +} + +/** + 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; + + DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n")); + Status =3D PlatformPeim (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "PlatformPeim failed\n")); + ASSERT (FALSE); + } + + BootModeInitialization (); + DEBUG ((DEBUG_INFO, "Platform BOOT mode initiated.\n")); + PublishPeiMemory (); + DEBUG ((DEBUG_INFO, "PEI memory published.\n")); + InitializeRamRegions (); + DEBUG ((DEBUG_INFO, "Platform RAM regions initiated.\n")); + + if (mBootMode !=3D BOOT_ON_S3_RESUME) { + PeiFvInitialization (); + MemMapInitialization (); + } + + MiscInitialization (); + Status =3D BuildCoreInformationHob (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Fail to build processor information HOB.\n")); + ASSERT (FALSE); + } + + return EFI_SUCCESS; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95120): https://edk2.groups.io/g/devel/message/95120 Mute This Topic: https://groups.io/mt/94300392/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 Sat May 18 17:16:06 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+95122+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+95122+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655158; cv=none; d=zohomail.com; s=zohoarc; b=LxgCKxu8/Dx+ULzyaN1PLPrRPm2QCS4vfNCJIVrWTvka7wf9ZymWilRH+GVhkeGSPtw90s93SG9IyKePZq/ym4+iBSAhh2MWDoQBz/XQgj2CluAd66gMi9JK2yzPQemiIrMAWywTcP+aFcaWW3otL1/pUQzYdgoHTBuM5rIIZv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655158; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=eE53KnPelRH+WjzpGMWGEr/xAiY73L9ILpJOuFWXycU=; b=B6zzUIPbaVQhJrkIutt05FkEwRBltYx37nOUGhEfNK2aEkjFUMxJqDMqXwMTD4EHqZBi9IIdAMBMOkUWh9VhJ4obWT1Tab0rwUJJrbjSKHBAFb5+NG/j8DqdEgPXNzsAwe0lQMSqJfNtOHcK8G+m1KjL3t6hvQHSdnnid54qklk= 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+95122+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655158322878.1796986793685; Thu, 13 Oct 2022 02:59:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HoFnYY1788612xSCP1nFMUIH; Thu, 13 Oct 2022 02:59:17 -0700 X-Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mx.groups.io with SMTP id smtpd.web08.5681.1665655156307817794 for ; Thu, 13 Oct 2022 02:59:16 -0700 X-Received: by mail-pl1-f179.google.com with SMTP id n7so1378325plp.1 for ; Thu, 13 Oct 2022 02:59:16 -0700 (PDT) X-Gm-Message-State: h3zdP7JJTHqSFyrbXogpSo8zx1787277AA= X-Google-Smtp-Source: AMsMyM5nDeriA/faBQ+WIgVyXtKX66t2+s0ECjOkJiTBZu8wHYp9jGDEvqMKo2hHQDErkdzfGTWAXw== X-Received: by 2002:a17:902:724b:b0:183:16f:fae4 with SMTP id c11-20020a170902724b00b00183016ffae4mr17314309pll.88.1665655155481; Thu, 13 Oct 2022 02:59:15 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:14 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 13/34] UefiCpuPkg/CpuTimerLib: Refactor to allow other architectures Date: Thu, 13 Oct 2022 15:28:08 +0530 Message-Id: <20221013095829.1454581-14-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655157; bh=ZhvZvJL5R0vCUI7I3nO8S5XkjncxpRsxBGbwJDxaIk4=; h=Cc:Date:From:Reply-To:Subject:To; b=DEi4usxONX7QLt7FXn7S5BDzRv/9c0VXQj6I0GW0NhI0hDME70BJLtIPrrrnouBYpDv pPTw6S7tH/ea/reJmxsw80o7ztJ8PGRWqLVUbuYRpuB4rexWPqq97f3DyDkYmJGHUpK+W N+YMOLj3rf0/fz+X0AJMZxx6C9chOrThADw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655160018100011 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Currently, CpuTimerLib library supports only X86 architecture. Refactor to allow other CPU architectures. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Sunil V L --- UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf | 6 +++--- .../Library/CpuTimerLib/{ =3D> Ia32_X64}/BaseCpuTimerLib.c | 0 UefiCpuPkg/Library/CpuTimerLib/{ =3D> Ia32_X64}/CpuTimerLib.c | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename UefiCpuPkg/Library/CpuTimerLib/{ =3D> Ia32_X64}/BaseCpuTimerLib.c (= 100%) rename UefiCpuPkg/Library/CpuTimerLib/{ =3D> Ia32_X64}/CpuTimerLib.c (100%) diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf b/UefiCpuPk= g/Library/CpuTimerLib/BaseCpuTimerLib.inf index de0648de91b5..a22457b44940 100644 --- a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf @@ -18,9 +18,9 @@ [Defines] LIBRARY_CLASS =3D TimerLib MODULE_UNI_FILE =3D BaseCpuTimerLib.uni =20 -[Sources] - CpuTimerLib.c - BaseCpuTimerLib.c +[Sources.IA32, Sources.X64] + Ia32_X64/CpuTimerLib.c + Ia32_X64/BaseCpuTimerLib.c =20 [Packages] MdePkg/MdePkg.dec diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c b/UefiCpuPkg/= Library/CpuTimerLib/Ia32_X64/BaseCpuTimerLib.c similarity index 100% rename from UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c rename to UefiCpuPkg/Library/CpuTimerLib/Ia32_X64/BaseCpuTimerLib.c diff --git a/UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c b/UefiCpuPkg/Libr= ary/CpuTimerLib/Ia32_X64/CpuTimerLib.c similarity index 100% rename from UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c rename to UefiCpuPkg/Library/CpuTimerLib/Ia32_X64/CpuTimerLib.c --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95122): https://edk2.groups.io/g/devel/message/95122 Mute This Topic: https://groups.io/mt/94300394/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 Sat May 18 17:16:06 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+95123+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+95123+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655160; cv=none; d=zohomail.com; s=zohoarc; b=IwoDLC91w8T+iRhh5Vr97sa4xpg4LbXBGpf/Siz4MmoZIHbK99AGdHUAde05k4WoC9SpGSzHvdZW8Y/zvUEZwJ/KKgruUCLHwOgt6S2yyMpDyRtdFHy0umGxFz/UkP5ff9FZA9mo3IWXFqIfmwoJK+3uO7k8Es3qQmQPq9iLdc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655160; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=KyEZ9RC2aYasxtMgAxnLLOzNnqlMaAWM6OPES5sFxUQ=; b=cm6fXNEDmXLoahqPD+5zk7+667hhbUET1mfvsuDl823bvOhQ0YpjzMv2iDdK7s9sIWExaYqU5mzJcNjz7Mi6kAX1o2CrGMKoF51Mj/Vc93qg+Tt6NNmc7AG/iEIqInDQgJLYJrHZFv9kl2+sU0vbIsYv1vZe6PYft58PCx6yKsI= 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+95123+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655160517927.3722735956383; Thu, 13 Oct 2022 02:59:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0CIDYY1788612xEUcz4KtvNd; Thu, 13 Oct 2022 02:59:20 -0700 X-Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mx.groups.io with SMTP id smtpd.web11.5668.1665655159175675521 for ; Thu, 13 Oct 2022 02:59:19 -0700 X-Received: by mail-pf1-f177.google.com with SMTP id y1so1510703pfr.3 for ; Thu, 13 Oct 2022 02:59:19 -0700 (PDT) X-Gm-Message-State: IodieukKtaZDk8roccXWfilkx1787277AA= X-Google-Smtp-Source: AMsMyM6dXgunbVK+gLySqn3QGIkbhUWrAxruGq0uOp6YqHyqCudjGb7ba6XLDQgXN3iu6njEeJhpBg== X-Received: by 2002:a63:2bd5:0:b0:434:ea9a:ace2 with SMTP id r204-20020a632bd5000000b00434ea9aace2mr29767540pgr.323.1665655158171; Thu, 13 Oct 2022 02:59:18 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:17 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 14/34] UefiCpuPkg/CpuTimerLib: Add support for RISC-V Date: Thu, 13 Oct 2022 15:28:09 +0530 Message-Id: <20221013095829.1454581-15-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655160; bh=YR2jC/NjWXrk/UW5oS777WYTmF2fknr3NC3ZMuPC4Jc=; h=Cc:Date:From:Reply-To:Subject:To; b=rZ1X9D/qWtUIJEGqvUrG0S+w7TFmjR/PpKOw1ZCbgagTcKbJzIQMKRW++kCQgTAoXQB b6t8jWOJO5fGB87Hx4xBaGiCd++0ghS10ktRTjFclexp/2LDqHEfeO6zDLj3uJenw6a2N vuTzZ6NAUe1vEYWFeuvydutgZOk9BULBllU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655162084100001 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This is mostly copied from edk2-platforms/Silicon/RISC-V/ProcessorPkg/Library/RiscVTimerLib Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Daniel Schaefer Signed-off-by: Sunil V L --- .../Library/CpuTimerLib/BaseCpuTimerLib.inf | 3 + .../Library/CpuTimerLib/RiscV64/CpuTimerLib.c | 199 ++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf b/UefiCpuPk= g/Library/CpuTimerLib/BaseCpuTimerLib.inf index a22457b44940..554ce9fe9db8 100644 --- a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf @@ -22,6 +22,9 @@ [Sources.IA32, Sources.X64] Ia32_X64/CpuTimerLib.c Ia32_X64/BaseCpuTimerLib.c =20 +[Sources.RISCV64] + RiscV64/CpuTimerLib.c + [Packages] MdePkg/MdePkg.dec UefiCpuPkg/UefiCpuPkg.dec diff --git a/UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c b/UefiCpu= Pkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c new file mode 100644 index 000000000000..9c8efc0f3530 --- /dev/null +++ b/UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c @@ -0,0 +1,199 @@ +/** @file + RISC-V instance of Timer Library. + + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + Stalls the CPU for at least the given number of ticks. + + Stalls the CPU for at least the given number of ticks. It's invoked by + MicroSecondDelay() and NanoSecondDelay(). + + @param Delay A period of time to delay in ticks. + +**/ +VOID +InternalRiscVTimerDelay ( + IN UINT32 Delay + ) +{ + UINT32 Ticks; + UINT32 Times; + + Times =3D Delay >> (RISCV_TIMER_COMPARE_BITS - 2); + Delay &=3D ((1 << (RISCV_TIMER_COMPARE_BITS - 2)) - 1); + do { + // + // The target timer count is calculated here + // + Ticks =3D RiscVReadTimer () + Delay; + Delay =3D 1 << (RISCV_TIMER_COMPARE_BITS - 2); + while (((Ticks - RiscVReadTimer ()) & (1 << (RISCV_TIMER_COMPARE_BITS = - 1))) =3D=3D 0) { + CpuPause (); + } + } while (Times-- > 0); +} + +/** + 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 + ) +{ + InternalRiscVTimerDelay ( + (UINT32)DivU64x32 ( + MultU64x32 ( + MicroSeconds, + PcdGet64 (PcdCpuCoreCrystalClockFrequency) + ), + 1000000u + ) + ); + 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 + ) +{ + InternalRiscVTimerDelay ( + (UINT32)DivU64x32 ( + MultU64x32 ( + NanoSeconds, + PcdGet64 (PcdCpuCoreCrystalClockFrequency) + ), + 1000000000u + ) + ); + return NanoSeconds; +} + +/** + Retrieves the current value of a 64-bit free running performance counter. + + Retrieves the current value of a 64-bit free running performance counter= . The + counter can either count up by 1 or count down by 1. If the physical + performance counter counts by a larger increment, then the counter values + must be translated. The properties of the counter can be retrieved from + GetPerformanceCounterProperties(). + + @return The current value of the free running performance counter. + +**/ +UINT64 +EFIAPI +GetPerformanceCounter ( + VOID + ) +{ + return (UINT64)RiscVReadTimer (); +} + +/**return + Retrieves the 64-bit frequency in Hz and the range of performance counter + values. + + If StartValue is not NULL, then the value that the performance counter s= tarts + with immediately after is it rolls over is returned in StartValue. If + EndValue is not NULL, then the value that the performance counter end wi= th + immediately before it rolls over is returned in EndValue. The 64-bit + frequency of the performance counter in Hz is always returned. If StartV= alue + is less than EndValue, then the performance counter counts up. If StartV= alue + is greater than EndValue, then the performance counter counts down. For + example, a 64-bit free running counter that counts up would have a Start= Value + of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter + that counts down would have a StartValue of 0xFFFFFF and an EndValue of = 0. + + @param StartValue The value the performance counter starts with when it + rolls over. + @param EndValue The value that the performance counter ends with bef= ore + 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 32 - 1; + } + + return PcdGet64 (PcdCpuCoreCrystalClockFrequency); +} + +/** + 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 NanoSeconds; + UINT32 Remainder; + + // + // Ticks + // Time =3D --------- x 1,000,000,000 + // Frequency + // + NanoSeconds =3D MultU64x32 (DivU64x32Remainder (Ticks, PcdGet64 (PcdCpuC= oreCrystalClockFrequency), &Remainder), 1000000000u); + + // + // Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder = * 1,000,000,000) + // will not overflow 64-bit. + // + NanoSeconds +=3D DivU64x32 (MultU64x32 ((UINT64)Remainder, 1000000000u),= PcdGet64 (PcdCpuCoreCrystalClockFrequency)); + + return NanoSeconds; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95123): https://edk2.groups.io/g/devel/message/95123 Mute This Topic: https://groups.io/mt/94300395/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 Sat May 18 17:16:06 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+95125+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+95125+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655162; cv=none; d=zohomail.com; s=zohoarc; b=WxOa7zbLUHpeTx4MzqIo+CL7FGJVV1KNpxr/xAHyvrfBxvRtZsbq8DERNxhhBhHN1/7co1W0zdjxOA9pN7bPSphg6cfu25YSvOtPvm2R7o7iM80MmvqLZth1MY4tLqYWkpk6EwmsclnimLXc2iFPfFrFRYpNYrfihTnibVEhTJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655162; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AuZjbd5uZ9KNUXVzkiUdEXVRJAcaBHrzc/wkS8sSmMY=; b=ZHAGd5IjtIw8pLGdMxFzRAeW4OgfOg+N/b23j11aHJF4nS2oWyAgVB9rXmnf1x3GwZEwerzColh0/RxFYHa3aP4yT1rtcsQATm/gEO9UYRj5zaqAj/2dVmteogtMIEA4nHqnmQuKOHd4AUpafHjy/tkHqzBtQmWPceSr40a/ZDc= 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+95125+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655162575601.4850135139383; Thu, 13 Oct 2022 02:59:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id argcYY1788612xeGCGqXcuyI; Thu, 13 Oct 2022 02:59:22 -0700 X-Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web10.5673.1665655161599786146 for ; Thu, 13 Oct 2022 02:59:21 -0700 X-Received: by mail-pf1-f170.google.com with SMTP id i3so1475113pfc.11 for ; Thu, 13 Oct 2022 02:59:21 -0700 (PDT) X-Gm-Message-State: tRHTKDatm0jML5C4tWz8P5gOx1787277AA= X-Google-Smtp-Source: AMsMyM59NOfz055KlV0C0x3zz/UIouMhITx4cIE4IAI18XkmxSdgit1Jm3AbZXOb+QDXLz0Cm0+6Gw== X-Received: by 2002:a63:1203:0:b0:43c:7fa:f306 with SMTP id h3-20020a631203000000b0043c07faf306mr29009071pgl.169.1665655160450; Thu, 13 Oct 2022 02:59:20 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:19 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 15/34] UefiCpuPkg/CpuExceptionHandlerLib: Refactor to allow other architectures Date: Thu, 13 Oct 2022 15:28:10 +0530 Message-Id: <20221013095829.1454581-16-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655162; bh=ZzmuBrVF0SLjAIgasz04+q5wQLkHVpHzStzxv+iSUec=; h=Cc:Date:From:Reply-To:Subject:To; b=h2AEa+EKITknmwCq1taQxi6V68ColIcT8hedYoXfJQ7GBMMFCG/SQZj7nDLZq3GTvtK U8t/qkwL+lfIKzdSrvF8MzuMYVOoKMZhQwp3FxMla9lJvt+7KMVl8pJ/4aGCmQFnzlC6s G7VVKuX005Fw95PV+WBsHy3ZFlTInOj5WDk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655164104100008 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Currently, the CpuExceptionHandlerLib library supports only X86. Refactor the library to allow adding other CPU architectures. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Sunil V L --- .../DxeCpuExceptionHandlerLib.inf | 14 ++++++++------ .../PeiCpuExceptionHandlerLib.inf | 8 ++++---- .../SecPeiCpuExceptionHandlerLib.inf | 12 +++++++----- .../SmmCpuExceptionHandlerLib.inf | 8 ++++---- .../Xcode5SecPeiCpuExceptionHandlerLib.inf | 6 +++--- .../{ =3D> Ia32_X64}/CpuExceptionCommon.h | 0 .../{ =3D> Ia32_X64}/CpuExceptionCommon.c | 0 .../{ =3D> Ia32_X64}/DxeException.c | 0 .../{ =3D> Ia32_X64}/PeiCpuException.c | 0 .../{ =3D> Ia32_X64}/PeiDxeSmmCpuException.c | 0 .../{ =3D> Ia32_X64}/SecPeiCpuException.c | 0 .../{ =3D> Ia32_X64}/SmmException.c | 0 12 files changed, 26 insertions(+), 22 deletions(-) rename UefiCpuPkg/Library/CpuExceptionHandlerLib/{ =3D> Ia32_X64}/CpuExcep= tionCommon.h (100%) rename UefiCpuPkg/Library/CpuExceptionHandlerLib/{ =3D> Ia32_X64}/CpuExcep= tionCommon.c (100%) rename UefiCpuPkg/Library/CpuExceptionHandlerLib/{ =3D> Ia32_X64}/DxeExcep= tion.c (100%) rename UefiCpuPkg/Library/CpuExceptionHandlerLib/{ =3D> Ia32_X64}/PeiCpuEx= ception.c (100%) rename UefiCpuPkg/Library/CpuExceptionHandlerLib/{ =3D> Ia32_X64}/PeiDxeSm= mCpuException.c (100%) rename UefiCpuPkg/Library/CpuExceptionHandlerLib/{ =3D> Ia32_X64}/SecPeiCp= uException.c (100%) rename UefiCpuPkg/Library/CpuExceptionHandlerLib/{ =3D> Ia32_X64}/SmmExcep= tion.c (100%) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandle= rLib.inf index e7a81bebdb13..ef07b05c080a 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf @@ -32,11 +32,11 @@ [Sources.X64] X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h =20 -[Sources.common] - CpuExceptionCommon.h - CpuExceptionCommon.c - PeiDxeSmmCpuException.c - DxeException.c +[Sources.IA32, Sources.X64] + Ia32_X64/CpuExceptionCommon.h + Ia32_X64/CpuExceptionCommon.c + Ia32_X64/PeiDxeSmmCpuException.c + Ia32_X64/DxeException.c =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard @@ -56,8 +56,10 @@ [LibraryClasses] SerialPortLib PrintLib SynchronizationLib - LocalApicLib PeCoffGetEntryPointLib MemoryAllocationLib DebugLib + +[LibraryClasses.IA32, LibraryClasses.X64] + LocalApicLib VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandle= rLib.inf index 7c2ec3b2db4c..7e7e1a4296de 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf @@ -33,10 +33,10 @@ [Sources.X64] X64/ArchInterruptDefs.h =20 [Sources.common] - CpuExceptionCommon.h - CpuExceptionCommon.c - PeiCpuException.c - PeiDxeSmmCpuException.c + Ia32_X64/CpuExceptionCommon.h + Ia32_X64/CpuExceptionCommon.c + Ia32_X64/PeiCpuException.c + Ia32_X64/PeiDxeSmmCpuException.c =20 [Packages] MdePkg/MdePkg.dec diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHa= ndlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException= HandlerLib.inf index 6a170286c8fc..28341abd4493 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf @@ -32,10 +32,10 @@ [Sources.X64] X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h =20 -[Sources.common] - CpuExceptionCommon.h - CpuExceptionCommon.c - SecPeiCpuException.c +[Sources.IA32, Sources.X64] + Ia32_X64/CpuExceptionCommon.h + Ia32_X64/CpuExceptionCommon.c + Ia32_X64/SecPeiCpuException.c =20 [Packages] MdePkg/MdePkg.dec @@ -46,8 +46,10 @@ [LibraryClasses] BaseLib SerialPortLib PrintLib - LocalApicLib PeCoffGetEntryPointLib + +[LibraryClasses.IA32, LibraryClasses.X64] + LocalApicLib VmgExitLib =20 [Pcd] diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandle= rLib.inf index 9dde07612a04..b7f395f45ab4 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf @@ -33,10 +33,10 @@ [Sources.X64] X64/ArchInterruptDefs.h =20 [Sources.common] - CpuExceptionCommon.h - CpuExceptionCommon.c - PeiDxeSmmCpuException.c - SmmException.c + Ia32_X64/CpuExceptionCommon.h + Ia32_X64/CpuExceptionCommon.c + Ia32_X64/PeiDxeSmmCpuException.c + Ia32_X64/SmmException.c =20 [Packages] MdePkg/MdePkg.dec diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExcep= tionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPei= CpuExceptionHandlerLib.inf index 6d2f66504a5b..7830b3e6663f 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHan= dlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHan= dlerLib.inf @@ -38,9 +38,9 @@ [Sources.X64] X64/ArchInterruptDefs.h =20 [Sources.common] - CpuExceptionCommon.h - CpuExceptionCommon.c - SecPeiCpuException.c + Ia32_X64/CpuExceptionCommon.h + Ia32_X64/CpuExceptionCommon.c + Ia32_X64/SecPeiCpuException.c =20 [Packages] MdePkg/MdePkg.dec diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/CpuExceptionCommon.h similarity index 100% rename from UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h rename to UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/CpuExceptionCo= mmon.h diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/CpuExceptionCommon.c similarity index 100% rename from UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c rename to UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/CpuExceptionCo= mmon.c diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c b/Uef= iCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/DxeException.c similarity index 100% rename from UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c rename to UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/DxeException.c diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c b/= UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/PeiCpuException.c similarity index 100% rename from UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c rename to UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/PeiCpuExceptio= n.c diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuExceptio= n.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/PeiDxeSmmCpuExcept= ion.c similarity index 100% rename from UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException= .c rename to UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/PeiDxeSmmCpuEx= ception.c diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/SecPeiCpuException.c similarity index 100% rename from UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c rename to UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/SecPeiCpuExcep= tion.c diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c b/Uef= iCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/SmmException.c similarity index 100% rename from UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c rename to UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32_X64/SmmException.c --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95125): https://edk2.groups.io/g/devel/message/95125 Mute This Topic: https://groups.io/mt/94300397/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 Sat May 18 17:16:06 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+95126+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+95126+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655164; cv=none; d=zohomail.com; s=zohoarc; b=Dajwlj3sB2H4Nc6fXrkWZL3HHlMqAED1KFEu7aq7Bj9olW0ty9d+mXjaMJSGhRUboG6lqrkvVnDihvP1bR+xgc6Q+dS/Kdfhyybo4XYmj7Yf0v1HQqWcqMGMyDG4ocL/PrMotoGzixl4CzyKjLFX/E0851rePWEqPsVNdI12c2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655164; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=4ATEU3DB9MWuA5Uno3D2f6wZhwPdakGihoohkD1u6C4=; b=na/lyGdriZxB6HdC2bqaJSbmaljgfUteejy6wyUG1+gqpakk2I/qgTn+QYEQrWjUa55Th8Hrg0i0poa2xI30C1a2E1TdXaVAa0VKzXJC7b/KEI5BQk7vHLWJkMYtPJC/bb074xCopgupOYO1DNMUYVFFkIvkQ39NovFWqt8wAgQ= 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+95126+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655164957843.6428323431495; Thu, 13 Oct 2022 02:59:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eegyYY1788612xOaOdmsMUhG; Thu, 13 Oct 2022 02:59:24 -0700 X-Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mx.groups.io with SMTP id smtpd.web09.5763.1665655163846146805 for ; Thu, 13 Oct 2022 02:59:23 -0700 X-Received: by mail-pf1-f171.google.com with SMTP id d10so1499550pfh.6 for ; Thu, 13 Oct 2022 02:59:23 -0700 (PDT) X-Gm-Message-State: RTaCJoLMeKtrgQexIgDvQWdox1787277AA= X-Google-Smtp-Source: AMsMyM5RH4/UeD2qzp9RTGWNwRIKIaA56+/V+0dIr3Tj/oD+osYxir5yCAJEteq0M0GyG8Yj3voHuA== X-Received: by 2002:a63:5b05:0:b0:460:a6a:ec38 with SMTP id p5-20020a635b05000000b004600a6aec38mr23207014pgb.485.1665655163045; Thu, 13 Oct 2022 02:59:23 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:22 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 16/34] UefiCpuPkg/CpuExceptionHandlerLib: Add support for RISC-V Date: Thu, 13 Oct 2022 15:28:11 +0530 Message-Id: <20221013095829.1454581-17-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655164; bh=xxyqVg74D1ThMN/YQkJE10KXkpzpEUFP1QY6ZB9TPG4=; h=Cc:Date:From:Reply-To:Subject:To; b=l+ss8NwitIq4VWCqjwIYA0y9jCP2PHrbBl1qLYW1OBTDsl2or7iU3w+Ll/kTk8b8Uu4 BCzXwEr6a3NdGJtNwmBos9eQ7PLeVEtpUWyh3pneSgMYNSdid4YG3Hz/iOV8hQo+Acl4D iIK45yarSv9Qpjrq91i2QUgMEcmLK72wkFQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655166115100013 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Daniel Schaefer Signed-off-by: Sunil V L --- .../DxeCpuExceptionHandlerLib.inf | 7 +- .../SecPeiCpuExceptionHandlerLib.inf | 7 +- .../RiscV64/CpuExceptionHandlerLib.h | 116 +++++++++++++++ .../RiscV64/CpuExceptionHandlerLib.c | 133 ++++++++++++++++++ .../RiscV64/SupervisorTrapHandler.S | 105 ++++++++++++++ 5 files changed, 366 insertions(+), 2 deletions(-) create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuEx= ceptionHandlerLib.h create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuEx= ceptionHandlerLib.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/Super= visorTrapHandler.S diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandle= rLib.inf index ef07b05c080a..b689e7af56e7 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf @@ -18,7 +18,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 +# VALID_ARCHITECTURES =3D IA32 X64 RISCV64 # =20 [Sources.Ia32] @@ -38,6 +38,11 @@ [Sources.IA32, Sources.X64] Ia32_X64/PeiDxeSmmCpuException.c Ia32_X64/DxeException.c =20 +[Sources.RISCV64] + RiscV64/SupervisorTrapHandler.S + RiscV64/CpuExceptionHandlerLib.c + RiscV64/CpuExceptionHandlerLib.h + [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHa= ndlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException= HandlerLib.inf index 28341abd4493..b490ef5aff8a 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf @@ -18,7 +18,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 +# VALID_ARCHITECTURES =3D IA32 X64 RISCV64 # =20 [Sources.Ia32] @@ -37,6 +37,11 @@ [Sources.IA32, Sources.X64] Ia32_X64/CpuExceptionCommon.c Ia32_X64/SecPeiCpuException.c =20 +[Sources.RISCV64] + RiscV64/SupervisorTrapHandler.S + RiscV64/CpuExceptionHandlerLib.c + RiscV64/CpuExceptionHandlerLib.h + [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuException= HandlerLib.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExcepti= onHandlerLib.h new file mode 100644 index 000000000000..30f47e87552b --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandler= Lib.h @@ -0,0 +1,116 @@ +/** @file + + RISC-V Exception Handler library definition file. + + Copyright (c) 2019-2022, Hewlett Packard Enterprise Development LP. All = rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef RISCV_CPU_EXECPTION_HANDLER_LIB_H_ +#define RISCV_CPU_EXECPTION_HANDLER_LIB_H_ + +#include + +/** + Trap Handler for S-mode + +**/ +VOID +SupervisorModeTrap ( + VOID + ); + +// +// Index of SMode trap register +// +#define SMODE_TRAP_REGS_zero 0 +#define SMODE_TRAP_REGS_ra 1 +#define SMODE_TRAP_REGS_sp 2 +#define SMODE_TRAP_REGS_gp 3 +#define SMODE_TRAP_REGS_tp 4 +#define SMODE_TRAP_REGS_t0 5 +#define SMODE_TRAP_REGS_t1 6 +#define SMODE_TRAP_REGS_t2 7 +#define SMODE_TRAP_REGS_s0 8 +#define SMODE_TRAP_REGS_s1 9 +#define SMODE_TRAP_REGS_a0 10 +#define SMODE_TRAP_REGS_a1 11 +#define SMODE_TRAP_REGS_a2 12 +#define SMODE_TRAP_REGS_a3 13 +#define SMODE_TRAP_REGS_a4 14 +#define SMODE_TRAP_REGS_a5 15 +#define SMODE_TRAP_REGS_a6 16 +#define SMODE_TRAP_REGS_a7 17 +#define SMODE_TRAP_REGS_s2 18 +#define SMODE_TRAP_REGS_s3 19 +#define SMODE_TRAP_REGS_s4 20 +#define SMODE_TRAP_REGS_s5 21 +#define SMODE_TRAP_REGS_s6 22 +#define SMODE_TRAP_REGS_s7 23 +#define SMODE_TRAP_REGS_s8 24 +#define SMODE_TRAP_REGS_s9 25 +#define SMODE_TRAP_REGS_s10 26 +#define SMODE_TRAP_REGS_s11 27 +#define SMODE_TRAP_REGS_t3 28 +#define SMODE_TRAP_REGS_t4 29 +#define SMODE_TRAP_REGS_t5 30 +#define SMODE_TRAP_REGS_t6 31 +#define SMODE_TRAP_REGS_sepc 32 +#define SMODE_TRAP_REGS_sstatus 33 +#define SMODE_TRAP_REGS_sie 34 +#define SMODE_TRAP_REGS_last 35 + +#define SMODE_TRAP_REGS_OFFSET(x) ((SMODE_TRAP_REGS_##x) * __SIZEOF_POINT= ER__) +#define SMODE_TRAP_REGS_SIZE SMODE_TRAP_REGS_OFFSET(last) + +#pragma pack(1) +typedef struct { + // + // Below are follow the format of EFI_SYSTEM_CONTEXT + // + UINT64 zero; + UINT64 ra; + UINT64 sp; + UINT64 gp; + UINT64 tp; + UINT64 t0; + UINT64 t1; + UINT64 t2; + UINT64 s0; + UINT64 s1; + UINT64 a0; + UINT64 a1; + UINT64 a2; + UINT64 a3; + UINT64 a4; + UINT64 a5; + UINT64 a6; + UINT64 a7; + UINT64 s2; + UINT64 s3; + UINT64 s4; + UINT64 s5; + UINT64 s6; + UINT64 s7; + UINT64 s8; + UINT64 s9; + UINT64 s10; + UINT64 s11; + UINT64 t3; + UINT64 t4; + UINT64 t5; + UINT64 t6; + // + // Below are the additional information to + // EFI_SYSTEM_CONTEXT, private to supervisor mode trap + // and not public to EFI environment. + // + UINT64 sepc; + UINT64 sstatus; + UINT64 sie; +} SMODE_TRAP_REGISTERS; +#pragma pack() + +#endif diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuException= HandlerLib.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExcepti= onHandlerLib.c new file mode 100644 index 000000000000..f1ee7d236aec --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandler= Lib.c @@ -0,0 +1,133 @@ +/** @file + RISC-V Exception Handler library implementation. + + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +#include "CpuExceptionHandlerLib.h" + +STATIC EFI_CPU_INTERRUPT_HANDLER mInterruptHandlers[2]; + +/** + 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 + ) +{ + RiscVSetSupervisorStvec ((UINT64)SupervisorModeTrap); + return EFI_SUCCESS; +} + +/** + Registers a function to be called from the processor interrupt 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. + NOTE: This function should be invoked after InitializeCpuExceptionHandle= rs() or + InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED retu= rned. + + @param[in] InterruptType Defines which interrupt or exception to ho= ok. + @param[in] InterruptHandler A pointer to a function of type EFI_CPU_IN= TERRUPT_HANDLER that is called + when a processor interrupt occurs. If this= parameter 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, + or this function is not supported. +**/ +EFI_STATUS +EFIAPI +RegisterCpuInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ) +{ + DEBUG ((DEBUG_INFO, "%a: Type:%x Handler: %x\n", __FUNCTION__, Interrupt= Type, InterruptHandler)); + mInterruptHandlers[InterruptType] =3D InterruptHandler; + 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; +} + +/** + Supervisor mode trap handler. + + @param[in] SmodeTrapReg Registers before trap occurred. + +**/ +VOID +RiscVSupervisorModeTrapHandler ( + SMODE_TRAP_REGISTERS *SmodeTrapReg + ) +{ + UINTN SCause; + EFI_SYSTEM_CONTEXT RiscVSystemContext; + + RiscVSystemContext.SystemContextRiscV64 =3D (EFI_SYSTEM_CONTEXT_RISCV64 = *)SmodeTrapReg; + // + // Check scasue register. + // + SCause =3D (UINTN)RiscVGetSupervisorTrapCause (); + if ((SCause & (1UL << (sizeof (UINTN) * 8- 1))) !=3D 0) { + // + // This is interrupt event. + // + SCause &=3D ~(1UL << (sizeof (UINTN) * 8- 1)); + if ((SCause =3D=3D IRQ_S_TIMER) && (mInterruptHandlers[EXCEPT_RISCV_TI= MER_INT] !=3D NULL)) { + mInterruptHandlers[EXCEPT_RISCV_TIMER_INT](EXCEPT_RISCV_TIMER_INT, R= iscVSystemContext); + } + } +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorTr= apHandler.S b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorT= rapHandler.S new file mode 100644 index 000000000000..649c4c5becf4 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorTrapHandl= er.S @@ -0,0 +1,105 @@ +/** @file + RISC-V Processor supervisor mode trap handler + + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include "CpuExceptionHandlerLib.h" + + .align 3 + .section .entry, "ax", %progbits + .globl SupervisorModeTrap +SupervisorModeTrap: + addi sp, sp, -SMODE_TRAP_REGS_SIZE + + /* Save all general regisers except SP */ + sd t0, SMODE_TRAP_REGS_OFFSET(t0)(sp) + + csrr t0, CSR_SSTATUS + and t0, t0, (SSTATUS_SIE | SSTATUS_SPIE) + sd t0, SMODE_TRAP_REGS_OFFSET(sstatus)(sp) + csrr t0, CSR_SEPC + sd t0, SMODE_TRAP_REGS_OFFSET(sepc)(sp) + csrr t0, CSR_SIE + sd t0, SMODE_TRAP_REGS_OFFSET(sie)(sp) + ld t0, SMODE_TRAP_REGS_OFFSET(t0)(sp) + + sd ra, SMODE_TRAP_REGS_OFFSET(ra)(sp) + sd gp, SMODE_TRAP_REGS_OFFSET(gp)(sp) + sd tp, SMODE_TRAP_REGS_OFFSET(tp)(sp) + sd t1, SMODE_TRAP_REGS_OFFSET(t1)(sp) + sd t2, SMODE_TRAP_REGS_OFFSET(t2)(sp) + sd s0, SMODE_TRAP_REGS_OFFSET(s0)(sp) + sd s1, SMODE_TRAP_REGS_OFFSET(s1)(sp) + sd a0, SMODE_TRAP_REGS_OFFSET(a0)(sp) + sd a1, SMODE_TRAP_REGS_OFFSET(a1)(sp) + sd a2, SMODE_TRAP_REGS_OFFSET(a2)(sp) + sd a3, SMODE_TRAP_REGS_OFFSET(a3)(sp) + sd a4, SMODE_TRAP_REGS_OFFSET(a4)(sp) + sd a5, SMODE_TRAP_REGS_OFFSET(a5)(sp) + sd a6, SMODE_TRAP_REGS_OFFSET(a6)(sp) + sd a7, SMODE_TRAP_REGS_OFFSET(a7)(sp) + sd s2, SMODE_TRAP_REGS_OFFSET(s2)(sp) + sd s3, SMODE_TRAP_REGS_OFFSET(s3)(sp) + sd s4, SMODE_TRAP_REGS_OFFSET(s4)(sp) + sd s5, SMODE_TRAP_REGS_OFFSET(s5)(sp) + sd s6, SMODE_TRAP_REGS_OFFSET(s6)(sp) + sd s7, SMODE_TRAP_REGS_OFFSET(s7)(sp) + sd s8, SMODE_TRAP_REGS_OFFSET(s8)(sp) + sd s9, SMODE_TRAP_REGS_OFFSET(s9)(sp) + sd s10, SMODE_TRAP_REGS_OFFSET(s10)(sp) + sd s11, SMODE_TRAP_REGS_OFFSET(s11)(sp) + sd t3, SMODE_TRAP_REGS_OFFSET(t3)(sp) + sd t4, SMODE_TRAP_REGS_OFFSET(t4)(sp) + sd t5, SMODE_TRAP_REGS_OFFSET(t5)(sp) + sd t6, SMODE_TRAP_REGS_OFFSET(t6)(sp) + + /* Call to Supervisor mode trap handler in CpuExceptionHandlerLib.c */ + call RiscVSupervisorModeTrapHandler + + /* Restore all general regisers except SP */ + ld ra, SMODE_TRAP_REGS_OFFSET(ra)(sp) + ld gp, SMODE_TRAP_REGS_OFFSET(gp)(sp) + ld tp, SMODE_TRAP_REGS_OFFSET(tp)(sp) + ld t2, SMODE_TRAP_REGS_OFFSET(t2)(sp) + ld s0, SMODE_TRAP_REGS_OFFSET(s0)(sp) + ld s1, SMODE_TRAP_REGS_OFFSET(s1)(sp) + ld a0, SMODE_TRAP_REGS_OFFSET(a0)(sp) + ld a1, SMODE_TRAP_REGS_OFFSET(a1)(sp) + ld a2, SMODE_TRAP_REGS_OFFSET(a2)(sp) + ld a3, SMODE_TRAP_REGS_OFFSET(a3)(sp) + ld a4, SMODE_TRAP_REGS_OFFSET(a4)(sp) + ld a5, SMODE_TRAP_REGS_OFFSET(a5)(sp) + ld a6, SMODE_TRAP_REGS_OFFSET(a6)(sp) + ld a7, SMODE_TRAP_REGS_OFFSET(a7)(sp) + ld s2, SMODE_TRAP_REGS_OFFSET(s2)(sp) + ld s3, SMODE_TRAP_REGS_OFFSET(s3)(sp) + ld s4, SMODE_TRAP_REGS_OFFSET(s4)(sp) + ld s5, SMODE_TRAP_REGS_OFFSET(s5)(sp) + ld s6, SMODE_TRAP_REGS_OFFSET(s6)(sp) + ld s7, SMODE_TRAP_REGS_OFFSET(s7)(sp) + ld s8, SMODE_TRAP_REGS_OFFSET(s8)(sp) + ld s9, SMODE_TRAP_REGS_OFFSET(s9)(sp) + ld s10, SMODE_TRAP_REGS_OFFSET(s10)(sp) + ld s11, SMODE_TRAP_REGS_OFFSET(s11)(sp) + ld t3, SMODE_TRAP_REGS_OFFSET(t3)(sp) + ld t4, SMODE_TRAP_REGS_OFFSET(t4)(sp) + ld t5, SMODE_TRAP_REGS_OFFSET(t5)(sp) + ld t6, SMODE_TRAP_REGS_OFFSET(t6)(sp) + + ld t0, SMODE_TRAP_REGS_OFFSET(sepc)(sp) + csrw CSR_SEPC, t0 + ld t0, SMODE_TRAP_REGS_OFFSET(sie)(sp) + csrw CSR_SIE, t0 + csrr t0, CSR_SSTATUS + ld t1, SMODE_TRAP_REGS_OFFSET(sstatus)(sp) + or t0, t0, t1 + csrw CSR_SSTATUS, t0 + ld t1, SMODE_TRAP_REGS_OFFSET(t1)(sp) + ld t0, SMODE_TRAP_REGS_OFFSET(t0)(sp) + addi sp, sp, SMODE_TRAP_REGS_SIZE + sret --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95126): https://edk2.groups.io/g/devel/message/95126 Mute This Topic: https://groups.io/mt/94300398/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 Sat May 18 17:16:06 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+95127+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+95127+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655167; cv=none; d=zohomail.com; s=zohoarc; b=h9BHVheyrVmn6WeKFoIYphOgPBitz5DIS819NaKnM532WXS+mEt6UVgfgTlF17OPGh+d9JH1Kq8rLc46TTJWmmBEzXa9YL9rp7r7rGgvHDK0eWdx9S1nwfsdsm3bjldwOHGNS55pylRwwlhGmBLJJKwPb5D2DLwJINjtjtjdY1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655167; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=pOBBhYhHnKr0M2eTtFD8s12uROyfWxsnGrsyS9UaoMk=; b=Hi/ECk6l4/EAnCf+oRrZkeZsgRF+MAPg/QOI0BYs9tUgYn0MOct4LYvVIKrcd1n1YVFklib8YODyZc3qttY2FnlgCp/1UEabHZoMVusuwQBWYUlsyx8DyCvce/8LMyyIENADvObwnyA8CgOLvwuaNvCVlEx5ypW9CNVoY1acZTo= 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+95127+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 166565516790095.5414674668699; Thu, 13 Oct 2022 02:59:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id xgGaYY1788612xQm7J7nejsO; Thu, 13 Oct 2022 02:59:27 -0700 X-Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mx.groups.io with SMTP id smtpd.web10.5675.1665655166677540610 for ; Thu, 13 Oct 2022 02:59:26 -0700 X-Received: by mail-pl1-f177.google.com with SMTP id c24so1370926plo.3 for ; Thu, 13 Oct 2022 02:59:26 -0700 (PDT) X-Gm-Message-State: liPOTen3ebeSnidT1GeJjvMtx1787277AA= X-Google-Smtp-Source: AMsMyM47AjbrEcw7RmRmfSymPRks1hkherCMmGdOCN9PMscXcYeeL9Z5s3+JdjSlFtfpgRU7p3EADQ== X-Received: by 2002:a17:902:d544:b0:17d:318a:adf7 with SMTP id z4-20020a170902d54400b0017d318aadf7mr34521457plf.148.1665655165947; Thu, 13 Oct 2022 02:59:25 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:25 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 17/34] UefiCpuPkg/CpuDxe: Refactor to allow other architectures Date: Thu, 13 Oct 2022 15:28:12 +0530 Message-Id: <20221013095829.1454581-18-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655167; bh=ZyncN6nVdFo2q1g8GcYRHKeeEtqvyhAqJjrsBLs63+M=; h=Cc:Date:From:Reply-To:Subject:To; b=IgfcOqM1DFKTmDwqnTfiCNz2tIf5i/WWpzpxg1/m8QJU/hRy6A1C/SuboVEU4b77omp tqkTg12hw2FOXG37iKpsbiA25pxwWG27KuUfIXoE5HdATcxVnUaT5ARFIWExtOd+j3R01 /zCVLathtuYsxIqq4aSnc4MvcPYCXmosnpo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655170101100002 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Currently, CpuDxe supports only X86 architecture. To add support for other architectures like RISC-V, this need to be refactored. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Sunil V L --- UefiCpuPkg/CpuDxe/CpuDxe.inf | 28 ++++++++++--------- UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuDxe.h | 0 UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuGdt.h | 0 UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuMp.h | 0 .../CpuDxe/{ =3D> Ia32_X64}/CpuPageTable.h | 0 UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuDxe.c | 0 UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuGdt.c | 0 UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuMp.c | 0 .../CpuDxe/{ =3D> Ia32_X64}/CpuPageTable.c | 0 9 files changed, 15 insertions(+), 13 deletions(-) rename UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuDxe.h (100%) rename UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuGdt.h (100%) rename UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuMp.h (100%) rename UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuPageTable.h (100%) rename UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuDxe.c (100%) rename UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuGdt.c (100%) rename UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuMp.c (100%) rename UefiCpuPkg/CpuDxe/{ =3D> Ia32_X64}/CpuPageTable.c (100%) diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf index 235241899222..069a7f2933bd 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.inf +++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf @@ -29,28 +29,30 @@ [LibraryClasses] DebugLib DxeServicesTableLib MemoryAllocationLib - MtrrLib UefiBootServicesTableLib UefiDriverEntryPoint - LocalApicLib - UefiCpuLib UefiLib CpuExceptionHandlerLib HobLib ReportStatusCodeLib - MpInitLib TimerLib PeCoffGetEntryPointLib =20 -[Sources] - CpuDxe.c - CpuDxe.h - CpuGdt.c - CpuGdt.h - CpuMp.c - CpuMp.h - CpuPageTable.h - CpuPageTable.c +[LibraryClasses.IA32, LibraryClasses.X64] + LocalApicLib + MpInitLib + MtrrLib + UefiCpuLib + +[Sources.IA32, Sources.X64] + Ia32_X64/CpuDxe.c + Ia32_X64/CpuDxe.h + Ia32_X64/CpuGdt.c + Ia32_X64/CpuGdt.h + Ia32_X64/CpuMp.c + Ia32_X64/CpuMp.h + Ia32_X64/CpuPageTable.h + Ia32_X64/CpuPageTable.c =20 [Sources.IA32] Ia32/CpuAsm.nasm diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/Ia32_X64/CpuDxe= .h similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuDxe.h rename to UefiCpuPkg/CpuDxe/Ia32_X64/CpuDxe.h diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.h b/UefiCpuPkg/CpuDxe/Ia32_X64/CpuGdt= .h similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuGdt.h rename to UefiCpuPkg/CpuDxe/Ia32_X64/CpuGdt.h diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/Ia32_X64/CpuMp.h similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuMp.h rename to UefiCpuPkg/CpuDxe/Ia32_X64/CpuMp.h diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.h b/UefiCpuPkg/CpuDxe/Ia32_X64/= CpuPageTable.h similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuPageTable.h rename to UefiCpuPkg/CpuDxe/Ia32_X64/CpuPageTable.h diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/Ia32_X64/CpuDxe= .c similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuDxe.c rename to UefiCpuPkg/CpuDxe/Ia32_X64/CpuDxe.c diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/Ia32_X64/CpuGdt= .c similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuGdt.c rename to UefiCpuPkg/CpuDxe/Ia32_X64/CpuGdt.c diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/Ia32_X64/CpuMp.c similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuMp.c rename to UefiCpuPkg/CpuDxe/Ia32_X64/CpuMp.c diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c b/UefiCpuPkg/CpuDxe/Ia32_X64/= CpuPageTable.c similarity index 100% rename from UefiCpuPkg/CpuDxe/CpuPageTable.c rename to UefiCpuPkg/CpuDxe/Ia32_X64/CpuPageTable.c --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95127): https://edk2.groups.io/g/devel/message/95127 Mute This Topic: https://groups.io/mt/94300400/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 Sat May 18 17:16:06 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+95128+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+95128+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655172; cv=none; d=zohomail.com; s=zohoarc; b=gdVuaoPpwcGT4Wu7IRu0bPECmI6KMAQXIjqM8G5NmBKpLx2EX0Nm/slLLfZF8HJOjcrPYPVJ7SCItoriCVx9TClWDXvdEFCr6CtBg4dJWX4FP2EwWt3Ke40d9Q4ATM4n7jAPTioLPi0gsHV/QnQ6cJXvmBu3DoDRQW/oY0SleX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655172; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=u3txRcs5Z8Bw396/BelOcB5i208wK4CLuFUa+gLudCo=; b=TmEdrs2Mbj22jNO7VQ+hDakIhJDlOn5jt0Jg+EP9g/8kspp2iTrq6UuUve4Gc9lT+BOzx6oXLtCGzO7eU9qqrmMHI/kXs/sPrObFVocv9zs50f7ZL3oZHcOuWyH/wKmfWhiljr4FvW09xGAha2Wf36OlhNNPBhDs5ep7hkEgNUc= 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+95128+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655172632613.9205296313422; Thu, 13 Oct 2022 02:59:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 187dYY1788612xB7wAH7Ew9b; Thu, 13 Oct 2022 02:59:32 -0700 X-Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mx.groups.io with SMTP id smtpd.web10.5678.1665655171474776152 for ; Thu, 13 Oct 2022 02:59:31 -0700 X-Received: by mail-pj1-f51.google.com with SMTP id x1-20020a17090ab00100b001fda21bbc90so4449580pjq.3 for ; Thu, 13 Oct 2022 02:59:31 -0700 (PDT) X-Gm-Message-State: wVlUrGEqNx9YXkhlaA027Ki5x1787277AA= X-Google-Smtp-Source: AMsMyM6cAEKj3y6MnaFV3rFI0aY2CxJRytYAzP1ZZPEK1ntf90FWnsTuAgR2/pdnVK1WGY5rooaNOQ== X-Received: by 2002:a17:90b:3502:b0:20c:e1ce:46d6 with SMTP id ls2-20020a17090b350200b0020ce1ce46d6mr10268354pjb.94.1665655170378; Thu, 13 Oct 2022 02:59:30 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:28 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 18/34] UefiCpuPkg/CpuDxe: Add support for RISC-V Date: Thu, 13 Oct 2022 15:28:13 +0530 Message-Id: <20221013095829.1454581-19-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655172; bh=oBr4OU+g6OJp9lHstPqM046FssKLmXlmIJclxgs6Gz8=; h=Cc:Date:From:Reply-To:Subject:To; b=liKqsFR55ZxbL1d9j3WWbWgwDDuZug2jYqXzoDiK1TYJXzCTPyhfuEBffQ1eECXTEBE sqn5OtUacDbPco025zjNr5IrARSYxLJtxeF4RHiAtMMcfXt3g3FwEo5tBdMErIOboqm6X 7g9G4Tt2B4MS7GMbs0Yc2Ynlm+ZYDF6hlaM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655174115100001 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This is migrated from edk2-platforms/Silicon/RISC-V/ProcessorPkg/Universal/CpuDxe Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Daniel Schaefer Signed-off-by: Sunil V L --- UefiCpuPkg/CpuDxe/CpuDxe.inf | 11 ++ UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h | 199 +++++++++++++++++++ UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c | 307 +++++++++++++++++++++++++++++ 3 files changed, 517 insertions(+) create mode 100644 UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h create mode 100644 UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf index 069a7f2933bd..5a6ead3bfbb6 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.inf +++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf @@ -44,6 +44,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] MtrrLib UefiCpuLib =20 +[LibraryClasses.RISCV64] + RiscVSbiLib + [Sources.IA32, Sources.X64] Ia32_X64/CpuDxe.c Ia32_X64/CpuDxe.h @@ -62,11 +65,18 @@ [Sources.X64] X64/CpuAsm.nasm X64/PagingAttribute.c =20 +[Sources.RISCV64] + RiscV64/CpuDxe.c + RiscV64/CpuDxe.h + [Protocols] gEfiCpuArchProtocolGuid ## PRODUCES gEfiMpServiceProtocolGuid ## PRODUCES gEfiSmmBase2ProtocolGuid ## SOMETIMES_CONSUMES =20 +[Protocols.RISCV64] + gRiscVEfiBootProtocolGuid ## PRODUCES + [Guids] gIdleLoopEventGuid ## CONSUMES ## E= vent gEfiVectorHandoffTableGuid ## SOMETIMES_CONSUMES ## S= ystemTable @@ -83,6 +93,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList ##= CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask ##= CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ##= CONSUMES =20 [Depex] TRUE diff --git a/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h b/UefiCpuPkg/CpuDxe/RiscV64= /CpuDxe.h new file mode 100644 index 000000000000..49f4e119665a --- /dev/null +++ b/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h @@ -0,0 +1,199 @@ +/** @file + RISC-V CPU DXE module header file. + + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. Al= l 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 + +/** + Flush CPU data cache. If the instruction cache is fully coherent + with all DMA operations then function can just return EFI_SUCCESS. + + @param This Protocol instance structure + @param Start Physical address to start flushing from. + @param Length Number of bytes to flush. Round up to chipset + granularity. + @param FlushType Specifies the type of flush operation to perfo= rm. + + @retval EFI_SUCCESS If cache was flushed + @retval EFI_UNSUPPORTED If flush type is not supported. + @retval EFI_DEVICE_ERROR If requested range could not be flushed. + +**/ +EFI_STATUS +EFIAPI +CpuFlushCpuDataCache ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_CPU_FLUSH_TYPE FlushType + ); + +/** + Enables CPU interrupts. + + @param This Protocol instance structure + + @retval EFI_SUCCESS If interrupts were enabled in the CPU + @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU. + +**/ +EFI_STATUS +EFIAPI +CpuEnableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ); + +/** + Disables CPU interrupts. + + @param This Protocol instance structure + + @retval EFI_SUCCESS If interrupts were disabled in the CPU. + @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU. + +**/ +EFI_STATUS +EFIAPI +CpuDisableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ); + +/** + Return the state of interrupts. + + @param This Protocol instance structure + @param State Pointer to the CPU's current interrupt st= ate + + @retval EFI_SUCCESS If interrupts were disabled in the CPU. + @retval EFI_INVALID_PARAMETER State is NULL. + +**/ +EFI_STATUS +EFIAPI +CpuGetInterruptState ( + IN EFI_CPU_ARCH_PROTOCOL *This, + OUT BOOLEAN *State + ); + +/** + Generates an INIT to the CPU. + + @param This Protocol instance structure + @param InitType Type of CPU INIT to perform + + @retval EFI_SUCCESS If CPU INIT occurred. This value should never = be + seen. + @retval EFI_DEVICE_ERROR If CPU INIT failed. + @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported. + +**/ +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 + ); + +/** + Set memory cacheability attributes for given range of memeory. + + @param This Protocol instance structure + @param BaseAddress Specifies the start address of the + memory range + @param Length Specifies the length of the memory range + @param Attributes The memory cacheability for the memory ra= nge + + @retval EFI_SUCCESS If the cacheability of that memory range = is + set successfully + @retval EFI_UNSUPPORTED If the desired operation cannot be done + @retval EFI_INVALID_PARAMETER The input parameter is not correct, + such as Length =3D 0 + +**/ +EFI_STATUS +EFIAPI +CpuSetMemoryAttributes ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ); + +#endif diff --git a/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c b/UefiCpuPkg/CpuDxe/RiscV64= /CpuDxe.c new file mode 100644 index 000000000000..9f557b776a09 --- /dev/null +++ b/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c @@ -0,0 +1,307 @@ +/** @file + RISC-V CPU DXE driver. + + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "CpuDxe.h" + +// +// Global Variables +// +STATIC BOOLEAN mInterruptState =3D FALSE; +STATIC EFI_HANDLE mCpuHandle =3D NULL; + +EFI_CPU_ARCH_PROTOCOL gCpu =3D { + CpuFlushCpuDataCache, + CpuEnableInterrupt, + CpuDisableInterrupt, + CpuGetInterruptState, + CpuInit, + CpuRegisterInterruptHandler, + CpuGetTimerValue, + CpuSetMemoryAttributes, + 1, // NumberOfTimers + 4 // DmaBufferAlignment +}; + +// +// CPU Arch Protocol Functions +// + +/** + Flush CPU data cache. If the instruction cache is fully coherent + with all DMA operations then function can just return EFI_SUCCESS. + + @param This Protocol instance structure + @param Start Physical address to start flushing from. + @param Length Number of bytes to flush. Round up to chipset + granularity. + @param FlushType Specifies the type of flush operation to perfo= rm. + + @retval EFI_SUCCESS If cache was flushed + @retval EFI_UNSUPPORTED If flush type is not supported. + @retval EFI_DEVICE_ERROR If requested range could not be flushed. + +**/ +EFI_STATUS +EFIAPI +CpuFlushCpuDataCache ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_CPU_FLUSH_TYPE FlushType + ) +{ + return EFI_SUCCESS; +} + +/** + Enables CPU interrupts. + + @param This Protocol instance structure + + @retval EFI_SUCCESS If interrupts were enabled in the CPU + @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU. + +**/ +EFI_STATUS +EFIAPI +CpuEnableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ) +{ + EnableInterrupts (); + mInterruptState =3D TRUE; + return EFI_SUCCESS; +} + +/** + Disables CPU interrupts. + + @param This Protocol instance structure + + @retval EFI_SUCCESS If interrupts were disabled in the CPU. + @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU. + +**/ +EFI_STATUS +EFIAPI +CpuDisableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ) +{ + DisableInterrupts (); + mInterruptState =3D FALSE; + return EFI_SUCCESS; +} + +/** + Return the state of interrupts. + + @param This Protocol instance structure + @param State Pointer to the CPU's current interrupt st= ate + + @retval EFI_SUCCESS If interrupts were disabled in the CPU. + @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 mInterruptState; + return EFI_SUCCESS; +} + +/** + Generates an INIT to the CPU. + + @param This Protocol instance structure + @param InitType Type of CPU INIT to perform + + @retval EFI_SUCCESS If CPU INIT occurred. This value should never = be + seen. + @retval EFI_DEVICE_ERROR If CPU INIT failed. + @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported. + +**/ +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 RegisterCpuInterruptHandler (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 + ) +{ + if (TimerValue =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (TimerIndex !=3D 0) { + return EFI_INVALID_PARAMETER; + } + + *TimerValue =3D (UINT64)RiscVReadTimer (); + if (TimerPeriod !=3D NULL) { + *TimerPeriod =3D DivU64x32 ( + 1000000000000000u, + PcdGet64 (PcdCpuCoreCrystalClockFrequency) + ); + } + + return EFI_SUCCESS; +} + +/** + Implementation of SetMemoryAttributes() service of CPU Architecture Prot= ocol. + + 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. + Attributes specified an illegal combinatio= n of attributes that + cannot be set together. + @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 + ) +{ + DEBUG ((DEBUG_INFO, "%a: Set memory attributes not supported yet\n", __F= UNCTION__)); + return EFI_SUCCESS; +} + +/** + 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 +EFIAPI +InitializeCpu ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + InitializeCpuExceptionHandlers(NULL); + + // + // Make sure interrupts are disabled + // + DisableInterrupts (); + + // + // Install CPU Architectural Protocol + // + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &mCpuHandle, + &gEfiCpuArchProtocolGuid, + &gCpu, + NULL + ); + ASSERT_EFI_ERROR (Status); + return Status; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95128): https://edk2.groups.io/g/devel/message/95128 Mute This Topic: https://groups.io/mt/94300402/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 Sat May 18 17:16:06 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+95129+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+95129+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655175; cv=none; d=zohomail.com; s=zohoarc; b=mOLXaAoaXCrI0tTZe4+A0yAbMwqgwx/fGtJ7LMjPx2RjiGx8eR2v65RMWvPJEpBCpE6Yh1b/+kBHHmFubCeeNnXwH4n41HTrRn5Gtp8YJbLWWeI3YXcktmjlG2iGX2prGPRVQvk7KUKRslw1uq24Iagf54xw/hY/Jg/SGanLrpQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655175; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Dn25KSYMy06aWo0nf6ggERnCUMs2k2lK0MmcrXGWGOQ=; b=ScVCN1GQiocv3nln/33MRZn/JmCB3Ql6WcGTYF7mxwpUZnQcrgkW2A75N5lGVZFQmvSwpGCz0hc9PoOxJfB57pfG041pI0WasKaz3hTRJFG6uO7ysC4gdsI7MYlqYUmYX7uyzoTQrORMF1Tz8e9/yCc0RBzFu/mfPYOiIkASTgs= 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+95129+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655175836845.3909571847352; Thu, 13 Oct 2022 02:59:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id LRk5YY1788612xfimaaRg8Xh; Thu, 13 Oct 2022 02:59:35 -0700 X-Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mx.groups.io with SMTP id smtpd.web10.5679.1665655174904282491 for ; Thu, 13 Oct 2022 02:59:34 -0700 X-Received: by mail-pj1-f48.google.com with SMTP id 70so1505485pjo.4 for ; Thu, 13 Oct 2022 02:59:34 -0700 (PDT) X-Gm-Message-State: LftUPhoh8gbM368WdoRx0F8px1787277AA= X-Google-Smtp-Source: AMsMyM7njfGwFGfz+tu4Nn+/S/rXib7waYySEY2ZkR9ckYflq1DBLapo9M3pyBCwWMKLQvhv0iyYzQ== X-Received: by 2002:a17:902:d50f:b0:178:6505:fae3 with SMTP id b15-20020a170902d50f00b001786505fae3mr34952300plg.54.1665655174097; Thu, 13 Oct 2022 02:59:34 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:33 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 19/34] UefiCpuPkg/CpuDxe: Add RISC-V Boot protocol support Date: Thu, 13 Oct 2022 15:28:14 +0530 Message-Id: <20221013095829.1454581-20-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655175; bh=a1YZAJDREG6JsU2B/NMQ0ZRrqpLXZwREzQq0JHR7o48=; h=Cc:Date:From:Reply-To:Subject:To; b=ktpniKg+CW09KD7Zz5E2mnRzrLsdZEHEHqI+4ussvd2azsmp6+KsTPWmctOQp4ieT4X SHT5ZZ4wni0dNH3QdRq9j5/+24xDPWsb9sq0F5wyJF5W7+6bIOdOe4sjLdZxNzIRbzblk xoXMyWiovWeiNXnIX6qbwkgqR/XtFeUj3Ms= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655176125100005 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 RISC-V UEFI platforms need to support RISCV_EFI_BOOT_PROTOCOL. Add the support for this protocol which is defined in the spec: https://github.com/riscv-non-isa/riscv-uefi/releases/download/1.0.0/RISCV_U= EFI_PROTOCOL-spec.pdf Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Daniel Schaefer Signed-off-by: Sunil V L --- UefiCpuPkg/UefiCpuPkg.dsc | 12 +++--- UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c | 66 ++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index f694b3a77c2e..6ea90507e36f 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -122,9 +122,13 @@ [Components] UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf UefiCpuPkg/MicrocodeMeasurementDxe/MicrocodeMeasurementDxe.inf - -[Components.IA32, Components.X64] UefiCpuPkg/CpuDxe/CpuDxe.inf + UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf +!if $(TOOL_CHAIN_TAG) !=3D "XCODE5" + UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.i= nf +!endif + +[Components.IA32, Components.X64] UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf { NULL|UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf @@ -141,10 +145,6 @@ [Components.IA32, Components.X64] UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf - UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf -!if $(TOOL_CHAIN_TAG) !=3D "XCODE5" - UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.i= nf -!endif UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandle= rLib.inf diff --git a/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c b/UefiCpuPkg/CpuDxe/RiscV64= /CpuDxe.c index 9f557b776a09..7551e0653603 100644 --- a/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c +++ b/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c @@ -2,6 +2,7 @@ RISC-V CPU DXE driver. =20 Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
+ Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -12,8 +13,41 @@ // // Global Variables // -STATIC BOOLEAN mInterruptState =3D FALSE; -STATIC EFI_HANDLE mCpuHandle =3D NULL; +STATIC BOOLEAN mInterruptState =3D FALSE; +STATIC EFI_HANDLE mCpuHandle =3D NULL; +STATIC UINTN mBootHartId; +RISCV_EFI_BOOT_PROTOCOL gRiscvBootProtocol; + +/** + Get the boot hartid + + @param This Protocol instance structure + @param BootHartId Pointer to the Boot Hart ID variable + + @retval EFI_SUCCESS If BootHartId is returned + @retval EFI_INVALID_PARAMETER Either "BootHartId" is NULL or "This" is = not + a valid RISCV_EFI_BOOT_PROTOCOL instance. + +**/ +EFI_STATUS +EFIAPI +RiscvGetBootHartId ( + IN RISCV_EFI_BOOT_PROTOCOL *This, + OUT UINTN *BootHartId + ) +{ + if ((This !=3D &gRiscvBootProtocol) || (BootHartId =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + *BootHartId =3D mBootHartId; + return EFI_SUCCESS; +} + +RISCV_EFI_BOOT_PROTOCOL gRiscvBootProtocol =3D { + RISCV_EFI_BOOT_PROTOCOL_LATEST_VERSION, + RiscvGetBootHartId +}; =20 EFI_CPU_ARCH_PROTOCOL gCpu =3D { CpuFlushCpuDataCache, @@ -284,15 +318,39 @@ InitializeCpu ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; + EFI_STATUS Status; + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext; =20 - InitializeCpuExceptionHandlers(NULL); + GetFirmwareContextPointer (&FirmwareContext); + ASSERT (FirmwareContext !=3D NULL); + if (FirmwareContext =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "Failed to get the pointer of EFI_RISCV_FIRMWARE_= CONTEXT\n")); + return EFI_NOT_FOUND; + } + + DEBUG ((DEBUG_INFO, " %a: Firmware Context is at 0x%x.\n", __FUNCTION__,= FirmwareContext)); + + mBootHartId =3D FirmwareContext->BootHartId; + DEBUG ((DEBUG_INFO, " %a: mBootHartId =3D 0x%x.\n", __FUNCTION__, mBootH= artId)); + + InitializeCpuExceptionHandlers (NULL); =20 // // Make sure interrupts are disabled // DisableInterrupts (); =20 + // + // Install Boot protocol + // + Status =3D gBS->InstallProtocolInterface ( + &ImageHandle, + &gRiscVEfiBootProtocolGuid, + EFI_NATIVE_INTERFACE, + &gRiscvBootProtocol + ); + ASSERT_EFI_ERROR (Status); + // // Install CPU Architectural Protocol // --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95129): https://edk2.groups.io/g/devel/message/95129 Mute This Topic: https://groups.io/mt/94300403/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 Sat May 18 17:16:06 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+95130+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+95130+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655180; cv=none; d=zohomail.com; s=zohoarc; b=G9Jr03geh++iy29kOXLCfrdSdBOGCdD8QmLIwcSYBrtmu6JVUTUxwQkswRPHTT+KRSzNrg2CEa+11GYeTYqLUgzpnv98Aa99E11/WYCeO+aszBP11t1dxbiMHQXW+vIGr+8aRF/s+b9myOZWXd1OKsNkMXGMCXq9UMOacP/zMh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655180; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=hWv2MuFYd4A3eqatf8dnoOY8DbsGfdD+dfJjUoQYBHk=; b=JOCMbnRzPi/SrKNlFTnY+auDf7mfbbrDHR+kJK/AQZne+tzketSNVEf6KzJPwqsoic9S3anJUYLTCJk0bE59GGx42KGnEUyVr8Hx6rafqMENzgfCyPn2UaZnG/R8YIEzza9IhdBJyTEU5hoaaa0h3/ebXCkjdKKB5qV7xza1aus= 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+95130+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655180173580.8230238709705; Thu, 13 Oct 2022 02:59:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ahEVYY1788612xayj79Bv3tT; Thu, 13 Oct 2022 02:59:39 -0700 X-Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mx.groups.io with SMTP id smtpd.web11.5670.1665655178481380837 for ; Thu, 13 Oct 2022 02:59:38 -0700 X-Received: by mail-pl1-f181.google.com with SMTP id l4so1344110plb.8 for ; Thu, 13 Oct 2022 02:59:38 -0700 (PDT) X-Gm-Message-State: VHhXGFJ8v3RShh75rsPQZiSFx1787277AA= X-Google-Smtp-Source: AMsMyM6uvaP753qJTnQyRCnm8WvZR58QiMNY6CION2GvVKah/H3Hj8HDijG0Y+ZrTSE0NKmAvFOXDw== X-Received: by 2002:a17:902:a508:b0:181:2875:3b09 with SMTP id s8-20020a170902a50800b0018128753b09mr26157547plq.45.1665655177698; Thu, 13 Oct 2022 02:59:37 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:36 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 20/34] UefiCpuPkg: Add CpuTimerDxe module Date: Thu, 13 Oct 2022 15:28:15 +0530 Message-Id: <20221013095829.1454581-21-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655179; bh=FGRTdf0qlxredjFgyx15xLBGh3bk7i3VaKyscFGqevE=; h=Cc:Date:From:Reply-To:Subject:To; b=EPU6g0xZDsdbD0oEvZAfTHKc/kRFRjpLjKu1fIq5EA0cWF+gEhjBvx/RNWx1FPK9/jx FXZdzo8y24ByIGl6Fi45Vkx2KNf+pdL90VLdQiMcEdWx473oDVvR1zKMNmeHRkm27lyj6 zL2wWu+8OnOlYr/PlJSZkwYnfTdk9DT5mLw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655182162100001 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This DXE module initializes the timer interrupt handler and installs the Arch Timer protocol. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Daniel Schaefer Signed-off-by: Sunil V L --- UefiCpuPkg/UefiCpuPkg.dsc | 3 + UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf | 51 ++++ UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h | 177 ++++++++++++++ UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.c | 294 +++++++++++++++++++++++ UefiCpuPkg/CpuTimerDxe/CpuTimer.uni | 15 ++ UefiCpuPkg/CpuTimerDxe/CpuTimerExtra.uni | 13 + 6 files changed, 553 insertions(+) create mode 100644 UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf create mode 100644 UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h create mode 100644 UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.c create mode 100644 UefiCpuPkg/CpuTimerDxe/CpuTimer.uni create mode 100644 UefiCpuPkg/CpuTimerDxe/CpuTimerExtra.uni diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 6ea90507e36f..54ef5edd6eae 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -178,5 +178,8 @@ [Components.IA32, Components.X64] UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf =20 +[Components.RISCV64] + UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf + [BuildOptions] *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES diff --git a/UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf b/UefiCpuPkg/CpuTimerDx= e/CpuTimerDxe.inf new file mode 100644 index 000000000000..d7706328b591 --- /dev/null +++ b/UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf @@ -0,0 +1,51 @@ +## @file +# Timer Arch protocol module +# +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001b + BASE_NAME =3D CpuTimerDxe + MODULE_UNI_FILE =3D CpuTimer.uni + FILE_GUID =3D 055DDAC6-9142-4013-BF20-FC2E5BC325C9 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D TimerDriverInitialize +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D RISCV64 +# +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + IoLib + CpuLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[LibraryClasses.RISCV64] + RiscVSbiLib + +[Sources.RISCV64] + RiscV64/Timer.h + RiscV64/Timer.c + +[Protocols] + gEfiCpuArchProtocolGuid ## CONSUMES + gEfiTimerArchProtocolGuid ## PRODUCES + +[Depex] + gEfiCpuArchProtocolGuid + +[UserExtensions.TianoCore."ExtraFiles"] + CpuTimerExtra.uni diff --git a/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h b/UefiCpuPkg/CpuTimerDx= e/RiscV64/Timer.h new file mode 100644 index 000000000000..586eb0cfadb4 --- /dev/null +++ b/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h @@ -0,0 +1,177 @@ +/** @file + RISC-V Timer Architectural Protocol definitions + + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef TIMER_H_ +#define TIMER_H_ + +#include + +#include +#include + +#include +#include +#include +#include + +// +// RISC-V use 100us timer. +// The default timer tick duration is set to 10 ms =3D 10 * 1000 * 10 100 = ns units +// +#define DEFAULT_TIMER_TICK_DURATION 100000 + +extern VOID +RiscvSetTimerPeriod ( + UINT32 TimerPeriod + ); + +// +// Function Prototypes +// + +/** + 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 occured attempting to init= ialize the driver. + +**/ +EFI_STATUS +EFIAPI +TimerDriverInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +; + +/** + + 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_UNSUPPORTEDT The platform does not support the generation o= f soft timer interrupts. + +**/ +EFI_STATUS +EFIAPI +TimerDriverGenerateSoftInterrupt ( + IN EFI_TIMER_ARCH_PROTOCOL *This + ) +; + +#endif diff --git a/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.c b/UefiCpuPkg/CpuTimerDx= e/RiscV64/Timer.c new file mode 100644 index 000000000000..db153f715e60 --- /dev/null +++ b/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.c @@ -0,0 +1,294 @@ +/** @file + RISC-V Timer Architectural Protocol + + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include "Timer.h" + +// +// The handle onto which the Timer Architectural Protocol will be installed +// +STATIC EFI_HANDLE mTimerHandle =3D 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. +// +STATIC EFI_TIMER_NOTIFY mTimerNotifyFunction; + +// +// The current period of the timer interrupt +// +STATIC UINT64 mTimerPeriod =3D 0; + +/** + Timer Interrupt Handler. + + @param InterruptType The type of interrupt that occured + @param SystemContext A pointer to the system context when the interru= pt occured +**/ +VOID +EFIAPI +TimerInterruptHandler ( + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_SYSTEM_CONTEXT SystemContext + ) +{ + EFI_TPL OriginalTPL; + UINT64 RiscvTimer; + + OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); + if (mTimerNotifyFunction !=3D NULL) { + mTimerNotifyFunction (mTimerPeriod); + } + + RiscVDisableTimerInterrupt (); // Disable SMode timer int + RiscVClearPendingTimerInterrupt (); + if (mTimerPeriod =3D=3D 0) { + gBS->RestoreTPL (OriginalTPL); + RiscVDisableTimerInterrupt (); // Disable SMode timer int + return; + } + + RiscvTimer =3D RiscVReadTimer (); + SbiSetTimer (RiscvTimer +=3D mTimerPeriod); + gBS->RestoreTPL (OriginalTPL); + RiscVEnableTimerInterrupt (); // enable SMode timer int +} + +/** + + 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 + ) +{ + DEBUG ((DEBUG_INFO, "TimerDriverRegisterHandler(0x%lx) called\n", Notify= Function)); + 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 RiscvTimer; + + DEBUG ((DEBUG_INFO, "TimerDriverSetTimerPeriod(0x%lx)\n", TimerPeriod)); + + if (TimerPeriod =3D=3D 0) { + mTimerPeriod =3D 0; + RiscVDisableTimerInterrupt (); // Disable SMode timer int + return EFI_SUCCESS; + } + + mTimerPeriod =3D TimerPeriod / 10; // convert unit from 100ns to 1us + RiscvTimer =3D RiscVReadTimer (); + SbiSetTimer (RiscvTimer + mTimerPeriod); + + mCpu->EnableInterrupt (mCpu); + RiscVEnableTimerInterrupt (); // enable SMode timer int + 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 + ) +{ + *TimerPeriod =3D mTimerPeriod; + return EFI_SUCCESS; +} + +/** + + 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_UNSUPPORTEDT The platform does not support the generation o= f soft timer interrupts. + +**/ +EFI_STATUS +EFIAPI +TimerDriverGenerateSoftInterrupt ( + IN EFI_TIMER_ARCH_PROTOCOL *This + ) +{ + return EFI_SUCCESS; +} + +/** + 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 occured attempting to init= ialize the driver. + +**/ +EFI_STATUS +EFIAPI +TimerDriverInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // 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); + + // + // Install interrupt handler for RISC-V Timer. + // + Status =3D mCpu->RegisterInterruptHandler (mCpu, EXCEPT_RISCV_TIMER_INT,= TimerInterruptHandler); + ASSERT_EFI_ERROR (Status); + + // + // 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); + return Status; +} diff --git a/UefiCpuPkg/CpuTimerDxe/CpuTimer.uni b/UefiCpuPkg/CpuTimerDxe/C= puTimer.uni new file mode 100644 index 000000000000..07272a8a787b --- /dev/null +++ b/UefiCpuPkg/CpuTimerDxe/CpuTimer.uni @@ -0,0 +1,15 @@ +// /** @file +// +// Timer Arch protocol strings. +// +// Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+// Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Timer driver that= provides Timer Arch protocol" + +#string STR_MODULE_DESCRIPTION #language en-US "Timer driver that= provides Timer Arch protocol." diff --git a/UefiCpuPkg/CpuTimerDxe/CpuTimerExtra.uni b/UefiCpuPkg/CpuTimer= Dxe/CpuTimerExtra.uni new file mode 100644 index 000000000000..ad80afe2674c --- /dev/null +++ b/UefiCpuPkg/CpuTimerDxe/CpuTimerExtra.uni @@ -0,0 +1,13 @@ +// /** @file +// Timer Localized Strings and Content +// +// Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+// Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_PROPERTIES_MODULE_NAME +#language en-US +"Timer DXE Driver" --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95130): https://edk2.groups.io/g/devel/message/95130 Mute This Topic: https://groups.io/mt/94300404/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 Sat May 18 17:16:06 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+95131+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+95131+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655182; cv=none; d=zohomail.com; s=zohoarc; b=SALX37F4ClOvzUQ1T4rkkN26lifDOplrhctPyql64ljqUKb1geZx56u7m08gNR3C//b6oUGsTgtQhEYS/ksV7IU7kpT8mMeyZPRfCDYZRYRBpXbH4FaCz0767amoiBXs5zi3tVuP8ShlFB2co20epXbVOkDiMAPNf0KW8WGZczY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655182; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=1/mxvifnD0KiQL/ZMIZXxkp7+4d7n1nHoXO0sXMe2Q4=; b=CAdsq8/tMnOlybJs9aL2VMa1Rlox+MyU/NtThyMoEIO9f14vlYx9OKbg7ZVUYuyiruyyGYUKZAFdP/WSMgKUb9fJ01zhlfSa+LpvB08gF60xiJxLB3lMLoj7fMjxgWkIp57E9k951Gb1z7lZLtXyY8oqep9br4BAhfiNS6+3cFM= 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+95131+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16656551821091017.2296507549835; Thu, 13 Oct 2022 02:59:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vlbqYY1788612x05Mu44LR3o; Thu, 13 Oct 2022 02:59:41 -0700 X-Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mx.groups.io with SMTP id smtpd.web12.5674.1665655181113092679 for ; Thu, 13 Oct 2022 02:59:41 -0700 X-Received: by mail-pl1-f174.google.com with SMTP id c20so1360569plc.5 for ; Thu, 13 Oct 2022 02:59:41 -0700 (PDT) X-Gm-Message-State: Pf9S3jyoW4ADj34SEQjNSXOfx1787277AA= X-Google-Smtp-Source: AMsMyM69FQMnsYJghV3IAotCC88IRK5eD7JXkElqcMk9FQT1d7OB/6zeu3WFZ+Y8LJxz87cGT5Kgfg== X-Received: by 2002:a17:902:7c97:b0:17f:5abf:9450 with SMTP id y23-20020a1709027c9700b0017f5abf9450mr33362256pll.19.1665655180401; Thu, 13 Oct 2022 02:59:40 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:39 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 21/34] ArmVirtPkg/PlatformHasAcpiDtDxe: Move to OvmfPkg Date: Thu, 13 Oct 2022 15:28:16 +0530 Message-Id: <20221013095829.1454581-22-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655181; bh=JkYzMwA+P2AimQJZTIXjdkC7OA34YBSPULSsQ8kycwI=; h=Cc:Date:From:Reply-To:Subject:To; b=t6sCqU+RNozIGoc+e6EpnxYDpYyDukahHNLr+l71peAfTj0rK2WK7ephZbIPOcIYysp SzlHR/qM/mU/pVkSY7HpISRBoiP8WTI2Z+79Lf/Qg+UYVQEPTr3cGbzq12jmqnHaG8YQc S6rNuiWBLU13iA8LWEfIFS1JjyHgKO9MlFU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655184176100005 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This module is required by other architectures like RISC-V. Hence, move this to OvmfPkg. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Sunil V L --- ArmVirtPkg/ArmVirtPkg.dec | 9 --------- OvmfPkg/OvmfPkg.dec | 7 +++++++ .../PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf | 3 +-- .../PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c | 0 4 files changed, 8 insertions(+), 11 deletions(-) rename {ArmVirtPkg =3D> OvmfPkg}/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe= .inf (89%) rename {ArmVirtPkg =3D> OvmfPkg}/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe= .c (100%) diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec index 4e165f6cd845..d2d325d71ea7 100644 --- a/ArmVirtPkg/ArmVirtPkg.dec +++ b/ArmVirtPkg/ArmVirtPkg.dec @@ -33,8 +33,6 @@ [Guids.common] gEarlyPL011BaseAddressGuid =3D { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x8= 0, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } } gEarly16550UartBaseAddressGuid =3D { 0xea67ca3e, 0x1f54, 0x436b, { 0x9= 7, 0x88, 0xd4, 0xeb, 0x29, 0xc3, 0x42, 0x67 } } =20 - gArmVirtVariableGuid =3D { 0x50bea1e5, 0xa2c5, 0x46e9, { 0x9b, 0x3a, 0= x59, 0x59, 0x65, 0x16, 0xb0, 0x0a } } - [PcdsFeatureFlag] # # Feature Flag PCD that defines whether TPM2 support is enabled @@ -68,10 +66,3 @@ [PcdsFixedAtBuild, PcdsPatchableInModule] # Cloud Hypervisor has no other way to pass Rsdp address to the guest ex= cept use a PCD. # gArmVirtTokenSpaceGuid.PcdCloudHvAcpiRsdpBaseAddress|0x0|UINT64|0x000000= 05 - -[PcdsDynamic] - # - # Whether to force disable ACPI, regardless of the fw_cfg settings - # exposed by QEMU - # - gArmVirtTokenSpaceGuid.PcdForceNoAcpi|0x0|BOOLEAN|0x00000003 diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index f13dd4a61f01..716c98e084fd 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -147,6 +147,7 @@ [Guids] gConfidentialComputingSevSnpBlobGuid =3D {0x067b1f5f, 0xcf26, 0x44c5, {= 0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42}} gUefiOvmfPkgPlatformInfoGuid =3D {0xdec9b486, 0x1f16, 0x47c7, {= 0x8f, 0x68, 0xdf, 0x1a, 0x41, 0x88, 0x8b, 0xa5}} gVMMBootOrderGuid =3D {0x668f4529, 0x63d0, 0x4bb5, {= 0xb6, 0x5d, 0x6f, 0xbb, 0x9d, 0x36, 0xa4, 0x4a}} + gOvmfVariableGuid =3D {0x50bea1e5, 0xa2c5, 0x46e9, {= 0x9b, 0x3a, 0x59, 0x59, 0x65, 0x16, 0xb0, 0x0a}} =20 [Ppis] # PPI whose presence in the PPI database signals that the TPM base addre= ss @@ -456,6 +457,12 @@ [PcdsDynamic, PcdsDynamicEx] ## This PCD records LASA field in CC EVENTLOG ACPI table. gUefiOvmfPkgTokenSpaceGuid.PcdCcEventlogAcpiTableLasa|0|UINT64|0x67 =20 + # + # Whether to force disable ACPI, regardless of the fw_cfg settings + # exposed by QEMU + # + gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|0x0|BOOLEAN|0x69 + [PcdsFeatureFlag] gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0= x1c gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN= |0x1d diff --git a/ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf b/Ovm= fPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf similarity index 89% rename from ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf rename to OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf index e900aa992661..85873f73b2eb 100644 --- a/ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf +++ b/OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf @@ -19,7 +19,6 @@ [Sources] PlatformHasAcpiDtDxe.c =20 [Packages] - ArmVirtPkg/ArmVirtPkg.dec EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec @@ -38,7 +37,7 @@ [Guids] gEdkiiPlatformHasDeviceTreeGuid ## SOMETIMES_PRODUCES ## PROTOCOL =20 [Pcd] - gArmVirtTokenSpaceGuid.PcdForceNoAcpi + gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi =20 [Depex] gEfiVariableArchProtocolGuid diff --git a/ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c b/OvmfP= kg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c similarity index 100% rename from ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c rename to OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95131): https://edk2.groups.io/g/devel/message/95131 Mute This Topic: https://groups.io/mt/94300405/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 Sat May 18 17:16:06 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+95132+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+95132+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655185; cv=none; d=zohomail.com; s=zohoarc; b=kKbXZ7WADhl9wF952xt3wUZCI+oN8RmOcgtYy/O+mO3mYUoW9hRHiuhqRGgmJOqzOQPcJdErZnTjvIzpOrGdutt4cw7T2D56ZzPmEYRPtHJf91oXaydEQw+wpE6vUzfrVyEbSww9LUaBHWZH9gAD1/kHq0onumWSgBsQ8V/Ji2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655185; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=BttFMNO2pjBYOy+5HYaoPYVc6Hwt5Bvmot5ZXU1tMUY=; b=YBZeBznAY0DFeKHYcEhpoMi0z8vfHXXhLFi5QacK3xayfSLcS2dNG2m8TsTfl57jXYwQ7dVmv3tCeEyXe6Bdy9HYqBeYFVmF/oueU15Zl2vDMyTF3giZra1qOAeLnNlhtk56VoTMREMaabCLIoVXBgNeRJosdqeYGa6hB+zbrHE= 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+95132+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 166565518524337.75209693325064; Thu, 13 Oct 2022 02:59:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id O8pHYY1788612xeyzSY7unGr; Thu, 13 Oct 2022 02:59:44 -0700 X-Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mx.groups.io with SMTP id smtpd.web10.5680.1665655184260725793 for ; Thu, 13 Oct 2022 02:59:44 -0700 X-Received: by mail-pl1-f176.google.com with SMTP id 10so1408607pli.0 for ; Thu, 13 Oct 2022 02:59:44 -0700 (PDT) X-Gm-Message-State: pZdxt6K72kaFBIBPcotPu1Glx1787277AA= X-Google-Smtp-Source: AMsMyM5e5YH+mJqakd771QdTWbPSWPEGLXwaSwxXL+FU2XbT8o3VEMx8o52/xfFWJrYlBMvU73wtmQ== X-Received: by 2002:a17:902:da8b:b0:178:391d:d0b1 with SMTP id j11-20020a170902da8b00b00178391dd0b1mr33993460plx.32.1665655183375; Thu, 13 Oct 2022 02:59:43 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:42 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 22/34] ArmVirtPkg: Fix up the location of PlatformHasAcpiDtDxe Date: Thu, 13 Oct 2022 15:28:17 +0530 Message-Id: <20221013095829.1454581-23-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655184; bh=KSCxqJE/fLpPtZflcZ8ybjkl3Z9wt7PKn+3uOZlddcY=; h=Cc:Date:From:Reply-To:Subject:To; b=X5YpsE7bCe/TP1hqXAdOPeJRifJuGsiolMVoipw6BaDNHhH1vrpSx07g+OMukp+w/HL PvwT4nZSHpxbglfzeJN+jso8dZrn2uOTe2LrmZ99RM/eZ+HRxS1BgK1syjKIo9MxnwVMm 9vz/TElnrbiouyvhtfGN2qAwCRi0//g0nIc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655186147100009 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 PlatformHasAcpiDtDxe is required by other architectures also. Hence, it is moved to OvmfPkg. So, update the consumers of this module with the new location. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Signed-off-by: Sunil V L --- ArmVirtPkg/ArmVirtCloudHv.dsc | 2 +- ArmVirtPkg/ArmVirtQemu.dsc | 4 ++-- ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +- .../CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf | 2 +- ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf | 2 +- ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index 7ca7a391d9cf..c975e139a216 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -198,7 +198,7 @@ [PcdsDynamicDefault.common] gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress|0x0 =20 [PcdsDynamicHii] - gArmVirtTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gArmVirtVariableGui= d|0x0|FALSE|NV,BS + gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gOvmfVariableGu= id|0x0|FALSE|NV,BS =20 ##########################################################################= ###### # diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 9369a88858fd..9112cd6b07dc 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -286,7 +286,7 @@ [PcdsDynamicDefault.common] !endif =20 [PcdsDynamicHii] - gArmVirtTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gArmVirtVariableGui= d|0x0|FALSE|NV,BS + gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gOvmfVariableGu= id|0x0|FALSE|NV,BS =20 !if $(TPM2_CONFIG_ENABLE) =3D=3D TRUE gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer|L"TCG2_= VERSION"|gTcg2ConfigFormSetGuid|0x0|"1.3"|NV,BS @@ -543,7 +543,7 @@ [Components.common] # # ACPI Support # - ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf + OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf [Components.AARCH64] MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsRes= ourceTableDxe.inf OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf { diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index 7f7d15d6eee3..21684f3666c8 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -457,7 +457,7 @@ [Components.common] # # ACPI Support # - ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf + OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf [Components.AARCH64] MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsRes= ourceTableDxe.inf OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf { diff --git a/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf= b/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf index 4af06b2a6746..7cad40e11f33 100644 --- a/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf +++ b/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf @@ -36,7 +36,7 @@ [Guids] gEdkiiPlatformHasDeviceTreeGuid ## SOMETIMES_PRODUCES ## PROTOCOL =20 [Pcd] - gArmVirtTokenSpaceGuid.PcdForceNoAcpi + gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi =20 [Depex] gEfiVariableArchProtocolGuid diff --git a/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf b/ArmVirt= Pkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf index 1cf25780f830..5888fcdc0b26 100644 --- a/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf +++ b/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf @@ -37,7 +37,7 @@ [Guids] gEdkiiPlatformHasDeviceTreeGuid ## SOMETIMES_PRODUCES ## PROTOCOL =20 [Pcd] - gArmVirtTokenSpaceGuid.PcdForceNoAcpi + gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi =20 [Depex] TRUE diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuF= vMain.fdf.inc index d4df6dede0fe..17799de845ba 100644 --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc @@ -141,7 +141,7 @@ [FV.FvMain] # # ACPI Support # - INF ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf + INF OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf !if $(ARCH) =3D=3D AARCH64 INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphic= sResourceTableDxe.inf --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95132): https://edk2.groups.io/g/devel/message/95132 Mute This Topic: https://groups.io/mt/94300406/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 Sat May 18 17:16:06 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+95133+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+95133+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655187; cv=none; d=zohomail.com; s=zohoarc; b=Jf4ntV4YKb9XI+tuUS/k2xfQskqQFOLiNDJ54jH0mrIs8H2Xqgbdzv5kxcOnvRwGH6Hp1eyRRbJVbnMFcUlXsbrgQdc2dwP2C436xtGXigpC3sRBz49B03i5jWJv3THloEXjesl5QxdeJVopxkbAd/L/StkjVdnihB2KKu+LYSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655187; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=6o9k9gVclRFUzweVpN7XSIAAoGNvZvpM9WK28nrPtxE=; b=ky/d3EE26Z2rb8dZjGU7xn/JkatHJAQb9snvwVOYpSFVexqCXLpNtLJDA3zdKqMyMm4OMDrLqfsvM303PrDCcI0X/WeZBNao9d/fe4Qrdpnkh4LFObEyzQawiZCcZJoFj/vXHSSxpTyW0cfQxfHU9fD1P+QX5qJ8RXV/UdCmTvU= 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+95133+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655187936145.40596104965607; Thu, 13 Oct 2022 02:59:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2YOsYY1788612xy8oJbIlydu; Thu, 13 Oct 2022 02:59:47 -0700 X-Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mx.groups.io with SMTP id smtpd.web12.5675.1665655186955983275 for ; Thu, 13 Oct 2022 02:59:47 -0700 X-Received: by mail-pj1-f46.google.com with SMTP id a5-20020a17090aa50500b002008eeb040eso5267437pjq.1 for ; Thu, 13 Oct 2022 02:59:46 -0700 (PDT) X-Gm-Message-State: 9lLVOtImZ1N4eBXh0fcyXTwOx1787277AA= X-Google-Smtp-Source: AMsMyM52klF3SDIa0+tMJn7DLMiGx82a7jaglKFvfImyVX+aSNP2FuQuSxmUvjVjavQANqXwn4Aeew== X-Received: by 2002:a17:902:e747:b0:185:378d:7c00 with SMTP id p7-20020a170902e74700b00185378d7c00mr1857318plf.123.1665655186251; Thu, 13 Oct 2022 02:59:46 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:45 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Gerd Hoffmann , Jiewen Yao , Jordan Justen Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 23/34] ArmVirtPkg/PlatformBootManagerLib: Move to OvmfPkg Date: Thu, 13 Oct 2022 15:28:18 +0530 Message-Id: <20221013095829.1454581-24-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655187; bh=wXEL/1eyZSapOjmSOXcJwcEA4Q62sDg1VLsDVPNFGRQ=; h=Cc:Date:From:Reply-To:Subject:To; b=Faj+qTKiyXu2NarOxZ8TxUEkbKSNj9P/Lmfrwy8lJfxa4TlWqqSGrnPePuuGtE/tBkb W+bT93LSNXeUgLRgPWlkTXdeJ9hQSYQykJJ6l5yQu6SDSB11bZnR/Yac0RT2L3chYWcOX nLI+aZOYiYx8TgFflhV5NgrA7Au7Wgi5RPY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655188185100013 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 PlatformBootManagerLib in ArmVirtPkg is required for RISC-V also. So, move it to OvmfPkg. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Cc: Jiewen Yao Cc: Jordan Justen Signed-off-by: Sunil V L --- OvmfPkg/OvmfPkg.dec | 7 +++++++ .../PlatformBootManagerLibVirt}/PlatformBootManagerLib.inf | 3 +-- .../Library/PlatformBootManagerLibVirt}/PlatformBm.h | 0 .../Library/PlatformBootManagerLibVirt}/PlatformBm.c | 0 .../Library/PlatformBootManagerLibVirt}/QemuKernel.c | 0 OvmfPkg/OvmfPkg.ci.yaml | 1 + 6 files changed, 9 insertions(+), 2 deletions(-) rename {ArmVirtPkg/Library/PlatformBootManagerLib =3D> OvmfPkg/Library/Pla= tformBootManagerLibVirt}/PlatformBootManagerLib.inf (92%) rename {ArmVirtPkg/Library/PlatformBootManagerLib =3D> OvmfPkg/Library/Pla= tformBootManagerLibVirt}/PlatformBm.h (100%) rename {ArmVirtPkg/Library/PlatformBootManagerLib =3D> OvmfPkg/Library/Pla= tformBootManagerLibVirt}/PlatformBm.c (100%) rename {ArmVirtPkg/Library/PlatformBootManagerLib =3D> OvmfPkg/Library/Pla= tformBootManagerLibVirt}/QemuKernel.c (100%) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 716c98e084fd..7d2acc5ea0e0 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -463,6 +463,13 @@ [PcdsDynamic, PcdsDynamicEx] # gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|0x0|BOOLEAN|0x69 =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*|0x70 + [PcdsFeatureFlag] gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0= x1c gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN= |0x1d diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerL= ib.inf b/OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBootManagerLib.= inf similarity index 92% rename from ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLi= b.inf rename to OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBootManagerLib= .inf index 997eb1a4429f..a747ea3feac0 100644 --- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBootManagerLib.inf @@ -29,7 +29,6 @@ [Sources] QemuKernel.c =20 [Packages] - ArmVirtPkg/ArmVirtPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec @@ -61,7 +60,7 @@ [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits =20 [Pcd] - gArmVirtTokenSpaceGuid.PcdTerminalTypeGuidBuffer + gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut =20 [Guids] diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.h b/OvmfP= kg/Library/PlatformBootManagerLibVirt/PlatformBm.h similarity index 100% rename from ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.h rename to OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBm.h diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c b/OvmfP= kg/Library/PlatformBootManagerLibVirt/PlatformBm.c similarity index 100% rename from ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c rename to OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBm.c diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c b/OvmfP= kg/Library/PlatformBootManagerLibVirt/QemuKernel.c similarity index 100% rename from ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c rename to OvmfPkg/Library/PlatformBootManagerLibVirt/QemuKernel.c diff --git a/OvmfPkg/OvmfPkg.ci.yaml b/OvmfPkg/OvmfPkg.ci.yaml index ff022242b018..c6efb9a8e59e 100644 --- a/OvmfPkg/OvmfPkg.ci.yaml +++ b/OvmfPkg/OvmfPkg.ci.yaml @@ -22,6 +22,7 @@ ], ## Both file path and directory path are accepted. "IgnoreFiles": [ + "Library/PlatformBootManagerLibVirt/PlatformBm.c" ], "skip": True }, --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95133): https://edk2.groups.io/g/devel/message/95133 Mute This Topic: https://groups.io/mt/94300407/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 Sat May 18 17:16:06 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+95134+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+95134+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655191; cv=none; d=zohomail.com; s=zohoarc; b=AUs467gZQQGBXbZCeRcxoRN7/B0Fjf0lS4lFWOcU/zHkIn+bos4OJNOk2LXKGwIME9CZvIQJKdMyFaY5MnrnMR8E1QF4xShQQlVBd9TBgWZ4u3NaOQfa+GWdwvkwSu9xXFezR9PVq7DT5J1tkpj7YJU5/d+/UpmYvIamv17Gtco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655191; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ezzbFBEb7n7j4TNeoU3IqmsDQgdsO+safCD4V2icdyk=; b=cCFKp6vKnFcloBHtNN2G1KxTVs+lvxVF6VVSzokJAXVUu+5BNFvcBVHbA4r1dJPsG1rSgZ49qWrZg7Vyb2agPM/NPpIPakxznesmoWl516eTTGVf9aiuGr13VytLw40VkTRmYhG1X4Puh0L+BcYGG/kk2OxLAbaP/SzJYkVDIlM= 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+95134+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655191506722.0344146400051; Thu, 13 Oct 2022 02:59:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9fSlYY1788612xZvEHDkyEcF; Thu, 13 Oct 2022 02:59:50 -0700 X-Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web09.5764.1665655189421321320 for ; Thu, 13 Oct 2022 02:59:49 -0700 X-Received: by mail-pf1-f170.google.com with SMTP id i3so1486997pfk.9 for ; Thu, 13 Oct 2022 02:59:49 -0700 (PDT) X-Gm-Message-State: pWwN2EliVLGLmekE2QCoiFh5x1787277AA= X-Google-Smtp-Source: AMsMyM668cVSpWy+u7eg2B2MOM56k2V3/PiAGw6ncPOVlu3Edz3DhuSHPGUvE7Je1I/KILtIPu8y5g== X-Received: by 2002:a65:6e97:0:b0:439:e6a3:9f6d with SMTP id bm23-20020a656e97000000b00439e6a39f6dmr28953858pgb.369.1665655188734; Thu, 13 Oct 2022 02:59:48 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:48 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 24/34] ArmVirtPkg: Fix up the paths to PlatformBootManagerLib Date: Thu, 13 Oct 2022 15:28:19 +0530 Message-Id: <20221013095829.1454581-25-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655190; bh=tmJag/IfwGcBf6z2FCIvNlfWJmip0AIRb4gMLE3srmM=; h=Cc:Date:From:Reply-To:Subject:To; b=hfpDhI60O9jh1HqpIYp16eSUNK4myaN799lQAulh7ZRt2vsZz7Gwpgz4fQpAwBV/idB WzZ3t+shsv8X0EKxahBBUBYfJyVbH8ApVqp1qncV87YIGG0rWLD7BpSJl4u+SUURDAw+o hBw9iHi2nzaksby2/cs4xmJPeylwCtaIChk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655192212100002 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 PlatformBootManagerLib has been moved to OvmfPkg so that other CPU architectures can reuse. So, update existing paths with the new location. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Signed-off-by: Sunil V L --- ArmVirtPkg/ArmVirtQemu.dsc | 4 ++-- ArmVirtPkg/ArmVirtQemuKernel.dsc | 4 ++-- ArmVirtPkg/ArmVirtPkg.ci.yaml | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 9112cd6b07dc..0e460d21b2f5 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -71,7 +71,7 @@ [LibraryClasses.common] =20 CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf - PlatformBootManagerLib|ArmVirtPkg/Library/PlatformBootManagerLib/Platfor= mBootManagerLib.inf + PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLibVirt/Platfo= rmBootManagerLib.inf PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrin= tScLib.inf CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf @@ -167,7 +167,7 @@ [PcdsFixedAtBuild.common] !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 21684f3666c8..e3967db53133 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -69,7 +69,7 @@ [LibraryClasses.common] =20 CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf - PlatformBootManagerLib|ArmVirtPkg/Library/PlatformBootManagerLib/Platfor= mBootManagerLib.inf + PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLibVirt/Platfo= rmBootManagerLib.inf PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrin= tScLib.inf CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf @@ -146,7 +146,7 @@ [PcdsFixedAtBuild.common] !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/ArmVirtPkg.ci.yaml b/ArmVirtPkg/ArmVirtPkg.ci.yaml index 1e799dc4e194..552511c2694e 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 --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95134): https://edk2.groups.io/g/devel/message/95134 Mute This Topic: https://groups.io/mt/94300409/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 Sat May 18 17:16:06 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+95135+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+95135+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655193; cv=none; d=zohomail.com; s=zohoarc; b=cIcZ2Kp5UxlerKHQxKW1htYOZK3q+8dSf0S/emeFYGKnlgbxvMlDNearNR+iycuqgliV/FZNBF2RlpkmjLMN4G7EPVrDQ9XNMNiJqO5+D9qYiWYXWEfiF0CmwjVFU6zYlOavPc9fAhN+2Yt+St5J9lB+mH63KkXwg30IQ8zdLtQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655193; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=GiWUHZrarYd2ej6B1Y6iX6xO/PNboi0BaDDaxOZ7Cl4=; b=hYxAp2MYbScbg2XTbQMgc5hU/h4wtbSePIwBR36vmbAt2zrPZtTin7kYbwxph6K36Zn9/lconutq1w9eHXSaD7Zp576T2LjKqUSKOJTHENh6Zn1hPyL8DJzMffqYRcf/i3/xRDNbOzCPZo/I9uAlrqdmTVe60QljpQKxoKR1dqc= 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+95135+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655193357709.0971465225007; Thu, 13 Oct 2022 02:59:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id W07FYY1788612xYcSN97P0xW; Thu, 13 Oct 2022 02:59:52 -0700 X-Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mx.groups.io with SMTP id smtpd.web10.5682.1665655192246811720 for ; Thu, 13 Oct 2022 02:59:52 -0700 X-Received: by mail-pj1-f48.google.com with SMTP id x31-20020a17090a38a200b0020d2afec803so1471030pjb.2 for ; Thu, 13 Oct 2022 02:59:52 -0700 (PDT) X-Gm-Message-State: YijutpeG3uYDIxTwoh1QEgP2x1787277AA= X-Google-Smtp-Source: AMsMyM4zW09snv+lwqNhTKpxEH35h1BJZbZ3YXQVkBDlg0aOLpimIx7dHFxUGIIZsfXenlUA+EYyAw== X-Received: by 2002:a17:902:b104:b0:184:eec6:cd4d with SMTP id q4-20020a170902b10400b00184eec6cd4dmr4736718plr.138.1665655191537; Thu, 13 Oct 2022 02:59:51 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:51 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Michael D Kinney , Liming Gao , Zhiguang Liu , Andrew Fish Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 25/34] ArmPlatformPkg/NorFlashPlatformLib.h:Move to MdePkg Date: Thu, 13 Oct 2022 15:28:20 +0530 Message-Id: <20221013095829.1454581-26-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655192; bh=u9siAM2dh9pA19Dte1seySf//XgXJulW2Exy49qexf0=; h=Cc:Date:From:Reply-To:Subject:To; b=trSxXJzan7xQlRxULZh2p3YBg4P5xfOGFpWo+hgiq/E83Xlh4tXWS31eHgDUdMpbb7i fTN6jYTN7zlLmvRmaJrOyeLweLKA2qLNyTZEwhdnvYg1VqrDMJJfoxVWnizaRp8fcXFXH upBw0N5wB74xKBNS4dZdOA0m+1a5SGb/NJ0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655194235100005 Content-Type: text/plain; charset="utf-8" Migrate NorFlashPlatformLib.h to MdePkg and add a Null instance of the NorFlashPlatformLib library in MdePkg. Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Andrew Fish Signed-off-by: Sunil V L --- ArmPlatformPkg/ArmPlatformPkg.dec | 4 --- MdePkg/MdePkg.dec | 4 +++ MdePkg/MdePkg.dsc | 1 + .../NorFlashPlatformLibNull.inf | 22 ++++++++++++++++ .../Include/Library/NorFlashPlatformLib.h | 0 .../NorFlashPlatformLibNull.c | 26 +++++++++++++++++++ 6 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 MdePkg/Library/NorFlashPlatformLibNull/NorFlashPlatform= LibNull.inf rename {ArmPlatformPkg =3D> MdePkg}/Include/Library/NorFlashPlatformLib.h = (100%) create mode 100644 MdePkg/Library/NorFlashPlatformLibNull/NorFlashPlatform= LibNull.c diff --git a/ArmPlatformPkg/ArmPlatformPkg.dec b/ArmPlatformPkg/ArmPlatform= Pkg.dec index dd6e78f62aa1..86559aa6e57d 100644 --- a/ArmPlatformPkg/ArmPlatformPkg.dec +++ b/ArmPlatformPkg/ArmPlatformPkg.dec @@ -38,10 +38,6 @@ [LibraryClasses] # LcdPlatformLib|Include/Library/LcdPlatformLib.h =20 - ## @libraryclass Provides a Nor flash interface. - # - NorFlashPlatformLib|Include/Library/NorFlashPlatformLib.h - ## @libraryclass Provides an interface to the clock of a PL011 device. # PL011UartClockLib|Include/Library/PL011UartClockLib.h diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 1762068ffad7..16d01948f746 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -275,6 +275,10 @@ [LibraryClasses] ## @libraryclass Provides function for SMM CPU Rendezvous Library. SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h =20 + ## @libraryclass Provides a Nor flash interface. + # + NorFlashPlatformLib|Include/Library/NorFlashPlatformLib.h + [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64] ## @libraryclass Provides services to generate random number. # diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index fd08122f441d..c575390bcff2 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -133,6 +133,7 @@ [Components] MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf + MdePkg/Library/NorFlashPlatformLibNull/NorFlashPlatformLibNull.inf =20 [Components.IA32, Components.X64, Components.ARM, Components.AARCH64] # diff --git a/MdePkg/Library/NorFlashPlatformLibNull/NorFlashPlatformLibNull= .inf b/MdePkg/Library/NorFlashPlatformLibNull/NorFlashPlatformLibNull.inf new file mode 100644 index 000000000000..e4bd85ba7ace --- /dev/null +++ b/MdePkg/Library/NorFlashPlatformLibNull/NorFlashPlatformLibNull.inf @@ -0,0 +1,22 @@ +## @file +# NorFlashPlatformLib null instance +# +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D NorFlashPlatformLibNull + FILE_GUID =3D DE9C2866-5C5C-4BD3-9A09-3C4EB7448069 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D NorFlashPlatformLib + +[Sources.common] + NorFlashPlatformLibNull.c + +[Packages] + MdePkg/MdePkg.dec diff --git a/ArmPlatformPkg/Include/Library/NorFlashPlatformLib.h b/MdePkg/= Include/Library/NorFlashPlatformLib.h similarity index 100% rename from ArmPlatformPkg/Include/Library/NorFlashPlatformLib.h rename to MdePkg/Include/Library/NorFlashPlatformLib.h diff --git a/MdePkg/Library/NorFlashPlatformLibNull/NorFlashPlatformLibNull= .c b/MdePkg/Library/NorFlashPlatformLibNull/NorFlashPlatformLibNull.c new file mode 100644 index 000000000000..cd779f504e40 --- /dev/null +++ b/MdePkg/Library/NorFlashPlatformLibNull/NorFlashPlatformLibNull.c @@ -0,0 +1,26 @@ +/** @file + + Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + **/ + +#include + +EFI_STATUS +NorFlashPlatformInitialization ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +NorFlashPlatformGetDevices ( + OUT NOR_FLASH_DESCRIPTION **NorFlashDescriptions, + OUT UINT32 *Count + ) +{ + return EFI_SUCCESS; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95135): https://edk2.groups.io/g/devel/message/95135 Mute This Topic: https://groups.io/mt/94300410/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 Sat May 18 17:16:06 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+95136+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+95136+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655197; cv=none; d=zohomail.com; s=zohoarc; b=nZyXHT7TeJ5s6erxvntFXyHlxkmdG221iw7GQBDaIPJAkDhr3TxVOY5o3uqd1ru19WIMfDvdi1e/OWvlIDdyivjrWkB59mXcr4XB/aoDKblLuZbUyOxzfpshXfprE6TGaKr8zY+VKnWC5g8IhylbXaIDrAbRcnYRFhTcSjlCkz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655197; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=76zbOELaW1+fTIUcdT/hkuaSBbl6rxl+wHi/diG4aWM=; b=XuiZSMnPFz+1ibktpsMQ5Mkc7BO60JQ78VDJSp2wrFPAbI1hT4vzI5HoKe05pgAjaa+NH3miYc46dE4PvgvIRNcK/ad3qi+Oxva/nK1Wzw0DtZKIg5NU8M7/dQFx+e7XyT5VVeM/om0Sdf+lum4gqXJn57sp48a4tK6kz9Cy2yQ= 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+95136+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655197289249.87691603066787; Thu, 13 Oct 2022 02:59:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gfDPYY1788612x7MAZnjBzeU; Thu, 13 Oct 2022 02:59:56 -0700 X-Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mx.groups.io with SMTP id smtpd.web08.5687.1665655196353514461 for ; Thu, 13 Oct 2022 02:59:56 -0700 X-Received: by mail-pl1-f172.google.com with SMTP id h10so1373962plb.2 for ; Thu, 13 Oct 2022 02:59:56 -0700 (PDT) X-Gm-Message-State: m13TAMSEmBOujZk3q9Of5abrx1787277AA= X-Google-Smtp-Source: AMsMyM6C67CFJGmSK2H0DlwCzdB63XU+/jryk/4mz+3xW2Kw1d1D/S7M17tbaGnJQPxZr6nD3Kcr+A== X-Received: by 2002:a17:90b:4c45:b0:20d:4ead:6e3b with SMTP id np5-20020a17090b4c4500b0020d4ead6e3bmr10479044pjb.76.1665655195534; Thu, 13 Oct 2022 02:59:55 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:54 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Abner Chang , Daniel Schaefer , Jian J Wang , Liming Gao , Andrew Fish , Michael D Kinney Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 26/34] EmbeddedPkg/NvVarStoreFormattedLib: Migrate to MdeModulePkg Date: Thu, 13 Oct 2022 15:28:21 +0530 Message-Id: <20221013095829.1454581-27-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655196; bh=iFwG569yeW8G+gHGjhh7dz5Whp6iCTFzRmALnnCVeTk=; h=Cc:Date:From:Reply-To:Subject:To; b=sTDo1dT/ifGMorrWWplQ5Kf5pICuUA1LoCCD2n455NaookhgWpU+8jK1NL9P0U3VU2l wm3/yagkRhPEAqksfHjvgq2wA45/l5C9UHr3CvakunssyiuLgQuj4r0GgroqNRlEq987E wHA334OBXef6ONwAODiyA/3Z6ZrKvNGpM6w= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655198268100001 Content-Type: text/plain; charset="utf-8" This library is required by NorFlashDxe. Since it will be used by both virtual and real platforms, migrate this library to MdeModulePkg. Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Abner Chang Cc: Daniel Schaefer Cc: Jian J Wang Cc: Liming Gao Cc: Andrew Fish Cc: Michael D Kinney Signed-off-by: Sunil V L --- EmbeddedPkg/EmbeddedPkg.dec | 3 --- MdeModulePkg/MdeModulePkg.dec | 3 +++ MdeModulePkg/MdeModulePkg.dsc | 2 ++ .../Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf | 1 - .../Include/Guid/NvVarStoreFormatted.h | 0 .../Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.c | 0 6 files changed, 5 insertions(+), 4 deletions(-) rename {EmbeddedPkg =3D> MdeModulePkg}/Library/NvVarStoreFormattedLib/NvVa= rStoreFormattedLib.inf (96%) rename {EmbeddedPkg =3D> MdeModulePkg}/Include/Guid/NvVarStoreFormatted.h = (100%) rename {EmbeddedPkg =3D> MdeModulePkg}/Library/NvVarStoreFormattedLib/NvVa= rStoreFormattedLib.c (100%) diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec index 341ef5e6a679..b1f5654835f6 100644 --- a/EmbeddedPkg/EmbeddedPkg.dec +++ b/EmbeddedPkg/EmbeddedPkg.dec @@ -69,9 +69,6 @@ [Guids.common] # HII form set GUID for ConsolePrefDxe driver gConsolePrefFormSetGuid =3D { 0x2d2358b4, 0xe96c, 0x484d, { 0xb2, 0xdd, = 0x7c, 0x2e, 0xdf, 0xc7, 0xd5, 0x6f } } =20 - ## Include/Guid/NvVarStoreFormatted.h - gEdkiiNvVarStoreFormattedGuid =3D { 0xd1a86e3f, 0x0707, 0x4c35, { 0x83, = 0xcd, 0xdc, 0x2c, 0x29, 0xc8, 0x91, 0xa3 } } - [Protocols.common] gHardwareInterruptProtocolGuid =3D { 0x2890B3EA, 0x053D, 0x1643, { 0xAD= , 0x0C, 0xD6, 0x48, 0x08, 0xDA, 0x3F, 0xF1 } } gHardwareInterrupt2ProtocolGuid =3D { 0x32898322, 0x2da1, 0x474a, { 0xba= , 0xaa, 0xf3, 0xf7, 0xcf, 0x56, 0x94, 0x70 } } diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 58e6ab004882..492bff8b7890 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -412,6 +412,9 @@ [Guids] ## Include/Guid/MigratedFvInfo.h gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4,= 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } } =20 + ## Include/Guid/NvVarStoreFormatted.h + gEdkiiNvVarStoreFormattedGuid =3D { 0xd1a86e3f, 0x0707, 0x4c35, { 0x83, = 0xcd, 0xdc, 0x2c, 0x29, 0xc8, 0x91, 0xa3 } } + # # GUID defined in UniversalPayload # diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 45a8ec84ad69..0a2885ba8023 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -104,6 +104,7 @@ [LibraryClasses] VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/Var= iablePolicyHelperLib.inf MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibN= ull.inf VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseV= ariableFlashInfoLib.inf + NvVarStoreFormattedLib|MdeModulePkg/Library/NvVarStoreFormattedLib/NvVar= StoreFormattedLib.inf =20 [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf @@ -443,6 +444,7 @@ [Components] MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.i= nf + MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf =20 [Components.IA32, Components.X64, Components.AARCH64] MdeModulePkg/Universal/EbcDxe/EbcDxe.inf diff --git a/EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormatted= Lib.inf b/MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLi= b.inf similarity index 96% rename from EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedL= ib.inf rename to MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLi= b.inf index e2eed26c5b2d..5e8cd94cc9e0 100644 --- a/EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf +++ b/MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf @@ -32,7 +32,6 @@ [Sources] NvVarStoreFormattedLib.c =20 [Packages] - EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec =20 diff --git a/EmbeddedPkg/Include/Guid/NvVarStoreFormatted.h b/MdeModulePkg/= Include/Guid/NvVarStoreFormatted.h similarity index 100% rename from EmbeddedPkg/Include/Guid/NvVarStoreFormatted.h rename to MdeModulePkg/Include/Guid/NvVarStoreFormatted.h diff --git a/EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormatted= Lib.c b/MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.c similarity index 100% rename from EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedL= ib.c rename to MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLi= b.c --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95136): https://edk2.groups.io/g/devel/message/95136 Mute This Topic: https://groups.io/mt/94300411/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 Sat May 18 17:16:06 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+95137+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+95137+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655201; cv=none; d=zohomail.com; s=zohoarc; b=Oc8LO2k1GA0rm1MJIlsmbfIdNlWv4QJrIE3Vne4XYgIxJyM3AsDwVBjI5846Y3QiYPBL4IdFhsShw+6UrwXC9enMtVO8W3EVz5LQjQslYWbQhqxzfAT1AIm6F+otIIN9tLd3ct2utfrFtuGgK1IrHca9K0/DNlx0w+GXjatm2KA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655201; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=8qoLG9KhOl4QXs1+sj64qeZOSVULdrWgfbhXkONuO5s=; b=Q3XWdLstZODLKw2hRBPA7cNGSKzzbSt7eZFM5QSmq2lv2TYJzdrJMyoNFN7Qp/eAPKQ/XzqvDh9bxmYeBl7Eq1+5av686FIasdZCEzO1N5Ebz2IPiHIqtRQJ+Gz6wYXVcwnJs/JOafwDnwqEQKM2KJgmrbuwGkKk8dO2TzICB8A= 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+95137+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655201438188.60395846764163; Thu, 13 Oct 2022 03:00:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 77NvYY1788612xtU6JvEXGKX; Thu, 13 Oct 2022 03:00:00 -0700 X-Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by mx.groups.io with SMTP id smtpd.web12.5678.1665655199255012782 for ; Thu, 13 Oct 2022 02:59:59 -0700 X-Received: by mail-pj1-f50.google.com with SMTP id fw14so1510125pjb.3 for ; Thu, 13 Oct 2022 02:59:59 -0700 (PDT) X-Gm-Message-State: ixAAaDDHEjJNBGn4c1QarV3vx1787277AA= X-Google-Smtp-Source: AMsMyM5yVNSZ6/vNSWkD6tK4D81JOJfy1uhUTbAQZ+Cw9IYip9YQbGBvM+GBd2zL3XdIPWrJVr9wvg== X-Received: by 2002:a17:90a:a415:b0:20a:f813:83a3 with SMTP id y21-20020a17090aa41500b0020af81383a3mr10359795pjp.238.1665655198305; Thu, 13 Oct 2022 02:59:58 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 02:59:57 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 27/34] ArmVirtPkg: Update the references to NvVarStoreFormattedLib Date: Thu, 13 Oct 2022 15:28:22 +0530 Message-Id: <20221013095829.1454581-28-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655200; bh=LwQTubRuVAu3XyosR+Zt8eKF1gLgIEtcbASrCCAioQw=; h=Cc:Date:From:Reply-To:Subject:To; b=UYaGbb8TTK5GLx0Hkqnk7vuj8vLuEUN31I3Q+ljKeCyuYlkRSEeOYfAjZjy11VVkqwD m868EUmGzpyQAn35j5oXhA15P4CSpS883edPyeWkN4j/2T3urxhNxm1c4cy3kqFJ1WxxN pOSo2X6zBiO/BKZBym19S7MoCQfRS+kiOo8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655202263100006 Content-Type: text/plain; charset="utf-8" The NvVarStoreFormattedLib library is moved to MdeModulePkg. So, updates its users with the new location. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann Signed-off-by: Sunil V L --- ArmVirtPkg/ArmVirtKvmTool.dsc | 2 +- ArmVirtPkg/ArmVirtQemu.dsc | 2 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index 3bd3ebd6e0b3..a40bea5b4bb2 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -258,7 +258,7 @@ [Components.common] MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf - NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedL= ib.inf + NULL|MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormatted= Lib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf } =20 diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 0e460d21b2f5..96ae26e751be 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -357,7 +357,7 @@ [Components.common] MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf - NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedL= ib.inf + NULL|MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormatted= Lib.inf # don't use unaligned CopyMem () on the UEFI varstore NOR flash regi= on BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf } diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index e3967db53133..bbcd7264572e 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -294,7 +294,7 @@ [Components.common] MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf - NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedL= ib.inf + NULL|MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormatted= Lib.inf # don't use unaligned CopyMem () on the UEFI varstore NOR flash regi= on BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf } --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95137): https://edk2.groups.io/g/devel/message/95137 Mute This Topic: https://groups.io/mt/94300412/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 Sat May 18 17:16:06 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+95138+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+95138+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655203; cv=none; d=zohomail.com; s=zohoarc; b=P0yeUG0pwgQCv6teFP7WIGh2ABA3xIBl2c+bQoUhx383yy+/4bTlFN2AuLjLnTSHxWRhWND0/31eCg1jadfpeiSdOX9BE8oDxbNUFitumHYqSWiAH0fiM7h9tNo/P+4dIJefUpV1yZzW7RkvpOIZ0RHUSrUHvUe5+CneX0rH2EQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655203; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=5RLl9OWg3oAiOiHKMQcYUPr3T4pHaQ2IaFRTA1tYBtQ=; b=ivpCQhG5V9JI9KmRXKUY/Fph5JbR5fX4n1UutKC8Y3pgygbAcnhaTDhCuHSUKSVpm44p2Da7Cw971v70E28T7W1GEUR+Zdn4etHKDTcuhf2biwp31Wx5BOF42r6qiBAr+dViPS49r+PCso+uqGcMBz9ayCyAn4vE/FsDOSBVBf8= 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+95138+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 166565520358857.10503141976915; Thu, 13 Oct 2022 03:00:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id EYmbYY1788612x54QW2qEsqa; Thu, 13 Oct 2022 03:00:03 -0700 X-Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mx.groups.io with SMTP id smtpd.web09.5766.1665655202495944477 for ; Thu, 13 Oct 2022 03:00:02 -0700 X-Received: by mail-pj1-f46.google.com with SMTP id pq16so1525876pjb.2 for ; Thu, 13 Oct 2022 03:00:02 -0700 (PDT) X-Gm-Message-State: 7psNF5EZKiaqfpNC1WtQFZTSx1787277AA= X-Google-Smtp-Source: AMsMyM4frUO0EFmZo7V8tS2VZW8baSaQKsM+8y/Lh7iTHtZAoV0Y31X5snjt0ceL1CyCm6yGOXoF7A== X-Received: by 2002:a17:902:f64f:b0:179:edcc:2bf4 with SMTP id m15-20020a170902f64f00b00179edcc2bf4mr34455365plg.70.1665655201619; Thu, 13 Oct 2022 03:00:01 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.02.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 03:00:00 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Daniel Schaefer Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 28/34] OvmfPkg: Add NorFlashQemuLib library Date: Thu, 13 Oct 2022 15:28:23 +0530 Message-Id: <20221013095829.1454581-29-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655203; bh=TV4hES4lZjgU7ol34SXQFRIeXXeqgGr7S7M6QLEqHNw=; h=Cc:Date:From:Reply-To:Subject:To; b=bwxpQ0x0r76w3z+BT+2Q4U/5K+D/G8vkx5XjQJCv08pQAuPUzZ/0/q6jpwc3BEZdp4a zbb2UoBESUnYlfJHm/I7tx0HnnR3TU0eOxpizWlBQZ1JxG1iKyTLnYGSOl+XnRdmKeGGJ GYkdzi6d7ZYJRb4r+XTpE8G2hWx2XE6NhS8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655204313100009 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This is mostly copied from ArmVirtPkg since it is required for other architectures also. It uses OVMF specific PCD variables. Also add the instance for single flash drive which has both code and variables. This is copied from SbsaQemu. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Daniel Schaefer Signed-off-by: Sunil V L --- OvmfPkg/OvmfPkg.dec | 4 + .../NorFlashQemuLib/NorFlashQemuLib.inf | 40 ++++++ .../NorFlashQemuUnifiedLib.inf | 30 ++++ .../Library/NorFlashQemuLib/NorFlashQemuLib.c | 136 ++++++++++++++++++ .../NorFlashQemuLib/NorFlashQemuUnifiedLib.c | 40 ++++++ 5 files changed, 250 insertions(+) create mode 100644 OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf create mode 100644 OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuUnifiedLib.= inf create mode 100644 OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c create mode 100644 OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuUnifiedLib.c diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 7d2acc5ea0e0..1a77b6ff801d 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -405,6 +405,10 @@ [PcdsFixedAtBuild] # check to decide whether to abort dispatch of the driver it is linked = into. gUefiOvmfPkgTokenSpaceGuid.PcdEntryPointOverrideFwCfgVarName|""|VOID*|0x= 68 =20 + ## The base address and size of the FVMAIN + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvBaseAddress|0|UINT64|0x71 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvSize|0|UINT32|0x72 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf b/OvmfPkg/= Library/NorFlashQemuLib/NorFlashQemuLib.inf new file mode 100644 index 000000000000..ecd8059b3508 --- /dev/null +++ b/OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf @@ -0,0 +1,40 @@ +#/** @file +# +# Component description file for NorFlashQemuLib module +# +# Copyright (c) 2014, Linaro Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D NorFlashQemuLib + FILE_GUID =3D 42C30D8E-BFAD-4E77-9041-E7DAAE88DF7A + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D NorFlashPlatformLib + +[Sources.common] + NorFlashQemuLib.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiBootServicesTableLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Depex] + gFdtClientProtocolGuid + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvSize diff --git a/OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuUnifiedLib.inf b/O= vmfPkg/Library/NorFlashQemuLib/NorFlashQemuUnifiedLib.inf new file mode 100644 index 000000000000..91d1406fc3e7 --- /dev/null +++ b/OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuUnifiedLib.inf @@ -0,0 +1,30 @@ +#/** @file +# +# Component description file for NorFlashQemuLib module +# +# Copyright (c) 2014, Linaro Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D NorFlashQemuUnifiedLib + FILE_GUID =3D 064742F1-E531-4D7D-A154-22315889CC23 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D NorFlashPlatformLib + +[Sources.common] + NorFlashQemuUnifiedLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase diff --git a/OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c b/OvmfPkg/Li= brary/NorFlashQemuLib/NorFlashQemuLib.c new file mode 100644 index 000000000000..3632fa9e7a98 --- /dev/null +++ b/OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c @@ -0,0 +1,136 @@ +/** @file + + Copyright (c) 2014-2018, Linaro Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + **/ + +#include +#include +#include +#include + +#include + +#define QEMU_NOR_BLOCK_SIZE SIZE_256KB + +#define MAX_FLASH_BANKS 4 + +EFI_STATUS +NorFlashPlatformInitialization ( + VOID + ) +{ + return EFI_SUCCESS; +} + +NOR_FLASH_DESCRIPTION mNorFlashDevices[MAX_FLASH_BANKS]; + +EFI_STATUS +NorFlashPlatformGetDevices ( + OUT NOR_FLASH_DESCRIPTION **NorFlashDescriptions, + OUT UINT32 *Count + ) +{ + FDT_CLIENT_PROTOCOL *FdtClient; + INT32 Node; + EFI_STATUS Status; + EFI_STATUS FindNodeStatus; + CONST UINT32 *Reg; + UINT32 PropSize; + UINT32 Num; + UINT64 Base; + UINT64 Size; + + Status =3D gBS->LocateProtocol ( + &gFdtClientProtocolGuid, + NULL, + (VOID **)&FdtClient + ); + ASSERT_EFI_ERROR (Status); + + Num =3D 0; + for (FindNodeStatus =3D FdtClient->FindCompatibleNode ( + FdtClient, + "cfi-flash", + &Node + ); + !EFI_ERROR (FindNodeStatus) && Num < MAX_FLASH_BANKS; + FindNodeStatus =3D FdtClient->FindNextCompatibleNode ( + FdtClient, + "cfi-flash", + Node, + &Node + )) + { + 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", + __FUNCTION__, + Status + )); + continue; + } + + ASSERT ((PropSize % (4 * sizeof (UINT32))) =3D=3D 0); + + while (PropSize >=3D (4 * sizeof (UINT32)) && Num < MAX_FLASH_BANKS) { + Base =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0])); + Size =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2])); + Reg +=3D 4; + + PropSize -=3D 4 * sizeof (UINT32); + + // + // Disregard any flash devices that overlap with the primary FV. + // The firmware is not updatable from inside the guest anyway. + // + if ((PcdGet64 (PcdOvmfFvBaseAddress) + PcdGet32 (PcdOvmfFvSize) > Ba= se) && + ((Base + Size) > PcdGet64 (PcdOvmfFvBaseAddress))) + { + continue; + } + + mNorFlashDevices[Num].DeviceBaseAddress =3D (UINTN)Base; + mNorFlashDevices[Num].RegionBaseAddress =3D (UINTN)Base; + mNorFlashDevices[Num].Size =3D (UINTN)Size; + mNorFlashDevices[Num].BlockSize =3D QEMU_NOR_BLOCK_SIZE; + Num++; + } + + // + // UEFI takes ownership of the NOR flash, and exposes its functionality + // through the UEFI Runtime Services GetVariable, SetVariable, etc. Th= is + // means we need to disable it in the device tree to prevent the OS fr= om + // attaching its device driver as well. + // Note that this also hides other flash banks, but the only other fla= sh + // bank we expect to encounter is the one that carries the UEFI execut= able + // code, which is not intended to be guest updatable, and is usually b= acked + // 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 Num; + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuUnifiedLib.c b/Ovm= fPkg/Library/NorFlashQemuLib/NorFlashQemuUnifiedLib.c new file mode 100644 index 000000000000..1420fb5b596c --- /dev/null +++ b/OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuUnifiedLib.c @@ -0,0 +1,40 @@ +/** @file + + Copyright (c) 2019, Linaro Ltd. All rights reserved + + SPDX-License-Identifier: BSD-2-Clause-Patent + + **/ + +#include +#include +#include + +#define QEMU_NOR_BLOCK_SIZE SIZE_256KB + +EFI_STATUS +NorFlashPlatformInitialization ( + VOID + ) +{ + return EFI_SUCCESS; +} + +NOR_FLASH_DESCRIPTION mNorFlashDevice =3D +{ + FixedPcdGet32 (PcdOvmfFdBaseAddress), + FixedPcdGet64 (PcdFlashNvStorageVariableBase), + FixedPcdGet32 (PcdOvmfFirmwareFdSize), + QEMU_NOR_BLOCK_SIZE +}; + +EFI_STATUS +NorFlashPlatformGetDevices ( + OUT NOR_FLASH_DESCRIPTION **NorFlashDescriptions, + OUT UINT32 *Count + ) +{ + *NorFlashDescriptions =3D &mNorFlashDevice; + *Count =3D 1; + return EFI_SUCCESS; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95138): https://edk2.groups.io/g/devel/message/95138 Mute This Topic: https://groups.io/mt/94300416/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 Sat May 18 17:16:06 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+95139+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+95139+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655210; cv=none; d=zohomail.com; s=zohoarc; b=SzCJWbx+c6Wdjn6pOq76XdbCsq/oI4NA9rs7HdbG8PzCkrkZOYL8jLNwLsKQMEYnIUkjb9pvAIse/KQcGjYqXYr5xBUtReFHvRXq8d9Fisft7DNFBGH7+p07QJ6QtVtt5oqNOf02cnjeLpML3sHNXF0FOiYS+unWOuI7vizXlyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655210; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Fp940q9InyFvAGL+QeeSTMF8jZ4buKOviArX+KY+oyE=; b=QhYdwn1LLq83WMhUa4qAROBCTapfZ1AWGQUFWhj+XJz0kluaX7pzer7lZbUZUo/uTr08PiWWVxEeWD3NAhErJofdjJhK81Mfnpcwu26H29RZOAOBBUI0nCcjCfpBZpPaOR0yTFglFZkkgxiskhInlbUxalo5I7qk8pDBSaCKWgY= 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+95139+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655210065890.6309179579983; Thu, 13 Oct 2022 03:00:10 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FcaQYY1788612xS4A0xl7fxV; Thu, 13 Oct 2022 03:00:07 -0700 X-Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by mx.groups.io with SMTP id smtpd.web10.5686.1665655206563496649 for ; Thu, 13 Oct 2022 03:00:06 -0700 X-Received: by mail-pj1-f41.google.com with SMTP id g8-20020a17090a128800b0020c79f987ceso4446168pja.5 for ; Thu, 13 Oct 2022 03:00:06 -0700 (PDT) X-Gm-Message-State: CraDZYS8qNS2MhrbqEfaeXqJx1787277AA= X-Google-Smtp-Source: AMsMyM7Px7KYLsiPd6tx3yLxFahZrUwOh8yJGq8dbY6F2OVEKiPItA1MpMVCsdSssCJyXs5uNKUeuA== X-Received: by 2002:a17:902:724b:b0:183:16f:fae4 with SMTP id c11-20020a170902724b00b00183016ffae4mr17316981pll.88.1665655204951; Thu, 13 Oct 2022 03:00:04 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.03.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 03:00:04 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 29/34] OvmfPkg: Add Qemu NOR flash DXE driver Date: Thu, 13 Oct 2022 15:28:24 +0530 Message-Id: <20221013095829.1454581-30-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655207; bh=izCikrt+XcMR46C5WmOzUbuiuXtz+r4h9OFB+GsKvl0=; h=Cc:Date:From:Reply-To:Subject:To; b=Hllq1g9W6193E9N9pHt8ITlXIUZdOhmzqaDZ5bfkJtXAAP/7DSM9oM8TslSPSeymLd3 fsu+AWpuEsi0Whz/ttI8rfC1ugTXQTiVxwQCgotPqwl+7zgzkMM4UuRP97U2mfmDSzsIl Xa799H+HxxY/zRvUY5dCm63U2OiZBCOyAl4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655212422100005 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 RISC-V needs NorFlashDxe driver for qemu virt machine. The ArmPlatformPkg has this driver but migrating it to generic package like MdeModulePkg introduces circular dependencies. So, add NorFlashDxe driver in OvmfPkg which is mostly the copy of the driver in ArmPlatformPkg except the support for PcdNorFlashCheckBlockLocked feature. This approach also allows to optimize the driver for virtual platforms. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Sunil V L --- OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.inf | 67 ++ .../NorFlashDxe/NorFlashStandaloneMm.inf | 61 ++ OvmfPkg/Drivers/NorFlashDxe/NorFlash.h | 422 ++++++++ OvmfPkg/Drivers/NorFlashDxe/NorFlash.c | 972 ++++++++++++++++++ .../Drivers/NorFlashDxe/NorFlashBlockIoDxe.c | 123 +++ OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c | 506 +++++++++ OvmfPkg/Drivers/NorFlashDxe/NorFlashFvb.c | 777 ++++++++++++++ .../NorFlashDxe/NorFlashStandaloneMm.c | 383 +++++++ 8 files changed, 3311 insertions(+) create mode 100644 OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.inf create mode 100644 OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf create mode 100644 OvmfPkg/Drivers/NorFlashDxe/NorFlash.h create mode 100644 OvmfPkg/Drivers/NorFlashDxe/NorFlash.c create mode 100644 OvmfPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c create mode 100644 OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c create mode 100644 OvmfPkg/Drivers/NorFlashDxe/NorFlashFvb.c create mode 100644 OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.inf b/OvmfPkg/Drivers/= NorFlashDxe/NorFlashDxe.inf new file mode 100644 index 000000000000..cc2f48bcb6bf --- /dev/null +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.inf @@ -0,0 +1,67 @@ +#/** @file +# +# Component description file for NorFlashDxe module +# +# Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D NorFlashDxe + FILE_GUID =3D D4F3B3FC-3AEF-4774-AC94-304438ABDA53 + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D NorFlashInitialise + +[Sources.common] + NorFlash.c + NorFlash.h + NorFlashDxe.c + NorFlashFvb.c + NorFlashBlockIoDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + IoLib + BaseLib + DebugLib + HobLib + NorFlashPlatformLib + UefiLib + UefiDriverEntryPoint + UefiBootServicesTableLib + UefiRuntimeLib + DxeServicesTableLib + +[Guids] + gEfiSystemNvDataFvGuid + gEfiVariableGuid + gEfiAuthenticatedVariableGuid + gEfiEventVirtualAddressChangeGuid + gEdkiiNvVarStoreFormattedGuid ## PRODUCES ## PROTOCOL + +[Protocols] + gEfiBlockIoProtocolGuid + gEfiDevicePathProtocolGuid + gEfiFirmwareVolumeBlockProtocolGuid + gEfiDiskIoProtocolGuid + +[Pcd.common] + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize + +[Depex] + gEfiCpuArchProtocolGuid diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf b/OvmfPkg= /Drivers/NorFlashDxe/NorFlashStandaloneMm.inf new file mode 100644 index 000000000000..18294c587d22 --- /dev/null +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf @@ -0,0 +1,61 @@ +#/** @file +# +# Component description file for NorFlashStandaloneMm module +# +# Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.
+# Copyright (c) 2020, Linaro, Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D NorFlashStandaloneMm + FILE_GUID =3D 9FFDD489-54D9-44EA-855E-E79FD6DF4E43 + MODULE_TYPE =3D MM_STANDALONE + VERSION_STRING =3D 1.0 + PI_SPECIFICATION_VERSION =3D 0x00010032 + ENTRY_POINT =3D NorFlashInitialise + +[Sources.common] + NorFlash.h + NorFlash.c + NorFlashStandaloneMm.c + NorFlashFvb.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + IoLib + MemoryAllocationLib + MmServicesTableLib + NorFlashPlatformLib + StandaloneMmDriverEntryPoint + +[Guids] + gEfiSystemNvDataFvGuid + gEfiVariableGuid + gEfiAuthenticatedVariableGuid + +[Protocols] + gEfiSmmFirmwareVolumeBlockProtocolGuid + +[FixedPcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize + +[Depex] + TRUE diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlash.h b/OvmfPkg/Drivers/NorFl= ashDxe/NorFlash.h new file mode 100644 index 000000000000..c83032e87d9c --- /dev/null +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlash.h @@ -0,0 +1,422 @@ +/** @file NorFlash.h + + Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __NOR_FLASH_H__ +#define __NOR_FLASH_H__ + +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#define NOR_FLASH_ERASE_RETRY 10 + +// Device access macros +// These are necessary because we use 2 x 16bit parts to make up 32bit data + +#define HIGH_16_BITS 0xFFFF0000 +#define LOW_16_BITS 0x0000FFFF +#define LOW_8_BITS 0x000000FF + +#define FOLD_32BIT_INTO_16BIT(value) ( ( value >> 16 ) | ( value & LOW_16= _BITS ) ) + +#define GET_LOW_BYTE(value) ( value & LOW_8_BITS ) +#define GET_HIGH_BYTE(value) ( GET_LOW_BYTE( value >> 16 ) ) + +// Each command must be sent simultaneously to both chips, +// i.e. at the lower 16 bits AND at the higher 16 bits +#define CREATE_NOR_ADDRESS(BaseAddr, OffsetAddr) ((BaseAddr) + ((Off= setAddr) << 2)) +#define CREATE_DUAL_CMD(Cmd) ( ( Cmd << 16) | ( = Cmd & LOW_16_BITS) ) +#define SEND_NOR_COMMAND(BaseAddr, Offset, Cmd) MmioWrite32 (CREATE= _NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd)) +#define GET_NOR_BLOCK_ADDRESS(BaseAddr, Lba, LbaSize) ( BaseAddr + (UINTN= )((Lba) * LbaSize) ) + +// Status Register Bits +#define P30_SR_BIT_WRITE (BIT7 << 16 | BIT7) +#define P30_SR_BIT_ERASE_SUSPEND (BIT6 << 16 | BIT6) +#define P30_SR_BIT_ERASE (BIT5 << 16 | BIT5) +#define P30_SR_BIT_PROGRAM (BIT4 << 16 | BIT4) +#define P30_SR_BIT_VPP (BIT3 << 16 | BIT3) +#define P30_SR_BIT_PROGRAM_SUSPEND (BIT2 << 16 | BIT2) +#define P30_SR_BIT_BLOCK_LOCKED (BIT1 << 16 | BIT1) +#define P30_SR_BIT_BEFP (BIT0 << 16 | BIT0) + +// Device Commands for Intel StrataFlash(R) Embedded Memory (P30) Family + +// On chip buffer size for buffered programming operations +// There are 2 chips, each chip can buffer up to 32 (16-bit)words, and eac= h word is 2 bytes. +// Therefore the total size of the buffer is 2 x 32 x 2 =3D 128 bytes +#define P30_MAX_BUFFER_SIZE_IN_BYTES ((UINTN)128) +#define P30_MAX_BUFFER_SIZE_IN_WORDS (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINT= N)4)) +#define MAX_BUFFERED_PROG_ITERATIONS 10000000 +#define BOUNDARY_OF_32_WORDS 0x7F + +// CFI Addresses +#define P30_CFI_ADDR_QUERY_UNIQUE_QRY 0x10 +#define P30_CFI_ADDR_VENDOR_ID 0x13 + +// CFI Data +#define CFI_QRY 0x00595251 + +// READ Commands +#define P30_CMD_READ_DEVICE_ID 0x0090 +#define P30_CMD_READ_STATUS_REGISTER 0x0070 +#define P30_CMD_CLEAR_STATUS_REGISTER 0x0050 +#define P30_CMD_READ_ARRAY 0x00FF +#define P30_CMD_READ_CFI_QUERY 0x0098 + +// WRITE Commands +#define P30_CMD_WORD_PROGRAM_SETUP 0x0040 +#define P30_CMD_ALTERNATE_WORD_PROGRAM_SETUP 0x0010 +#define P30_CMD_BUFFERED_PROGRAM_SETUP 0x00E8 +#define P30_CMD_BUFFERED_PROGRAM_CONFIRM 0x00D0 +#define P30_CMD_BEFP_SETUP 0x0080 +#define P30_CMD_BEFP_CONFIRM 0x00D0 + +// ERASE Commands +#define P30_CMD_BLOCK_ERASE_SETUP 0x0020 +#define P30_CMD_BLOCK_ERASE_CONFIRM 0x00D0 + +// SUSPEND Commands +#define P30_CMD_PROGRAM_OR_ERASE_SUSPEND 0x00B0 +#define P30_CMD_SUSPEND_RESUME 0x00D0 + +// BLOCK LOCKING / UNLOCKING Commands +#define P30_CMD_LOCK_BLOCK_SETUP 0x0060 +#define P30_CMD_LOCK_BLOCK 0x0001 +#define P30_CMD_UNLOCK_BLOCK 0x00D0 +#define P30_CMD_LOCK_DOWN_BLOCK 0x002F + +// PROTECTION Commands +#define P30_CMD_PROGRAM_PROTECTION_REGISTER_SETUP 0x00C0 + +// CONFIGURATION Commands +#define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP 0x0060 +#define P30_CMD_READ_CONFIGURATION_REGISTER 0x0003 + +#define NOR_FLASH_SIGNATURE SIGNATURE_32('n', 'o', 'r', '0') +#define INSTANCE_FROM_FVB_THIS(a) CR(a, NOR_FLASH_INSTANCE, FvbProtoco= l, NOR_FLASH_SIGNATURE) +#define INSTANCE_FROM_BLKIO_THIS(a) CR(a, NOR_FLASH_INSTANCE, BlockIoPro= tocol, NOR_FLASH_SIGNATURE) +#define INSTANCE_FROM_DISKIO_THIS(a) CR(a, NOR_FLASH_INSTANCE, DiskIoProt= ocol, NOR_FLASH_SIGNATURE) + +typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE; + +#pragma pack (1) +typedef struct { + VENDOR_DEVICE_PATH Vendor; + UINT8 Index; + EFI_DEVICE_PATH_PROTOCOL End; +} NOR_FLASH_DEVICE_PATH; +#pragma pack () + +struct _NOR_FLASH_INSTANCE { + UINT32 Signature; + EFI_HANDLE Handle; + + UINTN DeviceBaseAddress; + UINTN RegionBaseAddress; + UINTN Size; + EFI_LBA StartLba; + + EFI_BLOCK_IO_PROTOCOL BlockIoProtocol; + EFI_BLOCK_IO_MEDIA Media; + EFI_DISK_IO_PROTOCOL DiskIoProtocol; + + EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol; + VOID *ShadowBuffer; + + NOR_FLASH_DEVICE_PATH DevicePath; +}; + +EFI_STATUS +NorFlashReadCfiData ( + IN UINTN DeviceBaseAddress, + IN UINTN CFI_Offset, + IN UINT32 NumberOfBytes, + OUT UINT32 *Data + ); + +EFI_STATUS +NorFlashWriteBuffer ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN TargetAddress, + IN UINTN BufferSizeInBytes, + IN UINT32 *Buffer + ); + +// +// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset +// +EFI_STATUS +EFIAPI +NorFlashBlockIoReset ( + IN EFI_BLOCK_IO_PROTOCOL *This, + IN BOOLEAN ExtendedVerification + ); + +// +// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks +// +EFI_STATUS +EFIAPI +NorFlashBlockIoReadBlocks ( + IN EFI_BLOCK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + OUT VOID *Buffer + ); + +// +// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks +// +EFI_STATUS +EFIAPI +NorFlashBlockIoWriteBlocks ( + IN EFI_BLOCK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + IN VOID *Buffer + ); + +// +// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks +// +EFI_STATUS +EFIAPI +NorFlashBlockIoFlushBlocks ( + IN EFI_BLOCK_IO_PROTOCOL *This + ); + +// +// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.ReadDisk +// +EFI_STATUS +EFIAPI +NorFlashDiskIoReadDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 Offset, + IN UINTN BufferSize, + OUT VOID *Buffer + ); + +// +// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.WriteDisk +// +EFI_STATUS +EFIAPI +NorFlashDiskIoWriteDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 Offset, + IN UINTN BufferSize, + IN VOID *Buffer + ); + +// +// NorFlashFvbDxe.c +// + +EFI_STATUS +EFIAPI +FvbGetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ); + +EFI_STATUS +EFIAPI +FvbSetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ); + +EFI_STATUS +EFIAPI +FvbGetPhysicalAddress ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + OUT EFI_PHYSICAL_ADDRESS *Address + ); + +EFI_STATUS +EFIAPI +FvbGetBlockSize ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + OUT UINTN *BlockSize, + OUT UINTN *NumberOfBlocks + ); + +EFI_STATUS +EFIAPI +FvbRead ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN OUT UINT8 *Buffer + ); + +EFI_STATUS +EFIAPI +FvbWrite ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ); + +EFI_STATUS +EFIAPI +FvbEraseBlocks ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + ... + ); + +EFI_STATUS +ValidateFvHeader ( + IN NOR_FLASH_INSTANCE *Instance + ); + +EFI_STATUS +InitializeFvAndVariableStoreHeaders ( + IN NOR_FLASH_INSTANCE *Instance + ); + +VOID +EFIAPI +FvbVirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ); + +// +// NorFlashDxe.c +// + +EFI_STATUS +NorFlashWriteFullBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINT32 *DataBuffer, + IN UINT32 BlockSizeInWords + ); + +EFI_STATUS +NorFlashUnlockAndEraseSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ); + +EFI_STATUS +NorFlashCreateInstance ( + IN UINTN NorFlashDeviceBase, + IN UINTN NorFlashRegionBase, + IN UINTN NorFlashSize, + IN UINT32 Index, + IN UINT32 BlockSize, + IN BOOLEAN SupportFvb, + OUT NOR_FLASH_INSTANCE **NorFlashInstance + ); + +EFI_STATUS +EFIAPI +NorFlashFvbInitialize ( + IN NOR_FLASH_INSTANCE *Instance + ); + +// +// NorFlash.c +// +EFI_STATUS +NorFlashWriteSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ); + +EFI_STATUS +NorFlashWriteBlocks ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + IN VOID *Buffer + ); + +EFI_STATUS +NorFlashReadBlocks ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + OUT VOID *Buffer + ); + +EFI_STATUS +NorFlashRead ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN UINTN BufferSizeInBytes, + OUT VOID *Buffer + ); + +EFI_STATUS +NorFlashWrite ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ); + +EFI_STATUS +NorFlashReset ( + IN NOR_FLASH_INSTANCE *Instance + ); + +EFI_STATUS +NorFlashEraseSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ); + +EFI_STATUS +NorFlashUnlockSingleBlockIfNecessary ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ); + +EFI_STATUS +NorFlashWriteSingleWord ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN WordAddress, + IN UINT32 WriteData + ); + +VOID +EFIAPI +NorFlashVirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ); + +#endif /* __NOR_FLASH_H__ */ diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c b/OvmfPkg/Drivers/NorFl= ashDxe/NorFlash.c new file mode 100644 index 000000000000..c2a6aa281578 --- /dev/null +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c @@ -0,0 +1,972 @@ +/** @file NorFlash.c + + Copyright (c) 2011 - 2020, Arm Limited. All rights reserved.
+ Copyright (c) 2020, Linaro, Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include "NorFlash.h" + +// +// Global variable declarations +// +extern NOR_FLASH_INSTANCE **mNorFlashInstances; +extern UINT32 mNorFlashDeviceCount; + +UINT32 +NorFlashReadStatusRegister ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN SR_Address + ) +{ + // Prepare to read the status register + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_STATUS_RE= GISTER); + return MmioRead32 (Instance->DeviceBaseAddress); +} + +STATIC +BOOLEAN +NorFlashBlockIsLocked ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ) +{ + UINT32 LockStatus; + + // Send command for reading device id + SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID); + + // Read block lock status + LockStatus =3D MmioRead32 (CREATE_NOR_ADDRESS (BlockAddress, 2)); + + // Decode block lock status + LockStatus =3D FOLD_32BIT_INTO_16BIT (LockStatus); + + if ((LockStatus & 0x2) !=3D 0) { + DEBUG ((DEBUG_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOW= N\n")); + } + + return ((LockStatus & 0x1) !=3D 0); +} + +STATIC +EFI_STATUS +NorFlashUnlockSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ) +{ + UINT32 LockStatus; + + // Raise the Task Priority Level to TPL_NOTIFY to serialise all its oper= ations + // and to protect shared data structures. + + // Request a lock setup + SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_LOCK_BLOCK_SETUP); + + // Request an unlock + SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_UNLOCK_BLOCK); + + // Wait until the status register gives us the all clear + do { + LockStatus =3D NorFlashReadStatusRegister (Instance, BlockAddress); + } while ((LockStatus & P30_SR_BIT_WRITE) !=3D P30_SR_BIT_WRITE); + + // Put device back into Read Array mode + SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_READ_ARRAY); + + DEBUG ((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=3D0x%08x\n", Block= Address)); + + return EFI_SUCCESS; +} + +EFI_STATUS +NorFlashUnlockSingleBlockIfNecessary ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ) +{ + EFI_STATUS Status; + + Status =3D EFI_SUCCESS; + + if (NorFlashBlockIsLocked (Instance, BlockAddress)) { + Status =3D NorFlashUnlockSingleBlock (Instance, BlockAddress); + } + + return Status; +} + +/** + * The following function presumes that the block has already been unlocke= d. + **/ +EFI_STATUS +NorFlashEraseSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ) +{ + EFI_STATUS Status; + UINT32 StatusRegister; + + Status =3D EFI_SUCCESS; + + // Request a block erase and then confirm it + SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_BLOCK_ERASE_SETUP); + SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_BLOCK_ERASE_CONFIRM); + + // Wait until the status register gives us the all clear + do { + StatusRegister =3D NorFlashReadStatusRegister (Instance, BlockAddress); + } while ((StatusRegister & P30_SR_BIT_WRITE) !=3D P30_SR_BIT_WRITE); + + if (StatusRegister & P30_SR_BIT_VPP) { + DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=3D0x%08x: VPP Rang= e Error\n", BlockAddress)); + Status =3D EFI_DEVICE_ERROR; + } + + if ((StatusRegister & (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) =3D=3D (P= 30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) { + DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=3D0x%08x: Command = Sequence Error\n", BlockAddress)); + Status =3D EFI_DEVICE_ERROR; + } + + if (StatusRegister & P30_SR_BIT_ERASE) { + DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=3D0x%08x: Block Er= ase Error StatusRegister:0x%X\n", BlockAddress, StatusRegister)); + Status =3D EFI_DEVICE_ERROR; + } + + if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) { + // The debug level message has been reduced because a device lock migh= t happen. In this case we just retry it ... + DEBUG ((DEBUG_INFO, "EraseSingleBlock(BlockAddress=3D0x%08x: Block Loc= ked Error\n", BlockAddress)); + Status =3D EFI_WRITE_PROTECTED; + } + + if (EFI_ERROR (Status)) { + // Clear the Status Register + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS= _REGISTER); + } + + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + + return Status; +} + +EFI_STATUS +NorFlashWriteSingleWord ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN WordAddress, + IN UINT32 WriteData + ) +{ + EFI_STATUS Status; + UINT32 StatusRegister; + + Status =3D EFI_SUCCESS; + + // Request a write single word command + SEND_NOR_COMMAND (WordAddress, 0, P30_CMD_WORD_PROGRAM_SETUP); + + // Store the word into NOR Flash; + MmioWrite32 (WordAddress, WriteData); + + // Wait for the write to complete and then check for any errors; i.e. ch= eck the Status Register + do { + // Prepare to read the status register + StatusRegister =3D NorFlashReadStatusRegister (Instance, WordAddress); + // The chip is busy while the WRITE bit is not asserted + } while ((StatusRegister & P30_SR_BIT_WRITE) !=3D P30_SR_BIT_WRITE); + + // Perform a full status check: + // Mask the relevant bits of Status Register. + // Everything should be zero, if not, we have a problem + + if (StatusRegister & P30_SR_BIT_VPP) { + DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleWord(WordAddress:0x%X): VPP R= ange Error\n", WordAddress)); + Status =3D EFI_DEVICE_ERROR; + } + + if (StatusRegister & P30_SR_BIT_PROGRAM) { + DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleWord(WordAddress:0x%X): Progr= am Error\n", WordAddress)); + Status =3D EFI_DEVICE_ERROR; + } + + if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) { + DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleWord(WordAddress:0x%X): Devic= e Protect Error\n", WordAddress)); + Status =3D EFI_DEVICE_ERROR; + } + + if (!EFI_ERROR (Status)) { + // Clear the Status Register + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS= _REGISTER); + } + + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + + return Status; +} + +/* + * Writes data to the NOR Flash using the Buffered Programming method. + * + * The maximum size of the on-chip buffer is 32-words, because of hardware= restrictions. + * Therefore this function will only handle buffers up to 32 words or 128 = bytes. + * To deal with larger buffers, call this function again. + * + * This function presumes that both the TargetAddress and the TargetAddres= s+BufferSize + * exist entirely within the NOR Flash. Therefore these conditions will no= t be checked here. + * + * In buffered programming, if the target address not at the beginning of = a 32-bit word boundary, + * then programming time is doubled and power consumption is increased. + * Therefore, it is a requirement to align buffer writes to 32-bit word bo= undaries. + * i.e. the last 4 bits of the target start address must be zero: 0x......= 00 + */ +EFI_STATUS +NorFlashWriteBuffer ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN TargetAddress, + IN UINTN BufferSizeInBytes, + IN UINT32 *Buffer + ) +{ + EFI_STATUS Status; + UINTN BufferSizeInWords; + UINTN Count; + volatile UINT32 *Data; + UINTN WaitForBuffer; + BOOLEAN BufferAvailable; + UINT32 StatusRegister; + + WaitForBuffer =3D MAX_BUFFERED_PROG_ITERATIONS; + BufferAvailable =3D FALSE; + + // Check that the target address does not cross a 32-word boundary. + if ((TargetAddress & BOUNDARY_OF_32_WORDS) !=3D 0) { + return EFI_INVALID_PARAMETER; + } + + // Check there are some data to program + if (BufferSizeInBytes =3D=3D 0) { + return EFI_BUFFER_TOO_SMALL; + } + + // Check that the buffer size does not exceed the maximum hardware buffe= r size on chip. + if (BufferSizeInBytes > P30_MAX_BUFFER_SIZE_IN_BYTES) { + return EFI_BAD_BUFFER_SIZE; + } + + // Check that the buffer size is a multiple of 32-bit words + if ((BufferSizeInBytes % 4) !=3D 0) { + return EFI_BAD_BUFFER_SIZE; + } + + // Pre-programming conditions checked, now start the algorithm. + + // Prepare the data destination address + Data =3D (UINT32 *)TargetAddress; + + // Check the availability of the buffer + do { + // Issue the Buffered Program Setup command + SEND_NOR_COMMAND (TargetAddress, 0, P30_CMD_BUFFERED_PROGRAM_SETUP); + + // Read back the status register bit#7 from the same address + if (((*Data) & P30_SR_BIT_WRITE) =3D=3D P30_SR_BIT_WRITE) { + BufferAvailable =3D TRUE; + } + + // Update the loop counter + WaitForBuffer--; + } while ((WaitForBuffer > 0) && (BufferAvailable =3D=3D FALSE)); + + // The buffer was not available for writing + if (WaitForBuffer =3D=3D 0) { + Status =3D EFI_DEVICE_ERROR; + goto EXIT; + } + + // From now on we work in 32-bit words + BufferSizeInWords =3D BufferSizeInBytes / (UINTN)4; + + // Write the word count, which is (buffer_size_in_words - 1), + // because word count 0 means one word. + SEND_NOR_COMMAND (TargetAddress, 0, (BufferSizeInWords - 1)); + + // Write the data to the NOR Flash, advancing each address by 4 bytes + for (Count =3D 0; Count < BufferSizeInWords; Count++, Data++, Buffer++) { + MmioWrite32 ((UINTN)Data, *Buffer); + } + + // Issue the Buffered Program Confirm command, to start the programming = operation + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_BUFFERED_PROGR= AM_CONFIRM); + + // Wait for the write to complete and then check for any errors; i.e. ch= eck the Status Register + do { + StatusRegister =3D NorFlashReadStatusRegister (Instance, TargetAddress= ); + // The chip is busy while the WRITE bit is not asserted + } while ((StatusRegister & P30_SR_BIT_WRITE) !=3D P30_SR_BIT_WRITE); + + // Perform a full status check: + // Mask the relevant bits of Status Register. + // Everything should be zero, if not, we have a problem + + Status =3D EFI_SUCCESS; + + if (StatusRegister & P30_SR_BIT_VPP) { + DEBUG ((DEBUG_ERROR, "NorFlashWriteBuffer(TargetAddress:0x%X): VPP Ran= ge Error\n", TargetAddress)); + Status =3D EFI_DEVICE_ERROR; + } + + if (StatusRegister & P30_SR_BIT_PROGRAM) { + DEBUG ((DEBUG_ERROR, "NorFlashWriteBuffer(TargetAddress:0x%X): Program= Error\n", TargetAddress)); + Status =3D EFI_DEVICE_ERROR; + } + + if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) { + DEBUG ((DEBUG_ERROR, "NorFlashWriteBuffer(TargetAddress:0x%X): Device = Protect Error\n", TargetAddress)); + Status =3D EFI_DEVICE_ERROR; + } + + if (!EFI_ERROR (Status)) { + // Clear the Status Register + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS= _REGISTER); + } + +EXIT: + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + + return Status; +} + +EFI_STATUS +NorFlashWriteBlocks ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + IN VOID *Buffer + ) +{ + UINT32 *pWriteBuffer; + EFI_STATUS Status; + EFI_LBA CurrentBlock; + UINT32 BlockSizeInWords; + UINT32 NumBlocks; + UINT32 BlockCount; + + Status =3D EFI_SUCCESS; + + // The buffer must be valid + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (Instance->Media.ReadOnly =3D=3D TRUE) { + return EFI_WRITE_PROTECTED; + } + + // We must have some bytes to read + DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=3D0x%x\n", = BufferSizeInBytes)); + if (BufferSizeInBytes =3D=3D 0) { + return EFI_BAD_BUFFER_SIZE; + } + + // The size of the buffer must be a multiple of the block size + DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =3D0x%x\n"= , Instance->Media.BlockSize)); + if ((BufferSizeInBytes % Instance->Media.BlockSize) !=3D 0) { + return EFI_BAD_BUFFER_SIZE; + } + + // All blocks must be within the device + NumBlocks =3D ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize; + + DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=3D%d, LastBlock=3D%= ld, Lba=3D%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba)); + + if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) { + DEBUG ((DEBUG_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed l= ast block.\n")); + return EFI_INVALID_PARAMETER; + } + + BlockSizeInWords =3D Instance->Media.BlockSize / 4; + + // Because the target *Buffer is a pointer to VOID, we must put all the = data into a pointer + // to a proper data type, so use *ReadBuffer + pWriteBuffer =3D (UINT32 *)Buffer; + + CurrentBlock =3D Lba; + for (BlockCount =3D 0; BlockCount < NumBlocks; BlockCount++, CurrentBloc= k++, pWriteBuffer =3D pWriteBuffer + BlockSizeInWords) { + DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: Writing block #%d\n", (UINT= N)CurrentBlock)); + + Status =3D NorFlashWriteFullBlock (Instance, CurrentBlock, pWriteBuffe= r, BlockSizeInWords); + + if (EFI_ERROR (Status)) { + break; + } + } + + DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: Exit Status =3D \"%r\".\n", S= tatus)); + return Status; +} + +#define BOTH_ALIGNED(a, b, align) ((((UINTN)(a) | (UINTN)(b)) & ((align) = - 1)) =3D=3D 0) + +/** + Copy Length bytes from Source to Destination, using aligned accesses onl= y. + Note that this implementation uses memcpy() semantics rather then memmov= e() + semantics, i.e., SourceBuffer and DestinationBuffer should not overlap. + + @param DestinationBuffer The target of the copy request. + @param SourceBuffer The place to copy from. + @param Length The number of bytes to copy. + + @return Destination + +**/ +STATIC +VOID * +AlignedCopyMem ( + OUT VOID *DestinationBuffer, + IN CONST VOID *SourceBuffer, + IN UINTN Length + ) +{ + UINT8 *Destination8; + CONST UINT8 *Source8; + UINT32 *Destination32; + CONST UINT32 *Source32; + UINT64 *Destination64; + CONST UINT64 *Source64; + + if (BOTH_ALIGNED (DestinationBuffer, SourceBuffer, 8) && (Length >=3D 8)= ) { + Destination64 =3D DestinationBuffer; + Source64 =3D SourceBuffer; + while (Length >=3D 8) { + *Destination64++ =3D *Source64++; + Length -=3D 8; + } + + Destination8 =3D (UINT8 *)Destination64; + Source8 =3D (CONST UINT8 *)Source64; + } else if (BOTH_ALIGNED (DestinationBuffer, SourceBuffer, 4) && (Length = >=3D 4)) { + Destination32 =3D DestinationBuffer; + Source32 =3D SourceBuffer; + while (Length >=3D 4) { + *Destination32++ =3D *Source32++; + Length -=3D 4; + } + + Destination8 =3D (UINT8 *)Destination32; + Source8 =3D (CONST UINT8 *)Source32; + } else { + Destination8 =3D DestinationBuffer; + Source8 =3D SourceBuffer; + } + + while (Length-- !=3D 0) { + *Destination8++ =3D *Source8++; + } + + return DestinationBuffer; +} + +EFI_STATUS +NorFlashReadBlocks ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + OUT VOID *Buffer + ) +{ + UINT32 NumBlocks; + UINTN StartAddress; + + DEBUG (( + DEBUG_BLKIO, + "NorFlashReadBlocks: BufferSize=3D0x%xB BlockSize=3D0x%xB LastBlock=3D= %ld, Lba=3D%ld.\n", + BufferSizeInBytes, + Instance->Media.BlockSize, + Instance->Media.LastBlock, + Lba + )); + + // The buffer must be valid + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // Return if we have not any byte to read + if (BufferSizeInBytes =3D=3D 0) { + return EFI_SUCCESS; + } + + // The size of the buffer must be a multiple of the block size + if ((BufferSizeInBytes % Instance->Media.BlockSize) !=3D 0) { + return EFI_BAD_BUFFER_SIZE; + } + + // All blocks must be within the device + NumBlocks =3D ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize; + + if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) { + DEBUG ((DEBUG_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed las= t block\n")); + return EFI_INVALID_PARAMETER; + } + + // Get the address to start reading from + StartAddress =3D GET_NOR_BLOCK_ADDRESS ( + Instance->RegionBaseAddress, + Lba, + Instance->Media.BlockSize + ); + + // Put the device into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + + // Readout the data + AlignedCopyMem (Buffer, (VOID *)StartAddress, BufferSizeInBytes); + + return EFI_SUCCESS; +} + +EFI_STATUS +NorFlashRead ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN UINTN BufferSizeInBytes, + OUT VOID *Buffer + ) +{ + UINTN StartAddress; + + // The buffer must be valid + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // Return if we have not any byte to read + if (BufferSizeInBytes =3D=3D 0) { + return EFI_SUCCESS; + } + + if (((Lba * Instance->Media.BlockSize) + Offset + BufferSizeInBytes) > I= nstance->Size) { + DEBUG ((DEBUG_ERROR, "NorFlashRead: ERROR - Read will exceed device si= ze.\n")); + return EFI_INVALID_PARAMETER; + } + + // Get the address to start reading from + StartAddress =3D GET_NOR_BLOCK_ADDRESS ( + Instance->RegionBaseAddress, + Lba, + Instance->Media.BlockSize + ); + + // Put the device into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + + // Readout the data + AlignedCopyMem (Buffer, (VOID *)(StartAddress + Offset), BufferSizeInByt= es); + + return EFI_SUCCESS; +} + +/* + Write a full or portion of a block. It must not span block boundaries; t= hat is, + Offset + *NumBytes <=3D Instance->Media.BlockSize. +*/ +EFI_STATUS +NorFlashWriteSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ) +{ + EFI_STATUS TempStatus; + UINT32 Tmp; + UINT32 TmpBuf; + UINT32 WordToWrite; + UINT32 Mask; + BOOLEAN DoErase; + UINTN BytesToWrite; + UINTN CurOffset; + UINTN WordAddr; + UINTN BlockSize; + UINTN BlockAddress; + UINTN PrevBlockAddress; + + PrevBlockAddress =3D 0; + + DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=3D%ld, Of= fset=3D0x%x, *NumBytes=3D0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes,= Buffer)); + + // Detect WriteDisabled state + if (Instance->Media.ReadOnly =3D=3D TRUE) { + DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - Can not write:= Device is in WriteDisabled state.\n")); + // It is in WriteDisabled state, return an error right away + return EFI_ACCESS_DENIED; + } + + // Cache the block size to avoid de-referencing pointers all the time + BlockSize =3D Instance->Media.BlockSize; + + // The write must not span block boundaries. + // We need to check each variable individually because adding two large = values together overflows. + if ((Offset >=3D BlockSize) || + (*NumBytes > BlockSize) || + ((Offset + *NumBytes) > BlockSize)) + { + DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER= _SIZE: (Offset=3D0x%x + NumBytes=3D0x%x) > BlockSize=3D0x%x\n", Offset, *Nu= mBytes, BlockSize)); + return EFI_BAD_BUFFER_SIZE; + } + + // We must have some bytes to write + if (*NumBytes =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER= _SIZE: (Offset=3D0x%x + NumBytes=3D0x%x) > BlockSize=3D0x%x\n", Offset, *Nu= mBytes, BlockSize)); + return EFI_BAD_BUFFER_SIZE; + } + + // Pick 128bytes as a good start for word operations as opposed to erasi= ng the + // block and writing the data regardless if an erase is really needed. + // It looks like most individual NV variable writes are smaller than 128= bytes. + if (*NumBytes <=3D 128) { + // Check to see if we need to erase before programming the data into N= OR. + // If the destination bits are only changing from 1s to 0s we can just= write. + // After a block is erased all bits in the block is set to 1. + // If any byte requires us to erase we just give up and rewrite all of= it. + DoErase =3D FALSE; + BytesToWrite =3D *NumBytes; + CurOffset =3D Offset; + + while (BytesToWrite > 0) { + // Read full word from NOR, splice as required. A word is the smalle= st + // unit we can write. + TempStatus =3D NorFlashRead (Instance, Lba, CurOffset & ~(0x3), size= of (Tmp), &Tmp); + if (EFI_ERROR (TempStatus)) { + return EFI_DEVICE_ERROR; + } + + // Physical address of word in NOR to write. + WordAddr =3D (CurOffset & ~(0x3)) + GET_NOR_BLOCK_ADDRESS ( + Instance->RegionBaseAddress, + Lba, + BlockSize + ); + // The word of data that is to be written. + TmpBuf =3D *((UINT32 *)(Buffer + (*NumBytes - BytesToWrite))); + + // First do word aligned chunks. + if ((CurOffset & 0x3) =3D=3D 0) { + if (BytesToWrite >=3D 4) { + // Is the destination still in 'erased' state? + if (~Tmp !=3D 0) { + // Check to see if we are only changing bits to zero. + if ((Tmp ^ TmpBuf) & TmpBuf) { + DoErase =3D TRUE; + break; + } + } + + // Write this word to NOR + WordToWrite =3D TmpBuf; + CurOffset +=3D sizeof (TmpBuf); + BytesToWrite -=3D sizeof (TmpBuf); + } else { + // BytesToWrite < 4. Do small writes and left-overs + Mask =3D ~((~0) << (BytesToWrite * 8)); + // Mask out the bytes we want. + TmpBuf &=3D Mask; + // Is the destination still in 'erased' state? + if ((Tmp & Mask) !=3D Mask) { + // Check to see if we are only changing bits to zero. + if ((Tmp ^ TmpBuf) & TmpBuf) { + DoErase =3D TRUE; + break; + } + } + + // Merge old and new data. Write merged word to NOR + WordToWrite =3D (Tmp & ~Mask) | TmpBuf; + CurOffset +=3D BytesToWrite; + BytesToWrite =3D 0; + } + } else { + // Do multiple words, but starting unaligned. + if (BytesToWrite > (4 - (CurOffset & 0x3))) { + Mask =3D ((~0) << ((CurOffset & 0x3) * 8)); + // Mask out the bytes we want. + TmpBuf &=3D Mask; + // Is the destination still in 'erased' state? + if ((Tmp & Mask) !=3D Mask) { + // Check to see if we are only changing bits to zero. + if ((Tmp ^ TmpBuf) & TmpBuf) { + DoErase =3D TRUE; + break; + } + } + + // Merge old and new data. Write merged word to NOR + WordToWrite =3D (Tmp & ~Mask) | TmpBuf; + BytesToWrite -=3D (4 - (CurOffset & 0x3)); + CurOffset +=3D (4 - (CurOffset & 0x3)); + } else { + // Unaligned and fits in one word. + Mask =3D (~((~0) << (BytesToWrite * 8))) << ((CurOffset & 0x3) *= 8); + // Mask out the bytes we want. + TmpBuf =3D (TmpBuf << ((CurOffset & 0x3) * 8)) & Mask; + // Is the destination still in 'erased' state? + if ((Tmp & Mask) !=3D Mask) { + // Check to see if we are only changing bits to zero. + if ((Tmp ^ TmpBuf) & TmpBuf) { + DoErase =3D TRUE; + break; + } + } + + // Merge old and new data. Write merged word to NOR + WordToWrite =3D (Tmp & ~Mask) | TmpBuf; + CurOffset +=3D BytesToWrite; + BytesToWrite =3D 0; + } + } + + // + // Write the word to NOR. + // + + BlockAddress =3D GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,= Lba, BlockSize); + if (BlockAddress !=3D PrevBlockAddress) { + TempStatus =3D NorFlashUnlockSingleBlockIfNecessary (Instance, Blo= ckAddress); + if (EFI_ERROR (TempStatus)) { + return EFI_DEVICE_ERROR; + } + + PrevBlockAddress =3D BlockAddress; + } + + TempStatus =3D NorFlashWriteSingleWord (Instance, WordAddr, WordToWr= ite); + if (EFI_ERROR (TempStatus)) { + return EFI_DEVICE_ERROR; + } + } + + // Exit if we got here and could write all the data. Otherwise do the + // Erase-Write cycle. + if (!DoErase) { + return EFI_SUCCESS; + } + } + + // Check we did get some memory. Buffer is BlockSize. + if (Instance->ShadowBuffer =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "FvbWrite: ERROR - Buffer not ready\n")); + return EFI_DEVICE_ERROR; + } + + // Read NOR Flash data into shadow buffer + TempStatus =3D NorFlashReadBlocks (Instance, Lba, BlockSize, Instance->S= hadowBuffer); + if (EFI_ERROR (TempStatus)) { + // Return one of the pre-approved error statuses + return EFI_DEVICE_ERROR; + } + + // Put the data at the appropriate location inside the buffer area + CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumB= ytes); + + // Write the modified buffer back to the NorFlash + TempStatus =3D NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->= ShadowBuffer); + if (EFI_ERROR (TempStatus)) { + // Return one of the pre-approved error statuses + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} + +/* + Although DiskIoDxe will automatically install the DiskIO protocol whenev= er + we install the BlockIO protocol, its implementation is sub-optimal as it= reads + and writes entire blocks using the BlockIO protocol. In fact we can acce= ss + NOR flash with a finer granularity than that, so we can improve performa= nce + by directly producing the DiskIO protocol. +*/ + +/** + Read BufferSize bytes from Offset into Buffer. + + @param This Protocol instance pointer. + @param MediaId Id of the media, changes every time the me= dia is replaced. + @param Offset The starting byte offset to read from + @param BufferSize Size of Buffer + @param Buffer Buffer containing read data + + @retval EFI_SUCCESS The data was read correctly from the devic= e. + @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the read. + @retval EFI_NO_MEDIA There is no media in the device. + @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice. + @retval EFI_INVALID_PARAMETER The read request contains device addresses= that are not + valid for the device. + +**/ +EFI_STATUS +EFIAPI +NorFlashDiskIoReadDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 DiskOffset, + IN UINTN BufferSize, + OUT VOID *Buffer + ) +{ + NOR_FLASH_INSTANCE *Instance; + UINT32 BlockSize; + UINT32 BlockOffset; + EFI_LBA Lba; + + Instance =3D INSTANCE_FROM_DISKIO_THIS (This); + + if (MediaId !=3D Instance->Media.MediaId) { + return EFI_MEDIA_CHANGED; + } + + BlockSize =3D Instance->Media.BlockSize; + Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset); + + return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer); +} + +/** + Writes a specified number of bytes to a device. + + @param This Indicates a pointer to the calling context. + @param MediaId ID of the medium to be written. + @param Offset The starting byte offset on the logical block I/O dev= ice to write. + @param BufferSize The size in bytes of Buffer. The number of bytes to w= rite to the device. + @param Buffer A pointer to the buffer containing the data to be wri= tten. + + @retval EFI_SUCCESS The data was written correctly to the devi= ce. + @retval EFI_WRITE_PROTECTED The device can not be written to. + @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the write. + @retval EFI_NO_MEDIA There is no media in the device. + @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice. + @retval EFI_INVALID_PARAMETER The write request contains device addresse= s that are not + valid for the device. + +**/ +EFI_STATUS +EFIAPI +NorFlashDiskIoWriteDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 DiskOffset, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + NOR_FLASH_INSTANCE *Instance; + UINT32 BlockSize; + UINT32 BlockOffset; + EFI_LBA Lba; + UINTN RemainingBytes; + UINTN WriteSize; + EFI_STATUS Status; + + Instance =3D INSTANCE_FROM_DISKIO_THIS (This); + + if (MediaId !=3D Instance->Media.MediaId) { + return EFI_MEDIA_CHANGED; + } + + BlockSize =3D Instance->Media.BlockSize; + Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset); + + RemainingBytes =3D BufferSize; + + // Write either all the remaining bytes, or the number of bytes that bri= ng + // us up to a block boundary, whichever is less. + // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next + // block boundary (even if it is already on one). + WriteSize =3D MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1) = - DiskOffset); + + do { + if (WriteSize =3D=3D BlockSize) { + // Write a full block + Status =3D NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSize = / sizeof (UINT32)); + } else { + // Write a partial block + Status =3D NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &Wr= iteSize, Buffer); + } + + if (EFI_ERROR (Status)) { + return Status; + } + + // Now continue writing either all the remaining bytes or single block= s. + RemainingBytes -=3D WriteSize; + Buffer =3D (UINT8 *)Buffer + WriteSize; + Lba++; + BlockOffset =3D 0; + WriteSize =3D MIN (RemainingBytes, BlockSize); + } while (RemainingBytes); + + return Status; +} + +EFI_STATUS +NorFlashReset ( + IN NOR_FLASH_INSTANCE *Instance + ) +{ + // As there is no specific RESET to perform, ensure that the devices is = in the default Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + return EFI_SUCCESS; +} + +/** + 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 +**/ +VOID +EFIAPI +NorFlashVirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + UINTN Index; + + for (Index =3D 0; Index < mNorFlashDeviceCount; Index++) { + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->DeviceBas= eAddress); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->RegionBas= eAddress); + + // Convert BlockIo protocol + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoPr= otocol.FlushBlocks); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoPr= otocol.ReadBlocks); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoPr= otocol.Reset); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoPr= otocol.WriteBlocks); + + // Convert Fvb + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtoc= ol.EraseBlocks); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtoc= ol.GetAttributes); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtoc= ol.GetBlockSize); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtoc= ol.GetPhysicalAddress); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtoc= ol.Read); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtoc= ol.SetAttributes); + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtoc= ol.Write); + + if (mNorFlashInstances[Index]->ShadowBuffer !=3D NULL) { + EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->ShadowB= uffer); + } + } + + return; +} diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c b/OvmfPkg/Dri= vers/NorFlashDxe/NorFlashBlockIoDxe.c new file mode 100644 index 000000000000..9d4732c6905a --- /dev/null +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c @@ -0,0 +1,123 @@ +/** @file NorFlashBlockIoDxe.c + + Copyright (c) 2011-2013, ARM Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include "NorFlash.h" + +// +// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset +// +EFI_STATUS +EFIAPI +NorFlashBlockIoReset ( + IN EFI_BLOCK_IO_PROTOCOL *This, + IN BOOLEAN ExtendedVerification + ) +{ + NOR_FLASH_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_BLKIO_THIS (This); + + DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=3D0x%x)\n", This->Med= ia->MediaId)); + + return NorFlashReset (Instance); +} + +// +// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks +// +EFI_STATUS +EFIAPI +NorFlashBlockIoReadBlocks ( + IN EFI_BLOCK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + OUT VOID *Buffer + ) +{ + NOR_FLASH_INSTANCE *Instance; + EFI_STATUS Status; + EFI_BLOCK_IO_MEDIA *Media; + + if (This =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Instance =3D INSTANCE_FROM_BLKIO_THIS (This); + Media =3D This->Media; + + DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=3D0x%x, Lba=3D%l= d, BufferSize=3D0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, B= ufferSizeInBytes, BufferSizeInBytes, Buffer)); + + if (!Media) { + Status =3D EFI_INVALID_PARAMETER; + } else if (!Media->MediaPresent) { + Status =3D EFI_NO_MEDIA; + } else if (Media->MediaId !=3D MediaId) { + Status =3D EFI_MEDIA_CHANGED; + } else if ((Media->IoAlign > 2) && (((UINTN)Buffer & (Media->IoAlign - 1= )) !=3D 0)) { + Status =3D EFI_INVALID_PARAMETER; + } else { + Status =3D NorFlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffe= r); + } + + return Status; +} + +// +// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks +// +EFI_STATUS +EFIAPI +NorFlashBlockIoWriteBlocks ( + IN EFI_BLOCK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + IN VOID *Buffer + ) +{ + NOR_FLASH_INSTANCE *Instance; + EFI_STATUS Status; + + Instance =3D INSTANCE_FROM_BLKIO_THIS (This); + + DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=3D0x%x, Lba=3D%= ld, BufferSize=3D0x%x bytes, BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSi= zeInBytes, Buffer)); + + if ( !This->Media->MediaPresent ) { + Status =3D EFI_NO_MEDIA; + } else if ( This->Media->MediaId !=3D MediaId ) { + Status =3D EFI_MEDIA_CHANGED; + } else if ( This->Media->ReadOnly ) { + Status =3D EFI_WRITE_PROTECTED; + } else { + Status =3D NorFlashWriteBlocks (Instance, Lba, BufferSizeInBytes, Buff= er); + } + + return Status; +} + +// +// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks +// +EFI_STATUS +EFIAPI +NorFlashBlockIoFlushBlocks ( + IN EFI_BLOCK_IO_PROTOCOL *This + ) +{ + // No Flush required for the NOR Flash driver + // because cache operations are not permitted. + + DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENT= ED (not required).\n")); + + // Nothing to do so just return without error + return EFI_SUCCESS; +} diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/OvmfPkg/Drivers/No= rFlashDxe/NorFlashDxe.c new file mode 100644 index 000000000000..f7b92de21a57 --- /dev/null +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -0,0 +1,506 @@ +/** @file NorFlashDxe.c + + Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include + +#include "NorFlash.h" + +STATIC EFI_EVENT mNorFlashVirtualAddrChangeEvent; + +// +// Global variable declarations +// +NOR_FLASH_INSTANCE **mNorFlashInstances; +UINT32 mNorFlashDeviceCount; +UINTN mFlashNvStorageVariableBase; +EFI_EVENT mFvbVirtualAddrChangeEvent; + +NOR_FLASH_INSTANCE mNorFlashInstanceTemplate =3D { + NOR_FLASH_SIGNATURE, // Signature + NULL, // Handle ... NEED TO BE FILLED + + 0, // DeviceBaseAddress ... NEED TO BE FILLED + 0, // RegionBaseAddress ... NEED TO BE FILLED + 0, // Size ... NEED TO BE FILLED + 0, // StartLba + + { + EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision + NULL, // Media ... NEED TO BE FILLED + NorFlashBlockIoReset, // Reset; + NorFlashBlockIoReadBlocks, // ReadBlocks + NorFlashBlockIoWriteBlocks, // WriteBlocks + NorFlashBlockIoFlushBlocks // FlushBlocks + }, // BlockIoProtocol + + { + 0, // MediaId ... NEED TO BE FILLED + FALSE, // RemovableMedia + TRUE, // MediaPresent + FALSE, // LogicalPartition + FALSE, // ReadOnly + FALSE, // WriteCaching; + 0, // BlockSize ... NEED TO BE FILLED + 4, // IoAlign + 0, // LastBlock ... NEED TO BE FILLED + 0, // LowestAlignedLba + 1, // LogicalBlocksPerPhysicalBlock + }, // Media; + + { + EFI_DISK_IO_PROTOCOL_REVISION, // Revision + NorFlashDiskIoReadDisk, // ReadDisk + NorFlashDiskIoWriteDisk // WriteDisk + }, + + { + FvbGetAttributes, // GetAttributes + FvbSetAttributes, // SetAttributes + FvbGetPhysicalAddress, // GetPhysicalAddress + FvbGetBlockSize, // GetBlockSize + FvbRead, // Read + FvbWrite, // Write + FvbEraseBlocks, // EraseBlocks + NULL, // ParentHandle + }, // FvbProtoccol; + NULL, // ShadowBuffer + { + { + { + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + { + (UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End)), + (UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8) + } + }, + { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0,= 0x0, 0x0, 0x0, 0x0 } + }, // GU= ID ... NEED TO BE FILLED + }, + 0, // Index + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 } + } + } // DevicePath +}; + +EFI_STATUS +NorFlashCreateInstance ( + IN UINTN NorFlashDeviceBase, + IN UINTN NorFlashRegionBase, + IN UINTN NorFlashSize, + IN UINT32 Index, + IN UINT32 BlockSize, + IN BOOLEAN SupportFvb, + OUT NOR_FLASH_INSTANCE **NorFlashInstance + ) +{ + EFI_STATUS Status; + NOR_FLASH_INSTANCE *Instance; + + ASSERT (NorFlashInstance !=3D NULL); + + Instance =3D AllocateRuntimeCopyPool (sizeof (NOR_FLASH_INSTANCE), &mNor= FlashInstanceTemplate); + if (Instance =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Instance->DeviceBaseAddress =3D NorFlashDeviceBase; + Instance->RegionBaseAddress =3D NorFlashRegionBase; + Instance->Size =3D NorFlashSize; + + Instance->BlockIoProtocol.Media =3D &Instance->Media; + Instance->Media.MediaId =3D Index; + Instance->Media.BlockSize =3D BlockSize; + Instance->Media.LastBlock =3D (NorFlashSize / BlockSize)-1; + + CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid); + Instance->DevicePath.Index =3D (UINT8)Index; + + Instance->ShadowBuffer =3D AllocateRuntimePool (BlockSize); + if (Instance->ShadowBuffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + if (SupportFvb) { + NorFlashFvbInitialize (Instance); + + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &Instance->Handle, + &gEfiDevicePathProtocolGuid, + &Instance->DevicePath, + &gEfiBlockIoProtocolGuid, + &Instance->BlockIoProtocol, + &gEfiFirmwareVolumeBlockProtocolGuid, + &Instance->FvbProtocol, + NULL + ); + if (EFI_ERROR (Status)) { + FreePool (Instance); + return Status; + } + } else { + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &Instance->Handle, + &gEfiDevicePathProtocolGuid, + &Instance->DevicePath, + &gEfiBlockIoProtocolGuid, + &Instance->BlockIoProtocol, + &gEfiDiskIoProtocolGuid, + &Instance->DiskIoProtocol, + NULL + ); + if (EFI_ERROR (Status)) { + FreePool (Instance); + return Status; + } + } + + *NorFlashInstance =3D Instance; + return Status; +} + +/** + * This function unlock and erase an entire NOR Flash block. + **/ +EFI_STATUS +NorFlashUnlockAndEraseSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ) +{ + EFI_STATUS Status; + UINTN Index; + EFI_TPL OriginalTPL; + + if (!EfiAtRuntime ()) { + // Raise TPL to TPL_HIGH to stop anyone from interrupting us. + OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); + } else { + // This initialization is only to prevent the compiler to complain abo= ut the + // use of uninitialized variables + OriginalTPL =3D TPL_HIGH_LEVEL; + } + + Index =3D 0; + // The block erase might fail a first time (SW bug ?). Retry it ... + do { + // Unlock the block if we have to + Status =3D NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddres= s); + if (EFI_ERROR (Status)) { + break; + } + + Status =3D NorFlashEraseSingleBlock (Instance, BlockAddress); + Index++; + } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status =3D=3D EFI_WRITE_PRO= TECTED)); + + if (Index =3D=3D NOR_FLASH_ERASE_RETRY) { + DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=3D0x%08x: Block Lo= cked Error (try to erase %d times)\n", BlockAddress, Index)); + } + + if (!EfiAtRuntime ()) { + // Interruptions can resume. + gBS->RestoreTPL (OriginalTPL); + } + + return Status; +} + +EFI_STATUS +NorFlashWriteFullBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINT32 *DataBuffer, + IN UINT32 BlockSizeInWords + ) +{ + EFI_STATUS Status; + UINTN WordAddress; + UINT32 WordIndex; + UINTN BufferIndex; + UINTN BlockAddress; + UINTN BuffersInBlock; + UINTN RemainingWords; + EFI_TPL OriginalTPL; + UINTN Cnt; + + Status =3D EFI_SUCCESS; + + // Get the physical address of the block + BlockAddress =3D GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba= , BlockSizeInWords * 4); + + // Start writing from the first address at the start of the block + WordAddress =3D BlockAddress; + + if (!EfiAtRuntime ()) { + // Raise TPL to TPL_HIGH to stop anyone from interrupting us. + OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); + } else { + // This initialization is only to prevent the compiler to complain abo= ut the + // use of uninitialized variables + OriginalTPL =3D TPL_HIGH_LEVEL; + } + + Status =3D NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and E= rase the single block at 0x%X\n", BlockAddress)); + goto EXIT; + } + + // To speed up the programming operation, NOR Flash is programmed using = the Buffered Programming method. + + // Check that the address starts at a 32-word boundary, i.e. last 7 bits= must be zero + if ((WordAddress & BOUNDARY_OF_32_WORDS) =3D=3D 0x00) { + // First, break the entire block into buffer-sized chunks. + BuffersInBlock =3D (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE= _IN_BYTES; + + // Then feed each buffer chunk to the NOR Flash + // If a buffer does not contain any data, don't write it. + for (BufferIndex =3D 0; + BufferIndex < BuffersInBlock; + BufferIndex++, WordAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES, Dat= aBuffer +=3D P30_MAX_BUFFER_SIZE_IN_WORDS + ) + { + // Check the buffer to see if it contains any data (not set all 1s). + for (Cnt =3D 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) { + if (~DataBuffer[Cnt] !=3D 0 ) { + // Some data found, write the buffer. + Status =3D NorFlashWriteBuffer ( + Instance, + WordAddress, + P30_MAX_BUFFER_SIZE_IN_BYTES, + DataBuffer + ); + if (EFI_ERROR (Status)) { + goto EXIT; + } + + break; + } + } + } + + // Finally, finish off any remaining words that are less than the maxi= mum size of the buffer + RemainingWords =3D BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS; + + if (RemainingWords !=3D 0) { + Status =3D NorFlashWriteBuffer (Instance, WordAddress, (RemainingWor= ds * 4), DataBuffer); + if (EFI_ERROR (Status)) { + goto EXIT; + } + } + } else { + // For now, use the single word programming algorithm + // It is unlikely that the NOR Flash will exist in an address which fa= lls within a 32 word boundary range, + // i.e. which ends in the range 0x......01 - 0x......7F. + for (WordIndex =3D 0; WordIndex < BlockSizeInWords; WordIndex++, DataB= uffer++, WordAddress =3D WordAddress + 4) { + Status =3D NorFlashWriteSingleWord (Instance, WordAddress, *DataBuff= er); + if (EFI_ERROR (Status)) { + goto EXIT; + } + } + } + +EXIT: + if (!EfiAtRuntime ()) { + // Interruptions can resume. + gBS->RestoreTPL (OriginalTPL); + } + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed = at address 0x%08x. Exit Status =3D \"%r\".\n", WordAddress, Status)); + } + + return Status; +} + +EFI_STATUS +EFIAPI +NorFlashInitialise ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UINT32 Index; + NOR_FLASH_DESCRIPTION *NorFlashDevices; + BOOLEAN ContainVariableStorage; + + Status =3D NorFlashPlatformInitialization (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to initialize Nor Flash= devices\n")); + return Status; + } + + Status =3D NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDevic= eCount); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to get Nor Flash device= s\n")); + return Status; + } + + mNorFlashInstances =3D AllocateRuntimePool (sizeof (NOR_FLASH_INSTANCE *= ) * mNorFlashDeviceCount); + + for (Index =3D 0; Index < mNorFlashDeviceCount; Index++) { + // Check if this NOR Flash device contain the variable storage region + + if (PcdGet64 (PcdFlashNvStorageVariableBase64) !=3D 0) { + ContainVariableStorage =3D + (NorFlashDevices[Index].RegionBaseAddress <=3D PcdGet64 (PcdFlashN= vStorageVariableBase64)) && + (PcdGet64 (PcdFlashNvStorageVariableBase64) + PcdGet32 (PcdFlashNv= StorageVariableSize) <=3D + NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index]= .Size); + } else { + ContainVariableStorage =3D + (NorFlashDevices[Index].RegionBaseAddress <=3D PcdGet32 (PcdFlashN= vStorageVariableBase)) && + (PcdGet32 (PcdFlashNvStorageVariableBase) + PcdGet32 (PcdFlashNvSt= orageVariableSize) <=3D + NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index]= .Size); + } + + Status =3D NorFlashCreateInstance ( + NorFlashDevices[Index].DeviceBaseAddress, + NorFlashDevices[Index].RegionBaseAddress, + NorFlashDevices[Index].Size, + Index, + NorFlashDevices[Index].BlockSize, + ContainVariableStorage, + &mNorFlashInstances[Index] + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to create instance fo= r NorFlash[%d]\n", Index)); + } + } + + // + // Register for the virtual address change event + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + NorFlashVirtualNotifyEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &mNorFlashVirtualAddrChangeEvent + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +EFI_STATUS +EFIAPI +NorFlashFvbInitialize ( + IN NOR_FLASH_INSTANCE *Instance + ) +{ + EFI_STATUS Status; + UINT32 FvbNumLba; + EFI_BOOT_MODE BootMode; + UINTN RuntimeMmioRegionSize; + + DEBUG ((DEBUG_BLKIO, "NorFlashFvbInitialize\n")); + ASSERT ((Instance !=3D NULL)); + + // + // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME + // + + // Note: all the NOR Flash region needs to be reserved into the UEFI Run= time memory; + // even if we only use the small block region at the top of the NO= R Flash. + // The reason is when the NOR Flash memory is set into program mod= e, the command + // is written as the base of the flash region (ie: Instance->Devic= eBaseAddress) + RuntimeMmioRegionSize =3D (Instance->RegionBaseAddress - Instance->Devic= eBaseAddress) + Instance->Size; + + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypeMemoryMappedIo, + Instance->DeviceBaseAddress, + RuntimeMmioRegionSize, + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + ASSERT_EFI_ERROR (Status); + + Status =3D gDS->SetMemorySpaceAttributes ( + Instance->DeviceBaseAddress, + RuntimeMmioRegionSize, + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + ASSERT_EFI_ERROR (Status); + + mFlashNvStorageVariableBase =3D (PcdGet64 (PcdFlashNvStorageVariableBase= 64) !=3D 0) ? + PcdGet64 (PcdFlashNvStorageVariableBase64)= : PcdGet32 (PcdFlashNvStorageVariableBase); + + // Set the index of the first LBA for the FVB + Instance->StartLba =3D (mFlashNvStorageVariableBase - Instance->RegionBa= seAddress) / Instance->Media.BlockSize; + + BootMode =3D GetBootModeHob (); + if (BootMode =3D=3D BOOT_WITH_DEFAULT_SETTINGS) { + Status =3D EFI_INVALID_PARAMETER; + } else { + // Determine if there is a valid header at the beginning of the NorFla= sh + Status =3D ValidateFvHeader (Instance); + } + + // Install the Default FVB header if required + if (EFI_ERROR (Status)) { + // There is no valid header, so time to install one. + DEBUG ((DEBUG_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__= )); + DEBUG (( + DEBUG_INFO, + "%a: Installing a correct one for this volume.\n", + __FUNCTION__ + )); + + // Erase all the NorFlash that is reserved for variable storage + FvbNumLba =3D (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (Pc= dFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) = / Instance->Media.BlockSize; + + Status =3D FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumL= ba, EFI_LBA_LIST_TERMINATOR); + if (EFI_ERROR (Status)) { + return Status; + } + + // Install all appropriate headers + Status =3D InitializeFvAndVariableStoreHeaders (Instance); + if (EFI_ERROR (Status)) { + return Status; + } + } + + // + // The driver implementing the variable read service can now be dispatch= ed; + // the varstore headers are in place. + // + Status =3D gBS->InstallProtocolInterface ( + &gImageHandle, + &gEdkiiNvVarStoreFormattedGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + ASSERT_EFI_ERROR (Status); + + // + // Register for the virtual address change event + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + FvbVirtualNotifyEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &mFvbVirtualAddrChangeEvent + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashFvb.c b/OvmfPkg/Drivers/No= rFlashDxe/NorFlashFvb.c new file mode 100644 index 000000000000..0767581308d2 --- /dev/null +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashFvb.c @@ -0,0 +1,777 @@ +/*++ @file NorFlashFvbDxe.c + + Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + --*/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "NorFlash.h" + +extern UINTN mFlashNvStorageVariableBase; +/// +/// The Firmware Volume Block Protocol is the low-level interface +/// to a firmware volume. File-level access to a firmware volume +/// should not be done using the Firmware Volume Block Protocol. +/// Normal access to a firmware volume must use the Firmware +/// Volume Protocol. Typically, only the file system driver that +/// produces the Firmware Volume Protocol will bind to the +/// Firmware Volume Block Protocol. +/// + +/** + Initialises the FV Header and Variable Store Header + to support variable operations. + + @param[in] Ptr - Location to initialise the headers + +**/ +EFI_STATUS +InitializeFvAndVariableStoreHeaders ( + IN NOR_FLASH_INSTANCE *Instance + ) +{ + EFI_STATUS Status; + VOID *Headers; + UINTN HeadersLength; + EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumeHeader; + VARIABLE_STORE_HEADER *VariableStoreHeader; + UINT32 NvStorageFtwSpareSize; + UINT32 NvStorageFtwWorkingSize; + UINT32 NvStorageVariableSize; + UINT64 NvStorageFtwSpareBase; + UINT64 NvStorageFtwWorkingBase; + UINT64 NvStorageVariableBase; + + HeadersLength =3D sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_B= LOCK_MAP_ENTRY) + sizeof (VARIABLE_STORE_HEADER); + Headers =3D AllocateZeroPool (HeadersLength); + + NvStorageFtwWorkingSize =3D PcdGet32 (PcdFlashNvStorageFtwWorkingSize); + NvStorageFtwSpareSize =3D PcdGet32 (PcdFlashNvStorageFtwSpareSize); + NvStorageVariableSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); + + NvStorageFtwSpareBase =3D (PcdGet64 (PcdFlashNvStorageFtwSpareBase64) != =3D 0) ? + PcdGet64 (PcdFlashNvStorageFtwSpareBase64) : Pcd= Get32 (PcdFlashNvStorageFtwSpareBase); + NvStorageFtwWorkingBase =3D (PcdGet64 (PcdFlashNvStorageFtwWorkingBase64= ) !=3D 0) ? + PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) := PcdGet32 (PcdFlashNvStorageFtwWorkingBase); + NvStorageVariableBase =3D (PcdGet64 (PcdFlashNvStorageVariableBase64) != =3D 0) ? + PcdGet64 (PcdFlashNvStorageVariableBase64) : Pcd= Get32 (PcdFlashNvStorageVariableBase); + + // FirmwareVolumeHeader->FvLength is declared to have the Variable area = AND the FTW working area AND the FTW Spare contiguous. + if ((NvStorageVariableBase + NvStorageVariableSize) !=3D NvStorageFtwWor= kingBase) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageFtwWorkingBase is not contiguous with NvStorageVariabl= eBase region\n", + __FUNCTION__ + )); + return EFI_INVALID_PARAMETER; + } + + if ((NvStorageFtwWorkingBase + NvStorageFtwWorkingSize) !=3D NvStorageFt= wSpareBase) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageFtwSpareBase is not contiguous with NvStorageFtwWorkin= gBase region\n", + __FUNCTION__ + )); + return EFI_INVALID_PARAMETER; + } + + // Check if the size of the area is at least one block size + if ((NvStorageVariableSize <=3D 0) || (NvStorageVariableSize / Instance-= >Media.BlockSize <=3D 0)) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageVariableSize is 0x%x, should be atleast one block size= \n", + __FUNCTION__, + NvStorageVariableSize + )); + return EFI_INVALID_PARAMETER; + } + + if ((NvStorageFtwWorkingSize <=3D 0) || (NvStorageFtwWorkingSize / Insta= nce->Media.BlockSize <=3D 0)) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageFtwWorkingSize is 0x%x, should be atleast one block si= ze\n", + __FUNCTION__, + NvStorageFtwWorkingSize + )); + return EFI_INVALID_PARAMETER; + } + + if ((NvStorageFtwSpareSize <=3D 0) || (NvStorageFtwSpareSize / Instance-= >Media.BlockSize <=3D 0)) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageFtwSpareSize is 0x%x, should be atleast one block size= \n", + __FUNCTION__, + NvStorageFtwSpareSize + )); + return EFI_INVALID_PARAMETER; + } + + // Ensure the Variable area Base Addresses are aligned on a block size b= oundaries + if ((NvStorageVariableBase % Instance->Media.BlockSize !=3D 0) || + (NvStorageFtwWorkingBase % Instance->Media.BlockSize !=3D 0) || + (NvStorageFtwSpareBase % Instance->Media.BlockSize !=3D 0)) + { + DEBUG ((DEBUG_ERROR, "%a: NvStorage Base addresses must be aligned to = block size boundaries", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + // + // EFI_FIRMWARE_VOLUME_HEADER + // + FirmwareVolumeHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)Headers; + CopyGuid (&FirmwareVolumeHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid= ); + FirmwareVolumeHeader->FvLength =3D + PcdGet32 (PcdFlashNvStorageVariableSize) + + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) + + PcdGet32 (PcdFlashNvStorageFtwSpareSize); + FirmwareVolumeHeader->Signature =3D EFI_FVH_SIGNATURE; + FirmwareVolumeHeader->Attributes =3D (EFI_FVB_ATTRIBUTES_2)( + EFI_FVB2_READ_= ENABLED_CAP | // Reads may be enabled + EFI_FVB2_READ_= STATUS | // Reads are currently enabled + EFI_FVB2_STICK= Y_WRITE | // A block erase is required to flip bits into EFI_FVB2_ERA= SE_POLARITY + EFI_FVB2_MEMOR= Y_MAPPED | // It is memory mapped + EFI_FVB2_ERASE= _POLARITY | // After erasure all bits take this value (i.e. '1') + EFI_FVB2_WRITE= _STATUS | // Writes are currently enabled + EFI_FVB2_WRITE= _ENABLED_CAP // Writes may be enabled + ); + FirmwareVolumeHeader->HeaderLength =3D sizeof (EFI_FIRMWARE_VOL= UME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY); + FirmwareVolumeHeader->Revision =3D EFI_FVH_REVISION; + FirmwareVolumeHeader->BlockMap[0].NumBlocks =3D Instance->Media.LastBloc= k + 1; + FirmwareVolumeHeader->BlockMap[0].Length =3D Instance->Media.BlockSiz= e; + FirmwareVolumeHeader->BlockMap[1].NumBlocks =3D 0; + FirmwareVolumeHeader->BlockMap[1].Length =3D 0; + FirmwareVolumeHeader->Checksum =3D CalculateCheckSum16 ((UI= NT16 *)FirmwareVolumeHeader, FirmwareVolumeHeader->HeaderLength); + + // + // VARIABLE_STORE_HEADER + // + VariableStoreHeader =3D (VARIABLE_STORE_HEADER *)((UINTN)Headers + Firmw= areVolumeHeader->HeaderLength); + CopyGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGui= d); + VariableStoreHeader->Size =3D PcdGet32 (PcdFlashNvStorageVariableSize)= - FirmwareVolumeHeader->HeaderLength; + VariableStoreHeader->Format =3D VARIABLE_STORE_FORMATTED; + VariableStoreHeader->State =3D VARIABLE_STORE_HEALTHY; + + // Install the combined super-header in the NorFlash + Status =3D FvbWrite (&Instance->FvbProtocol, 0, 0, &HeadersLength, Heade= rs); + + FreePool (Headers); + return Status; +} + +/** + Check the integrity of firmware volume header. + + @param[in] FwVolHeader - A pointer to a firmware volume header + + @retval EFI_SUCCESS - The firmware volume is consistent + @retval EFI_NOT_FOUND - The firmware volume has been corrupted. + +**/ +EFI_STATUS +ValidateFvHeader ( + IN NOR_FLASH_INSTANCE *Instance + ) +{ + UINT16 Checksum; + EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; + VARIABLE_STORE_HEADER *VariableStoreHeader; + UINTN VariableStoreLength; + UINTN FvLength; + + FwVolHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)Instance->RegionBaseAddres= s; + + FvLength =3D PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFla= shNvStorageFtwWorkingSize) + + PcdGet32 (PcdFlashNvStorageFtwSpareSize); + + // + // Verify the header revision, header signature, length + // Length of FvBlock cannot be 2**64-1 + // HeaderLength cannot be an odd number + // + if ( (FwVolHeader->Revision !=3D EFI_FVH_REVISION) + || (FwVolHeader->Signature !=3D EFI_FVH_SIGNATURE) + || (FwVolHeader->FvLength !=3D FvLength) + ) + { + DEBUG (( + DEBUG_INFO, + "%a: No Firmware Volume header present\n", + __FUNCTION__ + )); + return EFI_NOT_FOUND; + } + + // Check the Firmware Volume Guid + if ( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid)= =3D=3D FALSE ) { + DEBUG (( + DEBUG_INFO, + "%a: Firmware Volume Guid non-compatible\n", + __FUNCTION__ + )); + return EFI_NOT_FOUND; + } + + // Verify the header checksum + Checksum =3D CalculateSum16 ((UINT16 *)FwVolHeader, FwVolHeader->HeaderL= ength); + if (Checksum !=3D 0) { + DEBUG (( + DEBUG_INFO, + "%a: FV checksum is invalid (Checksum:0x%X)\n", + __FUNCTION__, + Checksum + )); + return EFI_NOT_FOUND; + } + + VariableStoreHeader =3D (VARIABLE_STORE_HEADER *)((UINTN)FwVolHeader + F= wVolHeader->HeaderLength); + + // Check the Variable Store Guid + if (!CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) && + !CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVar= iableGuid)) + { + DEBUG (( + DEBUG_INFO, + "%a: Variable Store Guid non-compatible\n", + __FUNCTION__ + )); + return EFI_NOT_FOUND; + } + + VariableStoreLength =3D PcdGet32 (PcdFlashNvStorageVariableSize) - FwVol= Header->HeaderLength; + if (VariableStoreHeader->Size !=3D VariableStoreLength) { + DEBUG (( + DEBUG_INFO, + "%a: Variable Store Length does not match\n", + __FUNCTION__ + )); + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + +/** + The GetAttributes() function retrieves the attributes and + current settings of the block. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL ins= tance. + + @param Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the attribut= es and + current settings are returned. + Type EFI_FVB_ATTRIBUTES_2 is defined in EFI_FIRMWARE_= VOLUME_HEADER. + + @retval EFI_SUCCESS The firmware volume attributes were returned. + + **/ +EFI_STATUS +EFIAPI +FvbGetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ) +{ + EFI_FVB_ATTRIBUTES_2 FlashFvbAttributes; + NOR_FLASH_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + FlashFvbAttributes =3D (EFI_FVB_ATTRIBUTES_2)( + + EFI_FVB2_READ_ENABLED_CAP | = // Reads may be enabled + EFI_FVB2_READ_STATUS | = // Reads are currently enabled + EFI_FVB2_STICKY_WRITE | = // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY + EFI_FVB2_MEMORY_MAPPED | = // It is memory mapped + EFI_FVB2_ERASE_POLARITY = // After erasure all bits take this value (i.e. '1') + + ); + + // Check if it is write protected + if (Instance->Media.ReadOnly !=3D TRUE) { + FlashFvbAttributes =3D FlashFvbAttributes | + EFI_FVB2_WRITE_STATUS | // Writes are curren= tly enabled + EFI_FVB2_WRITE_ENABLED_CAP; // Writes may be ena= bled + } + + *Attributes =3D FlashFvbAttributes; + + DEBUG ((DEBUG_BLKIO, "FvbGetAttributes(0x%X)\n", *Attributes)); + + return EFI_SUCCESS; +} + +/** + The SetAttributes() function sets configurable firmware volume attributes + and returns the new settings of the firmware volume. + + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_= PROTOCOL instance. + + @param Attributes On input, Attributes is a pointer to EFI_= FVB_ATTRIBUTES_2 + that contains the desired firmware volume= settings. + On successful return, it contains the new= settings of + the firmware volume. + Type EFI_FVB_ATTRIBUTES_2 is defined in E= FI_FIRMWARE_VOLUME_HEADER. + + @retval EFI_SUCCESS The firmware volume attributes were retur= ned. + + @retval EFI_INVALID_PARAMETER The attributes requested are in conflict = with the capabilities + as declared in the firmware volume header. + + **/ +EFI_STATUS +EFIAPI +FvbSetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ) +{ + DEBUG ((DEBUG_BLKIO, "FvbSetAttributes(0x%X) is not supported\n", *Attri= butes)); + return EFI_UNSUPPORTED; +} + +/** + The GetPhysicalAddress() function retrieves the base address of + a memory-mapped firmware volume. This function should be called + only for memory-mapped firmware volumes. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOC= OL instance. + + @param Address Pointer to a caller-allocated + EFI_PHYSICAL_ADDRESS that, on successful + return from GetPhysicalAddress(), contains the + base address of the firmware volume. + + @retval EFI_SUCCESS The firmware volume base address was returned. + + @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped. + + **/ +EFI_STATUS +EFIAPI +FvbGetPhysicalAddress ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + OUT EFI_PHYSICAL_ADDRESS *Address + ) +{ + NOR_FLASH_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + DEBUG ((DEBUG_BLKIO, "FvbGetPhysicalAddress(BaseAddress=3D0x%08x)\n", In= stance->RegionBaseAddress)); + + ASSERT (Address !=3D NULL); + + *Address =3D mFlashNvStorageVariableBase; + return EFI_SUCCESS; +} + +/** + The GetBlockSize() function retrieves the size of the requested + block. It also returns the number of additional blocks with + the identical size. The GetBlockSize() function is used to + retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER). + + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_= PROTOCOL instance. + + @param Lba Indicates the block for which to return t= he size. + + @param BlockSize Pointer to a caller-allocated UINTN in wh= ich + the size of the block is returned. + + @param NumberOfBlocks Pointer to a caller-allocated UINTN in + which the number of consecutive blocks, + starting with Lba, is returned. All + blocks in this range have a size of + BlockSize. + + + @retval EFI_SUCCESS The firmware volume base address was retu= rned. + + @retval EFI_INVALID_PARAMETER The requested LBA is out of range. + + **/ +EFI_STATUS +EFIAPI +FvbGetBlockSize ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + OUT UINTN *BlockSize, + OUT UINTN *NumberOfBlocks + ) +{ + EFI_STATUS Status; + NOR_FLASH_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=3D%ld, BlockSize=3D0x%x, LastB= lock=3D%ld)\n", Lba, Instance->Media.BlockSize, Instance->Media.LastBlock)); + + if (Lba > Instance->Media.LastBlock) { + DEBUG ((DEBUG_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is be= yond the last Lba (%ld).\n", Lba, Instance->Media.LastBlock)); + Status =3D EFI_INVALID_PARAMETER; + } else { + // This is easy because in this platform each NorFlash device has equa= l sized blocks. + *BlockSize =3D (UINTN)Instance->Media.BlockSize; + *NumberOfBlocks =3D (UINTN)(Instance->Media.LastBlock - Lba + 1); + + DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=3D0x%x, *NumberOfBlo= cks=3D0x%x.\n", *BlockSize, *NumberOfBlocks)); + + Status =3D EFI_SUCCESS; + } + + return Status; +} + +/** + Reads the specified number of bytes into a buffer from the specified bloc= k. + + The Read() function reads the requested number of bytes from the + requested block and stores them in the provided buffer. + Implementations should be mindful that the firmware volume + might be in the ReadDisabled state. If it is in this state, + the Read() function must return the status code + EFI_ACCESS_DENIED without modifying the contents of the + buffer. The Read() function must also prevent spanning block + boundaries. If a read is requested that would span a block + boundary, the read must read up to the boundary but not + beyond. The output parameter NumBytes must be set to correctly + indicate the number of bytes actually read. The caller must be + aware that a read may be partially completed. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROT= OCOL instance. + + @param Lba The starting logical block index from which t= o read. + + @param Offset Offset into the block at which to begin readi= ng. + + @param NumBytes Pointer to a UINTN. + At entry, *NumBytes contains the total size o= f the buffer. + At exit, *NumBytes contains the total number = of bytes read. + + @param Buffer Pointer to a caller-allocated buffer that wil= l be used + to hold the data that is read. + + @retval EFI_SUCCESS The firmware volume was read successfully, a= nd contents are + in Buffer. + + @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. + On output, NumBytes contains the total number= of bytes + returned in Buffer. + + @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled st= ate. + + @retval EFI_DEVICE_ERROR The block device is not functioning correctly= and could not be read. + + **/ +EFI_STATUS +EFIAPI +FvbRead ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN OUT UINT8 *Buffer + ) +{ + EFI_STATUS TempStatus; + UINTN BlockSize; + NOR_FLASH_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=3D%ld, Offset=3D0x%x, *Num= Bytes=3D0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBy= tes, Buffer)); + + TempStatus =3D EFI_SUCCESS; + + // Cache the block size to avoid de-referencing pointers all the time + BlockSize =3D Instance->Media.BlockSize; + + DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=3D0x%x + NumBytes=3D0x%x= ) <=3D BlockSize=3D0x%x\n", Offset, *NumBytes, BlockSize)); + + // The read must not span block boundaries. + // We need to check each variable individually because adding two large = values together overflows. + if ((Offset >=3D BlockSize) || + (*NumBytes > BlockSize) || + ((Offset + *NumBytes) > BlockSize)) + { + DEBUG ((DEBUG_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=3D= 0x%x + NumBytes=3D0x%x) > BlockSize=3D0x%x\n", Offset, *NumBytes, BlockSize= )); + return EFI_BAD_BUFFER_SIZE; + } + + // We must have some bytes to read + if (*NumBytes =3D=3D 0) { + return EFI_BAD_BUFFER_SIZE; + } + + // Decide if we are doing full block reads or not. + if (*NumBytes % BlockSize !=3D 0) { + TempStatus =3D NorFlashRead (Instance, Instance->StartLba + Lba, Offse= t, *NumBytes, Buffer); + if (EFI_ERROR (TempStatus)) { + return EFI_DEVICE_ERROR; + } + } else { + // Read NOR Flash data into shadow buffer + TempStatus =3D NorFlashReadBlocks (Instance, Instance->StartLba + Lba,= BlockSize, Buffer); + if (EFI_ERROR (TempStatus)) { + // Return one of the pre-approved error statuses + return EFI_DEVICE_ERROR; + } + } + + return EFI_SUCCESS; +} + +/** + Writes the specified number of bytes from the input buffer to the block. + + The Write() function writes the specified number of bytes from + the provided buffer to the specified block and offset. If the + firmware volume is sticky write, the caller must ensure that + all the bits of the specified range to write are in the + EFI_FVB_ERASE_POLARITY state before calling the Write() + function, or else the result will be unpredictable. This + unpredictability arises because, for a sticky-write firmware + volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY + state but cannot flip it back again. Before calling the + Write() function, it is recommended for the caller to first call + the EraseBlocks() function to erase the specified block to + write. A block erase cycle will transition bits from the + (NOT)EFI_FVB_ERASE_POLARITY state back to the + EFI_FVB_ERASE_POLARITY state. Implementations should be + mindful that the firmware volume might be in the WriteDisabled + state. If it is in this state, the Write() function must + return the status code EFI_ACCESS_DENIED without modifying the + contents of the firmware volume. The Write() function must + also prevent spanning block boundaries. If a write is + requested that spans a block boundary, the write must store up + to the boundary but not beyond. The output parameter NumBytes + must be set to correctly indicate the number of bytes actually + written. The caller must be aware that a write may be + partially completed. All writes, partial or otherwise, must be + fully flushed to the hardware before the Write() service + returns. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROT= OCOL instance. + + @param Lba The starting logical block index to write to. + + @param Offset Offset into the block at which to begin writi= ng. + + @param NumBytes The pointer to a UINTN. + At entry, *NumBytes contains the total size o= f the buffer. + At exit, *NumBytes contains the total number = of bytes actually written. + + @param Buffer The pointer to a caller-allocated buffer that= contains the source for the write. + + @retval EFI_SUCCESS The firmware volume was written successfully. + + @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundar= y. + On output, NumBytes contains the total number= of bytes + actually written. + + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled s= tate. + + @retval EFI_DEVICE_ERROR The block device is malfunctioning and could = not be written. + + + **/ +EFI_STATUS +EFIAPI +FvbWrite ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ) +{ + NOR_FLASH_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + return NorFlashWriteSingleBlock (Instance, Instance->StartLba + Lba, Off= set, NumBytes, Buffer); +} + +/** + Erases and initialises a firmware volume block. + + The EraseBlocks() function erases one or more blocks as denoted + by the variable argument list. The entire parameter list of + blocks must be verified before erasing any blocks. If a block is + requested that does not exist within the associated firmware + volume (it has a larger index than the last block of the + firmware volume), the EraseBlocks() function must return the + status code EFI_INVALID_PARAMETER without modifying the contents + of the firmware volume. Implementations should be mindful that + the firmware volume might be in the WriteDisabled state. If it + is in this state, the EraseBlocks() function must return the + status code EFI_ACCESS_DENIED without modifying the contents of + the firmware volume. All calls to EraseBlocks() must be fully + flushed to the hardware before the EraseBlocks() service + returns. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_= PROTOCOL + instance. + + @param ... The variable argument list is a list of t= uples. + Each tuple describes a range of LBAs to e= rase + and consists of the following: + - An EFI_LBA that indicates the starting = LBA + - A UINTN that indicates the number of bl= ocks to erase. + + The list is terminated with an EFI_LBA_LI= ST_TERMINATOR. + For example, the following indicates that= two ranges of blocks + (5-7 and 10-11) are to be erased: + EraseBlocks (This, 5, 3, 10, 2, EFI_LBA_L= IST_TERMINATOR); + + @retval EFI_SUCCESS The erase request successfully completed. + + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabl= ed state. + + @retval EFI_DEVICE_ERROR The block device is not functioning corre= ctly and could not be written. + The firmware device may have been partial= ly erased. + + @retval EFI_INVALID_PARAMETER One or more of the LBAs listed in the var= iable argument list do + not exist in the firmware volume. + + **/ +EFI_STATUS +EFIAPI +FvbEraseBlocks ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + ... + ) +{ + EFI_STATUS Status; + VA_LIST Args; + UINTN BlockAddress; // Physical address of Lba to erase + EFI_LBA StartingLba; // Lba from which we start erasing + UINTN NumOfLba; // Number of Lba blocks to erase + NOR_FLASH_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks()\n")); + + Status =3D EFI_SUCCESS; + + // Detect WriteDisabled state + if (Instance->Media.ReadOnly =3D=3D TRUE) { + // Firmware volume is in WriteDisabled state + DEBUG ((DEBUG_ERROR, "FvbEraseBlocks: ERROR - Device is in WriteDisabl= ed state.\n")); + return EFI_ACCESS_DENIED; + } + + // Before erasing, check the entire list of parameters to ensure all spe= cified blocks are valid + + VA_START (Args, This); + do { + // Get the Lba from which we start erasing + StartingLba =3D VA_ARG (Args, EFI_LBA); + + // Have we reached the end of the list? + if (StartingLba =3D=3D EFI_LBA_LIST_TERMINATOR) { + // Exit the while loop + break; + } + + // How many Lba blocks are we requested to erase? + NumOfLba =3D VA_ARG (Args, UINTN); + + // All blocks must be within range + DEBUG (( + DEBUG_BLKIO, + "FvbEraseBlocks: Check if: ( StartingLba=3D%ld + NumOfLba=3D%Lu - 1 = ) > LastBlock=3D%ld.\n", + Instance->StartLba + StartingLba, + (UINT64)NumOfLba, + Instance->Media.LastBlock + )); + if ((NumOfLba =3D=3D 0) || ((Instance->StartLba + StartingLba + NumOfL= ba - 1) > Instance->Media.LastBlock)) { + VA_END (Args); + DEBUG ((DEBUG_ERROR, "FvbEraseBlocks: ERROR - Lba range goes past th= e last Lba.\n")); + Status =3D EFI_INVALID_PARAMETER; + goto EXIT; + } + } while (TRUE); + + VA_END (Args); + + // + // To get here, all must be ok, so start erasing + // + VA_START (Args, This); + do { + // Get the Lba from which we start erasing + StartingLba =3D VA_ARG (Args, EFI_LBA); + + // Have we reached the end of the list? + if (StartingLba =3D=3D EFI_LBA_LIST_TERMINATOR) { + // Exit the while loop + break; + } + + // How many Lba blocks are we requested to erase? + NumOfLba =3D VA_ARG (Args, UINTN); + + // Go through each one and erase it + while (NumOfLba > 0) { + // Get the physical address of Lba to erase + BlockAddress =3D GET_NOR_BLOCK_ADDRESS ( + Instance->RegionBaseAddress, + Instance->StartLba + StartingLba, + Instance->Media.BlockSize + ); + + // Erase it + DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Erasing Lba=3D%ld @ 0x%08x.\n"= , Instance->StartLba + StartingLba, BlockAddress)); + Status =3D NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress= ); + if (EFI_ERROR (Status)) { + VA_END (Args); + Status =3D EFI_DEVICE_ERROR; + goto EXIT; + } + + // Move to the next Lba + StartingLba++; + NumOfLba--; + } + } while (TRUE); + + VA_END (Args); + +EXIT: + return Status; +} + +/** + 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 +**/ +VOID +EFIAPI +FvbVirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EfiConvertPointer (0x0, (VOID **)&mFlashNvStorageVariableBase); + return; +} diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c b/OvmfPkg/D= rivers/NorFlashDxe/NorFlashStandaloneMm.c new file mode 100644 index 000000000000..b72ad97b0b55 --- /dev/null +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c @@ -0,0 +1,383 @@ +/** @file NorFlashStandaloneMm.c + + Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.
+ Copyright (c) 2020, Linaro, Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +#include "NorFlash.h" + +// +// Global variable declarations +// +NOR_FLASH_INSTANCE **mNorFlashInstances; +UINT32 mNorFlashDeviceCount; +UINTN mFlashNvStorageVariableBase; + +NOR_FLASH_INSTANCE mNorFlashInstanceTemplate =3D { + NOR_FLASH_SIGNATURE, // Signature + NULL, // Handle ... NEED TO BE FILLED + + 0, // DeviceBaseAddress ... NEED TO BE FILLED + 0, // RegionBaseAddress ... NEED TO BE FILLED + 0, // Size ... NEED TO BE FILLED + 0, // StartLba + + { + EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision + NULL, // Media ... NEED TO BE FILLED + NULL, // Reset; + NULL, // ReadBlocks + NULL, // WriteBlocks + NULL // FlushBlocks + }, // BlockIoProtocol + + { + 0, // MediaId ... NEED TO BE FILLED + FALSE, // RemovableMedia + TRUE, // MediaPresent + FALSE, // LogicalPartition + FALSE, // ReadOnly + FALSE, // WriteCaching; + 0, // BlockSize ... NEED TO BE FILLED + 4, // IoAlign + 0, // LastBlock ... NEED TO BE FILLED + 0, // LowestAlignedLba + 1, // LogicalBlocksPerPhysicalBlock + }, // Media; + + { + EFI_DISK_IO_PROTOCOL_REVISION, // Revision + NULL, // ReadDisk + NULL // WriteDisk + }, + + { + FvbGetAttributes, // GetAttributes + FvbSetAttributes, // SetAttributes + FvbGetPhysicalAddress, // GetPhysicalAddress + FvbGetBlockSize, // GetBlockSize + FvbRead, // Read + FvbWrite, // Write + FvbEraseBlocks, // EraseBlocks + NULL, // ParentHandle + }, // FvbProtoccol; + NULL, // ShadowBuffer + { + { + { + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + { + (UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End)), + (UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8) + } + }, + { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0,= 0x0, 0x0, 0x0, 0x0 } + }, // GU= ID ... NEED TO BE FILLED + }, + 0, // Index + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 } + } + } // DevicePath +}; + +EFI_STATUS +NorFlashCreateInstance ( + IN UINTN NorFlashDeviceBase, + IN UINTN NorFlashRegionBase, + IN UINTN NorFlashSize, + IN UINT32 Index, + IN UINT32 BlockSize, + IN BOOLEAN SupportFvb, + OUT NOR_FLASH_INSTANCE **NorFlashInstance + ) +{ + EFI_STATUS Status; + NOR_FLASH_INSTANCE *Instance; + + ASSERT (NorFlashInstance !=3D NULL); + + Instance =3D AllocateRuntimeCopyPool (sizeof (NOR_FLASH_INSTANCE), &mNor= FlashInstanceTemplate); + if (Instance =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Instance->DeviceBaseAddress =3D NorFlashDeviceBase; + Instance->RegionBaseAddress =3D NorFlashRegionBase; + Instance->Size =3D NorFlashSize; + + Instance->BlockIoProtocol.Media =3D &Instance->Media; + Instance->Media.MediaId =3D Index; + Instance->Media.BlockSize =3D BlockSize; + Instance->Media.LastBlock =3D (NorFlashSize / BlockSize)-1; + + CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid); + Instance->DevicePath.Index =3D (UINT8)Index; + + Instance->ShadowBuffer =3D AllocateRuntimePool (BlockSize); + if (Instance->ShadowBuffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + if (SupportFvb) { + NorFlashFvbInitialize (Instance); + + Status =3D gMmst->MmInstallProtocolInterface ( + &Instance->Handle, + &gEfiSmmFirmwareVolumeBlockProtocolGuid, + EFI_NATIVE_INTERFACE, + &Instance->FvbProtocol + ); + if (EFI_ERROR (Status)) { + FreePool (Instance); + return Status; + } + } else { + DEBUG ((DEBUG_ERROR, "standalone MM NOR Flash driver only support FVB.= \n")); + FreePool (Instance); + return EFI_UNSUPPORTED; + } + + *NorFlashInstance =3D Instance; + return Status; +} + +/** + * This function unlock and erase an entire NOR Flash block. + **/ +EFI_STATUS +NorFlashUnlockAndEraseSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ) +{ + EFI_STATUS Status; + UINTN Index; + + Index =3D 0; + // The block erase might fail a first time (SW bug ?). Retry it ... + do { + // Unlock the block if we have to + Status =3D NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddres= s); + if (EFI_ERROR (Status)) { + break; + } + + Status =3D NorFlashEraseSingleBlock (Instance, BlockAddress); + Index++; + } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status =3D=3D EFI_WRITE_PRO= TECTED)); + + if (Index =3D=3D NOR_FLASH_ERASE_RETRY) { + DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=3D0x%08x: Block Lo= cked Error (try to erase %d times)\n", BlockAddress, Index)); + } + + return Status; +} + +EFI_STATUS +NorFlashWriteFullBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINT32 *DataBuffer, + IN UINT32 BlockSizeInWords + ) +{ + EFI_STATUS Status; + UINTN WordAddress; + UINT32 WordIndex; + UINTN BufferIndex; + UINTN BlockAddress; + UINTN BuffersInBlock; + UINTN RemainingWords; + UINTN Cnt; + + Status =3D EFI_SUCCESS; + + // Get the physical address of the block + BlockAddress =3D GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba= , BlockSizeInWords * 4); + + // Start writing from the first address at the start of the block + WordAddress =3D BlockAddress; + + Status =3D NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and E= rase the single block at 0x%X\n", BlockAddress)); + goto EXIT; + } + + // To speed up the programming operation, NOR Flash is programmed using = the Buffered Programming method. + + // Check that the address starts at a 32-word boundary, i.e. last 7 bits= must be zero + if ((WordAddress & BOUNDARY_OF_32_WORDS) =3D=3D 0x00) { + // First, break the entire block into buffer-sized chunks. + BuffersInBlock =3D (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE= _IN_BYTES; + + // Then feed each buffer chunk to the NOR Flash + // If a buffer does not contain any data, don't write it. + for (BufferIndex =3D 0; + BufferIndex < BuffersInBlock; + BufferIndex++, WordAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES, Dat= aBuffer +=3D P30_MAX_BUFFER_SIZE_IN_WORDS + ) + { + // Check the buffer to see if it contains any data (not set all 1s). + for (Cnt =3D 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) { + if (~DataBuffer[Cnt] !=3D 0 ) { + // Some data found, write the buffer. + Status =3D NorFlashWriteBuffer ( + Instance, + WordAddress, + P30_MAX_BUFFER_SIZE_IN_BYTES, + DataBuffer + ); + if (EFI_ERROR (Status)) { + goto EXIT; + } + + break; + } + } + } + + // Finally, finish off any remaining words that are less than the maxi= mum size of the buffer + RemainingWords =3D BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS; + + if (RemainingWords !=3D 0) { + Status =3D NorFlashWriteBuffer (Instance, WordAddress, (RemainingWor= ds * 4), DataBuffer); + if (EFI_ERROR (Status)) { + goto EXIT; + } + } + } else { + // For now, use the single word programming algorithm + // It is unlikely that the NOR Flash will exist in an address which fa= lls within a 32 word boundary range, + // i.e. which ends in the range 0x......01 - 0x......7F. + for (WordIndex =3D 0; WordIndex < BlockSizeInWords; WordIndex++, DataB= uffer++, WordAddress =3D WordAddress + 4) { + Status =3D NorFlashWriteSingleWord (Instance, WordAddress, *DataBuff= er); + if (EFI_ERROR (Status)) { + goto EXIT; + } + } + } + +EXIT: + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed = at address 0x%08x. Exit Status =3D \"%r\".\n", WordAddress, Status)); + } + + return Status; +} + +EFI_STATUS +EFIAPI +NorFlashInitialise ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *MmSystemTable + ) +{ + EFI_STATUS Status; + UINT32 Index; + NOR_FLASH_DESCRIPTION *NorFlashDevices; + BOOLEAN ContainVariableStorage; + + Status =3D NorFlashPlatformInitialization (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to initialize Nor Flash= devices\n")); + return Status; + } + + Status =3D NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDevic= eCount); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to get Nor Flash device= s\n")); + return Status; + } + + mNorFlashInstances =3D AllocatePool (sizeof (NOR_FLASH_INSTANCE *) * mNo= rFlashDeviceCount); + + for (Index =3D 0; Index < mNorFlashDeviceCount; Index++) { + // Check if this NOR Flash device contain the variable storage region + + if (FixedPcdGet64 (PcdFlashNvStorageVariableBase64) !=3D 0) { + ContainVariableStorage =3D + (NorFlashDevices[Index].RegionBaseAddress <=3D FixedPcdGet64 (PcdF= lashNvStorageVariableBase64)) && + (FixedPcdGet64 (PcdFlashNvStorageVariableBase64) + FixedPcdGet32 (= PcdFlashNvStorageVariableSize) <=3D + NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index]= .Size); + } else { + ContainVariableStorage =3D + (NorFlashDevices[Index].RegionBaseAddress <=3D FixedPcdGet32 (PcdF= lashNvStorageVariableBase)) && + (FixedPcdGet32 (PcdFlashNvStorageVariableBase) + FixedPcdGet32 (Pc= dFlashNvStorageVariableSize) <=3D + NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index]= .Size); + } + + Status =3D NorFlashCreateInstance ( + NorFlashDevices[Index].DeviceBaseAddress, + NorFlashDevices[Index].RegionBaseAddress, + NorFlashDevices[Index].Size, + Index, + NorFlashDevices[Index].BlockSize, + ContainVariableStorage, + &mNorFlashInstances[Index] + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to create instance fo= r NorFlash[%d]\n", Index)); + } + } + + return Status; +} + +EFI_STATUS +EFIAPI +NorFlashFvbInitialize ( + IN NOR_FLASH_INSTANCE *Instance + ) +{ + EFI_STATUS Status; + UINT32 FvbNumLba; + + ASSERT ((Instance !=3D NULL)); + + mFlashNvStorageVariableBase =3D (FixedPcdGet64 (PcdFlashNvStorageVariabl= eBase64) !=3D 0) ? + FixedPcdGet64 (PcdFlashNvStorageVariableBa= se64) : FixedPcdGet32 (PcdFlashNvStorageVariableBase); + // Set the index of the first LBA for the FVB + Instance->StartLba =3D (mFlashNvStorageVariableBase - Instance->RegionBa= seAddress) / Instance->Media.BlockSize; + + // Determine if there is a valid header at the beginning of the NorFlash + Status =3D ValidateFvHeader (Instance); + + // Install the Default FVB header if required + if (EFI_ERROR (Status)) { + // There is no valid header, so time to install one. + DEBUG ((DEBUG_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__= )); + DEBUG (( + DEBUG_INFO, + "%a: Installing a correct one for this volume.\n", + __FUNCTION__ + )); + + // Erase all the NorFlash that is reserved for variable storage + FvbNumLba =3D (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (Pc= dFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) = / Instance->Media.BlockSize; + + Status =3D FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumL= ba, EFI_LBA_LIST_TERMINATOR); + if (EFI_ERROR (Status)) { + return Status; + } + + // Install all appropriate headers + Status =3D InitializeFvAndVariableStoreHeaders (Instance); + if (EFI_ERROR (Status)) { + return Status; + } + } + + return Status; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95139): https://edk2.groups.io/g/devel/message/95139 Mute This Topic: https://groups.io/mt/94300419/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 Sat May 18 17:16:06 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+95140+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+95140+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655209; cv=none; d=zohomail.com; s=zohoarc; b=H5Q/ShIodM8TJHL5fgTv9xFVhDPP2696BKhSDzOzQbZPhjEWp2hzOAxP+wZozmYzfRdQtSbhjRrQps7ZUnucLfmvcpHSDt4beosVL1iIarq6vEP96WhMIBH6BIPMd03OZKpKrwg7gmPX9DdelmgoRXKD9jImRdlcCHfGnlBPyPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655209; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=TxU2aJAxql9OJp3Dz1jsBpUSyInZVbR1ZM+ubBsyTwc=; b=ILR3xmRsZ9gwiwUTHesjAowLPvWLR9mQjZypS80LED7U1h4xF5KzWduij+wumEFrvFmXJfKF58zmb8v/mTtxQ+FyTFr376c12VfqQD7nvIbj7LGOfA7TPviFCl+C0HsVONp8ZhfnDtuCLLtp+10LXdktTR7ol1UCtS8mP3tXyYY= 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+95140+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655209724581.0740134194806; Thu, 13 Oct 2022 03:00:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aplbYY1788612xztik1A9zpE; Thu, 13 Oct 2022 03:00:09 -0700 X-Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mx.groups.io with SMTP id smtpd.web12.5675.1665655186955983275 for ; Thu, 13 Oct 2022 03:00:08 -0700 X-Received: by mail-pj1-f46.google.com with SMTP id a5-20020a17090aa50500b002008eeb040eso5267934pjq.1 for ; Thu, 13 Oct 2022 03:00:08 -0700 (PDT) X-Gm-Message-State: 8b2pRcXY5NFDRkrBRo5vybtQx1787277AA= X-Google-Smtp-Source: AMsMyM5TvRseLjY++wBEXNovpmxgBir94F0naZ86CYJP742hulhit+FQGCiH5XD/OXA+c6rM4G62sA== X-Received: by 2002:a17:90b:1b4f:b0:20d:6ddd:9ef6 with SMTP id nv15-20020a17090b1b4f00b0020d6ddd9ef6mr10125478pjb.200.1665655207886; Thu, 13 Oct 2022 03:00:07 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.03.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 03:00:07 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 30/34] OvmfPkg/NorFlashDxe: Avoid switching to array mode during writes Date: Thu, 13 Oct 2022 15:28:25 +0530 Message-Id: <20221013095829.1454581-31-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655209; bh=Ldy4aWaQYtgPhXGyIYD7UWmwtWWRoP8RPcrQn2Somyc=; h=Cc:Date:From:Reply-To:Subject:To; b=t5bxVXyNPte0oVWcj/GTXIBLr5dsjhUYF8JuWuzUGtUuf9TaqxO1aYyeI5e7xkJw5cj bXjXmFjY/WdsGW4ar53FiONHLwLyEY4V0upYBbEnGbiU3Ao3NnAgNgpn6zwM+wUHuJF2e V1bnOLMxAU4VF98EnKAyq0o111USJehk9+0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655210300100001 Content-Type: text/plain; charset="utf-8" Switching to array mode (i.e., ROM memory mode rather than NOR flash programming mode) is rather costly when running under KVM emulation, as it involves setting up the read-only memslot in the hypervisor's stage 2 page tables. So let's avoid jumping between modes unnecessarily, and only switch back to array mode when we are done writing to flash. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Ard Biesheuvel --- OvmfPkg/Drivers/NorFlashDxe/NorFlash.c | 9 +++------ OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c | 3 +++ OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c b/OvmfPkg/Drivers/NorFl= ashDxe/NorFlash.c index c2a6aa281578..cdc6b5da8bfb 100644 --- a/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c @@ -205,9 +205,6 @@ NorFlashWriteSingleWord ( SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS= _REGISTER); } =20 - // Put device back into Read Array mode - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); - return Status; } =20 @@ -338,9 +335,6 @@ NorFlashWriteBuffer ( } =20 EXIT: - // Put device back into Read Array mode - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); - return Status; } =20 @@ -750,6 +744,9 @@ NorFlashWriteSingleBlock ( } =20 TempStatus =3D NorFlashWriteSingleWord (Instance, WordAddr, WordToWr= ite); + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY= ); + if (EFI_ERROR (TempStatus)) { return EFI_DEVICE_ERROR; } diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/OvmfPkg/Drivers/No= rFlashDxe/NorFlashDxe.c index f7b92de21a57..862a8e621fd0 100644 --- a/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -316,6 +316,9 @@ NorFlashWriteFullBlock ( } =20 EXIT: + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + if (!EfiAtRuntime ()) { // Interruptions can resume. gBS->RestoreTPL (OriginalTPL); diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c b/OvmfPkg/D= rivers/NorFlashDxe/NorFlashStandaloneMm.c index b72ad97b0b55..f6dec84176d4 100644 --- a/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlashStandaloneMm.c @@ -270,6 +270,9 @@ NorFlashWriteFullBlock ( } =20 EXIT: + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed = at address 0x%08x. Exit Status =3D \"%r\".\n", WordAddress, Status)); } --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95140): https://edk2.groups.io/g/devel/message/95140 Mute This Topic: https://groups.io/mt/94300420/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 Sat May 18 17:16:06 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+95141+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+95141+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655217; cv=none; d=zohomail.com; s=zohoarc; b=e3i0SOj0py0Vx6+NLcJcI4uIWrEfYpxF8HvHUTyoAHVBk/uqwuvw+DosAn2PgTwqPRcxyQk05pmkfMG3s0VA2/8OodJyt0KtEpMpeJ6IniAavWln+mJHSkfgO7hwXsDwZsMAsSJLI1/Py7mxJfe8BVASu+IOHVE1aTf4qcRUGRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655217; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=EbUMujwkpSP49sl1/QdPA5kYQTWlOHtY4M6yngwb6Gs=; b=hJ87WtB1ve8KmDtzHcnN5lISreL7B2OJ40TgemJa1fHxmtxwYK6EqLjIrFLZZ3FMKjBmOJbjIxtaZTLqLtvYyeSVzvZhtmFlCluzMJJSeNvxIjdlQG9EveCNeUm8tsYL+K4i9hE0Jftig9fJa6ItJhR+I1TVtPa+ckyKBJOy7W0= 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+95141+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655217024688.9342442283069; Thu, 13 Oct 2022 03:00:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id GYGdYY1788612xUbdWTY676Z; Thu, 13 Oct 2022 03:00:13 -0700 X-Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by mx.groups.io with SMTP id smtpd.web12.5678.1665655199255012782 for ; Thu, 13 Oct 2022 03:00:12 -0700 X-Received: by mail-pj1-f50.google.com with SMTP id fw14so1510627pjb.3 for ; Thu, 13 Oct 2022 03:00:12 -0700 (PDT) X-Gm-Message-State: ootBqeVkdFUVaGod5rL2iLIKx1787277AA= X-Google-Smtp-Source: AMsMyM68mqrAgvAaxI6QUxkjLyboqBoVIouuF4Yf2LdDidgqoYBtfHX8QQMDXzlVg9ED9jC926RbzA== X-Received: by 2002:a17:902:c942:b0:180:3f94:2975 with SMTP id i2-20020a170902c94200b001803f942975mr30884092pla.50.1665655212024; Thu, 13 Oct 2022 03:00:12 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.03.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 03:00:10 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 31/34] OvmfPkg/NorFlashDxe: Avoid switching between modes in a tight loop Date: Thu, 13 Oct 2022 15:28:26 +0530 Message-Id: <20221013095829.1454581-32-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655213; bh=8D1t/3UzIGMcYqa6Lx07Ci1NOhAW6yA0LdSQWmA0Enk=; h=Cc:Date:From:Reply-To:Subject:To; b=CqIzn5B87oF+/Y+L0jGjfWrSAbx/UFFiq+9rnX1cN0+RMFoWVi2c/EY/WLTaL9GiWUq /jPU00sDH3OUzw5cO93eEfldz2xXSXwaeXe6o0J08x6ZVMvjgyGdoZ9JRFH++XjghUM+A ye/T4I4JAyT4PaZnGYfEOUrE4a1akTYOOp4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655220377100001 Content-Type: text/plain; charset="utf-8" Currently, when dealing with small updates that can be written out directly (i.e., if they only involve clearing bits and not setting bits, as the latter requires a block level erase), we iterate over the data one word at a time, read the old value, compare it, write the new value, and repeat, unless we encountered a value that we cannot write (0->1 transition), in which case we fall back to a block level operation. This is inefficient for two reasons: - reading and writing a word at a time involves switching between array and programming mode for every word of data, which is disproportionately costly when running under KVM; - we end up writing some data twice, as we may not notice that a block erase is needed until after some data has been written to flash. So replace this sequence with a single read of up to twice the buffered write maximum size, followed by one or two buffered writes if the data can be written directly. Otherwise, fall back to the existing block level sequence, but without writing out part of the data twice. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Ard Biesheuvel --- OvmfPkg/Drivers/NorFlashDxe/NorFlash.c | 211 +++++++++---------------- 1 file changed, 75 insertions(+), 136 deletions(-) diff --git a/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c b/OvmfPkg/Drivers/NorFl= ashDxe/NorFlash.c index cdc6b5da8bfb..649e0789db3c 100644 --- a/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c +++ b/OvmfPkg/Drivers/NorFlashDxe/NorFlash.c @@ -582,20 +582,11 @@ NorFlashWriteSingleBlock ( IN UINT8 *Buffer ) { - EFI_STATUS TempStatus; - UINT32 Tmp; - UINT32 TmpBuf; - UINT32 WordToWrite; - UINT32 Mask; - BOOLEAN DoErase; - UINTN BytesToWrite; + EFI_STATUS Status; UINTN CurOffset; - UINTN WordAddr; UINTN BlockSize; UINTN BlockAddress; - UINTN PrevBlockAddress; - - PrevBlockAddress =3D 0; + UINT8 *OrigData; =20 DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=3D%ld, Of= fset=3D0x%x, *NumBytes=3D0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes,= Buffer)); =20 @@ -606,6 +597,12 @@ NorFlashWriteSingleBlock ( return EFI_ACCESS_DENIED; } =20 + // Check we did get some memory. Buffer is BlockSize. + if (Instance->ShadowBuffer =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "FvbWrite: ERROR - Buffer not ready\n")); + return EFI_DEVICE_ERROR; + } + // Cache the block size to avoid de-referencing pointers all the time BlockSize =3D Instance->Media.BlockSize; =20 @@ -625,149 +622,91 @@ NorFlashWriteSingleBlock ( return EFI_BAD_BUFFER_SIZE; } =20 - // Pick 128bytes as a good start for word operations as opposed to erasi= ng the - // block and writing the data regardless if an erase is really needed. - // It looks like most individual NV variable writes are smaller than 128= bytes. - if (*NumBytes <=3D 128) { + // Pick P30_MAX_BUFFER_SIZE_IN_BYTES (=3D=3D 128 bytes) as a good start = for word + // operations as opposed to erasing the block and writing the data regar= dless + // if an erase is really needed. It looks like most individual NV varia= ble + // writes are smaller than 128 bytes. + // To avoid pathological cases were a 2 byte write is disregarded becaus= e it + // occurs right at a 128 byte buffered write alignment boundary, permit = up to + // twice the max buffer size, and perform two writes if needed. + if ((*NumBytes + (Offset & BOUNDARY_OF_32_WORDS)) <=3D (2 * P30_MAX_BUFF= ER_SIZE_IN_BYTES)) { // Check to see if we need to erase before programming the data into N= OR. // If the destination bits are only changing from 1s to 0s we can just= write. // After a block is erased all bits in the block is set to 1. // If any byte requires us to erase we just give up and rewrite all of= it. - DoErase =3D FALSE; - BytesToWrite =3D *NumBytes; - CurOffset =3D Offset; =20 - while (BytesToWrite > 0) { - // Read full word from NOR, splice as required. A word is the smalle= st - // unit we can write. - TempStatus =3D NorFlashRead (Instance, Lba, CurOffset & ~(0x3), size= of (Tmp), &Tmp); - if (EFI_ERROR (TempStatus)) { - return EFI_DEVICE_ERROR; - } - - // Physical address of word in NOR to write. - WordAddr =3D (CurOffset & ~(0x3)) + GET_NOR_BLOCK_ADDRESS ( - Instance->RegionBaseAddress, - Lba, - BlockSize - ); - // The word of data that is to be written. - TmpBuf =3D *((UINT32 *)(Buffer + (*NumBytes - BytesToWrite))); - - // First do word aligned chunks. - if ((CurOffset & 0x3) =3D=3D 0) { - if (BytesToWrite >=3D 4) { - // Is the destination still in 'erased' state? - if (~Tmp !=3D 0) { - // Check to see if we are only changing bits to zero. - if ((Tmp ^ TmpBuf) & TmpBuf) { - DoErase =3D TRUE; - break; - } - } - - // Write this word to NOR - WordToWrite =3D TmpBuf; - CurOffset +=3D sizeof (TmpBuf); - BytesToWrite -=3D sizeof (TmpBuf); - } else { - // BytesToWrite < 4. Do small writes and left-overs - Mask =3D ~((~0) << (BytesToWrite * 8)); - // Mask out the bytes we want. - TmpBuf &=3D Mask; - // Is the destination still in 'erased' state? - if ((Tmp & Mask) !=3D Mask) { - // Check to see if we are only changing bits to zero. - if ((Tmp ^ TmpBuf) & TmpBuf) { - DoErase =3D TRUE; - break; - } - } - - // Merge old and new data. Write merged word to NOR - WordToWrite =3D (Tmp & ~Mask) | TmpBuf; - CurOffset +=3D BytesToWrite; - BytesToWrite =3D 0; - } - } else { - // Do multiple words, but starting unaligned. - if (BytesToWrite > (4 - (CurOffset & 0x3))) { - Mask =3D ((~0) << ((CurOffset & 0x3) * 8)); - // Mask out the bytes we want. - TmpBuf &=3D Mask; - // Is the destination still in 'erased' state? - if ((Tmp & Mask) !=3D Mask) { - // Check to see if we are only changing bits to zero. - if ((Tmp ^ TmpBuf) & TmpBuf) { - DoErase =3D TRUE; - break; - } - } + // Read the old version of the data into the shadow buffer + Status =3D NorFlashRead ( + Instance, + Lba, + Offset & ~BOUNDARY_OF_32_WORDS, + (*NumBytes | BOUNDARY_OF_32_WORDS) + 1, + Instance->ShadowBuffer + ); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } =20 - // Merge old and new data. Write merged word to NOR - WordToWrite =3D (Tmp & ~Mask) | TmpBuf; - BytesToWrite -=3D (4 - (CurOffset & 0x3)); - CurOffset +=3D (4 - (CurOffset & 0x3)); - } else { - // Unaligned and fits in one word. - Mask =3D (~((~0) << (BytesToWrite * 8))) << ((CurOffset & 0x3) *= 8); - // Mask out the bytes we want. - TmpBuf =3D (TmpBuf << ((CurOffset & 0x3) * 8)) & Mask; - // Is the destination still in 'erased' state? - if ((Tmp & Mask) !=3D Mask) { - // Check to see if we are only changing bits to zero. - if ((Tmp ^ TmpBuf) & TmpBuf) { - DoErase =3D TRUE; - break; - } - } + // Make OrigData point to the start of the old version of the data ins= ide + // the word aligned buffer + OrigData =3D Instance->ShadowBuffer + (Offset & BOUNDARY_OF_32_WORDS); =20 - // Merge old and new data. Write merged word to NOR - WordToWrite =3D (Tmp & ~Mask) | TmpBuf; - CurOffset +=3D BytesToWrite; - BytesToWrite =3D 0; - } + // Update the buffer containing the old version of the data with the n= ew + // contents, while checking whether the old version had any bits clear= ed + // that we want to set. In that case, we will need to erase the block = first. + for (CurOffset =3D 0; CurOffset < *NumBytes; CurOffset++) { + if (~OrigData[CurOffset] & Buffer[CurOffset]) { + goto DoErase; } =20 - // - // Write the word to NOR. - // + OrigData[CurOffset] =3D Buffer[CurOffset]; + } =20 - BlockAddress =3D GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,= Lba, BlockSize); - if (BlockAddress !=3D PrevBlockAddress) { - TempStatus =3D NorFlashUnlockSingleBlockIfNecessary (Instance, Blo= ckAddress); - if (EFI_ERROR (TempStatus)) { - return EFI_DEVICE_ERROR; - } + // + // Write the updated buffer to NOR. + // + BlockAddress =3D GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, L= ba, BlockSize); =20 - PrevBlockAddress =3D BlockAddress; - } + // Unlock the block if we have to + Status =3D NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddres= s); + if (EFI_ERROR (Status)) { + goto Exit; + } =20 - TempStatus =3D NorFlashWriteSingleWord (Instance, WordAddr, WordToWr= ite); - // Put device back into Read Array mode - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY= ); + Status =3D NorFlashWriteBuffer ( + Instance, + BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), + P30_MAX_BUFFER_SIZE_IN_BYTES, + Instance->ShadowBuffer + ); + if (EFI_ERROR (Status)) { + goto Exit; + } =20 - if (EFI_ERROR (TempStatus)) { - return EFI_DEVICE_ERROR; + if ((*NumBytes + (Offset & BOUNDARY_OF_32_WORDS)) > P30_MAX_BUFFER_SIZ= E_IN_BYTES) { + BlockAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES; + Status =3D NorFlashWriteBuffer ( + Instance, + BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), + P30_MAX_BUFFER_SIZE_IN_BYTES, + Instance->ShadowBuffer + P30_MAX_BUFFER_SIZE_IN_BY= TES + ); + if (EFI_ERROR (Status)) { + goto Exit; } } =20 - // Exit if we got here and could write all the data. Otherwise do the - // Erase-Write cycle. - if (!DoErase) { - return EFI_SUCCESS; - } - } +Exit: + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); =20 - // Check we did get some memory. Buffer is BlockSize. - if (Instance->ShadowBuffer =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "FvbWrite: ERROR - Buffer not ready\n")); - return EFI_DEVICE_ERROR; + return Status; } =20 +DoErase: // Read NOR Flash data into shadow buffer - TempStatus =3D NorFlashReadBlocks (Instance, Lba, BlockSize, Instance->S= hadowBuffer); - if (EFI_ERROR (TempStatus)) { + Status =3D NorFlashReadBlocks (Instance, Lba, BlockSize, Instance->Shado= wBuffer); + if (EFI_ERROR (Status)) { // Return one of the pre-approved error statuses return EFI_DEVICE_ERROR; } @@ -776,8 +715,8 @@ NorFlashWriteSingleBlock ( CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumB= ytes); =20 // Write the modified buffer back to the NorFlash - TempStatus =3D NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->= ShadowBuffer); - if (EFI_ERROR (TempStatus)) { + Status =3D NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->Shad= owBuffer); + if (EFI_ERROR (Status)) { // Return one of the pre-approved error statuses return EFI_DEVICE_ERROR; } --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95141): https://edk2.groups.io/g/devel/message/95141 Mute This Topic: https://groups.io/mt/94300421/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 Sat May 18 17:16:06 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+95142+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+95142+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655219; cv=none; d=zohomail.com; s=zohoarc; b=brXVlp0StTODCH8D+b2simv7f1qUxvJjFe1/vdTFxP2/mYkst9pYyksppyUCg/17kmD93E5spy6NS3KBNR/D40+koYRNj1/lEtVvVqR8BWmrEPQ/Ah8qrh4yqKPRuMhZkCVdOFl5mxvuZniB5YUO/QKWzhnl5q04RECyYm83ngg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655219; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zlLl23oCHhBOf4DrzZUQmUVMLvaBqdw9PrcgMPFX1Lw=; b=bJZUM7kyBldkOiLY+UiORT9Jl1FPdpyG8NcsBLysNG4oGX9UdmxeyQLwe4HKop+zt4j+qFjlbIoHPmh9odMEkvN5Y8/biT5nkGBJ+MjO1wISyZMzvtqhOE+mRAw9kykLekjOAOldg+LbHSlsGkzWQO3wzhh9NIpGnQkFRoERyVI= 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+95142+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655218974256.91569339261525; Thu, 13 Oct 2022 03:00:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tsl1YY1788612xZmCwYmCArw; Thu, 13 Oct 2022 03:00:18 -0700 X-Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mx.groups.io with SMTP id smtpd.web09.5769.1665655216962509986 for ; Thu, 13 Oct 2022 03:00:17 -0700 X-Received: by mail-pj1-f48.google.com with SMTP id t10-20020a17090a4e4a00b0020af4bcae10so1455914pjl.3 for ; Thu, 13 Oct 2022 03:00:16 -0700 (PDT) X-Gm-Message-State: MM3lIYbY3E4OCUUaVHqyyTv2x1787277AA= X-Google-Smtp-Source: AMsMyM5QM0yE4GDW2KwsXgBK0LCfLYb4O38HC7tt5C+OtrZbmEjTtmIU27bSU+tiD7NU9418THncmw== X-Received: by 2002:a17:903:246:b0:179:b6d0:f8fd with SMTP id j6-20020a170903024600b00179b6d0f8fdmr34501411plh.124.1665655215247; Thu, 13 Oct 2022 03:00:15 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.03.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 03:00:14 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 32/34] OvmfPkg: RiscVVirt: Add Qemu Virt platform support Date: Thu, 13 Oct 2022 15:28:27 +0530 Message-Id: <20221013095829.1454581-33-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655218; bh=5CXRexBifCnbQv3THC3PLEt/qS8nYyIMGbIlF4M5rJA=; h=Cc:Date:From:Reply-To:Subject:To; b=ui5Q8El/OMVPAIr5yCCLZhVwRxOgXkzV7MxQqIHIDJ16RuNnMJA2DRc2IALdb3d/9tV kPZMYjtxwfc9J7tbXkMc7Wt7ReDUWwbwMWnpNIxGNHOejd98QG/FlfVHuB8jW0GbWFDbb LMu/4D3pYKAE1PdG5l3MScC9Up9liythGC8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655220558100003 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 Add infrastructure files to build edk2 for RISC-V qemu virt machine. - EDK2 will boot as S-mode payload of opensbi. - It supports building either code and variables in unified flash or in two separate drives via build time option UNIFIED_NVVARS. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Sunil V L --- OvmfPkg/Platforms/RiscVVirt/RiscVVirt.dsc | 726 ++++++++++++++++++ OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf | 406 ++++++++++ OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf.inc | 66 ++ OvmfPkg/Platforms/RiscVVirt/VarStore.fdf.inc | 79 ++ 4 files changed, 1277 insertions(+) create mode 100644 OvmfPkg/Platforms/RiscVVirt/RiscVVirt.dsc create mode 100644 OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf create mode 100644 OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf.inc create mode 100644 OvmfPkg/Platforms/RiscVVirt/VarStore.fdf.inc diff --git a/OvmfPkg/Platforms/RiscVVirt/RiscVVirt.dsc b/OvmfPkg/Platforms/= RiscVVirt/RiscVVirt.dsc new file mode 100644 index 000000000000..63d95e91abe2 --- /dev/null +++ b/OvmfPkg/Platforms/RiscVVirt/RiscVVirt.dsc @@ -0,0 +1,726 @@ +## @file +# RISC-V EFI on RiscVVirt RISC-V platform +# +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+# Copyright (c) 2022, Ventana Micro Systems Inc. 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 RiscVVirt + PLATFORM_GUID =3D 39DADB39-1B21-4867-838E-830B6149B9E0 + PLATFORM_VERSION =3D 0.1 + DSC_SPECIFICATION =3D 0x0001001c + OUTPUT_DIRECTORY =3D Build/$(PLATFORM_NAME) + SUPPORTED_ARCHITECTURES =3D RISCV64 + BUILD_TARGETS =3D DEBUG|RELEASE|NOOPT + SKUID_IDENTIFIER =3D DEFAULT + FLASH_DEFINITION =3D OvmfPkg/Platforms/RiscVVirt/RiscVVirt= .fdf + + # + # Enable below options may cause build error or may not work on + # the initial version of RISC-V package + # Defines for default states. These can be changed on the command line. + # -D FLAG=3DVALUE + # + DEFINE SECURE_BOOT_ENABLE =3D FALSE + DEFINE DEBUG_ON_SERIAL_PORT =3D TRUE + + # + # Network definition + # + DEFINE NETWORK_SNP_ENABLE =3D FALSE + DEFINE NETWORK_IP6_ENABLE =3D FALSE + DEFINE NETWORK_TLS_ENABLE =3D TRUE + DEFINE NETWORK_HTTP_BOOT_ENABLE =3D TRUE + DEFINE NETWORK_ISCSI_ENABLE =3D FALSE + DEFINE NETWORK_ALLOW_HTTP_CONNECTIONS =3D TRUE + +[BuildOptions] + GCC:RELEASE_*_*_CC_FLAGS =3D -DMDEPKG_NDEBUG +!ifdef $(SOURCE_DEBUG_ENABLE) + GCC:*_*_RISCV64_GENFW_FLAGS =3D --keepexceptiontable +!endif + +[BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] + GCC: *_*_*_DLINK_FLAGS =3D -z common-page-size=3D0x1000 + MSFT: *_*_*_DLINK_FLAGS =3D /ALIGN:4096 + +##########################################################################= ###### +# +# 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] + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniza= tionLib.inf + CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf + PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibN= ull.inf + PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf + CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMain= tenanceLib.inf + UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompres= sLib.inf + UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServic= esLib.inf + HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf + CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableL= ib.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHo= okStatusCodeLibNull.inf + SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPort= Lib16550.inf + PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatfor= mHookLibNull.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBoo= tServicesTableLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/U= efiRuntimeServicesTableLib.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntry= Point.inf + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiA= pplicationEntryPoint.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDev= icePathLibDevicePathProtocol.inf + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeS= ecurityManagementLib.inf + UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf + CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf + SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf + VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseV= ariableFlashInfoLib.inf + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManag= erLib.inf + VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyL= ibRuntimeDxe.inf + FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf + VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/Var= iablePolicyHelperLib.inf + TimerLib|UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf + TimeBaseLib|EmbeddedPkg//Library/TimeBaseLib/TimeBaseLib.inf + RealTimeClockLib|EmbeddedPkg//Library/VirtualRealTimeClockLib/VirtualRea= lTimeClockLib.inf +!ifdef $(UNIFIED_VARSTORE) + NorFlashPlatformLib|OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuUnifiedL= ib.inf +!else + NorFlashPlatformLib|OvmfPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf +!endif + QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf + +!ifdef $(SOURCE_DEBUG_ENABLE) + PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDeb= ug/PeCoffExtraActionLibDebug.inf + DebugCommunicationLib|SourceLevelDebugPkg/Library/DebugCommunicationLibS= erialPort/DebugCommunicationLibSerialPort.inf +!else + PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeC= offExtraActionLibNull.inf + DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.i= nf +!endif + + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseD= ebugPrintErrorLevelLib.inf + +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf + TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasure= mentLib.inf + AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf +!else + TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf + AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf +!endif + VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf + +!if $(HTTP_BOOT_ENABLE) =3D=3D TRUE + HttpLib|MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.inf +!endif + + SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf + OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf + +[LibraryClasses.common] +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf +!endif + + RiscVSbiLib|MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf + + # PCI Libraries + PciLib|MdePkg/Library/BasePciLibPciExpress/BasePciLibPciExpress.inf + PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf + PciCapLib|OvmfPkg/Library/BasePciCapLib/BasePciCapLib.inf + PciCapPciSegmentLib|OvmfPkg/Library/BasePciCapPciSegmentLib/BasePciCapPc= iSegmentLib.inf + PciCapPciIoLib|OvmfPkg/Library/UefiPciCapPciIoLib/UefiPciCapPciIoLib.inf + DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + + # Virtio Support + VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf + VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice= Lib.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf + QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFw= CfgSimpleParserLib.inf + QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf + + # PCI support + PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.i= nf + PciHostBridgeLib|MdeModulePkg/Library/PciHostBridgeLibNull/PciHostBridge= LibNull.inf + + # Boot Manager +!if $(TPM2_ENABLE) =3D=3D TRUE + Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeT= cg2PhysicalPresenceLib.inf + TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasure= mentLib.inf + TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLi= b/PeiDxeTpmPlatformHierarchyLib.inf +!else + TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf + TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLi= bNull/PeiDxeTpmPlatformHierarchyLib.inf +!endif + + BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf + PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrin= tScLib.inf + + PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLibVirt/Platfo= rmBootManagerLib.inf + + FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf + QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf + +[LibraryClasses.common.SEC] +!ifdef $(DEBUG_ON_SERIAL_PORT) + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!else + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!endif + + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiRepor= tStatusCodeLib.inf + ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseE= xtractGuidedSectionLib.inf + +!ifdef $(SOURCE_DEBUG_ENABLE) + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib= .inf +!endif + + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAlloc= ationLib.inf + PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.= inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + +[LibraryClasses.common.PEI_CORE] + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/Pei= ServicesTablePointerLib.inf + PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAlloc= ationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiRepor= tStatusCodeLib.inf + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHo= okStatusCodeLibNull.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf +!ifdef $(DEBUG_ON_SERIAL_PORT) + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!else + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!endif + PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf + PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf + +[LibraryClasses.common.PEIM] + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/Pei= ServicesTablePointerLib.inf + PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAlloc= ationLib.inf + PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf + ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiRepor= tStatusCodeLib.inf + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHo= okStatusCodeLibNull.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf +!ifdef $(DEBUG_ON_SERIAL_PORT) + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!else + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!endif + PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf + PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiRe= sourcePublicationLib.inf + ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExt= ractGuidedSectionLib.inf +!ifdef $(SOURCE_DEBUG_ENABLE) + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib= .inf +!endif + ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResou= rcePublicationLib.inf + +[LibraryClasses.common.DXE_CORE] + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf + HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf + DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf + MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeC= oreMemoryAllocationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf +!ifdef $(DEBUG_ON_SERIAL_PORT) + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!else + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!endif + ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExt= ractGuidedSectionLib.inf +!ifdef $(SOURCE_DEBUG_ENABLE) + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf +!endif + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + +[LibraryClasses.common.DXE_RUNTIME_DRIVER] + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf + DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/R= untimeDxeReportStatusCodeLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf +!ifdef $(DEBUG_ON_SERIAL_PORT) + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!else + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!endif +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf +!endif + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManag= erLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + +[LibraryClasses.common.UEFI_DRIVER] + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf +!ifdef $(DEBUG_ON_SERIAL_PORT) + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!else + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!endif + UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf + VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyL= ib.inf + PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExp= ressLib.inf + PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.= inf + PciHostBridgeLib|OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostB= ridgeUtilityLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + +[LibraryClasses.common.DXE_DRIVER] + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf + UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf +!ifdef $(DEBUG_ON_SERIAL_PORT) + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!else + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!endif +!ifdef $(SOURCE_DEBUG_ENABLE) + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf +!endif + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManag= erLib.inf + PlatformUpdateProgressLib|MdeModulePkg/Library/PlatformBootManagerLibNul= l/PlatformBootManagerLibNull.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + +[LibraryClasses.common.UEFI_APPLICATION] + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf +!ifdef $(DEBUG_ON_SERIAL_PORT) + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!else + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!endif + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + +##########################################################################= ###### +# +# Pcd Section - list of all EDK II PCD Entries defined by this Platform. +# +##########################################################################= ###### +[PcdsFeatureFlag] + gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportUefiDecompress|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE + +[PcdsFixedAtBuild] + gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1 + gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE + gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x10 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize|0x8000 + gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 + gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE + + gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 + + gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x02 + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F +!ifdef $(SOURCE_DEBUG_ENABLE) + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17 +!else + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F +!endif + +!ifdef $(SOURCE_DEBUG_ENABLE) + gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2 +!endif + +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + # override the default values from SecurityPkg to ensure images from all= sources are verified in secure boot + gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x04 + gEfiSecurityPkgTokenSpaceGuid.PcdFixedMediaImageVerificationPolicy|0x04 + gEfiSecurityPkgTokenSpaceGuid.PcdRemovableMediaImageVerificationPolicy|0= x04 +!endif + + # + # F2 for UI APP + # + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } + + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"2.7" + + # Serial Port + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x10000000 + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate|9600 + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|3686400 + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|1 + +##########################################################################= ###### +# +# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Pla= tform +# +##########################################################################= ###### + +[PcdsDynamicDefault] + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800 + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600 + + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|10 + + # Set video resolution for text setup. + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution|640 + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution|480 + + gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion|0x0208 + gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 + +##########################################################################= ###### +# +# Components Section - list of all EDK II Modules needed by this Platform. +# +##########################################################################= ###### +[Components] + + # + # SEC Phase modules + # + OvmfPkg/Sec/SecMain.inf { + + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompre= ssLib.inf + } + + # + # PEI Phase modules + # + MdeModulePkg/Core/Pei/PeiMain.inf + MdeModulePkg/Universal/PCD/Pei/Pcd.inf { + + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouter= Pei.inf + MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf + MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf { + + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompress= Lib.inf + } + + OvmfPkg/PlatformPei/PlatformPei.inf { + + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + PlatformInitLib|OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf + } + + # + # DXE Phase modules + # + MdeModulePkg/Core/Dxe/DxeMain.inf { + + NULL|MdeModulePkg//Library/LzmaCustomDecompressLib/LzmaCustomDecompr= essLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.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 + +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { + + NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificatio= nLib.inf + } +!else + MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf +!endif + + MdeModulePkg/Universal/Metronome/Metronome.inf + EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf + + # + # RISC-V Platform module + # + UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf + + OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.inf + + # + # RISC-V Core module + # + UefiCpuPkg/CpuDxe/CpuDxe.inf + MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf + + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { + + NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf + } + MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf + MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntim= eDxe.inf + MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf + MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf + +# Graphic console + MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf + + MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf + MdeModulePkg/Universal/PrintDxe/PrintDxe.inf + MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf + MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf + MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf + MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf + MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf + MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf + MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf + MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf + MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf + MdeModulePkg/Universal/SerialDxe/SerialDxe.inf + + # + # Network Support + # + !include NetworkPkg/Network.dsc.inc + + # + # 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 + + # + # PCI support + # + UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf { + + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + } + MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf + MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { + + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + } + OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf + OvmfPkg/Virtio10Dxe/Virtio10.inf + + # + # Video support + # + OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf + OvmfPkg/VirtioGpuDxe/VirtioGpu.inf + OvmfPkg/PlatformDxe/Platform.inf + + # + # Platform Driver + # + OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf + EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf + OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf + OvmfPkg/VirtioBlkDxe/VirtioBlk.inf + OvmfPkg/VirtioScsiDxe/VirtioScsi.inf + OvmfPkg/VirtioNetDxe/VirtioNet.inf + OvmfPkg/VirtioRngDxe/VirtioRng.inf + + MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf + OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf + + # + # FAT filesystem + GPT/MBR partitioning + UDF filesystem + # + FatPkg/EnhancedFatDxe/Fat.inf + MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + + OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + } + + 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/UefiShellAcpiViewCommandLib/UefiShellAcpiViewC= ommandLib.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 + } + +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDx= e.inf +!endif + + # + # Bds + # + MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf { + + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + } + MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf + MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf + MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.inf + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf + MdeModulePkg/Logo/LogoDxe.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 + } + +# HTTPS(secure) support in GUI for updating ssl keys for PXE boot + MdeModulePkg/Application/UiApp/UiApp.inf { + + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc= eManagerUiLib.inf + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib= .inf + } + +# TFTP support for PXE boot + ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + } + ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + } + + # HTTP support for PXE boot + ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + HttpLib|NetworkPkg/Library/DxeHttpLib/DxeHttpLib.inf + } + ShellPkg/DynamicCommand/HttpDynamicCommand/HttpApp.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + HttpLib|NetworkPkg/Library/DxeHttpLib/DxeHttpLib.inf + } + +# HTTPS (secure) support for PXE boot + NetworkPkg/TlsDxe/TlsDxe.inf { + + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf + IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf + RngLib|MdePkg/Library/DxeRngLib/DxeRngLib.inf + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib= .inf + } + NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf { + + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib= .inf + NULL|OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf + } + +[PcdsDynamicDefault.common] + # set PcdPciExpressBaseAddress to MAX_UINT64, which signifies that this + # PCD and PcdPciDisableBusEnumeration above have not been assigned yet + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xFFFFFFFFFFFFFFFF + + gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation|0x0 + +[PcdsFeatureFlag.common] + gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE + gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|TRUE + + ## If TRUE, Graphics Output Protocol will be installed on virtual handle= created by ConsplitterDxe. + # It could be set FALSE to save size. + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE diff --git a/OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf b/OvmfPkg/Platforms/= RiscVVirt/RiscVVirt.fdf new file mode 100644 index 000000000000..3e0e0eb9ae77 --- /dev/null +++ b/OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf @@ -0,0 +1,406 @@ +# @file +# Flash definition file on RiscVVirt RISC-V platform +# +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# Platform definitions +# + +!include RiscVVirt.fdf.inc + +##########################################################################= ###### +!ifdef UNIFIED_VARSTORE +[FD.RISCV_VIRT] +BaseAddress =3D $(FW_BASE_ADDRESS)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdB= aseAddress +Size =3D $(FW_SIZE)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdS= ize +ErasePolarity =3D 1 +BlockSize =3D $(BLOCK_SIZE) +NumBlocks =3D $(FW_BLOCKS) + +$(SECFV_OFFSET)|$(SECFV_SIZE) +FV =3D SECFV + +$(FVMAIN_OFFSET)|$(FVMAIN_SIZE) +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvBaseAddress|gUefiOvmfPkgTokenSpaceGuid= .PcdOvmfFvSize +FV =3D FVMAIN_COMPACT + +!include VarStore.fdf.inc + +!else +[FD.RISCV_CODE] +BaseAddress =3D $(FW_BASE_ADDRESS)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdB= aseAddress +Size =3D $(CODE_SIZE) +ErasePolarity =3D 1 +BlockSize =3D $(BLOCK_SIZE) +NumBlocks =3D $(CODE_BLOCKS) + +$(SECFV_OFFSET)|$(SECFV_SIZE) +FV =3D SECFV + +$(FVMAIN_OFFSET)|$(FVMAIN_SIZE) +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvBaseAddress|gUefiOvmfPkgTokenSpaceGuid= .PcdOvmfFvSize +FV =3D FVMAIN_COMPACT + +##########################################################################= ###### +[FD.RISCV_NVVARS] +BaseAddress =3D $(VARS_BASE_ADDRESS) +Size =3D $(VARS_SIZE) +ErasePolarity =3D 1 +BlockSize =3D $(VARS_BLOCK_SIZE) +NumBlocks =3D $(VARS_BLOCKS) + +!include VarStore.fdf.inc +!endif +##########################################################################= ###### + +[FD.RISCV_MEMFD] +BaseAddress =3D $(MEMFD_BASE_ADDRESS) +Size =3D 0x00a00000 +ErasePolarity =3D 1 +BlockSize =3D $(BLOCK_SIZE) +NumBlocks =3D 0xa00 + +0x00000000|0x00010000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize + +0x00010000|0x001000 +gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|gUefiOvmfPkgT= okenSpaceGuid.PcdGuidedExtractHandlerTableSize + +0x00040000|0x00080000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase|gUefiOvmfPkgTokenSpaceGuid.= PcdOvmfPeiMemFvSize +FV =3D PEIFV + +0x00100000|0x00900000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase|gUefiOvmfPkgTokenSpaceGuid.= PcdOvmfDxeMemFvSize +FV =3D DXEFV + +##########################################################################= ################ + +[FV.SECFV] +BlockSize =3D 0x1000 +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 + +# +# SEC Phase modules +# +# The code in this FV handles the initial firmware startup, and +# decompresses the PEI and DXE FVs which handles the rest of the boot sequ= ence. +# +INF OvmfPkg/Sec/SecMain.inf + +##########################################################################= ###### +[FV.PEIFV] +BlockSize =3D 0x10000 +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 + +APRIORI PEI { + INF MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeR= outerPei.inf + INF MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.i= nf + INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf +} + +# +# PEI Phase modules +# +INF MdeModulePkg/Core/Pei/PeiMain.inf +INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf +INF MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRou= terPei.inf +INF MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf +INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf + +# RISC-V Platform PEI Driver +INF OvmfPkg/PlatformPei/PlatformPei.inf + +##########################################################################= ###### + +[FV.DXEFV] +BlockSize =3D 0x10000 +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 + +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 + +# +# PCI support +# +INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.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 + +# +# Video support +# +INF OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf +INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf +INF OvmfPkg/PlatformDxe/Platform.inf + +# +# Platform Driver +# +INF OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf +INF EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf +INF OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf +INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf +INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf +INF OvmfPkg/VirtioNetDxe/VirtioNet.inf +INF OvmfPkg/VirtioRngDxe/VirtioRng.inf +INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf +INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf + +INF MdeModulePkg/Universal/Metronome/Metronome.inf +INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf + +INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf +INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf +INF OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf + +# RISC-V Platform Drivers +INF OvmfPkg/Drivers/NorFlashDxe/NorFlashDxe.inf + +# RISC-V Core Drivers +INF UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf +INF UefiCpuPkg/CpuDxe/CpuDxe.inf + +INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf + +INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootCon= figDxe.inf +!endif + +INF MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf +INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf +INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRun= timeDxe.inf +INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf +INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf +INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf +INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.= inf +INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf +INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf +INF MdeModulePkg/Universal/PrintDxe/PrintDxe.inf +INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf +INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf +INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf +INF MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf +INF MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf +INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf +INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf +INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe= .inf +INF FatPkg/EnhancedFatDxe/Fat.inf +INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + +!ifndef $(SOURCE_DEBUG_ENABLE) +INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf +!endif + +INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .inf +INF ShellPkg/Application/Shell/Shell.inf + +# TFTP support for PXE boot +INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf +INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf + +# HTTP support for PXE boot +INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf +INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpApp.inf + +# +# Network modules +# +!if $(E1000_ENABLE) + FILE DRIVER =3D 5D695E11-9B3F-4b83-B25F-4A8D5D69BE07 { + SECTION PE32 =3D Intel3.5/EFIX64/E3507X2.EFI + } +!endif + +!include NetworkPkg/Network.fdf.inc + +# +# 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 + +INF MdeModulePkg/Application/UiApp/UiApp.inf +INF OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf + +##########################################################################= ###### + +[FV.FVMAIN_COMPACT] +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 +FvNameGuid =3D 27A72E80-3118-4c0c-8673-AA5B4EFA9613 + +FILE FV_IMAGE =3D 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 { + SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED= =3D TRUE { + # + # These firmware volumes will have files placed in them uncompressed, + # and then both firmware volumes will be compressed in a single + # compression operation in order to achieve better overall compressio= n. + # + SECTION FV_IMAGE =3D PEIFV + SECTION FV_IMAGE =3D DXEFV + } + } + +[Rule.Common.SEC] + FILE SEC =3D $(NAMED_GUID) RELOCS_STRIPPED { + PE32 PE32 Align=3D4K $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING =3D"$(MODULE_NAME)" Optional + VERSION STRING =3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBE= R) + } + +[Rule.Common.PEI_CORE] + FILE PEI_CORE =3D $(NAMED_GUID) { + PE32 PE32 Align=3D4K $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING =3D"$(MODULE_NAME)" Optional + VERSION STRING =3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBE= R) + } + +[Rule.Common.PEIM] + FILE PEIM =3D $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align=3D4K $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBE= R) + } + +[Rule.Common.DXE_CORE] + FILE DXE_CORE =3D $(NAMED_GUID) { + PE32 PE32 Align=3D4K $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBER) + } + +[Rule.Common.DXE_DRIVER] + FILE DRIVER =3D $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align=3D4K $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBER) + } + +[Rule.Common.DXE_RUNTIME_DRIVER] + FILE DRIVER =3D $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align =3D 4K $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBER) + } + +[Rule.Common.UEFI_DRIVER] + FILE DRIVER =3D $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align=3D4K $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBER) + } + +[Rule.Common.UEFI_DRIVER.BINARY] + FILE DRIVER =3D $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional |.depex + PE32 PE32 Align=3D4K |.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 Align=3D4K $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBER) + } + +[Rule.Common.UEFI_APPLICATION.BINARY] + FILE APPLICATION =3D $(NAMED_GUID) { + PE32 PE32 Align=3D4K |.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/Platforms/RiscVVirt/RiscVVirt.fdf.inc b/OvmfPkg/Platfo= rms/RiscVVirt/RiscVVirt.fdf.inc new file mode 100644 index 000000000000..5a2d96d53c8e --- /dev/null +++ b/OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf.inc @@ -0,0 +1,66 @@ +## @file +# Definitions of Flash definition file on RiscVVirt RISC-V platform +# +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## +[Defines] +DEFINE BLOCK_SIZE =3D 0x1000 + +DEFINE PFLASH1_BASE =3D 0x22000000 +DEFINE PFLASH2_BASE =3D 0x23000000 + +DEFINE FW_BASE_ADDRESS =3D $(PFLASH1_BASE) +DEFINE FW_SIZE =3D 0x00300000 +DEFINE FW_BLOCKS =3D 0x300 + +DEFINE CODE_BASE_ADDRESS =3D $(FW_BASE_ADDRESS) +DEFINE CODE_SIZE =3D 0x00240000 +DEFINE CODE_BLOCKS =3D 0x240 + +# +# Separate varstore will start at 3rd pflash address +# +DEFINE VARS_BASE_ADDRESS =3D $(PFLASH2_BASE) + +DEFINE VARS_SIZE =3D 0x000C0000 +DEFINE VARS_BLOCK_SIZE =3D 0x40000 +DEFINE VARS_BLOCKS =3D 0x3 + +# +# The size of memory region must be power of 2. +# The base address must be aligned with the size. +# +# FW memory region +# +DEFINE SECFV_OFFSET =3D 0x00000000 +DEFINE SECFV_SIZE =3D 0x00040000 +DEFINE FVMAIN_OFFSET =3D 0x00040000 +DEFINE FVMAIN_SIZE =3D 0x00200000 + +# +# EFI Variable memory region. +# The total size of EFI Variable FD must include +# all of sub regions of EFI Variable +# +!ifdef $(UNIFIED_VARSTORE) +DEFINE VARS_OFFSET =3D $(CODE_SIZE) +!else +DEFINE VARS_OFFSET =3D 0x00000000 +!endif +DEFINE VARS_LIVE_SIZE =3D 0x00040000 +DEFINE VARS_FTW_WORKING_OFFSET =3D $(VARS_OFFSET) + $(VARS_LIVE_SIZE) +DEFINE VARS_FTW_WORKING_SIZE =3D 0x00040000 +DEFINE VARS_FTW_SPARE_OFFSET =3D $(VARS_FTW_WORKING_OFFSET) + $(VA= RS_FTW_WORKING_SIZE) +DEFINE VARS_FTW_SPARE_SIZE =3D 0x00040000 + +# +# Base Address where SEC phase will decompress and load +# the PEI and DXE FVs +# +DEFINE MEMFD_BASE_ADDRESS =3D 0x80200000 + +SET gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency =3D 10000000 diff --git a/OvmfPkg/Platforms/RiscVVirt/VarStore.fdf.inc b/OvmfPkg/Platfor= ms/RiscVVirt/VarStore.fdf.inc new file mode 100644 index 000000000000..30b170d77997 --- /dev/null +++ b/OvmfPkg/Platforms/RiscVVirt/VarStore.fdf.inc @@ -0,0 +1,79 @@ +## @file +# FDF include file with Layout Regions that define an empty variable stor= e. +# +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+# Copyright (C) 2014, Red Hat, Inc. +# Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +$(VARS_OFFSET)|$(VARS_LIVE_SIZE) +gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|gEfiMdeModule= PkgTokenSpaceGuid.PcdFlashNvStorageVariableSize +# +# 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: 0x20000 + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + # Signature "_FVH" # Attributes + 0x5f, 0x46, 0x56, 0x48, 0xff, 0xfe, 0x04, 0x00, + # HeaderLength # CheckSum # ExtHeaderOffset #Reserved #Revision + 0x48, 0x00, 0x39, 0xF1, 0x00, 0x00, 0x00, 0x02, + # Blockmap[0]: 0x20 Blocks * 0x1000 Bytes / Block + 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + # Blockmap[1]: End + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ## This is the VARIABLE_STORE_HEADER +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + # 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, +!else + # Signature: gEfiVariableGuid =3D + # { 0xddcf3616, 0x3275, 0x4164, + # { 0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d }} + 0x16, 0x36, 0xcf, 0xdd, 0x75, 0x32, 0x64, 0x41, + 0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d, +!endif + # 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 +} + +$(VARS_FTW_WORKING_OFFSET)|$(VARS_FTW_WORKING_SIZE) +gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|gEfiMdeModu= lePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize +# +#NV_FTW_WROK +# +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 + 0x2c, 0xaf, 0x2c, 0x64, 0xFE, 0xFF, 0xFF, 0xFF, + # WriteQueueSize: UINT64 + 0xE0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +} + +$(VARS_FTW_SPARE_OFFSET)|$(VARS_FTW_SPARE_SIZE) +gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|gEfiMdeModule= PkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize +# +#NV_FTW_SPARE --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95142): https://edk2.groups.io/g/devel/message/95142 Mute This Topic: https://groups.io/mt/94300422/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 Sat May 18 17:16:06 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+95144+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+95144+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655232; cv=none; d=zohomail.com; s=zohoarc; b=m3YVfpWoMa4A1R3Xmuf70mfvPGaiLCuTZ4JJFXkyIFkXsTRMLkcwUU7eRONGu1t/CP172ia4tTwrqB6vfANZoSFOQvAAmYkzF8Va5pEeGuysaeL590scbr2GvaSyh9V7yl2BgnFxZfapkRSCJLchx/iObSbtVYAegAGZXYracUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655232; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=bZvQUPR7ywt4mfPv9xDajF4zdWYWFUZriaxAgnHXqe8=; b=aMOPPydGGOkJgClQI2ShWvYWJukZF6KJNpfQiMsRDgdpSViYUMZIRfQhqp4f9QCJpeT6NOtMmjhZYawn7RzhZzcpdH5lS4es6ABaNzpWztrhh4KSY2UVbjTDlkc4gkztAkmQyuPsMVXYhVHuj6vyZhZrCIQZPen6RselKuWAKEc= 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+95144+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665655232841584.2215370158008; Thu, 13 Oct 2022 03:00:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RTRjYY1788612xWwqJKzILQG; Thu, 13 Oct 2022 03:00:32 -0700 X-Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by mx.groups.io with SMTP id smtpd.web09.5771.1665655228697527913 for ; Thu, 13 Oct 2022 03:00:28 -0700 X-Received: by mail-pj1-f49.google.com with SMTP id a6-20020a17090abe0600b0020d7c0c6650so4511454pjs.0 for ; Thu, 13 Oct 2022 03:00:28 -0700 (PDT) X-Gm-Message-State: bs6UHsHqFQsQseCGhXSQMebyx1787277AA= X-Google-Smtp-Source: AMsMyM4VEj/G9UQgCumNctwpfv8UNZx+9bfrPRw5G52GRN5HB0vhTXHjBsXlfcBZ3ZZw0bO2AXuC0w== X-Received: by 2002:a17:902:e88a:b0:183:9ecb:ff85 with SMTP id w10-20020a170902e88a00b001839ecbff85mr13792645plg.169.1665655217468; Thu, 13 Oct 2022 03:00:17 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.03.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 03:00:17 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Andrew Fish , Leif Lindholm , Michael D Kinney Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 33/34] Maintainers.txt: Add entry for OvmfPkg/RiscVVirt Date: Thu, 13 Oct 2022 15:28:28 +0530 Message-Id: <20221013095829.1454581-34-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655232; bh=tkEeAy6jC2aw+wm0+BFzKkFH8alZmChc5sUR8mhyAdU=; h=Cc:Date:From:Reply-To:Subject:To; b=Q1Tfp9DMfhQhI57D8cmBHcbMbNKVwV6P49o9NLWDPjfcRlZjkHEoZVyTHVUai6tDSX5 7LxtShgzp05gFrc+bs3RbN4PTvXyD40Ke1z4YMcRR5ApZh4b3WCPjAoYVlwYRiHMxTa8f YjShn/IHCyZ6AnU0ehfMV1w289wRoIvtcNU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655234520100002 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 RiscVVirt is created to support EDK2 for RISC-V qemu virt machine platform. Add maintainer entries. Cc: Andrew Fish Cc: Leif Lindholm Cc: Michael D Kinney Signed-off-by: Sunil V L --- Maintainers.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Maintainers.txt b/Maintainers.txt index c641414109ad..ed8891b34606 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -527,6 +527,10 @@ F: OvmfPkg/XenResetVector/ R: Anthony Perard [sheep] R: Julien Grall [jgrall] =20 +OvmfPkg: RISC-V Qemu Virt Platform +F: OvmfPkg/Platforms/RiscVVirt +R: Sunil V L [vlsunil] + PcAtChipsetPkg F: PcAtChipsetPkg/ W: https://github.com/tianocore/tianocore.github.io/wiki/PcAtChipsetPkg --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95144): https://edk2.groups.io/g/devel/message/95144 Mute This Topic: https://groups.io/mt/94300424/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 Sat May 18 17:16:06 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+95143+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+95143+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665655225; cv=none; d=zohomail.com; s=zohoarc; b=axbVi5YupjfVjLHfTX4AK/RUnpAgHe6ZfN81GxmFDsRLCvqn760ByJyxE+odCfAK3Yh1BEoXrddQsKnUVjKE6pkIaLA9Vz83VEiNVs70Q3+gpgCVjdPDx/InILMrbwCCFI5yjlLlkX3zp0iunMyf7pWb+15BmINPCGZatEVnPQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665655225; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=lzf8e1H5V/dp6C9dtkFIFhVbznH9WjY01RHAmxC7Ig0=; b=l4OC06B6pxpC4orFJmfv3C0SphGj69eM3h0yeBkT8CO4KUfP0Br4RzcD7Scc2kAGnzyfzJzWBzoshXLZ3TSM6IGAfYfoH7KjEsnerPgLFQ8bGEugnhELNlDDLBSHOlkLW9cc3+eLjHPRUjxiXwAubaM6ucs5d8qs8c9F0dXe8rE= 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+95143+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16656552254681005.9525817054587; Thu, 13 Oct 2022 03:00:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eqAAYY1788612x1IkDjitol0; Thu, 13 Oct 2022 03:00:25 -0700 X-Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by mx.groups.io with SMTP id smtpd.web12.5678.1665655199255012782 for ; Thu, 13 Oct 2022 03:00:20 -0700 X-Received: by mail-pj1-f50.google.com with SMTP id fw14so1510894pjb.3 for ; Thu, 13 Oct 2022 03:00:20 -0700 (PDT) X-Gm-Message-State: IYZuCLg8aAaBehObm5cyXWctx1787277AA= X-Google-Smtp-Source: AMsMyM6WFcUJRkr1XHQx9uaDjKuB7brO+VPSfSvbpJS/ZRtiY6dwkbAgTGfIZk3S2/7W+wh1LOLZ/g== X-Received: by 2002:a17:90b:4a11:b0:20d:382d:3994 with SMTP id kk17-20020a17090b4a1100b0020d382d3994mr10137030pjb.173.1665655219753; Thu, 13 Oct 2022 03:00:19 -0700 (PDT) X-Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id w8-20020a17090abc0800b0020d43c5c9a0sm2931845pjr.18.2022.10.13.03.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 03:00:19 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 34/34] UefiCpuPkg/UefiCpuPkg.ci.yaml: Ignore RISC-V file Date: Thu, 13 Oct 2022 15:28:29 +0530 Message-Id: <20221013095829.1454581-35-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-1-sunilvl@ventanamicro.com> References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sunilvl@ventanamicro.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665655225; bh=ypVZ4TKKzBcyyt0EyaOjc66vVl8JzaLUKX8AZiAFDJA=; h=Cc:Date:From:Reply-To:Subject:To; b=tdjwX+RG4k00dfAPdSOuPKBd87t8dhBOfFIPZEB4+gE55c/GxRzmfciotuuYOmccfAu M561qIWNoyji7OIXK/AH/+WkEjFupU5KlJM7ZpLEJHjspZhwJrTcwHYQ1/bh0UfFZgbex 7AaAzjz/dlviJ4TKDOQFyGUft5+G7yaGcZA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665655226489100002 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 RISC-V register names do not follow the EDK2 formatting. So, add it to ignore list for now. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Sunil V L --- UefiCpuPkg/UefiCpuPkg.ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/UefiCpuPkg/UefiCpuPkg.ci.yaml b/UefiCpuPkg/UefiCpuPkg.ci.yaml index bbdc44a45b34..ae963e94c8e6 100644 --- a/UefiCpuPkg/UefiCpuPkg.ci.yaml +++ b/UefiCpuPkg/UefiCpuPkg.ci.yaml @@ -19,6 +19,7 @@ ], ## Both file path and directory path are accepted. "IgnoreFiles": [ + "Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLib.h" ] }, "CompilerPlugin": { --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95143): https://edk2.groups.io/g/devel/message/95143 Mute This Topic: https://groups.io/mt/94300423/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-