SlideShare a Scribd company logo
1 of 25
Download to read offline
Quick and Easy Device Drivers for Embedded
Linux Using UIO
Chris Simmonds
Embedded World 2017
Quick and Easy Device Drivers for Embedded Linux Using UIO 1 Copyright © 2011-2017, 2net Ltd
License
These slides are available under a Creative Commons Attribution-ShareAlike 3.0 license. You can read the full
text of the license here
http://creativecommons.org/licenses/by-sa/3.0/legalcode
You are free to
• copy, distribute, display, and perform the work
• make derivative works
• make commercial use of the work
Under the following conditions
• Attribution: you must give the original author credit
• Share Alike: if you alter, transform, or build upon this work, you may distribute the resulting work only
under a license identical to this one (i.e. include this page exactly as it is)
• For any reuse or distribution, you must make clear to others the license terms of this work
Quick and Easy Device Drivers for Embedded Linux Using UIO 2 Copyright © 2011-2017, 2net Ltd
About Chris Simmonds
• Consultant and trainer
• Author of Mastering Embedded Linux Programming
• Working with embedded Linux since 1999
• Android since 2009
• Speaker at many conferences and workshops
"Looking after the Inner Penguin" blog at http://2net.co.uk/
https://uk.linkedin.com/in/chrisdsimmonds/
https://google.com/+chrissimmonds
Quick and Easy Device Drivers for Embedded Linux Using UIO 3 Copyright © 2011-2017, 2net Ltd
Overview
• Conventional Linux drivers
• The UIO framework
• An example UIO driver
• Scheduling and interrupt latencies
Quick and Easy Device Drivers for Embedded Linux Using UIO 4 Copyright © 2011-2017, 2net Ltd
Conventional device driver model
User
space
System call handler
Generic services
Device drivers
Hardware
Application
C library
interrupts
Kernel
space
Quick and Easy Device Drivers for Embedded Linux Using UIO 5 Copyright © 2011-2017, 2net Ltd
Userspace drivers
• Writing kernel device drivers can be difficult
• Luckily, there are generic drivers that that allow you to write most of the
code in userspace
• For example
• USB (via libusb)
• GPIO
• I2C
Reference
www.slideshare.net/chrissimmonds/userspace-drivers2016
Quick and Easy Device Drivers for Embedded Linux Using UIO 6 Copyright © 2011-2017, 2net Ltd
UIO drivers
• Userspace I/O (UIO) is a framework for userspace drivers that do not
fit into the standard patterns
• Typical use-cases include interfaces to FPGAs and custom PCI
functions
• UIO may be appropriate for your hardware interface if:
• it has registers and/or buffers that are memory mapped
• it generates interrupts
Quick and Easy Device Drivers for Embedded Linux Using UIO 7 Copyright © 2011-2017, 2net Ltd
The UIO way
IRQ
mmap
interrupt
handler
Register
bank
/dev/uio0
mmap()
read()
Hardware Kernel Application
Register
bank
Quick and Easy Device Drivers for Embedded Linux Using UIO 8 Copyright © 2011-2017, 2net Ltd
Kernel and userspace components
• UIO drivers are in two parts
• A simple kernel stub driver, which creates device node /dev/uioX
• A user-space driver that implements the majority of the code
• Device node /dev/uioX links the two together
Quick and Easy Device Drivers for Embedded Linux Using UIO 9 Copyright © 2011-2017, 2net Ltd
The UIO kernel driver
• Kernel driver needs to
• point to one (or more) memory regions
• assign the interrupt number (IRQ)
• implement interrupt handler
• register as a UIO driver
Quick and Easy Device Drivers for Embedded Linux Using UIO 10 Copyright © 2011-2017, 2net Ltd
Example driver
This device has 8 KiB (0x2000) of memory-mapped registers at 0x4804C000 and is
attached to hardware interrupt IRQ 85
static int demo_probe(struct platform_device *pdev)
{
info.name = "demo";
info.version = "1.0";
info.mem[0].addr = 0x4804C000;
info.mem[0].size = 0x2000;
info.mem[0].memtype = UIO_MEM_PHYS;
info.irq = 85;
info.irq_flags = 0;
info.handler = demo_handler;
return uio_register_device(&pdev->dev, &info);
}
Quick and Easy Device Drivers for Embedded Linux Using UIO 11 Copyright © 2011-2017, 2net Ltd
Kernel interrupt handler
• Usually very simple
• For example, disable interrupt source, which will be enabled again in
userspace
drivers/uio/uio_aec.c:
static irqreturn_t aectc_irq(int irq, struct uio_info *dev_info)
{
void __iomem *int_flag = dev_info->priv + INTA_DRVR_ADDR;
unsigned char status = ioread8(int_flag);
if ((status & INTA_ENABLED_FLAG) && (status & INTA_FLAG)) {
/* application writes 0x00 to 0x2F to get next interrupt */
status = ioread8(dev_info->priv + MAILBOX);
return IRQ_HANDLED;
}
return IRQ_NONE;
}
Quick and Easy Device Drivers for Embedded Linux Using UIO 12 Copyright © 2011-2017, 2net Ltd
The user-space driver
• Each UIO driver represented by device node /dev/uioX
• X = 0 for first, 1 for second, etc.
• User space application uses it to mmap the memory and receive
notification of interrupts
Quick and Easy Device Drivers for Embedded Linux Using UIO 13 Copyright © 2011-2017, 2net Ltd
Mapping memory
• mmap(2) maps memory associated with a file descriptor
• Example: map 0x2000 bytes from file /dev/uio0:
int main(int argc, char **argv)
{
int f;
char *ptr;
f = open("/dev/uio0", O_RDWR);
if (f == -1) {
return 1;
}
ptr = mmap(0, 0x2000, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0);
if (ptr == MAP_FAILED) {
return 1;
}
ptr points to the base of the register bank. UIO framework maps the memory without
processor cache, so writes and reads force memory cycles on the system bus
Quick and Easy Device Drivers for Embedded Linux Using UIO 14 Copyright © 2011-2017, 2net Ltd
Handling interrupts
• Wait for interrupt by reading from /dev/uioX
• The read() blocks until the next interrupt arrives
• Data returned by read contains the count of interrupts since the UIO
kernel driver was started
• Can detect missed interrupts by comparing with previous interrupt count
Quick and Easy Device Drivers for Embedded Linux Using UIO 15 Copyright © 2011-2017, 2net Ltd
Interrupt example 1
• Simple example, using blocking read call
static void wait_for_int(int f)
{
int n;
unsigned int irc_count;
printf("Waitingn");
n = read(f, &irc_count, sizeof(irc_count));
if (n == -1) {
printf("read errorn");
return;
}
printf("irc_count = %dn", irc_count);
}
Quick and Easy Device Drivers for Embedded Linux Using UIO 16 Copyright © 2011-2017, 2net Ltd
Blocking behaviour
• Blocking in read() means that the application cannot do any work
between interrupts
• Solution 1: use poll() or select() to wait with a timeout
• possibly on several data sources at once
• Solution 2: use a thread to wait
Quick and Easy Device Drivers for Embedded Linux Using UIO 17 Copyright © 2011-2017, 2net Ltd
Interrupt example 2
• Using poll(2)
static void wait_for_int_poll(int f)
{
struct pollfd poll_fds [1];
int ret;
unsigned int irc_count;
printf("Waitingn");
poll_fds[0].fd = f;
poll_fds[0].events = POLLIN;
ret = poll(poll_fds, 1, 100); /* timeout = 100 ms */
if (ret > 0) {
if (poll_fds[0].revents && POLLIN) {
read(f, &irc_count, sizeof(irc_count));
printf("irc_count = %dn", irc_count);
}
}
}
Quick and Easy Device Drivers for Embedded Linux Using UIO 18 Copyright © 2011-2017, 2net Ltd
Mapping more than one memory area
• Example: a device with two address ranges:
info.name = "demo";
info.version = "1.0";
info.mem[0].addr = 0x4804C000;
info.mem[0].size = 0x2000;
info.mem[0].memtype = UIO_MEM_PHYS;
info.mem[1].addr = 0x48060000;
info.mem[1].size = 0x4000;
info.mem[1].memtype = UIO_MEM_PHYS;
return uio_register_device(&pdev->dev, &info);
UIO allows up to 5 address ranges
Quick and Easy Device Drivers for Embedded Linux Using UIO 19 Copyright © 2011-2017, 2net Ltd
Mapping address ranges
• The range to map is specified as mmap offset (last parameter)
• Because behind the scenes mmap works in pages instead of bytes,
the index has to be given in pages
• To mmap address range in info.mem[1], use offset = 1 page:
ptr2 = mmap(0, 0x4000, PROT_READ | PROT_WRITE,
MAP_SHARED, f, 1 * getpagesize());
Quick and Easy Device Drivers for Embedded Linux Using UIO 20 Copyright © 2011-2017, 2net Ltd
Scheduling
• Where interrupts are concerned, the process or thread should be
real-time
• scheduling policy = SCHED_FIFO
• Memory locked using mlockall
struct sched_param param;
mlockall (MCL_CURRENT | MCL_FUTURE);
param.sched_priority = 10;
if (sched_setscheduler (getpid (), SCHED_FIFO, &param) != 0)
printf ("Failed to change policy and priorityn");
Quick and Easy Device Drivers for Embedded Linux Using UIO 21 Copyright © 2011-2017, 2net Ltd
Interrupt latency
• Even a real-time thread may have high jitter on interrupt latency if the
kernel is not preemptive
• Configure kernel with CONFIG_PREEMPT
• Or, implement Real-time kernel patche and configure with
CONFIG_PREEMPT_RT
• Measures latencies will vary from platform to platform, but should be
less than a few hundred microseconds
Quick and Easy Device Drivers for Embedded Linux Using UIO 22 Copyright © 2011-2017, 2net Ltd
Further reading
• Kernel source documentation: Documentation/DocBook/uio-howto
• on-line at https://www.osadl.org/fileadmin/dam/interface/
docbook/howtos/uio-howto.pdf
• LWN article: https://lwn.net/Articles/232575/
Quick and Easy Device Drivers for Embedded Linux Using UIO 23 Copyright © 2011-2017, 2net Ltd
Summary
• UIO provides a convenient way to implement drivers for FPGA
interfaces and hardware for which there is no existing Linux driver
• Applicable to hardware that provides mappable memory and
generates interrupts
Quick and Easy Device Drivers for Embedded Linux Using UIO 24 Copyright © 2011-2017, 2net Ltd
• Any questions?
This and other topics associated with building robust embedded systems are covered in
my training courses http://www.2net.co.uk/training.html
Quick and Easy Device Drivers for Embedded Linux Using UIO 25 Copyright © 2011-2017, 2net Ltd

More Related Content

What's hot

Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmicsDenys Haryachyy
 
Poll mode driver integration into dpdk
Poll mode driver integration into dpdkPoll mode driver integration into dpdk
Poll mode driver integration into dpdkVipin Varghese
 
How Linux Processes Your Network Packet - Elazar Leibovich
How Linux Processes Your Network Packet - Elazar LeibovichHow Linux Processes Your Network Packet - Elazar Leibovich
How Linux Processes Your Network Packet - Elazar LeibovichDevOpsDays Tel Aviv
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machineAlexei Starovoitov
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network InterfacesKernel TLV
 
What are latest new features that DPDK brings into 2018?
What are latest new features that DPDK brings into 2018?What are latest new features that DPDK brings into 2018?
What are latest new features that DPDK brings into 2018?Michelle Holley
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionGene Chang
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDKKernel TLV
 
Berkeley Packet Filters
Berkeley Packet FiltersBerkeley Packet Filters
Berkeley Packet FiltersKernel TLV
 
X / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural OverviewX / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural OverviewMoriyoshi Koizumi
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptablesKernel TLV
 

What's hot (20)

Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmics
 
Poll mode driver integration into dpdk
Poll mode driver integration into dpdkPoll mode driver integration into dpdk
Poll mode driver integration into dpdk
 
DPDK KNI interface
DPDK KNI interfaceDPDK KNI interface
DPDK KNI interface
 
How Linux Processes Your Network Packet - Elazar Leibovich
How Linux Processes Your Network Packet - Elazar LeibovichHow Linux Processes Your Network Packet - Elazar Leibovich
How Linux Processes Your Network Packet - Elazar Leibovich
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
 
Linux Internals - Part III
Linux Internals - Part IIILinux Internals - Part III
Linux Internals - Part III
 
Dpdk performance
Dpdk performanceDpdk performance
Dpdk performance
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
BeagleBone Black Booting Process
BeagleBone Black Booting ProcessBeagleBone Black Booting Process
BeagleBone Black Booting Process
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network Interfaces
 
What are latest new features that DPDK brings into 2018?
What are latest new features that DPDK brings into 2018?What are latest new features that DPDK brings into 2018?
What are latest new features that DPDK brings into 2018?
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
 
Qemu Pcie
Qemu PcieQemu Pcie
Qemu Pcie
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
 
Berkeley Packet Filters
Berkeley Packet FiltersBerkeley Packet Filters
Berkeley Packet Filters
 
X / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural OverviewX / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural Overview
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 

Viewers also liked

Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Chris Simmonds
 
Software update for IoT: the current state of play
Software update for IoT: the current state of playSoftware update for IoT: the current state of play
Software update for IoT: the current state of playChris Simmonds
 
Read-only rootfs: theory and practice
Read-only rootfs: theory and practiceRead-only rootfs: theory and practice
Read-only rootfs: theory and practiceChris Simmonds
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016Chris Simmonds
 
Linux field-update-2015
Linux field-update-2015Linux field-update-2015
Linux field-update-2015Chris Simmonds
 
10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easierChris Simmonds
 
A timeline for embedded Linux
A timeline for embedded LinuxA timeline for embedded Linux
A timeline for embedded LinuxChris Simmonds
 
The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)Chris Simmonds
 
