xref: /netbsd-src/sys/dev/xmi/xmi.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: xmi.c,v 1.13 2021/08/07 16:19:17 thorpej Exp $	*/
2c0f8f713Sragge 
3c0f8f713Sragge /*
4c0f8f713Sragge  * Copyright (c) 2000 Ludd, University of Lule}, Sweden. All rights reserved.
5c0f8f713Sragge  *
6c0f8f713Sragge  * Redistribution and use in source and binary forms, with or without
7c0f8f713Sragge  * modification, are permitted provided that the following conditions
8c0f8f713Sragge  * are met:
9c0f8f713Sragge  * 1. Redistributions of source code must retain the above copyright
10c0f8f713Sragge  *    notice, this list of conditions and the following disclaimer.
11c0f8f713Sragge  * 2. Redistributions in binary form must reproduce the above copyright
12c0f8f713Sragge  *    notice, this list of conditions and the following disclaimer in the
13c0f8f713Sragge  *    documentation and/or other materials provided with the distribution.
14c0f8f713Sragge  * 3. All advertising materials mentioning features or use of this software
15c0f8f713Sragge  *    must display the following acknowledgement:
16c0f8f713Sragge  *      This product includes software developed at Ludd, University of
17c0f8f713Sragge  *      Lule}, Sweden and its contributors.
18c0f8f713Sragge  * 4. The name of the author may not be used to endorse or promote products
19c0f8f713Sragge  *    derived from this software without specific prior written permission
20c0f8f713Sragge  *
21c0f8f713Sragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22c0f8f713Sragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23c0f8f713Sragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24c0f8f713Sragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25c0f8f713Sragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26c0f8f713Sragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27c0f8f713Sragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28c0f8f713Sragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29c0f8f713Sragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30c0f8f713Sragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31c0f8f713Sragge  */
32c0f8f713Sragge 
33c0f8f713Sragge /*
34c0f8f713Sragge  * XMI specific routines.
35c0f8f713Sragge  */
36c0f8f713Sragge 
37b5895882Slukem #include <sys/cdefs.h>
38*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: xmi.c,v 1.13 2021/08/07 16:19:17 thorpej Exp $");
39b5895882Slukem 
40c0f8f713Sragge #include <sys/param.h>
41c0f8f713Sragge #include <sys/systm.h>
42c0f8f713Sragge #include <sys/device.h>
43c0f8f713Sragge 
44a2a38285Sad #include <sys/bus.h>
45a2a38285Sad #include <sys/cpu.h>
46c0f8f713Sragge 
47c0f8f713Sragge #include <dev/xmi/xmireg.h>
48c0f8f713Sragge #include <dev/xmi/xmivar.h>
49c0f8f713Sragge 
50c0f8f713Sragge static int xmi_print(void *, const char *);
51c0f8f713Sragge 
52dfba8166Smatt const struct xmi_list xmi_list[] = {
53c0f8f713Sragge 	{XMIDT_KA62, 0, "ka6200"},
54c0f8f713Sragge 	{XMIDT_KA64, 1, "ka6400"},
55c0f8f713Sragge 	{XMIDT_KA65, 0, "ka6500"},
56c0f8f713Sragge 	{XMIDT_KA66, 0, "ka6600"},
57c0f8f713Sragge 	{XMIDT_MS62, 1, "ms62"},
58c0f8f713Sragge 	{XMIDT_DWMBA, 1, "dwmba"},
59c0f8f713Sragge 	{0,0,0}
60c0f8f713Sragge };
61c0f8f713Sragge 
62c0f8f713Sragge int
xmi_print(void * aux,const char * name)63c0f8f713Sragge xmi_print(void *aux, const char *name)
64c0f8f713Sragge {
65dfba8166Smatt 	struct xmi_attach_args * const xa = aux;
66dfba8166Smatt 	const struct xmi_list *xl;
67c0f8f713Sragge 
68c0f8f713Sragge 	for (xl = &xmi_list[0]; xl->xl_nr; xl++)
69c0f8f713Sragge 		if (xl->xl_nr == bus_space_read_2(xa->xa_iot, xa->xa_ioh, 0))
70c0f8f713Sragge 			break;
71c0f8f713Sragge 
72c0f8f713Sragge 	if (name) {
73c0f8f713Sragge 		if (xl->xl_nr == 0)
7472a7af27Sthorpej 			aprint_normal("unknown device 0x%x",
75c0f8f713Sragge 			    bus_space_read_2(xa->xa_iot, xa->xa_ioh, 0));
76c0f8f713Sragge 		else
77da0fbadfSthorpej 			aprint_normal(xl->xl_name);
7872a7af27Sthorpej 		aprint_normal(" at %s", name);
79c0f8f713Sragge 	}
8072a7af27Sthorpej 	aprint_normal(" node %d", xa->xa_nodenr);
81c0f8f713Sragge 	return xl->xl_havedriver ? UNCONF : UNSUPP;
82c0f8f713Sragge }
83c0f8f713Sragge 
84c0f8f713Sragge static	int lastiv = 0;
85c0f8f713Sragge 
86c0f8f713Sragge void
xmi_attach(struct xmi_softc * sc)87c0f8f713Sragge xmi_attach(struct xmi_softc *sc)
88c0f8f713Sragge {
89c0f8f713Sragge 	struct xmi_attach_args xa;
90c0f8f713Sragge 	int nodenr;
91c0f8f713Sragge 
92dfba8166Smatt 	aprint_normal("\n");
93c0f8f713Sragge 
94c0f8f713Sragge 	xa.xa_iot = sc->sc_iot;
95c0f8f713Sragge 	xa.xa_busnr = sc->sc_busnr;
96c0f8f713Sragge 	xa.xa_dmat = sc->sc_dmat;
97c0f8f713Sragge 	xa.xa_intcpu = sc->sc_intcpu;
98c0f8f713Sragge 	/*
99c0f8f713Sragge 	 * Interrupt numbers. All vectors from 256-512 are free, use
100c0f8f713Sragge 	 * them for XMI devices and just count them up.
101c0f8f713Sragge 	 * Above 512 are only interrupt vectors for unibus devices.
102c0f8f713Sragge 	 *
103c0f8f713Sragge 	 * The XMI nodespace is giant in size. Only map in the first
104c0f8f713Sragge 	 * page here and map more (if needed) in the device itself.
105c0f8f713Sragge 	 */
106c0f8f713Sragge 	for (nodenr = 0; nodenr < NNODEXMI; nodenr++) {
107c0f8f713Sragge 		if (bus_space_map(sc->sc_iot, sc->sc_addr + XMI_NODE(nodenr),
10852d8769eSthorpej 		    PAGE_SIZE, 0, &xa.xa_ioh)) {
109dfba8166Smatt 			aprint_error_dev(sc->sc_dev,
110dfba8166Smatt 			    "bus_space_map failed, node %d\n", nodenr);
111c0f8f713Sragge 			return;
112c0f8f713Sragge 		}
11353524e44Schristos 		if (badaddr((void *)xa.xa_ioh, 4)) {
11452d8769eSthorpej 			bus_space_unmap(sc->sc_iot, xa.xa_ioh, PAGE_SIZE);
115c0f8f713Sragge 			continue;
116c0f8f713Sragge 		}
117c0f8f713Sragge 		xa.xa_nodenr = nodenr;
118c0f8f713Sragge 		xa.xa_ivec = 256 + lastiv;
119c0f8f713Sragge 		lastiv += 4;
120*c7fb772bSthorpej 		config_found(sc->sc_dev, &xa, xmi_print, CFARGS_NONE);
121c0f8f713Sragge 	}
122c0f8f713Sragge }
123