dec_6600.c revision 1.36
1/* $NetBSD: dec_6600.c,v 1.36 2023/12/04 00:32:10 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.36 2023/12/04 00:32:10 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
85static int comcnrate __attribute__((unused)) = CONSPEED;
86
87void dec_6600_init(void);
88static void dec_6600_cons_init(void);
89static void dec_6600_device_register(device_t, void *);
90static void dec_6600_mcheck(unsigned long, struct ev6_logout_area *);
91static void dec_6600_mcheck_sys(unsigned int, struct ev6_logout_area *);
92static 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
98static const char *kgdb_devlist[] = {
99	"com",
100	NULL,
101};
102#endif /* KGDB */
103
104void
105dec_6600_init(void)
106{
107
108	platform.family = "6600";
109
110	if ((platform.model = alpha_dsr_sysname()) == NULL) {
111		/* XXX Don't know the system variations, yet. */
112		platform.model = alpha_unknown_sysname();
113	}
114
115	platform.iobus = "tsc";
116	platform.cons_init = dec_6600_cons_init;
117	platform.device_register = dec_6600_device_register;
118	platform.mcheck_handler = dec_6600_mcheck_handler;
119
120	/* enable Cchip and Pchip error interrupts */
121	STQP(TS_C_DIM0) = 0xe000000000000000;
122	STQP(TS_C_DIM1) = 0xe000000000000000;
123}
124
125static void
126dec_6600_cons_init(void)
127{
128	struct ctb *ctb;
129	uint64_t ctbslot;
130	struct tsp_config *tsp;
131
132	ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
133	ctbslot = ctb->ctb_turboslot;
134
135	/* Console hose defaults to hose 0. */
136	tsp_console_hose = 0;
137
138	tsp = tsp_init(tsp_console_hose);
139
140	switch (ctb->ctb_term_type) {
141	case CTB_PRINTERPORT:
142		/* serial console ... */
143		assert(CTB_TURBOSLOT_HOSE(ctbslot) == 0);
144		/* XXX */
145		{
146			/*
147			 * Delay to allow PROM putchars to complete.
148			 * FIFO depth * character time,
149			 * character time = (1000000 / (defaultrate / 10))
150			 */
151			DELAY(160000000 / comcnrate);
152
153			if(comcnattach(&tsp->pc_iot, 0x3f8, comcnrate,
154			    COM_FREQ, COM_TYPE_NORMAL,
155			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
156				panic("can't init serial console");
157
158			break;
159		}
160
161	case CTB_GRAPHICS:
162#if NPCKBD > 0
163		/* display console ... */
164		/* XXX */
165		(void) pckbc_cnattach(&tsp->pc_iot, IO_KBD, KBCMDP,
166		    PCKBC_KBD_SLOT, 0);
167
168		if (CTB_TURBOSLOT_TYPE(ctbslot) ==
169		    CTB_TURBOSLOT_TYPE_ISA)
170			isa_display_console(&tsp->pc_iot, &tsp->pc_memt);
171		else {
172			/* The display PCI might be different */
173			tsp_console_hose = CTB_TURBOSLOT_HOSE(ctbslot);
174			tsp = tsp_init(tsp_console_hose);
175			pci_display_console(&tsp->pc_iot, &tsp->pc_memt,
176			    &tsp->pc_pc, CTB_TURBOSLOT_BUS(ctbslot),
177			    CTB_TURBOSLOT_SLOT(ctbslot), 0);
178		}
179#else
180		panic("not configured to use display && keyboard console");
181#endif
182		break;
183
184	default:
185		printf("ctb_term_type = 0x%lx ctb_turboslot = 0x%lx"
186		    " hose = %ld\n", ctb->ctb_term_type, ctbslot,
187		    CTB_TURBOSLOT_HOSE(ctbslot));
188
189		panic("consinit: unknown console type %ld",
190		    ctb->ctb_term_type);
191	}
192#ifdef KGDB
193	/* Attach the KGDB device. */
194	alpha_kgdb_init(kgdb_devlist, &tsp->pc_iot);
195#endif /* KGDB */
196}
197
198static void
199dec_6600_device_register(device_t dev, void *aux)
200{
201	static int found, initted, diskboot, netboot;
202	static device_t primarydev, pcidev, ctrlrdev;
203	struct bootdev_data *b = bootdev_data;
204	device_t parent = device_parent(dev);
205
206	if (found)
207		return;
208
209	if (!initted) {
210		diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
211		    (strcasecmp(b->protocol, "RAID") == 0) ||
212		    (strcasecmp(b->protocol, "I2O") == 0) ||
213		    (strcasecmp(b->protocol, "IDE") == 0);
214		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
215		    (strcasecmp(b->protocol, "MOP") == 0);
216		DR_VERBOSE(printf("diskboot = %d, netboot = %d\n", diskboot,
217		    netboot));
218		initted = 1;
219	}
220
221	if (primarydev == NULL) {
222		if (!device_is_a(dev, "tsp"))
223			return;
224		else {
225			struct tsp_attach_args *tsp = aux;
226
227			if (b->bus != tsp->tsp_slot)
228				return;
229			primarydev = dev;
230			DR_VERBOSE(printf("\nprimarydev = %s\n",
231			    device_xname(dev)));
232			return;
233		}
234	}
235
236	if (pcidev == NULL) {
237		if (!device_is_a(dev, "pci"))
238			return;
239		/*
240		 * Try to find primarydev anywhere in the ancestry.  This is
241		 * necessary if the PCI bus is hidden behind a bridge.
242		 */
243		while (parent) {
244			if (parent == primarydev)
245				break;
246			parent = device_parent(parent);
247		}
248		if (!parent)
249			return;
250		else {
251			struct pcibus_attach_args *pba = aux;
252
253			if ((b->slot / 1000) != pba->pba_bus)
254				return;
255
256			pcidev = dev;
257			DR_VERBOSE(printf("\npcidev = %s\n", device_xname(dev)));
258			return;
259		}
260	}
261
262	if (ctrlrdev == NULL) {
263		if (parent != pcidev)
264			return;
265		else {
266			struct pci_attach_args *pa = aux;
267			int slot;
268
269			slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
270			    pa->pa_device;
271			if (b->slot != slot)
272				return;
273
274			if (netboot) {
275				booted_device = dev;
276				DR_VERBOSE(printf("\nbooted_device = %s\n",
277				    device_xname(dev)));
278				found = 1;
279			} else {
280				ctrlrdev = dev;
281				DR_VERBOSE(printf("\nctrlrdev = %s\n",
282				    device_xname(dev)));
283			}
284			return;
285		}
286	}
287
288	if (!diskboot)
289		return;
290
291	if (device_is_a(dev, "sd") ||
292	    device_is_a(dev, "st") ||
293	    device_is_a(dev, "cd")) {
294		struct scsipibus_attach_args *sa = aux;
295		struct scsipi_periph *periph = sa->sa_periph;
296		int unit;
297
298		if (device_parent(parent) != ctrlrdev)
299			return;
300
301		unit = periph->periph_target * 100 + periph->periph_lun;
302		if (b->unit != unit)
303			return;
304		if (b->channel != periph->periph_channel->chan_channel)
305			return;
306
307		/* we've found it! */
308		booted_device = dev;
309		DR_VERBOSE(printf("\nbooted_device = %s\n", device_xname(dev)));
310		found = 1;
311	}
312
313	if (device_is_a(dev, "ld") && device_is_a(parent, "iop")) {
314		/*
315		 * Argh!  The attach arguments for ld devices is not
316		 * consistent, so each supported raid controller requires
317		 * different checks.
318		 */
319		struct iop_attach_args *iopa = aux;
320
321		if (parent != ctrlrdev)
322			return;
323
324		if (b->unit != iopa->ia_tid)
325			return;
326		/* we've found it! */
327		booted_device = dev;
328		DR_VERBOSE(printf("\nbooted_device = %s\n", device_xname(dev)));
329		found = 1;
330	}
331
332	if (device_is_a(dev, "ld") && device_is_a(parent, "mlx")) {
333		/*
334		 * Argh!  The attach arguments for ld devices is not
335		 * consistent, so each supported raid controller requires
336		 * different checks.
337		 */
338		struct mlx_attach_args *mlxa = aux;
339
340		if (parent != ctrlrdev)
341			return;
342
343		if (b->unit != mlxa->mlxa_unit)
344			return;
345		/* we've found it! */
346		booted_device = dev;
347		DR_VERBOSE(printf("\nbooted_device = %s\n", device_xname(dev)));
348		found = 1;
349	}
350
351	/*
352	 * Support to boot from IDE drives.
353	 */
354	if (device_is_a(dev, "wd")) {
355		struct ata_device *adev = aux;
356
357		if (!device_is_a(parent, "atabus"))
358			return;
359		if (device_parent(parent) != ctrlrdev)
360			return;
361
362		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
363		    adev->adev_drv_data->drive, adev->adev_channel));
364		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
365		    b->unit, b->channel));
366		if (b->unit != adev->adev_drv_data->drive ||
367		    b->channel != adev->adev_channel)
368			return;
369
370		/* we've found it! */
371		booted_device = dev;
372		DR_VERBOSE(printf("booted_device = %s\n", device_xname(dev)));
373		found = 1;
374	}
375}
376
377
378static void
379dec_6600_mcheck(unsigned long vector, struct ev6_logout_area *la)
380{
381	const char *t = "Unknown", *c = "";
382
383	if (vector == ALPHA_SYS_ERROR || vector == ALPHA_PROC_ERROR)
384		c = " Correctable";
385
386	switch (vector) {
387	case ALPHA_SYS_ERROR:
388	case ALPHA_SYS_MCHECK:
389		t = "System";
390		break;
391
392	case ALPHA_PROC_ERROR:
393	case ALPHA_PROC_MCHECK:
394		t = "Processor";
395		break;
396
397	case ALPHA_ENV_MCHECK:
398		t = "Environmental";
399		break;
400	}
401
402	printf("\n%s%s Machine Check (%lx): "
403	       "Rev 0x%x, Code 0x%x, Flags 0x%x\n\n",
404	       t, c, vector, la->mchk_rev, la->mchk_code, la->la.la_flags);
405}
406
407static void
408dec_6600_mcheck_sys(unsigned int indent, struct ev6_logout_area *la)
409{
410	struct ev6_logout_sys *ls =
411		(struct ev6_logout_sys *)ALPHA_LOGOUT_SYSTEM_AREA(&la->la);
412
413#define FMT	"%-30s = 0x%016lx\n"
414
415	IPRINTF(indent, FMT, "Software Error Summary Flags", ls->flags);
416
417	IPRINTF(indent, FMT, "CPU Device Interrupt Requests", ls->dir);
418	tsc_print_dir(indent + 1, ls->dir);
419
420	IPRINTF(indent, FMT, "Cchip Miscellaneous Register", ls->misc);
421	tsc_print_misc(indent + 1, ls->misc);
422
423	IPRINTF(indent, FMT, "Pchip 0 Error Register", ls->p0_error);
424	if (ls->flags & 0x5)
425		tsp_print_error(indent + 1, ls->p0_error);
426
427	IPRINTF(indent, FMT, "Pchip 1 Error Register", ls->p1_error);
428	if (ls->flags & 0x6)
429		tsp_print_error(indent + 1, ls->p1_error);
430}
431
432static void
433dec_6600_mcheck_handler(unsigned long mces, struct trapframe *framep,
434			unsigned long vector, unsigned long param)
435{
436	struct mchkinfo *mcp;
437	struct ev6_logout_area *la = (struct ev6_logout_area *)param;
438
439	/*
440	 * If we expected a machine check, just go handle it in common code.
441	 */
442	mcp = &curcpu()->ci_mcinfo;
443	if (mcp->mc_expected)
444		machine_check(mces, framep, vector, param);
445
446	dec_6600_mcheck(vector, la);
447
448	switch (vector) {
449	case ALPHA_SYS_ERROR:
450	case ALPHA_SYS_MCHECK:
451		dec_6600_mcheck_sys(1, la);
452		break;
453
454	}
455
456	machine_check(mces, framep, vector, param);
457}
458