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