xref: /freebsd/share/man/man9/OF_node_from_xref.9 (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
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
43.Pp
44Some OpenFirmware implementations (FDT, IBM) have a concept
45of effective phandle or xrefs.
46They are used to cross-reference device tree nodes.
47For instance, a framebuffer controller may refer to a GPIO
48controller and pin that controls the backlight.
49In this example, the GPIO node would have a cell (32-bit integer)
50property with a reserved name like "phandle" or "linux,phandle"
51whose value uniquely identifies the node.
52The actual name depends on the implementation.
53The framebuffer node would have a property with the name
54described by device bindings (device-specific set of properties).
55It can be a cell property or a combined property with one part
56of it being a cell.
57The value of the framebuffer node's property would be the same
58as the value of the GPIO "phandle" property so it can be said
59that the framebuffer node refers to the GPIO node.
60The kernel uses internal logic to assign unique identifiers
61to the device tree nodes, and these values do not match
62the values of "phandle" properties.
63.Fn OF_node_from_xref
64and
65.Fn OF_xref_from_node
66are used to perform conversion between these two kinds of node
67identifiers.
68.Pp
69.Fn OF_node_from_xref
70returns the kernel phandle for the effective phandle
71.Fa xref .
72If one cannot be found or the OpenFirmware implementation
73does not support effective phandles, the function returns
74the input value.
75.Pp
76.Fn OF_xref_from_xref
77returns the effective phandle for the kernel phandle
78.Fa xref .
79If one cannot be found or the OpenFirmware implementation
80does not support effective phandles, the function returns
81the input value.
82.Sh EXAMPLES
83.Bd -literal
84    phandle_t panelnode, panelxref;
85    char *model;
86
87    if (OF_getencprop(node, "lcd-panel", &panelxref) <= 0)
88        return;
89
90    panelnode = OF_node_from_xref(panelxref);
91    if (OF_getprop_alloc(hdminode, "model", (void **)&model) <= 0)
92        return;
93.Ed
94.Sh SEE ALSO
95.Xr OF_device_from_xref 9
96.Xr OF_device_register_xref 9
97.Sh AUTHORS
98.An -nosplit
99This manual page was written by
100.An Oleksandr Tymoshenko Aq Mt gonzo@FreeBSD.org .
101