Home | History | Annotate | Line # | Download | only in dev
pcc.c revision 1.13
      1 /*	$NetBSD: pcc.c,v 1.13 2000/03/18 22:33:03 scw Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe and 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  * Copyright (c) 1995 Charles D. Cranor
     41  * All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *      This product includes software developed by Charles D. Cranor.
     54  * 4. The name of the author may not be used to endorse or promote products
     55  *    derived from this software without specific prior written permission.
     56  *
     57  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     58  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     61  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     62  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     63  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     64  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     65  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     66  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67  */
     68 
     69 /*
     70  * peripheral channel controller
     71  */
     72 
     73 #include <sys/param.h>
     74 #include <sys/kernel.h>
     75 #include <sys/systm.h>
     76 #include <sys/device.h>
     77 
     78 #include <machine/cpu.h>
     79 #include <machine/bus.h>
     80 
     81 #include <mvme68k/mvme68k/isr.h>
     82 
     83 #include <mvme68k/dev/mainbus.h>
     84 #include <mvme68k/dev/pccreg.h>
     85 #include <mvme68k/dev/pccvar.h>
     86 
     87 /*
     88  * Autoconfiguration stuff for the PCC chip on mvme147
     89  */
     90 
     91 void pccattach __P((struct device *, struct device *, void *));
     92 int pccmatch __P((struct device *, struct cfdata *, void *));
     93 int pccprint __P((void *, const char *));
     94 
     95 struct cfattach pcc_ca = {
     96 	sizeof(struct pcc_softc), pccmatch, pccattach
     97 };
     98 
     99 extern struct cfdriver pcc_cd;
    100 static int pccintr __P((void *));
    101 
    102 /*
    103  * Structure used to describe a device for autoconfiguration purposes.
    104  */
    105 struct pcc_device {
    106 	char *pcc_name;		/* name of device (e.g. "clock") */
    107 	bus_addr_t pcc_offset;	/* offset from PCC base */
    108 };
    109 
    110 /*
    111  * Devices that live on the PCC, attached in this order.
    112  */
    113 static struct pcc_device pcc_devices[] = {
    114 	{"clock", PCC_RTC_OFF},
    115 	{"nvram", PCC_NVRAM_OFF},
    116 	{"zsc", PCC_ZS0_OFF},
    117 	{"zsc", PCC_ZS1_OFF},
    118 	{"le", PCC_LE_OFF},
    119 	{"wdsc", PCC_WDSC_OFF},
    120 	{"lpt", PCC_LPT_OFF},
    121 	{"vmepcc", PCC_VME_OFF},
    122 	{NULL, 0},
    123 };
    124 
    125 static int pcc_vec2intctrl[] = {
    126 	PCCREG_ACFAIL_INTR_CTRL,/* PCCV_ACFAIL */
    127 	PCCREG_BUSERR_INTR_CTRL,/* PCCV_BERR */
    128 	PCCREG_ABORT_INTR_CTRL,	/* PCCV_ABORT */
    129 	PCCREG_SERIAL_INTR_CTRL,/* PCCV_ZS */
    130 	PCCREG_LANCE_INTR_CTRL,	/* PCCV_LE */
    131 	PCCREG_SCSI_INTR_CTRL,	/* PCCV_SCSI */
    132 	PCCREG_DMA_INTR_CTRL,	/* PCCV_DMA */
    133 	PCCREG_PRNT_INTR_CTRL,	/* PCCV_PRINTER */
    134 	PCCREG_TMR1_INTR_CTRL,	/* PCCV_TIMER1 */
    135 	PCCREG_TMR2_INTR_CTRL,	/* PCCV_TIMER2 */
    136 	PCCREG_SOFT1_INTR_CTRL,	/* PCCV_SOFT1 */
    137 	PCCREG_SOFT2_INTR_CTRL	/* PCCV_SOFT2 */
    138 };
    139 
    140 struct pcc_softc *sys_pcc;
    141 
    142 /* ARGSUSED */
    143 int
    144 pccmatch(parent, cf, args)
    145 	struct device *parent;
    146 	struct cfdata *cf;
    147 	void *args;
    148 {
    149 	struct mainbus_attach_args *ma;
    150 
    151 	ma = args;
    152 
    153 	/* Only attach one PCC. */
    154 	if (sys_pcc)
    155 		return (0);
    156 
    157 	return (strcmp(ma->ma_name, pcc_cd.cd_name) == 0);
    158 }
    159 
    160 /* ARGSUSED */
    161 void
    162 pccattach(parent, self, args)
    163 	struct device *parent;
    164 	struct device *self;
    165 	void *args;
    166 {
    167 	struct mainbus_attach_args *ma;
    168 	struct pcc_attach_args npa;
    169 	struct pcc_softc *sc;
    170 	u_int8_t reg;
    171 	int i;
    172 
    173 	ma = args;
    174 	sc = sys_pcc = (struct pcc_softc *) self;
    175 
    176 	/* Get a handle to the PCC's registers. */
    177 	sc->sc_bust = ma->ma_bust;
    178 	bus_space_map(sc->sc_bust, PCC_REG_OFF + ma->ma_offset,
    179 	    PCCREG_SIZE, 0, &sc->sc_bush);
    180 
    181 	/* Tell the chip the base interrupt vector */
    182 	pcc_reg_write(sc, PCCREG_VECTOR_BASE, PCC_VECBASE);
    183 
    184 	printf(": Peripheral Channel Controller, "
    185 	    "rev %d, vecbase 0x%x\n", pcc_reg_read(sc, PCCREG_REVISION),
    186 	    pcc_reg_read(sc, PCCREG_VECTOR_BASE));
    187 
    188 	/* Hook up interrupt handler for abort button, and enable it */
    189 	pccintr_establish(PCCV_ABORT, pccintr, 7, NULL);
    190 	pcc_reg_write(sc, PCCREG_ABORT_INTR_CTRL,
    191 	    PCC_ABORT_IEN | PCC_ABORT_ACK);
    192 
    193 	/* Make sure the global interrupt line is hot. */
    194 	reg = pcc_reg_read(sc, PCCREG_GENERAL_CONTROL) | PCC_GENCR_IEN;
    195 	pcc_reg_write(sc, PCCREG_GENERAL_CONTROL, reg);
    196 
    197 	/*
    198 	 * Attach configured children.
    199 	 */
    200 	for (i = 0; pcc_devices[i].pcc_name != NULL; ++i) {
    201 		/*
    202 		 * Note that IPL is filled in by match function.
    203 		 */
    204 		npa.pa_name = pcc_devices[i].pcc_name;
    205 		npa.pa_ipl = -1;
    206 		npa.pa_dmat = ma->ma_dmat;
    207 		npa.pa_bust = ma->ma_bust;
    208 		npa.pa_offset = pcc_devices[i].pcc_offset + ma->ma_offset;
    209 
    210 		/* Attach the device if configured. */
    211 		(void) config_found(self, &npa, pccprint);
    212 	}
    213 }
    214 
    215 int
    216 pccprint(aux, cp)
    217 	void *aux;
    218 	const char *cp;
    219 {
    220 	struct pcc_attach_args *pa;
    221 
    222 	pa = aux;
    223 
    224 	if (cp)
    225 		printf("%s at %s", pa->pa_name, cp);
    226 
    227 	printf(" offset 0x%lx", pa->pa_offset);
    228 	if (pa->pa_ipl != -1)
    229 		printf(" ipl %d", pa->pa_ipl);
    230 
    231 	return (UNCONF);
    232 }
    233 
    234 /*
    235  * pccintr_establish: establish pcc interrupt
    236  */
    237 void
    238 pccintr_establish(pccvec, hand, lvl, arg)
    239 	int pccvec;
    240 	int (*hand) __P((void *)), lvl;
    241 	void *arg;
    242 {
    243 
    244 #ifdef DEBUG
    245 	if (pccvec < 0 || pccvec >= PCC_NVEC) {
    246 		printf("pcc: illegal vector offset: 0x%x\n", pccvec);
    247 		panic("pccintr_establish");
    248 	}
    249 	if (lvl < 1 || lvl > 7) {
    250 		printf("pcc: illegal interrupt level: %d\n", lvl);
    251 		panic("pccintr_establish");
    252 	}
    253 #endif
    254 
    255 	isrlink_vectored(hand, arg, lvl, pccvec + PCC_VECBASE);
    256 }
    257 
    258 void
    259 pccintr_disestablish(pccvec)
    260 	int pccvec;
    261 {
    262 
    263 #ifdef DEBUG
    264 	if (pccvec < 0 || pccvec >= PCC_NVEC) {
    265 		printf("pcc: illegal vector offset: 0x%x\n", pccvec);
    266 		panic("pccintr_disestablish");
    267 	}
    268 #endif
    269 
    270 	/* Disable the interrupt */
    271 	pcc_reg_write(sys_pcc, pcc_vec2intctrl[pccvec], PCC_ICLEAR);
    272 	isrunlink_vectored(pccvec + PCC_VECBASE);
    273 }
    274 
    275 /*
    276  * Handle NMI from abort switch.
    277  */
    278 static int
    279 pccintr(frame)
    280 	void *frame;
    281 {
    282 
    283 	/* XXX wait until button pops out */
    284 	pcc_reg_write(sys_pcc, PCCREG_ABORT_INTR_CTRL,
    285 	    PCC_ABORT_IEN | PCC_ABORT_ACK);
    286 
    287 	return (nmihand(frame));
    288 }
    289