Linux kernel's source code contains the sources of drivers for plenty of devices under /drivers directory. Sometimes by looking at the source code comment, it's possible to get a hint of the device the driver is written for. But, many times I get no clue whatsoever on the device or the family of devices the driver is targeted for. Is it possible by any chance to trace a driver back to the corresponding device?


It depends on the type of device for which the driver is written. A simple, but common example are PCI devices.

PCI devices identify themselves with a series of registers in the PCI Configuration Space. So, for example, a network card will identify which type of card it is with a series of register values that the Linux kernel can read.

Device drivers for PCI devices export a table of PCI IDs that describe which devices the driver itself can control. This table of IDs is registered with the Linux kernel. The Linux kernel can then walk through each device attached to the system, get the PCI ID from the device, and then check which driver is registered for that ID. This is how a driver is selected for a particular piece of PCI hardware.

I wrote a comprehensive blog post about the Linux network stack (tuning, optimizing, monitoring, and more). At the start of that blog post I walk through the igb Linux network driver code (with actual code samples) and show the code which exports the PCI IDs for the devices that the igb driver can control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.