scvesactl.c revision 119420
139287Ssos/*- 239643Syokota * 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 939643Syokota * notice, this list of conditions and the following disclaimer as 1039643Syokota * the first lines of this file unmodified. 1139287Ssos * 2. Redistributions in binary form must reproduce the above copyright 1239287Ssos * notice, this list of conditions and the following disclaimer in the 1339287Ssos * documentation and/or other materials provided with the distribution. 1439287Ssos * 1539643Syokota * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1639643Syokota * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1739643Syokota * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1839643Syokota * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1939643Syokota * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2039643Syokota * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2139643Syokota * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2239643Syokota * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2339643Syokota * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2439643Syokota * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2539287Ssos * 2639287Ssos */ 2739287Ssos 28119420Sobrien#include <sys/cdefs.h> 29119420Sobrien__FBSDID("$FreeBSD: head/sys/dev/syscons/scvesactl.c 119420 2003-08-24 18:17:24Z obrien $"); 30119420Sobrien 3142504Syokota#include "opt_vga.h" 3239287Ssos 3356836Speter#ifndef VGA_NO_MODE_CHANGE 3439287Ssos 3539287Ssos#include <sys/param.h> 3639287Ssos#include <sys/systm.h> 3739668Syokota#include <sys/conf.h> 3839287Ssos#include <sys/tty.h> 3939287Ssos#include <sys/kernel.h> 4066859Sphk#include <sys/fbio.h> 4166859Sphk#include <sys/consio.h> 4239287Ssos 4339287Ssos#include <machine/pc/vesa.h> 4439287Ssos 4542504Syokota#include <dev/fb/fbreg.h> 4642504Syokota#include <dev/syscons/syscons.h> 4739287Ssos 4839667Syokotastatic d_ioctl_t *prev_user_ioctl; 4939287Ssos 5039667Syokotastatic int 5183366Sjulianvesa_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td) 5239287Ssos{ 5339287Ssos scr_stat *scp; 5439287Ssos struct tty *tp; 5539287Ssos int mode; 5639287Ssos 5751654Sphk tp = dev->si_tty; 5839287Ssos if (!tp) 5939287Ssos return ENXIO; 6051404Syokota scp = SC_STAT(tp->t_dev); 6139287Ssos 6239287Ssos switch (cmd) { 6339287Ssos 6439591Syokota /* generic text modes */ 6539591Syokota case SW_TEXT_132x25: case SW_TEXT_132x30: 6639591Syokota case SW_TEXT_132x43: case SW_TEXT_132x50: 6739591Syokota case SW_TEXT_132x60: 6848104Syokota if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE)) 6939591Syokota return ENODEV; 7039591Syokota return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0); 7139591Syokota 7239287Ssos /* text modes */ 7339287Ssos case SW_VESA_C80x60: 7439287Ssos case SW_VESA_C132x25: 7539287Ssos case SW_VESA_C132x43: 7639287Ssos case SW_VESA_C132x50: 7739287Ssos case SW_VESA_C132x60: 7848104Syokota if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE)) 7939287Ssos return ENODEV; 8039287Ssos mode = (cmd & 0xff) + M_VESA_BASE; 8139287Ssos return sc_set_text_mode(scp, tp, mode, 0, 0, 0); 8239287Ssos 8339287Ssos /* graphics modes */ 8439287Ssos case SW_VESA_32K_320: case SW_VESA_64K_320: 8539287Ssos case SW_VESA_FULL_320: 8639287Ssos 8739287Ssos case SW_VESA_CG640x400: 8839287Ssos 8939287Ssos case SW_VESA_CG640x480: 9039287Ssos case SW_VESA_32K_640: case SW_VESA_64K_640: 9139287Ssos case SW_VESA_FULL_640: 9239287Ssos 9339287Ssos case SW_VESA_800x600: case SW_VESA_CG800x600: 9439287Ssos case SW_VESA_32K_800: case SW_VESA_64K_800: 9539287Ssos case SW_VESA_FULL_800: 9639287Ssos 9739287Ssos case SW_VESA_1024x768: case SW_VESA_CG1024x768: 9839287Ssos case SW_VESA_32K_1024: case SW_VESA_64K_1024: 9939287Ssos case SW_VESA_FULL_1024: 10039287Ssos 10139287Ssos case SW_VESA_1280x1024: case SW_VESA_CG1280x1024: 10239287Ssos case SW_VESA_32K_1280: case SW_VESA_64K_1280: 10339287Ssos case SW_VESA_FULL_1280: 10448104Syokota if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE)) 10539287Ssos return ENODEV; 10639287Ssos mode = (cmd & 0xff) + M_VESA_BASE; 10739287Ssos return sc_set_graphics_mode(scp, tp, mode); 10839287Ssos } 10939287Ssos 11039287Ssos if (prev_user_ioctl) 11183366Sjulian return (*prev_user_ioctl)(dev, cmd, data, flag, td); 11239287Ssos else 11339287Ssos return ENOIOCTL; 11439287Ssos} 11539287Ssos 11639287Ssosint 11739287Ssosvesa_load_ioctl(void) 11839287Ssos{ 11939287Ssos if (prev_user_ioctl) 12039287Ssos return EBUSY; 12139287Ssos prev_user_ioctl = sc_user_ioctl; 12239287Ssos sc_user_ioctl = vesa_ioctl; 12339287Ssos return 0; 12439287Ssos} 12539287Ssos 12639287Ssosint 12739287Ssosvesa_unload_ioctl(void) 12839287Ssos{ 12939287Ssos if (sc_user_ioctl != vesa_ioctl) 13039287Ssos return EBUSY; 13139287Ssos sc_user_ioctl = prev_user_ioctl; 13239287Ssos prev_user_ioctl = NULL; 13339287Ssos return 0; 13439287Ssos} 13539287Ssos 13656836Speter#endif /* SC_NO_MODE_CHANGE */ 137