Chapter 5. Generic PCI UIO driver

Table of Contents

Making the driver recognize the device
Things to know about uio_pci_generic
Writing userspace driver using uio_pci_generic
Example code using uio_pci_generic

The generic driver is a kernel module named uio_pci_generic. It can work with any device compliant to PCI 2.3 (circa 2002) and any compliant PCI Express device. Using this, you only need to write the userspace driver, removing the need to write a hardware-specific kernel module.

Making the driver recognize the device

Since the driver does not declare any device ids, it will not get loaded automatically and will not automatically bind to any devices, you must load it and allocate id to the driver yourself. For example:

 modprobe uio_pci_generic
 echo "8086 10f5" > /sys/bus/pci/drivers/uio_pci_generic/new_id
	

If there already is a hardware specific kernel driver for your device, the generic driver still won't bind to it, in this case if you want to use the generic driver (why would you?) you'll have to manually unbind the hardware specific driver and bind the generic driver, like this:

    echo -n 0000:00:19.0 > /sys/bus/pci/drivers/e1000e/unbind
    echo -n 0000:00:19.0 > /sys/bus/pci/drivers/uio_pci_generic/bind
	

You can verify that the device has been bound to the driver by looking for it in sysfs, for example like the following:

    ls -l /sys/bus/pci/devices/0000:00:19.0/driver
	

Which if successful should print

  .../0000:00:19.0/driver -> ../../../bus/pci/drivers/uio_pci_generic
	

Note that the generic driver will not bind to old PCI 2.2 devices. If binding the device failed, run the following command:

  dmesg
	

and look in the output for failure reasons