1 /* $NetBSD: dec_550.c,v 1.38 2024/03/31 19:06:30 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996, 1997 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 "opt_kgdb.h"
34
35 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
36
37 __KERNEL_RCSID(0, "$NetBSD: dec_550.c,v 1.38 2024/03/31 19:06:30 thorpej Exp $");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/termios.h>
43 #include <sys/conf.h>
44 #include <dev/cons.h>
45
46 #include <uvm/uvm_extern.h>
47
48 #include <machine/rpb.h>
49 #include <machine/autoconf.h>
50 #include <machine/cpuconf.h>
51 #include <sys/bus.h>
52
53 #include <dev/ic/comreg.h>
54 #include <dev/ic/comvar.h>
55
56 #include <dev/isa/isareg.h>
57 #include <dev/isa/isavar.h>
58 #include <dev/ic/i8042reg.h>
59 #include <dev/ic/pckbcvar.h>
60 #include <dev/pci/pcireg.h>
61 #include <dev/pci/pcivar.h>
62
63 #include <alpha/pci/ciareg.h>
64 #include <alpha/pci/ciavar.h>
65
66 #include <dev/scsipi/scsi_all.h>
67 #include <dev/scsipi/scsipi_all.h>
68 #include <dev/scsipi/scsiconf.h>
69 #include <dev/ata/atavar.h>
70
71 /* Write this to Pyxis General Purpose Output to turn off the power. */
72 #define DEC_550_PYXIS_GPO_POWERDOWN 0x00000400
73
74 #include "pckbd.h"
75
76 #ifndef CONSPEED
77 #define CONSPEED TTYDEF_SPEED
78 #endif
79 static int comcnrate = CONSPEED;
80
81 #define DR_VERBOSE(f) while (0)
82
83 void dec_550_init(void);
84 static void dec_550_cons_init(void);
85 static void dec_550_device_register(device_t, void *);
86 static void dec_550_powerdown(void);
87
88 #ifdef KGDB
89 #include <machine/db_machdep.h>
90
91 static const char *kgdb_devlist[] = {
92 "com",
93 NULL,
94 };
95 #endif /* KGDB */
96
97 void
dec_550_init(void)98 dec_550_init(void)
99 {
100
101 platform.family = "Digital Personal Workstation";
102
103 if ((platform.model = alpha_dsr_sysname()) == NULL) {
104 /* XXX Don't know the system variations, yet. */
105 platform.model = alpha_unknown_sysname();
106 }
107
108 platform.iobus = "cia";
109 platform.cons_init = dec_550_cons_init;
110 platform.device_register = dec_550_device_register;
111 platform.powerdown = dec_550_powerdown;
112
113 /*
114 * If Miata systems have a secondary cache, it's 2MB.
115 */
116 uvmexp.ncolors = atop(2 * 1024 * 1024);
117 }
118
119 static void
dec_550_cons_init(void)120 dec_550_cons_init(void)
121 {
122 struct ctb *ctb;
123 struct cia_config *ccp;
124 extern struct cia_config cia_configuration;
125
126 ccp = &cia_configuration;
127 cia_init(ccp);
128
129 ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
130
131 switch (ctb->ctb_term_type) {
132 case CTB_PRINTERPORT:
133 /* serial console ... */
134 /* XXX */
135 {
136 /*
137 * Delay to allow PROM putchars to complete.
138 * FIFO depth * character time,
139 * character time = (1000000 / (defaultrate / 10))
140 */
141 DELAY(160000000 / comcnrate);
142
143 if(comcnattach(&ccp->cc_iot, 0x3f8, comcnrate,
144 COM_FREQ, COM_TYPE_NORMAL,
145 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
146 panic("can't init serial console");
147
148 break;
149 }
150
151 case CTB_GRAPHICS:
152 #if NPCKBD > 0
153 /* display console ... */
154 /* XXX */
155 (void) pckbc_cnattach(&ccp->cc_iot, IO_KBD, KBCMDP,
156 PCKBC_KBD_SLOT, 0);
157
158 if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
159 CTB_TURBOSLOT_TYPE_ISA)
160 isa_display_console(&ccp->cc_iot, &ccp->cc_memt);
161 else
162 pci_display_console(&ccp->cc_iot, &ccp->cc_memt,
163 &ccp->cc_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
164 CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
165 #else
166 panic("not configured to use display && keyboard console");
167 #endif
168 break;
169
170 default:
171 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
172 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
173
174 panic("consinit: unknown console type %ld",
175 ctb->ctb_term_type);
176 }
177 #ifdef KGDB
178 /* Attach the KGDB device. */
179 alpha_kgdb_init(kgdb_devlist, &ccp->cc_iot);
180 #endif /* KGDB */
181 }
182
183 static void
dec_550_device_register(device_t dev,void * aux)184 dec_550_device_register(device_t dev, void *aux)
185 {
186 static int found, initted, diskboot, netboot;
187 static device_t pcidev, ctrlrdev;
188 struct bootdev_data *b = bootdev_data;
189 device_t parent = device_parent(dev);
190
191 if (b == NULL || found)
192 return;
193
194 if (!initted) {
195 diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
196 (strcasecmp(b->protocol, "IDE") == 0);
197 netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
198 (strcasecmp(b->protocol, "MOP") == 0);
199 DR_VERBOSE(printf("diskboot = %d, netboot = %d\n", diskboot,
200 netboot));
201 initted = 1;
202 }
203
204 if (pcidev == NULL) {
205 if (!device_is_a(dev, "pci"))
206 return;
207 else {
208 struct pcibus_attach_args *pba = aux;
209
210 if ((b->slot / 1000) != pba->pba_bus)
211 return;
212
213 pcidev = dev;
214 DR_VERBOSE(printf("\npcidev = %s\n", device_xname(dev)));
215 return;
216 }
217 }
218
219 if (ctrlrdev == NULL) {
220 if (parent != pcidev)
221 return;
222 else {
223 struct pci_attach_args *pa = aux;
224 int slot;
225
226 slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
227 pa->pa_device;
228 if (b->slot != slot)
229 return;
230
231 if (netboot) {
232 booted_device = dev;
233 DR_VERBOSE(printf("\nbooted_device = %s\n",
234 device_xname(dev)));
235 found = 1;
236 } else {
237 ctrlrdev = dev;
238 DR_VERBOSE(printf("\nctrlrdev = %s\n",
239 device_xname(dev)));
240 }
241 return;
242 }
243 }
244
245 if (!diskboot)
246 return;
247
248 if (device_is_a(dev, "sd") ||
249 device_is_a(dev, "st") ||
250 device_is_a(dev, "cd")) {
251 struct scsipibus_attach_args *sa = aux;
252 struct scsipi_periph *periph = sa->sa_periph;
253 int unit;
254
255 if (device_parent(parent) != ctrlrdev)
256 return;
257
258 unit = periph->periph_target * 100 + periph->periph_lun;
259 if (b->unit != unit)
260 return;
261 if (b->channel != periph->periph_channel->chan_channel)
262 return;
263
264 /* we've found it! */
265 booted_device = dev;
266 DR_VERBOSE(printf("\nbooted_device = %s\n", device_xname(dev)));
267 found = 1;
268 }
269
270 /*
271 * Support to boot from IDE drives.
272 */
273 if (device_is_a(dev, "wd")) {
274 struct ata_device *adev = aux;
275
276 if (!device_is_a(parent, "atabus"))
277 return;
278 if (device_parent(parent) != ctrlrdev)
279 return;
280
281 DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
282 adev->adev_drv_data->drive, adev->adev_channel));
283 DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
284 b->unit, b->channel));
285 if (b->unit != adev->adev_drv_data->drive ||
286 b->channel != adev->adev_channel)
287 return;
288
289 /* we've found it! */
290 booted_device = dev;
291 DR_VERBOSE(printf("booted_device = %s\n", device_xname(dev)));
292 found = 1;
293 }
294 }
295
296 static void
dec_550_powerdown(void)297 dec_550_powerdown(void)
298 {
299
300 REGVAL(PYXIS_GPO) = DEC_550_PYXIS_GPO_POWERDOWN;
301 alpha_mb();
302 }
303