pci_up1000.c revision 1.14
1/* $OpenBSD: pci_up1000.c,v 1.14 2008/07/22 18:45:51 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/pciidereg.h> 51#include <dev/pci/pciidevar.h> 52 53#include <alpha/pci/irongatevar.h> 54 55#include <alpha/pci/pci_up1000.h> 56#include <alpha/pci/siovar.h> 57#include <alpha/pci/sioreg.h> 58 59#include "sio.h" 60 61int api_up1000_intr_map(struct pci_attach_args *, pci_intr_handle_t *); 62const char *api_up1000_intr_string(void *, pci_intr_handle_t); 63int api_up1000_intr_line(void *, pci_intr_handle_t); 64void *api_up1000_intr_establish(void *, pci_intr_handle_t, 65 int, int (*func)(void *), void *, char *); 66void api_up1000_intr_disestablish(void *, void *); 67 68void *api_up1000_pciide_compat_intr_establish(void *, struct device *, 69 struct pci_attach_args *, int, int (*)(void *), void *); 70void api_up1000_pciide_compat_intr_disestablish(void *, void *); 71 72void 73pci_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 97int 98api_up1000_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp) 99{ 100 pcitag_t bustag = pa->pa_intrtag; 101 int buspin = pa->pa_intrpin, line = pa->pa_intrline; 102 pci_chipset_tag_t pc = pa->pa_pc; 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#ifdef DIAGNOSTIC 130 printf("api_up1000_intr_map: ISA IRQ too large (%d)\n", 131 line); 132#endif 133 return (1); 134 } 135 if (line == 2) { 136#ifdef DIAGNOSTIC 137 printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n"); 138#endif 139 line = 9; 140 } 141 142 *ihp = line; 143 return (0); 144} 145 146const char * 147api_up1000_intr_string(void *icv, pci_intr_handle_t ih) 148{ 149#if 0 150 struct irongate_config *icp = icv; 151#endif 152 153 return sio_intr_string(NULL /*XXX*/, ih); 154} 155 156int 157api_up1000_intr_line(void *icv, pci_intr_handle_t ih) 158{ 159 return sio_intr_line(NULL /*XXX*/, ih); 160} 161 162void * 163api_up1000_intr_establish(void *icv, pci_intr_handle_t ih, int level, 164 int (*func)(void *), void *arg, char *name) 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, name); 172} 173 174void 175api_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 184void * 185api_up1000_pciide_compat_intr_establish(void *icv, struct device *dev, 186 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 192 pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL); 193 194 /* 195 * If this isn't PCI bus #0, all bets are off. 196 */ 197 if (bus != 0) 198 return (NULL); 199 200 irq = PCIIDE_COMPAT_IRQ(chan); 201#if NSIO 202 cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO, 203 func, arg, dev->dv_xname); 204 if (cookie == NULL) 205 return (NULL); 206#endif 207 return (cookie); 208} 209 210void 211api_up1000_pciide_compat_intr_disestablish(void *v, void *cookie) 212{ 213 sio_intr_disestablish(NULL, cookie); 214} 215