FAME Operatinf Systems - Modules

Size: px
Start display at page:

Download "FAME Operatinf Systems - Modules"

Transcription

1 FAME Operatinf Systems - Modules 2012 David Picard Contributions: Arnaud Revel, Mickaël Maillard picard@ensea.fr

2 Introduction Linux is not a monolithic pile of code anymore Possibility to add/remove functionalities (code) dynamically Avoid bloated kernel at runtime No need to compile the kernel each time you want to add or remove functionalities Not even necessary to reboot the OS Modules are used to provide device drivers Or also to provide functionalities that need access to supervisor rights

3 Kernel sources To compile a module, the sources are needed (usually in /usr/src/linux). -- 3rdparty -- Documentation -- arch -- block -- crypto -- drivers -- fs -- include -- init -- ipc -- kernel -- lib -- mm -- net -- scripts -- security -- sound -- usr

4 Compilation Heavy use of Makefile obj-m := mon_mondule_a_moi.o module objs := mon_mondule_a_moi.o KERNEL_SOURCE = /usr/src/linux $(shell uname -r) all : make C $ (KERNEL_SOURCE) M=$(PWD) modules clean : make C $ (KERNEL_SOURCE) M=$(PWD) clean install : make C $ (KERNEL_SOURCE) M=$(PWD) modules install

5 Modules management insmod: load a module directly into the running kernel without dependancy checking (insert) modprobe: load a module with dependancy checking rmmod: unload the module (remove) lsmod: list loaded modules modinfo: print information on module (loaded or not)

6 Simplest example #include <linux/module.h> #include <linux/kernel.h> / Pour KERN INFO / MODULE_DESCRIPTION( Hello World module ); MODULE_AUTHOR( Pierre Ficheux, Open Wide ); MODULE_LICENSE( GPL ); static int init hello_init( void ) { printk(kern_info Hello World\n ); return 0; } static void exit hello_exit(void) { printk(kern_info Goodbye, cruel world!\n ); } module_init(hello_init); module_exit(hello_exit);

7 Module parameters Declaration of parameters using macros: Usage: module_param(var,type, rights) module_param_array(var, type, addr, rights) module_param_string(name_in_modinfo, var, taille, rights) int myint = 3; module_param(myint, int, 0); Loading: modprobe monmodule myint=2

8 procfs procfs (process file system) is a pseudo filesystem (not on real hdd) mounted on /proc useful to access to information on the running kernel No corresponding file on any block device Ex: info on processes ( /proc/[0-9]+/) Debugging,...

9 Adding a procfs entry struct proc_dir_entry* create_proc_entry(const char* name, mode_t mode, struct proc_dir_entry* parent); name: name of the file Mode: permission rights parent: parent entry in procfs (NULL if root) Returns a structure representing the entry in the procfs Support for complex paths ( /proc/some/complex/path )

10 Remove void remove_proc_entry(const char* name, struct proc_dir_entry* parent); name: name of file parent: parent entry in procfs Support for complex paths ( /proc/some/complex/path )

11 Communication struct proc_dir_entry* entry; entry->read_proc = read_func; entry->write_proc = write_func; entry is the structure return by the create() call read_proc() is the function used by a read() call on the file of the procfs (careful: reverse point of view) write_proc is the function used by a write() call on the file of the procfs (careful: reverse point of view)

12 read int read_func(char* page, char** start, off_t off, int count, int* eof, void* data); page: address to fill (destination buffer) off: starting offset count: max number of byte to write eof: 1 if count > than available data start:??? data: up to the module developper

13 Read example char* message = read() call ; static int read_func (char page, char start, off_t off, int count, int eof, void data ) { int len = 0; len += sprintf ( page + len, %s\n, message ) ; return len ; }

14 write int write_func(struct file* file, const char* buffer, unsigned long count, void* data); count: max number of byte to read from the buffer file:??? data: up to module developpers

15 Write example static int write_func (struct file file, const char buffer, unsigned long count, void data ) { int len = count; if(copy_from_user(message, buffer, count)) { return EFAULT; } message[count] = 0; printk(kern_info Modification in message : %s\n, message); } return len;

16 Device entry Device entry: interaction with a device through a file Creation: # mknod /dev/name_of_device_file c major minor major: number defining the class of device hdd, usb, pci... minor: specific instance o the device (model, manufacturer) Different manufacturers Same driver

17 Types 3 block First MFM, RLL and IDE hard disk/cd-rom interface 0 = /dev/hda Master: whole disk (or CD-ROM) 64 = /dev/hdb Slave: whole disk (or CD-ROM) For partitions, add to the whole disk device number: 0 = /dev/hd? Whole disk 1 = /dev/hd?1 First partition 2 = /dev/hd?2 Second partition = /dev/hd?63 63rd partition For Linux/i386, partitions 1-4 are the primary partitions, and 5 and above are logical partitions. Other versions of Linux use partitioning schemes appropriate to their respective architectures. 4 char TTY devices 0 = /dev/tty0 Current virtual console 1 = /dev/tty1 First virtual console = /dev/tty63 63rd virtual console 64 = /dev/ttys0 First UART serial port = /dev/ttys nd UART serial port UART serial ports refer to 8250/16450/16550 series devices.

18 Drivers: implement related ops struct file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); ssize_t (*read) (struct file *, char user *, size_t, loff_t *); ssize_t (*write) (struct file *, const char user *, size_t, loff_t *); ssize_t (*aio_read) (struct kiocb *, const struct iovec *, ulong, loff_t); ssize_t (*aio_write) (struct kiocb *, const struct iovec *, ulong, loff_t); int (*readdir) (struct file *, void *, filldir_t); uint (*poll) (struct file *, struct poll_table_struct *); int (*ioctl) (struct inode *, struct file *, uint, ulong); long (*unlocked_ioctl) (struct file *, uint, ulong); long (*compat_ioctl) (struct file *, uint, ulong); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) (struct inode *, struct file *); int (*flush) (struct file *, fl_owner_t id); int (*release) (struct inode *, struct file *); int (*fsync) (struct file *, struct dentry *, int datasync); int (*aio_fsync) (struct kiocb *, int datasync); int (*fasync) (int, struct file *, int); int (*lock) (struct file *, int, struct file_lock *); ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *); ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); ulong (*get_unmapped_area)(struct file *, ulong, ulong, ulong, ulong); int (*check_flags)(int); int (*dir_notify)(struct file *filp, ulong arg); int (*flock) (struct file *, int, struct file_lock *); ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, uint); ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, uint); };

19 Operations? No need to redefine all operations Open: initialize some device related resources Release: free these resources read/write: exchange data with user space static struct file_operations mon_driver_fops = {.owner =.read =.write =.open = THIS_MODULE, my_driver_read, my_driver_write, my_driver_open,.release = my_driver_release, };

20 #include <linux/kernel.h> /* printk() */ #include <linux/module.h> /* modules */ #include <linux/fs.h> /* file_operations */ MODULE_DESCRIPTION("mydriver1"); MODULE_AUTHOR("Stelian Pop/Pierre Ficheux, Open Wide"); MODULE_LICENSE("GPL"); /* Arguments */ static int major = 0; /* Major number */ module_param(major, int, 0644); MODULE_PARM_DESC(major, "Static major number (none = dynamic)"); /* File operations */ static ssize_t mydriver1_read(struct file *file, char *buf, size_t count, loff_t *ppos) { printk(kern_info "mydriver1: read()\n"); return count; } static ssize_t mydriver1_write(struct file *file, const char *buf, size_t count, loff_t *ppos) { printk(kern_info "mydriver1: write()\n"); return count; } static int mydriver1_open(struct inode *inode, struct file *file) { printk(kern_info "mydriver1: open()\n"); return 0; } static int mydriver1_release(struct inode *inode, struct file *file) { printk(kern_info "mydriver1: release()\n"); return 0; }

21 static struct file_operations mydriver1_fops = {.owner = THIS_MODULE,.read = mydriver1_read,.write = mydriver1_write,.open = mydriver1_open,.release = mydriver1_release, }; /* Init and Exit */ static int init mydriver1_init(void) { int ret; ret = register_chrdev(major, "mydriver1", &mydriver1_fops); if (ret < 0) { printk(kern_warning "mydriver1: unable to get a major\n"); return ret; } if (major == 0) major = ret; /* dynamic value */ printk(kern_info "mydriver1: successfully loaded with major %d\n", major); return 0; } static void exit mydriver1_exit(void) { if (unregister_chrdev(major, "mydriver1") < 0) { printk(kern_warning "mydriver1: error while unregistering\n"); return; } printk(kern_info "mydriver1: successfully unloaded\n"); } /* Module entry points */ module_init(mydriver1_init); module_exit(mydriver1_exit);

22 I/O Ports Each device has a range of addresses on some I/O bus Theses addresses are called I/O ports The kernel has special routines to read or write to these addresses Some addresses can be reserved such that the module has exclusive access to them

23 How to int inb(int read_addr) Read on byte from the I/O port read_addr void outb(int write_addr, char value) Write one byte to the I/O port write_addr One routine per type of data (b for byte, w for 16bits, l for 32bits)

24 Example (from LDD3) ÉCOLE NATIONALE SUPÉRIEURE DE L'ÉLECTRONIQUE ET DE SES APPLICATIONS

25 Example /* default is the first printer port on PC's */ static unsigned long base = 0x378; /* Version-specific methods for the fops structure. */ ssize_t short_write(struct file *filp, const char user *buf, size_t count, loff_t *f_pos) { int retval = count; unsigned char *kbuf = kmalloc(count, GFP_KERNEL), *ptr; if (!kbuf) return -ENOMEM; if (copy_from_user(kbuf, buf, count)) return -EFAULT; ptr = kbuf; } while (count--) { outb(*(ptr++), base); wmb(); } return retval; struct file_operations short_fops = {.owner = THIS_MODULE,.write = short_write, };

26 I/O memory Modern devices have addressable memory zones. Control registers (similar to I/O ports) Data storage (video texture, network packets,...) The kernel offers to map these zone into the main memory This mapping is called I/O memory

27 Usage Mapping: struct resource *request_mem_region(unsigned long start, unsigned long len, char *name); Unmapping : Test: void release_mem_region(unsigned long start, unsigned long len); int check_mem_region(unsigned long start, unsigned long len); Remapping : void *ioremap(unsigned long phys_addr, unsigned long size); The returned pointer points towards the devices memory Can not use this pointer as any other pointer (because of instruction reordering)!

28 Communication with I/O memory Read: Write: Loop: unsigned int ioread8(void *addr); unsigned int ioread16(void *addr); unsigned int ioread32(void *addr); void iowrite8(u8 value, void *addr); void iowrite16(u16 value, void *addr); void iowrite32(u32 value, void *addr); void ioread8_rep(void *addr, void *buf, unsigned long count);...

29 Interrupts int request_irq(unsigned int irq, void (*gest)(int, void *, struct pt_regs *), unsigned long drap_interrupt, const char *devname, void *dev_id) Associate an interrupt number (irq) with a handler function gest who handles the interruption for device devname identified by dev_id The handler returns: IRQ_HANDLED if handled correctly IRQ_NONE Deregister the handler with void free_irq(unsigned int irq, void *dev_id)

30 Timer void fastcall init_timer(struct timer_list * timer): creation of a programmable timer timer_list structure with field function called each time the time quantum is reached and data defines the parameters to transmit to the function int mod_timer(struct timer_list * timer, unsigned long expires): activate timer at the specified time in number of tick starting from kernel boot If you want to activate launch the function in 100 ticks, expires is jiffies+100 For periodical timers, need to reactivate at each use (like for signals)

