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