1 /* $NetBSD: intreg.c,v 1.23 2005/12/11 12:19:27 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Adam Glass and Gordon W. Ross. 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * This handles multiple attach of autovectored interrupts, 41 * and the handy software interrupt request register. 42 */ 43 44 #include <sys/cdefs.h> 45 __KERNEL_RCSID(0, "$NetBSD: intreg.c,v 1.23 2005/12/11 12:19:27 christos Exp $"); 46 47 #include <sys/param.h> 48 #include <sys/systm.h> 49 #include <sys/device.h> 50 #include <sys/vmmeter.h> 51 52 #include <uvm/uvm_extern.h> 53 54 #include <m68k/asm_single.h> 55 56 #include <machine/autoconf.h> 57 #include <machine/cpu.h> 58 #include <machine/mon.h> 59 60 #include <sun3/sun3/interreg.h> 61 #include <sun3/sun3/machdep.h> 62 63 struct intreg_softc { 64 struct device sc_dev; 65 volatile u_char *sc_reg; 66 }; 67 68 static int intreg_match(struct device *, struct cfdata *, void *); 69 static void intreg_attach(struct device *, struct device *, void *); 70 static int soft1intr(void *); 71 72 CFATTACH_DECL(intreg, sizeof(struct intreg_softc), 73 intreg_match, intreg_attach, NULL, NULL); 74 75 volatile u_char *interrupt_reg; 76 int intreg_attached; 77 78 /* called early (by internal_configure) */ 79 void 80 intreg_init(void) 81 { 82 interrupt_reg = obio_find_mapping(IREG_ADDR, 1); 83 if (!interrupt_reg) { 84 mon_printf("intreg_init\n"); 85 sunmon_abort(); 86 } 87 /* Turn off all interrupts until clock_attach */ 88 *interrupt_reg = 0; 89 } 90 91 92 static int 93 intreg_match(struct device *parent, struct cfdata *cf, void *args) 94 { 95 struct confargs *ca = args; 96 97 /* This driver only supports one instance. */ 98 if (intreg_attached) 99 return (0); 100 101 /* Validate the given address. */ 102 if (ca->ca_paddr != IREG_ADDR) 103 return (0); 104 105 return (1); 106 } 107 108 109 static void 110 intreg_attach(struct device *parent, struct device *self, void *args) 111 { 112 struct intreg_softc *sc = (void *)self; 113 114 printf("\n"); 115 116 sc->sc_reg = interrupt_reg; 117 118 /* Install handler for our "soft" interrupt. */ 119 isr_add_autovect(soft1intr, (void *)sc, 1); 120 intreg_attached = 1; 121 } 122 123 124 /* 125 * Level 1 software interrupt. 126 * Possible reasons: 127 * Network software interrupt 128 * Soft clock interrupt 129 */ 130 static int 131 soft1intr(void *arg) 132 { 133 union sun3sir sir; 134 int s; 135 136 s = splhigh(); 137 sir.sir_any = sun3sir.sir_any; 138 sun3sir.sir_any = 0; 139 isr_soft_clear(1); 140 splx(s); 141 142 if (sir.sir_any) { 143 uvmexp.softs++; 144 if (sir.sir_which[SIR_NET]) { 145 sir.sir_which[SIR_NET] = 0; 146 netintr(); 147 } 148 if (sir.sir_which[SIR_CLOCK]) { 149 sir.sir_which[SIR_CLOCK] = 0; 150 softclock(NULL); 151 } 152 if (sir.sir_which[SIR_SPARE2]) { 153 sir.sir_which[SIR_SPARE2] = 0; 154 /* spare2intr(); */ 155 } 156 if (sir.sir_which[SIR_SPARE3]) { 157 sir.sir_which[SIR_SPARE3] = 0; 158 /* spare3intr(); */ 159 } 160 return (1); 161 } 162 return(0); 163 } 164 165 166 void 167 isr_soft_request(int level) 168 { 169 u_char bit; 170 171 if ((level < 1) || (level > 3)) 172 return; 173 174 bit = 1 << level; 175 single_inst_bset_b(*interrupt_reg, bit); 176 } 177 178 void 179 isr_soft_clear(int level) 180 { 181 u_char bit; 182 183 if ((level < 1) || (level > 3)) 184 return; 185 186 bit = 1 << level; 187 single_inst_bclr_b(*interrupt_reg, bit); 188 } 189 190