dec_6600.c revision 1.12
1/* $NetBSD: dec_6600.c,v 1.12 2001/06/05 04:53:11 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.12 2001/06/05 04:53:11 thorpej Exp $");
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/device.h>
39#include <sys/termios.h>
40#include <dev/cons.h>
41
42#include <machine/rpb.h>
43#include <machine/autoconf.h>
44#include <machine/conf.h>
45#include <machine/bus.h>
46
47#include <dev/ic/comreg.h>
48#include <dev/ic/comvar.h>
49
50#include <dev/isa/isareg.h>
51#include <dev/isa/isavar.h>
52#include <dev/ic/i8042reg.h>
53#include <dev/ic/pckbcvar.h>
54#include <dev/pci/pcireg.h>
55#include <dev/pci/pcivar.h>
56
57#include <alpha/pci/tsreg.h>
58#include <alpha/pci/tsvar.h>
59
60#include <dev/scsipi/scsi_all.h>
61#include <dev/scsipi/scsipi_all.h>
62#include <dev/scsipi/scsiconf.h>
63#include <dev/ata/atavar.h>
64
65#include "pckbd.h"
66
67#ifndef CONSPEED
68#define CONSPEED TTYDEF_SPEED
69#endif
70
71#define	DR_VERBOSE(f) while (0)
72
73static int comcnrate __attribute__((unused)) = CONSPEED;
74
75void dec_6600_init __P((void));
76static void dec_6600_cons_init __P((void));
77static void dec_6600_device_register __P((struct device *, void *));
78
79#ifdef KGDB
80#include <machine/db_machdep.h>
81
82static const char *kgdb_devlist[] = {
83	"com",
84	NULL,
85};
86#endif /* KGDB */
87
88void
89dec_6600_init()
90{
91
92	platform.family = "6600";
93
94	if ((platform.model = alpha_dsr_sysname()) == NULL) {
95		/* XXX Don't know the system variations, yet. */
96		platform.model = alpha_unknown_sysname();
97	}
98
99	platform.iobus = "tsc";
100	platform.cons_init = dec_6600_cons_init;
101	platform.device_register = dec_6600_device_register;
102	STQP(TS_C_DIM0) = 0UL;
103	STQP(TS_C_DIM1) = 0UL;
104}
105
106static void
107dec_6600_cons_init()
108{
109	struct ctb *ctb;
110	u_int64_t ctbslot;
111	struct tsp_config *tsp;
112
113	ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
114	ctbslot = ctb->ctb_turboslot;
115
116	/* Console hose defaults to hose 0. */
117	tsp_console_hose = 0;
118
119	tsp = tsp_init(0, tsp_console_hose);
120
121	switch (ctb->ctb_term_type) {
122	case CTB_PRINTERPORT:
123		/* serial console ... */
124		assert(CTB_TURBOSLOT_HOSE(ctbslot) == 0);
125		/* XXX */
126		{
127			/*
128			 * Delay to allow PROM putchars to complete.
129			 * FIFO depth * character time,
130			 * character time = (1000000 / (defaultrate / 10))
131			 */
132			DELAY(160000000 / comcnrate);
133
134			if(comcnattach(&tsp->pc_iot, 0x3f8, comcnrate,
135			    COM_FREQ,
136			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
137				panic("can't init serial console");
138
139			break;
140		}
141
142	case CTB_GRAPHICS:
143#if NPCKBD > 0
144		/* display console ... */
145		/* XXX */
146		(void) pckbc_cnattach(&tsp->pc_iot, IO_KBD, KBCMDP,
147		    PCKBC_KBD_SLOT);
148
149		if (CTB_TURBOSLOT_TYPE(ctbslot) ==
150		    CTB_TURBOSLOT_TYPE_ISA)
151			isa_display_console(&tsp->pc_iot, &tsp->pc_memt);
152		else {
153			/* The display PCI might be different */
154			tsp_console_hose = CTB_TURBOSLOT_HOSE(ctbslot);
155			tsp = tsp_init(0, tsp_console_hose);
156			pci_display_console(&tsp->pc_iot, &tsp->pc_memt,
157			    &tsp->pc_pc, CTB_TURBOSLOT_BUS(ctbslot),
158			    CTB_TURBOSLOT_SLOT(ctbslot), 0);
159		}
160#else
161		panic("not configured to use display && keyboard console");
162#endif
163		break;
164
165	default:
166		printf("ctb_term_type = 0x%lx ctb_turboslot = 0x%lx"
167		    " hose = %ld\n", ctb->ctb_term_type, ctbslot,
168		    CTB_TURBOSLOT_HOSE(ctbslot));
169
170		panic("consinit: unknown console type %ld\n",
171		    ctb->ctb_term_type);
172	}
173#ifdef KGDB
174	/* Attach the KGDB device. */
175	alpha_kgdb_init(kgdb_devlist, &tsp->pc_iot);
176#endif /* KGDB */
177}
178
179static void
180dec_6600_device_register(dev, aux)
181	struct device *dev;
182	void *aux;
183{
184	static int found, initted, scsiboot, ideboot, netboot;
185	static struct device *primarydev, *pcidev, *scsipidev;
186	struct bootdev_data *b = bootdev_data;
187	struct device *parent = dev->dv_parent;
188	struct cfdata *cf = dev->dv_cfdata;
189	struct cfdriver *cd = cf->cf_driver;
190
191	if (found)
192		return;
193
194	if (!initted) {
195		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
196		netboot = (strcmp(b->protocol, "BOOTP") == 0) ||
197		    (strcmp(b->protocol, "MOP") == 0);
198		/*
199		 * Add an extra check to boot from ide drives:
200		 * Newer SRM firmware use the protocol identifier IDE,
201		 * older SRM firmware use the protocol identifier SCSI.
202		 */
203		ideboot = (strcmp(b->protocol, "IDE") == 0);
204		DR_VERBOSE(printf("scsiboot = %d, ideboot = %d, netboot = %d\n",
205		    scsiboot, ideboot, netboot));
206		initted = 1;
207	}
208	if (primarydev == NULL) {
209		if (strcmp(cd->cd_name, "tsp"))
210			return;
211		else {
212			struct tsp_attach_args *tsp = aux;
213
214			if (b->bus != tsp->tsp_slot)
215				return;
216			primarydev = dev;
217			DR_VERBOSE(printf("\nprimarydev = %s\n",
218			    primarydev->dv_xname));
219			return;
220		}
221	}
222	if (pcidev == NULL) {
223		if (parent != primarydev)
224			return;
225		if (strcmp(cd->cd_name, "pci"))
226			return;
227		else {
228			struct pcibus_attach_args *pba = aux;
229
230			if ((b->slot / 1000) != pba->pba_bus)
231				return;
232
233			pcidev = dev;
234			DR_VERBOSE(printf("\npcidev = %s\n",
235			    pcidev->dv_xname));
236			return;
237		}
238	}
239	if ((ideboot || scsiboot) && (scsipidev == NULL)) {
240		if (parent != pcidev)
241			return;
242		else {
243			struct pci_attach_args *pa = aux;
244
245			if (b->slot % 1000 / 100 != pa->pa_function)
246				return;
247			if (b->slot % 100 != pa->pa_device)
248				return;
249
250			scsipidev = dev;
251			DR_VERBOSE(printf("\nscsipidev = %s\n",
252			    scsipidev->dv_xname));
253			return;
254		}
255	}
256	if ((ideboot || scsiboot) &&
257	    (!strcmp(cd->cd_name, "sd") ||
258	     !strcmp(cd->cd_name, "st") ||
259	     !strcmp(cd->cd_name, "cd"))) {
260		struct scsipibus_attach_args *sa = aux;
261
262		if (parent->dv_parent != scsipidev)
263			return;
264
265		if ((sa->sa_periph->periph_channel->chan_bustype->bustype_type
266		     == SCSIPI_BUSTYPE_SCSI ||
267		     sa->sa_periph->periph_channel->chan_bustype->bustype_type
268		     == SCSIPI_BUSTYPE_ATAPI)
269		    && b->unit / 100 != sa->sa_periph->periph_target)
270			return;
271
272		/* XXX LUN! */
273
274		switch (b->boot_dev_type) {
275		case 0:
276			if (strcmp(cd->cd_name, "sd") &&
277			    strcmp(cd->cd_name, "cd"))
278				return;
279			break;
280		case 1:
281			if (strcmp(cd->cd_name, "st"))
282				return;
283			break;
284		default:
285			return;
286		}
287
288		/* we've found it! */
289		booted_device = dev;
290		DR_VERBOSE(printf("\nbooted_device = %s\n",
291		    booted_device->dv_xname));
292		found = 1;
293	}
294
295	/*
296	 * Support to boot from IDE drives.
297	 */
298	if ((ideboot || scsiboot) && !strcmp(cd->cd_name, "wd")) {
299		struct ata_atapi_attach *aa_link = aux;
300		if ((strncmp("pciide", parent->dv_xname, 6) != 0)) {
301			return;
302		} else {
303			if (parent != scsipidev)
304				return;
305		}
306		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
307		    aa_link->aa_drv_data->drive, aa_link->aa_channel));
308		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
309		    b->unit, b->channel));
310		if (b->unit != aa_link->aa_drv_data->drive ||
311		    b->channel != aa_link->aa_channel)
312			return;
313
314		/* we've found it! */
315		booted_device = dev;
316		DR_VERBOSE(printf("booted_device = %s\n",
317		    booted_device->dv_xname));
318		found = 1;
319	}
320	if (netboot) {
321		if (parent != pcidev)
322			return;
323		else {
324			struct pci_attach_args *pa = aux;
325
326			if (b->slot % 1000 / 100 != pa->pa_function)
327				return;
328			if ((b->slot % 100) != pa->pa_device)
329				return;
330
331			booted_device = dev;
332			DR_VERBOSE(printf("\nbooted_device = %s\n",
333			    booted_device->dv_xname));
334			found = 1;
335			return;
336		}
337	}
338}
339