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