Is Kernel module is the same as a device driver?


 
Thread Tools Search this Thread
Operating Systems Linux Fedora Is Kernel module is the same as a device driver?
# 1  
Old 05-01-2011
Is Kernel module is the same as a device driver?

I have been reading prep questions for my second unix academy exam, and there's a nuance, I'm not sure I understand it correctly.
I've been under impression from my readings of book by Evi Nemeth and from unix academy DVDs I've been watching, that kernel's modules are drivers. I think of it, as there are standard drivers that come precompiled as a part of a kernel, and some drivers that are not part of a "standard setup", so we load them when necessary as modules.
Now, I see in my readings and in the DVDs, modules and drivers are discussed on separate occasions, which makes me confused! Are they the same or they aren't? I mean, is this "module" and "driver" terminology is interchangeable and it is just figure of speech, or there's real difference between them?
# 2  
Old 05-02-2011
The exact answer depends on the OS. I gather from your name that you are interested in Linux. With Linux, lsmod can provide a list of modules and modinfo can give you a description of a module. If you get descriptions of all of the modules, you will see that most are drivers. But not all. If you make a list of the drivers that are modules you will be missing some drivers. That's because some drivers are permanently built into the kernel without being encapsulated as a module.

A driver talks to hardware or pretends to talk to hardware. Device files like /dev/tty or /dev/null exist so your program can interface with a driver.

A module is a piece of a kernel that can be optionally loaded into the kernel.

This is from the perspective of the kernel. CUPS talks about "drivers" while Perl talks about modules. But neither means these kind of drivers and modules. So the terms get overloaded to mean lots of stuff and become a little fuzzy.

This is the best I can do to give a quick answer to a complicated question.
This User Gave Thanks to Perderabo For This Post:
# 3  
Old 05-03-2011
So, generally speaking, kernel module is a driver? Isn't it? Is there any command that can show loaded driver-device dependency tree?
# 4  
Old 05-03-2011
lsmod shows which modules are using what other modules, though not as a tree.

It's not always as simple as one module for one device. USB needs a whole bunch of modules to do anything, plus sometimes device-specific things on top of the generic drivers -- but then again, sometimes the generic ones are enough. Sound also takes a bunch of interdependent modules to work.

There's also modules that don't do anything device-related -- like a module to let the kernel understand ext4 filesystems.

So it's really not the same thing, but often close enough for most purposes.

These modules can also be built right into the kernel, instead of being loaded from a file, too. It's possible to create a kernel that loads no modules for anything, ever. You can even build parts of a set of modules into the kernel and leave part of it out. This is sometimes important for things like ALSA, where you might want to replace some modules with updated ones later, but need certain basic parts built in.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 05-03-2011
Corona688, thanks for the clarification. Please correct me if I'm wrong.

Below are my assumptions:

user process->kernel->major device number(the driver)->minor device number->device

Let say I have device X and I want to know what driver(s) it uses (because it makes problems, or just out of curiosity). So how can it be done? It is really easy in Windows.
# 6  
Old 05-03-2011
The kernel knows what a major+minor number means, but this often just deals with generic input layers like "SCSI disk" -- which these days can mean anything from USB to SATA to PATA, not just actual SCSI. That Linux is now able to treat nearly all disks so identically is mostly a good thing -- device names don't mysteriously change from hda to sda anymore -- but also means it doesn't tell you much about which driver's used.

Try lspci -k, that'll tell you what PCI/AGP/PCIE devices are being claimed by what modules. You can also explore the virtual /sys/ directories to find out more about the devices within.
# 7  
Old 05-03-2011
On RedHat at least we have /usr/include/linux/major.h which documents which major number goes with which driver. And remember that there are character drivers and block drivers and one of each can use the same major number. By convention, when this happens the two drivers should be closely related. For example:
Code:
#define MEM_MAJOR               1
#define RAMDISK_MAJOR           1

is an excerpt from that header file and we have
Code:
     $ ls -l /dev | awk '$5 == "1,"' | sort -k1.1,1.1  -k6
brw-r----- 1 root  disk     1,     0 Jan 17 10:38 ram0
brw-r----- 1 root  disk     1,     1 Jan 17 10:38 ram1
brw-r----- 1 root  disk     1,     2 Jan 17 10:38 ram2
brw-r----- 1 root  disk     1,     3 Jan 17 10:38 ram3
brw-r----- 1 root  disk     1,     4 Jan 17 10:38 ram4
brw-r----- 1 root  disk     1,     5 Jan 17 10:38 ram5
brw-r----- 1 root  disk     1,     6 Jan 17 10:38 ram6
brw-r----- 1 root  disk     1,     7 Jan 17 10:38 ram7
brw-r----- 1 root  disk     1,     8 Jan 17 10:38 ram8
brw-r----- 1 root  disk     1,     9 Jan 17 10:38 ram9
brw-r----- 1 root  disk     1,    10 Jan 17 10:38 ram10
brw-r----- 1 root  disk     1,    11 Jan 17 10:38 ram11
brw-r----- 1 root  disk     1,    12 Jan 17 10:38 ram12
brw-r----- 1 root  disk     1,    13 Jan 17 10:38 ram13
brw-r----- 1 root  disk     1,    14 Jan 17 10:38 ram14
brw-r----- 1 root  disk     1,    15 Jan 17 10:38 ram15
crw-r----- 1 root  kmem     1,     1 Jan 17 15:38 mem
crw-rw-rw- 1 root  root     1,     3 Jan 17 15:38 null
crw-r----- 1 root  kmem     1,     4 Jan 17 15:38 port
crw-rw-rw- 1 root  root     1,     5 Jan 17 15:38 zero
crw-rw-rw- 1 root  root     1,     7 Jan 17 15:38 full
crw-rw-rw- 1 root  root     1,     8 Jan 17 15:38 random
cr--r--r-- 1 root  root     1,     9 Jan 17 15:38 urandom
crw------- 1 root  root     1,    11 Jan 17 15:38 kmsg
crw------- 1 root  root     1,    12 Jan 17 15:38 oldmem
$

The major number just tells the kernel which driver to invoke. The driver is the part of the kernel that understands its own minor numbers. But there are conventions here too.

Not all driver writers completely follow conventions. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Get pointer for existing device class (struct class) in Linux kernel module

Hi all! I am trying to register a device in an existing device class, but I am having trouble getting the pointer to an existing class. I can create a class in a module, get the pointer to it and then use it to register the device with: *cl = class_create(THIS_MODULE, className);... (0 Replies)
Discussion started by: hdaniel@ualg.pt
0 Replies

2. Linux

Linux Device Driver: avoid mem copy from/to user/kernel space

I recently started working with Linux and wrote my first device driver for a hardware chip controlled by a host CPU running Linux 2.6.x kernel. 1. The user space process makes an IOCTL call with pointer to a user memory buffer. 2. The kernel device driver in the big switch-case of IOCTL,... (1 Reply)
Discussion started by: agaurav
1 Replies

3. Solaris

SUNWglmr -- rasctrl environment monitoring driver for i2c or SCSI device driver ?

I've been researching minimizeing Solaris 8 and found that on the web page http://www.sun.com/bigadmin/content/packagelist/s8u7PkgList/p2.html the package SUNWglmr is listed as "rasctrl environment monitoring driver for i2c, (Root) (32-bit)" while in the document "Solaris 8 minimize-updt1.pdf"... (1 Reply)
Discussion started by: roygoodwin
1 Replies

4. UNIX for Advanced & Expert Users

Kernel and Device Driver Programming

I am looking for a guide on how to program for either the Linux or FreeBSD (includes 4.4BSD, NetBSD or OpenBSD) kernel. I would prefer to learn how to write device drivers, but anything would help. If you know, please email me at *removed* or leave a post here Regards, Farhan (0 Replies)
Discussion started by: Farhan
0 Replies
Login or Register to Ask a Question