The ‘ioctl’ driver-function On implementing a way to query and modify our UART’s baudrate via the ‘device-file’ abstraction.

Slides:



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

Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
Products Training -- DGUS LCM
Input and Output CS 215 Lecture #20.
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
I/O Multiplexing The role of the ‘poll()’ method in Linux device-driver operations.
CS 686: Programming SuperVGA Graphics Devices Introduction: An exercise in working with graphics file formats.
Creating a device-file node An introduction to some privileged Linux system-calls (needed for an upcoming programming exercise)
I/o multiplexing On adding a ‘poll()’ method to our character-mode device-driver for an 82573L network controller.
Computer Science 635 Advanced Systems Programming Fall 2007 Professor Allan Cruse.
The ‘system-call’ interface We see how an application program can invoke privileged kernel services.
Sleeping and waking An introduction to character-mode device-driver modules for Linux.
UNIX’s “grand illusion” How Linux makes a hardware device appear to be a ‘file’
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.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
UNIX Chapter 01 Overview of Operating Systems Mr. Mohammad A. Smirat.
© 2004, D. J. Foreman 1 O/S Organization. © 2004, D. J. Foreman 2 Topics  Basic functions of an OS ■ Dev mgmt ■ Process & resource mgmt ■ Memory mgmt.
Character Driver Issues Implementing ‘/dev/physmem’
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
Standard C Libraries Application Programmming Interface to System-Calls.
The ‘ioctl’ driver-function On implementing ‘show’ and ‘hide’ for the SiS 315 hardware cursor.
Standard C Library Application Programming Interface to System-Calls.
The UART alternative Substituting input from our PC’s serial-port for local keystrokes when we do ‘single-stepping’
Our ‘nic.c’ module We create a ‘character-mode’ device-driver for the 82573L NIC to use in futrure experiments.
Adjusting out device-driver Here we complete the job of modifying our ‘nicf.c’ Linux driver to support ‘raw’ packet-transfers.
CS 686: Programming SuperVGA Graphics Devices Introduction: An exercise in working with graphics file formats.
Looking at kernel objects How a character-mode Linux device driver can be useful in viewing a ‘net_device’ structure.
A device-driver for Video Memory Introduction to basic principles of the PC’s graphics display.
The ‘mmap()’ method Adding the ‘mmap()’ capability to our ‘vram.c’ device-driver.
Multiplexing i/o A look at some alternatives under Linux for dealing concurrently with multiple sources of device-input.
Notes for Lab 10 On implementing ‘show’ and ‘hide’ for the SiS 315 hardware cursor.
Copyright Arshi Khan1 System Programming Instructor Arshi Khan.
An Introduction to Device Drivers Sarah Diesburg COP 5641 / CIS 4930.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Device Management. Serial Port Serial Device Serial Device Memory CPU Printer Terminal Modem Mouse etc.
Operating System Program 5 I/O System DMA Device Driver.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Computer Organization
UART and UART Driver B. Ramamurthy.
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
Slide 5-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5.
Operating System What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. An operating.
‘Identify Device’ A mandatory command that allows device-drivers to query any standard IDE/ATA hard disk for its parameters.
SAPC Hardware Pentium CPU (or 486) 4M usable memory no hard disk; boot from floppy no keyboard or monitor or mouse COM2 serial port: used for console i/o.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
An Introduction to Device Drivers Ted Baker  Andy Wang COP 5641 / CIS 4930.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
A. Frank - P. Weisberg Operating Systems Structure of Operating Systems.
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.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 1.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Linux Details: Device Drivers
UART and UART Driver B. Ramamurthy.
Want to play a game? – Linux Kernel Modules
An Introduction to Device Drivers
Operation System Program 4
UART and UART Driver B. Ramamurthy.
Computer Science 210 Computer Organization
Chapter 2: The Linux System Part 1
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
CS-3013 Operating Systems Hugh C. Lauer
Computer Science 210 Computer Organization
Linux Details: Device Drivers
Computer System Laboratory
Presentation transcript:

