From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com
Subject: [Qemu-devel] [PULL 07/14] hw/vfio/pci: add type, name and group fields in VFIODevice
Date: Mon, 22 Dec 2014 13:43:52 -0700 [thread overview]
Message-ID: <20141222204351.31398.64545.stgit@bling.home> (raw)
In-Reply-To: <20141222204144.31398.31803.stgit@bling.home>
From: Eric Auger <eric.auger@linaro.org>
Add 3 new fields in the VFIODevice struct. Type is set to
VFIO_DEVICE_TYPE_PCI. The type enum value will later be used
to discriminate between VFIO PCI and platform devices. The name is
set to domain:bus:slot:function. Currently used to test whether
the device already is attached to the group. Later on, the name
will be used to simplify all traces. The group is simply moved
from VFIOPCIDevice to VFIODevice.
Signed-off-by: Eric Auger <eric.auger@linaro.org>
[Fix g_strdup_printf() usage]
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
hw/vfio/pci.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 22d0c85..be7b8ff 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -48,6 +48,10 @@
#define VFIO_ALLOW_KVM_MSI 1
#define VFIO_ALLOW_KVM_MSIX 1
+enum {
+ VFIO_DEVICE_TYPE_PCI = 0,
+};
+
struct VFIOPCIDevice;
typedef struct VFIOQuirk {
@@ -186,7 +190,10 @@ typedef struct VFIOMSIXInfo {
} VFIOMSIXInfo;
typedef struct VFIODevice {
+ struct VFIOGroup *group;
+ char *name;
int fd;
+ int type;
} VFIODevice;
typedef struct VFIOPCIDevice {
@@ -208,7 +215,6 @@ typedef struct VFIOPCIDevice {
VFIOVGA vga; /* 0xa0000, 0x3b0, 0x3c0 */
PCIHostDeviceAddress host;
QLIST_ENTRY(VFIOPCIDevice) next;
- struct VFIOGroup *group;
EventNotifier err_notifier;
uint32_t features;
#define VFIO_FEATURE_ENABLE_VGA_BIT 0
@@ -3924,7 +3930,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
}
vdev->vbasedev.fd = ret;
- vdev->group = group;
+ vdev->vbasedev.group = group;
QLIST_INSERT_HEAD(&group->device_list, vdev, next);
/* Sanity check device */
@@ -4054,7 +4060,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
error:
if (ret) {
QLIST_REMOVE(vdev, next);
- vdev->group = NULL;
+ vdev->vbasedev.group = NULL;
close(vdev->vbasedev.fd);
}
return ret;
@@ -4063,9 +4069,10 @@ error:
static void vfio_put_device(VFIOPCIDevice *vdev)
{
QLIST_REMOVE(vdev, next);
- vdev->group = NULL;
+ vdev->vbasedev.group = NULL;
trace_vfio_put_device(vdev->vbasedev.fd);
close(vdev->vbasedev.fd);
+ g_free(vdev->vbasedev.name);
if (vdev->msix) {
g_free(vdev->msix);
vdev->msix = NULL;
@@ -4197,6 +4204,11 @@ static int vfio_initfn(PCIDevice *pdev)
return -errno;
}
+ vdev->vbasedev.type = VFIO_DEVICE_TYPE_PCI;
+ vdev->vbasedev.name = g_strdup_printf("%04x:%02x:%02x.%01x",
+ vdev->host.domain, vdev->host.bus,
+ vdev->host.slot, vdev->host.function);
+
strncat(path, "iommu_group", sizeof(path) - strlen(path) - 1);
len = readlink(path, iommu_group_path, sizeof(path));
@@ -4227,10 +4239,7 @@ static int vfio_initfn(PCIDevice *pdev)
vdev->host.function);
QLIST_FOREACH(pvdev, &group->device_list, next) {
- if (pvdev->host.domain == vdev->host.domain &&
- pvdev->host.bus == vdev->host.bus &&
- pvdev->host.slot == vdev->host.slot &&
- pvdev->host.function == vdev->host.function) {
+ if (strcmp(pvdev->vbasedev.name, vdev->vbasedev.name) == 0) {
error_report("vfio: error: device %s is already attached", path);
vfio_put_group(group);
@@ -4333,7 +4342,7 @@ out_put:
static void vfio_exitfn(PCIDevice *pdev)
{
VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
- VFIOGroup *group = vdev->group;
+ VFIOGroup *group = vdev->vbasedev.group;
vfio_unregister_err_notifier(vdev);
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
next prev parent reply other threads:[~2014-12-22 20:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-22 20:43 [Qemu-devel] [PULL 00/14] QEMU: VFIO updates Alex Williamson
2014-12-22 20:43 ` [Qemu-devel] [PULL 01/14] vfio: migration to trace points Alex Williamson
2014-12-22 20:43 ` [Qemu-devel] [PULL 02/14] vfio: fix adding memory listener to the right address space Alex Williamson
2014-12-22 20:43 ` [Qemu-devel] [PULL 03/14] vfio: move hw/misc/vfio.c to hw/vfio/pci.c Move vfio.h into include/hw/vfio Alex Williamson
2014-12-22 20:43 ` [Qemu-devel] [PULL 04/14] hw/vfio/pci: Rename VFIODevice into VFIOPCIDevice Alex Williamson
2014-12-22 20:43 ` [Qemu-devel] [PULL 05/14] hw/vfio/pci: generalize mask/unmask to any IRQ index Alex Williamson
2014-12-22 20:43 ` [Qemu-devel] [PULL 06/14] hw/vfio/pci: introduce minimalist VFIODevice with fd Alex Williamson
2014-12-22 20:43 ` Alex Williamson [this message]
2014-12-22 20:43 ` [Qemu-devel] [PULL 08/14] hw/vfio/pci: handle reset at VFIODevice Alex Williamson
2014-12-22 20:44 ` [Qemu-devel] [PULL 09/14] hw/vfio/pci: Introduce VFIORegion Alex Williamson
2014-12-22 20:44 ` [Qemu-devel] [PULL 10/14] hw/vfio/pci: split vfio_get_device Alex Williamson
2014-12-22 20:44 ` [Qemu-devel] [PULL 11/14] hw/vfio/pci: rename group_list into vfio_group_list Alex Williamson
2014-12-22 20:44 ` [Qemu-devel] [PULL 12/14] hw/vfio/pci: use name field in format strings Alex Williamson
2014-12-22 20:44 ` [Qemu-devel] [PULL 13/14] hw/vfio: create common module Alex Williamson
2014-12-22 20:44 ` [Qemu-devel] [PULL 14/14] vfio: Cleanup error_report()s Alex Williamson
2014-12-23 15:05 ` [Qemu-devel] [PULL 00/14] QEMU: VFIO updates 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=20141222204351.31398.64545.stgit@bling.home \
--to=alex.williamson@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).