xref: /netbsd/sys/arch/alpha/alpha/dec_eb164.c (revision c4a72b64)
1 /* $NetBSD: dec_eb164.c,v 1.46 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_eb164.c,v 1.46 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/ciareg.h>
64 #include <alpha/pci/ciavar.h>
65 
66 #include <dev/scsipi/scsi_all.h>
67 #include <dev/scsipi/scsipi_all.h>
68 #include <dev/scsipi/scsiconf.h>
69 #include <dev/ata/atavar.h>
70 #include <dev/ata/wdvar.h>
71 
72 #include "pckbd.h"
73 
74 #ifndef CONSPEED
75 #define CONSPEED TTYDEF_SPEED
76 #endif
77 static int comcnrate = CONSPEED;
78 
79 #define	DR_VERBOSE(f) while (0)
80 
81 void dec_eb164_init __P((void));
82 static void dec_eb164_cons_init __P((void));
83 static void dec_eb164_device_register __P((struct device *, void *));
84 
85 #ifdef KGDB
86 #include <machine/db_machdep.h>
87 
88 static const char *kgdb_devlist[] = {
89 	"com",
90 	NULL,
91 };
92 #endif /* KGDB */
93 
94 void
95 dec_eb164_init()
96 {
97 
98 	platform.family = "EB164";
99 
100 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
101 		/* XXX Don't know the system variations, yet. */
102 		platform.model = alpha_unknown_sysname();
103 	}
104 
105 	platform.iobus = "cia";
106 	platform.cons_init = dec_eb164_cons_init;
107 	platform.device_register = dec_eb164_device_register;
108 
109 	/*
110 	 * EB164 systems have a 2MB secondary cache.
111 	 */
112 	uvmexp.ncolors = atop(2 * 1024 * 1024);
113 }
114 
115 static void
116 dec_eb164_cons_init()
117 {
118 	struct ctb *ctb;
119 	struct cia_config *ccp;
120 	extern struct cia_config cia_configuration;
121 
122 	ccp = &cia_configuration;
123 	cia_init(ccp, 0);
124 
125 	ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
126 
127 	switch (ctb->ctb_term_type) {
128 	case CTB_PRINTERPORT:
129 		/* serial console ... */
130 		/* XXX */
131 		{
132 			/*
133 			 * Delay to allow PROM putchars to complete.
134 			 * FIFO depth * character time,
135 			 * character time = (1000000 / (defaultrate / 10))
136 			 */
137 			DELAY(160000000 / comcnrate);
138 
139 			if(comcnattach(&ccp->cc_iot, 0x3f8, comcnrate,
140 			    COM_FREQ,
141 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
142 				panic("can't init serial console");
143 
144 			break;
145 		}
146 
147 	case CTB_GRAPHICS:
148 #if NPCKBD > 0
149 		/* display console ... */
150 		/* XXX */
151 		(void) pckbc_cnattach(&ccp->cc_iot, IO_KBD, KBCMDP,
152 		    PCKBC_KBD_SLOT);
153 
154 		if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
155 		    CTB_TURBOSLOT_TYPE_ISA)
156 			isa_display_console(&ccp->cc_iot, &ccp->cc_memt);
157 		else
158 			pci_display_console(&ccp->cc_iot, &ccp->cc_memt,
159 			    &ccp->cc_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
160 			    CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
161 #else
162 		panic("not configured to use display && keyboard console");
163 #endif
164 		break;
165 
166 	default:
167 		printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
168 		printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
169 
170 		panic("consinit: unknown console type %ld",
171 		    ctb->ctb_term_type);
172 	}
173 #ifdef KGDB
174 	/* Attach the KGDB device. */
175 	alpha_kgdb_init(kgdb_devlist, &ccp->cc_iot);
176 #endif /* KGDB */
177 }
178 
179 static void
180 dec_eb164_device_register(dev, aux)
181 	struct device *dev;
182 	void *aux;
183 {
184 	static int found, initted, scsiboot, ideboot, netboot;
185 	static struct device *pcidev, *scsipidev;
186 	struct bootdev_data *b = bootdev_data;
187 	struct device *parent = dev->dv_parent;
188 	struct cfdata *cf = dev->dv_cfdata;
189 	const char *name = cf->cf_name;
190 
191 	if (found)
192 		return;
193 
194 	if (!initted) {
195 		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
196 		netboot = (strcmp(b->protocol, "BOOTP") == 0) ||
197 		    (strcmp(b->protocol, "MOP") == 0);
198 		/*
199 		 * Add an extra check to boot from ide drives:
200 		 * Newer SRM firmware use the protocol identifier IDE,
201 		 * older SRM firmware use the protocol identifier SCSI.
202 		 */
203 		ideboot = (strcmp(b->protocol, "IDE") == 0);
204 		DR_VERBOSE(printf("scsiboot = %d, ideboot = %d, netboot = %d\n",
205 		    scsiboot, ideboot, netboot));
206 		initted = 1;
207 	}
208 
209 	if (pcidev == NULL) {
210 		if (strcmp(name, "pci"))
211 			return;
212 		else {
213 			struct pcibus_attach_args *pba = aux;
214 
215 			if ((b->slot / 1000) != pba->pba_bus)
216 				return;
217 
218 			pcidev = dev;
219 			DR_VERBOSE(printf("\npcidev = %s\n",
220 			    pcidev->dv_xname));
221 			return;
222 		}
223 	}
224 
225 	if ((ideboot || scsiboot) && (scsipidev == NULL)) {
226 		if (parent != pcidev)
227 			return;
228 		else {
229 			struct pci_attach_args *pa = aux;
230 
231 			if (b->slot % 1000 / 100 != pa->pa_function)
232 				return;
233 			if (b->slot % 100 != pa->pa_device)
234 				return;
235 
236 			scsipidev = dev;
237 			DR_VERBOSE(printf("\nscsipidev = %s\n",
238 			    scsipidev->dv_xname));
239 			return;
240 		}
241 	}
242 
243 	if ((ideboot || scsiboot) &&
244 	    (!strcmp(name, "sd") ||
245 	     !strcmp(name, "st") ||
246 	     !strcmp(name, "cd"))) {
247 		struct scsipibus_attach_args *sa = aux;
248 
249 		if (parent->dv_parent != scsipidev)
250 			return;
251 
252 		if ((sa->sa_periph->periph_channel->chan_bustype->bustype_type
253 		     == SCSIPI_BUSTYPE_SCSI ||
254 		     sa->sa_periph->periph_channel->chan_bustype->bustype_type
255 		     == SCSIPI_BUSTYPE_ATAPI)
256 		    && b->unit / 100 != sa->sa_periph->periph_target)
257 			return;
258 
259 		/* XXX LUN! */
260 
261 		switch (b->boot_dev_type) {
262 		case 0:
263 			if (strcmp(name, "sd") &&
264 			    strcmp(name, "cd"))
265 				return;
266 			break;
267 		case 1:
268 			if (strcmp(name, "st"))
269 				return;
270 			break;
271 		default:
272 			return;
273 		}
274 
275 		/* we've found it! */
276 		booted_device = dev;
277 		DR_VERBOSE(printf("\nbooted_device = %s\n",
278 		    booted_device->dv_xname));
279 		found = 1;
280 	}
281 
282 	/*
283 	 * Support to boot from IDE drives.
284 	 */
285 	if ((ideboot || scsiboot) && !strcmp(name, "wd")) {
286 		struct ata_device *adev = aux;
287 		if ((strncmp("pciide", parent->dv_xname, 6) != 0)) {
288 			return;
289 		} else {
290 			if (parent != scsipidev)
291 				return;
292 		}
293 		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
294 		    adev->adev_drv_data->drive, adev->adev_channel));
295 		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
296 		    b->unit, b->channel));
297 		if (b->unit != adev->adev_drv_data->drive ||
298 		    b->channel != adev->adev_channel)
299 			return;
300 
301 		/* we've found it! */
302 		booted_device = dev;
303 		DR_VERBOSE(printf("booted_device = %s\n",
304 		    booted_device->dv_xname));
305 		found = 1;
306 	}
307 
308 	if (netboot) {
309 		if (parent != pcidev)
310 			return;
311 		else {
312 			struct pci_attach_args *pa = aux;
313 
314 			if ((b->slot % 1000) != pa->pa_device)
315 				return;
316 
317 			/* XXX function? */
318 
319 			booted_device = dev;
320 			DR_VERBOSE(printf("\nbooted_device = %s\n",
321 			    booted_device->dv_xname));
322 			found = 1;
323 			return;
324 		}
325 	}
326 }
327