[Midnightbsd-cvs] src [10088] trunk/sys/dev/ofw: sync ofw

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun May 27 19:29:08 EDT 2018


Revision: 10088
          http://svnweb.midnightbsd.org/src/?rev=10088
Author:   laffer1
Date:     2018-05-27 19:29:07 -0400 (Sun, 27 May 2018)
Log Message:
-----------
sync ofw

Modified Paths:
--------------
    trunk/sys/dev/ofw/ofw_bus.h
    trunk/sys/dev/ofw/ofw_bus_if.m
    trunk/sys/dev/ofw/ofw_bus_subr.c
    trunk/sys/dev/ofw/ofw_bus_subr.h
    trunk/sys/dev/ofw/ofw_console.c
    trunk/sys/dev/ofw/ofw_disk.c
    trunk/sys/dev/ofw/ofw_fdt.c
    trunk/sys/dev/ofw/ofw_if.m
    trunk/sys/dev/ofw/ofw_iicbus.c
    trunk/sys/dev/ofw/ofw_pci.h
    trunk/sys/dev/ofw/ofw_standard.c
    trunk/sys/dev/ofw/ofwvar.h
    trunk/sys/dev/ofw/openfirm.c
    trunk/sys/dev/ofw/openfirm.h
    trunk/sys/dev/ofw/openfirmio.c
    trunk/sys/dev/ofw/openfirmio.h
    trunk/sys/dev/ofw/openpromio.c
    trunk/sys/dev/ofw/openpromio.h

Added Paths:
-----------
    trunk/sys/dev/ofw/ofw_cpu.c
    trunk/sys/dev/ofw/ofwbus.c

Property Changed:
----------------
    trunk/sys/dev/ofw/ofw_bus_if.m
    trunk/sys/dev/ofw/ofw_if.m

Modified: trunk/sys/dev/ofw/ofw_bus.h
===================================================================
--- trunk/sys/dev/ofw/ofw_bus.h	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_bus.h	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2001, 2003 by Thomas Moestl <tmm at FreeBSD.org>
  * Copyright (c) 2004 by Marius Strobl <marius at FreeBSD.org>
@@ -23,7 +24,7 @@
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/ofw/ofw_bus.h 266128 2014-05-15 14:26:11Z ian $
  */
 
 #ifndef	_DEV_OFW_OFW_BUS_H_
@@ -70,4 +71,10 @@
 	return (OFW_BUS_GET_TYPE(device_get_parent(dev), dev));
 }
 
+static __inline int
+ofw_bus_map_intr(device_t dev, phandle_t iparent, int icells, pcell_t *intr)
+{
+	return (OFW_BUS_MAP_INTR(dev, dev, iparent, icells, intr));
+}
+
 #endif /* !_DEV_OFW_OFW_BUS_H_ */

Modified: trunk/sys/dev/ofw/ofw_bus_if.m
===================================================================
--- trunk/sys/dev/ofw/ofw_bus_if.m	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_bus_if.m	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 #-
 # Copyright (c) 2001, 2003 by Thomas Moestl <tmm at FreeBSD.org>
 # Copyright (c) 2004, 2005 by Marius Strobl <marius at FreeBSD.org>
@@ -23,7 +24,7 @@
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
-# $MidnightBSD$
+# $FreeBSD: stable/10/sys/dev/ofw/ofw_bus_if.m 266135 2014-05-15 15:15:23Z loos $
 
 # Interface for retrieving the package handle and a subset, namely
 # 'compatible', 'device_type', 'model' and 'name', of the standard
@@ -46,6 +47,7 @@
 		char		*obd_model;
 		char		*obd_name;
 		char		*obd_type;
+		char		*obd_status;
 	};
 };
 
@@ -56,6 +58,7 @@
 	static ofw_bus_get_name_t ofw_bus_default_get_name;
 	static ofw_bus_get_node_t ofw_bus_default_get_node;
 	static ofw_bus_get_type_t ofw_bus_default_get_type;
+	static ofw_bus_map_intr_t ofw_bus_default_map_intr;
 
 	static const struct ofw_bus_devinfo *
 	ofw_bus_default_get_devinfo(device_t bus, device_t dev)
@@ -98,6 +101,19 @@
 
 		return (NULL);
 	}
+
+	int
+	ofw_bus_default_map_intr(device_t bus, device_t dev, phandle_t iparent,
+	    int icells, pcell_t *interrupt)
+	{
+		/* Propagate up the bus hierarchy until someone handles it. */	
+		if (device_get_parent(bus) != NULL)
+			return OFW_BUS_MAP_INTR(device_get_parent(bus), dev,
+			    iparent, icells, interrupt);
+
+		/* If that fails, then assume a one-domain system */
+		return (interrupt[0]);
+	}
 };
 
 # Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus
@@ -131,7 +147,7 @@
 } DEFAULT ofw_bus_default_get_name;
 
 # Get the firmware node for the device dev on the bus. The default method will
-# return 0, which signals that there is no such node.
+# return -1, which signals that there is no such node.
 METHOD phandle_t get_node {
 	device_t bus;
 	device_t dev;
@@ -143,3 +159,14 @@
 	device_t bus;
 	device_t dev;
 } DEFAULT ofw_bus_default_get_type;
+
+# Map an (interrupt parent, IRQ) pair to a unique system-wide interrupt number.
+# If the interrupt encoding includes a sense field, the interrupt sense will
+# also be configured.
+METHOD int map_intr {
+	device_t bus;
+	device_t dev;
+	phandle_t iparent;
+	int icells;
+	pcell_t *interrupt;
+} DEFAULT ofw_bus_default_map_intr;


Property changes on: trunk/sys/dev/ofw/ofw_bus_if.m
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/dev/ofw/ofw_bus_subr.c
===================================================================
--- trunk/sys/dev/ofw/ofw_bus_subr.c	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_bus_subr.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2001 - 2003 by Thomas Moestl <tmm at FreeBSD.org>.
  * Copyright (c) 2005 Marius Strobl <marius at FreeBSD.org>
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/ofw_bus_subr.c 283334 2015-05-23 22:36:41Z ian $");
 
 #include "opt_platform.h"
 #include <sys/param.h>
@@ -37,6 +38,8 @@
 #include <sys/errno.h>
 #include <sys/libkern.h>
 
+#include <machine/resource.h>
+
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
 #include <dev/ofw/openfirm.h>
@@ -55,6 +58,7 @@
 	OF_getprop_alloc(node, "compatible", 1, (void **)&obd->obd_compat);
 	OF_getprop_alloc(node, "device_type", 1, (void **)&obd->obd_type);
 	OF_getprop_alloc(node, "model", 1, (void **)&obd->obd_model);
+	OF_getprop_alloc(node, "status", 1, (void **)&obd->obd_status);
 	obd->obd_node = node;
 	return (0);
 }
@@ -73,6 +77,8 @@
 		free(obd->obd_name, M_OFWPROP);
 	if (obd->obd_type != NULL)
 		free(obd->obd_type, M_OFWPROP);
+	if (obd->obd_status != NULL)
+		free(obd->obd_status, M_OFWPROP);
 }
 
 int
@@ -147,7 +153,31 @@
 	return (obd->obd_type);
 }
 
+const char *
+ofw_bus_get_status(device_t dev)
+{
+	const struct ofw_bus_devinfo *obd;
+
+	obd = OFW_BUS_GET_DEVINFO(device_get_parent(dev), dev);
+	if (obd == NULL)
+		return (NULL);
+
+	return (obd->obd_status);
+}
+
 int
