tlsb.c revision 1.9 1 1.9 thorpej /* $NetBSD: tlsb.c,v 1.9 1998/05/13 23:23:23 thorpej Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.2 cgd * Copyright (c) 1997 by Matthew Jacob
5 1.1 cgd * NASA AMES Research Center.
6 1.1 cgd * All rights reserved.
7 1.1 cgd *
8 1.1 cgd * Based in part upon a prototype version by Jason Thorpe
9 1.1 cgd * Copyright (c) 1996 by Jason Thorpe.
10 1.1 cgd *
11 1.1 cgd * Redistribution and use in source and binary forms, with or without
12 1.1 cgd * modification, are permitted provided that the following conditions
13 1.1 cgd * are met:
14 1.1 cgd * 1. Redistributions of source code must retain the above copyright
15 1.1 cgd * notice immediately at the beginning of the file, without modification,
16 1.1 cgd * this list of conditions, and the following disclaimer.
17 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 cgd * notice, this list of conditions and the following disclaimer in the
19 1.1 cgd * documentation and/or other materials provided with the distribution.
20 1.1 cgd * 3. The name of the author may not be used to endorse or promote products
21 1.1 cgd * derived from this software without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27 1.1 cgd * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd */
35 1.1 cgd
36 1.1 cgd /*
37 1.1 cgd * Autoconfiguration and support routines for the TurboLaser System Bus
38 1.1 cgd * found on AlphaServer 8200 and 8400 systems.
39 1.1 cgd */
40 1.3 cgd
41 1.4 cgd #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
42 1.4 cgd
43 1.9 thorpej __KERNEL_RCSID(0, "$NetBSD: tlsb.c,v 1.9 1998/05/13 23:23:23 thorpej Exp $");
44 1.1 cgd
45 1.1 cgd #include <sys/param.h>
46 1.1 cgd #include <sys/systm.h>
47 1.1 cgd #include <sys/device.h>
48 1.1 cgd #include <sys/malloc.h>
49 1.1 cgd
50 1.1 cgd #include <machine/autoconf.h>
51 1.1 cgd #include <machine/rpb.h>
52 1.1 cgd #include <machine/pte.h>
53 1.1 cgd
54 1.1 cgd #include <alpha/tlsb/tlsbreg.h>
55 1.1 cgd #include <alpha/tlsb/tlsbvar.h>
56 1.1 cgd
57 1.5 jtk #include "locators.h"
58 1.5 jtk
59 1.1 cgd extern int cputype;
60 1.1 cgd
61 1.1 cgd #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
62 1.1 cgd
63 1.1 cgd static int tlsbmatch __P((struct device *, struct cfdata *, void *));
64 1.1 cgd static void tlsbattach __P((struct device *, struct device *, void *));
65 1.7 thorpej
66 1.1 cgd struct cfattach tlsb_ca = {
67 1.1 cgd sizeof (struct device), tlsbmatch, tlsbattach
68 1.1 cgd };
69 1.1 cgd
70 1.7 thorpej extern struct cfdriver tlsb_cd;
71 1.1 cgd
72 1.1 cgd static int tlsbprint __P((void *, const char *));
73 1.1 cgd static int tlsbsubmatch __P((struct device *, struct cfdata *, void *));
74 1.1 cgd static char *tlsb_node_type_str __P((u_int32_t));
75 1.1 cgd
76 1.9 thorpej /* There can be only one. */
77 1.9 thorpej int tlsb_found;
78 1.9 thorpej
79 1.1 cgd static int
80 1.9 thorpej tlsbprint(aux, pnp)
81 1.1 cgd void *aux;
82 1.9 thorpej const char *pnp;
83 1.1 cgd {
84 1.1 cgd struct tlsb_dev_attach_args *tap = aux;
85 1.9 thorpej
86 1.9 thorpej if (pnp)
87 1.9 thorpej printf("%s at %s node %d", tlsb_node_type_str(tap->ta_dtype),
88 1.9 thorpej pnp, tap->ta_node);
89 1.9 thorpej else
90 1.9 thorpej printf(" node %d: %s", tap->ta_node,
91 1.9 thorpej tlsb_node_type_str(tap->ta_dtype));
92 1.9 thorpej
93 1.1 cgd return (UNCONF);
94 1.1 cgd }
95 1.1 cgd
96 1.1 cgd static int
97 1.1 cgd tlsbsubmatch(parent, cf, aux)
98 1.1 cgd struct device *parent;
99 1.1 cgd struct cfdata *cf;
100 1.1 cgd void *aux;
101 1.1 cgd {
102 1.1 cgd struct tlsb_dev_attach_args *tap = aux;
103 1.9 thorpej
104 1.5 jtk if (cf->cf_loc[TLSBCF_NODE] != TLSBCF_NODE_DEFAULT &&
105 1.5 jtk cf->cf_loc[TLSBCF_NODE] != tap->ta_node)
106 1.1 cgd return (0);
107 1.9 thorpej
108 1.1 cgd return ((*cf->cf_attach->ca_match)(parent, cf, aux));
109 1.1 cgd }
110 1.1 cgd
111 1.1 cgd static int
112 1.1 cgd tlsbmatch(parent, cf, aux)
113 1.1 cgd struct device *parent;
114 1.1 cgd struct cfdata *cf;
115 1.1 cgd void *aux;
116 1.1 cgd {
117 1.1 cgd struct confargs *ca = aux;
118 1.1 cgd
119 1.1 cgd /* Make sure we're looking for a TurboLaser. */
120 1.1 cgd if (strcmp(ca->ca_name, tlsb_cd.cd_name) != 0)
121 1.1 cgd return (0);
122 1.1 cgd
123 1.1 cgd /*
124 1.1 cgd * Only one instance of TurboLaser allowed,
125 1.1 cgd * and only available on 21000 processor type
126 1.1 cgd * platforms.
127 1.1 cgd */
128 1.9 thorpej if ((cputype != ST_DEC_21000) || tlsb_found)
129 1.1 cgd return (0);
130 1.1 cgd
131 1.1 cgd return (1);
132 1.1 cgd }
133 1.1 cgd
134 1.1 cgd static void
135 1.1 cgd tlsbattach(parent, self, aux)
136 1.1 cgd struct device *parent;
137 1.1 cgd struct device *self;
138 1.1 cgd void *aux;
139 1.1 cgd {
140 1.7 thorpej extern struct cfdriver cpu_cd;
141 1.1 cgd struct tlsb_dev_attach_args ta;
142 1.1 cgd u_int32_t tldev;
143 1.1 cgd u_int8_t vid;
144 1.1 cgd int node;
145 1.1 cgd struct cfdriver *cfd = &cpu_cd;
146 1.1 cgd
147 1.1 cgd printf("\n");
148 1.1 cgd
149 1.9 thorpej tlsb_found = 1;
150 1.9 thorpej
151 1.1 cgd /*
152 1.1 cgd * Attempt to find all devices on the bus, including
153 1.1 cgd * CPUs, memory modules, and I/O modules.
154 1.1 cgd */
155 1.1 cgd
156 1.1 cgd /*
157 1.1 cgd * Sigh. I would like to just start off nicely,
158 1.1 cgd * but I need to treat I/O modules differently-
159 1.1 cgd * The highest priority I/O node has to be in
160 1.1 cgd * node #8, and I want to find it *first*, since
161 1.1 cgd * it will have the primary disks (most likely)
162 1.1 cgd * on it.
163 1.1 cgd */
164 1.1 cgd for (node = 0; node <= TLSB_NODE_MAX; ++node) {
165 1.1 cgd /*
166 1.1 cgd * Check for invalid address. This may not really
167 1.1 cgd * be necessary, but what the heck...
168 1.1 cgd */
169 1.1 cgd if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
170 1.1 cgd continue;
171 1.1 cgd tldev = TLSB_GET_NODEREG(node, TLDEV);
172 1.1 cgd if (tldev == 0) {
173 1.1 cgd /* Nothing at this node. */
174 1.1 cgd continue;
175 1.1 cgd }
176 1.1 cgd if (TLDEV_ISIOPORT(tldev))
177 1.1 cgd continue; /* not interested right now */
178 1.1 cgd ta.ta_node = node;
179 1.1 cgd ta.ta_dtype = TLDEV_DTYPE(tldev);
180 1.1 cgd ta.ta_swrev = TLDEV_SWREV(tldev);
181 1.1 cgd ta.ta_hwrev = TLDEV_HWREV(tldev);
182 1.1 cgd
183 1.1 cgd /*
184 1.1 cgd * Deal with hooking CPU instances to TurboLaser nodes.
185 1.1 cgd */
186 1.1 cgd if (TLDEV_ISCPU(tldev)) {
187 1.1 cgd printf("%s node %d: %s", self->dv_xname,
188 1.1 cgd node, tlsb_node_type_str(tldev));
189 1.1 cgd
190 1.1 cgd /*
191 1.1 cgd * Hook in the first CPU unit.
192 1.1 cgd */
193 1.1 cgd vid = (TLSB_GET_NODEREG(node, TLVID) &
194 1.1 cgd TLVID_VIDA_MASK) >> TLVID_VIDA_SHIFT;
195 1.8 mjacob printf(", VID %d -> %s", vid, cfd->cd_name);
196 1.1 cgd printf("\n");
197 1.1 cgd TLSB_PUT_NODEREG(node, TLCPUMASK, (1<<vid));
198 1.1 cgd }
199 1.1 cgd /*
200 1.1 cgd * Attach any children nodes, including a CPU's GBus
201 1.1 cgd */
202 1.1 cgd config_found_sm(self, &ta, tlsbprint, tlsbsubmatch);
203 1.1 cgd }
204 1.1 cgd /*
205 1.1 cgd * *Now* search for I/O nodes (in descending order)
206 1.1 cgd */
207 1.1 cgd while (--node > 0) {
208 1.1 cgd if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
209 1.1 cgd continue;
210 1.1 cgd tldev = TLSB_GET_NODEREG(node, TLDEV);
211 1.1 cgd if (tldev == 0) {
212 1.1 cgd continue;
213 1.1 cgd }
214 1.1 cgd if (TLDEV_ISIOPORT(tldev)) {
215 1.1 cgd ta.ta_node = node;
216 1.1 cgd ta.ta_dtype = TLDEV_DTYPE(tldev);
217 1.1 cgd ta.ta_swrev = TLDEV_SWREV(tldev);
218 1.1 cgd ta.ta_hwrev = TLDEV_HWREV(tldev);
219 1.1 cgd config_found_sm(self, &ta, tlsbprint, tlsbsubmatch);
220 1.1 cgd }
221 1.1 cgd }
222 1.1 cgd }
223 1.1 cgd
224 1.1 cgd static char *
225 1.1 cgd tlsb_node_type_str(dtype)
226 1.1 cgd u_int32_t dtype;
227 1.1 cgd {
228 1.1 cgd static char tlsb_line[64];
229 1.1 cgd
230 1.1 cgd switch (dtype & TLDEV_DTYPE_MASK) {
231 1.1 cgd case TLDEV_DTYPE_KFTHA:
232 1.1 cgd return ("KFTHA I/O interface");
233 1.1 cgd
234 1.1 cgd case TLDEV_DTYPE_KFTIA:
235 1.1 cgd return ("KFTIA I/O interface");
236 1.1 cgd
237 1.1 cgd case TLDEV_DTYPE_MS7CC:
238 1.1 cgd return ("MS7CC Memory Module");
239 1.1 cgd
240 1.1 cgd case TLDEV_DTYPE_SCPU4:
241 1.1 cgd return ("Single CPU, 4MB cache");
242 1.1 cgd
243 1.1 cgd case TLDEV_DTYPE_SCPU16:
244 1.1 cgd return ("Single CPU, 16MB cache");
245 1.1 cgd
246 1.1 cgd case TLDEV_DTYPE_DCPU4:
247 1.1 cgd return ("Dual CPU, 4MB cache");
248 1.1 cgd
249 1.1 cgd case TLDEV_DTYPE_DCPU16:
250 1.1 cgd return ("Dual CPU, 16MB cache");
251 1.1 cgd
252 1.1 cgd default:
253 1.1 cgd bzero(tlsb_line, sizeof(tlsb_line));
254 1.1 cgd sprintf(tlsb_line, "unknown, dtype 0x%x", dtype);
255 1.1 cgd return (tlsb_line);
256 1.1 cgd }
257 1.1 cgd /* NOTREACHED */
258 1.1 cgd }
259