Re: [PATCH v4] Shared memory uio_pci driver

2010-04-24 Thread Avi Kivity

On 04/23/2010 08:45 PM, Cam Macdonell wrote:

On Mon, Apr 12, 2010 at 2:57 PM, Avi Kivitya...@redhat.com  wrote:
   

There is work now to bring msi to the generic pci 2.3 driver, perhaps we can
use that instead.  From a quick look it looks fine.

 

I'd be interested to follow this development.  I can't find anything
on LKML, is it being discussed anywhere?

   


Look for patches from Tom Lyon (on kvm@ as well).

--
Do not meddle in the internals of kernels, for they are subtle and quick to 
panic.

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] Shared memory uio_pci driver

2010-04-23 Thread Cam Macdonell
On Mon, Apr 12, 2010 at 2:57 PM, Avi Kivity a...@redhat.com wrote:

 There is work now to bring msi to the generic pci 2.3 driver, perhaps we can
 use that instead.  From a quick look it looks fine.


I'd be interested to follow this development.  I can't find anything
on LKML, is it being discussed anywhere?

Thanks,
Cam
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] Shared memory uio_pci driver

2010-04-12 Thread Avi Kivity

On 04/08/2010 02:00 AM, Cam Macdonell wrote:

This patch adds a driver for my shared memory PCI device using the uio_pci
interface.  The driver has three memory regions.  The first memory region is for
device registers for sending interrupts. The second BAR is for receiving MSI-X
interrupts and the third memory region maps the shared memory.  The device only
exports the first and third memory regions to userspace.

This driver supports MSI-X and regular pin interrupts.  Currently, the number
of MSI vectors is set to 2 (one for new connections and the other for
interrupts) but it could easily be increased.  If MSI is not available, then
regular interrupts will be used.

This version added formatting and style corrections as well as better
error-checking and cleanup when errors occur.

   


There is work now to bring msi to the generic pci 2.3 driver, perhaps we 
can use that instead.  From a quick look it looks fine.


--
Do not meddle in the internals of kernels, for they are subtle and quick to 
panic.

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4] Shared memory uio_pci driver

2010-04-07 Thread Cam Macdonell
This patch adds a driver for my shared memory PCI device using the uio_pci
interface.  The driver has three memory regions.  The first memory region is for
device registers for sending interrupts. The second BAR is for receiving MSI-X
interrupts and the third memory region maps the shared memory.  The device only
exports the first and third memory regions to userspace.

This driver supports MSI-X and regular pin interrupts.  Currently, the number
of MSI vectors is set to 2 (one for new connections and the other for
interrupts) but it could easily be increased.  If MSI is not available, then
regular interrupts will be used.

This version added formatting and style corrections as well as better
error-checking and cleanup when errors occur.

---
 drivers/uio/Kconfig   |8 ++
 drivers/uio/Makefile  |1 +
 drivers/uio/uio_ivshmem.c |  252 +
 3 files changed, 261 insertions(+), 0 deletions(-)
 create mode 100644 drivers/uio/uio_ivshmem.c

diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
index 1da73ec..b92cded 100644
--- a/drivers/uio/Kconfig
+++ b/drivers/uio/Kconfig
@@ -74,6 +74,14 @@ config UIO_SERCOS3
 
  If you compile this as a module, it will be called uio_sercos3.
 
+config UIO_IVSHMEM
+   tristate KVM shared memory PCI driver
+   default n
+   help
+ Userspace I/O interface for the KVM shared memory device.  This
+ driver will make available two memory regions, the first is
+ registers and the second is a region for sharing between VMs.
+
 config UIO_PCI_GENERIC
tristate Generic driver for PCI 2.3 and PCI Express cards
depends on PCI
diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
index 18fd818..25c1ca5 100644
--- a/drivers/uio/Makefile
+++ b/drivers/uio/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_UIO_AEC)   += uio_aec.o
 obj-$(CONFIG_UIO_SERCOS3)  += uio_sercos3.o
 obj-$(CONFIG_UIO_PCI_GENERIC)  += uio_pci_generic.o
 obj-$(CONFIG_UIO_NETX) += uio_netx.o
+obj-$(CONFIG_UIO_IVSHMEM) += uio_ivshmem.o
diff --git a/drivers/uio/uio_ivshmem.c b/drivers/uio/uio_ivshmem.c
new file mode 100644
index 000..42ac9a7
--- /dev/null
+++ b/drivers/uio/uio_ivshmem.c
@@ -0,0 +1,252 @@
+/*
+ * UIO IVShmem Driver
+ *
+ * (C) 2009 Cam Macdonell
+ * based on Hilscher CIF card driver (C) 2007 Hans J. Koch h...@linutronix.de
+ *
+ * Licensed under GPL version 2 only.
+ *
+ */
+
+#include linux/device.h
+#include linux/module.h
+#include linux/pci.h
+#include linux/uio_driver.h
+
+#include asm/io.h
+
+#define IntrStatus 0x04
+#define IntrMask 0x00
+
+struct ivshmem_info {
+   struct uio_info *uio;
+   struct pci_dev *dev;
+   char (*msix_names)[256];
+   struct msix_entry *msix_entries;
+   int nvectors;
+};
+
+static irqreturn_t ivshmem_handler(int irq, struct uio_info *dev_info)
+{
+
+   void __iomem *plx_intscr = dev_info-mem[0].internal_addr
+   + IntrStatus;
+   u32 val;
+
+   val = readl(plx_intscr);
+   if (val == 0)
+   return IRQ_NONE;
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t ivshmem_msix_handler(int irq, void *opaque)
+{
+
+   struct uio_info * dev_info = (struct uio_info *) opaque;
+
+   /* we have to do this explicitly when using MSI-X */
+   uio_event_notify(dev_info);
+   return IRQ_HANDLED;
+}
+
+static void free_msix_vectors(struct ivshmem_info *ivs_info,
+   const int max_vector)
+{
+   int i;
+
+   for (i = 0; i  max_vector; i++)
+   free_irq(ivs_info-msix_entries[i].vector, ivs_info-uio);
+}
+
+static int request_msix_vectors(struct ivshmem_info *ivs_info, int nvectors)
+{
+   int i, err;
+   const char *name = ivshmem;
+
+   ivs_info-nvectors = nvectors;
+
+   ivs_info-msix_entries = kmalloc(nvectors * sizeof *
+   ivs_info-msix_entries,
+   GFP_KERNEL);
+   if (ivs_info-msix_entries == NULL)
+   return -ENOSPC;
+
+   ivs_info-msix_names = kmalloc(nvectors * sizeof *ivs_info-msix_names,
+   GFP_KERNEL);
+   if (ivs_info-msix_names == NULL) {
+   kfree(ivs_info-msix_entries);
+   return -ENOSPC;
+   }
+
+   for (i = 0; i  nvectors; ++i)
+   ivs_info-msix_entries[i].entry = i;
+
+   err = pci_enable_msix(ivs_info-dev, ivs_info-msix_entries,
+   ivs_info-nvectors);
+   if (err  0) {
+   ivs_info-nvectors = err; /* msi-x positive error code
+returns the number available*/
+   err = pci_enable_msix(ivs_info-dev, ivs_info-msix_entries,
+   ivs_info-nvectors);
+   if (err) {
+   printk(KERN_INFO no MSI (%d). Back to INTx.\n, err);
+