Home | History | Annotate | Line # | Download | only in mvme
pcctwo.c revision 1.1
      1  1.1  scw /*	$NetBSD: pcctwo.c,v 1.1 2002/02/12 20:38:49 scw Exp $	*/
      2  1.1  scw 
      3  1.1  scw /*-
      4  1.1  scw  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
      5  1.1  scw  * All rights reserved.
      6  1.1  scw  *
      7  1.1  scw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  scw  * by Steve C. Woodford.
      9  1.1  scw  *
     10  1.1  scw  * Redistribution and use in source and binary forms, with or without
     11  1.1  scw  * modification, are permitted provided that the following conditions
     12  1.1  scw  * are met:
     13  1.1  scw  * 1. Redistributions of source code must retain the above copyright
     14  1.1  scw  *    notice, this list of conditions and the following disclaimer.
     15  1.1  scw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  scw  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  scw  *    documentation and/or other materials provided with the distribution.
     18  1.1  scw  * 3. All advertising materials mentioning features or use of this software
     19  1.1  scw  *    must display the following acknowledgement:
     20  1.1  scw  *	      This product includes software developed by the NetBSD
     21  1.1  scw  *	      Foundation, Inc. and its contributors.
     22  1.1  scw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  scw  *    contributors may be used to endorse or promote products derived
     24  1.1  scw  *    from this software without specific prior written permission.
     25  1.1  scw  *
     26  1.1  scw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  scw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  scw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  scw  */
     38  1.1  scw 
     39  1.1  scw /*
     40  1.1  scw  * PCCchip2 and MCchip Driver
     41  1.1  scw  */
     42  1.1  scw 
     43  1.1  scw #include <sys/param.h>
     44  1.1  scw #include <sys/kernel.h>
     45  1.1  scw #include <sys/systm.h>
     46  1.1  scw #include <sys/device.h>
     47  1.1  scw 
     48  1.1  scw #include <machine/cpu.h>
     49  1.1  scw #include <machine/bus.h>
     50  1.1  scw 
     51  1.1  scw #include <dev/mvme/pcctworeg.h>
     52  1.1  scw #include <dev/mvme/pcctwovar.h>
     53  1.1  scw 
     54  1.1  scw /*
     55  1.1  scw  * Global Pointer to the PCCChip2/MCchip soft state, and chip ID
     56  1.1  scw  */
     57  1.1  scw struct pcctwo_softc *sys_pcctwo;
     58  1.1  scw 
     59  1.1  scw int pcctwoprint(void *, const char *);
     60  1.1  scw 
     61  1.1  scw 
     62  1.1  scw /* ARGSUSED */
     63  1.1  scw void
     64  1.1  scw pcctwo_init(sc, pd, devoff)
     65  1.1  scw 	struct pcctwo_softc *sc;
     66  1.1  scw 	struct pcctwo_device *pd;
     67  1.1  scw 	int devoff;
     68  1.1  scw {
     69  1.1  scw 	struct pcctwo_attach_args npa;
     70  1.1  scw 	u_int8_t cid;
     71  1.1  scw 
     72  1.1  scw 	/*
     73  1.1  scw 	 * Fix up the vector base for PCCChip2 Interrupts
     74  1.1  scw 	 */
     75  1.1  scw 	pcc2_reg_write(sc, PCC2REG_VECTOR_BASE, sc->sc_vecbase);
     76  1.1  scw 
     77  1.1  scw 	/*
     78  1.1  scw 	 * Enable PCCChip2 Interrupts
     79  1.1  scw 	 */
     80  1.1  scw 	pcc2_reg_write(sc, PCC2REG_GENERAL_CONTROL,
     81  1.1  scw 	    pcc2_reg_read(sc, PCC2REG_GENERAL_CONTROL) | PCCTWO_GEN_CTRL_MIEN);
     82  1.1  scw 
     83  1.1  scw 	/* What are we? */
     84  1.1  scw 	cid = pcc2_reg_read(sc, PCC2REG_CHIP_ID);
     85  1.1  scw 
     86  1.1  scw 	/*
     87  1.1  scw 	 * Announce ourselves to the world in general
     88  1.1  scw 	 */
     89  1.1  scw 	if (cid == PCCTWO_CHIP_ID_PCC2)
     90  1.1  scw 		printf(": Peripheral Channel Controller (PCCchip2), Rev %d\n",
     91  1.1  scw 		    pcc2_reg_read(sc, PCC2REG_CHIP_REVISION));
     92  1.1  scw 	else
     93  1.1  scw 	if (cid == PCCTWO_CHIP_ID_MCCHIP)
     94  1.1  scw 		printf(": Memory Controller ASIC (MCchip), Rev %d\n",
     95  1.1  scw 		    pcc2_reg_read(sc, PCC2REG_CHIP_REVISION));
     96  1.1  scw 
     97  1.1  scw 	/*
     98  1.1  scw 	 * Attach configured children.
     99  1.1  scw 	 */
    100  1.1  scw 	npa._pa_base = devoff;
    101  1.1  scw 	while (pd->pcc_name != NULL) {
    102  1.1  scw 		/*
    103  1.1  scw 		 * Note that IPL is filled in by match function.
    104  1.1  scw 		 */
    105  1.1  scw 		npa.pa_name = pd->pcc_name;
    106  1.1  scw 		npa.pa_ipl = -1;
    107  1.1  scw 		npa.pa_dmat = sc->sc_dmat;
    108  1.1  scw 		npa.pa_bust = sc->sc_bust;
    109  1.1  scw 		npa.pa_offset = pd->pcc_offset + devoff;
    110  1.1  scw 		pd++;
    111  1.1  scw 
    112  1.1  scw 		/* Attach the device if configured. */
    113  1.1  scw 		(void) config_found(&sc->sc_dev, &npa, pcctwoprint);
    114  1.1  scw 	}
    115  1.1  scw }
    116  1.1  scw 
    117  1.1  scw int
    118  1.1  scw pcctwoprint(aux, cp)
    119  1.1  scw 	void *aux;
    120  1.1  scw 	const char *cp;
    121  1.1  scw {
    122  1.1  scw 	struct pcctwo_attach_args *pa;
    123  1.1  scw 
    124  1.1  scw 	pa = aux;
    125  1.1  scw 
    126  1.1  scw 	if (cp)
    127  1.1  scw 		printf("%s at %s", pa->pa_name, cp);
    128  1.1  scw 
    129  1.1  scw 	printf(" offset 0x%lx", pa->pa_offset - pa->_pa_base);
    130  1.1  scw 	if (pa->pa_ipl != -1)
    131  1.1  scw 		printf(" ipl %d", pa->pa_ipl);
    132  1.1  scw 
    133  1.1  scw 	return (UNCONF);
    134  1.1  scw }
    135  1.1  scw 
    136  1.1  scw /*
    137  1.1  scw  * pcctwointr_establish: Establish PCCChip2 Interrupt
    138  1.1  scw  */
    139  1.1  scw void
    140  1.1  scw pcctwointr_establish(vec, hand, lvl, arg, evcnt)
    141  1.1  scw 	int vec;
    142  1.1  scw 	int (*hand) __P((void *)), lvl;
    143  1.1  scw 	void *arg;
    144  1.1  scw 	struct evcnt *evcnt;
    145  1.1  scw {
    146  1.1  scw 	int vec2icsr;
    147  1.1  scw 
    148  1.1  scw #ifdef DEBUG
    149  1.1  scw 	if (vec < 0 || vec >= PCCTWOV_MAX) {
    150  1.1  scw 		printf("pcctwo: illegal vector offset: 0x%x\n", vec);
    151  1.1  scw 		panic("pcctwointr_establish");
    152  1.1  scw 	}
    153  1.1  scw 	if (lvl < 1 || lvl > 7) {
    154  1.1  scw 		printf("pcctwo: illegal interrupt level: %d\n", lvl);
    155  1.1  scw 		panic("pcctwointr_establish");
    156  1.1  scw 	}
    157  1.1  scw 	if (sys_pcctwo->sc_vec2icsr[vec] == -1) {
    158  1.1  scw 		printf("pcctwo: unsupported vector: %d\n", vec);
    159  1.1  scw 		panic("pcctwointr_establish");
    160  1.1  scw 	}
    161  1.1  scw #endif
    162  1.1  scw 
    163  1.1  scw 	vec2icsr = sys_pcctwo->sc_vec2icsr[vec];
    164  1.1  scw 	pcc2_reg_write(sys_pcctwo, VEC2ICSR_REG(vec2icsr), 0);
    165  1.1  scw 
    166  1.1  scw 	/* Hook the interrupt */
    167  1.1  scw 	(*sys_pcctwo->sc_isrlink)(sys_pcctwo->sc_isrcookie, hand, arg,
    168  1.1  scw 	    lvl, vec + sys_pcctwo->sc_vecbase, evcnt);
    169  1.1  scw 
    170  1.1  scw 	/* Enable it in hardware */
    171  1.1  scw 	pcc2_reg_write(sys_pcctwo, VEC2ICSR_REG(vec2icsr),
    172  1.1  scw 	    VEC2ICSR_INIT(vec2icsr) | lvl);
    173  1.1  scw }
    174  1.1  scw 
    175  1.1  scw void
    176  1.1  scw pcctwointr_disestablish(vec)
    177  1.1  scw 	int vec;
    178  1.1  scw {
    179  1.1  scw 
    180  1.1  scw #ifdef DEBUG
    181  1.1  scw 	if (vec < 0 || vec >= PCCTWOV_MAX) {
    182  1.1  scw 		printf("pcctwo: illegal vector offset: 0x%x\n", vec);
    183  1.1  scw 		panic("pcctwointr_disestablish");
    184  1.1  scw 	}
    185  1.1  scw 	if (sys_pcctwo->sc_vec2icsr[vec] == -1) {
    186  1.1  scw 		printf("pcctwo: unsupported vector: %d\n", vec);
    187  1.1  scw 		panic("pcctwointr_establish");
    188  1.1  scw 	}
    189  1.1  scw #endif
    190  1.1  scw 
    191  1.1  scw 	/* Disable it in hardware */
    192  1.1  scw 	pcc2_reg_write(sys_pcctwo, sys_pcctwo->sc_vec2icsr[vec], 0);
    193  1.1  scw 
    194  1.1  scw 	(*sys_pcctwo->sc_isrunlink)(sys_pcctwo->sc_isrcookie,
    195  1.1  scw 	    vec + sys_pcctwo->sc_vecbase);
    196  1.1  scw }
    197  1.1  scw 
    198  1.1  scw struct evcnt *
    199  1.1  scw pcctwointr_evcnt(lev)
    200  1.1  scw 	int lev;
    201  1.1  scw {
    202  1.1  scw 
    203  1.1  scw 	return ((*sys_pcctwo->sc_isrevcnt)(sys_pcctwo->sc_isrcookie, lev));
    204  1.1  scw }
    205