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