1 /* $NetBSD: intreg.c,v 1.13 1999/03/24 05:51:14 mrg 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 <vm/vm.h> 50 51 #include <uvm/uvm_extern.h> 52 53 #include <m68k/asm_single.h> 54 55 #include <machine/autoconf.h> 56 #include <machine/cpu.h> 57 #include <machine/mon.h> 58 59 #include <sun3/sun3/interreg.h> 60 #include <sun3/sun3/machdep.h> 61 62 struct intreg_softc { 63 struct device sc_dev; 64 volatile u_char *sc_reg; 65 }; 66 67 static int intreg_match __P((struct device *, struct cfdata *, void *)); 68 static void intreg_attach __P((struct device *, struct device *, void *)); 69 static int soft1intr __P((void *)); 70 71 struct cfattach intreg_ca = { 72 sizeof(struct intreg_softc), intreg_match, intreg_attach 73 }; 74 75 volatile u_char *interrupt_reg; 76 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 unit. */ 101 if (cf->cf_unit != 0) 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 } 127 128 129 /* 130 * Level 1 software interrupt. 131 * Possible reasons: 132 * Network software interrupt 133 * Soft clock interrupt 134 */ 135 static int 136 soft1intr(arg) 137 void *arg; 138 { 139 union sun3sir sir; 140 int s; 141 142 s = splhigh(); 143 sir.sir_any = sun3sir.sir_any; 144 sun3sir.sir_any = 0; 145 isr_soft_clear(1); 146 splx(s); 147 148 if (sir.sir_any) { 149 uvmexp.softs++; 150 if (sir.sir_which[SIR_NET]) { 151 sir.sir_which[SIR_NET] = 0; 152 netintr(); 153 } 154 if (sir.sir_which[SIR_CLOCK]) { 155 sir.sir_which[SIR_CLOCK] = 0; 156 softclock(); 157 } 158 if (sir.sir_which[SIR_SPARE2]) { 159 sir.sir_which[SIR_SPARE2] = 0; 160 /* spare2intr(); */ 161 } 162 if (sir.sir_which[SIR_SPARE3]) { 163 sir.sir_which[SIR_SPARE3] = 0; 164 /* spare3intr(); */ 165 } 166 return (1); 167 } 168 return(0); 169 } 170 171 172 void isr_soft_request(level) 173 int level; 174 { 175 register u_char bit; 176 177 if ((level < 1) || (level > 3)) 178 return; 179 180 bit = 1 << level; 181 single_inst_bset_b(*interrupt_reg, bit); 182 } 183 184 void isr_soft_clear(level) 185 int level; 186 { 187 register u_char bit; 188 189 if ((level < 1) || (level > 3)) 190 return; 191 192 bit = 1 << level; 193 single_inst_bclr_b(*interrupt_reg, bit); 194 } 195 196