Understanding Device Drivers: A Comprehensive Guide for University Students, Study notes of Design

An in-depth exploration of device drivers, their role in the computer system, and how they are developed. Students will learn about the differences between kernel modules and device drivers, the various types of devices, and the implementation steps for writing a Linux device driver. The document also covers essential concepts such as file operations, kernel functions, and registering and unregistering devices.

Typology: Study notes

2021/2022

Uploaded on 09/27/2022

paulina
paulina 🇺🇸

4.4

(13)

240 documents

1 / 46

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
University of Massachusetts Amherst 1
Topic 10: Device Driver
Tong ping Liu
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

Partial preview of the text

Download Understanding Device Drivers: A Comprehensive Guide for University Students and more Study notes Design in PDF only on Docsity!

Topic 10: Device Driver

Tongping Liu

Administration

  • Today it is the deadline of Project
  • Homework5 is posted, due on 05/
  • Bonus points: ECE570 – 3 points, ECE670- 5 points - Design exam questions - Process&threads, scheduling, synchronization, IPC, memory management, device driver/virtualization - Due: 05/
  • Survey project (ECE570/ECE670): 05/

Outline

  • Basic concepts
  • Kernel module
  • Writing device driver

Device Driver

  • A special kind of computer program that operates or controls a particular type of device that is attached to a computer

Whole System Stack

Note: This picture is excerpted from Write a Linux Hardware Device Driver, Andrew O’Shauqhnessy, Unix world

Another View from OS

Linux Device Driver

  • Manage data flow between user programs and device
  • Typically a self-contained kernel module
    • Add and remove dynamically
  • Device is a special file in /dev that user can access, e.g. /dev/lp
  • Can be only programed with C/assembly language

Device Files

  • Unix-like systems handle device files with separate subdirectory of /dev for each type of device: disk, block etc.
  • Device files are created with mknod : mknod filename type major minor
    • filename is the device file to be created.
  • type is c for a character device or b for a block device.
  • major and minor are the major and minor device numbers.

Device Jump Table

  • Each driver supports some or all of the following functions: probe attach open close read reset stop select strategy dump psize write
  • Addresses of these functions are stored in a structure called a jump table, which are indexed by major number
  • Two tables exists
    • One for character device
    • One for block devices.
  • Upon operations on a device file
    • Kernel catches the reference, looks up the appropriate function name in the jump table, and transfers control to it.
  • For unusual operation (ejecting floppy disk)
    • ioctl() to pass a message directly from user space into the driver

Device Jump Table

Block Device Driver

  • Accessed through a cache so buffering is required.
  • Seeking is possible, which can move back and forth between any location
  • Kernel provides an entire subsystem, since it is too complex
  • Reads and write done by buffer cache mechanism by bread(), bwrite(). These request may be asynchronous.

Outline

  • Basic concepts
  • Kernel module
  • Writing device driver

Kernel Modules

  • Definition: modules are pieces of code that can be loaded and unloaded into the kernel upon demand. - They extend the functionality of the kernel without the need to rebuild/reboot the system. - Without modules, we would have to build monolithic kernels and add new functionality directly into the kernel image.
  • Advantages:
    • We do not need to build the entire kernel, saving time
    • Help us to save memory, due to load on demand

Kernel Modules vs. Device Drivers

  • Most modules are device drivers
    • But some are not, such as IPv6 support or some file systems
  • Device drivers: drive the hardware
    • They can be built as kernel modules so that it can be dynamically loaded later.
    • They can also be built statically into the kernel file on disk.