1/* $NetBSD: dec_eb66.c,v 1.26 2011/07/01 19:22:35 dyoung 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 * Additional Copyright (c) 1997 by Matthew Jacob for NASA/Ames Research Center
31 */
32
33#include "opt_kgdb.h"
34
35#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
36
37__KERNEL_RCSID(0, "$NetBSD: dec_eb66.c,v 1.26 2011/07/01 19:22:35 dyoung Exp $");
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/device.h>
42#include <sys/termios.h>
43#include <sys/conf.h>
44#include <dev/cons.h>
45
46#include <uvm/uvm_extern.h>
47
48#include <machine/rpb.h>
49#include <machine/autoconf.h>
50#include <machine/cpuconf.h>
51#include <sys/bus.h>
52
53#include <dev/ic/comreg.h>
54#include <dev/ic/comvar.h>
55
56#include <dev/isa/isareg.h>
57#include <dev/isa/isavar.h>
58#include <dev/ic/i8042reg.h>
59#include <dev/ic/pckbcvar.h>
60#include <dev/pci/pcireg.h>
61#include <dev/pci/pcivar.h>
62
63#include <alpha/pci/lcareg.h>
64#include <alpha/pci/lcavar.h>
65
66#include <dev/scsipi/scsi_all.h>
67#include <dev/scsipi/scsipi_all.h>
68#include <dev/scsipi/scsiconf.h>
69
70#include "pckbd.h"
71
72#ifndef CONSPEED
73#define CONSPEED TTYDEF_SPEED
74#endif
75static int comcnrate = CONSPEED;
76
77void dec_eb66_init(void);
78static void dec_eb66_cons_init(void);
79static void dec_eb66_device_register(device_t, void *);
80
81#ifdef KGDB
82#include <machine/db_machdep.h>
83
84static const char *kgdb_devlist[] = {
85	"com",
86	NULL,
87};
88#endif /* KGDB */
89
90const struct alpha_variation_table dec_eb66_variations[] = {
91	{ 0, "DEC EB66" },
92	{ 0, NULL },
93};
94
95void
96dec_eb66_init(void)
97{
98	uint64_t variation;
99
100	platform.family = "EB66";
101
102	if ((platform.model = alpha_dsr_sysname()) == NULL) {
103		variation = hwrpb->rpb_variation & SV_ST_MASK;
104		if ((platform.model = alpha_variation_name(variation,
105		    dec_eb66_variations)) == NULL)
106			platform.model = alpha_unknown_sysname();
107	}
108
109	platform.iobus = "lca";
110	platform.cons_init = dec_eb66_cons_init;
111	platform.device_register = dec_eb66_device_register;
112
113	/*
114	 * EB66 systems have 1M secondary caches.
115	 */
116	uvmexp.ncolors = atop(1 * 1024 * 1024);
117}
118
119static void
120dec_eb66_cons_init(void)
121{
122	struct ctb *ctb;
123	struct lca_config *lcp;
124	extern struct lca_config lca_configuration;
125
126	lcp = &lca_configuration;
127	lca_init(lcp, 0);
128
129	ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
130
131	switch (ctb->ctb_term_type) {
132	case CTB_PRINTERPORT:
133		/* serial console ... */
134		/* XXX */
135		{
136			/*
137			 * Delay to allow PROM putchars to complete.
138			 * FIFO depth * character time,
139			 * character time = (1000000 / (defaultrate / 10))
140			 */
141			DELAY(160000000 / comcnrate);
142
143			if(comcnattach(&lcp->lc_iot, 0x3f8, comcnrate,
144			    COM_FREQ, COM_TYPE_NORMAL,
145			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
146				panic("can't init serial console");
147
148			break;
149		}
150
151	case CTB_GRAPHICS:
152#if NPCKBD > 0
153		/* display console ... */
154		/* XXX */
155		(void) pckbc_cnattach(&lcp->lc_iot, IO_KBD, KBCMDP,
156		    PCKBC_KBD_SLOT);
157
158		if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
159		    CTB_TURBOSLOT_TYPE_ISA)
160			isa_display_console(&lcp->lc_iot, &lcp->lc_memt);
161		else
162			pci_display_console(&lcp->lc_iot, &lcp->lc_memt,
163			    &lcp->lc_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
164			    CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
165#else
166		panic("not configured to use display && keyboard console");
167#endif
168		break;
169
170	default:
171		printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
172		printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
173
174		panic("consinit: unknown console type %ld",
175		    ctb->ctb_term_type);
176	}
177#ifdef KGDB
178	/* Attach the KGDB device. */
179	alpha_kgdb_init(kgdb_devlist, &lcp->lc_iot);
180#endif /* KGDB */
181}
182
183static void
184dec_eb66_device_register(device_t dev, void *aux)
185{
186	static int found, initted, diskboot, netboot;
187	static device_t pcidev, ctrlrdev;
188	struct bootdev_data *b = bootdev_data;
189	device_t parent = device_parent(dev);
190
191	if (found)
192		return;
193
194	if (!initted) {
195		diskboot = (strcasecmp(b->protocol, "SCSI") == 0);
196		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
197		    (strcasecmp(b->protocol, "MOP") == 0);
198#if 0
199		printf("diskboot = %d, netboot = %d\n", diskboot, netboot);
200#endif
201		initted =1;
202	}
203
204	if (pcidev == NULL) {
205		if (!device_is_a(dev, "pci"))
206			return;
207		else {
208			struct pcibus_attach_args *pba = aux;
209
210			if ((b->slot / 1000) != pba->pba_bus)
211				return;
212
213			pcidev = dev;
214#if 0
215			printf("\npcidev = %s\n", device_xname(dev));
216#endif
217			return;
218		}
219	}
220
221	if (ctrlrdev == NULL) {
222		if (parent != pcidev)
223			return;
224		else {
225			struct pci_attach_args *pa = aux;
226			int slot;
227
228			slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
229			    pa->pa_device;
230			if (b->slot != slot)
231				return;
232
233			if (netboot) {
234				booted_device = dev;
235#if 0
236				printf("\nbooted_device = %s\n", device_xname(dev));
237#endif
238				found = 1;
239			} else {
240				ctrlrdev = dev;
241#if 0
242				printf("\nctrlrdev = %s\n", device_xname(dev));
243#endif
244			}
245			return;
246		}
247	}
248
249	if (!diskboot)
250		return;
251
252	if (device_is_a(dev, "sd") ||
253	    device_is_a(dev, "st") ||
254	    device_is_a(dev, "cd")) {
255		struct scsipibus_attach_args *sa = aux;
256		struct scsipi_periph *periph = sa->sa_periph;
257		int unit;
258
259		if (device_parent(parent) != ctrlrdev)
260			return;
261
262		unit = periph->periph_target * 100 + periph->periph_lun;
263		if (b->unit != unit)
264			return;
265		if (b->channel != periph->periph_channel->chan_channel)
266			return;
267
268		/* we've found it! */
269		booted_device = dev;
270#if 0
271		printf("\nbooted_device = %s\n", device_xname(dev));
272#endif
273		found = 1;
274	}
275}
276