M. Muztaba Fuad Advanced Operating System Project Device Drivers.

Slides:



Advertisements
Similar presentations
CT213 – Computing system Organization
Advertisements

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Sogang University Advanced Operating Systems (Linux Device Drivers) Advanced Operating Systems (Linux Device Drivers) Sang Gue Oh, Ph.D.
Computer System Laboratory
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
EEE 435 Principles of Operating Systems Operating System Concepts (Modern Operating Systems 1.5)
CMPT 300: Operating Systems I Dr. Mohamed Hefeeda
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
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Dr. Mohamed Hefeeda.
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)
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.
OS Spring’03 Introduction Operating Systems Spring 2003.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
1 Device Management The von Neumann Architecture System Architecture Device Management Polling Interrupts DMA operating systems.
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
Comparative Operating Systems Understanding the Kernel Structure Prashant Thuppala.
OPERATING SYSTEMS Introduction
1 I/O Management in Representative Operating Systems.
Copyright Arshi Khan1 System Programming Instructor Arshi Khan.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
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,
COMP 3438 – Part I - Lecture 4 Introduction to Device Drivers Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
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.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
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.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 7 OS System Structure.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
Slide 3-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3.
UNIX Files File organization and a few primitives.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
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.
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.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems Overview I/O Hardware Application.
OSes: 2. Structs 1 Operating Systems v Objective –to give a (selective) overview of computer system architectures Certificate Program in Software Development.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Device Driver Concepts Digital UNIX Internals II Device Driver Concepts Chapter 13.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
ICOM Noack Linux I/O structure Device special files Device switch tables and fops How the kernel finds a device Parts of a device driver or module.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 2.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
Major OS Components CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Introduction to Operating Systems Concepts
Introduction to Kernel
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.
Chapter 11: File System Implementation
Chapter 12: File System Implementation
Linux Kernel Driver.
Chapter 2: The Linux System Part 2
Chapter 2: System Structures
CS703 - Advanced Operating Systems
Lecture Topics: 11/1 General Operating System Concepts Processes
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Mr. M. D. Jamadar Assistant Professor
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

M. Muztaba Fuad Advanced Operating System Project Device Drivers

Slide 2 Overview Basics –Definitions –What the OS books say? Linux way of doing things (Kernel 2.4) –Check Linux Source code. Windows way of doing things –Check Windows Source code (just kidding !). Write your own driver in Linux –What you need to know? –How to write? –Things to remember Changes in Kernel 2.6

Slide 3

Slide 4 I/O Devices I/O devices are attached to the computer bus. Each I/O device consists of a controller subassembly to control the detailed operation of the physical device itself. Process Abstract I/O Machine BUSBUS Device Controller Device Program to manage device controller Supervisor mode software Program to manage device controller Supervisor mode software

Slide 5 Device ControllerBusyBusyDoneDoneErrorError…….……. CommandCommandStatusStatusDataData LogicLogic

Slide 6 Memory Access PrimaryMemoryPrimaryMemory CPUCPU ControllerController DeviceDevice PrimaryMemoryPrimaryMemory CPUCPU ControllerController DeviceDevice ConventionalDMA

Slide 7 Device Addressing PrimaryMemoryPrimaryMemory Device 0 Device 1 Device 2 PrimaryMemoryPrimaryMemory Device 0 Device 1 Device 2 Memory Address Device Address Memory Address Conventional Memory Mapped I/O

Slide 8 Device Independent I/O Driver No Standard Interface Standard Interface

Slide 9 Device Manager Abstraction Device Interface TerminalDriverTerminalDriver TerminalControllerTerminalController PrinterDriverPrinterDriver PrinterControllerPrinterController DiskDriverDiskDriver DiskControllerDiskController ……. read(….); ……. Common Device Interface

Slide 10 Device Management Organization Device Controller CommandCommandStatusStatusDataData System Interface Hardware Interface Device Manager Device Independent Device Dependent FileManager ApplicationProcess

Slide 11 I/O Strategies Direct I/O with polling –The CPU is responsible for data transfer between device and primary memory. –Slow data transfer. –Difficult to achieve effective CPU utilization Interrupt Driven I/O –The controller don’t needs to be checked for status constantly. –Controller “interrupts” the device manager to indicate when it finishes its operation.

