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