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