OF_NODE_FROM_XREF(9)
β¨ NAME β¨
OF_node_from_xref, OF_xref_from_node β the little glow-up that converts between a kernel phandle and an effective phandle π«
okay so bestie, this is page OF_NODE_FROM_XREF(9) from the Kernel Developer's Manual, and it's genuinely iconic. two tiny functions, one big job: translating between two flavours of node ID so your device tree doesn't ghost you. π¦
πΈ SYNOPSIS πΈ
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
phandle_t
OF_node_from_xref(phandle_t xref);
phandle_t
OF_xref_from_node(phandle_t node);
π DESCRIPTION π
so some OpenFirmware implementations (FDT, IBM) have this whole concept of an effective phandle, aka an xref. they exist to cross-reference device tree nodes, which is very main character of them. β¨
picture this π
: a framebuffer controller wants to point at a GPIO controller <em>and</em> a pin, because that's what controls the backlight. in that setup, the GPIO node would have a cell (32-bit integer) property with a reserved name like "phandle" or "linux,phandle", and its value uniquely identifies the node. the actual name depends on the implementation, iykyk. then the framebuffer node would have a property with the name described by device bindings (that's the device-specific set of properties). it can be a cell property, or a combined property with one part of it being a cell. the value of the framebuffer node's property would be the same as the value of the GPIO "phandle" property β so yeah, we can say the framebuffer node refers to the GPIO node. obsessed. π«Ά
but here's the plot twist π: the kernel uses its own internal logic to assign unique identifiers to the device tree nodes, and those values do not match the values of the "phandle" properties. so we need a translator. that's literally what these two are for β OF_node_from_xref() and OF_xref_from_node() perform the conversion between these two kinds of node identifiers. periodt. π
OF_node_from_xref()β hands you the kernel phandle for the effective phandle xref. and if one can't be found, or the OpenFirmware implementation just doesn't support effective phandles at all? it returns the input value. no drama, no cap. πOF_xref_from_xref()β hands you the effective phandle for the kernel phandle xref. same deal: if one can't be found, or the implementation doesn't support effective phandles, it returns the input value. π
π EXAMPLES π
phandle_t panelnode, panelxref;
char *model;
if (OF_getencprop(node, "lcd-panel", &panelxref) <= 0)
return;
panelnode = OF_node_from_xref(panelxref);
if (OF_getprop_alloc(hdminode, "model", (void **)&model) <= 0)
return;
look at her go π so clean, so slay π₯
π SEE ALSO π
π AUTHORS π
this manual page was written by Oleksandr Tymoshenko <gonzo@FreeBSD.org>. we stan. π«Άβ¨
and that's the whole vibe check, bestie β Debian, April 9, 2018, page OF_NODE_FROM_XREF(9), out. π
πΈ bye babes! π¦π
π¦ 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