Home | History | Annotate | Line # | Download | only in dev
frodo.c revision 1.10
      1  1.10  gmcgarry /*	$NetBSD: frodo.c,v 1.10 2002/03/17 05:44:48 gmcgarry Exp $	*/
      2   1.2   thorpej 
      3   1.2   thorpej /*-
      4   1.5   thorpej  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
      5   1.2   thorpej  * All rights reserved.
      6   1.2   thorpej  *
      7   1.2   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.2   thorpej  * by Jason R. Thorpe.
      9   1.2   thorpej  *
     10   1.2   thorpej  * Redistribution and use in source and binary forms, with or without
     11   1.2   thorpej  * modification, are permitted provided that the following conditions
     12   1.2   thorpej  * are met:
     13   1.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     14   1.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     15   1.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17   1.2   thorpej  *    documentation and/or other materials provided with the distribution.
     18   1.2   thorpej  * 3. All advertising materials mentioning features or use of this software
     19   1.2   thorpej  *    must display the following acknowledgement:
     20   1.2   thorpej  *	This product includes software developed by the NetBSD
     21   1.2   thorpej  *	Foundation, Inc. and its contributors.
     22   1.2   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.2   thorpej  *    contributors may be used to endorse or promote products derived
     24   1.2   thorpej  *    from this software without specific prior written permission.
     25   1.2   thorpej  *
     26   1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.2   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.2   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.2   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.2   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.2   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.2   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.2   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.2   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.2   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.2   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37   1.2   thorpej  */
     38   1.1   thorpej 
     39   1.1   thorpej /*
     40   1.1   thorpej  * Copyright (c) 1997 Michael Smith.  All rights reserved.
     41   1.1   thorpej  *
     42   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     43   1.1   thorpej  * modification, are permitted provided that the following conditions
     44   1.1   thorpej  * are met:
     45   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     46   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     47   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     48   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     49   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     50   1.1   thorpej  *
     51   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     52   1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     53   1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     54   1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     55   1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     56   1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     57   1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     58   1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     59   1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     60   1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     61   1.1   thorpej  * SUCH DAMAGE.
     62   1.1   thorpej  */
     63   1.1   thorpej 
     64   1.1   thorpej /*
     65   1.1   thorpej  * Support for the "Frodo" (a.k.a. "Apollo Utility") chip found
     66   1.1   thorpej  * in HP Apollo 9000/4xx workstations.
     67   1.1   thorpej  */
     68   1.9  gmcgarry 
     69   1.9  gmcgarry #include <sys/cdefs.h>
     70  1.10  gmcgarry __KERNEL_RCSID(0, "$NetBSD: frodo.c,v 1.10 2002/03/17 05:44:48 gmcgarry Exp $");
     71   1.1   thorpej 
     72   1.1   thorpej #define	_HP300_INTR_H_PRIVATE
     73   1.1   thorpej 
     74   1.1   thorpej #include <sys/param.h>
     75   1.1   thorpej #include <sys/systm.h>
     76   1.1   thorpej #include <sys/kernel.h>
     77   1.1   thorpej #include <sys/syslog.h>
     78   1.1   thorpej #include <sys/device.h>
     79   1.1   thorpej 
     80   1.1   thorpej #include <machine/cpu.h>
     81   1.1   thorpej #include <machine/intr.h>
     82   1.1   thorpej #include <machine/hp300spu.h>
     83   1.1   thorpej 
     84   1.1   thorpej #include <hp300/dev/intiovar.h>
     85   1.1   thorpej 
     86   1.1   thorpej #include <hp300/dev/frodoreg.h>
     87   1.1   thorpej #include <hp300/dev/frodovar.h>
     88   1.1   thorpej 
     89   1.1   thorpej /*
     90   1.1   thorpej  * Description of a Frodo interrupt handler.
     91   1.1   thorpej  */
     92   1.8  gmcgarry struct frodo_interhand {
     93   1.8  gmcgarry 	int	(*ih_fn) __P((void *));
     94   1.8  gmcgarry 	void	*ih_arg;
     95   1.8  gmcgarry 	int	ih_priority;
     96   1.1   thorpej };
     97   1.1   thorpej 
     98   1.1   thorpej struct frodo_softc {
     99   1.1   thorpej 	struct device	sc_dev;		/* generic device glue */
    100   1.1   thorpej 	volatile u_int8_t *sc_regs;	/* register base */
    101   1.8  gmcgarry 	struct frodo_interhand sc_intr[FRODO_NINTR]; /* interrupt handlers */
    102   1.6  gmcgarry 	int		sc_ipl;
    103   1.1   thorpej 	void		*sc_ih;		/* out interrupt cookie */
    104   1.1   thorpej 	int		sc_refcnt;	/* number of interrupt refs */
    105   1.1   thorpej };
    106   1.1   thorpej 
    107   1.1   thorpej int	frodomatch __P((struct device *, struct cfdata *, void *));
    108   1.1   thorpej void	frodoattach __P((struct device *, struct device *, void *));
    109   1.1   thorpej 
    110   1.1   thorpej int	frodoprint __P((void *, const char *));
    111   1.1   thorpej int	frodosubmatch __P((struct device *, struct cfdata *, void *));
    112   1.1   thorpej 
    113   1.1   thorpej int	frodointr __P((void *));
    114   1.1   thorpej 
    115   1.1   thorpej void	frodo_imask __P((struct frodo_softc *, u_int16_t, u_int16_t));
    116   1.1   thorpej 
    117   1.1   thorpej struct cfattach frodo_ca = {
    118   1.1   thorpej 	sizeof(struct frodo_softc), frodomatch, frodoattach
    119   1.1   thorpej };
    120   1.1   thorpej 
    121   1.1   thorpej struct frodo_attach_args frodo_subdevs[] = {
    122   1.1   thorpej 	{ "dnkbd",	FRODO_APCI_OFFSET(0),	FRODO_INTR_APCI0 },
    123   1.1   thorpej 	{ "apci",	FRODO_APCI_OFFSET(1),	FRODO_INTR_APCI1 },
    124   1.1   thorpej 	{ "apci",	FRODO_APCI_OFFSET(2),	FRODO_INTR_APCI2 },
    125   1.1   thorpej 	{ "apci",	FRODO_APCI_OFFSET(3),	FRODO_INTR_APCI3 },
    126   1.1   thorpej 	{ NULL,		0,			0 },
    127   1.1   thorpej };
    128   1.1   thorpej 
    129   1.1   thorpej int
    130   1.1   thorpej frodomatch(parent, match, aux)
    131   1.1   thorpej 	struct device *parent;
    132   1.1   thorpej 	struct cfdata *match;
    133   1.1   thorpej 	void *aux;
    134   1.1   thorpej {
    135   1.1   thorpej 	struct intio_attach_args *ia = aux;
    136   1.1   thorpej 	static int frodo_matched = 0;
    137   1.1   thorpej 
    138   1.1   thorpej 	/* only allow one instance */
    139   1.1   thorpej 	if (frodo_matched)
    140   1.1   thorpej 		return (0);
    141   1.1   thorpej 
    142  1.10  gmcgarry 	if (strcmp(ia->ia_modname, "frodo") != 0)
    143   1.1   thorpej 		return (0);
    144   1.1   thorpej 
    145   1.6  gmcgarry 	if (badaddr((caddr_t)ia->ia_addr))
    146   1.1   thorpej 		return (0);
    147   1.1   thorpej 
    148   1.1   thorpej 	frodo_matched = 1;
    149   1.1   thorpej 	return (1);
    150   1.1   thorpej }
    151   1.1   thorpej 
    152   1.1   thorpej void
    153   1.1   thorpej frodoattach(parent, self, aux)
    154   1.1   thorpej 	struct device *parent, *self;
    155   1.1   thorpej 	void *aux;
    156   1.1   thorpej {
    157   1.1   thorpej 	struct frodo_softc *sc = (struct frodo_softc *)self;
    158   1.1   thorpej 	struct intio_attach_args *ia = aux;
    159   1.1   thorpej 	int i;
    160   1.1   thorpej 
    161   1.6  gmcgarry 	sc->sc_regs = (volatile u_int8_t *)ia->ia_addr;
    162   1.6  gmcgarry 	sc->sc_ipl = ia->ia_ipl;
    163   1.1   thorpej 
    164   1.1   thorpej 	if ((FRODO_READ(sc, FRODO_IISR) & FRODO_IISR_SERVICE) == 0)
    165   1.1   thorpej 		printf(": service mode enabled");
    166   1.1   thorpej 	printf("\n");
    167   1.1   thorpej 
    168   1.1   thorpej 	/* Clear all of the interrupt handlers. */
    169   1.7  gmcgarry 	memset(sc->sc_intr, 0, sizeof(sc->sc_intr));
    170   1.1   thorpej 	sc->sc_refcnt = 0;
    171   1.1   thorpej 
    172   1.1   thorpej 	/*
    173   1.1   thorpej 	 * Disable all of the interrupt lines; we reenable them
    174   1.1   thorpej 	 * as subdevices attach.
    175   1.1   thorpej 	 */
    176   1.1   thorpej 	frodo_imask(sc, 0, 0xffff);
    177   1.1   thorpej 
    178   1.1   thorpej 	/* Clear any pending interrupts. */
    179   1.1   thorpej 	FRODO_WRITE(sc, FRODO_PIC_PU, 0xff);
    180   1.1   thorpej 	FRODO_WRITE(sc, FRODO_PIC_PL, 0xff);
    181   1.1   thorpej 
    182   1.1   thorpej 	/* Set interrupt polarities. */
    183   1.1   thorpej 	FRODO_WRITE(sc, FRODO_PIO_IPR, 0x10);
    184   1.1   thorpej 
    185   1.1   thorpej 	/* ...and configure for edge triggering. */
    186   1.1   thorpej 	FRODO_WRITE(sc, FRODO_PIO_IELR, 0xcf);
    187   1.1   thorpej 
    188   1.1   thorpej 	/*
    189   1.1   thorpej 	 * We defer hooking up our interrupt handler until
    190   1.1   thorpej 	 * a subdevice hooks up theirs.
    191   1.1   thorpej 	 */
    192   1.1   thorpej 	sc->sc_ih = NULL;
    193   1.1   thorpej 
    194   1.1   thorpej 	/* ... and attach subdevices. */
    195   1.5   thorpej 	for (i = 0; frodo_subdevs[i].fa_name != NULL; i++) {
    196   1.5   thorpej 		/*
    197   1.5   thorpej 		 * Skip the first serial port if we're not a 425e;
    198   1.5   thorpej 		 * it's mapped to the DCA at select code 9 on all
    199   1.5   thorpej 		 * other models.
    200   1.5   thorpej 		 */
    201   1.5   thorpej 		if (frodo_subdevs[i].fa_offset == FRODO_APCI_OFFSET(1) &&
    202   1.5   thorpej 		    mmuid != MMUID_425_E)
    203   1.5   thorpej 			continue;
    204   1.1   thorpej 		config_found_sm(self, &frodo_subdevs[i],
    205   1.1   thorpej 		    frodoprint, frodosubmatch);
    206   1.5   thorpej 	}
    207   1.1   thorpej }
    208   1.1   thorpej 
    209   1.1   thorpej int
    210   1.1   thorpej frodosubmatch(parent, cf, aux)
    211   1.1   thorpej 	struct device *parent;
    212   1.1   thorpej 	struct cfdata *cf;
    213   1.1   thorpej 	void *aux;
    214   1.1   thorpej {
    215   1.1   thorpej 	struct frodo_attach_args *fa = aux;
    216   1.1   thorpej 
    217   1.1   thorpej 	if (cf->frodocf_offset != FRODO_UNKNOWN_OFFSET &&
    218   1.1   thorpej 	    cf->frodocf_offset != fa->fa_offset)
    219   1.1   thorpej 		return (0);
    220   1.1   thorpej 
    221   1.1   thorpej 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    222   1.1   thorpej }
    223   1.1   thorpej 
    224   1.1   thorpej int
    225   1.1   thorpej frodoprint(aux, pnp)
    226   1.1   thorpej 	void *aux;
    227   1.1   thorpej 	const char *pnp;
    228   1.1   thorpej {
    229   1.1   thorpej 	struct frodo_attach_args *fa = aux;
    230   1.1   thorpej 
    231   1.1   thorpej 	if (pnp)
    232   1.1   thorpej 		printf("%s at %s", fa->fa_name, pnp);
    233   1.1   thorpej 	printf(" offset 0x%x", fa->fa_offset);
    234   1.1   thorpej 	return (UNCONF);
    235   1.1   thorpej }
    236   1.1   thorpej 
    237   1.1   thorpej void
    238   1.1   thorpej frodo_intr_establish(frdev, func, arg, line, priority)
    239   1.1   thorpej 	struct device *frdev;
    240   1.1   thorpej 	int (*func) __P((void *));
    241   1.1   thorpej 	void *arg;
    242   1.1   thorpej 	int line;
    243   1.1   thorpej 	int priority;
    244   1.1   thorpej {
    245   1.1   thorpej 	struct frodo_softc *sc = (struct frodo_softc *)frdev;
    246   1.8  gmcgarry 	struct hp300_intrhand *ih = sc->sc_ih;
    247   1.1   thorpej 
    248   1.1   thorpej 	if (line < 0 || line >= FRODO_NINTR) {
    249   1.1   thorpej 		printf("%s: bad interrupt line %d\n",
    250   1.1   thorpej 		    sc->sc_dev.dv_xname, line);
    251   1.1   thorpej 		goto lose;
    252   1.1   thorpej 	}
    253   1.8  gmcgarry 	if (sc->sc_intr[line].ih_fn != NULL) {
    254   1.1   thorpej 		printf("%s: interrupt line %d already used\n",
    255   1.1   thorpej 		    sc->sc_dev.dv_xname, line);
    256   1.1   thorpej 		goto lose;
    257   1.1   thorpej 	}
    258   1.1   thorpej 
    259   1.1   thorpej 	/* Install the handler. */
    260   1.8  gmcgarry 	sc->sc_intr[line].ih_fn = func;
    261   1.8  gmcgarry 	sc->sc_intr[line].ih_arg = arg;
    262   1.8  gmcgarry 	sc->sc_intr[line].ih_priority = priority;
    263   1.1   thorpej 
    264   1.1   thorpej 	/*
    265   1.1   thorpej 	 * If this is the first one, establish the frodo
    266   1.1   thorpej 	 * interrupt handler.  If not, reestablish at a
    267   1.1   thorpej 	 * higher priority if necessary.
    268   1.1   thorpej 	 */
    269   1.8  gmcgarry 	if (ih == NULL || ih->ih_priority < priority) {
    270   1.8  gmcgarry 		if (ih != NULL)
    271   1.8  gmcgarry 			intr_disestablish(ih);
    272   1.6  gmcgarry 		sc->sc_ih = intr_establish(frodointr, sc, sc->sc_ipl, priority);
    273   1.1   thorpej 	}
    274   1.1   thorpej 
    275   1.1   thorpej 	sc->sc_refcnt++;
    276   1.1   thorpej 
    277   1.1   thorpej 	/* Enable the interrupt line. */
    278   1.1   thorpej 	frodo_imask(sc, (1 << line), 0);
    279   1.1   thorpej 	return;
    280   1.1   thorpej  lose:
    281   1.1   thorpej 	panic("frodo_intr_establish");
    282   1.1   thorpej }
    283   1.1   thorpej 
    284   1.1   thorpej void
    285   1.1   thorpej frodo_intr_disestablish(frdev, line)
    286   1.1   thorpej 	struct device *frdev;
    287   1.1   thorpej 	int line;
    288   1.1   thorpej {
    289   1.1   thorpej 	struct frodo_softc *sc = (struct frodo_softc *)frdev;
    290   1.8  gmcgarry 	struct hp300_intrhand *ih = sc->sc_ih;
    291   1.1   thorpej 	int newpri;
    292   1.1   thorpej 
    293   1.8  gmcgarry 	if (sc->sc_intr[line].ih_fn == NULL) {
    294   1.1   thorpej 		printf("%s: no handler for line %d\n",
    295   1.1   thorpej 		    sc->sc_dev.dv_xname, line);
    296   1.1   thorpej 		panic("frodo_intr_disestablish");
    297   1.1   thorpej 	}
    298   1.1   thorpej 
    299   1.8  gmcgarry 	sc->sc_intr[line].ih_fn = NULL;
    300   1.1   thorpej 	frodo_imask(sc, 0, (1 << line));
    301   1.1   thorpej 
    302   1.1   thorpej 	/* If this was the last, unhook ourselves. */
    303   1.1   thorpej 	if (sc->sc_refcnt-- == 1) {
    304   1.8  gmcgarry 		intr_disestablish(ih);
    305   1.1   thorpej 		return;
    306   1.1   thorpej 	}
    307   1.1   thorpej 
    308   1.1   thorpej 	/* Lower our priority, if appropriate. */
    309   1.1   thorpej 	for (newpri = 0, line = 0; line < FRODO_NINTR; line++)
    310   1.8  gmcgarry 		if (sc->sc_intr[line].ih_fn != NULL &&
    311   1.8  gmcgarry 		    sc->sc_intr[line].ih_priority > newpri)
    312   1.8  gmcgarry 			newpri = sc->sc_intr[line].ih_priority;
    313   1.1   thorpej 
    314   1.8  gmcgarry 	if (newpri != ih->ih_priority) {
    315   1.8  gmcgarry 		intr_disestablish(ih);
    316   1.6  gmcgarry 		sc->sc_ih = intr_establish(frodointr, sc, sc->sc_ipl, newpri);
    317   1.1   thorpej 	}
    318   1.1   thorpej }
    319   1.1   thorpej 
    320   1.1   thorpej int
    321   1.1   thorpej frodointr(arg)
    322   1.1   thorpej 	void *arg;
    323   1.1   thorpej {
    324   1.1   thorpej 	struct frodo_softc *sc = arg;
    325   1.8  gmcgarry 	struct frodo_interhand *fih;
    326   1.1   thorpej 	int line, taken = 0;
    327   1.1   thorpej 
    328   1.1   thorpej 	/* Any interrupts pending? */
    329   1.1   thorpej 	if (FRODO_GETPEND(sc) == 0)
    330   1.1   thorpej 		return (0);
    331   1.1   thorpej 
    332   1.1   thorpej 	do {
    333   1.1   thorpej 		/*
    334   1.1   thorpej 		 * Get pending interrupt; this also clears it for us.
    335   1.1   thorpej 		 */
    336   1.1   thorpej 		line = FRODO_IPEND(sc);
    337   1.8  gmcgarry 		fih = &sc->sc_intr[line];
    338   1.8  gmcgarry 		if (fih->ih_fn == NULL ||
    339   1.8  gmcgarry 		    (*fih->ih_fn)(fih->ih_arg) == 0)
    340   1.1   thorpej 			printf("%s: spurious interrupt on line %d\n",
    341   1.1   thorpej 			    sc->sc_dev.dv_xname, line);
    342   1.1   thorpej 		if (taken++ > 100)
    343   1.1   thorpej 			panic("frodointr: looping!");
    344   1.1   thorpej 	} while (FRODO_GETPEND(sc) != 0);
    345   1.1   thorpej 
    346   1.1   thorpej 	return (1);
    347   1.1   thorpej }
    348   1.1   thorpej 
    349   1.1   thorpej void
    350   1.1   thorpej frodo_imask(sc, set, clear)
    351   1.1   thorpej 	struct frodo_softc *sc;
    352   1.1   thorpej 	u_int16_t set, clear;
    353   1.1   thorpej {
    354   1.1   thorpej 	u_int16_t imask;
    355   1.1   thorpej 
    356   1.1   thorpej 	imask = FRODO_GETMASK(sc);
    357   1.1   thorpej 
    358   1.1   thorpej 	imask |= set;
    359   1.1   thorpej 	imask &= ~clear;
    360   1.1   thorpej 
    361   1.1   thorpej 	FRODO_SETMASK(sc, imask);
    362   1.1   thorpej }
    363