Android beyond the smartphone
Android beyond the smartphoneAndroid beyond the smartphone
Android beyond the smartphoneChris Simmonds
 
CTM360 adv-0317-01 dns messenger
CTM360 adv-0317-01 dns messengerCTM360 adv-0317-01 dns messenger
CTM360 adv-0317-01 dns messengerMigin Vincent
 
законы и рекомендации в области образования детей с ки
законы и рекомендации в области образования детей с кизаконы и рекомендации в области образования детей с ки
законы и рекомендации в области образования детей с киMonika Lehnhardt PhD
 
Pathophysiology of food intake
Pathophysiology of food intakePathophysiology of food intake
Pathophysiology of food intakeP. GAURAV KUMAR
 

Viewers also liked (20)

Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017
 
Software update for IoT: the current state of play
Software update for IoT: the current state of playSoftware update for IoT: the current state of play
Software update for IoT: the current state of play
 
Read-only rootfs: theory and practice
Read-only rootfs: theory and practiceRead-only rootfs: theory and practice
Read-only rootfs: theory and practice
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016
 
Linux field-update-2015
Linux field-update-2015Linux field-update-2015
Linux field-update-2015
 
10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier
 
A timeline for embedded Linux
A timeline for embedded LinuxA timeline for embedded Linux
A timeline for embedded Linux
 
