Home | History | Annotate | Line # | Download | only in dev
xel.c revision 1.2
      1  1.2  minoura /*	$NetBSD: xel.c,v 1.2 1999/03/16 16:30:20 minoura Exp $	*/
      2  1.2  minoura 
      3  1.2  minoura /*
      4  1.2  minoura  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.2  minoura  * All rights reserved.
      6  1.2  minoura  *
      7  1.2  minoura  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2  minoura  * by Minoura Makoto.
      9  1.2  minoura  *
     10  1.2  minoura  * Redistribution and use in source and binary forms, with or without
     11  1.2  minoura  * modification, are permitted provided that the following conditions
     12  1.2  minoura  * are met:
     13  1.2  minoura  * 1. Redistributions of source code must retain the above copyright
     14  1.2  minoura  *    notice, this list of conditions and the following disclaimer.
     15  1.2  minoura  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  minoura  *    notice, this list of conditions and the following disclaimer in the
     17  1.2  minoura  *    documentation and/or other materials provided with the distribution.
     18  1.2  minoura  * 3. All advertising materials mentioning features or use of this software
     19  1.2  minoura  *    must display the following acknowledgement:
     20  1.2  minoura  *        This product includes software developed by the NetBSD
     21  1.2  minoura  *        Foundation, Inc. and its contributors.
     22  1.2  minoura  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2  minoura  *    contributors may be used to endorse or promote products derived
     24  1.2  minoura  *    from this software without specific prior written permission.
     25  1.2  minoura  *
     26  1.2  minoura  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2  minoura  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2  minoura  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2  minoura  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2  minoura  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2  minoura  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2  minoura  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2  minoura  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2  minoura  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2  minoura  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2  minoura  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2  minoura  */
     38  1.2  minoura 
     39  1.2  minoura /*
     40  1.2  minoura  * TSR Xellent30 driver.
     41  1.2  minoura  * Detect Xellent30, and reserve its I/O area.
     42  1.2  minoura  */
     43  1.2  minoura 
     44  1.2  minoura #include <sys/param.h>
     45  1.2  minoura #include <sys/systm.h>
     46  1.2  minoura #include <sys/kernel.h>
     47  1.2  minoura #include <sys/device.h>
     48  1.2  minoura 
     49  1.2  minoura #include <machine/cpu.h>
     50  1.2  minoura #include <machine/bus.h>
     51  1.2  minoura 
     52  1.2  minoura #include <arch/x68k/dev/intiovar.h>
     53  1.2  minoura 
     54  1.2  minoura static paddr_t xel_addr __P((struct device *, struct cfdata *,
     55  1.2  minoura 			     struct intio_attach_args *));
     56  1.2  minoura static int xel_probe __P((paddr_t));
     57  1.2  minoura static int xel_match __P((struct device *, struct cfdata *, void *));
     58  1.2  minoura static void xel_attach __P((struct device *, struct device *, void *));
     59  1.2  minoura 
     60  1.2  minoura struct xel_softc {
     61  1.2  minoura 	struct device dev;
     62  1.2  minoura 
     63  1.2  minoura 	bus_space_tag_t sc_bst;
     64  1.2  minoura 	bus_space_handle_t sc_bh;
     65  1.2  minoura };
     66  1.2  minoura 
     67  1.2  minoura struct cfattach xel_ca = {
     68  1.2  minoura 	sizeof (struct xel_softc), xel_match, xel_attach
     69  1.2  minoura };
     70  1.2  minoura 
     71  1.2  minoura static paddr_t xel_addrs[] = { 0xec0000, 0xec4000, 0xec8000, 0xecc000 };
     72  1.2  minoura 
     73  1.2  minoura #define XEL_MODE_RAM_LOWER	0x00
     74  1.2  minoura #define XEL_MODE_RAM_HIGHER	0x01
     75  1.2  minoura #define XEL_MODE_UNMAP_RAM	0x00
     76  1.2  minoura #define XEL_MODE_MAP_RAM	0x02
     77  1.2  minoura #define XEL_MODE_MPU_000	0x00
     78  1.2  minoura #define XEL_MODE_MPU_030	0x04
     79  1.2  minoura 
     80  1.2  minoura #define XEL_RAM_ADDR_LOWER	0xbc0000
     81  1.2  minoura #define XEL_RAM_ADDR_HIGHER	0xfc0000
     82  1.2  minoura 
     83  1.2  minoura 
     84  1.2  minoura static paddr_t
     85  1.2  minoura xel_addr (parent, match, ia)
     86  1.2  minoura 	struct device *parent;
     87  1.2  minoura 	struct cfdata *match;
     88  1.2  minoura 	struct intio_attach_args *ia;
     89  1.2  minoura {
     90  1.2  minoura 	paddr_t addr = 0;
     91  1.2  minoura 
     92  1.2  minoura 	if (match->cf_addr == INTIOCF_ADDR_DEFAULT) {
     93  1.2  minoura 		int i;
     94  1.2  minoura 
     95  1.2  minoura 		for (i=0; i<sizeof(xel_addrs)/sizeof(xel_addrs[0]); i++) {
     96  1.2  minoura 			if (xel_probe(xel_addrs[i])) {
     97  1.2  minoura 				addr = xel_addrs[i];
     98  1.2  minoura 				break;
     99  1.2  minoura 			}
    100  1.2  minoura 		}
    101  1.2  minoura 	} else {
    102  1.2  minoura 		if (xel_probe((paddr_t) match->cf_addr))
    103  1.2  minoura 			addr = (paddr_t) match->cf_addr;
    104  1.2  minoura 	}
    105  1.2  minoura 
    106  1.2  minoura 	if (addr) {
    107  1.2  minoura 		/* found! */
    108  1.2  minoura 		ia->ia_addr = (int) addr;
    109  1.2  minoura 		ia->ia_size = 0x4000;
    110  1.2  minoura 		if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY)
    111  1.2  minoura 		    < 0)
    112  1.2  minoura 			return 0;
    113  1.2  minoura 		else
    114  1.2  minoura 			return addr;
    115  1.2  minoura 	}
    116  1.2  minoura 
    117  1.2  minoura 	return 0;
    118  1.2  minoura }
    119  1.2  minoura 
    120  1.2  minoura extern int *nofault;
    121  1.2  minoura 
    122  1.2  minoura static int
    123  1.2  minoura xel_probe(addr)
    124  1.2  minoura 	paddr_t addr;
    125  1.2  minoura {
    126  1.2  minoura 	u_int32_t b1, b2;
    127  1.2  minoura 	u_int16_t *start = (void*) INTIO_ADDR(addr);
    128  1.2  minoura 	label_t	faultbuf;
    129  1.2  minoura 	volatile u_int32_t *sram = (void*) INTIO_ADDR(XEL_RAM_ADDR_HIGHER);
    130  1.2  minoura 
    131  1.2  minoura 	if (badaddr(start))
    132  1.2  minoura 		return 0;
    133  1.2  minoura 
    134  1.2  minoura 	nofault = (int *) &faultbuf;
    135  1.2  minoura 	if (setjmp(&faultbuf)) {
    136  1.2  minoura 		nofault = (int *) 0;
    137  1.2  minoura 		return 0;
    138  1.2  minoura 	}
    139  1.2  minoura 
    140  1.2  minoura 	b1 = sram[0];
    141  1.2  minoura 	b2 = sram[1];
    142  1.2  minoura 	/* Try to map the Xellent local memory. */
    143  1.2  minoura 	start[0] = XEL_MODE_RAM_HIGHER | XEL_MODE_MAP_RAM | XEL_MODE_MPU_030;
    144  1.2  minoura 
    145  1.2  minoura #if 0
    146  1.2  minoura 	/* the contents should be deferent. */
    147  1.2  minoura 	if (b1 == sram[0] && b2 == sram[1]) {
    148  1.2  minoura 		nofault = (int *) 0;
    149  1.2  minoura 		return 0;
    150  1.2  minoura 	}
    151  1.2  minoura #else
    152  1.2  minoura 	/* Try to write to the local memory. */
    153  1.2  minoura 	sram[0] = 0x55555555;
    154  1.2  minoura 	sram[1] = 0xaaaaaaaa;
    155  1.2  minoura 	if (sram[0] != 0x55555555 || sram[1] != 0xaaaaaaaa) {
    156  1.2  minoura 		sram[0] = b1;
    157  1.2  minoura 		sram[1] = b2;
    158  1.2  minoura 		nofault = (int *) 0;
    159  1.2  minoura 		return 0;
    160  1.2  minoura 	}
    161  1.2  minoura 	sram[0] = 0xaaaaaaaa;
    162  1.2  minoura 	sram[1] = 0x55555555;
    163  1.2  minoura 	if (sram[0] != 0xaaaaaaaa || sram[1] != 0x55555555) {
    164  1.2  minoura 		sram[0] = b1;
    165  1.2  minoura 		sram[1] = b2;
    166  1.2  minoura 		nofault = (int *) 0;
    167  1.2  minoura 		return 0;
    168  1.2  minoura 	}
    169  1.2  minoura 	sram[0] = b1;
    170  1.2  minoura 	sram[1] = b2;
    171  1.2  minoura #endif
    172  1.2  minoura 
    173  1.2  minoura 	/* Unmap. */
    174  1.2  minoura 	start[0] = XEL_MODE_UNMAP_RAM | XEL_MODE_MPU_030;
    175  1.2  minoura 
    176  1.2  minoura 	nofault = (int *) 0;
    177  1.2  minoura 	return 1;
    178  1.2  minoura }
    179  1.2  minoura 
    180  1.2  minoura static int
    181  1.2  minoura xel_match (parent, match, aux)
    182  1.2  minoura 	struct device *parent;
    183  1.2  minoura 	struct cfdata *match;
    184  1.2  minoura 	void *aux;
    185  1.2  minoura {
    186  1.2  minoura 	struct intio_attach_args *ia = aux;
    187  1.2  minoura 
    188  1.2  minoura 	if (strcmp (ia->ia_name, "xel") != 0)
    189  1.2  minoura 		return 0;
    190  1.2  minoura 
    191  1.2  minoura 	if (xel_addr(parent, match, ia)) {
    192  1.2  minoura #ifdef DIAGNOSTIC
    193  1.2  minoura 		if (cputype != CPU_68030)
    194  1.2  minoura 			panic ("Non-030 Xellent???");
    195  1.2  minoura #endif
    196  1.2  minoura 		return 1;
    197  1.2  minoura 	}
    198  1.2  minoura 	return 0;
    199  1.2  minoura }
    200  1.2  minoura 
    201  1.2  minoura static void
    202  1.2  minoura xel_attach (parent, self, aux)
    203  1.2  minoura 	struct device *parent, *self;
    204  1.2  minoura 	void *aux;
    205  1.2  minoura {
    206  1.2  minoura 	struct xel_softc *sc = (void*)self;
    207  1.2  minoura 	struct intio_attach_args *ia = aux;
    208  1.2  minoura 	struct cfdata *cf = self->dv_cfdata;
    209  1.2  minoura 	paddr_t addr;
    210  1.2  minoura 	int r;
    211  1.2  minoura 
    212  1.2  minoura 	addr = xel_addr(parent, cf, aux);
    213  1.2  minoura 	sc->sc_bst = ia->ia_bst;
    214  1.2  minoura 	ia->ia_addr = (int) addr;
    215  1.2  minoura 	ia->ia_size = 0x4000;
    216  1.2  minoura 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    217  1.2  minoura #ifdef DIAGNOSTIC
    218  1.2  minoura 	if (r)
    219  1.2  minoura 		panic ("IO map for Xellent30 corruption??");
    220  1.2  minoura #endif
    221  1.2  minoura 	printf (": Xellent30 MPU Accelerator.\n");
    222  1.2  minoura 
    223  1.2  minoura 	return;
    224  1.2  minoura }
    225