2000-03-23 10:01:25 +03:00
|
|
|
/* $NetBSD: vga.c,v 1.26 2000/03/23 07:01:33 thorpej Exp $ */
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Chris G. Demetriou
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1998-03-22 18:11:49 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
|
1998-05-28 20:48:40 +04:00
|
|
|
#include <dev/ic/mc6845reg.h>
|
|
|
|
#include <dev/ic/pcdisplayvar.h>
|
|
|
|
#include <dev/ic/vgareg.h>
|
|
|
|
#include <dev/ic/vgavar.h>
|
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
#include <dev/wscons/wsdisplayvar.h>
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
1999-02-20 21:27:53 +03:00
|
|
|
#include <dev/wscons/unicode.h>
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1998-05-15 00:49:55 +04:00
|
|
|
#include <dev/ic/pcdisplay.h>
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1999-04-01 15:52:42 +04:00
|
|
|
#include "opt_wsdisplay_compat.h" /* for WSCONS_SUPPORT_PCVTFONTS */
|
|
|
|
|
1999-01-13 19:48:58 +03:00
|
|
|
static struct vgafont {
|
|
|
|
char name[16];
|
|
|
|
int height;
|
|
|
|
int encoding;
|
|
|
|
#ifdef notyet
|
|
|
|
int firstchar, numchars;
|
|
|
|
#endif
|
|
|
|
int slot;
|
|
|
|
} vga_builtinfont = {
|
|
|
|
"builtin",
|
|
|
|
16,
|
|
|
|
WSDISPLAY_FONTENC_IBM,
|
|
|
|
#ifdef notyet
|
|
|
|
0, 256,
|
|
|
|
#endif
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
struct vgascreen {
|
1998-05-28 20:48:40 +04:00
|
|
|
struct pcdisplayscreen pcs;
|
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
LIST_ENTRY(vgascreen) next;
|
|
|
|
|
|
|
|
struct vga_config *cfg;
|
|
|
|
|
|
|
|
/* videostate */
|
1999-01-13 19:48:58 +03:00
|
|
|
struct vgafont *fontset1, *fontset2;
|
1998-03-22 18:11:49 +03:00
|
|
|
/* font data */
|
|
|
|
/* palette */
|
1998-07-24 20:20:14 +04:00
|
|
|
|
|
|
|
int mindispoffset, maxdispoffset;
|
1998-03-22 18:11:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct vga_config {
|
|
|
|
struct vga_handle hdl;
|
|
|
|
|
|
|
|
int nscreens;
|
|
|
|
LIST_HEAD(, vgascreen) screens;
|
|
|
|
struct vgascreen *active; /* current display */
|
1999-01-09 18:29:26 +03:00
|
|
|
const struct wsscreen_descr *currenttype;
|
1999-01-13 19:48:58 +03:00
|
|
|
int currentfontset1, currentfontset2;
|
1998-06-12 22:41:01 +04:00
|
|
|
|
|
|
|
int vc_biosmapped;
|
|
|
|
bus_space_tag_t vc_biostag;
|
|
|
|
bus_space_handle_t vc_bioshdl;
|
1999-01-13 19:48:58 +03:00
|
|
|
|
|
|
|
struct vgafont *vc_fonts[8];
|
1999-12-06 21:54:50 +03:00
|
|
|
|
|
|
|
struct vgascreen *wantedscreen;
|
|
|
|
void (*switchcb) __P((void *, int, int));
|
|
|
|
void *switchcbarg;
|
2000-03-23 10:01:25 +03:00
|
|
|
|
|
|
|
struct callout vc_switch_callout;
|
1998-03-22 18:11:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static int vgaconsole, vga_console_type, vga_console_attached;
|
|
|
|
static struct vgascreen vga_console_screen;
|
|
|
|
static struct vga_config vga_console_vc;
|
|
|
|
|
1999-01-13 19:48:58 +03:00
|
|
|
int vga_selectfont __P((struct vga_config *, struct vgascreen *,
|
|
|
|
char *, char *));
|
1998-05-28 20:48:40 +04:00
|
|
|
void vga_init_screen __P((struct vga_config *, struct vgascreen *,
|
|
|
|
const struct wsscreen_descr *,
|
1998-05-15 00:49:55 +04:00
|
|
|
int, long *));
|
1998-03-22 18:11:49 +03:00
|
|
|
void vga_init __P((struct vga_config *, bus_space_tag_t,
|
|
|
|
bus_space_tag_t));
|
1999-01-13 19:48:58 +03:00
|
|
|
static void vga_setfont __P((struct vga_config *, struct vgascreen *));
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1999-02-12 14:25:23 +03:00
|
|
|
static int vga_mapchar __P((void *, int, unsigned int *));
|
1998-05-15 00:49:55 +04:00
|
|
|
static int vga_alloc_attr __P((void *, int, int, int, long *));
|
1998-07-24 20:20:14 +04:00
|
|
|
void vga_copyrows __P((void *, int, int, int));
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
const struct wsdisplay_emulops vga_emulops = {
|
1998-05-28 20:48:40 +04:00
|
|
|
pcdisplay_cursor,
|
1999-01-13 19:48:58 +03:00
|
|
|
vga_mapchar,
|
1998-06-21 01:55:05 +04:00
|
|
|
pcdisplay_putchar,
|
1998-05-28 20:48:40 +04:00
|
|
|
pcdisplay_copycols,
|
|
|
|
pcdisplay_erasecols,
|
1998-07-24 20:20:14 +04:00
|
|
|
vga_copyrows,
|
1998-05-28 20:48:40 +04:00
|
|
|
pcdisplay_eraserows,
|
1998-05-15 00:49:55 +04:00
|
|
|
vga_alloc_attr
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* translate WS(=ANSI) color codes to standard pc ones
|
|
|
|
*/
|
1998-06-21 01:55:05 +04:00
|
|
|
static unsigned char fgansitopc[] = {
|
1998-05-15 00:49:55 +04:00
|
|
|
#ifdef __alpha__
|
|
|
|
/*
|
|
|
|
* XXX DEC HAS SWITCHED THE CODES FOR BLUE AND RED!!!
|
|
|
|
* XXX We should probably not bother with this
|
|
|
|
* XXX (reinitialize the palette registers).
|
|
|
|
*/
|
|
|
|
FG_BLACK, FG_BLUE, FG_GREEN, FG_CYAN, FG_RED,
|
|
|
|
FG_MAGENTA, FG_BROWN, FG_LIGHTGREY
|
|
|
|
#else
|
|
|
|
FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
|
|
|
|
FG_MAGENTA, FG_CYAN, FG_LIGHTGREY
|
|
|
|
#endif
|
|
|
|
}, bgansitopc[] = {
|
|
|
|
#ifdef __alpha__
|
|
|
|
BG_BLACK, BG_BLUE, BG_GREEN, BG_CYAN, BG_RED,
|
|
|
|
BG_MAGENTA, BG_BROWN, BG_LIGHTGREY
|
|
|
|
#else
|
|
|
|
BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
|
|
|
|
BG_MAGENTA, BG_CYAN, BG_LIGHTGREY
|
|
|
|
#endif
|
1998-03-22 18:11:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct wsscreen_descr vga_stdscreen = {
|
|
|
|
"80x25", 80, 25,
|
|
|
|
&vga_emulops,
|
1998-05-15 00:49:55 +04:00
|
|
|
8, 16,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
|
|
|
|
}, vga_stdscreen_mono = {
|
|
|
|
"80x25", 80, 25,
|
|
|
|
&vga_emulops,
|
|
|
|
8, 16,
|
|
|
|
WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
|
1999-01-13 19:48:58 +03:00
|
|
|
}, vga_stdscreen_bf = {
|
|
|
|
"80x25bf", 80, 25,
|
|
|
|
&vga_emulops,
|
|
|
|
8, 16,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_BLINK
|
1999-04-10 18:02:11 +04:00
|
|
|
}, vga_40lscreen = {
|
|
|
|
"80x40", 80, 40,
|
|
|
|
&vga_emulops,
|
|
|
|
8, 10,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
|
|
|
|
}, vga_40lscreen_mono = {
|
|
|
|
"80x40", 80, 40,
|
|
|
|
&vga_emulops,
|
|
|
|
8, 10,
|
|
|
|
WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
|
|
|
|
}, vga_40lscreen_bf = {
|
|
|
|
"80x40bf", 80, 40,
|
|
|
|
&vga_emulops,
|
|
|
|
8, 10,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_BLINK
|
1999-01-13 19:48:58 +03:00
|
|
|
}, vga_50lscreen = {
|
1998-03-22 18:11:49 +03:00
|
|
|
"80x50", 80, 50,
|
|
|
|
&vga_emulops,
|
1998-05-15 00:49:55 +04:00
|
|
|
8, 8,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
|
|
|
|
}, vga_50lscreen_mono = {
|
|
|
|
"80x50", 80, 50,
|
|
|
|
&vga_emulops,
|
|
|
|
8, 8,
|
|
|
|
WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
|
1999-01-13 19:48:58 +03:00
|
|
|
}, vga_50lscreen_bf = {
|
|
|
|
"80x50bf", 80, 50,
|
|
|
|
&vga_emulops,
|
|
|
|
8, 8,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_BLINK
|
1998-03-22 18:11:49 +03:00
|
|
|
};
|
|
|
|
|
1999-01-13 19:48:58 +03:00
|
|
|
#define VGA_SCREEN_CANTWOFONTS(type) (!((type)->capabilities & WSSCREEN_HILIT))
|
|
|
|
|
1998-04-07 20:35:42 +04:00
|
|
|
const struct wsscreen_descr *_vga_scrlist[] = {
|
1998-03-22 18:11:49 +03:00
|
|
|
&vga_stdscreen,
|
1999-01-13 19:48:58 +03:00
|
|
|
&vga_stdscreen_bf,
|
1999-04-10 18:02:11 +04:00
|
|
|
&vga_40lscreen,
|
|
|
|
&vga_40lscreen_bf,
|
1998-03-22 18:11:49 +03:00
|
|
|
&vga_50lscreen,
|
1999-01-13 19:48:58 +03:00
|
|
|
&vga_50lscreen_bf,
|
1998-03-22 18:11:49 +03:00
|
|
|
/* XXX other formats, graphics screen? */
|
1998-05-15 00:49:55 +04:00
|
|
|
}, *_vga_scrlist_mono[] = {
|
|
|
|
&vga_stdscreen_mono,
|
1999-04-10 18:02:11 +04:00
|
|
|
&vga_40lscreen_mono,
|
1998-05-15 00:49:55 +04:00
|
|
|
&vga_50lscreen_mono,
|
|
|
|
/* XXX other formats, graphics screen? */
|
1998-03-22 18:11:49 +03:00
|
|
|
};
|
|
|
|
|
1998-05-15 00:49:55 +04:00
|
|
|
const struct wsscreen_list vga_screenlist = {
|
|
|
|
sizeof(_vga_scrlist) / sizeof(struct wsscreen_descr *),
|
|
|
|
_vga_scrlist
|
|
|
|
}, vga_screenlist_mono = {
|
|
|
|
sizeof(_vga_scrlist_mono) / sizeof(struct wsscreen_descr *),
|
|
|
|
_vga_scrlist_mono
|
1998-03-22 18:11:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static int vga_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
|
|
|
|
static int vga_mmap __P((void *, off_t, int));
|
|
|
|
static int vga_alloc_screen __P((void *, const struct wsscreen_descr *,
|
1998-05-15 00:49:55 +04:00
|
|
|
void **, int *, int *, long *));
|
1998-03-22 18:11:49 +03:00
|
|
|
static void vga_free_screen __P((void *, void *));
|
1999-12-06 21:54:50 +03:00
|
|
|
static int vga_show_screen __P((void *, void *, int,
|
|
|
|
void (*) (void *, int, int), void *));
|
1999-01-13 19:48:58 +03:00
|
|
|
static int vga_load_font __P((void *, void *, struct wsdisplay_font *));
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1999-12-06 21:54:50 +03:00
|
|
|
void vga_doswitch __P((struct vga_config *));
|
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
const struct wsdisplay_accessops vga_accessops = {
|
|
|
|
vga_ioctl,
|
|
|
|
vga_mmap,
|
|
|
|
vga_alloc_screen,
|
|
|
|
vga_free_screen,
|
|
|
|
vga_show_screen,
|
|
|
|
vga_load_font
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following functions implement back-end configuration grabbing
|
|
|
|
* and attachment.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vga_common_probe(iot, memt)
|
|
|
|
bus_space_tag_t iot, memt;
|
|
|
|
{
|
|
|
|
bus_space_handle_t ioh_vga, ioh_6845, memh;
|
1998-05-28 20:48:40 +04:00
|
|
|
u_int8_t regval;
|
1998-03-22 18:11:49 +03:00
|
|
|
u_int16_t vgadata;
|
|
|
|
int gotio_vga, gotio_6845, gotmem, mono, rv;
|
|
|
|
int dispoffset;
|
|
|
|
|
|
|
|
gotio_vga = gotio_6845 = gotmem = rv = 0;
|
|
|
|
|
|
|
|
if (bus_space_map(iot, 0x3c0, 0x10, 0, &ioh_vga))
|
|
|
|
goto bad;
|
|
|
|
gotio_vga = 1;
|
|
|
|
|
|
|
|
/* read "misc output register" */
|
1998-05-28 20:48:40 +04:00
|
|
|
regval = bus_space_read_1(iot, ioh_vga, 0xc);
|
|
|
|
mono = !(regval & 1);
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
if (bus_space_map(iot, (mono ? 0x3b0 : 0x3d0), 0x10, 0, &ioh_6845))
|
|
|
|
goto bad;
|
|
|
|
gotio_6845 = 1;
|
|
|
|
|
|
|
|
if (bus_space_map(memt, 0xa0000, 0x20000, 0, &memh))
|
|
|
|
goto bad;
|
|
|
|
gotmem = 1;
|
|
|
|
|
|
|
|
dispoffset = (mono ? 0x10000 : 0x18000);
|
|
|
|
|
|
|
|
vgadata = bus_space_read_2(memt, memh, dispoffset);
|
|
|
|
bus_space_write_2(memt, memh, dispoffset, 0xa55a);
|
1998-05-28 20:48:40 +04:00
|
|
|
if (bus_space_read_2(memt, memh, dispoffset) != 0xa55a)
|
|
|
|
goto bad;
|
1998-03-22 18:11:49 +03:00
|
|
|
bus_space_write_2(memt, memh, dispoffset, vgadata);
|
|
|
|
|
1998-05-28 20:48:40 +04:00
|
|
|
/*
|
|
|
|
* check if this is really a VGA
|
|
|
|
* (try to write "Color Select" register as XFree86 does)
|
|
|
|
* XXX check before if at least EGA?
|
|
|
|
*/
|
|
|
|
/* reset state */
|
|
|
|
(void) bus_space_read_1(iot, ioh_6845, 10);
|
|
|
|
bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
|
|
|
|
20 | 0x20); /* colselect | enable */
|
|
|
|
regval = bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR);
|
|
|
|
/* toggle the implemented bits */
|
|
|
|
bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval ^ 0x0f);
|
|
|
|
bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
|
|
|
|
20 | 0x20);
|
|
|
|
/* read back */
|
|
|
|
if (bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR) != (regval ^ 0x0f))
|
|
|
|
goto bad;
|
|
|
|
/* restore contents */
|
|
|
|
bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval);
|
|
|
|
|
|
|
|
rv = 1;
|
1998-03-22 18:11:49 +03:00
|
|
|
bad:
|
|
|
|
if (gotio_vga)
|
|
|
|
bus_space_unmap(iot, ioh_vga, 0x10);
|
|
|
|
if (gotio_6845)
|
|
|
|
bus_space_unmap(iot, ioh_6845, 0x10);
|
|
|
|
if (gotmem)
|
|
|
|
bus_space_unmap(memt, memh, 0x20000);
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
1999-01-13 19:48:58 +03:00
|
|
|
/*
|
1999-03-22 21:24:23 +03:00
|
|
|
* We want at least ASCII 32..127 be present in the
|
|
|
|
* first font slot.
|
1999-01-13 19:48:58 +03:00
|
|
|
*/
|
|
|
|
#define vga_valid_primary_font(f) \
|
|
|
|
(f->encoding == WSDISPLAY_FONTENC_IBM || \
|
|
|
|
f->encoding == WSDISPLAY_FONTENC_ISO)
|
|
|
|
|
|
|
|
int
|
|
|
|
vga_selectfont(vc, scr, name1, name2)
|
|
|
|
struct vga_config *vc;
|
|
|
|
struct vgascreen *scr;
|
1999-03-22 21:24:23 +03:00
|
|
|
char *name1, *name2; /* NULL: take first found */
|
1999-01-13 19:48:58 +03:00
|
|
|
{
|
|
|
|
const struct wsscreen_descr *type = scr->pcs.type;
|
|
|
|
struct vgafont *f1, *f2;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
f1 = f2 = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
struct vgafont *f = vc->vc_fonts[i];
|
|
|
|
if (!f || f->height != type->fontheight)
|
|
|
|
continue;
|
|
|
|
if (!f1 &&
|
|
|
|
vga_valid_primary_font(f) &&
|
|
|
|
(!name1 || !strcmp(name1, f->name))) {
|
|
|
|
f1 = f;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!f2 &&
|
|
|
|
VGA_SCREEN_CANTWOFONTS(type) &&
|
|
|
|
(!name2 || !strcmp(name2, f->name))) {
|
|
|
|
f2 = f;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-22 21:24:23 +03:00
|
|
|
/*
|
|
|
|
* The request fails if no primary font was found,
|
|
|
|
* or if a second font was requested but not found.
|
|
|
|
*/
|
1999-01-13 19:48:58 +03:00
|
|
|
if (f1 && (!name2 || f2)) {
|
|
|
|
#ifdef VGAFONTDEBUG
|
|
|
|
if (scr != &vga_console_screen || vga_console_attached) {
|
|
|
|
printf("vga (%s): font1=%s (slot %d)", type->name,
|
|
|
|
f1->name, f1->slot);
|
|
|
|
if (f2)
|
|
|
|
printf(", font2=%s (slot %d)",
|
|
|
|
f2->name, f2->slot);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
scr->fontset1 = f1;
|
|
|
|
scr->fontset2 = f2;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
void
|
1998-05-28 20:48:40 +04:00
|
|
|
vga_init_screen(vc, scr, type, existing, attrp)
|
|
|
|
struct vga_config *vc;
|
1998-03-22 18:11:49 +03:00
|
|
|
struct vgascreen *scr;
|
|
|
|
const struct wsscreen_descr *type;
|
|
|
|
int existing;
|
1998-05-15 00:49:55 +04:00
|
|
|
long *attrp;
|
1998-03-22 18:11:49 +03:00
|
|
|
{
|
1998-07-24 20:20:14 +04:00
|
|
|
int cpos;
|
1998-05-15 00:49:55 +04:00
|
|
|
int res;
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1998-05-28 20:48:40 +04:00
|
|
|
scr->cfg = vc;
|
|
|
|
scr->pcs.hdl = (struct pcdisplay_handle *)&vc->hdl;
|
|
|
|
scr->pcs.type = type;
|
|
|
|
scr->pcs.active = 0;
|
1998-07-24 20:20:14 +04:00
|
|
|
scr->mindispoffset = 0;
|
|
|
|
scr->maxdispoffset = 0x8000 - type->nrows * type->ncols * 2;
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
if (existing) {
|
|
|
|
cpos = vga_6845_read(&vc->hdl, cursorh) << 8;
|
|
|
|
cpos |= vga_6845_read(&vc->hdl, cursorl);
|
|
|
|
|
|
|
|
/* make sure we have a valid cursor position */
|
|
|
|
if (cpos < 0 || cpos >= type->nrows * type->ncols)
|
|
|
|
cpos = 0;
|
1998-07-24 20:20:14 +04:00
|
|
|
|
|
|
|
scr->pcs.dispoffset = vga_6845_read(&vc->hdl, startadrh) << 9;
|
|
|
|
scr->pcs.dispoffset |= vga_6845_read(&vc->hdl, startadrl) << 1;
|
|
|
|
|
|
|
|
/* make sure we have a valid memory offset */
|
|
|
|
if (scr->pcs.dispoffset < scr->mindispoffset ||
|
|
|
|
scr->pcs.dispoffset > scr->maxdispoffset)
|
|
|
|
scr->pcs.dispoffset = scr->mindispoffset;
|
|
|
|
} else {
|
|
|
|
cpos = 0;
|
|
|
|
scr->pcs.dispoffset = scr->mindispoffset;
|
1998-03-22 18:11:49 +03:00
|
|
|
}
|
|
|
|
|
1998-05-28 20:48:40 +04:00
|
|
|
scr->pcs.vc_crow = cpos / type->ncols;
|
|
|
|
scr->pcs.vc_ccol = cpos % type->ncols;
|
2000-01-25 05:44:03 +03:00
|
|
|
pcdisplay_cursor_init(&scr->pcs, existing);
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
#ifdef __alpha__
|
1998-05-28 20:48:40 +04:00
|
|
|
if (!vc->hdl.vh_mono)
|
1998-05-15 00:49:55 +04:00
|
|
|
/*
|
|
|
|
* DEC firmware uses a blue background.
|
|
|
|
*/
|
|
|
|
res = vga_alloc_attr(scr, WSCOL_WHITE, WSCOL_BLUE,
|
|
|
|
WSATTR_WSCOLORS, attrp);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
res = vga_alloc_attr(scr, 0, 0, 0, attrp);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (res)
|
|
|
|
panic("vga_init_screen: attribute botch");
|
1998-03-22 18:11:49 +03:00
|
|
|
#endif
|
|
|
|
|
1998-05-28 20:48:40 +04:00
|
|
|
scr->pcs.mem = NULL;
|
1999-03-22 21:24:23 +03:00
|
|
|
|
|
|
|
scr->fontset1 = scr->fontset2 = 0;
|
1999-01-13 19:48:58 +03:00
|
|
|
if (vga_selectfont(vc, scr, 0, 0)) {
|
|
|
|
if (scr == &vga_console_screen)
|
|
|
|
panic("vga_init_screen: no font");
|
|
|
|
else
|
|
|
|
printf("vga_init_screen: no font\n");
|
|
|
|
}
|
1999-03-22 21:24:23 +03:00
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
vc->nscreens++;
|
|
|
|
LIST_INSERT_HEAD(&vc->screens, scr, next);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vga_init(vc, iot, memt)
|
|
|
|
struct vga_config *vc;
|
|
|
|
bus_space_tag_t iot, memt;
|
|
|
|
{
|
|
|
|
struct vga_handle *vh = &vc->hdl;
|
|
|
|
u_int8_t mor;
|
1999-01-13 19:48:58 +03:00
|
|
|
int i;
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
vh->vh_iot = iot;
|
|
|
|
vh->vh_memt = memt;
|
|
|
|
|
|
|
|
if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
|
|
|
|
panic("vga_common_setup: couldn't map vga io");
|
|
|
|
|
|
|
|
/* read "misc output register" */
|
|
|
|
mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, 0xc);
|
1998-05-28 20:48:40 +04:00
|
|
|
vh->vh_mono = !(mor & 1);
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1998-05-28 20:48:40 +04:00
|
|
|
if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
|
1998-03-22 18:11:49 +03:00
|
|
|
&vh->vh_ioh_6845))
|
|
|
|
panic("vga_common_setup: couldn't map 6845 io");
|
|
|
|
|
|
|
|
if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 0, &vh->vh_allmemh))
|
|
|
|
panic("vga_common_setup: couldn't map memory");
|
|
|
|
|
|
|
|
if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh,
|
1998-05-28 20:48:40 +04:00
|
|
|
(vh->vh_mono ? 0x10000 : 0x18000), 0x8000,
|
1998-03-22 18:11:49 +03:00
|
|
|
&vh->vh_memh))
|
|
|
|
panic("vga_common_setup: mem subrange failed");
|
|
|
|
|
1998-06-12 22:41:01 +04:00
|
|
|
/* should only reserve the space (no need to map - save KVM) */
|
|
|
|
vc->vc_biostag = memt;
|
|
|
|
if (bus_space_map(vc->vc_biostag, 0xc0000, 0x8000, 0,
|
|
|
|
&vc->vc_bioshdl))
|
|
|
|
vc->vc_biosmapped = 0;
|
|
|
|
else
|
|
|
|
vc->vc_biosmapped = 1;
|
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
vc->nscreens = 0;
|
|
|
|
LIST_INIT(&vc->screens);
|
|
|
|
vc->active = NULL;
|
1999-01-09 18:29:26 +03:00
|
|
|
vc->currenttype = vh->vh_mono ? &vga_stdscreen_mono : &vga_stdscreen;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_init(&vc->vc_switch_callout);
|
1999-01-13 19:48:58 +03:00
|
|
|
|
|
|
|
vc->vc_fonts[0] = &vga_builtinfont;
|
1999-12-13 17:04:06 +03:00
|
|
|
for (i = 1; i < 8; i++)
|
1999-01-13 19:48:58 +03:00
|
|
|
vc->vc_fonts[i] = 0;
|
|
|
|
|
|
|
|
vc->currentfontset1 = vc->currentfontset2 = 0;
|
1998-03-22 18:11:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vga_common_attach(self, iot, memt, type)
|
|
|
|
struct device *self;
|
|
|
|
bus_space_tag_t iot, memt;
|
|
|
|
int type;
|
|
|
|
{
|
|
|
|
int console;
|
|
|
|
struct vga_config *vc;
|
|
|
|
struct wsemuldisplaydev_attach_args aa;
|
|
|
|
|
|
|
|
console = vga_is_console(iot, type);
|
|
|
|
|
|
|
|
if (console) {
|
|
|
|
vc = &vga_console_vc;
|
|
|
|
vga_console_attached = 1;
|
|
|
|
} else {
|
|
|
|
vc = malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK);
|
|
|
|
vga_init(vc, iot, memt);
|
|
|
|
}
|
|
|
|
|
|
|
|
aa.console = console;
|
1998-05-28 20:48:40 +04:00
|
|
|
aa.scrdata = (vc->hdl.vh_mono ? &vga_screenlist_mono : &vga_screenlist);
|
1998-03-22 18:11:49 +03:00
|
|
|
aa.accessops = &vga_accessops;
|
|
|
|
aa.accesscookie = vc;
|
|
|
|
|
|
|
|
config_found(self, &aa, wsemuldisplaydevprint);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vga_cnattach(iot, memt, type, check)
|
|
|
|
bus_space_tag_t iot, memt;
|
|
|
|
int type, check;
|
|
|
|
{
|
1998-05-15 00:49:55 +04:00
|
|
|
long defattr;
|
|
|
|
const struct wsscreen_descr *scr;
|
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
if (check && !vga_common_probe(iot, memt))
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/* set up bus-independent VGA configuration */
|
|
|
|
vga_init(&vga_console_vc, iot, memt);
|
1999-01-09 18:29:26 +03:00
|
|
|
scr = vga_console_vc.currenttype;
|
1998-05-28 20:48:40 +04:00
|
|
|
vga_init_screen(&vga_console_vc, &vga_console_screen, scr, 1, &defattr);
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1998-05-28 20:48:40 +04:00
|
|
|
vga_console_screen.pcs.active = 1;
|
1998-03-22 18:11:49 +03:00
|
|
|
vga_console_vc.active = &vga_console_screen;
|
|
|
|
|
1998-05-15 00:49:55 +04:00
|
|
|
wsdisplay_cnattach(scr, &vga_console_screen,
|
1998-05-28 20:48:40 +04:00
|
|
|
vga_console_screen.pcs.vc_ccol,
|
|
|
|
vga_console_screen.pcs.vc_crow,
|
1998-05-15 00:49:55 +04:00
|
|
|
defattr);
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
vgaconsole = 1;
|
|
|
|
vga_console_type = type;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vga_is_console(iot, type)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
int type;
|
|
|
|
{
|
|
|
|
if (vgaconsole &&
|
|
|
|
!vga_console_attached &&
|
|
|
|
iot == vga_console_vc.hdl.vh_iot &&
|
|
|
|
(vga_console_type == -1 || (type == vga_console_type)))
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vga_ioctl(v, cmd, data, flag, p)
|
|
|
|
void *v;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
struct vga_config *vc = v;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
#if 0
|
|
|
|
case WSDISPLAYIO_GTYPE:
|
|
|
|
*(int *)data = vc->vc_type;
|
|
|
|
/* XXX should get detailed hardware information here */
|
|
|
|
return 0;
|
1998-12-30 16:54:03 +03:00
|
|
|
#else
|
|
|
|
case WSDISPLAYIO_GTYPE:
|
|
|
|
*(int *)data = WSDISPLAY_TYPE_UNKNOWN;
|
|
|
|
return 0;
|
1998-03-22 18:11:49 +03:00
|
|
|
#endif
|
1999-01-13 19:48:58 +03:00
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
case WSDISPLAYIO_GINFO:
|
|
|
|
case WSDISPLAYIO_GETCMAP:
|
|
|
|
case WSDISPLAYIO_PUTCMAP:
|
|
|
|
case WSDISPLAYIO_GVIDEO:
|
|
|
|
case WSDISPLAYIO_SVIDEO:
|
|
|
|
case WSDISPLAYIO_GCURPOS:
|
|
|
|
case WSDISPLAYIO_SCURPOS:
|
|
|
|
case WSDISPLAYIO_GCURMAX:
|
|
|
|
case WSDISPLAYIO_GCURSOR:
|
|
|
|
case WSDISPLAYIO_SCURSOR:
|
|
|
|
/* NONE of these operations are by the generic VGA driver. */
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
1999-01-13 19:48:58 +03:00
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vga_mmap(v, offset, prot)
|
|
|
|
void *v;
|
|
|
|
off_t offset;
|
|
|
|
int prot;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-05-15 00:49:55 +04:00
|
|
|
vga_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
|
1998-03-22 18:11:49 +03:00
|
|
|
void *v;
|
|
|
|
const struct wsscreen_descr *type;
|
|
|
|
void **cookiep;
|
|
|
|
int *curxp, *curyp;
|
1998-05-15 00:49:55 +04:00
|
|
|
long *defattrp;
|
1998-03-22 18:11:49 +03:00
|
|
|
{
|
|
|
|
struct vga_config *vc = v;
|
|
|
|
struct vgascreen *scr;
|
|
|
|
|
|
|
|
if (vc->nscreens == 1) {
|
|
|
|
/*
|
|
|
|
* When allocating the second screen, get backing store
|
|
|
|
* for the first one too.
|
|
|
|
* XXX We could be more clever and use video RAM.
|
|
|
|
*/
|
1998-05-28 20:48:40 +04:00
|
|
|
vc->screens.lh_first->pcs.mem =
|
1998-03-22 18:11:49 +03:00
|
|
|
malloc(type->ncols * type->nrows * 2, M_DEVBUF, M_WAITOK);
|
|
|
|
}
|
|
|
|
|
|
|
|
scr = malloc(sizeof(struct vgascreen), M_DEVBUF, M_WAITOK);
|
1998-05-28 20:48:40 +04:00
|
|
|
vga_init_screen(vc, scr, type, vc->nscreens == 0, defattrp);
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1998-05-28 20:48:40 +04:00
|
|
|
if (vc->nscreens == 1) {
|
|
|
|
scr->pcs.active = 1;
|
1998-03-22 18:11:49 +03:00
|
|
|
vc->active = scr;
|
1999-01-09 18:29:26 +03:00
|
|
|
vc->currenttype = type;
|
1998-05-28 20:48:40 +04:00
|
|
|
} else {
|
|
|
|
scr->pcs.mem = malloc(type->ncols * type->nrows * 2,
|
|
|
|
M_DEVBUF, M_WAITOK);
|
|
|
|
pcdisplay_eraserows(&scr->pcs, 0, type->nrows, *defattrp);
|
1998-03-22 18:11:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
*cookiep = scr;
|
1998-05-28 20:48:40 +04:00
|
|
|
*curxp = scr->pcs.vc_ccol;
|
|
|
|
*curyp = scr->pcs.vc_crow;
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vga_free_screen(v, cookie)
|
|
|
|
void *v;
|
|
|
|
void *cookie;
|
|
|
|
{
|
|
|
|
struct vgascreen *vs = cookie;
|
1999-01-09 18:29:26 +03:00
|
|
|
struct vga_config *vc = vs->cfg;
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
LIST_REMOVE(vs, next);
|
|
|
|
if (vs != &vga_console_screen)
|
|
|
|
free(vs, M_DEVBUF);
|
|
|
|
else
|
|
|
|
panic("vga_free_screen: console");
|
1999-01-09 18:29:26 +03:00
|
|
|
|
|
|
|
if (vc->active == vs)
|
|
|
|
vc->active = 0;
|
1998-03-22 18:11:49 +03:00
|
|
|
}
|
|
|
|
|
1999-01-13 19:48:58 +03:00
|
|
|
static void
|
|
|
|
vga_setfont(vc, scr)
|
|
|
|
struct vga_config *vc;
|
|
|
|
struct vgascreen *scr;
|
|
|
|
{
|
|
|
|
int fontslot1, fontslot2;
|
|
|
|
|
|
|
|
fontslot1 = (scr->fontset1 ? scr->fontset1->slot : 0);
|
|
|
|
fontslot2 = (scr->fontset2 ? scr->fontset2->slot : fontslot1);
|
|
|
|
if (vc->currentfontset1 != fontslot1 ||
|
|
|
|
vc->currentfontset2 != fontslot2) {
|
|
|
|
vga_setfontset(&vc->hdl, fontslot1, fontslot2);
|
|
|
|
vc->currentfontset1 = fontslot1;
|
|
|
|
vc->currentfontset2 = fontslot2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-06 21:54:50 +03:00
|
|
|
int
|
|
|
|
vga_show_screen(v, cookie, waitok, cb, cbarg)
|
1998-03-22 18:11:49 +03:00
|
|
|
void *v;
|
|
|
|
void *cookie;
|
1999-12-06 21:54:50 +03:00
|
|
|
int waitok;
|
|
|
|
void (*cb) __P((void *, int, int));
|
|
|
|
void *cbarg;
|
1998-03-22 18:11:49 +03:00
|
|
|
{
|
1998-05-28 20:48:40 +04:00
|
|
|
struct vgascreen *scr = cookie, *oldscr;
|
1998-03-22 18:11:49 +03:00
|
|
|
struct vga_config *vc = scr->cfg;
|
1999-12-06 21:54:50 +03:00
|
|
|
|
|
|
|
oldscr = vc->active; /* can be NULL! */
|
|
|
|
if (scr == oldscr) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
vc->wantedscreen = cookie;
|
|
|
|
vc->switchcb = cb;
|
|
|
|
vc->switchcbarg = cbarg;
|
|
|
|
if (cb) {
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&vc->vc_switch_callout, 0,
|
|
|
|
(void(*)(void *))vga_doswitch, vc);
|
1999-12-06 21:54:50 +03:00
|
|
|
return (EAGAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
vga_doswitch(vc);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vga_doswitch(vc)
|
|
|
|
struct vga_config *vc;
|
|
|
|
{
|
|
|
|
struct vgascreen *scr, *oldscr;
|
1998-03-22 18:11:49 +03:00
|
|
|
struct vga_handle *vh = &vc->hdl;
|
1999-12-06 21:54:50 +03:00
|
|
|
const struct wsscreen_descr *type;
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1999-12-06 21:54:50 +03:00
|
|
|
scr = vc->wantedscreen;
|
|
|
|
if (!scr) {
|
|
|
|
printf("vga_doswitch: disappeared\n");
|
|
|
|
(*vc->switchcb)(vc->switchcbarg, EIO, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
type = scr->pcs.type;
|
1999-01-09 18:29:26 +03:00
|
|
|
oldscr = vc->active; /* can be NULL! */
|
1998-05-28 20:48:40 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1999-01-09 18:29:26 +03:00
|
|
|
if (oldscr) {
|
|
|
|
if (!oldscr->pcs.active)
|
|
|
|
panic("vga_show_screen: not active");
|
|
|
|
if (oldscr->pcs.type != vc->currenttype)
|
|
|
|
panic("vga_show_screen: bad type");
|
|
|
|
}
|
1998-05-28 20:48:40 +04:00
|
|
|
#endif
|
|
|
|
if (scr == oldscr) {
|
1998-03-22 18:11:49 +03:00
|
|
|
return;
|
1998-05-28 20:48:40 +04:00
|
|
|
}
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (scr->pcs.active)
|
|
|
|
panic("vga_show_screen: active");
|
|
|
|
#endif
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1999-01-09 18:29:26 +03:00
|
|
|
if (oldscr) {
|
|
|
|
const struct wsscreen_descr *oldtype = oldscr->pcs.type;
|
1998-05-28 20:48:40 +04:00
|
|
|
|
1999-01-09 18:29:26 +03:00
|
|
|
oldscr->pcs.active = 0;
|
|
|
|
bus_space_read_region_2(vh->vh_memt, vh->vh_memh,
|
|
|
|
oldscr->pcs.dispoffset, oldscr->pcs.mem,
|
|
|
|
oldtype->ncols * oldtype->nrows);
|
|
|
|
}
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1999-01-09 18:29:26 +03:00
|
|
|
if (vc->currenttype != type) {
|
1998-05-28 20:48:40 +04:00
|
|
|
vga_setscreentype(vh, type);
|
1999-01-09 18:29:26 +03:00
|
|
|
vc->currenttype = type;
|
|
|
|
}
|
1999-01-13 19:48:58 +03:00
|
|
|
|
|
|
|
vga_setfont(vc, scr);
|
1999-01-09 18:29:26 +03:00
|
|
|
/* XXX swich colours! */
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1998-07-24 20:20:14 +04:00
|
|
|
scr->pcs.dispoffset = scr->mindispoffset;
|
1999-01-09 18:29:26 +03:00
|
|
|
if (!oldscr || (scr->pcs.dispoffset != oldscr->pcs.dispoffset)) {
|
1998-07-24 20:20:14 +04:00
|
|
|
vga_6845_write(vh, startadrh, scr->pcs.dispoffset >> 9);
|
|
|
|
vga_6845_write(vh, startadrl, scr->pcs.dispoffset >> 1);
|
|
|
|
}
|
|
|
|
|
1999-01-09 18:29:26 +03:00
|
|
|
bus_space_write_region_2(vh->vh_memt, vh->vh_memh,
|
|
|
|
scr->pcs.dispoffset, scr->pcs.mem,
|
|
|
|
type->ncols * type->nrows);
|
1998-05-28 20:48:40 +04:00
|
|
|
scr->pcs.active = 1;
|
1999-01-09 18:29:26 +03:00
|
|
|
|
1998-03-22 18:11:49 +03:00
|
|
|
vc->active = scr;
|
1998-05-28 20:48:40 +04:00
|
|
|
|
|
|
|
pcdisplay_cursor(&scr->pcs, scr->pcs.cursoron,
|
|
|
|
scr->pcs.vc_crow, scr->pcs.vc_ccol);
|
1999-12-06 21:54:50 +03:00
|
|
|
|
|
|
|
vc->wantedscreen = 0;
|
|
|
|
if (vc->switchcb)
|
|
|
|
(*vc->switchcb)(vc->switchcbarg, 0, 0);
|
1998-03-22 18:11:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-01-13 19:48:58 +03:00
|
|
|
vga_load_font(v, cookie, data)
|
1998-03-22 18:11:49 +03:00
|
|
|
void *v;
|
|
|
|
void *cookie;
|
1999-01-13 19:48:58 +03:00
|
|
|
struct wsdisplay_font *data;
|
1998-03-22 18:11:49 +03:00
|
|
|
{
|
1999-01-13 19:48:58 +03:00
|
|
|
struct vga_config *vc = v;
|
1998-03-22 18:11:49 +03:00
|
|
|
struct vgascreen *scr = cookie;
|
1999-01-13 19:48:58 +03:00
|
|
|
char *name2;
|
|
|
|
int res, slot;
|
|
|
|
struct vgafont *f;
|
|
|
|
|
|
|
|
if (scr) {
|
|
|
|
name2 = strchr(data->name, ',');
|
|
|
|
if (name2)
|
|
|
|
*name2++ = '\0';
|
|
|
|
res = vga_selectfont(vc, scr, data->name, name2);
|
|
|
|
if (!res)
|
|
|
|
vga_setfont(vc, scr);
|
|
|
|
return (res);
|
|
|
|
}
|
1998-03-22 18:11:49 +03:00
|
|
|
|
1999-01-13 19:48:58 +03:00
|
|
|
if (data->fontwidth != 8 || data->stride != 1)
|
1998-03-22 18:11:49 +03:00
|
|
|
return (EINVAL); /* XXX 1 byte per line */
|
1999-01-13 19:48:58 +03:00
|
|
|
if (data->firstchar != 0 || data->numchars != 256)
|
|
|
|
return (EINVAL);
|
1999-04-01 15:52:42 +04:00
|
|
|
#ifndef WSCONS_SUPPORT_PCVTFONTS
|
|
|
|
if (data->encoding == WSDISPLAY_FONTENC_PCVT) {
|
|
|
|
printf("vga: pcvt font support not built in, see vga(4)\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
#endif
|
1999-01-13 19:48:58 +03:00
|
|
|
|
|
|
|
for (slot = 0; slot < 8; slot++)
|
|
|
|
if (!vc->vc_fonts[slot])
|
|
|
|
break;
|
|
|
|
if (slot == 8)
|
|
|
|
return (ENOSPC);
|
|
|
|
|
|
|
|
f = malloc(sizeof(struct vgafont), M_DEVBUF, M_WAITOK);
|
|
|
|
strncpy(f->name, data->name, sizeof(f->name));
|
|
|
|
f->height = data->fontheight;
|
|
|
|
f->encoding = data->encoding;
|
|
|
|
#ifdef notyet
|
|
|
|
f->firstchar = data->firstchar;
|
|
|
|
f->numchars = data->numchars;
|
|
|
|
#endif
|
|
|
|
#ifdef VGAFONTDEBUG
|
|
|
|
printf("vga: load %s (8x%d, enc %d) font to slot %d\n", f->name,
|
|
|
|
f->height, f->encoding, slot);
|
|
|
|
#endif
|
|
|
|
vga_loadchars(&vc->hdl, slot, 0, 256, f->height, data->data);
|
|
|
|
f->slot = slot;
|
|
|
|
vc->vc_fonts[slot] = f;
|
1998-03-22 18:11:49 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-05-15 00:49:55 +04:00
|
|
|
static int
|
|
|
|
vga_alloc_attr(id, fg, bg, flags, attrp)
|
|
|
|
void *id;
|
|
|
|
int fg, bg;
|
|
|
|
int flags;
|
|
|
|
long *attrp;
|
|
|
|
{
|
|
|
|
struct vgascreen *scr = id;
|
|
|
|
struct vga_config *vc = scr->cfg;
|
|
|
|
|
1998-05-28 20:48:40 +04:00
|
|
|
if (vc->hdl.vh_mono) {
|
1998-05-15 00:49:55 +04:00
|
|
|
if (flags & WSATTR_WSCOLORS)
|
|
|
|
return (EINVAL);
|
|
|
|
if (flags & WSATTR_REVERSE)
|
|
|
|
*attrp = 0x70;
|
|
|
|
else
|
|
|
|
*attrp = 0x07;
|
|
|
|
if (flags & WSATTR_UNDERLINE)
|
|
|
|
*attrp |= FG_UNDERLINE;
|
|
|
|
if (flags & WSATTR_HILIT)
|
|
|
|
*attrp |= FG_INTENSE;
|
|
|
|
} else {
|
|
|
|
if (flags & (WSATTR_UNDERLINE | WSATTR_REVERSE))
|
|
|
|
return (EINVAL);
|
|
|
|
if (flags & WSATTR_WSCOLORS)
|
|
|
|
*attrp = fgansitopc[fg] | bgansitopc[bg];
|
|
|
|
else
|
|
|
|
*attrp = 7;
|
|
|
|
if (flags & WSATTR_HILIT)
|
|
|
|
*attrp += 8;
|
|
|
|
}
|
|
|
|
if (flags & WSATTR_BLINK)
|
|
|
|
*attrp |= FG_BLINK;
|
|
|
|
return (0);
|
|
|
|
}
|
1998-07-24 20:20:14 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
vga_copyrows(id, srcrow, dstrow, nrows)
|
|
|
|
void *id;
|
|
|
|
int srcrow, dstrow, nrows;
|
|
|
|
{
|
|
|
|
struct vgascreen *scr = id;
|
|
|
|
bus_space_tag_t memt = scr->pcs.hdl->ph_memt;
|
|
|
|
bus_space_handle_t memh = scr->pcs.hdl->ph_memh;
|
|
|
|
int ncols = scr->pcs.type->ncols;
|
|
|
|
bus_size_t srcoff, dstoff;
|
|
|
|
|
|
|
|
srcoff = srcrow * ncols + 0;
|
|
|
|
dstoff = dstrow * ncols + 0;
|
|
|
|
|
|
|
|
if (scr->pcs.active) {
|
|
|
|
if (dstrow == 0 && (srcrow + nrows == scr->pcs.type->nrows)) {
|
1999-09-20 01:48:08 +04:00
|
|
|
#ifdef PCDISPLAY_SOFTCURSOR
|
1999-09-29 21:29:24 +04:00
|
|
|
int cursoron = scr->pcs.cursoron;
|
|
|
|
|
1999-11-03 18:55:27 +03:00
|
|
|
if (cursoron)
|
|
|
|
pcdisplay_cursor(&scr->pcs, 0,
|
|
|
|
scr->pcs.vc_crow, scr->pcs.vc_ccol);
|
1999-09-20 01:48:08 +04:00
|
|
|
#endif
|
1998-07-24 20:20:14 +04:00
|
|
|
/* scroll up whole screen */
|
|
|
|
if ((scr->pcs.dispoffset + srcrow * ncols * 2)
|
|
|
|
<= scr->maxdispoffset) {
|
|
|
|
scr->pcs.dispoffset += srcrow * ncols * 2;
|
|
|
|
} else {
|
|
|
|
bus_space_copy_region_2(memt, memh,
|
|
|
|
scr->pcs.dispoffset + srcoff * 2,
|
|
|
|
memh, scr->mindispoffset,
|
|
|
|
nrows * ncols);
|
|
|
|
scr->pcs.dispoffset = scr->mindispoffset;
|
|
|
|
}
|
|
|
|
vga_6845_write(&scr->cfg->hdl, startadrh,
|
|
|
|
scr->pcs.dispoffset >> 9);
|
|
|
|
vga_6845_write(&scr->cfg->hdl, startadrl,
|
|
|
|
scr->pcs.dispoffset >> 1);
|
1999-09-20 01:48:08 +04:00
|
|
|
#ifdef PCDISPLAY_SOFTCURSOR
|
1999-11-03 18:55:27 +03:00
|
|
|
if (cursoron)
|
|
|
|
pcdisplay_cursor(&scr->pcs, 1,
|
|
|
|
scr->pcs.vc_crow, scr->pcs.vc_ccol);
|
1999-09-20 01:48:08 +04:00
|
|
|
#endif
|
1998-07-24 20:20:14 +04:00
|
|
|
} else {
|
|
|
|
bus_space_copy_region_2(memt, memh,
|
|
|
|
scr->pcs.dispoffset + srcoff * 2,
|
|
|
|
memh, scr->pcs.dispoffset + dstoff * 2,
|
|
|
|
nrows * ncols);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
bcopy(&scr->pcs.mem[srcoff], &scr->pcs.mem[dstoff],
|
|
|
|
nrows * ncols * 2);
|
|
|
|
}
|
1999-01-13 19:48:58 +03:00
|
|
|
|
|
|
|
#ifdef WSCONS_SUPPORT_PCVTFONTS
|
|
|
|
|
|
|
|
#define NOTYET 0xffff
|
|
|
|
static u_int16_t pcvt_unichars[0xa0] = {
|
1999-02-20 21:27:53 +03:00
|
|
|
/* 0 */ _e006U,
|
|
|
|
NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
|
1999-01-13 19:48:58 +03:00
|
|
|
NOTYET,
|
|
|
|
0x2409, /* SYMBOL FOR HORIZONTAL TABULATION */
|
|
|
|
0x240a, /* SYMBOL FOR LINE FEED */
|
|
|
|
0x240b, /* SYMBOL FOR VERTICAL TABULATION */
|
|
|
|
0x240c, /* SYMBOL FOR FORM FEED */
|
|
|
|
0x240d, /* SYMBOL FOR CARRIAGE RETURN */
|
|
|
|
NOTYET, NOTYET,
|
1999-02-20 21:27:53 +03:00
|
|
|
/* 1 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
|
1999-01-13 19:48:58 +03:00
|
|
|
NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
|
|
|
|
/* 2 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
|
|
|
|
NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
|
1999-02-20 21:27:53 +03:00
|
|
|
/* 3 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
|
1999-01-13 19:48:58 +03:00
|
|
|
NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
|
|
|
|
/* 4 */ 0x03c1, /* GREEK SMALL LETTER RHO */
|
|
|
|
0x03c8, /* GREEK SMALL LETTER PSI */
|
|
|
|
0x2202, /* PARTIAL DIFFERENTIAL */
|
|
|
|
0x03bb, /* GREEK SMALL LETTER LAMDA */
|
|
|
|
0x03b9, /* GREEK SMALL LETTER IOTA */
|
|
|
|
0x03b7, /* GREEK SMALL LETTER ETA */
|
|
|
|
0x03b5, /* GREEK SMALL LETTER EPSILON */
|
|
|
|
0x03c7, /* GREEK SMALL LETTER CHI */
|
|
|
|
0x2228, /* LOGICAL OR */
|
|
|
|
0x2227, /* LOGICAL AND */
|
|
|
|
0x222a, /* UNION */
|
|
|
|
0x2283, /* SUPERSET OF */
|
|
|
|
0x2282, /* SUBSET OF */
|
|
|
|
0x03a5, /* GREEK CAPITAL LETTER UPSILON */
|
|
|
|
0x039e, /* GREEK CAPITAL LETTER XI */
|
|
|
|
0x03a8, /* GREEK CAPITAL LETTER PSI */
|
1999-02-20 21:27:53 +03:00
|
|
|
/* 5 */ 0x03a0, /* GREEK CAPITAL LETTER PI */
|
1999-01-13 19:48:58 +03:00
|
|
|
0x21d2, /* RIGHTWARDS DOUBLE ARROW */
|
|
|
|
0x21d4, /* LEFT RIGHT DOUBLE ARROW */
|
|
|
|
0x039b, /* GREEK CAPITAL LETTER LAMDA */
|
|
|
|
0x0398, /* GREEK CAPITAL LETTER THETA */
|
|
|
|
0x2243, /* ASYMPTOTICALLY EQUAL TO */
|
|
|
|
0x2207, /* NABLA */
|
|
|
|
0x2206, /* INCREMENT */
|
|
|
|
0x221d, /* PROPORTIONAL TO */
|
|
|
|
0x2234, /* THEREFORE */
|
|
|
|
0x222b, /* INTEGRAL */
|
|
|
|
0x2215, /* DIVISION SLASH */
|
|
|
|
0x2216, /* SET MINUS */
|
1999-02-20 21:27:53 +03:00
|
|
|
_e00eU,
|
|
|
|
_e00dU,
|
|
|
|
_e00bU,
|
|
|
|
/* 6 */ _e00cU,
|
|
|
|
_e007U,
|
|
|
|
_e008U,
|
|
|
|
_e009U,
|
|
|
|
_e00aU,
|
1999-01-13 19:48:58 +03:00
|
|
|
0x221a, /* SQUARE ROOT */
|
|
|
|
0x03c9, /* GREEK SMALL LETTER OMEGA */
|
|
|
|
0x00a5, /* YEN SIGN */
|
|
|
|
0x03be, /* GREEK SMALL LETTER XI */
|
|
|
|
0x00fd, /* LATIN SMALL LETTER Y WITH ACUTE */
|
|
|
|
0x00fe, /* LATIN SMALL LETTER THORN */
|
|
|
|
0x00f0, /* LATIN SMALL LETTER ETH */
|
|
|
|
0x00de, /* LATIN CAPITAL LETTER THORN */
|
|
|
|
0x00dd, /* LATIN CAPITAL LETTER Y WITH ACUTE */
|
|
|
|
0x00d7, /* MULTIPLICATION SIGN */
|
|
|
|
0x00d0, /* LATIN CAPITAL LETTER ETH */
|
1999-02-20 21:27:53 +03:00
|
|
|
/* 7 */ 0x00be, /* VULGAR FRACTION THREE QUARTERS */
|
1999-01-13 19:48:58 +03:00
|
|
|
0x00b8, /* CEDILLA */
|
|
|
|
0x00b4, /* ACUTE ACCENT */
|
|
|
|
0x00af, /* MACRON */
|
|
|
|
0x00ae, /* REGISTERED SIGN */
|
|
|
|
0x00ad, /* SOFT HYPHEN */
|
|
|
|
0x00ac, /* NOT SIGN */
|
|
|
|
0x00a8, /* DIAERESIS */
|
|
|
|
0x2260, /* NOT EQUAL TO */
|
1999-02-20 21:27:53 +03:00
|
|
|
_e005U,
|
|
|
|
_e004U,
|
|
|
|
_e003U,
|
|
|
|
_e002U,
|
|
|
|
_e001U,
|
1999-01-13 19:48:58 +03:00
|
|
|
0x03c5, /* GREEK SMALL LETTER UPSILON */
|
|
|
|
0x00f8, /* LATIN SMALL LETTER O WITH STROKE */
|
|
|
|
/* 8 */ 0x0153, /* LATIN SMALL LIGATURE OE */
|
|
|
|
0x00f5, /* LATIN SMALL LETTER O WITH TILDE !!!doc bug */
|
|
|
|
0x00e3, /* LATIN SMALL LETTER A WITH TILDE */
|
|
|
|
0x0178, /* LATIN CAPITAL LETTER Y WITH DIAERESIS */
|
|
|
|
0x00db, /* LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
|
|
|
|
0x00da, /* LATIN CAPITAL LETTER U WITH ACUTE */
|
|
|
|
0x00d9, /* LATIN CAPITAL LETTER U WITH GRAVE */
|
|
|
|
0x00d8, /* LATIN CAPITAL LETTER O WITH STROKE */
|
|
|
|
0x0152, /* LATIN CAPITAL LIGATURE OE */
|
|
|
|
0x00d5, /* LATIN CAPITAL LETTER O WITH TILDE */
|
|
|
|
0x00d4, /* LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
|
|
|
|
0x00d3, /* LATIN CAPITAL LETTER O WITH ACUTE */
|
|
|
|
0x00d2, /* LATIN CAPITAL LETTER O WITH GRAVE */
|
|
|
|
0x00cf, /* LATIN CAPITAL LETTER I WITH DIAERESIS */
|
|
|
|
0x00ce, /* LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
|
|
|
|
0x00cd, /* LATIN CAPITAL LETTER I WITH ACUTE */
|
1999-02-20 21:27:53 +03:00
|
|
|
/* 9 */ 0x00cc, /* LATIN CAPITAL LETTER I WITH GRAVE */
|
1999-01-13 19:48:58 +03:00
|
|
|
0x00cb, /* LATIN CAPITAL LETTER E WITH DIAERESIS */
|
|
|
|
0x00ca, /* LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
|
|
|
|
0x00c8, /* LATIN CAPITAL LETTER E WITH GRAVE */
|
|
|
|
0x00c3, /* LATIN CAPITAL LETTER A WITH TILDE */
|
|
|
|
0x00c2, /* LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
|
|
|
|
0x00c1, /* LATIN CAPITAL LETTER A WITH ACUTE */
|
|
|
|
0x00c0, /* LATIN CAPITAL LETTER A WITH GRAVE */
|
|
|
|
0x00b9, /* SUPERSCRIPT ONE */
|
|
|
|
0x00b7, /* MIDDLE DOT */
|
|
|
|
0x03b6, /* GREEK SMALL LETTER ZETA */
|
|
|
|
0x00b3, /* SUPERSCRIPT THREE */
|
|
|
|
0x00a9, /* COPYRIGHT SIGN */
|
|
|
|
0x00a4, /* CURRENCY SIGN */
|
|
|
|
0x03ba, /* GREEK SMALL LETTER KAPPA */
|
1999-02-20 21:27:53 +03:00
|
|
|
_e000U
|
1999-01-13 19:48:58 +03:00
|
|
|
};
|
|
|
|
|
1999-02-12 14:25:23 +03:00
|
|
|
static int vga_pcvt_mapchar __P((int, unsigned int *));
|
1999-01-13 19:48:58 +03:00
|
|
|
|
|
|
|
static int
|
1999-02-12 14:25:23 +03:00
|
|
|
vga_pcvt_mapchar(uni, index)
|
1999-01-13 19:48:58 +03:00
|
|
|
int uni;
|
1999-02-12 14:25:23 +03:00
|
|
|
unsigned int *index;
|
1999-01-13 19:48:58 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 0xa0; i++) /* 0xa0..0xff are reserved */
|
1999-02-12 14:25:23 +03:00
|
|
|
if (uni == pcvt_unichars[i]) {
|
|
|
|
*index = i;
|
|
|
|
return (5);
|
|
|
|
}
|
|
|
|
*index = 0x99; /* middle dot */
|
|
|
|
return (0);
|
1999-01-13 19:48:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WSCONS_SUPPORT_PCVTFONTS */
|
|
|
|
|
1999-02-12 14:25:23 +03:00
|
|
|
static int _vga_mapchar __P((void *, struct vgafont *, int, unsigned int *));
|
1999-01-13 19:48:58 +03:00
|
|
|
|
|
|
|
static int
|
1999-02-12 14:25:23 +03:00
|
|
|
_vga_mapchar(id, font, uni, index)
|
1999-01-13 19:48:58 +03:00
|
|
|
void *id;
|
|
|
|
struct vgafont *font;
|
|
|
|
int uni;
|
1999-02-12 14:25:23 +03:00
|
|
|
unsigned int *index;
|
1999-01-13 19:48:58 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (font->encoding) {
|
|
|
|
case WSDISPLAY_FONTENC_ISO:
|
1999-02-12 14:25:23 +03:00
|
|
|
if (uni < 256) {
|
|
|
|
*index = uni;
|
|
|
|
return (5);
|
|
|
|
} else {
|
|
|
|
*index = ' ';
|
|
|
|
return (0);
|
|
|
|
}
|
1999-01-13 19:48:58 +03:00
|
|
|
break;
|
|
|
|
case WSDISPLAY_FONTENC_IBM:
|
1999-02-12 14:25:23 +03:00
|
|
|
return (pcdisplay_mapchar(id, uni, index));
|
1999-01-13 19:48:58 +03:00
|
|
|
#ifdef WSCONS_SUPPORT_PCVTFONTS
|
|
|
|
case WSDISPLAY_FONTENC_PCVT:
|
1999-02-12 14:25:23 +03:00
|
|
|
return (vga_pcvt_mapchar(uni, index));
|
1999-01-13 19:48:58 +03:00
|
|
|
#endif
|
1999-02-12 14:25:23 +03:00
|
|
|
default:
|
1999-04-01 15:52:42 +04:00
|
|
|
#ifdef VGAFONTDEBUG
|
1999-02-12 14:25:23 +03:00
|
|
|
printf("_vga_mapchar: encoding=%d\n", font->encoding);
|
1999-04-01 15:52:42 +04:00
|
|
|
#endif
|
1999-02-12 14:25:23 +03:00
|
|
|
*index = ' ';
|
|
|
|
return (0);
|
1999-01-13 19:48:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-12 14:25:23 +03:00
|
|
|
static int
|
|
|
|
vga_mapchar(id, uni, index)
|
1999-01-13 19:48:58 +03:00
|
|
|
void *id;
|
|
|
|
int uni;
|
1999-02-12 14:25:23 +03:00
|
|
|
unsigned int *index;
|
1999-01-13 19:48:58 +03:00
|
|
|
{
|
|
|
|
struct vgascreen *scr = id;
|
1999-02-12 14:25:23 +03:00
|
|
|
unsigned int idx1, idx2;
|
|
|
|
int res1, res2;
|
|
|
|
|
|
|
|
res1 = 0;
|
|
|
|
idx1 = ' '; /* space */
|
|
|
|
if (scr->fontset1)
|
|
|
|
res1 = _vga_mapchar(id, scr->fontset1, uni, &idx1);
|
|
|
|
res2 = -1;
|
1999-01-13 19:48:58 +03:00
|
|
|
if (scr->fontset2) {
|
|
|
|
KASSERT(VGA_SCREEN_CANTWOFONTS(scr->pcs.type));
|
1999-02-12 14:25:23 +03:00
|
|
|
res2 = _vga_mapchar(id, scr->fontset2, uni, &idx2);
|
1999-01-13 19:48:58 +03:00
|
|
|
}
|
1999-02-12 14:25:23 +03:00
|
|
|
if (res2 > res1) {
|
1999-02-20 21:27:53 +03:00
|
|
|
*index = idx2 | 0x0800; /* attribute bit 3 */
|
|
|
|
return (res2);
|
1999-02-12 14:25:23 +03:00
|
|
|
}
|
|
|
|
*index = idx1;
|
|
|
|
return (res1);
|
1999-01-13 19:48:58 +03:00
|
|
|
}
|