1 / 29

Device Drivers

Device Drivers. Writing UNIX Device Drivers George Pajari Chapter : 1,2,5,13 Design and anatomy of UNIX device driver: Types of device driver General design of UNIX character device driver General design of UNIX block device driver UNIX device driver installation. What is Device Driver ??.

kita
Télécharger la présentation

Device Drivers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Device Drivers • Writing UNIX Device Drivers • George Pajari • Chapter : 1,2,5,13 • Design and anatomy of UNIX device driver: Types of device driver • General design of UNIX character device driver • General design of UNIX block device driver • UNIX device driver installation.

  2. What is Device Driver ?? Chapter - 1

  3. What is Device Driver ? • A Device Driver is glue between an OS and its I/O devices. • Act as Translators, Requests to Command etc. • Device drivers communicate directly with devices. • A device is a physical or logical entity that requires control, resource management, or both from the operating system (OS). • A device driver is a software module that manages the operation of a virtual or physical device, a protocol, or a service.

  4. What is Device Driver ?

  5. Major Design Issue • OS / Driver Communication • Exchange information (command and data) • Support functions that the kernel provides • Driver / Hardware Communication • Exchange information (command and data) • Software talks to the hardware • Hardware talks to the software • Driver Opertaions • Interrupting ,scheduling, managing, read, write, accepting

  6. Types of Device Drivers • Block Drivers • Character Drivers • Terminal Drivers • Stream Drivers

  7. Block Drivers • It communicate with OS through a collection of fixed-sized bufferss. • For example, disks are commonly implemented as block devices.

  8. Character Drivers • It can handle I/O requests of arbitary size. • Mostly used devices, Pritners

  9. Terminal Drivers • Same as character drivers to deal with communication terminals that connect users to OS. • E.g. MODEM,

  10. STREAM Drivers • It can handle high speed communication devices such as networking adapters that deal with unusal sized chunks of data and that need to handle protocol. • It is also known as Network Device Drivers. • eg. Network Devices

  11. Charcter Driver I – A Test Data Generator Chapter - 2

  12. Character Driver : Entry Points • init( ): Initialize hardware • start( ): Boot time initialization (require system services) • open(dev, flag, id): initialization for read or write • close(dev, flag, id): release resources after read and write • halt( ): call before the system is shutdown • intr(vector): called by the kernel on a hardware interrupt • read/write calls: data transfer • poll(pri): called by the kernel 25 to 100 times a second • ioctl(dev, cmd, arg, mode): special request processing

  13. Character Driver : Prologue It includes all of the definition and declarations required by the driver. Three types of Prologue : Reference to the header files (Data types / Structures) Definitions that local for driver Declaration local to the Driver

  14. Reference to the header files #include <sys/types.h> #include <sys/param.h> #include <sys/dir.h> #include <sys/signal.h> #include <sys/errno.h> All above header files are found in the directory /usr/include/sys and read before writing first driver.

  15. Header files example Sys/types.h : contain variaous data types Sys/param.h : contain definition of various kernel parameter and macros that are needed by sys/user.h Sys/dir.h : contains definition of directory structure Sys/signal.h : contains the definition related to signals needed by sys/user.h Sys/user.h : contains the definition of user structure. Sys/errno.h : contains the definition of various error codes.

  16. Init() Entry Point To check device actually installed on the machine To print message (Presence / Absence) Initialize device (Prior to open) Allocate Local Memory It is optional entry point

  17. Block Drivers I : A Test Data Generator Chapter - 5

  18. Block Drivers - Prologue #include <sys/types.h> #include <sys/buf.h> - Definition of buffer header that are used to coordinate the transfer of data to and from block drivers. #include <sys/cmn_err.h> - definition used by the error reporting routine.

  19. Block Drivers – Entry Points Init() Open() Close() Strategy() - Responsible for handling requests for data (in or Out) and replace both the read and write entry points found in character drivers. Print() - it to used by the kernel report problems related to the driver. It needs to print the error message on the console and usyally calls upon the kernel routine cmn_err() to display message.

  20. Driver Installation Chapter - 13

  21. Driver Installation Steps Compiling the device driver Modifying the kernel configuration tables and files Linking the device with the kernel object files to produce a new kernel Creating the necessary entries in the /dev directory Rebooting the system with the new kernel.

  22. Compiling the driver It is similar to compiling any other C Program. Driver is not a stand-alone program, It is always compiled to produce an Object rather than a linked executable file. It need to linking in to the kernel. Necessary information obtained from system's documentation

  23. Configuing the Kernel Kernel Configuration tables to reflect the addition of new driver. Method varies between different Version of Unix. There are two Config files used by the system to generate a new kernel are the mdevice and sdevice file contain entry for each device driver that exists on the system. Sdevice contains info for each device driver that is to be incorporated into the kernel Mdevice contains entry for each device driver that exist on the system.

  24. Mdevice file Device Name Fucntion List Driver characteristics Handle Prefix Block Major Number Character Major Number Minimum Unit Maximum Unit DMA Channel

  25. Sdevice file Device Name Configure Unit Lpl Interrupt Type Vector Start I/O Address End I/O Address Start Controller Memory Address End Controller Memory Address

  26. Building a New Kernel Sytem utlity to run is idbuild.

  27. Creating Entries in /dev /dev directory that reference your device driver. It can be done with mknod command. On most system it will be automatically. Node files has four fields. Device Name Node Name Node Type Minor Device Number

  28. Rebooting the New Kernel Reboot the system

  29. ALL THE BEST

More Related