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