1 /* $NetBSD: isa_hades.c,v 1.9 2009/03/18 10:22:25 cegger Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Leo Weppelman. 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> 33 __KERNEL_RCSID(0, "$NetBSD: isa_hades.c,v 1.9 2009/03/18 10:22:25 cegger Exp $"); 34 35 #include <sys/types.h> 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/device.h> 39 40 #include <dev/isa/isavar.h> 41 #include <dev/isa/isareg.h> 42 43 #include <m68k/asm_single.h> 44 45 #include <machine/iomap.h> 46 #include <machine/mfp.h> 47 48 void isa_bus_init(void); 49 50 void 51 isa_bus_init(void) 52 { 53 } 54 55 /* 56 * The interrupt stuff is rather ugly. On the Hades, all interrupt lines 57 * for a slot are wired together and connected to either IO3 (slot1) or 58 * IO7 (slot2). Since no info can be obtained about the slot position 59 * at isa_intr_establish() time, the following assumption is made: 60 * - irq <= 6 -> slot 1 61 * - irq > 6 -> slot 2 62 */ 63 64 #define SLOTNR(irq) ((irq <= 6) ? 0 : 1) 65 66 static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } }; 67 68 static int iifun(int, int); 69 70 static int 71 iifun(int slot, int sr) 72 { 73 isa_intr_info_t *iinfo_p; 74 int s; 75 76 iinfo_p = &iinfo[slot]; 77 78 /* 79 * Disable the interrupts 80 */ 81 if (slot == 0) { 82 single_inst_bclr_b(MFP->mf_imrb, IB_ISA1); 83 } 84 else { 85 single_inst_bclr_b(MFP->mf_imra, IA_ISA2); 86 } 87 88 if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) { 89 /* 90 * We're running at a too high priority now. 91 */ 92 add_sicallback((si_farg)iifun, (void*)slot, 0); 93 } 94 else { 95 s = splx(iinfo_p->ipl); 96 if (slot == 0) { 97 do { 98 MFP->mf_iprb = (u_int8_t)~IB_ISA1; 99 (void) (iinfo_p->ifunc)(iinfo_p->iarg); 100 } while (MFP->mf_iprb & IB_ISA1); 101 single_inst_bset_b(MFP->mf_imrb, IB_ISA1); 102 } 103 else { 104 do { 105 MFP->mf_ipra = (u_int8_t)~IA_ISA2; 106 (void) (iinfo_p->ifunc)(iinfo_p->iarg); 107 } while (MFP->mf_ipra & IA_ISA2); 108 single_inst_bset_b(MFP->mf_imra, IA_ISA2); 109 } 110 splx(s); 111 } 112 return 1; 113 } 114 115 116 /* 117 * XXXX 118 * XXXX Note that this function is not really working yet! The big problem is 119 * XXXX to only generate interrupts for the slot the card is in... 120 */ 121 int 122 isa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq) 123 { 124 isa_intr_info_t *iinfo_p; 125 int slot, i; 126 127 128 /* 129 * The Hades only supports edge triggered interrupts! 130 */ 131 if (type != IST_EDGE) 132 return 1; 133 134 #define MAXIRQ 10 /* XXX: Pure fiction */ 135 for (i = 0; i < MAXIRQ; i++) { 136 if (mask & (1<<i)) { 137 slot = SLOTNR(i); 138 iinfo_p = &iinfo[slot]; 139 140 if (iinfo_p->slot < 0) { 141 *irq = i; 142 printf("WARNING: isa_intr_alloc is not yet ready!\n" 143 " make sure the card is in slot %d!\n", 144 slot); 145 return 0; 146 } 147 } 148 } 149 return (1); 150 } 151 void * 152 isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, int level, int (*ih_fun)(void *), void *ih_arg) 153 { 154 isa_intr_info_t *iinfo_p; 155 struct intrhand *ihand; 156 int slot; 157 158 /* 159 * The Hades only supports edge triggered interrupts! 160 */ 161 if (type != IST_EDGE) 162 return NULL; 163 164 slot = SLOTNR(irq); 165 iinfo_p = &iinfo[slot]; 166 167 if (iinfo_p->slot >= 0) 168 panic("isa_intr_establish: interrupt was already established"); 169 170 ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0, 171 (hw_ifun_t)iifun, (void *)slot); 172 if (ihand != NULL) { 173 iinfo_p->slot = slot; 174 iinfo_p->ipl = level; 175 iinfo_p->ifunc = ih_fun; 176 iinfo_p->iarg = ih_arg; 177 iinfo_p->ihand = ihand; 178 179 /* 180 * Enable (unmask) the interrupt 181 */ 182 if (slot == 0) { 183 single_inst_bset_b(MFP->mf_imrb, IB_ISA1); 184 single_inst_bset_b(MFP->mf_ierb, IB_ISA1); 185 } 186 else { 187 single_inst_bset_b(MFP->mf_imra, IA_ISA2); 188 single_inst_bset_b(MFP->mf_iera, IA_ISA2); 189 } 190 return(iinfo_p); 191 } 192 return NULL; 193 } 194 195 void 196 isa_intr_disestablish(isa_chipset_tag_t ic, void *handler) 197 { 198 isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler; 199 200 if (iinfo_p->slot < 0) 201 panic("isa_intr_disestablish: interrupt was not established"); 202 203 (void) intr_disestablish(iinfo_p->ihand); 204 iinfo_p->slot = -1; 205 } 206