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
  3. vt_init

   1 /*
   2  *  kernel/chr_drv/vt.c
   3  *
   4  *  (C) 1992 obz under the linux copyright
   5  */
   6 
   7 #include <errno.h>
   8 
   9 #include <sys/types.h>
  10 #include <sys/kd.h>
  11 #include <sys/vt.h>
  12 
  13 #include <asm/io.h>
  14 #include <asm/segment.h>
  15 
  16 #include <linux/sched.h>
  17 #include <linux/tty.h>
  18 #include <linux/kernel.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_info vt_info[MAX_CONSOLES];
  27 
  28 extern int NR_CONSOLES;
  29 extern unsigned char kleds;
  30 extern unsigned char kraw;
  31 extern unsigned char ke0;
  32 
  33 extern int sys_ioperm(unsigned long from, unsigned long num, int on);
  34 extern void set_leds(void);
  35 
  36 /*
  37  * these are the valid i/o ports we're allowed to change. they map all the
  38  * video ports
  39  */
  40 #define GPFIRST 0x3b4
  41 #define GPLAST 0x3df
  42 #define GPNUM (GPLAST - GPFIRST + 1)
  43 
  44 /*
  45  * turns on sound of some freq. 0 turns it off.
  46  * stolen from console.c, so i'm not sure if its the correct interpretation
  47  */
  48 static int
  49 kiocsound(unsigned int freq)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51         if (freq == 0) {
  52                 /* disable counter 2 */
  53                 outb(inb_p(0x61)&0xFC, 0x61);
  54         }
  55         else {
  56                 /* enable counter 2 */
  57                 outb_p(inb_p(0x61)|3, 0x61);
  58                 /* set command for counter 2, 2 byte write */
  59                 outb_p(0xB6, 0x43);
  60                 /* select desired HZ */
  61                 outb_p(freq & 0xff, 0x42);
  62                 outb((freq >> 8) & 0xff, 0x42);
  63         }
  64         return 0;
  65 }
  66 
  67 int
  68 vt_ioctl(struct tty_struct *tty, int dev, int cmd, int arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 {
  70         switch (cmd) {
  71         case KIOCSOUND:
  72                 return kiocsound((unsigned int)arg);
  73 
  74         case KDGKBTYPE:
  75                 verify_area((void *) arg, sizeof(unsigned char));
  76                 put_fs_byte(KB_101, (unsigned char *) arg);
  77                 return 0;
  78 
  79         case KDADDIO:
  80         case KDDELIO:
  81                 /*
  82                  * KDADDIO and KDDELIO may be able to add ports beyond what
  83                  * we reject here, but to be safe...
  84                  */
  85                 if (arg < GPFIRST || arg > GPLAST)
  86                         return -EINVAL;
  87                 return sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
  88 
  89         case KDENABIO:
  90         case KDDISABIO:
  91                 return sys_ioperm(GPFIRST, GPNUM, (cmd == KDENABIO)) ? -ENXIO : 0;
  92 
  93         case KDSETMODE:
  94                 /*
  95                  * currently, setting the mode from KD_TEXT to KD_GRAPHICS
  96                  * doesn't do a whole lot. i'm not sure if it should do any
  97                  * restoration of modes or what...
  98                  */
  99                 switch (arg) {
 100                 case KD_GRAPHICS:
 101                         break;
 102                 case KD_TEXT0:
 103                 case KD_TEXT1:
 104                         arg = KD_TEXT;
 105                 case KD_TEXT:
 106                         break;
 107                 default:
 108                         return -EINVAL;
 109                 }
 110                 vt_info[fg_console].mode = arg;
 111                 return 0;
 112         case KDGETMODE:
 113                 verify_area((void *) arg, sizeof(unsigned long));
 114                 put_fs_long(vt_info[fg_console].mode, (unsigned long *) arg);
 115                 return 0;
 116 
 117         case KDMAPDISP:
 118         case KDUNMAPDISP:
 119                 /*
 120                  * these work like a combination of mmap and KDENABIO.
 121                  * this could be easily finished.
 122                  */
 123                 return -EINVAL;
 124 
 125         case KDSKBMODE:
 126                 if (arg == K_RAW) {
 127                         kraw = 1;
 128                         ke0 = 0;
 129                 }
 130                 else if (arg == K_XLATE) {
 131                         kraw = 0;
 132                 }
 133                 else
 134                         return -EINVAL;
 135                 return 0;
 136         case KDGKBMODE:
 137                 verify_area((void *) arg, sizeof(unsigned long));
 138                 put_fs_long(kraw ? K_RAW : K_XLATE, (unsigned long *) arg);
 139                 return 0;
 140 
 141         case KDGETLED:
 142                 verify_area((void *) arg, sizeof(unsigned char));
 143                 put_fs_byte((((kleds & 1) ? LED_SCR : 0) |
 144                              ((kleds & 2) ? LED_NUM : 0) |
 145                              ((kleds & 4) ? LED_CAP : 0)),
 146                             (unsigned char *) arg);
 147                 return 0;
 148         case KDSETLED:
 149                 if (arg & ~7)
 150                         return -EINVAL;
 151                 kleds = (((arg & LED_SCR) ? 1 : 0) |
 152                          ((arg & LED_NUM) ? 2 : 0) |
 153                          ((arg & LED_CAP) ? 4 : 0));
 154                 set_leds();
 155                 return 0;
 156 
 157         default:
 158                 return -EINVAL;
 159         }
 160 }
 161 
 162 void
 163 vt_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 164 {
 165         int i;
 166 
 167         for (i = 0; i < NR_CONSOLES; ++i) {
 168                 vt_info[i].mode = KD_TEXT;
 169         }
 170 }

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