vfio/pci: Split pci.c
cover vfio/pci: Split pci.c
Hello,
hw/vfio/pci.c has grown into a large monolithic file. This series extract interrupt handling, PCI capability setup and ROM management into dedicated files and normalizes function names for consistency. Other aspects, config space, BAR setup, VGA, could be addressed later.
A g_memdup deprecation fix is included as a standalone cleanup.
No functional changes.
Thanks,
C.
Cédric Le Goater (9):
vfio/pci: Extract interrupt handling into pci-irq.c vfio/pci: Move vfio_mmap_set_enabled() to region.c vfio/pci: Rename IRQ functions
vfio/pci: Replace deprecated g_memdup() with g_memdup2() vfio/pci: Extract PCI capability setup into pci-caps.c vfio/pci: Rename capability functions
vfio/pci: Rename vfio_sub_page_bar_update_mappings() function vfio/pci: Extract ROM handling into pci-rom.c vfio/pci: Rename vfio_opt_rom_in_denylist() to
vfio_quirk_rom_in_denylist()
hw/vfio/pci.h | 46 +- hw/vfio/vfio-region.h | 4 +- hw/vfio-user/pci.c | 4 +- hw/vfio/cpr.c | 4 +- hw/vfio/pci-caps.c | 730 ++++++++++ hw/vfio/pci-irq.c | 1630 +++++++++++++++++++++ hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci-rom.c | 239 ++++ hw/vfio/pci.c | 3128 ++++------------------------------------- hw/vfio/region.c | 12 +- hw/vfio/meson.build | 3 + 11 files changed, 2949 insertions(+), 2853 deletions(-) create mode 100644 hw/vfio/pci-caps.c create mode 100644 hw/vfio/pci-irq.c create mode 100644 hw/vfio/pci-rom.c
Signature · 1 line
2.56.0
PATCH 1/9 vfio/pci: Extract interrupt handling into pci-irq.c
Move all interrupt handling code into a dedicated pci-irq.c file. Export vfio_pci_config_space_read/write() since pci-irq.c needs them.
No functional change. Retain existing license 'GPL-2.0-only'.
--- hw/vfio/pci.h | 18 + hw/vfio/pci-irq.c | 1644 +++++++++++++++++++++++++++++++++++++++ hw/vfio/pci.c | 1806 +++---------------------------------------- hw/vfio/meson.build | 1 + 4 files changed, 1757 insertions(+), 1712 deletions(-) create mode 100644 hw/vfio/pci-irq.c
hw/vfio/pci.h +18 -0
@@ -221,11 +221,27 @@ bool vfio_pci_intx_enable(VFIOPCIDevice *vdev, Error **errp);void vfio_pci_intx_set_handler (VFIOPCIDevice *vdev,bool enable);void vfio_pci_msix_set_notifiers (VFIOPCIDevice *vdev);void vfio_pci_msi_set_handler (VFIOPCIDevice *vdev,int nr,bool enable); +void vfio_disable_interrupts (VFIOPCIDevice *vdev); +bool vfio_intx_enable (VFIOPCIDevice *vdev,Error **errp); +void vfio_intx_disable (VFIOPCIDevice *vdev); +void vfio_msi_enable (VFIOPCIDevice *vdev); +void vfio_msi_disable (VFIOPCIDevice *vdev); +void vfio_msix_enable (VFIOPCIDevice *vdev); +void vfio_msix_disable (VFIOPCIDevice *vdev); +void vfio_update_msi (VFIOPCIDevice *vdev); +bool vfio_msix_early_setup (VFIOPCIDevice *vdev,Error **errp); +bool vfio_msi_setup (VFIOPCIDevice *vdev,int pos,Error **errp); +bool vfio_msix_setup (VFIOPCIDevice *vdev,int pos,Error **errp); +void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled);bool vfio_pci_interrupt_setup (VFIOPCIDevice *vdev,Error **errp);void vfio_pci_intx_eoi (VFIODevice *vbasedev);void vfio_pci_teardown_msi (VFIOPCIDevice *vdev);/* Config space */ +int vfio_pci_config_space_read (VFIOPCIDevice *vdev,off_t offset, +uint32_t size,void *data); +int vfio_pci_config_space_write (VFIOPCIDevice *vdev,off_t offset, +uint32_t size,void *data);uint32_t vfio_pci_read_config (PCIDevice *pdev,uint32_t addr,int len);void vfio_pci_write_config (PCIDevice *pdev,uint32_t addr,uint32_t val,int len);
@@ -286,7 +302,9 @@ extern const VMStateDescription vfio_display_vmstate;/* Notifiers */ void vfio_pci_register_err_notifier (VFIOPCIDevice *vdev); +void vfio_unregister_err_notifier (VFIOPCIDevice *vdev);void vfio_pci_register_req_notifier (VFIOPCIDevice *vdev); +void vfio_unregister_req_notifier (VFIOPCIDevice *vdev);/** * vfio_pci_from_vfio_device: Transform from VFIODevice to
hw/vfio/pci-irq.c new file +1644 -0
1,644 lines not on this page · raw message
hw/vfio/pci.c +94 -1712
1,320 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.56.0
Part of the diff is not shown here. View the raw message.
PATCH 2/9 vfio/pci: Move vfio_mmap_set_enabled() to region.c
In reply to Cédric Le Goatervfio_mmap_set_enabled() iterates over BAR regions calling vfio_region_mmaps_set_enabled(). Move it from pci-irq.c to region.c and rename it to vfio_region_set_enabled().
No functional change.
--- hw/vfio/pci.h | 1 - hw/vfio/vfio-region.h | 4 +++- hw/vfio/pci-irq.c | 15 +++------------ hw/vfio/region.c | 12 +++++++++++- 4 files changed, 17 insertions(+), 15 deletions(-)
hw/vfio/pci.h +0 -1
@@ -232,7 +232,6 @@ void vfio_update_msi(VFIOPCIDevice *vdev);bool vfio_msix_early_setup (VFIOPCIDevice *vdev,Error **errp);bool vfio_msi_setup (VFIOPCIDevice *vdev,int pos,Error **errp);bool vfio_msix_setup (VFIOPCIDevice *vdev,int pos,Error **errp); -void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled);bool vfio_pci_interrupt_setup (VFIOPCIDevice *vdev,Error **errp);void vfio_pci_intx_eoi (VFIODevice *vbasedev);void vfio_pci_teardown_msi (VFIOPCIDevice *vdev);
hw/vfio/vfio-region.h +3 -1
@@ -42,7 +42,6 @@ uint64_t vfio_region_read(void *opaque,int vfio_region_setup (Object *obj,VFIODevice *vbasedev,VFIORegion *region,int index,const char *name,Error **errp);int vfio_region_mmap (VFIORegion *region); -void vfio_region_mmaps_set_enabled (VFIORegion *region,bool enabled);void vfio_region_exit (VFIORegion *region);void vfio_region_finalize (VFIORegion *region);
@@ -51,4 +50,7 @@ int vfio_region_setup_sparse_mmaps(VFIORegion *region,struct vfio_region_info *info, Error **errp); +struct VFIOPCIDevice ; +void vfio_region_set_enabled (struct VFIOPCIDevice *vdev,bool enabled); +#endif /* HW_VFIO_REGION_H */
hw/vfio/pci-irq.c +3 -12
@@ -93,7 +93,7 @@ static void vfio_intx_mmap_enable(void *opaque)return ; } -vfio_mmap_set_enabled (vdev, true); +vfio_region_set_enabled (vdev, true); }static void vfio_intx_interrupt (void *opaque)
@@ -109,7 +109,7 @@ static void vfio_intx_interrupt(void *opaque) vdev->intx.pending = true;pci_irq_assert (pdev); -vfio_mmap_set_enabled (vdev, false); +vfio_region_set_enabled (vdev, false);if (vdev->intx.mmap_timeout) {timer_mod (vdev->intx.mmap_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) + vdev->intx.mmap_timeout);
@@ -389,7 +389,7 @@ void vfio_intx_disable(VFIOPCIDevice *vdev)vfio_device_irq_disable (&vdev->vbasedev,VFIO_PCI_INTX_IRQ_INDEX ); vdev->intx.pending = false;pci_irq_deassert (pdev); -vfio_mmap_set_enabled (vdev, true); +vfio_region_set_enabled (vdev, true); fd =event_notifier_get_fd (&vdev->intx.interrupt);qemu_set_fd_handler (fd,NULL ,NULL , vdev);
@@ -1439,15 +1439,6 @@ void vfio_pci_teardown_msi(VFIOPCIDevice *vdev) } } -void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled) -{ -int i; - -for (i =0 ; i <PCI_ROM_SLOT ; i++) { -vfio_region_mmaps_set_enabled (&vdev->bars[i].region, enabled); - } -} -/* * Err/Req notifiers */
hw/vfio/region.c +11 -1
@@ -30,6 +30,7 @@#include "qemu/units.h" #include "monitor/monitor.h" #include "system/ramblock.h" +#include "pci.h" #include "vfio-helpers.h" /*
@@ -539,7 +540,7 @@ void vfio_region_finalize(VFIORegion *region) region->nr =0 ; } -void vfio_region_mmaps_set_enabled (VFIORegion *region,bool enabled) +static void vfio_region_mmaps_set_enabled (VFIORegion *region,bool enabled) {int i;
@@ -556,3 +557,12 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled)trace_vfio_region_mmaps_set_enabled (memory_region_name (region->mem), enabled); } + +void vfio_region_set_enabled (VFIOPCIDevice *vdev,bool enabled) +{ +int i; + +for (i =0 ; i <PCI_ROM_SLOT ; i++) { +vfio_region_mmaps_set_enabled (&vdev->bars[i].region, enabled); + } +}
Signature · 1 line
2.56.0
PATCH 3/9 vfio/pci: Rename IRQ functions
In reply to Cédric Le GoaterNormalize IRQ function names to a consistent vfio_pci_*_verb pattern:
vfio_pci_interrupt_setup -> vfio_pci_irq_setup vfio_disable_interrupts -> vfio_pci_irq_disable vfio_intx_enable -> vfio_pci_intx_enable vfio_intx_disable -> vfio_pci_intx_disable vfio_pci_vector_init -> vfio_pci_msi_vector_use vfio_msi_setup -> vfio_pci_msi_setup vfio_msi_enable -> vfio_pci_msi_enable vfio_msi_disable -> vfio_pci_msi_disable vfio_update_msi -> vfio_pci_msi_update vfio_pci_teardown_msi -> vfio_pci_msi_teardown vfio_msix_early_setup -> vfio_pci_msix_early_setup vfio_msix_setup -> vfio_pci_msix_setup vfio_msix_enable -> vfio_pci_msix_enable vfio_msix_disable -> vfio_pci_msix_disable
vfio_unregister_err_notifier -> vfio_pci_unregister_err_notifier vfio_unregister_req_notifier -> vfio_pci_unregister_req_notifier
Drop the vfio_pci_intx_enable() wrapper that called vfio_intx_enable() and reorder the declarations in pci.h.
No functional change.
--- hw/vfio/pci.h | 45 ++++++++++++++++++---------------- hw/vfio-user/pci.c | 4 +-- hw/vfio/cpr.c | 2 +- hw/vfio/pci-irq.c | 61 +++++++++++++++++++++------------------------- hw/vfio/pci.c | 38 ++++++++++++++--------------- 5 files changed, 74 insertions(+), 76 deletions(-)
hw/vfio/pci.h +24 -21
@@ -212,29 +212,32 @@ static inline bool vfio_is_base_display(VFIOPCIDevice *vdev) }/* MSI/MSI-X/INTx */ -void vfio_pci_vector_init (VFIOPCIDevice *vdev,int nr); +bool vfio_pci_irq_setup (VFIOPCIDevice *vdev,Error **errp); +void vfio_pci_irq_disable (VFIOPCIDevice *vdev); + +bool vfio_pci_intx_enable (VFIOPCIDevice *vdev,Error **errp); +void vfio_pci_intx_disable (VFIOPCIDevice *vdev); +void vfio_pci_intx_eoi (VFIODevice *vbasedev); +void vfio_pci_intx_set_handler (VFIOPCIDevice *vdev,bool enable); + +bool vfio_pci_msi_setup (VFIOPCIDevice *vdev,int pos,Error **errp); +void vfio_pci_msi_vector_use (VFIOPCIDevice *vdev,int nr); +void vfio_pci_msi_enable (VFIOPCIDevice *vdev); +void vfio_pci_msi_disable (VFIOPCIDevice *vdev); +void vfio_pci_msi_update (VFIOPCIDevice *vdev); +void vfio_pci_msi_set_handler (VFIOPCIDevice *vdev,int nr,bool enable); +void vfio_pci_msi_teardown (VFIOPCIDevice *vdev); + +bool vfio_pci_msix_early_setup (VFIOPCIDevice *vdev,Error **errp); +bool vfio_pci_msix_setup (VFIOPCIDevice *vdev,int pos,Error **errp); +void vfio_pci_msix_enable (VFIOPCIDevice *vdev); +void vfio_pci_msix_disable (VFIOPCIDevice *vdev); +void vfio_pci_msix_set_notifiers (VFIOPCIDevice *vdev); +void vfio_pci_add_kvm_msi_virq (VFIOPCIDevice *vdev,VFIOMSIVector *vector,int vector_n,bool msix);void vfio_pci_prepare_kvm_msi_virq_batch (VFIOPCIDevice *vdev);void vfio_pci_commit_kvm_msi_virq_batch (VFIOPCIDevice *vdev); -bool vfio_pci_intx_enable (VFIOPCIDevice *vdev,Error **errp); -void vfio_pci_intx_set_handler (VFIOPCIDevice *vdev,bool enable); -void vfio_pci_msix_set_notifiers (VFIOPCIDevice *vdev); -void vfio_pci_msi_set_handler (VFIOPCIDevice *vdev,int nr,bool enable); -void vfio_disable_interrupts (VFIOPCIDevice *vdev); -bool vfio_intx_enable (VFIOPCIDevice *vdev,Error **errp); -void vfio_intx_disable (VFIOPCIDevice *vdev); -void vfio_msi_enable (VFIOPCIDevice *vdev); -void vfio_msi_disable (VFIOPCIDevice *vdev); -void vfio_msix_enable (VFIOPCIDevice *vdev); -void vfio_msix_disable (VFIOPCIDevice *vdev); -void vfio_update_msi (VFIOPCIDevice *vdev); -bool vfio_msix_early_setup (VFIOPCIDevice *vdev,Error **errp); -bool vfio_msi_setup (VFIOPCIDevice *vdev,int pos,Error **errp); -bool vfio_msix_setup (VFIOPCIDevice *vdev,int pos,Error **errp); -bool vfio_pci_interrupt_setup (VFIOPCIDevice *vdev,Error **errp); -void vfio_pci_intx_eoi (VFIODevice *vbasedev); -void vfio_pci_teardown_msi (VFIOPCIDevice *vdev);/* Config space */ int vfio_pci_config_space_read(VFIOPCIDevice *vdev, off_t offset,
@@ -301,9 +304,9 @@ extern const VMStateDescription vfio_display_vmstate;/* Notifiers */ void vfio_pci_register_err_notifier (VFIOPCIDevice *vdev); -void vfio_unregister_err_notifier (VFIOPCIDevice *vdev); +void vfio_pci_unregister_err_notifier (VFIOPCIDevice *vdev);void vfio_pci_register_req_notifier (VFIOPCIDevice *vdev); -void vfio_unregister_req_notifier (VFIOPCIDevice *vdev); +void vfio_pci_unregister_req_notifier (VFIOPCIDevice *vdev);/** * vfio_pci_from_vfio_device: Transform from VFIODevice to
hw/vfio-user/pci.c +2 -2
@@ -345,7 +345,7 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Error **errp)vfio_user_msix_setup (vdev); } -if (!vfio_pci_interrupt_setup (vdev, errp)) { +if (!vfio_pci_irq_setup (vdev, errp)) { goto out_teardown; }
@@ -355,7 +355,7 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Error **errp)return ; out_teardown: -vfio_pci_teardown_msi (vdev); +vfio_pci_msi_teardown (vdev);vfio_pci_bars_exit (vdev); error:error_prepend (errp,VFIO_MSG_PREFIX , vdev->vbasedev.name);
hw/vfio/cpr.c +1 -1
@@ -69,7 +69,7 @@ static void vfio_cpr_claim_vectors(VFIOPCIDevice *vdev, int nr_vectors, fd =vfio_cpr_load_vector_fd (vdev,"interrupt" , i);if (fd >=0 ) { -vfio_pci_vector_init (vdev, i); +vfio_pci_msi_vector_use (vdev, i);vfio_pci_msi_set_handler (vdev, i, true); }
hw/vfio/pci-irq.c +28 -33
214 lines not on this page · raw message
hw/vfio/pci.c +19 -19
@@ -482,13 +482,13 @@ void vfio_pci_write_config(PCIDevice *pdev,if (!was_enabled) {if (is_enabled) { -vfio_msi_enable (vdev); +vfio_pci_msi_enable (vdev); } }else {if (!is_enabled) { -vfio_msi_disable (vdev); +vfio_pci_msi_disable (vdev); }else { -vfio_update_msi (vdev); +vfio_pci_msi_update (vdev); } } } else if (pdev->cap_present & QEMU_PCI_CAP_MSIX &&
@@ -500,9 +500,9 @@ void vfio_pci_write_config(PCIDevice *pdev, is_enabled =msix_enabled (pdev);if (!was_enabled && is_enabled) { -vfio_msix_enable (vdev); +vfio_pci_msix_enable (vdev); }else if (was_enabled && !is_enabled) { -vfio_msix_disable (vdev); +vfio_pci_msix_disable (vdev); } }else if (ranges_overlap (addr, len,PCI_BASE_ADDRESS_0 ,24 ) ||range_covers_byte (addr, len,PCI_COMMAND )) {
@@ -1021,14 +1021,14 @@ static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp)switch (cap_id) {case PCI_CAP_ID_MSI : - ret =vfio_msi_setup (vdev, pos, errp); + ret =vfio_pci_msi_setup (vdev, pos, errp);break ;case PCI_CAP_ID_EXP :vfio_check_pcie_flr (vdev, pos); ret =vfio_setup_pcie_cap (vdev, pos, size, errp);break ;case PCI_CAP_ID_MSIX : - ret =vfio_msix_setup (vdev, pos, errp); + ret =vfio_pci_msix_setup (vdev, pos, errp);break ;case PCI_CAP_ID_PM :vfio_check_pm_reset (vdev, pos);
@@ -1361,7 +1361,7 @@ void vfio_pci_pre_reset(VFIOPCIDevice *vdev)uint32_t val;uint16_t cmd; -vfio_disable_interrupts (vdev); +vfio_pci_irq_disable (vdev);/* * Stop any ongoing DMA by disconnecting I/O, MMIO, and bus master.
@@ -1410,7 +1410,7 @@ void vfio_pci_post_reset(VFIOPCIDevice *vdev)Error *err =NULL ;int ret, nr; -if (!vfio_intx_enable (vdev, &err)) { +if (!vfio_pci_intx_enable (vdev, &err)) {error_reportf_err (err,VFIO_MSG_PREFIX , vdev->vbasedev.name); }
@@ -1618,9 +1618,9 @@ static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) }if (msi_enabled (pdev)) { -vfio_msi_enable (vdev); +vfio_pci_msi_enable (vdev); }else if (msix_enabled (pdev)) { -vfio_msix_enable (vdev); +vfio_pci_msix_enable (vdev); }return ret;
@@ -1944,7 +1944,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)vfio_bars_prepare (vdev); -if (!vfio_msix_early_setup (vdev, errp)) { +if (!vfio_pci_msix_early_setup (vdev, errp)) {return false; }
@@ -2043,7 +2043,7 @@ static void vfio_pci_realize(PCIDevice *pdev, Error **errp)vfio_bar_quirk_setup (vdev, i); } -if (!vfio_pci_interrupt_setup (vdev, errp)) { +if (!vfio_pci_irq_setup (vdev, errp)) { goto out_unset_idev; }
@@ -2097,7 +2097,7 @@ static void vfio_pci_realize(PCIDevice *pdev, Error **errp) out_deregister:vfio_display_exit (vdev);if (vdev->interrupt == VFIO_INT_INTx) { -vfio_intx_disable (vdev); +vfio_pci_intx_disable (vdev); }pci_device_set_intx_routing_notifier (pdev,NULL );if (vdev->irqchip_change_notifier.notify) {
@@ -2111,7 +2111,7 @@ out_unset_idev:pci_device_unset_iommu_device (pdev); } out_teardown: -vfio_pci_teardown_msi (vdev); +vfio_pci_msi_teardown (vdev);vfio_pci_bars_exit (vdev); error:error_prepend (errp,VFIO_MSG_PREFIX , vbasedev->name);
@@ -2130,17 +2130,17 @@ static void vfio_exitfn(PCIDevice *pdev)VFIODevice *vbasedev = &vdev->vbasedev;vfio_display_exit (vdev); -vfio_unregister_req_notifier (vdev); -vfio_unregister_err_notifier (vdev); +vfio_pci_unregister_req_notifier (vdev); +vfio_pci_unregister_err_notifier (vdev);pci_device_set_intx_routing_notifier (pdev,NULL );if (vdev->irqchip_change_notifier.notify) {kvm_irqchip_remove_change_notifier (&vdev->irqchip_change_notifier); } -vfio_disable_interrupts (vdev); +vfio_pci_irq_disable (vdev);if (vdev->intx.mmap_timer) {timer_free (vdev->intx.mmap_timer); } -vfio_pci_teardown_msi (vdev); +vfio_pci_msi_teardown (vdev);vfio_pci_disable_rp_atomics (vdev);vfio_pci_bars_exit (vdev);vfio_migration_exit (vbasedev);
Signature · 1 line
2.56.0
PATCH 4/9 vfio/pci: Replace deprecated g_memdup() with g_memdup2()
In reply to Cédric Le Goaterg_memdup() is deprecated since GLib 2.68. Use g_memdup2() instead.
--- hw/vfio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/pci.c +1 -1
@@ -1225,7 +1225,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed)* physical device, we cache the config space to avoid overwriting * the original config space when we parse the extended capabilities. */ - config =g_memdup (pdev->config, vdev->config_size); + config =g_memdup2 (pdev->config, vdev->config_size);/* * Extended capabilities are chained with each pointing to the next, so we
Signature · 1 line
2.56.0
PATCH 5/9 vfio/pci: Extract PCI capability setup into pci-caps.c
In reply to Cédric Le GoaterMove PCI capability enumeration and setup into a dedicated pci-caps.c file.
No functional change. Retain existing license 'GPL-2.0-only'.
--- hw/vfio/pci.h | 5 + hw/vfio/pci-caps.c | 730 ++++++++++++++++++++++++++++++++++++++++++++ hw/vfio/pci.c | 708 ------------------------------------------ hw/vfio/meson.build | 1 + 4 files changed, 736 insertions(+), 708 deletions(-) create mode 100644 hw/vfio/pci-caps.c
hw/vfio/pci.h +5 -0
@@ -263,6 +263,11 @@ void vfio_pci_bars_exit(VFIOPCIDevice *vdev);void vfio_sub_page_bar_update_mappings (VFIOPCIDevice *vdev);/* Capabilities */ +void vfio_add_emulated_word (VFIOPCIDevice *vdev,int pos, +uint16_t val,uint16_t mask); +void vfio_add_emulated_long (VFIOPCIDevice *vdev,int pos, +uint32_t val,uint32_t mask); +void vfio_pci_disable_rp_atomics (VFIOPCIDevice *vdev);bool vfio_pci_add_capabilities (VFIOPCIDevice *vdev,Error **errp);/* Quirks */
hw/vfio/pci-caps.c new file +730 -0
730 lines not on this page · raw message
hw/vfio/pci.c +0 -708
714 lines not on this page · raw message
hw/vfio/meson.build +1 -0
@@ -12,6 +12,7 @@ stub_ss.add(files('kvm-stubs.c')) vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c')) vfio_ss.add(when: ['CONFIG_KVM', 'CONFIG_PSERIES'], if_true: files('kvm-spapr.c')) vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( + 'pci-caps.c', 'pci-irq.c', 'pci-quirks.c', 'pci.c',
Signature · 1 line
2.56.0
PATCH 6/9 vfio/pci: Rename capability functions
In reply to Cédric Le Goater vfio_add_emulated_word -> vfio_pci_cap_add_emulated_word
vfio_add_emulated_long -> vfio_pci_cap_add_emulated_long
vfio_pci_disable_rp_atomics -> vfio_pci_cap_disable_rp_atomics
No functional change.
--- hw/vfio/pci.h | 10 +++++----- hw/vfio/pci-caps.c | 32 ++++++++++++++++---------------- hw/vfio/pci.c | 12 ++++++------ 3 files changed, 27 insertions(+), 27 deletions(-)
hw/vfio/pci.h +5 -5
@@ -263,11 +263,11 @@ void vfio_pci_bars_exit(VFIOPCIDevice *vdev);void vfio_sub_page_bar_update_mappings (VFIOPCIDevice *vdev);/* Capabilities */ -void vfio_add_emulated_word (VFIOPCIDevice *vdev,int pos, -uint16_t val,uint16_t mask); -void vfio_add_emulated_long (VFIOPCIDevice *vdev,int pos, -uint32_t val,uint32_t mask); -void vfio_pci_disable_rp_atomics (VFIOPCIDevice *vdev); +void vfio_pci_cap_add_emulated_word (VFIOPCIDevice *vdev,int pos, +uint16_t val,uint16_t mask); +void vfio_pci_cap_add_emulated_long (VFIOPCIDevice *vdev,int pos, +uint32_t val,uint32_t mask); +void vfio_pci_cap_disable_rp_atomics (VFIOPCIDevice *vdev);bool vfio_pci_add_capabilities (VFIOPCIDevice *vdev,Error **errp);/* Quirks */
hw/vfio/pci-caps.c +16 -16
@@ -59,7 +59,7 @@ static void vfio_set_word_bits(uint8_t *buf, uint16_t val, uint16_t mask)pci_set_word (buf, (pci_get_word (buf) & ~mask) | val); } -void vfio_add_emulated_word (VFIOPCIDevice *vdev,int pos, +void vfio_pci_cap_add_emulated_word (VFIOPCIDevice *vdev,int pos,uint16_t val,uint16_t mask) {PCIDevice *pdev =PCI_DEVICE (vdev);
@@ -74,7 +74,7 @@ static void vfio_set_long_bits(uint8_t *buf, uint32_t val, uint32_t mask)pci_set_long (buf, (pci_get_long (buf) & ~mask) | val); } -void vfio_add_emulated_long (VFIOPCIDevice *vdev,int pos, +void vfio_pci_cap_add_emulated_long (VFIOPCIDevice *vdev,int pos,uint32_t val,uint32_t mask) {PCIDevice *pdev =PCI_DEVICE (vdev);
@@ -148,7 +148,7 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev) vdev->clear_parent_atomics_on_exit = true; } -void vfio_pci_disable_rp_atomics (VFIOPCIDevice *vdev) +void vfio_pci_cap_disable_rp_atomics (VFIOPCIDevice *vdev) {PCIDevice *pdev =PCI_DEVICE (vdev);
@@ -220,15 +220,15 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,* Endpoints, which changes the type and clears the LNK & LNK2 fields. */ if (type ==PCI_EXP_TYPE_ENDPOINT ) { -vfio_add_emulated_word (vdev, pos +PCI_CAP_FLAGS , +vfio_pci_cap_add_emulated_word (vdev, pos +PCI_CAP_FLAGS ,PCI_EXP_TYPE_RC_END <<4 ,PCI_EXP_FLAGS_TYPE );/* Link Capabilities, Status, and Control goes away */ if (size >PCI_EXP_LNKCTL ) { -vfio_add_emulated_long (vdev, pos +PCI_EXP_LNKCAP ,0 , ~0 ); -vfio_add_emulated_word (vdev, pos +PCI_EXP_LNKCTL ,0 , ~0 ); -vfio_add_emulated_word (vdev, pos +PCI_EXP_LNKSTA ,0 , ~0 ); +vfio_pci_cap_add_emulated_long (vdev, pos +PCI_EXP_LNKCAP ,0 , ~0 ); +vfio_pci_cap_add_emulated_word (vdev, pos +PCI_EXP_LNKCTL ,0 , ~0 ); +vfio_pci_cap_add_emulated_word (vdev, pos +PCI_EXP_LNKSTA ,0 , ~0 );#ifndef PCI_EXP_LNKCAP2 #define PCI_EXP_LNKCAP2 44
@@ -238,9 +238,9 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,#endif /* Link 2 Capabilities, Status, and Control goes away */ if (size >PCI_EXP_LNKCAP2 ) { -vfio_add_emulated_long (vdev, pos +PCI_EXP_LNKCAP2 ,0 , ~0 ); -vfio_add_emulated_word (vdev, pos +PCI_EXP_LNKCTL2 ,0 , ~0 ); -vfio_add_emulated_word (vdev, pos +PCI_EXP_LNKSTA2 ,0 , ~0 ); +vfio_pci_cap_add_emulated_long (vdev, pos +PCI_EXP_LNKCAP2 ,0 , ~0 ); +vfio_pci_cap_add_emulated_word (vdev, pos +PCI_EXP_LNKCTL2 ,0 , ~0 ); +vfio_pci_cap_add_emulated_word (vdev, pos +PCI_EXP_LNKSTA2 ,0 , ~0 ); } }
@@ -258,13 +258,13 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,* These devices don't support LNK/LNK2 capabilities, so make them up. */ if (type ==PCI_EXP_TYPE_RC_END ) { -vfio_add_emulated_word (vdev, pos +PCI_CAP_FLAGS , +vfio_pci_cap_add_emulated_word (vdev, pos +PCI_CAP_FLAGS ,PCI_EXP_TYPE_ENDPOINT <<4 ,PCI_EXP_FLAGS_TYPE ); -vfio_add_emulated_long (vdev, pos +PCI_EXP_LNKCAP , +vfio_pci_cap_add_emulated_long (vdev, pos +PCI_EXP_LNKCAP ,QEMU_PCI_EXP_LNKCAP_MLW (QEMU_PCI_EXP_LNK_X1 ) |QEMU_PCI_EXP_LNKCAP_MLS (QEMU_PCI_EXP_LNK_2_5GT ), ~0 ); -vfio_add_emulated_word (vdev, pos +PCI_EXP_LNKCTL ,0 , ~0 ); +vfio_pci_cap_add_emulated_word (vdev, pos +PCI_EXP_LNKCTL ,0 , ~0 ); }vfio_pci_enable_rp_atomics (vdev);
@@ -278,7 +278,7 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,* config space. */ if ((flags &PCI_EXP_FLAGS_VERS ) ==0 ) { -vfio_add_emulated_word (vdev, pos +PCI_CAP_FLAGS , +vfio_pci_cap_add_emulated_word (vdev, pos +PCI_CAP_FLAGS ,1 ,PCI_EXP_FLAGS_VERS ); }
@@ -476,8 +476,8 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)* BAR size. A write of an unsupported value is undefined, therefore * the register field is essentially RO. */ -vfio_add_emulated_long (vdev, pos +PCI_REBAR_CAP + (i *8 ), cap, ~0 ); -vfio_add_emulated_long (vdev, pos +PCI_REBAR_CTRL + (i *8 ), ctrl, ~0 ); +vfio_pci_cap_add_emulated_long (vdev, pos +PCI_REBAR_CAP + (i *8 ), cap, ~0 ); +vfio_pci_cap_add_emulated_long (vdev, pos +PCI_REBAR_CTRL + (i *8 ), ctrl, ~0 ); }return 0 ;
hw/vfio/pci.c +6 -6
@@ -1158,7 +1158,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)error_setg (errp,"invalid PCI vendor ID provided" );return false; } -vfio_add_emulated_word (vdev,PCI_VENDOR_ID , vdev->vendor_id, ~0 ); +vfio_pci_cap_add_emulated_word (vdev,PCI_VENDOR_ID , vdev->vendor_id, ~0 );trace_vfio_pci_emulated_vendor_id (vbasedev->name, vdev->vendor_id); }else { vdev->vendor_id =pci_get_word (pdev->config +PCI_VENDOR_ID );
@@ -1169,7 +1169,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)error_setg (errp,"invalid PCI device ID provided" );return false; } -vfio_add_emulated_word (vdev,PCI_DEVICE_ID , vdev->device_id, ~0 ); +vfio_pci_cap_add_emulated_word (vdev,PCI_DEVICE_ID , vdev->device_id, ~0 );trace_vfio_pci_emulated_device_id (vbasedev->name, vdev->device_id); }else { vdev->device_id =pci_get_word (pdev->config +PCI_DEVICE_ID );
@@ -1180,7 +1180,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)error_setg (errp,"invalid PCI subsystem vendor ID provided" );return false; } -vfio_add_emulated_word (vdev,PCI_SUBSYSTEM_VENDOR_ID , +vfio_pci_cap_add_emulated_word (vdev,PCI_SUBSYSTEM_VENDOR_ID , vdev->sub_vendor_id, ~0 );trace_vfio_pci_emulated_sub_vendor_id (vbasedev->name, vdev->sub_vendor_id);
@@ -1191,7 +1191,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)error_setg (errp,"invalid PCI subsystem device ID provided" );return false; } -vfio_add_emulated_word (vdev,PCI_SUBSYSTEM_ID , vdev->sub_device_id, ~0 ); +vfio_pci_cap_add_emulated_word (vdev,PCI_SUBSYSTEM_ID , vdev->sub_device_id, ~0 );trace_vfio_pci_emulated_sub_device_id (vbasedev->name, vdev->sub_device_id); }
@@ -1206,7 +1206,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)return false; }/* Higher 24 bits of PCI_CLASS_REVISION are class code */ -vfio_add_emulated_long (vdev,PCI_CLASS_REVISION , +vfio_pci_cap_add_emulated_long (vdev,PCI_CLASS_REVISION , vdev->class_code <<8 , ~0xff );trace_vfio_pci_emulated_class_code (vbasedev->name, vdev->class_code); }else {
@@ -1433,7 +1433,7 @@ static void vfio_exitfn(PCIDevice *pdev)timer_free (vdev->intx.mmap_timer); }vfio_pci_msi_teardown (vdev); -vfio_pci_disable_rp_atomics (vdev); +vfio_pci_cap_disable_rp_atomics (vdev);vfio_pci_bars_exit (vdev);vfio_migration_exit (vbasedev);if (!vbasedev->mdev) {
Signature · 1 line
2.56.0
PATCH 7/9 vfio/pci: Rename vfio_sub_page_bar_update_mappings() function
In reply to Cédric Le Goater vfio_sub_page_bar_update_mappings -> vfio_pci_bar_update_sub_page_mappings
No functional change.
--- hw/vfio/pci.h | 2 +- hw/vfio/cpr.c | 2 +- hw/vfio/pci.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
hw/vfio/pci.h +1 -1
@@ -260,7 +260,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp);/* BARs */ void vfio_pci_bars_exit (VFIOPCIDevice *vdev); -void vfio_sub_page_bar_update_mappings (VFIOPCIDevice *vdev); +void vfio_pci_bar_update_sub_page_mappings (VFIOPCIDevice *vdev);/* Capabilities */ void vfio_pci_cap_add_emulated_word(VFIOPCIDevice *vdev, int pos,
hw/vfio/cpr.c +1 -1
@@ -116,7 +116,7 @@ static int vfio_cpr_pci_post_load(void *opaque, int version_id)PCIDevice *pdev =PCI_DEVICE (vdev);int nr_vectors; -vfio_sub_page_bar_update_mappings (vdev); +vfio_pci_bar_update_sub_page_mappings (vdev);if (msix_enabled (pdev)) {vfio_pci_msix_set_notifiers (vdev);
hw/vfio/pci.c +1 -1
@@ -927,7 +927,7 @@ VFIOPCIDevice *vfio_pci_from_vfio_device(VFIODevice *vbasedev)return NULL ; } -void vfio_sub_page_bar_update_mappings (VFIOPCIDevice *vdev) +void vfio_pci_bar_update_sub_page_mappings (VFIOPCIDevice *vdev) {PCIDevice *pdev =PCI_DEVICE (vdev);int page_size =qemu_real_host_page_size ();
Signature · 1 line
2.56.0
PATCH 8/9 vfio/pci: Extract ROM handling into pci-rom.c
In reply to Cédric Le GoaterMove ROM handling routines into a dedicated pci-rom.c file.
No functional change. Retain existing license 'GPL-2.0-only'.
--- hw/vfio/pci.h | 1 + hw/vfio/pci-rom.c | 239 ++++++++++++++++++++++++++++++++++++++++++++ hw/vfio/pci.c | 218 ---------------------------------------- hw/vfio/meson.build | 1 + 4 files changed, 241 insertions(+), 218 deletions(-) create mode 100644 hw/vfio/pci-rom.c
hw/vfio/pci.h +1 -0
@@ -251,6 +251,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp);void vfio_pci_config_register_vga (VFIOPCIDevice *vdev);/* ROM */ +void vfio_pci_size_rom (VFIOPCIDevice *vdev);bool vfio_opt_rom_in_denylist (VFIOPCIDevice *vdev);/* VGA */
hw/vfio/pci-rom.c new file +239 -0
239 lines not on this page · raw message
hw/vfio/pci.c +0 -218
230 lines not on this page · raw message
hw/vfio/meson.build +1 -0
@@ -15,6 +15,7 @@ vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( 'pci-caps.c', 'pci-irq.c', 'pci-quirks.c', + 'pci-rom.c', 'pci.c', )) vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
Signature · 1 line
2.56.0
PATCH 9/9 vfio/pci: Rename vfio_opt_rom_in_denylist() to vfio_quirk_rom_in_denylist()
In reply to Cédric Le GoaterThe function is defined in pci-quirks.c. Rename it to follow the vfio_quirk_ naming convention.
No functional change.
--- hw/vfio/pci.h | 2 +- hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci-rom.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
hw/vfio/pci.h +1 -1
@@ -252,7 +252,6 @@ void vfio_pci_config_register_vga(VFIOPCIDevice *vdev);/* ROM */ void vfio_pci_size_rom (VFIOPCIDevice *vdev); -bool vfio_opt_rom_in_denylist (VFIOPCIDevice *vdev);/* VGA */ uint64_t vfio_vga_read (void *opaque,hwaddr addr,unsigned size);
@@ -284,6 +283,7 @@ bool vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp);void vfio_rom_quirk_setup (VFIOPCIDevice *vdev);void vfio_quirk_reset (VFIOPCIDevice *vdev);VFIOQuirk *vfio_quirk_alloc (int nr_mem); +bool vfio_quirk_rom_in_denylist (VFIOPCIDevice *vdev);/* IGD */ void vfio_probe_igd_bar0_quirk (VFIOPCIDevice *vdev,int nr);
hw/vfio/pci-quirks.c +1 -1
@@ -48,7 +48,7 @@ static const struct { { 0x14e4, 0x168e }, /* Broadcom BCM 57810 */ }; -bool vfio_opt_rom_in_denylist (VFIOPCIDevice *vdev) +bool vfio_quirk_rom_in_denylist (VFIOPCIDevice *vdev) {int i;
hw/vfio/pci-rom.c +2 -2
@@ -180,7 +180,7 @@ void vfio_pci_size_rom(VFIOPCIDevice *vdev)if (pdev->romfile || !pdev->rom_bar) {/* Since pci handles romfile, just print a message and return */ -if (vfio_opt_rom_in_denylist (vdev) && pdev->romfile) { +if (vfio_quirk_rom_in_denylist (vdev) && pdev->romfile) {warn_report ("Device at %s is known to cause system instability" " issues during option rom execution" , vdev->vbasedev.name);
@@ -208,7 +208,7 @@ void vfio_pci_size_rom(VFIOPCIDevice *vdev)return ; } -if (vfio_opt_rom_in_denylist (vdev)) { +if (vfio_quirk_rom_in_denylist (vdev)) {if (pdev->rom_bar >0 ) { warn_report("Device at %s is known to cause system instability" " issues during option rom execution",
Signature · 1 line
2.56.0