1.\" 2.\" Copyright (c) 2018 Oleksandr Tymoshenko <gonzo@FreeBSD.org> 3.\" 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd April 9, 2018 29.Dt OF_NODE_FROM_XREF 9 30.Os 31.Sh NAME 32.Nm OF_node_from_xref , 33.Nm OF_xref_from_node 34.Nd convert between kernel phandle and effective phandle 35.Sh SYNOPSIS 36.In dev/ofw/ofw_bus.h 37.In dev/ofw/ofw_bus_subr.h 38.Ft phandle_t 39.Fn OF_node_from_xref "phandle_t xref" 40.Ft phandle_t 41.Fn OF_xref_from_node "phandle_t node" 42.Sh DESCRIPTION 43Some OpenFirmware implementations (FDT, IBM) have a concept 44of effective phandle or xrefs. 45They are used to cross-reference device tree nodes. 46For instance, a framebuffer controller may refer to a GPIO 47controller and pin that controls the backlight. 48In this example, the GPIO node would have a cell (32-bit integer) 49property with a reserved name like "phandle" or "linux,phandle" 50whose value uniquely identifies the node. 51The actual name depends on the implementation. 52The framebuffer node would have a property with the name 53described by device bindings (device-specific set of properties). 54It can be a cell property or a combined property with one part 55of it being a cell. 56The value of the framebuffer node's property would be the same 57as the value of the GPIO "phandle" property so it can be said 58that the framebuffer node refers to the GPIO node. 59The kernel uses internal logic to assign unique identifiers 60to the device tree nodes, and these values do not match 61the values of "phandle" properties. 62.Fn OF_node_from_xref 63and 64.Fn OF_xref_from_node 65are used to perform conversion between these two kinds of node 66identifiers. 67.Pp 68.Fn OF_node_from_xref 69returns the kernel phandle for the effective phandle 70.Fa xref . 71If one cannot be found or the OpenFirmware implementation 72does not support effective phandles, the function returns 73the input value. 74.Pp 75.Fn OF_xref_from_xref 76returns the effective phandle for the kernel phandle 77.Fa xref . 78If one cannot be found or the OpenFirmware implementation 79does not support effective phandles, the function returns 80the input value. 81.Sh EXAMPLES 82.Bd -literal 83 phandle_t panelnode, panelxref; 84 char *model; 85 86 if (OF_getencprop(node, "lcd-panel", &panelxref) <= 0) 87 return; 88 89 panelnode = OF_node_from_xref(panelxref); 90 if (OF_getprop_alloc(hdminode, "model", (void **)&model) <= 0) 91 return; 92.Ed 93.Sh SEE ALSO 94.Xr OF_device_from_xref 9 , 95.Xr OF_device_register_xref 9 96.Sh AUTHORS 97.An -nosplit 98This manual page was written by 99.An Oleksandr Tymoshenko Aq Mt gonzo@FreeBSD.org . 100