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