xref: /netbsd/sys/arch/alpha/alpha/dec_550.c (revision bf9ec67e)
1 /* $NetBSD: dec_550.c,v 1.16 2001/12/02 22:54:26 bouyer 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_550.c,v 1.16 2001/12/02 22:54:26 bouyer 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/ciareg.h>
63 #include <alpha/pci/ciavar.h>
64 
65 #include <dev/scsipi/scsi_all.h>
66 #include <dev/scsipi/scsipi_all.h>
67 #include <dev/scsipi/scsiconf.h>
68 #include <dev/ata/atavar.h>
69 #include <dev/ata/wdvar.h>
70 
71 /* Write this to Pyxis General Purpose Output to turn off the power. */
72 #define	DEC_550_PYXIS_GPO_POWERDOWN	0x00000400
73 
74 #include "pckbd.h"
75 
76 #ifndef CONSPEED
77 #define CONSPEED TTYDEF_SPEED
78 #endif
79 static int comcnrate = CONSPEED;
80 
81 #define	DR_VERBOSE(f) while (0)
82 
83 void dec_550_init __P((void));
84 static void dec_550_cons_init __P((void));
85 static void dec_550_device_register __P((struct device *, void *));
86 static void dec_550_powerdown __P((void));
87 
88 #ifdef KGDB
89 #include <machine/db_machdep.h>
90 
91 static const char *kgdb_devlist[] = {
92 	"com",
93 	NULL,
94 };
95 #endif /* KGDB */
96 
97 void
98 dec_550_init()
99 {
100 
101 	platform.family = "Digital Personal Workstation";
102 
103 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
104 		/* XXX Don't know the system variations, yet. */
105 		platform.model = alpha_unknown_sysname();
106 	}
107 
108 	platform.iobus = "cia";
109 	platform.cons_init = dec_550_cons_init;
110 	platform.device_register = dec_550_device_register;
111 	platform.powerdown = dec_550_powerdown;
112 
113 	/*
114 	 * If Miata systems have a secondary cache, it's 2MB.
115 	 */
116 	uvmexp.ncolors = atop(2 * 1024 * 1024);
117 }
118 
119 static void
120 dec_550_cons_init()
121 {
122 	struct ctb *ctb;
123 	struct cia_config *ccp;
124 	extern struct cia_config cia_configuration;
125 
126 	ccp = &cia_configuration;
127 	cia_init(ccp, 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(&ccp->cc_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(&ccp->cc_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(&ccp->cc_iot, &ccp->cc_memt);
161 		else
162 			pci_display_console(&ccp->cc_iot, &ccp->cc_memt,
163 			    &ccp->cc_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\n",
175 		    ctb->ctb_term_type);
176 	}
177 #ifdef KGDB
178 	/* Attach the KGDB device. */
179 	alpha_kgdb_init(kgdb_devlist, &ccp->cc_iot);
180 #endif /* KGDB */
181 }
182 
183 static void
184 dec_550_device_register(dev, aux)
185 	struct device *dev;
186 	void *aux;
187 {
188 	static int found, initted, scsiboot, ideboot, netboot;
189 	static struct device *pcidev, *scsipidev;
190 	struct bootdev_data *b = bootdev_data;
191 	struct device *parent = dev->dv_parent;
192 	struct cfdata *cf = dev->dv_cfdata;
193 	struct cfdriver *cd = cf->cf_driver;
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 		/*
203 		 * Add an extra check to boot from ide drives:
204 		 * Newer SRM firmware use the protocol identifier IDE,
205 		 * older SRM firmware use the protocol identifier SCSI.
206 		 */
207 		ideboot = (strcmp(b->protocol, "IDE") == 0);
208 		DR_VERBOSE(printf("scsiboot = %d, ideboot = %d, netboot = %d\n",
209 		    scsiboot, ideboot, netboot));
210 		initted = 1;
211 	}
212 
213 	if (pcidev == NULL) {
214 		if (strcmp(cd->cd_name, "pci"))
215 			return;
216 		else {
217 			struct pcibus_attach_args *pba = aux;
218 
219 			if ((b->slot / 1000) != pba->pba_bus)
220 				return;
221 
222 			pcidev = dev;
223 			DR_VERBOSE(printf("\npcidev = %s\n",
224 			    pcidev->dv_xname));
225 			return;
226 		}
227 	}
228 
229 	if ((ideboot || scsiboot) && (scsipidev == NULL)) {
230 		if (parent != pcidev)
231 			return;
232 		else {
233 			struct pci_attach_args *pa = aux;
234 
235 			if ((b->slot % 1000) != pa->pa_device)
236 				return;
237 
238 			/* XXX function? */
239 
240 			scsipidev = dev;
241 			DR_VERBOSE(printf("\nscsipidev = %s\n",
242 			    scsipidev->dv_xname));
243 			return;
244 		}
245 	}
246 
247 	if ((ideboot || scsiboot) &&
248 	    (!strcmp(cd->cd_name, "sd") ||
249 	     !strcmp(cd->cd_name, "st") ||
250 	     !strcmp(cd->cd_name, "cd"))) {
251 		struct scsipibus_attach_args *sa = aux;
252 
253 		if (parent->dv_parent != scsipidev)
254 			return;
255 
256 		if ((sa->sa_periph->periph_channel->chan_bustype->bustype_type
257 		     == SCSIPI_BUSTYPE_SCSI ||
258 		     sa->sa_periph->periph_channel->chan_bustype->bustype_type
259 		     == SCSIPI_BUSTYPE_ATAPI)
260 		    && b->unit / 100 != sa->sa_periph->periph_target)
261 			return;
262 
263 		/* XXX LUN! */
264 
265 		switch (b->boot_dev_type) {
266 		case 0:
267 			if (strcmp(cd->cd_name, "sd") &&
268 			    strcmp(cd->cd_name, "cd"))
269 				return;
270 			break;
271 		case 1:
272 			if (strcmp(cd->cd_name, "st"))
273 				return;
274 			break;
275 		default:
276 			return;
277 		}
278 
279 		/* we've found it! */
280 		booted_device = dev;
281 		DR_VERBOSE(printf("\nbooted_device = %s\n",
282 		    booted_device->dv_xname));
283 		found = 1;
284 	}
285 
286 	/*
287 	 * Support to boot from IDE drives.
288 	 */
289 	if ((ideboot || scsiboot) && !strcmp(cd->cd_name, "wd")) {
290 		struct ata_device *adev = aux;
291 		if ((strncmp("pciide", parent->dv_xname, 6) != 0)) {
292 			return;
293 		} else {
294 			if (parent != scsipidev)
295 				return;
296 		}
297 		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
298 		    adev->adev_drv_data->drive, adev->adev_channel));
299 		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
300 		    b->unit, b->channel));
301 		if (b->unit != adev->adev_drv_data->drive ||
302 		    b->channel != adev->adev_channel)
303 			return;
304 
305 		/* we've found it! */
306 		booted_device = dev;
307 		DR_VERBOSE(printf("booted_device = %s\n",
308 		    booted_device->dv_xname));
309 		found = 1;
310 	}
311 
312 	if (netboot) {
313 		if (parent != pcidev)
314 			return;
315 		else {
316 			struct pci_attach_args *pa = aux;
317 
318 			if ((b->slot % 1000) != pa->pa_device)
319 				return;
320 
321 			/* XXX function? */
322 
323 			booted_device = dev;
324 			DR_VERBOSE(printf("\nbooted_device = %s\n",
325 			    booted_device->dv_xname));
326 			found = 1;
327 			return;
328 		}
329 	}
330 }
331 
332 static void
333 dec_550_powerdown()
334 {
335 
336 	REGVAL(PYXIS_GPO) = DEC_550_PYXIS_GPO_POWERDOWN;
337 	alpha_mb();
338 }
339