1 1.16 tsutsui /* $NetBSD: isa_milan.c,v 1.16 2018/01/20 19:36:47 tsutsui Exp $ */ 2 1.1 leo 3 1.1 leo /*- 4 1.1 leo * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 1.1 leo * All rights reserved. 6 1.1 leo * 7 1.1 leo * This code is derived from software contributed to The NetBSD Foundation 8 1.1 leo * by Leo Weppelman. 9 1.1 leo * 10 1.1 leo * Redistribution and use in source and binary forms, with or without 11 1.1 leo * modification, are permitted provided that the following conditions 12 1.1 leo * are met: 13 1.1 leo * 1. Redistributions of source code must retain the above copyright 14 1.1 leo * notice, this list of conditions and the following disclaimer. 15 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 leo * notice, this list of conditions and the following disclaimer in the 17 1.1 leo * documentation and/or other materials provided with the distribution. 18 1.1 leo * 19 1.1 leo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 leo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 leo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 leo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 leo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 leo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 leo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 leo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 leo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 leo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 leo * POSSIBILITY OF SUCH DAMAGE. 30 1.1 leo */ 31 1.7 lukem 32 1.7 lukem #include <sys/cdefs.h> 33 1.16 tsutsui __KERNEL_RCSID(0, "$NetBSD: isa_milan.c,v 1.16 2018/01/20 19:36:47 tsutsui Exp $"); 34 1.1 leo 35 1.1 leo #include <sys/types.h> 36 1.1 leo #include <sys/param.h> 37 1.1 leo #include <sys/systm.h> 38 1.1 leo #include <sys/device.h> 39 1.1 leo 40 1.1 leo #include <dev/isa/isavar.h> 41 1.1 leo #include <dev/isa/isareg.h> 42 1.1 leo 43 1.1 leo #include <machine/iomap.h> 44 1.1 leo 45 1.1 leo void isa_bus_init(void); 46 1.5 leo 47 1.5 leo static void new_imask(void); 48 1.3 leo static void isa_callback(int); 49 1.1 leo 50 1.1 leo /* 51 1.5 leo * Bitmask of currently enabled isa interrupts. Used by new_imask(). 52 1.1 leo */ 53 1.1 leo static u_int16_t imask_enable = 0xffff; 54 1.1 leo 55 1.5 leo #define IRQ_SLAVE 2 /* Slave at level 2 */ 56 1.5 leo #define MILAN_MAX_ISA_INTS 16 /* Max. number of vectors */ 57 1.5 leo #define ICU_OFFSET 0 /* Interrupt vector base */ 58 1.1 leo 59 1.5 leo #define WICU(icu, val) *(volatile u_int8_t*)(icu) = val 60 1.1 leo 61 1.1 leo static isa_intr_info_t milan_isa_iinfo[MILAN_MAX_ISA_INTS]; 62 1.1 leo 63 1.1 leo void 64 1.14 cegger isa_bus_init(void) 65 1.1 leo { 66 1.5 leo volatile u_int8_t *icu; 67 1.1 leo 68 1.5 leo /* 69 1.5 leo * Initialize both the icu's: 70 1.5 leo * - enter Special Mask Mode 71 1.5 leo * - Block all interrupts 72 1.5 leo */ 73 1.1 leo icu = (u_int8_t*)(AD_8259_MASTER); 74 1.1 leo 75 1.1 leo icu[0] = 0x11; /* reset; program device, four bytes */ 76 1.1 leo icu[1] = ICU_OFFSET; /* starting at this vector index */ 77 1.1 leo icu[1] = (1 << IRQ_SLAVE); /* slave on line 2 */ 78 1.1 leo icu[1] = 1; /* 8086 mode */ 79 1.1 leo icu[1] = 0xff; /* leave interrupts masked */ 80 1.5 leo icu[0] = 0x68; /* special mask mode */ 81 1.5 leo icu[0] = 0x0a; /* Read IRR by default. */ 82 1.1 leo 83 1.1 leo icu = (u_int8_t*)(AD_8259_SLAVE); 84 1.1 leo 85 1.1 leo icu[0] = 0x11; /* reset; program device, four bytes */ 86 1.1 leo icu[1] = ICU_OFFSET + 8; /* starting at this vector index */ 87 1.1 leo icu[1] = IRQ_SLAVE; /* slave on line 2 */ 88 1.1 leo icu[1] = 1; /* 8086 mode */ 89 1.1 leo icu[1] = 0xff; /* leave interrupts masked */ 90 1.5 leo icu[0] = 0x68; /* special mask mode */ 91 1.5 leo icu[0] = 0x0a; /* Read IRR by default. */ 92 1.1 leo } 93 1.1 leo 94 1.5 leo /* 95 1.5 leo * Determine and activate new interrupt mask by scanning the milan_isa_iinfo 96 1.5 leo * array for enabled interrupts. 97 1.5 leo */ 98 1.1 leo static void 99 1.14 cegger new_imask(void) 100 1.1 leo { 101 1.1 leo int irq; 102 1.1 leo u_int16_t nmask = 0; 103 1.1 leo 104 1.1 leo for (irq = 0; irq < MILAN_MAX_ISA_INTS; irq++) { 105 1.1 leo if (milan_isa_iinfo[irq].ifunc != NULL) 106 1.1 leo nmask |= 1 << irq; 107 1.1 leo if (nmask >= 0x100) 108 1.1 leo nmask |= 1 << IRQ_SLAVE; 109 1.1 leo } 110 1.1 leo imask_enable = ~nmask; 111 1.5 leo WICU(AD_8259_MASTER+1, imask_enable & 0xff); 112 1.5 leo WICU(AD_8259_SLAVE+1 , (imask_enable >> 8) & 0xff); 113 1.1 leo } 114 1.1 leo 115 1.3 leo static void 116 1.11 dsl isa_callback(int vector) 117 1.3 leo { 118 1.3 leo isa_intr_info_t *iinfo_p; 119 1.3 leo int s; 120 1.3 leo 121 1.3 leo iinfo_p = &milan_isa_iinfo[vector]; 122 1.3 leo 123 1.3 leo s = splx(iinfo_p->ipl); 124 1.3 leo (void) (iinfo_p->ifunc)(iinfo_p->iarg); 125 1.16 tsutsui if (vector > 7) { 126 1.5 leo WICU(AD_8259_SLAVE, 0x60 | (vector & 7)); 127 1.16 tsutsui vector = IRQ_SLAVE; 128 1.16 tsutsui } 129 1.16 tsutsui WICU(AD_8259_MASTER, 0x60 | (vector & 7)); 130 1.3 leo splx(s); 131 1.3 leo } 132 1.1 leo 133 1.3 leo void milan_isa_intr(int, int); 134 1.1 leo void 135 1.12 dsl milan_isa_intr(int vector, int sr) 136 1.1 leo { 137 1.1 leo isa_intr_info_t *iinfo_p; 138 1.4 leo int s; 139 1.1 leo 140 1.1 leo if (vector >= MILAN_MAX_ISA_INTS) { 141 1.1 leo printf("milan_isa_intr: Bogus vector %d\n", vector); 142 1.1 leo return; 143 1.1 leo } 144 1.1 leo 145 1.1 leo iinfo_p = &milan_isa_iinfo[vector]; 146 1.3 leo if (iinfo_p->ifunc == NULL) { 147 1.1 leo printf("milan_isa_intr: Stray interrupt: %d (mask:%04x)\n", 148 1.1 leo vector, imask_enable); 149 1.3 leo return; 150 1.3 leo } 151 1.3 leo if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) { 152 1.3 leo /* 153 1.3 leo * We're running at a too high priority now. 154 1.3 leo */ 155 1.3 leo add_sicallback((si_farg)isa_callback, (void*)vector, 0); 156 1.3 leo } 157 1.3 leo else { 158 1.3 leo s = splx(iinfo_p->ipl); 159 1.3 leo (void) (iinfo_p->ifunc)(iinfo_p->iarg); 160 1.16 tsutsui if (vector > 7) { 161 1.5 leo WICU(AD_8259_SLAVE, 0x60 | (vector & 7)); 162 1.16 tsutsui vector = IRQ_SLAVE; 163 1.16 tsutsui } 164 1.16 tsutsui WICU(AD_8259_MASTER, 0x60 | (vector & 7)); 165 1.3 leo splx(s); 166 1.3 leo } 167 1.1 leo } 168 1.1 leo 169 1.1 leo /* 170 1.1 leo * Try to allocate a free interrupt... On the Milan, we have available: 171 1.1 leo * 5, 9, 10, 11, 13. Or in a bitmask: 0x1720. 172 1.1 leo */ 173 1.1 leo #define MILAN_AVAIL_ISA_INTS 0x1720 174 1.1 leo 175 1.1 leo int 176 1.11 dsl isa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq) 177 1.1 leo { 178 1.1 leo int i; 179 1.1 leo 180 1.1 leo /* 181 1.1 leo * Say no to impossible questions... 182 1.1 leo */ 183 1.1 leo if (!(mask &= MILAN_AVAIL_ISA_INTS)) 184 1.1 leo return 1; 185 1.1 leo 186 1.1 leo for (i = 0; i < MILAN_MAX_ISA_INTS; i++) { 187 1.1 leo if (mask & (1<<i)) { 188 1.1 leo if (milan_isa_iinfo[i].ifunc == NULL) { 189 1.1 leo *irq = i; 190 1.1 leo return 0; 191 1.1 leo } 192 1.1 leo } 193 1.1 leo } 194 1.1 leo return (1); 195 1.1 leo } 196 1.1 leo 197 1.1 leo void * 198 1.13 dsl isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, int level, int (*ih_fun)(void *), void *ih_arg) 199 1.1 leo { 200 1.1 leo isa_intr_info_t *iinfo_p; 201 1.1 leo 202 1.1 leo iinfo_p = &milan_isa_iinfo[irq]; 203 1.1 leo 204 1.1 leo if (iinfo_p->ifunc != NULL) { 205 1.1 leo printf("isa_intr_establish: interrupt %d was already " 206 1.1 leo "established\n", irq); 207 1.1 leo return NULL; 208 1.1 leo } 209 1.1 leo 210 1.1 leo iinfo_p->slot = 0; /* Unused on Milan */ 211 1.1 leo iinfo_p->ihand = NULL; /* Unused on Milan */ 212 1.15 tsutsui iinfo_p->ipl = ipl2psl_table[level]; 213 1.1 leo iinfo_p->ifunc = ih_fun; 214 1.1 leo iinfo_p->iarg = ih_arg; 215 1.1 leo 216 1.5 leo new_imask(); 217 1.1 leo return(iinfo_p); 218 1.1 leo } 219 1.1 leo 220 1.1 leo void 221 1.11 dsl isa_intr_disestablish(isa_chipset_tag_t ic, void *handler) 222 1.1 leo { 223 1.1 leo isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler; 224 1.1 leo 225 1.1 leo if (iinfo_p->ifunc == NULL) 226 1.6 provos panic("isa_intr_disestablish: interrupt was not established"); 227 1.1 leo 228 1.1 leo iinfo_p->ifunc = NULL; 229 1.5 leo new_imask(); 230 1.1 leo } 231