LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-12-2014, 06:37 PM   #1
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 74

Rep: Reputation: Disabled
Two different types of device drivers


Hi,

I feel that there are two different types of device drivers.

Type 1: the device driver provides userspace API such as .read, .write and .ioctl. The driver is assigned a major/minor number and userspace program may access physical devices by use the API it provides.

Type 2: the device driver doesn't not provide user space API (no read, write or .ioctl), and the driver is used by another driver in the kernel.

So how do I categorize these two types of drivers? What are the correct technical terms for them?

Thanks,
Wei
 
Old 06-13-2014, 08:14 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,096
Blog Entries: 10

Rep: Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522
Depending on how you perceive things, there are a few different type of device drivers. I've always thought there were: character, block, and network device driver categories; however it's been a while and mainly I dealt with character drivers, which are of the read/write/ioctl variety.

Here are some references:

http://www.tldp.org/LDP/khg/HyperNew...s/devices.html
http://www.tldp.org/LDP/tlk/dd/drivers.html
 
Old 06-13-2014, 12:56 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Those layered drivers... such as the device drivers handled by the SCSI module (each SCSI device has its own driver, and USB/ATAPI drivers, SATA drivers...).

The drivers are device drivers, which interface to the device by passing command packets to the middle layer driver (the controller driver) that hand off those packets to the physical device over the peripheral bus (USB/SCSI/SATA/ATAPI or PATA and others).

As I understand it, the controller drivers still provide the read/write/... device operations as that is how the procfs and sysfs provides access to controller configuration/statistics (/proc/bus, and /sys/bus).

Also note - the controller drivers provide global functions that implement the interface to the specific controller for the layered drivers (for USB, they are "usb_<function name>") and it is up to the device driver to register with the controller driver when loaded, and unregister when being removed. This maintains a reference count for the controller driver that prevents it from being removed out from under the device drivers that are still available/active (that would cause a crash - usually due to an invalid address being used for a function call).

The "block" or "character" devices is an external designation based on how it works (it is more historical than required - but it allows devices that are primarily block oriented to be categorized that way from those that are stream oriented (everything else). It does allow for some optimization of buffer handling for block devices - but in operation there isn't that much of a difference.

Historical note: Originally drivers were put into one or two tables - The order of entry in the table defined the major number. Block drivers went into the block list, stream drivers went into the character table. But then operating modes of disk drivers allowed raw access (hence the addition of the block devices to the character table). This was partially done to allow ioctl functions (which were always unique to the driver, but not defined for the block list - at least, I don't remember an entry for it) to do really oddball things (like rewinding a disk???). Adding block devices to the character table allowed for access to functions like low level formatting disks, bad block management... Things that made sense to have access to, but outside the functions read/writing blocks of data.

PS. There is also a third major driver - one that interfaces not with a device (or controller) but interfaces with the system (procfs, devfs...) These drivers are usually built into the kernel rather than being modules that can be loaded/removed. And then there are filesystems... But now it starts getting vague as to the definition of "driver", as modules can be drivers... except when they are not (is a security module a "driver"???)

Last edited by jpollard; 06-13-2014 at 01:23 PM. Reason: someday I will learn to type...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux device drivers : how can i unregister a character device ? zampa Linux - General 5 06-21-2012 06:34 AM
[SOLVED] URGENT : How to handle one device through two separted device drivers Khadidja Linux - Kernel 2 02-16-2011 03:33 AM
[SOLVED] Conflicting type declarations between sys/types.h and linux/types.h Da Shi Cao Programming 3 09-14-2010 12:55 AM
sys/types.h & linux/types.h conflict while compiling johnnyhal Linux - Software 1 12-28-2008 07:39 PM
conflicting redeclaration of sys/types.h and linux/types.h schmil Programming 6 12-11-2008 03:02 PM


All times are GMT -5. The time now is 09:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration