1 /* $NetBSD: intreg.c,v 1.21 2003/07/15 03:36:17 lukem 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.21 2003/07/15 03:36:17 lukem 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 __P((struct device *, struct cfdata *, void *)); 69 static void intreg_attach __P((struct device *, struct device *, void *)); 70 static int soft1intr __P((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() 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(parent, cf, args) 94 struct device *parent; 95 struct cfdata *cf; 96 void *args; 97 { 98 struct confargs *ca = args; 99 100 /* This driver only supports one instance. */ 101 if (intreg_attached) 102 return (0); 103 104 /* Validate the given address. */ 105 if (ca->ca_paddr != IREG_ADDR) 106 return (0); 107 108 return (1); 109 } 110 111 112 static void 113 intreg_attach(parent, self, args) 114 struct device *parent; 115 struct device *self; 116 void *args; 117 { 118 struct intreg_softc *sc = (void *)self; 119 120 printf("\n"); 121 122 sc->sc_reg = interrupt_reg; 123 124 /* Install handler for our "soft" interrupt. */ 125 isr_add_autovect(soft1intr, (void *)sc, 1); 126 intreg_attached = 1; 127 } 128 129 130 /* 131 * Level 1 software interrupt. 132 * Possible reasons: 133 * Network software interrupt 134 * Soft clock interrupt 135 */ 136 static int 137 soft1intr(arg) 138 void *arg; 139 { 140 union sun3sir sir; 141 int s; 142 143 s = splhigh(); 144 sir.sir_any = sun3sir.sir_any; 145 sun3sir.sir_any = 0; 146 isr_soft_clear(1); 147 splx(s); 148 149 if (sir.sir_any) { 150 uvmexp.softs++; 151 if (sir.sir_which[SIR_NET]) { 152 sir.sir_which[SIR_NET] = 0; 153 netintr(); 154 } 155 if (sir.sir_which[SIR_CLOCK]) { 156 sir.sir_which[SIR_CLOCK] = 0; 157 softclock(NULL); 158 } 159 if (sir.sir_which[SIR_SPARE2]) { 160 sir.sir_which[SIR_SPARE2] = 0; 161 /* spare2intr(); */ 162 } 163 if (sir.sir_which[SIR_SPARE3]) { 164 sir.sir_which[SIR_SPARE3] = 0; 165 /* spare3intr(); */ 166 } 167 return (1); 168 } 169 return(0); 170 } 171 172 173 void isr_soft_request(level) 174 int level; 175 { 176 u_char bit; 177 178 if ((level < 1) || (level > 3)) 179 return; 180 181 bit = 1 << level; 182 single_inst_bset_b(*interrupt_reg, bit); 183 } 184 185 void isr_soft_clear(level) 186 int level; 187 { 188 u_char bit; 189 190 if ((level < 1) || (level > 3)) 191 return; 192 193 bit = 1 << level; 194 single_inst_bclr_b(*interrupt_reg, bit); 195 } 196 197