Home | History | Annotate | Line # | Download | only in dev
xel.c revision 1.2
      1 /*	$NetBSD: xel.c,v 1.2 1999/03/16 16:30:20 minoura 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 struct cfattach xel_ca = {
     68 	sizeof (struct xel_softc), xel_match, xel_attach
     69 };
     70 
     71 static paddr_t xel_addrs[] = { 0xec0000, 0xec4000, 0xec8000, 0xecc000 };
     72 
     73 #define XEL_MODE_RAM_LOWER	0x00
     74 #define XEL_MODE_RAM_HIGHER	0x01
     75 #define XEL_MODE_UNMAP_RAM	0x00
     76 #define XEL_MODE_MAP_RAM	0x02
     77 #define XEL_MODE_MPU_000	0x00
     78 #define XEL_MODE_MPU_030	0x04
     79 
     80 #define XEL_RAM_ADDR_LOWER	0xbc0000
     81 #define XEL_RAM_ADDR_HIGHER	0xfc0000
     82 
     83 
     84 static paddr_t
     85 xel_addr (parent, match, ia)
     86 	struct device *parent;
     87 	struct cfdata *match;
     88 	struct intio_attach_args *ia;
     89 {
     90 	paddr_t addr = 0;
     91 
     92 	if (match->cf_addr == INTIOCF_ADDR_DEFAULT) {
     93 		int i;
     94 
     95 		for (i=0; i<sizeof(xel_addrs)/sizeof(xel_addrs[0]); i++) {
     96 			if (xel_probe(xel_addrs[i])) {
     97 				addr = xel_addrs[i];
     98 				break;
     99 			}
    100 		}
    101 	} else {
    102 		if (xel_probe((paddr_t) match->cf_addr))
    103 			addr = (paddr_t) match->cf_addr;
    104 	}
    105 
    106 	if (addr) {
    107 		/* found! */
    108 		ia->ia_addr = (int) addr;
    109 		ia->ia_size = 0x4000;
    110 		if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY)
    111 		    < 0)
    112 			return 0;
    113 		else
    114 			return addr;
    115 	}
    116 
    117 	return 0;
    118 }
    119 
    120 extern int *nofault;
    121 
    122 static int
    123 xel_probe(addr)
    124 	paddr_t addr;
    125 {
    126 	u_int32_t b1, b2;
    127 	u_int16_t *start = (void*) INTIO_ADDR(addr);
    128 	label_t	faultbuf;
    129 	volatile u_int32_t *sram = (void*) INTIO_ADDR(XEL_RAM_ADDR_HIGHER);
    130 
    131 	if (badaddr(start))
    132 		return 0;
    133 
    134 	nofault = (int *) &faultbuf;
    135 	if (setjmp(&faultbuf)) {
    136 		nofault = (int *) 0;
    137 		return 0;
    138 	}
    139 
    140 	b1 = sram[0];
    141 	b2 = sram[1];
    142 	/* Try to map the Xellent local memory. */
    143 	start[0] = XEL_MODE_RAM_HIGHER | XEL_MODE_MAP_RAM | XEL_MODE_MPU_030;
    144 
    145 #if 0
    146 	/* the contents should be deferent. */
    147 	if (b1 == sram[0] && b2 == sram[1]) {
    148 		nofault = (int *) 0;
    149 		return 0;
    150 	}
    151 #else
    152 	/* Try to write to the local memory. */
    153 	sram[0] = 0x55555555;
    154 	sram[1] = 0xaaaaaaaa;
    155 	if (sram[0] != 0x55555555 || sram[1] != 0xaaaaaaaa) {
    156 		sram[0] = b1;
    157 		sram[1] = b2;
    158 		nofault = (int *) 0;
    159 		return 0;
    160 	}
    161 	sram[0] = 0xaaaaaaaa;
    162 	sram[1] = 0x55555555;
    163 	if (sram[0] != 0xaaaaaaaa || sram[1] != 0x55555555) {
    164 		sram[0] = b1;
    165 		sram[1] = b2;
    166 		nofault = (int *) 0;
    167 		return 0;
    168 	}
    169 	sram[0] = b1;
    170 	sram[1] = b2;
    171 #endif
    172 
    173 	/* Unmap. */
    174 	start[0] = XEL_MODE_UNMAP_RAM | XEL_MODE_MPU_030;
    175 
    176 	nofault = (int *) 0;
    177 	return 1;
    178 }
    179 
    180 static int
    181 xel_match (parent, match, aux)
    182 	struct device *parent;
    183 	struct cfdata *match;
    184 	void *aux;
    185 {
    186 	struct intio_attach_args *ia = aux;
    187 
    188 	if (strcmp (ia->ia_name, "xel") != 0)
    189 		return 0;
    190 
    191 	if (xel_addr(parent, match, ia)) {
    192 #ifdef DIAGNOSTIC
    193 		if (cputype != CPU_68030)
    194 			panic ("Non-030 Xellent???");
    195 #endif
    196 		return 1;
    197 	}
    198 	return 0;
    199 }
    200 
    201 static void
    202 xel_attach (parent, self, aux)
    203 	struct device *parent, *self;
    204 	void *aux;
    205 {
    206 	struct xel_softc *sc = (void*)self;
    207 	struct intio_attach_args *ia = aux;
    208 	struct cfdata *cf = self->dv_cfdata;
    209 	paddr_t addr;
    210 	int r;
    211 
    212 	addr = xel_addr(parent, cf, aux);
    213 	sc->sc_bst = ia->ia_bst;
    214 	ia->ia_addr = (int) addr;
    215 	ia->ia_size = 0x4000;
    216 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    217 #ifdef DIAGNOSTIC
    218 	if (r)
    219 		panic ("IO map for Xellent30 corruption??");
    220 #endif
    221 	printf (": Xellent30 MPU Accelerator.\n");
    222 
    223 	return;
    224 }
    225