Home | History | Annotate | Line # | Download | only in dev
pcc.c revision 1.10
      1  1.10   thorpej /*	$NetBSD: pcc.c,v 1.10 1997/10/05 18:17:36 thorpej 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.10   thorpej  * by Jason R. Thorpe.
      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.1     chuck 
     73   1.1     chuck #include <sys/param.h>
     74   1.1     chuck #include <sys/conf.h>
     75   1.1     chuck #include <sys/ioctl.h>
     76   1.1     chuck #include <sys/proc.h>
     77   1.1     chuck #include <sys/user.h>
     78   1.1     chuck #include <sys/tty.h>
     79   1.1     chuck #include <sys/uio.h>
     80   1.1     chuck #include <sys/callout.h>
     81   1.1     chuck #include <sys/systm.h>
     82   1.1     chuck #include <sys/kernel.h>
     83   1.1     chuck #include <sys/syslog.h>
     84   1.1     chuck #include <sys/fcntl.h>
     85   1.1     chuck #include <sys/device.h>
     86   1.1     chuck #include <machine/cpu.h>
     87   1.1     chuck #include <dev/cons.h>
     88   1.3     chuck 
     89   1.1     chuck #include <mvme68k/mvme68k/isr.h>
     90   1.3     chuck 
     91   1.1     chuck #include <mvme68k/dev/pccreg.h>
     92   1.3     chuck #include <mvme68k/dev/pccvar.h>
     93   1.1     chuck 
     94   1.1     chuck /*
     95   1.1     chuck  * Autoconfiguration stuff.
     96   1.1     chuck  */
     97   1.1     chuck 
     98   1.1     chuck struct pccsoftc {
     99   1.1     chuck 	struct device	sc_dev;
    100   1.1     chuck 	struct pcc	*sc_pcc;
    101   1.1     chuck };
    102   1.1     chuck 
    103   1.3     chuck void	pccattach __P((struct device *, struct device *, void *));
    104   1.9       gwr int 	pccmatch __P((struct device *, struct cfdata *, void *));
    105   1.9       gwr int 	pccprint __P((void *, const char *));
    106   1.1     chuck 
    107   1.2   thorpej struct cfattach pcc_ca = {
    108   1.2   thorpej 	sizeof(struct pccsoftc), pccmatch, pccattach
    109   1.2   thorpej };
    110   1.2   thorpej 
    111   1.2   thorpej struct cfdriver pcc_cd = {
    112   1.2   thorpej 	NULL, "pcc", DV_DULL, 0
    113   1.1     chuck };
    114   1.1     chuck 
    115   1.3     chuck int	pccintr __P((void *));
    116   1.3     chuck 
    117   1.1     chuck /*
    118   1.1     chuck  * globals
    119   1.1     chuck  */
    120   1.1     chuck 
    121   1.1     chuck struct pcc *sys_pcc = NULL;
    122   1.1     chuck 
    123   1.3     chuck /*
    124   1.3     chuck  * Devices that live on the PCC, attached in this order.
    125   1.3     chuck  */
    126   1.3     chuck struct pcc_device pcc_devices[] = {
    127   1.3     chuck 	{ "clock",	PCC_CLOCK_OFF,	1 },
    128   1.3     chuck 	{ "zsc",	PCC_ZS0_OFF,	1 },
    129   1.3     chuck 	{ "zsc",	PCC_ZS1_OFF,	1 },
    130   1.3     chuck 	{ "le",		PCC_LE_OFF,	2 },
    131   1.3     chuck 	{ "wdsc",	PCC_WDSC_OFF,	1 },
    132   1.3     chuck 	{ "lpt",	PCC_LPT_OFF,	1 },
    133   1.3     chuck 	{ "vmechip",	PCC_VME_OFF,	2 },
    134   1.3     chuck 	{ NULL,		0,		0 },
    135   1.3     chuck };
    136   1.1     chuck 
    137   1.1     chuck int
    138   1.9       gwr pccmatch(parent, cf, args)
    139   1.1     chuck 	struct device *parent;
    140   1.9       gwr 	struct cfdata *cf;
    141   1.9       gwr 	void *args;
    142   1.1     chuck {
    143   1.3     chuck 	char *ma_name = args;
    144   1.3     chuck 
    145   1.3     chuck 	/* Only attach one PCC. */
    146   1.3     chuck 	if (sys_pcc)
    147   1.3     chuck 		return (0);
    148   1.1     chuck 
    149   1.3     chuck 	return (strcmp(ma_name, pcc_cd.cd_name) == 0);
    150   1.1     chuck }
    151   1.1     chuck 
    152   1.1     chuck void
    153   1.1     chuck pccattach(parent, self, args)
    154   1.1     chuck 	struct device *parent, *self;
    155   1.1     chuck 	void *args;
    156   1.1     chuck {
    157   1.1     chuck 	struct pccsoftc *pccsc;
    158   1.3     chuck 	struct pcc_attach_args npa;
    159   1.3     chuck 	caddr_t kva;
    160   1.6   thorpej 	int i;
    161   1.1     chuck 
    162   1.1     chuck 	if (sys_pcc)
    163   1.3     chuck 		panic("pccattach: pcc already attached!");
    164   1.1     chuck 
    165   1.3     chuck 	sys_pcc = (struct pcc *)PCC_VADDR(PCC_REG_OFF);
    166   1.1     chuck 
    167   1.1     chuck 	/*
    168   1.3     chuck 	 * link into softc and set up interrupt vector base,
    169   1.3     chuck 	 * and initialize the chip.
    170   1.1     chuck 	 */
    171   1.1     chuck 	pccsc = (struct pccsoftc *) self;
    172   1.3     chuck 	pccsc->sc_pcc = sys_pcc;
    173   1.1     chuck 	pccsc->sc_pcc->int_vectr = PCC_VECBASE;
    174   1.1     chuck 
    175   1.8  christos 	printf(": Peripheral Channel Controller, "
    176   1.3     chuck 	    "rev %d, vecbase 0x%x\n", pccsc->sc_pcc->pcc_rev,
    177   1.1     chuck 	    pccsc->sc_pcc->int_vectr);
    178   1.3     chuck 
    179   1.3     chuck 	/* Hook up interrupt handler for abort button. */
    180   1.3     chuck 	pccintr_establish(PCCV_ABORT, pccintr, 7, NULL);
    181   1.3     chuck 
    182   1.3     chuck 	/*
    183   1.3     chuck 	 * Now that the interrupt handler has been established,
    184   1.3     chuck 	 * enable the ABORT switch interrupt.
    185   1.3     chuck 	 */
    186   1.3     chuck 	pccsc->sc_pcc->abrt_int = PCC_ABORT_IEN | PCC_ABORT_ACK;
    187   1.3     chuck 
    188   1.3     chuck 	/* Make sure the global interrupt line is hot. */
    189   1.3     chuck 	pccsc->sc_pcc->gen_cr |= PCC_GENCR_IEN;
    190   1.3     chuck 
    191   1.3     chuck 	/*
    192   1.3     chuck 	 * Attach configured children.
    193   1.3     chuck 	 */
    194   1.3     chuck 	for (i = 0; pcc_devices[i].pcc_name != NULL; ++i) {
    195   1.3     chuck 		/*
    196   1.3     chuck 		 * Note that IPL is filled in by match function.
    197   1.3     chuck 		 */
    198   1.3     chuck 		npa.pa_name = pcc_devices[i].pcc_name;
    199   1.3     chuck 		npa.pa_offset = pcc_devices[i].pcc_offset;
    200   1.3     chuck 		npa.pa_ipl = -1;
    201   1.3     chuck 
    202   1.3     chuck 		/* Check for hardware. (XXX is this really necessary?) */
    203   1.3     chuck 		kva = PCC_VADDR(npa.pa_offset);
    204   1.6   thorpej 		if (badaddr(kva, pcc_devices[i].pcc_bytes)) {
    205   1.3     chuck 			/*
    206   1.3     chuck 			 * Hardware not present.
    207   1.3     chuck 			 */
    208   1.3     chuck 			continue;
    209   1.3     chuck 		}
    210   1.3     chuck 
    211   1.3     chuck 		/* Attach the device if configured. */
    212   1.3     chuck 		(void)config_found(self, &npa, pccprint);
    213   1.3     chuck 	}
    214   1.1     chuck }
    215   1.1     chuck 
    216   1.1     chuck int
    217   1.3     chuck pccprint(aux, cp)
    218   1.3     chuck 	void *aux;
    219   1.5       cgd 	const char *cp;
    220   1.1     chuck {
    221   1.3     chuck 	struct pcc_attach_args *pa = aux;
    222   1.3     chuck 
    223   1.3     chuck 	if (cp)
    224   1.8  christos 		printf("%s at %s", pa->pa_name, cp);
    225   1.3     chuck 
    226   1.8  christos 	printf(" offset 0x%lx", pa->pa_offset);
    227   1.3     chuck 	if (pa->pa_ipl != -1)
    228   1.8  christos 		printf(" ipl %d", pa->pa_ipl);
    229   1.1     chuck 
    230   1.3     chuck 	return (UNCONF);
    231   1.1     chuck }
    232   1.1     chuck 
    233   1.1     chuck /*
    234   1.1     chuck  * pccintr_establish: establish pcc interrupt
    235   1.1     chuck  */
    236   1.3     chuck void
    237   1.3     chuck pccintr_establish(pccvec, hand, lvl, arg)
    238   1.3     chuck 	int pccvec;
    239   1.3     chuck 	int (*hand) __P((void *)), lvl;
    240   1.1     chuck 	void *arg;
    241   1.1     chuck {
    242   1.3     chuck 
    243   1.3     chuck 	if ((pccvec < 0) || (pccvec >= PCC_NVEC)) {
    244   1.8  christos 		printf("pcc: illegal vector offset: 0x%x\n", pccvec);
    245   1.1     chuck 		panic("pccintr_establish");
    246   1.1     chuck 	}
    247   1.1     chuck 
    248   1.3     chuck 	if ((lvl < 1) || (lvl > 7)) {
    249   1.8  christos 		printf("pcc: illegal interrupt level: %d\n", lvl);
    250   1.1     chuck 		panic("pccintr_establish");
    251   1.1     chuck 	}
    252   1.1     chuck 
    253   1.3     chuck 	isrlink_vectored(hand, arg, lvl, pccvec + PCC_VECBASE);
    254   1.3     chuck }
    255   1.3     chuck 
    256   1.3     chuck void
    257   1.3     chuck pccintr_disestablish(pccvec)
    258   1.3     chuck 	int pccvec;
    259   1.3     chuck {
    260   1.3     chuck 
    261   1.3     chuck 	if ((pccvec < 0) || (pccvec >= PCC_NVEC)) {
    262   1.8  christos 		printf("pcc: illegal vector offset: 0x%x\n", pccvec);
    263   1.3     chuck 		panic("pccintr_establish");
    264   1.3     chuck 	}
    265   1.3     chuck 
    266   1.3     chuck 	isrunlink_vectored(pccvec + PCC_VECBASE);
    267   1.3     chuck }
    268   1.3     chuck 
    269   1.3     chuck /*
    270   1.3     chuck  * Handle NMI from abort switch.
    271   1.3     chuck  */
    272   1.3     chuck int
    273   1.3     chuck pccintr(frame)
    274   1.3     chuck 	void *frame;
    275   1.3     chuck {
    276   1.3     chuck 
    277   1.3     chuck 	/* XXX wait until button pops out */
    278   1.3     chuck 	sys_pcc->abrt_int = PCC_ABORT_IEN | PCC_ABORT_ACK;
    279   1.3     chuck 	nmihand((struct frame *)frame);
    280   1.3     chuck 	return (1);
    281   1.1     chuck }
    282