xref: /netbsd-src/sys/arch/sun3/sun3/intreg.c (revision cd22f25e6f6d1cc1f197fe8c5468a80f51d1c4e1)
1 /*	$NetBSD: intreg.c,v 1.28 2008/04/28 20:23:38 martin 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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * This handles multiple attach of autovectored interrupts,
34  * and the handy software interrupt request register.
35  */
36 
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: intreg.c,v 1.28 2008/04/28 20:23:38 martin Exp $");
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/vmmeter.h>
44 
45 #include <uvm/uvm_extern.h>
46 
47 #include <m68k/asm_single.h>
48 
49 #include <machine/autoconf.h>
50 #include <machine/cpu.h>
51 #include <machine/mon.h>
52 
53 #include <sun3/sun3/interreg.h>
54 #include <sun3/sun3/machdep.h>
55 
56 struct intreg_softc {
57 	struct device sc_dev;
58 	volatile u_char *sc_reg;
59 };
60 
61 static int  intreg_match(struct device *, struct cfdata *, void *);
62 static void intreg_attach(struct device *, struct device *, void *);
63 
64 CFATTACH_DECL(intreg, sizeof(struct intreg_softc),
65     intreg_match, intreg_attach, NULL, NULL);
66 
67 volatile u_char *interrupt_reg;
68 int intreg_attached;
69 
70 /* called early (by internal_configure) */
71 void
72 intreg_init(void)
73 {
74 	vaddr_t va;
75 
76 	if (find_prom_map(IREG_ADDR, PMAP_OBIO, 1, &va) != 0) {
77 		mon_printf("intreg_init\n");
78 		sunmon_abort();
79 	}
80 	interrupt_reg = (void *)va;
81 
82 	/* Turn off all interrupts until clock_attach */
83 	*interrupt_reg = 0;
84 }
85 
86 
87 static int
88 intreg_match(struct device *parent, struct cfdata *cf, void *args)
89 {
90 	struct confargs *ca = args;
91 
92 	/* This driver only supports one instance. */
93 	if (intreg_attached)
94 		return (0);
95 
96 	/* Validate the given address. */
97 	if (ca->ca_paddr != IREG_ADDR)
98 		return (0);
99 
100 	return (1);
101 }
102 
103 
104 static void
105 intreg_attach(struct device *parent, struct device *self, void *args)
106 {
107 	struct intreg_softc *sc = (void *)self;
108 
109 	printf("\n");
110 
111 	sc->sc_reg = interrupt_reg;
112 
113 	intreg_attached = 1;
114 }
115 
116 
117 #if 0
118 void
119 isr_soft_request(int level)
120 {
121 	u_char bit;
122 
123 	if ((level < _IPL_SOFT_LEVEL_MIN) || (level > _IPL_SOFT_LEVEL_MAX))
124 		return;
125 
126 	bit = 1 << level;
127 	single_inst_bset_b(*interrupt_reg, bit);
128 }
129 
130 void
131 isr_soft_clear(int level)
132 {
133 	u_char bit;
134 
135 	if ((level < _IPL_SOFT_LEVEL_MIN) || (level > _IPL_SOFT_LEVEL_MAX))
136 		return;
137 
138 	bit = 1 << level;
139 	single_inst_bclr_b(*interrupt_reg, bit);
140 }
141 #endif
142