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