diff options
| author | Zhenzhong Duan <zhenzhong.duan@intel.com> | 2025-08-22 02:40:42 -0400 |
|---|---|---|
| committer | Cédric Le Goater <clg@redhat.com> | 2025-09-08 16:46:31 +0200 |
| commit | bb1a6f1f43374a1850c314c4d0e945667d013d07 (patch) | |
| tree | abf7b0185b16aa9284bebfb3fba42107a93a6420 /hw/vfio/pci.c | |
| parent | 1b50621881241ac5bc75ae7f8aa4c278ada8a668 (diff) | |
| download | focaccia-qemu-bb1a6f1f43374a1850c314c4d0e945667d013d07.tar.gz focaccia-qemu-bb1a6f1f43374a1850c314c4d0e945667d013d07.zip | |
vfio: Introduce helper vfio_pci_from_vfio_device()
Introduce helper vfio_pci_from_vfio_device() to transform from VFIODevice to VFIOPCIDevice, also to hide low level VFIO_DEVICE_TYPE_PCI type check. Suggested-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Link: https://lore.kernel.org/qemu-devel/20250822064101.123526-5-zhenzhong.duan@intel.com [ clg: Added documentation ] Signed-off-by: Cédric Le Goater <clg@redhat.com>
Diffstat (limited to 'hw/vfio/pci.c')
| -rw-r--r-- | hw/vfio/pci.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 07257d0fa0..3fe5b03eb1 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2833,6 +2833,15 @@ static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) return ret; } +/* Transform from VFIODevice to VFIOPCIDevice. Return NULL if fails. */ +VFIOPCIDevice *vfio_pci_from_vfio_device(VFIODevice *vbasedev) +{ + if (vbasedev && vbasedev->type == VFIO_DEVICE_TYPE_PCI) { + return container_of(vbasedev, VFIOPCIDevice, vbasedev); + } + return NULL; +} + void vfio_sub_page_bar_update_mappings(VFIOPCIDevice *vdev) { PCIDevice *pdev = &vdev->pdev; |