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