Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Jul 2010 13:22:34 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r210677 - in head/sys: conf powerpc/conf powerpc/mambo
Message-ID:  <201007311322.o6VDMYON090428@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Sat Jul 31 13:22:34 2010
New Revision: 210677
URL: http://svn.freebsd.org/changeset/base/210677

Log:
  Add support for the IBM Full-System Simulator (Mambo). This code has been
  developed against the 970 and Cell simulators.

Added:
  head/sys/powerpc/mambo/
  head/sys/powerpc/mambo/mambo.c   (contents, props changed)
  head/sys/powerpc/mambo/mambo_console.c   (contents, props changed)
  head/sys/powerpc/mambo/mambo_disk.c   (contents, props changed)
  head/sys/powerpc/mambo/mambo_openpic.c   (contents, props changed)
  head/sys/powerpc/mambo/mambocall.S   (contents, props changed)
  head/sys/powerpc/mambo/mambocall.h   (contents, props changed)
Modified:
  head/sys/conf/files.powerpc
  head/sys/conf/options.powerpc
  head/sys/powerpc/conf/GENERIC
  head/sys/powerpc/conf/GENERIC64
  head/sys/powerpc/conf/NOTES

Modified: head/sys/conf/files.powerpc
==============================================================================
--- head/sys/conf/files.powerpc	Sat Jul 31 12:14:28 2010	(r210676)
+++ head/sys/conf/files.powerpc	Sat Jul 31 13:22:34 2010	(r210677)
@@ -111,6 +111,11 @@ powerpc/fpu/fpu_implode.c	optional	fpu_e
 powerpc/fpu/fpu_mul.c		optional	fpu_emu
 powerpc/fpu/fpu_sqrt.c		optional	fpu_emu
 powerpc/fpu/fpu_subr.c		optional	fpu_emu
+powerpc/mambo/mambocall.S	optional	mambo
+powerpc/mambo/mambo.c		optional	mambo
+powerpc/mambo/mambo_console.c	optional	mambo
+powerpc/mambo/mambo_disk.c	optional	mambo
+powerpc/mambo/mambo_openpic.c	optional	mambo
 powerpc/mpc85xx/atpic.c		optional	mpc85xx isa
 powerpc/mpc85xx/ds1553_bus_fdt.c	optional	ds1553 fdt
 powerpc/mpc85xx/ds1553_core.c	optional	ds1553

Modified: head/sys/conf/options.powerpc
==============================================================================
--- head/sys/conf/options.powerpc	Sat Jul 31 12:14:28 2010	(r210676)
+++ head/sys/conf/options.powerpc	Sat Jul 31 13:22:34 2010	(r210677)
@@ -17,6 +17,7 @@ GFB_NO_MODE_CHANGE	opt_gfb.h
 
 MPC85XX			opt_platform.h
 POWERMAC		opt_platform.h
+MAMBO
 PSIM
 
 SC_OFWFB		opt_ofwfb.h

Modified: head/sys/powerpc/conf/GENERIC
==============================================================================
--- head/sys/powerpc/conf/GENERIC	Sat Jul 31 12:14:28 2010	(r210676)
+++ head/sys/powerpc/conf/GENERIC	Sat Jul 31 13:22:34 2010	(r210677)
@@ -28,6 +28,7 @@ makeoptions	DEBUG=-g		#Build kernel with
 # Platform support
 options 	POWERMAC		#NewWorld Apple PowerMacs
 options 	PSIM			#GDB PSIM ppc simulator
+options		MAMBO			#IBM Mambo Full System Simulator
 
 options 	SCHED_ULE		#ULE scheduler
 options 	INET			#InterNETworking

Modified: head/sys/powerpc/conf/GENERIC64
==============================================================================
--- head/sys/powerpc/conf/GENERIC64	Sat Jul 31 12:14:28 2010	(r210676)
+++ head/sys/powerpc/conf/GENERIC64	Sat Jul 31 13:22:34 2010	(r210677)
@@ -27,6 +27,7 @@ makeoptions	DEBUG=-g		#Build kernel with
 
 # Platform support
 options 	POWERMAC		#NewWorld Apple PowerMacs
+options		MAMBO			#IBM Mambo Full System Simulator
 
 options 	SCHED_ULE		#ULE scheduler
 options 	INET			#InterNETworking

Modified: head/sys/powerpc/conf/NOTES
==============================================================================
--- head/sys/powerpc/conf/NOTES	Sat Jul 31 12:14:28 2010	(r210676)
+++ head/sys/powerpc/conf/NOTES	Sat Jul 31 13:22:34 2010	(r210677)
@@ -20,6 +20,7 @@ options 	FPU_EMU
 #options 	MPC85XX
 options 	POWERMAC		#NewWorld Apple PowerMacs
 options 	PSIM			#GDB PSIM ppc simulator
+options		MAMBO			#IBM Mambo Full System Simulator
 
 options 	SC_OFWFB		# OFW frame buffer
 

Added: head/sys/powerpc/mambo/mambo.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/powerpc/mambo/mambo.c	Sat Jul 31 13:22:34 2010	(r210677)
@@ -0,0 +1,101 @@
+/*-
+ * Copyright 2008 by 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 THE AUTHOR ``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 THE AUTHOR 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$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/openfirm.h>
+
+#include <machine/bus.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+#include <sys/rman.h>
+
+/*
+ * Mambo interface
+ */
+static int	mambobus_probe(device_t);
+static int	mambobus_attach(device_t);
+
+static device_method_t  mambobus_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		mambobus_probe),
+	DEVMETHOD(device_attach,	mambobus_attach),
+
+	/* Bus interface */
+	DEVMETHOD(bus_driver_added,	bus_generic_driver_added),
+	DEVMETHOD(bus_add_child,	bus_generic_add_child),
+	DEVMETHOD(bus_print_child,	bus_generic_print_child),
+	DEVMETHOD(bus_read_ivar,	bus_generic_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),
+
+	{0,0}
+};
+
+static driver_t mambobus_driver = {
+	"mambo",
+	mambobus_methods,
+	0
+};
+
+static devclass_t mambobus_devclass;
+
+DRIVER_MODULE(mambo, nexus, mambobus_driver, mambobus_devclass, 0, 0);
+
+static int
+mambobus_probe(device_t dev)
+{
+	const char *name = ofw_bus_get_name(dev);
+
+	if (name && !strcmp(name, "mambo")) {
+		device_set_desc(dev, "Mambo Simulator");
+		return (0);
+	}
+
+	return (ENXIO);
+}
+
+static int
+mambobus_attach(device_t dev)
+{
+	bus_generic_probe(dev);
+	return (bus_generic_attach(dev));
+}
+

Added: head/sys/powerpc/mambo/mambo_console.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/powerpc/mambo/mambo_console.c	Sat Jul 31 13:22:34 2010	(r210677)
@@ -0,0 +1,192 @@
+/*-
+ * Copyright (C) 2008 by 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 THE AUTHOR ``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$");
+
+#include "opt_comconsole.h"
+
+#include <sys/param.h>
+#include <sys/kdb.h>
+#include <sys/kernel.h>
+#include <sys/priv.h>
+#include <sys/systm.h>
+#include <sys/types.h>
+#include <sys/conf.h>
+#include <sys/cons.h>
+#include <sys/consio.h>
+#include <sys/tty.h>
+
+#include <dev/ofw/openfirm.h>
+
+#include <ddb/ddb.h>
+
+#include "mambocall.h"
+
+#define MAMBOBURSTLEN	128	/* max number of bytes to write in one chunk */
+
+#define MAMBO_CONSOLE_WRITE	0
+#define MAMBO_CONSOLE_READ	60
+
+static tsw_outwakeup_t mambotty_outwakeup;
+
+static struct ttydevsw mambo_ttydevsw = {
+	.tsw_flags	= TF_NOPREFIX,
+	.tsw_outwakeup	= mambotty_outwakeup,
+};
+
+static int			polltime;
+static struct callout		mambo_callout;
+static struct tty 		*tp = NULL;
+
+#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
+static int			alt_break_state;
+#endif
+
+static void	mambo_timeout(void *);
+
+static cn_probe_t	mambo_cnprobe;
+static cn_init_t	mambo_cninit;
+static cn_term_t	mambo_cnterm;
+static cn_getc_t	mambo_cngetc;
+static cn_putc_t	mambo_cnputc;
+
+CONSOLE_DRIVER(mambo);
+
+static void
+cn_drvinit(void *unused)
+{
+
+	if (mambo_consdev.cn_pri != CN_DEAD &&
+	    mambo_consdev.cn_name[0] != '\0') {
+		if (OF_finddevice("/mambo") == -1)
+			return;
+
+		tp = tty_alloc(&mambo_ttydevsw, NULL);
+		tty_init_console(tp, 0);
+		tty_makedev(tp, NULL, "%s", "mambocons");
+		tty_makealias(tp, "mambocons");
+
+		polltime = 1;
+
+		callout_init(&mambo_callout, CALLOUT_MPSAFE);
+		callout_reset(&mambo_callout, polltime, mambo_timeout, NULL);
+	}
+}
+
+SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);
+
+static void
+mambotty_outwakeup(struct tty *tp)
+{
+	int len;
+	u_char buf[MAMBOBURSTLEN];
+
+	for (;;) {
+		len = ttydisc_getc(tp, buf, sizeof buf);
+		if (len == 0)
+			break;
+		mambocall(MAMBO_CONSOLE_WRITE, buf, (register_t)len, 1UL);
+	}
+}
+
+static void
+mambo_timeout(void *v)
+{
+	int 	c;
+
+	tty_lock(tp);
+	while ((c = mambo_cngetc(NULL)) != -1)
+		ttydisc_rint(tp, c, 0);
+	ttydisc_rint_done(tp);
+	tty_unlock(tp);
+
+	callout_reset(&mambo_callout, polltime, mambo_timeout, NULL);
+}
+
+static void
+mambo_cnprobe(struct consdev *cp)
+{
+	if (OF_finddevice("/mambo") == -1) {
+		cp->cn_pri = CN_DEAD;
+		return;
+	}
+
+	cp->cn_pri = CN_NORMAL;
+}
+
+static void
+mambo_cninit(struct consdev *cp)
+{
+
+	/* XXX: This is the alias, but that should be good enough */
+	strcpy(cp->cn_name, "mambocons");
+}
+
+static void
+mambo_cnterm(struct consdev *cp)
+{
+}
+
+static int
+mambo_cngetc(struct consdev *cp)
+{
+	int ch;
+
+	ch = mambocall(MAMBO_CONSOLE_READ);
+
+	if (ch > 0 && ch < 0xff) {
+#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
+		int kdb_brk;
+
+		if ((kdb_brk = kdb_alt_break(ch, &alt_break_state)) != 0) {
+			switch (kdb_brk) {
+			case KDB_REQ_DEBUGGER:
+				kdb_enter(KDB_WHY_BREAK,
+				    "Break sequence on console");
+				break;
+			case KDB_REQ_PANIC:
+				kdb_panic("Panic sequence on console");
+				break;
+			case KDB_REQ_REBOOT:
+				kdb_reboot();
+				break;
+
+			}
+		}
+#endif
+		return (ch);
+	}
+
+	return (-1);
+}
+
+static void
+mambo_cnputc(struct consdev *cp, int c)
+{
+	char cbuf;
+
+	cbuf = c;
+	mambocall(MAMBO_CONSOLE_WRITE, &cbuf, 1UL, 1UL);
+}

