ofw_bus_is_compatible(9)
π¦ ofw_bus_is_compatible β check device tree nodes for compatibility with drivers
okay bestie, gather round, because this is one of those little manpages from the Kernel Developer's Manual that lowkey runs the whole show: ofw_bus_is_compatible(9). It's the friend group of four functions β ofw_bus_is_compatible, ofw_bus_is_compatible_strict, ofw_bus_node_is_compatible, and ofw_bus_search_compatible β and they all exist to answer one deeply important question: does this device tree node vibe with my driver or not π
β¨ NAME β¨
ofw_bus_is_compatible, ofw_bus_is_compatible_strict, ofw_bus_node_is_compatible, ofw_bus_search_compatible β check device tree nodes for compatibility with drivers πΈ
π SYNOPSIS π
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
int
ofw_bus_is_compatible(device_t dev, const char *compatstr);
int
ofw_bus_is_compatible_strict(device_t dev, const char *compatstr);
int
ofw_bus_node_is_compatible(phandle_t node, const char *compatstr);
const struct ofw_compat_data *
ofw_bus_search_compatible(device_t dev,
const struct ofw_compat_data *compat);
π DESCRIPTION π
So the "compatible" property on a device tree node is basically the node's whole personality β it tells you what kind of device this node even is. And the property? It's a list of one or more strings, each one representing a hardware type the device is compatible with. no cap.
The classic format for these strings is "vendor,hardware", where "vendor" is a short little nickname for the manufacturer and "hardware" is a device identifier. Like, for real: "fsl" is short for "Freescale", and "imx6ul-i2c" is the I2C controller. iconic. π«Ά
More than one string is needed when you want compatibility with older revisions of the driver. The way it works: if hardware revision B is backward compatible with revision A, the device tree node can signal that by putting both "vndr,hrdwrA" and "vndr,hrdwrB" strings in the "compatible" property value. That way the older driver can still use the features that only exist in revision A, while the new version of the driver gets to take full advantage of revision B's feature set. best of both worlds fr fr β¨
π¦ the functions, one by one
ofw_bus_is_compatible()β returns1if the compatstr value shows up anywhere in the"compatible"property list of the device tree node attached to the device dev, and0if it doesn't. simple. clean. slay.ofw_bus_is_compatible_strict()β the picky one, and honestly? valid. Returns1only if the"compatible"property of the device tree node attached to dev consists of just one single string, and that string is exactly equal to compatstr. Anything else?0. periodt.ofw_bus_node_is_compatible()β same energy as the first one but you hand it a node instead of a device: returns1if the compatstr value occurs in the"compatible"property list of the device tree node node, and0otherwise.ofw_bus_search_compatible()β the main character of the group tbh π. It returns a pointer to the first entry of the compat table whoseocd_strfield occurs in the"compatible"property of the device tree node attached to the device dev.
π the compat table, explained
The compat table is just an array of struct ofw_compat_data elements, defined like this:
struct ofw_compat_data {
const char *ocd_str;
uintptr_t ocd_data;
};
β οΈ okay this part is important: the compat table must be terminated by the entry withocd_strset toNULL. Do not forget it. Do not skip it. It's the little safety rail of this whole operation, bestie.
And if the device tree node isn't compatible with any of the entries? The function just hands you back the pointer to that terminating entry. no drama, no crash, just the terminator. π
π EXAMPLES π
static struct ofw_compat_data compat_data[] = {
{"arm,hrdwrA", FEATURE_A},
{"arm,hrdwrB", FEATURE_A | FEATURE_B},
{NULL, 0}
};
static int
hrdwr_probe(device_t dev)
{
...
if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data)
return (ENXIO);
...
}
static int
hrdwr_attach(device_t dev)
{
...
sc = device_get_softc(dev);
sc->sc_features = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
...
}
π§ SEE ALSO π§
ofw_bus_find_compatible(9)
π AUTHORS π
This manual page was written by Oleksandr Tymoshenko.
and that's the whole page, bestie π this one comes to you from Debian, dated April 8, 2018, living in the Kernel Developer's Manual as ofw_bus_is_compatible(9) β go forth and vibe check those device tree nodes, you've got this π¦β¨
π¦ 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
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms