Docsity

Understanding UART Interrupts in Linux Kernel 2.6.22.5, Slides of Computer Applications

Partial preview of the text

Download Understanding UART Interrupts in Linux Kernel 2.6.22.5 and more Slides Computer Applications in PDF only on Docsity!

Handling a UART interrupt

A look at some recent changes in

the Linux kernel’s programming

interface for device-interrupts

The new ‘anchor’ cluster

• To reduce contention for CS workstations

that have null-modem cables attached, we

are bringing online an additional cluster of

eight servers – you access them remotely

‘anchor00’ ‘anchor01’

‘anchor02’ ‘anchor03’

‘anchor04’ ‘anchor05’

‘anchor06’ ‘anchor07’

Thanks to overnight efforts by Alex Fedosov and our CS support-team!

Example 1

• Our textbook shows the prototype for a

device-driver’s interrupt service routine:

irqreturn_t isr ( int irq, void *dev_id, struct pt_regs *regs );

• But this has changed in kernel 2.6.22.5 to:

Irqreturn_t isr ( int irq, void *dev_id );

• What prompted the kernel developers to

remove that third function-argument?

• Just a guess, but probably it was because

programmers were not actually using it

Example 2

• The kernel’s header-files <asm/signal.h>

provided symbolic names for important

interrupt-related constants in 2.6.10:

#define SA_SHIRQ 0x

• Such definitions, formerly replicated for

each supported CPU architecture, have

now been consolidated (and renamed) in

the kernel header-file <linux/interrupt.h>:

#define IRQF_SHARED 0x

Our ‘uartintr.c’ module

• We have written a kernel module that you

can study (and experiment with) showing

an interrupt-handler for the UART device

that we created purely for demonstration

purposes using kernel version 2.6.22.

• Obviously you would need to modify it if

you wanted to use an interrupt-handler in

your solution for our course’s Project

Module’s components

init

exit

The isr function

The LKM layout

registers the ‘isr’ and then enables the UART device to generate interrupt-signals

disables the UART’s interrupt-signals and then unregisters this module’s ‘isr’

module’s ‘payload’ is just a single callback-function that will ‘handle’ a UART interrupt

the usual pair of module-administration functions

An interrupt service routine

• Whenever the UART receives a new byte

of data, it will transmit it back to the sender

#include <linux/interrupt.h> #include <asm/io.h> #define UART_BASE 0x03F

irqreturn_t my_uart_isr ( int irq, void *dev_id ) { int intr_identify = inb( UART_BASE + 2 ) & 0x0F; if ( intr_identify == 0x01 ) return IRQ_NONE;

if ( intr_identify == 0x04 ) // a new character has arrived outb( inb( UART_BASE ), UART_BASE ); return IRQ_HANDLED; }

Installing the ‘isr()’

• Here is how your module asks the kernel

to execute your UART interrupt-handler:

#define UART_IRQ 4 // signal-line’s number to the IO-APIC char modname[] = “uartintr”; // kernel displays this in ‘/proc/interrupts’

static int __init my_init ( void ) { … if ( request_irq ( UART_IRQ, &my_uart_isr, IRQF_SHARED, modname, &modname ) < 0 ) return –EBUSY; … // your code to enable the UART’s interrupts goes here … return 0; // SUCCESS }

FIFO Control Register

RCVR FIFO

trigger-level

reserved reserved

DMA Mode select

XMIT FIFO reset

RCVR FIFO reset

FIFO

enable

Writing 0 will disable the UART’s FIFO-mode, writing 1 will enable FIFO-mode

Writing 1 empties the FIFO, writing 0 has no effect

00 = 1 byte 01 = 4 bytes 10 = 8 bytes 11 = 14 bytes

NOTE: DMA is unsupported for the UART on our systems

Modem Control Register

LOOP

BACK

OUT2 OUT1 RTS DTR

Legend: DTR = Data Terminal Ready (1=yes, 0=no) RTS = Request To Send (1=yes, 0=no) OUT1 = not used (except in loopback mode) OUT2 = enables the UART to issue interrupts LOOPBACK-mode (1=enabled, 0=disabled)

Disabling UART interrupts

• Here is code that disables any more UART

interrupts, so that your module’s ‘cleanup’

can safely remove your interrupt-handler:

static __exit my_exit ( void ) { … // disable any further UART interrupt-requests outb( 0x00, UART_BASE + 1 ); // INTERRUPT_ENABLE outb( 0x00, UART_BASE + 4 ); // MODEM_CONTROL

// remove your UART interrupt-service routine free_irq ( UART_IRQ, modname ); … }

In-class exercise

• Try running our ‘trycable.cpp’ application

on an adjacent workstation after you have

downloaded, compiled, and installed our

‘uartintr.c’ demo-module

• What do you see on the two screens?

• Tonight’s class ends early -- so that you

can attend the ACM Chapter’s Pizza Night