From: Manojlo Pekovic <[email protected]> Extract atomic capability checking logic into a separate function vfio_get_atomic_cap() for better code organization and reusability.
Signed-off-by: Manojlo Pekovic <[email protected]> --- hw/vfio/pci.c | 53 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 14bcc725c3..6a6c8f1807 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1900,13 +1900,41 @@ static void vfio_add_emulated_long(VFIOPCIDevice *vdev, int pos, vfio_set_long_bits(vdev->emulated_config_bits + pos, mask, mask); } -static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev) +static uint32_t vfio_get_atomic_cap(VFIOPCIDevice *vdev) { struct vfio_device_info_cap_pci_atomic_comp *cap; g_autofree struct vfio_device_info *info = NULL; + struct vfio_info_cap_header *hdr; + uint32_t mask = 0; + + info = vfio_get_device_info(vdev->vbasedev.fd); + if (!info) { + return mask; + } + + hdr = vfio_get_device_info_cap(info, VFIO_DEVICE_INFO_CAP_PCI_ATOMIC_COMP); + if (!hdr) { + return mask; + } + + cap = (void *)hdr; + if (cap->flags & VFIO_PCI_ATOMIC_COMP32) { + mask |= PCI_EXP_DEVCAP2_ATOMIC_COMP32; + } + if (cap->flags & VFIO_PCI_ATOMIC_COMP64) { + mask |= PCI_EXP_DEVCAP2_ATOMIC_COMP64; + } + if (cap->flags & VFIO_PCI_ATOMIC_COMP128) { + mask |= PCI_EXP_DEVCAP2_ATOMIC_COMP128; + } + + return mask; +} + +static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev) +{ PCIBus *bus = pci_get_bus(&vdev->pdev); PCIDevice *parent = bus->parent_dev; - struct vfio_info_cap_header *hdr; uint32_t mask = 0; uint8_t *pos; @@ -1934,26 +1962,7 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev) return; } - info = vfio_get_device_info(vdev->vbasedev.fd); - if (!info) { - return; - } - - hdr = vfio_get_device_info_cap(info, VFIO_DEVICE_INFO_CAP_PCI_ATOMIC_COMP); - if (!hdr) { - return; - } - - cap = (void *)hdr; - if (cap->flags & VFIO_PCI_ATOMIC_COMP32) { - mask |= PCI_EXP_DEVCAP2_ATOMIC_COMP32; - } - if (cap->flags & VFIO_PCI_ATOMIC_COMP64) { - mask |= PCI_EXP_DEVCAP2_ATOMIC_COMP64; - } - if (cap->flags & VFIO_PCI_ATOMIC_COMP128) { - mask |= PCI_EXP_DEVCAP2_ATOMIC_COMP128; - } + mask = vfio_get_atomic_cap(vdev); if (!mask) { return; -- 2.43.0
