xref: /netbsd/sys/arch/alpha/alpha/dec_6600.c (revision 6550d01e)
1 /* $NetBSD: dec_6600.c,v 1.30 2010/10/07 19:55:02 hans Exp $ */
2 
3 /*
4  * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
5  * All rights reserved.
6  *
7  * Author: Chris G. Demetriou
8  *
9  * Permission to use, copy, modify and distribute this software and
10  * its documentation is hereby granted, provided that both the copyright
11  * notice and this permission notice appear in all copies of the
12  * software, derivative works or modified versions, and any portions
13  * thereof, and that both notices appear in supporting documentation.
14  *
15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie the
27  * rights to redistribute these changes.
28  */
29 
30 #include "opt_kgdb.h"
31 
32 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
33 
34 __KERNEL_RCSID(0, "$NetBSD: dec_6600.c,v 1.30 2010/10/07 19:55:02 hans Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/termios.h>
40 #include <sys/conf.h>
41 #include <dev/cons.h>
42 
43 #include <machine/rpb.h>
44 #include <machine/autoconf.h>
45 #include <machine/cpuconf.h>
46 #include <machine/bus.h>
47 #include <machine/alpha.h>
48 #include <machine/logout.h>
49 
50 #include <dev/ic/comreg.h>
51 #include <dev/ic/comvar.h>
52 
53 #include <dev/isa/isareg.h>
54 #include <dev/isa/isavar.h>
55 #include <dev/ic/i8042reg.h>
56 #include <dev/ic/pckbcvar.h>
57 #include <dev/pci/pcireg.h>
58 #include <dev/pci/pcivar.h>
59 
60 #include <alpha/pci/tsreg.h>
61 #include <alpha/pci/tsvar.h>
62 
63 #include <dev/scsipi/scsi_all.h>
64 #include <dev/scsipi/scsipi_all.h>
65 #include <dev/scsipi/scsiconf.h>
66 #include <dev/ata/atavar.h>
67 
68 #include <dev/ic/mlxio.h>
69 #include <dev/ic/mlxvar.h>
70 
71 #include <dev/i2o/i2o.h>
72 #include <dev/i2o/iopio.h>
73 #include <dev/i2o/iopvar.h>
74 
75 #include "pckbd.h"
76 
77 #ifndef CONSPEED
78 #define CONSPEED TTYDEF_SPEED
79 #endif
80 
81 #define	DR_VERBOSE(f) while (0)
82 
83 static int comcnrate __attribute__((unused)) = CONSPEED;
84 
85 void dec_6600_init(void);
86 static void dec_6600_cons_init(void);
87 static void dec_6600_device_register(struct device *, void *);
88 static void dec_6600_mcheck(unsigned long, struct ev6_logout_area *);
89 static void dec_6600_mcheck_sys(unsigned int, struct ev6_logout_area *);
90 static void dec_6600_mcheck_handler(unsigned long, struct trapframe *,
91 				    unsigned long, unsigned long);
92 
93 #ifdef KGDB
94 #include <machine/db_machdep.h>
95 
96 static const char *kgdb_devlist[] = {
97 	"com",
98 	NULL,
99 };
100 #endif /* KGDB */
101 
102 void
103 dec_6600_init()
104 {
105 
106 	platform.family = "6600";
107 
108 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
109 		/* XXX Don't know the system variations, yet. */
110 		platform.model = alpha_unknown_sysname();
111 	}
112 
113 	platform.iobus = "tsc";
114 	platform.cons_init = dec_6600_cons_init;
115 	platform.device_register = dec_6600_device_register;
116 	platform.mcheck_handler = dec_6600_mcheck_handler;
117 
118 	/* enable Cchip and Pchip error interrupts */
119 	STQP(TS_C_DIM0) = 0xe000000000000000;
120 	STQP(TS_C_DIM1) = 0xe000000000000000;
121 }
122 
123 static void
124 dec_6600_cons_init()
125 {
126 	struct ctb *ctb;
127 	u_int64_t ctbslot;
128 	struct tsp_config *tsp;
129 
130 	ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
131 	ctbslot = ctb->ctb_turboslot;
132 
133 	/* Console hose defaults to hose 0. */
134 	tsp_console_hose = 0;
135 
136 	tsp = tsp_init(0, tsp_console_hose);
137 
138 	switch (ctb->ctb_term_type) {
139 	case CTB_PRINTERPORT:
140 		/* serial console ... */
141 		assert(CTB_TURBOSLOT_HOSE(ctbslot) == 0);
142 		/* XXX */
143 		{
144 			/*
145 			 * Delay to allow PROM putchars to complete.
146 			 * FIFO depth * character time,
147 			 * character time = (1000000 / (defaultrate / 10))
148 			 */
149 			DELAY(160000000 / comcnrate);
150 
151 			if(comcnattach(&tsp->pc_iot, 0x3f8, comcnrate,
152 			    COM_FREQ, COM_TYPE_NORMAL,
153 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
154 				panic("can't init serial console");
155 
156 			break;
157 		}
158 
159 	case CTB_GRAPHICS:
160 #if NPCKBD > 0
161 		/* display console ... */
162 		/* XXX */
163 		(void) pckbc_cnattach(&tsp->pc_iot, IO_KBD, KBCMDP,
164 		    PCKBC_KBD_SLOT);
165 
166 		if (CTB_TURBOSLOT_TYPE(ctbslot) ==
167 		    CTB_TURBOSLOT_TYPE_ISA)
168 			isa_display_console(&tsp->pc_iot, &tsp->pc_memt);
169 		else {
170 			/* The display PCI might be different */
171 			tsp_console_hose = CTB_TURBOSLOT_HOSE(ctbslot);
172 			tsp = tsp_init(0, tsp_console_hose);
173 			pci_display_console(&tsp->pc_iot, &tsp->pc_memt,
174 			    &tsp->pc_pc, CTB_TURBOSLOT_BUS(ctbslot),
175 			    CTB_TURBOSLOT_SLOT(ctbslot), 0);
176 		}
177 #else
178 		panic("not configured to use display && keyboard console");
179 #endif
180 		break;
181 
182 	default:
183 		printf("ctb_term_type = 0x%lx ctb_turboslot = 0x%lx"
184 		    " hose = %ld\n", ctb->ctb_term_type, ctbslot,
185 		    CTB_TURBOSLOT_HOSE(ctbslot));
186 
187 		panic("consinit: unknown console type %ld",
188 		    ctb->ctb_term_type);
189 	}
190 #ifdef KGDB
191 	/* Attach the KGDB device. */
192 	alpha_kgdb_init(kgdb_devlist, &tsp->pc_iot);
193 #endif /* KGDB */
194 }
195 
196 static void
197 dec_6600_device_register(struct device *dev, void *aux)
198 {
199 	static int found, initted, diskboot, netboot;
200 	static struct device *primarydev, *pcidev, *ctrlrdev;
201 	struct bootdev_data *b = bootdev_data;
202 	struct device *parent = device_parent(dev);
203 
204 	if (found)
205 		return;
206 
207 	if (!initted) {
208 		diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
209 		    (strcasecmp(b->protocol, "RAID") == 0) ||
210 		    (strcasecmp(b->protocol, "I2O") == 0) ||
211 		    (strcasecmp(b->protocol, "IDE") == 0);
212 		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
213 		    (strcasecmp(b->protocol, "MOP") == 0);
214 		DR_VERBOSE(printf("diskboot = %d, netboot = %d\n", diskboot,
215 		    netboot));
216 		initted = 1;
217 	}
218 
219 	if (primarydev == NULL) {
220 		if (!device_is_a(dev, "tsp"))
221 			return;
222 		else {
223 			struct tsp_attach_args *tsp = aux;
224 
225 			if (b->bus != tsp->tsp_slot)
226 				return;
227 			primarydev = dev;
228 			DR_VERBOSE(printf("\nprimarydev = %s\n",
229 			    dev->dv_xname));
230 			return;
231 		}
232 	}
233 
234 	if (pcidev == NULL) {
235 		if (!device_is_a(dev, "pci"))
236 			return;
237 		/*
238 		 * Try to find primarydev anywhere in the ancestry.  This is
239 		 * necessary if the PCI bus is hidden behind a bridge.
240 		 */
241 		while (parent) {
242 			if (parent == primarydev)
243 				break;
244 			parent = device_parent(parent);
245 		}
246 		if (!parent)
247 			return;
248 		else {
249 			struct pcibus_attach_args *pba = aux;
250 
251 			if ((b->slot / 1000) != pba->pba_bus)
252 				return;
253 
254 			pcidev = dev;
255 			DR_VERBOSE(printf("\npcidev = %s\n", dev->dv_xname));
256 			return;
257 		}
258 	}
259 
260 	if (ctrlrdev == NULL) {
261 		if (parent != pcidev)
262 			return;
263 		else {
264 			struct pci_attach_args *pa = aux;
265 			int slot;
266 
267 			slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
268 			    pa->pa_device;
269 			if (b->slot != slot)
270 				return;
271 
272 			if (netboot) {
273 				booted_device = dev;
274 				DR_VERBOSE(printf("\nbooted_device = %s\n",
275 				    dev->dv_xname));
276 				found = 1;
277 			} else {
278 				ctrlrdev = dev;
279 				DR_VERBOSE(printf("\nctrlrdev = %s\n",
280 				    dev->dv_xname));
281 			}
282 			return;
283 		}
284 	}
285 
286 	if (!diskboot)
287 		return;
288 
289 	if (device_is_a(dev, "sd") ||
290 	    device_is_a(dev, "st") ||
291 	    device_is_a(dev, "cd")) {
292 		struct scsipibus_attach_args *sa = aux;
293 		struct scsipi_periph *periph = sa->sa_periph;
294 		int unit;
295 
296 		if (device_parent(parent) != ctrlrdev)
297 			return;
298 
299 		unit = periph->periph_target * 100 + periph->periph_lun;
300 		if (b->unit != unit)
301 			return;
302 		if (b->channel != periph->periph_channel->chan_channel)
303 			return;
304 
305 		/* we've found it! */
306 		booted_device = dev;
307 		DR_VERBOSE(printf("\nbooted_device = %s\n", dev->dv_xname));
308 		found = 1;
309 	}
310 
311 	if (device_is_a(dev, "ld") && device_is_a(parent, "iop")) {
312 		/*
313 		 * Argh!  The attach arguments for ld devices is not
314 		 * consistent, so each supported raid controller requires
315 		 * different checks.
316 		 */
317 		struct iop_attach_args *iopa = aux;
318 
319 		if (parent != ctrlrdev)
320 			return;
321 
322 		if (b->unit != iopa->ia_tid)
323 			return;
324 		/* we've found it! */
325 		booted_device = dev;
326 		DR_VERBOSE(printf("\nbooted_device = %s\n", dev->dv_xname));
327 		found = 1;
328 	}
329 
330 	if (device_is_a(dev, "ld") && device_is_a(parent, "mlx")) {
331 		/*
332 		 * Argh!  The attach arguments for ld devices is not
333 		 * consistent, so each supported raid controller requires
334 		 * different checks.
335 		 */
336 		struct mlx_attach_args *mlxa = aux;
337 
338 		if (parent != ctrlrdev)
339 			return;
340 
341 		if (b->unit != mlxa->mlxa_unit)
342 			return;
343 		/* we've found it! */
344 		booted_device = dev;
345 		DR_VERBOSE(printf("\nbooted_device = %s\n", dev->dv_xname));
346 		found = 1;
347 	}
348 
349 	/*
350 	 * Support to boot from IDE drives.
351 	 */
352 	if (device_is_a(dev, "wd")) {
353 		struct ata_device *adev = aux;
354 
355 		if (!device_is_a(parent, "atabus"))
356 			return;
357 		if (device_parent(parent) != ctrlrdev)
358 			return;
359 
360 		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
361 		    adev->adev_drv_data->drive, adev->adev_channel));
362 		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
363 		    b->unit, b->channel));
364 		if (b->unit != adev->adev_drv_data->drive ||
365 		    b->channel != adev->adev_channel)
366 			return;
367 
368 		/* we've found it! */
369 		booted_device = dev;
370 		DR_VERBOSE(printf("booted_device = %s\n", dev->dv_xname));
371 		found = 1;
372 	}
373 }
374 
375 
376 static void
377 dec_6600_mcheck(unsigned long vector, struct ev6_logout_area *la)
378 {
379 	const char *t = "Unknown", *c = "";
380 
381 	if (vector == ALPHA_SYS_ERROR || vector == ALPHA_PROC_ERROR)
382 		c = " Correctable";
383 
384 	switch (vector) {
385 	case ALPHA_SYS_ERROR:
386 	case ALPHA_SYS_MCHECK:
387 		t = "System";
388 		break;
389 
390 	case ALPHA_PROC_ERROR:
391 	case ALPHA_PROC_MCHECK:
392 		t = "Processor";
393 		break;
394 
395 	case ALPHA_ENV_MCHECK:
396 		t = "Environmental";
397 		break;
398 	}
399 
400 	printf("\n%s%s Machine Check (%lx): "
401 	       "Rev 0x%x, Code 0x%x, Flags 0x%x\n\n",
402 	       t, c, vector, la->mchk_rev, la->mchk_code, la->la.la_flags);
403 }
404 
405 static void
406 dec_6600_mcheck_sys(unsigned int indent, struct ev6_logout_area *la)
407 {
408 	struct ev6_logout_sys *ls =
409 		(struct ev6_logout_sys *)ALPHA_LOGOUT_SYSTEM_AREA(&la->la);
410 
411 #define FMT	"%-30s = 0x%016lx\n"
412 
413 	IPRINTF(indent, FMT, "Software Error Summary Flags", ls->flags);
414 
415 	IPRINTF(indent, FMT, "CPU Device Interrupt Requests", ls->dir);
416 	tsc_print_dir(indent + 1, ls->dir);
417 
418 	IPRINTF(indent, FMT, "Cchip Miscellaneous Register", ls->misc);
419 	tsc_print_misc(indent + 1, ls->misc);
420 
421 	IPRINTF(indent, FMT, "Pchip 0 Error Register", ls->p0_error);
422 	if (ls->flags & 0x5)
423 		tsp_print_error(indent + 1, ls->p0_error);
424 
425 	IPRINTF(indent, FMT, "Pchip 1 Error Register", ls->p1_error);
426 	if (ls->flags & 0x6)
427 		tsp_print_error(indent + 1, ls->p1_error);
428 }
429 
430 static void
431 dec_6600_mcheck_handler(unsigned long mces, struct trapframe *framep,
432 			unsigned long vector, unsigned long param)
433 {
434 	struct mchkinfo *mcp;
435 	struct ev6_logout_area *la = (struct ev6_logout_area *)param;
436 
437 	/*
438 	 * If we expected a machine check, just go handle it in common code.
439 	 */
440 	mcp = &curcpu()->ci_mcinfo;
441 	if (mcp->mc_expected)
442 		machine_check(mces, framep, vector, param);
443 
444 	dec_6600_mcheck(vector, la);
445 
446 	switch (vector) {
447 	case ALPHA_SYS_ERROR:
448 	case ALPHA_SYS_MCHECK:
449 		dec_6600_mcheck_sys(1, la);
450 		break;
451 
452 	}
453 
454 	machine_check(mces, framep, vector, param);
455 }
456