From 1ac37de6b36b3e9aa695f689453573e47662d47f Mon Sep 17 00:00:00 2001
From: Peter Grehan <grehan@FreeBSD.org>
Date: Wed, 4 Feb 2004 12:52:57 +0000
Subject: [PATCH] - add an identify method, since the disk device used to be
 picked up in the recursive OpenFirmware node walk. Rely on the psim config
 file to have a "ofwdisk" device alias - minor white space nits

---
 sys/dev/ofw/ofw_disk.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/sys/dev/ofw/ofw_disk.c b/sys/dev/ofw/ofw_disk.c
index aa0213a4739a..8d4ae8238157 100644
--- a/sys/dev/ofw/ofw_disk.c
+++ b/sys/dev/ofw/ofw_disk.c
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/conf.h>
 #include <sys/kernel.h>
+#include <sys/limits.h>
 #include <geom/geom_disk.h>
 
 #include <dev/ofw/openfirm.h>
@@ -55,10 +56,12 @@ struct ofwd_softc
 /*
  * Disk device bus interface.
  */
+static void	ofwd_identify(driver_t *, device_t);
 static int	ofwd_probe(device_t);
 static int	ofwd_attach(device_t);
 
 static device_method_t	ofwd_methods[] = {
+	DEVMETHOD(device_identify,	ofwd_identify),
 	DEVMETHOD(device_probe, 	ofwd_probe),
 	DEVMETHOD(device_attach,	ofwd_attach),
 	{ 0, 0 }
@@ -122,17 +125,40 @@ ofwd_strategy(struct bio *bp)
 	}
 
 	bp->bio_resid -= r;
-	
+
 	if (r < bp->bio_bcount) {
 		device_printf(sc->ofwd_dev, "r (%ld) < bp->bio_bcount (%ld)\n",
 		    r, bp->bio_bcount);
 		biofinish(bp, NULL, EIO);	/* XXX: probably not an error */
 		return;
-	} 
+	}
 	biodone(bp);
 	return;
 }
 
+/*
+ * Attach the OpenFirmware disk to nexus if present
+ */
+static void
+ofwd_identify(driver_t *driver, device_t parent)
+{
+	device_t child;
+	phandle_t ofd;
+	static char type[8];
+
+	ofd = OF_finddevice("ofwdisk");
+	if (ofd == -1)
+		return;
+
+	OF_getprop(ofd, "device_type", type, sizeof(type));
+
+	child = BUS_ADD_CHILD(parent, INT_MAX, "ofwd", 0);
+	if (child != NULL) {
+		nexus_set_device_type(child, type);
+		nexus_set_node(child, ofd);
+	}
+}
+
 /*
  * Probe for an OpenFirmware disk.
  */
@@ -146,7 +172,7 @@ ofwd_probe(device_t dev)
 	type = nexus_get_device_type(dev);
 	node = nexus_get_node(dev);
 
-	if (type == NULL || 
+	if (type == NULL ||
 	    (strcmp(type, "disk") != 0 && strcmp(type, "block") != 0))
 		return (ENXIO);