COMP 3438 – Part I - Lecture 4 Introduction to Device Drivers Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.

Slides:



Advertisements
Similar presentations
Operating System.
Advertisements

EEE 435 Principles of Operating Systems Principles and Structure of I/O Software (Modern Operating Systems 5.2 & 5.3) 5/22/20151Dr Alain Beaulieu.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
04/14/2008CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
File Management Systems
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
CS 104 Introduction to Computer Science and Graphics Problems Operating Systems (4) File Management & Input/Out Systems 10/14/2008 Yang Song (Prepared.
Introduction to Kernel
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
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:
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
I/O Systems CS 3100 I/O Hardware1. I/O Hardware Incredible variety of I/O devices Common concepts ◦Port ◦Bus (daisy chain or shared direct access) ◦Controller.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
1 I/O Management in Representative Operating Systems.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Copyright ©: Nahrstedt, Angrave, Abdelzaher
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
Device Management. Serial Port Serial Device Serial Device Memory CPU Printer Terminal Modem Mouse etc.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
CSC 322 Operating Systems Concepts Lecture - 25: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
I/O Systems I/O Hardware Application I/O Interface
1 Lecture 20: I/O n I/O hardware n I/O structure n communication with controllers n device interrupts n device drivers n streams.
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.
Introduction to Operating Systems Chapter 1. cs431 -cotter2 Lecture Objectives Understand the relationship between computing hardware, operating system,
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Principles of I/0 hardware.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
Slide 5-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5.
UNIX Files File organization and a few primitives.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
LINUX System : Lecture 7 Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System.
UNIX Unit 1- Architecture of Unix - By Pratima.
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.
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)
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems Overview I/O Hardware Application.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Device Driver Concepts Digital UNIX Internals II Device Driver Concepts Chapter 13.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 I/O through system calls Protection.
COMP 3438 – Part II-Lecture 5 Syntax Analysis II Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Security Architecture and Design Chapter 4 Part 2 Pages 319 to 357.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
I/O Software CS 537 – Introduction to Operating Systems.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
COMP 3438 – Part II-Lecture 6 Syntax Analysis III Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Introduction to Operating Systems Concepts
Input/Output (I/O) Important OS function – control I/O
Module 12: I/O Systems I/O hardware Application I/O Interface
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
CSCI 315 Operating Systems Design
Chapter 11: File System Implementation
CPSC 457 Operating Systems
I/O Systems I/O Hardware Application I/O Interface
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
CS703 - Advanced Operating Systems
LINUX System : Lecture 7 Lecture notes acknowledgement : The design of UNIX Operating System.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Mr. M. D. Jamadar Assistant Professor
Module 12: I/O Systems I/O hardwared Application I/O Interface
Presentation transcript:

COMP 3438 – Part I - Lecture 4 Introduction to Device Drivers Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.

Overview of the Subject (COMP 3438) Overview of Unix Sys. Prog. ProcessFile System Overview of Device Driver Development Character Device Driver Development Introduction to Block Device Driver Overview of Complier Design Lexical Analysis Syntax Analysis Part I: Unix System Programming (Device Driver Development) Part II: Compiler Design Course Organization (This lecture is in red)

Outline Lecture 4: Introduction to Device Drivers 1. What is a device driver? 2. Related kernel data structures from a generic view 3. Devices and Files 4. Major design issues 5. Types of device drivers Lecture 5-I: Char device driver I A simple device driver – “Hello world” Lecture 5-II: Char device driver II A device driver for LED Lecture 6: Block Device Driver A device driver for RAM Disk Lecture 5-II: Char device driver III Interrupt-driven driver (Button)

Part I: Intro. to Device Drivers

What is a device driver? A device driver is a computer program that glues an O.S. and its I/O devices together. Device drivers act as translators Converting generic requests received from an O.S. into commands that specific peripheral controllers can understand. Example Generic File Requests: write(fd, buf, 100); Kernel – Device Driver: write to harddisk 2, block 12345

Related Kernel Data Structures In Unix, from a generic view, the following structures are related to device drivers: Unix System Architecture File Subsystem and its relations with Char/Block device driver tables Char/Block device driver tables “from a generic view” – what that means? In a particular Unix O.S., these structures or table names may be different from we mention here. But the basic idea should be the same.

7 UNIX System Architecture

File Subsystem & Char/Block Device Driver Tables File Subsystem open close read write ioctl open close read write mount unmount Character Device Driver TableBlock Device Driver Table Buffer Cache open close read write ioctl Char Device Driver Device Interrupt Handling open close Strategy Block Device Driver Device Interrupt Handling Interrupt Vectors Interrupts

