1 /* $NetBSD: dec_2100_a500.c,v 1.26 2024/03/31 19:06:30 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1999 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
34 * All rights reserved.
35 *
36 * Author: Chris G. Demetriou
37 *
38 * Permission to use, copy, modify and distribute this software and
39 * its documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
43 *
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
46 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie the
56 * rights to redistribute these changes.
57 */
58
59 #include "opt_kgdb.h"
60
61 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
62
63 __KERNEL_RCSID(0, "$NetBSD: dec_2100_a500.c,v 1.26 2024/03/31 19:06:30 thorpej Exp $");
64
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/device.h>
68 #include <sys/lwp.h>
69 #include <sys/termios.h>
70
71 #include <sys/conf.h>
72 #include <dev/cons.h>
73
74 #include <machine/rpb.h>
75 #include <machine/autoconf.h>
76 #include <machine/cpuconf.h>
77 #include <sys/bus.h>
78 #include <machine/alpha.h>
79
80 #include <dev/ic/comreg.h>
81 #include <dev/ic/comvar.h>
82
83 #include <dev/isa/isareg.h>
84 #include <dev/isa/isavar.h>
85 #include <dev/ic/i8042reg.h>
86 #include <dev/ic/pckbcvar.h>
87 #include <dev/pci/pcireg.h>
88 #include <dev/pci/pcivar.h>
89
90 #include <alpha/pci/ttwogareg.h>
91 #include <alpha/pci/ttwogavar.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 <dev/ic/mlxio.h>
98 #include <dev/ic/mlxvar.h>
99
100 #include "pckbd.h"
101
102 #ifndef CONSPEED
103 #define CONSPEED TTYDEF_SPEED
104 #endif
105 static int comcnrate = CONSPEED;
106
107 void _dec_2100_a500_init(void);
108 static void dec_2100_a500_cons_init(void);
109 static void dec_2100_a500_device_register(device_t, void *);
110 static void dec_2100_a500_machine_check(unsigned long, struct trapframe *,
111 unsigned long, unsigned long);
112
113 #ifdef KGDB
114 #include <machine/db_machdep.h>
115
116 static const char *kgdb_devlist[] = {
117 "com",
118 NULL,
119 };
120 #endif /* KGDB */
121
122 void
_dec_2100_a500_init(void)123 _dec_2100_a500_init(void)
124 {
125
126 switch (cputype) {
127 case ST_DEC_2100_A500:
128 if (alpha_implver() == ALPHA_IMPLVER_EV5)
129 platform.family = "AlphaServer 2100 (\"Sable-Gamma\")";
130 else
131 platform.family = "AlphaServer 2100 (\"Sable\")";
132 break;
133
134 case ST_DEC_2100A_A500:
135 platform.family = "AlphaServer 2100A (\"Lynx\")";
136 break;
137
138 default:
139 panic("dec_2100_a500_init: Not a Sable, Sable-Gamma, or Lynx?");
140 }
141
142 if ((platform.model = alpha_dsr_sysname()) == NULL) {
143 /* XXX don't know variations yet */
144 platform.model = alpha_unknown_sysname();
145 }
146
147 platform.iobus = "ttwoga";
148 platform.cons_init = dec_2100_a500_cons_init;
149 platform.device_register = dec_2100_a500_device_register;
150 platform.mcheck_handler = dec_2100_a500_machine_check;
151 }
152
153 static void
dec_2100_a500_cons_init(void)154 dec_2100_a500_cons_init(void)
155 {
156 struct ctb *ctb;
157 uint64_t ctbslot;
158 struct ttwoga_config *tcp;
159
160 ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
161 ctbslot = ctb->ctb_turboslot;
162
163 tcp = ttwoga_init(0);
164
165 switch (ctb->ctb_term_type) {
166 case CTB_PRINTERPORT:
167 /* serial console ... */
168 assert(CTB_TURBOSLOT_HOSE(ctbslot) == 0);
169 /* XXX */
170 {
171 /*
172 * Delay to allow PROM putchars to complete.
173 * FIFO depth * character time,
174 * character time = (1000000 / (defaultrate / 10))
175 */
176 DELAY(160000000 / comcnrate);
177
178 if(comcnattach(&tcp->tc_iot, 0x3f8, comcnrate,
179 COM_FREQ, COM_TYPE_NORMAL,
180 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
181 panic("can't init serial console");
182
183 break;
184 }
185
186 case CTB_GRAPHICS:
187 #if NPCKBD > 0
188 /* display console ... */
189 /* XXX */
190 (void) pckbc_cnattach(&tcp->tc_iot, IO_KBD, KBCMDP,
191 PCKBC_KBD_SLOT, 0);
192
193 switch (CTB_TURBOSLOT_TYPE(ctbslot)) {
194 case CTB_TURBOSLOT_TYPE_ISA:
195 /*
196 * XXX The following is apparently necessary for an
197 * XXX ISA VGA card, but what happens with real EISA
198 * XXX VGA cards?
199 */
200 case CTB_TURBOSLOT_TYPE_EISA:
201 isa_display_console(&tcp->tc_iot, &tcp->tc_memt);
202 break;
203
204 case CTB_TURBOSLOT_TYPE_PCI:
205 /* The display PCI might be different */
206 tcp = ttwoga_init(CTB_TURBOSLOT_HOSE(ctbslot));
207 pci_display_console(&tcp->tc_iot, &tcp->tc_memt,
208 &tcp->tc_pc, CTB_TURBOSLOT_BUS(ctbslot),
209 CTB_TURBOSLOT_SLOT(ctbslot), 0);
210 break;
211
212 default:
213 printf("type = 0x%lx, hose = 0x%lx, bus = 0x%lx, "
214 "slot = 0x%lx\n",
215 CTB_TURBOSLOT_TYPE(ctbslot),
216 CTB_TURBOSLOT_HOSE(ctbslot),
217 CTB_TURBOSLOT_BUS(ctbslot),
218 CTB_TURBOSLOT_SLOT(ctbslot));
219 panic("unknown display console type");
220 }
221 #else
222 panic("not configured to use display && keyboard console");
223 #endif
224 break;
225
226 default:
227 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
228 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
229
230 panic("consinit: unknown console type %ld",
231 ctb->ctb_term_type);
232 }
233 #ifdef KGDB
234 /* Attach the KGDB device. */
235 alpha_kgdb_init(kgdb_devlist, &tcp->tc_iot);
236 #endif /* KGDB */
237 }
238
239 static void
dec_2100_a500_device_register(device_t dev,void * aux)240 dec_2100_a500_device_register(device_t dev, void *aux)
241 {
242 static int found, initted, diskboot, netboot;
243 static device_t pcidev, ctrlrdev;
244 struct bootdev_data *b = bootdev_data;
245 device_t parent = device_parent(dev);
246
247 if (b == NULL || found)
248 return;
249
250 if (!initted) {
251 diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
252 (strcasecmp(b->protocol, "RAID") == 0);
253 netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
254 (strcasecmp(b->protocol, "MOP") == 0);
255 #if 0
256 printf("diskboot = %d, netboot = %d\n", diskboot, netboot);
257 #endif
258 initted =1;
259 }
260
261 if (pcidev == NULL) {
262 if (!device_is_a(dev, "pci"))
263 return;
264 else {
265 struct pcibus_attach_args *pba = aux;
266
267 if ((b->slot / 1000) != pba->pba_bus)
268 return;
269
270 pcidev = dev;
271 #if 0
272 printf("\npcidev = %s\n", device_xname(dev));
273 #endif
274 return;
275 }
276 }
277
278 if (ctrlrdev == NULL) {
279 if (parent != pcidev)
280 return;
281 else {
282 struct pci_attach_args *pa = aux;
283 int slot;
284
285 slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
286 pa->pa_device;
287 if (b->slot != slot)
288 return;
289
290 if (netboot) {
291 booted_device = dev;
292 #if 0
293 printf("\nbooted_device = %s\n", device_xname(dev));
294 #endif
295 found = 1;
296 } else {
297 ctrlrdev = dev;
298 #if 0
299 printf("\nctrlrdev = %s\n", device_xname(dev));
300 #endif
301 }
302 return;
303 }
304 }
305
306 if (!diskboot)
307 return;
308
309 if (device_is_a(dev, "sd") ||
310 device_is_a(dev, "st") ||
311 device_is_a(dev, "cd")) {
312 struct scsipibus_attach_args *sa = aux;
313 struct scsipi_periph *periph = sa->sa_periph;
314 int unit;
315
316 if (device_parent(parent) != ctrlrdev)
317 return;
318
319 unit = periph->periph_target * 100 + periph->periph_lun;
320 if (b->unit != unit)
321 return;
322 if (b->channel != periph->periph_channel->chan_channel)
323 return;
324
325 /* we've found it! */
326 booted_device = dev;
327 #if 0
328 printf("\nbooted_device = %s\n", device_xname(dev));
329 #endif
330 found = 1;
331 }
332
333 if (device_is_a(dev, "ld") && device_is_a(parent, "mlx")) {
334 /*
335 * Argh! The attach arguments for ld devices is not
336 * consistent, so each supported raid controller requires
337 * different checks.
338 */
339 struct mlx_attach_args *mlxa = aux;
340
341 if (parent != ctrlrdev)
342 return;
343
344 if (b->unit != mlxa->mlxa_unit)
345 return;
346 /* we've found it! */
347 booted_device = dev;
348 #if 0
349 printf("\nbooted_device = %s\n", device_xname(dev));
350 #endif
351 found = 1;
352 }
353 }
354
355 /*
356 * Sable, Sable-Gamma, and Lynx machine check handlers.
357 */
358
359 static void
dec_2100_a500_machine_check(unsigned long mces,struct trapframe * framep,unsigned long vector,unsigned long param)360 dec_2100_a500_machine_check(unsigned long mces, struct trapframe *framep,
361 unsigned long vector, unsigned long param)
362 {
363 struct mchkinfo *mcp = &curcpu()->ci_mcinfo;
364
365 /*
366 * This is a work-around for a T2 core logic bug. See
367 * alpha/pci/ttwoga_pci.c.
368 */
369
370 if (ttwoga_conf_cpu == cpu_number())
371 mcp->mc_expected = 1;
372
373 machine_check(mces, framep, vector, param);
374 }
375