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