1 /* $NetBSD: intreg.c,v 1.12 1998/06/08 20:47:46 gwr 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 "opt_uvm.h" 45 46 #include <sys/param.h> 47 #include <sys/systm.h> 48 #include <sys/device.h> 49 #include <sys/vmmeter.h> 50 51 #if defined(UVM) 52 #include <vm/vm.h> 53 #include <uvm/uvm_extern.h> 54 #endif 55 56 #include <m68k/asm_single.h> 57 58 #include <machine/autoconf.h> 59 #include <machine/cpu.h> 60 #include <machine/mon.h> 61 62 #include <sun3/sun3/interreg.h> 63 #include <sun3/sun3/machdep.h> 64 65 struct intreg_softc { 66 struct device sc_dev; 67 volatile u_char *sc_reg; 68 }; 69 70 static int intreg_match __P((struct device *, struct cfdata *, void *)); 71 static void intreg_attach __P((struct device *, struct device *, void *)); 72 static int soft1intr __P((void *)); 73 74 struct cfattach intreg_ca = { 75 sizeof(struct intreg_softc), intreg_match, intreg_attach 76 }; 77 78 volatile u_char *interrupt_reg; 79 80 81 /* called early (by internal_configure) */ 82 void 83 intreg_init() 84 { 85 interrupt_reg = obio_find_mapping(IREG_ADDR, 1); 86 if (!interrupt_reg) { 87 mon_printf("intreg_init\n"); 88 sunmon_abort(); 89 } 90 /* Turn off all interrupts until clock_attach */ 91 *interrupt_reg = 0; 92 } 93 94 95 static int 96 intreg_match(parent, cf, args) 97 struct device *parent; 98 struct cfdata *cf; 99 void *args; 100 { 101 struct confargs *ca = args; 102 103 /* This driver only supports one unit. */ 104 if (cf->cf_unit != 0) 105 return (0); 106 107 /* Validate the given address. */ 108 if (ca->ca_paddr != IREG_ADDR) 109 return (0); 110 111 return (1); 112 } 113 114 115 static void 116 intreg_attach(parent, self, args) 117 struct device *parent; 118 struct device *self; 119 void *args; 120 { 121 struct intreg_softc *sc = (void *)self; 122 123 printf("\n"); 124 125 sc->sc_reg = interrupt_reg; 126 127 /* Install handler for our "soft" interrupt. */ 128 isr_add_autovect(soft1intr, (void *)sc, 1); 129 } 130 131 132 /* 133 * Level 1 software interrupt. 134 * Possible reasons: 135 * Network software interrupt 136 * Soft clock interrupt 137 */ 138 static int 139 soft1intr(arg) 140 void *arg; 141 { 142 union sun3sir sir; 143 int s; 144 145 s = splhigh(); 146 sir.sir_any = sun3sir.sir_any; 147 sun3sir.sir_any = 0; 148 isr_soft_clear(1); 149 splx(s); 150 151 if (sir.sir_any) { 152 #if defined(UVM) 153 uvmexp.softs++; 154 #else 155 cnt.v_soft++; 156 #endif 157 if (sir.sir_which[SIR_NET]) { 158 sir.sir_which[SIR_NET] = 0; 159 netintr(); 160 } 161 if (sir.sir_which[SIR_CLOCK]) { 162 sir.sir_which[SIR_CLOCK] = 0; 163 softclock(); 164 } 165 if (sir.sir_which[SIR_SPARE2]) { 166 sir.sir_which[SIR_SPARE2] = 0; 167 /* spare2intr(); */ 168 } 169 if (sir.sir_which[SIR_SPARE3]) { 170 sir.sir_which[SIR_SPARE3] = 0; 171 /* spare3intr(); */ 172 } 173 return (1); 174 } 175 return(0); 176 } 177 178 179 void isr_soft_request(level) 180 int level; 181 { 182 register u_char bit; 183 184 if ((level < 1) || (level > 3)) 185 return; 186 187 bit = 1 << level; 188 single_inst_bset_b(*interrupt_reg, bit); 189 } 190 191 void isr_soft_clear(level) 192 int level; 193 { 194 register u_char bit; 195 196 if ((level < 1) || (level > 3)) 197 return; 198 199 bit = 1 << level; 200 single_inst_bclr_b(*interrupt_reg, bit); 201 } 202 203