31 Example #include <linux/timer.h> #define INTERVALLE 100 static struct timer_list timer; static void mytimer(unsigned long data) {... /* periodical timer */ mod_timer(&timer,jiffies+100);... } static int init module_init(void) {... init_timer(&timer); timer.function = mytimer; timer.data = 0; mod_timer(&timer, jiffies + INTERVALLE); }

32 Mutex Critical resources inside the kernel: up to the modules to limit access DECLARE_MUTEX(sem) Declare a mutex mutex_lock(&sem) Acquire the mutex mutex_unlock(&sem) Free the mutex

33 Management of longer interrupts Sometimes the processing of an interrupt can be heavy The kernel has to stay the least possible in an interrupt (because it blocks the system) Two step procedure: Step top-half: rapidly returns from interrupt but adds the processing to a tasklet list (low latency) or a workqueue Step bottom-half: asynchronous management of the processing by the tasklet or the workqueue

34 Tasklets Tasklets are called only in interrupts Creating a tasklet is demanding the kernel to execute an atomic task later (asynchronous) When it is possible (low load) Never beyond one tick

35 Tasklets DECLARE_TASKLET(name, func, data) Declares tasklet with name name, associated with function func with parameters data tasklet_schedule(&name) Ask the kernel to schedule the tasklet tasklet_hi_schedule(&name) Scheduling with high priority (for audio buffer for example) DECLARE_TASKLET_DISABLED(), tasklet_disable(), tasklet_disable_nosync() Deactivate a tasklet tasklet_enable() Reactivate a tasklet tasklet_kill() Delete a tasklet

36 Example #include <linux/interrupt.h> void tasklet_function(unsigned long); char tasklet_data[64]; DECLARE_TASKLET(test_tasklet, tasklet_function, (unsigned long) &tasklet_data); void tasklet_function(unsigned long data) { struct timeval now; do_gettimeofday(&now); printk("%s at %ld,%ld\n", (char *) data, now.tv_sec, now.tv_usec); } int init_module(void) { sprintf(tasklet_data,"%s\n", "Linux tasklet called in init_module"); tasklet_schedule(&test_tasklet); }

37 Workqueue Inside a kernel process context More flexible, can be preempted and resumed Asynchronous execution Creation: create_workqueue(name) Create the queu and return a pointer struct workqueue_struct Destruction: void destroy_workqueue(struct workqueue_struct *queue) Free the file

38 How to DECLARE_WORK(name,function,data) Declare a work int queue_work(struct workqueue_struct *wq, struct work_struct *work) Put the work in the file int queue_delayed_work(struct workqueue_struct *wq, struct work_struct *work, unsigned long delay) Add work to file, but no execution before delay ticks int cancel_delayed_work(struct work_struct *work) Remove work from queue void flush_workqueue(struct workqueue_struct *queue) Clear the queue

CS5460/6460: Operating Systems. Lecture 24: Device drivers. Anton Burtsev April, 2014

CS5460/6460: Operating Systems. Lecture 24: Device drivers. Anton Burtsev April, 2014 CS5460/6460: Operating Systems Lecture 24: Device drivers Anton Burtsev April, 2014 Device drivers Conceptually Implement interface to hardware Expose some high-level interface to the kernel or applications

More information

Virtual File System (VFS) Implementation in Linux. Tushar B. Kute,

Virtual File System (VFS) Implementation in Linux. Tushar B. Kute, Virtual File System (VFS) Implementation in Linux Tushar B. Kute, http://tusharkute.com Virtual File System The Linux kernel implements the concept of Virtual File System (VFS, originally Virtual Filesystem

More information

CS 423 Operating System Design: Introduction to Linux Kernel Programming (MP1 Q&A)

CS 423 Operating System Design: Introduction to Linux Kernel Programming (MP1 Q&A) CS 423 Operating System Design: Introduction to Linux Kernel Programming (MP1 Q&A) Professor Adam Bates Fall 2018 Learning Objectives: Talk about the relevant skills required in MP1 Announcements: MP1

More information

Unix (Linux) Device Drivers

Unix (Linux) Device Drivers Unix (Linux) Device Drivers Kernel module that handles the interaction with an specific hardware device, hiding its operational details behind a common interface Three basic categories Character Block

More information

Finish up OS topics Group plans

Finish up OS topics Group plans Finish up OS topics Group plans Today Finish up and review Linux device driver stuff Walk example again See how it all goes together Discuss talking to MMIO RTOS (on board) Deferred interrupts Discussion

More information

CS 378 (Spring 2003)

CS 378 (Spring 2003) Department of Computer Sciences THE UNIVERSITY OF TEXAS AT AUSTIN CS 378 (Spring 2003) Linux Kernel Programming Yongguang Zhang (ygz@cs.utexas.edu) Copyright 2003, Yongguang Zhang This Lecture Device Driver

More information

Linux Device Drivers Interrupt Requests

Linux Device Drivers Interrupt Requests Overview 1 2 3 Installation of an interrupt handler Interface /proc 4 5 6 7 primitive devices can be managed only with I/O regions, most devices require a more complicated approach, devices cooperate with

More information

Loadable Kernel Module

Loadable Kernel Module Instituto Superior de Engenharia do Porto Mestrado em Engenharia Eletrotécnica e de Computadores Arquitetura de Computadores Loadable Kernel Module The objective of this lesson is to analyze, compile and

More information

Kernel Modules. Kartik Gopalan

Kernel Modules. Kartik Gopalan Kernel Modules Kartik Gopalan Kernel Modules Allow code to be added to the kernel, dynamically Only those modules that are needed are loaded. Unload when no longer required - frees up memory and other

More information

/dev/hello_world: A Simple Introduction to Device Drivers under Linux

