OF_DEVICE_FROM_XREF(9)
β¨ OF_DEVICE_FROM_XREF(9) β¨
okay bestie, welcome to the Kernel Developer's Manual section 9, where we talk about OF_device_from_xref, OF_xref_from_device, and OF_device_register_xref β the little trio that handles the mappings between xrefs and devices. yes this is real and yes it slays π
πΈ NAME πΈ
OF_device_from_xref,OF_xref_from_device,OF_device_register_xrefβ manage mappings between xrefs and devices π¦
π SYNOPSIS π
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
int
OF_device_register_xref(phandle_t xref, device_t dev);
device_t
OF_device_from_xref(phandle_t xref);
phandle_t
OF_xref_from_device(device_t dev);
π DESCRIPTION π
so here's the vibe: when a device tree node references another node, the driver might need to get a device_t instance that's associated with that referenced node. like, imagine an Ethernet driver trying to reach its PHY device. to make that whole thing possible, the kernel keeps a table mapping effective handles to device_t instances. iconic behavior fr fr π
OF_device_register_xref()β adds a map entry from the effective phandle xref to dev. and if a mapping entry for xref already exists? it gets replaced with the new one, no hesitation, main character energy. this function always returns0. always. periodt.OF_device_from_xref()β returns thedevice_tinstance associated with the effective phandle xref. but if no such mapping exists, it returnsNULL. sad but true πOF_xref_from_device()β returns the effective phandle associated with the device dev. and if no such mapping exists, it returns0. ngl that's just how it is π«Ά
π¦ EXAMPLES π¦
static int
acmephy_attach(device_t dev)
{
phandle_t node;
/* PHY node is referenced from eth device, register it */
node = ofw_bus_get_node(dev);
OF_device_register_xref(OF_xref_from_node(node), dev);
return (0);
}
look at that. registering the PHY node, returning (0), being adorable about it β¨
π SEE ALSO π
OF_node_to_xref(9)β go read that one too bestie, iykyk π
π AUTHORS π
this manual page was written by Oleksandr Tymoshenko <gonzo@FreeBSD.org>. give them their flowers π
and that's the whole page, no cap. every flag, every return value, everyNULLand every0accounted for π
Debian β’ April 9, 2018 β k bye bestie, go map some xrefs ππ¦β¨
π¦ 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) 2018 Oleksandr Tymoshenko <gonzo@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms