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