xref: /netbsd/sys/arch/alpha/alpha/dec_eb64plus.c (revision bf9ec67e)
1 /* $NetBSD: dec_eb64plus.c,v 1.25 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_eb64plus.c,v 1.25 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/alpha.h>
49 #include <machine/autoconf.h>
50 #include <machine/conf.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/apecsreg.h>
63 #include <alpha/pci/apecsvar.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_eb64plus_init __P((void));
77 static void dec_eb64plus_cons_init __P((void));
78 static void dec_eb64plus_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_eb64plus_variations[] = {
90 	{ 0, "DEC EB64+" },
91 	{ 0, NULL },
92 };
93 
94 void
95 dec_eb64plus_init()
96 {
97 	u_int64_t variation;
98 
99 	platform.family = "EB64+";
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_eb64plus_variations)) == NULL)
105 			platform.model = alpha_unknown_sysname();
106 	}
107 
108 	platform.iobus = "apecs";
109 	platform.cons_init = dec_eb64plus_cons_init;
110 	platform.device_register = dec_eb64plus_device_register;
111 
112 	/*
113 	 * EB64+ systems can have 512K, 1M, or 2M secondary
114 	 * caches.  Default to middle-of-the-road.
115 	 *
116 	 * XXX Need to dynamically size it!
117 	 */
118 	uvmexp.ncolors = atop(1 * 1024 * 1024);
119 }
120 
121 static void
122 dec_eb64plus_cons_init()
123 {
124 	struct ctb *ctb;
125 	struct apecs_config *acp;
126 	extern struct apecs_config apecs_configuration;
127 
128 	acp = &apecs_configuration;
129 	apecs_init(acp, 0);
130 
131 	ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
132 
133 	switch (ctb->ctb_term_type) {
134 	case CTB_PRINTERPORT:
135 		/* serial console ... */
136 		/* XXX */
137 		{
138 			/*
139 			 * Delay to allow PROM putchars to complete.
140 			 * FIFO depth * character time,
141 			 * character time = (1000000 / (defaultrate / 10))
142 			 */
143 			DELAY(160000000 / comcnrate);
144 
145 			if(comcnattach(&acp->ac_iot, 0x3f8, comcnrate,
146 			    COM_FREQ,
147 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
148 				panic("can't init serial console");
149 
150 			break;
151 		}
152 
153 	case CTB_GRAPHICS:
154 #if NPCKBD > 0
155 		/* display console ... */
156 		/* XXX */
157 		(void) pckbc_cnattach(&acp->ac_iot, IO_KBD, KBCMDP,
158 		    PCKBC_KBD_SLOT);
159 
160 		if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
161 		    CTB_TURBOSLOT_TYPE_ISA)
162 			isa_display_console(&acp->ac_iot, &acp->ac_memt);
163 		else
164 			pci_display_console(&acp->ac_iot, &acp->ac_memt,
165 			    &acp->ac_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
166 			    CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
167 #else
168 		panic("not configured to use display && keyboard console");
169 #endif
170 		break;
171 
172 	default:
173 		printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
174 		printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
175 
176 		panic("consinit: unknown console type %ld\n",
177 		    ctb->ctb_term_type);
178 	}
179 #ifdef KGDB
180 	/* Attach the KGDB device. */
181 	alpha_kgdb_init(kgdb_devlist, &acp->ac_iot);
182 #endif /* KGDB */
183 }
184 
185 static void
186 dec_eb64plus_device_register(dev, aux)
187 	struct device *dev;
188 	void *aux;
189 {
190 	static int found, initted, scsiboot, netboot;
191 	static struct device *pcidev, *scsidev;
192 	struct bootdev_data *b = bootdev_data;
193 	struct device *parent = dev->dv_parent;
194 	struct cfdata *cf = dev->dv_cfdata;
195 	struct cfdriver *cd = cf->cf_driver;
196 
197 	if (found)
198 		return;
199 
200 	if (!initted) {
201 		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
202 		netboot = (strcmp(b->protocol, "BOOTP") == 0) ||
203 		    (strcmp(b->protocol, "MOP") == 0);
204 #if 0
205 		printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot);
206 #endif
207 		initted =1;
208 	}
209 
210 	if (pcidev == NULL) {
211 		if (strcmp(cd->cd_name, "pci"))
212 			return;
213 		else {
214 			struct pcibus_attach_args *pba = aux;
215 
216 			if ((b->slot / 1000) != pba->pba_bus)
217 				return;
218 
219 			pcidev = dev;
220 #if 0
221 			printf("\npcidev = %s\n", pcidev->dv_xname);
222 #endif
223 			return;
224 		}
225 	}
226 
227 	if (scsiboot && (scsidev == NULL)) {
228 		if (parent != pcidev)
229 			return;
230 		else {
231 			struct pci_attach_args *pa = aux;
232 
233 			if ((b->slot % 1000) != pa->pa_device)
234 				return;
235 
236 			/* XXX function? */
237 
238 			scsidev = dev;
239 #if 0
240 			printf("\nscsidev = %s\n", scsidev->dv_xname);
241 #endif
242 			return;
243 		}
244 	}
245 
246 	if (scsiboot &&
247 	    (!strcmp(cd->cd_name, "sd") ||
248 	     !strcmp(cd->cd_name, "st") ||
249 	     !strcmp(cd->cd_name, "cd"))) {
250 		struct scsipibus_attach_args *sa = aux;
251 
252 		if (parent->dv_parent != scsidev)
253 			return;
254 
255 		if (b->unit / 100 != sa->sa_periph->periph_target)
256 			return;
257 
258 		/* XXX LUN! */
259 
260 		switch (b->boot_dev_type) {
261 		case 0:
262 			if (strcmp(cd->cd_name, "sd") &&
263 			    strcmp(cd->cd_name, "cd"))
264 				return;
265 			break;
266 		case 1:
267 			if (strcmp(cd->cd_name, "st"))
268 				return;
269 			break;
270 		default:
271 			return;
272 		}
273 
274 		/* we've found it! */
275 		booted_device = dev;
276 #if 0
277 		printf("\nbooted_device = %s\n", booted_device->dv_xname);
278 #endif
279 		found = 1;
280 	}
281 
282 	if (netboot) {
283 		if (parent != pcidev)
284 			return;
285 		else {
286 			struct pci_attach_args *pa = aux;
287 
288 			if ((b->slot % 1000) != pa->pa_device)
289 				return;
290 
291 			/* XXX function? */
292 
293 			booted_device = dev;
294 #if 0
295 			printf("\nbooted_device = %s\n", booted_device->dv_xname);
296 #endif
297 			found = 1;
298 			return;
299 		}
300 	}
301 }
302