scvesactl.c revision 39287
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 * 2939287Ssos * $Id$ 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 5339287Ssosextern struct tty *scdevtotty(dev_t dev); 5439287Ssos 5539287Ssosint 5639287Ssosvesa_ioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p) 5739287Ssos{ 5839287Ssos scr_stat *scp; 5939287Ssos struct tty *tp; 6039287Ssos video_info_t info; 6139287Ssos video_adapter_t *adp; 6239287Ssos int mode; 6339287Ssos int error; 6439287Ssos int s; 6539287Ssos 6639287Ssos tp = scdevtotty(dev); 6739287Ssos if (!tp) 6839287Ssos return ENXIO; 6939287Ssos scp = sc_get_scr_stat(tp->t_dev); 7039287Ssos 7139287Ssos switch (cmd) { 7239287Ssos case SW_VESA_USER: 7339287Ssos 7439287Ssos mode = (int)data; 7539287Ssos if ((*biosvidsw.get_info)(scp->adp, mode, &info)) 7639287Ssos return ENODEV; 7739287Ssos if (info.vi_flags & V_INFO_GRAPHICS) 7839287Ssos goto vesa_graphics; 7939287Ssos else 8039287Ssos goto vesa_text; 8139287Ssos 8239287Ssos /* text modes */ 8339287Ssos case SW_VESA_C80x60: 8439287Ssos case SW_VESA_C132x25: 8539287Ssos case SW_VESA_C132x43: 8639287Ssos case SW_VESA_C132x50: 8739287Ssos case SW_VESA_C132x60: 8839287Ssos adp = get_adapter(scp); 8939287Ssos if (!(adp->va_flags & V_ADP_MODECHANGE)) 9039287Ssos return ENODEV; 9139287Ssos mode = (cmd & 0xff) + M_VESA_BASE; 9239287Ssosvesa_text: 9339287Ssos return sc_set_text_mode(scp, tp, mode, 0, 0, 0); 9439287Ssos 9539287Ssos /* graphics modes */ 9639287Ssos case SW_VESA_32K_320: case SW_VESA_64K_320: 9739287Ssos case SW_VESA_FULL_320: 9839287Ssos 9939287Ssos case SW_VESA_CG640x400: 10039287Ssos 10139287Ssos case SW_VESA_CG640x480: 10239287Ssos case SW_VESA_32K_640: case SW_VESA_64K_640: 10339287Ssos case SW_VESA_FULL_640: 10439287Ssos 10539287Ssos case SW_VESA_800x600: case SW_VESA_CG800x600: 10639287Ssos case SW_VESA_32K_800: case SW_VESA_64K_800: 10739287Ssos case SW_VESA_FULL_800: 10839287Ssos 10939287Ssos case SW_VESA_1024x768: case SW_VESA_CG1024x768: 11039287Ssos case SW_VESA_32K_1024: case SW_VESA_64K_1024: 11139287Ssos case SW_VESA_FULL_1024: 11239287Ssos 11339287Ssos case SW_VESA_1280x1024: case SW_VESA_CG1280x1024: 11439287Ssos case SW_VESA_32K_1280: case SW_VESA_64K_1280: 11539287Ssos case SW_VESA_FULL_1280: 11639287Ssos adp = get_adapter(scp); 11739287Ssos if (!(adp->va_flags & V_ADP_MODECHANGE)) 11839287Ssos return ENODEV; 11939287Ssos mode = (cmd & 0xff) + M_VESA_BASE; 12039287Ssosvesa_graphics: 12139287Ssos return sc_set_graphics_mode(scp, tp, mode); 12239287Ssos } 12339287Ssos 12439287Ssos if (prev_user_ioctl) 12539287Ssos return (*prev_user_ioctl)(dev, cmd, data, flag, p); 12639287Ssos else 12739287Ssos return ENOIOCTL; 12839287Ssos} 12939287Ssos 13039287Ssosint 13139287Ssosvesa_load_ioctl(void) 13239287Ssos{ 13339287Ssos if (prev_user_ioctl) 13439287Ssos return EBUSY; 13539287Ssos prev_user_ioctl = sc_user_ioctl; 13639287Ssos sc_user_ioctl = vesa_ioctl; 13739287Ssos return 0; 13839287Ssos} 13939287Ssos 14039287Ssosint 14139287Ssosvesa_unload_ioctl(void) 14239287Ssos{ 14339287Ssos if (sc_user_ioctl != vesa_ioctl) 14439287Ssos return EBUSY; 14539287Ssos sc_user_ioctl = prev_user_ioctl; 14639287Ssos prev_user_ioctl = NULL; 14739287Ssos return 0; 14839287Ssos} 14939287Ssos 15039287Ssos#endif /* (NSC > 0 && VESA && VM86) || VESA_MODULE */ 151