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