Linux Device Drivers - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Linux Device Drivers

Description:

Gain better understanding of Linux environment. Become ... 9 GB Seagate Barracuda Model: ST39175LU. 4 GB Quantum Fireball Model: ST4.3S. Redhat Linux 7.2 ... – PowerPoint PPT presentation

Number of Views:133
Avg rating:3.0/5.0
Slides: 27
Provided by: Augu1
Category:

less

Transcript and Presenter's Notes

Title: Linux Device Drivers


1
Linux Device Drivers
  • By Adam Ormond
  • ormonda_at_msoe.edu

2
Purpose
  • Gain better understanding of Linux environment
  • Become familiar with device drivers
  • How they work
  • How theyre written
  • What they can do
  • Learn more about Makefiles and gcc

3
Resources
  • Dr. Russell Meier Independent Study Advisor
  • Rubini, Alessandro and Corbet, Jonathon. Linux
    Device Drivers. OReilly Sebastopol, CA. June
    2001.
  • Victor Meyer Engineering Technician
  • Welsh, Matt and Kaufman, Lar. Running Linux.
    OReilly Sebastopol, CA. August 1996.
  • http//people.msoe.edu/ormonda/index.php?content
    projects/LDD/LDD

4
Goals
5
Development Machine
  • Abit AB-ZM6 motherboard
  • Pentium Celeron 333 MHz overclocked to 416 MHz
    (83Mhz FSB 5)
  • 256 MB of SDRAM
  • 9 GB Seagate Barracuda Model ST39175LU
  • 4 GB Quantum Fireball Model ST4.3S
  • Redhat Linux 7.2
  • Kernel Version 2.4.7-10

6
Simple Module
  • Purpose
  • Ensure test machine works properly
  • Become familiar with insmod and rmmod
  • Learn basic functions
  • init_module
  • cleanup_module
  • printk

7
Simple Module
  • Issues/Difficulties
  • Problem Messages using printk not displaying on
    console
  • Solution set DEFAULT_CONSOLE_LOGLEVEL to 8 using
    echo 8 gt /proc/sys/kernel/print

8
DEFAULT_CONSOLE_LOGLEVEL
  • KERN_EMERG
  • KERN_ALERT
  • KERN_CRIT
  • KERN_ERR
  • KERN_WARNING
  • KERN_NOTICE
  • KERN_INFO
  • KERN_DEBUG

9
Simple Character Device
  • Purpose
  • Allocate memory
  • Read/write memory
  • Learn about device nodes
  • mknod
  • Device file system
  • register_chrdev
  • unregister_chrdev

10
Simple Character Device
  • Requirements
  • Major number
  • Minor number
  • file_operations structure
  • file structure
  • open, release, read, and write methods

11
file_operations
  • Provides hooks for llseek, read, write, readdir,
    poll, ioctl, mmap, open, flush, release, fsync,
    fasync, lock, readv, and writev
  • Uses a tagged structure struct file_operations
    Char_Dev read c_d_read, write
    c_d_write, open c_d_open, release
    c_d_release

12
file
  • Structure that represents an open file
  • Struct members
  • mode_t f_mode
  • FMODE_READ
  • FMODE_WRITE
  • loff_t f_pos
  • usnigned int f_flags
  • O_RDONLY
  • O_NONBLOCK
  • O_SYNC
  • struct file_operations f_op
  • void private_data
  • struct dentry f_dentry

13
devfs
  • devfs_handle_t devfs_mk_dir (devfs_handle_t dir,
    const char name, void info)
  • devfs_handle_t devfs_register (devfs_handle_t
    dir, const char name, unsigned int flags,
    unsigned int major, unsigned int minor, umode_t
    mode, void ops, void info)
  • devfs_unregister(devfs_handle_t de)

14
Methods implemented
  • open
  • Initialization of device
  • Increment usage count
  • MOD_INC_USE_COUNT
  • Check for problems with device
  • Determine minor number and update file_operations
    struct
  • Allocate memory for filp-gtprivate_data

15
Methods implemented
  • release
  • Deallocate memory
  • Shut down device if usage count 1
  • Decrement usage count
  • MOD_DEC_USE_COUNT

16
Methods implemented
  • read
  • ssize_t read(struct file filp, char buff,
    size_t count, loff_t offp)
  • down_interruptible
  • unsigned long copy_to_user(void to, const void
    from, unsigned long count)

17
Methods Implemented
  • write
  • ssize_t write(struct file filp, const char
    buff, size_t count, loff_t offp)
  • down_interruptible
  • unsigned long copy_from_user(voit to, const void
    from, unsigned long count)

18
Issues/Difficulties
  • gcc
  • Problem Inline statements not being compiled
  • Solution use O flag to expand inline statements
  • ifdef
  • Problem missing endif statements
  • Solution add endif statements

19
Advanced Character Device
  • Purpose
  • Utilize ioctl and llseek functionality
  • Hardware device control is given through ioctl
  • Ability to seek the device is given through llseek

20
ioctl
  • int ioctl(struct inode inode, struct file
    filp, unsigned int cmd, unsigned long arg)
  • Defining commands
  • Function usually uses a switch statement
  • Defining commands to use 1-x not safe
  • Unix method uses a magic number and then a plain
    number (example 0x6b01, 0x6b02, etc)
  • New method uses a magic number, ordinal number,
    direction of transfer, and size of argument.
    These are set using a variety of macros (example
    _IO(k, 1)). Defined in ltasm/ioctl.hgt

21
llseek
  • loff_t llseek(struct file filp, loff_t off, int
    whence)
  • Retrieve the file length of the device
  • whence values
  • SEEK_SET
  • SEEK_CUR
  • SEEK_END

22
Parallel Port Device
  • Purpose
  • Transfer data across the parallel port
  • Gain more experience with soldering
  • Learn about memory barriers
  • Requirements
  • Working parallel port
  • LED bank with interface to parallel port

23
LED Bank
24
Memory barriers
  • Prevent compiler optimization and hardware
    reordering
  • Keeps order of operations the same
  • void barrier(void)
  • void rmb(void)
  • void wmb(void)
  • void mb(void)

25
Conclusion
  • Accomplished most major goals
  • Learned a lot about Linux device drivers
  • More familiar with electrical components
  • Enjoyed working independently, using instructors
    and books as resources

26
Questions
Write a Comment
User Comments (0)
About PowerShow.com