1 /* $OpenBSD: dec_550.c,v 1.14 2014/05/08 20:46:49 miod Exp $ */
2 /* $NetBSD: dec_550.c,v 1.10 2000/06/20 03:48:53 matt Exp $ */
3
4 /*
5 * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
6 * All rights reserved.
7 *
8 * Author: Chris G. Demetriou
9 *
10 * Permission to use, copy, modify and distribute this software and
11 * its documentation is hereby granted, provided that both the copyright
12 * notice and this permission notice appear in all copies of the
13 * software, derivative works or modified versions, and any portions
14 * thereof, and that both notices appear in supporting documentation.
15 *
16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 *
20 * Carnegie Mellon requests users of this software to return to
21 *
22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
23 * School of Computer Science
24 * Carnegie Mellon University
25 * Pittsburgh PA 15213-3890
26 *
27 * any improvements or extensions that they make and grant Carnegie the
28 * rights to redistribute these changes.
29 */
30 /*
31 * Additional Copyright (c) 1997 by Matthew Jacob for NASA/Ames Research Center
32 */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 #include <sys/termios.h>
38 #include <dev/cons.h>
39 #include <sys/conf.h>
40
41 #include <machine/rpb.h>
42 #include <machine/autoconf.h>
43 #include <machine/cpuconf.h>
44 #include <machine/bus.h>
45
46 #include <dev/ic/comreg.h>
47 #include <dev/ic/comvar.h>
48
49 #include <dev/isa/isareg.h>
50 #include <dev/isa/isavar.h>
51 #include <dev/ic/i8042reg.h>
52
53 #include <dev/ic/pckbcvar.h>
54 #include <dev/pci/pcireg.h>
55 #include <dev/pci/pcivar.h>
56
57 #include <alpha/pci/ciareg.h>
58 #include <alpha/pci/ciavar.h>
59
60 #include <scsi/scsi_all.h>
61 #include <scsi/scsiconf.h>
62 #include <dev/ata/atavar.h>
63
64 /* Write this to Pyxis General Purpose Output to turn off the power. */
65 #define DEC_550_PYXIS_GPO_POWERDOWN 0x00000400
66
67 #include "pckbd.h"
68
69 #ifndef CONSPEED
70 #define CONSPEED TTYDEF_SPEED
71 #endif
72 static int comcnrate = CONSPEED;
73
74 #define DR_VERBOSE(f) while (0)
75
76 void dec_550_init(void);
77 static void dec_550_cons_init(void);
78 static void dec_550_device_register(struct device *, void *);
79 static void dec_550_powerdown(void);
80
81 void
dec_550_init()82 dec_550_init()
83 {
84
85 platform.family = "Digital Personal Workstation";
86
87 if ((platform.model = alpha_dsr_sysname()) == NULL) {
88 /* XXX Don't know the system variations, yet. */
89 platform.model = alpha_unknown_sysname();
90 }
91
92 platform.iobus = "cia";
93 platform.cons_init = dec_550_cons_init;
94 platform.device_register = dec_550_device_register;
95 platform.powerdown = dec_550_powerdown;
96 }
97
98 static void
dec_550_cons_init()99 dec_550_cons_init()
100 {
101 struct ctb *ctb;
102 struct cia_config *ccp;
103 extern struct cia_config cia_configuration;
104
105 ccp = &cia_configuration;
106 cia_init(ccp, 0);
107
108 ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
109
110 switch (ctb->ctb_term_type) {
111 case CTB_PRINTERPORT:
112 /* serial console ... */
113 /* XXX */
114 {
115 /*
116 * Delay to allow PROM putchars to complete.
117 * FIFO depth * character time,
118 * character time = (1000000 / (defaultrate / 10))
119 */
120 DELAY(160000000 / comcnrate);
121
122 if(comcnattach(&ccp->cc_iot, 0x3f8, comcnrate,
123 COM_FREQ,
124 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
125 panic("can't init serial console");
126
127 break;
128 }
129
130 case CTB_GRAPHICS:
131 #if NPCKBD > 0
132 /* display console ... */
133 /* XXX */
134 (void) pckbc_cnattach(&ccp->cc_iot, IO_KBD, KBCMDP, 0);
135
136 if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
137 CTB_TURBOSLOT_TYPE_ISA)
138 isa_display_console(&ccp->cc_iot, &ccp->cc_memt);
139 else
140 pci_display_console(&ccp->cc_iot, &ccp->cc_memt,
141 &ccp->cc_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
142 CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
143 #else
144 panic("not configured to use display && keyboard console");
145 #endif
146 break;
147
148 default:
149 printf("ctb->ctb_term_type = 0x%lx\n",
150 (unsigned long)ctb->ctb_term_type);
151 printf("ctb->ctb_turboslot = 0x%lx\n",
152 (unsigned long)ctb->ctb_turboslot);
153
154 panic("consinit: unknown console type %lu",
155 (unsigned long)ctb->ctb_term_type);
156 }
157 }
158
159 static void
dec_550_device_register(dev,aux)160 dec_550_device_register(dev, aux)
161 struct device *dev;
162 void *aux;
163 {
164 static int found, initted, diskboot, netboot;
165 static struct device *pcidev, *ctrlrdev;
166 struct bootdev_data *b = bootdev_data;
167 struct device *parent = dev->dv_parent;
168 struct cfdata *cf = dev->dv_cfdata;
169 struct cfdriver *cd = cf->cf_driver;
170
171 if (found)
172 return;
173
174 if (!initted) {
175 diskboot = (strncasecmp(b->protocol, "SCSI", 4) == 0) ||
176 (strncasecmp(b->protocol, "IDE", 3) == 0);
177 netboot = (strncasecmp(b->protocol, "BOOTP", 5) == 0) ||
178 (strncasecmp(b->protocol, "MOP", 3) == 0);
179 DR_VERBOSE(printf("diskboot = %d, netboot = %d\n", diskboot,
180 netboot));
181 initted = 1;
182 }
183
184 if (pcidev == NULL) {
185 if (strcmp(cd->cd_name, "pci"))
186 return;
187 else {
188 struct pcibus_attach_args *pba = aux;
189
190 if ((b->slot / 1000) != pba->pba_bus)
191 return;
192
193 pcidev = dev;
194 DR_VERBOSE(printf("\npcidev = %s\n", pcidev->dv_xname));
195 return;
196 }
197 }
198
199 if (ctrlrdev == NULL) {
200 if (parent != pcidev)
201 return;
202 else {
203 struct pci_attach_args *pa = aux;
204 int slot;
205
206 slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
207 pa->pa_device;
208 if (b->slot != slot)
209 return;
210
211 if (netboot) {
212 booted_device = dev;
213 DR_VERBOSE(printf("\nbooted_device = %s\n",
214 dev->dv_xname));
215 found = 1;
216 } else {
217 ctrlrdev = dev;
218 DR_VERBOSE(printf("\nctrlrdev = %s\n",
219 dev->dv_xname));
220 }
221 return;
222 }
223 }
224
225 if (!diskboot)
226 return;
227
228 if (!strcmp(cd->cd_name, "sd") || !strcmp(cd->cd_name, "st") ||
229 !strcmp(cd->cd_name, "cd")) {
230 struct scsi_attach_args *sa = aux;
231 struct scsi_link *periph = sa->sa_sc_link;
232 int unit;
233
234 if (parent->dv_parent != ctrlrdev)
235 return;
236
237 unit = periph->target * 100 + periph->lun;
238 if (b->unit != unit)
239 return;
240
241 /* we've found it! */
242 booted_device = dev;
243 DR_VERBOSE(printf("\nbooted_device = %s\n", dev->dv_xname));
244 found = 1;
245 }
246
247 /*
248 * Support to boot from IDE drives.
249 */
250 if (!strcmp(cd->cd_name, "wd")) {
251 struct ata_atapi_attach *aa_link = aux;
252
253 if ((strcmp("pciide", parent->dv_cfdata->cf_driver->cd_name) != 0))
254 return;
255 if (parent != ctrlrdev)
256 return;
257
258 DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
259 aa_link->aa_drv_data->drive, aa_link->aa_channel));
260 DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
261 b->unit, b->channel));
262 if (b->unit != aa_link->aa_drv_data->drive ||
263 b->channel != aa_link->aa_channel)
264 return;
265
266 /* we've found it! */
267 booted_device = dev;
268 DR_VERBOSE(printf("booted_device = %s\n", dev->dv_xname));
269 found = 1;
270 }
271 }
272
273 static void
dec_550_powerdown()274 dec_550_powerdown()
275 {
276
277 REGVAL(PYXIS_GPO) = DEC_550_PYXIS_GPO_POWERDOWN;
278 alpha_mb();
279 }
280