1 /* $NetBSD: intreg.c,v 1.20 2002/10/02 16:02:28 thorpej 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/param.h> 45 #include <sys/systm.h> 46 #include <sys/device.h> 47 #include <sys/vmmeter.h> 48 49 #include <uvm/uvm_extern.h> 50 51 #include <m68k/asm_single.h> 52 53 #include <machine/autoconf.h> 54 #include <machine/cpu.h> 55 #include <machine/mon.h> 56 57 #include <sun3/sun3/interreg.h> 58 #include <sun3/sun3/machdep.h> 59 60 struct intreg_softc { 61 struct device sc_dev; 62 volatile u_char *sc_reg; 63 }; 64 65 static int intreg_match __P((struct device *, struct cfdata *, void *)); 66 static void intreg_attach __P((struct device *, struct device *, void *)); 67 static int soft1intr __P((void *)); 68 69 CFATTACH_DECL(intreg, sizeof(struct intreg_softc), 70 intreg_match, intreg_attach, NULL, NULL); 71 72 volatile u_char *interrupt_reg; 73 int intreg_attached; 74 75 /* called early (by internal_configure) */ 76 void 77 intreg_init() 78 { 79 interrupt_reg = obio_find_mapping(IREG_ADDR, 1); 80 if (!interrupt_reg) { 81 mon_printf("intreg_init\n"); 82 sunmon_abort(); 83 } 84 /* Turn off all interrupts until clock_attach */ 85 *interrupt_reg = 0; 86 } 87 88 89 static int 90 intreg_match(parent, cf, args) 91 struct device *parent; 92 struct cfdata *cf; 93 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(parent, self, args) 111 struct device *parent; 112 struct device *self; 113 void *args; 114 { 115 struct intreg_softc *sc = (void *)self; 116 117 printf("\n"); 118 119 sc->sc_reg = interrupt_reg; 120 121 /* Install handler for our "soft" interrupt. */ 122 isr_add_autovect(soft1intr, (void *)sc, 1); 123 intreg_attached = 1; 124 } 125 126 127 /* 128 * Level 1 software interrupt. 129 * Possible reasons: 130 * Network software interrupt 131 * Soft clock interrupt 132 */ 133 static int 134 soft1intr(arg) 135 void *arg; 136 { 137 union sun3sir sir; 138 int s; 139 140 s = splhigh(); 141 sir.sir_any = sun3sir.sir_any; 142 sun3sir.sir_any = 0; 143 isr_soft_clear(1); 144 splx(s); 145 146 if (sir.sir_any) { 147 uvmexp.softs++; 148 if (sir.sir_which[SIR_NET]) { 149 sir.sir_which[SIR_NET] = 0; 150 netintr(); 151 } 152 if (sir.sir_which[SIR_CLOCK]) { 153 sir.sir_which[SIR_CLOCK] = 0; 154 softclock(NULL); 155 } 156 if (sir.sir_which[SIR_SPARE2]) { 157 sir.sir_which[SIR_SPARE2] = 0; 158 /* spare2intr(); */ 159 } 160 if (sir.sir_which[SIR_SPARE3]) { 161 sir.sir_which[SIR_SPARE3] = 0; 162 /* spare3intr(); */ 163 } 164 return (1); 165 } 166 return(0); 167 } 168 169 170 void isr_soft_request(level) 171 int level; 172 { 173 u_char bit; 174 175 if ((level < 1) || (level > 3)) 176 return; 177 178 bit = 1 << level; 179 single_inst_bset_b(*interrupt_reg, bit); 180 } 181 182 void isr_soft_clear(level) 183 int level; 184 { 185 u_char bit; 186 187 if ((level < 1) || (level > 3)) 188 return; 189 190 bit = 1 << level; 191 single_inst_bclr_b(*interrupt_reg, bit); 192 } 193 194