tlsb.c revision 1.7 1 /* $NetBSD: tlsb.c,v 1.7 1998/01/12 10:21:24 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1997 by Matthew Jacob
5 * NASA AMES Research Center.
6 * All rights reserved.
7 *
8 * Based in part upon a prototype version by Jason Thorpe
9 * Copyright (c) 1996 by Jason Thorpe.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice immediately at the beginning of the file, without modification,
16 * this list of conditions, and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 /*
37 * Autoconfiguration and support routines for the TurboLaser System Bus
38 * found on AlphaServer 8200 and 8400 systems.
39 */
40
41 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
42
43 __KERNEL_RCSID(0, "$NetBSD: tlsb.c,v 1.7 1998/01/12 10:21:24 thorpej Exp $");
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48 #include <sys/malloc.h>
49
50 #include <machine/autoconf.h>
51 #include <machine/rpb.h>
52 #include <machine/pte.h>
53
54 #include <alpha/tlsb/tlsbreg.h>
55 #include <alpha/tlsb/tlsbvar.h>
56
57 #include "locators.h"
58
59 extern int cputype;
60 int cpu_node_id;
61
62 #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
63
64 static int tlsbmatch __P((struct device *, struct cfdata *, void *));
65 static void tlsbattach __P((struct device *, struct device *, void *));
66
67 struct cfattach tlsb_ca = {
68 sizeof (struct device), tlsbmatch, tlsbattach
69 };
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 *, void *));
75 static char *tlsb_node_type_str __P((u_int32_t));
76
77 static int
78 tlsbprint(aux, cp)
79 void *aux;
80 const char *cp;
81 {
82 struct tlsb_dev_attach_args *tap = aux;
83 printf(" node %d: %s", tap->ta_node,
84 tlsb_node_type_str(tap->ta_dtype));
85 return (UNCONF);
86 }
87
88 static int
89 tlsbsubmatch(parent, cf, aux)
90 struct device *parent;
91 struct cfdata *cf;
92 void *aux;
93 {
94 struct tlsb_dev_attach_args *tap = aux;
95 if (tap->ta_name != tlsb_cd.cd_name)
96 return (0);
97 if (cf->cf_loc[TLSBCF_NODE] != TLSBCF_NODE_DEFAULT &&
98 cf->cf_loc[TLSBCF_NODE] != tap->ta_node)
99 return (0);
100 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
101 }
102
103 static int
104 tlsbmatch(parent, cf, aux)
105 struct device *parent;
106 struct cfdata *cf;
107 void *aux;
108 {
109 struct confargs *ca = aux;
110
111 /* Make sure we're looking for a TurboLaser. */
112 if (strcmp(ca->ca_name, tlsb_cd.cd_name) != 0)
113 return (0);
114
115 /*
116 * Only one instance of TurboLaser allowed,
117 * and only available on 21000 processor type
118 * platforms.
119 */
120 if ((cputype != ST_DEC_21000) || (cf->cf_unit != 0))
121 return (0);
122
123 return (1);
124 }
125
126 static void
127 tlsbattach(parent, self, aux)
128 struct device *parent;
129 struct device *self;
130 void *aux;
131 {
132 extern struct cfdriver cpu_cd;
133 struct tlsb_dev_attach_args ta;
134 u_int32_t tldev;
135 u_int8_t vid;
136 int node;
137 struct tlsb_cpu_busdep *tcpu;
138 struct cfdriver *cfd = &cpu_cd;
139
140 printf("\n");
141
142 /*
143 * Attempt to find all devices on the bus, including
144 * CPUs, memory modules, and I/O modules.
145 */
146
147 /*
148 * Sigh. I would like to just start off nicely,
149 * but I need to treat I/O modules differently-
150 * The highest priority I/O node has to be in
151 * node #8, and I want to find it *first*, since
152 * it will have the primary disks (most likely)
153 * on it.
154 */
155 for (node = 0; node <= TLSB_NODE_MAX; ++node) {
156 /*
157 * Check for invalid address. This may not really
158 * be necessary, but what the heck...
159 */
160 if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
161 continue;
162 tldev = TLSB_GET_NODEREG(node, TLDEV);
163 if (tldev == 0) {
164 /* Nothing at this node. */
165 continue;
166 }
167 if (TLDEV_ISIOPORT(tldev))
168 continue; /* not interested right now */
169 ta.ta_name = tlsb_cd.cd_name;
170 ta.ta_node = node;
171 ta.ta_dtype = TLDEV_DTYPE(tldev);
172 ta.ta_swrev = TLDEV_SWREV(tldev);
173 ta.ta_hwrev = TLDEV_HWREV(tldev);
174
175 /*
176 * Deal with hooking CPU instances to TurboLaser nodes.
177 */
178 if (TLDEV_ISCPU(tldev)) {
179 printf("%s node %d: %s", self->dv_xname,
180 node, tlsb_node_type_str(tldev));
181
182 /*
183 * Hook in the first CPU unit.
184 */
185 vid = (TLSB_GET_NODEREG(node, TLVID) &
186 TLVID_VIDA_MASK) >> TLVID_VIDA_SHIFT;
187
188 if ((tcpu = malloc(sizeof(struct tlsb_cpu_busdep),
189 M_DEVBUF, M_NOWAIT)) == NULL)
190 panic("\nno memory for cpu busdep info");
191
192 tcpu->tcpu_vid = vid;
193 tcpu->tcpu_node = node;
194 cpu_node_id = node;
195 printf(", VID %d -> %s", tcpu->tcpu_vid, cfd->cd_name);
196
197 /*
198 * Do 2nd CPU (if available) here.
199 */
200 printf("\n");
201 TLSB_PUT_NODEREG(node, TLCPUMASK, (1<<vid));
202
203 /*
204 * XXX: Check to make sure that INTRMASK has ints
205 * XXX: enabled for this CPU.
206 */
207 }
208 /*
209 * Attach any children nodes, including a CPU's GBus
210 */
211 config_found_sm(self, &ta, tlsbprint, tlsbsubmatch);
212 }
213 /*
214 * *Now* search for I/O nodes (in descending order)
215 */
216 while (--node > 0) {
217 if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
218 continue;
219 tldev = TLSB_GET_NODEREG(node, TLDEV);
220 if (tldev == 0) {
221 continue;
222 }
223 if (TLDEV_ISIOPORT(tldev)) {
224 ta.ta_name = tlsb_cd.cd_name;
225 ta.ta_node = node;
226 ta.ta_dtype = TLDEV_DTYPE(tldev);
227 ta.ta_swrev = TLDEV_SWREV(tldev);
228 ta.ta_hwrev = TLDEV_HWREV(tldev);
229 config_found_sm(self, &ta, tlsbprint, tlsbsubmatch);
230 }
231 }
232 }
233
234 static char *
235 tlsb_node_type_str(dtype)
236 u_int32_t dtype;
237 {
238 static char tlsb_line[64];
239
240 switch (dtype & TLDEV_DTYPE_MASK) {
241 case TLDEV_DTYPE_KFTHA:
242 return ("KFTHA I/O interface");
243
244 case TLDEV_DTYPE_KFTIA:
245 return ("KFTIA I/O interface");
246
247 case TLDEV_DTYPE_MS7CC:
248 return ("MS7CC Memory Module");
249
250 case TLDEV_DTYPE_SCPU4:
251 return ("Single CPU, 4MB cache");
252
253 case TLDEV_DTYPE_SCPU16:
254 return ("Single CPU, 16MB cache");
255
256 case TLDEV_DTYPE_DCPU4:
257 return ("Dual CPU, 4MB cache");
258
259 case TLDEV_DTYPE_DCPU16:
260 return ("Dual CPU, 16MB cache");
261
262 default:
263 bzero(tlsb_line, sizeof(tlsb_line));
264 sprintf(tlsb_line, "unknown, dtype 0x%x", dtype);
265 return (tlsb_line);
266 }
267 /* NOTREACHED */
268 }
269