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