Home | History | Annotate | Line # | Download | only in sbus
xbox.c revision 1.1
      1  1.1  pk /*	$NetBSD: xbox.c,v 1.1 1998/04/18 19:00:17 pk Exp $ */
      2  1.1  pk 
      3  1.1  pk /*-
      4  1.1  pk  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.1  pk  * All rights reserved.
      6  1.1  pk  *
      7  1.1  pk  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  pk  * by Paul Kranenburg.
      9  1.1  pk  *
     10  1.1  pk  * Redistribution and use in source and binary forms, with or without
     11  1.1  pk  * modification, are permitted provided that the following conditions
     12  1.1  pk  * are met:
     13  1.1  pk  * 1. Redistributions of source code must retain the above copyright
     14  1.1  pk  *    notice, this list of conditions and the following disclaimer.
     15  1.1  pk  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  pk  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  pk  *    documentation and/or other materials provided with the distribution.
     18  1.1  pk  * 3. All advertising materials mentioning features or use of this software
     19  1.1  pk  *    must display the following acknowledgement:
     20  1.1  pk  *        This product includes software developed by the NetBSD
     21  1.1  pk  *        Foundation, Inc. and its contributors.
     22  1.1  pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  pk  *    contributors may be used to endorse or promote products derived
     24  1.1  pk  *    from this software without specific prior written permission.
     25  1.1  pk  *
     26  1.1  pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  pk  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  pk  */
     38  1.1  pk 
     39  1.1  pk /*
     40  1.1  pk  * Sbus expansion box.
     41  1.1  pk  */
     42  1.1  pk 
     43  1.1  pk #include <sys/param.h>
     44  1.1  pk #include <sys/malloc.h>
     45  1.1  pk #include <sys/systm.h>
     46  1.1  pk #include <sys/device.h>
     47  1.1  pk #include <vm/vm.h>
     48  1.1  pk 
     49  1.1  pk #include <machine/bus.h>
     50  1.1  pk #include <sparc/dev/sbusvar.h>
     51  1.1  pk #include <sparc/dev/xboxvar.h>
     52  1.1  pk #include <machine/autoconf.h>
     53  1.1  pk 
     54  1.1  pk /*
     55  1.1  pk  * Xbox registers definitions.
     56  1.1  pk  *
     57  1.1  pk  * The xbox device can operate in two mode: "opaque" and "transparent".
     58  1.1  pk  * In opaque mode, all accesses to the xbox address space are directed
     59  1.1  pk  * to the xbox itself. In transparent mode, all accesses are mapped to
     60  1.1  pk  * the SBus cards in the expansion box.
     61  1.1  pk  *
     62  1.1  pk  * To access the xbox registers in transparent mode, you must write
     63  1.1  pk  * to the "write0" register. The layout of this register appears to
     64  1.1  pk  * be as follows:
     65  1.1  pk  *
     66  1.1  pk  *	bit 31-24: xbox key (identifies device when you cascade them)
     67  1.1  pk  *	bit 23-12: offset of register to access
     68  1.1  pk  *	bit 11-0:  value to write
     69  1.1  pk  *
     70  1.1  pk  * For instance, to switch to opaque mode:
     71  1.1  pk  *	(*sc->write0_reg) = (sc->sc_key << 24) | XAC_CTL1_OFFSET;
     72  1.1  pk  *
     73  1.1  pk  * (note we're not currently using any of this)
     74  1.1  pk  */
     75  1.1  pk #define WRITE0_OFFSET		0
     76  1.1  pk 
     77  1.1  pk #define XAC_ERR_OFFSET		0x2000
     78  1.1  pk #define XAC_CTL0_OFFSET		0x10000
     79  1.1  pk #define XAC_CTL1_OFFSET		0x11000
     80  1.1  pk #define XAC_ELUA_OFFSET		0x12000
     81  1.1  pk #define XAC_ELLA_OFFSET		0x13000
     82  1.1  pk #define XAC_ELE_OFFSET		0x14000
     83  1.1  pk 
     84  1.1  pk #define XBC_ERR_OFFSET		0x42000
     85  1.1  pk #define XBC_CTL0_OFFSET		0x50000
     86  1.1  pk #define XBC_CTL1_OFFSET		0x51000
     87  1.1  pk #define XBC_ELUA_OFFSET		0x52000
     88  1.1  pk #define XBC_ELLA_OFFSET		0x53000
     89  1.1  pk #define XBC_ELE_OFFSET		0x54000
     90  1.1  pk 
     91  1.1  pk #define XBOX_NREG		13
     92  1.1  pk 
     93  1.1  pk struct xbox_softc {
     94  1.1  pk 	struct device	sc_dev;		/* base device */
     95  1.1  pk 	int		sc_key;		/* this xbox's unique key */
     96  1.1  pk };
     97  1.1  pk 
     98  1.1  pk /* autoconfiguration driver */
     99  1.1  pk int	xbox_match __P((struct device *, struct cfdata *, void *));
    100  1.1  pk void	xbox_attach __P((struct device *, struct device *, void *));
    101  1.1  pk int	xbox_print __P(( void *, const char *));
    102  1.1  pk 
    103  1.1  pk struct cfattach xbox_ca = {
    104  1.1  pk 	sizeof(struct xbox_softc), xbox_match, xbox_attach
    105  1.1  pk };
    106  1.1  pk 
    107  1.1  pk int
    108  1.1  pk xbox_print(args, busname)
    109  1.1  pk 	void *args;
    110  1.1  pk 	const char *busname;
    111  1.1  pk {
    112  1.1  pk 	struct xbox_attach_args *xa = args;
    113  1.1  pk 
    114  1.1  pk 	if (busname)
    115  1.1  pk 		printf("%s at %s", xa->xa_name, busname);
    116  1.1  pk 	return (UNCONF);
    117  1.1  pk }
    118  1.1  pk 
    119  1.1  pk int
    120  1.1  pk xbox_match(parent, cf, aux)
    121  1.1  pk 	struct device *parent;
    122  1.1  pk 	struct cfdata *cf;
    123  1.1  pk 	void *aux;
    124  1.1  pk {
    125  1.1  pk 	struct sbus_attach_args *sa = aux;
    126  1.1  pk 
    127  1.1  pk 	return (strcmp("SUNW,xbox", sa->sa_name) == 0);
    128  1.1  pk }
    129  1.1  pk 
    130  1.1  pk /*
    131  1.1  pk  * Attach an Xbox.
    132  1.1  pk  */
    133  1.1  pk void
    134  1.1  pk xbox_attach(parent, self, aux)
    135  1.1  pk 	struct device *parent;
    136  1.1  pk 	struct device *self;
    137  1.1  pk 	void *aux;
    138  1.1  pk {
    139  1.1  pk 	struct xbox_softc *sc = (struct xbox_softc *)self;
    140  1.1  pk 	struct sbus_attach_args *sa = aux;
    141  1.1  pk 	struct bootpath *bp = sa->sa_bp;
    142  1.1  pk 	int node = sa->sa_node;
    143  1.1  pk 	struct xbox_attach_args xa;
    144  1.1  pk 	char *cp;
    145  1.1  pk 
    146  1.1  pk 	sc->sc_key = getpropint(node, "write0-key", -1);
    147  1.1  pk 
    148  1.1  pk 	cp = getpropstring(node, "model");
    149  1.1  pk 	printf(": model %s", cp);
    150  1.1  pk 
    151  1.1  pk 	cp = getpropstring(node, "child-present");
    152  1.1  pk 	if (strcmp(cp, "true") != 0) {
    153  1.1  pk 		printf(": no sbus devices\n");
    154  1.1  pk 		return;
    155  1.1  pk 	}
    156  1.1  pk 
    157  1.1  pk 	printf("\n");
    158  1.1  pk 
    159  1.1  pk 	/* Propagate bootpath */
    160  1.1  pk 	if (bp != NULL && strcmp(bp->name, "xbox") == 0)
    161  1.1  pk 		bp++;
    162  1.1  pk 	else
    163  1.1  pk 		bp = NULL;
    164  1.1  pk 
    165  1.1  pk 	/*
    166  1.1  pk 	 * Now pretend to be another Sbus.
    167  1.1  pk 	 */
    168  1.1  pk 	bzero(&xa, sizeof xa);
    169  1.1  pk 	xa.xa_name = "sbus";
    170  1.1  pk 	xa.xa_node = node;
    171  1.1  pk 	xa.xa_bustag = sa->sa_bustag;
    172  1.1  pk 	xa.xa_dmatag = sa->sa_dmatag;
    173  1.1  pk 	xa.xa_bp = bp;
    174  1.1  pk 
    175  1.1  pk 	(void) config_found(&sc->sc_dev, (void *)&xa, xbox_print);
    176  1.1  pk }
    177