The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)
 
Android beyond the smartphone
Android beyond the smartphoneAndroid beyond the smartphone
Android beyond the smartphone
 
Políticos [Maçonaria]
Políticos [Maçonaria]Políticos [Maçonaria]
Políticos [Maçonaria]
 
Perfect places
Perfect placesPerfect places
Perfect places
 
CTM360 adv-0317-01 dns messenger
CTM360 adv-0317-01 dns messengerCTM360 adv-0317-01 dns messenger
CTM360 adv-0317-01 dns messenger
 
Ti 13 quidam
Ti 13 quidamTi 13 quidam
Ti 13 quidam
 
Nowhere is perfect
Nowhere is perfectNowhere is perfect
Nowhere is perfect
 
Mejores del futbol (2)
Mejores del futbol (2)Mejores del futbol (2)
Mejores del futbol (2)
 
Research workshop
Research workshopResearch workshop
Research workshop
 
законы и рекомендации в области образования детей с ки
законы и рекомендации в области образования детей с кизаконы и рекомендации в области образования детей с ки
законы и рекомендации в области образования детей с ки
 
Pathophysiology of food intake
Pathophysiology of food intakePathophysiology of food intake
Pathophysiology of food intake
 
Repaso metodologías Erasmus +
Repaso metodologías Erasmus +Repaso metodologías Erasmus +
Repaso metodologías Erasmus +
 
