USERSPACE I/O Reporter: R98922086 張凱富.

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
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.
Device Drivers cs423, Fall 2007 Klara Nahrstedt/Sam King 6/6/20141.
RT_FIFO, Device driver.
purpose Search : automation methods for device driver development in IP-based embedded systems in order to achieve high reliability, productivity, reusability.
Sogang University Advanced Operating Systems (Linux Device Drivers) Advanced Operating Systems (Linux Device Drivers) Sang Gue Oh, Ph.D.
Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /
Computer System Laboratory
MPI Message Passing Interface
Threads Relation to processes Threads exist as subsets of processes Threads share memory and state information within a process Switching between threads.
The Linux Kernel: Memory Management
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Assistant Professor, University of Maryland Baltimore County.
Wang Lei Chapter 5 Device Management Chapter 5 Device Management — for the Solaris Platform.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Operating System Structure. Announcements Make sure you are registered for CS 415 First CS 415 project is up –Initial design documents due next Friday,
Embedded System Programming Introduction to Device Drivers.
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.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Students:Gilad Goldman Lior Kamran Supervisor:Mony Orbach Mid-Semester Presentation Spring 2005 Network Sniffer.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Operating System Program 5 I/O System DMA Device Driver.
Real-time Systems Lab, Computer Science and Engineering, ASU Linux Input Systems (ESP – Fall 2014) Computer Science & Engineering Department Arizona State.
Cpr E 308 Input/Output Recall: OS must abstract out all the details of specific I/O devices Today –Block and Character Devices –Hardware Issues – Programmed.
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.
LWIP TCP/IP Stack 김백규.
I/O Example: Disk Drives To access data: — seek: position head over the proper track (8 to 20 ms. avg.) — rotational latency: wait for desired sector (.5.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
Chapter 1 : The Linux System Part 1 Lecture 1 10/21/
UNIX Files File organization and a few primitives.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
An Introduction to Device Drivers Ted Baker  Andy Wang COP 5641 / CIS 4930.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
CSE 466 – Fall Introduction - 1 User / Kernel Space Physical Memory mem mapped I/O kernel code user pages user code GPLR virtual kernel C
4P13 Week 12 Talking Points Device Drivers 1.Auto-configuration and initialization routines 2.Routines for servicing I/O requests (the top half)
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
Device Driver Concepts Digital UNIX Internals II Device Driver Concepts Chapter 13.
I/O Software CS 537 – Introduction to Operating Systems.
Kernel Modules – Introduction CSC/ECE 573, Sections 001 Fall, 2012.
Using Linux with ARM Tutorial #3.
Tgt: Framework Target Drivers FUJITA Tomonori NTT Cyber Solutions Laboratories Mike Christie Red Hat, Inc Ottawa Linux.
CSCE451/851 Introduction to Operating Systems
Introduction to Operating Systems Concepts
Computer System Structures
Input/Output (I/O) Important OS function – control I/O
Kernel Design & Implementation
Interrupts and Interrupts Handling
Chapter 12: File System Implementation
Protection of System Resources
Operating System Structure
Linux Kernel Driver.
Linux device driver development
The PCI bus (Peripheral Component Interconnect ) is the most commonly used peripheral bus on desktops and bigger computers. higher-level bus architectures.
An Introduction to Device Drivers
Undermining the Linux Kernel: Malicious Code Injection via /dev/mem
Making Virtual Memory Real: The Linux-x86-64 way
Memory Management Tasks
Lecture Topics: 11/1 General Operating System Concepts Processes
Operating Systems Lecture 3.
Processes in Unix and Windows
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

USERSPACE I/O Reporter: R98922086 張凱富

Introduction For many types of devices, creating a Linux kernel driver is overkill. Most Requirements : handle an interrupt access to the memory space of the device no need for other resources in kernel One such class of devices : industrial I/O cards

Introducion Userspace I/O systems are designed Advantages : only a very small kernel module needed main part running in user space Advantages : Ease of development Stability Reliability Maintainability

Introduction UIO is not an universal driver interface. Devices well handled by kernel subsystems are no candidates. Like networking or serial or USB Requirements for UIO The device memory can be mapped. usually generates interrupts fit into no standard kernel subsystems.

Introduction Linux kernel 2.6.24 permit userspace drivers Industry card Linux kernel tends to be monolithic Short response time Mode protection

Difficulties to Be Solved Direct interrupt to userspace User processes access hardware Support DMA Efficient communication between User/Kernel space

Linux Userspace Driver Model

How It Works Map hardware memory to drivers’ address space Kernel part includes interrupt service routines It is notified when interrupt is thrown by blocking or reading from /dev/uio0 Then waiting processes wake up Driver parts exchange data via maped registers (addresses)

How It Works Driver model just specifies How resources are mapped How interrupts are handled Userspace drivers determine how to access devices

The Kernel Part Juggles Three Objects

Kernel Part struct uio_info kpart_info = { .name = "kpart", .version = "0.1", .irq = UIO_IRQ_NONE, }; static int drv_kpart_probe(struct device *dev); static int drv_kpart_remove(struct device *dev); static struct device_driver uio_dummy_driver = { .bus = &platform_bus_type, .probe = drv_kpart_probe, .remove = drv_kpart_remove,

Kernel Part static int drv_kpart_probe(struct device *dev) { kpart_info.mem[0].addr = (unsigned long)kmalloc(2,GFP_KERNEL); if( kpart_info.mem[0].addr==0 ) return -ENOMEM; kpart_info.mem[0].memtype =UIO_MEM_LOGICAL; kpart_info.mem[0].size =512; if( uio_register_device(dev,&kpart_info) ) return -ENODEV; return 0; }

Kernel Part static int drv_kpart_remove(struct device *dev){ uio_unregister_device(&kpart_info); return 0; } static struct platform_device *uio_dummy_device; static int __init uio_kpart_init(void) { uio_dummy_device = platform_device_register_simple("kpart", -1,NULL, 0); return driver_register(&uio_dummy_driver);

Kernel Part static void __exit uio_kpart_exit(void) { platform_device_unregister(uio_dummy_device); driver_unregister(&uio_dummy_driver); } module_init( uio_kpart_init ); module_exit( uio_kpart_exit ); MODULE_LICENSE("GPL");

Registration In uio_register_device(), UIO subsystem check if the device model contains uio device class. If not, it creates the class. It ensures a major number to module and reserves minor number to the driver. udev creates device file /dev/uio# (#starting from 0)

Registration To find out the hardware represented by device files, we can look up the pseudo-files in the sys file system

User Part The user part finds the address information stored by the kernel part in the relevant directory. The user part then calls mmap() to bind the addresses into its own address space.

User Part #define UIO_DEV "/dev/uio0" #define UIO_ADDR "/sys/class/uio/uio0/maps/map0/addr“ #define UIO_SIZE "/sys/class/uio/uio0/maps/map0/size" static char uio_addr_buf[16], uio_size_buf[16]; int main( int argc, char **argv ) { int uio_fd, addr_fd, size_fd; int uio_size; void *uio_addr, *access_address; addr_fd = open( UIO_ADDR, O_RDONLY ); size_fd = open( UIO_SIZE, O_RDONLY ); uio_fd = open( UIO_DEV, O_RDONLY);

User Part read( addr_fd, uio_addr_buf, sizeof(uio_addr_buf) ); read( size_fd, uio_size_buf, sizeof(uio_size_buf) ); uio_addr = (void *)strtoul( uio_addr_buf, NULL, 0 ); uio_size = (int)strtol( uio_size_buf, NULL, 0 ); access_address = mmap(NULL, uio_size, PROT_READ, MAP_SHARED, uio_fd, 0); printf("The HW address %p (length %d) can be accessed over logical addrss %p\n", uio_addr, uio_size, access_address); // Access to the hardware registers can occur from here on ... return 0; }

User Part A routine that needs to be notified when interrupts occur calls select() or read() in non-blocking mode. read() returns the number of events (interrupts) as a 4-byte value.

Pros and Cons Advantages: • Version change: The user only needs to rebuild the kernel part after making any required modifications. • Stability: Protects the kernel against buggy drivers. • Floating point is available. • Efficient, because processes do not need to be swapped. • License: The user part of the source code does not need to be published (although this is a controversial subject in the context of the GPL).

Pros and Cons Disadvantages: • Kernel know-how is required for standard drivers, the sys file system, IRQ, and PCI. • Timing is less precise than in kernel space. • Response to interrupts: Response times are longer than in kernel space (process change). • Functionality is severely restricted in userland; for example, DMA is not available. • API: The application can’t use a defined interface to access the device. • Restricted security is sometimes difficult to achieve