1 /* $NetBSD: xel.c,v 1.6 2002/10/02 16:02:44 thorpej 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 Minoura Makoto. 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 * TSR Xellent30 driver. 41 * Detect Xellent30, and reserve its I/O area. 42 */ 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/kernel.h> 47 #include <sys/device.h> 48 49 #include <machine/cpu.h> 50 #include <machine/bus.h> 51 52 #include <arch/x68k/dev/intiovar.h> 53 54 static paddr_t xel_addr __P((struct device *, struct cfdata *, 55 struct intio_attach_args *)); 56 static int xel_probe __P((paddr_t)); 57 static int xel_match __P((struct device *, struct cfdata *, void *)); 58 static void xel_attach __P((struct device *, struct device *, void *)); 59 60 struct xel_softc { 61 struct device dev; 62 63 bus_space_tag_t sc_bst; 64 bus_space_handle_t sc_bh; 65 }; 66 67 CFATTACH_DECL(xel, sizeof (struct xel_softc), 68 xel_match, xel_attach, NULL, NULL); 69 70 static paddr_t xel_addrs[] = { 0xec0000, 0xec4000, 0xec8000, 0xecc000 }; 71 72 #define XEL_MODE_RAM_LOWER 0x00 73 #define XEL_MODE_RAM_HIGHER 0x01 74 #define XEL_MODE_UNMAP_RAM 0x00 75 #define XEL_MODE_MAP_RAM 0x02 76 #define XEL_MODE_MPU_000 0x00 77 #define XEL_MODE_MPU_030 0x04 78 79 #define XEL_RAM_ADDR_LOWER 0xbc0000 80 #define XEL_RAM_ADDR_HIGHER 0xfc0000 81 82 83 static paddr_t 84 xel_addr (parent, match, ia) 85 struct device *parent; 86 struct cfdata *match; 87 struct intio_attach_args *ia; 88 { 89 paddr_t addr = 0; 90 91 if (match->cf_addr == INTIOCF_ADDR_DEFAULT) { 92 int i; 93 94 for (i=0; i<sizeof(xel_addrs)/sizeof(xel_addrs[0]); i++) { 95 if (xel_probe(xel_addrs[i])) { 96 addr = xel_addrs[i]; 97 break; 98 } 99 } 100 } else { 101 if (xel_probe((paddr_t) match->cf_addr)) 102 addr = (paddr_t) match->cf_addr; 103 } 104 105 if (addr) { 106 /* found! */ 107 ia->ia_addr = (int) addr; 108 ia->ia_size = 0x4000; 109 if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY) 110 < 0) 111 return 0; 112 else 113 return addr; 114 } 115 116 return 0; 117 } 118 119 extern int *nofault; 120 121 static int 122 xel_probe(addr) 123 paddr_t addr; 124 { 125 u_int32_t b1, b2; 126 u_int16_t *start = (void*) INTIO_ADDR(addr); 127 label_t faultbuf; 128 volatile u_int32_t *sram = (void*) INTIO_ADDR(XEL_RAM_ADDR_HIGHER); 129 130 if (badaddr((caddr_t)start)) 131 return 0; 132 133 nofault = (int *) &faultbuf; 134 if (setjmp(&faultbuf)) { 135 nofault = (int *) 0; 136 return 0; 137 } 138 139 b1 = sram[0]; 140 b2 = sram[1]; 141 /* Try to map the Xellent local memory. */ 142 start[0] = XEL_MODE_RAM_HIGHER | XEL_MODE_MAP_RAM | XEL_MODE_MPU_030; 143 144 #if 0 145 /* the contents should be deferent. */ 146 if (b1 == sram[0] && b2 == sram[1]) { 147 nofault = (int *) 0; 148 return 0; 149 } 150 #else 151 /* Try to write to the local memory. */ 152 sram[0] = 0x55555555; 153 sram[1] = 0xaaaaaaaa; 154 if (sram[0] != 0x55555555 || sram[1] != 0xaaaaaaaa) { 155 sram[0] = b1; 156 sram[1] = b2; 157 nofault = (int *) 0; 158 return 0; 159 } 160 sram[0] = 0xaaaaaaaa; 161 sram[1] = 0x55555555; 162 if (sram[0] != 0xaaaaaaaa || sram[1] != 0x55555555) { 163 sram[0] = b1; 164 sram[1] = b2; 165 nofault = (int *) 0; 166 return 0; 167 } 168 sram[0] = b1; 169 sram[1] = b2; 170 #endif 171 172 /* Unmap. */ 173 start[0] = XEL_MODE_UNMAP_RAM | XEL_MODE_MPU_030; 174 175 nofault = (int *) 0; 176 return 1; 177 } 178 179 static int 180 xel_match (parent, match, aux) 181 struct device *parent; 182 struct cfdata *match; 183 void *aux; 184 { 185 struct intio_attach_args *ia = aux; 186 187 if (strcmp (ia->ia_name, "xel") != 0) 188 return 0; 189 190 if (xel_addr(parent, match, ia)) { 191 #ifdef DIAGNOSTIC 192 if (cputype != CPU_68030) 193 panic ("Non-030 Xellent???"); 194 #endif 195 return 1; 196 } 197 return 0; 198 } 199 200 static void 201 xel_attach (parent, self, aux) 202 struct device *parent, *self; 203 void *aux; 204 { 205 struct xel_softc *sc = (void*)self; 206 struct intio_attach_args *ia = aux; 207 struct cfdata *cf = self->dv_cfdata; 208 paddr_t addr; 209 int r; 210 211 addr = xel_addr(parent, cf, aux); 212 sc->sc_bst = ia->ia_bst; 213 ia->ia_addr = (int) addr; 214 ia->ia_size = 0x4000; 215 r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE); 216 #ifdef DIAGNOSTIC 217 if (r) 218 panic ("IO map for Xellent30 corruption??"); 219 #endif 220 printf (": Xellent30 MPU Accelerator.\n"); 221 222 return; 223 } 224