1 /* $NetBSD: console.c,v 1.45 2015/09/30 19:46:27 macallan 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.45 2015/09/30 19:46:27 macallan 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 <sys/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
consinit(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 mace_init_bus();
119 pckbc_cnattach(mace_isa_memt,
120 MACE_BASE + 0x320000, 8,
121 PCKBC_KBD_SLOT, 0);
122 #endif
123 #endif
124 return;
125 }
126 #else
127 panic("this ip32 kernel does not contain framebuffer support.");
128 #endif
129 break;
130
131 default:
132 panic("consinit(): unknown machine type IP%d\n", mach_type);
133 break;
134 }
135
136 printf("Using ARCS for console I/O.\n");
137 }
138
139 static int
scn_serial_init(const char * consdev)140 scn_serial_init(const char *consdev)
141 {
142 #if (NSCN > 0)
143 if ((strlen(consdev) == 9) && (!strncmp(consdev, "serial", 6)) &&
144 (consdev[7] == '0' || consdev[7] == '1')) {
145 cn_tab = &scn_cn;
146 (*cn_tab->cn_init)(cn_tab);
147
148 return (1);
149 }
150 #endif
151
152 return (0);
153 }
154
155 static int
zs_serial_init(const char * consdev)156 zs_serial_init(const char *consdev)
157 {
158 #if (NZSC > 0)
159 if ((strlen(consdev) == 9) && (!strncmp(consdev, "serial", 6)) &&
160 (consdev[7] == '0' || consdev[7] == '1')) {
161 cn_tab = &zs_cn;
162 (*cn_tab->cn_init)(cn_tab);
163
164 return (1);
165 }
166 #endif
167
168 return (0);
169 }
170
171 static int
gio_video_init(const char * consdev)172 gio_video_init(const char *consdev)
173 {
174 #if (NGIO > 0)
175 if (strcmp(consdev, "video()") == 0) {
176 /*
177 * XXX Assumes that if output is video()
178 * input must be keyboard().
179 */
180 if (gio_cnattach() != 0)
181 return (0);
182
183 switch(mach_type) {
184 case MACH_SGI_IP12:
185 case MACH_SGI_IP20:
186 #if (NZSKBD > 0)
187 /* XXX Hardcoded unit, channel */
188 zskbd_cnattach(0, 0);
189 #endif
190 break;
191
192 case MACH_SGI_IP22:
193 #if (NPCKBC > 0)
194 /* XXX Hardcoded iotag, HPC address XXX */
195 pckbc_cnattach(normal_memt,
196 HPC_BASE_ADDRESS_0 +
197 HPC3_PBUS_CH6_DEVREGS + IOC_KB_REGS, KBCMDP,
198 PCKBC_KBD_SLOT, 0);
199 #endif
200 break;
201 }
202
203 return (1);
204 }
205 #endif
206
207 return (0);
208 }
209
210 static int
mace_serial_init(const char * consdev)211 mace_serial_init(const char *consdev)
212 {
213 #if (NCOM > 0)
214 const char *dbaud;
215 int speed;
216 u_int32_t base;
217
218 if ((strlen(consdev) == 9) && (!strncmp(consdev, "serial", 6)) &&
219 (consdev[7] == '0' || consdev[7] == '1')) {
220 /* Get comm speed from ARCS */
221 dbaud = arcbios_GetEnvironmentVariable("dbaud");
222 speed = strtoul(dbaud, NULL, 10);
223 base = (consdev[7] == '0') ? MACE_ISA_SER1_BASE :
224 MACE_ISA_SER2_BASE;
225
226 delay(10000);
227
228 /* XXX: hardcoded MACE iotag */
229 mace_init_bus();
230 if (comcnattach(mace_isa_memt, MACE_BASE + base,
231 speed, COM_FREQ, COM_TYPE_NORMAL, comcnmode) == 0)
232 return (1);
233 }
234 #endif
235
236 return (0);
237 }
238
239 #if defined(KGDB)
240 void
kgdb_port_init(void)241 kgdb_port_init(void)
242 {
243 # if (NCOM > 0)
244 # define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
245 if (mach_type == MACH_SGI_IP32) {
246 mace_init_bus();
247 com_kgdb_attach(mace_isa_memt, 0xbf398000, 9600, COM_FREQ, COM_TYPE_NORMAL,
248 KGDB_DEVMODE);
249 }
250 # endif /* (NCOM > 0) */
251
252 # if (NZSC > 0)
253 switch(mach_type) {
254 case MACH_SGI_IP12:
255 case MACH_SGI_IP20:
256 case MACH_SGI_IP22:
257 zs_kgdb_init(); /* XXX */
258 }
259 # endif
260 }
261 #endif /* KGDB */
262