Home | History | Annotate | Line # | Download | only in dev
pcc.c revision 1.2
      1  1.2  thorpej /* $Id: pcc.c,v 1.2 1996/03/17 01:35:03 thorpej Exp $ */
      2  1.1    chuck 
      3  1.1    chuck /*
      4  1.1    chuck  *
      5  1.1    chuck  * Copyright (c) 1995 Charles D. Cranor
      6  1.1    chuck  * All rights reserved.
      7  1.1    chuck  *
      8  1.1    chuck  * Redistribution and use in source and binary forms, with or without
      9  1.1    chuck  * modification, are permitted provided that the following conditions
     10  1.1    chuck  * are met:
     11  1.1    chuck  * 1. Redistributions of source code must retain the above copyright
     12  1.1    chuck  *    notice, this list of conditions and the following disclaimer.
     13  1.1    chuck  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1    chuck  *    notice, this list of conditions and the following disclaimer in the
     15  1.1    chuck  *    documentation and/or other materials provided with the distribution.
     16  1.1    chuck  * 3. All advertising materials mentioning features or use of this software
     17  1.1    chuck  *    must display the following acknowledgement:
     18  1.1    chuck  *      This product includes software developed by Charles D. Cranor.
     19  1.1    chuck  * 4. The name of the author may not be used to endorse or promote products
     20  1.1    chuck  *    derived from this software without specific prior written permission.
     21  1.1    chuck  *
     22  1.1    chuck  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1    chuck  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1    chuck  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1    chuck  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1    chuck  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1    chuck  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1    chuck  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1    chuck  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1    chuck  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1    chuck  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1    chuck  */
     33  1.1    chuck 
     34  1.1    chuck /*
     35  1.1    chuck  * peripheral channel controller
     36  1.1    chuck  */
     37  1.1    chuck 
     38  1.1    chuck #include <sys/param.h>
     39  1.1    chuck #include <sys/conf.h>
     40  1.1    chuck #include <sys/ioctl.h>
     41  1.1    chuck #include <sys/proc.h>
     42  1.1    chuck #include <sys/user.h>
     43  1.1    chuck #include <sys/tty.h>
     44  1.1    chuck #include <sys/uio.h>
     45  1.1    chuck #include <sys/callout.h>
     46  1.1    chuck #include <sys/systm.h>
     47  1.1    chuck #include <sys/kernel.h>
     48  1.1    chuck #include <sys/syslog.h>
     49  1.1    chuck #include <sys/fcntl.h>
     50  1.1    chuck #include <sys/device.h>
     51  1.1    chuck #include <machine/cpu.h>
     52  1.1    chuck #include <dev/cons.h>
     53  1.1    chuck #include <mvme68k/mvme68k/isr.h>
     54  1.1    chuck #include <mvme68k/dev/iio.h>
     55  1.1    chuck #include <mvme68k/dev/pccreg.h>
     56  1.1    chuck 
     57  1.1    chuck /*
     58  1.1    chuck  * Autoconfiguration stuff.
     59  1.1    chuck  */
     60  1.1    chuck 
     61  1.1    chuck struct pccsoftc {
     62  1.1    chuck 	struct device	sc_dev;
     63  1.1    chuck 	struct pcc	*sc_pcc;
     64  1.1    chuck };
     65  1.1    chuck 
     66  1.1    chuck 
     67  1.1    chuck void pccattach __P((struct device *, struct device *, void *));
     68  1.1    chuck int  pccmatch __P((struct device *, void *, void *));
     69  1.1    chuck 
     70  1.2  thorpej struct cfattach pcc_ca = {
     71  1.2  thorpej 	sizeof(struct pccsoftc), pccmatch, pccattach
     72  1.2  thorpej };
     73  1.2  thorpej 
     74  1.2  thorpej struct cfdriver pcc_cd = {
     75  1.2  thorpej 	NULL, "pcc", DV_DULL, 0
     76  1.1    chuck };
     77  1.1    chuck 
     78  1.1    chuck /*
     79  1.1    chuck  * globals
     80  1.1    chuck  */
     81  1.1    chuck 
     82  1.1    chuck struct pcc *sys_pcc = NULL;
     83  1.1    chuck 
     84  1.1    chuck struct {
     85  1.1    chuck 	int	(*pcc_fn)();
     86  1.1    chuck 	void	*arg;
     87  1.1    chuck 	int	lvl;
     88  1.1    chuck } pcc_vecs[PCC_NVEC];
     89  1.1    chuck 
     90  1.1    chuck int
     91  1.1    chuck pccmatch(parent, vcf, args)
     92  1.1    chuck 	struct device *parent;
     93  1.1    chuck 	void *vcf, *args;
     94  1.1    chuck {
     95  1.1    chuck 	struct cfdata *cf = vcf;
     96  1.1    chuck 
     97  1.1    chuck 	return !badbaddr((caddr_t) IIO_CFLOC_ADDR(cf));
     98  1.1    chuck }
     99  1.1    chuck 
    100  1.1    chuck void
    101  1.1    chuck pccattach(parent, self, args)
    102  1.1    chuck 	struct device *parent, *self;
    103  1.1    chuck 	void *args;
    104  1.1    chuck {
    105  1.1    chuck 	struct pccsoftc *pccsc;
    106  1.1    chuck 
    107  1.1    chuck 	if (sys_pcc)
    108  1.1    chuck 		panic("pcc already attached!");
    109  1.1    chuck 
    110  1.1    chuck 	iio_print(self->dv_cfdata);
    111  1.1    chuck 
    112  1.1    chuck 	/*
    113  1.1    chuck 	 * link into softc and set up interrupt vector base
    114  1.1    chuck 	 */
    115  1.1    chuck 	pccsc = (struct pccsoftc *) self;
    116  1.1    chuck 	sys_pcc = pccsc->sc_pcc = (struct pcc *)IIO_CFLOC_ADDR(self->dv_cfdata);
    117  1.1    chuck 	pccsc->sc_pcc->int_vectr = PCC_VECBASE;
    118  1.1    chuck 	bzero(pcc_vecs, sizeof(pcc_vecs));
    119  1.1    chuck 
    120  1.1    chuck 	printf(" rev %d intbvr 0x%x\n", pccsc->sc_pcc->pcc_rev,
    121  1.1    chuck 	    pccsc->sc_pcc->int_vectr);
    122  1.1    chuck }
    123  1.1    chuck 
    124  1.1    chuck 
    125  1.1    chuck /*
    126  1.1    chuck  * pccintr: called from locore with the PC and evec from the trap frame.
    127  1.1    chuck  */
    128  1.1    chuck int
    129  1.1    chuck pccintr(pc, evec, frame)
    130  1.1    chuck 	int pc;
    131  1.1    chuck 	int evec;
    132  1.1    chuck 	void *frame;
    133  1.1    chuck {
    134  1.1    chuck 	int vec = (evec & 0xfff) >> 2; /* XXX should be m68k macro? */
    135  1.1    chuck 	extern u_long intrcnt[]; /* XXX from locore */
    136  1.1    chuck 
    137  1.1    chuck 	vec = vec & 0xf; /* XXX mask out */
    138  1.1    chuck 	if (vec >= PCC_NVEC || pcc_vecs[vec].pcc_fn == NULL)
    139  1.1    chuck 		return(straytrap(pc, evec));
    140  1.1    chuck 
    141  1.1    chuck 	cnt.v_intr++;
    142  1.1    chuck 	intrcnt[pcc_vecs[vec].lvl]++;
    143  1.1    chuck 
    144  1.1    chuck 	/* arg override?  only timer1 gets access to frame */
    145  1.1    chuck 	if (vec != PCCV_TIMER1)
    146  1.1    chuck 		frame = pcc_vecs[vec].arg;
    147  1.1    chuck 	return((*pcc_vecs[vec].pcc_fn)(frame));
    148  1.1    chuck }
    149  1.1    chuck 
    150  1.1    chuck 
    151  1.1    chuck /*
    152  1.1    chuck  * pccintr_establish: establish pcc interrupt
    153  1.1    chuck  */
    154  1.1    chuck int
    155  1.1    chuck pccintr_establish(vec, hand, lvl, arg)
    156  1.1    chuck 	u_long vec;
    157  1.1    chuck 	int (*hand)(), lvl;
    158  1.1    chuck 	void *arg;
    159  1.1    chuck {
    160  1.1    chuck 	if (vec >= PCC_NVEC) {
    161  1.1    chuck 		printf("pcc: illegal vector: 0x%x\n", vec);
    162  1.1    chuck 		panic("pccintr_establish");
    163  1.1    chuck 	}
    164  1.1    chuck 
    165  1.1    chuck 	if (pcc_vecs[vec].pcc_fn) {
    166  1.1    chuck 		printf("pcc: vector 0x%x in use: (0x%x,0x%x) (0x%x,0x%x)\n",
    167  1.1    chuck 		    hand, arg, pcc_vecs[vec].pcc_fn, pcc_vecs[vec].arg);
    168  1.1    chuck 		panic("pccintr_establish");
    169  1.1    chuck 	}
    170  1.1    chuck 
    171  1.1    chuck 	pcc_vecs[vec].pcc_fn = hand;
    172  1.1    chuck 	pcc_vecs[vec].lvl = lvl;
    173  1.1    chuck 	pcc_vecs[vec].arg = arg;
    174  1.1    chuck }
    175