xref: /openbsd/sys/arch/alpha/alpha/dec_1000a.c (revision f4c36297)
1 /* $OpenBSD: dec_1000a.c,v 1.9 2017/04/30 13:04:49 mpi Exp $ */
2 /* $NetBSD: dec_1000a.c,v 1.14 2001/06/05 04:53:11 thorpej Exp $ */
3 
4 /*
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is based on dec_kn20aa.c, written by Chris G. Demetriou at
9  * Carnegie-Mellon University. Platform support for Noritake, Pintake, and
10  * Corelle by Ross Harvey with copyright assignment by permission of Avalon
11  * Computer Systems, Inc.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*
36  * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
37  * All rights reserved.
38  *
39  * Author: Chris G. Demetriou
40  *
41  * Permission to use, copy, modify and distribute this software and
42  * its documentation is hereby granted, provided that both the copyright
43  * notice and this permission notice appear in all copies of the
44  * software, derivative works or modified versions, and any portions
45  * thereof, and that both notices appear in supporting documentation.
46  *
47  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
48  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
49  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
50  *
51  * Carnegie Mellon requests users of this software to return to
52  *
53  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
54  *  School of Computer Science
55  *  Carnegie Mellon University
56  *  Pittsburgh PA 15213-3890
57  *
58  * any improvements or extensions that they make and grant Carnegie the
59  * rights to redistribute these changes.
60  */
61 /*
62  * Additional Copyright (c) 1997 by Matthew Jacob for NASA/Ames Research Center
63  */
64 
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/device.h>
68 #include <sys/termios.h>
69 #include <dev/cons.h>
70 
71 #include <machine/rpb.h>
72 #include <machine/autoconf.h>
73 #include <machine/cpuconf.h>
74 #include <machine/conf.h>
75 #include <machine/bus.h>
76 
77 #include <dev/ic/comreg.h>
78 #include <dev/ic/comvar.h>
79 
80 #include <dev/isa/isareg.h>
81 #include <dev/isa/isavar.h>
82 #include <dev/ic/i8042reg.h>
83 #include <dev/ic/pckbcvar.h>
84 #include <dev/pci/pcireg.h>
85 #include <dev/pci/pcivar.h>
86 
87 #include <alpha/pci/apecsreg.h>
88 #include <alpha/pci/apecsvar.h>
89 #include <alpha/pci/ciareg.h>
90 #include <alpha/pci/ciavar.h>
91 
92 #include <scsi/scsi_all.h>
93 #include <scsi/scsiconf.h>
94 
95 #include "pckbd.h"
96 
97 #ifndef CONSPEED
98 #define CONSPEED TTYDEF_SPEED
99 #endif
100 static int comcnrate = CONSPEED;
101 
102 void _dec_1000a_init(void);
103 void dec_1000a_cons_init(void);
104 void dec_1000a_device_register(struct device *, void *);
105 
106 const struct alpha_variation_table dec_1000_variations[] = {
107 	{ 0, "AlphaServer 1000" },
108 	{ 0, NULL },
109 };
110 
111 const struct alpha_variation_table dec_1000a_variations[] = {
112 	{ 0, "AlphaServer 1000A" },
113 	{ 0, NULL },
114 };
115 
116 void
_dec_1000a_init()117 _dec_1000a_init()
118 {
119 	u_int64_t variation;
120 
121 	platform.family = "AlphaServer 1000/1000A";
122 
123 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
124 		variation = hwrpb->rpb_variation & SV_ST_MASK;
125 		if ((platform.model = alpha_variation_name(variation,
126 		    cputype == ST_DEC_1000 ? dec_1000_variations
127 					   : dec_1000a_variations)) == NULL)
128 			platform.model = alpha_unknown_sysname();
129 	}
130 
131 	switch(PCS_CPU_MAJORTYPE(LOCATE_PCS(hwrpb, 0))) {
132 	    case PCS_PROC_EV4:
133 	    case PCS_PROC_EV45:
134 		platform.iobus = "apecs";
135 		break;
136 	    default:
137 		platform.iobus = "cia";
138 		break;
139 	}
140 	platform.cons_init = dec_1000a_cons_init;
141 	platform.device_register = dec_1000a_device_register;
142 }
143 
144 void
dec_1000a_cons_init()145 dec_1000a_cons_init()
146 {
147 	struct ctb *ctb;
148 	struct cia_config *ccp;
149 	struct apecs_config *acp;
150 	extern struct cia_config cia_configuration;
151 	extern struct apecs_config apecs_configuration;
152 	bus_space_tag_t iot, memt;
153 	struct alpha_pci_chipset *pcichipset;
154 
155 	if(strcmp(platform.iobus, "cia") == 0) {
156 		ccp = &cia_configuration;
157 		cia_init(ccp, 0);
158 		iot = &ccp->cc_iot;
159 		memt = &ccp->cc_memt;
160 		pcichipset = &ccp->cc_pc;
161 	} else {
162 		acp = &apecs_configuration;
163 		apecs_init(acp, 0);
164 		iot = &acp->ac_iot;
165 		memt = &acp->ac_memt;
166 		pcichipset = &acp->ac_pc;
167 	}
168 
169 	ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
170 
171 	switch (ctb->ctb_term_type) {
172 	case CTB_PRINTERPORT:
173 		/* serial console ... */
174 		/* XXX */
175 		{
176 			/*
177 			 * Delay to allow PROM putchars to complete.
178 			 * FIFO depth * character time,
179 			 * character time = (1000000 / (defaultrate / 10))
180 			 */
181 			DELAY(160000000 / comcnrate);
182 
183 			if(comcnattach(iot, 0x3f8, comcnrate,
184 			    COM_FREQ,
185 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
186 				panic("can't init serial console");
187 
188 			break;
189 		}
190 
191 	case CTB_GRAPHICS:
192 #if NPCKBD > 0
193 		/* display console ... */
194 		/* XXX */
195 		(void) pckbc_cnattach(iot, IO_KBD, KBCMDP, 0);
196 
197 		/*
198 		 * AlphaServer 1000s have a firmware bug whereby the
199 		 * built-in ISA VGA is reported incorrectly -- ctb_turboslot
200 		 * is mostly 0.
201 		 */
202 		switch (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot)) {
203 		case CTB_TURBOSLOT_TYPE_PCI:
204 			pci_display_console(iot, memt, pcichipset,
205 			    CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
206 			    CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
207 			break;
208 
209 		default:
210 			isa_display_console(iot, memt);
211 			break;
212 		}
213 #else
214 		panic("not configured to use display && keyboard console");
215 #endif
216 		break;
217 
218 	default:
219 		printf("ctb->ctb_term_type = 0x%lx\n",
220 		    (unsigned long)ctb->ctb_term_type);
221 		printf("ctb->ctb_turboslot = 0x%lx\n",
222 		    (unsigned long)ctb->ctb_turboslot);
223 
224 		panic("consinit: unknown console type %lu",
225 		    (unsigned long)ctb->ctb_term_type);
226 	}
227 }
228 
229 void
dec_1000a_device_register(dev,aux)230 dec_1000a_device_register(dev, aux)
231 	struct device *dev;
232 	void *aux;
233 {
234 	static int found, initted, diskboot, netboot;
235 	static struct device *pcidev, *ctrlrdev;
236 	struct bootdev_data *b = bootdev_data;
237 	struct device *parent = dev->dv_parent;
238 	struct cfdata *cf = dev->dv_cfdata;
239 	struct cfdriver *cd = cf->cf_driver;
240 
241 	if (found)
242 		return;
243 
244 	if (!initted) {
245 		diskboot = (strncasecmp(b->protocol, "SCSI", 4) == 0);
246 		netboot = (strncasecmp(b->protocol, "BOOTP", 5) == 0) ||
247 		    (strncasecmp(b->protocol, "MOP", 3) == 0);
248 #if 0
249 		printf("diskboot = %d, netboot = %d\n", diskboot, netboot);
250 #endif
251 		initted =1;
252 	}
253 
254 	if (pcidev == NULL) {
255 		if (strcmp(cd->cd_name, "pci"))
256 			return;
257 		else {
258 			struct pcibus_attach_args *pba = aux;
259 
260 			if ((b->slot / 1000) != pba->pba_bus)
261 				return;
262 
263 			pcidev = dev;
264 #if 0
265 			printf("\npcidev = %s\n", dev->dv_xname);
266 #endif
267 			return;
268 		}
269 	}
270 
271 	if (ctrlrdev == NULL) {
272 		if (parent != pcidev)
273 			return;
274 		else {
275 			struct pci_attach_args *pa = aux;
276 			int slot;
277 
278 			slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
279 			    pa->pa_device;
280 			if (b->slot != slot)
281 				return;
282 
283 			if (netboot) {
284 				booted_device = dev;
285 #if 0
286 				printf("\nbooted_device = %s\n", dev->dv_xname);
287 #endif
288 				found = 1;
289 			} else {
290 				ctrlrdev = dev;
291 #if 0
292 				printf("\nctrlrdev = %s\n", dev->dv_xname);
293 #endif
294 			}
295 			return;
296 		}
297 	}
298 
299 	if (!diskboot)
300 		return;
301 
302 	if (!strcmp(cd->cd_name, "sd") || !strcmp(cd->cd_name, "st") ||
303 	    !strcmp(cd->cd_name, "cd")) {
304 		struct scsi_attach_args *sa = aux;
305 		struct scsi_link *periph = sa->sa_sc_link;
306 		int unit;
307 
308 		if (parent->dv_parent != ctrlrdev)
309 			return;
310 
311 		unit = periph->target * 100 + periph->lun;
312 		if (b->unit != unit)
313 			return;
314 
315 		/* we've found it! */
316 		booted_device = dev;
317 #if 0
318 		printf("\nbooted_device = %s\n", dev->dv_xname);
319 #endif
320 		found = 1;
321 	}
322 }
323