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