DEVICE_IDENTIFY(9)
π DEVICE_IDENTIFY(9) π
okay bestie, so we're in the Kernel Developer's Manual today and the star of the show is DEVICE_IDENTIFY β the function that goes "hey, i see a device, let me tell the kernel about it" β¨
β¨ NAME β¨
DEVICE_IDENTIFY β identify a device, register it π«Ά
πΈ SYNOPSIS πΈ
#include <sys/param.h>
#include <sys/bus.h>
void
DEVICE_IDENTIFY(driver_t *driver, device_t parent);
like, that's the whole signature. cute, right? π
π¦ DESCRIPTION π¦
so the identify function for a device is only needed for devices on buses that literally cannot identify their own children independently β think the ISA bus, that's the classic example π
what it does: it recognizes the device (usually by poking at non-ambiguous registers in the hardware β iykyk) and then tells the kernel about it, which creates a brand new device instance. it's giving matchmaker energy fr fr π
then you use BUS_ADD_CHILD(9) to register the device as a child of the bus. and the device's resources β like IRQ and I/O ports β get registered with the kernel by calling bus_set_resource() for each resource. (go read bus_set_resource(9) for the whole tea, i'm not gonna re-explain it here π)
now here's the part that's giving caution β οΈ β the device tree and the device driver tree are disjoint, so DEVICE_IDENTIFY() has to keep that in mind. if you load and unload your device driver that has the identify routine, the child node has the potential to add the same node multiple times unless specific measures are taken to preclude that possibility. no cap, that's a real one. don't let it happen to you π
π EXAMPLES π
here's some pseudo-code showing a function that probes for a piece of hardware and registers it and its resource (an I/O port) with the kernel. slay π
void
foo_identify(driver_t *driver, device_t parent)
{
device_t child;
retrieve_device_information;
if (devices matches one of your supported devices &&
not already in device tree) {
child = BUS_ADD_CHILD(parent, 0, "foo", -1);
bus_set_resource(child, SYS_RES_IOPORT, 0, FOO_IOADDR, 1);
}
}
notice that <purple>not already in device tree</purple> check? that's the whole "don't add the same node twice" thing from the description. main character behavior honestly π
π SEE ALSO π
BUS_ADD_CHILD(9)bus_set_resource(9)device(9)device_add_child(9)DEVICE_ATTACH(9)DEVICE_DETACH(9)DEVICE_PROBE(9)DEVICE_SHUTDOWN(9)
go read them all bestie, they're all connected π§
π AUTHORS π
this manual page was written by Alexander Langer <alex@FreeBSD.org> π
and that's the whole page!! Debian, January 15, 2017 β periodt π β¨ mwah, go register some devices responsibly π«Άπ
π¦ 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) 2001 Alexander Langer
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms