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