DEVICE_IDENTIFY(9)
π DEVICE_IDENTIFY(9) β the kernel dev manual, but make it make sense
Okay bestie, so this is DEVICE_IDENTIFY(9) from the kernel developer's manual, and it's literally all about registering new child devices on a bus. Periodt. Let's get into it. β¨
π NAME π
DEVICE_IDENTIFY β identify new child devices and register them. That's the whole vibe: spot 'em, then sign 'em up. π
π¦ SYNOPSIS π¦
#include <sys/param.h>
#include <sys/bus.h>
void
DEVICE_IDENTIFY(driver_t *driver, device_t parent);
No cap, that's the exact signature. Don't touch it, just use it. π«Ά
πΈ DESCRIPTION πΈ
So the identify method of a device driver is how you add devices that the standard bus method can't enumerate. Like, the bus is doing its usual thing and some devices are just sitting there being unenumerable, and this is your moment. π
Devices can be enumerated in various ways, including accessing non-ambiguous device registers and parsing firmware tables. Software-only pseudo devices also get enumerated via identify methods all the time β they're not even real hardware, they're just vibing. π§
For each newly identified device, you should create a new device instance by invoking the BUS_ADD_CHILD(9) method. And if your identify method can discover other properties about the new device, those should be set too. For example, device resources should be added to the device by calling bus_set_resource(9) for each resource. Don't leave your children resourceless, that's not the move. π
Heads up bestie: anidentifymethod might be invoked multiple times. If a device driver is unloaded and loaded, theidentifymethod will be called a second time after being reloaded. So youridentifymethod should avoid duplicate devices β no clones, no repeats, we are not doing that today. π
Devices added by identify methods typically use a fixed device name, in which case device_find_child(9) can be used to detect existing devices. Use it, bestie β it's literally the vibe check for "does this child already exist?" β
π₯ EXAMPLES π₯
The following pseudo-code shows an example of a function that probes for a piece of hardware and registers it and its resource (an I/O port) with the parent bus device. It's giving main character energy, fr fr. π
void
foo_identify(driver_t *driver, device_t parent)
{
device_t child;
retrieve_device_information;
if (devices matches one of your supported devices &&
device_find_child(parent, "foo", DEVICE_UNIT_ANY) == NULL) {
child = BUS_ADD_CHILD(parent, 0, "foo", DEVICE_UNIT_ANY);
bus_set_resource(child, SYS_RES_IOPORT, 0, FOO_IOADDR, 1);
}
}
See how it checks device_find_child(parent, "foo", DEVICE_UNIT_ANY) == NULL before adding? That's the anti-duplicate slay. No double-adding, no drama. π
π SEE ALSO π
All the icons, all linked. Go read 'em. πβ¨
π«Ά AUTHORS π«Ά
This manual page was written by Alexander Langer <alex@FreeBSD.org>. Iconic behavior, honestly. π
Okay that's the whole page, bestie β you're now officially enrolled in the identify-method fan club. This was the DEVICE_IDENTIFY(9) page from the Debian kernel developer's manual, dated February 5, 2025. Slay. πβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 2001 Alexander Langer
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms