mcbus.c revision 1.6 1 /* $NetBSD: mcbus.c,v 1.6 1999/04/15 22:19:52 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1998 by Matthew Jacob
5 * NASA AMES Research Center.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 /*
34 * Autoconfiguration routines for the MCBUS system
35 * bus found on AlphaServer 4100 systems.
36 */
37
38 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
39
40 __KERNEL_RCSID(0, "$NetBSD: mcbus.c,v 1.6 1999/04/15 22:19:52 thorpej Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
46
47 #include <machine/autoconf.h>
48 #include <machine/rpb.h>
49 #include <machine/pte.h>
50
51 #include <alpha/mcbus/mcbusreg.h>
52 #include <alpha/mcbus/mcbusvar.h>
53
54 #include "locators.h"
55
56 #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
57
58 extern struct cfdriver mcbus_cd;
59
60 struct mcbus_cpu_busdep mcbus_primary;
61
62 static int mcbusmatch __P((struct device *, struct cfdata *, void *));
63 static void mcbusattach __P((struct device *, struct device *, void *));
64 static int mcbusprint __P((void *, const char *));
65 static int mcbussubmatch __P((struct device *, struct cfdata *, void *));
66 static char *mcbus_node_type_str __P((u_int8_t));
67
68 typedef struct {
69 struct device mcbus_dev;
70 u_int8_t mcbus_types[MCBUS_MID_MAX];
71 } mcbus_softc_t;
72
73 struct cfattach mcbus_ca = {
74 sizeof (mcbus_softc_t), mcbusmatch, mcbusattach
75 };
76
77 /*
78 * Tru64 UNIX (formerly Digital UNIX (formerly DEC OSF/1)) probes for MCPCIAs
79 * in the following order:
80 *
81 * 5, 4, 7, 6
82 *
83 * This is so that the built-in CD-ROM on the internal 53c810 is always
84 * dka500. We probe them in the same order, for consistency.
85 */
86 const int mcbus_mcpcia_probe_order[] = { 5, 4, 7, 6 };
87
88 extern void mcpcia_config_cleanup __P((void));
89
90 static int
91 mcbusprint(aux, cp)
92 void *aux;
93 const char *cp;
94 {
95 struct mcbus_dev_attach_args *tap = aux;
96 printf(" mid %d: %s", tap->ma_mid, mcbus_node_type_str(tap->ma_type));
97 return (UNCONF);
98 }
99
100 static int
101 mcbussubmatch(parent, cf, aux)
102 struct device *parent;
103 struct cfdata *cf;
104 void *aux;
105 {
106 struct mcbus_dev_attach_args *tap = aux;
107 if (tap->ma_name != mcbus_cd.cd_name)
108 return (0);
109 if (cf->cf_loc[MCBUSCF_MID] != MCBUSCF_MID_DEFAULT &&
110 cf->cf_loc[MCBUSCF_MID] != tap->ma_mid)
111 return (0);
112 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
113 }
114
115 static int
116 mcbusmatch(parent, cf, aux)
117 struct device *parent;
118 struct cfdata *cf;
119 void *aux;
120 {
121 struct mainbus_attach_args *ma = aux;
122
123 /* Make sure we're looking for a MCBUS. */
124 if (strcmp(ma->ma_name, mcbus_cd.cd_name) != 0)
125 return (0);
126
127 /*
128 * Only available on 4100 processor type platforms.
129 */
130 if (cputype != ST_DEC_4100)
131 return (0);
132 return (1);
133 }
134
135 static void
136 mcbusattach(parent, self, aux)
137 struct device *parent;
138 struct device *self;
139 void *aux;
140 {
141 static const char *bcs[8] = {
142 "(no bcache)", "1MB BCache", "2MB BCache", "4MB BCache",
143 "??(4)??", "??(5)??", "??(6)??", "??(7)??"
144 };
145 struct mcbus_dev_attach_args ta;
146 mcbus_softc_t *mbp = (mcbus_softc_t *)self;
147 int i, mid;
148
149 printf("\n");
150
151 mbp->mcbus_types[0] = MCBUS_TYPE_RES;
152 for (mid = 1; mid <= MCBUS_MID_MAX; ++mid) {
153 mbp->mcbus_types[mid] = MCBUS_TYPE_UNK;
154 }
155
156 /*
157 * Find and "configure" memory.
158 */
159 ta.ma_name = mcbus_cd.cd_name;
160 /*
161 * XXX If we ever support more than one MCBUS, we'll
162 * XXX have to probe for them, and map them to unit
163 * XXX numbers.
164 */
165 ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0);
166 ta.ma_mid = 1;
167 ta.ma_type = MCBUS_TYPE_MEM;
168 mbp->mcbus_types[1] = MCBUS_TYPE_MEM;
169 (void) config_found_sm(self, &ta, mcbusprint, mcbussubmatch);
170
171 /*
172 * Now find PCI busses.
173 */
174 for (i = 0; i < MCPCIA_PER_MCBUS; i++) {
175 mid = mcbus_mcpcia_probe_order[i];
176 ta.ma_name = mcbus_cd.cd_name;
177 /*
178 * XXX If we ever support more than one MCBUS, we'll
179 * XXX have to probe for them, and map them to unit
180 * XXX numbers.
181 */
182 ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0);
183 ta.ma_mid = mid;
184 ta.ma_type = MCBUS_TYPE_PCI;
185 /*
186 * XXX MUST ACTUALLY PROBE FOR MCPCIA!
187 */
188 (void) config_found_sm(self, &ta, mcbusprint, mcbussubmatch);
189 }
190
191 /*
192 * Deal with hooking CPU instances to MCBUS module ids.
193 *
194 * Note that we do this here because it's the read of
195 * stupid MCPCIA WHOAMI register that can get us the
196 * module ID and type of the configuring CPU.
197 */
198
199 if (mcbus_primary.mcbus_valid) {
200 mid = mcbus_primary.mcbus_cpu_mid;
201 printf("%s mid %d: %s %s\n", self->dv_xname,
202 mid, mcbus_node_type_str(MCBUS_TYPE_CPU),
203 bcs[mcbus_primary.mcbus_bcache & 0x7]);
204 #if 0
205 ta.ma_name = mcbus_cd.cd_name;
206 /*
207 * XXX If we ever support more than one MCBUS, we'll
208 * XXX have to probe for them, and map them to unit
209 * XXX numbers.
210 */
211 ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0);
212 ta.ma_mid = mid;
213 ta.ma_type = MCBUS_TYPE_CPU;
214 mbp->mcbus_types[mid] = MCBUS_TYPE_CPU;
215 (void) config_found_sm(self, &ta, mcbusprint, mcbussubmatch);
216 #endif
217 }
218
219 /*
220 * Now clean up after configuring everything.
221 *
222 * This is an unfortunate layering violation- but
223 * we can't enable interrupts until *all* probing
224 * is done, but the code and knowledge to clean
225 * up after probing and to enable interrupts is
226 * down in the MCPCIA layer.
227 */
228 mcpcia_config_cleanup();
229 }
230
231 static char *
232 mcbus_node_type_str(type)
233 u_int8_t type;
234 {
235 switch (type) {
236 case MCBUS_TYPE_RES:
237 panic ("RESERVED TYPE IN MCBUS_NODE_TYPE_STR");
238 break;
239 case MCBUS_TYPE_UNK:
240 panic ("UNKNOWN TYPE IN MCBUS_NODE_TYPE_STR");
241 break;
242 case MCBUS_TYPE_MEM:
243 return ("Memory");
244 case MCBUS_TYPE_CPU:
245 return ("CPU");
246 case MCBUS_TYPE_PCI:
247 return ("PCI Bridge");
248 default:
249 panic("REALLY UNKNWON (%x) TYPE IN MCBUS_NODE_TYPE_STR", type);
250 break;
251 }
252 }
253