OF_DEVICE_FROM_XREF(9)
π OF_DEVICE_FROM_XREF π
okay bestie, welcome to OF_DEVICE_FROM_XREF(9) β the section 9 kernel developer's manual page that's literally all about keeping track of who's who in the device tree π
β¨ NAME β¨
OF_device_from_xref, OF_xref_from_device, OF_device_register_xref, OF_device_unregister_xref β manage mappings between xrefs and devices. yes girl, it's giving "matchmaker for nodes" π
π¦ 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);
void
OF_device_unregister_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);
like, four functions, two headers, zero drama π«Ά
πΈ DESCRIPTION πΈ
so picture this: a device tree node is out here referencing another node (main character energy tbh), and the driver lowkey needs to get the device_t instance that's associated with the referenced node. classic example? an Ethernet driver trying to vibe with a PHY device. to make that whole situation possible, the kernel keeps a whole table mapping effective handles to device_t instances. it's giving rolodex π
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 cap. this function always returns0. always. it's an overachiever in the consistency department πOF_device_unregister_xref()β removes the map entry from the effective phandle xref to dev. if there's no mapping entry for xref? it just silently returns. no error, no fuss, no text back, it's giving read receipt off π«₯OF_device_from_xref()β returns thedevice_tinstance associated with the effective phandle xref. if that mapping doesn't exist, it returnsNULL. bestie said "not found" and moved on πOF_xref_from_device()β returns the effective phandle associated with the device dev. and if no such mapping exists, it returns0. periodt π
π§ EXAMPLES π§
ok so here's the whole thing in action:
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);
}
see how the comment says it all? the PHY node is referenced from the eth device, and we register it. iconic behavior honestly β
π₯ SEE ALSO π₯
OF_node_to_xref(9)β go read that one next, iykyk
π AUTHORS π
this manual page was written by Oleksandr Tymoshenko <gonzo@FreeBSD.org>. we stan a documentation legend π
and that's a wrap, bestie! this page came to you courtesy of Debian, dated April 3, 2025, and yes β OF_DEVICE_FROM_XREF(9) is the name and it's staying in the group chat ππ¦β¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2018 Oleksandr Tymoshenko <gonzo@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms