xref: /netbsd/sys/arch/alpha/alpha/dec_2000_300.c (revision c4a72b64)
1 /* $NetBSD: dec_2000_300.c,v 1.8 2002/09/27 15:35:34 provos 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.8 2002/09/27 15:35:34 provos Exp $");
71 
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/device.h>
75 #include <sys/termios.h>
76 #include <sys/conf.h>
77 
78 #include <machine/rpb.h>
79 #include <machine/autoconf.h>
80 #include <machine/cpuconf.h>
81 
82 #include <dev/eisa/eisavar.h>
83 #include <dev/isa/isareg.h>
84 #include <dev/isa/isavar.h>
85 #include <dev/ic/i8042reg.h>
86 
87 #include <dev/ic/comvar.h>
88 #include <dev/ic/comreg.h>
89 #include <dev/ic/pckbcvar.h>
90 
91 #include <alpha/jensenio/jenseniovar.h>
92 
93 #include <dev/scsipi/scsi_all.h>
94 #include <dev/scsipi/scsipi_all.h>
95 #include <dev/scsipi/scsiconf.h>
96 
97 #include "pckbd.h"
98 
99 void dec_2000_300_init(void);
100 static void dec_2000_300_cons_init(void);
101 static void dec_2000_300_device_register(struct device *, void *);
102 
103 #ifdef KGDB
104 #include <machine/db_machdep.h>
105 
106 static const char *kgdb_devlist[] = {
107 	"com",
108 	NULL,
109 };
110 #endif /* KGDB */
111 
112 void
113 dec_2000_300_init(void)
114 {
115 
116 	platform.family = "DECpc AXP 150 (\"Jensen\")";
117 
118 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
119 		/* XXX Don't know the system variations, yet. */
120 		platform.model = alpha_unknown_sysname();
121 	}
122 
123 	platform.iobus = "jensenio";
124 	platform.cons_init = dec_2000_300_cons_init;
125 	platform.device_register = dec_2000_300_device_register;
126 }
127 
128 static void
129 dec_2000_300_cons_init(void)
130 {
131 	struct ctb_tt *ctb;
132 	struct jensenio_config *jcp;
133 	extern struct jensenio_config jensenio_configuration;
134 
135 	jcp = &jensenio_configuration;
136 	jensenio_init(jcp, 0);
137 
138 	ctb = (struct ctb_tt *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
139 
140 	/*
141 	 * The Jensen uses an older (pre-Type 4) CTB format.  The
142 	 * console type is specified directly by ctb_type, and only
143 	 * minimal info is given, only for the serial console.
144 	 *
145 	 * Thankfully, the only graphics device we can have is
146 	 * ISA/EISA, so it really doesn't matter too much.
147 	 */
148 
149 	switch (ctb->ctb_type) {
150 	case CTB_PRINTERPORT:
151 		/* serial console... */
152 		/* XXX */
153 		{
154 #if 0
155 			printf("CTB CSR = 0x%08lx\n", ctb->ctb_csr);
156 			printf("CTB BAUD = %lu\n", ctb->ctb_baud);
157 #endif
158 			/*
159 			 * Delay to allow PROM putchars to complete.
160 			 * FIFO depth * character time,
161 			 * character time = (1000000 / (defaultrate / 10))
162 			 */
163 			DELAY(160000000 / ctb->ctb_baud);
164 
165 			if (comcnattach(&jcp->jc_internal_iot, 0x3f8,
166 			    ctb->ctb_baud, COM_FREQ,
167 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
168 				panic("can't init serial console");
169 
170 			break;
171 		}
172 
173 	case CTB_GRAPHICS:
174 #if NPCKBD > 0
175 		/* display console... */
176 		/* XXX */
177 		(void) pckbc_cnattach(&jcp->jc_internal_iot, IO_KBD, KBCMDP,
178 		    PCKBC_KBD_SLOT);
179 
180 		isa_display_console(&jcp->jc_eisa_iot, &jcp->jc_eisa_memt);
181 #else
182 		panic("not configured to use display && keyboard console");
183 #endif
184 		break;
185 
186 
187 	default:
188 		goto badconsole;
189 	}
190 #ifdef KGDB
191 	/* Attach the KGDB device. */
192 	alpha_kgdb_init(kgdb_devlist, &jcp->jc_internal_iot);
193 #endif /* KGDB */
194 
195 	return;
196  badconsole:
197 	printf("ctb->ctb_type = 0x%lx\n", ctb->ctb_type);
198 	printf("ctb->ctb_csr = 0x%lx\n", ctb->ctb_csr);
199 	printf("ctb->ctb_baud = %lu\n", ctb->ctb_baud);
200 
201 	panic("consinit: unknown console type %lu",
202 	    ctb->ctb_type);
203 }
204 
205 static void
206 dec_2000_300_device_register(struct device *dev, void *aux)
207 {
208 	static int found, initted, scsiboot, netboot;
209 	static struct device *eisadev, *isadev, *scsidev;
210 	struct bootdev_data *b = bootdev_data;
211 	struct device *parent = dev->dv_parent;
212 	struct cfdata *cf = dev->dv_cfdata;
213 	const char *name = cf->cf_name;
214 
215 	if (found)
216 		return;
217 
218 	if (!initted) {
219 		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
220 		netboot = (strcmp(b->protocol, "BOOTP") == 0);
221 #if 0
222 		printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot);
223 #endif
224 		initted = 1;
225 	}
226 
227 	if (eisadev == NULL && strcmp(name, "eisa") == 0)
228 		eisadev = dev;
229 
230 	if (isadev == NULL && strcmp(name, "isa") == 0)
231 		isadev = dev;
232 
233 	if (scsiboot && (scsidev == NULL)) {
234 		if (parent != eisadev)
235 			return;
236 		else {
237 			struct eisa_attach_args *ea = aux;
238 
239 			if (b->slot != ea->ea_slot)
240 				return;
241 
242 			scsidev = dev;
243 #if 0
244 			printf("\nscsidev = %s\n", scsidev->dv_xname);
245 #endif
246 			return;
247 		}
248 	}
249 
250 	if (scsiboot &&
251 	    (!strcmp(name, "sd") ||
252 	     !strcmp(name, "st") ||
253 	     !strcmp(name, "cd"))) {
254 		struct scsipibus_attach_args *sa = aux;
255 
256 		if (parent->dv_parent != scsidev)
257 			return;
258 
259 		if (b->unit / 100 != sa->sa_periph->periph_target)
260 			return;
261 
262 		/* XXX LUN! */
263 
264 		switch (b->boot_dev_type) {
265 		case 0:
266 			if (strcmp(name, "sd") &&
267 			    strcmp(name, "cd"))
268 				return;
269 			break;
270 		case 1:
271 			if (strcmp(name, "st"))
272 				return;
273 			break;
274 		default:
275 			return;
276 		}
277 
278 		/* we've found it! */
279 		booted_device = dev;
280 #if 0
281 		printf("\nbooted_device = %s\n", booted_device->dv_xname);
282 #endif
283 		found = 1;
284 		return;
285 	}
286 
287 	if (netboot) {
288 		/*
289 		 * XXX WHAT ABOUT ISA NETWORK CARDS?
290 		 */
291 		if (parent != eisadev)
292 			return;
293 		else {
294 			struct eisa_attach_args *ea = aux;
295 
296 			if (b->slot != ea->ea_slot)
297 				return;
298 
299 			booted_device = dev;
300 #if 0
301 			printf("\nbooted_device = %s\n", booted_device->dv_xname);
302 #endif
303 			found = 1;
304 			return;
305 		}
306 	}
307 }
308