The ‘ioctl’ driver-function On implementing a way to query and modify our UART’s baudrate via the ‘device-file’ abstraction

‘struct file_operations’ For a Linux device-driver’s ‘module_init()’ function, there are two main actions: –Initializing the driver’s global data-structures (this includes verifying the device’s presence) –Registering the driver’s service-functions with the kernel (i.e., the ‘file_operations’ structure) The driver’s ‘module_exit()’ function then has the duty to ‘unregister’ those services

Driver services For character-mode device-drivers (like ‘dram.c’, ‘cmos.c’ and ‘vram.c’), we have implemented some (or all) of the following service-functions (i.e., driver ‘methods’): – read() – llseek() – write() – mmap()

The ‘file’ paradigm The UNIX approach to device-control is to create objects that represent i/o-devices, but which behave like ‘files’ do, insofar as the application programmer is concerned So ‘read()’, ‘lseek()’, ‘write()’ and ‘mmap() use the same function-call syntax – and in most respects the same semantics – for both ordinary ‘files’ and ‘device-files’

An imperfect paradigm But often there are a few ways in which the file-object paradigm doesn’t quite fit with important features of an i/o device In these cases, device-drivers can provide a ‘workaround’ that allows applications to perform device-actions that deviate from customary ‘read/write/seek’ file-like actions This ‘workaround’ mechanism is ‘ioctl()’

The serial UART Our PC’s serial UART device offers us an easy example of some desirable behavior that’s outside the traditional ‘file’ paradigm In order to use our ‘dev/vram’ device-file for communications with computers that we can’t control, we may need to adjust our UART’s communication parameters How can a program change ‘baudrate’?

Our ‘baudrate.c’ module These techniques are demonstrated in this device-driver module’s ‘ioctl()’ function Two IOCTL services are implemented: #define GET_BAUDRATE0 #define SET_BAUDRATE1 Applications can open the device-file and invoke an ‘ioctl’ system-call; for example: int fd = open( “/dev/uart”, O_RDWR ); ioctl( fd, GET_BAUDRATE, &baudrate );

Recall role of a device-driver user application standard “runtime” libraries call ret user spacekernel space Operating System kernel syscall sysret device-driver module call ret hardware device out in operating parameters RAM A device-driver is a software module that controls a hardware device in response to OS kernel requests relayed, often, from an application

UART’s baudrate-control MSB LSB i/o port 0x03F8 i/o port 0x03F9 i/o port 0x03FB DLABDLAB LINE CONTROL REGISTER DIVISOR LATCH (bits 7..0) DIVISOR LATCH (bits 15..8) BREAKBREAK data bits stop bits parity controls

Algorithm to ‘get’ baudrate Input (and save) the LINE_CONTROL Set DLAB-bit in LINE_CONTROL to 1 Input (and save) the DIVISOR_LATCH Restore LINE_CONTROL to former value Compute ‘baudrate’ from divisor_latch: baudrate  / divisor_latch Return this current ‘baudrate’ value

Algorithm to ‘set’ baudrate Receive ‘baudrate’ as function-argument Verify that argument is within valid range Compute ‘divisor_latch’ from ‘baudrate’: divisor_latch  / baudrate Input (and save) the LINE_CONTROL Set DLAB-bit in LINE_CONTROL to 1 Output ‘divisor_latch’ to UART register Restore LINE_CONTROL to former value

Demo-program: ‘setbaud.cpp’ This application-program lets a user query or modify the UART’s current baudrate in a convenient manner – without requiring any ‘special’ privileges (don’t need ‘iopl3’) To see the current baudrate: $./setbaud To change the current baudrate: $./setbaud 2400

In-class exercise Can you modify our ‘baudrate.c’ driver so it implements an additional ‘ioctl’ service: # define GET_LINECTRL2 Then add an extra ‘ioctl’ system-call in our ‘setbaud.cpp’ application so that it displays the UART’s current data-format (as well as baudrate) using format similar to 8-N-1 HINT: look at driver’s ‘get_info()’ function