DRIVER(9)
πΈ NAME πΈ
okay so this is DRIVER(9) from the Kernel Developer's Manual, and the whole vibe is: driver β the structure describing a device driver. that's it, that's the NAME section, short and iconic, periodt. π
β¨
β¨ SYNOPSIS β¨
here's the exact cast of characters, bestie β includes, function declarations, method table, driver struct, and the DRIVER_MODULE registration, all copied character-for-character:
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
static int foo_probe(device_t);
static int foo_attach(device_t);
static int foo_detach(device_t);
static int foo_frob(device_t, int, int);
static int foo_twiddle(device_t, char *);
static device_method_t foo_methods[] = {
/* Methods from the device interface */
DEVMETHOD(device_probe, foo_probe),
DEVMETHOD(device_attach, foo_attach),
DEVMETHOD(device_detach, foo_detach),
/* Methods from the bogo interface */
DEVMETHOD(bogo_frob, foo_frob),
DEVMETHOD(bogo_twiddle, foo_twiddle),
/* Terminate method list */
DEVMETHOD_END
};
static driver_t foo_driver = {
"foo",
foo_methods,
sizeof(struct foo_softc)
};
DRIVER_MODULE(foo, bogo, foo_driver, NULL, NULL);
π DESCRIPTION π
okay so every driver in the kernel is described by a driver_t structure. that structure contains:
- the name of the device,
- a pointer to a list of methods,
- an indication of the kind of device which the driver implements,
- and the size of the private data which the driver needs to associate with a device instance.
each driver will implement one or more sets of methods β those sets are called interfaces. the example driver up in the synopsis implements the standard "driver" interface and the fictitious "bogo" interface. no cap. π«Ά
when a driver is registered with the system (by the DRIVER_MODULE macro, see DRIVER_MODULE(9)), it is added to the list of drivers contained in the devclass of its parent bus type. for instance, all PCI drivers would be contained in the devclass named "pci" and all ISA drivers would be in the devclass named "isa". the reason the drivers are not held in the device object of the parent bus is to handle multiple instances of a given type of bus β iconic design choice, tbh. the DRIVER_MODULE macro will also create the devclass with the name of the driver and can optionally call extra initialisation code in the driver by specifying an extra module event handler and argument as the last two arguments. π₯
π₯ SEE ALSO π₯
devclass(9)device(9)DEVICE_ATTACH(9)DEVICE_DETACH(9)DEVICE_IDENTIFY(9)DEVICE_PROBE(9)DEVICE_SHUTDOWN(9)DRIVER_MODULE(9)
π¦ HISTORY π¦
the driver framework first appeared in FreeBSD 2.2.7 β history icon behavior, fr fr. π¦
π AUTHORS π
this manual page was written by Doug Rabson β credits to him, bestie, we love a legend. π
this cutie is from the Debian source/version, dated April 19, 2022, and the page is DRIVER(9) β bye bestie, go write a driver ππ«Άβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1998 Doug Rabson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms