1 /* $OpenBSD: pci_up1000.c,v 1.17 2015/08/15 19:18:27 miod Exp $ */ 2 /* $NetBSD: pci_up1000.c,v 1.6 2000/12/28 22:59:07 sommerfeld Exp $ */ 3 4 /*- 5 * Copyright (c) 2000 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Jason R. Thorpe. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/types.h> 34 #include <sys/param.h> 35 #include <sys/time.h> 36 #include <sys/systm.h> 37 #include <sys/errno.h> 38 #include <sys/device.h> 39 40 #include <uvm/uvm_extern.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 48 #include <dev/pci/pcireg.h> 49 #include <dev/pci/pcivar.h> 50 #include <dev/pci/ppbreg.h> 51 #include <dev/pci/pciidereg.h> 52 #include <dev/pci/pciidevar.h> 53 54 #include <alpha/pci/irongatevar.h> 55 56 #include <alpha/pci/pci_up1000.h> 57 #include <alpha/pci/siovar.h> 58 59 #include "sio.h" 60 61 int api_up1000_intr_map(struct pci_attach_args *, pci_intr_handle_t *); 62 const char *api_up1000_intr_string(void *, pci_intr_handle_t); 63 int api_up1000_intr_line(void *, pci_intr_handle_t); 64 void *api_up1000_intr_establish(void *, pci_intr_handle_t, 65 int, int (*func)(void *), void *, const char *); 66 void api_up1000_intr_disestablish(void *, void *); 67 68 void *api_up1000_pciide_compat_intr_establish(void *, struct device *, 69 struct pci_attach_args *, int, int (*)(void *), void *); 70 void api_up1000_pciide_compat_intr_disestablish(void *, void *); 71 72 void 73 pci_up1000_pickintr(struct irongate_config *icp) 74 { 75 bus_space_tag_t iot = &icp->ic_iot; 76 pci_chipset_tag_t pc = &icp->ic_pc; 77 78 pc->pc_intr_v = icp; 79 pc->pc_intr_map = api_up1000_intr_map; 80 pc->pc_intr_string = api_up1000_intr_string; 81 pc->pc_intr_line = api_up1000_intr_line; 82 pc->pc_intr_establish = api_up1000_intr_establish; 83 pc->pc_intr_disestablish = api_up1000_intr_disestablish; 84 85 pc->pc_pciide_compat_intr_establish = 86 api_up1000_pciide_compat_intr_establish; 87 pc->pc_pciide_compat_intr_disestablish = 88 api_up1000_pciide_compat_intr_disestablish; 89 90 #if NSIO 91 sio_intr_setup(pc, iot); 92 #else 93 panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)"); 94 #endif 95 } 96 97 int 98 api_up1000_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp) 99 { 100 int buspin, line = pa->pa_intrline; 101 102 /* 103 * The console places the interrupt mapping in the "line" value. 104 * We trust it whenever possible. 105 */ 106 if (line >= 0 && line <= 15) { 107 if (line == 2) { 108 #ifdef DEBUG 109 printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n"); 110 #endif 111 line = 9; 112 } 113 114 *ihp = line; 115 return 0; 116 } 117 118 if (pa->pa_bridgetag) { 119 buspin = PPB_INTERRUPT_SWIZZLE(pa->pa_rawintrpin, 120 pa->pa_device); 121 if (pa->pa_bridgeih[buspin - 1] != 0) { 122 *ihp = pa->pa_bridgeih[buspin - 1]; 123 return 0; 124 } 125 } 126 127 return 1; 128 } 129 130 const char * 131 api_up1000_intr_string(void *icv, pci_intr_handle_t ih) 132 { 133 #if 0 134 struct irongate_config *icp = icv; 135 #endif 136 137 return sio_intr_string(NULL /*XXX*/, ih); 138 } 139 140 int 141 api_up1000_intr_line(void *icv, pci_intr_handle_t ih) 142 { 143 return sio_intr_line(NULL /*XXX*/, ih); 144 } 145 146 void * 147 api_up1000_intr_establish(void *icv, pci_intr_handle_t ih, int level, 148 int (*func)(void *), void *arg, const char *name) 149 { 150 #if 0 151 struct irongate_config *icp = icv; 152 #endif 153 154 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func, 155 arg, name); 156 } 157 158 void 159 api_up1000_intr_disestablish(void *icv, void *cookie) 160 { 161 #if 0 162 struct irongate_config *icp = icv; 163 #endif 164 165 sio_intr_disestablish(NULL /*XXX*/, cookie); 166 } 167 168 void * 169 api_up1000_pciide_compat_intr_establish(void *icv, struct device *dev, 170 struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg) 171 { 172 pci_chipset_tag_t pc = pa->pa_pc; 173 void *cookie = NULL; 174 int bus, irq; 175 176 pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL); 177 178 /* 179 * If this isn't PCI bus #0, all bets are off. 180 */ 181 if (bus != 0) 182 return (NULL); 183 184 irq = PCIIDE_COMPAT_IRQ(chan); 185 #if NSIO 186 cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO, 187 func, arg, dev->dv_xname); 188 if (cookie == NULL) 189 return (NULL); 190 #endif 191 return (cookie); 192 } 193 194 void 195 api_up1000_pciide_compat_intr_disestablish(void *v, void *cookie) 196 { 197 sio_intr_disestablish(NULL, cookie); 198 } 199