xref: /netbsd-src/sys/arch/alpha/alpha/dec_6600.c (revision 33e1df375d6dc609ceb4b70418d8342d90fbd3ef)
1 /* $NetBSD: dec_6600.c,v 1.38 2024/03/31 19:11:21 thorpej 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.38 2024/03/31 19:11:21 thorpej Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/lwp.h>
40 #include <sys/termios.h>
41 
42 #include <sys/conf.h>
43 #include <dev/cons.h>
44 
45 #include <machine/rpb.h>
46 #include <machine/autoconf.h>
47 #include <machine/cpuconf.h>
48 #include <sys/bus.h>
49 #include <machine/alpha.h>
50 #include <machine/logout.h>
51 
52 #include <dev/ic/comreg.h>
53 #include <dev/ic/comvar.h>
54 
55 #include <dev/isa/isareg.h>
56 #include <dev/isa/isavar.h>
57 #include <dev/ic/i8042reg.h>
58 #include <dev/ic/pckbcvar.h>
59 #include <dev/pci/pcireg.h>
60 #include <dev/pci/pcivar.h>
61 
62 #include <alpha/pci/tsreg.h>
63 #include <alpha/pci/tsvar.h>
64 
65 #include <dev/scsipi/scsi_all.h>
66 #include <dev/scsipi/scsipi_all.h>
67 #include <dev/scsipi/scsiconf.h>
68 #include <dev/ata/atavar.h>
69 
70 #include <dev/ic/mlxio.h>
71 #include <dev/ic/mlxvar.h>
72 
73 #include <dev/i2o/i2o.h>
74 #include <dev/i2o/iopio.h>
75 #include <dev/i2o/iopvar.h>
76 
77 #include "pckbd.h"
78 
79 #ifndef CONSPEED
80 #define CONSPEED TTYDEF_SPEED
81 #endif
82 
83 #define	DR_VERBOSE(f) while (0)
84 
85 static int comcnrate __attribute__((unused)) = CONSPEED;
86 
87 void dec_6600_init(void);
88 static void dec_6600_cons_init(void);
89 static void dec_6600_device_register(device_t, void *);
90 static void dec_6600_mcheck(unsigned long, struct ev6_logout_area *);
91 static void dec_6600_mcheck_sys(unsigned int, struct ev6_logout_area *);
92 static void dec_6600_mcheck_handler(unsigned long, struct trapframe *,
93 				    unsigned long, unsigned long);
94 
95 #ifdef KGDB
96 #include <machine/db_machdep.h>
97 
98 static const char *kgdb_devlist[] = {
99 	"com",
100 	NULL,
101 };
102 #endif /* KGDB */
103 
104 static const struct alpha_variation_table dec_6600_variations[] = {
105 	{ SV_ST_DP264, "AlphaPC DP264" },
106 	{ SV_ST_CLIPPER, "AlphaServer ES40 (\"Clipper\")" },
107 	{ SV_ST_GOLDRUSH, "AlphaServer DS20 (\"GoldRush\")" },
108 	{ SV_ST_WEBBRICK, "AlphaServer DS10 (\"WebBrick\")" },
109 	{ SV_ST_SHARK, "AlphaServer DS20L (\"Shark\")" },
110 	{ 0, NULL },
111 };
112 
113 static const struct alpha_variation_table dec_titan_variations[] = {
114 	{ 0, NULL },
115 };
116 
117 void
dec_6600_init(void)118 dec_6600_init(void)
119 {
120 	uint64_t variation;
121 
122 	platform.family = (hwrpb->rpb_type == ST_DEC_TITAN) ? "Titan"
123 							    : "6600";
124 
125 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
126 		const struct alpha_variation_table *vartab =
127 		    (hwrpb->rpb_type == ST_DEC_TITAN) ? dec_titan_variations
128 						      : dec_6600_variations;
129 		variation = hwrpb->rpb_variation & SV_ST_MASK;
130 		if ((platform.model = alpha_variation_name(variation,
131 							   vartab)) == NULL) {
132 			platform.model = alpha_unknown_sysname();
133 		}
134 	}
135 
136 	platform.iobus = "tsc";
137 	platform.cons_init = dec_6600_cons_init;
138 	platform.device_register = dec_6600_device_register;
139 	platform.mcheck_handler = dec_6600_mcheck_handler;
140 
141 	/* enable Cchip and Pchip error interrupts */
142 	STQP(TS_C_DIM0) = 0xe000000000000000;
143 	STQP(TS_C_DIM1) = 0xe000000000000000;
144 }
145 
146 static void
dec_6600_cons_init(void)147 dec_6600_cons_init(void)
148 {
149 	struct ctb *ctb;
150 	uint64_t ctbslot;
151 	struct tsp_config *tsp;
152 
153 	ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
154 	ctbslot = ctb->ctb_turboslot;
155 
156 	/* Console hose defaults to hose 0. */
157 	tsp_console_hose = 0;
158 
159 	tsp = tsp_init(tsp_console_hose);
160 
161 	switch (ctb->ctb_term_type) {
162 	case CTB_PRINTERPORT:
163 		/* serial console ... */
164 		assert(CTB_TURBOSLOT_HOSE(ctbslot) == 0);
165 		/* XXX */
166 		{
167 			/*
168 			 * Delay to allow PROM putchars to complete.
169 			 * FIFO depth * character time,
170 			 * character time = (1000000 / (defaultrate / 10))
171 			 */
172 			DELAY(160000000 / comcnrate);
173 
174 			if(comcnattach(&tsp->pc_iot, 0x3f8, comcnrate,
175 			    COM_FREQ, COM_TYPE_NORMAL,
176 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
177 				panic("can't init serial console");
178 
179 			break;
180 		}
181 
182 	case CTB_GRAPHICS:
183 #if NPCKBD > 0
184 		/* display console ... */
185 		/* XXX */
186 		(void) pckbc_cnattach(&tsp->pc_iot, IO_KBD, KBCMDP,
187 		    PCKBC_KBD_SLOT, 0);
188 
189 		if (CTB_TURBOSLOT_TYPE(ctbslot) ==
190 		    CTB_TURBOSLOT_TYPE_ISA)
191 			isa_display_console(&tsp->pc_iot, &tsp->pc_memt);
192 		else {
193 			/* The display PCI might be different */
194 			tsp_console_hose = CTB_TURBOSLOT_HOSE(ctbslot);
195 			tsp = tsp_init(tsp_console_hose);
196 			pci_display_console(&tsp->pc_iot, &tsp->pc_memt,
197 			    &tsp->pc_pc, CTB_TURBOSLOT_BUS(ctbslot),
198 			    CTB_TURBOSLOT_SLOT(ctbslot), 0);
199 		}
200 #else
201 		panic("not configured to use display && keyboard console");
202 #endif
203 		break;
204 
205 	default:
206 		printf("ctb_term_type = 0x%lx ctb_turboslot = 0x%lx"
207 		    " hose = %ld\n", ctb->ctb_term_type, ctbslot,
208 		    CTB_TURBOSLOT_HOSE(ctbslot));
209 
210 		panic("consinit: unknown console type %ld",
211 		    ctb->ctb_term_type);
212 	}
213 #ifdef KGDB
214 	/* Attach the KGDB device. */
215 	alpha_kgdb_init(kgdb_devlist, &tsp->pc_iot);
216 #endif /* KGDB */
217 }
218 
219 static void
dec_6600_device_register(device_t dev,void * aux)220 dec_6600_device_register(device_t dev, void *aux)
221 {
222 	static int found, initted, diskboot, netboot;
223 	static device_t primarydev, pcidev, ctrlrdev;
224 	struct bootdev_data *b = bootdev_data;
225 	device_t parent = device_parent(dev);
226 
227 	/*
228 	 * First section: Deal with system-specific quirks.
229 	 */
230 
231 	if ((hwrpb->rpb_variation & SV_ST_MASK) == SV_ST_WEBBRICK) {
232 		/*
233 		 * DMA on the on-board ALI IDE controller is not
234 		 * working correctly; disable it for now to let
235 		 * the systems at least hobble along.
236 		 *
237 		 * N.B. There's only one Pchip on a DS10, do there
238 		 * is not need to determine which hose we have here.
239 		 *
240 		 * XXX This is meant to be temporary until we can find
241 		 * XXX and fix the issue with bus-master DMA.
242 		 */
243 		if (device_is_a(parent, "pci") && device_is_a(dev, "aceride")) {
244 			struct pci_attach_args *pa = aux;
245 
246 			if (pa->pa_bus == 0 && pa->pa_device == 13 &&
247 			    pa->pa_function == 0) {
248 				prop_dictionary_set_bool(device_properties(dev),
249 				    "pciide-disable-dma", true);
250 			}
251 		}
252 	}
253 
254 	/*
255 	 * Second section: Boot device detection.
256 	 */
257 
258 	if (b == NULL || found)
259 		return;
260 
261 	if (!initted) {
262 		diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
263 		    (strcasecmp(b->protocol, "RAID") == 0) ||
264 		    (strcasecmp(b->protocol, "I2O") == 0) ||
265 		    (strcasecmp(b->protocol, "IDE") == 0);
266 		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
267 		    (strcasecmp(b->protocol, "MOP") == 0);
268 		DR_VERBOSE(printf("diskboot = %d, netboot = %d\n", diskboot,
269 		    netboot));
270 		initted = 1;
271 	}
272 
273 	if (primarydev == NULL) {
274 		if (!device_is_a(dev, "tsp"))
275 			return;
276 		else {
277 			struct tsp_attach_args *tsp = aux;
278 
279 			if (b->bus != tsp->tsp_slot)
280 				return;
281 			primarydev = dev;
282 			DR_VERBOSE(printf("\nprimarydev = %s\n",
283 			    device_xname(dev)));
284 			return;
285 		}
286 	}
287 
288 	if (pcidev == NULL) {
289 		if (!device_is_a(dev, "pci"))
290 			return;
291 		/*
292 		 * Try to find primarydev anywhere in the ancestry.  This is
293 		 * necessary if the PCI bus is hidden behind a bridge.
294 		 */
295 		while (parent) {
296 			if (parent == primarydev)
297 				break;
298 			parent = device_parent(parent);
299 		}
300 		if (!parent)
301 			return;
302 		else {
303 			struct pcibus_attach_args *pba = aux;
304 
305 			if ((b->slot / 1000) != pba->pba_bus)
306 				return;
307 
308 			pcidev = dev;
309 			DR_VERBOSE(printf("\npcidev = %s\n", device_xname(dev)));
310 			return;
311 		}
312 	}
313 
314 	if (ctrlrdev == NULL) {
315 		if (parent != pcidev)
316 			return;
317 		else {
318 			struct pci_attach_args *pa = aux;
319 			int slot;
320 
321 			slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
322 			    pa->pa_device;
323 			if (b->slot != slot)
324 				return;
325 
326 			if (netboot) {
327 				booted_device = dev;
328 				DR_VERBOSE(printf("\nbooted_device = %s\n",
329 				    device_xname(dev)));
330 				found = 1;
331 			} else {
332 				ctrlrdev = dev;
333 				DR_VERBOSE(printf("\nctrlrdev = %s\n",
334 				    device_xname(dev)));
335 			}
336 			return;
337 		}
338 	}
339 
340 	if (!diskboot)
341 		return;
342 
343 	if (device_is_a(dev, "sd") ||
344 	    device_is_a(dev, "st") ||
345 	    device_is_a(dev, "cd")) {
346 		struct scsipibus_attach_args *sa = aux;
347 		struct scsipi_periph *periph = sa->sa_periph;
348 		int unit;
349 
350 		if (device_parent(parent) != ctrlrdev)
351 			return;
352 
353 		unit = periph->periph_target * 100 + periph->periph_lun;
354 		if (b->unit != unit)
355 			return;
356 		if (b->channel != periph->periph_channel->chan_channel)
357 			return;
358 
359 		/* we've found it! */
360 		booted_device = dev;
361 		DR_VERBOSE(printf("\nbooted_device = %s\n", device_xname(dev)));
362 		found = 1;
363 	}
364 
365 	if (device_is_a(dev, "ld") && device_is_a(parent, "iop")) {
366 		/*
367 		 * Argh!  The attach arguments for ld devices is not
368 		 * consistent, so each supported raid controller requires
369 		 * different checks.
370 		 */
371 		struct iop_attach_args *iopa = aux;
372 
373 		if (parent != ctrlrdev)
374 			return;
375 
376 		if (b->unit != iopa->ia_tid)
377 			return;
378 		/* we've found it! */
379 		booted_device = dev;
380 		DR_VERBOSE(printf("\nbooted_device = %s\n", device_xname(dev)));
381 		found = 1;
382 	}
383 
384 	if (device_is_a(dev, "ld") && device_is_a(parent, "mlx")) {
385 		/*
386 		 * Argh!  The attach arguments for ld devices is not
387 		 * consistent, so each supported raid controller requires
388 		 * different checks.
389 		 */
390 		struct mlx_attach_args *mlxa = aux;
391 
392 		if (parent != ctrlrdev)
393 			return;
394 
395 		if (b->unit != mlxa->mlxa_unit)
396 			return;
397 		/* we've found it! */
398 		booted_device = dev;
399 		DR_VERBOSE(printf("\nbooted_device = %s\n", device_xname(dev)));
400 		found = 1;
401 	}
402 
403 	/*
404 	 * Support to boot from IDE drives.
405 	 */
406 	if (device_is_a(dev, "wd")) {
407 		struct ata_device *adev = aux;
408 
409 		if (!device_is_a(parent, "atabus"))
410 			return;
411 		if (device_parent(parent) != ctrlrdev)
412 			return;
413 
414 		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
415 		    adev->adev_drv_data->drive, adev->adev_channel));
416 		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
417 		    b->unit, b->channel));
418 		if (b->unit != adev->adev_drv_data->drive ||
419 		    b->channel != adev->adev_channel)
420 			return;
421 
422 		/* we've found it! */
423 		booted_device = dev;
424 		DR_VERBOSE(printf("booted_device = %s\n", device_xname(dev)));
425 		found = 1;
426 	}
427 }
428 
429 
430 static void
dec_6600_mcheck(unsigned long vector,struct ev6_logout_area * la)431 dec_6600_mcheck(unsigned long vector, struct ev6_logout_area *la)
432 {
433 	const char *t = "Unknown", *c = "";
434 
435 	if (vector == ALPHA_SYS_ERROR || vector == ALPHA_PROC_ERROR)
436 		c = " Correctable";
437 
438 	switch (vector) {
439 	case ALPHA_SYS_ERROR:
440 	case ALPHA_SYS_MCHECK:
441 		t = "System";
442 		break;
443 
444 	case ALPHA_PROC_ERROR:
445 	case ALPHA_PROC_MCHECK:
446 		t = "Processor";
447 		break;
448 
449 	case ALPHA_ENV_MCHECK:
450 		t = "Environmental";
451 		break;
452 	}
453 
454 	printf("\n%s%s Machine Check (%lx): "
455 	       "Rev 0x%x, Code 0x%x, Flags 0x%x\n\n",
456 	       t, c, vector, la->mchk_rev, la->mchk_code, la->la.la_flags);
457 }
458 
459 static void
dec_6600_mcheck_sys(unsigned int indent,struct ev6_logout_area * la)460 dec_6600_mcheck_sys(unsigned int indent, struct ev6_logout_area *la)
461 {
462 	struct ev6_logout_sys *ls =
463 		(struct ev6_logout_sys *)ALPHA_LOGOUT_SYSTEM_AREA(&la->la);
464 
465 #define FMT	"%-30s = 0x%016lx\n"
466 
467 	IPRINTF(indent, FMT, "Software Error Summary Flags", ls->flags);
468 
469 	IPRINTF(indent, FMT, "CPU Device Interrupt Requests", ls->dir);
470 	tsc_print_dir(indent + 1, ls->dir);
471 
472 	IPRINTF(indent, FMT, "Cchip Miscellaneous Register", ls->misc);
473 	tsc_print_misc(indent + 1, ls->misc);
474 
475 	IPRINTF(indent, FMT, "Pchip 0 Error Register", ls->p0_error);
476 	if (ls->flags & 0x5)
477 		tsp_print_error(indent + 1, ls->p0_error);
478 
479 	IPRINTF(indent, FMT, "Pchip 1 Error Register", ls->p1_error);
480 	if (ls->flags & 0x6)
481 		tsp_print_error(indent + 1, ls->p1_error);
482 }
483 
484 static void
dec_6600_mcheck_handler(unsigned long mces,struct trapframe * framep,unsigned long vector,unsigned long param)485 dec_6600_mcheck_handler(unsigned long mces, struct trapframe *framep,
486 			unsigned long vector, unsigned long param)
487 {
488 	struct mchkinfo *mcp;
489 	struct ev6_logout_area *la = (struct ev6_logout_area *)param;
490 
491 	/*
492 	 * If we expected a machine check, just go handle it in common code.
493 	 */
494 	mcp = &curcpu()->ci_mcinfo;
495 	if (mcp->mc_expected)
496 		machine_check(mces, framep, vector, param);
497 
498 	dec_6600_mcheck(vector, la);
499 
500 	switch (vector) {
501 	case ALPHA_SYS_ERROR:
502 	case ALPHA_SYS_MCHECK:
503 		dec_6600_mcheck_sys(1, la);
504 		break;
505 
506 	}
507 
508 	machine_check(mces, framep, vector, param);
509 }
510