1 /* $NetBSD: dec_eb64plus.c,v 1.43 2024/03/31 19:06:31 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_eb64plus.c,v 1.43 2024/03/31 19:06:31 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/alpha.h>
50 #include <machine/autoconf.h>
51 #include <machine/cpuconf.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/apecsreg.h>
64 #include <alpha/pci/apecsvar.h>
65
66 #include <dev/scsipi/scsi_all.h>
67 #include <dev/scsipi/scsipi_all.h>
68 #include <dev/scsipi/scsiconf.h>
69
70 #include "pckbd.h"
71
72 #ifndef CONSPEED
73 #define CONSPEED TTYDEF_SPEED
74 #endif
75 static int comcnrate = CONSPEED;
76
77 void dec_eb64plus_init(void);
78 static void dec_eb64plus_cons_init(void);
79 static void dec_eb64plus_device_register(device_t, void *);
80
81 #ifdef KGDB
82 #include <machine/db_machdep.h>
83
84 static const char *kgdb_devlist[] = {
85 "com",
86 NULL,
87 };
88 #endif /* KGDB */
89
90 const struct alpha_variation_table dec_eb64plus_variations[] = {
91 { 0, "DEC EB64+" },
92 { 0, NULL },
93 };
94
95 void
dec_eb64plus_init(void)96 dec_eb64plus_init(void)
97 {
98 uint64_t variation;
99
100 platform.family = "EB64+";
101
102 if ((platform.model = alpha_dsr_sysname()) == NULL) {
103 variation = hwrpb->rpb_variation & SV_ST_MASK;
104 if ((platform.model = alpha_variation_name(variation,
105 dec_eb64plus_variations)) == NULL)
106 platform.model = alpha_unknown_sysname();
107 }
108
109 platform.iobus = "apecs";
110 platform.cons_init = dec_eb64plus_cons_init;
111 platform.device_register = dec_eb64plus_device_register;
112
113 /*
114 * EB64+ systems can have 512K, 1M, or 2M secondary
115 * caches. Default to middle-of-the-road.
116 *
117 * XXX Need to dynamically size it!
118 */
119 uvmexp.ncolors = atop(1 * 1024 * 1024);
120 }
121
122 static void
dec_eb64plus_cons_init(void)123 dec_eb64plus_cons_init(void)
124 {
125 struct ctb *ctb;
126 struct apecs_config *acp;
127 extern struct apecs_config apecs_configuration;
128
129 acp = &apecs_configuration;
130 apecs_init(acp);
131
132 ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
133
134 switch (ctb->ctb_term_type) {
135 case CTB_PRINTERPORT:
136 /* serial console ... */
137 /* XXX */
138 {
139 /*
140 * Delay to allow PROM putchars to complete.
141 * FIFO depth * character time,
142 * character time = (1000000 / (defaultrate / 10))
143 */
144 DELAY(160000000 / comcnrate);
145
146 if(comcnattach(&acp->ac_iot, 0x3f8, comcnrate,
147 COM_FREQ, COM_TYPE_NORMAL,
148 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
149 panic("can't init serial console");
150
151 break;
152 }
153
154 case CTB_GRAPHICS:
155 #if NPCKBD > 0
156 /* display console ... */
157 /* XXX */
158 (void) pckbc_cnattach(&acp->ac_iot, IO_KBD, KBCMDP,
159 PCKBC_KBD_SLOT, 0);
160
161 if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
162 CTB_TURBOSLOT_TYPE_ISA)
163 isa_display_console(&acp->ac_iot, &acp->ac_memt);
164 else
165 pci_display_console(&acp->ac_iot, &acp->ac_memt,
166 &acp->ac_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
167 CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
168 #else
169 panic("not configured to use display && keyboard console");
170 #endif
171 break;
172
173 default:
174 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
175 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
176
177 panic("consinit: unknown console type %ld",
178 ctb->ctb_term_type);
179 }
180 #ifdef KGDB
181 /* Attach the KGDB device. */
182 alpha_kgdb_init(kgdb_devlist, &acp->ac_iot);
183 #endif /* KGDB */
184 }
185
186 static void
dec_eb64plus_device_register(device_t dev,void * aux)187 dec_eb64plus_device_register(device_t dev, void *aux)
188 {
189 static int found, initted, diskboot, netboot;
190 static device_t pcidev, ctrlrdev;
191 struct bootdev_data *b = bootdev_data;
192 device_t parent = device_parent(dev);
193
194 if (b == NULL || found)
195 return;
196
197 if (!initted) {
198 diskboot = (strcasecmp(b->protocol, "SCSI") == 0);
199 netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
200 (strcasecmp(b->protocol, "MOP") == 0);
201 #if 0
202 printf("diskboot = %d, netboot = %d\n", diskboot, netboot);
203 #endif
204 initted =1;
205 }
206
207 if (pcidev == NULL) {
208 if (!device_is_a(dev, "pci"))
209 return;
210 else {
211 struct pcibus_attach_args *pba = aux;
212
213 if ((b->slot / 1000) != pba->pba_bus)
214 return;
215
216 pcidev = dev;
217 #if 0
218 printf("\npcidev = %s\n", device_xname(dev));
219 #endif
220 return;
221 }
222 }
223
224 if (ctrlrdev == NULL) {
225 if (parent != pcidev)
226 return;
227 else {
228 struct pci_attach_args *pa = aux;
229 int slot;
230
231 slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
232 pa->pa_device;
233 if (b->slot != slot)
234 return;
235
236 if (netboot) {
237 booted_device = dev;
238 #if 0
239 printf("\nbooted_device = %s\n", device_xname(dev));
240 #endif
241 found = 1;
242 } else {
243 ctrlrdev = dev;
244 #if 0
245 printf("\nctrlrdev = %s\n", device_xname(dev));
246 #endif
247 }
248 return;
249 }
250 }
251
252 if (!diskboot)
253 return;
254
255 if (device_is_a(dev, "sd") ||
256 device_is_a(dev, "st") ||
257 device_is_a(dev, "cd")) {
258 struct scsipibus_attach_args *sa = aux;
259 struct scsipi_periph *periph = sa->sa_periph;
260 int unit;
261
262 if (device_parent(parent) != ctrlrdev)
263 return;
264
265 unit = periph->periph_target * 100 + periph->periph_lun;
266 if (b->unit != unit)
267 return;
268 if (b->channel != periph->periph_channel->chan_channel)
269 return;
270
271 /* we've found it! */
272 booted_device = dev;
273 #if 0
274 printf("\nbooted_device = %s\n", device_xname(dev));
275 #endif
276 found = 1;
277 }
278 }
279