1 /* $OpenBSD: pci_2100_a50.c,v 1.26 2024/09/20 02:00:46 jsg Exp $ */ 2 /* $NetBSD: pci_2100_a50.c,v 1.12 1996/11/13 21:13:29 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 6 * All rights reserved. 7 * 8 * Author: 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/param.h> 32 #include <sys/time.h> 33 #include <sys/systm.h> 34 #include <sys/errno.h> 35 #include <sys/device.h> 36 #include <uvm/uvm_extern.h> 37 38 #include <machine/autoconf.h> 39 #include <machine/bus.h> 40 #include <machine/intr.h> 41 42 #include <dev/isa/isavar.h> 43 #include <dev/pci/pcireg.h> 44 #include <dev/pci/pcivar.h> 45 #include <dev/pci/ppbreg.h> 46 47 #include <alpha/pci/apecsvar.h> 48 49 #include <alpha/pci/pci_2100_a50.h> 50 #include <alpha/pci/siovar.h> 51 #include <alpha/pci/sioreg.h> 52 53 #include "sio.h" 54 55 int dec_2100_a50_intr_map(struct pci_attach_args *, pci_intr_handle_t *); 56 const char *dec_2100_a50_intr_string(void *, pci_intr_handle_t); 57 int dec_2100_a50_intr_line(void *, pci_intr_handle_t); 58 void *dec_2100_a50_intr_establish(void *, pci_intr_handle_t, 59 int, int (*func)(void *), void *, const char *); 60 void dec_2100_a50_intr_disestablish(void *, void *); 61 62 #define APECS_SIO_DEVICE 7 /* XXX */ 63 64 void 65 pci_2100_a50_pickintr(acp) 66 struct apecs_config *acp; 67 { 68 bus_space_tag_t iot = &acp->ac_iot; 69 pci_chipset_tag_t pc = &acp->ac_pc; 70 pcireg_t sioclass; 71 int sioII; 72 73 /* XXX MAGIC NUMBER */ 74 sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, 7, 0), PCI_CLASS_REG); 75 sioII = (sioclass & 0xff) >= 3; 76 77 if (!sioII) 78 printf("WARNING: SIO NOT SIO II... NO BETS...\n"); 79 80 pc->pc_intr_v = acp; 81 pc->pc_intr_map = dec_2100_a50_intr_map; 82 pc->pc_intr_string = dec_2100_a50_intr_string; 83 pc->pc_intr_line = dec_2100_a50_intr_line; 84 pc->pc_intr_establish = dec_2100_a50_intr_establish; 85 pc->pc_intr_disestablish = dec_2100_a50_intr_disestablish; 86 87 /* Not supported on 2100 A50. */ 88 pc->pc_pciide_compat_intr_establish = NULL; 89 pc->pc_pciide_compat_intr_disestablish = NULL; 90 91 #if NSIO 92 sio_intr_setup(pc, iot); 93 #else 94 panic("pci_2100_a50_pickintr: no I/O interrupt handler (no sio)"); 95 #endif 96 } 97 98 int 99 dec_2100_a50_intr_map(pa, ihp) 100 struct pci_attach_args *pa; 101 pci_intr_handle_t *ihp; 102 { 103 pcitag_t bustag = pa->pa_intrtag; 104 pci_chipset_tag_t pc = pa->pa_pc; 105 int buspin, device, pirq; 106 pcireg_t pirqreg; 107 u_int8_t pirqline; 108 109 if (pa->pa_bridgetag) { 110 buspin = PPB_INTERRUPT_SWIZZLE(pa->pa_rawintrpin, 111 pa->pa_device); 112 if (pa->pa_bridgeih[buspin - 1] != 0) { 113 *ihp = pa->pa_bridgeih[buspin - 1]; 114 return 0; 115 } 116 117 return 1; 118 } 119 120 buspin = pa->pa_intrpin; 121 pci_decompose_tag(pc, bustag, NULL, &device, NULL); 122 123 switch (device) { 124 case 6: /* NCR SCSI */ 125 pirq = 3; 126 break; 127 128 case 11: /* slot 1 */ 129 case 14: /* slot 3 */ 130 switch (buspin) { 131 default: 132 case PCI_INTERRUPT_PIN_A: 133 case PCI_INTERRUPT_PIN_D: 134 pirq = 0; 135 break; 136 case PCI_INTERRUPT_PIN_B: 137 pirq = 2; 138 break; 139 case PCI_INTERRUPT_PIN_C: 140 pirq = 1; 141 break; 142 } 143 break; 144 145 case 12: /* slot 2 */ 146 switch (buspin) { 147 default: 148 case PCI_INTERRUPT_PIN_A: 149 case PCI_INTERRUPT_PIN_D: 150 pirq = 1; 151 break; 152 case PCI_INTERRUPT_PIN_B: 153 pirq = 0; 154 break; 155 case PCI_INTERRUPT_PIN_C: 156 pirq = 2; 157 break; 158 } 159 break; 160 161 case 13: /* slot 3 */ 162 switch (buspin) { 163 default: 164 case PCI_INTERRUPT_PIN_A: 165 case PCI_INTERRUPT_PIN_D: 166 pirq = 2; 167 break; 168 case PCI_INTERRUPT_PIN_B: 169 pirq = 1; 170 break; 171 case PCI_INTERRUPT_PIN_C: 172 pirq = 0; 173 break; 174 } 175 break; 176 177 default: 178 printf("dec_2100_a50_intr_map: don't know how to setup %d/%d/%d\n", 179 pa->pa_bus, pa->pa_device, pa->pa_function); 180 return 1; 181 } 182 183 pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, APECS_SIO_DEVICE, 0), 184 SIO_PCIREG_PIRQ_RTCTRL); 185 pirqline = (pirqreg >> (pirq * 8)) & 0xff; 186 if ((pirqline & 0x80) != 0) 187 return 1; 188 pirqline &= 0xf; 189 190 *ihp = pirqline; 191 return 0; 192 } 193 194 const char * 195 dec_2100_a50_intr_string(acv, ih) 196 void *acv; 197 pci_intr_handle_t ih; 198 { 199 return sio_intr_string(NULL /*XXX*/, ih); 200 } 201 202 int 203 dec_2100_a50_intr_line(acv, ih) 204 void *acv; 205 pci_intr_handle_t ih; 206 { 207 return sio_intr_line(NULL /*XXX*/, ih); 208 } 209 210 void * 211 dec_2100_a50_intr_establish(acv, ih, level, func, arg, name) 212 void *acv, *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_2100_a50_intr_disestablish(acv, cookie) 224 void *acv, *cookie; 225 { 226 sio_intr_disestablish(NULL /*XXX*/, cookie); 227 } 228