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