139287Ssos/*- 239643Syokota * Copyright (c) 1998 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 339287Ssos * All rights reserved. 439287Ssos * 5146736Sdelphij * This code is derived from software contributed to The DragonFly Project 6146736Sdelphij * by Sascha Wildner <saw@online.de> 7146736Sdelphij * 839287Ssos * Redistribution and use in source and binary forms, with or without 939287Ssos * modification, are permitted provided that the following conditions 1039287Ssos * are met: 1139287Ssos * 1. Redistributions of source code must retain the above copyright 1239643Syokota * notice, this list of conditions and the following disclaimer as 1339643Syokota * the first lines of this file unmodified. 1439287Ssos * 2. Redistributions in binary form must reproduce the above copyright 1539287Ssos * notice, this list of conditions and the following disclaimer in the 1639287Ssos * documentation and/or other materials provided with the distribution. 1739287Ssos * 1839643Syokota * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1939643Syokota * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2039643Syokota * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2139643Syokota * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2239643Syokota * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2339643Syokota * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2439643Syokota * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2539643Syokota * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2639643Syokota * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2739643Syokota * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2839287Ssos * 2939287Ssos */ 3039287Ssos 31119420Sobrien#include <sys/cdefs.h> 32119420Sobrien__FBSDID("$FreeBSD$"); 33119420Sobrien 3442504Syokota#include "opt_vga.h" 3539287Ssos 3656836Speter#ifndef VGA_NO_MODE_CHANGE 3739287Ssos 3839287Ssos#include <sys/param.h> 3939287Ssos#include <sys/systm.h> 4039668Syokota#include <sys/conf.h> 4139287Ssos#include <sys/tty.h> 4239287Ssos#include <sys/kernel.h> 4366859Sphk#include <sys/fbio.h> 4466859Sphk#include <sys/consio.h> 4539287Ssos 46197025Sdelphij#include <dev/fb/vesa.h> 4739287Ssos 4842504Syokota#include <dev/fb/fbreg.h> 4942504Syokota#include <dev/syscons/syscons.h> 5039287Ssos 51181905Sedstatic tsw_ioctl_t *prev_user_ioctl; 5239287Ssos 5339667Syokotastatic int 54181905Sedvesa_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) 5539287Ssos{ 5639287Ssos scr_stat *scp; 5739287Ssos int mode; 5839287Ssos 59181905Sed scp = SC_STAT(tp); 6039287Ssos 6139287Ssos switch (cmd) { 6239287Ssos 6339591Syokota /* generic text modes */ 6439591Syokota case SW_TEXT_132x25: case SW_TEXT_132x30: 6539591Syokota case SW_TEXT_132x43: case SW_TEXT_132x50: 6639591Syokota case SW_TEXT_132x60: 6748104Syokota if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE)) 6839591Syokota return ENODEV; 69149640Srodrigc return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0); 7039591Syokota 7139287Ssos /* text modes */ 7239287Ssos case SW_VESA_C80x60: 7339287Ssos case SW_VESA_C132x25: 7439287Ssos case SW_VESA_C132x43: 7539287Ssos case SW_VESA_C132x50: 7639287Ssos case SW_VESA_C132x60: 7748104Syokota if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE)) 7839287Ssos return ENODEV; 7939287Ssos mode = (cmd & 0xff) + M_VESA_BASE; 80149640Srodrigc return sc_set_text_mode(scp, tp, mode, 0, 0, 0, 0); 8139287Ssos 8239287Ssos /* graphics modes */ 8339287Ssos case SW_VESA_32K_320: case SW_VESA_64K_320: 8439287Ssos case SW_VESA_FULL_320: 8539287Ssos 8639287Ssos case SW_VESA_CG640x400: 8739287Ssos 8839287Ssos case SW_VESA_CG640x480: 8939287Ssos case SW_VESA_32K_640: case SW_VESA_64K_640: 9039287Ssos case SW_VESA_FULL_640: 9139287Ssos 9239287Ssos case SW_VESA_800x600: case SW_VESA_CG800x600: 9339287Ssos case SW_VESA_32K_800: case SW_VESA_64K_800: 9439287Ssos case SW_VESA_FULL_800: 9539287Ssos 9639287Ssos case SW_VESA_1024x768: case SW_VESA_CG1024x768: 9739287Ssos case SW_VESA_32K_1024: case SW_VESA_64K_1024: 9839287Ssos case SW_VESA_FULL_1024: 9939287Ssos 10039287Ssos case SW_VESA_1280x1024: case SW_VESA_CG1280x1024: 10139287Ssos case SW_VESA_32K_1280: case SW_VESA_64K_1280: 10239287Ssos case SW_VESA_FULL_1280: 10348104Syokota if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE)) 10439287Ssos return ENODEV; 10539287Ssos mode = (cmd & 0xff) + M_VESA_BASE; 10639287Ssos return sc_set_graphics_mode(scp, tp, mode); 107146736Sdelphij default: 108146736Sdelphij if (IOCGROUP(cmd) == 'V') { 109146736Sdelphij if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE)) 110146736Sdelphij return ENODEV; 111146736Sdelphij 112146736Sdelphij mode = (cmd & 0xff) + M_VESA_BASE; 113146736Sdelphij 114147224Sdelphij if (((cmd & IOC_DIRMASK) == IOC_VOID) && 115147224Sdelphij (mode > M_VESA_FULL_1280) && 116146736Sdelphij (mode < M_VESA_MODE_MAX)) 117146736Sdelphij return sc_set_graphics_mode(scp, tp, mode); 118146736Sdelphij } 11939287Ssos } 12039287Ssos 12139287Ssos if (prev_user_ioctl) 122181905Sed return (*prev_user_ioctl)(tp, cmd, data, td); 12339287Ssos else 12439287Ssos return ENOIOCTL; 12539287Ssos} 12639287Ssos 12739287Ssosint 12839287Ssosvesa_load_ioctl(void) 12939287Ssos{ 13039287Ssos if (prev_user_ioctl) 13139287Ssos return EBUSY; 13239287Ssos prev_user_ioctl = sc_user_ioctl; 13339287Ssos sc_user_ioctl = vesa_ioctl; 13439287Ssos return 0; 13539287Ssos} 13639287Ssos 13739287Ssosint 13839287Ssosvesa_unload_ioctl(void) 13939287Ssos{ 14039287Ssos if (sc_user_ioctl != vesa_ioctl) 14139287Ssos return EBUSY; 14239287Ssos sc_user_ioctl = prev_user_ioctl; 14339287Ssos prev_user_ioctl = NULL; 14439287Ssos return 0; 14539287Ssos} 14639287Ssos 147165927Smarius#endif /* VGA_NO_MODE_CHANGE */ 148