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