xref: /netbsd-src/sys/arch/sun3/sun3/intreg.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: intreg.c,v 1.27 2007/12/04 15:12:07 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/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: intreg.c,v 1.27 2007/12/04 15:12:07 tsutsui 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(struct device *, struct cfdata *, void *);
69 static void intreg_attach(struct device *, struct device *, void *);
70 
71 CFATTACH_DECL(intreg, sizeof(struct intreg_softc),
72     intreg_match, intreg_attach, NULL, NULL);
73 
74 volatile u_char *interrupt_reg;
75 int intreg_attached;
76 
77 /* called early (by internal_configure) */
78 void
79 intreg_init(void)
80 {
81 	vaddr_t va;
82 
83 	if (find_prom_map(IREG_ADDR, PMAP_OBIO, 1, &va) != 0) {
84 		mon_printf("intreg_init\n");
85 		sunmon_abort();
86 	}
87 	interrupt_reg = (void *)va;
88 
89 	/* Turn off all interrupts until clock_attach */
90 	*interrupt_reg = 0;
91 }
92 
93 
94 static int
95 intreg_match(struct device *parent, struct cfdata *cf, void *args)
96 {
97 	struct confargs *ca = args;
98 
99 	/* This driver only supports one instance. */
100 	if (intreg_attached)
101 		return (0);
102 
103 	/* Validate the given address. */
104 	if (ca->ca_paddr != IREG_ADDR)
105 		return (0);
106 
107 	return (1);
108 }
109 
110 
111 static void
112 intreg_attach(struct device *parent, struct device *self, void *args)
113 {
114 	struct intreg_softc *sc = (void *)self;
115 
116 	printf("\n");
117 
118 	sc->sc_reg = interrupt_reg;
119 
120 	intreg_attached = 1;
121 }
122 
123 
124 #if 0
125 void
126 isr_soft_request(int level)
127 {
128 	u_char bit;
129 
130 	if ((level < _IPL_SOFT_LEVEL_MIN) || (level > _IPL_SOFT_LEVEL_MAX))
131 		return;
132 
133 	bit = 1 << level;
134 	single_inst_bset_b(*interrupt_reg, bit);
135 }
136 
137 void
138 isr_soft_clear(int level)
139 {
140 	u_char bit;
141 
142 	if ((level < _IPL_SOFT_LEVEL_MIN) || (level > _IPL_SOFT_LEVEL_MAX))
143 		return;
144 
145 	bit = 1 << level;
146 	single_inst_bclr_b(*interrupt_reg, bit);
147 }
148 #endif
149