virtio: configuration change callback

Various drivers want to know when their configuration information
changes: the balloon driver is the immediate user, but the network
driver may one day have a "carrier" status as well.

This introduces that callback, and adds it to the virtio PCI
implementation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 drivers/virtio/virtio_pci.c |   10 ++++++++++
 include/linux/virtio.h      |    3 +++
 include/linux/virtio_pci.h  |    3 +++
 3 files changed, 16 insertions(+)

diff -r 16ddf4f6bbec drivers/virtio/virtio_pci.c
--- a/drivers/virtio/virtio_pci.c	Wed Jan 09 22:57:39 2008 +1100
+++ b/drivers/virtio/virtio_pci.c	Wed Jan 09 22:59:11 2008 +1100
@@ -184,6 +184,16 @@ static irqreturn_t vp_interrupt(int irq,
 	/* It's definitely not us if the ISR was not high */
 	if (!isr)
 		return IRQ_NONE;
+
+	/* Configuration change?  Tell driver if it wants to know. */
+	if (isr & VIRTIO_PCI_ISR_CONFIG) {
+		struct virtio_driver *drv;
+		drv = container_of(vp_dev->vdev.dev.driver,
+				   struct virtio_driver, driver);
+
+		if (drv->config_changed)
+			drv->config_changed(&vp_dev->vdev);
+	}
 
 	spin_lock(&vp_dev->lock);
 	list_for_each_entry(info, &vp_dev->virtqueues, node) {
diff -r 16ddf4f6bbec include/linux/virtio.h
--- a/include/linux/virtio.h	Wed Jan 09 22:57:39 2008 +1100
+++ b/include/linux/virtio.h	Wed Jan 09 22:59:11 2008 +1100
@@ -98,12 +98,15 @@ void unregister_virtio_device(struct vir
  * @probe: the function to call when a device is found.  Returns a token for
  *    remove, or PTR_ERR().
  * @remove: the function when a device is removed.
+ * @config_changed: optional function to call when the device configuration
+ *    changes; may be called in interrupt context.
  */
 struct virtio_driver {
 	struct device_driver driver;
 	const struct virtio_device_id *id_table;
 	int (*probe)(struct virtio_device *dev);
 	void (*remove)(struct virtio_device *dev);
+	void (*config_changed)(struct virtio_device *dev);
 };
 
 int register_virtio_driver(struct virtio_driver *drv);
diff -r 16ddf4f6bbec include/linux/virtio_pci.h
--- a/include/linux/virtio_pci.h	Wed Jan 09 22:57:39 2008 +1100
+++ b/include/linux/virtio_pci.h	Wed Jan 09 22:59:11 2008 +1100
@@ -45,6 +45,9 @@
  * a read-and-acknowledge. */
 #define VIRTIO_PCI_ISR			19
 
+/* The bit of the ISR which indicates a device configuration change. */
+#define VIRTIO_PCI_ISR_CONFIG		0x2
+
 /* The remaining space is defined by each driver as the per-driver
  * configuration space */
 #define VIRTIO_PCI_CONFIG		20