/dev/hello_world: A Simple Introduction to Device Drivers under Linux Published on Linux DevCenter (http://www.linuxdevcenter.com/) See this if you're having trouble printing code examples /dev/hello_world: A Simple Introduction to Device Drivers under Linux by Valerie Henson

More information

Linux Device Drivers. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5. Interrupts

Linux Device Drivers. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5. Interrupts Linux Device Drivers Dr. Wolfgang Koch Friedrich Schiller University Jena Department of Mathematics and Computer Science Jena, Germany wolfgang.koch@uni-jena.de Linux Device Drivers 1. Introduction 2.

More information

Linux drivers - Exercise

Linux drivers - Exercise Embedded Realtime Software Linux drivers - Exercise Scope Keywords Prerequisites Contact Learn how to implement a device driver for the Linux OS. Linux, driver Linux basic knowledges Roberto Bucher, roberto.bucher@supsi.ch

More information

Linux Kernel Modules & Device Drivers April 9, 2012

Linux Kernel Modules & Device Drivers April 9, 2012 Linux Kernel Modules & Device Drivers April 9, 2012 Pacific University 1 Resources Linux Device Drivers,3rd Edition, Corbet, Rubini, Kroah- Hartman; O'Reilly kernel 2.6.10 we will use 3.1.9 The current

More information

Linux Kernel Module Programming. Tushar B. Kute,

Linux Kernel Module Programming. Tushar B. Kute, Linux Kernel Module Programming Tushar B. Kute, http://tusharkute.com Kernel Modules Kernel modules are piece of code, that can be loaded and unloaded from kernel on demand. Kernel modules offers an easy

More information

NPTEL Course Jan K. Gopinath Indian Institute of Science

NPTEL Course Jan K. Gopinath Indian Institute of Science Storage Systems NPTEL Course Jan 2012 (Lecture 17) K. Gopinath Indian Institute of Science Accessing Devices/Device Driver Many ways to access devices under linux Non-block based devices ( char ) - stream

More information

Device Drivers. CS449 Fall 2017

Device Drivers. CS449 Fall 2017 Device Drivers CS449 Fall 2017 Software Layers User-level I/O so7ware & libraries Device-independent OS so7ware Device drivers Interrupt handlers User OperaEng system (kernel) Hardware Device Drivers User

More information

MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT

MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT University of Illinois at Urbana-Champaign Department of Computer Science CS423 Fall 2011 Keun Soo Yim GOAL A Linux kernel module to profile VM system events

More information

Designing and developing device drivers. Coding drivers

Designing and developing device drivers. Coding drivers Designing and developing device drivers Coding drivers Registering a driver 2 calls to register a driver defined in int register_chrdev_region(dev_t first, unsigned int count, char *name);

More information

Abstraction via the OS. Device Drivers. Software Layers. Device Drivers. Types of Devices. Mechanism vs. Policy. Jonathan Misurda

Abstraction via the OS. Device Drivers. Software Layers. Device Drivers. Types of Devices. Mechanism vs. Policy. Jonathan Misurda Abstraction via the OS Device Drivers Jonathan Misurda jmisurda@cs.pitt.edu Software Layers level I/O software & libraries Device independent OS software Device drivers Interrupt handlers Hardware Operating

More information

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Disk and File System

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Disk and File System ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective Part I: Operating system overview: Disk and File System 1 What Disks Look Like Hitachi Deskstar T7K500 SATA 2

More information

Linux Device Driver. Analog/Digital Signal Interfacing

Linux Device Driver. Analog/Digital Signal Interfacing Linux Device Driver Analog/Digital Signal Interfacing User Program & Kernel Interface Loadable Kernel Module(LKM) A new kernel module can be added on the fly (while OS is still running) LKMs are often

More information

Software Layers. Device Drivers 4/15/2013. User

Software Layers. Device Drivers 4/15/2013. User Software Layers Device Drivers User-level I/O software & libraries Device-independent OS software Device drivers Interrupt handlers Hardware User Operating system (kernel) Abstraction via the OS Device

More information

University of Texas at Arlington. CSE Spring 2018 Operating Systems Project 4a - The /Proc File Systems and mmap. Instructor: Jia Rao

University of Texas at Arlington. CSE Spring 2018 Operating Systems Project 4a - The /Proc File Systems and mmap. Instructor: Jia Rao University of Texas at Arlington CSE 3320 - Spring 2018 Operating Systems Project 4a - The /Proc File Systems and mmap Instructor: Jia Rao Introduction Points Possible: 100 Handed out: Apr. 20, 2018 Due

More information

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University Prof. Peng Li TA: Andrew Targhetta (Lab exercise created by A Targhetta and P Gratz) Laboratory

More information

REVISION HISTORY NUMBER DATE DESCRIPTION NAME

REVISION HISTORY NUMBER DATE DESCRIPTION NAME i ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME iii Contents 1 The structure of a Linux kernel module 1 1.1 Install XV6...................................................... 1 1.2 Compile and load a

More information

Introduction Reading Writing scull. Linux Device Drivers - char driver

Introduction Reading Writing scull. Linux Device Drivers - char driver Overview 1 2 3 4 Major, minor File Operations The file Structure The inode structure Registraction simplest driver, suitable for most simple devices, follow the book. Jernej Figure: Vičič. (Simple Character

More information

Introduction to Operating Systems. Device Drivers. John Franco. Dept. of Electrical Engineering and Computing Systems University of Cincinnati

Introduction to Operating Systems. Device Drivers. John Franco. Dept. of Electrical Engineering and Computing Systems University of Cincinnati Introduction to Operating Systems Device Drivers John Franco Dept. of Electrical Engineering and Computing Systems University of Cincinnati Basic Computer Architecture CPU Main Memory System Bus Channel

More information

NPTEL Course Jan K. Gopinath Indian Institute of Science

NPTEL Course Jan K. Gopinath Indian Institute of Science Storage Systems NPTEL Course Jan 2012 (Lecture 18) K. Gopinath Indian Institute of Science Spinlocks & Semaphores Shared data betw different parts of code in kernel most common: access to data structures

More information

Linux Loadable Kernel Modules (LKM)

Linux Loadable Kernel Modules (LKM) Device Driver Linux Loadable Kernel Modules (LKM) A way dynamically ADD code to the Linux kernel LKM is usually used for dynamically add device drivers filesystem drivers system calls network drivers executable

More information

USB. Development of a USB device driver working on Linux and Control Interface. Takeshi Fukutani, Shoji Kodani and Tomokazu Takahashi

USB. Development of a USB device driver working on Linux and Control Interface. Takeshi Fukutani, Shoji Kodani and Tomokazu Takahashi Linux USB Development of a USB device driver working on Linux and Control Interface Takeshi Fukutani, Shoji Kodani and Tomokazu Takahashi Recently, it s becoming more popular to utilize Linux for controlling

More information

Scrivere device driver su Linux. Better Embedded 2012 Andrea Righi

Scrivere device driver su Linux. Better Embedded 2012 Andrea Righi Scrivere device driver su Linux Agenda Overview Kernel-space vs user-space programming Hello, world! kernel module Writing a character device driver Example(s) Q/A Overview What's a kernel? The kernel

More information

Device Drivers Demystified ESC 117. Doug Abbott, Principal Consultant Intellimetrix. Why device drivers? What s a device driver?

Device Drivers Demystified ESC 117. Doug Abbott, Principal Consultant Intellimetrix. Why device drivers? What s a device driver? ESC 117, Principal Consultant Intellimetrix Outline Introduction Why device drivers? What s a device driver? Abstract model of device driver OS agnostic What makes drivers seem complicated? Independently

More information

Introduction to Linux Device Drivers Recreating Life One Driver At a Time

Introduction to Linux Device Drivers Recreating Life One Driver At a Time Introduction to Linux Device Drivers Recreating Life One Driver At a Time Muli Ben-Yehuda mulix@mulix.org IBM Haifa Research Labs, Haifa Linux Club Linux Device Drivers, Technion, Jan 2004 p.1/42 why write

More information

Interrupt handling. Interrupt handling. Deferred work. Interrupt handling. Remove an interrupt handler. 1. Link a struct work to a function

Interrupt handling. Interrupt handling. Deferred work. Interrupt handling. Remove an interrupt handler. 1. Link a struct work to a function Interrupt handling Interrupt handling error = request_irq(irq_number, interrupt_service_routine, flags, module_name, (void*)dataptr); error: == 0 OK!= 0 FAILED interrupt_service_routine: irqreturn_t interrupt_service_routine(int

More information

Linux Device Drivers

Linux Device Drivers Linux Device Drivers Modules A piece of code that can be added to the kernel at runtime is called a module A device driver is one kind of module Each module is made up of object code that can be dynamically

More information

Linux Device Drivers. 3. Char Drivers cont. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5.

Linux Device Drivers. 3. Char Drivers cont. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5. Linux Device Drivers Dr. Wolfgang Koch Friedrich Schiller University Jena Department of Mathematics and Computer Science Jena, Germany wolfgang.koch@uni-jena.de Linux Device Drivers 1. Introduction 2.

More information

Step Motor. Step Motor Device Driver. Step Motor. Step Motor (2) Step Motor. Step Motor. source. open loop,

Step Motor. Step Motor Device Driver. Step Motor. Step Motor (2) Step Motor. Step Motor. source. open loop, Step Motor Device Driver Step Motor Step Motor Step Motor source Embedded System Lab. II Embedded System Lab. II 2 Step Motor (2) open loop, : : Pulse, Pulse,, -, +5%, step,, Step Motor Step Motor ( ),

More information

The device driver (DD) implements these user functions, which translate system calls into device-specific operations that act on real hardware

The device driver (DD) implements these user functions, which translate system calls into device-specific operations that act on real hardware Introduction (Linux Device Drivers, 3rd Edition (www.makelinux.net/ldd3)) Device Drivers -> DD They are a well defined programming interface between the applications and the actual hardware They hide completely

More information

Make Your Own Linux Module CS 444/544

Make Your Own Linux Module CS 444/544 Make Your Own Linux Module CS 444/544 Lab Preparation: Running VM! Download the image using - wget http://cslabs.clarkson.edu/oslab/syscall_lab.vdi! Applications -> Accessories-> VirtualBox! In Virtual

More information

Concurrency Aspects of Project 2

Concurrency Aspects of Project 2 Locking Concurrency Aspects of Project 2 Multiple producers, one consumer Multiple users can issue system calls at the same time Need to protect all shared data Examples Passengers may appear on a floor

More information

LINUX DEVICE DRIVERS Weekend Workshop

LINUX DEVICE DRIVERS Weekend Workshop Here to take you beyond LINUX DEVICE DRIVERS Weekend Workshop Linux Device Drivers Weekend workshop Objectives: To get you started with writing device drivers in Linux Provide real time hardware exposure

More information

Operating systems for embedded systems

Operating systems for embedded systems Operating systems for embedded systems Embedded operating systems How do they differ from desktop operating systems? Programming model Process-based Event-based How is concurrency handled? How are resource

More information

RF-IDs in the Kernel -- Episode III: I want to File Away

RF-IDs in the Kernel -- Episode III: I want to File Away What s on the menu Software Comprehension and Maintenance June 2005 RF-IDs in the Kernel -- Episode III: I want to File Away Achilleas Anagnostopoulos (archie@istlab.dmst.aueb.gr) Department of Management

More information

REVISION HISTORY NUMBER DATE DESCRIPTION NAME

REVISION HISTORY NUMBER DATE DESCRIPTION NAME i ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME iii Contents 1 Walking through the Assignment 2 1 1.1 Preparing the base code from Assignment 1..................................... 1 1.2 Dummy port

More information

Embedded Systems Programming

Embedded Systems Programming Embedded Systems Programming Work Queue and Input Processing in Linux (Module 16) Yann-Hang Lee Arizona State University yhlee@asu.edu (480) 727-7507 Summer 2014 Example of Work Structure and Handler #include

More information

7.4 Simple example of Linux drivers

7.4 Simple example of Linux drivers 407 7.4 Simple example of Linux drivers In the previous section, we introduce a simple Hello module driver, it is just some information from the serial port output, the board did not correspond to the

More information

Linux Device Driver in Action (LDDiA)

Linux Device Driver in Action (LDDiA) Linux Device Driver in Action (LDDiA) Duy-Ky Nguyen 2015-04-30 1. On Memory Any unit under user control must have a controller board (CB) with a controller unit (CU) and several devices (Dev.x) doing what

More information

Operating systems for embedded systems. Embedded Operating Systems

Operating systems for embedded systems. Embedded Operating Systems Operating systems for embedded systems Embedded operating systems How do they differ from desktop operating systems? Programming model Process-based Event-based How is concurrency handled? How are resource

More information

Applying User-level Drivers on

Applying User-level Drivers on Applying User-level Drivers on DTV System Gunho Lee, Senior Research Engineer, ELC, April 18, 2007 Content Background Requirements of DTV Device Drivers Design of LG DTV User-level Drivers Implementation

More information

Chapter 12 IoT Projects Case Studies. Lesson-01: Introduction

Chapter 12 IoT Projects Case Studies. Lesson-01: Introduction Chapter 12 IoT Projects Case Studies Lesson-01: Introduction 1 1. Real Time Linux 2 Linux 2.6.x Linux known so after Linus Torvalds father of the Linux operating system Linux 2.6.x provides functions for

More information

- Knowledge of basic computer architecture and organization, ECE 445

- Knowledge of basic computer architecture and organization, ECE 445 ECE 446: Device Driver Development Fall 2014 Wednesdays 7:20-10 PM Office hours: Wednesdays 6:15-7:15 PM or by appointment, Adjunct office Engineering Building room 3707/3708 Last updated: 8/24/14 Instructor:

More information

Linux Kernel Development (LKD)

Linux Kernel Development (LKD) Linux Kernel Development (LKD) Session 1 Loadable Kernel Modules (LKM) Paulo Baltarejo Sousa pbs@isep.ipp.pt 2017 PBS LKD: S1 1 / 66 Disclaimer Material and Slides Some of the material/slides are adapted

More information

Linux Kernel Development (LKD)

Linux Kernel Development (LKD) Linux Kernel Development (LKD) Session 2 CISTER Framework: Laboratory 2 Paulo Baltarejo Sousa pbs@isep.ipp.pt 2017 1 Introduction The goal of the CISTER framework is to create a set of tools that help

More information

Kernel. Kernel = computer program that connects the user applications to the system hardware Handles:

Kernel. Kernel = computer program that connects the user applications to the system hardware Handles: Kernel programming Kernel Kernel = computer program that connects the user applications to the system hardware Handles: Memory management CPU scheduling (Process and task management) Disk management User

More information

Introduction I/O ports and I/O memory I/O port usage Example: I/O port access I/O memory. Sistemsko programiranje hardware communication

Introduction I/O ports and I/O memory I/O port usage Example: I/O port access I/O memory. Sistemsko programiranje hardware communication Sistemsko programiranje hardware communication Overview 1 2 I/O registers and normal memory 3 I/O port allocation I/O port handling I/O port access from user space String instructions Platform dependency

More information

PMON Module An Example of Writing Kernel Module Code for Debian 2.6 on Genesi Pegasos II

PMON Module An Example of Writing Kernel Module Code for Debian 2.6 on Genesi Pegasos II Freescale Semiconductor Application Note AN2744 Rev. 1, 12/2004 PMON Module An Example of Writing Kernel Module Code for Debian 2.6 on Genesi Pegasos II by Maurie Ommerman CPD Applications Freescale Semiconductor,

More information

PCI Bus & Interrupts

PCI Bus & Interrupts PCI Bus & Interrupts PCI Bus A bus is made up of both an electrical interface and a programming interface PCI (Peripheral Component Interconnect) A set of specifications of how parts of a computer should

More information

Character Device Drivers One Module - Multiple Devices

Character Device Drivers One Module - Multiple Devices Review from previous classes Three Types: Block, Character, and Network Interface Device Drivers MAJOR & MINOR numbers assigned register_chrdev_region(), alloc_chrdev_region(), unregister_chrdev_region()

More information

Advanced Operating Systems #13

Advanced Operating Systems #13 http://www.pf.is.s.u-tokyo.ac.jp/class.html Advanced Operating Systems #13 Shinpei Kato Associate Professor Department of Computer Science Graduate School of Information Science and Technology

More information

Character Device Drivers

Character Device Drivers Character Device Drivers 張大緯 CSIE, NCKU The information on the slides are from Linux Device Drivers, Third Edition, by Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman. Copyright 2005 O Reilly

More information

Dissecting a 17-year-old kernel bug

Dissecting a 17-year-old kernel bug Dissecting a 17-year-old kernel bug Vitaly Nikolenko bevx 2018 - Hong Kong https://www.beyondsecurity.com/bevxcon/ Agenda Vulnerability analysis CVE-2018-6554^ - memory leak CVE-2018-6555^ - privilege

More information

7.3 Simplest module for embedded Linux drivers

7.3 Simplest module for embedded Linux drivers 401 7.3 Simplest module for embedded Linux drivers Section 7.1 introduce a simple Linux program Hello World, which is run in user mode applications, we now introduce a run in kernel mode Hello World program,

More information

I/O and Device Drivers

I/O and Device Drivers I/O and Device Drivers Minsoo Ryu Real-Time Computing and Communications Lab. Hanyang University msryu@hanyang.ac.kr Topics Covered I/O Components I/O Interface I/O Operations Device Drivers 2 I/O Components

More information

What is a Linux Device Driver? Kevin Dankwardt, Ph.D. VP Technology Open Source Careers

What is a Linux Device Driver? Kevin Dankwardt, Ph.D. VP Technology Open Source Careers What is a Linux Device Driver? Kevin Dankwardt, Ph.D. VP Technology Open Source Careers kdankwardt@oscareers.com What does a driver do? Provides a more convenient interface to user-space for the hardware.

More information

3 Character Drivers. 3.1 The Design of scullc. Linux Device Drivers in Assembly

3 Character Drivers. 3.1 The Design of scullc. Linux Device Drivers in Assembly 3 Character Drivers In this chapter we will develop a simple character driver named SCULL for Simple Character Utility for Loading Localities; again, don t blame me for the name). As in the previous chapter,

More information

CMPS 105 Systems Programming. Prof. Darrell Long E2.371

CMPS 105 Systems Programming. Prof. Darrell Long E2.371 + CMPS 105 Systems Programming Prof. Darrell Long E2.371 darrell@ucsc.edu + Chapter 3: File I/O 2 + File I/O 3 n What attributes do files need? n Data storage n Byte stream n Named n Non-volatile n Shared

More information

Workspace for '5-linux' Page 1 (row 1, column 1)

Workspace for '5-linux' Page 1 (row 1, column 1) Workspace for '5-linux' Page 1 (row 1, column 1) Workspace for '5-linux' Page 2 (row 2, column 1) ECEN 449 Microprocessor System Design Introduction to Linux 1 Objectives of this Lecture Unit Learn basics

More information

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University ECEN 449 Microprocessor System Design Hardware-Software Communication 1 Objectives of this Lecture Unit Learn basics of Hardware-Software communication Memory Mapped I/O Polling/Interrupts 2 Motivation

More information

Interrupt Handler: Bottom Half. Changwoo Min

Interrupt Handler: Bottom Half. Changwoo Min 1 Interrupt Handler: Bottom Half Changwoo Min 2 Project 3 TA Jinwoo Yom (jinwoo@vt.edu) 3 Hands-on day and office hours Hands-on day (10/09, Tue) In-class design discussion Led by the Project TA, Jinwoo

More information

Simple char driver. for Linux. my_first.c: headers. my_first.c: file structure. Calcolatori Elettronici e Sistemi Operativi.

Simple char driver. for Linux. my_first.c: headers. my_first.c: file structure. Calcolatori Elettronici e Sistemi Operativi. Calcolatori Elettronici e Sistemi Operativi Simple char driver Simple char driver for Linux Code organization my_first.c driver code: Headers Macro definitions Device structure definition Globals and module

More information

Real Time and Embedded Systems. by Dr. Lesley Shannon Course Website:

Real Time and Embedded Systems. by Dr. Lesley Shannon   Course Website: Real Time and Embedded Systems by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc351 Simon Fraser University Slide Set: 8 Date: November 15,

More information

ASE++ : Linux Kernel Programming

ASE++ : Linux Kernel Programming ASE++ : Linux Kernel Programming Giuseppe Lipari (giuseppe.lipari@univ-lille.fr) April 8, 2018 Contents 1 Introduction 1 2 Setting up the environment 2 3 Writing a kernel module 5 4 Other useful information

More information

CPSC 8220 FINAL EXAM, SPRING 2016

CPSC 8220 FINAL EXAM, SPRING 2016 CPSC 8220 FINAL EXAM, SPRING 2016 NAME: Questions are short answer and multiple choice. For each of the multiple choice questions, put a CIRCLE around the letter of the ONE correct answer. Make sure that

More information

CSE 333 SECTION 3. POSIX I/O Functions

CSE 333 SECTION 3. POSIX I/O Functions CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight Exercise 7 due Monday (out later today) POSIX Portable Operating System Interface Family of standards specified by the

More information

Developing Real-Time Applications

Developing Real-Time Applications Developing Real-Time Applications Real Time Operating Systems and Middleware Luca Abeni luca.abeni@unitn.it Characterised by temporal constraints deadlines Concurrent (application: set of real-time tasks)

More information

I/O MANAGEMENT CATEGORIES OF I/O DEVICES 1. Slide 1. Slide 3. Controller: Three classes of devices (by usage):

I/O MANAGEMENT CATEGORIES OF I/O DEVICES 1. Slide 1. Slide 3. Controller: Three classes of devices (by usage): Monitor Keyboard Floppy disk drive Hard disk drive Slide I/O MANAGEMENT Categories of I/O devices and their integration with processor and bus Design of I/O subsystems Slide CPU Memory Video controller

More information

Table of Contents. Preface... xi

Table of Contents. Preface... xi ,ldr3toc.fm.4587 Page v Thursday, January 20, 2005 9:30 AM Table of Contents Preface................................................................. xi 1. An Introduction to Device Drivers.....................................

More information

CS 453: Operating Systems Programming Project 5 (100 points) Linux Device Driver

CS 453: Operating Systems Programming Project 5 (100 points) Linux Device Driver CS 453: Operating Systems Programming Project 5 (100 points) Linux Device Driver 1 Setup In this assignment, we will write a simple character driver called booga. Please do a git pull --rebase in your

More information

Loadable Kernel Modules

Loadable Kernel Modules Loadable Kernel Modules Kevin Dankwardt, Ph.D. kevin.dankwardt@gmail.com Topics 1. Why loadable kernel modules? 2. Using Modules 3. Writing modules 4. Compiling & Installing Modules 5. Example : Simple

More information

20-EECE-4029 Operating Systems Fall, 2015 John Franco

20-EECE-4029 Operating Systems Fall, 2015 John Franco 20-EECE-4029 Operating Systems Fall, 2015 John Franco First Exam Question 1: Barrier name: a) Describe, in general terms, what a barrier is trying to do Undo some of the optimizations that processor hardware

More information

The course that gives CMU its Zip! I/O Nov 15, 2001

The course that gives CMU its Zip! I/O Nov 15, 2001 15-213 The course that gives CMU its Zip! I/O Nov 15, 2001 Topics Files Unix I/O Standard I/O A typical hardware system CPU chip register file ALU system bus memory bus bus interface I/O bridge main memory

More information

Kthreads, Mutexes, and Debugging. Sarah Diesburg CS 3430 Operating Systems

Kthreads, Mutexes, and Debugging. Sarah Diesburg CS 3430 Operating Systems Kthreads, Mutexes, and Debugging Sarah Diesburg CS 3430 Operating Systems 1 Story of Kernel Development Some context 2 In the old days There were no modules or virtual machines The kernel is a program

More information

Design and Implementation of an Asymmetric Multiprocessor Environment Within an SMP System. Roberto Mijat, ARM Santa Clara, October 2, 2007

Design and Implementation of an Asymmetric Multiprocessor Environment Within an SMP System. Roberto Mijat, ARM Santa Clara, October 2, 2007 Design and Implementation of an Asymmetric Multiprocessor Environment Within an SMP System Roberto Mijat, ARM Santa Clara, October 2, 2007 1 Agenda Design Principle ARM11 MPCore TM overview System s considerations

More information

SuSE Labs / Novell.

SuSE Labs / Novell. Write a real Linux driver Greg Kroah-Hartman SuSE Labs / Novell http://www.kroah.com/usb.tar.gz gregkh@suse.de greg@kroah.com Agenda Intro to kernel modules sysfs basics USB basics Driver to device binding

More information

Operating System Concepts Ch. 11: File System Implementation

Operating System Concepts Ch. 11: File System Implementation Operating System Concepts Ch. 11: File System Implementation Silberschatz, Galvin & Gagne Introduction When thinking about file system implementation in Operating Systems, it is important to realize the

More information

Input & Output 1: File systems

Input & Output 1: File systems Input & Output 1: File systems What are files? A sequence of (usually) fixed sized blocks stored on a device. A device is often refered to as a volume. A large device might be split into several volumes,

More information

Memory Mapping. Sarah Diesburg COP5641

Memory Mapping. Sarah Diesburg COP5641 Memory Mapping Sarah Diesburg COP5641 Memory Mapping Translation of address issued by some device (e.g., CPU or I/O device) to address sent out on memory bus (physical address) Mapping is performed by

More information

CPSC Tutorial 17

CPSC Tutorial 17 CPSC 457 - Tutorial 17 Loadable Kernel Modules Department of Computer Science University of Calgary March 27, 2012 1 / 10 Reminder Homework 4 is due to March 31, 2012 at 11:59pm (Saturday) Thursday, March

More information

Introduction to Device Drivers Part-1

Introduction to Device Drivers Part-1 Introduction to Device Drivers Part-1 Introduction to Device Drivers-1 Objectives GNU/Linux Learn how to access the hardware similar to the sysfs method but faster Understand the basic techniques of how

More information

The Kernel Abstraction. Chapter 2 OSPP Part I

The Kernel Abstraction. Chapter 2 OSPP Part I The Kernel Abstraction Chapter 2 OSPP Part I Kernel The software component that controls the hardware directly, and implements the core privileged OS functions. Modern hardware has features that allow

More information

Operating Systems II BS degree in Computer Engineering Sapienza University of Rome Lecturer: Francesco Quaglia. Topics: 1.

Operating Systems II BS degree in Computer Engineering Sapienza University of Rome Lecturer: Francesco Quaglia. Topics: 1. Operating Systems II BS degree in Computer Engineering Sapienza University of Rome Lecturer: Francesco Quaglia Topics: 1. LINUX modules Modules basics A LINUX module is a software component which can be

More information

ECE 650 Systems Programming & Engineering. Spring 2018

ECE 650 Systems Programming & Engineering. Spring 2018 ECE 650 Systems Programming & Engineering Spring 2018 Inter-process Communication (IPC) Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Recall Process vs. Thread A process is

More information

ECE 598 Advanced Operating Systems Lecture 19

ECE 598 Advanced Operating Systems Lecture 19 ECE 598 Advanced Operating Systems Lecture 19 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 7 April 2016 Homework #7 was due Announcements Homework #8 will be posted 1 Why use

More information

Modules. Mail: Web: University of Nice - Sophia Antipolis

Modules. Mail: Web:  University of Nice - Sophia Antipolis Modules Mail: Stephane.Lavirotte@unice.fr Web: http://stephane.lavirotte.com/ University of Nice - Sophia Antipolis Introduction For a good start 2 Where does the Modules come from? Principle based on

More information

SpiNNaker Application Programming Interface (API)

SpiNNaker Application Programming Interface (API) SpiNNaker Application Programming Interface (API) Version 2.0.0 10 March 2016 Application programming interface (API) Event-driven programming model The SpiNNaker API programming model is a simple, event-driven

More information

PFStat. Global notes

PFStat. Global notes PFStat Global notes Counts expand_stack returns in case of error, so the stack_low count needed to be inside transparent huge page, 2 cases : There is no PMD, we should create a transparent one (There

More information

Linux Device Driver. Amir Hossein Payberah. (Kmod & Advanced Modularization)

Linux Device Driver. Amir Hossein Payberah. (Kmod & Advanced Modularization) Linux Device Driver (Kmod & Advanced Modularization) Amir Hossein Payberah payberah@yahoo.com Contents Loading Module on Demand Intermodule Communication 2 Loading Module on Demand To make it easier for

More information

Operating Systems 2010/2011

Operating Systems 2010/2011 Operating Systems 2010/2011 Input/Output Systems part 1 (ch13) Shudong Chen 1 Objectives Discuss the principles of I/O hardware and its complexity Explore the structure of an operating system s I/O subsystem

More information

we are here Page 1 Recall: How do we Hide I/O Latency? I/O & Storage Layers Recall: C Low level I/O

we are here Page 1 Recall: How do we Hide I/O Latency? I/O & Storage Layers Recall: C Low level I/O CS162 Operating Systems and Systems Programming Lecture 18 Systems October 30 th, 2017 Prof. Anthony D. Joseph http://cs162.eecs.berkeley.edu Recall: How do we Hide I/O Latency? Blocking Interface: Wait

More information