xref: /netbsd-src/sys/arch/alpha/alpha/dec_3000_500.c (revision 296121ed992a66fda2c79e843285616269b1d6d1)
1 /* $NetBSD: dec_3000_500.c,v 1.48 2024/03/31 19:06:30 thorpej Exp $ */
2 
3 /*
4  * Copyright (c) 1994, 1995, 1996 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 <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
34 
35 __KERNEL_RCSID(0, "$NetBSD: dec_3000_500.c,v 1.48 2024/03/31 19:06:30 thorpej Exp $");
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/termios.h>
41 #include <sys/conf.h>
42 #include <dev/cons.h>
43 
44 #include <machine/rpb.h>
45 #include <machine/autoconf.h>
46 #include <machine/cpuconf.h>
47 
48 #include <dev/tc/tcvar.h>
49 #include <dev/tc/tcdsvar.h>
50 #include <alpha/tc/tc_3000_500.h>
51 
52 #include <machine/z8530var.h>
53 #include <dev/tc/zs_ioasicvar.h>
54 
55 #include <dev/scsipi/scsi_all.h>
56 #include <dev/scsipi/scsipi_all.h>
57 #include <dev/scsipi/scsiconf.h>
58 
59 #include "wsdisplay.h"
60 
61 void dec_3000_500_init(void);
62 static void dec_3000_500_cons_init(void);
63 static void dec_3000_500_device_register(device_t, void *);
64 
65 static const char dec_3000_500_sp[] = "DEC 3000/400 (\"Sandpiper\")";
66 static const char dec_3000_500_sf[] = "DEC 3000/500 (\"Flamingo\")";
67 
68 const struct alpha_variation_table dec_3000_500_variations[] = {
69 	{ SV_ST_SANDPIPER, dec_3000_500_sp },
70 	{ SV_ST_FLAMINGO, dec_3000_500_sf },
71 	{ SV_ST_HOTPINK, "DEC 3000/500X (\"Hot Pink\")" },
72 	{ SV_ST_FLAMINGOPLUS, "DEC 3000/800 (\"Flamingo+\")" },
73 	{ SV_ST_SANDPLUS, "DEC 3000/600 (\"Sandpiper+\")" },
74 	{ SV_ST_SANDPIPER45, "DEC 3000/700 (\"Sandpiper45\")" },
75 	{ SV_ST_FLAMINGO45, "DEC 3000/900 (\"Flamingo45\")" },
76 	{ 0, NULL },
77 };
78 
79 void
dec_3000_500_init(void)80 dec_3000_500_init(void)
81 {
82 	uint64_t variation;
83 
84 	platform.family = "DEC 3000/500 (\"Flamingo\")";
85 
86 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
87 		variation = hwrpb->rpb_variation & SV_ST_MASK;
88 		if (variation == SV_ST_ULTRA) {
89 			/* These are really the same. */
90 			variation = SV_ST_FLAMINGOPLUS;
91 		}
92 		if ((platform.model = alpha_variation_name(variation,
93 		    dec_3000_500_variations)) == NULL) {
94 			/*
95 			 * This is how things used to be done.
96 			 */
97 			if (variation == SV_ST_RESERVED) {
98 				if (hwrpb->rpb_variation & SV_GRAPHICS)
99 					platform.model = dec_3000_500_sf;
100 				else
101 					platform.model = dec_3000_500_sp;
102 			} else
103 				platform.model = alpha_unknown_sysname();
104 		}
105 	}
106 
107 	platform.iobus = "tcasic";
108 	platform.cons_init = dec_3000_500_cons_init;
109 	platform.device_register = dec_3000_500_device_register;
110 }
111 
112 static void
dec_3000_500_cons_init(void)113 dec_3000_500_cons_init(void)
114 {
115 	struct ctb *ctb;
116 
117 	ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
118 
119 	switch (ctb->ctb_term_type) {
120 	case CTB_GRAPHICS:
121 #if NWSDISPLAY > 0
122 		/* display console ... */
123 		if (zs_ioasic_lk201_cnattach(0x1e0000000, 0x00180000, 0) == 0 &&
124 		    tc_3000_500_fb_cnattach(
125 		     CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot)) == 0) {
126 			break;
127 		}
128 #endif
129 		printf("consinit: Unable to init console on keyboard and ");
130 		printf("TURBOchannel slot 0x%lx.\n", ctb->ctb_turboslot);
131 		printf("Using serial console.\n");
132 		/* FALLTHROUGH */
133 
134 	case CTB_PRINTERPORT:
135 		/* serial console ... */
136 		/*
137 		 * XXX This could stand some cleanup...
138 		 */
139 		{
140 			/*
141 			 * Delay to allow PROM putchars to complete.
142 			 * FIFO depth * character time,
143 			 * character time = (1000000 / (defaultrate / 10))
144 			 */
145 			DELAY(160000000 / 9600);	/* XXX */
146 
147 			/*
148 			 * Console is channel B of the second SCC.
149 			 * XXX Should use ctb_line_off to get the
150 			 * XXX line parameters--these are the defaults.
151 			 */
152 			zs_ioasic_cnattach(0x1e0000000, 0x00180000, 1);
153 			break;
154 		}
155 
156 	default:
157 		printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
158 		printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
159 		panic("consinit: unknown console type %lu",
160 		    ctb->ctb_term_type);
161 		/* NOTREACHED */
162 	}
163 }
164 
165 static void
dec_3000_500_device_register(device_t dev,void * aux)166 dec_3000_500_device_register(device_t dev, void *aux)
167 {
168 	static int found, initted, scsiboot, netboot;
169 	static device_t scsidev;
170 	static device_t tcdsdev;
171 	struct bootdev_data *b = bootdev_data;
172 	device_t parent = device_parent(dev);
173 
174 	if (b == NULL || found)
175 		return;
176 
177 	if (!initted) {
178 		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
179 		netboot = (strcmp(b->protocol, "BOOTP") == 0) ||
180 		    (strcmp(b->protocol, "MOP") == 0);
181 #if 0
182 		printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot);
183 #endif
184 		initted = 1;
185 	}
186 
187 	/*
188 	 * for scsi boot, we look for "tcds", make sure it has the
189 	 * right slot number, then find the "asc" on this tcds that
190 	 * as the right channel.  then we find the actual scsi
191 	 * device we came from.  note: no SCSI LUN support (yet).
192 	 */
193 	if (scsiboot && device_is_a(dev, "tcds")) {
194 		struct tc_attach_args *tcargs = aux;
195 
196 		if (b->slot != tcargs->ta_slot)
197 			return;
198 
199 		tcdsdev = dev;
200 #if 0
201 		printf("\ntcdsdev = %s\n", device_xname(dev));
202 #endif
203 	}
204 	if (scsiboot && tcdsdev &&
205 	    device_is_a(dev, "asc")) {
206 		struct tcdsdev_attach_args *ta = aux;
207 
208 		if (parent != tcdsdev)
209 			return;
210 
211 		if (ta->tcdsda_chip != b->channel)
212 			return;
213 
214 		scsidev = dev;
215 #if 0
216 		printf("\nscsidev = %s\n", device_xname(dev));
217 #endif
218 	}
219 
220 	if (scsiboot && scsidev &&
221 	    (device_is_a(dev, "sd") ||
222 	     device_is_a(dev, "st") ||
223 	     device_is_a(dev, "cd"))) {
224 		struct scsipibus_attach_args *sa = aux;
225 
226 		if (device_parent(parent) != scsidev)
227 			return;
228 
229 		if (b->unit / 100 != sa->sa_periph->periph_target)
230 			return;
231 
232 		/* XXX LUN! */
233 
234 		switch (b->boot_dev_type) {
235 		case 0:
236 			if (!device_is_a(dev, "sd") &&
237 			    !device_is_a(dev, "cd"))
238 				return;
239 			break;
240 		case 1:
241 			if (!device_is_a(dev, "st"))
242 				return;
243 			break;
244 		default:
245 			return;
246 		}
247 
248 		/* we've found it! */
249 		booted_device = dev;
250 #if 0
251 		printf("\nbooted_device = %s\n", device_xname(booted_device));
252 #endif
253 		found = 1;
254 	}
255 
256 	if (netboot) {
257 	        if (b->slot == 7 && device_is_a(dev, "le") &&
258 		    device_is_a(parent, "ioasic")) {
259 			/*
260 			 * no need to check ioasic_attach_args, since only
261 			 * one le on ioasic.
262 			 */
263 
264 			booted_device = dev;
265 #if 0
266 			printf("\nbooted_device = %s\n", device_xname(booted_device));
267 #endif
268 			found = 1;
269 			return;
270 		}
271 
272 		/*
273 		 * XXX GENERIC SUPPORT FOR TC NETWORK BOARDS
274 		 */
275 	}
276 }
277