[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/11] vfio-pci: Extend reset
From: |
Alex Williamson |
Subject: |
[Qemu-devel] [PATCH 10/11] vfio-pci: Extend reset |
Date: |
Thu, 04 Oct 2012 16:18:38 -0600 |
User-agent: |
StGIT/0.14.3 |
Take what we've learned from pci-assign and apply it to vfio-pci.
On reset, disable previous interrupt config, perform a device
reset if available, re-enable INTx, and disable memory regions on
the device to prevent continuing DMA.
Signed-off-by: Alex Williamson <address@hidden>
---
hw/vfio_pci.c | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/hw/vfio_pci.c b/hw/vfio_pci.c
index a554e7c..b2383c4 100644
--- a/hw/vfio_pci.c
+++ b/hw/vfio_pci.c
@@ -1891,16 +1891,31 @@ static void vfio_pci_reset(DeviceState *dev)
{
PCIDevice *pdev = DO_UPCAST(PCIDevice, qdev, dev);
VFIODevice *vdev = DO_UPCAST(VFIODevice, pdev, pdev);
+ uint16_t cmd;
- if (!vdev->reset_works) {
- return;
- }
+ DPRINTF("%s(%04x:%02x:%02x.%x)\n", __func__, vdev->host.domain,
+ vdev->host.bus, vdev->host.slot, vdev->host.function);
+
+ vfio_disable_interrupts(vdev);
- if (ioctl(vdev->fd, VFIO_DEVICE_RESET)) {
- error_report("vfio: Error unable to reset physical device "
- "(%04x:%02x:%02x.%x): %m\n", vdev->host.domain,
- vdev->host.bus, vdev->host.slot, vdev->host.function);
+ /*
+ * Stop any ongoing DMA by disconecting I/O, MMIO, and bus master.
+ * Also put INTx Disable in known state.
+ */
+ cmd = vfio_pci_read_config(pdev, PCI_COMMAND, 2);
+ cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
+ PCI_COMMAND_INTX_DISABLE);
+ vfio_pci_write_config(pdev, PCI_COMMAND, cmd, 2);
+
+ if (vdev->reset_works) {
+ if (ioctl(vdev->fd, VFIO_DEVICE_RESET)) {
+ error_report("vfio: Error unable to reset physical device "
+ "(%04x:%02x:%02x.%x): %m\n", vdev->host.domain,
+ vdev->host.bus, vdev->host.slot, vdev->host.function);
+ }
}
+
+ vfio_enable_intx(vdev);
}
static Property vfio_pci_dev_properties[] = {
- [Qemu-devel] [PATCH 00/11] vfio-pci cleanup and fixes, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 01/11] vfio-pci: Update slow path INTx algorithm, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 02/11] vfio-pci: Re-order map/unmap, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 03/11] vfio-pci: Unmap and retry DMA mapping, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 05/11] vfio-pci: No spurious MSIs, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 06/11] vfio-pci: Roll the header into the .c file, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 07/11] vfio-pci: Don't peak at msi_supported, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 11/11] vfio-pci: Cleanup on INTx setup failure, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 08/11] vfio-pci: Use uintptr_t for void* cast, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 10/11] vfio-pci: Extend reset,
Alex Williamson <=
- [Qemu-devel] [PATCH 04/11] vfio-pci: Rework MSIX setup/teardown, Alex Williamson, 2012/10/04
- [Qemu-devel] [PATCH 09/11] vfio-pci: Remove setting of MSI qsize, Alex Williamson, 2012/10/04