Slide 12 Polling I/O Read read(….); DataData Device Driver Readfunction Read function Write function Device Controller CommandCommandStatusStatusDataData Device Interface Hardware Interface

Slide 13 Interrupt Processing When the kernel receives an interrupt from a particular device, the kernel passes control to its corresponding interrupt handler Interrupt handlers do not belong to any single process context –Scheduler cannot place an interrupt handler in a run queue –Thus, interrupt handler cannot sleep, call the scheduler, be preempted or raise faults or exceptions –As a result, most interrupt handlers are designed to execute quickly Interrupts are divided into top and bottom halves –Top half sets up. –Bottom half performs the operation.

Slide 14 Interrupt Driven I/O Device Driver Read function Write function Device Controller CommandCommandStatusStatusDataData Device Interface Hardware Interface read(….); DataData Device Status Table Device Status Table Device Handler Device Handler Interrupt Handler Interrupt Handler

Slide 15

Slide 16 Linux Device Driver Device Drivers ModulesModulesInterfaceInterfaceKernelKernel Initial Unix implementations has the device drivers coded inside the kernel. – –Problems ???? Module is an independent software unit that can be loaded into the kernel dynamically at run time. – –Helps to install new device without modifying the kernel. Kernel provides common interface for I/O system calls.

Slide 17 Kernel Driver Initialization Device files are more than half of the size of the kernel source. fs/devices.c  Defines all the device functions /devices directory  Holds all the device driver codes – –/devices/char – –/devices/block Kernel driver initialization: – –start_kernel  init/main.c setup_arch  arch/i386/kernel/setup.c – –Sets up system variables, such as video type, root device etc. console_init  driver/char/tty_io.c init  init/main.c – –do_basic_setup  init/main.c » »Initialize all bus sub system – –prepare_namespace  init/do_mounts.c » »Mount root and device file system – –do_initcalls  init/main.c » »All built in device driver is initialized which are registered with __initcall()

Slide 18 Linux Device Driver Most have been written by independent developers. Typically implemented as loadable kernel modules. Device special files – –Most devices are represented by device special files. – –Entries in the /dev directory that provide access to devices. – –List of devices in the system can be obtained by reading the contents of /proc/devices. Devices are grouped into classes – –Three classes: Character Devices Block Devices Network Devices – –Members of each device class perform similar functions

Slide 19 Major and minor identification numbers –Used by device drivers to identify their devices –Devices that are assigned the same major identification number are controlled by the same driver –Minor identification numbers enable the system to distinguish between devices of the same class –/usr/src/linux/Documentation/devices.txt Linux Device Driver brw-rw root disk 3, 1 May hda1 brw-rw root disk 3, 2 May hda2 brw-rw root disk 3, 3 May hda3 crw root root 4, 0 Jan tty0 crw root root 4, 1 Oct 31 14:55 tty1 crw-r--r-- 1 root root 10, 135 Jan rtc

Slide 20 Device special files are accessed via the virtual file system –System calls pass to the VFS, which in turn issues calls to device drivers –Most drivers implement common file operations such as read, write and seek –To support tasks such as ejecting a CD-ROM tray or retrieving status information from a printer, Linux provides the ioctl system call Linux Device Driver

Slide 21 I/O Interface Layers

Slide 22 Character Device I/O Transmits data as a stream of bytes Represented by a structure that contains the driver name and a pointer to the driver’s file_operations structure –Maintains the operations supported by the device driver –All registered drivers are referenced by a vector (major number) The file_operations structure –Stores functions called by the VFS when a system call accesses a device special file Driver 1 Driver 2 Driver 3 Driver n …… File Operations open close read open close read write seek ….. chardevs

Slide 23 Block Device I/O Block I/O subsystem –Complex then character device Buffering Caching Direct I/O and so on…. –Represented by block_device_operations Different than file_operations Extra operations for caching, buffering and queue management When data from a block device is requested, kernel first searches page cache –If found, data is copied to the process’s address space –Otherwise, typically added to a request queue –Direct I/O Enables driver to bypass kernel caches when accessing devices Some times, need to provide advanced algorithms for certain devices –Optimizing moving head storage

