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