xref: /netbsd/sys/arch/alpha/alpha/dec_eb66.c (revision c4a72b64)
1 /* $NetBSD: dec_eb66.c,v 1.15 2002/09/27 15:35:35 provos 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.15 2002/09/27 15:35:35 provos 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 <machine/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
75 static int comcnrate = CONSPEED;
76 
77 void dec_eb66_init __P((void));
78 static void dec_eb66_cons_init __P((void));
79 static void dec_eb66_device_register __P((struct device *, void *));
80 
81 #ifdef KGDB
82 #include <machine/db_machdep.h>
83 
84 static const char *kgdb_devlist[] = {
85 	"com",
86 	NULL,
87 };
88 #endif /* KGDB */
89 
90 const struct alpha_variation_table dec_eb66_variations[] = {
91 	{ 0, "DEC EB66" },
92 	{ 0, NULL },
93 };
94 
95 void
96 dec_eb66_init()
97 {
98 	u_int64_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 
119 static void
120 dec_eb66_cons_init()
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 *)(((caddr_t)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,
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 
183 static void
184 dec_eb66_device_register(dev, aux)
185 	struct device *dev;
186 	void *aux;
187 {
188 	static int found, initted, scsiboot, netboot;
189 	static struct device *pcidev, *scsidev;
190 	struct bootdev_data *b = bootdev_data;
191 	struct device *parent = dev->dv_parent;
192 	struct cfdata *cf = dev->dv_cfdata;
193 	const char *name = cf->cf_name;
194 
195 	if (found)
196 		return;
197 
198 	if (!initted) {
199 		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
200 		netboot = (strcmp(b->protocol, "BOOTP") == 0) ||
201 		    (strcmp(b->protocol, "MOP") == 0);
202 #if 0
203 		printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot);
204 #endif
205 		initted =1;
206 	}
207 
208 	if (pcidev == NULL) {
209 		if (strcmp(name, "pci"))
210 			return;
211 		else {
212 			struct pcibus_attach_args *pba = aux;
213 
214 			if ((b->slot / 1000) != pba->pba_bus)
215 				return;
216 
217 			pcidev = dev;
218 #if 0
219 			printf("\npcidev = %s\n", pcidev->dv_xname);
220 #endif
221 			return;
222 		}
223 	}
224 
225 	if (scsiboot && (scsidev == NULL)) {
226 		if (parent != pcidev)
227 			return;
228 		else {
229 			struct pci_attach_args *pa = aux;
230 
231 			if ((b->slot % 1000) != pa->pa_device)
232 				return;
233 
234 			/* XXX function? */
235 
236 			scsidev = dev;
237 #if 0
238 			printf("\nscsidev = %s\n", scsidev->dv_xname);
239 #endif
240 			return;
241 		}
242 	}
243 
244 	if (scsiboot &&
245 	    (!strcmp(name, "sd") ||
246 	     !strcmp(name, "st") ||
247 	     !strcmp(name, "cd"))) {
248 		struct scsipibus_attach_args *sa = aux;
249 
250 		if (parent->dv_parent != scsidev)
251 			return;
252 
253 		if (b->unit / 100 != sa->sa_periph->periph_target)
254 			return;
255 
256 		/* XXX LUN! */
257 
258 		switch (b->boot_dev_type) {
259 		case 0:
260 			if (strcmp(name, "sd") &&
261 			    strcmp(name, "cd"))
262 				return;
263 			break;
264 		case 1:
265 			if (strcmp(name, "st"))
266 				return;
267 			break;
268 		default:
269 			return;
270 		}
271 
272 		/* we've found it! */
273 		booted_device = dev;
274 #if 0
275 		printf("\nbooted_device = %s\n", booted_device->dv_xname);
276 #endif
277 		found = 1;
278 	}
279 
280 	if (netboot) {
281 		if (parent != pcidev)
282 			return;
283 		else {
284 			struct pci_attach_args *pa = aux;
285 
286 			if ((b->slot % 1000) != pa->pa_device)
287 				return;
288 
289 			/* XXX function? */
290 
291 			booted_device = dev;
292 #if 0
293 			printf("\nbooted_device = %s\n", booted_device->dv_xname);
294 #endif
295 			found = 1;
296 			return;
297 		}
298 	}
299 }
300