xref: /freebsd-src/share/man/man9/OF_device_from_xref.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1*ac32b99cSOleksandr Tymoshenko.\"
2*ac32b99cSOleksandr Tymoshenko.\" Copyright (c) 2018 Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3*ac32b99cSOleksandr Tymoshenko.\"
4*ac32b99cSOleksandr Tymoshenko.\" All rights reserved.
5*ac32b99cSOleksandr Tymoshenko.\"
6*ac32b99cSOleksandr Tymoshenko.\" Redistribution and use in source and binary forms, with or without
7*ac32b99cSOleksandr Tymoshenko.\" modification, are permitted provided that the following conditions
8*ac32b99cSOleksandr Tymoshenko.\" are met:
9*ac32b99cSOleksandr Tymoshenko.\" 1. Redistributions of source code must retain the above copyright
10*ac32b99cSOleksandr Tymoshenko.\"    notice, this list of conditions and the following disclaimer.
11*ac32b99cSOleksandr Tymoshenko.\" 2. Redistributions in binary form must reproduce the above copyright
12*ac32b99cSOleksandr Tymoshenko.\"    notice, this list of conditions and the following disclaimer in the
13*ac32b99cSOleksandr Tymoshenko.\"    documentation and/or other materials provided with the distribution.
14*ac32b99cSOleksandr Tymoshenko.\"
15*ac32b99cSOleksandr Tymoshenko.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16*ac32b99cSOleksandr Tymoshenko.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*ac32b99cSOleksandr Tymoshenko.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*ac32b99cSOleksandr Tymoshenko.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19*ac32b99cSOleksandr Tymoshenko.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*ac32b99cSOleksandr Tymoshenko.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*ac32b99cSOleksandr Tymoshenko.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*ac32b99cSOleksandr Tymoshenko.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*ac32b99cSOleksandr Tymoshenko.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*ac32b99cSOleksandr Tymoshenko.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*ac32b99cSOleksandr Tymoshenko.\"
26*ac32b99cSOleksandr Tymoshenko.Dd April 9, 2018
27*ac32b99cSOleksandr Tymoshenko.Dt OF_DEVICE_FROM_XREF 9
28*ac32b99cSOleksandr Tymoshenko.Os
29*ac32b99cSOleksandr Tymoshenko.Sh NAME
30*ac32b99cSOleksandr Tymoshenko.Nm OF_device_from_xref ,
31*ac32b99cSOleksandr Tymoshenko.Nm OF_xref_from_device ,
32*ac32b99cSOleksandr Tymoshenko.Nm OF_device_register_xref
33*ac32b99cSOleksandr Tymoshenko.Nd "manage mappings between xrefs and devices"
34*ac32b99cSOleksandr Tymoshenko.Sh SYNOPSIS
35*ac32b99cSOleksandr Tymoshenko.In dev/ofw/ofw_bus.h
36*ac32b99cSOleksandr Tymoshenko.In dev/ofw/ofw_bus_subr.h
37*ac32b99cSOleksandr Tymoshenko.Ft int
38*ac32b99cSOleksandr Tymoshenko.Fn OF_device_register_xref "phandle_t xref" "device_t dev"
39*ac32b99cSOleksandr Tymoshenko.Ft device_t
40*ac32b99cSOleksandr Tymoshenko.Fn OF_device_from_xref "phandle_t xref"
41*ac32b99cSOleksandr Tymoshenko.Ft phandle_t
42*ac32b99cSOleksandr Tymoshenko.Fn OF_xref_from_device "device_t dev"
43*ac32b99cSOleksandr Tymoshenko.Sh DESCRIPTION
44*ac32b99cSOleksandr TymoshenkoWhen a device tree node references another node, the driver may
45*ac32b99cSOleksandr Tymoshenkoneed to get a device_t instance associated with the referenced node.
46*ac32b99cSOleksandr TymoshenkoFor instance, an Ethernet driver accessing a PHY device.
47*ac32b99cSOleksandr TymoshenkoTo make this possible, the kernel maintains a table that
48*ac32b99cSOleksandr Tymoshenkomaps effective handles to device_t instances.
49*ac32b99cSOleksandr Tymoshenko.Pp
50*ac32b99cSOleksandr Tymoshenko.Fn OF_device_register_xref
51*ac32b99cSOleksandr Tymoshenkoadds a map entry from the effective phandle
52*ac32b99cSOleksandr Tymoshenko.Fa xref
53*ac32b99cSOleksandr Tymoshenkoto device
54*ac32b99cSOleksandr Tymoshenko.Fa dev .
55*ac32b99cSOleksandr TymoshenkoIf a mapping entry for
56*ac32b99cSOleksandr Tymoshenko.Fa xref
57*ac32b99cSOleksandr Tymoshenkoalready exists, it is replaced with the new one.
58*ac32b99cSOleksandr TymoshenkoThe function always returns 0.
59*ac32b99cSOleksandr Tymoshenko.Pp
60*ac32b99cSOleksandr Tymoshenko.Fn OF_device_from_xref
61*ac32b99cSOleksandr Tymoshenkoreturns a device_t instance associated with the effective phandle
62*ac32b99cSOleksandr Tymoshenko.Fa xref .
63*ac32b99cSOleksandr TymoshenkoIf no such mapping exists, the function returns NULL.
64*ac32b99cSOleksandr Tymoshenko.Pp
65*ac32b99cSOleksandr Tymoshenko.Fn OF_xref_from_device
66*ac32b99cSOleksandr Tymoshenkoreturns the effective phandle associated with the device
67*ac32b99cSOleksandr Tymoshenko.Fa dev .
68*ac32b99cSOleksandr TymoshenkoIf no such mapping exists, the function returns 0.
69*ac32b99cSOleksandr Tymoshenko.Sh EXAMPLES
70*ac32b99cSOleksandr Tymoshenko.Bd -literal
71*ac32b99cSOleksandr Tymoshenko    static int
72*ac32b99cSOleksandr Tymoshenko    acmephy_attach(device_t dev)
73*ac32b99cSOleksandr Tymoshenko    {
74*ac32b99cSOleksandr Tymoshenko        phandle_t node;
75*ac32b99cSOleksandr Tymoshenko
76*ac32b99cSOleksandr Tymoshenko	/* PHY node is referenced from eth device, register it */
77*ac32b99cSOleksandr Tymoshenko        node = ofw_bus_get_node(dev);
78*ac32b99cSOleksandr Tymoshenko        OF_device_register_xref(OF_xref_from_node(node), dev);
79*ac32b99cSOleksandr Tymoshenko
80*ac32b99cSOleksandr Tymoshenko        return (0);
81*ac32b99cSOleksandr Tymoshenko    }
82*ac32b99cSOleksandr Tymoshenko.Ed
83*ac32b99cSOleksandr Tymoshenko.Sh SEE ALSO
84*ac32b99cSOleksandr Tymoshenko.Xr OF_node_to_xref 9
85*ac32b99cSOleksandr Tymoshenko.Sh AUTHORS
86*ac32b99cSOleksandr Tymoshenko.An -nosplit
87*ac32b99cSOleksandr TymoshenkoThis manual page was written by
88*ac32b99cSOleksandr Tymoshenko.An Oleksandr Tymoshenko Aq Mt gonzo@FreeBSD.org .
89