xref: /netbsd-src/sys/arch/vax/bi/bi_nmi.c (revision 6a6027692662ba623e7bf5274322989a7b5d1440)
1*6a602769Sragge /*	$NetBSD: bi_nmi.c,v 1.9 2017/05/22 16:53:59 ragge Exp $	   */
2b38b1995Sragge /*
3b38b1995Sragge  * Copyright (c) 1999 Ludd, University of Lule}, Sweden.
4b38b1995Sragge  * All rights reserved.
5b38b1995Sragge  *
6b38b1995Sragge  * Redistribution and use in source and binary forms, with or without
7b38b1995Sragge  * modification, are permitted provided that the following conditions
8b38b1995Sragge  * are met:
9b38b1995Sragge  * 1. Redistributions of source code must retain the above copyright
10b38b1995Sragge  *    notice, this list of conditions and the following disclaimer.
11b38b1995Sragge  * 2. Redistributions in binary form must reproduce the above copyright
12b38b1995Sragge  *    notice, this list of conditions and the following disclaimer in the
13b38b1995Sragge  *    documentation and/or other materials provided with the distribution.
14b38b1995Sragge  *
15b38b1995Sragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16b38b1995Sragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17b38b1995Sragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18b38b1995Sragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19b38b1995Sragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20b38b1995Sragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21b38b1995Sragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22b38b1995Sragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23b38b1995Sragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24b38b1995Sragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25b38b1995Sragge  */
26b38b1995Sragge 
273b4fb6d0Slukem #include <sys/cdefs.h>
28*6a602769Sragge __KERNEL_RCSID(0, "$NetBSD: bi_nmi.c,v 1.9 2017/05/22 16:53:59 ragge Exp $");
29b38b1995Sragge 
30b38b1995Sragge #define _VAX_BUS_DMA_PRIVATE
3106386a01Smatt 
3206386a01Smatt #include <sys/param.h>
3306386a01Smatt #include <sys/systm.h>
3406386a01Smatt #include <sys/bus.h>
3506386a01Smatt #include <sys/cpu.h>
3606386a01Smatt #include <sys/device.h>
3706386a01Smatt 
38b38b1995Sragge #include <machine/nexus.h>
39b38b1995Sragge #include <machine/sid.h>
40b38b1995Sragge #include <machine/scb.h>
41b38b1995Sragge #include <machine/ka88.h>
42b38b1995Sragge 
43b38b1995Sragge #include <dev/bi/bivar.h>
44b38b1995Sragge #include <dev/bi/bireg.h>
45b38b1995Sragge 
46b38b1995Sragge #include "locators.h"
47b38b1995Sragge 
48b38b1995Sragge static int
bi_nmi_match(device_t parent,cfdata_t cf,void * aux)49dfba8166Smatt bi_nmi_match(device_t parent, cfdata_t cf, void *aux)
50b38b1995Sragge {
51dfba8166Smatt 	struct nmi_attach_args * const na = aux;
52b38b1995Sragge 
53b38b1995Sragge 	if (cf->cf_loc[NMICF_SLOT] != NMICF_SLOT_DEFAULT &&
54dfba8166Smatt 	    cf->cf_loc[NMICF_SLOT] != na->na_slot)
55b38b1995Sragge 		return 0;
56dfba8166Smatt 	return na->na_slot < 10;
57b38b1995Sragge }
58b38b1995Sragge 
59b38b1995Sragge static void
bi_nmi_attach(device_t parent,device_t self,void * aux)60dfba8166Smatt bi_nmi_attach(device_t parent, device_t self, void *aux)
61b38b1995Sragge {
62dfba8166Smatt 	struct nmi_attach_args * const na = aux;
63dfba8166Smatt 	struct bi_softc * const sc = device_private(self);
64b38b1995Sragge 	volatile int *v, *v2;
65b38b1995Sragge 	extern int avail_end;
66b38b1995Sragge 	int nid;
67b38b1995Sragge 
68dfba8166Smatt 	sc->sc_dev = self;
69dfba8166Smatt 
70b38b1995Sragge 	/*
71b38b1995Sragge 	 * Fill in bus specific data.
72b38b1995Sragge 	 */
73dfba8166Smatt 	sc->sc_addr = (bus_addr_t)BI_BASE(na->na_slot, 0);
74dfba8166Smatt 	sc->sc_iot = na->na_iot;	/* No special I/O handling */
75dfba8166Smatt 	sc->sc_dmat = na->na_dmat;	/* No special DMA handling either */
76b38b1995Sragge 
77b38b1995Sragge 	/* Must get the NBIB node number (interrupt routing) */
78b38b1995Sragge 	/*
79b38b1995Sragge 	 * XXX - need a big cleanup here!
80b38b1995Sragge 	 */
81dfba8166Smatt 	v = (int *)vax_map_physmem(NBIA_REGS(na->na_slot/2), 1);
82b38b1995Sragge 	v[1] = v[1]; /* Clear errors */
83b38b1995Sragge 	v[0] = 0x400 | CSR0_NBIIE | CSR0_LOOP; /* XXX */
84b38b1995Sragge 	v2 = (int *)vax_map_physmem(sc->sc_addr, 1);
85b38b1995Sragge 	v2[10] = v2[10] | 0x48;
86b38b1995Sragge 	v2[8] = 0;
87b38b1995Sragge 	v2[9] = (avail_end + 0x3ffff) & (~0x3ffff);
88b38b1995Sragge 	v2[2] = v2[2];
89b38b1995Sragge 	v2[1] = v2[1] | BICSR_BROKE;
90b38b1995Sragge 	nid = v2[1] & 15;
91b38b1995Sragge 	v[0] = (v[0] & ~CSR0_LOOP);
92b38b1995Sragge 	DELAY(1000);
93b38b1995Sragge 
94b38b1995Sragge 	sc->sc_intcpu = 1 << nid;
95dfba8166Smatt 	sc->sc_lastiv = /* 0x400 * na->na_slot + */ 0x400;
96b38b1995Sragge 
97b38b1995Sragge 	bi_attach(sc);
98b38b1995Sragge }
99b38b1995Sragge 
100dfba8166Smatt CFATTACH_DECL_NEW(bi_nmi, sizeof(struct bi_softc),
1014bf871a7Sthorpej     bi_nmi_match, bi_nmi_attach, NULL, NULL);
102