1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/* $NetBSD: wscons.c,v 1.3 1995/11/23 02:38:36 cgd Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Chris G. Demetriou
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
#include <sys/param.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/systm.h>
#include <sys/ioctl.h>
#include <sys/proc.h>
#include <sys/tty.h>
#include <sys/termios.h>
#include <dev/cons.h>
#include <dev/pseudo/ansicons.h>
#include <alpha/pci/wsconsvar.h>
#define NWSC 16 /* XXX XXX XXX */
#define WSCUNIT(dev) minor(dev)
struct wsc_softc {
int sc_flags;
struct device *sc_odev;
struct ansicons *sc_ansicons;
struct tty *sc_tty;
};
#define WSC_INPUT 0x01
#define WSC_OUTPUT 0x02
#define WSC_ALIVE (WSC_INPUT | WSC_OUTPUT)
struct wsc_softc wsc_sc[NWSC]; /* XXX XXX XXX */
int nwsc = NWSC;
int nextiwsc;
int nextowsc;
void wscstart __P((struct tty *));
int wscparam __P((struct tty *, struct termios *));
int wsccngetc __P((dev_t));
void wsccnputc __P((dev_t, int));
void wsccnpollc __P((dev_t, int));
struct ansicons *wsc_console_ansicons;
void *wsc_input_arg;
int (*wsc_console_getc) __P((void *)) = NULL;
void (*wsc_console_pollc) __P((void *, int)) = NULL;
struct consdev wsccons = { NULL, NULL, wsccngetc, wsccnputc,
wsccnpollc, NODEV, 1 };
int wsc_kbdfocusunit = -1; /* XXX */
int
wscattach_output(dev, console, acp, acf, acfarg, mrow, mcol, crow, ccol)
struct device *dev;
int console;
struct ansicons *acp;
struct ansicons_functions *acf;
void *acfarg;
int mrow, mcol, crow, ccol;
{
if (nextowsc >= nwsc)
return 0;
wsc_sc[nextowsc].sc_odev = dev;
wsc_sc[nextowsc].sc_ansicons = acp;
if (wsc_kbdfocusunit == -1)
wsc_kbdfocusunit = nextowsc;
if (!console)
ansicons_attach(acp, acf, acfarg, mrow, mcol, crow, ccol);
else {
wsc_kbdfocusunit = nextowsc;
wsccons.cn_dev = makedev(25, nextowsc);
}
wsc_sc[nextowsc].sc_flags |= WSC_OUTPUT;
wsc_sc[nextowsc].sc_tty = ttymalloc();
printf("wsc%d: %s attached as output\n", nextowsc, dev->dv_xname);
if (console)
printf("wsc%d: console\n", nextowsc);
nextowsc++;
return 1;
}
void
wscattach_input(dev, cookie, getc, pollc)
struct device *dev;
void *cookie;
int (*getc) __P((void *));
void (*pollc) __P((void *, int));
{
printf("wsc: %s attached as input device\n", dev->dv_xname);
wsc_input_arg = cookie;
wsc_console_getc = getc;
wsc_console_pollc = pollc;
}
int
wscopen(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
struct wsc_softc *sc;
int unit = WSCUNIT(dev);
struct tty *tp;
if (unit >= nwsc)
return ENXIO;
sc = &wsc_sc[unit];
if (sc == 0)
return ENXIO;
if ((sc->sc_flags & WSC_ALIVE) == 0)
return ENXIO;
if (!sc->sc_tty)
panic("wscopen: no tty!");
tp = sc->sc_tty;
tp->t_oproc = wscstart;
tp->t_param = wscparam;
tp->t_dev = dev;
if ((tp->t_state & TS_ISOPEN) == 0) {
tp->t_state |= TS_WOPEN;
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
wscparam(tp, &tp->t_termios);
ttsetwater(tp);
} else if ((tp->t_state & TS_XCLUDE) != 0 && p->p_ucred->cr_uid != 0)
return EBUSY;
tp->t_state |= TS_CARR_ON;
return ((*linesw[tp->t_line].l_open)(dev, tp));
}
int
wscclose(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
struct wsc_softc *sc = &wsc_sc[WSCUNIT(dev)];
struct tty *tp = sc->sc_tty;
(*linesw[tp->t_line].l_close)(tp, flag);
ttyclose(tp);
#ifdef notyet /* XXX */
ttyfree(tp);
#endif
return(0);
}
int
wscread(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
struct wsc_softc *sc = &wsc_sc[WSCUNIT(dev)];
struct tty *tp = sc->sc_tty;
return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
}
int
wscwrite(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
struct wsc_softc *sc = &wsc_sc[WSCUNIT(dev)];
struct tty *tp = sc->sc_tty;
return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
}
struct tty *
wsctty(dev)
dev_t dev;
{
struct wsc_softc *sc = &wsc_sc[WSCUNIT(dev)];
struct tty *tp = sc->sc_tty;
return (tp);
}
int
wscioctl(dev, cmd, data, flag, p)
dev_t dev;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct wsc_softc *sc = &wsc_sc[WSCUNIT(dev)];
struct tty *tp = sc->sc_tty;
int error;
error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
if (error >= 0)
return error;
error = ttioctl(tp, cmd, data, flag, p);
if (error >= 0)
return error;
switch (cmd) {
default:
return (ENOTTY);
}
#ifdef DIAGNOSTIC
panic("wscioctl: impossible");
#endif
}
void
wscstart(tp)
register struct tty *tp;
{
register int s, n, i;
char buf[OBUFSIZ];
s = spltty();
if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
splx(s);
return;
}
tp->t_state |= TS_BUSY;
splx(s);
n = q_to_b(&tp->t_outq, buf, sizeof(buf));
for (i = 0; i < n; ++i)
buf[i] &= 0177; /* strip parity (argh) */
ansicons_input(wsc_sc[WSCUNIT(tp->t_dev)].sc_ansicons, buf, n);
s = spltty();
tp->t_state &= ~TS_BUSY;
/* Come back if there's more to do */
if (tp->t_outq.c_cc) {
tp->t_state |= TS_TIMEOUT;
timeout(ttrstrt, tp, 1);
}
if (tp->t_outq.c_cc <= tp->t_lowat) {
if (tp->t_state&TS_ASLEEP) {
tp->t_state &= ~TS_ASLEEP;
wakeup((caddr_t)&tp->t_outq);
}
selwakeup(&tp->t_wsel);
}
splx(s);
}
void
wscstop(tp, flag)
struct tty *tp;
int flag;
{
}
/*
* Set line parameters.
*/
int
wscparam(tp, t)
struct tty *tp;
struct termios *t;
{
tp->t_ispeed = t->c_ispeed;
tp->t_ospeed = t->c_ospeed;
tp->t_cflag = t->c_cflag;
return 0;
}
/*
* keyboard input!
*/
void
wscons_kbdinput(cp)
char *cp;
{
struct wsc_softc *sc;
struct tty *tp;
if (wsc_kbdfocusunit == -1)
return;
sc = &wsc_sc[wsc_kbdfocusunit];
tp = sc->sc_tty;
while (*cp)
(*linesw[tp->t_line].l_rint)(*cp++, tp);
}
/*
* XXX CONSOLE HANDLING GUNK.
*/
void
wsc_console(acp, acf, acfarg, mrow, mcol, crow, ccol)
struct ansicons *acp;
struct ansicons_functions *acf;
void *acfarg;
int mrow, mcol, crow, ccol;
{
wsc_console_ansicons = acp;
ansicons_attach(acp, acf, acfarg, mrow, mcol, crow, ccol);
cn_tab = &wsccons;
}
void
wsccnputc(dev, ic)
dev_t dev;
int ic;
{
char c = ic;
ansicons_input(wsc_console_ansicons, &c, 1);
}
int
wsccngetc(dev)
dev_t dev;
{
if (wsc_console_getc != NULL)
return (*wsc_console_getc)(wsc_input_arg);
else
return '\0';
}
void
wsccnpollc(dev, i)
dev_t dev;
int i;
{
if (wsc_console_pollc != NULL)
(*wsc_console_pollc)(wsc_input_arg, i);
}
|