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 <kraxel@redhat.com>
---
OvmfPkg/PlatformPei/PlatformPei.inf | 1 +
OvmfPkg/PlatformPei/Platform.c | 45 +++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf
index 1c56ba275835..8ef404168c45 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 906f64615de7..c9ec1d7e99fb 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
--
2.33.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#84687): https://edk2.groups.io/g/devel/message/84687
Mute This Topic: https://groups.io/mt/87693654/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On 12/13/21 09:16, Gerd Hoffmann wrote:
> 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
Link returns 404.
>
> https://bugzilla.tianocore.org/show_bug.cgi?id=3689
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> OvmfPkg/PlatformPei/PlatformPei.inf | 1 +
> OvmfPkg/PlatformPei/Platform.c | 45 +++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+)
>
> diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf
> index 1c56ba275835..8ef404168c45 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 906f64615de7..c9ec1d7e99fb 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__));
FreePages (NewBase)?
Otherwise:
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
> + 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
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#84760): https://edk2.groups.io/g/devel/message/84760
Mute This Topic: https://groups.io/mt/87693654/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On Mon, Dec 13, 2021 at 10:33:55AM +0100, Philippe Mathieu-Daudé wrote: > On 12/13/21 09:16, Gerd Hoffmann wrote: > > 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 > > Link returns 404. Oh, need to fix the commit message. It's upstream in qemu 6.2+ meanwhile. take care, Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#84694): https://edk2.groups.io/g/devel/message/84694 Mute This Topic: https://groups.io/mt/87693654/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
On Mon, 13 Dec 2021 at 09:17, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> 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 <kraxel@redhat.com>
> ---
> OvmfPkg/PlatformPei/PlatformPei.inf | 1 +
> OvmfPkg/PlatformPei/Platform.c | 45 +++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+)
>
> diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf
> index 1c56ba275835..8ef404168c45 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 906f64615de7..c9ec1d7e99fb 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 ();
Is this the best spot for calling Microvm related init code that is
entirely unrelated to PCIe?
> PcdStatus = PcdSet16S (
> PcdOvmfHostBridgePciDevId,
> MICROVM_PSEUDO_DEVICE_ID
> --
> 2.33.1
>
>
>
>
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#84693): https://edk2.groups.io/g/devel/message/84693
Mute This Topic: https://groups.io/mt/87693654/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Hi, > > @@ -368,6 +412,7 @@ MiscInitialization ( > > break; > > case 0xffff: /* microvm */ > > DEBUG ((DEBUG_INFO, "%a: microvm\n", __FUNCTION__)); > > + MicrovmInitialization (); > > Is this the best spot for calling Microvm related init code that is > entirely unrelated to PCIe? Looked like the best place to me. Various platform-specific initialization happens there. And, yes, for 'pc' and 'q35' qemu machines this includes pci host bridge setup. Do you have a better suggestion? take care, Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#84695): https://edk2.groups.io/g/devel/message/84695 Mute This Topic: https://groups.io/mt/87693654/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
On Mon, 13 Dec 2021 at 12:26, Gerd Hoffmann <kraxel@redhat.com> wrote: > > Hi, > > > > @@ -368,6 +412,7 @@ MiscInitialization ( > > > break; > > > case 0xffff: /* microvm */ > > > DEBUG ((DEBUG_INFO, "%a: microvm\n", __FUNCTION__)); > > > + MicrovmInitialization (); > > > > Is this the best spot for calling Microvm related init code that is > > entirely unrelated to PCIe? > > Looked like the best place to me. Various platform-specific > initialization happens there. And, yes, for 'pc' and 'q35' > qemu machines this includes pci host bridge setup. > Fair enough. Given the comment that future changes will include DT based PCIe host bridge probing, I think this is fine. -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#84696): https://edk2.groups.io/g/devel/message/84696 Mute This Topic: https://groups.io/mt/87693654/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.