Backward Compatibility

The current implementation of PCI support in the kernel was not available with version 2.0 of the kernel. With 2.0 the support API was much more raw, because it lacked the various objects that have been described in this chapter.

The six functions to access the configuration space received as arguments the 16-bit low-level key to the PCI device instead of using a pointer to struct pci_dev. Also, you had to include <asm/pcibios.h> before being able to read or write to the configuration space.

Fortunately, dealing with the difference is not a big problem, and if you include sysdep.h you’ll be able to use 2.4 semantics even when compiling under 2.0. PCI support for version 2.0 is available in the header pci-compat.h, automatically included by sysdep.h when you compile under 2.0. The header, as distributed, implements the most important functions used to work with the PCI bus.

If you use pci-compat.h to develop drivers that work all the way from 2.0 through 2.4, you must call pci_release_device when you are done with a pci_dev item. This happens because the fake pci_dev structures created by the header are allocated with kmalloc, whereas the real structures of 2.2 and 2.4 are static resources in the kernel proper. The extra function is defined to do nothing by sysdep.h whenever compiling for 2.2 or 2.4, so it does no harm. Feel free to look at pciregions.c or pcidata.c to see portable code in action.

Another relevant difference in 2.0 is /proc support for PCI. There was no /proc/bus/pci file hierarchy (and no /proc/bus at all, actually), only a single /proc/pci file. It was meant more for human reading than for machine reading, and it was not very readable anyway. Under 2.2 it was possible to select a “backward-compatible /proc/pci” at compile time, but the obsolete file was completely removed in version 2.4.

The concept of hot-pluggable PCI drivers (and struct pci_driver) is new as of version 2.4. We do not offer backward-compatible macros to use the feature on older kernels.

Get Linux Device Drivers, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.