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