Linux Device Drivers - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Linux Device Drivers

Description:

Map standard calls to specific hardware. Build separately from kernel & plugged ... ftp://ftp.llp.fu-berlin.de/pub/linux/LINUX-LAB/whitepapers/drivers.ps.gz ' ... – PowerPoint PPT presentation

Number of Views:459
Avg rating:3.0/5.0
Slides: 20
Provided by: soti1
Category:
Tags: berlin | device | drivers | linux | map

less

Transcript and Presenter's Notes

Title: Linux Device Drivers


1
Linux Device Drivers
  • CSlab _at_ NTUA
  • ???ast???? ?p?????st???? S?st?µ?t??
  • ?????? ?ets?ß?? ????te??e??

2
Device Drivers
  • Black boxes
  • Hide details
  • Standardized calls
  • Map standard calls to specific hardware
  • Build separately from kernel plugged in at
    runtime

3
Why Do We Need Drivers?
  • New devices constantly available
  • Hardware vendors
  • Learn things most people dont know ?
  • Learn how machine works
  • Learn about OS kernel

4
Mechanism vs. Policy
  • device driver provides mechanism, not policy
  • X server vs. window manager
  • TCP/IP (sockets interface is mechanism, servers
    provide policy)
  • Floppy driver (mechanism to see data blocks,
    filesystem provides policy)

5
User Programs Needed
  • Kernel programming not enough
  • User apps needed to communicate with kernel
  • e.g. sound volume control (sndctl)

6
Kernel
  • Big chunk of executable code
  • Process management
  • Memory management
  • Filesystems
  • Device control
  • Networking

7
Modules
  • Ability to extend features offered by kernel at
    runtime
  • Module is piece of code
  • insmod/rmmod
  • Device driver can be a module

8
Classes of Devices
  • Char devices
  • Block devices
  • Network devices

9
Classes of Modules
  • Device drivers
  • filesystems

10
Building and Running Modules
include ltlinux/module.hgt int init_module()
printk("Hello, world\n")   return 0 void
cleanup_module() printk(Bye Bye\n")
11
Building and Running Modules (2)
  • Kernel functions only, no C library
  • Dont use printf, only printk
  • insmod ./hello.o
  • dmesg to see kernel messages
  • rmmod hello.o
  • Dmesg to see kernel messages
  • Insmod/rmmod called by super-user (root)

12
User Space and Kernel Space
  • Modules run in kernel space
  • Applications in user space
  • Different memory mapping-address space
  • User?kernel space by system call or hardware
    interrupt

Kernel code is executed in process context,
acceses data in process address space
Runs in no process context
13
Character Devices
mknod /dev/lunix c 69 0
Example of ls l /dev on my system
  • crw------- 1 gtsouk users 14, 3 Apr 17
    1999 /dev/dsp
  • crw-rw-rw- 1 root root 69, 0 May 5
    1998 /dev/lunix
  • crw-rw-rw- 1 root root 1, 3 May 5
    1998 /dev/null
  • crw-r--r-- 1 root root 1, 8 May 5
    1998 /dev/random
  • crw------- 1 sotirop users 4, 0 May 5
    1998 /dev/tty0
  • crw-r----- 1 root uucp 4, 64 Mar 19
    1456 /dev/ttyS0
  • crw-rw-rw- 1 root root 1, 5 May 5
    1998 /dev/zero

14
Character Devices
  • int (open) (struct inode , struct file )
  • void (release) (struct inode , struct file )
  • int (read) (struct inode , struct file , char
    , unsigned long)
  • int (write) (struct inode , struct file ,
    const char , unsigned long)
  • int (lseek) (struct inode , struct file , long
    long, int)
  • int (ioctl) (struct inode , struct file ,
    unsigned int, unseigned long)

15
Character Devices
  • static struct file_operations lunix_fops
  • open (void )lunix_open,
  • release (void )lunix_release,
  • read (void )lunix_read,
  • write (void )lunix_write,
  • llseek (void )lunix_llseek,
  • ioctl (void )lunix_ioctl,

16
Character Devices
  • register_chrdev()
  • unregister_chrdev()
  • Character devices
  • 1 mem
  • 2 pty
  • 69 lunix_driver
  • 180 usb
  • Block devices
  • 2 fd
  • 33 ide2

17
Exercise and Notes
  • http//www.cslab.ntua.gr/courses
  • http//ray.cslab.ntua.gr/dd
  • Labs exercise and notes in .pdf.
  • Give it a try!

18
Linux Device Drivers, 2nd Edition
19
Bibliography
  • Writing Character Device Driver for Linux
  • ftp//ftp.llp.fu-berlin.de/pub/linux/LINUX-LAB/whi
    tepapers/drivers.ps.gz
  •  
  • The Linux Kernel Module Programming Guide
    http//www.ntua.gr/LDP/guides.html
  •  
  • Linux Device Drivers, 2nd Edition, Alessandro
    Rubini and Jonathan Corbet. http//www.xml.com/ldd
    /chapter/book/
Write a Comment
User Comments (0)
About PowerShow.com