0

I have noticed that some drivers are more difficult to find for certain distributions of Linux.

Is it possible to make a driver interface or driver API that is the same for multiple Linux distributions?

Has this been done? A common driver API for multiple Linux OS?

1
  • 1
    I fully expect drivers to be dependent on the currently running or available kernels, and whether or not someone bothered to compile them for said kernels. There's no API (or issue with such a thing). Commented Jan 25 at 17:18

2 Answers 2

2

The Linux kernel developers have decided that they do not want to expend the considerable amount of resources required to maintain a stable API and, more importantly, a stable ABI for drivers. The Linux kernel does guarantee both stable APIs and ABIs for userspace code.

The proper way to develop a driver for Linux is to bring the code up to a level of quality that is acceptable for the Linux kernel, then merge it into the Linux kernel source code. That way, every time the API changes, the person who makes the API change is responsible for updating all the drivers as well, and every time the kernel gets compiled, the driver gets compiled with the correct ABI.

If a hardware vendor does not want to merge the driver into the kernel, then it is their responsibility to make the driver available to their customers.

In 2003, Dell developed Dynamic Kernel Module Support, a framework that allows to dynamically detect and compile drivers and other Linux kernel modules. However, again, it is the responsibility of the DKMS developers to make sure DKMS stays compatible with Linux distributions, and if a hardware vendor wants to use DKMS, it is their responsibility to make their drivers compatible with it.

It is the hardware vendors responsibility to either make drivers available, or to make documentation available that would allow someone else to develop a driver. This is simply because nobody else has the necessary information to do it.

This is really no different from other operating systems. I have devices which don't work under Windows because the hardware vendor refuses to make Windows drivers available for it and does not provide any documentation, and I have devices which don't work under macOS for the same reasons. Linux is not special here.

What is special about Linux is that, if a hardware vendor releases their driver to be included into the Linux kernel, and provides the necessary documentation, then the Linux community will maintain the driver for them, for free.

[Note: most of what I wrote here is not specific to Linux, it also applies to many other open source operating systems such as the various BSDs (NetBSD, OpenBSD, FreeBSD, Dragonfly BSD, etc.), Haiku, or Redox.]

The Linux kernel developers have documented their reasoning in The Linux Kernel Driver Interface – all of your questions answered and then some. Quoting from the Executive Summary [bold italic emphasis mine]:

You think you want a stable kernel interface, but you really do not, and you don’t even know it. What you want is a stable running driver, and you get that only if your driver is in the main kernel tree. You also get lots of other good benefits if your driver is in the main kernel tree, all of which has made Linux into such a strong, stable, and mature operating system which is the reason you are using it in the first place.

To answer your questions directly:

Is it possible to make a driver interface or driver API that is the same for multiple Linux distributions?

Yes, it is possible, but it is not necessary.

Has this been done? A common driver API for multiple Linux OS?

No, it has not been done, because the people who would benefit from it (proprietary hardware vendors) are not willing to pay for it, and the people responsible for developing the Linux kernel do not want it.

Some vendors have done it for parts of the Linux kernel. For example, Nvidia developed an abstraction that would allow their proprietary drivers to work with multiple versions of Linux and multiple distributions. But they did not share this development with others, so it only worked for Nvidia drivers.

0

There is VFIO - “Virtual Function I/O” in which:

  1. The vfio-pci Kernel module is maintained by the Linux Kernel developers.
  2. /usr/include/linux/vfio.h defines an IOCTL API interface between the Kernel module and user space, which I presume is a stable API. E.g. code which was developed for VFIO in a 4.x series Kernel also worked without modification in 5.x and 6.x series Kernels.
  3. The actual driver for a device is implemented in user space.

My use case for VFIO was creating a driver for Xilinx IP in a FPGA which provides a custom PCIe endpoint. While Xilinx provided Linux drivers for their IP, the Xilinx drivers were provided as source for out of tree Kernel modules which had the following which I considered disadvantageous:

  1. Marked the Kernel as tainted, which could be an issue if you want to get support for an error from the Kernel.
  2. If secure boot is enabled, you need to sign out of tree Kernel modules before they can be loaded.

Whereas by binding the vfio-pci Kernel module to a custom device, a driver could then be written in user space without having to maintain a Kernel module.

Another use case for VFIO is PCI passthrough via OVMF, offering the virtual machine native graphics performance which is useful for graphic-intensive tasks.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.