Writing userspace IO device driverUIO DriversLinux provides a standard called UIO (User I/O) framework for developing user-space-based device drivers. The UIO framework defines a small kernel-space component that performs two key tasks:
a. Indicate device memory regions to user space.
b. Register for device interrupts and provide interrupt indication to user space.
The kernel-space UIO component then exposes the device via a set of sysfs entries like /dev/uioXX. The user-space component searches for these entries, reads the device address ranges and maps them to user space memory.
The user-space component can perform all device-management tasks including I/O from the device. For interrupts however, it needs to perform a blocking read() on the device entry, which results in the kernel component putting the user-space application to sleep and waking it up once an interrupt is received.
If we use UIO for our card's driver, here's what we get:
- only one small kernel module to write and maintain.
- develop the main part of our driver in user space, with all the tools and libraries we're used to.
- bugs in our driver won't crash the kernel.
- updates of our driver can take place without recompiling the kernel.
Creating an UIO driver
In this section we will create an UIO driver using the UIO framework. We will modify the program used in part41 and call it: LED_DimmerUIO.c.
1. We start by generating a new application called LED_DimmerUIO.
-> cd ..../PetaZed
-> petaliniux-create -t apps --name LED_DimmerUIO
2. Replace the template file LED_DimmerUIO.c with the file downloaded from this page.
Configure user application
3. Run petalinux-config -c rootfs and select the LED_DimmerUIO application.
-> petalinux-config -c rootfs
4. Save and exit
Configure the Linux kernel
5. Run petalinux-config -c to start kernel configuration
-> petalinux-config -c kernel
6. Scroll down and select Device Drivers.
7. Scroll down and select Userspace I/O drivers.
8. Mark with an "M" for module.
9. Save and exit.
Edit the system.dts file
We find the device tree definition file system.dts file here:
10. Open the system.dts file in an editor and change the line after #gpio-cells = <2> to compatible = "generic-uio";
Rebuild the Linux kernel
The first time after we added the UIO module and edited the DTS file we have to rebuild the kernel from scratch.
-> petalinux-build -x mrproper
When the build has finished we copy the image.ub file to the SD card and we are ready to boot PetaLinux.
Insert the SD card, power on the board and connect a terminal. Here are the commands executed to load the UIO module:
Top Previous Next