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