xref: /openbsd/sys/arch/alpha/alpha/api_up1000.c (revision e86d96d5)
1 /*	$OpenBSD: api_up1000.c,v 1.12 2014/05/08 20:46:49 miod Exp $	*/
2 /* $NetBSD: api_up1000.c,v 1.4 2000/06/20 03:48:53 matt 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/irongatereg.h>
57 #include <alpha/pci/irongatevar.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 #ifdef DEBUG
71 int bootdev_debug;
72 #define	DPRINTF(x)	if (bootdev_debug) printf x
73 #else
74 #define DPRINTF(x)
75 #endif
76 
77 void api_up1000_init(void);
78 static void api_up1000_cons_init(void);
79 static void api_up1000_device_register(struct device *, void *);
80 
81 void
api_up1000_init()82 api_up1000_init()
83 {
84 
85 	platform.family = "API UP1000";
86 
87 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
88 		/* XXX Don't know the system variations, yet. */
89 		platform.model = alpha_unknown_sysname();
90 	}
91 
92 	platform.iobus = "irongate";
93 	platform.cons_init = api_up1000_cons_init;
94 	platform.device_register = api_up1000_device_register;
95 }
96 
97 static void
api_up1000_cons_init()98 api_up1000_cons_init()
99 {
100 	struct ctb *ctb;
101 	struct irongate_config *icp;
102 	extern struct irongate_config irongate_configuration;
103 
104 	icp = &irongate_configuration;
105 	irongate_init(icp, 0);
106 
107 	ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
108 
109 	switch (ctb->ctb_term_type) {
110 	case CTB_PRINTERPORT:
111 		/* serial console ... */
112 		/* XXX */
113 		{
114 			/*
115 			 * Delay to allow PROM putchars to complete.
116 			 * FIFO depth * character time,
117 			 * character time = (1000000 / (defaultrate / 10))
118 			 */
119 			DELAY(160000000 / comcnrate);
120 
121 			if (comcnattach(&icp->ic_iot, 0x3f8, comcnrate,
122 			    COM_FREQ,
123 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
124 				panic("can't init serial console");
125 
126 			break;
127 		}
128 
129 	case CTB_GRAPHICS:
130 #if NPCKBD > 0
131 		/* display console ... */
132 		/* XXX */
133 		(void) pckbc_cnattach(&icp->ic_iot, IO_KBD, KBCMDP, 0);
134 
135 		if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
136 		    CTB_TURBOSLOT_TYPE_ISA)
137 			isa_display_console(&icp->ic_iot, &icp->ic_memt);
138 		else
139 			pci_display_console(&icp->ic_iot, &icp->ic_memt,
140 			    &icp->ic_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
141 			    CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
142 #else
143 		panic("not configured to use display && keyboard console");
144 #endif
145 		break;
146 
147 	default:
148 		printf("ctb->ctb_term_type = 0x%lx\n",
149 		    (unsigned long)ctb->ctb_term_type);
150 		printf("ctb->ctb_turboslot = 0x%lx\n",
151 		    (unsigned long)ctb->ctb_turboslot);
152 
153 		panic("consinit: unknown console type %lu",
154 		    (unsigned long)ctb->ctb_term_type);
155 	}
156 }
157 
158 static void
api_up1000_device_register(dev,aux)159 api_up1000_device_register(dev, aux)
160 	struct device *dev;
161 	void *aux;
162 {
163 	static int found, initted, scsiboot, ideboot, netboot;
164 	static struct device *pcidev, *scsidev;
165 	struct bootdev_data *b = bootdev_data;
166 	struct device *parent = dev->dv_parent;
167 	struct cfdata *cf = dev->dv_cfdata;
168 	struct cfdriver *cd = cf->cf_driver;
169 
170 	if (found)
171 		return;
172 
173 	if (!initted) {
174 		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
175 		netboot = (strcmp(b->protocol, "BOOTP") == 0) ||
176 		    (strcmp(b->protocol, "MOP") == 0);
177 		/*
178 		 * Add an extra check to boot from ide drives:
179 		 * Newer SRM firmware use the protocol identifier IDE,
180 		 * older SRM firmware use the protocol identifier SCSI.
181 		 */
182 		ideboot = (strcmp(b->protocol, "IDE") == 0);
183 		DPRINTF(("\nscsiboot = %d, ideboot = %d, netboot = %d\n",
184 		    scsiboot, ideboot, netboot));
185 		initted = 1;
186 	}
187 
188 	if (pcidev == NULL) {
189 		if (strcmp(cd->cd_name, "pci"))
190 			return;
191 		else {
192 			struct pcibus_attach_args *pba = aux;
193 
194 			if ((b->slot / 1000) != pba->pba_bus)
195 				return;
196 
197 			pcidev = dev;
198 			DPRINTF(("\npcidev = %s\n", pcidev->dv_xname));
199 			return;
200 		}
201 	}
202 
203 	if ((ideboot || scsiboot) && (scsidev == NULL)) {
204 		if (parent != pcidev)
205 			return;
206 		else {
207 			struct pci_attach_args *pa = aux;
208 
209 			if (b->slot % 1000 / 100 != pa->pa_function)
210 				return;
211 			if (b->slot % 100 != pa->pa_device)
212 				return;
213 
214 			scsidev = dev;
215 			DPRINTF(("\nscsidev = %s\n", scsidev->dv_xname));
216 			return;
217 		}
218 	}
219 
220 	if ((ideboot || scsiboot) &&
221 	    (!strcmp(cd->cd_name, "sd") ||
222 	     !strcmp(cd->cd_name, "st") ||
223 	     !strcmp(cd->cd_name, "cd"))) {
224 		struct scsi_attach_args *sa = aux;
225 
226 		if (parent->dv_parent != scsidev)
227 			return;
228 
229 		if (b->unit / 100 != sa->sa_sc_link->target)
230 			return;
231 
232 		/* XXX LUN! */
233 
234 		switch (b->boot_dev_type) {
235 		case 0:
236 			if (strcmp(cd->cd_name, "sd") &&
237 			    strcmp(cd->cd_name, "cd"))
238 				return;
239 			break;
240 		case 1:
241 			if (strcmp(cd->cd_name, "st"))
242 				return;
243 			break;
244 		default:
245 			return;
246 		}
247 
248 		/* we've found it! */
249 		booted_device = dev;
250 		DPRINTF(("\nbooted_device = %s\n", booted_device->dv_xname));
251 		found = 1;
252 	}
253 
254 	/*
255 	 * Support to boot from IDE drives.
256 	 */
257 	if ((ideboot || scsiboot) && !strcmp(cd->cd_name, "wd")) {
258 		struct ata_atapi_attach *aa_link = aux;
259 		if ((strcmp("pciide", parent->dv_cfdata->cf_driver->cd_name) != 0)) {
260 			return;
261 		} else {
262 			if (parent != scsidev)
263 				return;
264 		}
265 		DPRINTF(("\natapi info: drive %d, channel %d\n",
266 		    aa_link->aa_drv_data->drive, aa_link->aa_channel));
267 		DPRINTF(("bootdev info: unit: %d, channel: %d\n",
268 		    b->unit, b->channel));
269 		if (b->unit != aa_link->aa_drv_data->drive ||
270 		    b->channel != aa_link->aa_channel)
271 			return;
272 
273 		/* we've found it! */
274 		booted_device = dev;
275 		DPRINTF(("booted_device = %s\n", booted_device->dv_xname));
276 		found = 1;
277 	}
278 
279 	if (netboot) {
280 		if (parent != pcidev)
281 			return;
282 		else {
283 			struct pci_attach_args *pa = aux;
284 
285 			if ((b->slot % 1000) != pa->pa_device)
286 				return;
287 
288 			/* XXX function? */
289 
290 			booted_device = dev;
291 			DPRINTF(("\nbooted_device = %s\n",
292 			    booted_device->dv_xname));
293 			found = 1;
294 			return;
295 		}
296 	}
297 }
298