scvesactl.c revision 39591
139287Ssos/*- 239287Ssos * Copyright (c) 1998 Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp) 339287Ssos * All rights reserved. 439287Ssos * 539287Ssos * Redistribution and use in source and binary forms, with or without 639287Ssos * modification, are permitted provided that the following conditions 739287Ssos * are met: 839287Ssos * 1. Redistributions of source code must retain the above copyright 939287Ssos * notice, this list of conditions and the following disclaimer. 1039287Ssos * 2. Redistributions in binary form must reproduce the above copyright 1139287Ssos * notice, this list of conditions and the following disclaimer in the 1239287Ssos * documentation and/or other materials provided with the distribution. 1339287Ssos * 3. The name of the author may not be used to endorse or promote 1439287Ssos * products derived from this software without specific prior written 1539287Ssos * permission. 1639287Ssos * 1739287Ssos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1839287Ssos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1939287Ssos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2039287Ssos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2139287Ssos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2239287Ssos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2339287Ssos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2439287Ssos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2539287Ssos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2639287Ssos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2739287Ssos * SUCH DAMAGE. 2839287Ssos * 2939591Syokota * $Id: scvesactl.c,v 1.1 1998/09/15 18:16:37 sos Exp $ 3039287Ssos */ 3139287Ssos 3239287Ssos#include "sc.h" 3339287Ssos#include "opt_vesa.h" 3439287Ssos#include "opt_vm86.h" 3539287Ssos 3639287Ssos#if (NSC > 0 && defined(VESA) && defined(VM86)) || defined(VESA_MODULE) 3739287Ssos 3839287Ssos#include <sys/param.h> 3939287Ssos#include <sys/systm.h> 4039287Ssos#include <sys/tty.h> 4139287Ssos#include <sys/kernel.h> 4239287Ssos 4339287Ssos#include <machine/apm_bios.h> 4439287Ssos#include <machine/console.h> 4539287Ssos#include <machine/pc/vesa.h> 4639287Ssos 4739287Ssos#include <i386/isa/videoio.h> 4839287Ssos#include <i386/isa/syscons.h> 4939287Ssos 5039287Ssosstatic int (*prev_user_ioctl)(dev_t dev, int cmd, caddr_t data, int flag, 5139287Ssos struct proc *p); 5239287Ssos 5339591Syokota/* external functions */ 5439591Syokotastruct tty *scdevtotty(dev_t dev); 5539287Ssos 5639591Syokota/* functions in this module */ 5739591Syokotaint vesa_ioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p); 5839591Syokota 5939287Ssosint 6039287Ssosvesa_ioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p) 6139287Ssos{ 6239287Ssos scr_stat *scp; 6339287Ssos struct tty *tp; 6439287Ssos video_info_t info; 6539287Ssos video_adapter_t *adp; 6639287Ssos int mode; 6739287Ssos int error; 6839287Ssos int s; 6939287Ssos 7039287Ssos tp = scdevtotty(dev); 7139287Ssos if (!tp) 7239287Ssos return ENXIO; 7339287Ssos scp = sc_get_scr_stat(tp->t_dev); 7439287Ssos 7539287Ssos switch (cmd) { 7639287Ssos case SW_VESA_USER: 7739287Ssos 7839287Ssos mode = (int)data; 7939287Ssos if ((*biosvidsw.get_info)(scp->adp, mode, &info)) 8039287Ssos return ENODEV; 8139287Ssos if (info.vi_flags & V_INFO_GRAPHICS) 8239287Ssos goto vesa_graphics; 8339287Ssos else 8439287Ssos goto vesa_text; 8539287Ssos 8639591Syokota /* generic text modes */ 8739591Syokota case SW_TEXT_132x25: case SW_TEXT_132x30: 8839591Syokota case SW_TEXT_132x43: case SW_TEXT_132x50: 8939591Syokota case SW_TEXT_132x60: 9039591Syokota adp = get_adapter(scp); 9139591Syokota if (!(adp->va_flags & V_ADP_MODECHANGE)) 9239591Syokota return ENODEV; 9339591Syokota return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0); 9439591Syokota 9539287Ssos /* text modes */ 9639287Ssos case SW_VESA_C80x60: 9739287Ssos case SW_VESA_C132x25: 9839287Ssos case SW_VESA_C132x43: 9939287Ssos case SW_VESA_C132x50: 10039287Ssos case SW_VESA_C132x60: 10139287Ssos adp = get_adapter(scp); 10239287Ssos if (!(adp->va_flags & V_ADP_MODECHANGE)) 10339287Ssos return ENODEV; 10439287Ssos mode = (cmd & 0xff) + M_VESA_BASE; 10539287Ssosvesa_text: 10639287Ssos return sc_set_text_mode(scp, tp, mode, 0, 0, 0); 10739287Ssos 10839287Ssos /* graphics modes */ 10939287Ssos case SW_VESA_32K_320: case SW_VESA_64K_320: 11039287Ssos case SW_VESA_FULL_320: 11139287Ssos 11239287Ssos case SW_VESA_CG640x400: 11339287Ssos 11439287Ssos case SW_VESA_CG640x480: 11539287Ssos case SW_VESA_32K_640: case SW_VESA_64K_640: 11639287Ssos case SW_VESA_FULL_640: 11739287Ssos 11839287Ssos case SW_VESA_800x600: case SW_VESA_CG800x600: 11939287Ssos case SW_VESA_32K_800: case SW_VESA_64K_800: 12039287Ssos case SW_VESA_FULL_800: 12139287Ssos 12239287Ssos case SW_VESA_1024x768: case SW_VESA_CG1024x768: 12339287Ssos case SW_VESA_32K_1024: case SW_VESA_64K_1024: 12439287Ssos case SW_VESA_FULL_1024: 12539287Ssos 12639287Ssos case SW_VESA_1280x1024: case SW_VESA_CG1280x1024: 12739287Ssos case SW_VESA_32K_1280: case SW_VESA_64K_1280: 12839287Ssos case SW_VESA_FULL_1280: 12939287Ssos adp = get_adapter(scp); 13039287Ssos if (!(adp->va_flags & V_ADP_MODECHANGE)) 13139287Ssos return ENODEV; 13239287Ssos mode = (cmd & 0xff) + M_VESA_BASE; 13339287Ssosvesa_graphics: 13439287Ssos return sc_set_graphics_mode(scp, tp, mode); 13539287Ssos } 13639287Ssos 13739287Ssos if (prev_user_ioctl) 13839287Ssos return (*prev_user_ioctl)(dev, cmd, data, flag, p); 13939287Ssos else 14039287Ssos return ENOIOCTL; 14139287Ssos} 14239287Ssos 14339287Ssosint 14439287Ssosvesa_load_ioctl(void) 14539287Ssos{ 14639287Ssos if (prev_user_ioctl) 14739287Ssos return EBUSY; 14839287Ssos prev_user_ioctl = sc_user_ioctl; 14939287Ssos sc_user_ioctl = vesa_ioctl; 15039287Ssos return 0; 15139287Ssos} 15239287Ssos 15339287Ssosint 15439287Ssosvesa_unload_ioctl(void) 15539287Ssos{ 15639287Ssos if (sc_user_ioctl != vesa_ioctl) 15739287Ssos return EBUSY; 15839287Ssos sc_user_ioctl = prev_user_ioctl; 15939287Ssos prev_user_ioctl = NULL; 16039287Ssos return 0; 16139287Ssos} 16239287Ssos 16339287Ssos#endif /* (NSC > 0 && VESA && VM86) || VESA_MODULE */ 164