Home | History | Annotate | Line # | Download | only in pci
pci_eb164.c revision 1.1
      1  1.1  cgd /*	$NetBSD: pci_eb164.c,v 1.1 1996/11/11 21:08:12 cgd Exp $	*/
      2  1.1  cgd 
      3  1.1  cgd /*
      4  1.1  cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  1.1  cgd  * All rights reserved.
      6  1.1  cgd  *
      7  1.1  cgd  * Author: Chris G. Demetriou
      8  1.1  cgd  *
      9  1.1  cgd  * Permission to use, copy, modify and distribute this software and
     10  1.1  cgd  * its documentation is hereby granted, provided that both the copyright
     11  1.1  cgd  * notice and this permission notice appear in all copies of the
     12  1.1  cgd  * software, derivative works or modified versions, and any portions
     13  1.1  cgd  * thereof, and that both notices appear in supporting documentation.
     14  1.1  cgd  *
     15  1.1  cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.1  cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  1.1  cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.1  cgd  *
     19  1.1  cgd  * Carnegie Mellon requests users of this software to return to
     20  1.1  cgd  *
     21  1.1  cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  1.1  cgd  *  School of Computer Science
     23  1.1  cgd  *  Carnegie Mellon University
     24  1.1  cgd  *  Pittsburgh PA 15213-3890
     25  1.1  cgd  *
     26  1.1  cgd  * any improvements or extensions that they make and grant Carnegie the
     27  1.1  cgd  * rights to redistribute these changes.
     28  1.1  cgd  */
     29  1.1  cgd 
     30  1.1  cgd #include <sys/types.h>
     31  1.1  cgd #include <sys/param.h>
     32  1.1  cgd #include <sys/time.h>
     33  1.1  cgd #include <sys/systm.h>
     34  1.1  cgd #include <sys/errno.h>
     35  1.1  cgd #include <sys/malloc.h>
     36  1.1  cgd #include <sys/device.h>
     37  1.1  cgd #include <sys/syslog.h>
     38  1.1  cgd 
     39  1.1  cgd #include <vm/vm.h>
     40  1.1  cgd 
     41  1.1  cgd #include <machine/autoconf.h>
     42  1.1  cgd 
     43  1.1  cgd #include <dev/pci/pcireg.h>
     44  1.1  cgd #include <dev/pci/pcivar.h>
     45  1.1  cgd 
     46  1.1  cgd #include <alpha/pci/ciareg.h>
     47  1.1  cgd #include <alpha/pci/ciavar.h>
     48  1.1  cgd 
     49  1.1  cgd #include <alpha/pci/pci_eb164.h>
     50  1.1  cgd 
     51  1.1  cgd #ifndef EVCNT_COUNTERS
     52  1.1  cgd #include <machine/intrcnt.h>
     53  1.1  cgd #endif
     54  1.1  cgd 
     55  1.1  cgd #include "sio.h"
     56  1.1  cgd #if NSIO
     57  1.1  cgd #include <alpha/pci/siovar.h>
     58  1.1  cgd #endif
     59  1.1  cgd 
     60  1.1  cgd int	dec_eb164_intr_map __P((void *, pcitag_t, int, int,
     61  1.1  cgd 	    pci_intr_handle_t *));
     62  1.1  cgd const char *dec_eb164_intr_string __P((void *, pci_intr_handle_t));
     63  1.1  cgd void	*dec_eb164_intr_establish __P((void *, pci_intr_handle_t,
     64  1.1  cgd 	    int, int (*func)(void *), void *));
     65  1.1  cgd void	dec_eb164_intr_disestablish __P((void *, void *));
     66  1.1  cgd 
     67  1.1  cgd #if 0 /* XXX */
     68  1.1  cgd #define	KN20AA_PCEB_IRQ	31
     69  1.1  cgd #define	KN20AA_MAX_IRQ	32
     70  1.1  cgd #define	PCI_STRAY_MAX	5
     71  1.1  cgd 
     72  1.1  cgd struct eb164_intrhand {
     73  1.1  cgd 	TAILQ_ENTRY(eb164_intrhand) ih_q;
     74  1.1  cgd         int     (*ih_fun)();
     75  1.1  cgd         void    *ih_arg;
     76  1.1  cgd         u_long  ih_count;
     77  1.1  cgd         int     ih_level;
     78  1.1  cgd };
     79  1.1  cgd TAILQ_HEAD(eb164_intrchain, eb164_intrhand);
     80  1.1  cgd 
     81  1.1  cgd struct eb164_intrchain eb164_pci_intrs[KN20AA_MAX_IRQ];
     82  1.1  cgd int	eb164_pci_strayintrcnt[KN20AA_MAX_IRQ];
     83  1.1  cgd #ifdef EVCNT_COUNTERS
     84  1.1  cgd struct evcnt eb164_intr_evcnt;
     85  1.1  cgd #endif
     86  1.1  cgd #endif /* 0 XXX */
     87  1.1  cgd 
     88  1.1  cgd void	eb164_pci_strayintr __P((int irq));
     89  1.1  cgd void	eb164_iointr __P((void *framep, unsigned long vec));
     90  1.1  cgd #if 0 /* XXX */
     91  1.1  cgd void	eb164_enable_intr __P((int irq));
     92  1.1  cgd void	eb164_disable_intr __P((int irq));
     93  1.1  cgd struct eb164_intrhand *eb164_attach_intr __P((struct eb164_intrchain *,
     94  1.1  cgd 			    int, int (*) (void *), void *));
     95  1.1  cgd #endif /* 0 XXX */
     96  1.1  cgd 
     97  1.1  cgd void
     98  1.1  cgd pci_eb164_pickintr(ccp)
     99  1.1  cgd 	struct cia_config *ccp;
    100  1.1  cgd {
    101  1.1  cgd 	int i;
    102  1.1  cgd #if 0 /* XXX */
    103  1.1  cgd 	struct eb164_intrhand *nintrhand;
    104  1.1  cgd #endif /* 0 XXX */
    105  1.1  cgd 	bus_space_tag_t iot = ccp->cc_iot;
    106  1.1  cgd 	pci_chipset_tag_t pc = &ccp->cc_pc;
    107  1.1  cgd 
    108  1.1  cgd #if 0 /* XXX */
    109  1.1  cgd 	for (i = 0; i < KN20AA_MAX_IRQ; i++)
    110  1.1  cgd 		TAILQ_INIT(&eb164_pci_intrs[i]);
    111  1.1  cgd #endif /* 0 XXX */
    112  1.1  cgd 
    113  1.1  cgd         pc->pc_intr_v = ccp;
    114  1.1  cgd         pc->pc_intr_map = dec_eb164_intr_map;
    115  1.1  cgd         pc->pc_intr_string = dec_eb164_intr_string;
    116  1.1  cgd         pc->pc_intr_establish = dec_eb164_intr_establish;
    117  1.1  cgd         pc->pc_intr_disestablish = dec_eb164_intr_disestablish;
    118  1.1  cgd 
    119  1.1  cgd #if NSIO
    120  1.1  cgd 	sio_intr_setup(iot);
    121  1.1  cgd #endif
    122  1.1  cgd 
    123  1.1  cgd 	set_iointr(eb164_iointr);
    124  1.1  cgd 
    125  1.1  cgd #if 0 /* XXX */
    126  1.1  cgd #if NSIO
    127  1.1  cgd 	eb164_enable_intr(KN20AA_PCEB_IRQ);
    128  1.1  cgd #if 0 /* XXX init PCEB interrupt handler? */
    129  1.1  cgd 	eb164_attach_intr(&eb164_pci_intrs[KN20AA_PCEB_IRQ], ???, ???, ???);
    130  1.1  cgd #endif
    131  1.1  cgd #endif
    132  1.1  cgd #endif /* 0 XXX */
    133  1.1  cgd }
    134  1.1  cgd 
    135  1.1  cgd int
    136  1.1  cgd dec_eb164_intr_map(ccv, bustag, buspin, line, ihp)
    137  1.1  cgd         void *ccv;
    138  1.1  cgd         pcitag_t bustag;
    139  1.1  cgd         int buspin, line;
    140  1.1  cgd         pci_intr_handle_t *ihp;
    141  1.1  cgd {
    142  1.1  cgd 
    143  1.1  cgd 	printf("dec_eb164_intr_map(0x%lx, %d, %d)\n", bustag, buspin, line);
    144  1.1  cgd 	return 0;
    145  1.1  cgd 
    146  1.1  cgd #if 0
    147  1.1  cgd 	struct cia_config *ccp = ccv;
    148  1.1  cgd 	pci_chipset_tag_t pc = &ccp->cc_pc;
    149  1.1  cgd 	int device;
    150  1.1  cgd 	int eb164_irq;
    151  1.1  cgd 	void *ih;
    152  1.1  cgd 
    153  1.1  cgd         if (buspin == 0) {
    154  1.1  cgd                 /* No IRQ used. */
    155  1.1  cgd                 return 1;
    156  1.1  cgd         }
    157  1.1  cgd         if (buspin > 4) {
    158  1.1  cgd                 printf("pci_map_int: bad interrupt pin %d\n", buspin);
    159  1.1  cgd                 return 1;
    160  1.1  cgd         }
    161  1.1  cgd 
    162  1.1  cgd 	/*
    163  1.1  cgd 	 * Slot->interrupt translation.  Appears to work, though it
    164  1.1  cgd 	 * may not hold up forever.
    165  1.1  cgd 	 *
    166  1.1  cgd 	 * The DEC engineers who did this hardware obviously engaged
    167  1.1  cgd 	 * in random drug testing.
    168  1.1  cgd 	 */
    169  1.1  cgd 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    170  1.1  cgd 	switch (device) {
    171  1.1  cgd 	case 11:
    172  1.1  cgd 	case 12:
    173  1.1  cgd 		eb164_irq = ((device - 11) + 0) * 4;
    174  1.1  cgd 		break;
    175  1.1  cgd 
    176  1.1  cgd 	case 7:
    177  1.1  cgd 		eb164_irq = 8;
    178  1.1  cgd 		break;
    179  1.1  cgd 
    180  1.1  cgd 	case 9:
    181  1.1  cgd 		eb164_irq = 12;
    182  1.1  cgd 		break;
    183  1.1  cgd 
    184  1.1  cgd 	case 6:					/* 21040 on AlphaStation 500 */
    185  1.1  cgd 		eb164_irq = 13;
    186  1.1  cgd 		break;
    187  1.1  cgd 
    188  1.1  cgd 	case 8:
    189  1.1  cgd 		eb164_irq = 16;
    190  1.1  cgd 		break;
    191  1.1  cgd 
    192  1.1  cgd 	default:
    193  1.1  cgd #ifdef KN20AA_BOGUS_IRQ_FROB
    194  1.1  cgd 		*ihp = 0xdeadbeef;
    195  1.1  cgd 		printf("\n\n BOGUS INTERRUPT MAPPING: dev %d, pin %d\n",
    196  1.1  cgd 		    device, buspin);
    197  1.1  cgd 		return (0);
    198  1.1  cgd #endif
    199  1.1  cgd 		panic("pci_eb164_map_int: invalid device number %d\n",
    200  1.1  cgd 		    device);
    201  1.1  cgd 	}
    202  1.1  cgd 
    203  1.1  cgd 	eb164_irq += buspin - 1;
    204  1.1  cgd 	if (eb164_irq > KN20AA_MAX_IRQ)
    205  1.1  cgd 		panic("pci_eb164_map_int: eb164_irq too large (%d)\n",
    206  1.1  cgd 		    eb164_irq);
    207  1.1  cgd 
    208  1.1  cgd 	*ihp = eb164_irq;
    209  1.1  cgd 	return (0);
    210  1.1  cgd #endif
    211  1.1  cgd }
    212  1.1  cgd 
    213  1.1  cgd const char *
    214  1.1  cgd dec_eb164_intr_string(ccv, ih)
    215  1.1  cgd 	void *ccv;
    216  1.1  cgd 	pci_intr_handle_t ih;
    217  1.1  cgd {
    218  1.1  cgd 	struct cia_config *ccp = ccv;
    219  1.1  cgd         static char irqstr[15];          /* 11 + 2 + NULL + sanity */
    220  1.1  cgd 
    221  1.1  cgd 	sprintf(irqstr, "BOGUS");
    222  1.1  cgd 	return (irqstr);
    223  1.1  cgd 
    224  1.1  cgd #if 0 /* XXX */
    225  1.1  cgd #ifdef KN20AA_BOGUS_IRQ_FROB
    226  1.1  cgd 	if (ih == 0xdeadbeef) {
    227  1.1  cgd 		sprintf(irqstr, "BOGUS");
    228  1.1  cgd 		return (irqstr);
    229  1.1  cgd 	}
    230  1.1  cgd #endif
    231  1.1  cgd         if (ih > KN20AA_MAX_IRQ)
    232  1.1  cgd                 panic("dec_eb164_a50_intr_string: bogus eb164 IRQ 0x%x\n",
    233  1.1  cgd 		    ih);
    234  1.1  cgd 
    235  1.1  cgd         sprintf(irqstr, "eb164 irq %d", ih);
    236  1.1  cgd         return (irqstr);
    237  1.1  cgd #endif /* 0 XXX */
    238  1.1  cgd }
    239  1.1  cgd 
    240  1.1  cgd void *
    241  1.1  cgd dec_eb164_intr_establish(ccv, ih, level, func, arg)
    242  1.1  cgd         void *ccv, *arg;
    243  1.1  cgd         pci_intr_handle_t ih;
    244  1.1  cgd         int level;
    245  1.1  cgd         int (*func) __P((void *));
    246  1.1  cgd {
    247  1.1  cgd 
    248  1.1  cgd 	printf("dec_eb164_intr_establish(0x%lx, %d, %p, %p)\n", ih, level, func, arg);
    249  1.1  cgd 	return ((void *)0xbabefacedeadbeef);
    250  1.1  cgd 
    251  1.1  cgd #if 0 /* XXX */
    252  1.1  cgd         struct cia_config *ccp = ccv;
    253  1.1  cgd 	void *cookie;
    254  1.1  cgd 
    255  1.1  cgd #ifdef KN20AA_BOGUS_IRQ_FROB
    256  1.1  cgd 	if (ih == 0xdeadbeef) {
    257  1.1  cgd 		int i;
    258  1.1  cgd 		char chars[10];
    259  1.1  cgd 
    260  1.1  cgd 		printf("dec_eb164_intr_establish: BOGUS IRQ\n");
    261  1.1  cgd 		do {
    262  1.1  cgd 			printf("IRQ to enable? ");
    263  1.1  cgd 			getstr(chars, 10);
    264  1.1  cgd 			i = atoi(chars);
    265  1.1  cgd 		} while (i < 0 || i > 32);
    266  1.1  cgd 		printf("ENABLING IRQ %d\n", i);
    267  1.1  cgd 		eb164_enable_intr(i);
    268  1.1  cgd 		return ((void *)0xbabefacedeadbeef);
    269  1.1  cgd 	}
    270  1.1  cgd #endif
    271  1.1  cgd         if (ih > KN20AA_MAX_IRQ)
    272  1.1  cgd                 panic("dec_eb164_intr_establish: bogus eb164 IRQ 0x%x\n",
    273  1.1  cgd 		    ih);
    274  1.1  cgd 
    275  1.1  cgd 	cookie = eb164_attach_intr(&eb164_pci_intrs[ih], level, func, arg);
    276  1.1  cgd 	eb164_enable_intr(ih);
    277  1.1  cgd 	return (cookie);
    278  1.1  cgd #endif /* XXX */
    279  1.1  cgd }
    280  1.1  cgd 
    281  1.1  cgd void
    282  1.1  cgd dec_eb164_intr_disestablish(ccv, cookie)
    283  1.1  cgd         void *ccv, *cookie;
    284  1.1  cgd {
    285  1.1  cgd 	struct cia_config *ccp = ccv;
    286  1.1  cgd 
    287  1.1  cgd 	panic("dec_eb164_intr_disestablish not implemented"); /* XXX */
    288  1.1  cgd }
    289  1.1  cgd 
    290  1.1  cgd /*
    291  1.1  cgd  * caught a stray interrupt; notify if not too many seen already.
    292  1.1  cgd  */
    293  1.1  cgd void
    294  1.1  cgd eb164_pci_strayintr(irq)
    295  1.1  cgd 	int irq;
    296  1.1  cgd {
    297  1.1  cgd 
    298  1.1  cgd 	log(LOG_ERR, "stray eb164 irq %d\n", irq);
    299  1.1  cgd 
    300  1.1  cgd #if 0 /* XXX */
    301  1.1  cgd 	eb164_pci_strayintrcnt[irq]++;
    302  1.1  cgd 	if (eb164_pci_strayintrcnt[irq] == PCI_STRAY_MAX)
    303  1.1  cgd 		eb164_disable_intr(irq);
    304  1.1  cgd 
    305  1.1  cgd 	log(LOG_ERR, "stray eb164 irq %d\n", irq);
    306  1.1  cgd 	if (eb164_pci_strayintrcnt[irq] == PCI_STRAY_MAX)
    307  1.1  cgd 		log(LOG_ERR, "disabling interrupts on eb164 irq %d\n", irq);
    308  1.1  cgd #endif /* 0 XXX */
    309  1.1  cgd }
    310  1.1  cgd 
    311  1.1  cgd void
    312  1.1  cgd eb164_iointr(framep, vec)
    313  1.1  cgd 	void *framep;
    314  1.1  cgd 	unsigned long vec;
    315  1.1  cgd {
    316  1.1  cgd 	struct eb164_intrhand *ih;
    317  1.1  cgd 	int irq, handled;
    318  1.1  cgd 
    319  1.1  cgd #if 0 /* XXX */
    320  1.1  cgd 	if (vec >= 0x900) {
    321  1.1  cgd 		if (vec >= 0x900 + (KN20AA_MAX_IRQ << 4))
    322  1.1  cgd 			panic("eb164_iointr: vec 0x%x out of range\n", vec);
    323  1.1  cgd 		irq = (vec - 0x900) >> 4;
    324  1.1  cgd 
    325  1.1  cgd #ifdef EVCNT_COUNTERS
    326  1.1  cgd 		eb164_intr_evcnt.ev_count++;
    327  1.1  cgd #else
    328  1.1  cgd 		if (KN20AA_MAX_IRQ != INTRCNT_KN20AA_IRQ_LEN)
    329  1.1  cgd 			panic("eb164 interrupt counter sizes inconsistent");
    330  1.1  cgd 		intrcnt[INTRCNT_KN20AA_IRQ + irq]++;
    331  1.1  cgd #endif
    332  1.1  cgd 
    333  1.1  cgd 		for (ih = eb164_pci_intrs[irq].tqh_first, handled = 0;
    334  1.1  cgd 		    ih != NULL; ih = ih->ih_q.tqe_next) {
    335  1.1  cgd 			int rv;
    336  1.1  cgd 
    337  1.1  cgd 			rv = (*ih->ih_fun)(ih->ih_arg);
    338  1.1  cgd 
    339  1.1  cgd 			ih->ih_count++;
    340  1.1  cgd 			handled = handled || (rv != 0);
    341  1.1  cgd 		}
    342  1.1  cgd 		if (!handled)
    343  1.1  cgd 			eb164_pci_strayintr(irq);
    344  1.1  cgd 		return;
    345  1.1  cgd 	}
    346  1.1  cgd 	if (vec >= 0x800) {
    347  1.1  cgd #if NSIO
    348  1.1  cgd 		sio_iointr(framep, vec);
    349  1.1  cgd #endif
    350  1.1  cgd 		return;
    351  1.1  cgd 	}
    352  1.1  cgd #endif /* 0 XXX */
    353  1.1  cgd 	panic("eb164_iointr: weird vec 0x%x\n", vec);
    354  1.1  cgd }
    355  1.1  cgd 
    356  1.1  cgd #if 0 /* XXX */
    357  1.1  cgd void
    358  1.1  cgd eb164_enable_intr(irq)
    359  1.1  cgd 	int irq;
    360  1.1  cgd {
    361  1.1  cgd 
    362  1.1  cgd 	/*
    363  1.1  cgd 	 * From disassembling small bits of the OSF/1 kernel:
    364  1.1  cgd 	 * the following appears to enable a given interrupt request.
    365  1.1  cgd 	 * "blech."  I'd give valuable body parts for better docs or
    366  1.1  cgd 	 * for a good decompiler.
    367  1.1  cgd 	 */
    368  1.1  cgd 	alpha_mb();
    369  1.1  cgd 	REGVAL(0x8780000000L + 0x40L) |= (1 << irq);	/* XXX */
    370  1.1  cgd 	alpha_mb();
    371  1.1  cgd }
    372  1.1  cgd 
    373  1.1  cgd void
    374  1.1  cgd eb164_disable_intr(irq)
    375  1.1  cgd 	int irq;
    376  1.1  cgd {
    377  1.1  cgd 
    378  1.1  cgd 	alpha_mb();
    379  1.1  cgd 	REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq);	/* XXX */
    380  1.1  cgd 	alpha_mb();
    381  1.1  cgd }
    382  1.1  cgd 
    383  1.1  cgd struct eb164_intrhand *
    384  1.1  cgd eb164_attach_intr(chain, level, func, arg)
    385  1.1  cgd 	struct eb164_intrchain *chain;
    386  1.1  cgd 	int level;
    387  1.1  cgd 	int (*func) __P((void *));
    388  1.1  cgd 	void *arg;
    389  1.1  cgd {
    390  1.1  cgd 	struct eb164_intrhand *nintrhand;
    391  1.1  cgd 
    392  1.1  cgd 	nintrhand = (struct eb164_intrhand *)
    393  1.1  cgd 	    malloc(sizeof *nintrhand, M_DEVBUF, M_WAITOK);
    394  1.1  cgd 
    395  1.1  cgd         nintrhand->ih_fun = func;
    396  1.1  cgd         nintrhand->ih_arg = arg;
    397  1.1  cgd         nintrhand->ih_count = 0;
    398  1.1  cgd         nintrhand->ih_level = level;
    399  1.1  cgd 	TAILQ_INSERT_TAIL(chain, nintrhand, ih_q);
    400  1.1  cgd 
    401  1.1  cgd 	return (nintrhand);
    402  1.1  cgd }
    403  1.1  cgd #endif /* 0 XXX */
    404