From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
"Mark Cave-Ayland" <mark.caveayland@nutanix.com>,
"Tomita Moeko" <tomitamoeko@gmail.com>,
"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 28/31] vfio/igd.c: use QOM casts where appropriate
Date: Mon, 8 Sep 2025 18:53:51 +0200 [thread overview]
Message-ID: <20250908165354.1731444-29-clg@redhat.com> (raw)
In-Reply-To: <20250908165354.1731444-1-clg@redhat.com>
From: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
accessing pdev directly.
Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Reviewed-by: Tomita Moeko <tomitamoeko@gmail.com>
Link: https://lore.kernel.org/qemu-devel/20250715093110.107317-20-mark.caveayland@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
hw/vfio/igd.c | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index f116c40ccd933c8e6e7fd99d599c6372c26973e1..4bfa2e0fcd22a811c9dcf2b1c2357ad34c9e4a68 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -200,7 +200,7 @@ static bool vfio_pci_igd_opregion_detect(VFIOPCIDevice *vdev,
}
/* Hotplugging is not supported for opregion access */
- if (vdev->pdev.qdev.hotplugged) {
+ if (DEVICE(vdev)->hotplugged) {
warn_report("IGD device detected, but OpRegion is not supported "
"on hotplugged device.");
return false;
@@ -260,11 +260,12 @@ static int vfio_pci_igd_copy(VFIOPCIDevice *vdev, PCIDevice *pdev,
static int vfio_pci_igd_host_init(VFIOPCIDevice *vdev,
struct vfio_region_info *info)
{
+ PCIDevice *pdev = PCI_DEVICE(vdev);
PCIBus *bus;
PCIDevice *host_bridge;
int ret;
- bus = pci_device_root_bus(&vdev->pdev);
+ bus = pci_device_root_bus(pdev);
host_bridge = pci_find_device(bus, 0, PCI_DEVFN(0, 0));
if (!host_bridge) {
@@ -327,13 +328,14 @@ type_init(vfio_pci_igd_register_types)
static int vfio_pci_igd_lpc_init(VFIOPCIDevice *vdev,
struct vfio_region_info *info)
{
+ PCIDevice *pdev = PCI_DEVICE(vdev);
PCIDevice *lpc_bridge;
int ret;
- lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
+ lpc_bridge = pci_find_device(pci_device_root_bus(pdev),
0, PCI_DEVFN(0x1f, 0));
if (!lpc_bridge) {
- lpc_bridge = pci_create_simple(pci_device_root_bus(&vdev->pdev),
+ lpc_bridge = pci_create_simple(pci_device_root_bus(pdev),
PCI_DEVFN(0x1f, 0), "vfio-pci-igd-lpc-bridge");
}
@@ -350,13 +352,14 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
{
struct vfio_region_info *host = NULL;
struct vfio_region_info *lpc = NULL;
+ PCIDevice *pdev = PCI_DEVICE(vdev);
PCIDevice *lpc_bridge;
int ret;
/*
* Copying IDs or creating new devices are not supported on hotplug
*/
- if (vdev->pdev.qdev.hotplugged) {
+ if (DEVICE(vdev)->hotplugged) {
error_setg(errp, "IGD LPC is not supported on hotplugged device");
return false;
}
@@ -366,7 +369,7 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
* can stuff host values into, so if there's already one there and it's not
* one we can hack on, this quirk is no-go. Sorry Q35.
*/
- lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
+ lpc_bridge = pci_find_device(pci_device_root_bus(pdev),
0, PCI_DEVFN(0x1f, 0));
if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge),
"vfio-pci-igd-lpc-bridge")) {
@@ -510,6 +513,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
{
struct vfio_region_info *opregion = NULL;
+ PCIDevice *pdev = PCI_DEVICE(vdev);
int ret, gen;
uint64_t gms_size = 0;
uint64_t *bdsm_size;
@@ -529,7 +533,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
info_report("OpRegion detected on Intel display %x.", vdev->device_id);
gen = igd_gen(vdev);
- gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4);
+ gmch = vfio_pci_read_config(pdev, IGD_GMCH, 4);
/*
* For backward compatibility, enable legacy mode when
@@ -544,7 +548,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
(gen >= 6 && gen <= 9) &&
!(gmch & IGD_GMCH_VGA_DISABLE) &&
!strcmp(MACHINE_GET_CLASS(qdev_get_machine())->family, "pc_piix") &&
- (&vdev->pdev == pci_find_device(pci_device_root_bus(&vdev->pdev),
+ (pdev == pci_find_device(pci_device_root_bus(pdev),
0, PCI_DEVFN(0x2, 0)))) {
/*
* IGD legacy mode requires:
@@ -566,7 +570,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
*/
ret = vfio_device_get_region_info(&vdev->vbasedev,
VFIO_PCI_ROM_REGION_INDEX, &rom);
- if ((ret || !rom->size) && !vdev->pdev.romfile) {
+ if ((ret || !rom->size) && !pdev->romfile) {
error_setg(&err, "Device has no ROM");
goto error;
}
@@ -611,8 +615,8 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
* ASLS (OpRegion address) is read-only, emulated
* It contains HPA, guest firmware need to reprogram it with GPA.
*/
- pci_set_long(vdev->pdev.config + IGD_ASLS, 0);
- pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0);
+ pci_set_long(pdev->config + IGD_ASLS, 0);
+ pci_set_long(pdev->wmask + IGD_ASLS, ~0);
pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0);
/*
@@ -626,8 +630,8 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
}
/* GMCH is read-only, emulated */
- pci_set_long(vdev->pdev.config + IGD_GMCH, gmch);
- pci_set_long(vdev->pdev.wmask + IGD_GMCH, 0);
+ pci_set_long(pdev->config + IGD_GMCH, gmch);
+ pci_set_long(pdev->wmask + IGD_GMCH, 0);
pci_set_long(vdev->emulated_config_bits + IGD_GMCH, ~0);
}
@@ -636,12 +640,12 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
/* BDSM is read-write, emulated. BIOS needs to be able to write it */
if (gen < 11) {
- pci_set_long(vdev->pdev.config + IGD_BDSM, 0);
- pci_set_long(vdev->pdev.wmask + IGD_BDSM, ~0);
+ pci_set_long(pdev->config + IGD_BDSM, 0);
+ pci_set_long(pdev->wmask + IGD_BDSM, ~0);
pci_set_long(vdev->emulated_config_bits + IGD_BDSM, ~0);
} else {
- pci_set_quad(vdev->pdev.config + IGD_BDSM_GEN11, 0);
- pci_set_quad(vdev->pdev.wmask + IGD_BDSM_GEN11, ~0);
+ pci_set_quad(pdev->config + IGD_BDSM_GEN11, 0);
+ pci_set_quad(pdev->wmask + IGD_BDSM_GEN11, ~0);
pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0);
}
}
--
2.51.0
next prev parent reply other threads:[~2025-09-08 17:02 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 16:53 [PULL 00/31] vfio queue Cédric Le Goater
2025-09-08 16:53 ` [PULL 01/31] MAINTAINERS: Add myself as reviewer for PowerNV and XIVE Cédric Le Goater
2025-09-08 16:53 ` [PULL 02/31] vfio/igd: Enable quirks when IGD is not the primary display Cédric Le Goater
2025-09-08 16:53 ` [PULL 03/31] vfio: Remove 'vfio-amd-xgbe' device Cédric Le Goater
2025-09-08 16:53 ` [PULL 04/31] vfio: Remove 'vfio-calxeda-xgmac' device Cédric Le Goater
2025-09-08 16:53 ` [PULL 05/31] vfio: Remove 'vfio-platform' Cédric Le Goater
2025-09-08 16:53 ` [PULL 06/31] vfio: Move vfio-region.h under hw/vfio/ Cédric Le Goater
2025-09-08 16:53 ` [PULL 07/31] vfio/container: set error on cpr failure Cédric Le Goater
2025-09-08 16:53 ` [PULL 08/31] vfio: Report an error when the 'dma_max_mappings' limit is reached Cédric Le Goater
2025-09-08 16:53 ` [PULL 09/31] hw/vfio-user: add x-pci-class-code Cédric Le Goater
2025-09-08 16:53 ` [PULL 10/31] vfio: Introduce helper vfio_pci_from_vfio_device() Cédric Le Goater
2025-09-08 16:53 ` [PULL 11/31] vfio/vfio-container-base.h: update VFIOContainerBase declaration Cédric Le Goater
2025-09-08 16:53 ` [PULL 12/31] vfio/vfio-container.h: update VFIOContainer declaration Cédric Le Goater
2025-09-08 16:53 ` [PULL 13/31] hw/vfio/cpr-legacy.c: use QOM casts where appropriate Cédric Le Goater
2025-09-08 16:53 ` [PULL 14/31] hw/vfio/container.c: " Cédric Le Goater
2025-09-08 16:53 ` [PULL 15/31] ppc/spapr_pci_vfio.c: " Cédric Le Goater
2025-09-08 16:53 ` [PULL 16/31] vfio/spapr.c: " Cédric Le Goater
2025-09-08 16:53 ` [PULL 17/31] vfio/vfio-container.h: rename VFIOContainer bcontainer field to parent_obj Cédric Le Goater
2025-09-08 16:53 ` [PULL 18/31] vfio-user/container.h: update VFIOUserContainer declaration Cédric Le Goater
2025-09-08 16:53 ` [PULL 19/31] vfio/container.c: use QOM casts where appropriate Cédric Le Goater
2025-09-08 16:53 ` [PULL 20/31] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj Cédric Le Goater
2025-09-08 16:53 ` [PULL 21/31] vfio-user/pci.c: update VFIOUserPCIDevice declaration Cédric Le Goater
2025-09-08 16:53 ` [PULL 22/31] vfio-user/pci.c: use QOM casts where appropriate Cédric Le Goater
2025-09-08 16:53 ` [PULL 23/31] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj Cédric Le Goater
2025-09-08 16:53 ` [PULL 24/31] vfio/pci.h: update VFIOPCIDevice declaration Cédric Le Goater
2025-09-08 16:53 ` [PULL 25/31] vfio/pci.c: use QOM casts where appropriate Cédric Le Goater
2025-09-08 16:53 ` [PULL 26/31] vfio/pci-quirks.c: " Cédric Le Goater
2025-09-08 16:53 ` [PULL 27/31] vfio/cpr.c: " Cédric Le Goater
2025-09-08 16:53 ` Cédric Le Goater [this message]
2025-09-08 16:53 ` [PULL 29/31] vfio-user/pci.c: " Cédric Le Goater
2025-09-08 16:53 ` [PULL 30/31] s390x/s390-pci-vfio.c: " Cédric Le Goater
2025-09-08 16:53 ` [PULL 31/31] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj Cédric Le Goater
2025-09-11 13:11 ` [PULL 00/31] vfio queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250908165354.1731444-29-clg@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=mark.caveayland@nutanix.com \
--cc=qemu-devel@nongnu.org \
--cc=tomitamoeko@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).