From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mx.groups.io with SMTP id smtpd.web10.19046.1681498724900000614 for ; Fri, 14 Apr 2023 11:58:44 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=AyJ6lMw3; spf=pass (domain: ventanamicro.com, ip: 209.85.214.174, mailfrom: tphan@ventanamicro.com) Received: by mail-pl1-f174.google.com with SMTP id lh8so6260128plb.1 for ; Fri, 14 Apr 2023 11:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681498724; x=1684090724; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qfk4sUWspZr87Pw9l/O0AFGclPH8B9NM5XZHOaclpnA=; b=AyJ6lMw3vJVEw6b9+woyq0ZofzD1PArIN/5TfNlozTj0SYmy5Ojmxd0pZqU9Uv26VB ih587gxhft9wHPp3EcmmhB10W1IT+Zf6d+AaqvrU1p442FeevxbPMwsOba0i3+k+dQOx doQPEs82Zmqn8wCdLtALjLWRn5FuGTnklofYtZ6QOwGxceHlVlSoqoIGzm+h1qFAAC4R Q4loeM0zpIhj5POebYxw8G3kgwafjJshI6407hcfr1pAUaYNRHqJt1mJ7MQxQhbvSCGf 7ydQmXdMirYZtPyejpyW+biAv2pdaZOS1gz/VnKIzmDcRhQiJtjRvQPi5S2d6zMxWklO hgxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681498724; x=1684090724; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qfk4sUWspZr87Pw9l/O0AFGclPH8B9NM5XZHOaclpnA=; b=M49GoS0sjCbA1a1eJB+yjDkyqJ+KrAZANLc8xW54CcY2D9QhQ5T8u7Nqfv2UCS2FhD 9fT4SXN8ksNir/FvyVxQOTAUXBrTczx1A2tSNbqeT80QyUXda4OnNzOHVD0zxJrVIp7t djGSvhXJPD2iwEyrZvbqe1EzhuLY4bEvh2tSkhUlPaosJnb37wKqNsWsyc3B1fVqy/kK 9qTuy0BnFnrMRzB5Mgb8i3a5/sm9Mld4mnskku2Q5xeE7P4SdHb8k1DCGlaRoac46M/H NkzzS9EP3p150ylph3bZIWmQlwhfi/pcn16fMaLBr4z0V2cuW40d91jvgoJXCBl2Pr95 cwEw== X-Gm-Message-State: AAQBX9cxzQQ4JtVVIWk58X+grIlVaG7/sRGN738aSg/eUmDi31oQe5sS JLtlXBSqPPXxF9ywVvpneNKDyjBfGNwVYvOJzxpQLw== X-Google-Smtp-Source: AKy350Zyehw4CYUta3psjpLOcOVzrvVXcYSrR9XbFYycwhYo45/B55hXK2nO/9B/Ma+n/CSNNJFYVQ== X-Received: by 2002:a17:903:40c8:b0:1a4:fc40:bf04 with SMTP id t8-20020a17090340c800b001a4fc40bf04mr4229255pld.27.1681498723659; Fri, 14 Apr 2023 11:58:43 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id g20-20020a170902869400b001a681d123a0sm3329760plo.297.2023.04.14.11.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 11:58:43 -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, Tuan Phan Subject: [PATCH v2 6/6] OvmfPkg/RiscVVirt: SEC: Add IO memory resource hob for platform devices Date: Fri, 14 Apr 2023 11:58:15 -0700 Message-Id: <20230414185815.2994-7-tphan@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230414185815.2994-1-tphan@ventanamicro.com> References: <20230414185815.2994-1-tphan@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Normally, DXE driver would add device resource to GCD before start using. But some key resources such as uart, flash base address are being accessing directly in some core modules. Those resources should be populated to HOB in SEC phase so they are added to GCD before anyone can access them. Signed-off-by: Tuan Phan --- OvmfPkg/RiscVVirt/Sec/Platform.c | 62 +++++++++++++++++++++++++++++++ OvmfPkg/RiscVVirt/Sec/SecMain.inf | 1 + 2 files changed, 63 insertions(+) diff --git a/OvmfPkg/RiscVVirt/Sec/Platform.c b/OvmfPkg/RiscVVirt/Sec/Platf= orm.c index 3645c27b0b12..944b82c84a6e 100644 --- a/OvmfPkg/RiscVVirt/Sec/Platform.c +++ b/OvmfPkg/RiscVVirt/Sec/Platform.c @@ -21,6 +21,63 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D =0D +/**=0D + Build memory map I/O range resource HOB using the=0D + base address and size.=0D +=0D + @param MemoryBase Memory map I/O base.=0D + @param MemorySize Memory map I/O size.=0D +=0D +**/=0D +STATIC=0D +VOID=0D +AddIoMemoryBaseSizeHob (=0D + EFI_PHYSICAL_ADDRESS MemoryBase,=0D + UINT64 MemorySize=0D + )=0D +{=0D + /* Align to EFI_PAGE_SIZE */=0D + MemorySize =3D ALIGN_VALUE (MemorySize, EFI_PAGE_SIZE);=0D + BuildResourceDescriptorHob (=0D + EFI_RESOURCE_MEMORY_MAPPED_IO,=0D + EFI_RESOURCE_ATTRIBUTE_PRESENT |=0D + EFI_RESOURCE_ATTRIBUTE_INITIALIZED |=0D + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |=0D + EFI_RESOURCE_ATTRIBUTE_TESTED,=0D + MemoryBase,=0D + MemorySize=0D + );=0D +}=0D +=0D +/**=0D + Populate IO resources from FDT that not added to GCD by its=0D + driver in the DXE phase. =0D +=0D + @param FdtBase Fdt base address=0D + @param Compatible Compatible string=0D +=0D +**/=0D +STATIC=0D +VOID=0D +PopulateIoResources (=0D + VOID *FdtBase,=0D + CONST CHAR8* Compatible=0D + )=0D +{=0D + UINT64 *Reg;=0D + INT32 Node, LenP;=0D +=0D + Node =3D fdt_node_offset_by_compatible (FdtBase, -1, Compatible);=0D + while (Node !=3D -FDT_ERR_NOTFOUND) {=0D + Reg =3D (UINT64 *)fdt_getprop (FdtBase, Node, "reg", &LenP);=0D + if (Reg) {=0D + ASSERT (LenP =3D=3D (2 * sizeof (UINT64)));=0D + AddIoMemoryBaseSizeHob (SwapBytes64 (Reg[0]), SwapBytes64 (Reg[1]));= =0D + }=0D + Node =3D fdt_node_offset_by_compatible (FdtBase, Node, Compatible);=0D + }=0D +}=0D +=0D /**=0D @retval EFI_SUCCESS The address of FDT is passed in HOB.=0D EFI_UNSUPPORTED Can't locate FDT.=0D @@ -80,5 +137,10 @@ PlatformPeimInitialization ( =0D BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSiz= e));=0D =0D + PopulateIoResources (Base, "ns16550a");=0D + PopulateIoResources (Base, "qemu,fw-cfg-mmio");=0D + PopulateIoResources (Base, "virtio,mmio");=0D + AddIoMemoryBaseSizeHob (PcdGet32 (PcdOvmfFdBaseAddress), PcdGet32 (PcdOv= mfFirmwareFdSize));=0D +=0D return EFI_SUCCESS;=0D }=0D diff --git a/OvmfPkg/RiscVVirt/Sec/SecMain.inf b/OvmfPkg/RiscVVirt/Sec/SecM= ain.inf index aed35d3af596..e1f562264eea 100644 --- a/OvmfPkg/RiscVVirt/Sec/SecMain.inf +++ b/OvmfPkg/RiscVVirt/Sec/SecMain.inf @@ -61,6 +61,7 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase=0D gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize=0D gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress=0D + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize=0D =0D [Guids]=0D gFdtHobGuid=0D --=20 2.25.1