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