From nobody Sun Feb 8 05:40:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106941+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+106941+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689361732; cv=none; d=zohomail.com; s=zohoarc; b=k7pOhMA3rp0qUS/Pn1EhXEvuGVu4KL39hUwwJhAojOulRAOyoo737H713m9P+Hw8sRTBjs0JpR4Wzp4gYIMxMfMFODLzO1aQbBIydZQgvX7ScIponpgzo6uYSdUEMbD0lo7cTYcPjTHtBiFmPRlSBhapBOAgQ0+Z+0L4YqRIfK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689361732; 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=tnYV15iqYe24tylnLW3VtimeVNCj8M5dSbR04kMP2dM=; b=cahBNAS+So6yyPAbWvrlIRODzW6w0htH2tjSoI86hWGC2yfgjyH3iISq4FJUhS/iX5oyaWxAY3z/3LMp2pCrHdOQX+Y4OwZVZb7S8rvHrgex7FGEEyTFmf7FCUbDSci4tOvTl5m8L8leYzLQm7RrJGvWlU8bfisubFZFFkVbDO0= 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+106941+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689361732192637.6766789004201; Fri, 14 Jul 2023 12:08:52 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=ooq2MKdsk9y6tgbQlSnJUHdYiuLH5KilC5/jxxCYotw=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689361731; v=1; b=ivcczm6YoVUnfR/uHaVG5GMteHLvKFWnq1sDNpSVLVzyK7zG+boRnc3j/gM9EIbKrI5tnsp9 wiyn+o2+6++v1GURfSufzDOQILIYpjeh5OlNgrISVKJ4dDzBzUPAXDXmRjt7WJNC0CY7/Vt9CZh qLnJ93XvqlyDFwGCjG1bjjY0= X-Received: by 127.0.0.2 with SMTP id uFPHYY1788612xJfSNAupQsA; Fri, 14 Jul 2023 12:08:51 -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.3993.1689361731233021650 for ; Fri, 14 Jul 2023 12:08:51 -0700 X-Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1b9e93a538dso12477615ad.3 for ; Fri, 14 Jul 2023 12:08:51 -0700 (PDT) X-Gm-Message-State: 32u9zKgLVGicMJpofDWZRLifx1787277AA= X-Google-Smtp-Source: APBJJlHfGFiAIXjGKhy2n+fKpW4q3f8lSIjuPvcX5y62j8NHck4diG/mUUBlZM84060kQbvYdBz2Qg== X-Received: by 2002:a17:902:da8f:b0:1b8:8b2e:ae36 with SMTP id j15-20020a170902da8f00b001b88b2eae36mr4471335plx.3.1689361730275; Fri, 14 Jul 2023 12:08:50 -0700 (PDT) X-Received: from localhost.localdomain (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id p18-20020a170902ead200b001a98f844e60sm8041413pld.263.2023.07.14.12.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 12:08:49 -0700 (PDT) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com, ardb+tianocore@kernel.org, Tuan Phan Subject: [edk2-devel] [PATCH v5 4/7] OvmfPkg/RiscVVirt: SEC: Add IO memory resource hob for platform devices Date: Fri, 14 Jul 2023 12:08:21 -0700 Message-Id: <20230714190824.16552-5-tphan@ventanamicro.com> In-Reply-To: <20230714190824.16552-1-tphan@ventanamicro.com> References: <20230714190824.16552-1-tphan@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,tphan@ventanamicro.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689361734169100013 Content-Type: text/plain; charset="utf-8" Normally, DXE driver would add device resource to GCD before start using. But some key resources such as uart used for printing info at very early stage. Those resources should be populated to HOB in SEC phase so they are added to GCD before MMU enabled. Signed-off-by: Tuan Phan Reviewed-by: Andrei Warkentin --- OvmfPkg/RiscVVirt/Sec/Platform.c | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/OvmfPkg/RiscVVirt/Sec/Platform.c b/OvmfPkg/RiscVVirt/Sec/Platf= orm.c index 3645c27b0b12..c66432473067 100644 --- a/OvmfPkg/RiscVVirt/Sec/Platform.c +++ b/OvmfPkg/RiscVVirt/Sec/Platform.c @@ -21,6 +21,64 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include =20 +/** + 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. + +**/ +STATIC +VOID +AddIoMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ) +{ + /* Align to EFI_PAGE_SIZE */ + MemorySize =3D ALIGN_VALUE (MemorySize, EFI_PAGE_SIZE); + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + MemoryBase, + MemorySize + ); +} + +/** + Populate IO resources from FDT that not added to GCD by its + driver in the DXE phase. + + @param FdtBase Fdt base address + @param Compatible Compatible string + +**/ +STATIC +VOID +PopulateIoResources ( + VOID *FdtBase, + CONST CHAR8 *Compatible + ) +{ + UINT64 *Reg; + INT32 Node, LenP; + + Node =3D fdt_node_offset_by_compatible (FdtBase, -1, Compatible); + while (Node !=3D -FDT_ERR_NOTFOUND) { + Reg =3D (UINT64 *)fdt_getprop (FdtBase, Node, "reg", &LenP); + if (Reg) { + ASSERT (LenP =3D=3D (2 * sizeof (UINT64))); + AddIoMemoryBaseSizeHob (SwapBytes64 (Reg[0]), SwapBytes64 (Reg[1])); + } + + Node =3D fdt_node_offset_by_compatible (FdtBase, Node, Compatible); + } +} + /** @retval EFI_SUCCESS The address of FDT is passed in HOB. EFI_UNSUPPORTED Can't locate FDT. @@ -80,5 +138,9 @@ PlatformPeimInitialization ( =20 BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSiz= e)); =20 + PopulateIoResources (Base, "ns16550a"); + PopulateIoResources (Base, "qemu,fw-cfg-mmio"); + PopulateIoResources (Base, "virtio,mmio"); + 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 (#106941): https://edk2.groups.io/g/devel/message/106941 Mute This Topic: https://groups.io/mt/100147810/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-