1 /*- 2 * Copyright (c) 1998 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer as 10 * the first lines of this file unmodified. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $Id: scvesactl.c,v 1.6 1998/10/01 11:39:17 yokota Exp $ 27 */ 28 29 #include "sc.h" 30 #include "opt_vesa.h" 31 #include "opt_vm86.h" 32 33 #if (NSC > 0 && defined(VESA) && defined(VM86)) || defined(VESA_MODULE) 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/conf.h> 38 #include <sys/tty.h> 39 #include <sys/kernel.h> 40 41 #include <machine/apm_bios.h> 42 #include <machine/console.h> 43 #include <machine/pc/vesa.h> 44 45 #include <i386/isa/videoio.h> 46 #include <i386/isa/syscons.h> 47 48 static d_ioctl_t *prev_user_ioctl; 49 50 static int 51 vesa_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) 52 { 53 scr_stat *scp; 54 struct tty *tp; 55 video_adapter_t *adp; 56 int mode; 57 58 tp = scdevtotty(dev); 59 if (!tp) 60 return ENXIO; 61 scp = sc_get_scr_stat(tp->t_dev); 62 63 switch (cmd) { 64 65 /* generic text modes */ 66 case SW_TEXT_132x25: case SW_TEXT_132x30: 67 case SW_TEXT_132x43: case SW_TEXT_132x50: 68 case SW_TEXT_132x60: 69 adp = get_adapter(scp); 70 if (!(adp->va_flags & V_ADP_MODECHANGE)) 71 return ENODEV; 72 return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0); 73 74 /* text modes */ 75 case SW_VESA_C80x60: 76 case SW_VESA_C132x25: 77 case SW_VESA_C132x43: 78 case SW_VESA_C132x50: 79 case SW_VESA_C132x60: 80 adp = get_adapter(scp); 81 if (!(adp->va_flags & V_ADP_MODECHANGE)) 82 return ENODEV; 83 mode = (cmd & 0xff) + M_VESA_BASE; 84 return sc_set_text_mode(scp, tp, mode, 0, 0, 0); 85 86 /* graphics modes */ 87 case SW_VESA_32K_320: case SW_VESA_64K_320: 88 case SW_VESA_FULL_320: 89 90 case SW_VESA_CG640x400: 91 92 case SW_VESA_CG640x480: 93 case SW_VESA_32K_640: case SW_VESA_64K_640: 94 case SW_VESA_FULL_640: 95 96 case SW_VESA_800x600: case SW_VESA_CG800x600: 97 case SW_VESA_32K_800: case SW_VESA_64K_800: 98 case SW_VESA_FULL_800: 99 100 case SW_VESA_1024x768: case SW_VESA_CG1024x768: 101 case SW_VESA_32K_1024: case SW_VESA_64K_1024: 102 case SW_VESA_FULL_1024: 103 104 case SW_VESA_1280x1024: case SW_VESA_CG1280x1024: 105 case SW_VESA_32K_1280: case SW_VESA_64K_1280: 106 case SW_VESA_FULL_1280: 107 adp = get_adapter(scp); 108 if (!(adp->va_flags & V_ADP_MODECHANGE)) 109 return ENODEV; 110 mode = (cmd & 0xff) + M_VESA_BASE; 111 return sc_set_graphics_mode(scp, tp, mode); 112 } 113 114 if (prev_user_ioctl) 115 return (*prev_user_ioctl)(dev, cmd, data, flag, p); 116 else 117 return ENOIOCTL; 118 } 119 120 int 121 vesa_load_ioctl(void) 122 { 123 if (prev_user_ioctl) 124 return EBUSY; 125 prev_user_ioctl = sc_user_ioctl; 126 sc_user_ioctl = vesa_ioctl; 127 return 0; 128 } 129 130 int 131 vesa_unload_ioctl(void) 132 { 133 if (sc_user_ioctl != vesa_ioctl) 134 return EBUSY; 135 sc_user_ioctl = prev_user_ioctl; 136 prev_user_ioctl = NULL; 137 return 0; 138 } 139 140 #endif /* (NSC > 0 && VESA && VM86) || VESA_MODULE */ 141