OF_GETPROP(9)
π¦ OF_GETPROP(9) β from the Kernel Developer's Manual, but make it bestie π¦
okay so this is the OF_GETPROP(9) page, and itβs literally all about accessing properties of device tree nodes. The whole squad is here and theyβre iconic. π
β¨ NAME β¨
Meet the property-access besties: OF_getprop, OF_getproplen, OF_getencprop, OF_hasprop, OF_searchprop, OF_searchencprop, OF_getprop_alloc, OF_getencprop_alloc, OF_getprop_alloc_multi, OF_getencprop_alloc_multi, OF_prop_free, OF_nextprop, OF_setprop β they access properties of device tree node. No cap, thatβs the whole vibe. π«Ά
π SYNOPSIS π
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
ssize_t
OF_getproplen(phandle_t node, const char *propname);
ssize_t
OF_getprop(phandle_t node, const char *propname, void *buf, size_t len);
ssize_t
OF_getencprop(phandle_t node, const char *prop, pcell_t *buf,
size_t len);
int
OF_hasprop(phandle_t node, const char *propname);
ssize_t
OF_searchprop(phandle_t node, const char *propname, void *buf,
size_t len);
ssize_t
OF_searchencprop(phandle_t node, const char *propname, pcell_t *buf,
size_t len);
ssize_t
OF_getprop_alloc(phandle_t node, const char *propname, void **buf);
ssize_t
OF_getencprop_alloc(phandle_t node, const char *propname,
pcell_t **buf);
ssize_t
OF_getprop_alloc_multi(phandle_t node, const char *propname, int elsz,
void **buf);
ssize_t
OF_getencprop_alloc_multi(phandle_t node, const char *propname,
int elsz, pcell_t **buf);
void
OF_prop_free(void *buf);
int
OF_nextprop(phandle_t node, const char *propname, char *buf,
size_t len);
int
OF_setprop(phandle_t node, const char *propname, const void *buf,
size_t len);
π DESCRIPTION π
Okay so device nodes can have associated properties. A property is a name plus a value. The name is a human-readable string from 1 to 31 characters long. The value is an array of zero or more bytes that encode certain information β what those bytes mean is literally up to how drivers interpret them. Properties can encode byte arrays, text strings, unsigned 32-bit values, or any combination of these types. π§
A property with a zero-length value usually represents boolean information. If the property is present, it signifies true; otherwise false. π
A byte array is encoded as a sequence of bytes and represents values like MAC addresses. A text string is a sequence of n printable characters. It is encoded as a byte array of length n + 1 bytes with characters represented as bytes plus a terminating null character. Unsigned 32-bit values, also sometimes called cells, are encoded as a sequence of 4 bytes in big-endian order. π
OF_getproplen()β returns either the length of the value associated with the propertypropnamein the node identified bynode, or0if the property exists but has no associated value. Ifpropnamedoes not exist,-1is returned. πOF_getprop()β copies a maximum oflenbytes from the value associated with the propertypropnameof the device nodenodeinto the memory specified bybuf. Returns the actual size of the value or-1if the property does not exist. β¨OF_getencprop()β copies a maximum oflenbytes into memory specified bybuf, then converts cell values from big-endian to host byte order. Returns the actual size of the value in bytes, or-1if the property does not exist.lenmust be a multiple of4. πOF_hasprop()β returns1if the device nodenodehas a property specified bypropname, and zero if the property does not exist. π¦OF_searchprop()β recursively looks for the property specified bypropnamestarting with the device nodenodefollowed by the parent node and up to the root node. If the property is found, the function copies a maximum oflenbytes of the value associated with the property into the memory specified bybuf. Returns the actual size in bytes of the value, or-1if the property does not exist. π₯OF_searchencprop()β recursively looks for the property specified bypropnamestarting with the device nodenodefollowed by the parent node and up to the root node. If the property is found, the function copies a maximum oflenbytes of the value associated with the property into the memory specified bybuf, then converts cell values from big-endian to host byte order. Returns the actual size in bytes of the value, or-1if the property does not exist. πΈOF_getprop_alloc()β allocates memory large enough to hold the value associated with the propertypropnameof the device nodenodeand copies the value into the newly allocated memory region. Returns the actual size of the value and stores the address of the allocated memory in*buf. If the property has a zero-sized value*bufis setNULL. Returns-1if the property does not exist or memory allocation failed. Allocated memory should be released when no longer required by callingOF_prop_free(). The function might sleep when allocating memory. πOF_getencprop_alloc()β allocates enough memory to hold the value associated with the propertypropnameof the device nodenode, copies the value into the newly allocated memory region, and then converts cell values from big-endian to host byte order. The actual size of the value is returned and the address of allocated memory is stored in*buf. If the property has zero-length value,*bufis set toNULL. Returns-1if the property does not exist or memory allocation failed or the size of the value is not divisible by a cell size (4bytes). Allocated memory should be released when no longer required by callingOF_prop_free(). The function might sleep when allocating memory. πOF_getprop_alloc_multi()β allocates memory large enough to hold the value associated with the propertypropnameof the device nodenodeand copies the value into the newly allocated memory region. The value is expected to be an array of zero or more elementselszbytes long. Returns the number of elements in the value and stores the address of the allocated memory in*buf. If the property has a zero-sized value*bufis setNULL. Returns-1if the property does not exist or memory allocation failed or the size of the value is not divisible byelsz. Allocated memory should be released when no longer required by callingOF_prop_free(). The function might sleep when allocating memory. βOF_getencprop_alloc_multi()β allocates memory large enough to hold the value associated with the propertypropnameof the device nodenodeand copies the value into the newly allocated memory region, and then converts cell values from big-endian to host byte order. The value is expected to be an array of zero or more elementselszbytes long. Returns the number of elements in the value and stores the address of the allocated memory in*buf. If the property has a zero-sized value*bufis setNULL. Returns-1if the property does not exist or memory allocation failed or the size of the value is not divisible byelsz. Allocated memory should be released when no longer required by callingOF_prop_free(). The function might sleep when allocating memory. π«OF_prop_free()β releases memory atbufthat was allocated byOF_getprop_alloc(),OF_getencprop_alloc(),OF_getprop_alloc_multi(),OF_getencprop_alloc_multi(). πOF_nextprop()β copies a maximum ofsizebytes of the name of the property following thepropnameproperty intobuf. IfpropnameisNULL, the function copies the name of the first property of the device nodenode.OF_nextprop()returns-1ifpropnameis invalid or there is an internal error,0if there are no more properties afterpropname, or1otherwise. πOF_setprop()β sets the value of the propertypropnamein the device nodenodeto the value beginning at the address specified bybufand running forlenbytes. If the property does not exist, the function tries to create it.OF_setprop()returns the actual size of the new value, or-1if the property value cannot be changed or the new property cannot be created. π₯
π§Έ EXAMPLES π§Έ
Hereβs the code, bestie β exact as the original, no cap: π«Ά
phandle_t node;
phandle_t hdmixref, hdminode;
device_t hdmi;
uint8_t mac[6];
char *model;
/*
* Get a byte array property
*/
if (OF_getprop(node, "eth,hwaddr", mac, sizeof(mac)) != sizeof(mac))
return;
/*
* Get internal node reference and device associated with it
*/
if (OF_getencprop(node, "hdmi", &hdmixref) <= 0)
return;
hdmi = OF_device_from_xref(hdmixref);
/*
* Get string value of model property of HDMI framer node
*/
hdminode = OF_node_from_xref(hdmixref);
if (OF_getprop_alloc(hdminode, "model", (void **)&model) <= 0)
return;
π SEE ALSO π
π AUTHORS π
This manual page was written by Oleksandr Tymoshenko <gonzo@FreeBSD.org>. π
π Sign-off: this cutie is from Debian, dated June 23, 2018, and itβs literally the OF_GETPROP(9) manual page. Bye bestie! π
π«Ά
π¦ where this page comes from
- freebsd 14.5: base 14.5
- 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