Chatbots for HR
Chatbots for HRChatbots for HR
Chatbots for HR
 

Similar to Quick and Easy Device Drivers for Embedded Linux Using UIO

Fn project quick installation guide
Fn project quick installation guideFn project quick installation guide
Fn project quick installation guideJohan Louwers
 
Reducing the boot time of Linux devices
Reducing the boot time of Linux devicesReducing the boot time of Linux devices
Reducing the boot time of Linux devicesChris Simmonds
 
OpenStack Integration with OpenContrail and OpenDaylight
OpenStack Integration with OpenContrail and OpenDaylightOpenStack Integration with OpenContrail and OpenDaylight
OpenStack Integration with OpenContrail and OpenDaylightSyed Moneeb
 
LCNA14: Why Use Xen for Large Scale Enterprise Deployments? - Konrad Rzeszute...
LCNA14: Why Use Xen for Large Scale Enterprise Deployments? - Konrad Rzeszute...LCNA14: Why Use Xen for Large Scale Enterprise Deployments? - Konrad Rzeszute...
LCNA14: Why Use Xen for Large Scale Enterprise Deployments? - Konrad Rzeszute...The Linux Foundation
 
Why kernelspace sucks?
Why kernelspace sucks?Why kernelspace sucks?
Why kernelspace sucks?OpenFest team
 
Improving User Experience with Ubiquitous QuickBoot
 Improving User Experience with Ubiquitous QuickBoot Improving User Experience with Ubiquitous QuickBoot
Improving User Experience with Ubiquitous QuickBootICS
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Opersys inc.
 
Srikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latestSrikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latestSrikanth Pilli
 
TEE - kernel support is now upstream. What this means for open source security
TEE - kernel support is now upstream. What this means for open source securityTEE - kernel support is now upstream. What this means for open source security
TEE - kernel support is now upstream. What this means for open source securityLinaro
 
Using VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear ContainersUsing VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear ContainersMichelle Holley
 
Devicemgmt
DevicemgmtDevicemgmt
Devicemgmtxyxz
 
What’s New in UniVerse 11.2
What’s New in UniVerse 11.2What’s New in UniVerse 11.2
What’s New in UniVerse 11.2Rocket Software
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemdAlison Chaiken
 
Cooking security sans@night
Cooking security sans@nightCooking security sans@night
Cooking security sans@nightjtimberman
 
PT101-WEEK-8-9-Importance-functions-of-Input-output-in-OS-1.pptx
PT101-WEEK-8-9-Importance-functions-of-Input-output-in-OS-1.pptxPT101-WEEK-8-9-Importance-functions-of-Input-output-in-OS-1.pptx
PT101-WEEK-8-9-Importance-functions-of-Input-output-in-OS-1.pptxAngelikaSolomon
 
Using Embedded Linux for Infrastructure Systems
Using Embedded Linux for Infrastructure SystemsUsing Embedded Linux for Infrastructure Systems
Using Embedded Linux for Infrastructure SystemsYoshitake Kobayashi
 

Similar to Quick and Easy Device Drivers for Embedded Linux Using UIO (20)

Fn project quick installation guide
Fn project quick installation guideFn project quick installation guide
Fn project quick installation guide
 
Reducing the boot time of Linux devices
Reducing the boot time of Linux devicesReducing the boot time of Linux devices
Reducing the boot time of Linux devices
 
OpenStack Integration with OpenContrail and OpenDaylight
OpenStack Integration with OpenContrail and OpenDaylightOpenStack Integration with OpenContrail and OpenDaylight
OpenStack Integration with OpenContrail and OpenDaylight
 
LCNA14: Why Use Xen for Large Scale Enterprise Deployments? - Konrad Rzeszute...
LCNA14: Why Use Xen for Large Scale Enterprise Deployments? - Konrad Rzeszute...LCNA14: Why Use Xen for Large Scale Enterprise Deployments? - Konrad Rzeszute...
LCNA14: Why Use Xen for Large Scale Enterprise Deployments? - Konrad Rzeszute...
 
Why kernelspace sucks?
Why kernelspace sucks?Why kernelspace sucks?
Why kernelspace sucks?
 
Improving User Experience with Ubiquitous QuickBoot
 Improving User Experience with Ubiquitous QuickBoot Improving User Experience with Ubiquitous QuickBoot
Improving User Experience with Ubiquitous QuickBoot
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
 
Srikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latestSrikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latest
 
