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