summaryrefslogtreecommitdiffstats
path: root/sys/alpha/tlsb/tlsb.c
blob: f1097b20a4a15cdc9a50f090c58624b241694ec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/* $Id */
/* $NetBSD: tlsb.c,v 1.10 1998/05/14 00:01:32 thorpej Exp $ */

/*
 * Copyright (c) 1997 by Matthew Jacob
 * NASA AMES Research Center.
 * All rights reserved.
 *
 * Based in part upon a prototype version by Jason Thorpe
 * Copyright (c) 1996 by Jason Thorpe.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice immediately at the beginning of the file, without modification,
 *    this list of conditions, and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * Autoconfiguration and support routines for the TurboLaser System Bus
 * found on AlphaServer 8200 and 8400 systems.
 */

#include "opt_simos.h"

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/malloc.h>

#include <machine/rpb.h>
#include <machine/cpuconf.h>

#include <alpha/tlsb/tlsbreg.h>
#include <alpha/tlsb/tlsbvar.h>

/* #include "locators.h" */

extern int	cputype;

#define KV(_addr)	((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))

/*
 * The structure used to attach devices to the TurboLaser.
 */
struct tlsb_device {
	int		td_node;	/* node number */
	u_int16_t	td_dtype;	/* device type */
	u_int8_t	td_swrev;	/* software revision */
	u_int8_t	td_hwrev;	/* hardware revision */
};
#define DEVTOTLSB(dev)	((struct tlsb_device*) device_get_ivars(dev))

struct intr_mapping {
	STAILQ_ENTRY(intr_mapping) queue;
	driver_intr_t*	intr;
	void*		arg;
};

struct tlsb_softc {
	STAILQ_HEAD(, intr_mapping) intr_handlers;
};

static char	*tlsb_node_type_str(u_int32_t);
static void	tlsb_intr(void* frame, u_long vector);

/* There can be only one. */
static int			tlsb_found;
static struct tlsb_softc*	tlsb0_softc;
static devclass_t		tlsb_devclass;

/*
 * Device methods
 */
static int tlsb_probe(device_t dev);
static void tlsb_print_child(device_t dev, device_t child);
static int tlsb_read_ivar(device_t dev, device_t child, int which, u_long* result);
static int tlsb_setup_intr(device_t dev, device_t child,
			   struct resource *irq, int flags,
			   driver_intr_t *intr, void *arg, void **cookiep);
static int tlsb_teardown_intr(device_t dev, device_t child,
			      struct resource *irq, void *cookie);

static device_method_t tlsb_methods[] = {
	/* Device interface */
	DEVMETHOD(device_probe,		tlsb_probe),
	DEVMETHOD(device_attach,	bus_generic_attach),
	DEVMETHOD(device_detach,	bus_generic_detach),
	DEVMETHOD(device_shutdown,	bus_generic_shutdown),

	/* Bus interface */
	DEVMETHOD(bus_print_child,	tlsb_print_child),
	DEVMETHOD(bus_read_ivar,	tlsb_read_ivar),
	DEVMETHOD(bus_write_ivar,	bus_generic_write_ivar),
	DEVMETHOD(bus_setup_intr,	tlsb_setup_intr),
	DEVMETHOD(bus_teardown_intr,	tlsb_teardown_intr),

	{ 0, 0 }
};

static driver_t tlsb_driver = {
	"tlsb",
	tlsb_methods,
	sizeof(struct tlsb_softc),
};

/*
 * At 'probe' time, we add all the devices which we know about to the
 * bus.  The generic attach routine will probe and attach them if they
 * are alive.
 */
