1 /* $OpenBSD: pci_alphabook1.c,v 1.4 2015/08/15 19:18:27 miod Exp $ */ 2 /* $NetBSD: pci_alphabook1.c,v 1.16 2012/02/06 02:14:15 matt Exp $ */ 3 4 /*- 5 * Copyright (c) 1998 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 of the Numerical Aerospace Simulation Facility, 10 * NASA Ames Research Center. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 36 * All rights reserved. 37 * 38 * Authors: Jeffrey Hsu and Chris G. Demetriou 39 * 40 * Permission to use, copy, modify and distribute this software and 41 * its documentation is hereby granted, provided that both the copyright 42 * notice and this permission notice appear in all copies of the 43 * software, derivative works or modified versions, and any portions 44 * thereof, and that both notices appear in supporting documentation. 45 * 46 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 47 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 48 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 49 * 50 * Carnegie Mellon requests users of this software to return to 51 * 52 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 53 * School of Computer Science 54 * Carnegie Mellon University 55 * Pittsburgh PA 15213-3890 56 * 57 * any improvements or extensions that they make and grant Carnegie the 58 * rights to redistribute these changes. 59 */ 60 61 #include <sys/types.h> 62 #include <sys/param.h> 63 #include <sys/time.h> 64 #include <sys/systm.h> 65 #include <sys/errno.h> 66 #include <sys/device.h> 67 68 #include <machine/intr.h> 69 70 #include <dev/isa/isavar.h> 71 #include <dev/pci/pcireg.h> 72 #include <dev/pci/pcivar.h> 73 #include <dev/pci/ppbreg.h> 74 75 #include <alpha/pci/lcavar.h> 76 77 #include <alpha/pci/pci_alphabook1.h> 78 #include <alpha/pci/siovar.h> 79 80 #include "sio.h" 81 82 int dec_alphabook1_intr_map(struct pci_attach_args *, 83 pci_intr_handle_t *); 84 const char *dec_alphabook1_intr_string(void *, pci_intr_handle_t); 85 int dec_alphabook1_intr_line(void *, pci_intr_handle_t); 86 void *dec_alphabook1_intr_establish(void *, pci_intr_handle_t, 87 int, int (*func)(void *), void *, const char *); 88 void dec_alphabook1_intr_disestablish(void *, void *); 89 90 #define LCA_SIO_DEVICE 7 /* XXX */ 91 92 void 93 pci_alphabook1_pickintr(struct lca_config *lcp) 94 { 95 bus_space_tag_t iot = &lcp->lc_iot; 96 pci_chipset_tag_t pc = &lcp->lc_pc; 97 pcireg_t sioclass; 98 int sioII; 99 100 /* XXX MAGIC NUMBER */ 101 sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0), 102 PCI_CLASS_REG); 103 sioII = (sioclass & 0xff) >= 3; 104 105 if (!sioII) 106 printf("WARNING: SIO NOT SIO II... NO BETS...\n"); 107 108 pc->pc_intr_v = lcp; 109 pc->pc_intr_map = dec_alphabook1_intr_map; 110 pc->pc_intr_string = dec_alphabook1_intr_string; 111 pc->pc_intr_line = dec_alphabook1_intr_line; 112 pc->pc_intr_establish = dec_alphabook1_intr_establish; 113 pc->pc_intr_disestablish = dec_alphabook1_intr_disestablish; 114 115 /* Not supported on AlphaBook. */ 116 pc->pc_pciide_compat_intr_establish = NULL; 117 118 #if NSIO 119 sio_intr_setup(pc, iot); 120 #else 121 panic("pci_alphabook1_pickintr: no I/O interrupt handler (no sio)"); 122 #endif 123 } 124 125 int 126 dec_alphabook1_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp) 127 { 128 pcitag_t bustag = pa->pa_intrtag; 129 int buspin, device; 130 131 #ifdef notyet 132 if (pa->pa_bridgetag) { 133 buspin = PPB_INTERRUPT_SWIZZLE(pa->pa_rawintrpin, 134 pa->pa_device); 135 if (pa->pa_bridgeih[buspin - 1] == 0) 136 return 1; 137 138 *ihp = pa->pa_bridgeih[buspin - 1]; 139 return 0; 140 } 141 #endif 142 143 buspin = pa->pa_intrpin; 144 pci_decompose_tag(pa->pa_pc, bustag, NULL, &device, NULL); 145 146 /* 147 * There are only two interrupting PCI devices on the AlphaBook: 148 * the SCSI and PCMCIA controllers. The other PCI device is the 149 * SIO, and there are no option slots available. 150 * 151 * NOTE! Apparently, there was a later AlphaBook which uses 152 * a different interrupt scheme, and has a built-in Tulip Ethernet 153 * interface! We do not handle that here! 154 */ 155 156 switch (device) { 157 case 6: /* NCR SCSI */ 158 *ihp = 14; 159 return 0; 160 case 8: /* Cirrus CL-PD6729 */ 161 *ihp = 15; 162 return 0; 163 default: 164 return 1; 165 } 166 } 167 168 const char * 169 dec_alphabook1_intr_string(void *lcv, pci_intr_handle_t ih) 170 { 171 return sio_intr_string(NULL /*XXX*/, ih); 172 } 173 174 int 175 dec_alphabook1_intr_line(void *lcv, pci_intr_handle_t ih) 176 { 177 return sio_intr_line(NULL /*XXX*/, ih); 178 } 179 180 void * 181 dec_alphabook1_intr_establish(void *lcv, pci_intr_handle_t ih, 182 int level, int (*func)(void *), void *arg, const char *name) 183 { 184 /* 185 * PCI interrupts on that platform are ISA interrupts in disguise, 186 * and are edge- rather than level-triggered. 187 */ 188 return sio_intr_establish(NULL /*XXX*/, ih, IST_EDGE, level, func, 189 arg, name); 190 } 191 192 void 193 dec_alphabook1_intr_disestablish(void *lcv, void *cookie) 194 { 195 sio_intr_disestablish(NULL /*XXX*/, cookie); 196 } 197