Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

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

3 Introduction to Device Driver What is Device Driver?

4 Introduction to Device Driver What is Device Driver? Software Hardware

5 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)

6 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

7 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 254 0 – 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);

8 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

9 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

10 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); }

11 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; }

12 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.

13 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.

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

15 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.

16 Environment & Policies Environment Same with Lab2 Policies Same with Lab2 Due : 3/25 11:59 PM Submission : (hard copy) : not decided yet. (soft copy) : cmkim@core.kaist.ac.kr

17 Appendix Queue Example

18 Appendix Queue Example

19 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; }

20

21 Thank You! Good Luck with your finishing.


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

Similar presentations


Ads by Google