DRIVER_MODULE(9)
π DRIVER_MODULE(9) β the kernel driver declaration macro, bestie π
okay so this is the DRIVER_MODULE(9) page from the Kernel Developer's Manual, and it's literally all about how you tell the kernel "hey girl, here's a driver, pls notice her" β¨ no cap, it's giving main character energy for your kernel module.
πΈ NAME πΈ
DRIVER_MODULE, DRIVER_MODULE_ORDERED, EARLY_DRIVER_MODULE, EARLY_DRIVER_MODULE_ORDERED β the kernel driver declaration macro π
β¨ SYNOPSIS β¨
like, include these first, obviously:
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
and then the actual macros, slay:
DRIVER_MODULE(name, busname, driver_t driver, modeventhand_t evh,
void *arg);
DRIVER_MODULE_ORDERED(name, busname, driver_t driver,
modeventhand_t evh, void *arg, int order);
EARLY_DRIVER_MODULE(name, busname, driver_t driver, modeventhand_t evh,
void *arg, int pass);
EARLY_DRIVER_MODULE_ORDERED(name, busname, driver_t driver,
modeventhand_t evh, void *arg, enum sysinit_elem_order order,
int pass);
π DESCRIPTION π
so the DRIVER_MODULE() macro declares a kernel driver, periodt. it expands into the real driver declaration, and the phrase name gets used as the naming prefix for the driver and all its functions π«Ά lowkey important: name is supplied as plain text, not a char or char * β don't come at it with pointers, she's not that kind of girl.
busname is the parent bus of the driver (PCI, ISA, PPBUS and others), like 'pci', 'isa', or 'ppbus' ππ¨
the identifier you use in DRIVER_MODULE() can totally be different from the driver name. also, the same driver identifier can exist on different buses β and that's actually a pretty clean way of making front ends for different cards using the same driver on the same or different buses. iconic. for example, this is allowed:
DRIVER_MODULE(foo, isa, foo_driver, NULL, NULL);
DRIVER_MODULE(foo, pci, foo_driver, NULL, NULL);
driver is the driver of type driver_t, which contains the information about the driver β so it's one of the two most important parts of the call to DRIVER_MODULE() π (yes, she said one of the two, that's the whole thought, moving on).
the evh argument is the event handler that gets called when the driver (or module) is loaded or unloaded β see module(9) for the deets π
the arg is unused at this time and should be a NULL pointer. like, she's just there. vibe check: pass NULL π
the DRIVER_MODULE_ORDERED() macro lets a driver be registered in a specific order π¦ this is useful if a single kernel module contains multiple drivers that are inter-dependent. 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 β¨
the EARLY_DRIVER_MODULE() macro lets a driver be registered for a specific pass level π 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. 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. once a driver is registered it is available to attach to devices for all subsequent passes π
the EARLY_DRIVER_MODULE_ORDERED() macro lets a driver be registered both in a specific order and for a specific pass level. yeah, she does both π
π¦ SEE ALSO π¦
device(9), driver(9), module(9), MODULE_PNP_INFO(9), SYSINIT(9)
π HISTORY π
prior to FreeBSD 14.0, these macros accepted an additional devclass_t argument after driver. so if you're reading old code and something looks off, that's why, iykyk π
π AUTHORS π
this manual page was written by Alexander Langer <alex@FreeBSD.org> π«Ά thank you king
and that's the whole page, bestie π this was the DRIVER_MODULE(9) man page, from the Debian crew, dated April 19, 2022 β go forth and declare your drivers, you absolute icon π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2000 Alexander Langer
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms