[PULL 2/3] vfio: Move the TYPE_* to hw/vfio/types.h

Gerd Hoffmann posted 3 patches 3 months, 4 weeks ago
[PULL 2/3] vfio: Move the TYPE_* to hw/vfio/types.h
Posted by Gerd Hoffmann 3 months, 4 weeks ago
From: Shaoqin Huang <shahuang@redhat.com>

Move the TYPE_* to a new file hw/vfio/types.h because the
TYPE_VFIO_PCI will be used in later patch, but directly include the
hw/vfio/pci.h can cause some compilation error when cross build the
windows version.

The hw/vfio/types.h can be included to mitigate that problem.

Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Message-ID: <20250717100941.2230408-3-shahuang@redhat.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/vfio/pci.h   | 10 +---------
 hw/vfio/types.h | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 9 deletions(-)
 create mode 100644 hw/vfio/types.h

diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 826db8c1319b..0fd151c5dc2c 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -14,6 +14,7 @@
 
 #include "system/memory.h"
 #include "hw/pci/pci_device.h"
+#include "hw/vfio/types.h"
 #include "hw/vfio/vfio-device.h"
 #include "hw/vfio/vfio-region.h"
 #include "qemu/event_notifier.h"
@@ -119,17 +120,8 @@ typedef struct VFIOMSIXInfo {
     MemoryRegion *pba_region;
 } VFIOMSIXInfo;
 
-/*
- * TYPE_VFIO_PCI_BASE is an abstract type used to share code
- * between VFIO implementations that use a kernel driver
- * with those that use user sockets.
- */
-#define TYPE_VFIO_PCI_BASE "vfio-pci-base"
 OBJECT_DECLARE_SIMPLE_TYPE(VFIOPCIDevice, VFIO_PCI_BASE)
 
-#define TYPE_VFIO_PCI "vfio-pci"
-/* TYPE_VFIO_PCI shares struct VFIOPCIDevice. */
-
 struct VFIOPCIDevice {
     PCIDevice pdev;
     VFIODevice vbasedev;
diff --git a/hw/vfio/types.h b/hw/vfio/types.h
new file mode 100644
index 000000000000..fa20c29b9fbb
--- /dev/null
+++ b/hw/vfio/types.h
@@ -0,0 +1,21 @@
+/*
+ * VFIO types definition
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef HW_VFIO_VFIO_TYPES_H
+#define HW_VFIO_VFIO_TYPES_H
+
+/*
+ * TYPE_VFIO_PCI_BASE is an abstract type used to share code
+ * between VFIO implementations that use a kernel driver
+ * with those that use user sockets.
+ */
+#define TYPE_VFIO_PCI_BASE "vfio-pci-base"
+
+#define TYPE_VFIO_PCI "vfio-pci"
+/* TYPE_VFIO_PCI shares struct VFIOPCIDevice. */
+
+#endif /* HW_VFIO_VFIO_TYPES_H */
-- 
2.50.1
Re: [PULL 2/3] vfio: Move the TYPE_* to hw/vfio/types.h
Posted by Cédric Le Goater 3 months, 4 weeks ago
On 7/18/25 21:43, Gerd Hoffmann wrote:
> From: Shaoqin Huang <shahuang@redhat.com>
> 
> Move the TYPE_* to a new file hw/vfio/types.h because the
> TYPE_VFIO_PCI will be used in later patch, but directly include the
> hw/vfio/pci.h can cause some compilation error when cross build the
> windows version.
> 
> The hw/vfio/types.h can be included to mitigate that problem.

As said earlier, the string literal "vfio-pci" could be used instead
of the TYPE_VFIO_PCI define and avoid the extra vfio header file.

C.

> 
> Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
> Message-ID: <20250717100941.2230408-3-shahuang@redhat.com>
> Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>   hw/vfio/pci.h   | 10 +---------
>   hw/vfio/types.h | 21 +++++++++++++++++++++
>   2 files changed, 22 insertions(+), 9 deletions(-)
>   create mode 100644 hw/vfio/types.h
> 
> diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
> index 826db8c1319b..0fd151c5dc2c 100644
> --- a/hw/vfio/pci.h
> +++ b/hw/vfio/pci.h
> @@ -14,6 +14,7 @@
>   
>   #include "system/memory.h"
>   #include "hw/pci/pci_device.h"
> +#include "hw/vfio/types.h"
>   #include "hw/vfio/vfio-device.h"
>   #include "hw/vfio/vfio-region.h"
>   #include "qemu/event_notifier.h"
> @@ -119,17 +120,8 @@ typedef struct VFIOMSIXInfo {
>       MemoryRegion *pba_region;
>   } VFIOMSIXInfo;
>   
> -/*
> - * TYPE_VFIO_PCI_BASE is an abstract type used to share code
> - * between VFIO implementations that use a kernel driver
> - * with those that use user sockets.
> - */
> -#define TYPE_VFIO_PCI_BASE "vfio-pci-base"
>   OBJECT_DECLARE_SIMPLE_TYPE(VFIOPCIDevice, VFIO_PCI_BASE)
>   
> -#define TYPE_VFIO_PCI "vfio-pci"
> -/* TYPE_VFIO_PCI shares struct VFIOPCIDevice. */
> -
>   struct VFIOPCIDevice {
>       PCIDevice pdev;
>       VFIODevice vbasedev;
> diff --git a/hw/vfio/types.h b/hw/vfio/types.h
> new file mode 100644
> index 000000000000..fa20c29b9fbb
> --- /dev/null
> +++ b/hw/vfio/types.h
> @@ -0,0 +1,21 @@
> +/*
> + * VFIO types definition
> + *
> + * Copyright Red Hat, Inc. 2025
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +#ifndef HW_VFIO_VFIO_TYPES_H
> +#define HW_VFIO_VFIO_TYPES_H
> +
> +/*
> + * TYPE_VFIO_PCI_BASE is an abstract type used to share code
> + * between VFIO implementations that use a kernel driver
> + * with those that use user sockets.
> + */
> +#define TYPE_VFIO_PCI_BASE "vfio-pci-base"
> +
> +#define TYPE_VFIO_PCI "vfio-pci"
> +/* TYPE_VFIO_PCI shares struct VFIOPCIDevice. */
> +
> +#endif /* HW_VFIO_VFIO_TYPES_H */
Re: [PULL 2/3] vfio: Move the TYPE_* to hw/vfio/types.h
Posted by Gerd Hoffmann 3 months, 3 weeks ago
On Fri, Jul 18, 2025 at 11:03:40PM +0200, Cédric Le Goater wrote:
> On 7/18/25 21:43, Gerd Hoffmann wrote:
> > From: Shaoqin Huang <shahuang@redhat.com>
> > 
> > Move the TYPE_* to a new file hw/vfio/types.h because the
> > TYPE_VFIO_PCI will be used in later patch, but directly include the
> > hw/vfio/pci.h can cause some compilation error when cross build the
> > windows version.
> > 
> > The hw/vfio/types.h can be included to mitigate that problem.
> 
> As said earlier, the string literal "vfio-pci" could be used instead
> of the TYPE_VFIO_PCI define and avoid the extra vfio header file.

I think it makes sense to use TYPE_VFIO_PCI, for consistency and to
avoid typos in the device name.

take care,
  Gerd
Re: [PULL 2/3] vfio: Move the TYPE_* to hw/vfio/types.h
Posted by Cédric Le Goater 3 months, 3 weeks ago
On 7/21/25 08:28, Gerd Hoffmann wrote:
> On Fri, Jul 18, 2025 at 11:03:40PM +0200, Cédric Le Goater wrote:
>> On 7/18/25 21:43, Gerd Hoffmann wrote:
>>> From: Shaoqin Huang <shahuang@redhat.com>
>>>
>>> Move the TYPE_* to a new file hw/vfio/types.h because the
>>> TYPE_VFIO_PCI will be used in later patch, but directly include the
>>> hw/vfio/pci.h can cause some compilation error when cross build the
>>> windows version.
>>>
>>> The hw/vfio/types.h can be included to mitigate that problem.
>>
>> As said earlier, the string literal "vfio-pci" could be used instead
>> of the TYPE_VFIO_PCI define and avoid the extra vfio header file.
> 
> I think it makes sense to use TYPE_VFIO_PCI, for consistency and to
> avoid typos in the device name.

We should then generalize this practice to all types.

C.