TEE - kernel support is now upstream. What this means for open source security
TEE - kernel support is now upstream. What this means for open source securityTEE - kernel support is now upstream. What this means for open source security
TEE - kernel support is now upstream. What this means for open source security
 
Using VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear ContainersUsing VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear Containers
 
Devicemgmt
DevicemgmtDevicemgmt
Devicemgmt
 
What’s New in UniVerse 11.2
What’s New in UniVerse 11.2What’s New in UniVerse 11.2
What’s New in UniVerse 11.2
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemd
 
Cooking security sans@night
Cooking security sans@nightCooking security sans@night
Cooking security sans@night
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
PT101-WEEK-8-9-Importance-functions-of-Input-output-in-OS-1.pptx
PT101-WEEK-8-9-Importance-functions-of-Input-output-in-OS-1.pptxPT101-WEEK-8-9-Importance-functions-of-Input-output-in-OS-1.pptx
PT101-WEEK-8-9-Importance-functions-of-Input-output-in-OS-1.pptx
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 
Faults inside System Software
Faults inside System SoftwareFaults inside System Software
Faults inside System Software
 
Why containers
Why containersWhy containers
Why containers
 
Using Embedded Linux for Infrastructure Systems
Using Embedded Linux for Infrastructure SystemsUsing Embedded Linux for Infrastructure Systems
Using Embedded Linux for Infrastructure Systems
 

More from Chris Simmonds

Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDBChris Simmonds
 
Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Chris Simmonds
 
Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Chris Simmonds
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiChris Simmonds
 
Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Chris Simmonds
 
Reducing boot time in embedded Linux
Reducing boot time in embedded LinuxReducing boot time in embedded Linux
Reducing boot time in embedded LinuxChris Simmonds
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?Chris Simmonds
 
Embedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneEmbedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneChris Simmonds
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAMChris Simmonds
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depthChris Simmonds
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 

More from Chris Simmonds (11)

Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDB
 
Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?
 
Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
 
Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019
 
Reducing boot time in embedded Linux
Reducing boot time in embedded LinuxReducing boot time in embedded Linux
Reducing boot time in embedded Linux
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?
 
Embedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneEmbedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphone
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAM
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 

