xref: /netbsd/sys/arch/vax/vax/cmi.c (revision c4a72b64)
1 /*	$NetBSD: cmi.c,v 1.6 2002/10/02 16:02:35 thorpej Exp $ */
2 /*
3  * Copyright (c) 1999 Ludd, University of Lule}, Sweden.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *	This product includes software developed at Ludd, University of
17  *	Lule}, Sweden and its contributors.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/param.h>
34 #include <sys/device.h>
35 #include <sys/systm.h>
36 
37 #include <machine/bus.h>
38 #include <machine/nexus.h>
39 #include <machine/cpu.h>
40 #include <machine/sid.h>
41 #include <machine/ka750.h>
42 
43 static	int cmi_print(void *, const char *);
44 static	int cmi_match(struct device *, struct cfdata *, void *);
45 static	void cmi_attach(struct device *, struct device *, void*);
46 
47 CFATTACH_DECL(cmi, sizeof(struct device),
48     cmi_match, cmi_attach, NULL, NULL);
49 
50 int
51 cmi_print(void *aux, const char *name)
52 {
53 	struct sbi_attach_args *sa = (struct sbi_attach_args *)aux;
54 
55 	if (name)
56 		printf("unknown device 0x%x at %s", sa->sa_type, name);
57 
58 	printf(" tr%d", sa->sa_nexnum);
59 	return (UNCONF);
60 }
61 
62 
63 int
64 cmi_match(struct device *parent, struct cfdata *cf, void *aux)
65 {
66 	if (vax_bustype == VAX_CMIBUS)
67 		return 1;
68 	return 0;
69 }
70 
71 void
72 cmi_attach(struct device *parent, struct device *self, void *aux)
73 {
74 	struct	sbi_attach_args sa;
75 
76 	printf("\n");
77 	/*
78 	 * Probe for memory, can be in the first 4 slots.
79 	 */
80 #define NEXPAGES (sizeof(struct nexus) / VAX_NBPG)
81 	for (sa.sa_nexnum = 0; sa.sa_nexnum < 4; sa.sa_nexnum++) {
82 		sa.sa_ioh = vax_map_physmem(NEX750 +
83 		    sizeof(struct nexus) * sa.sa_nexnum, NEXPAGES);
84 		if (badaddr((caddr_t)sa.sa_ioh, 4)) {
85 			vax_unmap_physmem((vaddr_t)sa.sa_ioh, NEXPAGES);
86 		} else {
87 			sa.sa_type = NEX_MEM16;
88 			config_found(self, (void*)&sa, cmi_print);
89 		}
90 	}
91 
92 	/*
93 	 * Probe for mba's, can be in slot 4 - 7.
94 	 */
95 	for (sa.sa_nexnum = 4; sa.sa_nexnum < 7; sa.sa_nexnum++) {
96 		sa.sa_ioh = vax_map_physmem(NEX750 +
97 		    sizeof(struct nexus) * sa.sa_nexnum, NEXPAGES);
98 		if (badaddr((caddr_t)sa.sa_ioh, 4)) {
99 			vax_unmap_physmem((vaddr_t)sa.sa_ioh, NEXPAGES);
100 		} else {
101 			sa.sa_type = NEX_MBA;
102 			config_found(self, (void*)&sa, cmi_print);
103 		}
104 	}
105 
106 	/*
107 	 * There are always one generic UBA, and maybe an optional.
108 	 */
109 	sa.sa_nexnum = 8;
110 	sa.sa_ioh = vax_map_physmem(NEX750 +
111 	    sizeof(struct nexus) * sa.sa_nexnum, NEXPAGES);
112 	sa.sa_type = NEX_UBA0;
113 	config_found(self, (void*)&sa, cmi_print);
114 
115 	sa.sa_nexnum = 9;
116 	sa.sa_ioh = vax_map_physmem(NEX750 +
117 	    sizeof(struct nexus) * sa.sa_nexnum, NEXPAGES);
118 	sa.sa_type = NEX_UBA1;
119 	if (badaddr((caddr_t)sa.sa_ioh, 4))
120 		vax_unmap_physmem((vaddr_t)sa.sa_ioh, NEXPAGES);
121 	else
122 		config_found(self, (void*)&sa, cmi_print);
123 }
124