Home | History | Annotate | Line # | Download | only in dev
xel.c revision 1.7.8.1
      1  1.7.8.1     kent /*	$NetBSD: xel.c,v 1.7.8.1 2005/04/29 11:28:28 kent 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.7    lukem 
     44      1.7    lukem #include <sys/cdefs.h>
     45  1.7.8.1     kent __KERNEL_RCSID(0, "$NetBSD: xel.c,v 1.7.8.1 2005/04/29 11:28:28 kent Exp $");
     46      1.2  minoura 
     47      1.2  minoura #include <sys/param.h>
     48      1.2  minoura #include <sys/systm.h>
     49      1.2  minoura #include <sys/kernel.h>
     50      1.2  minoura #include <sys/device.h>
     51      1.2  minoura 
     52      1.2  minoura #include <machine/cpu.h>
     53      1.2  minoura #include <machine/bus.h>
     54      1.2  minoura 
     55      1.2  minoura #include <arch/x68k/dev/intiovar.h>
     56      1.2  minoura 
     57  1.7.8.1     kent static paddr_t xel_addr(struct device *, struct cfdata *,
     58  1.7.8.1     kent 	struct intio_attach_args *);
     59  1.7.8.1     kent static int xel_probe(paddr_t);
     60  1.7.8.1     kent static int xel_match(struct device *, struct cfdata *, void *);
     61  1.7.8.1     kent static void xel_attach(struct device *, struct device *, void *);
     62      1.2  minoura 
     63      1.2  minoura struct xel_softc {
     64      1.2  minoura 	struct device dev;
     65      1.2  minoura 
     66      1.2  minoura 	bus_space_tag_t sc_bst;
     67      1.2  minoura 	bus_space_handle_t sc_bh;
     68      1.2  minoura };
     69      1.2  minoura 
     70      1.5  thorpej CFATTACH_DECL(xel, sizeof (struct xel_softc),
     71      1.6  thorpej     xel_match, xel_attach, NULL, NULL);
     72      1.2  minoura 
     73      1.2  minoura static paddr_t xel_addrs[] = { 0xec0000, 0xec4000, 0xec8000, 0xecc000 };
     74      1.2  minoura 
     75      1.2  minoura #define XEL_MODE_RAM_LOWER	0x00
     76      1.2  minoura #define XEL_MODE_RAM_HIGHER	0x01
     77      1.2  minoura #define XEL_MODE_UNMAP_RAM	0x00
     78      1.2  minoura #define XEL_MODE_MAP_RAM	0x02
     79      1.2  minoura #define XEL_MODE_MPU_000	0x00
     80      1.2  minoura #define XEL_MODE_MPU_030	0x04
     81      1.2  minoura 
     82      1.2  minoura #define XEL_RAM_ADDR_LOWER	0xbc0000
     83      1.2  minoura #define XEL_RAM_ADDR_HIGHER	0xfc0000
     84      1.2  minoura 
     85      1.2  minoura 
     86  1.7.8.1     kent static paddr_t
     87  1.7.8.1     kent xel_addr(struct device *parent, struct cfdata *match,
     88  1.7.8.1     kent     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.7.8.1     kent 		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.7.8.1     kent 		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.7.8.1     kent static int
    123  1.7.8.1     kent xel_probe(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.7.8.1     kent 		nofault = NULL;
    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.7.8.1     kent 	nofault = NULL;
    176      1.2  minoura 	return 1;
    177      1.2  minoura }
    178      1.2  minoura 
    179  1.7.8.1     kent static int
    180  1.7.8.1     kent xel_match(struct device *parent, struct cfdata *match, void *aux)
    181      1.2  minoura {
    182      1.2  minoura 	struct intio_attach_args *ia = aux;
    183      1.2  minoura 
    184      1.2  minoura 	if (strcmp (ia->ia_name, "xel") != 0)
    185      1.2  minoura 		return 0;
    186      1.2  minoura 
    187      1.2  minoura 	if (xel_addr(parent, match, ia)) {
    188      1.2  minoura #ifdef DIAGNOSTIC
    189      1.2  minoura 		if (cputype != CPU_68030)
    190      1.2  minoura 			panic ("Non-030 Xellent???");
    191      1.2  minoura #endif
    192      1.2  minoura 		return 1;
    193      1.2  minoura 	}
    194      1.2  minoura 	return 0;
    195      1.2  minoura }
    196      1.2  minoura 
    197  1.7.8.1     kent static void
    198  1.7.8.1     kent xel_attach(struct device *parent, struct device *self, void *aux)
    199      1.2  minoura {
    200      1.2  minoura 	struct xel_softc *sc = (void*)self;
    201      1.2  minoura 	struct intio_attach_args *ia = aux;
    202      1.2  minoura 	struct cfdata *cf = self->dv_cfdata;
    203      1.2  minoura 	paddr_t addr;
    204      1.2  minoura 	int r;
    205      1.2  minoura 
    206      1.2  minoura 	addr = xel_addr(parent, cf, aux);
    207      1.2  minoura 	sc->sc_bst = ia->ia_bst;
    208      1.2  minoura 	ia->ia_addr = (int) addr;
    209      1.2  minoura 	ia->ia_size = 0x4000;
    210      1.2  minoura 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    211      1.2  minoura #ifdef DIAGNOSTIC
    212      1.2  minoura 	if (r)
    213      1.2  minoura 		panic ("IO map for Xellent30 corruption??");
    214      1.2  minoura #endif
    215      1.2  minoura 	printf (": Xellent30 MPU Accelerator.\n");
    216      1.2  minoura 
    217      1.2  minoura 	return;
    218      1.2  minoura }
    219