static int
tlsb_probe(device_t dev)
{
	struct tlsb_softc* sc = device_get_softc(dev);
	struct tlsb_device *tdev;
	u_int32_t tldev;
	u_int8_t vid;
	int node;
	device_t child;

	device_set_desc(dev, "TurboLaser bus");

	STAILQ_INIT(&sc->intr_handlers);
	tlsb0_softc = sc;

	set_iointr(tlsb_intr);

	printf("Probing for devices on the TurboLaser bus:\n");

	tlsb_found = 1;

	/*
	 * Attempt to find all devices on the bus, including
	 * CPUs, memory modules, and I/O modules.
	 */

	/*
	 * Sigh. I would like to just start off nicely,
	 * but I need to treat I/O modules differently-
	 * The highest priority I/O node has to be in
	 * node #8, and I want to find it *first*, since
	 * it will have the primary disks (most likely)
	 * on it.
	 */
	/*
	 * XXX dfr: I don't see why I need to do this
	 */
	for (node = 0; node <= TLSB_NODE_MAX; ++node) {
		/*
		 * Check for invalid address.  This may not really
		 * be necessary, but what the heck...
		 */
		if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
			continue;
		tldev = TLSB_GET_NODEREG(node, TLDEV);
#ifdef SIMOS
		if (node != 0 && node != 8)
			continue;
#endif
		if (tldev == 0) {
			/* Nothing at this node. */
			continue;
		}
#if 0
		if (TLDEV_ISIOPORT(tldev))
			continue;	/* not interested right now */
#endif

		tdev = (struct tlsb_device*)
			malloc(sizeof(struct tlsb_device),
			       M_DEVBUF, M_NOWAIT);

		if (!tdev)
			continue;

		tdev->td_node = node;
#ifdef SIMOS
		if (node == 0)
			tdev->td_dtype = TLDEV_DTYPE_SCPU4;
		else if (node == 8)
			tdev->td_dtype = TLDEV_DTYPE_KFTIA;
#else
		tdev->td_dtype = TLDEV_DTYPE(tldev);
#endif
		tdev->td_swrev = TLDEV_SWREV(tldev);
		tdev->td_hwrev = TLDEV_HWREV(tldev);

		child = device_add_child(dev, NULL, -1, tdev);
		device_set_desc(child, tlsb_node_type_str(tdev->td_dtype));

		/*
		 * Deal with hooking CPU instances to TurboLaser nodes.
		 */
		if (TLDEV_ISCPU(tldev)) {
			printf("%s%d node %d: %s",
			       device_get_name(dev), device_get_unit(dev),
			       node, tlsb_node_type_str(tldev));

			/*
			 * Hook in the first CPU unit.
			 */
			vid = (TLSB_GET_NODEREG(node, TLVID) &
			    TLVID_VIDA_MASK) >> TLVID_VIDA_SHIFT;
			printf(", VID %d\n", vid);
			TLSB_PUT_NODEREG(node, TLCPUMASK, (1<<vid));
		}
	}

	return 0;
}

static void
tlsb_print_child(device_t dev, device_t child)
{
	struct tlsb_device* tdev = DEVTOTLSB(child);

	printf(" at %s%d node %d",
	       device_get_name(dev),
	       device_get_unit(dev),
	       tdev->td_node);
}

static int
tlsb_read_ivar(device_t dev, device_t child,
	       int index, u_long* result)
{
	struct tlsb_device* tdev = DEVTOTLSB(child);

	switch (index) {
	case TLSB_IVAR_NODE:
		*result = tdev->td_node;
		break;

	case TLSB_IVAR_DTYPE:
		*result = tdev->td_dtype;
		break;

	case TLSB_IVAR_SWREV:
		*result = tdev->td_swrev;
		break;

	case TLSB_IVAR_HWREV:
		*result = tdev->td_hwrev;
		break;
	}
	return ENOENT;
}

static int
tlsb_setup_intr(device_t dev, device_t child,
		struct resource *irq, int flags,
		driver_intr_t *intr, void *arg, void **cookiep)
{
	struct tlsb_softc* sc = device_get_softc(dev);
	struct intr_mapping* i;
	i = malloc(sizeof(struct intr_mapping), M_DEVBUF, M_NOWAIT);
	if (!i)
		return ENOMEM;
	i->intr = intr;
	i->arg = arg;
	STAILQ_INSERT_TAIL(&sc->intr_handlers, i, queue);
	*cookiep = i;
	return 0;
}

static int
tlsb_teardown_intr(device_t dev, device_t child,
		   struct resource *irq, void *cookie)
{
	struct tlsb_softc* sc = device_get_softc(dev);
	struct intr_mapping* i = cookie;

	STAILQ_REMOVE(&sc->intr_handlers, i, intr_mapping, queue); 
	free(i, M_DEVBUF);
	return 0;
}

static void
tlsb_intr(void* frame, u_long vector)
{
	struct tlsb_softc* sc = tlsb0_softc;
	struct intr_mapping* i;

	/*
	 * XXX for SimOS, broadcast the interrupt.  A real implementation
	 * will decode the vector to extract node and host etc.
	 */
	for (i = STAILQ_FIRST(&sc->intr_handlers);
	     i; i = STAILQ_NEXT(i, queue))
		i->intr(i->arg);
}

DRIVER_MODULE(tlsb, root, tlsb_driver, tlsb_devclass, 0, 0);

static char *
tlsb_node_type_str(u_int32_t dtype)
{
	static char	tlsb_line[64];

	switch (dtype & TLDEV_DTYPE_MASK) {
	case TLDEV_DTYPE_KFTHA:
		return ("KFTHA I/O interface");

	case TLDEV_DTYPE_KFTIA:
		return ("KFTIA I/O interface");

	case TLDEV_DTYPE_MS7CC:
		return ("MS7CC Memory Module");

	case TLDEV_DTYPE_SCPU4:
		return ("Single CPU, 4MB cache");

	case TLDEV_DTYPE_SCPU16:
		return ("Single CPU, 16MB cache");

	case TLDEV_DTYPE_DCPU4:
		return ("Dual CPU, 4MB cache");

	case TLDEV_DTYPE_DCPU16:
		return ("Dual CPU, 16MB cache");

	default:
		bzero(tlsb_line, sizeof(tlsb_line));
		snprintf(tlsb_line, sizeof(tlsb_line),
			"unknown, dtype 0x%x", dtype);
		return (tlsb_line);
	}
	/* NOTREACHED */
}
OpenPOWER on IntegriCloud