On Thu, Jul 02, 2026 at 02:20:32AM +0800, Tomita Moeko wrote:
> Some devices, such as VFIO IGD passthrough, require device-specific
> fixups on the romfile provided by user. Add an optional romfile_fixup
> hook to PCIDevice. When set, it is invoked from pci_add_option_rom()
> right after the image is loaded, receiving the ROM buffer and its
> size. This provides a place to post-process a loaded romfile without
> leaking device-specific logic into the generic PCI core.
> 
> Reported-by: K S Maan <[email protected]>
> Signed-off-by: Tomita Moeko <[email protected]>

fine by me:

Acked-by: Michael S. Tsirkin <[email protected]>

> ---
>  hw/pci/pci.c                | 4 ++++
>  include/hw/pci/pci_device.h | 1 +
>  2 files changed, 5 insertions(+)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 4298adf5a0..7d30d44411 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -2632,6 +2632,10 @@ static void pci_add_option_rom(PCIDevice *pdev, bool 
> is_default_rom,
>              /* Only the default rom images will be patched (if needed). */
>              pci_patch_ids(pdev, ptr, size);
>          }
> +
> +        if (pdev->romfile_fixup) {
> +            pdev->romfile_fixup(pdev, ptr, size);
> +        }
>      }
>  
>      pci_register_bar(pdev, PCI_ROM_SLOT, 0, &pdev->rom);
> diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h
> index 5cac6e1688..a65e77018c 100644
> --- a/include/hw/pci/pci_device.h
> +++ b/include/hw/pci/pci_device.h
> @@ -159,6 +159,7 @@ struct PCIDevice {
>      bool has_rom;
>      MemoryRegion rom;
>      int32_t rom_bar;
> +    void (*romfile_fixup)(PCIDevice *pdev, uint8_t *ptr, uint32_t size);
>  
>      /* INTx routing notifier */
>      PCIINTxRoutingNotifier intx_routing_notifier;
> -- 
> 2.53.0


Reply via email to