Recently uploaded

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Quick and Easy Device Drivers for Embedded Linux Using UIO

  • 1. Quick and Easy Device Drivers for Embedded Linux Using UIO Chris Simmonds Embedded World 2017 Quick and Easy Device Drivers for Embedded Linux Using UIO 1 Copyright © 2011-2017, 2net Ltd
  • 2. License These slides are available under a Creative Commons Attribution-ShareAlike 3.0 license. You can read the full text of the license here http://creativecommons.org/licenses/by-sa/3.0/legalcode You are free to • copy, distribute, display, and perform the work • make derivative works • make commercial use of the work Under the following conditions • Attribution: you must give the original author credit • Share Alike: if you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one (i.e. include this page exactly as it is) • For any reuse or distribution, you must make clear to others the license terms of this work Quick and Easy Device Drivers for Embedded Linux Using UIO 2 Copyright © 2011-2017, 2net Ltd
  • 3. About Chris Simmonds • Consultant and trainer • Author of Mastering Embedded Linux Programming • Working with embedded Linux since 1999 • Android since 2009 • Speaker at many conferences and workshops "Looking after the Inner Penguin" blog at http://2net.co.uk/ https://uk.linkedin.com/in/chrisdsimmonds/ https://google.com/+chrissimmonds Quick and Easy Device Drivers for Embedded Linux Using UIO 3 Copyright © 2011-2017, 2net Ltd
  • 4. Overview • Conventional Linux drivers • The UIO framework • An example UIO driver • Scheduling and interrupt latencies Quick and Easy Device Drivers for Embedded Linux Using UIO 4 Copyright © 2011-2017, 2net Ltd
  • 5. Conventional device driver model User space System call handler Generic services Device drivers Hardware Application C library interrupts Kernel space Quick and Easy Device Drivers for Embedded Linux Using UIO 5 Copyright © 2011-2017, 2net Ltd
  • 6. Userspace drivers • Writing kernel device drivers can be difficult • Luckily, there are generic drivers that that allow you to write most of the code in userspace • For example • USB (via libusb) • GPIO • I2C Reference www.slideshare.net/chrissimmonds/userspace-drivers2016 Quick and Easy Device Drivers for Embedded Linux Using UIO 6 Copyright © 2011-2017, 2net Ltd
  • 7. UIO drivers • Userspace I/O (UIO) is a framework for userspace drivers that do not fit into the standard patterns • Typical use-cases include interfaces to FPGAs and custom PCI functions • UIO may be appropriate for your hardware interface if: • it has registers and/or buffers that are memory mapped • it generates interrupts Quick and Easy Device Drivers for Embedded Linux Using UIO 7 Copyright © 2011-2017, 2net Ltd
  • 8. The UIO way IRQ mmap interrupt handler Register bank /dev/uio0 mmap() read() Hardware Kernel Application Register bank Quick and Easy Device Drivers for Embedded Linux Using UIO 8 Copyright © 2011-2017, 2net Ltd
  • 9. Kernel and userspace components • UIO drivers are in two parts • A simple kernel stub driver, which creates device node /dev/uioX • A user-space driver that implements the majority of the code • Device node /dev/uioX links the two together Quick and Easy Device Drivers for Embedded Linux Using UIO 9 Copyright © 2011-2017, 2net Ltd
  • 10. The UIO kernel driver • Kernel driver needs to • point to one (or more) memory regions • assign the interrupt number (IRQ) • implement interrupt handler • register as a UIO driver Quick and Easy Device Drivers for Embedded Linux Using UIO 10 Copyright © 2011-2017, 2net Ltd
  • 11. Example driver This device has 8 KiB (0x2000) of memory-mapped registers at 0x4804C000 and is attached to hardware interrupt IRQ 85 static int demo_probe(struct platform_device *pdev) { info.name = "demo"; info.version = "1.0"; info.mem[0].addr = 0x4804C000; info.mem[0].size = 0x2000; info.mem[0].memtype = UIO_MEM_PHYS; info.irq = 85; info.irq_flags = 0; info.handler = demo_handler; return uio_register_device(&pdev->dev, &info); } Quick and Easy Device Drivers for Embedded Linux Using UIO 11 Copyright © 2011-2017, 2net Ltd
  • 12. Kernel interrupt handler • Usually very simple • For example, disable interrupt source, which will be enabled again in userspace drivers/uio/uio_aec.c: static irqreturn_t aectc_irq(int irq, struct uio_info *dev_info) { void __iomem *int_flag = dev_info->priv + INTA_DRVR_ADDR; unsigned char status = ioread8(int_flag); if ((status & INTA_ENABLED_FLAG) && (status & INTA_FLAG)) { /* application writes 0x00 to 0x2F to get next interrupt */ status = ioread8(dev_info->priv + MAILBOX); return IRQ_HANDLED; } return IRQ_NONE; } Quick and Easy Device Drivers for Embedded Linux Using UIO 12 Copyright © 2011-2017, 2net Ltd
  • 13. The user-space driver • Each UIO driver represented by device node /dev/uioX • X = 0 for first, 1 for second, etc. • User space application uses it to mmap the memory and receive notification of interrupts Quick and Easy Device Drivers for Embedded Linux Using UIO 13 Copyright © 2011-2017, 2net Ltd
  • 14. Mapping memory • mmap(2) maps memory associated with a file descriptor • Example: map 0x2000 bytes from file /dev/uio0: int main(int argc, char **argv) { int f; char *ptr; f = open("/dev/uio0", O_RDWR); if (f == -1) { return 1; } ptr = mmap(0, 0x2000, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0); if (ptr == MAP_FAILED) { return 1; } ptr points to the base of the register bank. UIO framework maps the memory without processor cache, so writes and reads force memory cycles on the system bus Quick and Easy Device Drivers for Embedded Linux Using UIO 14 Copyright © 2011-2017, 2net Ltd
  • 15. Handling interrupts • Wait for interrupt by reading from /dev/uioX • The read() blocks until the next interrupt arrives • Data returned by read contains the count of interrupts since the UIO kernel driver was started • Can detect missed interrupts by comparing with previous interrupt count Quick and Easy Device Drivers for Embedded Linux Using UIO 15 Copyright © 2011-2017, 2net Ltd
  • 16. Interrupt example 1 • Simple example, using blocking read call static void wait_for_int(int f) { int n; unsigned int irc_count; printf("Waitingn"); n = read(f, &irc_count, sizeof(irc_count)); if (n == -1) { printf("read errorn"); return; } printf("irc_count = %dn", irc_count); } Quick and Easy Device Drivers for Embedded Linux Using UIO 16 Copyright © 2011-2017, 2net Ltd
  • 17. Blocking behaviour • Blocking in read() means that the application cannot do any work between interrupts • Solution 1: use poll() or select() to wait with a timeout • possibly on several data sources at once • Solution 2: use a thread to wait Quick and Easy Device Drivers for Embedded Linux Using UIO 17 Copyright © 2011-2017, 2net Ltd
  • 18. Interrupt example 2 • Using poll(2) static void wait_for_int_poll(int f) { struct pollfd poll_fds [1]; int ret; unsigned int irc_count; printf("Waitingn"); poll_fds[0].fd = f; poll_fds[0].events = POLLIN; ret = poll(poll_fds, 1, 100); /* timeout = 100 ms */ if (ret > 0) { if (poll_fds[0].revents && POLLIN) { read(f, &irc_count, sizeof(irc_count)); printf("irc_count = %dn", irc_count); } } } Quick and Easy Device Drivers for Embedded Linux Using UIO 18 Copyright © 2011-2017, 2net Ltd
  • 19. Mapping more than one memory area • Example: a device with two address ranges: info.name = "demo"; info.version = "1.0"; info.mem[0].addr = 0x4804C000; info.mem[0].size = 0x2000; info.mem[0].memtype = UIO_MEM_PHYS; info.mem[1].addr = 0x48060000; info.mem[1].size = 0x4000; info.mem[1].memtype = UIO_MEM_PHYS; return uio_register_device(&pdev->dev, &info); UIO allows up to 5 address ranges Quick and Easy Device Drivers for Embedded Linux Using UIO 19 Copyright © 2011-2017, 2net Ltd
  • 20. Mapping address ranges • The range to map is specified as mmap offset (last parameter) • Because behind the scenes mmap works in pages instead of bytes, the index has to be given in pages • To mmap address range in info.mem[1], use offset = 1 page: ptr2 = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_SHARED, f, 1 * getpagesize()); Quick and Easy Device Drivers for Embedded Linux Using UIO 20 Copyright © 2011-2017, 2net Ltd
  • 21. Scheduling • Where interrupts are concerned, the process or thread should be real-time • scheduling policy = SCHED_FIFO • Memory locked using mlockall struct sched_param param; mlockall (MCL_CURRENT | MCL_FUTURE); param.sched_priority = 10; if (sched_setscheduler (getpid (), SCHED_FIFO, &param) != 0) printf ("Failed to change policy and priorityn"); Quick and Easy Device Drivers for Embedded Linux Using UIO 21 Copyright © 2011-2017, 2net Ltd
  • 22. Interrupt latency • Even a real-time thread may have high jitter on interrupt latency if the kernel is not preemptive • Configure kernel with CONFIG_PREEMPT • Or, implement Real-time kernel patche and configure with CONFIG_PREEMPT_RT • Measures latencies will vary from platform to platform, but should be less than a few hundred microseconds Quick and Easy Device Drivers for Embedded Linux Using UIO 22 Copyright © 2011-2017, 2net Ltd
  • 23. Further reading • Kernel source documentation: Documentation/DocBook/uio-howto • on-line at https://www.osadl.org/fileadmin/dam/interface/ docbook/howtos/uio-howto.pdf • LWN article: https://lwn.net/Articles/232575/ Quick and Easy Device Drivers for Embedded Linux Using UIO 23 Copyright © 2011-2017, 2net Ltd
  • 24. Summary • UIO provides a convenient way to implement drivers for FPGA interfaces and hardware for which there is no existing Linux driver • Applicable to hardware that provides mappable memory and generates interrupts Quick and Easy Device Drivers for Embedded Linux Using UIO 24 Copyright © 2011-2017, 2net Ltd
  • 25. • Any questions? This and other topics associated with building robust embedded systems are covered in my training courses http://www.2net.co.uk/training.html Quick and Easy Device Drivers for Embedded Linux Using UIO 25 Copyright © 2011-2017, 2net Ltd