Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /

Slides:



Advertisements
Similar presentations
DEVICE DRIVER VINOD KAMATH CS691X PROJECT WORK. Introduction How to write/install device drivers Systems, Kernel Programming Character, Block and Network.
Advertisements

Linux device-driver issues
Linux Device Drivers & Project3 preview CSC345. Project 3 Preview Write a device driver for a pseudo stack device Idea from
B LOCK D RIVERS Ted Baker Andy Wang CIS 4930 / COP 5641.
Lecture 101 Lecture 10: Kernel Modules and Device Drivers ECE 412: Microcomputer Laboratory.
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
RT_FIFO, Device driver.
Sogang University Advanced Operating Systems (Linux Device Drivers) Advanced Operating Systems (Linux Device Drivers) Sang Gue Oh, Ph.D.
Computer System Laboratory
Operating Systems Lecture 7.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
USERSPACE I/O Reporter: R 張凱富.
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
File and I/O system calls int open(const char* path, int flags, mode_t modes) int creat(const char *path, mode_t mode) ssize_t read(int fd, void *buf,
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
C Intro.
Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
CSE 451: Operating Systems Section 7 File Systems; Project 3.
52 Advanced Operating Systems Writing Device Drivers.
Processes CSCI 444/544 Operating Systems Fall 2008.
63 UQC152H3 Advanced OS Writing a Device Driver. 64 The SCULL Device Driver Simple Character Utility for Loading Localities 6 devices types –Scull-03.
Embedded System Programming Introduction to Device Drivers.
1 I/O Management in Representative Operating Systems.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Data Structures in the Kernel Sarah Diesburg COP 5641.
M. Muztaba Fuad Advanced Operating System Project Device Drivers.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
Operating System Program 5 I/O System DMA Device Driver.
Data Structures - Queues
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
Real-time Systems Lab, Computer Science and Engineering, ASU Linux Input Systems (ESP – Fall 2014) Computer Science & Engineering Department Arizona State.
1 Homework Introduction to HW7 –Complexity similar to HW6 –Don’t wait until last minute to start on it File Access will be needed in HW8.
COMP 3438 – Part I - Lecture 4 Introduction to Device Drivers Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
LWIP TCP/IP Stack 김백규.
1 Comp 104: Operating Systems Concepts Devices. 2 Today Devices –Introduction –Handling I/O Device handling Buffering and caching.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
UNIX Files File organization and a few primitives.
Implementation of Embedded OS Lab3 Linux Kernel Modules.
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
1 Chapter 4. INTERNAL REPRESENTATION OF FILES THE DESIGN OF THE UNIX OPERATING SYSTEM Maurice J. bach Prentice Hall.
Interfacing Device Drivers with the Kernel
B LOCK L AYER S UBSYSTEM Linux Kernel Programming CIS 4930/COP 5641.
Project 4. “File System Implementation”
CSE 466 – Fall Introduction - 1 User / Kernel Space Physical Memory mem mapped I/O kernel code user pages user code GPLR virtual kernel C
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
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
Documentation Javadocs. Design/Documentation An essential ingredient of good Object Oriented programming is known as design by contract. This means that.
4P13 Week 9 Talking Points
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
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.
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
Discussions on hw1 Objectives –Modify I/O library for serial ports –change from ring buffer to queue –implement interrupts I/O Library TTY0TTYn testio.
A simple control application with Real Time Linux Peter Wurmsdobler Real Time Systems Lab Jong-Koo, Lim Paper Survey.
Lecture 3 Module Programming and Device Driver (Homework#1 included)
Linux Kernel Module Programming
Computer System Laboratory
Linux Kernel Driver.
IB Computer Science Topic 2.1.1
Operation System Program 4
Introduction to Linux Device Drivers
Page Replacement.
Practical Session 11 File Systems & Midterm 2013
Implementation of Embedded OS
Computer System Laboratory
Loadable Kernel Modules
Mr. M. D. Jamadar Assistant Professor
Presentation transcript:

Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /

Contents Introduction to Device Driver Implementation of Device Driver Usage of Device Driver Problems Environment & Policies

Introduction to Device Driver What is Device Driver?

Introduction to Device Driver What is Device Driver? Software Hardware

Introduction to Device Driver Inside of Device Driver Basically, it is usually generated by C code. In other word, it can be simple as much as hello world in C programming. You can freely imagine your device driver structure. Even though it is not linked with real HW, it works. Closely related with kernel. (use of system calls)

Introduction to Device Driver Kinds of Device Drivers Character Device Bypass Buffer Cache Serialized Data User receives Row Data of the device Ex. Terminal, video card, sound card… Block Device Through Buffer Cache Random Accessible Ex. HDD, CDROM … Network Device Ex. Ethernet

Introduction to Device Driver How can we access to the device driver? Through Device File (special file) In the previous lab, you heard that /dev/sdb to mount. Char device and Block device have this file. Mknod /dev/dummy c – creation of the device file. Real Usage (system call) fd = open("/ dev/dummy ", O_RDWR); write(fd,buf,1); read(fd,buf,1); close(fd);

Implementation of Device Driver Specification of Dummy Device Driver No linkage with Real HW. Using printk, only printout the name of the device driver operation called by a user. Implementations Module init and cleanup 4 Operations in Dummy Device Driver dummy_read : read system call dummy_write : write system call dummy_open : open system call dummy_release : close system call

Implementation of Device Driver How can we implement it? Initialization (in init_module function) Mapping a device file with the device driver Registration of a Char Device : offered by OS Needs Major Number, Name, and File_operation Structure of the device driver. int register_chrdev( unsigned int major, const * name, struct file_operations * fops); struct file_operations dummy_fops = { open : dummy_open,// open read : dummy_read, // read write : dummy_write, // write release : dummy_release, // release }; Mapping system calls with the internal functions of the device drivers

Implementation of Device Driver How can we implement it? #define DUMMY_MAJOR_NUMBER 254 struct file_operations dummy_fops = { open : dummy_open,// open read : dummy_read, // read write : dummy_write, // write release : dummy_release, // release }; char devicename[20]; int init_module(void) { printk("init module\n"); strcpy(devicename, "Dummy_Driver"); register_chrdev( DUMMY_MAJOR_NUMBER, devicename, &dummy_fops); return 0; } void cleanup_module(void) { printk("Clean Up Module\n"); unregister_chrdev(DUMMY_MAJOR_NUMBER,devicename); }

Implementation of Device Driver How can we implement it? How can we build this? T.A. and the material will show you the way. int dummy_open(struct inode *inode, struct file *file) { printk("Open call \n"); return 0; } int dummy_open(struct inode *inode, struct file *file) { printk("Open call \n"); return 0; } ssize_t dummy_read(struct file *file, char *buffer, size_t length, loff_t *offset) { printk("Here is Read Call \n"); buffer[0] = 0x34; return 0; } ssize_t dummy_read(struct file *file, char *buffer, size_t length, loff_t *offset) { printk("Here is Read Call \n"); buffer[0] = 0x34; return 0; } ssize_t dummy_write(struct file *file, const char *buffer, size_t length, loff_t *offset) { printk("Here is Write Call [%x]\n ",buffer[0]); return 0; } ssize_t dummy_write(struct file *file, const char *buffer, size_t length, loff_t *offset) { printk("Here is Write Call [%x]\n ",buffer[0]); return 0; }

Usage of Device Driver Module Instructions Insmod dummy.ko -> the module output file built Rmmod dummy Check the kernel message -> since we used printk to see the device driver operations. Test this through your own user application. Simple C program appeared in the material. Insmod should be done first before executing the user application.

Problems 1. device driver with FIFO queue FIFO Queue structure In (write) & Creation of Entry in the Queue Out (read) & Deletion of Entry APP1 APP2 Check the written data sequence and the read data sequence are same or not.

Problems 2. flush operation makes queue empty APP1 APP2 APP3 Flush OP Thrash all the entries in the queue

Problems 3. Make a block device driver. With simple write and read operation. The unit of data of read and write should be a block. (kernel structure should be used) Hints are given in the material. Further hints will be given by T.A. Not Necessary, it is the extra-credit problem. But should be in the report.

Environment & Policies Environment Same with Lab2 Policies Same with Lab2 Due : 3/25 11:59 PM Submission : (hard copy) : not decided yet. (soft copy) :

Appendix Queue Example

Appendix Queue Example

Appendix Queue Example #define QUEUE_SIZE 1024 typedef { int head, tail; int item[QUEUE_SIZE]; } CQ_t; static inline void InitCQ(CQ_t *q) { q->head = q->tail = 0; } static inline int IsFull(CQ_t *q) { return ( (q->head+1)%QUEUE_SIZE == q->tail ); } static inline int IsEmpty(CQ_t *q) { return (q->head == q->tail); } #define QUEUE_SIZE 1024 typedef { int head, tail; int item[QUEUE_SIZE]; } CQ_t; static inline void InitCQ(CQ_t *q) { q->head = q->tail = 0; } static inline int IsFull(CQ_t *q) { return ( (q->head+1)%QUEUE_SIZE == q->tail ); } static inline int IsEmpty(CQ_t *q) { return (q->head == q->tail); } int Queue(CQ_t *q, int value) { if (q==NULL) return -1; if (IsFull(q)) return -2; q->item[q->head] = value; q->head = (q->head + 1)%QUEUE_SIZE; return 0; } int Dequeue(CQ_t *q, int *value) { if (q==NULL || value==NULL) return -1; if (IsEmpty(q)) return -2; *value = q->item[q->tail]; q->tail = (q->tail + 1)%QUEUE_SIZE; return 0; } int Queue(CQ_t *q, int value) { if (q==NULL) return -1; if (IsFull(q)) return -2; q->item[q->head] = value; q->head = (q->head + 1)%QUEUE_SIZE; return 0; } int Dequeue(CQ_t *q, int *value) { if (q==NULL || value==NULL) return -1; if (IsEmpty(q)) return -2; *value = q->item[q->tail]; q->tail = (q->tail + 1)%QUEUE_SIZE; return 0; }

Thank You! Good Luck with your finishing.