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 3, 2025 27.Dt OF_DEVICE_FROM_XREF 9 28.Os 29.Sh NAME 30.Nm OF_device_from_xref , 31.Nm OF_xref_from_device , 32.Nm OF_device_register_xref 33.Nm OF_device_unregister_xref 34.Nd "manage mappings between xrefs and devices" 35.Sh SYNOPSIS 36.In dev/ofw/ofw_bus.h 37.In dev/ofw/ofw_bus_subr.h 38.Ft int 39.Fn OF_device_register_xref "phandle_t xref" "device_t dev" 40.Ft void 41.Fn OF_device_unregister_xref "phandle_t xref" "device_t dev" 42.Ft device_t 43.Fn OF_device_from_xref "phandle_t xref" 44.Ft phandle_t 45.Fn OF_xref_from_device "device_t dev" 46.Sh DESCRIPTION 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_unregister_xref 64removes a map entry from the effective phandle 65.Fa xref 66to device 67.Fa dev . 68If a mapping entry for 69.Fa xref 70does not exists, it silently returns. 71.Pp 72.Fn OF_device_from_xref 73returns a device_t instance associated with the effective phandle 74.Fa xref . 75If no such mapping exists, the function returns NULL. 76.Pp 77.Fn OF_xref_from_device 78returns the effective phandle associated with the device 79.Fa dev . 80If no such mapping exists, the function returns 0. 81.Sh EXAMPLES 82.Bd -literal 83 static int 84 acmephy_attach(device_t dev) 85 { 86 phandle_t node; 87 88 /* PHY node is referenced from eth device, register it */ 89 node = ofw_bus_get_node(dev); 90 OF_device_register_xref(OF_xref_from_node(node), dev); 91 92 return (0); 93 } 94.Ed 95.Sh SEE ALSO 96.Xr OF_node_to_xref 9 97.Sh AUTHORS 98.An -nosplit 99This manual page was written by 100.An Oleksandr Tymoshenko Aq Mt gonzo@FreeBSD.org . 101