xref: /netbsd/sys/arch/sgimips/sgimips/console.c (revision 6550d01e)
1 /*	$NetBSD: console.c,v 1.40 2009/04/03 15:41:14 uebayasi Exp $	*/
2 
3 /*
4  * Copyright (c) 1994, 1995, 1996 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 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: console.c,v 1.40 2009/04/03 15:41:14 uebayasi Exp $");
32 
33 #include "opt_kgdb.h"
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/termios.h>
38 #include <sys/device.h>
39 
40 #include <machine/bus.h>
41 #include <machine/machtype.h>
42 
43 #include <dev/cons.h>
44 #include <dev/arcbios/arcbios.h>
45 #include <dev/arcbios/arcbiosvar.h>
46 #include <dev/ic/comreg.h>
47 #include <dev/ic/comvar.h>
48 #include <dev/ic/i8042reg.h>
49 #include <dev/ic/pckbcvar.h>
50 
51 #include <sgimips/gio/giovar.h>
52 #include <sgimips/hpc/hpcreg.h>
53 #include <sgimips/ioc/iocreg.h>
54 #include <sgimips/mace/macereg.h>
55 
56 #include "com.h"
57 #include "scn.h"
58 #include "zsc.h"
59 #include "gio.h"
60 #include "pckbc.h"
61 #include "zskbd.h"
62 #include "crmfb.h"
63 
64 #ifndef CONMODE
65 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
66 #endif
67 int comcnmode = CONMODE;
68 
69 extern struct consdev scn_cn;
70 extern struct consdev zs_cn;
71 
72 extern void	zs_kgdb_init(void);
73 extern void	zskbd_cnattach(int, int);
74 #if (NCRMFB > 0)
75 extern int	crmfb_probe(void);
76 #endif
77 
78 void		kgdb_port_init(void);
79 static int	scn_serial_init(const char *);
80 static int	zs_serial_init(const char *);
81 static int	gio_video_init(const char *);
82 static int	mace_serial_init(const char *);
83 
84 void
85 consinit(void)
86 {
87 	const char *consdev;
88 
89 	/* Ask ARCS what it is using for console output. */
90 	consdev = ARCBIOS->GetEnvironmentVariable("ConsoleOut");
91 
92 	if (consdev == NULL) {
93 		printf("WARNING: ConsoleOut environment variable not set\n");
94 		return;
95 	}
96 
97 	switch (mach_type) {
98 	case MACH_SGI_IP6 | MACH_SGI_IP10:
99 		if (scn_serial_init(consdev))
100 			return;
101 		break;
102 
103 	case MACH_SGI_IP12:
104 	case MACH_SGI_IP20:
105 	case MACH_SGI_IP22:
106 		if (gio_video_init(consdev) || zs_serial_init(consdev))
107 			return;
108 		break;
109 
110 	case MACH_SGI_IP32:
111 		if (mace_serial_init(consdev))
112 			return;
113 #if (NCRMFB > 0)
114 		if (crmfb_probe()) {
115 #if notyet
116 #if (NPCKBC > 0)
117 			/* XXX Hardcoded iotag, MACE address XXX */
118 			pckbc_cnattach(SGIMIPS_BUS_SPACE_NORMAL,
119 			    MACE_BASE + 0x320000, 8,
120 			    PCKBC_KBD_SLOT);
121 #endif
122 #endif
123 			return;
124 		}
125 #else
126 		panic("this ip32 kernel does not contain framebuffer support.");
127 #endif
128 		break;
129 
130 	default:
131 		panic("consinit(): unknown machine type IP%d\n", mach_type);
132 		break;
133 	}
134 
135 	printf("Using ARCS for console I/O.\n");
136 }
137 
138 static int
139 scn_serial_init(const char *consdev)
140 {
141 #if (NSCN > 0)
142 	if ((strlen(consdev) == 9) && (!strncmp(consdev, "serial", 6)) &&
143 	    (consdev[7] == '0' || consdev[7] == '1')) {
144 		cn_tab = &scn_cn;
145 		(*cn_tab->cn_init)(cn_tab);
146 
147 		return (1);
148 	}
149 #endif
150 
151 	return (0);
152 }
153 
154 static int
155 zs_serial_init(const char *consdev)
156 {
157 #if (NZSC > 0)
158 	if ((strlen(consdev) == 9) && (!strncmp(consdev, "serial", 6)) &&
159 	    (consdev[7] == '0' || consdev[7] == '1')) {
160 		cn_tab = &zs_cn;
161 		(*cn_tab->cn_init)(cn_tab);
162 
163 		return (1);
164 	}
165 #endif
166 
167 	return (0);
168 }
169 
170 static int
171 gio_video_init(const char *consdev)
172 {
173 #if (NGIO > 0)
174 	if (strcmp(consdev, "video()") == 0) {
175 		/*
176 		 * XXX Assumes that if output is video()
177 		 * input must be keyboard().
178 		 */
179 		if (gio_cnattach() != 0)
180 			return (0);
181 
182 		switch(mach_type) {
183 		case MACH_SGI_IP12:
184 		case MACH_SGI_IP20:
185 #if (NZSKBD > 0)
186 			/* XXX Hardcoded unit, channel */
187 			zskbd_cnattach(0, 0);
188 #endif
189 			break;
190 
191 		case MACH_SGI_IP22:
192 #if (NPCKBC > 0)
193 			/* XXX Hardcoded iotag, HPC address XXX */
194 			pckbc_cnattach(SGIMIPS_BUS_SPACE_HPC,
195 			    HPC_BASE_ADDRESS_0 +
196 			    HPC3_PBUS_CH6_DEVREGS + IOC_KB_REGS, KBCMDP,
197 			    PCKBC_KBD_SLOT);
198 #endif
199 			break;
200 		}
201 
202 		return (1);
203 	}
204 #endif
205 
206 	return (0);
207 }
208 
209 static int
210 mace_serial_init(const char *consdev)
211 {
212 #if (NCOM > 0)
213 	const char     *dbaud;
214 	int       speed;
215 	u_int32_t base;
216 
217 	if ((strlen(consdev) == 9) && (!strncmp(consdev, "serial", 6)) &&
218 	    (consdev[7] == '0' || consdev[7] == '1')) {
219 		/* Get comm speed from ARCS */
220 		dbaud = ARCBIOS->GetEnvironmentVariable("dbaud");
221 		speed = strtoul(dbaud, NULL, 10);
222 		base = (consdev[7] == '0') ? MACE_ISA_SER1_BASE :
223 		    MACE_ISA_SER2_BASE;
224 
225 		delay(10000);
226 
227 		/* XXX: hardcoded MACE iotag */
228 		if (comcnattach(SGIMIPS_BUS_SPACE_MACE, MIPS_PHYS_TO_KSEG1(MACE_BASE + base),
229 		    speed, COM_FREQ, COM_TYPE_NORMAL, comcnmode) == 0)
230 			return (1);
231 	}
232 #endif
233 
234 	return (0);
235 }
236 
237 #if defined(KGDB)
238 void
239 kgdb_port_init(void)
240 {
241 # if (NCOM > 0)
242 #  define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
243 	if (mach_type == MACH_SGI_IP32)
244 		com_kgdb_attach(SGIMIPS_BUS_SPACE_MACE, 0xbf398000, 9600, COM_FREQ, COM_TYPE_NORMAL,
245 		    KGDB_DEVMODE);
246 # endif	/* (NCOM > 0) */
247 
248 # if (NZSC > 0)
249 	switch(mach_type) {
250 	case MACH_SGI_IP12:
251 	case MACH_SGI_IP20:
252 	case MACH_SGI_IP22:
253 		zs_kgdb_init();			/* XXX */
254 	}
255 # endif
256 }
257 #endif	/* KGDB */
258