1 /* $NetBSD: pci_axppci_33.c,v 1.16 1997/09/02 20:10:29 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Authors: Jeffrey Hsu and 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@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_axppci_33.c,v 1.16 1997/09/02 20:10:29 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/device.h> 40 #include <vm/vm.h> 41 42 #include <machine/autoconf.h> 43 #include <machine/bus.h> 44 #include <machine/intr.h> 45 46 #include <dev/isa/isavar.h> 47 #include <dev/pci/pcireg.h> 48 #include <dev/pci/pcivar.h> 49 50 #include <alpha/pci/lcavar.h> 51 52 #include <alpha/pci/pci_axppci_33.h> 53 #include <alpha/pci/siovar.h> 54 #include <alpha/pci/sioreg.h> 55 56 #include "sio.h" 57 58 int dec_axppci_33_intr_map __P((void *, pcitag_t, int, int, 59 pci_intr_handle_t *)); 60 const char *dec_axppci_33_intr_string __P((void *, pci_intr_handle_t)); 61 void *dec_axppci_33_intr_establish __P((void *, pci_intr_handle_t, 62 int, int (*func)(void *), void *)); 63 void dec_axppci_33_intr_disestablish __P((void *, void *)); 64 65 #define LCA_SIO_DEVICE 7 /* XXX */ 66 67 void 68 pci_axppci_33_pickintr(lcp) 69 struct lca_config *lcp; 70 { 71 bus_space_tag_t iot = &lcp->lc_iot; 72 pci_chipset_tag_t pc = &lcp->lc_pc; 73 pcireg_t sioclass; 74 int sioII; 75 76 /* XXX MAGIC NUMBER */ 77 sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0), 78 PCI_CLASS_REG); 79 sioII = (sioclass & 0xff) >= 3; 80 81 if (!sioII) 82 printf("WARNING: SIO NOT SIO II... NO BETS...\n"); 83 84 pc->pc_intr_v = lcp; 85 pc->pc_intr_map = dec_axppci_33_intr_map; 86 pc->pc_intr_string = dec_axppci_33_intr_string; 87 pc->pc_intr_establish = dec_axppci_33_intr_establish; 88 pc->pc_intr_disestablish = dec_axppci_33_intr_disestablish; 89 90 #if NSIO 91 sio_intr_setup(iot); 92 set_iointr(&sio_iointr); 93 #else 94 panic("pci_axppci_33_pickintr: no I/O interrupt handler (no sio)"); 95 #endif 96 } 97 98 int 99 dec_axppci_33_intr_map(lcv, bustag, buspin, line, ihp) 100 void *lcv; 101 pcitag_t bustag; 102 int buspin, line; 103 pci_intr_handle_t *ihp; 104 { 105 struct lca_config *lcp = lcv; 106 pci_chipset_tag_t pc = &lcp->lc_pc; 107 int device, pirq; 108 pcireg_t pirqreg; 109 u_int8_t pirqline; 110 111 #ifndef DIAGNOSTIC 112 pirq = 0; /* XXX gcc -Wuninitialized */ 113 #endif 114 115 if (buspin == 0) { 116 /* No IRQ used. */ 117 return 1; 118 } 119 if (buspin > 4) { 120 printf("pci_map_int: bad interrupt pin %d\n", buspin); 121 return 1; 122 } 123 124 alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL); 125 126 switch (device) { 127 case 6: /* NCR SCSI */ 128 pirq = 3; 129 break; 130 131 case 11: /* slot 1 */ 132 switch (buspin) { 133 case PCI_INTERRUPT_PIN_A: 134 case PCI_INTERRUPT_PIN_D: 135 pirq = 0; 136 break; 137 case PCI_INTERRUPT_PIN_B: 138 pirq = 2; 139 break; 140 case PCI_INTERRUPT_PIN_C: 141 pirq = 1; 142 break; 143 #ifdef DIAGNOSTIC 144 default: /* XXX gcc -Wuninitialized */ 145 panic("dec_axppci_33_intr_map bogus PCI pin %d\n", 146 buspin); 147 #endif 148 }; 149 break; 150 151 case 12: /* slot 2 */ 152 switch (buspin) { 153 case PCI_INTERRUPT_PIN_A: 154 case PCI_INTERRUPT_PIN_D: 155 pirq = 1; 156 break; 157 case PCI_INTERRUPT_PIN_B: 158 pirq = 0; 159 break; 160 case PCI_INTERRUPT_PIN_C: 161 pirq = 2; 162 break; 163 #ifdef DIAGNOSTIC 164 default: /* XXX gcc -Wuninitialized */ 165 panic("dec_axppci_33_intr_map bogus PCI pin %d\n", 166 buspin); 167 #endif 168 }; 169 break; 170 171 case 8: /* slot 3 */ 172 switch (buspin) { 173 case PCI_INTERRUPT_PIN_A: 174 case PCI_INTERRUPT_PIN_D: 175 pirq = 2; 176 break; 177 case PCI_INTERRUPT_PIN_B: 178 pirq = 1; 179 break; 180 case PCI_INTERRUPT_PIN_C: 181 pirq = 0; 182 break; 183 #ifdef DIAGNOSTIC 184 default: /* XXX gcc -Wuninitialized */ 185 panic("dec_axppci_33_intr_map bogus PCI pin %d\n", 186 buspin); 187 #endif 188 }; 189 break; 190 191 default: 192 printf("dec_axppci_33_intr_map: weird device number %d\n", 193 device); 194 return 1; 195 } 196 197 pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0), 198 SIO_PCIREG_PIRQ_RTCTRL); 199 #if 0 200 printf("pci_axppci_33_map_int: device %d pin %c: pirq %d, reg = %x\n", 201 device, '@' + buspin, pirq, pirqreg); 202 #endif 203 pirqline = (pirqreg >> (pirq * 8)) & 0xff; 204 if ((pirqline & 0x80) != 0) 205 return 1; /* not routed? */ 206 pirqline &= 0xf; 207 208 #if 0 209 printf("pci_axppci_33_map_int: device %d pin %c: mapped to line %d\n", 210 device, '@' + buspin, pirqline); 211 #endif 212 213 *ihp = pirqline; 214 return (0); 215 } 216 217 const char * 218 dec_axppci_33_intr_string(lcv, ih) 219 void *lcv; 220 pci_intr_handle_t ih; 221 { 222 #if 0 223 struct lca_config *lcp = lcv; 224 #endif 225 226 return sio_intr_string(NULL /*XXX*/, ih); 227 } 228 229 void * 230 dec_axppci_33_intr_establish(lcv, ih, level, func, arg) 231 void *lcv, *arg; 232 pci_intr_handle_t ih; 233 int level; 234 int (*func) __P((void *)); 235 { 236 #if 0 237 struct lca_config *lcp = lcv; 238 #endif 239 240 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func, 241 arg); 242 } 243 244 void 245 dec_axppci_33_intr_disestablish(lcv, cookie) 246 void *lcv, *cookie; 247 { 248 #if 0 249 struct lca_config *lcp = lcv; 250 #endif 251 252 sio_intr_disestablish(NULL /*XXX*/, cookie); 253 } 254