Home | History | Annotate | Line # | Download | only in dev
vme_pcc.c revision 1.6
      1  1.6   thorpej /*	$NetBSD: vme_pcc.c,v 1.6 1998/01/12 19:51:10 thorpej Exp $	*/
      2  1.1     chuck 
      3  1.1     chuck /*-
      4  1.1     chuck  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  1.1     chuck  * All rights reserved.
      6  1.1     chuck  *
      7  1.1     chuck  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1     chuck  * by Jason R. Thorpe.
      9  1.1     chuck  *
     10  1.1     chuck  * Redistribution and use in source and binary forms, with or without
     11  1.1     chuck  * modification, are permitted provided that the following conditions
     12  1.1     chuck  * are met:
     13  1.1     chuck  * 1. Redistributions of source code must retain the above copyright
     14  1.1     chuck  *    notice, this list of conditions and the following disclaimer.
     15  1.1     chuck  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1     chuck  *    notice, this list of conditions and the following disclaimer in the
     17  1.1     chuck  *    documentation and/or other materials provided with the distribution.
     18  1.1     chuck  * 3. All advertising materials mentioning features or use of this software
     19  1.1     chuck  *    must display the following acknowledgement:
     20  1.1     chuck  *        This product includes software developed by the NetBSD
     21  1.1     chuck  *        Foundation, Inc. and its contributors.
     22  1.1     chuck  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1     chuck  *    contributors may be used to endorse or promote products derived
     24  1.1     chuck  *    from this software without specific prior written permission.
     25  1.1     chuck  *
     26  1.1     chuck  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1     chuck  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1     chuck  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.5       jtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.5       jtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1     chuck  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1     chuck  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1     chuck  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1     chuck  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1     chuck  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1     chuck  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1     chuck  */
     38  1.1     chuck 
     39  1.1     chuck /*
     40  1.1     chuck  * VME support specific to the Type 1 VMEchip found on the
     41  1.1     chuck  * MVME-147.
     42  1.1     chuck  *
     43  1.1     chuck  * For a manual on the MVME-147, call: 408.991.8634.  (Yes, this
     44  1.1     chuck  * is the Sunnyvale sales office.)
     45  1.1     chuck  */
     46  1.1     chuck 
     47  1.1     chuck #include <sys/param.h>
     48  1.1     chuck #include <sys/kernel.h>
     49  1.1     chuck #include <sys/systm.h>
     50  1.1     chuck #include <sys/device.h>
     51  1.1     chuck 
     52  1.1     chuck #include <machine/psl.h>
     53  1.1     chuck #include <machine/cpu.h>
     54  1.1     chuck 
     55  1.1     chuck #include <mvme68k/dev/pccreg.h>
     56  1.1     chuck #include <mvme68k/dev/pccvar.h>
     57  1.1     chuck #include <mvme68k/dev/vme_pccreg.h>
     58  1.1     chuck #include <mvme68k/dev/vmevar.h>
     59  1.1     chuck 
     60  1.4       gwr int 	vmechip_pcc_match  __P((struct device *, struct cfdata *, void *));
     61  1.1     chuck void	vmechip_pcc_attach __P((struct device *, struct device *, void *));
     62  1.1     chuck 
     63  1.1     chuck struct cfattach vmechip_pcc_ca = {
     64  1.1     chuck 	sizeof(struct vmechip_softc), vmechip_pcc_match, vmechip_pcc_attach
     65  1.1     chuck };
     66  1.6   thorpej 
     67  1.6   thorpej extern struct cfdriver vmechip_cd;
     68  1.6   thorpej extern struct cfdriver vmes_cd;
     69  1.6   thorpej extern struct cfdriver vmel_cd;
     70  1.1     chuck 
     71  1.1     chuck int	vmechip_pcc_translate_addr __P((u_long, size_t, int, int, u_long *));
     72  1.1     chuck void	vmechip_pcc_intrline_enable __P((int));
     73  1.1     chuck void	vmechip_pcc_intrline_disable __P((int));
     74  1.1     chuck 
     75  1.1     chuck struct vme_chip vme_pcc_switch = {
     76  1.1     chuck 	vmechip_pcc_translate_addr,
     77  1.1     chuck 	vmechip_pcc_intrline_enable,
     78  1.1     chuck 	vmechip_pcc_intrline_disable
     79  1.1     chuck };
     80  1.1     chuck 
     81  1.1     chuck struct vme_pcc *sys_vme_pcc;
     82  1.1     chuck 
     83  1.1     chuck extern	int physmem;
     84  1.1     chuck 
     85  1.1     chuck int
     86  1.4       gwr vmechip_pcc_match(parent, cf, aux)
     87  1.1     chuck 	struct device *parent;
     88  1.4       gwr 	struct cfdata *cf;
     89  1.4       gwr 	void *aux;
     90  1.1     chuck {
     91  1.1     chuck 	struct pcc_attach_args *pa = aux;
     92  1.1     chuck 
     93  1.1     chuck 	/* Only one VME chip, please. */
     94  1.1     chuck 	if (sys_vme_pcc)
     95  1.1     chuck 		return (0);
     96  1.1     chuck 
     97  1.1     chuck 	if (strcmp(pa->pa_name, vmechip_cd.cd_name))
     98  1.1     chuck 		return (0);
     99  1.1     chuck 
    100  1.1     chuck 	return (1);
    101  1.1     chuck }
    102  1.1     chuck 
    103  1.1     chuck void
    104  1.1     chuck vmechip_pcc_attach(parent, self, aux)
    105  1.1     chuck 	struct device *parent, *self;
    106  1.1     chuck 	void *aux;
    107  1.1     chuck {
    108  1.1     chuck 	struct vmechip_softc *sc = (struct vmechip_softc *)self;
    109  1.1     chuck 	struct pcc_attach_args *pa = aux;
    110  1.1     chuck 	struct vme_pcc *vme;
    111  1.1     chuck 
    112  1.1     chuck 	/* Glue into generic VME code. */
    113  1.1     chuck 	sc->sc_reg = PCC_VADDR(pa->pa_offset);
    114  1.1     chuck 	sc->sc_chip = &vme_pcc_switch;
    115  1.1     chuck 
    116  1.1     chuck 	/* Initialize the chip. */
    117  1.1     chuck 	vme = (struct vme_pcc *)sc->sc_reg;
    118  1.1     chuck 	vme->vme_scon &= ~VME1_SCON_SYSFAIL;	/* XXX doesn't work */
    119  1.1     chuck 
    120  1.1     chuck 	sys_vme_pcc = vme;
    121  1.1     chuck 
    122  1.3  christos 	printf(": Type 1 VMEchip, scon jumper %s\n",
    123  1.1     chuck 	    (vme->vme_scon & VME1_SCON_SWITCH) ? "enabled" : "disabled");
    124  1.1     chuck 
    125  1.1     chuck 	/* Attach children. */
    126  1.1     chuck 	vme_config(sc);
    127  1.1     chuck }
    128  1.1     chuck 
    129  1.1     chuck int
    130  1.1     chuck vmechip_pcc_translate_addr(start, len, bustype, atype, addrp)
    131  1.1     chuck 	u_long start;
    132  1.1     chuck 	size_t len;
    133  1.1     chuck 	int bustype, atype;
    134  1.1     chuck 	u_long *addrp;		/* result */
    135  1.1     chuck {
    136  1.1     chuck 	u_long end = (start + len) - 1;
    137  1.1     chuck 
    138  1.1     chuck 	switch (bustype) {
    139  1.1     chuck 	case VME_D16:
    140  1.1     chuck 		switch (atype) {
    141  1.1     chuck 		case VME_A16:
    142  1.1     chuck 			if (end < VME1_A16D16_LEN) {
    143  1.1     chuck 				*addrp = VME1_A16D16_START + start;
    144  1.1     chuck 				return (0);
    145  1.1     chuck 			}
    146  1.1     chuck 			break;
    147  1.1     chuck 
    148  1.1     chuck 		case VME_A24:
    149  1.1     chuck 			if (((end & 0x00ffffff) == end) &&
    150  1.1     chuck 			    (end < VME1_A32D16_LEN)) {
    151  1.1     chuck 				*addrp = VME1_A32D16_START + start;
    152  1.1     chuck 				return (0);
    153  1.1     chuck 			}
    154  1.1     chuck 			break;
    155  1.1     chuck 
    156  1.1     chuck 		case VME_A32:
    157  1.1     chuck 			if (end < VME1_A32D16_LEN) {
    158  1.1     chuck 				*addrp = VME1_A32D16_START + start;
    159  1.1     chuck 				return (0);
    160  1.1     chuck 			}
    161  1.1     chuck 			break;
    162  1.1     chuck 
    163  1.1     chuck 		default:
    164  1.3  christos 			printf("vmechip: impossible atype `%d'\n", atype);
    165  1.1     chuck 			panic("vmechip_pcc_translate_addr");
    166  1.1     chuck 		}
    167  1.1     chuck 
    168  1.3  christos 		printf("vmechip: can't map %s atype %d addr 0x%lx len 0x%x\n",
    169  1.1     chuck 		    vmes_cd.cd_name, atype, start, len);
    170  1.1     chuck 		break;
    171  1.1     chuck 
    172  1.1     chuck 	case VME_D32:
    173  1.1     chuck 		switch (atype) {
    174  1.1     chuck 		case VME_A16:
    175  1.1     chuck 			/* Can't map A16D32 */
    176  1.1     chuck 			break;
    177  1.1     chuck 
    178  1.1     chuck 		case VME_A24:
    179  1.1     chuck 			if (((u_long)physmem < 0x1000000) &&	/* 16MB */
    180  1.1     chuck 			    (start >= (u_long)physmem) &&
    181  1.1     chuck 			    (end < VME1_A32D32_LEN)) {
    182  1.1     chuck 				*addrp = start;
    183  1.1     chuck 				return (0);
    184  1.1     chuck 			}
    185  1.1     chuck 			break;
    186  1.1     chuck 
    187  1.1     chuck 		case VME_A32:
    188  1.1     chuck 			if ((start >= (u_long)physmem) &&
    189  1.1     chuck 			    (end < VME1_A32D32_LEN)) {
    190  1.1     chuck 				*addrp = start;
    191  1.1     chuck 				return (0);
    192  1.1     chuck 			}
    193  1.1     chuck 			break;
    194  1.1     chuck 
    195  1.1     chuck 		default:
    196  1.3  christos 			printf("vmechip: impossible atype `%d'\n", atype);
    197  1.1     chuck 			panic("vmechip_pcc_translate_addr");
    198  1.1     chuck 		}
    199  1.1     chuck 
    200  1.3  christos 		printf("vmechip: can't map %s atype %d addr 0x%lx len 0x%x\n",
    201  1.1     chuck 		    vmel_cd.cd_name, atype, start, len);
    202  1.1     chuck 		break;
    203  1.1     chuck 
    204  1.1     chuck 	default:
    205  1.1     chuck 		panic("vmechip_pcc_translate_addr: bad bustype");
    206  1.1     chuck 	}
    207  1.1     chuck 
    208  1.1     chuck 	return (1);
    209  1.1     chuck }
    210  1.1     chuck 
    211  1.1     chuck void
    212  1.1     chuck vmechip_pcc_intrline_enable(ipl)
    213  1.1     chuck 	int ipl;
    214  1.1     chuck {
    215  1.1     chuck 
    216  1.1     chuck 	sys_vme_pcc->vme_irqen |= VME1_IRQ_VME(ipl);
    217  1.1     chuck }
    218  1.1     chuck 
    219  1.1     chuck void
    220  1.1     chuck vmechip_pcc_intrline_disable(ipl)
    221  1.1     chuck 	int ipl;
    222  1.1     chuck {
    223  1.1     chuck 
    224  1.1     chuck 	sys_vme_pcc->vme_irqen &= ~VME1_IRQ_VME(ipl);
    225  1.1     chuck }
    226