xref: /openbsd/sys/arch/alpha/alpha/dec_eb164.c (revision e86d96d5)
1 /* $OpenBSD: dec_eb164.c,v 1.19 2014/05/08 20:46:49 miod Exp $ */
2 /* $NetBSD: dec_eb164.c,v 1.33 2000/05/22 20:13:32 thorpej Exp $ */
3 
4 /*
5  * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
6  * All rights reserved.
7  *
8  * Author: Chris G. Demetriou
9  *
10  * Permission to use, copy, modify and distribute this software and
11  * its documentation is hereby granted, provided that both the copyright
12  * notice and this permission notice appear in all copies of the
13  * software, derivative works or modified versions, and any portions
14  * thereof, and that both notices appear in supporting documentation.
15  *
16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19  *
20  * Carnegie Mellon requests users of this software to return to
21  *
22  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23  *  School of Computer Science
24  *  Carnegie Mellon University
25  *  Pittsburgh PA 15213-3890
26  *
27  * any improvements or extensions that they make and grant Carnegie the
28  * rights to redistribute these changes.
29  */
30 /*
31  * Additional Copyright (c) 1997 by Matthew Jacob for NASA/Ames Research Center
32  */
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 #include <sys/termios.h>
38 #include <dev/cons.h>
39 #include <sys/conf.h>
40 
41 #include <machine/rpb.h>
42 #include <machine/autoconf.h>
43 #include <machine/cpuconf.h>
44 #include <machine/bus.h>
45 
46 #include <dev/ic/comreg.h>
47 #include <dev/ic/comvar.h>
48 
49 #include <dev/isa/isareg.h>
50 #include <dev/isa/isavar.h>
51 #include <dev/ic/i8042reg.h>
52 #include <dev/ic/pckbcvar.h>
53 #include <dev/pci/pcireg.h>
54 #include <dev/pci/pcivar.h>
55 
56 #include <alpha/pci/ciareg.h>
57 #include <alpha/pci/ciavar.h>
58 
59 #include <scsi/scsi_all.h>
60 #include <scsi/scsiconf.h>
61 #include <dev/ata/atavar.h>
62 
63 #include "pckbd.h"
64 
65 #ifndef CONSPEED
66 #define CONSPEED TTYDEF_SPEED
67 #endif
68 static int comcnrate = CONSPEED;
69 
70 #define	DR_VERBOSE(f) while (0)
71 
72 void dec_eb164_init(void);
73 static void dec_eb164_cons_init(void);
74 static void dec_eb164_device_register(struct device *, void *);
75 
76 void
dec_eb164_init()77 dec_eb164_init()
78 {
79 
80 	platform.family = "EB164";
81 
82 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
83 		/* XXX Don't know the system variations, yet. */
84 		platform.model = alpha_unknown_sysname();
85 	}
86 
87 	platform.iobus = "cia";
88 	platform.cons_init = dec_eb164_cons_init;
89 	platform.device_register = dec_eb164_device_register;
90 }
91 
92 static void
dec_eb164_cons_init()93 dec_eb164_cons_init()
94 {
95 	struct ctb *ctb;
96 	struct cia_config *ccp;
97 	extern struct cia_config cia_configuration;
98 
99 	ccp = &cia_configuration;
100 	cia_init(ccp, 0);
101 
102 	ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
103 
104 	switch (ctb->ctb_term_type) {
105 	case CTB_PRINTERPORT:
106 		/* serial console ... */
107 		/* XXX */
108 		{
109 			/*
110 			 * Delay to allow PROM putchars to complete.
111 			 * FIFO depth * character time,
112 			 * character time = (1000000 / (defaultrate / 10))
113 			 */
114 			DELAY(160000000 / comcnrate);
115 
116 			if(comcnattach(&ccp->cc_iot, 0x3f8, comcnrate,
117 			    COM_FREQ,
118 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
119 				panic("can't init serial console");
120 
121 			break;
122 		}
123 
124 	case CTB_GRAPHICS:
125 #if NPCKBD > 0
126 		/* display console ... */
127 		/* XXX */
128 		(void) pckbc_cnattach(&ccp->cc_iot, IO_KBD, KBCMDP, 0);
129 
130 		/*
131 		 * On at least LX164, SRM reports an isa video board
132 		 * as a pci slot with 0xff as the bus and slot numbers.
133 		 * Since these values are not plausible from a pci point
134 		 * of view, it is safe to check for them.
135 		 */
136 		if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
137 		    CTB_TURBOSLOT_TYPE_ISA ||
138 		    (CTB_TURBOSLOT_BUS(ctb->ctb_turboslot) == 0xff &&
139 		     CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot) == 0xff))
140 			isa_display_console(&ccp->cc_iot, &ccp->cc_memt);
141 		else
142 			pci_display_console(&ccp->cc_iot, &ccp->cc_memt,
143 			    &ccp->cc_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
144 			    CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
145 #else
146 		panic("not configured to use display && keyboard console");
147 #endif
148 		break;
149 
150 	default:
151 		printf("ctb->ctb_term_type = 0x%lx\n",
152 		    (unsigned long)ctb->ctb_term_type);
153 		printf("ctb->ctb_turboslot = 0x%lx\n",
154 		    (unsigned long)ctb->ctb_turboslot);
155 
156 		panic("consinit: unknown console type %lu",
157 		    (unsigned long)ctb->ctb_term_type);
158 	}
159 }
160 
161 static void
dec_eb164_device_register(dev,aux)162 dec_eb164_device_register(dev, aux)
163 	struct device *dev;
164 	void *aux;
165 {
166 	static int found, initted, diskboot, netboot;
167 	static struct device *pcidev, *ctrlrdev;
168 	struct bootdev_data *b = bootdev_data;
169 	struct device *parent = dev->dv_parent;
170 	struct cfdata *cf = dev->dv_cfdata;
171 	struct cfdriver *cd = cf->cf_driver;
172 
173 	if (found)
174 		return;
175 
176 	if (!initted) {
177 		diskboot = (strncasecmp(b->protocol, "SCSI", 4) == 0) ||
178 		    (strncasecmp(b->protocol, "IDE", 3) == 0);
179 		netboot = (strncasecmp(b->protocol, "BOOTP", 5) == 0) ||
180 		    (strncasecmp(b->protocol, "MOP", 3) == 0);
181 		DR_VERBOSE(printf("diskboot = %d, netboot = %d\n", diskboot,
182 		    netboot));
183 		initted = 1;
184 	}
185 
186 	if (pcidev == NULL) {
187 		if (strcmp(cd->cd_name, "pci"))
188 			return;
189 		else {
190 			struct pcibus_attach_args *pba = aux;
191 
192 			if ((b->slot / 1000) != pba->pba_bus)
193 				return;
194 
195 			pcidev = dev;
196 			DR_VERBOSE(printf("\npcidev = %s\n", dev->dv_xname));
197 			return;
198 		}
199 	}
200 
201 	if (ctrlrdev == NULL) {
202 		if (parent != pcidev)
203 			return;
204 		else {
205 			struct pci_attach_args *pa = aux;
206 			int slot;
207 
208 			slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
209 			    pa->pa_device;
210 			if (b->slot != slot)
211 				return;
212 
213 			if (netboot) {
214 				booted_device = dev;
215 				DR_VERBOSE(printf("\nbooted_device = %s\n",
216 				    dev->dv_xname));
217 				found = 1;
218 			} else {
219 				ctrlrdev = dev;
220 				DR_VERBOSE(printf("\nctrlrdev = %s\n",
221 				    dev->dv_xname));
222 			}
223 			return;
224 		}
225 	}
226 
227 	if (!diskboot)
228 		return;
229 
230 	if (!strcmp(cd->cd_name, "sd") || !strcmp(cd->cd_name, "st") ||
231 	    !strcmp(cd->cd_name, "cd")) {
232 		struct scsi_attach_args *sa = aux;
233 		struct scsi_link *periph = sa->sa_sc_link;
234 		int unit;
235 
236 		if (parent->dv_parent != ctrlrdev)
237 			return;
238 
239 		unit = periph->target * 100 + periph->lun;
240 		if (b->unit != unit)
241 			return;
242 
243 		/* we've found it! */
244 		booted_device = dev;
245 		DR_VERBOSE(printf("\nbooted_device = %s\n", dev->dv_xname));
246 		found = 1;
247 	}
248 
249 	/*
250 	 * Support to boot from IDE drives.
251 	 */
252 	if (!strcmp(cd->cd_name, "wd")) {
253 		struct ata_atapi_attach *aa_link = aux;
254 		int variation = hwrpb->rpb_variation & SV_ST_MASK;
255 
256 		if ((strcmp("pciide", parent->dv_cfdata->cf_driver->cd_name) != 0))
257 			return;
258 		if (parent != ctrlrdev)
259 			return;
260 
261 		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
262 		    aa_link->aa_drv_data->drive, aa_link->aa_channel));
263 		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
264 		    b->unit, b->channel));
265 		if (b->unit != aa_link->aa_drv_data->drive)
266 			return;
267 
268 		/*
269 		 * On 164SX, the built-in IDE controller appears as
270 		 * two distinct pciide devices, both with a single
271 		 * channel.  However SRM will nevertheless pretend
272 		 * the second channel is channel #1 of the second
273 		 * device, while it is really channel #0, so just
274 		 * ignore the channel number in this case.
275 		 */
276 		if (variation >= SV_ST_ALPHAPC164SX_400 &&
277 		   variation <= SV_ST_ALPHAPC164SX_600 &&
278 		    b->slot == 0 * 1000 + 2 * 100 + 8) {
279 			/* nothing */
280 		} else {
281 			if (b->channel != aa_link->aa_channel)
282 				return;
283 		}
284 
285 		/* we've found it! */
286 		booted_device = dev;
287 		DR_VERBOSE(printf("booted_device = %s\n", dev->dv_xname));
288 		found = 1;
289 	}
290 }
291