From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by mx.groups.io with SMTP id smtpd.web10.1083.1678124014134125831 for ; Mon, 06 Mar 2023 09:33:34 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=VSBMV6GS; spf=pass (domain: ventanamicro.com, ip: 209.85.216.44, mailfrom: tphan@ventanamicro.com) Received: by mail-pj1-f44.google.com with SMTP id qa18-20020a17090b4fd200b0023750b675f5so13876688pjb.3 for ; Mon, 06 Mar 2023 09:33:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1678124013; 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=306E3rM8/S/OnVPZX/8gaQK8ERTRjb3t+N+l8EzhKyw=; b=VSBMV6GSn9tlOfR5dc63bVNNlDF2pJAs0nTrHv9Ur6VGZWcjzdy5zSQdRg13mmayKo 256oWlhkbchzI1uEO0ucRgDQHYSYAf13KAnB2qZRHBjIsaB3o8+gbEuKBxCVvGzT4kxS FvI67SSQsF16Lg9GX4LMpdOx6STntJFa618N0IrYak47qV93MgqQo6Cj4hrdMU6NYE4g Rl2ZUDYiz5lPlM+hYLW0NtiN6RZbI1BX/Hq5n8N+mvmGNG7tYMInza8Ds2HaoOTqfs7B JV1fOO7rSMe7BJwJoPo9jTyGzK8VPFozArKLzmbx9BQXi8/6oiXs1LqN58/sTD311ixh azmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678124013; 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=306E3rM8/S/OnVPZX/8gaQK8ERTRjb3t+N+l8EzhKyw=; b=V/gC8g86k5oG9BYRBsz4bssIUkyaZyfbRLj0S9F8HdUqcWYzF4ijv4ILDmiuw7K5Tk /AzRRDi0zpT33x5fYX7xJ/3545hqjY9XfCTNDILsZ5bU0Yf8eUGoia42ixJU5lJByrt7 aK2LlbemNmnHZrXBEQrpwA5g/ttsyyMl4zB48lL8J1ySHWxynvLQ6xM3S8J2ugtSMIe/ wZf+J0wDAh14lL4xUB+JqO1w5b26hyCoZeePG6+lhzq5UOtjMUMJgSD8tK8scq5r7To2 PP++bPiMHccgD3nGJqVTCXLpCP9pdDkZHlsroDDyCqshti38fVD7Cvg3uOf6ss2gWtV/ xM4w== X-Gm-Message-State: AO0yUKXP9n9RxsiiK5irqHB4DyuLO7+1x9irUCQLBdqtCOqvFxc7Q2c7 25E9vKEJBd7kUTKjqpjNXaK8lveSJKbAfVD3Tat37g== X-Google-Smtp-Source: AK7set9sFaLeG2LBiXuAN4XntdrDiVSxhkAmCoI8a2Y0XTh1aljQpoR4k1BW7SdR0HumB+GlvjtxLw== X-Received: by 2002:a05:6a20:ba94:b0:cd:f8c5:a9b4 with SMTP id fb20-20020a056a20ba9400b000cdf8c5a9b4mr10674725pzb.24.1678124013170; Mon, 06 Mar 2023 09:33:33 -0800 (PST) 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 v6-20020aa78506000000b005dd975176c3sm6579722pfn.53.2023.03.06.09.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 09:33:32 -0800 (PST) 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 6/7] OvmfPkg/RiscVVirt: SEC: Add IO memory resource hob for platform devices Date: Mon, 6 Mar 2023 09:33:15 -0800 Message-Id: <20230306173316.10319-7-tphan@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230306173316.10319-1-tphan@ventanamicro.com> References: <20230306173316.10319-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 e8fd126cf800..63bc21eb3f60 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