1 /* uio_pci_generic - generic UIO driver for PCI 2.3 devices
3 * Copyright (C) 2009 Red Hat, Inc.
4 * Author: Michael S. Tsirkin <mst@redhat.com>
6 * This work is licensed under the terms of the GNU GPL, version 2.
8 * Since the driver does not declare any device ids, you must allocate
9 * id and bind the device to the driver yourself. For example:
11 * # echo "8086 10f5" > /sys/bus/pci/drivers/uio_pci_generic/new_id
12 * # echo -n 0000:00:19.0 > /sys/bus/pci/drivers/e1000e/unbind
13 * # echo -n 0000:00:19.0 > /sys/bus/pci/drivers/uio_pci_generic/bind
14 * # ls -l /sys/bus/pci/devices/0000:00:19.0/driver
15 * .../0000:00:19.0/driver -> ../../../bus/pci/drivers/uio_pci_generic
17 * Driver won't bind to devices which do not support the Interrupt Disable Bit
18 * in the command register. All devices compliant to PCI 2.3 (circa 2002) and
19 * all compliant PCI Express devices should support this bit.
22 #include <linux/device.h>
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/slab.h>
26 #include <linux/uio_driver.h>
28 #define DRIVER_VERSION "0.01.0"
29 #define DRIVER_AUTHOR "Michael S. Tsirkin <mst@redhat.com>"
30 #define DRIVER_DESC "Generic UIO driver for PCI 2.3 devices"
32 struct uio_pci_generic_dev
{
37 static inline struct uio_pci_generic_dev
*
38 to_uio_pci_generic_dev(struct uio_info
*info
)
40 return container_of(info
, struct uio_pci_generic_dev
, info
);
43 /* Interrupt handler. Read/modify/write the command register to disable
45 static irqreturn_t
irqhandler(int irq
, struct uio_info
*info
)
47 struct uio_pci_generic_dev
*gdev
= to_uio_pci_generic_dev(info
);
49 if (!pci_check_and_mask_intx(gdev
->pdev
))
52 /* UIO core will signal the user process. */
56 static int probe(struct pci_dev
*pdev
,
57 const struct pci_device_id
*id
)
59 struct uio_pci_generic_dev
*gdev
;
62 err
= pci_enable_device(pdev
);
64 dev_err(&pdev
->dev
, "%s: pci_enable_device failed: %d\n",
69 if (pdev
->irq
&& !pci_intx_mask_supported(pdev
)) {
74 gdev
= kzalloc(sizeof(struct uio_pci_generic_dev
), GFP_KERNEL
);
80 gdev
->info
.name
= "uio_pci_generic";
81 gdev
->info
.version
= DRIVER_VERSION
;
84 gdev
->info
.irq
= pdev
->irq
;
85 gdev
->info
.irq_flags
= IRQF_SHARED
;
86 gdev
->info
.handler
= irqhandler
;
88 dev_warn(&pdev
->dev
, "No IRQ assigned to device: "
89 "no support for interrupts?\n");
92 err
= uio_register_device(&pdev
->dev
, &gdev
->info
);
95 pci_set_drvdata(pdev
, gdev
);
102 pci_disable_device(pdev
);
106 static void remove(struct pci_dev
*pdev
)
108 struct uio_pci_generic_dev
*gdev
= pci_get_drvdata(pdev
);
110 uio_unregister_device(&gdev
->info
);
111 pci_disable_device(pdev
);
115 static struct pci_driver uio_pci_driver
= {
116 .name
= "uio_pci_generic",
117 .id_table
= NULL
, /* only dynamic id's */
122 module_pci_driver(uio_pci_driver
);
123 MODULE_VERSION(DRIVER_VERSION
);
124 MODULE_LICENSE("GPL v2");
125 MODULE_AUTHOR(DRIVER_AUTHOR
);
126 MODULE_DESCRIPTION(DRIVER_DESC
);