[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 16/19] vfio-user: pci reset
From: |
Elena Ufimtseva |
Subject: |
[PATCH RFC 16/19] vfio-user: pci reset |
Date: |
Sun, 18 Jul 2021 23:27:55 -0700 |
From: John G Johnson <john.g.johnson@oracle.com>
Send VFIO_USER_DEVICE_RESET to reset remote device.
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.h | 1 +
hw/vfio/pci.c | 29 ++++++++++++++++++++++++++---
hw/vfio/user.c | 12 ++++++++++++
3 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/hw/vfio/user.h b/hw/vfio/user.h
index afb85952da..95c2fb1707 100644
--- a/hw/vfio/user.h
+++ b/hw/vfio/user.h
@@ -254,4 +254,5 @@ void vfio_user_set_reqhandler(VFIODevice *vbasdev,
VFIOUserFDs *fds),
void *reqarg);
int vfio_user_set_irqs(VFIODevice *vbasedev, struct vfio_irq_set *irq);
+void vfio_user_reset(VFIODevice *vbasedev);
#endif /* VFIO_USER_H */
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 52af5a1061..a6c28dac03 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2212,8 +2212,9 @@ static void vfio_pci_pre_reset(VFIOPCIDevice *vdev)
static void vfio_pci_post_reset(VFIOPCIDevice *vdev)
{
+ VFIODevice *vbasedev = &vdev->vbasedev;
Error *err = NULL;
- int nr;
+ int ret, nr;
vfio_intx_enable(vdev, &err);
if (err) {
@@ -2221,11 +2222,18 @@ static void vfio_pci_post_reset(VFIOPCIDevice *vdev)
}
for (nr = 0; nr < PCI_NUM_REGIONS - 1; ++nr) {
- off_t addr = vdev->config_offset + PCI_BASE_ADDRESS_0 + (4 * nr);
+ off_t addr = PCI_BASE_ADDRESS_0 + (4 * nr);
uint32_t val = 0;
uint32_t len = sizeof(val);
- if (pwrite(vdev->vbasedev.fd, &val, len, addr) != len) {
+ if (vbasedev->proxy != NULL) {
+ ret = vfio_user_region_write(vbasedev,
VFIO_PCI_CONFIG_REGION_INDEX,
+ addr, len, &val);
+ } else {
+ ret = pwrite(vdev->vbasedev.fd, &val, len,
+ vdev->config_offset + addr);
+ }
+ if (ret != len) {
error_report("%s(%s) reset bar %d failed: %m", __func__,
vdev->vbasedev.name, nr);
}
@@ -3634,6 +3642,20 @@ static void vfio_user_instance_finalize(Object *obj)
vfio_user_disconnect(vbasedev->proxy);
}
+static void vfio_user_pci_reset(DeviceState *dev)
+{
+ VFIOPCIDevice *vdev = VFIO_PCI_BASE(dev);
+ VFIODevice *vbasedev = &vdev->vbasedev;
+
+ vfio_pci_pre_reset(vdev);
+
+ if (vbasedev->reset_works) {
+ vfio_user_reset(vbasedev);
+ }
+
+ vfio_pci_post_reset(vdev);
+}
+
static Property vfio_user_pci_dev_properties[] = {
DEFINE_PROP_STRING("socket", VFIOUserPCIDevice, sock_name),
DEFINE_PROP_BOOL("secure-dma", VFIOUserPCIDevice, secure, false),
@@ -3645,6 +3667,7 @@ static void vfio_user_pci_dev_class_init(ObjectClass
*klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *pdc = PCI_DEVICE_CLASS(klass);
+ dc->reset = vfio_user_pci_reset;
device_class_set_props(dc, vfio_user_pci_dev_properties);
dc->desc = "VFIO over socket PCI device assignment";
pdc->realize = vfio_user_pci_realize;
diff --git a/hw/vfio/user.c b/hw/vfio/user.c
index 0fd7e01986..8917596a2f 100644
--- a/hw/vfio/user.c
+++ b/hw/vfio/user.c
@@ -905,3 +905,15 @@ int vfio_user_set_irqs(VFIODevice *vbasedev, struct
vfio_irq_set *irq)
return 0;
}
+
+void vfio_user_reset(VFIODevice *vbasedev)
+{
+ vfio_user_hdr_t msg;
+
+ vfio_user_request_msg(&msg, VFIO_USER_DEVICE_RESET, sizeof(msg), 0);
+
+ vfio_user_send_recv(vbasedev->proxy, &msg, NULL, 0);
+ if (msg.flags & VFIO_USER_ERROR) {
+ error_printf("reset reply error %d\n", msg.error_reply);
+ }
+}
--
2.25.1
- [PATCH RFC 09/19] vfio-user: get device info and get irq info, (continued)
- [PATCH RFC 15/19] vfio-user: vfio user device realize, Elena Ufimtseva, 2021/07/19
- [PATCH RFC 13/19] vfio-user: respond to remote DMA read/write requests, Elena Ufimtseva, 2021/07/19
- [PATCH RFC 18/19] vfio-user: migration support, Elena Ufimtseva, 2021/07/19
- [PATCH RFC 17/19] vfio-user: probe remote device ROM BAR, Elena Ufimtseva, 2021/07/19
- [PATCH RFC 19/19] vfio-user: add migration cli options and version negotiation, Elena Ufimtseva, 2021/07/19
- [PATCH RFC 16/19] vfio-user: pci reset,
Elena Ufimtseva <=
- [PATCH RFC server 00/11] vfio-user server in QEMU, Jagannathan Raman, 2021/07/19
- [PATCH RFC server 07/11] vfio-user: handle DMA mappings, Jagannathan Raman, 2021/07/19
- [PATCH RFC server 08/11] vfio-user: handle PCI BAR accesses, Jagannathan Raman, 2021/07/19
- [PATCH RFC server 10/11] vfio-user: register handlers to facilitate migration, Jagannathan Raman, 2021/07/19
- [PATCH RFC server 09/11] vfio-user: handle device interrupts, Jagannathan Raman, 2021/07/19
- [PATCH RFC server 11/11] vfio-user: acceptance test, Jagannathan Raman, 2021/07/19
- [PATCH RFC server 01/11] vfio-user: build library, Jagannathan Raman, 2021/07/19