1 /* $NetBSD: xbox.c,v 1.21 2011/07/18 00:58:52 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Sbus expansion box. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: xbox.c,v 1.21 2011/07/18 00:58:52 mrg Exp $"); 38 39 #include <sys/param.h> 40 #include <sys/malloc.h> 41 #include <sys/systm.h> 42 #include <sys/device.h> 43 44 #include <sys/bus.h> 45 #include <dev/sbus/sbusvar.h> 46 #include <dev/sbus/xboxvar.h> 47 #include <machine/autoconf.h> 48 49 /* 50 * Xbox registers definitions. 51 * 52 * The xbox device can operate in two mode: "opaque" and "transparent". 53 * In opaque mode, all accesses to the xbox address space are directed 54 * to the xbox itself. In transparent mode, all accesses are mapped to 55 * the SBus cards in the expansion box. 56 * 57 * To access the xbox registers in transparent mode, you must write 58 * to the "write0" register. The layout of this register appears to 59 * be as follows: 60 * 61 * bit 31-24: xbox key (identifies device when you cascade them) 62 * bit 23-12: offset of register to access 63 * bit 11-0: value to write 64 * 65 * For instance, to switch to opaque mode: 66 * (*sc->write0_reg) = (sc->sc_key << 24) | XAC_CTL1_OFFSET; 67 * 68 * (note we're not currently using any of this) 69 */ 70 #define WRITE0_OFFSET 0 71 72 #define XAC_ERR_OFFSET 0x2000 73 #define XAC_CTL0_OFFSET 0x10000 74 #define XAC_CTL1_OFFSET 0x11000 75 #define XAC_ELUA_OFFSET 0x12000 76 #define XAC_ELLA_OFFSET 0x13000 77 #define XAC_ELE_OFFSET 0x14000 78 79 #define XBC_ERR_OFFSET 0x42000 80 #define XBC_CTL0_OFFSET 0x50000 81 #define XBC_CTL1_OFFSET 0x51000 82 #define XBC_ELUA_OFFSET 0x52000 83 #define XBC_ELLA_OFFSET 0x53000 84 #define XBC_ELE_OFFSET 0x54000 85 86 #define XBOX_NREG 13 87 88 struct xbox_softc { 89 int sc_key; /* this xbox's unique key */ 90 }; 91 92 /* autoconfiguration driver */ 93 int xbox_match(device_t, cfdata_t, void *); 94 void xbox_attach(device_t, device_t, void *); 95 int xbox_print(void *, const char *); 96 97 CFATTACH_DECL_NEW(xbox, sizeof(struct xbox_softc), 98 xbox_match, xbox_attach, NULL, NULL); 99 100 int 101 xbox_print(void *args, const char *busname) 102 { 103 struct xbox_attach_args *xa = args; 104 105 if (busname) 106 aprint_normal("%s at %s", xa->xa_name, busname); 107 return (UNCONF); 108 } 109 110 int 111 xbox_match(device_t parent, cfdata_t cf, void *aux) 112 { 113 struct sbus_attach_args *sa = aux; 114 115 return (strcmp("SUNW,xbox", sa->sa_name) == 0); 116 } 117 118 /* 119 * Attach an Xbox. 120 */ 121 void 122 xbox_attach(device_t parent, device_t self, void *aux) 123 { 124 struct xbox_softc *sc = device_private(self); 125 struct sbus_attach_args *sa = aux; 126 int node = sa->sa_node; 127 struct xbox_attach_args xa; 128 char *cp; 129 130 sc->sc_key = prom_getpropint(node, "write0-key", -1); 131 132 cp = prom_getpropstring(node, "model"); 133 printf(": model %s", cp); 134 135 cp = prom_getpropstring(node, "child-present"); 136 if (strcmp(cp, "true") != 0) { 137 printf(": no sbus devices\n"); 138 return; 139 } 140 141 printf("\n"); 142 143 /* 144 * Now pretend to be another Sbus. 145 */ 146 memset(&xa, 0, sizeof xa); 147 xa.xa_name = "sbus"; 148 xa.xa_node = node; 149 xa.xa_bustag = sa->sa_bustag; 150 xa.xa_dmatag = sa->sa_dmatag; 151 152 (void) config_found(self, (void *)&xa, xbox_print); 153 } 154