Home | History | Annotate | Line # | Download | only in mvme
pcctwo.c revision 1.2
      1 /*	$NetBSD: pcctwo.c,v 1.2 2003/01/01 00:10:22 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Steve C. Woodford.
      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  * PCCchip2 and MCchip Driver
     41  */
     42 
     43 #include <sys/param.h>
     44 #include <sys/kernel.h>
     45 #include <sys/systm.h>
     46 #include <sys/device.h>
     47 
     48 #include <machine/cpu.h>
     49 #include <machine/bus.h>
     50 
     51 #include <dev/mvme/pcctworeg.h>
     52 #include <dev/mvme/pcctwovar.h>
     53 
     54 /*
     55  * Global Pointer to the PCCChip2/MCchip soft state, and chip ID
     56  */
     57 struct pcctwo_softc *sys_pcctwo;
     58 
     59 int pcctwoprint(void *, const char *);
     60 
     61 
     62 /* ARGSUSED */
     63 void
     64 pcctwo_init(sc, pd, devoff)
     65 	struct pcctwo_softc *sc;
     66 	struct pcctwo_device *pd;
     67 	int devoff;
     68 {
     69 	struct pcctwo_attach_args npa;
     70 	u_int8_t cid;
     71 
     72 	/*
     73 	 * Fix up the vector base for PCCChip2 Interrupts
     74 	 */
     75 	pcc2_reg_write(sc, PCC2REG_VECTOR_BASE, sc->sc_vecbase);
     76 
     77 	/*
     78 	 * Enable PCCChip2 Interrupts
     79 	 */
     80 	pcc2_reg_write(sc, PCC2REG_GENERAL_CONTROL,
     81 	    pcc2_reg_read(sc, PCC2REG_GENERAL_CONTROL) | PCCTWO_GEN_CTRL_MIEN);
     82 
     83 	/* What are we? */
     84 	cid = pcc2_reg_read(sc, PCC2REG_CHIP_ID);
     85 
     86 	/*
     87 	 * Announce ourselves to the world in general
     88 	 */
     89 	if (cid == PCCTWO_CHIP_ID_PCC2)
     90 		printf(": Peripheral Channel Controller (PCCchip2), Rev %d\n",
     91 		    pcc2_reg_read(sc, PCC2REG_CHIP_REVISION));
     92 	else
     93 	if (cid == PCCTWO_CHIP_ID_MCCHIP)
     94 		printf(": Memory Controller ASIC (MCchip), Rev %d\n",
     95 		    pcc2_reg_read(sc, PCC2REG_CHIP_REVISION));
     96 
     97 	/*
     98 	 * Attach configured children.
     99 	 */
    100 	npa._pa_base = devoff;
    101 	while (pd->pcc_name != NULL) {
    102 		/*
    103 		 * Note that IPL is filled in by match function.
    104 		 */
    105 		npa.pa_name = pd->pcc_name;
    106 		npa.pa_ipl = -1;
    107 		npa.pa_dmat = sc->sc_dmat;
    108 		npa.pa_bust = sc->sc_bust;
    109 		npa.pa_offset = pd->pcc_offset + devoff;
    110 		pd++;
    111 
    112 		/* Attach the device if configured. */
    113 		(void) config_found(&sc->sc_dev, &npa, pcctwoprint);
    114 	}
    115 }
    116 
    117 int
    118 pcctwoprint(aux, cp)
    119 	void *aux;
    120 	const char *cp;
    121 {
    122 	struct pcctwo_attach_args *pa;
    123 
    124 	pa = aux;
    125 
    126 	if (cp)
    127 		aprint_normal("%s at %s", pa->pa_name, cp);
    128 
    129 	aprint_normal(" offset 0x%lx", pa->pa_offset - pa->_pa_base);
    130 	if (pa->pa_ipl != -1)
    131 		aprint_normal(" ipl %d", pa->pa_ipl);
    132 
    133 	return (UNCONF);
    134 }
    135 
    136 /*
    137  * pcctwointr_establish: Establish PCCChip2 Interrupt
    138  */
    139 void
    140 pcctwointr_establish(vec, hand, lvl, arg, evcnt)
    141 	int vec;
    142 	int (*hand) __P((void *)), lvl;
    143 	void *arg;
    144 	struct evcnt *evcnt;
    145 {
    146 	int vec2icsr;
    147 
    148 #ifdef DEBUG
    149 	if (vec < 0 || vec >= PCCTWOV_MAX) {
    150 		printf("pcctwo: illegal vector offset: 0x%x\n", vec);
    151 		panic("pcctwointr_establish");
    152 	}
    153 	if (lvl < 1 || lvl > 7) {
    154 		printf("pcctwo: illegal interrupt level: %d\n", lvl);
    155 		panic("pcctwointr_establish");
    156 	}
    157 	if (sys_pcctwo->sc_vec2icsr[vec] == -1) {
    158 		printf("pcctwo: unsupported vector: %d\n", vec);
    159 		panic("pcctwointr_establish");
    160 	}
    161 #endif
    162 
    163 	vec2icsr = sys_pcctwo->sc_vec2icsr[vec];
    164 	pcc2_reg_write(sys_pcctwo, VEC2ICSR_REG(vec2icsr), 0);
    165 
    166 	/* Hook the interrupt */
    167 	(*sys_pcctwo->sc_isrlink)(sys_pcctwo->sc_isrcookie, hand, arg,
    168 	    lvl, vec + sys_pcctwo->sc_vecbase, evcnt);
    169 
    170 	/* Enable it in hardware */
    171 	pcc2_reg_write(sys_pcctwo, VEC2ICSR_REG(vec2icsr),
    172 	    VEC2ICSR_INIT(vec2icsr) | lvl);
    173 }
    174 
    175 void
    176 pcctwointr_disestablish(vec)
    177 	int vec;
    178 {
    179 
    180 #ifdef DEBUG
    181 	if (vec < 0 || vec >= PCCTWOV_MAX) {
    182 		printf("pcctwo: illegal vector offset: 0x%x\n", vec);
    183 		panic("pcctwointr_disestablish");
    184 	}
    185 	if (sys_pcctwo->sc_vec2icsr[vec] == -1) {
    186 		printf("pcctwo: unsupported vector: %d\n", vec);
    187 		panic("pcctwointr_establish");
    188 	}
    189 #endif
    190 
    191 	/* Disable it in hardware */
    192 	pcc2_reg_write(sys_pcctwo, sys_pcctwo->sc_vec2icsr[vec], 0);
    193 
    194 	(*sys_pcctwo->sc_isrunlink)(sys_pcctwo->sc_isrcookie,
    195 	    vec + sys_pcctwo->sc_vecbase);
    196 }
    197 
    198 struct evcnt *
    199 pcctwointr_evcnt(lev)
    200 	int lev;
    201 {
    202 
    203 	return ((*sys_pcctwo->sc_isrevcnt)(sys_pcctwo->sc_isrcookie, lev));
    204 }
    205