Added: head/sys/powerpc/mambo/mambo_disk.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/powerpc/mambo/mambo_disk.c	Sat Jul 31 13:22:34 2010	(r210677)
@@ -0,0 +1,277 @@
+/*-
+ * Copyright (c) 2008 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 THE AUTHOR ``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 THE AUTHOR 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$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bio.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/kthread.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <geom/geom_disk.h>
+
+#include <powerpc/mambo/mambocall.h>
+
+struct mambodisk_softc {
+	device_t dev;
+	struct mtx sc_mtx;
+	struct disk *disk;
+	struct proc *p;
+	struct bio_queue_head bio_queue;
+	int running;
+	int maxblocks;
+};
+
+#define MAMBO_DISK_READ		116
+#define	MAMBO_DISK_WRITE	117
+#define MAMBO_DISK_INFO		118
+
+#define MAMBO_INFO_STATUS	1
+#define MAMBO_INFO_BLKSZ	2
+#define MAMBO_INFO_DEVSZ	3
+
+/* bus entry points */
+static void mambodisk_identify(driver_t *driver, device_t parent);
+static int mambodisk_probe(device_t dev);
+static int mambodisk_attach(device_t dev);
+
+/* disk routines */
+static int mambodisk_open(struct disk *dp);
+static int mambodisk_close(struct disk *dp);
+static void mambodisk_strategy(struct bio *bp);
+static void mambodisk_task(void *arg);
+
+#define MBODISK_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
+#define	MBODISK_UNLOCK(_sc)	mtx_unlock(&(_sc)->sc_mtx)
+#define MBODISK_LOCK_INIT(_sc) \
+	mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->dev), \
+	    "mambodisk", MTX_DEF)
+#define MBODISK_LOCK_DESTROY(_sc)	mtx_destroy(&_sc->sc_mtx);
+#define MBODISK_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED);
+#define MBODISK_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);
+
+static void
+mambodisk_identify(driver_t *driver, device_t parent)
+{
+	int i = 0;
+
+	for (i = 0; mambocall(MAMBO_DISK_INFO,MAMBO_INFO_DEVSZ,i) > 0; i++)
+		BUS_ADD_CHILD(parent,0,"mambodisk",i);
+}
+
+static int
+mambodisk_probe(device_t dev)
+{
+	device_set_desc(dev, "Mambo Simulated Block Device");
+	return (0);
+}
+
+static int
+mambodisk_attach(device_t dev)
+{
+	struct mambodisk_softc *sc;
+	struct disk *d;
+	intmax_t mb;
+	char unit;
+
+	sc = device_get_softc(dev);
+	sc->dev = dev;
+	MBODISK_LOCK_INIT(sc);
+
+	d = sc->disk = disk_alloc();
+	d->d_open = mambodisk_open;
+	d->d_close = mambodisk_close;
+	d->d_strategy = mambodisk_strategy;
+	d->d_name = "mambodisk";
+	d->d_drv1 = sc;
+	d->d_maxsize = MAXPHYS;		/* Maybe ask bridge? */
+
+	d->d_sectorsize = 512;
+	sc->maxblocks = mambocall(MAMBO_DISK_INFO,MAMBO_INFO_BLKSZ,d->d_unit)
+	    / 512;
+
+	d->d_unit = device_get_unit(dev);
+	d->d_mediasize = mambocall(MAMBO_DISK_INFO,MAMBO_INFO_DEVSZ,d->d_unit)
+	    * 1024ULL; /* Mambo gives size in KB */
+
+	mb = d->d_mediasize >> 20;	/* 1MiB == 1 << 20 */
+	unit = 'M';
+	if (mb >= 10240) {		/* 1GiB = 1024 MiB */
+		unit = 'G';
+		mb /= 1024;
+	}
+	device_printf(dev, "%ju%cB, %d byte sectors\n", mb, unit, 
+	    d->d_sectorsize);
+	disk_create(d, DISK_VERSION);
+	bioq_init(&sc->bio_queue);
+
+	sc->running = 1;
+	kproc_create(&mambodisk_task, sc, &sc->p, 0, 0, "task: mambo hd");
+
+	return (0);
+}
+
+static int
+mambodisk_detach(device_t dev)
+{
+	struct mambodisk_softc *sc = device_get_softc(dev);
+
+	/* kill thread */
+	MBODISK_LOCK(sc);
+	sc->running = 0;
+	wakeup(sc);
+	MBODISK_UNLOCK(sc);
+
+	/* wait for thread to finish.  XXX probably want timeout.  -sorbo */
+	MBODISK_LOCK(sc);
+	while (sc->running != -1)
+		msleep(sc, &sc->sc_mtx, PRIBIO, "detach", 0);
+	MBODISK_UNLOCK(sc);
+
+	/* kill disk */
+	disk_destroy(sc->disk);
+	/* XXX destroy anything in queue */
+
+	MBODISK_LOCK_DESTROY(sc);
+
+	return (0);
+}
+
+static int
+mambodisk_open(struct disk *dp)
+{
+	return (0);
+}
+
+static int
+mambodisk_close(struct disk *dp)
+{
+	return (0);
+}
+
+static void
+mambodisk_strategy(struct bio *bp)
+{
+	struct mambodisk_softc *sc;
+
+	sc = (struct mambodisk_softc *)bp->bio_disk->d_drv1;
+	MBODISK_LOCK(sc);
+	bioq_disksort(&sc->bio_queue, bp);
+	wakeup(sc);
+	MBODISK_UNLOCK(sc);
+}
+
+static void
+mambodisk_task(void *arg)
+{
+	struct mambodisk_softc *sc = (struct mambodisk_softc*)arg;
+	struct bio *bp;
+	size_t sz;
+	int result;
+	daddr_t block, end;
+	device_t dev;
+	u_long unit;
+
+	dev = sc->dev;
+	unit = device_get_unit(dev);
+
+	while (sc->running) {
+		MBODISK_LOCK(sc);
+		do {
+			bp = bioq_first(&sc->bio_queue);
+			if (bp == NULL)
+				msleep(sc, &sc->sc_mtx, PRIBIO, "jobqueue", 0);
+		} while (bp == NULL && sc->running);
+		if (bp)
+			bioq_remove(&sc->bio_queue, bp);
+		MBODISK_UNLOCK(sc);
+		if (!sc->running)
+			break;
+		sz = sc->disk->d_sectorsize;
+		end = bp->bio_pblkno + (bp->bio_bcount / sz);
+		for (block = bp->bio_pblkno; block < end;) {
+			u_long numblocks;
+			char *vaddr = bp->bio_data + 
+			    (block - bp->bio_pblkno) * sz;
+
+			numblocks = end - block;
+			if (numblocks > sc->maxblocks)
+				numblocks = sc->maxblocks;
+
+			if (bp->bio_cmd == BIO_READ) {
+				result = mambocall(MAMBO_DISK_READ, vaddr, 
+				  (u_long)block, (numblocks << 16) | unit);
+			} else if (bp->bio_cmd == BIO_WRITE) {
+				result = mambocall(MAMBO_DISK_WRITE, vaddr, 
+				  (u_long)block, (numblocks << 16) | unit);
+			} else {
+				result = 1;
+			}
+		
+			if (result)
+				break;
+
+			block += numblocks;
+		}
+		if (block < end) {
+			bp->bio_error = EIO;
+			bp->bio_resid = (end - block) * sz;
+			bp->bio_flags |= BIO_ERROR;
+		}
+		biodone(bp);
+	}
+
+	/* tell parent we're done */
+	MBODISK_LOCK(sc);
+	sc->running = -1;
+	wakeup(sc);
+	MBODISK_UNLOCK(sc);
+
+	kproc_exit(0);
+}
+
+static device_method_t mambodisk_methods[] = {
+	DEVMETHOD(device_identify,	mambodisk_identify),
+	DEVMETHOD(device_probe,		mambodisk_probe),
+	DEVMETHOD(device_attach,	mambodisk_attach),
+	DEVMETHOD(device_detach,	mambodisk_detach),
+	{0, 0},
+};
+
+static driver_t mambodisk_driver = {
+	"mambodisk",
+	mambodisk_methods,
+	sizeof(struct mambodisk_softc),
+};
+static devclass_t mambodisk_devclass;
+
+DRIVER_MODULE(mambodisk, mambo, mambodisk_driver, mambodisk_devclass, 0, 0);

Added: head/sys/powerpc/mambo/mambo_openpic.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/powerpc/mambo/mambo_openpic.c	Sat Jul 31 13:22:34 2010	(r210677)
@@ -0,0 +1,180 @@
+/*-
+ * Copyright 2008 by 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 THE AUTHOR ``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 THE AUTHOR 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$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/openfirm.h>
+
+#include <machine/bus.h>
+#include <machine/intr_machdep.h>
+#include <machine/md_var.h>
+#include <machine/pio.h>
+#include <machine/resource.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+#include <sys/rman.h>
+
+#include <machine/openpicvar.h>
+
+#include "pic_if.h"
+
+/*
+ * Mambo interface
+ */
+static int	openpic_mambo_probe(device_t);
+static uint32_t	openpic_mambo_id(device_t dev);
+static int	openpicbus_mambo_probe(device_t dev);
+static int	openpicbus_mambo_attach(device_t dev);
+static struct resource *openpicbus_alloc_resource(device_t bus, device_t dev, 
+		    int type, int *rid, u_long start, u_long end, u_long count, 
+		    u_int flags);
+
+static device_method_t  openpicbus_mambo_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		openpicbus_mambo_probe),
+	DEVMETHOD(device_attach,	openpicbus_mambo_attach),
+
+	/* Bus interface */
+	DEVMETHOD(bus_alloc_resource,	openpicbus_alloc_resource),
+
+	{0,0}
+};
+
+struct openpicbus_softc {
+	vm_offset_t picaddr;
+};
+
+static driver_t openpicbus_mambo_driver = {
+	"openpicbus",
+	openpicbus_mambo_methods,
+	sizeof(struct openpicbus_softc),
+};
+
+static device_method_t  openpic_mambo_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		openpic_mambo_probe),
+	DEVMETHOD(device_attach,	openpic_attach),
+
+	/* PIC interface */
+	DEVMETHOD(pic_config,		openpic_config),
+	DEVMETHOD(pic_dispatch,		openpic_dispatch),
+	DEVMETHOD(pic_enable,		openpic_enable),
+	DEVMETHOD(pic_eoi,		openpic_eoi),
+	DEVMETHOD(pic_ipi,		openpic_ipi),
+	DEVMETHOD(pic_mask,		openpic_mask),
+	DEVMETHOD(pic_unmask,		openpic_unmask),
+	DEVMETHOD(pic_id,		openpic_mambo_id),
+
+	{ 0, 0 },
+};
+
+static driver_t openpic_mambo_driver = {
+	"openpic",
+	openpic_mambo_methods,
+	sizeof(struct openpic_softc),
+};
+
+static devclass_t openpicbus_devclass;
+
+DRIVER_MODULE(openpicbus, nexus, openpicbus_mambo_driver, 
+    openpicbus_devclass, 0, 0);
+DRIVER_MODULE(openpic, openpicbus, openpic_mambo_driver, 
+    openpic_devclass, 0, 0);
+
+static int
+openpicbus_mambo_probe(device_t dev)
+{
+	const char *type = ofw_bus_get_type(dev);
+
+	if (type == NULL || strcmp(type, "open-pic") != 0)
+                return (ENXIO);
+
+	device_set_desc(dev, "Mambo OpenPIC Container");
+
+	return (0);
+}
+
+static int
+openpicbus_mambo_attach(device_t dev)
+{
+	uint64_t picaddr;
+	phandle_t nexus;
+	struct openpicbus_softc *sc;
+
+	sc = device_get_softc(dev);
+
+	nexus = OF_parent(ofw_bus_get_node(dev));
+
+	OF_getprop(nexus,"platform-open-pic",
+	    &picaddr,sizeof(picaddr));
+
+	sc->picaddr = picaddr;
+
+	device_add_child(dev,"openpic",-1);
+
+	return (bus_generic_attach(dev));
+}
+
+static struct resource *
+openpicbus_alloc_resource(device_t bus, device_t dev, int type, int *rid,
+		   u_long start, u_long end, u_long count, u_int flags)
+{
+	struct openpicbus_softc *sc;
+
+	sc = device_get_softc(bus);
+
+	count = 0x40000;
+	start = sc->picaddr;
+	end = start + count;
+
+	return (bus_alloc_resource(bus, type, rid, start, end, count, flags));
+}
+
+static int
+openpic_mambo_probe(device_t dev)
+{
+	device_set_desc(dev, OPENPIC_DEVSTR);
+	
+	return (0);
+}
+
+static uint32_t
+openpic_mambo_id(device_t dev)
+{
+	return (ofw_bus_get_node(device_get_parent(dev)));
+}
+

Added: head/sys/powerpc/mambo/mambocall.S
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/powerpc/mambo/mambocall.S	Sat Jul 31 13:22:34 2010	(r210677)
@@ -0,0 +1,39 @@
+/*-
+ * Copyright 2008 by 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 THE AUTHOR ``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 THE AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <machine/asm.h>	
+
+	.text
+
+ASENTRY(mambocall)
+	/*
+	 * Use the special Mambo callout opcode and whatever arguments we
+	 * were passed. Then return whatever Mambo returned. 
+	 */
+	.long 0x000EAEB0
+	blr
+

Added: head/sys/powerpc/mambo/mambocall.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/powerpc/mambo/mambocall.h	Sat Jul 31 13:22:34 2010	(r210677)
@@ -0,0 +1,33 @@
+/*-
+ * Copyright 2008 by 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 THE AUTHOR ``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 THE AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MAMBO_MAMBOCALL_H_
+#define _MAMBO_MAMBOCALL_H_
+
+long mambocall(int op, ...);
+
+#endif /* _MAMBO_MAMBOCALL_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007311322.o6VDMYON090428>