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