Basics Device driver
- YASH KUMAR SONI
- Apr 8, 2023
- 2 min read
Device driver - Device driver program are used to create the interaction between the OS and the attached peripherals devices.
Today, most operating systems include a library of plug-n-play drivers that allows peripheral hardware to connect automatically with an operating system.
When a device is connected to the system, a device file is created in the /dev directory.
Most Common types of devices in Linux:
Character devices – These devices transmit the data character by characters, like a mouse or a keyboard.
Block devices – These devices transfer units of data storage called a block, USB drives, hard drives, and CD ROM.
User space and kernel space - User space programs do not have direct access to hardware devices and cannot interact with them without the help of device drivers. User space programs communicate with device drivers through system calls, which are executed in kernel space.
The technical difference between user space and kernel space in respect of device drivers is that device drivers run in kernel space, while user space programs interact with them through system calls.
This separation of user space and kernel space ensures that it also provides an additional layer of security by preventing user space programs from accessing sensitive hardware resources or introducing bugs that could destabilize the system.
LKM - Loadable kernel Module -
Kernel modules are pieces of code that can be loaded and unloaded into the kernel
upon demand. They extend the functionality of the kernel without the need to reboot the system.
Custom codes can be added to Linux kernels via two methods
The basic way is to add the code to the kernel source tree and recompile the kernel.
A more efficient way to do this is by adding code to the kernel while it is running. This process is called loading the module, where the module refers to the code that we want to add to the kernel.
Since we are loading these codes at runtime and they are not part of the official Linux kernel.
These are called loadable kernel modules (LKM), which is different from the “base kernel”.
The base kernel is located in the /boot directory and is always loaded when we boot our
machine whereas LKMs are loaded after the base kernel is already loaded. This LKM is very
much part of our kernel and they communicate with the base kernel to complete their
functions.
What is the use of Linux kernel Module -
Device Driver - A device driver is designed for a specific piece of hardware. The kernel uses it to communicate with that piece of hardware without having to know any details of how the hardware works.
File system Driver - Manage the file system related operations
Network Driver - A network driver interprets a network protocol. It feeds and consumes data streams at various layers of the kernel's networking function.
System calls - User space programs use system calls to get services from the kernel.
TTY line - It’s used to provide the active terminal for taking the input from the device.
Comments