DEV Community

Aadityansha
Aadityansha

Posted on

An interaction Between kernel Driver and Hardware: Understanding Drivers

Let’s continue our discussion with “What exactly is a driver”?

After understanding kernels — How kernel routes user request (such as connect Bluetooth/wifi) to the specific driver that handles the operation with Hardware?

A driver is a specialized type of program that knows how to communicate with specific hardware.

Think of drivers as translators between the kernel (which uses standardized interfaces) and hardware devices (which each have their own unique protocols and commands).

The Driver’s Job:

Receive instructions from the kernel in a standard format

Translate these instructions into hardware-specific commands

Send commands to the hardware (e.g., “scan for Bluetooth devices”)

Receive responses from hardware

Translate responses back into a format the kernel understands

Return the result to the kernel, which passes it back to your application

How kernel routes user request?
On each Driver hardware details are mentioned

So, when the hardware is plugged in,

the kernel detect the hardware and look for driver with same specifications (like product name, id, vendor name etc..)

Understanding Kernel Modules: The Plugin System
Here’s where it gets interesting. Modern kernels use a concept called modules.

What is a Module?

A kernel module is a piece of code that can be inserted into or removed from the running kernel without rebooting the system.

Think of modules like plugins:

Just like you add plugins to OBS Studio for specific features (screen capture, audio filters, etc.) without rewriting the entire OBS codebase

Similarly, you can add modules to the kernel for specific tasks without recompiling the entire kernel

Examples of kernel modules:

  1. Filesystem support (ext4, NTFS, FAT32)
  2. Network protocols
  3. Device drivers
  4. Security features
  5. Hardware monitoring tools
  6. Why Use Modules?
  7. Without modules, you’d need to:

Include all possible drivers and features in the kernel

Recompile and reboot the kernel every time you add new hardware

Have a huge, bloated kernel even for features you don’t use.

With modules, you can:

Load only the drivers you need

  1. Add new hardware support dynamically
  2. Keep the core kernel small and efficient ↓

Update drivers without rebooting (in most cases)

Drivers: A Special Type of Module

Here’s the key insight: drivers are a specialized kind of kernel module.

:
While modules can serve various purposes, drivers specifically exist to communicate with hardware.

They’re written with one purpose: to bridge the gap between the kernel’s generic hardware requests and the specific protocols that individual hardware devices understand.

Driver as a Two-Way Translator:

User → Kernel → Driver → Hardware

"Connect to Bluetooth device XYZ"

Driver converts this to:

HCI_COMMAND: (command that only hardware understand)
CREATE_CONNECTION 0xABCDEF
Hardware → Driver → Kernel → User
Hardware sends:
HCI_EVENT:
CONNECTION_COMPLETE
status=0x00
Driver translates: "Connected successfully"


Hope you people liked it and feel free to share your thoughts in comments, repost it and tell me should I also write about How to code a driver? this one as well

Top comments (0)