public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Extend virtio config routines to support ballooning
@ 2008-08-28 22:54 Anthony Liguori
  2008-08-28 22:54 ` [PATCH 2/3] add ballooning infrastructure to QEMU Anthony Liguori
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Anthony Liguori @ 2008-08-28 22:54 UTC (permalink / raw)
  To: kvm; +Cc: Marcelo Tosatti, Avi Kivity, Anthony Liguori

This patch updates the virtio device methods to provide hooks for setting and
getting the config.  This is needed for ballooning since the balloon driver
uses config changes to signal changes in the balloon amount.  We also add a
method to signal that we have changed the config.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

diff --git a/qemu/hw/virtio-blk.c b/qemu/hw/virtio-blk.c
index 88dc086..da9e795 100644
--- a/qemu/hw/virtio-blk.c
+++ b/qemu/hw/virtio-blk.c
@@ -286,7 +286,7 @@ void *virtio_blk_init(PCIBus *bus, uint16_t vendor, uint16_t device,
     if (!s)
 	return NULL;
 
-    s->vdev.update_config = virtio_blk_update_config;
+    s->vdev.get_config = virtio_blk_update_config;
     s->vdev.get_features = virtio_blk_get_features;
     s->vdev.reset = virtio_blk_reset;
     s->bs = bs;
diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index 409960f..bc2ede6 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
@@ -332,7 +332,7 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
     if (!n)
 	return NULL;
 
-    n->vdev.update_config = virtio_net_update_config;
+    n->vdev.get_config = virtio_net_update_config;
     n->vdev.get_features = virtio_net_get_features;
     n->vdev.set_features = virtio_net_set_features;
     n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx);
diff --git a/qemu/hw/virtio.c b/qemu/hw/virtio.c
index e035e4e..e675f43 100644
--- a/qemu/hw/virtio.c
+++ b/qemu/hw/virtio.c
@@ -313,6 +313,8 @@ static uint32_t virtio_config_readb(void *opaque, uint32_t addr)
     VirtIODevice *vdev = opaque;
     uint8_t val;
 
+    vdev->get_config(vdev, vdev->config);
+
     addr -= vdev->addr + VIRTIO_PCI_CONFIG;
     if (addr > (vdev->config_len - sizeof(val)))
 	return (uint32_t)-1;
@@ -326,6 +328,8 @@ static uint32_t virtio_config_readw(void *opaque, uint32_t addr)
     VirtIODevice *vdev = opaque;
     uint16_t val;
 
+    vdev->get_config(vdev, vdev->config);
+
     addr -= vdev->addr + VIRTIO_PCI_CONFIG;
     if (addr > (vdev->config_len - sizeof(val)))
 	return (uint32_t)-1;
@@ -339,6 +343,8 @@ static uint32_t virtio_config_readl(void *opaque, uint32_t addr)
     VirtIODevice *vdev = opaque;
     uint32_t val;
 
+    vdev->get_config(vdev, vdev->config);
+
     addr -= vdev->addr + VIRTIO_PCI_CONFIG;
     if (addr > (vdev->config_len - sizeof(val)))
 	return (uint32_t)-1;
@@ -357,6 +363,9 @@ static void virtio_config_writeb(void *opaque, uint32_t addr, uint32_t data)
 	return;
 
     memcpy(vdev->config + addr, &val, sizeof(val));
+
+    if (vdev->set_config)
+        vdev->set_config(vdev, vdev->config);
 }
 
 static void virtio_config_writew(void *opaque, uint32_t addr, uint32_t data)
@@ -369,6 +378,9 @@ static void virtio_config_writew(void *opaque, uint32_t addr, uint32_t data)
 	return;
 
     memcpy(vdev->config + addr, &val, sizeof(val));
+
+    if (vdev->set_config)
+        vdev->set_config(vdev, vdev->config);
 }
 
 static void virtio_config_writel(void *opaque, uint32_t addr, uint32_t data)
@@ -381,6 +393,9 @@ static void virtio_config_writel(void *opaque, uint32_t addr, uint32_t data)
 	return;
 
     memcpy(vdev->config + addr, &val, sizeof(val));
+
+    if (vdev->set_config)
+        vdev->set_config(vdev, vdev->config);
 }
 
 static void virtio_map(PCIDevice *pci_dev, int region_num,
@@ -409,7 +424,7 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 	register_ioport_read(addr + 20, vdev->config_len, 4,
 			     virtio_config_readl, vdev);
 
-	vdev->update_config(vdev, vdev->config);
+	vdev->get_config(vdev, vdev->config);
     }
 }
 
@@ -439,7 +454,13 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq)
 	(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT))
 	return;
 
-    vdev->isr = 1;
+    vdev->isr |= 0x01;
+    virtio_update_irq(vdev);
+}
+
+void virtio_notify_config(VirtIODevice *vdev)
+{
+    vdev->isr |= 0x03;
     virtio_update_irq(vdev);
 }
 
diff --git a/qemu/hw/virtio.h b/qemu/hw/virtio.h
index 1adaed3..0dcedbf 100644
--- a/qemu/hw/virtio.h
+++ b/qemu/hw/virtio.h
@@ -120,7 +120,8 @@ struct VirtIODevice
     void *config;
     uint32_t (*get_features)(VirtIODevice *vdev);
     void (*set_features)(VirtIODevice *vdev, uint32_t val);
-    void (*update_config)(VirtIODevice *vdev, uint8_t *config);
+    void (*get_config)(VirtIODevice *vdev, uint8_t *config);
+    void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
     void (*reset)(VirtIODevice *vdev);
     VirtQueue vq[VIRTIO_PCI_QUEUE_MAX];
 };
@@ -147,4 +148,6 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f);
 
 void virtio_load(VirtIODevice *vdev, QEMUFile *f);
 
+void virtio_notify_config(VirtIODevice *vdev);
+
 #endif

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-08-29 11:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-28 22:54 [PATCH 1/3] Extend virtio config routines to support ballooning Anthony Liguori
2008-08-28 22:54 ` [PATCH 2/3] add ballooning infrastructure to QEMU Anthony Liguori
2008-08-28 22:54 ` [PATCH 3/3] Add virtio balloon driver (v2) Anthony Liguori
2008-08-28 22:56   ` Anthony Liguori
2008-08-29 11:21     ` Avi Kivity
2008-08-29 11:31 ` [PATCH 1/3] Extend virtio config routines to support ballooning Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox