Home | History | Annotate | Line # | Download | only in pci
pci_kn20aa.c revision 1.37
      1 /* $NetBSD: pci_kn20aa.c,v 1.37 1999/12/15 22:28:15 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31 
     32 __KERNEL_RCSID(0, "$NetBSD: pci_kn20aa.c,v 1.37 1999/12/15 22:28:15 thorpej Exp $");
     33 
     34 #include <sys/types.h>
     35 #include <sys/param.h>
     36 #include <sys/time.h>
     37 #include <sys/systm.h>
     38 #include <sys/errno.h>
     39 #include <sys/malloc.h>
     40 #include <sys/device.h>
     41 #include <sys/syslog.h>
     42 
     43 #include <vm/vm.h>
     44 
     45 #include <machine/autoconf.h>
     46 
     47 #include <dev/pci/pcireg.h>
     48 #include <dev/pci/pcivar.h>
     49 
     50 #include <alpha/pci/ciareg.h>
     51 #include <alpha/pci/ciavar.h>
     52 
     53 #include <alpha/pci/pci_kn20aa.h>
     54 
     55 #ifndef EVCNT_COUNTERS
     56 #include <machine/intrcnt.h>
     57 #endif
     58 
     59 #include "sio.h"
     60 #if NSIO > 0 || NPCEB > 0
     61 #include <alpha/pci/siovar.h>
     62 #endif
     63 
     64 int	dec_kn20aa_intr_map __P((void *, pcitag_t, int, int,
     65 	    pci_intr_handle_t *));
     66 const char *dec_kn20aa_intr_string __P((void *, pci_intr_handle_t));
     67 void	*dec_kn20aa_intr_establish __P((void *, pci_intr_handle_t,
     68 	    int, int (*func)(void *), void *));
     69 void	dec_kn20aa_intr_disestablish __P((void *, void *));
     70 
     71 #define	KN20AA_PCEB_IRQ	31
     72 #define	KN20AA_MAX_IRQ	32
     73 #define	PCI_STRAY_MAX	5
     74 
     75 struct alpha_shared_intr *kn20aa_pci_intr;
     76 #ifdef EVCNT_COUNTERS
     77 struct evcnt kn20aa_intr_evcnt;
     78 #endif
     79 
     80 void	kn20aa_iointr __P((void *framep, unsigned long vec));
     81 void	kn20aa_enable_intr __P((int irq));
     82 void	kn20aa_disable_intr __P((int irq));
     83 
     84 void
     85 pci_kn20aa_pickintr(ccp)
     86 	struct cia_config *ccp;
     87 {
     88 	int i;
     89 #if NSIO > 0 || NPCEB > 0
     90 	bus_space_tag_t iot = &ccp->cc_iot;
     91 #endif
     92 	pci_chipset_tag_t pc = &ccp->cc_pc;
     93 
     94         pc->pc_intr_v = ccp;
     95         pc->pc_intr_map = dec_kn20aa_intr_map;
     96         pc->pc_intr_string = dec_kn20aa_intr_string;
     97         pc->pc_intr_establish = dec_kn20aa_intr_establish;
     98         pc->pc_intr_disestablish = dec_kn20aa_intr_disestablish;
     99 
    100 	/* Not supported on KN20AA. */
    101 	pc->pc_pciide_compat_intr_establish = NULL;
    102 
    103 	kn20aa_pci_intr = alpha_shared_intr_alloc(KN20AA_MAX_IRQ);
    104 	for (i = 0; i < KN20AA_MAX_IRQ; i++)
    105 		alpha_shared_intr_set_maxstrays(kn20aa_pci_intr, i,
    106 		    PCI_STRAY_MAX);
    107 
    108 #if NSIO > 0 || NPCEB > 0
    109 	sio_intr_setup(pc, iot);
    110 	kn20aa_enable_intr(KN20AA_PCEB_IRQ);
    111 #endif
    112 
    113 	set_iointr(kn20aa_iointr);
    114 }
    115 
    116 int
    117 dec_kn20aa_intr_map(ccv, bustag, buspin, line, ihp)
    118         void *ccv;
    119         pcitag_t bustag;
    120         int buspin, line;
    121         pci_intr_handle_t *ihp;
    122 {
    123 	struct cia_config *ccp = ccv;
    124 	pci_chipset_tag_t pc = &ccp->cc_pc;
    125 	int device;
    126 	int kn20aa_irq;
    127 
    128 	if (buspin == 0) {
    129 		/* No IRQ used. */
    130 		return 1;
    131 	}
    132 	if (buspin > 4) {
    133 		printf("dec_kn20aa_intr_map: bad interrupt pin %d\n", buspin);
    134 		return 1;
    135 	}
    136 
    137 	/*
    138 	 * Slot->interrupt translation.  Appears to work, though it
    139 	 * may not hold up forever.
    140 	 *
    141 	 * The DEC engineers who did this hardware obviously engaged
    142 	 * in random drug testing.
    143 	 */
    144 	alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    145 	switch (device) {
    146 	case 11:
    147 	case 12:
    148 		kn20aa_irq = ((device - 11) + 0) * 4;
    149 		break;
    150 
    151 	case 7:
    152 		kn20aa_irq = 8;
    153 		break;
    154 
    155 	case 9:
    156 		kn20aa_irq = 12;
    157 		break;
    158 
    159 	case 6:					/* 21040 on AlphaStation 500 */
    160 		kn20aa_irq = 13;
    161 		break;
    162 
    163 	case 8:
    164 		kn20aa_irq = 16;
    165 		break;
    166 
    167 	default:
    168                 printf("dec_kn20aa_intr_map: weird device number %d\n",
    169 		    device);
    170                 return 1;
    171 	}
    172 
    173 	kn20aa_irq += buspin - 1;
    174 	if (kn20aa_irq > KN20AA_MAX_IRQ)
    175 		panic("dec_kn20aa_intr_map: kn20aa_irq too large (%d)\n",
    176 		    kn20aa_irq);
    177 
    178 	*ihp = kn20aa_irq;
    179 	return (0);
    180 }
    181 
    182 const char *
    183 dec_kn20aa_intr_string(ccv, ih)
    184 	void *ccv;
    185 	pci_intr_handle_t ih;
    186 {
    187 #if 0
    188 	struct cia_config *ccp = ccv;
    189 #endif
    190         static char irqstr[15];          /* 11 + 2 + NULL + sanity */
    191 
    192         if (ih > KN20AA_MAX_IRQ)
    193                 panic("dec_kn20aa_intr_string: bogus kn20aa IRQ 0x%lx\n",
    194 		    ih);
    195 
    196         sprintf(irqstr, "kn20aa irq %ld", ih);
    197         return (irqstr);
    198 }
    199 
    200 void *
    201 dec_kn20aa_intr_establish(ccv, ih, level, func, arg)
    202         void *ccv, *arg;
    203         pci_intr_handle_t ih;
    204         int level;
    205         int (*func) __P((void *));
    206 {
    207 #if 0
    208         struct cia_config *ccp = ccv;
    209 #endif
    210 	void *cookie;
    211 
    212         if (ih > KN20AA_MAX_IRQ)
    213                 panic("dec_kn20aa_intr_establish: bogus kn20aa IRQ 0x%lx\n",
    214 		    ih);
    215 
    216 	cookie = alpha_shared_intr_establish(kn20aa_pci_intr, ih, IST_LEVEL,
    217 	    level, func, arg, "kn20aa irq");
    218 
    219 	if (cookie != NULL &&
    220 	    alpha_shared_intr_isactive(kn20aa_pci_intr, ih))
    221 		kn20aa_enable_intr(ih);
    222 	return (cookie);
    223 }
    224 
    225 void
    226 dec_kn20aa_intr_disestablish(ccv, cookie)
    227         void *ccv, *cookie;
    228 {
    229 #if 0
    230 	struct cia_config *ccp = ccv;
    231 #endif
    232 	struct alpha_shared_intrhand *ih = cookie;
    233 	unsigned int irq = ih->ih_num;
    234 	int s;
    235 
    236 	s = splhigh();
    237 
    238 	alpha_shared_intr_disestablish(kn20aa_pci_intr, cookie,
    239 	    "kn20aa irq");
    240 	if (alpha_shared_intr_isactive(kn20aa_pci_intr, irq) == 0) {
    241 		kn20aa_disable_intr(irq);
    242 		alpha_shared_intr_set_dfltsharetype(kn20aa_pci_intr, irq,
    243 		    IST_NONE);
    244 	}
    245 
    246 	splx(s);
    247 }
    248 
    249 void
    250 kn20aa_iointr(framep, vec)
    251 	void *framep;
    252 	unsigned long vec;
    253 {
    254 	int irq;
    255 
    256 	if (vec >= 0x900) {
    257 		if (vec >= 0x900 + (KN20AA_MAX_IRQ << 4))
    258 			panic("kn20aa_iointr: vec 0x%lx out of range\n", vec);
    259 		irq = (vec - 0x900) >> 4;
    260 
    261 #ifdef EVCNT_COUNTERS
    262 		kn20aa_intr_evcnt.ev_count++;
    263 #else
    264 		if (KN20AA_MAX_IRQ != INTRCNT_KN20AA_IRQ_LEN)
    265 			panic("kn20aa interrupt counter sizes inconsistent");
    266 		intrcnt[INTRCNT_KN20AA_IRQ + irq]++;
    267 #endif
    268 
    269 		if (!alpha_shared_intr_dispatch(kn20aa_pci_intr, irq)) {
    270 			alpha_shared_intr_stray(kn20aa_pci_intr, irq,
    271 			    "kn20aa irq");
    272 			if (ALPHA_SHARED_INTR_DISABLE(kn20aa_pci_intr, irq))
    273 				kn20aa_disable_intr(irq);
    274 		}
    275 		return;
    276 	}
    277 #if NSIO > 0 || NPCEB > 0
    278 	if (vec >= 0x800) {
    279 		sio_iointr(framep, vec);
    280 		return;
    281 	}
    282 #endif
    283 	panic("kn20aa_iointr: weird vec 0x%lx\n", vec);
    284 }
    285 
    286 void
    287 kn20aa_enable_intr(irq)
    288 	int irq;
    289 {
    290 
    291 	/*
    292 	 * From disassembling small bits of the OSF/1 kernel:
    293 	 * the following appears to enable a given interrupt request.
    294 	 * "blech."  I'd give valuable body parts for better docs or
    295 	 * for a good decompiler.
    296 	 */
    297 	alpha_mb();
    298 	REGVAL(0x8780000000L + 0x40L) |= (1 << irq);	/* XXX */
    299 	alpha_mb();
    300 }
    301 
    302 void
    303 kn20aa_disable_intr(irq)
    304 	int irq;
    305 {
    306 
    307 	alpha_mb();
    308 	REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq);	/* XXX */
    309 	alpha_mb();
    310 }
    311