---
name: "OF_device_from_xref"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/OF_device_from_xref"
---

# OF\_device\_from\_xref(9)

manage mappings between xrefs and devices

## NAME

**OF\_device\_from\_xref**, **OF\_xref\_from\_device**, **OF\_device\_register\_xref** **OF\_device\_unregister\_xref** – manage mappings between xrefs and devices

## SYNOPSIS

**#include \<dev/ofw/ofw\_bus.h\>**

**#include \<dev/ofw/ofw\_bus\_subr.h\>**

*int*\

**OF\_device\_register\_xref**(*phandle\_t xref*, *device\_t dev*);

*void*\

**OF\_device\_unregister\_xref**(*phandle\_t xref*, *device\_t dev*);

*device\_t*\

**OF\_device\_from\_xref**(*phandle\_t xref*);

*phandle\_t*\

**OF\_xref\_from\_device**(*device\_t dev*);

## DESCRIPTION

When a device tree node references another node, the driver may need to get a device\_t instance associated with the referenced node. For instance, an Ethernet driver accessing a PHY device. To make this possible, the kernel maintains a table that maps effective handles to device\_t instances.

**OF\_device\_register\_xref**() adds a map entry from the effective phandle *xref* to device *dev*. If a mapping entry for *xref* already exists, it is replaced with the new one. The function always returns 0.

**OF\_device\_unregister\_xref**() removes a map entry from the effective phandle *xref* to device *dev*. If a mapping entry for *xref* does not exists, it silently returns.

**OF\_device\_from\_xref**() returns a device\_t instance associated with the effective phandle *xref*. If no such mapping exists, the function returns NULL.

**OF\_xref\_from\_device**() returns the effective phandle associated with the device *dev*. If no such mapping exists, the function returns 0.

## EXAMPLES

```
    static int
    acmephy_attach(device_t dev)
    {
        phandle_t node;
	/* PHY node is referenced from eth device, register it */
        node = ofw_bus_get_node(dev);
        OF_device_register_xref(OF_xref_from_node(node), dev);
        return (0);
    }
```

## SEE ALSO

OF\_node\_to\_xref(9)

## AUTHORS

This manual page was written by Oleksandr Tymoshenko ⟨*gonzo@FreeBSD.org*⟩.
