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