1 /* $NetBSD: pci_up1000.c,v 1.15 2014/03/21 16:39:29 christos 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.15 2014/03/21 16:39:29 christos 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 <sys/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(const struct pci_attach_args *, 63 pci_intr_handle_t *); 64 const char *api_up1000_intr_string(void *, pci_intr_handle_t, char *, size_t); 65 const struct evcnt *api_up1000_intr_evcnt(void *, pci_intr_handle_t); 66 void *api_up1000_intr_establish(void *, pci_intr_handle_t, 67 int, int (*func)(void *), void *); 68 void api_up1000_intr_disestablish(void *, void *); 69 70 void *api_up1000_pciide_compat_intr_establish(void *, device_t, 71 const struct pci_attach_args *, int, int (*)(void *), void *); 72 73 void 74 pci_up1000_pickintr(struct irongate_config *icp) 75 { 76 #if NSIO 77 bus_space_tag_t iot = &icp->ic_iot; 78 pci_chipset_tag_t pc = &icp->ic_pc; 79 80 pc->pc_intr_v = icp; 81 pc->pc_intr_map = api_up1000_intr_map; 82 pc->pc_intr_string = api_up1000_intr_string; 83 pc->pc_intr_evcnt = api_up1000_intr_evcnt; 84 pc->pc_intr_establish = api_up1000_intr_establish; 85 pc->pc_intr_disestablish = api_up1000_intr_disestablish; 86 87 pc->pc_pciide_compat_intr_establish = 88 api_up1000_pciide_compat_intr_establish; 89 90 sio_intr_setup(pc, iot); 91 #else 92 panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)"); 93 #endif 94 } 95 96 int 97 api_up1000_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp) 98 { 99 pci_chipset_tag_t pc = pa->pa_pc; 100 int buspin = pa->pa_intrpin; 101 int bustag = pa->pa_intrtag; 102 int line = pa->pa_intrline; 103 int bus, device, function; 104 105 if (buspin == 0) { 106 /* No IRQ used. */ 107 return 1; 108 } 109 if (buspin > 4) { 110 printf("api_up1000_intr_map: bad interrupt pin %d\n", 111 buspin); 112 return 1; 113 } 114 115 pci_decompose_tag(pc, bustag, &bus, &device, &function); 116 117 /* 118 * The console places the interrupt mapping in the "line" value. 119 * A value of (char)-1 indicates there is no mapping. 120 */ 121 if (line == 0xff) { 122 printf("api_up1000_intr_map: no mapping for %d/%d/%d\n", 123 bus, device, function); 124 return (1); 125 } 126 127 /* XXX Check for 0? */ 128 if (line > 15) { 129 printf("api_up1000_intr_map: ISA IRQ too large (%d)\n", 130 line); 131 return (1); 132 } 133 if (line == 2) { 134 printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n"); 135 line = 9; 136 } 137 138 *ihp = line; 139 return (0); 140 } 141 142 const char * 143 api_up1000_intr_string(void *icv, pci_intr_handle_t ih, char *buf, size_t len) 144 { 145 #if 0 146 struct irongate_config *icp = icv; 147 #endif 148 149 return sio_intr_string(NULL /*XXX*/, ih, buf, len); 150 } 151 152 const struct evcnt * 153 api_up1000_intr_evcnt(void *icv, pci_intr_handle_t ih) 154 { 155 #if 0 156 struct irongate_config *icp = icv; 157 #endif 158 159 return sio_intr_evcnt(NULL /*XXX*/, ih); 160 } 161 162 void * 163 api_up1000_intr_establish(void *icv, pci_intr_handle_t ih, int level, 164 int (*func)(void *), void *arg) 165 { 166 #if 0 167 struct irongate_config *icp = icv; 168 #endif 169 170 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func, 171 arg); 172 } 173 174 void 175 api_up1000_intr_disestablish(void *icv, void *cookie) 176 { 177 #if 0 178 struct irongate_config *icp = icv; 179 #endif 180 181 sio_intr_disestablish(NULL /*XXX*/, cookie); 182 } 183 184 void * 185 api_up1000_pciide_compat_intr_establish(void *icv, device_t dev, 186 const struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg) 187 { 188 pci_chipset_tag_t pc = pa->pa_pc; 189 void *cookie = NULL; 190 int bus, irq; 191 char buf[64]; 192 193 pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL); 194 195 /* 196 * If this isn't PCI bus #0, all bets are off. 197 */ 198 if (bus != 0) 199 return (NULL); 200 201 irq = PCIIDE_COMPAT_IRQ(chan); 202 #if NSIO 203 cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO, 204 func, arg); 205 if (cookie == NULL) 206 return (NULL); 207 aprint_normal_dev(dev, "%s channel interrupting at %s\n", 208 PCIIDE_CHANNEL_NAME(chan), sio_intr_string(NULL /*XXX*/, irq, buf, 209 sizeof(buf))); 210 #endif 211 return (cookie); 212 } 213