xref: /freebsd/share/man/man9/OF_device_from_xref.9 (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
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_DEVICE_FROM_XREF 9
30.Os
31.Sh NAME
32.Nm OF_device_from_xref ,
33.Nm OF_xref_from_device ,
34.Nm OF_device_register_xref
35.Nd "manage mappings between xrefs and devices"
36.Sh SYNOPSIS
37.In dev/ofw/ofw_bus.h
38.In dev/ofw/ofw_bus_subr.h
39.Ft int
40.Fn OF_device_register_xref "phandle_t xref" "device_t dev"
41.Ft device_t
42.Fn OF_device_from_xref "phandle_t xref"
43.Ft phandle_t
44.Fn OF_xref_from_device "device_t dev"
45.Sh DESCRIPTION
46When a device tree node references another node, the driver may
47need to get a device_t instance associated with the referenced node.
48For instance, an Ethernet driver accessing a PHY device.
49To make this possible, the kernel maintains a table that
50maps effective handles to device_t instances.
51.Pp
52.Fn OF_device_register_xref
53adds a map entry from the effective phandle
54.Fa xref
55to device
56.Fa dev .
57If a mapping entry for
58.Fa xref
59already exists, it is replaced with the new one.
60The function always returns 0.
61.Pp
62.Fn OF_device_from_xref
63returns a device_t instance associated with the effective phandle
64.Fa xref .
65If no such mapping exists, the function returns NULL.
66.Pp
67.Fn OF_xref_from_device
68returns the effective phandle associated with the device
69.Fa dev .
70If no such mapping exists, the function returns 0.
71.Sh EXAMPLES
72.Bd -literal
73    static int
74    acmephy_attach(device_t dev)
75    {
76        phandle_t node;
77
78	/* PHY node is referenced from eth device, register it */
79        node = ofw_bus_get_node(dev);
80        OF_device_register_xref(OF_xref_from_node(node), dev);
81
82        return (0);
83    }
84.Ed
85.Sh SEE ALSO
86.Xr OF_node_to_xref 9
87.Sh AUTHORS
88.An -nosplit
89This manual page was written by
90.An Oleksandr Tymoshenko Aq Mt gonzo@FreeBSD.org .
91