scvesactl.c revision 56836
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 *
2650477Speter * $FreeBSD: head/sys/dev/syscons/scvesactl.c 56836 2000-01-29 15:08:56Z peter $
2739287Ssos */
2839287Ssos
2942504Syokota#include "opt_vga.h"
3039287Ssos
3156836Speter#ifndef VGA_NO_MODE_CHANGE
3239287Ssos
3339287Ssos#include <sys/param.h>
3439287Ssos#include <sys/systm.h>
3539668Syokota#include <sys/conf.h>
3639287Ssos#include <sys/tty.h>
3739287Ssos#include <sys/kernel.h>
3839287Ssos
3939287Ssos#include <machine/console.h>
4039287Ssos#include <machine/pc/vesa.h>
4139287Ssos
4242504Syokota#include <dev/fb/fbreg.h>
4342504Syokota#include <dev/syscons/syscons.h>
4439287Ssos
4539667Syokotastatic d_ioctl_t *prev_user_ioctl;
4639287Ssos
4739667Syokotastatic int
4839667Syokotavesa_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
4939287Ssos{
5039287Ssos	scr_stat *scp;
5139287Ssos	struct tty *tp;
5239287Ssos	int mode;
5339287Ssos
5451654Sphk	tp = dev->si_tty;
5539287Ssos	if (!tp)
5639287Ssos		return ENXIO;
5751404Syokota	scp = SC_STAT(tp->t_dev);
5839287Ssos
5939287Ssos	switch (cmd) {
6039287Ssos
6139591Syokota	/* generic text modes */
6239591Syokota	case SW_TEXT_132x25: case SW_TEXT_132x30:
6339591Syokota	case SW_TEXT_132x43: case SW_TEXT_132x50:
6439591Syokota	case SW_TEXT_132x60:
6548104Syokota		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
6639591Syokota			return ENODEV;
6739591Syokota		return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
6839591Syokota
6939287Ssos	/* text modes */
7039287Ssos	case SW_VESA_C80x60:
7139287Ssos	case SW_VESA_C132x25:
7239287Ssos	case SW_VESA_C132x43:
7339287Ssos	case SW_VESA_C132x50:
7439287Ssos	case SW_VESA_C132x60:
7548104Syokota		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
7639287Ssos			return ENODEV;
7739287Ssos		mode = (cmd & 0xff) + M_VESA_BASE;
7839287Ssos		return sc_set_text_mode(scp, tp, mode, 0, 0, 0);
7939287Ssos
8039287Ssos	/* graphics modes */
8139287Ssos	case SW_VESA_32K_320: 	case SW_VESA_64K_320:
8239287Ssos	case SW_VESA_FULL_320:
8339287Ssos
8439287Ssos	case SW_VESA_CG640x400:
8539287Ssos
8639287Ssos	case SW_VESA_CG640x480:
8739287Ssos	case SW_VESA_32K_640:	case SW_VESA_64K_640:
8839287Ssos	case SW_VESA_FULL_640:
8939287Ssos
9039287Ssos	case SW_VESA_800x600:	case SW_VESA_CG800x600:
9139287Ssos	case SW_VESA_32K_800:	case SW_VESA_64K_800:
9239287Ssos	case SW_VESA_FULL_800:
9339287Ssos
9439287Ssos	case SW_VESA_1024x768:	case SW_VESA_CG1024x768:
9539287Ssos	case SW_VESA_32K_1024:	case SW_VESA_64K_1024:
9639287Ssos	case SW_VESA_FULL_1024:
9739287Ssos
9839287Ssos	case SW_VESA_1280x1024:	case SW_VESA_CG1280x1024:
9939287Ssos	case SW_VESA_32K_1280:	case SW_VESA_64K_1280:
10039287Ssos	case SW_VESA_FULL_1280:
10148104Syokota		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
10239287Ssos			return ENODEV;
10339287Ssos		mode = (cmd & 0xff) + M_VESA_BASE;
10439287Ssos		return sc_set_graphics_mode(scp, tp, mode);
10539287Ssos	}
10639287Ssos
10739287Ssos	if (prev_user_ioctl)
10839287Ssos		return (*prev_user_ioctl)(dev, cmd, data, flag, p);
10939287Ssos	else
11039287Ssos		return ENOIOCTL;
11139287Ssos}
11239287Ssos
11339287Ssosint
11439287Ssosvesa_load_ioctl(void)
11539287Ssos{
11639287Ssos	if (prev_user_ioctl)
11739287Ssos		return EBUSY;
11839287Ssos	prev_user_ioctl = sc_user_ioctl;
11939287Ssos	sc_user_ioctl = vesa_ioctl;
12039287Ssos	return 0;
12139287Ssos}
12239287Ssos
12339287Ssosint
12439287Ssosvesa_unload_ioctl(void)
12539287Ssos{
12639287Ssos	if (sc_user_ioctl != vesa_ioctl)
12739287Ssos		return EBUSY;
12839287Ssos	sc_user_ioctl = prev_user_ioctl;
12939287Ssos	prev_user_ioctl = NULL;
13039287Ssos	return 0;
13139287Ssos}
13239287Ssos
13356836Speter#endif	/* SC_NO_MODE_CHANGE */
134