From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mx.groups.io with SMTP id smtpd.web10.6044.1687545673621861464 for ; Fri, 23 Jun 2023 11:41:13 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=RetwCAa3; spf=pass (domain: ventanamicro.com, ip: 209.85.210.180, mailfrom: tphan@ventanamicro.com) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6686708c986so776077b3a.0 for ; Fri, 23 Jun 2023 11:41:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1687545673; x=1690137673; 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=XsEodZYT1PBhwBnSXPgqqP7rVj+VyTJd5eAUus6j93c=; b=RetwCAa3JtJa9qg9kbEIXYdLfuBjdPE6VI0UrEGd2DXBNkcf+/4Qryy8eoZR21ntUL IB8OYU3hTAk4GS98kfTweZPp1b+OVPH8UQ8hOtcejv3Lh2LuF5TNOFelcI0EN4GAF9gu 58C/yoSIYk+H51w8Rp3Q5iNcx2ZVEeR+soYQeKz63gBJVyQuGpYZx945Px8Yd2EuOGRY lr/A6wvoOkIzikY0PfVze5qTN3h2sf6LIXUIGudSxkXWWomRfyKVFqQcSR+PKmZ8SzWb ImXlyZvXUSJTqrbEv50qnTqLWCNdw7KGKNKzosrB9CO5Gb/X9juYC6m1wLUOOGHsQaLb Oxsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687545673; x=1690137673; 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=XsEodZYT1PBhwBnSXPgqqP7rVj+VyTJd5eAUus6j93c=; b=JPKiumkfVYBKlyREFCLrKOo6owWpJoy2fE6kK2/540aWbB+y1qxzg7mMnadH6nILNF +y1csSxH2Yd/xrUYfp3T7pvpN2GJr46u86AjzfP7kCrGuHQEdMAhgrdbkZG15nFVrkWO kLh4e+M59zDW1Nb0rIThVhu3Qz0CUT1kUQ9UsvzZ1WMyvjXtUzGfTiVCHZ+HhvHGW9rF /0ze9NeyNYJRuvLfjTlAl/GxHUnCgj7Ux8g/5iQPn5oZJkPftCttjKoZfg1XnQgQvDzo Iso4VDdlfN4JcuNezxAXUbzP5I5KEMgi1vL9HIhkxqAlMKlzEfq87w68zV0IQHDTz7zH XFoQ== X-Gm-Message-State: AC+VfDwjvEJmyDTnkGkw+28F3vzdZN8WJxPGxkPJhKmzhVy2HQibpFhU oVUdSUmBtM/4G/u2GzC632+LVBN1qQa8yAWSSMkWIw== X-Google-Smtp-Source: ACHHUZ5fIYYZ6Ptr3KzIB9AHstERKJfCNRZp5ezreaFsRgPmviklhprLPctSej/Gbjkozs/o7sgGCQ== X-Received: by 2002:a05:6a20:6a2b:b0:10f:1d33:d667 with SMTP id p43-20020a056a206a2b00b0010f1d33d667mr27658440pzk.5.1687545672688; Fri, 23 Jun 2023 11:41:12 -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 v2-20020aa78502000000b006667b36e904sm6354184pfn.113.2023.06.23.11.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 11:41:12 -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: [PATCH v4 4/7] OvmfPkg/RiscVVirt: SEC: Add IO memory resource hob for platform devices Date: Fri, 23 Jun 2023 11:39:31 -0700 Message-Id: <20230623183934.23905-5-tphan@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230623183934.23905-1-tphan@ventanamicro.com> References: <20230623183934.23905-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 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 =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 +=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 +138,9 @@ 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 +=0D return EFI_SUCCESS;=0D }=0D --=20 2.25.1