xref: /netbsd/sys/arch/alpha/alpha/dec_2000_300.c (revision bf9ec67e)
1 /* $NetBSD: dec_2000_300.c,v 1.4 2001/05/30 15:24:26 lukem Exp $ */
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
41  * All rights reserved.
42  *
43  * Author: Chris G. Demetriou
44  *
45  * Permission to use, copy, modify and distribute this software and
46  * its documentation is hereby granted, provided that both the copyright
47  * notice and this permission notice appear in all copies of the
48  * software, derivative works or modified versions, and any portions
49  * thereof, and that both notices appear in supporting documentation.
50  *
51  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
52  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
53  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
54  *
55  * Carnegie Mellon requests users of this software to return to
56  *
57  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
58  *  School of Computer Science
59  *  Carnegie Mellon University
60  *  Pittsburgh PA 15213-3890
61  *
62  * any improvements or extensions that they make and grant Carnegie the
63  * rights to redistribute these changes.
64  */
65 
66 #include "opt_kgdb.h"
67 
68 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
69 
70 __KERNEL_RCSID(0, "$NetBSD: dec_2000_300.c,v 1.4 2001/05/30 15:24:26 lukem Exp $");
71 
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/device.h>
75 #include <sys/termios.h>
76 
77 #include <machine/rpb.h>
78 #include <machine/autoconf.h>
79 #include <machine/conf.h>
80 
81 #include <dev/eisa/eisavar.h>
82 #include <dev/isa/isareg.h>
83 #include <dev/isa/isavar.h>
84 #include <dev/ic/i8042reg.h>
85 
86 #include <dev/ic/comvar.h>
87 #include <dev/ic/comreg.h>
88 #include <dev/ic/pckbcvar.h>
89 
90 #include <alpha/jensenio/jenseniovar.h>
91 
92 #include <dev/scsipi/scsi_all.h>
93 #include <dev/scsipi/scsipi_all.h>
94 #include <dev/scsipi/scsiconf.h>
95 
96 #include "pckbd.h"
97 
98 void dec_2000_300_init(void);
99 static void dec_2000_300_cons_init(void);
100 static void dec_2000_300_device_register(struct device *, void *);
101 
102 #ifdef KGDB
103 #include <machine/db_machdep.h>
104 
105 static const char *kgdb_devlist[] = {
106 	"com",
107 	NULL,
108 };
109 #endif /* KGDB */
110 
111 void
112 dec_2000_300_init(void)
113 {
114 
115 	platform.family = "DECpc AXP 150 (\"Jensen\")";
116 
117 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
118 		/* XXX Don't know the system variations, yet. */
119 		platform.model = alpha_unknown_sysname();
120 	}
121 
122 	platform.iobus = "jensenio";
123 	platform.cons_init = dec_2000_300_cons_init;
124 	platform.device_register = dec_2000_300_device_register;
125 }
126 
127 static void
128 dec_2000_300_cons_init(void)
129 {
130 	struct ctb_tt *ctb;
131 	struct jensenio_config *jcp;
132 	extern struct jensenio_config jensenio_configuration;
133 
134 	jcp = &jensenio_configuration;
135 	jensenio_init(jcp, 0);
136 
137 	ctb = (struct ctb_tt *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
138 
139 	/*
140 	 * The Jensen uses an older (pre-Type 4) CTB format.  The
141 	 * console type is specified directly by ctb_type, and only
142 	 * minimal info is given, only for the serial console.
143 	 *
144 	 * Thankfully, the only graphics device we can have is
145 	 * ISA/EISA, so it really doesn't matter too much.
146 	 */
147 
148 	switch (ctb->ctb_type) {
149 	case CTB_PRINTERPORT:
150 		/* serial console... */
151 		/* XXX */
152 		{
153 #if 0
154 			printf("CTB CSR = 0x%08lx\n", ctb->ctb_csr);
155 			printf("CTB BAUD = %lu\n", ctb->ctb_baud);
156 #endif
157 			/*
158 			 * Delay to allow PROM putchars to complete.
159 			 * FIFO depth * character time,
160 			 * character time = (1000000 / (defaultrate / 10))
161 			 */
162 			DELAY(160000000 / ctb->ctb_baud);
163 
164 			if (comcnattach(&jcp->jc_internal_iot, 0x3f8,
165 			    ctb->ctb_baud, COM_FREQ,
166 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
167 				panic("can't init serial console");
168 
169 			break;
170 		}
171 
172 	case CTB_GRAPHICS:
173 #if NPCKBD > 0
174 		/* display console... */
175 		/* XXX */
176 		(void) pckbc_cnattach(&jcp->jc_internal_iot, IO_KBD, KBCMDP,
177 		    PCKBC_KBD_SLOT);
178 
179 		isa_display_console(&jcp->jc_eisa_iot, &jcp->jc_eisa_memt);
180 #else
181 		panic("not configured to use display && keyboard console");
182 #endif
183 		break;
184 
185 
186 	default:
187 		goto badconsole;
188 	}
189 #ifdef KGDB
190 	/* Attach the KGDB device. */
191 	alpha_kgdb_init(kgdb_devlist, &jcp->jc_internal_iot);
192 #endif /* KGDB */
193 
194 	return;
195  badconsole:
196 	printf("ctb->ctb_type = 0x%lx\n", ctb->ctb_type);
197 	printf("ctb->ctb_csr = 0x%lx\n", ctb->ctb_csr);
198 	printf("ctb->ctb_baud = %lu\n", ctb->ctb_baud);
199 
200 	panic("consinit: unknown console type %lu\n",
201 	    ctb->ctb_type);
202 }
203 
204 static void
205 dec_2000_300_device_register(struct device *dev, void *aux)
206 {
207 	static int found, initted, scsiboot, netboot;
208 	static struct device *eisadev, *isadev, *scsidev;
209 	struct bootdev_data *b = bootdev_data;
210 	struct device *parent = dev->dv_parent;
211 	struct cfdata *cf = dev->dv_cfdata;
212 	struct cfdriver *cd = cf->cf_driver;
213 
214 	if (found)
215 		return;
216 
217 	if (!initted) {
218 		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
219 		netboot = (strcmp(b->protocol, "BOOTP") == 0);
220 #if 0
221 		printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot);
222 #endif
223 		initted = 1;
224 	}
225 
226 	if (eisadev == NULL && strcmp(cd->cd_name, "eisa") == 0)
227 		eisadev = dev;
228 
229 	if (isadev == NULL && strcmp(cd->cd_name, "isa") == 0)
230 		isadev = dev;
231 
232 	if (scsiboot && (scsidev == NULL)) {
233 		if (parent != eisadev)
234 			return;
235 		else {
236 			struct eisa_attach_args *ea = aux;
237 
238 			if (b->slot != ea->ea_slot)
239 				return;
240 
241 			scsidev = dev;
242 #if 0
243 			printf("\nscsidev = %s\n", scsidev->dv_xname);
244 #endif
245 			return;
246 		}
247 	}
248 
249 	if (scsiboot &&
250 	    (!strcmp(cd->cd_name, "sd") ||
251 	     !strcmp(cd->cd_name, "st") ||
252 	     !strcmp(cd->cd_name, "cd"))) {
253 		struct scsipibus_attach_args *sa = aux;
254 
255 		if (parent->dv_parent != scsidev)
256 			return;
257 
258 		if (b->unit / 100 != sa->sa_periph->periph_target)
259 			return;
260 
261 		/* XXX LUN! */
262 
263 		switch (b->boot_dev_type) {
264 		case 0:
265 			if (strcmp(cd->cd_name, "sd") &&
266 			    strcmp(cd->cd_name, "cd"))
267 				return;
268 			break;
269 		case 1:
270 			if (strcmp(cd->cd_name, "st"))
271 				return;
272 			break;
273 		default:
274 			return;
275 		}
276 
277 		/* we've found it! */
278 		booted_device = dev;
279 #if 0
280 		printf("\nbooted_device = %s\n", booted_device->dv_xname);
281 #endif
282 		found = 1;
283 		return;
284 	}
285 
286 	if (netboot) {
287 		/*
288 		 * XXX WHAT ABOUT ISA NETWORK CARDS?
289 		 */
290 		if (parent != eisadev)
291 			return;
292 		else {
293 			struct eisa_attach_args *ea = aux;
294 
295 			if (b->slot != ea->ea_slot)
296 				return;
297 
298 			booted_device = dev;
299 #if 0
300 			printf("\nbooted_device = %s\n", booted_device->dv_xname);
301 #endif
302 			found = 1;
303 			return;
304 		}
305 	}
306 }
307