xref: /netbsd-src/sys/arch/sun3/sun3/intreg.c (revision 8f3d6d39adf63b7c25b4e182c5dd394f91c2f559)
1*8f3d6d39Stsutsui /*	$NetBSD: intreg.c,v 1.30 2013/09/07 15:56:11 tsutsui Exp $	*/
2c0a60cd8Sgwr 
303325025Sgwr /*-
403325025Sgwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
5c0a60cd8Sgwr  * All rights reserved.
6c0a60cd8Sgwr  *
703325025Sgwr  * This code is derived from software contributed to The NetBSD Foundation
803325025Sgwr  * by Adam Glass and Gordon W. Ross.
903325025Sgwr  *
10c0a60cd8Sgwr  * Redistribution and use in source and binary forms, with or without
11c0a60cd8Sgwr  * modification, are permitted provided that the following conditions
12c0a60cd8Sgwr  * are met:
13c0a60cd8Sgwr  * 1. Redistributions of source code must retain the above copyright
14c0a60cd8Sgwr  *    notice, this list of conditions and the following disclaimer.
15c0a60cd8Sgwr  * 2. Redistributions in binary form must reproduce the above copyright
16c0a60cd8Sgwr  *    notice, this list of conditions and the following disclaimer in the
17c0a60cd8Sgwr  *    documentation and/or other materials provided with the distribution.
18c0a60cd8Sgwr  *
1903325025Sgwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2003325025Sgwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2103325025Sgwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
228d9bb0e9Sgwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
238d9bb0e9Sgwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2403325025Sgwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2503325025Sgwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2603325025Sgwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2703325025Sgwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2803325025Sgwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2903325025Sgwr  * POSSIBILITY OF SUCH DAMAGE.
30c0a60cd8Sgwr  */
31c0a60cd8Sgwr 
32c0a60cd8Sgwr /*
33c0a60cd8Sgwr  * This handles multiple attach of autovectored interrupts,
34c0a60cd8Sgwr  * and the handy software interrupt request register.
35c0a60cd8Sgwr  */
36c0a60cd8Sgwr 
37ed517291Slukem #include <sys/cdefs.h>
38*8f3d6d39Stsutsui __KERNEL_RCSID(0, "$NetBSD: intreg.c,v 1.30 2013/09/07 15:56:11 tsutsui Exp $");
39ed517291Slukem 
40c0a60cd8Sgwr #include <sys/param.h>
41c0a60cd8Sgwr #include <sys/systm.h>
42c0a60cd8Sgwr #include <sys/device.h>
43c0a60cd8Sgwr #include <sys/vmmeter.h>
44c0a60cd8Sgwr 
455260d3fcSgwr #include <uvm/uvm_extern.h>
465260d3fcSgwr 
479587adc4Sgwr #include <m68k/asm_single.h>
489587adc4Sgwr 
49c0a60cd8Sgwr #include <machine/autoconf.h>
50c0a60cd8Sgwr #include <machine/cpu.h>
51c0a60cd8Sgwr #include <machine/mon.h>
52c0a60cd8Sgwr 
53ca8e9852Sgwr #include <sun3/sun3/interreg.h>
54eff2e270Sgwr #include <sun3/sun3/machdep.h>
55c0a60cd8Sgwr 
56c0a60cd8Sgwr struct intreg_softc {
572c5f71ccStsutsui 	device_t sc_dev;
582c5f71ccStsutsui 	volatile uint8_t *sc_reg;
59c0a60cd8Sgwr };
60c0a60cd8Sgwr 
612c5f71ccStsutsui static int  intreg_match(device_t, cfdata_t, void *);
622c5f71ccStsutsui static void intreg_attach(device_t, device_t, void *);
63c0a60cd8Sgwr 
642c5f71ccStsutsui CFATTACH_DECL_NEW(intreg, sizeof(struct intreg_softc),
654bf871a7Sthorpej     intreg_match, intreg_attach, NULL, NULL);
66c0a60cd8Sgwr 
672c5f71ccStsutsui volatile uint8_t *interrupt_reg;
682c5f71ccStsutsui static int intreg_attached;
69c0a60cd8Sgwr 
70c0a60cd8Sgwr /* called early (by internal_configure) */
710c5e3e49Sgwr void
intreg_init(void)7210b1a7beSchs intreg_init(void)
73c0a60cd8Sgwr {
74c207dcd8Stsutsui 	vaddr_t va;
75c207dcd8Stsutsui 
76c207dcd8Stsutsui 	if (find_prom_map(IREG_ADDR, PMAP_OBIO, 1, &va) != 0) {
77ca8e9852Sgwr 		mon_printf("intreg_init\n");
78ca8e9852Sgwr 		sunmon_abort();
79ca8e9852Sgwr 	}
80c207dcd8Stsutsui 	interrupt_reg = (void *)va;
81c207dcd8Stsutsui 
82c0a60cd8Sgwr 	/* Turn off all interrupts until clock_attach */
83c0a60cd8Sgwr 	*interrupt_reg = 0;
84c0a60cd8Sgwr }
85c0a60cd8Sgwr 
86c0a60cd8Sgwr 
87c0a60cd8Sgwr static int
intreg_match(device_t parent,cfdata_t cf,void * args)882c5f71ccStsutsui intreg_match(device_t parent, cfdata_t cf, void *args)
89c0a60cd8Sgwr {
90c0a60cd8Sgwr 	struct confargs *ca = args;
91c0a60cd8Sgwr 
927520514aSchs 	/* This driver only supports one instance. */
937520514aSchs 	if (intreg_attached)
942c5f71ccStsutsui 		return 0;
95c0a60cd8Sgwr 
96769fe0dfSgwr 	/* Validate the given address. */
97eff2e270Sgwr 	if (ca->ca_paddr != IREG_ADDR)
982c5f71ccStsutsui 		return 0;
99c0a60cd8Sgwr 
1002c5f71ccStsutsui 	return 1;
101c0a60cd8Sgwr }
102c0a60cd8Sgwr 
103c0a60cd8Sgwr 
104c0a60cd8Sgwr static void
intreg_attach(device_t parent,device_t self,void * args)1052c5f71ccStsutsui intreg_attach(device_t parent, device_t self, void *args)
106c0a60cd8Sgwr {
1072c5f71ccStsutsui 	struct intreg_softc *sc = device_private(self);
108c0a60cd8Sgwr 
1092c5f71ccStsutsui 	sc->sc_dev = self;
1102c5f71ccStsutsui 	aprint_normal("\n");
111c0a60cd8Sgwr 
112c0a60cd8Sgwr 	sc->sc_reg = interrupt_reg;
113c0a60cd8Sgwr 
1147520514aSchs 	intreg_attached = 1;
115c0a60cd8Sgwr }
116c0a60cd8Sgwr 
117c0a60cd8Sgwr 
1182f66d76bStsutsui #if 0
11910b1a7beSchs void
12010b1a7beSchs isr_soft_request(int level)
121c0a60cd8Sgwr {
1222c5f71ccStsutsui 	uint8_t bit;
123c0a60cd8Sgwr 
12462600eccStsutsui 	if ((level < _IPL_SOFT_LEVEL_MIN) || (level > _IPL_SOFT_LEVEL_MAX))
125c0a60cd8Sgwr 		return;
126c0a60cd8Sgwr 
1279587adc4Sgwr 	bit = 1 << level;
1289587adc4Sgwr 	single_inst_bset_b(*interrupt_reg, bit);
129c0a60cd8Sgwr }
130c0a60cd8Sgwr 
13110b1a7beSchs void
13210b1a7beSchs isr_soft_clear(int level)
133c0a60cd8Sgwr {
1342c5f71ccStsutsui 	uint8_t bit;
135c0a60cd8Sgwr 
13662600eccStsutsui 	if ((level < _IPL_SOFT_LEVEL_MIN) || (level > _IPL_SOFT_LEVEL_MAX))
1379587adc4Sgwr 		return;
138c0a60cd8Sgwr 
139c0a60cd8Sgwr 	bit = 1 << level;
1409587adc4Sgwr 	single_inst_bclr_b(*interrupt_reg, bit);
141c0a60cd8Sgwr }
1422f66d76bStsutsui #endif
143