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