1999-01-18 14:55:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999 FreeBSD(98) port team.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer as
|
|
|
|
* the first lines of this file unmodified.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1999-01-18 08:38:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_gdc.h"
|
|
|
|
#include "opt_fb.h"
|
|
|
|
#include "opt_syscons.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
|
|
|
|
#include <machine/console.h>
|
|
|
|
#include <machine/md_var.h>
|
|
|
|
#include <machine/pc/bios.h>
|
|
|
|
|
|
|
|
#include <dev/fb/fbreg.h>
|
|
|
|
|
|
|
|
#include <pc98/pc98/pc98.h>
|
|
|
|
#include <pc98/pc98/pc98_machdep.h>
|
1999-04-18 14:42:20 +00:00
|
|
|
#include <isa/isavar.h>
|
1999-01-18 08:38:08 +00:00
|
|
|
|
1999-01-18 14:55:38 +00:00
|
|
|
#define TEXT_GDC IO_GDC1 /* 0x60 */
|
|
|
|
#define ROW 25
|
|
|
|
#define COL 80
|
|
|
|
|
1999-01-18 08:38:08 +00:00
|
|
|
#define DRIVER_NAME "gdc"
|
|
|
|
|
|
|
|
/* cdev driver declaration */
|
|
|
|
|
|
|
|
#define GDC_UNIT(dev) minor(dev)
|
|
|
|
#define GDC_MKMINOR(unit) (unit)
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
typedef struct gdc_softc {
|
|
|
|
video_adapter_t *adp;
|
|
|
|
} gdc_softc_t;
|
|
|
|
|
|
|
|
#define GDC_SOFTC(unit) \
|
|
|
|
((gdc_softc_t *)devclass_get_softc(gdc_devclass, unit))
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
static devclass_t gdc_devclass;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
static int gdc_probe_unit(int unit, gdc_softc_t *sc, int flags);
|
|
|
|
static int gdc_attach_unit(int unit, gdc_softc_t *sc, int flags);
|
|
|
|
|
|
|
|
#if FB_INSTALL_CDEV
|
|
|
|
|
|
|
|
static d_open_t gdcopen;
|
|
|
|
static d_close_t gdcclose;
|
|
|
|
static d_read_t gdcread;
|
1999-06-24 10:51:40 +00:00
|
|
|
static d_write_t gdcwrite;
|
1999-01-18 08:38:08 +00:00
|
|
|
static d_ioctl_t gdcioctl;
|
1999-06-24 10:51:40 +00:00
|
|
|
static d_mmap_t gdcmmap;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
static struct cdevsw gdc_cdevsw = {
|
1999-05-30 16:53:49 +00:00
|
|
|
/* open */ gdcopen,
|
|
|
|
/* close */ gdcclose,
|
1999-06-24 10:51:40 +00:00
|
|
|
/* read */ gdcread,
|
|
|
|
/* write */ gdcwrite,
|
1999-05-30 16:53:49 +00:00
|
|
|
/* ioctl */ gdcioctl,
|
|
|
|
/* poll */ nopoll,
|
|
|
|
/* mmap */ nommap,
|
|
|
|
/* strategy */ nostrategy,
|
|
|
|
/* name */ DRIVER_NAME,
|
|
|
|
/* maj */ -1,
|
|
|
|
/* dump */ nodump,
|
|
|
|
/* psize */ nopsize,
|
|
|
|
/* flags */ 0,
|
|
|
|
/* bmaj */ -1
|
1999-01-18 08:38:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FB_INSTALL_CDEV */
|
|
|
|
|
2000-07-11 12:50:34 +00:00
|
|
|
static void
|
|
|
|
gdc_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
|
|
|
BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, DRIVER_NAME, 0);
|
|
|
|
}
|
|
|
|
|
1999-01-18 08:38:08 +00:00
|
|
|
static int
|
2000-07-12 10:15:43 +00:00
|
|
|
gdcprobe(device_t dev)
|
1999-01-18 08:38:08 +00:00
|
|
|
{
|
|
|
|
gdc_softc_t *sc;
|
|
|
|
|
1999-09-14 12:57:40 +00:00
|
|
|
/* Check isapnp ids */
|
|
|
|
if (isa_get_vendorid(dev))
|
|
|
|
return (ENXIO);
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
device_set_desc(dev, "Generic GDC");
|
|
|
|
sc = device_get_softc(dev);
|
1999-09-07 11:17:09 +00:00
|
|
|
return gdc_probe_unit(device_get_unit(dev), sc, device_get_flags(dev));
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-04-18 14:42:20 +00:00
|
|
|
gdc_attach(device_t dev)
|
1999-01-18 08:38:08 +00:00
|
|
|
{
|
|
|
|
gdc_softc_t *sc;
|
1999-06-24 10:51:40 +00:00
|
|
|
int error;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
sc = device_get_softc(dev);
|
1999-09-07 11:17:09 +00:00
|
|
|
error = gdc_attach_unit(device_get_unit(dev), sc, device_get_flags(dev));
|
1999-06-24 10:51:40 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
#ifdef FB_INSTALL_CDEV
|
|
|
|
/* attach a virtual frame buffer device */
|
|
|
|
error = fb_attach(makedev(0, GDC_MKMINOR(unit)), sc->adp, &gdc_cdevsw);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
#endif /* FB_INSTALL_CDEV */
|
|
|
|
|
|
|
|
if (bootverbose)
|
|
|
|
(*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose);
|
|
|
|
|
|
|
|
return 0;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdc_probe_unit(int unit, gdc_softc_t *sc, int flags)
|
|
|
|
{
|
|
|
|
video_switch_t *sw;
|
|
|
|
|
|
|
|
bzero(sc, sizeof(*sc));
|
|
|
|
sw = vid_get_switch(DRIVER_NAME);
|
|
|
|
if (sw == NULL)
|
1999-06-24 10:51:40 +00:00
|
|
|
return ENXIO;
|
1999-01-18 08:38:08 +00:00
|
|
|
return (*sw->probe)(unit, &sc->adp, NULL, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdc_attach_unit(int unit, gdc_softc_t *sc, int flags)
|
|
|
|
{
|
|
|
|
video_switch_t *sw;
|
|
|
|
|
|
|
|
sw = vid_get_switch(DRIVER_NAME);
|
|
|
|
if (sw == NULL)
|
|
|
|
return ENXIO;
|
1999-06-24 10:51:40 +00:00
|
|
|
return (*sw->init)(unit, sc->adp, flags);
|
|
|
|
}
|
1999-01-18 08:38:08 +00:00
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
/* cdev driver functions */
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
#ifdef FB_INSTALL_CDEV
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
static int
|
|
|
|
gdcopen(dev_t dev, int flag, int mode, struct proc *p)
|
|
|
|
{
|
|
|
|
gdc_softc_t *sc;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
sc = GDC_SOFTC(GDC_UNIT(dev));
|
|
|
|
if (sc == NULL)
|
|
|
|
return ENXIO;
|
|
|
|
if (mode & (O_CREAT | O_APPEND | O_TRUNC))
|
|
|
|
return ENODEV;
|
|
|
|
|
|
|
|
return genfbopen(&sc->gensc, sc->adp, flag, mode, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdcclose(dev_t dev, int flag, int mode, struct proc *p)
|
|
|
|
{
|
|
|
|
gdc_softc_t *sc;
|
|
|
|
|
|
|
|
sc = GDC_SOFTC(GDC_UNIT(dev));
|
|
|
|
return genfbclose(&sc->gensc, sc->adp, flag, mode, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdcread(dev_t dev, struct uio *uio, int flag)
|
|
|
|
{
|
|
|
|
gdc_softc_t *sc;
|
|
|
|
|
|
|
|
sc = GDC_SOFTC(GDC_UNIT(dev));
|
|
|
|
return genfbread(&sc->gensc, sc->adp, uio, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdcwrite(dev_t dev, struct uio *uio, int flag)
|
|
|
|
{
|
|
|
|
gdc_softc_t *sc;
|
|
|
|
|
|
|
|
sc = GDC_SOFTC(GDC_UNIT(dev));
|
|
|
|
return genfbread(&sc->gensc, sc->adp, uio, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdcioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p)
|
|
|
|
{
|
|
|
|
gdc_softc_t *sc;
|
|
|
|
|
|
|
|
sc = GDC_SOFTC(GDC_UNIT(dev));
|
|
|
|
return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, p);
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
static int
|
|
|
|
gdcmmap(dev_t dev, vm_offset_t offset, int prot)
|
|
|
|
{
|
|
|
|
gdc_softc_t *sc;
|
|
|
|
|
|
|
|
sc = GDC_SOFTC(GDC_UNIT(dev));
|
|
|
|
return genfbmmap(&sc->gensc, sc->adp, offset, prot);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* FB_INSTALL_CDEV */
|
|
|
|
|
2000-07-11 12:50:34 +00:00
|
|
|
static device_method_t gdc_methods[] = {
|
|
|
|
DEVMETHOD(device_identify, gdc_identify),
|
2000-07-12 10:15:43 +00:00
|
|
|
DEVMETHOD(device_probe, gdcprobe),
|
2000-07-11 12:50:34 +00:00
|
|
|
DEVMETHOD(device_attach, gdc_attach),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t gdcdriver = {
|
|
|
|
DRIVER_NAME,
|
|
|
|
gdc_methods,
|
|
|
|
sizeof(gdc_softc_t),
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(gdc, isa, gdcdriver, gdc_devclass, 0, 0);
|
|
|
|
|
1999-01-18 08:38:08 +00:00
|
|
|
/* LOW-LEVEL */
|
|
|
|
|
|
|
|
#include <machine/clock.h>
|
|
|
|
|
|
|
|
#include <pc98/pc98/30line.h>
|
|
|
|
|
|
|
|
#define TEXT_BUF_BASE 0x000a0000
|
|
|
|
#define TEXT_BUF_SIZE 0x00008000
|
|
|
|
#define GRAPHICS_BUF_BASE 0x000a8000
|
|
|
|
#define GRAPHICS_BUF_SIZE 0x00040000
|
|
|
|
#define VIDEO_BUF_BASE 0x000a0000
|
|
|
|
#define VIDEO_BUF_SIZE 0x00048000
|
|
|
|
|
|
|
|
#define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
|
|
|
|
#define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
|
|
|
|
#define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: `va_window' should have a virtual address, but is initialized
|
|
|
|
* with a physical address in the following table, they will be
|
|
|
|
* converted at run-time.
|
|
|
|
*/
|
|
|
|
static video_adapter_t adapter_init_value[] = {
|
|
|
|
{ 0,
|
|
|
|
KD_PC98, "gdc", /* va_type, va_name */
|
|
|
|
0, 0, /* va_unit, va_minor */
|
|
|
|
V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_BORDER,
|
|
|
|
IO_GDC1, 16, TEXT_GDC, /* va_io*, XXX */
|
|
|
|
VIDEO_BUF_BASE, VIDEO_BUF_SIZE, /* va_mem* */
|
1999-06-24 10:51:40 +00:00
|
|
|
TEXT_BUF_BASE, TEXT_BUF_SIZE, TEXT_BUF_SIZE, 0, /* va_window* */
|
1999-01-18 08:38:08 +00:00
|
|
|
0, 0, /* va_buffer, va_buffer_size */
|
1999-02-06 09:30:19 +00:00
|
|
|
0, M_PC98_80x25, 0, /* va_*mode* */
|
|
|
|
},
|
1999-01-18 08:38:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static video_adapter_t biosadapter[1];
|
|
|
|
|
|
|
|
/* video driver declarations */
|
|
|
|
static int gdc_configure(int flags);
|
|
|
|
static int gdc_nop(void);
|
1999-06-24 10:51:40 +00:00
|
|
|
static int gdc_err(video_adapter_t *adp, ...);
|
1999-01-18 08:38:08 +00:00
|
|
|
static vi_probe_t gdc_probe;
|
|
|
|
static vi_init_t gdc_init;
|
|
|
|
static vi_get_info_t gdc_get_info;
|
|
|
|
static vi_query_mode_t gdc_query_mode;
|
|
|
|
static vi_set_mode_t gdc_set_mode;
|
|
|
|
static vi_set_border_t gdc_set_border;
|
|
|
|
static vi_save_state_t gdc_save_state;
|
|
|
|
static vi_load_state_t gdc_load_state;
|
|
|
|
static vi_read_hw_cursor_t gdc_read_hw_cursor;
|
|
|
|
static vi_set_hw_cursor_t gdc_set_hw_cursor;
|
|
|
|
static vi_set_hw_cursor_shape_t gdc_set_hw_cursor_shape;
|
1999-06-24 10:51:40 +00:00
|
|
|
static vi_blank_display_t gdc_blank_display;
|
|
|
|
static vi_mmap_t gdc_mmap_buf;
|
|
|
|
static vi_ioctl_t gdc_dev_ioctl;
|
2000-04-27 13:34:32 +00:00
|
|
|
static vi_clear_t gdc_clear;
|
|
|
|
static vi_fill_rect_t gdc_fill_rect;
|
|
|
|
static vi_bitblt_t gdc_bitblt;
|
1999-01-18 08:38:08 +00:00
|
|
|
static vi_diag_t gdc_diag;
|
2000-04-27 13:34:32 +00:00
|
|
|
static vi_save_palette_t gdc_save_palette;
|
|
|
|
static vi_load_palette_t gdc_load_palette;
|
|
|
|
static vi_set_win_org_t gdc_set_origin;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
static video_switch_t gdcvidsw = {
|
|
|
|
gdc_probe,
|
|
|
|
gdc_init,
|
|
|
|
gdc_get_info,
|
|
|
|
gdc_query_mode,
|
|
|
|
gdc_set_mode,
|
|
|
|
(vi_save_font_t *)gdc_err,
|
|
|
|
(vi_load_font_t *)gdc_err,
|
|
|
|
(vi_show_font_t *)gdc_err,
|
2000-04-27 13:34:32 +00:00
|
|
|
gdc_save_palette,
|
|
|
|
gdc_load_palette,
|
1999-01-18 08:38:08 +00:00
|
|
|
gdc_set_border,
|
|
|
|
gdc_save_state,
|
|
|
|
gdc_load_state,
|
2000-04-27 13:34:32 +00:00
|
|
|
gdc_set_origin,
|
1999-01-18 08:38:08 +00:00
|
|
|
gdc_read_hw_cursor,
|
|
|
|
gdc_set_hw_cursor,
|
|
|
|
gdc_set_hw_cursor_shape,
|
1999-06-24 10:51:40 +00:00
|
|
|
gdc_blank_display,
|
|
|
|
gdc_mmap_buf,
|
|
|
|
gdc_dev_ioctl,
|
2000-04-27 13:34:32 +00:00
|
|
|
gdc_clear,
|
|
|
|
gdc_fill_rect,
|
|
|
|
gdc_bitblt,
|
1999-06-24 10:51:40 +00:00
|
|
|
(int (*)(void))gdc_err,
|
|
|
|
(int (*)(void))gdc_err,
|
1999-01-18 08:38:08 +00:00
|
|
|
gdc_diag,
|
|
|
|
};
|
|
|
|
|
|
|
|
VIDEO_DRIVER(gdc, gdcvidsw, gdc_configure);
|
|
|
|
|
|
|
|
/* GDC BIOS standard video modes */
|
|
|
|
#define EOT (-1)
|
|
|
|
#define NA (-2)
|
|
|
|
|
|
|
|
static video_info_t bios_vmode[] = {
|
|
|
|
{ M_PC98_80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
|
1999-06-24 10:51:40 +00:00
|
|
|
TEXT_BUF_BASE, TEXT_BUF_SIZE, TEXT_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
|
1999-01-18 08:38:08 +00:00
|
|
|
#ifdef LINE30
|
|
|
|
{ M_PC98_80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
|
1999-06-24 10:51:40 +00:00
|
|
|
TEXT_BUF_BASE, TEXT_BUF_SIZE, TEXT_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
|
2000-04-27 13:34:32 +00:00
|
|
|
#endif
|
|
|
|
#ifndef GDC_NOGRAPHICS
|
|
|
|
{ M_PC98_EGC640x400, V_INFO_COLOR | V_INFO_GRAPHICS,
|
|
|
|
640, 400, 8, 16, 4, 4,
|
|
|
|
GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
|
|
|
|
V_INFO_MM_OTHER },
|
|
|
|
{ M_PC98_PEGC640x400, V_INFO_COLOR | V_INFO_GRAPHICS | V_INFO_VESA,
|
|
|
|
640, 400, 8, 16, 8, 1,
|
|
|
|
GRAPHICS_BUF_BASE, 0x00008000, 0x00008000, 0, 0,
|
|
|
|
V_INFO_MM_PACKED, 1 },
|
|
|
|
#ifdef LINE30
|
|
|
|
{ M_PC98_PEGC640x480, V_INFO_COLOR | V_INFO_GRAPHICS | V_INFO_VESA,
|
|
|
|
640, 480, 8, 16, 8, 1,
|
|
|
|
GRAPHICS_BUF_BASE, 0x00008000, 0x00008000, 0, 0,
|
|
|
|
V_INFO_MM_PACKED, 1 },
|
|
|
|
#endif
|
1999-01-18 08:38:08 +00:00
|
|
|
#endif
|
|
|
|
{ EOT },
|
|
|
|
};
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
static int gdc_init_done = FALSE;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
/* local functions */
|
|
|
|
static int map_gen_mode_num(int type, int color, int mode);
|
|
|
|
static int probe_adapters(void);
|
|
|
|
static void dump_buffer(u_char *buf, size_t len);
|
|
|
|
|
|
|
|
#define prologue(adp, flag, err) \
|
1999-06-24 10:51:40 +00:00
|
|
|
if (!gdc_init_done || !((adp)->va_flags & (flag))) \
|
1999-01-18 08:38:08 +00:00
|
|
|
return (err)
|
|
|
|
|
|
|
|
/* a backdoor for the console driver */
|
|
|
|
static int
|
|
|
|
gdc_configure(int flags)
|
|
|
|
{
|
|
|
|
probe_adapters();
|
|
|
|
biosadapter[0].va_flags |= V_ADP_INITIALIZED;
|
|
|
|
if (!config_done(&biosadapter[0])) {
|
|
|
|
if (vid_register(&biosadapter[0]) < 0)
|
|
|
|
return 1;
|
|
|
|
biosadapter[0].va_flags |= V_ADP_REGISTERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* local subroutines */
|
|
|
|
|
|
|
|
/* map a generic video mode to a known mode number */
|
|
|
|
static int
|
|
|
|
map_gen_mode_num(int type, int color, int mode)
|
|
|
|
{
|
|
|
|
static struct {
|
|
|
|
int from;
|
|
|
|
int to;
|
|
|
|
} mode_map[] = {
|
|
|
|
{ M_TEXT_80x25, M_PC98_80x25, },
|
|
|
|
#ifdef LINE30
|
|
|
|
{ M_TEXT_80x30, M_PC98_80x30, },
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
|
|
|
|
if (mode_map[i].from == mode)
|
|
|
|
return mode_map[i].to;
|
|
|
|
}
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
static int
|
|
|
|
verify_adapter(video_adapter_t *adp)
|
|
|
|
{
|
|
|
|
#ifndef GDC_NOGRAPHICS
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (PC98_SYSTEM_PARAMETER(0x45c) & 0x40) { /* PEGC exists */
|
|
|
|
adp->va_flags |= V_ADP_VESA; /* XXX */
|
|
|
|
} else {
|
|
|
|
for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
|
|
|
|
if (bios_vmode[i].vi_flags & V_INFO_VESA)
|
|
|
|
bios_vmode[i].vi_mode = NA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-01-18 08:38:08 +00:00
|
|
|
/* probe video adapters and return the number of detected adapters */
|
|
|
|
static int
|
|
|
|
probe_adapters(void)
|
|
|
|
{
|
|
|
|
video_info_t info;
|
|
|
|
|
|
|
|
/* do this test only once */
|
1999-06-24 10:51:40 +00:00
|
|
|
if (gdc_init_done)
|
1999-01-18 08:38:08 +00:00
|
|
|
return 1;
|
1999-06-24 10:51:40 +00:00
|
|
|
gdc_init_done = TRUE;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
biosadapter[0] = adapter_init_value[0];
|
|
|
|
biosadapter[0].va_flags |= V_ADP_PROBED;
|
1999-01-18 14:47:01 +00:00
|
|
|
biosadapter[0].va_mode =
|
|
|
|
biosadapter[0].va_initial_mode = biosadapter[0].va_initial_bios_mode;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
gdc_get_info(&biosadapter[0], biosadapter[0].va_initial_mode, &info);
|
2000-04-27 13:34:32 +00:00
|
|
|
initialize_gdc(T25_G400, info.vi_flags & V_INFO_GRAPHICS);
|
|
|
|
|
1999-01-18 08:38:08 +00:00
|
|
|
biosadapter[0].va_window = BIOS_PADDRTOVADDR(info.vi_window);
|
|
|
|
biosadapter[0].va_window_size = info.vi_window_size;
|
|
|
|
biosadapter[0].va_window_gran = info.vi_window_gran;
|
|
|
|
biosadapter[0].va_buffer = 0;
|
|
|
|
biosadapter[0].va_buffer_size = 0;
|
1999-02-06 09:30:19 +00:00
|
|
|
if (info.vi_flags & V_INFO_GRAPHICS) {
|
|
|
|
switch (info.vi_depth/info.vi_planes) {
|
|
|
|
case 1:
|
|
|
|
biosadapter[0].va_line_width = info.vi_width/8;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
biosadapter[0].va_line_width = info.vi_width/4;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
biosadapter[0].va_line_width = info.vi_width/2;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
default: /* shouldn't happen */
|
|
|
|
biosadapter[0].va_line_width = info.vi_width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
biosadapter[0].va_line_width = info.vi_width;
|
|
|
|
}
|
|
|
|
bcopy(&info, &biosadapter[0].va_info, sizeof(info));
|
1999-01-18 08:38:08 +00:00
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
verify_adapter(&biosadapter[0]);
|
|
|
|
|
1999-01-18 08:38:08 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void master_gdc_cmd(unsigned int cmd)
|
|
|
|
{
|
|
|
|
while ( (inb(IO_GDC1) & 2) != 0);
|
|
|
|
outb(IO_GDC1+2, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void master_gdc_prm(unsigned int pmtr)
|
|
|
|
{
|
|
|
|
while ( (inb(IO_GDC1) & 2) != 0);
|
|
|
|
outb(IO_GDC1, pmtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void master_gdc_word_prm(unsigned int wpmtr)
|
|
|
|
{
|
|
|
|
master_gdc_prm(wpmtr & 0x00ff);
|
|
|
|
master_gdc_prm((wpmtr >> 8) & 0x00ff);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void master_gdc_fifo_empty(void)
|
|
|
|
{
|
|
|
|
while ( (inb(IO_GDC1) & 4) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void master_gdc_wait_vsync(void)
|
|
|
|
{
|
|
|
|
while ( (inb(IO_GDC1) & 0x20) != 0);
|
|
|
|
while ( (inb(IO_GDC1) & 0x20) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gdc_cmd(unsigned int cmd)
|
|
|
|
{
|
|
|
|
while ( (inb(IO_GDC2) & 2) != 0);
|
|
|
|
outb( IO_GDC2+2, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gdc_prm(unsigned int pmtr)
|
|
|
|
{
|
|
|
|
while ( (inb(IO_GDC2) & 2) != 0);
|
|
|
|
outb( IO_GDC2, pmtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gdc_word_prm(unsigned int wpmtr)
|
|
|
|
{
|
|
|
|
gdc_prm(wpmtr & 0x00ff);
|
|
|
|
gdc_prm((wpmtr >> 8) & 0x00ff);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gdc_fifo_empty(void)
|
|
|
|
{
|
|
|
|
while ( (inb(IO_GDC2) & 0x04) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gdc_wait_vsync(void)
|
|
|
|
{
|
|
|
|
while ( (inb(IO_GDC2) & 0x20) != 0);
|
|
|
|
while ( (inb(IO_GDC2) & 0x20) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_gdc_clock(void)
|
|
|
|
{
|
|
|
|
if ((inb(IO_SYSPORT) & 0x80) == 0){
|
|
|
|
return _5MHZ;
|
|
|
|
} else {
|
|
|
|
return _2_5MHZ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
static void initialize_gdc(unsigned int mode, int isGraph)
|
1999-01-18 08:38:08 +00:00
|
|
|
{
|
2000-04-27 13:34:32 +00:00
|
|
|
#ifdef LINE30
|
1999-01-18 08:38:08 +00:00
|
|
|
/* start 30line initialize */
|
2000-04-27 13:34:32 +00:00
|
|
|
int m_mode, s_mode, gdc_clock, hsync_clock;
|
|
|
|
|
1999-01-18 08:38:08 +00:00
|
|
|
gdc_clock = check_gdc_clock();
|
2000-04-27 13:34:32 +00:00
|
|
|
m_mode = (mode == T25_G400) ? _25L : _30L;
|
|
|
|
s_mode = 2*mode+gdc_clock;
|
|
|
|
gdc_INFO = m_mode;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
if ((PC98_SYSTEM_PARAMETER(0x597) & 0x80) ||
|
|
|
|
(PC98_SYSTEM_PARAMETER(0x458) & 0x80)) {
|
|
|
|
hsync_clock = (inb(0x9a8) & 1) ? _31KHZ : _24KHZ;
|
|
|
|
} else {
|
|
|
|
hsync_clock = _24KHZ;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
master_gdc_wait_vsync();
|
1999-01-18 08:38:08 +00:00
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
if ((gdc_clock == _2_5MHZ) &&
|
|
|
|
(slave_param[hsync_clock][s_mode][GDC_LF] > 400)) {
|
|
|
|
outb(0x6a, 0x83);
|
|
|
|
outb(0x6a, 0x85);
|
|
|
|
gdc_clock = _5MHZ;
|
|
|
|
s_mode = 2*mode+gdc_clock;
|
|
|
|
}
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
master_gdc_cmd(_GDC_RESET);
|
|
|
|
master_gdc_cmd(_GDC_MASTER);
|
|
|
|
gdc_cmd(_GDC_RESET);
|
|
|
|
gdc_cmd(_GDC_SLAVE);
|
|
|
|
|
|
|
|
/* GDC Master */
|
|
|
|
master_gdc_cmd(_GDC_SYNC);
|
|
|
|
master_gdc_prm(0x00); /* flush less */ /* text & graph */
|
2000-04-27 13:34:32 +00:00
|
|
|
master_gdc_prm(master_param[hsync_clock][m_mode][GDC_CR]);
|
|
|
|
master_gdc_word_prm(((master_param[hsync_clock][m_mode][GDC_HFP] << 10)
|
|
|
|
+ (master_param[hsync_clock][m_mode][GDC_VS] << 5)
|
|
|
|
+ master_param[hsync_clock][m_mode][GDC_HS]));
|
|
|
|
master_gdc_prm(master_param[hsync_clock][m_mode][GDC_HBP]);
|
|
|
|
master_gdc_prm(master_param[hsync_clock][m_mode][GDC_VFP]);
|
|
|
|
master_gdc_word_prm(((master_param[hsync_clock][m_mode][GDC_VBP] << 10)
|
|
|
|
+ (master_param[hsync_clock][m_mode][GDC_LF])));
|
1999-01-18 08:38:08 +00:00
|
|
|
master_gdc_fifo_empty();
|
|
|
|
master_gdc_cmd(_GDC_PITCH);
|
|
|
|
master_gdc_prm(MasterPCH);
|
|
|
|
master_gdc_fifo_empty();
|
|
|
|
|
|
|
|
/* GDC slave */
|
|
|
|
gdc_cmd(_GDC_SYNC);
|
|
|
|
gdc_prm(0x06);
|
2000-04-27 13:34:32 +00:00
|
|
|
gdc_prm(slave_param[hsync_clock][s_mode][GDC_CR]);
|
|
|
|
gdc_word_prm((slave_param[hsync_clock][s_mode][GDC_HFP] << 10)
|
|
|
|
+ (slave_param[hsync_clock][s_mode][GDC_VS] << 5)
|
|
|
|
+ (slave_param[hsync_clock][s_mode][GDC_HS]));
|
|
|
|
gdc_prm(slave_param[hsync_clock][s_mode][GDC_HBP]);
|
|
|
|
gdc_prm(slave_param[hsync_clock][s_mode][GDC_VFP]);
|
|
|
|
gdc_word_prm((slave_param[hsync_clock][s_mode][GDC_VBP] << 10)
|
|
|
|
+ (slave_param[hsync_clock][s_mode][GDC_LF]));
|
1999-01-18 08:38:08 +00:00
|
|
|
gdc_fifo_empty();
|
|
|
|
gdc_cmd(_GDC_PITCH);
|
|
|
|
gdc_prm(SlavePCH[gdc_clock]);
|
|
|
|
gdc_fifo_empty();
|
|
|
|
|
|
|
|
/* set Master GDC scroll param */
|
|
|
|
master_gdc_wait_vsync();
|
|
|
|
master_gdc_wait_vsync();
|
|
|
|
master_gdc_wait_vsync();
|
|
|
|
master_gdc_cmd(_GDC_SCROLL);
|
|
|
|
master_gdc_word_prm(0);
|
2000-04-27 13:34:32 +00:00
|
|
|
master_gdc_word_prm((master_param[hsync_clock][m_mode][GDC_LF] << 4)
|
|
|
|
| 0x0000);
|
1999-01-18 08:38:08 +00:00
|
|
|
master_gdc_fifo_empty();
|
|
|
|
|
|
|
|
/* set Slave GDC scroll param */
|
|
|
|
gdc_wait_vsync();
|
|
|
|
gdc_cmd(_GDC_SCROLL);
|
|
|
|
gdc_word_prm(0);
|
2000-04-27 13:34:32 +00:00
|
|
|
if (gdc_clock == _5MHZ) {
|
1999-01-18 08:38:08 +00:00
|
|
|
gdc_word_prm((SlaveScrlLF[mode] << 4) | 0x4000);
|
2000-04-27 13:34:32 +00:00
|
|
|
} else {
|
1999-01-18 08:38:08 +00:00
|
|
|
gdc_word_prm(SlaveScrlLF[mode] << 4);
|
|
|
|
}
|
|
|
|
gdc_fifo_empty();
|
|
|
|
|
|
|
|
gdc_word_prm(0);
|
2000-04-27 13:34:32 +00:00
|
|
|
if (gdc_clock == _5MHZ) {
|
1999-01-18 08:38:08 +00:00
|
|
|
gdc_word_prm((SlaveScrlLF[mode] << 4) | 0x4000);
|
2000-04-27 13:34:32 +00:00
|
|
|
} else {
|
1999-01-18 08:38:08 +00:00
|
|
|
gdc_word_prm(SlaveScrlLF[mode] << 4);
|
|
|
|
}
|
|
|
|
gdc_fifo_empty();
|
|
|
|
|
|
|
|
/* sync start */
|
2000-04-27 13:34:32 +00:00
|
|
|
gdc_cmd(isGraph ? _GDC_START : _GDC_STOP);
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
gdc_wait_vsync();
|
|
|
|
gdc_wait_vsync();
|
|
|
|
gdc_wait_vsync();
|
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
master_gdc_cmd(isGraph ? _GDC_STOP : _GDC_START);
|
|
|
|
#else
|
|
|
|
master_gdc_wait_vsync();
|
|
|
|
master_gdc_cmd(isGraph ? _GDC_STOP : _GDC_START); /* text */
|
|
|
|
gdc_wait_vsync();
|
|
|
|
gdc_cmd(isGraph ? _GDC_START : _GDC_STOP); /* graphics */
|
|
|
|
#endif
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
#ifndef GDC_NOGRAPHICS
|
|
|
|
static u_char b_palette[] = {
|
|
|
|
/* R G B */
|
|
|
|
0x00, 0x00, 0x00, /* 0 */
|
|
|
|
0x00, 0x00, 0x7f, /* 1 */
|
|
|
|
0x7f, 0x00, 0x00, /* 2 */
|
|
|
|
0x7f, 0x00, 0x7f, /* 3 */
|
|
|
|
0x00, 0x7f, 0x00, /* 4 */
|
|
|
|
0x00, 0x7f, 0x7f, /* 5 */
|
|
|
|
0x7f, 0x7f, 0x00, /* 6 */
|
|
|
|
0x7f, 0x7f, 0x7f, /* 7 */
|
|
|
|
0x40, 0x40, 0x40, /* 8 */
|
|
|
|
0x00, 0x00, 0xff, /* 9 */
|
|
|
|
0xff, 0x00, 0x00, /* 10 */
|
|
|
|
0xff, 0x00, 0xff, /* 11 */
|
|
|
|
0x00, 0xff, 0x00, /* 12 */
|
|
|
|
0x00, 0xff, 0xff, /* 13 */
|
|
|
|
0xff, 0xff, 0x00, /* 14 */
|
|
|
|
0xff, 0xff, 0xff, /* 15 */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdc_load_palette(video_adapter_t *adp, u_char *palette)
|
|
|
|
{
|
|
|
|
#ifndef GDC_NOGRAPHICS
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (adp->va_info.vi_flags & V_INFO_VESA) {
|
|
|
|
gdc_wait_vsync();
|
|
|
|
for (i = 0; i < 256; ++i) {
|
|
|
|
outb(0xa8, i);
|
|
|
|
outb(0xac, *palette++); /* R */
|
|
|
|
outb(0xaa, *palette++); /* G */
|
|
|
|
outb(0xae, *palette++); /* B */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* XXX - Even though PC-98 text color is independent of palette,
|
|
|
|
* we should set palette in text mode.
|
|
|
|
* Because the background color of text mode is palette 0's one.
|
|
|
|
*/
|
|
|
|
outb(0x6a, 1); /* 16 colors mode */
|
|
|
|
bcopy(palette, b_palette, sizeof(b_palette));
|
|
|
|
|
|
|
|
gdc_wait_vsync();
|
|
|
|
for (i = 0; i < 16; ++i) {
|
|
|
|
outb(0xa8, i);
|
|
|
|
outb(0xac, *palette++ >> 4); /* R */
|
|
|
|
outb(0xaa, *palette++ >> 4); /* G */
|
|
|
|
outb(0xae, *palette++ >> 4); /* B */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdc_save_palette(video_adapter_t *adp, u_char *palette)
|
|
|
|
{
|
|
|
|
#ifndef GDC_NOGRAPHICS
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (adp->va_info.vi_flags & V_INFO_VESA) {
|
|
|
|
for (i = 0; i < 256; ++i) {
|
|
|
|
outb(0xa8, i);
|
|
|
|
*palette++ = inb(0xac); /* R */
|
|
|
|
*palette++ = inb(0xaa); /* G */
|
|
|
|
*palette++ = inb(0xae); /* B */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bcopy(b_palette, palette, sizeof(b_palette));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdc_set_origin(video_adapter_t *adp, off_t offset)
|
|
|
|
{
|
|
|
|
#ifndef GDC_NOGRAPHICS
|
|
|
|
if (adp->va_info.vi_flags & V_INFO_VESA) {
|
|
|
|
writew(BIOS_PADDRTOVADDR(0x000e0004), offset >> 15);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
gdc_nop(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
/* entry points */
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
static int
|
|
|
|
gdc_err(video_adapter_t *adp, ...)
|
|
|
|
{
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
1999-01-18 08:38:08 +00:00
|
|
|
static int
|
|
|
|
gdc_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
|
|
|
|
{
|
|
|
|
probe_adapters();
|
|
|
|
if (unit >= 1)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
*adpp = &biosadapter[unit];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdc_init(int unit, video_adapter_t *adp, int flags)
|
|
|
|
{
|
|
|
|
if ((unit >= 1) || (adp == NULL) || !probe_done(adp))
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
if (!init_done(adp)) {
|
|
|
|
/* nothing to do really... */
|
|
|
|
adp->va_flags |= V_ADP_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!config_done(adp)) {
|
|
|
|
if (vid_register(adp) < 0)
|
|
|
|
return ENXIO;
|
|
|
|
adp->va_flags |= V_ADP_REGISTERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_info():
|
|
|
|
* Return the video_info structure of the requested video mode.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_get_info(video_adapter_t *adp, int mode, video_info_t *info)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
if (!gdc_init_done)
|
|
|
|
return ENXIO;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode);
|
|
|
|
for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
|
|
|
|
if (bios_vmode[i].vi_mode == NA)
|
|
|
|
continue;
|
|
|
|
if (mode == bios_vmode[i].vi_mode) {
|
|
|
|
*info = bios_vmode[i];
|
1999-06-24 10:51:40 +00:00
|
|
|
info->vi_buffer_size = info->vi_window_size*info->vi_planes;
|
1999-01-18 08:38:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
1999-06-24 10:51:40 +00:00
|
|
|
return EINVAL;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* query_mode():
|
|
|
|
* Find a video mode matching the requested parameters.
|
|
|
|
* Fields filled with 0 are considered "don't care" fields and
|
|
|
|
* match any modes.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_query_mode(video_adapter_t *adp, video_info_t *info)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
if (!gdc_init_done)
|
1999-12-09 12:32:50 +00:00
|
|
|
return ENXIO;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
|
|
|
|
if (bios_vmode[i].vi_mode == NA)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((info->vi_width != 0)
|
|
|
|
&& (info->vi_width != bios_vmode[i].vi_width))
|
|
|
|
continue;
|
|
|
|
if ((info->vi_height != 0)
|
|
|
|
&& (info->vi_height != bios_vmode[i].vi_height))
|
|
|
|
continue;
|
|
|
|
if ((info->vi_cwidth != 0)
|
|
|
|
&& (info->vi_cwidth != bios_vmode[i].vi_cwidth))
|
|
|
|
continue;
|
|
|
|
if ((info->vi_cheight != 0)
|
|
|
|
&& (info->vi_cheight != bios_vmode[i].vi_cheight))
|
|
|
|
continue;
|
|
|
|
if ((info->vi_depth != 0)
|
|
|
|
&& (info->vi_depth != bios_vmode[i].vi_depth))
|
|
|
|
continue;
|
|
|
|
if ((info->vi_planes != 0)
|
|
|
|
&& (info->vi_planes != bios_vmode[i].vi_planes))
|
|
|
|
continue;
|
|
|
|
/* XXX: should check pixel format, memory model */
|
|
|
|
if ((info->vi_flags != 0)
|
|
|
|
&& (info->vi_flags != bios_vmode[i].vi_flags))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* verify if this mode is supported on this adapter */
|
1999-12-09 12:32:50 +00:00
|
|
|
if (gdc_get_info(adp, bios_vmode[i].vi_mode, info))
|
1999-01-18 08:38:08 +00:00
|
|
|
continue;
|
1999-12-09 12:32:50 +00:00
|
|
|
return 0;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
1999-12-09 12:32:50 +00:00
|
|
|
return ENODEV;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set_mode():
|
|
|
|
* Change the video mode.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_set_mode(video_adapter_t *adp, int mode)
|
|
|
|
{
|
|
|
|
video_info_t info;
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
prologue(adp, V_ADP_MODECHANGE, ENODEV);
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
mode = map_gen_mode_num(adp->va_type,
|
|
|
|
adp->va_flags & V_ADP_COLOR, mode);
|
|
|
|
if (gdc_get_info(adp, mode, &info))
|
1999-06-24 10:51:40 +00:00
|
|
|
return EINVAL;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
1999-03-02 12:34:24 +00:00
|
|
|
switch (info.vi_mode) {
|
2000-04-27 13:34:32 +00:00
|
|
|
#ifndef GDC_NOGRAPHICS
|
|
|
|
case M_PC98_PEGC640x480: /* PEGC 640x480 */
|
|
|
|
initialize_gdc(T30_G480, info.vi_flags & V_INFO_GRAPHICS);
|
|
|
|
break;
|
|
|
|
case M_PC98_PEGC640x400: /* PEGC 640x400 */
|
|
|
|
case M_PC98_EGC640x400: /* EGC GRAPHICS */
|
|
|
|
#endif
|
|
|
|
case M_PC98_80x25: /* VGA TEXT */
|
|
|
|
initialize_gdc(T25_G400, info.vi_flags & V_INFO_GRAPHICS);
|
|
|
|
break;
|
|
|
|
case M_PC98_80x30: /* VGA TEXT */
|
|
|
|
initialize_gdc(T30_G400, info.vi_flags & V_INFO_GRAPHICS);
|
|
|
|
break;
|
1999-01-18 08:38:08 +00:00
|
|
|
default:
|
2000-04-27 13:34:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef GDC_NOGRAPHICS
|
|
|
|
if (info.vi_flags & V_INFO_VESA) {
|
|
|
|
outb(0x6a, 0x07); /* enable mode F/F change */
|
|
|
|
outb(0x6a, 0x21); /* enhanced graphics */
|
|
|
|
if (info.vi_height > 400)
|
|
|
|
outb(0x6a, 0x69); /* 800 lines */
|
|
|
|
writeb(BIOS_PADDRTOVADDR(0x000e0100), 0); /* packed pixel */
|
|
|
|
} else {
|
|
|
|
if (adp->va_flags & V_ADP_VESA) {
|
|
|
|
outb(0x6a, 0x07); /* enable mode F/F change */
|
|
|
|
outb(0x6a, 0x20); /* normal graphics */
|
|
|
|
outb(0x6a, 0x68); /* 400 lines */
|
|
|
|
}
|
|
|
|
outb(0x6a, 1); /* 16 colors */
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
adp->va_mode = mode;
|
|
|
|
adp->va_flags &= ~V_ADP_COLOR;
|
|
|
|
adp->va_flags |=
|
|
|
|
(info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
|
|
|
|
#if 0
|
|
|
|
adp->va_crtc_addr =
|
|
|
|
(adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
|
|
|
|
#endif
|
|
|
|
adp->va_window = BIOS_PADDRTOVADDR(info.vi_window);
|
|
|
|
adp->va_window_size = info.vi_window_size;
|
|
|
|
adp->va_window_gran = info.vi_window_gran;
|
|
|
|
if (info.vi_buffer_size == 0) {
|
|
|
|
adp->va_buffer = 0;
|
|
|
|
adp->va_buffer_size = 0;
|
|
|
|
} else {
|
|
|
|
adp->va_buffer = BIOS_PADDRTOVADDR(info.vi_buffer);
|
|
|
|
adp->va_buffer_size = info.vi_buffer_size;
|
|
|
|
}
|
1999-02-06 09:30:19 +00:00
|
|
|
if (info.vi_flags & V_INFO_GRAPHICS) {
|
|
|
|
switch (info.vi_depth/info.vi_planes) {
|
|
|
|
case 1:
|
|
|
|
adp->va_line_width = info.vi_width/8;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
adp->va_line_width = info.vi_width/4;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
adp->va_line_width = info.vi_width/2;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
default: /* shouldn't happen */
|
|
|
|
adp->va_line_width = info.vi_width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
adp->va_line_width = info.vi_width;
|
|
|
|
}
|
|
|
|
bcopy(&info, &adp->va_info, sizeof(info));
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
/* move hardware cursor out of the way */
|
|
|
|
(*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set_border():
|
|
|
|
* Change the border color.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_set_border(video_adapter_t *adp, int color)
|
|
|
|
{
|
|
|
|
outb(0x6c, color << 4);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* save_state():
|
|
|
|
* Read video card register values.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_save_state(video_adapter_t *adp, void *p, size_t size)
|
|
|
|
{
|
1999-06-24 10:51:40 +00:00
|
|
|
return ENODEV;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load_state():
|
|
|
|
* Set video card registers at once.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_load_state(video_adapter_t *adp, void *p)
|
|
|
|
{
|
1999-06-24 10:51:40 +00:00
|
|
|
return ENODEV;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read_hw_cursor():
|
|
|
|
* Read the position of the hardware text cursor.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
|
|
|
|
{
|
|
|
|
u_int16_t off;
|
|
|
|
int s;
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
if (!gdc_init_done)
|
|
|
|
return ENXIO;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
1999-02-06 09:30:19 +00:00
|
|
|
if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
|
1999-06-24 10:51:40 +00:00
|
|
|
return ENODEV;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
master_gdc_cmd(0xe0); /* _GDC_CSRR */
|
|
|
|
while((inb(TEXT_GDC + 0) & 0x1) == 0) {} /* GDC wait */
|
|
|
|
off = inb(TEXT_GDC + 2); /* EADl */
|
|
|
|
off |= (inb(TEXT_GDC + 2) << 8); /* EADh */
|
|
|
|
inb(TEXT_GDC + 2); /* dummy */
|
|
|
|
inb(TEXT_GDC + 2); /* dummy */
|
|
|
|
inb(TEXT_GDC + 2); /* dummy */
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if (off >= ROW*COL)
|
|
|
|
off = 0;
|
1999-02-06 09:30:19 +00:00
|
|
|
*row = off / adp->va_info.vi_width;
|
|
|
|
*col = off % adp->va_info.vi_width;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set_hw_cursor():
|
|
|
|
* Move the hardware text cursor. If col and row are both -1,
|
|
|
|
* the cursor won't be shown.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_set_hw_cursor(video_adapter_t *adp, int col, int row)
|
|
|
|
{
|
|
|
|
u_int16_t off;
|
|
|
|
int s;
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
if (!gdc_init_done)
|
|
|
|
return ENXIO;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
if ((col == -1) && (row == -1)) {
|
|
|
|
off = -1;
|
|
|
|
} else {
|
1999-02-06 09:30:19 +00:00
|
|
|
if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
|
1999-06-24 10:51:40 +00:00
|
|
|
return ENODEV;
|
1999-02-06 09:30:19 +00:00
|
|
|
off = row*adp->va_info.vi_width + col;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
master_gdc_cmd(0x49); /* _GDC_CSRW */
|
|
|
|
master_gdc_word_prm(off);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set_hw_cursor_shape():
|
|
|
|
* Change the shape of the hardware text cursor. If the height is zero
|
|
|
|
* or negative, the cursor won't be shown.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
|
|
|
|
int celsize, int blink)
|
|
|
|
{
|
|
|
|
int start;
|
|
|
|
int end;
|
|
|
|
int s;
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
if (!gdc_init_done)
|
|
|
|
return ENXIO;
|
|
|
|
|
1999-01-18 08:38:08 +00:00
|
|
|
start = celsize - (base + height);
|
|
|
|
end = celsize - base - 1;
|
|
|
|
/*
|
|
|
|
* muPD7220 GDC has anomaly that if end == celsize - 1 then start
|
|
|
|
* must be 0, otherwise the cursor won't be correctly shown
|
|
|
|
* in the first row in the screen. We shall set end to celsize - 2;
|
|
|
|
* if end == celsize -1 && start > 0. XXX
|
|
|
|
*/
|
|
|
|
if ((end == celsize - 1) && (start > 0))
|
|
|
|
--end;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
master_gdc_cmd(0x4b); /* _GDC_CSRFORM */
|
|
|
|
master_gdc_prm(((height > 0) ? 0x80 : 0) /* cursor on/off */
|
1999-06-24 10:51:40 +00:00
|
|
|
| ((celsize - 1) & 0x1f)); /* cel size */
|
1999-01-18 08:38:08 +00:00
|
|
|
master_gdc_word_prm(((end & 0x1f) << 11) /* end line */
|
|
|
|
| (12 << 6) /* blink rate */
|
|
|
|
| (blink ? 0x20 : 0) /* blink on/off */
|
|
|
|
| (start & 0x1f)); /* start line */
|
|
|
|
splx(s);
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
return 0;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
/*
|
|
|
|
* blank_display()
|
|
|
|
* Put the display in power save/power off mode.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_blank_display(video_adapter_t *adp, int mode)
|
1999-01-18 08:38:08 +00:00
|
|
|
{
|
1999-06-24 10:51:40 +00:00
|
|
|
int s;
|
2000-03-29 12:29:27 +00:00
|
|
|
static int standby = 0;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
if (!gdc_init_done)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
switch (mode) {
|
|
|
|
case V_DISPLAY_SUSPEND:
|
|
|
|
case V_DISPLAY_STAND_BY:
|
2000-03-29 12:29:27 +00:00
|
|
|
outb(0x09a2, 0x80 | 0x40); /* V/H-SYNC mask */
|
|
|
|
if (inb(0x09a2) == (0x80 | 0x40))
|
|
|
|
standby = 1;
|
1999-06-24 10:51:40 +00:00
|
|
|
/* FALL THROUGH */
|
|
|
|
|
|
|
|
case V_DISPLAY_BLANK:
|
1999-07-03 08:44:32 +00:00
|
|
|
if (epson_machine_id == 0x20) {
|
1999-06-24 10:51:40 +00:00
|
|
|
outb(0x43f, 0x42);
|
1999-07-03 08:44:32 +00:00
|
|
|
outb(0xc17, inb(0xc17) & ~0x08); /* turn off side light */
|
|
|
|
outb(0xc16, inb(0xc16) & ~0x02); /* turn off back light */
|
1999-06-24 10:51:40 +00:00
|
|
|
outb(0x43f, 0x40);
|
|
|
|
} else {
|
|
|
|
while (!(inb(TEXT_GDC) & 0x20)) /* V-SYNC wait */
|
|
|
|
;
|
2000-03-29 12:29:27 +00:00
|
|
|
outb(TEXT_GDC + 8, 0x0e); /* DISP off */
|
1999-06-24 10:51:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case V_DISPLAY_ON:
|
1999-07-03 08:44:32 +00:00
|
|
|
if (epson_machine_id == 0x20) {
|
1999-06-24 10:51:40 +00:00
|
|
|
outb(0x43f, 0x42);
|
|
|
|
outb(0xc17, inb(0xc17) | 0x08);
|
|
|
|
outb(0xc16, inb(0xc16) | 0x02);
|
|
|
|
outb(0x43f, 0x40);
|
|
|
|
} else {
|
|
|
|
while (!(inb(TEXT_GDC) & 0x20)) /* V-SYNC wait */
|
|
|
|
;
|
2000-03-29 12:29:27 +00:00
|
|
|
outb(TEXT_GDC + 8, 0x0f); /* DISP on */
|
|
|
|
}
|
|
|
|
if (standby) {
|
|
|
|
outb(0x09a2, 0x00); /* V/H-SYNC unmask */
|
|
|
|
standby = 0;
|
1999-06-24 10:51:40 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
1999-06-24 10:51:40 +00:00
|
|
|
splx(s);
|
|
|
|
return 0;
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mmap():
|
|
|
|
* Mmap frame buffer.
|
|
|
|
*/
|
|
|
|
static int
|
1999-06-24 10:51:40 +00:00
|
|
|
gdc_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot)
|
1999-01-18 08:38:08 +00:00
|
|
|
{
|
1999-06-24 10:51:40 +00:00
|
|
|
/* FIXME: is this correct? XXX */
|
|
|
|
if (offset > VIDEO_BUF_SIZE - PAGE_SIZE)
|
1999-01-18 08:38:08 +00:00
|
|
|
return -1;
|
1999-06-24 10:51:40 +00:00
|
|
|
return i386_btop(adp->va_info.vi_window + offset);
|
|
|
|
}
|
|
|
|
|
2000-04-27 13:34:32 +00:00
|
|
|
static int
|
|
|
|
gdc_clear(video_adapter_t *adp)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdc_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
|
|
|
|
{
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdc_bitblt(video_adapter_t *adp,...)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
static int
|
|
|
|
gdc_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case FBIO_GETWINORG: /* get frame buffer window origin */
|
|
|
|
*(u_int *)arg = 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case FBIO_SETWINORG: /* set frame buffer window origin */
|
|
|
|
case FBIO_SETDISPSTART: /* set display start address */
|
|
|
|
case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
|
|
|
|
case FBIO_GETPALETTE: /* get color palette */
|
|
|
|
case FBIO_SETPALETTE: /* set color palette */
|
|
|
|
case FBIOGETCMAP: /* get color palette */
|
|
|
|
case FBIOPUTCMAP: /* set color palette */
|
|
|
|
return ENODEV;
|
|
|
|
|
|
|
|
case FBIOGTYPE: /* get frame buffer type info. */
|
|
|
|
((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
|
|
|
|
((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
|
|
|
|
((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
|
|
|
|
((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
|
|
|
|
if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
|
|
|
|
((struct fbtype *)arg)->fb_cmsize = 0;
|
|
|
|
else
|
|
|
|
((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
|
|
|
|
((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return fb_commonioctl(adp, cmd, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_buffer(u_char *buf, size_t len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < len;) {
|
|
|
|
printf("%02x ", buf[i]);
|
|
|
|
if ((++i % 16) == 0)
|
|
|
|
printf("\n");
|
|
|
|
}
|
1999-01-18 08:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* diag():
|
|
|
|
* Print some information about the video adapter and video modes,
|
|
|
|
* with requested level of details.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
gdc_diag(video_adapter_t *adp, int level)
|
|
|
|
{
|
1999-01-28 11:24:36 +00:00
|
|
|
#if FB_DEBUG > 1
|
1999-01-18 08:38:08 +00:00
|
|
|
int i;
|
1999-01-28 11:24:36 +00:00
|
|
|
#endif
|
1999-01-18 08:38:08 +00:00
|
|
|
|
1999-06-24 10:51:40 +00:00
|
|
|
if (!gdc_init_done)
|
|
|
|
return ENXIO;
|
1999-01-18 08:38:08 +00:00
|
|
|
|
|
|
|
fb_dump_adp_info(DRIVER_NAME, adp, level);
|
|
|
|
|
|
|
|
#if FB_DEBUG > 1
|
|
|
|
for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
|
|
|
|
if (bios_vmode[i].vi_mode == NA)
|
|
|
|
continue;
|
|
|
|
if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
|
|
|
|
continue;
|
|
|
|
fb_dump_mode_info(DRIVER_NAME, adp, &bios_vmode[i], level);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|