[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v3 10/19] vfio-user: get device info
From: |
John Johnson |
Subject: |
[RFC v3 10/19] vfio-user: get device info |
Date: |
Mon, 8 Nov 2021 16:46:38 -0800 |
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
hw/vfio/user-protocol.h | 13 +++++++++++++
hw/vfio/user.h | 2 ++
hw/vfio/pci.c | 19 +++++++++++++++++++
hw/vfio/user.c | 40 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+)
diff --git a/hw/vfio/user-protocol.h b/hw/vfio/user-protocol.h
index 14b762d..13e44eb 100644
--- a/hw/vfio/user-protocol.h
+++ b/hw/vfio/user-protocol.h
@@ -82,4 +82,17 @@ typedef struct {
#define VFIO_USER_MAX_MAX_XFER (64 * 1024 * 1024)
+/*
+ * VFIO_USER_DEVICE_GET_INFO
+ * imported from struct_device_info
+ */
+typedef struct {
+ VFIOUserHdr hdr;
+ uint32_t argsz;
+ uint32_t flags;
+ uint32_t num_regions;
+ uint32_t num_irqs;
+ uint32_t cap_offset;
+} VFIOUserDeviceInfo;
+
#endif /* VFIO_USER_PROTOCOL_H */
diff --git a/hw/vfio/user.h b/hw/vfio/user.h
index 7ef3c95..19edd84 100644
--- a/hw/vfio/user.h
+++ b/hw/vfio/user.h
@@ -83,4 +83,6 @@ void vfio_user_set_handler(VFIODevice *vbasedev,
void *reqarg);
int vfio_user_validate_version(VFIODevice *vbasedev, Error **errp);
+extern VFIODevIO vfio_dev_io_sock;
+
#endif /* VFIO_USER_H */
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 1bd0f6c..40eb9e6 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -3484,6 +3484,8 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Error
**errp)
VFIODevice *vbasedev = &vdev->vbasedev;
SocketAddress addr;
VFIOProxy *proxy;
+ struct vfio_device_info info;
+ int ret;
Error *err = NULL;
/*
@@ -3524,8 +3526,25 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Error
**errp)
vbasedev->type = VFIO_DEVICE_TYPE_PCI;
vbasedev->no_mmap = false;
vbasedev->ops = &vfio_user_pci_ops;
+ vbasedev->io_ops = &vfio_dev_io_sock;
vbasedev->valid_ops = &vfio_pci_valid_ops;
+ ret = VDEV_GET_INFO(vbasedev, &info);
+ if (ret) {
+ error_setg_errno(errp, -ret, "get info failure");
+ goto error;
+ }
+ vbasedev->num_irqs = info.num_irqs;
+ vbasedev->num_regions = info.num_regions;
+ vbasedev->flags = info.flags;
+ vbasedev->reset_works = !!(info.flags & VFIO_DEVICE_FLAGS_RESET);
+
+ vfio_populate_device(vdev, &err);
+ if (err) {
+ error_propagate(errp, err);
+ goto error;
+ }
+
return;
error:
diff --git a/hw/vfio/user.c b/hw/vfio/user.c
index edf1816..ed2a4d7 100644
--- a/hw/vfio/user.c
+++ b/hw/vfio/user.c
@@ -905,3 +905,43 @@ int vfio_user_validate_version(VFIODevice *vbasedev, Error
**errp)
return 0;
}
+
+static int vfio_user_get_info(VFIOProxy *proxy, struct vfio_device_info *info)
+{
+ VFIOUserDeviceInfo msg;
+
+ memset(&msg, 0, sizeof(msg));
+ vfio_user_request_msg(&msg.hdr, VFIO_USER_DEVICE_GET_INFO, sizeof(msg), 0);
+ msg.argsz = sizeof(struct vfio_device_info);
+
+ vfio_user_send_wait(proxy, &msg.hdr, NULL, 0, false);
+ if (msg.hdr.flags & VFIO_USER_ERROR) {
+ return -msg.hdr.error_reply;
+ }
+
+ memcpy(info, &msg.argsz, sizeof(*info));
+ return 0;
+}
+
+
+/*
+ * Socket-based io_ops
+ */
+
+static int vfio_user_io_get_info(VFIODevice *vbasedev,
+ struct vfio_device_info *info)
+{
+ int ret;
+
+ ret = vfio_user_get_info(vbasedev->proxy, info);
+ if (ret) {
+ return ret;
+ }
+
+ return VDEV_VALID_INFO(vbasedev, info);
+}
+
+VFIODevIO vfio_dev_io_sock = {
+ .get_info = vfio_user_io_get_info,
+};
+
--
1.8.3.1
- [RFC v3 06/19] vfio-user: Define type vfio_user_pci_dev_info, (continued)
- [RFC v3 06/19] vfio-user: Define type vfio_user_pci_dev_info, John Johnson, 2021/11/08
- [RFC v3 04/19] Add device IO ops vector, John Johnson, 2021/11/08
- [RFC v3 09/19] vfio-user: define socket send functions, John Johnson, 2021/11/08
- [RFC v3 03/19] Add container IO ops vector, John Johnson, 2021/11/08
- [RFC v3 02/19] vfio-user: add VFIO base abstract class, John Johnson, 2021/11/08
- [RFC v3 07/19] vfio-user: connect vfio proxy to remote server, John Johnson, 2021/11/08
- [RFC v3 10/19] vfio-user: get device info,
John Johnson <=
- [RFC v3 08/19] vfio-user: define socket receive functions, John Johnson, 2021/11/08
- [RFC v3 05/19] Add validation ops vector, John Johnson, 2021/11/08
- [RFC v3 15/19] vfio-user: proxy container connect/disconnect, John Johnson, 2021/11/08
- [RFC v3 18/19] vfio-user: pci reset, John Johnson, 2021/11/08
- [RFC v3 12/19] vfio-user: region read/write, John Johnson, 2021/11/08
- [RFC v3 14/19] vfio-user: get and set IRQs, John Johnson, 2021/11/08
- [RFC v3 19/19] vfio-user: migration support, John Johnson, 2021/11/08