dec_6600.c revision 1.28
1/* $NetBSD: dec_6600.c,v 1.28 2009/03/14 15:35:59 dsl 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.28 2009/03/14 15:35:59 dsl 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(void);
77static void dec_6600_cons_init(void);
78static void dec_6600_device_register(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 *)(((char *)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(struct device *dev, void *aux)
182{
183	static int found, initted, diskboot, netboot;
184	static struct device *primarydev, *pcidev, *ctrlrdev;
185	struct bootdev_data *b = bootdev_data;
186	struct device *parent = device_parent(dev);
187
188	if (found)
189		return;
190
191	if (!initted) {
192		diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
193		    (strcasecmp(b->protocol, "IDE") == 0);
194		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
195		    (strcasecmp(b->protocol, "MOP") == 0);
196		DR_VERBOSE(printf("diskboot = %d, netboot = %d\n", diskboot,
197		    netboot));
198		initted = 1;
199	}
200
201	if (primarydev == NULL) {
202		if (!device_is_a(dev, "tsp"))
203			return;
204		else {
205			struct tsp_attach_args *tsp = aux;
206
207			if (b->bus != tsp->tsp_slot)
208				return;
209			primarydev = dev;
210			DR_VERBOSE(printf("\nprimarydev = %s\n",
211			    dev->dv_xname));
212			return;
213		}
214	}
215
216	if (pcidev == NULL) {
217		if (!device_is_a(dev, "pci"))
218			return;
219		/*
220		 * Try to find primarydev anywhere in the ancestry.  This is
221		 * necessary if the PCI bus is hidden behind a bridge.
222		 */
223		while (parent) {
224			if (parent == primarydev)
225				break;
226			parent = device_parent(parent);
227		}
228		if (!parent)
229			return;
230		else {
231			struct pcibus_attach_args *pba = aux;
232
233			if ((b->slot / 1000) != pba->pba_bus)
234				return;
235
236			pcidev = dev;
237			DR_VERBOSE(printf("\npcidev = %s\n", dev->dv_xname));
238			return;
239		}
240	}
241
242	if (ctrlrdev == NULL) {
243		if (parent != pcidev)
244			return;
245		else {
246			struct pci_attach_args *pa = aux;
247			int slot;
248
249			slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
250			    pa->pa_device;
251			if (b->slot != slot)
252				return;
253
254			if (netboot) {
255				booted_device = dev;
256				DR_VERBOSE(printf("\nbooted_device = %s\n",
257				    dev->dv_xname));
258				found = 1;
259			} else {
260				ctrlrdev = dev;
261				DR_VERBOSE(printf("\nctrlrdev = %s\n",
262				    dev->dv_xname));
263			}
264			return;
265		}
266	}
267
268	if (!diskboot)
269		return;
270
271	if (device_is_a(dev, "sd") ||
272	    device_is_a(dev, "st") ||
273	    device_is_a(dev, "cd")) {
274		struct scsipibus_attach_args *sa = aux;
275		struct scsipi_periph *periph = sa->sa_periph;
276		int unit;
277
278		if (device_parent(parent) != ctrlrdev)
279			return;
280
281		unit = periph->periph_target * 100 + periph->periph_lun;
282		if (b->unit != unit)
283			return;
284		if (b->channel != periph->periph_channel->chan_channel)
285			return;
286
287		/* we've found it! */
288		booted_device = dev;
289		DR_VERBOSE(printf("\nbooted_device = %s\n", dev->dv_xname));
290		found = 1;
291	}
292
293	/*
294	 * Support to boot from IDE drives.
295	 */
296	if (device_is_a(dev, "wd")) {
297		struct ata_device *adev = aux;
298
299		if (!device_is_a(parent, "atabus"))
300			return;
301		if (device_parent(parent) != ctrlrdev)
302			return;
303
304		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
305		    adev->adev_drv_data->drive, adev->adev_channel));
306		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
307		    b->unit, b->channel));
308		if (b->unit != adev->adev_drv_data->drive ||
309		    b->channel != adev->adev_channel)
310			return;
311
312		/* we've found it! */
313		booted_device = dev;
314		DR_VERBOSE(printf("booted_device = %s\n", dev->dv_xname));
315		found = 1;
316	}
317}
318