Home | History | Annotate | Line # | Download | only in pci
pci_eb164.c revision 1.10
      1 /* $NetBSD: pci_eb164.c,v 1.10 1997/09/02 20:10:30 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_eb164.c,v 1.10 1997/09/02 20:10:30 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_eb164.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_eb164_intr_map __P((void *, pcitag_t, int, int,
     65 	    pci_intr_handle_t *));
     66 const char *dec_eb164_intr_string __P((void *, pci_intr_handle_t));
     67 void	*dec_eb164_intr_establish __P((void *, pci_intr_handle_t,
     68 	    int, int (*func)(void *), void *));
     69 void	dec_eb164_intr_disestablish __P((void *, void *));
     70 
     71 #define	EB164_SIO_IRQ	4
     72 #define	EB164_MAX_IRQ	24
     73 #define	PCI_STRAY_MAX	5
     74 
     75 struct alpha_shared_intr *eb164_pci_intr;
     76 #ifdef EVCNT_COUNTERS
     77 struct evcnt eb164_intr_evcnt;
     78 #endif
     79 
     80 bus_space_tag_t eb164_intrgate_iot;
     81 bus_space_handle_t eb164_intrgate_ioh;
     82 
     83 void	eb164_iointr __P((void *framep, unsigned long vec));
     84 extern void	eb164_intr_enable __P((int irq));	/* pci_eb164_intr.S */
     85 extern void	eb164_intr_disable __P((int irq));	/* pci_eb164_intr.S */
     86 
     87 void
     88 pci_eb164_pickintr(ccp)
     89 	struct cia_config *ccp;
     90 {
     91 	bus_space_tag_t iot = &ccp->cc_iot;
     92 	pci_chipset_tag_t pc = &ccp->cc_pc;
     93 	int i;
     94 
     95         pc->pc_intr_v = ccp;
     96         pc->pc_intr_map = dec_eb164_intr_map;
     97         pc->pc_intr_string = dec_eb164_intr_string;
     98         pc->pc_intr_establish = dec_eb164_intr_establish;
     99         pc->pc_intr_disestablish = dec_eb164_intr_disestablish;
    100 
    101 	eb164_intrgate_iot = iot;
    102 	if (bus_space_map(eb164_intrgate_iot, 0x804, 3, 0,
    103 	    &eb164_intrgate_ioh) != 0)
    104 		panic("pci_eb164_pickintr: couldn't map interrupt PLD");
    105 	for (i = 0; i < EB164_MAX_IRQ; i++)
    106 		eb164_intr_disable(i);
    107 
    108 	eb164_pci_intr = alpha_shared_intr_alloc(EB164_MAX_IRQ);
    109 	for (i = 0; i < EB164_MAX_IRQ; i++)
    110 		alpha_shared_intr_set_maxstrays(eb164_pci_intr, i,
    111 			PCI_STRAY_MAX);
    112 
    113 #if NSIO
    114 	sio_intr_setup(iot);
    115 	eb164_intr_enable(EB164_SIO_IRQ);
    116 #endif
    117 
    118 	set_iointr(eb164_iointr);
    119 }
    120 
    121 int
    122 dec_eb164_intr_map(ccv, bustag, buspin, line, ihp)
    123         void *ccv;
    124         pcitag_t bustag;
    125         int buspin, line;
    126         pci_intr_handle_t *ihp;
    127 {
    128 	struct cia_config *ccp = ccv;
    129 	pci_chipset_tag_t pc = &ccp->cc_pc;
    130 	int device;
    131 	int eb164_irq, pinbase, pinoff;
    132 
    133 #ifndef DIAGNOSTIC
    134 	pinbase = pinoff = 0;			/* XXX gcc -Wuninitialized */
    135 #endif
    136 
    137         if (buspin == 0) {
    138                 /* No IRQ used. */
    139                 return 1;
    140         }
    141         if (buspin > 4) {
    142                 printf("pci_map_int: bad interrupt pin %d\n", buspin);
    143                 return 1;
    144         }
    145 
    146 	alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    147 	switch (device) {
    148 #if 0	/* THIS CODE SHOULD NEVER BE CALLED FOR THE SIO */
    149 	case 8: 					/* SIO */
    150 		eb164_irq = 4;
    151 		break;
    152 #endif
    153 
    154 	case 11:
    155 		eb164_irq = 5;				/* IDE */
    156 		break;
    157 
    158 	case 5:
    159 	case 6:
    160 	case 7:
    161 	case 9:
    162 		switch (buspin) {
    163 		case 1:
    164 			pinbase = 0;
    165 			break;
    166 		case 2:
    167 		case 3:
    168 		case 4:
    169 			pinbase = (buspin * 4) - 1;
    170 			break;
    171 #ifdef DIAGNOSTIC
    172 		default:
    173 			panic("dec_eb164_intr_map: slot buspin switch");
    174 #endif
    175 		};
    176 		switch (device) {
    177 		case 5:
    178 			pinoff = 2;
    179 			break;
    180 
    181 		case 6:
    182 		case 7:
    183 		case 9:
    184 			pinoff = device - 6;
    185 			break;
    186 #ifdef DIAGNOSTIC
    187 		default:
    188 			panic("dec_eb164_intr_map: slot device switch");
    189 #endif
    190 		}
    191 		eb164_irq = pinoff + pinbase;
    192 		break;
    193 	default:
    194 		panic("pci_eb164_map_int: invalid device number %d\n",
    195 		    device);
    196 	}
    197 
    198 	if (eb164_irq > EB164_MAX_IRQ)
    199 		panic("pci_eb164_map_int: eb164_irq too large (%d)\n",
    200 		    eb164_irq);
    201 
    202 	*ihp = eb164_irq;
    203 	return (0);
    204 }
    205 
    206 const char *
    207 dec_eb164_intr_string(ccv, ih)
    208 	void *ccv;
    209 	pci_intr_handle_t ih;
    210 {
    211 #if 0
    212 	struct cia_config *ccp = ccv;
    213 #endif
    214         static char irqstr[15];          /* 11 + 2 + NULL + sanity */
    215 
    216         if (ih > EB164_MAX_IRQ)
    217                 panic("dec_eb164_intr_string: bogus eb164 IRQ 0x%x\n", ih);
    218         sprintf(irqstr, "eb164 irq %d", ih);
    219         return (irqstr);
    220 }
    221 
    222 void *
    223 dec_eb164_intr_establish(ccv, ih, level, func, arg)
    224         void *ccv, *arg;
    225         pci_intr_handle_t ih;
    226         int level;
    227         int (*func) __P((void *));
    228 {
    229 #if 0
    230 	struct cia_config *ccp = ccv;
    231 #endif
    232 	void *cookie;
    233 
    234 	if (ih > EB164_MAX_IRQ)
    235 		panic("dec_eb164_intr_establish: bogus eb164 IRQ 0x%x\n", ih);
    236 
    237 	cookie = alpha_shared_intr_establish(eb164_pci_intr, ih, IST_LEVEL,
    238 	    level, func, arg, "eb164 irq");
    239 
    240 	if (cookie != NULL && alpha_shared_intr_isactive(eb164_pci_intr, ih))
    241 		eb164_intr_enable(ih);
    242 	return (cookie);
    243 }
    244 
    245 void
    246 dec_eb164_intr_disestablish(ccv, cookie)
    247         void *ccv, *cookie;
    248 {
    249 #if 0
    250 	struct cia_config *ccp = ccv;
    251 #endif
    252 
    253 	panic("dec_eb164_intr_disestablish not implemented"); /* XXX */
    254 }
    255 
    256 void
    257 eb164_iointr(framep, vec)
    258 	void *framep;
    259 	unsigned long vec;
    260 {
    261 	int irq;
    262 
    263 	if (vec >= 0x900) {
    264 		if (vec >= 0x900 + (EB164_MAX_IRQ << 4))
    265 			panic("eb164_iointr: vec 0x%x out of range\n", vec);
    266 		irq = (vec - 0x900) >> 4;
    267 
    268 #ifdef EVCNT_COUNTERS
    269 		eb164_intr_evcnt.ev_count++;
    270 #else
    271 		if (EB164_MAX_IRQ != INTRCNT_EB164_IRQ_LEN)
    272 			panic("eb164 interrupt counter sizes inconsistent");
    273 		intrcnt[INTRCNT_EB164_IRQ + irq]++;
    274 #endif
    275 
    276 		if (!alpha_shared_intr_dispatch(eb164_pci_intr, irq)) {
    277 			alpha_shared_intr_stray(eb164_pci_intr, irq,
    278 			    "eb164 irq");
    279 			if (eb164_pci_intr[irq].intr_nstrays ==
    280 			    eb164_pci_intr[irq].intr_maxstrays)
    281 				eb164_intr_disable(irq);
    282 		}
    283 		return;
    284 	}
    285 #if NSIO
    286 	if (vec >= 0x800) {
    287 		sio_iointr(framep, vec);
    288 		return;
    289 	}
    290 #endif
    291 	panic("eb164_iointr: weird vec 0x%x\n", vec);
    292 }
    293 
    294 #if 0		/* THIS DOES NOT WORK!  see pci_eb164_intr.S. */
    295 u_int8_t eb164_intr_mask[3] = { 0xff, 0xff, 0xff };
    296 
    297 void
    298 eb164_intr_enable(irq)
    299 	int irq;
    300 {
    301 	int byte = (irq / 8), bit = (irq % 8);
    302 
    303 #if 1
    304 	printf("eb164_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
    305 #endif
    306 	eb164_intr_mask[byte] &= ~(1 << bit);
    307 
    308 	bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
    309 	    eb164_intr_mask[byte]);
    310 }
    311 
    312 void
    313 eb164_intr_disable(irq)
    314 	int irq;
    315 {
    316 	int byte = (irq / 8), bit = (irq % 8);
    317 
    318 #if 1
    319 	printf("eb164_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
    320 #endif
    321 	eb164_intr_mask[byte] |= (1 << bit);
    322 
    323 	bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
    324 	    eb164_intr_mask[byte]);
    325 }
    326 #endif
    327