This source file includes following definitions.
- kd_nosound
- kd_mksound
- vt_ioctl
1
2
3
4
5
6
7 #include <linux/types.h>
8 #include <linux/errno.h>
9 #include <linux/sched.h>
10 #include <linux/tty.h>
11 #include <linux/timer.h>
12 #include <linux/kernel.h>
13 #include <linux/keyboard.h>
14 #include <linux/kd.h>
15 #include <linux/vt.h>
16
17 #include <asm/io.h>
18 #include <asm/segment.h>
19
20 #include "vt_kern.h"
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 struct vt_cons vt_cons[NR_CONSOLES];
36
37 extern int sys_ioperm(unsigned long from, unsigned long num, int on);
38 extern void change_console(unsigned int new_console);
39 extern void complete_change_console(unsigned int new_console);
40 extern int vt_waitactive(void);
41
42
43
44
45
46 #define GPFIRST 0x3b4
47 #define GPLAST 0x3df
48 #define GPNUM (GPLAST - GPFIRST + 1)
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 void
66 kd_nosound(void)
67 {
68
69 outb(inb_p(0x61)&0xFC, 0x61);
70 return;
71 }
72
73 void
74 kd_mksound(unsigned int count, unsigned int ticks)
75 {
76 if (count)
77 {
78
79 outb_p(inb_p(0x61)|3, 0x61);
80
81 outb_p(0xB6, 0x43);
82
83 outb_p(count & 0xff, 0x42);
84 outb((count >> 8) & 0xff, 0x42);
85
86 if (ticks)
87 {
88 timer_table[BEEP_TIMER].expires = jiffies + ticks;
89 timer_table[BEEP_TIMER].fn = kd_nosound;
90 timer_active |= (1 << BEEP_TIMER);
91 }
92 }
93
94 else
95 kd_nosound();
96
97 return;
98 }
99
100
101
102
103
104 int vt_ioctl(struct tty_struct *tty, struct file * file,
105 unsigned int cmd, unsigned int arg)
106 {
107 int console, i;
108 unsigned char ucval;
109 struct kbd_struct * kbd;
110
111 console = tty->line - 1;
112
113 if (console < 0 || console >= NR_CONSOLES)
114 return -EINVAL;
115
116 kbd = kbd_table + console;
117 switch (cmd) {
118 case KIOCSOUND:
119 kd_mksound((unsigned int)arg, 0);
120 return 0;
121
122 case KDMKTONE:
123 {
124 unsigned int ticks = HZ * ((arg >> 16) & 0xffff) / 1000;
125
126
127
128
129
130 kd_mksound(arg & 0xffff, ticks);
131 if (ticks == 0)
132 kd_nosound();
133 return 0;
134 }
135
136 case KDGKBTYPE:
137
138
139
140 verify_area((void *) arg, sizeof(unsigned char));
141 put_fs_byte(KB_101, (unsigned char *) arg);
142 return 0;
143
144 case KDADDIO:
145 case KDDELIO:
146
147
148
149
150 if (arg < GPFIRST || arg > GPLAST)
151 return -EINVAL;
152 return sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
153
154 case KDENABIO:
155 case KDDISABIO:
156 return sys_ioperm(GPFIRST, GPNUM,
157 (cmd == KDENABIO)) ? -ENXIO : 0;
158
159 case KDSETMODE:
160
161
162
163
164
165 switch (arg) {
166 case KD_GRAPHICS:
167 break;
168 case KD_TEXT0:
169 case KD_TEXT1:
170 arg = KD_TEXT;
171 case KD_TEXT:
172 break;
173 default:
174 return -EINVAL;
175 }
176 if (vt_cons[console].vc_mode == (unsigned char) arg)
177 return 0;
178 vt_cons[console].vc_mode = (unsigned char) arg;
179 if (console != fg_console)
180 return 0;
181
182
183
184 if (arg == KD_TEXT)
185 unblank_screen();
186 else {
187 timer_active &= ~(1<<BLANK_TIMER);
188 blank_screen();
189 }
190 return 0;
191
192 case KDGETMODE:
193 verify_area((void *) arg, sizeof(unsigned long));
194 put_fs_long(vt_cons[console].vc_mode, (unsigned long *) arg);
195 return 0;
196
197 case KDMAPDISP:
198 case KDUNMAPDISP:
199
200
201
202
203 return -EINVAL;
204
205 case KDSKBMODE:
206 if (arg == K_RAW) {
207 set_vc_kbd_flag(kbd, VC_RAW);
208 } else if (arg == K_XLATE) {
209 clr_vc_kbd_flag(kbd, VC_RAW);
210 }
211 else
212 return -EINVAL;
213 flush_input(tty);
214 return 0;
215
216 case KDGKBMODE:
217 verify_area((void *) arg, sizeof(unsigned long));
218 ucval = vc_kbd_flag(kbd, VC_RAW);
219 put_fs_long(ucval ? K_RAW : K_XLATE, (unsigned long *) arg);
220 return 0;
221
222 case KDGETLED:
223 verify_area((void *) arg, sizeof(unsigned char));
224 ucval = 0;
225 if (vc_kbd_flag(kbd, VC_SCROLLOCK))
226 ucval |= LED_SCR;
227 if (vc_kbd_flag(kbd, VC_NUMLOCK))
228 ucval |= LED_NUM;
229 if (vc_kbd_flag(kbd, VC_CAPSLOCK))
230 ucval |= LED_CAP;
231 put_fs_byte(ucval, (unsigned char *) arg);
232 return 0;
233
234 case KDSETLED:
235 if (arg & ~7)
236 return -EINVAL;
237 if (arg & LED_SCR)
238 set_vc_kbd_flag(kbd, VC_SCROLLOCK);
239 else
240 clr_vc_kbd_flag(kbd, VC_SCROLLOCK);
241 if (arg & LED_NUM)
242 set_vc_kbd_flag(kbd, VC_NUMLOCK);
243 else
244 clr_vc_kbd_flag(kbd, VC_NUMLOCK);
245 if (arg & LED_CAP)
246 set_vc_kbd_flag(kbd, VC_CAPSLOCK);
247 else
248 clr_vc_kbd_flag(kbd, VC_CAPSLOCK);
249 set_leds();
250 return 0;
251
252 case VT_SETMODE:
253 {
254 struct vt_mode *vtmode = (struct vt_mode *)arg;
255 char mode;
256
257 verify_area((void *)vtmode, sizeof(struct vt_mode));
258 mode = get_fs_byte(&vtmode->mode);
259 if (mode != VT_AUTO && mode != VT_PROCESS)
260 return -EINVAL;
261 vt_cons[console].vt_mode.mode = mode;
262 vt_cons[console].vt_mode.waitv = get_fs_byte(&vtmode->waitv);
263 vt_cons[console].vt_mode.relsig = get_fs_word(&vtmode->relsig);
264 vt_cons[console].vt_mode.acqsig = get_fs_word(&vtmode->acqsig);
265
266 vt_cons[console].vt_mode.frsig = 0;
267 vt_cons[console].vt_pid = current->pid;
268 vt_cons[console].vt_newvt = 0;
269 return 0;
270 }
271
272 case VT_GETMODE:
273 {
274 struct vt_mode *vtmode = (struct vt_mode *)arg;
275
276 verify_area((void *)arg, sizeof(struct vt_mode));
277 put_fs_byte(vt_cons[console].vt_mode.mode, &vtmode->mode);
278 put_fs_byte(vt_cons[console].vt_mode.waitv, &vtmode->waitv);
279 put_fs_word(vt_cons[console].vt_mode.relsig, &vtmode->relsig);
280 put_fs_word(vt_cons[console].vt_mode.acqsig, &vtmode->acqsig);
281 put_fs_word(vt_cons[console].vt_mode.frsig, &vtmode->frsig);
282 return 0;
283 }
284
285
286
287
288
289 case VT_GETSTATE:
290 {
291 struct vt_stat *vtstat = (struct vt_stat *)arg;
292 unsigned short state, mask;
293
294 verify_area((void *)vtstat, sizeof(struct vt_stat));
295 put_fs_word(fg_console + 1, &vtstat->v_active);
296 state = 1;
297 for (i = 1, mask = 2; i <= NR_CONSOLES; ++i, mask <<= 1)
298 if (tty_table[i] && tty_table[i]->count > 0)
299 state |= mask;
300 put_fs_word(state, &vtstat->v_state);
301 return 0;
302 }
303
304
305
306
307 case VT_OPENQRY:
308 verify_area((void *) arg, sizeof(long));
309 for (i = 1; i <= NR_CONSOLES; ++i)
310 if (!tty_table[i] || tty_table[i]->count == 0)
311 break;
312 put_fs_long(i <= NR_CONSOLES ? i : -1, (unsigned long *)arg);
313 return 0;
314
315
316
317
318
319
320 case VT_ACTIVATE:
321 if (arg == 0 || arg > NR_CONSOLES)
322 return -ENXIO;
323 change_console(arg - 1);
324 return 0;
325
326
327
328
329 case VT_WAITACTIVE:
330 if (arg == 0 || arg > NR_CONSOLES)
331 return -ENXIO;
332 while (fg_console != arg - 1)
333 {
334 if (vt_waitactive() < 0)
335 return -EINTR;
336 }
337 return 0;
338
339
340
341
342
343
344
345
346
347
348
349 case VT_RELDISP:
350 if (vt_cons[console].vt_mode.mode != VT_PROCESS)
351 return -EINVAL;
352
353
354
355
356 if (vt_cons[console].vt_newvt >= 0)
357 {
358 if (arg == 0)
359
360
361
362
363 vt_cons[console].vt_newvt = -1;
364
365 else
366 {
367
368
369
370
371 int newvt = vt_cons[console].vt_newvt;
372 vt_cons[console].vt_newvt = -1;
373 complete_change_console(newvt);
374 }
375 }
376
377
378
379
380 else
381 {
382
383
384
385 if (arg != VT_ACKACQ)
386 return -EINVAL;
387 }
388
389 return 0;
390
391 default:
392 return -EINVAL;
393 }
394 }