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