tlsb.c revision 1.27 1 /* $NetBSD: tlsb.c,v 1.27 2004/09/13 14:48:46 drochner Exp $ */
2 /*
3 * Copyright (c) 1997 by Matthew Jacob
4 * NASA AMES Research Center.
5 * All rights reserved.
6 *
7 * Based in part upon a prototype version by Jason Thorpe
8 * Copyright (c) 1996, 1998 by Jason Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 /*
36 * Autoconfiguration and support routines for the TurboLaser System Bus
37 * found on AlphaServer 8200 and 8400 systems.
38 */
39
40 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
41
42 __KERNEL_RCSID(0, "$NetBSD: tlsb.c,v 1.27 2004/09/13 14:48:46 drochner Exp $");
43
44 #include "opt_multiprocessor.h"
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/device.h>
49 #include <sys/malloc.h>
50
51 #include <machine/autoconf.h>
52 #include <machine/cpu.h>
53 #include <machine/cpuvar.h>
54 #include <machine/rpb.h>
55 #include <machine/pte.h>
56 #include <machine/alpha.h>
57
58 #include <alpha/tlsb/tlsbreg.h>
59 #include <alpha/tlsb/tlsbvar.h>
60
61 #include "locators.h"
62
63 #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
64
65 static int tlsbmatch __P((struct device *, struct cfdata *, void *));
66 static void tlsbattach __P((struct device *, struct device *, void *));
67
68 CFATTACH_DECL(tlsb, sizeof (struct device),
69 tlsbmatch, tlsbattach, NULL, NULL);
70
71 extern struct cfdriver tlsb_cd;
72
73 static int tlsbprint __P((void *, const char *));
74 static int tlsbsubmatch __P((struct device *, struct cfdata *,
75 const locdesc_t *, void *));
76 static char *tlsb_node_type_str __P((u_int32_t));
77
78 /*
79 * There can be only one TurboLaser, and we'll overload it
80 * with a bitmap of found turbo laser nodes. Note that
81 * these are just the actual hard TL node IDS that we
82 * discover here, not the virtual IDs that get assigned
83 * to CPUs. During TLSB specific error handling we
84 * only need to know which actual TLSB slots have boards
85 * in them (irrespective of how many CPUs they have).
86 */
87 int tlsb_found;
88
89 static int
90 tlsbprint(aux, pnp)
91 void *aux;
92 const char *pnp;
93 {
94 struct tlsb_dev_attach_args *tap = aux;
95
96 if (pnp)
97 aprint_normal("%s at %s node %d",
98 tlsb_node_type_str(tap->ta_dtype), pnp, tap->ta_node);
99 else
100 aprint_normal(" node %d: %s", tap->ta_node,
101 tlsb_node_type_str(tap->ta_dtype));
102
103 return (UNCONF);
104 }
105
106 static int
107 tlsbsubmatch(parent, cf, ldesc, aux)
108 struct device *parent;
109 struct cfdata *cf;
110 const locdesc_t *ldesc;
111 void *aux;
112 {
113
114 if (cf->cf_loc[TLSBCF_NODE] != TLSBCF_NODE_DEFAULT &&
115 cf->cf_loc[TLSBCF_NODE] != ldesc->locs[TLSBCF_NODE])
116 return (0);
117 if (cf->cf_loc[TLSBCF_OFFSET] != TLSBCF_OFFSET_DEFAULT &&
118 cf->cf_loc[TLSBCF_OFFSET] != ldesc->locs[TLSBCF_OFFSET])
119 return (0);
120
121 return (config_match(parent, cf, aux));
122 }
123
124 static int
125 tlsbmatch(parent, cf, aux)
126 struct device *parent;
127 struct cfdata *cf;
128 void *aux;
129 {
130 struct mainbus_attach_args *ma = aux;
131
132 /* Make sure we're looking for a TurboLaser. */
133 if (strcmp(ma->ma_name, tlsb_cd.cd_name) != 0)
134 return (0);
135
136 /*
137 * Only one instance of TurboLaser allowed,
138 * and only available on 21000 processor type
139 * platforms.
140 */
141 if ((cputype != ST_DEC_21000) || tlsb_found)
142 return (0);
143
144 return (1);
145 }
146
147 static void
148 tlsbattach(parent, self, aux)
149 struct device *parent;
150 struct device *self;
151 void *aux;
152 {
153 struct tlsb_dev_attach_args ta;
154 u_int32_t tldev;
155 int node;
156 int help[3];
157 locdesc_t *ldesc = (void *)help; /* XXX */
158
159 printf("\n");
160
161 /*
162 * Attempt to find all devices on the bus, including
163 * CPUs, memory modules, and I/O modules.
164 */
165
166 /*
167 * Sigh. I would like to just start off nicely,
168 * but I need to treat I/O modules differently-
169 * The highest priority I/O node has to be in
170 * node #8, and I want to find it *first*, since
171 * it will have the primary disks (most likely)
172 * on it.
173 */
174 for (node = 0; node <= TLSB_NODE_MAX; ++node) {
175 /*
176 * Check for invalid address. This may not really
177 * be necessary, but what the heck...
178 */
179 if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
180 continue;
181 tldev = TLSB_GET_NODEREG(node, TLDEV);
182 if (tldev == 0) {
183 /* Nothing at this node. */
184 continue;
185 }
186 /*
187 * Store up that we found something at this node.
188 * We do this so that we don't have to do something
189 * silly at fault time like try a 'baddadr'...
190 */
191 tlsb_found |= (1 << node);
192 if (TLDEV_ISIOPORT(tldev))
193 continue; /* not interested right now */
194 ta.ta_node = node;
195 ta.ta_dtype = TLDEV_DTYPE(tldev);
196 ta.ta_swrev = TLDEV_SWREV(tldev);
197 ta.ta_hwrev = TLDEV_HWREV(tldev);
198
199 /*
200 * Deal with hooking CPU instances to TurboLaser nodes.
201 */
202 if (TLDEV_ISCPU(tldev)) {
203 printf("%s node %d: %s\n", self->dv_xname,
204 node, tlsb_node_type_str(tldev));
205 }
206 /*
207 * Attach any children nodes, including a CPU's GBus
208 */
209 ldesc->len = 2;
210 ldesc->locs[TLSBCF_NODE] = node;
211 ldesc->locs[TLSBCF_OFFSET] = 0; /* XXX unused? */
212
213 config_found_sm_loc(self, "tlsb", ldesc, &ta,
214 tlsbprint, tlsbsubmatch);
215 }
216 /*
217 * *Now* search for I/O nodes (in descending order)
218 */
219 while (--node > 0) {
220 if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
221 continue;
222 tldev = TLSB_GET_NODEREG(node, TLDEV);
223 if (tldev == 0) {
224 continue;
225 }
226 if (TLDEV_ISIOPORT(tldev)) {
227 #if defined(MULTIPROCESSOR)
228 /*
229 * XXX Eventually, we want to select a secondary
230 * XXX processor on which to field interrupts for
231 * XXX this node. However, we just send them to
232 * XXX the primary CPU for now.
233 *
234 * XXX Maybe multiple CPUs? Does the hardware
235 * XXX round-robin, or check the length of the
236 * XXX per-CPU interrupt queue?
237 */
238 printf("%s node %d: routing interrupts to %s\n",
239 self->dv_xname, node,
240 cpu_info[hwrpb->rpb_primary_cpu_id]->ci_softc->sc_dev.dv_xname);
241 TLSB_PUT_NODEREG(node, TLCPUMASK,
242 (1UL << hwrpb->rpb_primary_cpu_id));
243 #else
244 /*
245 * Make sure interrupts are sent to the primary CPU.
246 */
247 TLSB_PUT_NODEREG(node, TLCPUMASK,
248 (1UL << hwrpb->rpb_primary_cpu_id));
249 #endif /* MULTIPROCESSOR */
250
251 ta.ta_node = node;
252 ta.ta_dtype = TLDEV_DTYPE(tldev);
253 ta.ta_swrev = TLDEV_SWREV(tldev);
254 ta.ta_hwrev = TLDEV_HWREV(tldev);
255
256 ldesc->len = 2;
257 ldesc->locs[TLSBCF_NODE] = node;
258 ldesc->locs[TLSBCF_OFFSET] = 0; /* XXX unused? */
259
260 config_found_sm_loc(self, "tlsb", ldesc, &ta,
261 tlsbprint, tlsbsubmatch);
262 }
263 }
264 }
265
266 static char *
267 tlsb_node_type_str(dtype)
268 u_int32_t dtype;
269 {
270 static char tlsb_line[64];
271
272 switch (dtype & TLDEV_DTYPE_MASK) {
273 case TLDEV_DTYPE_KFTHA:
274 return ("KFTHA I/O interface");
275
276 case TLDEV_DTYPE_KFTIA:
277 return ("KFTIA I/O interface");
278
279 case TLDEV_DTYPE_MS7CC:
280 return ("MS7CC Memory Module");
281
282 case TLDEV_DTYPE_SCPU4:
283 return ("Single CPU, 4MB cache");
284
285 case TLDEV_DTYPE_SCPU16:
286 return ("Single CPU, 16MB cache");
287
288 case TLDEV_DTYPE_DCPU4:
289 return ("Dual CPU, 4MB cache");
290
291 case TLDEV_DTYPE_DCPU16:
292 return ("Dual CPU, 16MB cache");
293
294 default:
295 memset(tlsb_line, 0, sizeof(tlsb_line));
296 sprintf(tlsb_line, "unknown, dtype 0x%x", dtype);
297 return (tlsb_line);
298 }
299 /* NOTREACHED */
300 }
301