DRIVER_MODULE(9)
π DRIVER_MODULE(9) π
okay bestie, welcome to the DRIVER_MODULE(9) page from the Kernel Developer's Manual β yes we're in the kernel dev manual, we're that girl now. grab a boba, this one's about how kernel drivers announce themselves to the world β¨
πΈ NAME πΈ
DRIVER_MODULE, DRIVER_MODULE_ORDERED, EARLY_DRIVER_MODULE, EARLY_DRIVER_MODULE_ORDERED β the macro that declares a kernel driver, fr fr π
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
DRIVER_MODULE(name, busname, driver_t driver, devclass_t devclass,
modeventhand_t evh, void *arg);
DRIVER_MODULE_ORDERED(name, busname, driver_t driver,
devclass_t devclass, modeventhand_t evh, void *arg, int order);
EARLY_DRIVER_MODULE(name, busname, driver_t driver, devclass_t devclass,
modeventhand_t evh, void *arg, enum sysinit_elem_order order,
int pass);
EARLY_DRIVER_MODULE_ORDERED(name, busname, driver_t driver,
devclass_t devclass, modeventhand_t evh, void *arg,
enum sysinit_elem_order order, int pass);
π¦ DESCRIPTION π¦
so like, DRIVER_MODULE() is the macro that declares a kernel driver. it expands into the actual real driver declaration, and that phrase name gets used as the naming prefix for the driver AND all its functions. lowkey important: it's supplied as plain text, not a char or a char *. no cap π«Ά
busname is the parent bus of the driver β think PCI, ISA, PPBUS and the rest of the squad β like pci, isa, or ppbus. iconic lineup honestly.
the identifier you use in DRIVER_MODULE() can be different from the driver name π. also, the same driver identifier can totally live on different buses β which is a pretty clean way of making front ends for different cards using the same driver on the same or different buses. like, this is allowed, and it slays:
DRIVER_MODULE(foo, isa, foo_driver, foo_devclass, NULL, NULL);
DRIVER_MODULE(foo, pci, foo_driver, foo_devclass, NULL, NULL);
driver is the driver of type driver_t, which holds all the info about the driver β and that's why it's one of the two most important parts of the call to DRIVER_MODULE(). main character energy tbh π
the devclass argument carries the kernel-internal info about the device, and it'll be used inside the kernel driver module. π
the evh argument is the event handler β it gets called whenever the driver (or module) is loaded or unloaded (peep module(9) for the tea).
the arg is unused at this time and should be a NULL pointer. it's giving "invited but didn't show up" π
DRIVER_MODULE_ORDERED() lets a driver register in a specific order. super useful if one single kernel module contains multiple drivers that are inter-dependent (they're in their codependent era π). the order argument should be one of the SYSINIT(9) initialization ordering constants (SI_ORDER_*). the default order for a driver module is SI_ORDER_MIDDLE. typically a module will specify an order of SI_ORDER_ANY for a single driver to make sure it's registered last β closing the group chat, last one out πͺβ¨
EARLY_DRIVER_MODULE() lets a driver register for a specific pass level. here's the vibe: the boot time probe and attach process makes multiple passes over the device tree. certain critical drivers that provide basic services needed by other devices get attached during earlier passes β they're the ones who show up early and set up the venue π. most drivers are attached in a final general pass. a driver that attaches during an early pass must register for a specific pass level (BUS_PASS_*) via the pass argument. and once a driver is registered, it's available to attach to devices for all subsequent passes. periodt. π
EARLY_DRIVER_MODULE_ORDERED() lets a driver register both in a specific order and for a specific pass level. best of both worlds, we love a multitasker π
π SEE ALSO π
π AUTHORS π
this manual page was written by Alexander Langer <alex@FreeBSD.org>. thank you for your service king π«‘
and that's a wrap bestie!! this page came from the <strong>Debian</strong> crew, dated <strong>February 12, 2018</strong>, and yes it's still filed under <strong>DRIVER_MODULE(9)</strong> in the kernel developer manual β go forth and declare ur drivers, ily πβ¨π¦
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2000 Alexander Langer
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms