root/kernel/chr_drv/vt.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. kiocsound
  2. vt_ioctl

   1 /*
   2  *  kernel/chr_drv/vt.c
   3  *
   4  *  Copyright (C) 1992 obz under the linux copyright
   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  * console (vt and kd) routines, as defined by usl svr4 manual
  24  */
  25 
  26 struct vt_cons vt_cons[NR_CONSOLES];
  27 
  28 extern int sys_ioperm(unsigned long from, unsigned long num, int on);
  29 extern void set_leds(void);
  30 
  31 /*
  32  * these are the valid i/o ports we're allowed to change. they map all the
  33  * video ports
  34  */
  35 #define GPFIRST 0x3b4
  36 #define GPLAST 0x3df
  37 #define GPNUM (GPLAST - GPFIRST + 1)
  38 
  39 /*
  40  * turns on sound of some freq. 0 turns it off.
  41  * stolen from console.c, so i'm not sure if its the correct interpretation
  42  */
  43 static int
  44 kiocsound(unsigned int freq)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46         if (freq == 0) {
  47                 /* disable counter 2 */
  48                 outb(inb_p(0x61)&0xFC, 0x61);
  49         }
  50         else {
  51                 /* enable counter 2 */
  52                 outb_p(inb_p(0x61)|3, 0x61);
  53                 /* set command for counter 2, 2 byte write */
  54                 outb_p(0xB6, 0x43);
  55                 /* select desired HZ */
  56                 outb_p(freq & 0xff, 0x42);
  57                 outb((freq >> 8) & 0xff, 0x42);
  58         }
  59         return 0;
  60 }
  61 
  62 /*
  63  * We handle the console-specific ioctl's here.  We allow the
  64  * capability to modify any console, not just the fg_console. 
  65  */
  66 int vt_ioctl(struct tty_struct *tty, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
  67              unsigned int cmd, unsigned int arg)
  68 {
  69         int console;
  70         unsigned char ucval;
  71         struct kbd_struct * kbd;
  72 
  73         console = tty->line - 1;
  74 
  75         if (console < 0 || console >= NR_CONSOLES)
  76                 return -EINVAL;
  77 
  78         kbd = kbd_table + console;
  79         switch (cmd) {
  80         case KIOCSOUND:
  81                 return kiocsound((unsigned int)arg);
  82 
  83         case KDGKBTYPE:
  84                 /*
  85                  * this is naive.
  86                  */
  87                 verify_area((void *) arg, sizeof(unsigned char));
  88                 put_fs_byte(KB_101, (unsigned char *) arg);
  89                 return 0;
  90 
  91         case KDADDIO:
  92         case KDDELIO:
  93                 /*
  94                  * KDADDIO and KDDELIO may be able to add ports beyond what
  95                  * we reject here, but to be safe...
  96                  */
  97                 if (arg < GPFIRST || arg > GPLAST)
  98                         return -EINVAL;
  99                 return sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
 100 
 101         case KDENABIO:
 102         case KDDISABIO:
 103                 return sys_ioperm(GPFIRST, GPNUM,
 104                                   (cmd == KDENABIO)) ? -ENXIO : 0;
 105 
 106         case KDSETMODE:
 107                 /*
 108                  * currently, setting the mode from KD_TEXT to KD_GRAPHICS
 109                  * doesn't do a whole lot. i'm not sure if it should do any
 110                  * restoration of modes or what...
 111                  */
 112                 switch (arg) {
 113                 case KD_GRAPHICS:
 114                         break;
 115                 case KD_TEXT0:
 116                 case KD_TEXT1:
 117                         arg = KD_TEXT;
 118                 case KD_TEXT:
 119                         break;
 120                 default:
 121                         return -EINVAL;
 122                 }
 123                 if (vt_cons[console].vt_mode == (unsigned char) arg)
 124                         return 0;
 125                 vt_cons[console].vt_mode = (unsigned char) arg;
 126                 if (console != fg_console)
 127                         return 0;
 128                 if (arg == KD_TEXT)
 129                         unblank_screen();
 130                 else {
 131                         timer_active &= 1<<BLANK_TIMER;
 132                         blank_screen();
 133                 }
 134                 return 0;
 135         case KDGETMODE:
 136                 verify_area((void *) arg, sizeof(unsigned long));
 137                 put_fs_long(vt_cons[console].vt_mode, (unsigned long *) arg);
 138                 return 0;
 139 
 140         case KDMAPDISP:
 141         case KDUNMAPDISP:
 142                 /*
 143                  * these work like a combination of mmap and KDENABIO.
 144                  * this could be easily finished.
 145                  */
 146                 return -EINVAL;
 147 
 148         case KDSKBMODE:
 149                 if (arg == K_RAW) {
 150                         set_vc_kbd_flag(kbd, VC_RAW);
 151                 } else if (arg == K_XLATE) {
 152                         clr_vc_kbd_flag(kbd, VC_RAW);
 153                 }
 154                 else
 155                         return -EINVAL;
 156                 flush_input(tty);
 157                 return 0;
 158         case KDGKBMODE:
 159                 verify_area((void *) arg, sizeof(unsigned long));
 160                 ucval = vc_kbd_flag(kbd, VC_RAW);
 161                 put_fs_long(ucval ? K_RAW : K_XLATE, (unsigned long *) arg);
 162                 return 0;
 163 
 164         case KDGETLED:
 165                 verify_area((void *) arg, sizeof(unsigned char));
 166                 ucval = 0;
 167                 if (vc_kbd_flag(kbd, VC_SCROLLOCK))
 168                         ucval |= LED_SCR;
 169                 if (vc_kbd_flag(kbd, VC_NUMLOCK))
 170                         ucval |= LED_NUM;
 171                 if (vc_kbd_flag(kbd, VC_CAPSLOCK))
 172                         ucval |= LED_CAP;
 173                 put_fs_byte(ucval, (unsigned char *) arg);
 174                 return 0;
 175         case KDSETLED:
 176                 if (arg & ~7)
 177                         return -EINVAL;
 178                 if (arg & LED_SCR)
 179                         set_vc_kbd_flag(kbd, VC_SCROLLOCK);
 180                 else
 181                         clr_vc_kbd_flag(kbd, VC_SCROLLOCK);
 182                 if (arg & LED_NUM)
 183                         set_vc_kbd_flag(kbd, VC_NUMLOCK);
 184                 else
 185                         clr_vc_kbd_flag(kbd, VC_NUMLOCK);
 186                 if (arg & LED_CAP)
 187                         set_vc_kbd_flag(kbd, VC_CAPSLOCK);
 188                 else
 189                         clr_vc_kbd_flag(kbd, VC_CAPSLOCK);
 190                 set_leds();
 191                 return 0;
 192 
 193         default:
 194                 return -EINVAL;
 195         }
 196 }

/* [previous][next][first][last][top][bottom][index][help] */