tlsb.c revision 1.6 1 /* $NetBSD: tlsb.c,v 1.6 1997/09/02 13:20:50 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.6 1997/09/02 13:20:50 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 extern struct cfdriver cpu_cd;
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 struct cfattach tlsb_ca = {
68 sizeof (struct device), tlsbmatch, tlsbattach
69 };
70
71 struct cfdriver tlsb_cd = {
72 NULL, "tlsb", DV_DULL,
73 };
74
75 static int tlsbprint __P((void *, const char *));
76 static int tlsbsubmatch __P((struct device *, struct cfdata *, void *));
77 static char *tlsb_node_type_str __P((u_int32_t));
78
79 static int
80 tlsbprint(aux, cp)
81 void *aux;
82 const char *cp;
83 {
84 struct tlsb_dev_attach_args *tap = aux;
85 printf(" node %d: %s", tap->ta_node,
86 tlsb_node_type_str(tap->ta_dtype));
87 return (UNCONF);
88 }
89
90 static int
91 tlsbsubmatch(parent, cf, aux)
92 struct device *parent;
93 struct cfdata *cf;
94 void *aux;
95 {
96 struct tlsb_dev_attach_args *tap = aux;
97 if (tap->ta_name != tlsb_cd.cd_name)
98 return (0);
99 if (cf->cf_loc[TLSBCF_NODE] != TLSBCF_NODE_DEFAULT &&
100 cf->cf_loc[TLSBCF_NODE] != tap->ta_node)
101 return (0);
102 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
103 }
104
105 static int
106 tlsbmatch(parent, cf, aux)
107 struct device *parent;
108 struct cfdata *cf;
109 void *aux;
110 {
111 struct confargs *ca = aux;
112
113 /* Make sure we're looking for a TurboLaser. */
114 if (strcmp(ca->ca_name, tlsb_cd.cd_name) != 0)
115 return (0);
116
117 /*
118 * Only one instance of TurboLaser allowed,
119 * and only available on 21000 processor type
120 * platforms.
121 */
122 if ((cputype != ST_DEC_21000) || (cf->cf_unit != 0))
123 return (0);
124
125 return (1);
126 }
127
128 static void
129 tlsbattach(parent, self, aux)
130 struct device *parent;
131 struct device *self;
132 void *aux;
133 {
134 struct tlsb_dev_attach_args ta;
135 u_int32_t tldev;
136 u_int8_t vid;
137 int node;
138 struct tlsb_cpu_busdep *tcpu;
139 struct cfdriver *cfd = &cpu_cd;
140
141 printf("\n");
142
143 /*
144 * Attempt to find all devices on the bus, including
145 * CPUs, memory modules, and I/O modules.
146 */
147
148 /*
149 * Sigh. I would like to just start off nicely,
150 * but I need to treat I/O modules differently-
151 * The highest priority I/O node has to be in
152 * node #8, and I want to find it *first*, since
153 * it will have the primary disks (most likely)
154 * on it.
155 */
156 for (node = 0; node <= TLSB_NODE_MAX; ++node) {
157 /*
158 * Check for invalid address. This may not really
159 * be necessary, but what the heck...
160 */
161 if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
162 continue;
163 tldev = TLSB_GET_NODEREG(node, TLDEV);
164 if (tldev == 0) {
165 /* Nothing at this node. */
166 continue;
167 }
168 if (TLDEV_ISIOPORT(tldev))
169 continue; /* not interested right now */
170 ta.ta_name = tlsb_cd.cd_name;
171 ta.ta_node = node;
172 ta.ta_dtype = TLDEV_DTYPE(tldev);
173 ta.ta_swrev = TLDEV_SWREV(tldev);
174 ta.ta_hwrev = TLDEV_HWREV(tldev);
175
176 /*
177 * Deal with hooking CPU instances to TurboLaser nodes.
178 */
179 if (TLDEV_ISCPU(tldev)) {
180 printf("%s node %d: %s", self->dv_xname,
181 node, tlsb_node_type_str(tldev));
182
183 /*
184 * Hook in the first CPU unit.
185 */
186 vid = (TLSB_GET_NODEREG(node, TLVID) &
187 TLVID_VIDA_MASK) >> TLVID_VIDA_SHIFT;
188
189 if ((tcpu = malloc(sizeof(struct tlsb_cpu_busdep),
190 M_DEVBUF, M_NOWAIT)) == NULL)
191 panic("\nno memory for cpu busdep info");
192
193 tcpu->tcpu_vid = vid;
194 tcpu->tcpu_node = node;
195 cpu_node_id = node;
196 printf(", VID %d -> %s", tcpu->tcpu_vid, cfd->cd_name);
197
198 /*
199 * Do 2nd CPU (if available) here.
200 */
201 printf("\n");
202 TLSB_PUT_NODEREG(node, TLCPUMASK, (1<<vid));
203
204 /*
205 * XXX: Check to make sure that INTRMASK has ints
206 * XXX: enabled for this CPU.
207 */
208 }
209 /*
210 * Attach any children nodes, including a CPU's GBus
211 */
212 config_found_sm(self, &ta, tlsbprint, tlsbsubmatch);
213 }
214 /*
215 * *Now* search for I/O nodes (in descending order)
216 */
217 while (--node > 0) {
218 if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
219 continue;
220 tldev = TLSB_GET_NODEREG(node, TLDEV);
221 if (tldev == 0) {
222 continue;
223 }
224 if (TLDEV_ISIOPORT(tldev)) {
225 ta.ta_name = tlsb_cd.cd_name;
226 ta.ta_node = node;
227 ta.ta_dtype = TLDEV_DTYPE(tldev);
228 ta.ta_swrev = TLDEV_SWREV(tldev);
229 ta.ta_hwrev = TLDEV_HWREV(tldev);
230 config_found_sm(self, &ta, tlsbprint, tlsbsubmatch);
231 }
232 }
233 }
234
235 static char *
236 tlsb_node_type_str(dtype)
237 u_int32_t dtype;
238 {
239 static char tlsb_line[64];
240
241 switch (dtype & TLDEV_DTYPE_MASK) {
242 case TLDEV_DTYPE_KFTHA:
243 return ("KFTHA I/O interface");
244
245 case TLDEV_DTYPE_KFTIA:
246 return ("KFTIA I/O interface");
247
248 case TLDEV_DTYPE_MS7CC:
249 return ("MS7CC Memory Module");
250
251 case TLDEV_DTYPE_SCPU4:
252 return ("Single CPU, 4MB cache");
253
254 case TLDEV_DTYPE_SCPU16:
255 return ("Single CPU, 16MB cache");
256
257 case TLDEV_DTYPE_DCPU4:
258 return ("Dual CPU, 4MB cache");
259
260 case TLDEV_DTYPE_DCPU16:
261 return ("Dual CPU, 16MB cache");
262
263 default:
264 bzero(tlsb_line, sizeof(tlsb_line));
265 sprintf(tlsb_line, "unknown, dtype 0x%x", dtype);
266 return (tlsb_line);
267 }
268 /* NOTREACHED */
269 }
270