1 /* $OpenBSD: pci_axppci_33.c,v 1.21 2015/07/26 05:09:44 miod Exp $ */ 2 /* $NetBSD: pci_axppci_33.c,v 1.10 1996/11/13 21:13:29 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 6 * All rights reserved. 7 * 8 * Authors: Jeffrey Hsu and Chris G. Demetriou 9 * 10 * Permission to use, copy, modify and distribute this software and 11 * its documentation is hereby granted, provided that both the copyright 12 * notice and this permission notice appear in all copies of the 13 * software, derivative works or modified versions, and any portions 14 * thereof, and that both notices appear in supporting documentation. 15 * 16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19 * 20 * Carnegie Mellon requests users of this software to return to 21 * 22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23 * School of Computer Science 24 * Carnegie Mellon University 25 * Pittsburgh PA 15213-3890 26 * 27 * any improvements or extensions that they make and grant Carnegie the 28 * rights to redistribute these changes. 29 */ 30 31 #include <sys/types.h> 32 #include <sys/param.h> 33 #include <sys/time.h> 34 #include <sys/systm.h> 35 #include <sys/errno.h> 36 #include <sys/device.h> 37 #include <uvm/uvm_extern.h> 38 39 #include <machine/autoconf.h> 40 #include <machine/bus.h> 41 #include <machine/intr.h> 42 43 #include <dev/isa/isavar.h> 44 #include <dev/pci/pcireg.h> 45 #include <dev/pci/pcivar.h> 46 #include <dev/pci/ppbreg.h> 47 48 #include <alpha/pci/lcavar.h> 49 50 #include <alpha/pci/pci_axppci_33.h> 51 #include <alpha/pci/siovar.h> 52 #include <alpha/pci/sioreg.h> 53 54 #include "sio.h" 55 56 int dec_axppci_33_intr_map(struct pci_attach_args *, pci_intr_handle_t *); 57 const char *dec_axppci_33_intr_string(void *, pci_intr_handle_t); 58 int dec_axppci_33_intr_line(void *, pci_intr_handle_t); 59 void *dec_axppci_33_intr_establish(void *, pci_intr_handle_t, 60 int, int (*func)(void *), void *, const char *); 61 void dec_axppci_33_intr_disestablish(void *, void *); 62 63 #define LCA_SIO_DEVICE 7 /* XXX */ 64 65 void 66 pci_axppci_33_pickintr(lcp) 67 struct lca_config *lcp; 68 { 69 bus_space_tag_t iot = &lcp->lc_iot; 70 pci_chipset_tag_t pc = &lcp->lc_pc; 71 pcireg_t sioclass; 72 int sioII; 73 74 /* XXX MAGIC NUMBER */ 75 sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0), 76 PCI_CLASS_REG); 77 sioII = (sioclass & 0xff) >= 3; 78 79 if (!sioII) 80 printf("WARNING: SIO NOT SIO II... NO BETS...\n"); 81 82 pc->pc_intr_v = lcp; 83 pc->pc_intr_map = dec_axppci_33_intr_map; 84 pc->pc_intr_string = dec_axppci_33_intr_string; 85 pc->pc_intr_line = dec_axppci_33_intr_line; 86 pc->pc_intr_establish = dec_axppci_33_intr_establish; 87 pc->pc_intr_disestablish = dec_axppci_33_intr_disestablish; 88 89 /* Not supported on AXPpci33. */ 90 pc->pc_pciide_compat_intr_establish = NULL; 91 pc->pc_pciide_compat_intr_disestablish = NULL; 92 93 #if NSIO > 0 94 sio_intr_setup(pc, iot); 95 #else 96 panic("pci_axppci_33_pickintr: no I/O interrupt handler (no sio)"); 97 #endif 98 } 99 100 int 101 dec_axppci_33_intr_map(pa, ihp) 102 struct pci_attach_args *pa; 103 pci_intr_handle_t *ihp; 104 { 105 pcitag_t bustag = pa->pa_intrtag; 106 pci_chipset_tag_t pc = pa->pa_pc; 107 int buspin, device, pirq; 108 pcireg_t pirqreg; 109 u_int8_t pirqline; 110 111 if (pa->pa_bridgetag) { 112 buspin = PPB_INTERRUPT_SWIZZLE(pa->pa_rawintrpin, 113 pa->pa_device); 114 if (pa->pa_bridgeih[buspin - 1] != 0) { 115 *ihp = pa->pa_bridgeih[buspin - 1]; 116 return 0; 117 } 118 119 return 1; 120 } 121 122 buspin = pa->pa_intrpin; 123 pci_decompose_tag(pc, bustag, NULL, &device, NULL); 124 125 switch (device) { 126 case 6: /* NCR SCSI */ 127 pirq = 3; 128 break; 129 130 case 11: /* slot 1 */ 131 switch (buspin) { 132 default: 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 }; 144 break; 145 146 case 12: /* slot 2 */ 147 switch (buspin) { 148 default: 149 case PCI_INTERRUPT_PIN_A: 150 case PCI_INTERRUPT_PIN_D: 151 pirq = 1; 152 break; 153 case PCI_INTERRUPT_PIN_B: 154 pirq = 0; 155 break; 156 case PCI_INTERRUPT_PIN_C: 157 pirq = 2; 158 break; 159 }; 160 break; 161 162 case 8: /* slot 3 */ 163 switch (buspin) { 164 default: 165 case PCI_INTERRUPT_PIN_A: 166 case PCI_INTERRUPT_PIN_D: 167 pirq = 2; 168 break; 169 case PCI_INTERRUPT_PIN_B: 170 pirq = 1; 171 break; 172 case PCI_INTERRUPT_PIN_C: 173 pirq = 0; 174 break; 175 }; 176 break; 177 178 default: 179 return 1; 180 } 181 182 pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0), 183 SIO_PCIREG_PIRQ_RTCTRL); 184 185 pirqline = (pirqreg >> (pirq * 8)) & 0xff; 186 if ((pirqline & 0x80) != 0) 187 return 1; /* not routed? */ 188 pirqline &= 0xf; 189 190 *ihp = pirqline; 191 return (0); 192 } 193 194 const char * 195 dec_axppci_33_intr_string(lcv, ih) 196 void *lcv; 197 pci_intr_handle_t ih; 198 { 199 return sio_intr_string(NULL /*XXX*/, ih); 200 } 201 202 int 203 dec_axppci_33_intr_line(lcv, ih) 204 void *lcv; 205 pci_intr_handle_t ih; 206 { 207 return sio_intr_line(NULL /*XXX*/, ih); 208 } 209 210 void * 211 dec_axppci_33_intr_establish(lcv, ih, level, func, arg, name) 212 void *lcv, *arg; 213 pci_intr_handle_t ih; 214 int level; 215 int (*func)(void *); 216 const char *name; 217 { 218 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func, 219 arg, name); 220 } 221 222 void 223 dec_axppci_33_intr_disestablish(lcv, cookie) 224 void *lcv, *cookie; 225 { 226 sio_intr_disestablish(NULL /*XXX*/, cookie); 227 } 228