Slide 24 Network Device I/O Network I/O –Accessed via the IPC subsystem’s socket interface. –Network traffic can arrive at any time. The read and write operations of a device special file are not sufficient to access data from network devices Kernel uses net_device structures to describe network devices –No file_operations structure Packet processing –Complex. –Depends on different issues.

Slide 25 Unified Device Model Attempts to simplify device management in the kernel Relates device classes to system buses –Helps support hot-swappable devices –Power management UDM defines structures to represent devices, device drivers, device classes, busesBusName Devices Drivers List of Drivers List of Devices

Slide 26 Kernel Module A new kernel module can be added on the fly –While the OS is still running. –No need to re-compile the kernel. They are not user program. Some times they are also called “Loadable Kernel Modules” Several types of kernel module: –Device Drivers –Virtual terminals –Interpreters Only be controlled by super user. All installed modules: –/lib/modules/KERNEL_VERSION

Slide 27 Modules Module Kernel init_module()init_module()registerregister unregisterunregistercleanup_module()cleanup_module() insmod rmmod printk(..)printk(..) ….…. ….…. lsmod

Slide 28

Slide 29 Windows Device Driver

Slide 30 Windows Device Driver Organized into device driver stack. Device driver with different level of services. Device Object –Stores data for device Driver Object –Pointers to common driver routines Plug and Play (PnP) –Dynamically add new hardware devices

Slide 31 Windows Driver Model Windows Driver Model (WDM) –Bus driver Interact directly with bus (PCI, SCSI) Mandatory one bus driver per bus Provide generic functions for devices on bus –Filter driver Optional Modify device actions: encryption Add features: security checks –Function driver Implements main function of device

Slide 32

Slide 33 Things to do Understand the device characteristic and supported commands. Map device specific operations to Linux file operation Select the device name (user interface) –/dev/virtual_device Select a major and minor number (a device special file creation) for VFS interface Implement interface subroutines Compile the device driver Install the device driver module. Or Rebuild (compile) the kernel

Slide 34 Interface between Kernel & Driver User Process e.g. open(“/dev/xyz”, “r”) VFS switch Kernel Driver routine registered with VFS through file_operatins structure xyz_open(){…}xyz_close(){…} struct file_operatins fops={ xyz_open();xyz_close();…}; int init_module(void){ register_device(major_number, &fops); …}…. xyz.c

Slide 35 file_operation file_operation Structure From the file /usr/src/linux-2.4/include/linux/fs.h struct file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); ssize_t (*read) (struct file *, char *, size_t, loff_t *); ssize_t (*write) (struct file *, const char *, size_t, loff_t *); int (*readdir) (struct file *, void *, filldir_t); unsigned int (*poll) (struct file *, struct poll_table_struct *); int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) (struct inode *, struct file *); int (*flush) (struct file *); int (*release) (struct inode *, struct file *); int (*fsync) (struct file *, struct dentry *, int datasync); int (*fasync) (int, struct file *, int); int (*lock) (struct file *, int, struct file_lock *); ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *); ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *); ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); };

Slide 36 Things to remember Careful ! You are programming in kernel mode ! –Can’t use any standard functions. –Can only use kernel functions, which are the functions you can see in /proc/ksyms. –Version. Compile –Need to use special gcc options. Device special file mknod /dev/device_name device_type major_number minor_number

Slide 37 Lets check our driver code

Slide 38 Kernel 2.6.x Creation of Unified Device Model is one of the most important changes in 2.6 kernel. Expanded the limitation of the major number from 255 to Now more than one million sub devices per type is allowed. PnP support. Module subsystem is changed: –kbuild tool. –New file naming concept. Modules now has “.ko” extension.

Slide 39 Loooooooong way to go.…. We can propose a course on device driver as after all that we didn’t touch the following: –I/O Buffering –I/O Caching –Block devices –Network devices. –Module programming –Stacked Modules –Controller interaction –Interrupt processing

Slide 40 References OS books: –Operating System Concepts by Silberschatz & Galvin –Operating System by Garry Nutt. Linux Device Driver book – Linux Programmer’s Guide – The Linux Kernel Module Programming Guide – – Device Driver Development for Microsoft Windows –

Slide 41 Thanks