From 79dcaf7054dbe90a30c7ce288b7f2ed882d96cf2 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 13 Dec 2021 09:16:55 +0100 Subject: [PATCH] OvmfPkg/Microvm/fdt: load fdt from fw_cfg 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 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3689 Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daude --- OvmfPkg/PlatformPei/Platform.c | 45 +++++++++++++++++++++++++++++ OvmfPkg/PlatformPei/PlatformPei.inf | 1 + 2 files changed, 46 insertions(+) diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 906f64615d..c9ec1d7e99 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -321,6 +321,50 @@ 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 +412,7 @@ MiscInitialization ( break; case 0xffff: /* microvm */ DEBUG ((DEBUG_INFO, "%a: microvm\n", __FUNCTION__)); + MicrovmInitialization (); PcdStatus = PcdSet16S ( PcdOvmfHostBridgePciDevId, MICROVM_PSEUDO_DEVICE_ID diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index 1c56ba2758..8ef404168c 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -44,6 +44,7 @@ [Guids] gEfiMemoryTypeInformationGuid + gFdtHobGuid [LibraryClasses] BaseLib