Char/Block Device Driver Tables conopenconcloseconreadconwriteconioctl testopentestclosetestreadtestwritenodev dzbopendzbclosedzbreaddzbwritedzbioctl syopennulldevsyreadsywritesyioctl nulldev mmreadmmwritenodev Character Device Driver Table Block Device Driver Table open close read write ioctl open close Strategy gdopengdclosegdstrategy rdopenrdcloserdstrategy Major Number: The index (id) of a device driver in char/block device driver tables. Minor Number: A number is used inside a device driver, e.g., one driver may control many devices then minor number can be used to distinguish them.

10 Advantages to Separate Device Drivers from O.S. Designers for O.S. Devices may not be available when an O.S. is designed Do not need to worry about how to operate devices (set up registers, check statuses, … ). Focus on O.S. itself by providing a generic interface for device driver development Designers for Device Drivers Do not need to worry about how I/O is managed in O.S. (how to design kernel data structures so as to efficient operate devices, … ) Focus on implementing functions of devices with device-related commands following the generic I/O interface

11 Devices and Files In Unix, devices are treated as special files. A file is associated with an inode. We can use mknod file_name c/b major_number minor_number to create a special file for a device file. When we create a special file (an inode) for a device file, we associate major/minor numbers with the file (the inode). The major number associated with a special file is used to identify its corresponding device drivers in the kernel.

12 Basically, there are two types of device files: character device file and block device file. Example: ls -l /dev/null crw-rw-rw-r 1 root root 1 3 June 1, 2013 null ls -l /dev/bon br--r--r-- 1 root root 97 0 June 1, br--r--r-- 1 root root 97 1 June 1, Character/Block Device Files character device filemajor number minor number block device filemajor number minor number

13 Major Design Issues O.S. / Device Driver Communication Device Driver / Hardware Communication Device Driver Operations Interpret commands received from O.S. Schedule multiple requests for services Manage data transfer across both interfaces Accept & process hardware interrupts Maintain the integrity of the device ’ s and kernel ’ s data structures

14 Types of Device Drivers Based on the differences in the way that device drivers communicate with Unix O.S. Block Character Terminal STREAMS

Block Device Drivers Block drivers – Communicate with O.S. through a collections of fixed-sized buffers. User Process Kernel Drivers read/write system calls read/write system call handler buffer management routines buffer cache headers buffer cache data Strategy

16 Block Device Drivers O.S. Manage a buffer cache Satisfy user requests for data by accessing buffers in the cache Driver is invoked when Requested data is not in the cache When buffers in the cache have been changed and must be written out (write back to the devices) By using buffer cache, block drivers be insulated from many of the details of users ’ requests only need to handle requests from O.S. to fill or empty fixed-size buffer Mainly support devices that contain file systems

Character Device Drivers Character devices can handle I/O requests of arbitrary size support almost any type of devices Be used to handle data a byte at a time (e.g. keyboard) or work best with data in chunks smaller or larger than the standard fixed-size buffer used by device driver (e.g. ADC)

Character Device Drivers The communication structure of character device driver User Process Kernel Drivers read/write system calls read/write system call handler read/write entry points

Major differences between Block/Char drivers Major difference with block driver Block driver – only interact with buffer cache Char driver – direct interact with user requests from user processes I/O requests are directly passed (essentially unchanged) to the drivers from processes Char driver is responsible for transferring data directly to and from between kernel memory space and user memory space

Terminal Drivers Special character drivers to deal with communication terminals that connect users to the central Unix systems Responsibilities Transfer data to and from users’ terminals Handle line editing and other terminal functions that are part of the standard Unix terminal interface described by the TERMIO manual page

Terminal Drivers The communication structure of Terminal Drivers User Process Kernel Drivers read/write system calls read/write system call handler line discipline routines read/write entry points proc routines (The additional processing and the additional kernel routines that are provided to handle terminal services)

STREAM Drivers Handle high-speed communication devices such as network adapters that deal with unusual-sized chunk of data and that need to handle protocols. To handle these, especially for protocols, we need to kernel’s help (character driver is not good enough). The kernel provides some routines/modules to support the processing of a number of layered protocols.

STREAM Drivers The communication structure of Terminal Drivers User Process Kernel Drivers read/write system calls Stream Head STREAMS Modules (Optional) STREAMS Drivers

General Programming Considerations Device drivers are parts of the kernel and not normal user processes, which means We can only use the kernel routines C library functions or system calls provided for users cannot be used Some kernel routines may have the same names as C library functions, but they are totally different in implementation Make frugal use of stack (local arrays & recursive functions) The stack space in the kernel is limited and not expandable Don’t use floating-point arithmetic – May cause incorrect results Don’t do busy wait that will prevent the whole system from doing nothing but responding to interrupts

Summary A device driver is a computer program that glues O.S. and its I/O devices together A device is treated as a special file in Unix. There are four types of device drivers based on the different communication manner between device drivers and O.S. Block Character Terminal STREAMS