+ofw_bus_status_okay(device_t dev)
+{
+	const char *status;
+
+	status = ofw_bus_get_status(dev);
+	if (status == NULL || strcmp(status, "okay") == 0)
+		return (1);
+	
+	return (0);
+}
+
+int
 ofw_bus_is_compatible(device_t dev, const char *onecompat)
 {
 	phandle_t node;
@@ -167,7 +197,8 @@
 	onelen = strlen(onecompat);
 
 	while (len > 0) {
-		if (strncasecmp(compat, onecompat, onelen) == 0)
+		if (strlen(compat) == onelen &&
+		    strncasecmp(compat, onecompat, onelen) == 0)
 			/* Found it. */
 			return (1);
 
@@ -183,17 +214,45 @@
 ofw_bus_is_compatible_strict(device_t dev, const char *compatible)
 {
 	const char *compat;
+	size_t len;
 
 	if ((compat = ofw_bus_get_compat(dev)) == NULL)
 		return (0);
 
-	if (strncasecmp(compat, compatible, strlen(compatible)) == 0)
+	len = strlen(compatible);
+	if (strlen(compat) == len &&
+	    strncasecmp(compat, compatible, len) == 0)
 		return (1);
 
 	return (0);
 }
 
-#ifndef FDT
+const struct ofw_compat_data *
+ofw_bus_search_compatible(device_t dev, const struct ofw_compat_data *compat)
+{
+
+	if (compat == NULL)
+		return NULL;
+
+	for (; compat->ocd_str != NULL; ++compat) {
+		if (ofw_bus_is_compatible(dev, compat->ocd_str))
+			break;
+	}
+
+	return (compat);
+}
+
+int
+ofw_bus_has_prop(device_t dev, const char *propname)
+{
+	phandle_t node;
+
+	if ((node = ofw_bus_get_node(dev)) == -1)
+		return (0);
+
+	return (OF_hasprop(node, propname));
+}
+
 void
 ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz)
 {
@@ -200,14 +259,14 @@
 	pcell_t addrc;
 	int msksz;
 
-	if (OF_getprop(node, "#address-cells", &addrc, sizeof(addrc)) == -1)
+	if (OF_getencprop(node, "#address-cells", &addrc, sizeof(addrc)) == -1)
 		addrc = 2;
 	ii->opi_addrc = addrc * sizeof(pcell_t);
 
-	ii->opi_imapsz = OF_getprop_alloc(node, "interrupt-map", 1,
+	ii->opi_imapsz = OF_getencprop_alloc(node, "interrupt-map", 1,
 	    (void **)&ii->opi_imap);
 	if (ii->opi_imapsz > 0) {
-		msksz = OF_getprop_alloc(node, "interrupt-map-mask", 1,
+		msksz = OF_getencprop_alloc(node, "interrupt-map-mask", 1,
 		    (void **)&ii->opi_imapmsk);
 		/*
 		 * Failure to get the mask is ignored; a full mask is used
@@ -222,8 +281,9 @@
 int
 ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg,
     int regsz, void *pintr, int pintrsz, void *mintr, int mintrsz,
-    phandle_t *iparent, void *maskbuf)
+    phandle_t *iparent)
 {
+	uint8_t maskbuf[regsz + pintrsz];
 	int rv;
 
 	if (ii->opi_imapsz <= 0)
@@ -231,9 +291,11 @@
 	KASSERT(regsz >= ii->opi_addrc,
 	    ("ofw_bus_lookup_imap: register size too small: %d < %d",
 		regsz, ii->opi_addrc));
-	rv = OF_getprop(node, "reg", reg, regsz);
-	if (rv < regsz)
-		panic("ofw_bus_lookup_imap: could not get reg property");
+	if (node != -1) {
+		rv = OF_getencprop(node, "reg", reg, regsz);
+		if (rv < regsz)
+			panic("ofw_bus_lookup_imap: cannot get reg property");
+	}
 	return (ofw_bus_search_intrmap(pintr, pintrsz, reg, ii->opi_addrc,
 	    ii->opi_imap, ii->opi_imapsz, ii->opi_imapmsk, maskbuf, mintr,
 	    mintrsz, iparent));
@@ -254,7 +316,7 @@
  * maskbuf must point to a buffer of length physsz + intrsz.
  * The interrupt is returned in result, which must point to a buffer of length
  * rintrsz (which gives the expected size of the mapped interrupt).
- * Returns 1 if a mapping was found, 0 otherwise.
+ * Returns number of cells in the interrupt if a mapping was found, 0 otherwise.
  */
 int
 ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz,
@@ -285,8 +347,8 @@
 	i = imapsz;
 	while (i > 0) {
 		bcopy(mptr + physsz + intrsz, &parent, sizeof(parent));
-		if (OF_searchprop(parent, "#interrupt-cells",
-		    &pintrsz, sizeof(pintrsz)) == -1)
+		if (OF_searchencprop(OF_node_from_xref(parent),
+		    "#interrupt-cells", &pintrsz, sizeof(pintrsz)) == -1)
 			pintrsz = 1;	/* default */
 		pintrsz *= sizeof(pcell_t);
 
@@ -294,19 +356,13 @@
 		tsz = physsz + intrsz + sizeof(phandle_t) + pintrsz;
 		KASSERT(i >= tsz, ("ofw_bus_search_intrmap: truncated map"));
 
-		/*
-		 * XXX: Apple hardware uses a second cell to set information
-		 * on the interrupt trigger type.  This information should
-		 * be used somewhere to program the PIC.
-		 */
-
 		if (bcmp(ref, mptr, physsz + intrsz) == 0) {
 			bcopy(mptr + physsz + intrsz + sizeof(parent),
-			    result, rintrsz);
+			    result, MIN(rintrsz, pintrsz));
 
 			if (iparent != NULL)
 				*iparent = parent;
-			return (1);
+			return (pintrsz/sizeof(pcell_t));
 		}
 		mptr += tsz;
 		i -= tsz;
@@ -313,4 +369,113 @@
 	}
 	return (0);
 }
-#endif /* !FDT */
+
+int
+ofw_bus_reg_to_rl(device_t dev, phandle_t node, pcell_t acells, pcell_t scells,
+    struct resource_list *rl)
+{
+	uint64_t phys, size;
+	ssize_t i, j, rid, nreg, ret;
+	uint32_t *reg;
+	char *name;
+
+	/*
+	 * This may be just redundant when having ofw_bus_devinfo
+	 * but makes this routine independent of it.
+	 */
+	ret = OF_getencprop_alloc(node, "name", sizeof(*name), (void **)&name);
+	if (ret == -1)
+		name = NULL;
+
+	ret = OF_getencprop_alloc(node, "reg", sizeof(*reg), (void **)&reg);
+	nreg = (ret == -1) ? 0 : ret;
+
+	if (nreg % (acells + scells) != 0) {
+		if (bootverbose)
+			device_printf(dev, "Malformed reg property on <%s>\n",
+			    (name == NULL) ? "unknown" : name);
+		nreg = 0;
+	}
+
+	for (i = 0, rid = 0; i < nreg; i += acells + scells, rid++) {
+		phys = size = 0;
+		for (j = 0; j < acells; j++) {
+			phys <<= 32;
+			phys |= reg[i + j];
+		}
+		for (j = 0; j < scells; j++) {
+			size <<= 32;
+			size |= reg[i + acells + j];
+		}
+		/* Skip the dummy reg property of glue devices like ssm(4). */
+		if (size != 0)
+			resource_list_add(rl, SYS_RES_MEMORY, rid,
+			    phys, phys + size - 1, size);
+	}
+	free(name, M_OFWPROP);
+	free(reg, M_OFWPROP);
+
+	return (0);
+}
+
+int
+ofw_bus_intr_to_rl(device_t dev, phandle_t node, struct resource_list *rl)
+{
+	phandle_t iparent;
+	uint32_t icells, *intr;
+	int err, i, irqnum, nintr, rid;
+	boolean_t extended;
+
+	nintr = OF_getencprop_alloc(node, "interrupts",  sizeof(*intr),
+	    (void **)&intr);
+	if (nintr > 0) {
+		if (OF_searchencprop(node, "interrupt-parent", &iparent,
+		    sizeof(iparent)) == -1) {
+			device_printf(dev, "No interrupt-parent found, "
+			    "assuming direct parent\n");
+			iparent = OF_parent(node);
+		}
+		if (OF_searchencprop(OF_node_from_xref(iparent), 
+		    "#interrupt-cells", &icells, sizeof(icells)) == -1) {
+			device_printf(dev, "Missing #interrupt-cells "
+			    "property, assuming <1>\n");
+			icells = 1;
+		}
+		if (icells < 1 || icells > nintr) {
+			device_printf(dev, "Invalid #interrupt-cells property "
+			    "value <%d>, assuming <1>\n", icells);
+			icells = 1;
+		}
+		extended = false;
+	} else {
+		nintr = OF_getencprop_alloc(node, "interrupts-extended",
+		    sizeof(*intr), (void **)&intr);
+		if (nintr <= 0)
+			return (0);
+		extended = true;
+	}
+	err = 0;
+	rid = 0;
+	for (i = 0; i < nintr; i += icells) {
+		if (extended) {
+			iparent = intr[i++];
+			if (OF_searchencprop(OF_node_from_xref(iparent), 
+			    "#interrupt-cells", &icells, sizeof(icells)) == -1) {
+				device_printf(dev, "Missing #interrupt-cells "
+				    "property\n");
+				err = ENOENT;
+				break;
+			}
+			if (icells < 1 || (i + icells) > nintr) {
+				device_printf(dev, "Invalid #interrupt-cells "
+				    "property value <%d>\n", icells);
+				err = ERANGE;
+				break;
+			}
+		}
+		irqnum = ofw_bus_map_intr(dev, iparent, icells, &intr[i]);
+		resource_list_add(rl, SYS_RES_IRQ, rid++, irqnum, irqnum, 1);
+	}
+	free(intr, M_OFWPROP);
+	return (err);
+}

Modified: trunk/sys/dev/ofw/ofw_bus_subr.h
===================================================================
--- trunk/sys/dev/ofw/ofw_bus_subr.h	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_bus_subr.h	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2005 Marius Strobl <marius at FreeBSD.org>
  * All rights reserved.
@@ -25,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/ofw/ofw_bus_subr.h 283334 2015-05-23 22:36:41Z ian $
  */
 
 #ifndef	_DEV_OFW_OFW_BUS_SUBR_H_
@@ -47,6 +48,11 @@
 	pcell_t			opi_addrc;
 };
 
+struct ofw_compat_data {
+	const char	*ocd_str;
+	uintptr_t	 ocd_data;
+};
+
 /* Generic implementation of ofw_bus_if.m methods and helper routines */
 int	ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *, phandle_t);
 void	ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *);
@@ -63,10 +69,19 @@
 /* Routines for processing firmware interrupt maps */
 void	ofw_bus_setup_iinfo(phandle_t, struct ofw_bus_iinfo *, int);
 int	ofw_bus_lookup_imap(phandle_t, struct ofw_bus_iinfo *, void *, int,
-	    void *, int, void *, int, phandle_t *, void *);
+	    void *, int, void *, int, phandle_t *);
 int	ofw_bus_search_intrmap(void *, int, void *, int, void *, int, void *,
 	    void *, void *, int, phandle_t *);
 
+/* Routines for parsing device-tree data into resource lists. */
+int ofw_bus_reg_to_rl(device_t, phandle_t, pcell_t, pcell_t,
+    struct resource_list *);
+int ofw_bus_intr_to_rl(device_t, phandle_t, struct resource_list *);
+
+/* Helper to get device status property */
+const char *ofw_bus_get_status(device_t dev);
+int ofw_bus_status_okay(device_t dev);
+
 /* Helper to get node's interrupt parent */
 void	ofw_bus_find_iparent(phandle_t);
 
@@ -74,4 +89,17 @@
 int ofw_bus_is_compatible(device_t, const char *);
 int ofw_bus_is_compatible_strict(device_t, const char *);
 
+/* 
+ * Helper routine to search a list of compat properties.  The table is
+ * terminated by an entry with a NULL compat-string pointer; a pointer to that
+ * table entry is returned if none of the compat strings match for the device,
+ * giving you control over the not-found value.  Will not return NULL unless the
+ * provided table pointer is NULL.
+ */
+const struct ofw_compat_data *
+    ofw_bus_search_compatible(device_t, const struct ofw_compat_data *);
+
+/* Helper routine for checking existence of a prop */
+int ofw_bus_has_prop(device_t, const char *);
+
 #endif /* !_DEV_OFW_OFW_BUS_SUBR_H_ */

Modified: trunk/sys/dev/ofw/ofw_console.c
===================================================================
--- trunk/sys/dev/ofw/ofw_console.c	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_console.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2001 Benno Rice.
  * All rights reserved.
@@ -24,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/ofw_console.c 265967 2014-05-13 17:59:17Z ian $");
 
 #include "opt_ofw.h"
 
@@ -88,24 +89,26 @@
 
 	if (ofw_consdev.cn_pri != CN_DEAD &&
 	    ofw_consdev.cn_name[0] != '\0') {
+		tp = tty_alloc(&ofw_ttydevsw, NULL);
+		tty_makedev(tp, NULL, "%s", "ofwcons");
+
+		/*
+		 * XXX: This is a hack and it may result in two /dev/ttya
+		 * XXX: devices on platforms where the sab driver works.
+		 */
 		if ((options = OF_finddevice("/options")) == -1 ||
 		    OF_getprop(options, "output-device", output,
 		    sizeof(output)) == -1)
 			return;
-		/*
-		 * XXX: This is a hack and it may result in two /dev/ttya
-		 * XXX: devices on platforms where the sab driver works.
-		 */
-		tp = tty_alloc(&ofw_ttydevsw, NULL);
-		tty_makedev(tp, NULL, "%s", output);
-		tty_makealias(tp, "ofwcons");
+		if (strlen(output) > 0)
+			tty_makealias(tp, output);
 	}
 }
 
 SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);
 
-static int	stdin;
-static int	stdout;
+static pcell_t	stdin;
+static pcell_t	stdout;
 
 static int
 ofwtty_open(struct tty *tp)
@@ -168,12 +171,12 @@
 		return;
 	}
 
-	if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1) {
+	if (OF_getencprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1) {
 		cp->cn_pri = CN_DEAD;
 		return;
 	}
 
-	if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) {
+	if (OF_getencprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) {
 		cp->cn_pri = CN_DEAD;
 		return;
 	}

Added: trunk/sys/dev/ofw/ofw_cpu.c
===================================================================
--- trunk/sys/dev/ofw/ofw_cpu.c	                        (rev 0)
+++ trunk/sys/dev/ofw/ofw_cpu.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -0,0 +1,223 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (C) 2009 Nathan Whitehorn
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/ofw_cpu.c 278609 2015-02-12 00:35:58Z ian $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/malloc.h>
+#include <sys/bus.h>
+#include <sys/cpu.h>
+#include <machine/bus.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+static int	ofw_cpulist_probe(device_t);
+static int	ofw_cpulist_attach(device_t);
+static const struct ofw_bus_devinfo *ofw_cpulist_get_devinfo(device_t dev,
+    device_t child);
+
+static MALLOC_DEFINE(M_OFWCPU, "ofwcpu", "OFW CPU device information");
+
+static device_method_t ofw_cpulist_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		ofw_cpulist_probe),
+	DEVMETHOD(device_attach,	ofw_cpulist_attach),
+
+	/* Bus interface */
+	DEVMETHOD(bus_add_child,	bus_generic_add_child),
+	DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
+
+	/* ofw_bus interface */
+	DEVMETHOD(ofw_bus_get_devinfo,	ofw_cpulist_get_devinfo),
+	DEVMETHOD(ofw_bus_get_compat,	ofw_bus_gen_get_compat),
+	DEVMETHOD(ofw_bus_get_model,	ofw_bus_gen_get_model),
+	DEVMETHOD(ofw_bus_get_name,	ofw_bus_gen_get_name),
+	DEVMETHOD(ofw_bus_get_node,	ofw_bus_gen_get_node),
+	DEVMETHOD(ofw_bus_get_type,	ofw_bus_gen_get_type),
+
+	DEVMETHOD_END
+};
+
+static driver_t ofw_cpulist_driver = {
+	"cpulist",
+	ofw_cpulist_methods,
+	0
+};
+
+static devclass_t ofw_cpulist_devclass;
+
+DRIVER_MODULE(ofw_cpulist, ofwbus, ofw_cpulist_driver, ofw_cpulist_devclass,
+    0, 0);
+
+static int 
+ofw_cpulist_probe(device_t dev) 
+{
+	const char	*name;
+
+	name = ofw_bus_get_name(dev);
+
+	if (name == NULL || strcmp(name, "cpus") != 0)
+		return (ENXIO);
+
+	device_set_desc(dev, "Open Firmware CPU Group");
+
+	return (0);
+}
+
+static int 
+ofw_cpulist_attach(device_t dev) 
+{
+	phandle_t root, child;
+	device_t cdev;
+	struct ofw_bus_devinfo *dinfo;
+
+	root = ofw_bus_get_node(dev);
+
+	for (child = OF_child(root); child != 0; child = OF_peer(child)) {
+		dinfo = malloc(sizeof(*dinfo), M_OFWCPU, M_WAITOK | M_ZERO);
+
+                if (ofw_bus_gen_setup_devinfo(dinfo, child) != 0) {
+                        free(dinfo, M_OFWCPU);
+                        continue;
+                }
+                cdev = device_add_child(dev, NULL, -1);
+                if (cdev == NULL) {
+                        device_printf(dev, "<%s>: device_add_child failed\n",
+                            dinfo->obd_name);
+                        ofw_bus_gen_destroy_devinfo(dinfo);
+                        free(dinfo, M_OFWCPU);
+                        continue;
+                }
+		device_set_ivars(cdev, dinfo);
+	}
+
+	return (bus_generic_attach(dev));
+}
+
+static const struct ofw_bus_devinfo *
+ofw_cpulist_get_devinfo(device_t dev, device_t child) 
+{
+	return (device_get_ivars(child));	
+}
+
+static int	ofw_cpu_probe(device_t);
+static int	ofw_cpu_attach(device_t);
+static int	ofw_cpu_read_ivar(device_t dev, device_t child, int index,
+    uintptr_t *result);
+
+struct ofw_cpu_softc {
+	struct pcpu	*sc_cpu_pcpu;
+	uint32_t	 sc_nominal_mhz;
+};
+
+static device_method_t ofw_cpu_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		ofw_cpu_probe),
+	DEVMETHOD(device_attach,	ofw_cpu_attach),
+
+	/* Bus interface */
+	DEVMETHOD(bus_add_child,	bus_generic_add_child),
+	DEVMETHOD(bus_read_ivar,	ofw_cpu_read_ivar),
+	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
+	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
+	DEVMETHOD(bus_alloc_resource,	bus_generic_alloc_resource),
+	DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
+	DEVMETHOD(bus_activate_resource,bus_generic_activate_resource),
+
+	DEVMETHOD_END
+};
+
+static driver_t ofw_cpu_driver = {
+	"cpu",
+	ofw_cpu_methods,
+	sizeof(struct ofw_cpu_softc)
+};
+
+static devclass_t ofw_cpu_devclass;
+
+DRIVER_MODULE(ofw_cpu, cpulist, ofw_cpu_driver, ofw_cpu_devclass, 0, 0);
+
+static int
+ofw_cpu_probe(device_t dev)
+{
+	const char *type = ofw_bus_get_type(dev);
+
+	if (type == NULL || strcmp(type, "cpu") != 0)
+		return (ENXIO);
+
+	device_set_desc(dev, "Open Firmware CPU");
+	return (0);
+}
+
+static int
+ofw_cpu_attach(device_t dev)
+{
+	struct ofw_cpu_softc *sc;
+	phandle_t node;
+	uint32_t cell;
+
+	sc = device_get_softc(dev);
+	node = ofw_bus_get_node(dev);
+	if (OF_getencprop(node, "reg", &cell, sizeof(cell)) < 0) {
+		cell = device_get_unit(dev);
+		device_printf(dev, "missing 'reg' property, using %u\n", cell);
+	}
+	sc->sc_cpu_pcpu = pcpu_find(cell);
+	if (OF_getencprop(node, "clock-frequency", &cell, sizeof(cell)) < 0) {
+		device_printf(dev, "missing 'clock-frequency' property\n");
+		return (ENXIO);
+	}
+	sc->sc_nominal_mhz = cell / 1000000; /* convert to MHz */
+
+	bus_generic_probe(dev);
+	return (bus_generic_attach(dev));
+}
+
+static int
+ofw_cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
+{
+	struct ofw_cpu_softc *sc;
+
+	sc = device_get_softc(dev);
+
+	switch (index) {
+	case CPU_IVAR_PCPU:
+		*result = (uintptr_t)sc->sc_cpu_pcpu;
+		return (0);
+	case CPU_IVAR_NOMINAL_MHZ:
+		*result = (uintptr_t)sc->sc_nominal_mhz;
+		return (0);
+	}
+
+	return (ENOENT);
+}
+


Property changes on: trunk/sys/dev/ofw/ofw_cpu.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/sys/dev/ofw/ofw_disk.c
===================================================================
--- trunk/sys/dev/ofw/ofw_disk.c	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_disk.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2002 Benno Rice <benno at FreeBSD.org>
  * All rights reserved.
@@ -24,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/ofw_disk.c 194139 2009-06-14 00:15:26Z marius $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/ofw/ofw_fdt.c
===================================================================
--- trunk/sys/dev/ofw/ofw_fdt.c	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_fdt.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/ofw_fdt.c 273652 2014-10-26 01:30:46Z ian $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -109,26 +110,32 @@
 }
 
 /*
- * Device tree functions
+ * Device tree functions.
+ *
+ * We use the offset from fdtp to the node as the 'phandle' in OF interface.
+ *
+ * phandle is a u32 value, therefore we cannot use the pointer to node as
+ * phandle in 64 bit. We also do not use the usual fdt offset as phandle,
+ * as it can be 0, and the OF interface has special meaning for phandle 0.
  */
 
+static phandle_t
+fdt_offset_phandle(int offset)
+{
+	if (offset < 0)
+		return (0);
+	return ((phandle_t)offset + fdt_off_dt_struct(fdtp));
+}
+
 static int
 fdt_phandle_offset(phandle_t p)
 {
-	const char *dt_struct;
-	int offset;
+	int pint = (int)p;
+	int dtoff = fdt_off_dt_struct(fdtp);
 
-	dt_struct = (const char *)fdtp + fdt_off_dt_struct(fdtp);
-
-	if (((const char *)p < dt_struct) ||
-	    (const char *)p > (dt_struct + fdt_size_dt_struct(fdtp)))
+	if (pint < dtoff)
 		return (-1);
-
-	offset = (const char *)p - dt_struct;
-	if (offset < 0)
-		return (-1);
-
-	return (offset);
+	return (pint - dtoff);
 }
 
 /* Return the next sibling of this node or 0. */
@@ -135,15 +142,13 @@
 static phandle_t
 ofw_fdt_peer(ofw_t ofw, phandle_t node)
 {
-	phandle_t p;
 	int depth, offset;
 
 	if (node == 0) {
 		/* Find root node */
 		offset = fdt_path_offset(fdtp, "/");
-		p = (phandle_t)fdt_offset_ptr(fdtp, offset, sizeof(p));
 
-		return (p);
+		return (fdt_offset_phandle(offset));
 	}
 
 	offset = fdt_phandle_offset(node);
@@ -155,10 +160,8 @@
 	    offset = fdt_next_node(fdtp, offset, &depth)) {
 		if (depth < 0)
 			return (0);
-		if (depth == 1) {
-			p = (phandle_t)fdt_offset_ptr(fdtp, offset, sizeof(p));
-			return (p);
-		}
+		if (depth == 1)
+			return (fdt_offset_phandle(offset));
 	}
 
 	return (0);
@@ -168,7 +171,6 @@
 static phandle_t
 ofw_fdt_child(ofw_t ofw, phandle_t node)
 {
-	phandle_t p;
 	int depth, offset;
 
 	offset = fdt_phandle_offset(node);
@@ -180,10 +182,8 @@
 	    offset = fdt_next_node(fdtp, offset, &depth)) {
 		if (depth < 0)
 			return (0);
-		if (depth == 1) {
-			p = (phandle_t)fdt_offset_ptr(fdtp, offset, sizeof(p));
-			return (p);
-		}
+		if (depth == 1)
+			return (fdt_offset_phandle(offset));
 	}
 
 	return (0);
@@ -193,7 +193,6 @@
 static phandle_t
 ofw_fdt_parent(ofw_t ofw, phandle_t node)
 {
-	phandle_t p;
 	int offset, paroffset;
 
 	offset = fdt_phandle_offset(node);
@@ -201,8 +200,7 @@
 		return (0);
 
 	paroffset = fdt_parent_offset(fdtp, offset);
-	p = (phandle_t)fdt_offset_ptr(fdtp, paroffset, sizeof(phandle_t));
-	return (p);
+	return (fdt_offset_phandle(paroffset));
 }
 
 /* Return the package handle that corresponds to an instance handle. */
@@ -209,22 +207,9 @@
 static phandle_t
 ofw_fdt_instance_to_package(ofw_t ofw, ihandle_t instance)
 {
-	phandle_t p;
-	int offset;
 
-	/*
-	 * Note: FDT does not have the notion of instances, but we somewhat
-	 * abuse the semantics and let treat as 'instance' the internal
-	 * 'phandle' prop, so that ofw I/F consumers have a uniform way of
-	 * translation between internal representation (which appear in some
-	 * contexts as property values) and effective phandles.
-	 */
-	offset = fdt_node_offset_by_phandle(fdtp, instance);
-	if (offset < 0)
-		return (-1);
-
-	p = (phandle_t)fdt_offset_ptr(fdtp, offset, sizeof(phandle_t));
-	return (p);
+	/* Where real OF uses ihandles in the tree, FDT uses xref phandles */
+	return (OF_node_from_xref(instance));
 }
 
 /* Get the length of a property of a package. */
@@ -282,44 +267,11 @@
 	return (len);
 }
 
-static int
-fdt_nextprop(int offset, char *buf, size_t size)
-{
-	const struct fdt_property *prop;
-	const char *name;
-	uint32_t tag;
-	int nextoffset, depth;
-
-	depth = 0;
-	tag = fdt_next_tag(fdtp, offset, &nextoffset);
-
-	/* Find the next prop */
-	do {
-		offset = nextoffset;
-		tag = fdt_next_tag(fdtp, offset, &nextoffset);
-
-		if (tag == FDT_BEGIN_NODE)
-			depth++;
-		else if (tag == FDT_END_NODE)
-			depth--;
-		else if ((tag == FDT_PROP) && (depth == 0)) {
-			prop =
-			    (const struct fdt_property *)fdt_offset_ptr(fdtp,
-			    offset, sizeof(*prop));
-			name = fdt_string(fdtp,
-			    fdt32_to_cpu(prop->nameoff));
-			strncpy(buf, name, size);
-			return (strlen(name));
-		} else
-			depth = -1;
-	} while (depth >= 0);
-
-	return (-1);
-}
-
 /*
- * Get the next property of a package. Return the actual len of retrieved
- * prop name.
+ * Get the next property of a package. Return values:
+ *  -1: package or previous property does not exist
+ *   0: no more properties
+ *   1: success
  */
 static int
 ofw_fdt_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf,
@@ -326,26 +278,42 @@
     size_t size)
 {
 	const struct fdt_property *prop;
-	int offset, rv;
+	const char *name;
+	int offset;
 
 	offset = fdt_phandle_offset(package);
 	if (offset < 0)
 		return (-1);
 
-	if (previous == NULL)
-		/* Find the first prop in the node */
-		return (fdt_nextprop(offset, buf, size));
+	/* Find the first prop in the node */
+	offset = fdt_first_property_offset(fdtp, offset);
+	if (offset < 0)
+		return (0); /* No properties */
 
-	/*
-	 * Advance to the previous prop
-	 */
-	prop = fdt_get_property(fdtp, offset, previous, NULL);
+	if (previous != NULL) {
+		while (offset >= 0) {
+			prop = fdt_get_property_by_offset(fdtp, offset, NULL);
+			if (prop == NULL)
+				return (-1); /* Internal error */
+
+			offset = fdt_next_property_offset(fdtp, offset);
+			if (offset < 0)
+				return (0); /* No more properties */
+
+			/* Check if the last one was the one we wanted */
+			name = fdt_string(fdtp, fdt32_to_cpu(prop->nameoff));
+			if (strcmp(name, previous) == 0)
+				break;
+		}
+	}
+
+	prop = fdt_get_property_by_offset(fdtp, offset, &offset);
 	if (prop == NULL)
-		return (-1);
+		return (-1); /* Internal error */
 
-	offset = fdt_phandle_offset((phandle_t)prop);
-	rv = fdt_nextprop(offset, buf, size);
-	return (rv);
+	strncpy(buf, fdt_string(fdtp, fdt32_to_cpu(prop->nameoff)), size);
+
+	return (1);
 }
 
 /* Set the value of a property of a package. */
@@ -374,14 +342,12 @@
 static phandle_t
 ofw_fdt_finddevice(ofw_t ofw, const char *device)
 {
-	phandle_t p;
 	int offset;
 
 	offset = fdt_path_offset(fdtp, device);
-
-	p = (phandle_t)fdt_offset_ptr(fdtp, offset, sizeof(p));
-
-	return (p);
+	if (offset < 0)
+		return (-1);
+	return (fdt_offset_phandle(offset));
 }
 
 /* Return the fully qualified pathname corresponding to an instance. */
@@ -388,8 +354,13 @@
 static ssize_t
 ofw_fdt_instance_to_path(ofw_t ofw, ihandle_t instance, char *buf, size_t len)
 {
+	phandle_t phandle;
 
-	return (-1);
+	phandle = OF_instance_to_package(instance);
+	if (phandle == -1)
+		return (-1);
+
+	return (OF_package_to_path(phandle, buf, len));
 }
 
 /* Return the fully qualified pathname corresponding to a package. */
@@ -409,7 +380,7 @@
 	ssize_t len;
 	int i;
 
-	if ((root = ofw_fdt_finddevice(ofw, "/")) == 0)
+	if ((root = ofw_fdt_finddevice(ofw, "/")) == -1)
 		return (ENODEV);
 
 	if ((len = ofw_fdt_getproplen(ofw, root, "model")) <= 0)

Modified: trunk/sys/dev/ofw/ofw_if.m
===================================================================
--- trunk/sys/dev/ofw/ofw_if.m	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_if.m	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 #-
 # Copyright (c) 2008 Nathan Whitehorn
 # All rights reserved.
@@ -23,7 +24,7 @@
 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 #
-# $MidnightBSD$
+# $FreeBSD: stable/10/sys/dev/ofw/ofw_if.m 212477 2010-09-11 18:55:00Z marius $
 #
 
 #include <dev/ofw/openfirm.h>


Property changes on: trunk/sys/dev/ofw/ofw_if.m
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/dev/ofw/ofw_iicbus.c
===================================================================
--- trunk/sys/dev/ofw/ofw_iicbus.c	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_iicbus.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009, Nathan Whitehorn <nwhitehorn at FreeBSD.org>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/ofw_iicbus.c 294672 2016-01-24 18:50:37Z ian $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -80,6 +81,7 @@
 
 DEFINE_CLASS_1(iicbus, ofw_iicbus_driver, ofw_iicbus_methods,
     sizeof(struct iicbus_softc), iicbus_driver);
+DRIVER_MODULE(ofw_iicbus, iicbb, ofw_iicbus_driver, ofwiicbus_devclass, 0, 0);
 DRIVER_MODULE(ofw_iicbus, iichb, ofw_iicbus_driver, ofwiicbus_devclass, 0, 0);
 MODULE_VERSION(ofw_iicbus, 1);
 MODULE_DEPEND(ofw_iicbus, iicbus, 1, 1, 1);
@@ -100,12 +102,24 @@
 {
 	struct iicbus_softc *sc = IICBUS_SOFTC(dev);
 	struct ofw_iicbus_devinfo *dinfo;
-	phandle_t child;
+	phandle_t child, node;
+	pcell_t freq, paddr;
 	device_t childdev;
-	uint32_t addr;
 
 	sc->dev = dev;
 	mtx_init(&sc->lock, "iicbus", NULL, MTX_DEF);
+
+	/*
+	 * If there is a clock-frequency property for the device node, use it as
+	 * the starting value for the bus frequency.  Then call the common
+	 * routine that handles the tunable/sysctl which allows the FDT value to
+	 * be overridden by the user.
+	 */
+	node = ofw_bus_get_node(dev);
+	freq = 0;
+	OF_getencprop(node, "clock-frequency", &freq, sizeof(freq));
+	iicbus_init_frequency(dev, freq);
+	
 	iicbus_reset(dev, IIC_FASTEST, 0, NULL);
 
 	bus_generic_probe(dev);
@@ -114,15 +128,16 @@
 	/*
 	 * Attach those children represented in the device tree.
 	 */
-	for (child = OF_child(ofw_bus_get_node(dev)); child != 0;
-	    child = OF_peer(child)) {
+	for (child = OF_child(node); child != 0; child = OF_peer(child)) {
 		/*
 		 * Try to get the I2C address first from the i2c-address
 		 * property, then try the reg property.  It moves around
 		 * on different systems.
 		 */
-		if (OF_getprop(child, "i2c-address", &addr, sizeof(addr)) == -1)
-			if (OF_getprop(child, "reg", &addr, sizeof(addr)) == -1)
+		if (OF_getencprop(child, "i2c-address", &paddr,
+		    sizeof(paddr)) == -1)
+			if (OF_getencprop(child, "reg", &paddr,
+			    sizeof(paddr)) == -1)
 				continue;
 
 		/*
@@ -133,7 +148,11 @@
 		    M_NOWAIT | M_ZERO);
 		if (dinfo == NULL)
 			continue;
-		dinfo->opd_dinfo.addr = addr;
+		/*
+		 * OFW uses 7-bit I2C address format (see ePAPR),
+		 * but system expect 8-bit.
+		 */
+		dinfo->opd_dinfo.addr = paddr << 1;
 		if (ofw_bus_gen_setup_devinfo(&dinfo->opd_obdinfo, child) !=
 		    0) {
 			free(dinfo, M_DEVBUF);

Modified: trunk/sys/dev/ofw/ofw_pci.h
===================================================================
--- trunk/sys/dev/ofw/ofw_pci.h	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_pci.h	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +30,7 @@
  *
  *	from: NetBSD: ofw_pci.h,v 1.5 2003/10/22 09:04:39 mjl Exp
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/ofw/ofw_pci.h 204520 2010-03-01 16:52:11Z joel $
  */
 
 #ifndef _DEV_OFW_OFW_PCI_H_

Modified: trunk/sys/dev/ofw/ofw_standard.c
===================================================================
--- trunk/sys/dev/ofw/ofw_standard.c	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofw_standard.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $	*/
 
 /*-
@@ -56,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/ofw_standard.c 212477 2010-09-11 18:55:00Z marius $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>

Added: trunk/sys/dev/ofw/ofwbus.c
===================================================================
--- trunk/sys/dev/ofw/ofwbus.c	                        (rev 0)
+++ trunk/sys/dev/ofw/ofwbus.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -0,0 +1,277 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright 1998 Massachusetts Institute of Technology
+ * Copyright 2001 by Thomas Moestl <tmm at FreeBSD.org>.
+ * Copyright 2006 by Marius Strobl <marius at FreeBSD.org>.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose and without fee is hereby
+ * granted, provided that both the above copyright notice and this
+ * permission notice appear in all copies, that both the above
+ * copyright notice and this permission notice appear in all
+ * supporting documentation, and that the name of M.I.T. not be used
+ * in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.  M.I.T. makes
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
+ * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
+ * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * 	from: FreeBSD: src/sys/i386/i386/nexus.c,v 1.43 2001/02/09
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/ofwbus.c 283477 2015-05-24 17:51:57Z ian $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/pcpu.h>
+#include <sys/rman.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/openfirm.h>
+#include <dev/fdt/simplebus.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+
+/*
+ * The ofwbus (which is a pseudo-bus actually) iterates over the nodes that
+ * hang from the Open Firmware root node and adds them as devices to this bus
+ * (except some special nodes which are excluded) so that drivers can be
+ * attached to them.
+ *
+ */
+
+struct ofwbus_softc {
+	struct simplebus_softc simplebus_sc;
+	struct rman	sc_intr_rman;
+	struct rman	sc_mem_rman;
+};
+
+static device_identify_t ofwbus_identify;
+static device_probe_t ofwbus_probe;
+static device_attach_t ofwbus_attach;
+static bus_alloc_resource_t ofwbus_alloc_resource;
+static bus_adjust_resource_t ofwbus_adjust_resource;
+static bus_release_resource_t ofwbus_release_resource;
+
+static device_method_t ofwbus_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_identify,	ofwbus_identify),
+	DEVMETHOD(device_probe,		ofwbus_probe),
+	DEVMETHOD(device_attach,	ofwbus_attach),
+
+	/* Bus interface */
+	DEVMETHOD(bus_alloc_resource,	ofwbus_alloc_resource),
+	DEVMETHOD(bus_adjust_resource,	ofwbus_adjust_resource),
+	DEVMETHOD(bus_release_resource,	ofwbus_release_resource),
+
+	DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(ofwbus, ofwbus_driver, ofwbus_methods,
+    sizeof(struct ofwbus_softc), simplebus_driver);
+static devclass_t ofwbus_devclass;
+EARLY_DRIVER_MODULE(ofwbus, nexus, ofwbus_driver, ofwbus_devclass, 0, 0,
+    BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
+MODULE_VERSION(ofwbus, 1);
+
+static void
+ofwbus_identify(driver_t *driver, device_t parent)
+{
+
+	/* Check if Open Firmware has been instantiated */
+	if (OF_peer(0) == -1)
+		return;
+
+	if (device_find_child(parent, "ofwbus", -1) == NULL)
+		BUS_ADD_CHILD(parent, 0, "ofwbus", -1);
+}
+
+static int
+ofwbus_probe(device_t dev)
+{
+
+	device_set_desc(dev, "Open Firmware Device Tree");
+	return (BUS_PROBE_NOWILDCARD);
+}
+
+static int
+ofwbus_attach(device_t dev)
+{
+	struct ofwbus_softc *sc;
+	phandle_t node;
+	struct ofw_bus_devinfo obd;
+
+	sc = device_get_softc(dev);
+
+	node = OF_peer(0);
+
+	/*
+	 * If no Open Firmware, bail early
+	 */
+	if (node == -1)
+		return (ENXIO);
+
+	/*
+	 * ofwbus bus starts on unamed node in FDT, so we cannot make
+	 * ofw_bus_devinfo from it. Pass node to simplebus_init directly.
+	 */
+	simplebus_init(dev, node);
+	sc->sc_intr_rman.rm_type = RMAN_ARRAY;
+	sc->sc_intr_rman.rm_descr = "Interrupts";
+	sc->sc_mem_rman.rm_type = RMAN_ARRAY;
+	sc->sc_mem_rman.rm_descr = "Device Memory";
+	if (rman_init(&sc->sc_intr_rman) != 0 ||
+	    rman_init(&sc->sc_mem_rman) != 0 ||
+	    rman_manage_region(&sc->sc_intr_rman, 0, ~0) != 0 ||
+	    rman_manage_region(&sc->sc_mem_rman, 0, BUS_SPACE_MAXADDR) != 0)
+		panic("%s: failed to set up rmans.", __func__);
+
+	/*
+	 * Allow devices to identify.
+	 */
+	bus_generic_probe(dev);
+
+	/*
+	 * Now walk the OFW tree and attach top-level devices.
+	 */
+	for (node = OF_child(node); node > 0; node = OF_peer(node)) {
+		if (ofw_bus_gen_setup_devinfo(&obd, node) != 0)
+			continue;
+		simplebus_add_device(dev, node, 0, NULL, -1, NULL);
+	}
+	return (bus_generic_attach(dev));
+}
+
+static struct resource *
+ofwbus_alloc_resource(device_t bus, device_t child, int type, int *rid,
+    u_long start, u_long end, u_long count, u_int flags)
+{
+	struct ofwbus_softc *sc;
+	struct rman *rm;
+	struct resource *rv;
+	struct resource_list_entry *rle;
+	int isdefault, passthrough;
+
+	isdefault = (start == 0UL && end == ~0UL);
+	passthrough = (device_get_parent(child) != bus);
+	sc = device_get_softc(bus);
+	rle = NULL;
+	if (!passthrough && isdefault) {
+		rle = resource_list_find(BUS_GET_RESOURCE_LIST(bus, child),
+		    type, *rid);
+		if (rle == NULL) {
+			if (bootverbose)
+				device_printf(bus, "no default resources for "
+				    "rid = %d, type = %d\n", *rid, type);
+			return (NULL);
+		}
+		start = rle->start;
+		count = ulmax(count, rle->count);
+		end = ulmax(rle->end, start + count - 1);
+	}
+
+	switch (type) {
+	case SYS_RES_IRQ:
+		rm = &sc->sc_intr_rman;
+		break;
+	case SYS_RES_MEMORY:
+		rm = &sc->sc_mem_rman;
+		break;
+	default:
+		return (NULL);
+	}
+
+	rv = rman_reserve_resource(rm, start, end, count, flags & ~RF_ACTIVE,
+	    child);
+	if (rv == NULL)
+		return (NULL);
+	rman_set_rid(rv, *rid);
+
+	if ((flags & RF_ACTIVE) != 0 && bus_activate_resource(child, type,
+	    *rid, rv) != 0) {
+		rman_release_resource(rv);
+		return (NULL);
+	}
+
+	if (!passthrough && rle != NULL) {
+		rle->res = rv;
+		rle->start = rman_get_start(rv);
+		rle->end = rman_get_end(rv);
+		rle->count = rle->end - rle->start + 1;
+	}
+
+	return (rv);
+}
+
+static int
+ofwbus_adjust_resource(device_t bus, device_t child __unused, int type,
+    struct resource *r, u_long start, u_long end)
+{
+	struct ofwbus_softc *sc;
+	struct rman *rm;
+	device_t ofwbus;
+
+	ofwbus = bus;
+	while (strcmp(device_get_name(device_get_parent(ofwbus)), "root") != 0)
+		ofwbus = device_get_parent(ofwbus);
+	sc = device_get_softc(ofwbus);
+	switch (type) {
+	case SYS_RES_IRQ:
+		rm = &sc->sc_intr_rman;
+		break;
+	case SYS_RES_MEMORY:
+		rm = &sc->sc_mem_rman;
+		break;
+	default:
+		return (EINVAL);
+	}
+	if (rm == NULL)
+		return (ENXIO);
+	if (rman_is_region_manager(r, rm) == 0)
+		return (EINVAL);
+	return (rman_adjust_resource(r, start, end));
+}
+
+static int
+ofwbus_release_resource(device_t bus, device_t child, int type,
+    int rid, struct resource *r)
+{
+	struct resource_list_entry *rle;
+	int error;
+
+	/* Clean resource list entry */
+	rle = resource_list_find(BUS_GET_RESOURCE_LIST(bus, child), type, rid);
+	if (rle != NULL)
+		rle->res = NULL;
+
+	if ((rman_get_flags(r) & RF_ACTIVE) != 0) {
+		error = bus_deactivate_resource(child, type, rid, r);
+		if (error)
+			return (error);
+	}
+	return (rman_release_resource(r));
+}


Property changes on: trunk/sys/dev/ofw/ofwbus.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/sys/dev/ofw/ofwvar.h
===================================================================
--- trunk/sys/dev/ofw/ofwvar.h	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/ofwvar.h	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2005 Peter Grehan
  * Copyright (c) 2008 Nathan Whitehorn
@@ -24,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/ofw/ofwvar.h 194138 2009-06-14 00:05:38Z marius $
  */
 
 #ifndef _DEV_OFW_OFWVAR_H_

Modified: trunk/sys/dev/ofw/openfirm.c
===================================================================
--- trunk/sys/dev/ofw/openfirm.c	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/openfirm.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $	*/
 
 /*-
@@ -56,14 +57,18 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/openfirm.c 283477 2015-05-24 17:51:57Z ian $");
 
 #include "opt_platform.h"
 
 #include <sys/param.h>
 #include <sys/kernel.h>
+#include <sys/lock.h>
 #include <sys/malloc.h>
+#include <sys/mutex.h>
+#include <sys/queue.h>
 #include <sys/systm.h>
+#include <sys/endian.h>
 
 #include <machine/stdarg.h>
 
@@ -83,7 +88,107 @@
 static struct ofw_kobj	ofw_kernel_obj;
 static struct kobj_ops	ofw_kernel_kops;
 
+struct xrefinfo {
+	phandle_t	xref;
+	phandle_t 	node;
+	device_t  	dev;
+	SLIST_ENTRY(xrefinfo) next_entry;
+};
+
+static SLIST_HEAD(, xrefinfo) xreflist = SLIST_HEAD_INITIALIZER(xreflist);
+static struct mtx xreflist_lock;
+static boolean_t xref_init_done;
+
+#define	FIND_BY_XREF	0
+#define	FIND_BY_NODE	1
+#define	FIND_BY_DEV	2
+
 /*
+ * xref-phandle-device lookup helper routines.
+ *
+ * As soon as we are able to use malloc(), walk the node tree and build a list
+ * of info that cross-references node handles, xref handles, and device_t
+ * instances.  This list exists primarily to allow association of a device_t
+ * with an xref handle, but it is also used to speed up translation between xref
+ * and node handles.  Before malloc() is available we have to recursively search
+ * the node tree each time we want to translate between a node and xref handle.
+ * Afterwards we can do the translations by searching this much shorter list.
+ */
+static void
+xrefinfo_create(phandle_t node)
+{
+	struct xrefinfo * xi;
+	phandle_t child, xref;
+
+	/*
+	 * Recursively descend from parent, looking for nodes with a property
+	 * named either "phandle", "ibm,phandle", or "linux,phandle".  For each
+	 * such node found create an entry in the xreflist.
+	 */
+	for (child = OF_child(node); child != 0; child = OF_peer(child)) {
+		xrefinfo_create(child);
+		if (OF_getencprop(child, "phandle", &xref, sizeof(xref)) ==
+		    -1 && OF_getencprop(child, "ibm,phandle", &xref,
+		    sizeof(xref)) == -1 && OF_getencprop(child,
+		    "linux,phandle", &xref, sizeof(xref)) == -1)
+			continue;
+		xi = malloc(sizeof(*xi), M_OFWPROP, M_WAITOK | M_ZERO);
+		xi->node = child;
+		xi->xref = xref;
+		SLIST_INSERT_HEAD(&xreflist, xi, next_entry);
+	}
+}
+
+static void
+xrefinfo_init(void *unsed)
+{
+
+	/*
+	 * There is no locking during this init because it runs much earlier
+	 * than any of the clients/consumers of the xref list data, but we do
+	 * initialize the mutex that will be used for access later.
+	 */
+	mtx_init(&xreflist_lock, "OF xreflist lock", NULL, MTX_DEF);
+	xrefinfo_create(OF_peer(0));
+	xref_init_done = true;
+}
+SYSINIT(xrefinfo, SI_SUB_KMEM, SI_ORDER_ANY, xrefinfo_init, NULL);
+
+static struct xrefinfo *
+xrefinfo_find(uintptr_t key, int find_by)
+{
+	struct xrefinfo *rv, *xi;
+
+	rv = NULL;
+	mtx_lock(&xreflist_lock);
+	SLIST_FOREACH(xi, &xreflist, next_entry) {
+		if ((find_by == FIND_BY_XREF && (phandle_t)key == xi->xref) ||
+		    (find_by == FIND_BY_NODE && (phandle_t)key == xi->node) ||
+		    (find_by == FIND_BY_DEV && key == (uintptr_t)xi->dev)) {
+			rv = xi;
+			break;
+		}
+	}
+	mtx_unlock(&xreflist_lock);
+	return (rv);
+}
+
+static struct xrefinfo *
+xrefinfo_add(phandle_t node, phandle_t xref, device_t dev)
+{
+	struct xrefinfo *xi;
+
+	xi = malloc(sizeof(*xi), M_OFWPROP, M_WAITOK);
+	xi->node = node;
+	xi->xref = xref;
+	xi->dev  = dev;
+	mtx_lock(&xreflist_lock);
+	SLIST_INSERT_HEAD(&xreflist, xi, next_entry);
+	mtx_unlock(&xreflist_lock);
+	return (xi);
+}
+
+/*
  * OFW install routines.  Highest priority wins, equal priority also
  * overrides allowing last-set to win.
  */
@@ -133,8 +238,9 @@
 
 	rv = OFW_INIT(ofw_obj, cookie);
 
-	if ((chosen = OF_finddevice("/chosen")) > 0)
-		if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
+	if ((chosen = OF_finddevice("/chosen")) != -1)
+		if (OF_getencprop(chosen, "stdout", &stdout,
+		    sizeof(stdout)) == -1)
 			stdout = -1;
 
 	return (rv);
@@ -261,6 +367,14 @@
 	return (OFW_GETPROPLEN(ofw_obj, package, propname));
 }
 
+/* Check existence of a property of a package. */
+int
+OF_hasprop(phandle_t package, const char *propname)
+{
+
+	return (OF_getproplen(package, propname) >= 0 ? 1 : 0);
+}
+
 /* Get the value of a property of a package. */
 ssize_t
 OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen)
@@ -272,6 +386,21 @@
 	return (OFW_GETPROP(ofw_obj, package, propname, buf, buflen));
 }
 
+ssize_t
+OF_getencprop(phandle_t node, const char *propname, pcell_t *buf, size_t len)
+{
+	ssize_t retval;
+	int i;
+
+	KASSERT(len % 4 == 0, ("Need a multiple of 4 bytes"));
+
+	retval = OF_getprop(node, propname, buf, len);
+	for (i = 0; i < len/4; i++)
+		buf[i] = be32toh(buf[i]);
+
+	return (retval);
+}
+
 /*
  * Recursively search the node and its parent for the given property, working
  * downward from the node to the device tree root.  Returns the value of the
@@ -288,6 +417,17 @@
 	return (-1);
 }
 
+ssize_t
+OF_searchencprop(phandle_t node, const char *propname, void *buf, size_t len)
+{
+	ssize_t rv;
+
+	for (; node != 0; node = OF_parent(node))
+		if ((rv = OF_getencprop(node, propname, buf, len)) != -1)
+			return (rv);
+	return (-1);
+}
+
 /*
  * Store the value of a property of a package into newly allocated memory
  * (using the M_OFWPROP malloc pool and M_WAITOK).  elsz is the size of a
@@ -312,6 +452,24 @@
 	return (len / elsz);
 }
 
+ssize_t
+OF_getencprop_alloc(phandle_t package, const char *name, int elsz, void **buf)
+{
+	ssize_t retval;
+	pcell_t *cell;
+	int i;
+
+	retval = OF_getprop_alloc(package, name, elsz, buf);
+	if (retval == -1 || retval*elsz % 4 != 0)
+		return (-1);
+
+	cell = *buf;
+	for (i = 0; i < retval*elsz/4; i++)
+		cell[i] = be32toh(cell[i]);
+
+	return (retval);
+}
+
 /* Get the next property of a package. */
 int
 OF_nextprop(phandle_t package, const char *previous, char *buf, size_t size)
@@ -378,6 +536,120 @@
 	return (OFW_PACKAGE_TO_PATH(ofw_obj, package, buf, len));
 }
 
+/* Look up effective phandle (see FDT/PAPR spec) */
+static phandle_t
+OF_child_xref_phandle(phandle_t parent, phandle_t xref)
+{
+	phandle_t child, rxref;
+
+	/*
+	 * Recursively descend from parent, looking for a node with a property
+	 * named either "phandle", "ibm,phandle", or "linux,phandle" that
+	 * matches the xref we are looking for.
+	 */
+
+	for (child = OF_child(parent); child != 0; child = OF_peer(child)) {
+		rxref = OF_child_xref_phandle(child, xref);
+		if (rxref != -1)
+			return (rxref);
+
+		if (OF_getencprop(child, "phandle", &rxref, sizeof(rxref)) ==
+		    -1 && OF_getencprop(child, "ibm,phandle", &rxref,
+		    sizeof(rxref)) == -1 && OF_getencprop(child,
+		    "linux,phandle", &rxref, sizeof(rxref)) == -1)
+			continue;
+
+		if (rxref == xref)
+			return (child);
+	}
+
+	return (-1);
+}
+
+phandle_t
+OF_node_from_xref(phandle_t xref)
+{
+	struct xrefinfo *xi;
+	phandle_t node;
+
+	if (xref_init_done) {
+		if ((xi = xrefinfo_find(xref, FIND_BY_XREF)) == NULL)
+			return (xref);
+		return (xi->node);
+	}
+
+	if ((node = OF_child_xref_phandle(OF_peer(0), xref)) == -1)
+		return (xref);
+	return (node);
+}
+
+phandle_t
+OF_xref_from_node(phandle_t node)
+{
+	struct xrefinfo *xi;
+	phandle_t xref;
+
+	if (xref_init_done) {
+		if ((xi = xrefinfo_find(node, FIND_BY_NODE)) == NULL)
+			return (node);
+		return (xi->xref);
+	}
+
+	if (OF_getencprop(node, "phandle", &xref, sizeof(xref)) ==
+	    -1 && OF_getencprop(node, "ibm,phandle", &xref,
+	    sizeof(xref)) == -1 && OF_getencprop(node,
+	    "linux,phandle", &xref, sizeof(xref)) == -1)
+		return (node);
+	return (xref);
+}
+
+device_t
+OF_device_from_xref(phandle_t xref)
+{
+	struct xrefinfo *xi;
+
+	if (xref_init_done) {
+		if ((xi = xrefinfo_find(xref, FIND_BY_XREF)) == NULL)
+			return (NULL);
+		return (xi->dev);
+	}
+	panic("Attempt to find device before xreflist_init");
+}
+
+phandle_t
+OF_xref_from_device(device_t dev)
+{
+	struct xrefinfo *xi;
+
+	if (xref_init_done) {
+		if ((xi = xrefinfo_find((uintptr_t)dev, FIND_BY_DEV)) == NULL)
+			return (0);
+		return (xi->xref);
+	}
+	panic("Attempt to find xref before xreflist_init");
+}
+
+int
+OF_device_register_xref(phandle_t xref, device_t dev)
+{
+	struct xrefinfo *xi;
+
+	/*
+	 * If the given xref handle doesn't already exist in the list then we
+	 * add a list entry.  In theory this can only happen on a system where
+	 * nodes don't contain phandle properties and xref and node handles are
+	 * synonymous, so the xref handle is added as the node handle as well.
+	 */
+	if (xref_init_done) {
+		if ((xi = xrefinfo_find(xref, FIND_BY_XREF)) == NULL)
+			xrefinfo_add(xref, xref, dev);
+		else 
+			xi->dev = dev;
+		return (0);
+	}
+	panic("Attempt to register device before xreflist_init");
+}
+
 /*  Call the method in the scope of a given instance. */
 int
 OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns,

Modified: trunk/sys/dev/ofw/openfirm.h
===================================================================
--- trunk/sys/dev/ofw/openfirm.h	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/openfirm.h	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: openfirm.h,v 1.1 1998/05/15 10:16:00 tsubai Exp $	*/
 
 /*-
@@ -54,7 +55,7 @@
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/ofw/openfirm.h 273655 2014-10-26 01:58:18Z ian $
  */
 
 #ifndef _DEV_OPENFIRM_H_
@@ -105,10 +106,17 @@
 ssize_t		OF_getproplen(phandle_t node, const char *propname);
 ssize_t		OF_getprop(phandle_t node, const char *propname, void *buf,
 		    size_t len);
+ssize_t		OF_getencprop(phandle_t node, const char *prop, pcell_t *buf,
+		    size_t len); /* Same as getprop, but maintains endianness */
+int		OF_hasprop(phandle_t node, const char *propname);
 ssize_t		OF_searchprop(phandle_t node, const char *propname, void *buf,
 		    size_t len);
+ssize_t		OF_searchencprop(phandle_t node, const char *propname,
+		    void *buf, size_t len);
 ssize_t		OF_getprop_alloc(phandle_t node, const char *propname,
 		    int elsz, void **buf);
+ssize_t		OF_getencprop_alloc(phandle_t node, const char *propname,
+		    int elsz, void **buf);
 int		OF_nextprop(phandle_t node, const char *propname, char *buf,
 		    size_t len);
 int		OF_setprop(phandle_t node, const char *name, const void *buf,
@@ -117,6 +125,26 @@
 phandle_t	OF_finddevice(const char *path);
 ssize_t		OF_package_to_path(phandle_t node, char *buf, size_t len);
 
+/*
+ * Some OF implementations (IBM, FDT) have a concept of effective phandles
+ * used for device-tree cross-references. Given one of these, returns the
+ * real phandle. If one can't be found (or running on OF implementations
+ * without this property), returns its input.
+ */
+phandle_t	OF_node_from_xref(phandle_t xref);
+phandle_t	OF_xref_from_node(phandle_t node);
+
+/*
+ * When properties contain references to other nodes using xref handles it is
+ * often necessary to use interfaces provided by the driver for the referenced
+ * instance.  These routines allow a driver that provides such an interface to
+ * register its association with an xref handle, and for other drivers to obtain
+ * the device_t associated with an xref handle.
+ */
+device_t	OF_device_from_xref(phandle_t xref);
+phandle_t	OF_xref_from_device(device_t dev);
+int		OF_device_register_xref(phandle_t xref, device_t dev);
+
 /* Device I/O functions */
 ihandle_t	OF_open(const char *path);
 void		OF_close(ihandle_t instance);

Modified: trunk/sys/dev/ofw/openfirmio.c
===================================================================
--- trunk/sys/dev/ofw/openfirmio.c	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/openfirmio.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,7 +1,8 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: openfirmio.c,v 1.4 2002/09/06 13:23:19 gehenna Exp $ */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/openfirmio.c 194138 2009-06-14 00:05:38Z marius $");
 
 /*-
  * Copyright (c) 1992, 1993

Modified: trunk/sys/dev/ofw/openfirmio.h
===================================================================
--- trunk/sys/dev/ofw/openfirmio.h	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/openfirmio.h	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: openfirmio.h,v 1.4 2002/09/06 13:23:19 gehenna Exp $ */
 
 /*-
@@ -34,7 +35,7 @@
  *
  *	@(#)openpromio.h	8.1 (Berkeley) 6/11/93
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/ofw/openfirmio.h 146400 2005-05-19 15:22:16Z marius $
  */
 
 #ifndef _DEV_OFW_OPENFIRMIO_H_

Modified: trunk/sys/dev/ofw/openpromio.c
===================================================================
--- trunk/sys/dev/ofw/openpromio.c	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/openpromio.c	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003 Jake Burkholder.
  * All rights reserved.
@@ -26,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ofw/openpromio.c 186347 2008-12-20 00:33:10Z nwhitehorn $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/ofw/openpromio.h
===================================================================
--- trunk/sys/dev/ofw/openpromio.h	2018-05-27 23:28:52 UTC (rev 10087)
+++ trunk/sys/dev/ofw/openpromio.h	2018-05-27 23:29:07 UTC (rev 10088)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003 Jake Burkholder.
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/ofw/openpromio.h 116551 2003-06-19 01:40:11Z jake $
  */
 
 #ifndef	_DEV_OFW_OPENPROMIO_H_



More information about the Midnightbsd-cvs mailing list