ofw_bus_is_compatible(9)
π ofw_bus_is_compatible β the Kernel Developer's Manual, but make it make sense π
okay bestie, so you know how the manual is literally called ofw_bus_is_compatible(9)? Yeah. That's the whole vibe. It lives in the Kernel Developer's Manual and it's all about checking device tree nodes for compatibility with drivers β like a vibe check, but for hardware. π¦
β¨ 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 of the device tree node is literally how you identify the type of device the node represents. Main character property, honestly. π
It's a list of one or more strings that represent the hardware types the device is compatible with. The common format for these strings is "vendor,hardware" β where "vendor" is an abbreviated name of the manufacturer and "hardware" is a device identifier. Like, for instance, "fsl" for "Freescale" and "imx6ul-i2c" for the I2C controller. Cute, right? π
More than one string is required for compatibility with older revisions of the driver. So if hardware revision B is backward compatible with revision A, the device tree node can signal this compatibility by providing both "vndr,hrdwrA" and "vndr,hrdwrB" strings in the "compatible" property value. This way the older driver can use features available only in revision A, and the new version of the driver can take advantage of the revision B feature set. Everyone eats, no one is left out. π«Ά
okay now the actual functions, one by one, no skips:
ofw_bus_is_compatible()β returns1if the compatstr value occurs in the"compatible"property list of the device tree node associated with the device dev, and0otherwise.ofw_bus_is_compatible_strict()β returns1if the"compatible"property of the device tree node associated with the device dev consists of only one string and this string is equal to compatstr, and0otherwise. Strict means strict, bestie, it's giving picky. πofw_bus_node_is_compatible()β returns1if the compatstr value occurs in the"compatible"property list of the device tree node node, and0otherwise.ofw_bus_search_compatible()β returns a pointer to the first entry of the compat table whoseocd_strfield occurs in the"compatible"property of the device tree node associated with the device dev.
The compat table is an array of struct ofw_compat_data elements, defined as follows:
struct ofw_compat_data {
const char *ocd_str;
uintptr_t ocd_data;
};
β οΈ Heads up: the compat table must be terminated by the entry withocd_strset toNULL. No cap, don't forget the sentinel.
If the device tree node is not compatible with any of the entries, the function returns the pointer to the terminating entry. So you always get a pointer back β worst case it's the sad little null-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 how that works? Probe checks the ocd_data and bails with ENXIO if it's falsy, and attach scoops the features straight out of the same table. Reuse is iconic. π₯
π SEE ALSO π
ofw_bus_find_compatible(9)
π AUTHORS π
This manual page was written by Oleksandr Tymoshenko. Respect the author, bestie. π«‘
β¨ and that's the whole page, fr fr β¨ β this little gem comes from Debian, dated April 8, 2018, and it's filed under ofw_bus_is_compatible(9). Go read your device trees, mwah ππ§
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2018 Oleksandr Tymoshenko
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms