Home | History | Annotate | Line # | Download | only in pci
pci_kn20aa.c revision 1.38
      1 /* $NetBSD: pci_kn20aa.c,v 1.38 2000/06/04 19:14:24 cgd 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.38 2000/06/04 19:14:24 cgd 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 const struct evcnt *dec_kn20aa_intr_evcnt __P((void *, pci_intr_handle_t));
     68 void	*dec_kn20aa_intr_establish __P((void *, pci_intr_handle_t,
     69 	    int, int (*func)(void *), void *));
     70 void	dec_kn20aa_intr_disestablish __P((void *, void *));
     71 
     72 #define	KN20AA_PCEB_IRQ	31
     73 #define	KN20AA_MAX_IRQ	32
     74 #define	PCI_STRAY_MAX	5
     75 
     76 struct alpha_shared_intr *kn20aa_pci_intr;
     77 #ifdef EVCNT_COUNTERS
     78 struct evcnt kn20aa_intr_evcnt;
     79 #endif
     80 
     81 void	kn20aa_iointr __P((void *framep, unsigned long vec));
     82 void	kn20aa_enable_intr __P((int irq));
     83 void	kn20aa_disable_intr __P((int irq));
     84 
     85 void
     86 pci_kn20aa_pickintr(ccp)
     87 	struct cia_config *ccp;
     88 {
     89 	int i;
     90 #if NSIO > 0 || NPCEB > 0
     91 	bus_space_tag_t iot = &ccp->cc_iot;
     92 #endif
     93 	pci_chipset_tag_t pc = &ccp->cc_pc;
     94 
     95         pc->pc_intr_v = ccp;
     96         pc->pc_intr_map = dec_kn20aa_intr_map;
     97         pc->pc_intr_string = dec_kn20aa_intr_string;
     98 	pc->pc_intr_evcnt = dec_kn20aa_intr_evcnt;
     99         pc->pc_intr_establish = dec_kn20aa_intr_establish;
    100         pc->pc_intr_disestablish = dec_kn20aa_intr_disestablish;
    101 
    102 	/* Not supported on KN20AA. */
    103 	pc->pc_pciide_compat_intr_establish = NULL;
    104 
    105 	kn20aa_pci_intr = alpha_shared_intr_alloc(KN20AA_MAX_IRQ);
    106 	for (i = 0; i < KN20AA_MAX_IRQ; i++)
    107 		alpha_shared_intr_set_maxstrays(kn20aa_pci_intr, i,
    108 		    PCI_STRAY_MAX);
    109 
    110 #if NSIO > 0 || NPCEB > 0
    111 	sio_intr_setup(pc, iot);
    112 	kn20aa_enable_intr(KN20AA_PCEB_IRQ);
    113 #endif
    114 
    115 	set_iointr(kn20aa_iointr);
    116 }
    117 
    118 int
    119 dec_kn20aa_intr_map(ccv, bustag, buspin, line, ihp)
    120         void *ccv;
    121         pcitag_t bustag;
    122         int buspin, line;
    123         pci_intr_handle_t *ihp;
    124 {
    125 	struct cia_config *ccp = ccv;
    126 	pci_chipset_tag_t pc = &ccp->cc_pc;
    127 	int device;
    128 	int kn20aa_irq;
    129 
    130 	if (buspin == 0) {
    131 		/* No IRQ used. */
    132 		return 1;
    133 	}
    134 	if (buspin > 4) {
    135 		printf("dec_kn20aa_intr_map: bad interrupt pin %d\n", buspin);
    136 		return 1;
    137 	}
    138 
    139 	/*
    140 	 * Slot->interrupt translation.  Appears to work, though it
    141 	 * may not hold up forever.
    142 	 *
    143 	 * The DEC engineers who did this hardware obviously engaged
    144 	 * in random drug testing.
    145 	 */
    146 	alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    147 	switch (device) {
    148 	case 11:
    149 	case 12:
    150 		kn20aa_irq = ((device - 11) + 0) * 4;
    151 		break;
    152 
    153 	case 7:
    154 		kn20aa_irq = 8;
    155 		break;
    156 
    157 	case 9:
    158 		kn20aa_irq = 12;
    159 		break;
    160 
    161 	case 6:					/* 21040 on AlphaStation 500 */
    162 		kn20aa_irq = 13;
    163 		break;
    164 
    165 	case 8:
    166 		kn20aa_irq = 16;
    167 		break;
    168 
    169 	default:
    170                 printf("dec_kn20aa_intr_map: weird device number %d\n",
    171 		    device);
    172                 return 1;
    173 	}
    174 
    175 	kn20aa_irq += buspin - 1;
    176 	if (kn20aa_irq > KN20AA_MAX_IRQ)
    177 		panic("dec_kn20aa_intr_map: kn20aa_irq too large (%d)\n",
    178 		    kn20aa_irq);
    179 
    180 	*ihp = kn20aa_irq;
    181 	return (0);
    182 }
    183 
    184 const char *
    185 dec_kn20aa_intr_string(ccv, ih)
    186 	void *ccv;
    187 	pci_intr_handle_t ih;
    188 {
    189 #if 0
    190 	struct cia_config *ccp = ccv;
    191 #endif
    192         static char irqstr[15];          /* 11 + 2 + NULL + sanity */
    193 
    194         if (ih > KN20AA_MAX_IRQ)
    195                 panic("dec_kn20aa_intr_string: bogus kn20aa IRQ 0x%lx\n",
    196 		    ih);
    197 
    198         sprintf(irqstr, "kn20aa irq %ld", ih);
    199         return (irqstr);
    200 }
    201 
    202 const struct evcnt *
    203 dec_kn20aa_intr_evcnt(ccv, ih)
    204 	void *ccv;
    205 	pci_intr_handle_t ih;
    206 {
    207 #if 0
    208 	struct cia_config *ccp = ccv;
    209 #endif
    210 
    211 	/* XXX for now, no evcnt parent reported */
    212 	return (NULL);
    213 }
    214 
    215 void *
    216 dec_kn20aa_intr_establish(ccv, ih, level, func, arg)
    217         void *ccv, *arg;
    218         pci_intr_handle_t ih;
    219         int level;
    220         int (*func) __P((void *));
    221 {
    222 #if 0
    223         struct cia_config *ccp = ccv;
    224 #endif
    225 	void *cookie;
    226 
    227         if (ih > KN20AA_MAX_IRQ)
    228                 panic("dec_kn20aa_intr_establish: bogus kn20aa IRQ 0x%lx\n",
    229 		    ih);
    230 
    231 	cookie = alpha_shared_intr_establish(kn20aa_pci_intr, ih, IST_LEVEL,
    232 	    level, func, arg, "kn20aa irq");
    233 
    234 	if (cookie != NULL &&
    235 	    alpha_shared_intr_isactive(kn20aa_pci_intr, ih))
    236 		kn20aa_enable_intr(ih);
    237 	return (cookie);
    238 }
    239 
    240 void
    241 dec_kn20aa_intr_disestablish(ccv, cookie)
    242         void *ccv, *cookie;
    243 {
    244 #if 0
    245 	struct cia_config *ccp = ccv;
    246 #endif
    247 	struct alpha_shared_intrhand *ih = cookie;
    248 	unsigned int irq = ih->ih_num;
    249 	int s;
    250 
    251 	s = splhigh();
    252 
    253 	alpha_shared_intr_disestablish(kn20aa_pci_intr, cookie,
    254 	    "kn20aa irq");
    255 	if (alpha_shared_intr_isactive(kn20aa_pci_intr, irq) == 0) {
    256 		kn20aa_disable_intr(irq);
    257 		alpha_shared_intr_set_dfltsharetype(kn20aa_pci_intr, irq,
    258 		    IST_NONE);
    259 	}
    260 
    261 	splx(s);
    262 }
    263 
    264 void
    265 kn20aa_iointr(framep, vec)
    266 	void *framep;
    267 	unsigned long vec;
    268 {
    269 	int irq;
    270 
    271 	if (vec >= 0x900) {
    272 		if (vec >= 0x900 + (KN20AA_MAX_IRQ << 4))
    273 			panic("kn20aa_iointr: vec 0x%lx out of range\n", vec);
    274 		irq = (vec - 0x900) >> 4;
    275 
    276 #ifdef EVCNT_COUNTERS
    277 		kn20aa_intr_evcnt.ev_count++;
    278 #else
    279 		if (KN20AA_MAX_IRQ != INTRCNT_KN20AA_IRQ_LEN)
    280 			panic("kn20aa interrupt counter sizes inconsistent");
    281 		intrcnt[INTRCNT_KN20AA_IRQ + irq]++;
    282 #endif
    283 
    284 		if (!alpha_shared_intr_dispatch(kn20aa_pci_intr, irq)) {
    285 			alpha_shared_intr_stray(kn20aa_pci_intr, irq,
    286 			    "kn20aa irq");
    287 			if (ALPHA_SHARED_INTR_DISABLE(kn20aa_pci_intr, irq))
    288 				kn20aa_disable_intr(irq);
    289 		}
    290 		return;
    291 	}
    292 #if NSIO > 0 || NPCEB > 0
    293 	if (vec >= 0x800) {
    294 		sio_iointr(framep, vec);
    295 		return;
    296 	}
    297 #endif
    298 	panic("kn20aa_iointr: weird vec 0x%lx\n", vec);
    299 }
    300 
    301 void
    302 kn20aa_enable_intr(irq)
    303 	int irq;
    304 {
    305 
    306 	/*
    307 	 * From disassembling small bits of the OSF/1 kernel:
    308 	 * the following appears to enable a given interrupt request.
    309 	 * "blech."  I'd give valuable body parts for better docs or
    310 	 * for a good decompiler.
    311 	 */
    312 	alpha_mb();
    313 	REGVAL(0x8780000000L + 0x40L) |= (1 << irq);	/* XXX */
    314 	alpha_mb();
    315 }
    316 
    317 void
    318 kn20aa_disable_intr(irq)
    319 	int irq;
    320 {
    321 
    322 	alpha_mb();
    323 	REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq);	/* XXX */
    324 	alpha_mb();
    325 }
    326