Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.

Slides:



Advertisements
Similar presentations
Principles of I/O Hardware I/O Devices Block devices, Character devices, Others Speed Device Controllers Separation of electronic from mechanical components.
Advertisements

Lecture 101 Lecture 10: Kernel Modules and Device Drivers ECE 412: Microcomputer Laboratory.
CSNB324 Advanced Operating Systems 6: Device Management
RT_FIFO, Device driver.
purpose Search : automation methods for device driver development in IP-based embedded systems in order to achieve high reliability, productivity, reusability.
Sogang University Advanced Operating Systems (Linux Device Drivers) Advanced Operating Systems (Linux Device Drivers) Sang Gue Oh, Ph.D.
Computer System Laboratory
USERSPACE I/O Reporter: R 張凱富.
Memory management.
I/O Unit.
I/O Devices and Drivers
63 UQC152H3 Advanced OS Writing a Device Driver. 64 The SCULL Device Driver Simple Character Utility for Loading Localities 6 devices types –Scull-03.
Introduction to Kernel
04/16/2010CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying an earlier edition.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Embedded Real-time Systems The Linux kernel. The Operating System Kernel Resident in memory, privileged mode System calls offer general purpose services.
Chapter 7 Interupts DMA Channels Context Switching.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output – 3 I/O Software CS 342 – Operating Systems Ibrahim Korpeoglu.
1 I/O Management in Representative Operating Systems.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Device Drivers In Linux © Gregory Kesden Fall 2000.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
M. Muztaba Fuad Advanced Operating System Project Device Drivers.
Operating System Program 5 I/O System DMA Device Driver.
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
System Calls 1.
Disk Access. DISK STRUCTURE Sector: Smallest unit of data transfer from/to disk; 512B 2/4/8 adjacent sectors transferred together: Blocks Read/write heads.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
MICROPROCESSOR INPUT/OUTPUT
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS6: Device Management 6.1. Principles of I/O.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Principles of I/0 hardware.
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Ethernet Driver Changes for NET+OS V5.1. Design Changes Resides in bsp\devices\ethernet directory. Source code broken into more C files. Native driver.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
UNIX Files File organization and a few primitives.
I/O Computer Organization II 1 Interconnecting Components Need interconnections between – CPU, memory, I/O controllers Bus: shared communication channel.
1.4 Hardware Review. CPU  Fetch-decode-execute cycle 1. Fetch 2. Bump PC 3. Decode 4. Determine operand addr (if necessary) 5. Fetch operand from memory.
Chapter 13 – I/O Systems (Pgs ). Devices  Two conflicting properties A. Growing uniformity in interfaces (both h/w and s/w): e.g., USB, TWAIN.
Interfacing Device Drivers with the Kernel
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
4P13 Week 12 Talking Points Device Drivers 1.Auto-configuration and initialization routines 2.Routines for servicing I/O requests (the top half)
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Device Driver Concepts Digital UNIX Internals II Device Driver Concepts Chapter 13.
Input Output Techniques Programmed Interrupt driven Direct Memory Access (DMA)
بسم الله الرحمن الرحيم MEMORY AND I/O.
1 The File System. 2 Linux File System Linux supports 15 file systems –ext, ext2, xia, minix, umsdos, msdos, vfat, proc, smb, ncp, iso9660, sysv, hpfs,
Part IVI/O Systems Chapter 13: I/O Systems. I/O Hardware a typical PCI bus structure 2.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Input/Output (I/O) Important OS function – control I/O
Introduction to Kernel
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
OS Concepts - Overview.
Linux Kernel Development - Robert Love
Linux Details: Device Drivers
Protection of System Resources
CS703 - Advanced Operating Systems
CSCI 315 Operating Systems Design
I/O Systems I/O Hardware Application I/O Interface
Operating Systems Chapter 5: Input/Output Management
CS703 - Advanced Operating Systems
Direct Memory Access Disk and Network transfers: awkward timing:
Linux Details: Device Drivers
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Presentation transcript:

Device Drivers

Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering –block device : R/W via buffer cache –Network device : BSD socket interface

Common Attributes of Devices Drivers Kernel code Kernel interface Kernel mechanisms and services Loadable : run time Configurable: compile time Dynamic : device may not exist

DMA A DMA controller allows devices to transfer data to or from the system's memory without the intervention of the processor Each DMA channel has associated with it a 16 bit address register and a 16 bit count register.

DMA DMA controllers know nothing about VM DMA controller cannot access the whole of physical memory –only bottom 16M physical memory DMA channels are scare resources : 7

Memory Device drivers located in Linux kernel they cannot use virtual memory Memory allocation shall be careful Device driver may specify the allocated memory is DMAable

Interfacing Device Drivers with Kernel Character Devices Registered device driver

Interfacing Device Drivers with Kernel Character Devices –special file for a file system : /dev/cua0 –represented by a VFS inode –its file operation are set to the default character device operations Registered device driver

Interfacing Device Drivers with Kernel Block Devices Registered device driver

Interfacing Device Drivers with Kernel Block Devices –every block device must provide an interface to the buffer cache (as well as normal file operations) –buffer cache R/W a block of data by adding a request data structure into blk_dev_struct –the buffer_haed are locked –Once the device driver has completed a request it must remove each of the buffer_head structures from the request structure Registered device driver

Interfacing Device Drivers with Kernel Block Devices –mark the buffer-header up to date and unlock them –wake up any process that has been sleeping waiting for the lock to complete Registered device driver

Polling mode The driver constantly interrogate the hardware Waste of CPU time Fastest way to communicate with the hardware

Interrupt Mode For example, write a character to a parallel port: –interruptible_sleep_on(&lp->lp_wait_q); ISR handling the interrupt then wake up the process –static void lp_interrupt(int irq){ wake_up(&lp->lp_wait_q);}

Interrupt Sharing The number of IRQs in a PC is limited PCI boards can be connect as interrupt sharing Linux 2.0 support interrupt sharing by building chains of interrupt handling routins When an interrupt occurs, each ISR in the chain is called by the do_IRQ()

Bottom halves Not all the functions need to be performed immediately after an interrupt occurs Others can be handled later or would take a relatively long time and it is preferable not to block the interrupt Bottom halves ret_from_syscall if no further interrupt in running at that time a list of up to 32 bottom halves is scanned

Implementing a driver The setup function Pass parameters to the drivers from LILO Called before init(); Only set up global variables

Init() Only called during kernel initialization Test for the presence of a device Generate internal device driver structures and register the device

open and release open –called as soon as a process opens a device file –Initialize the standard setting of the device release –Called when the file descriptors for the device is released –cleaning up activities

Read and Write Reader/Writer Problem Sleep/wake_up memcopy_fromfs () –interrupt may occur independently of the current process, data cannot be fetched from user area during the interrupt

IOCTL Each device has its own characteristics, –different operation mode and basic setting ioctl usually change the variables global to the driver Typical IOCTL call –static int pcsp_ioctl( strruct inode *inode, struct file *file, usigned int cmd, unsign long arg) – macros for coding the individual commands

Select Check whether data can be read from the device or written to it It is important function for the character devices

lseek mmap lseek : position (block devices) mmap: map the device to the user address space (block devices)

readdir, fsync, fasync check_media_change revalidate readdir, fsync, fasync –for file systems only check_media_change, revalidate –for exchangeable media