From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web09.8950.1635952018762532281 for ; Wed, 03 Nov 2021 08:06:59 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OeqkfGUB; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635952017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1120pErrXJc0wBvbjJ0Oyjh8afJ0zyi1WHmy3ZSS8VE=; b=OeqkfGUB2J4U+lD5HFOgCwpFrZ7jYezHaaQjzXEVKMfL1a6jRdvJRGUUyGnjH3Ub2Wg7x4 6UViAGv7C2x5Vk0xNm4BamrO1rep9QQkSEdPc4bSU02T/3a+IE2B1ESf2HRmCIsMhmnrpK eNXJXOg2tU+FqxxHEysTIcmmo/vSYEY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-583-1BD5JGUcOGGcx6dOzuvXZg-1; Wed, 03 Nov 2021 11:06:48 -0400 X-MC-Unique: 1BD5JGUcOGGcx6dOzuvXZg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67C9F10247A7; Wed, 3 Nov 2021 15:06:47 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.194.99]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0834219723; Wed, 3 Nov 2021 15:06:41 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8D46018221B4; Wed, 3 Nov 2021 16:06:27 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Jiewen Yao , Gerd Hoffmann , Jordan Justen , Ard Biesheuvel Subject: [PATCH v2 2/5] OvmfPkg/Microvm/fdt: load fdt from fw_cfg Date: Wed, 3 Nov 2021 16:06:24 +0100 Message-Id: <20211103150627.3133189-3-kraxel@redhat.com> In-Reply-To: <20211103150627.3133189-1-kraxel@redhat.com> References: <20211103150627.3133189-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Needed for hardware detection: virtio-mmio devices for now, later also pcie root bridge. Depends on patched qemu which actually provides an fdt: https://gitlab.com/kraxel/qemu/-/commits/sirius/microvm-device-tree https://bugzilla.tianocore.org/show_bug.cgi?id=3689 Signed-off-by: Gerd Hoffmann --- OvmfPkg/PlatformPei/PlatformPei.inf | 1 + OvmfPkg/PlatformPei/Platform.c | 40 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index 67eb7aa7166b..56876184b17a 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -44,6 +44,7 @@ [Packages] [Guids] gEfiMemoryTypeInformationGuid + gFdtHobGuid [LibraryClasses] BaseLib diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index df2d9ad015aa..3c0cdba67c83 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -321,6 +321,45 @@ PciExBarInitialization ( ); } +VOID +MicrovmInitialization ( + VOID + ) +{ + FIRMWARE_CONFIG_ITEM FdtItem; + UINTN FdtSize; + UINTN FdtPages; + EFI_STATUS Status; + UINT64 *FdtHobData; + VOID *NewBase; + + Status = QemuFwCfgFindFile ("etc/fdt", &FdtItem, &FdtSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: no etc/fdt found in fw_cfg\n", __FUNCTION__)); + return; + } + + FdtPages = EFI_SIZE_TO_PAGES (FdtSize); + NewBase = AllocatePages (FdtPages); + if (NewBase == NULL) { + DEBUG ((DEBUG_INFO, "%a: AllocatePages failed\n", __FUNCTION__)); + return; + } + + QemuFwCfgSelectItem (FdtItem); + QemuFwCfgReadBytes (FdtSize, NewBase); + + FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof (*FdtHobData)); + if (FdtHobData == NULL) { + DEBUG ((DEBUG_INFO, "%a: BuildGuidHob failed\n", __FUNCTION__)); + return; + } + + DEBUG ((DEBUG_INFO, "%a: fdt at 0x%x (size %d)\n", __FUNCTION__, + NewBase, FdtSize)); + *FdtHobData = (UINTN)NewBase; +} + VOID MiscInitialization ( VOID @@ -368,6 +407,7 @@ MiscInitialization ( break; case 0xffff: /* microvm */ DEBUG ((DEBUG_INFO, "%a: microvm\n", __FUNCTION__)); + MicrovmInitialization(); PcdStatus = PcdSet16S (PcdOvmfHostBridgePciDevId, MICROVM_PSEUDO_DEVICE_ID); ASSERT_RETURN_ERROR (PcdStatus); -- 2.31.1