Re: [PATCH 2/6] hw/pci: Introduce rom_need_patch_id flag in PCIDevice

2026-06-05 Thread Alex Williamson
On Thu,  4 Jun 2026 01:33:50 +0800
Tomita Moeko  wrote:

> diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h
> index 5cac6e1688..daa679b3f5 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;
> +bool rom_need_patch_id;
>  
>  /* INTx routing notifier */
>  PCIINTxRoutingNotifier intx_routing_notifier;

Micro nit, maybe groups better with has_rom.  It's filling an existing
hole either way, but might help some future cleanup.  Thanks,

Alex



[PATCH 2/6] hw/pci: Introduce rom_need_patch_id flag in PCIDevice

2026-06-03 Thread Tomita Moeko
Allow external code (e.g., VFIO IGD passthrough) to request PCI ID
patching for a custom romfile, replacing the existing is_default_rom
flag for this purpose.

Reported-by: K S Maan 
Signed-off-by: Tomita Moeko 
Tested-by: K S Maan 
---
 hw/pci/pci.c| 14 ++
 include/hw/pci/pci_device.h |  1 +
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 043fef1954..17ce7d8394 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -345,7 +345,7 @@ static const TypeInfo cxl_bus_info = {
 
 static void pci_update_mappings(PCIDevice *d);
 static void pci_irq_handler(void *opaque, int irq_num, int level);
-static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, Error **);
+static void pci_add_option_rom(PCIDevice *pdev, Error **);
 static void pci_del_option_rom(PCIDevice *pdev);
 
 static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET;
@@ -2250,7 +2250,6 @@ static void pci_qdev_realize(DeviceState *qdev, Error 
**errp)
 PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
 ObjectClass *klass = OBJECT_CLASS(pc);
 Error *local_err = NULL;
-bool is_default_rom;
 uint16_t class_id;
 
 /*
@@ -2363,13 +2362,13 @@ static void pci_qdev_realize(DeviceState *qdev, Error 
**errp)
 }
 
 /* rom loading */
-is_default_rom = false;
 if (pci_dev->romfile == NULL && pc->romfile != NULL) {
+/* using a built-in default rom */
 pci_dev->romfile = g_strdup(pc->romfile);
-is_default_rom = true;
+pci_dev->rom_need_patch_id = true;
 }
 
-pci_add_option_rom(pci_dev, is_default_rom, &local_err);
+pci_add_option_rom(pci_dev, &local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 pci_qdev_unrealize(DEVICE(pci_dev));
@@ -2549,8 +2548,7 @@ static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, 
uint32_t size)
 }
 
 /* Add an option rom for the device */
-static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
-   Error **errp)
+static void pci_add_option_rom(PCIDevice *pdev, Error **errp)
 {
 int64_t size = 0;
 g_autofree char *path = NULL;
@@ -2648,7 +2646,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool 
is_default_rom,
 return;
 }
 
-if (is_default_rom) {
+if (pdev->rom_need_patch_id) {
 /* Only the default rom images will be patched (if needed). */
 pci_patch_ids(pdev, ptr, size);
 }
diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h
index 5cac6e1688..daa679b3f5 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;
+bool rom_need_patch_id;
 
 /* INTx routing notifier */
 PCIINTxRoutingNotifier intx_routing_notifier;
-- 
2.53.0