Home | History | Annotate | Line # | Download | only in dev
pcc.c revision 1.24
      1  1.24       wiz /*	$NetBSD: pcc.c,v 1.24 2003/01/06 13:05:04 wiz 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.14       scw #include <sys/kcore.h>
     78  1.13       scw 
     79   1.1     chuck #include <machine/cpu.h>
     80  1.13       scw #include <machine/bus.h>
     81   1.3     chuck 
     82  1.13       scw #include <mvme68k/dev/mainbus.h>
     83   1.1     chuck #include <mvme68k/dev/pccreg.h>
     84   1.3     chuck #include <mvme68k/dev/pccvar.h>
     85   1.1     chuck 
     86   1.1     chuck /*
     87  1.13       scw  * Autoconfiguration stuff for the PCC chip on mvme147
     88   1.1     chuck  */
     89   1.1     chuck 
     90  1.13       scw void pccattach __P((struct device *, struct device *, void *));
     91  1.13       scw int pccmatch __P((struct device *, struct cfdata *, void *));
     92  1.13       scw int pccprint __P((void *, const char *));
     93   1.1     chuck 
     94  1.22   thorpej CFATTACH_DECL(pcc, sizeof(struct pcc_softc),
     95  1.22   thorpej     pccmatch, pccattach, NULL, NULL);
     96   1.2   thorpej 
     97  1.11   thorpej extern struct cfdriver pcc_cd;
     98  1.13       scw static int pccintr __P((void *));
     99  1.19       scw static int pccsoftintr __P((void *));
    100  1.19       scw static void pccsoftintrassert __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.20       scw 	{"clock", 0},
    115  1.13       scw 	{"zsc", PCC_ZS0_OFF},
    116  1.13       scw 	{"zsc", PCC_ZS1_OFF},
    117  1.13       scw 	{"le", PCC_LE_OFF},
    118  1.13       scw 	{"wdsc", PCC_WDSC_OFF},
    119  1.13       scw 	{"lpt", PCC_LPT_OFF},
    120  1.13       scw 	{"vmepcc", PCC_VME_OFF},
    121  1.13       scw 	{NULL, 0},
    122  1.13       scw };
    123  1.13       scw 
    124  1.13       scw static int pcc_vec2intctrl[] = {
    125  1.13       scw 	PCCREG_ACFAIL_INTR_CTRL,/* PCCV_ACFAIL */
    126  1.13       scw 	PCCREG_BUSERR_INTR_CTRL,/* PCCV_BERR */
    127  1.13       scw 	PCCREG_ABORT_INTR_CTRL,	/* PCCV_ABORT */
    128  1.13       scw 	PCCREG_SERIAL_INTR_CTRL,/* PCCV_ZS */
    129  1.13       scw 	PCCREG_LANCE_INTR_CTRL,	/* PCCV_LE */
    130  1.13       scw 	PCCREG_SCSI_INTR_CTRL,	/* PCCV_SCSI */
    131  1.13       scw 	PCCREG_DMA_INTR_CTRL,	/* PCCV_DMA */
    132  1.13       scw 	PCCREG_PRNT_INTR_CTRL,	/* PCCV_PRINTER */
    133  1.13       scw 	PCCREG_TMR1_INTR_CTRL,	/* PCCV_TIMER1 */
    134  1.13       scw 	PCCREG_TMR2_INTR_CTRL,	/* PCCV_TIMER2 */
    135  1.13       scw 	PCCREG_SOFT1_INTR_CTRL,	/* PCCV_SOFT1 */
    136  1.13       scw 	PCCREG_SOFT2_INTR_CTRL	/* PCCV_SOFT2 */
    137   1.3     chuck };
    138   1.1     chuck 
    139  1.14       scw extern phys_ram_seg_t mem_clusters[];
    140  1.13       scw struct pcc_softc *sys_pcc;
    141  1.13       scw 
    142  1.14       scw /* The base address of the MVME147 from the VMEbus */
    143  1.14       scw bus_addr_t pcc_slave_base_addr;
    144  1.14       scw 
    145  1.14       scw 
    146  1.13       scw /* ARGSUSED */
    147   1.1     chuck int
    148   1.9       gwr pccmatch(parent, cf, args)
    149   1.1     chuck 	struct device *parent;
    150   1.9       gwr 	struct cfdata *cf;
    151   1.9       gwr 	void *args;
    152   1.1     chuck {
    153  1.13       scw 	struct mainbus_attach_args *ma;
    154  1.13       scw 
    155  1.13       scw 	ma = args;
    156   1.3     chuck 
    157   1.3     chuck 	/* Only attach one PCC. */
    158   1.3     chuck 	if (sys_pcc)
    159   1.3     chuck 		return (0);
    160   1.1     chuck 
    161  1.13       scw 	return (strcmp(ma->ma_name, pcc_cd.cd_name) == 0);
    162   1.1     chuck }
    163   1.1     chuck 
    164  1.13       scw /* ARGSUSED */
    165   1.1     chuck void
    166   1.1     chuck pccattach(parent, self, args)
    167  1.13       scw 	struct device *parent;
    168  1.13       scw 	struct device *self;
    169   1.1     chuck 	void *args;
    170   1.1     chuck {
    171  1.13       scw 	struct mainbus_attach_args *ma;
    172   1.3     chuck 	struct pcc_attach_args npa;
    173  1.13       scw 	struct pcc_softc *sc;
    174  1.13       scw 	u_int8_t reg;
    175   1.6   thorpej 	int i;
    176   1.1     chuck 
    177  1.13       scw 	ma = args;
    178  1.13       scw 	sc = sys_pcc = (struct pcc_softc *) self;
    179   1.1     chuck 
    180  1.13       scw 	/* Get a handle to the PCC's registers. */
    181  1.13       scw 	sc->sc_bust = ma->ma_bust;
    182  1.20       scw 	bus_space_map(sc->sc_bust, ma->ma_offset, PCCREG_SIZE, 0, &sc->sc_bush);
    183   1.1     chuck 
    184  1.13       scw 	/* Tell the chip the base interrupt vector */
    185  1.13       scw 	pcc_reg_write(sc, PCCREG_VECTOR_BASE, PCC_VECBASE);
    186   1.1     chuck 
    187   1.8  christos 	printf(": Peripheral Channel Controller, "
    188  1.13       scw 	    "rev %d, vecbase 0x%x\n", pcc_reg_read(sc, PCCREG_REVISION),
    189  1.13       scw 	    pcc_reg_read(sc, PCCREG_VECTOR_BASE));
    190   1.3     chuck 
    191  1.18       scw 	evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
    192  1.18       scw 	    isrlink_evcnt(7), "nmi", "abort sw");
    193  1.18       scw 
    194  1.13       scw 	/* Hook up interrupt handler for abort button, and enable it */
    195  1.18       scw 	pccintr_establish(PCCV_ABORT, pccintr, 7, NULL, &sc->sc_evcnt);
    196  1.13       scw 	pcc_reg_write(sc, PCCREG_ABORT_INTR_CTRL,
    197  1.13       scw 	    PCC_ABORT_IEN | PCC_ABORT_ACK);
    198   1.3     chuck 
    199  1.19       scw 	/*
    200  1.19       scw 	 * Install a handler for Software Interrupt 1
    201  1.19       scw 	 * and arrange to schedule soft interrupts on demand.
    202  1.19       scw 	 */
    203  1.19       scw 	pccintr_establish(PCCV_SOFT1, pccsoftintr, 1, sc, &sc->sc_evcnt);
    204  1.19       scw 	_softintr_chipset_assert = pccsoftintrassert;
    205  1.19       scw 
    206   1.3     chuck 	/* Make sure the global interrupt line is hot. */
    207  1.13       scw 	reg = pcc_reg_read(sc, PCCREG_GENERAL_CONTROL) | PCC_GENCR_IEN;
    208  1.13       scw 	pcc_reg_write(sc, PCCREG_GENERAL_CONTROL, reg);
    209  1.14       scw 
    210  1.14       scw 	/*
    211  1.14       scw 	 * Calculate the board's VMEbus slave base address, for the
    212  1.14       scw 	 * benefit of the VMEchip driver.
    213  1.14       scw 	 * (Weird that this register is in the PCC ...)
    214  1.14       scw 	 */
    215  1.14       scw 	reg = pcc_reg_read(sc, PCCREG_SLAVE_BASE_ADDR) & PCC_SLAVE_BASE_MASK;
    216  1.14       scw 	pcc_slave_base_addr = (bus_addr_t)reg * mem_clusters[0].size;
    217   1.3     chuck 
    218   1.3     chuck 	/*
    219   1.3     chuck 	 * Attach configured children.
    220   1.3     chuck 	 */
    221  1.15       scw 	npa._pa_base = ma->ma_offset;
    222   1.3     chuck 	for (i = 0; pcc_devices[i].pcc_name != NULL; ++i) {
    223   1.3     chuck 		/*
    224   1.3     chuck 		 * Note that IPL is filled in by match function.
    225   1.3     chuck 		 */
    226   1.3     chuck 		npa.pa_name = pcc_devices[i].pcc_name;
    227   1.3     chuck 		npa.pa_ipl = -1;
    228  1.13       scw 		npa.pa_dmat = ma->ma_dmat;
    229  1.13       scw 		npa.pa_bust = ma->ma_bust;
    230  1.13       scw 		npa.pa_offset = pcc_devices[i].pcc_offset + ma->ma_offset;
    231   1.3     chuck 
    232   1.3     chuck 		/* Attach the device if configured. */
    233  1.13       scw 		(void) config_found(self, &npa, pccprint);
    234   1.3     chuck 	}
    235   1.1     chuck }
    236   1.1     chuck 
    237   1.1     chuck int
    238   1.3     chuck pccprint(aux, cp)
    239   1.3     chuck 	void *aux;
    240   1.5       cgd 	const char *cp;
    241   1.1     chuck {
    242  1.13       scw 	struct pcc_attach_args *pa;
    243  1.13       scw 
    244  1.13       scw 	pa = aux;
    245   1.3     chuck 
    246   1.3     chuck 	if (cp)
    247  1.23   thorpej 		aprint_normal("%s at %s", pa->pa_name, cp);
    248   1.3     chuck 
    249  1.23   thorpej 	aprint_normal(" offset 0x%lx", pa->pa_offset - pa->_pa_base);
    250   1.3     chuck 	if (pa->pa_ipl != -1)
    251  1.23   thorpej 		aprint_normal(" ipl %d", pa->pa_ipl);
    252   1.1     chuck 
    253   1.3     chuck 	return (UNCONF);
    254   1.1     chuck }
    255   1.1     chuck 
    256   1.1     chuck /*
    257   1.1     chuck  * pccintr_establish: establish pcc interrupt
    258   1.1     chuck  */
    259   1.3     chuck void
    260  1.18       scw pccintr_establish(pccvec, hand, lvl, arg, evcnt)
    261   1.3     chuck 	int pccvec;
    262   1.3     chuck 	int (*hand) __P((void *)), lvl;
    263   1.1     chuck 	void *arg;
    264  1.18       scw 	struct evcnt *evcnt;
    265   1.1     chuck {
    266   1.3     chuck 
    267  1.13       scw #ifdef DEBUG
    268  1.13       scw 	if (pccvec < 0 || pccvec >= PCC_NVEC) {
    269   1.8  christos 		printf("pcc: illegal vector offset: 0x%x\n", pccvec);
    270   1.1     chuck 		panic("pccintr_establish");
    271   1.1     chuck 	}
    272  1.13       scw 	if (lvl < 1 || lvl > 7) {
    273   1.8  christos 		printf("pcc: illegal interrupt level: %d\n", lvl);
    274   1.1     chuck 		panic("pccintr_establish");
    275   1.1     chuck 	}
    276  1.13       scw #endif
    277   1.1     chuck 
    278  1.18       scw 	isrlink_vectored(hand, arg, lvl, pccvec + PCC_VECBASE, evcnt);
    279   1.3     chuck }
    280   1.3     chuck 
    281   1.3     chuck void
    282   1.3     chuck pccintr_disestablish(pccvec)
    283   1.3     chuck 	int pccvec;
    284   1.3     chuck {
    285   1.3     chuck 
    286  1.13       scw #ifdef DEBUG
    287  1.13       scw 	if (pccvec < 0 || pccvec >= PCC_NVEC) {
    288   1.8  christos 		printf("pcc: illegal vector offset: 0x%x\n", pccvec);
    289  1.13       scw 		panic("pccintr_disestablish");
    290   1.3     chuck 	}
    291  1.13       scw #endif
    292   1.3     chuck 
    293  1.13       scw 	/* Disable the interrupt */
    294  1.13       scw 	pcc_reg_write(sys_pcc, pcc_vec2intctrl[pccvec], PCC_ICLEAR);
    295   1.3     chuck 	isrunlink_vectored(pccvec + PCC_VECBASE);
    296   1.3     chuck }
    297   1.3     chuck 
    298   1.3     chuck /*
    299   1.3     chuck  * Handle NMI from abort switch.
    300   1.3     chuck  */
    301  1.13       scw static int
    302   1.3     chuck pccintr(frame)
    303   1.3     chuck 	void *frame;
    304   1.3     chuck {
    305   1.3     chuck 
    306   1.3     chuck 	/* XXX wait until button pops out */
    307  1.13       scw 	pcc_reg_write(sys_pcc, PCCREG_ABORT_INTR_CTRL,
    308  1.13       scw 	    PCC_ABORT_IEN | PCC_ABORT_ACK);
    309  1.13       scw 
    310  1.13       scw 	return (nmihand(frame));
    311  1.19       scw }
    312  1.19       scw 
    313  1.19       scw static void
    314  1.19       scw pccsoftintrassert(void)
    315  1.19       scw {
    316  1.19       scw 
    317  1.19       scw 	/* Request a software interrupt at ipl 1 */
    318  1.19       scw 	pcc_reg_write(sys_pcc, PCCREG_SOFT1_INTR_CTRL, 1 | PCC_IENABLE);
    319  1.19       scw }
    320  1.19       scw 
    321  1.19       scw /*
    322  1.24       wiz  * Handle PCC soft interrupt #1
    323  1.19       scw  */
    324  1.19       scw static int
    325  1.19       scw pccsoftintr(arg)
    326  1.19       scw 	void *arg;
    327  1.19       scw {
    328  1.19       scw 	struct pcc_softc *sc = arg;
    329  1.19       scw 
    330  1.19       scw 	/* Clear the interrupt */
    331  1.19       scw 	pcc_reg_write(sc, PCCREG_SOFT1_INTR_CTRL, 0);
    332  1.19       scw 
    333  1.19       scw 	/* Call the soft interrupt dispatcher */
    334  1.19       scw 	softintr_dispatch();
    335  1.19       scw 
    336  1.19       scw 	return (1);
    337   1.1     chuck }
    338