Changes to allow machines which don't use text mode at the boot time

to use generic VGA driver(s):
- Allow VGA drivers to use wsfont instead of builtin font.
- Add vga_reset() function, which will be called from MD consinit(),
  to put VGA into text mode. This function is enabled by options VGA_RESET.
This commit is contained in:
tsutsui 2003-01-31 21:57:23 +00:00
parent 4eb408dcd9
commit ef47e3f676
6 changed files with 291 additions and 23 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files,v 1.592 2003/01/20 20:02:01 christos Exp $
# $NetBSD: files,v 1.593 2003/01/31 21:57:23 tsutsui Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@ -781,6 +781,7 @@ file dev/ic/pcdisplay_chars.c pcdisplayops
defparam opt_vga.h VGA_CONSOLE_SCREENTYPE
defflag opt_vga.h VGA_CONSOLE_ATI_BROKEN_FONTSEL
defflag opt_vga.h VGA_RASTERCONSOLE
defflag opt_vga.h VGA_RESET
device vga: wsemuldisplaydev, pcdisplayops
file dev/ic/vga.c vga & !vga_rasterconsole needs-flag
file dev/ic/vga_raster.c vga_rasterconsole needs-flag

View File

@ -1,4 +1,4 @@
/* $NetBSD: vga.c,v 1.67 2003/01/27 15:16:10 tsutsui Exp $ */
/* $NetBSD: vga.c,v 1.68 2003/01/31 21:57:25 tsutsui Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vga.c,v 1.67 2003/01/27 15:16:10 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: vga.c,v 1.68 2003/01/31 21:57:25 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -54,6 +54,8 @@ __KERNEL_RCSID(0, "$NetBSD: vga.c,v 1.67 2003/01/27 15:16:10 tsutsui Exp $");
/* for WSCONS_SUPPORT_PCVTFONTS and WSDISPLAY_CHARFUNCS */
#include "opt_wsdisplay_compat.h"
int vga_no_builtinfont = 0;
static struct wsdisplay_font _vga_builtinfont = {
"builtin", /* typeface name */
0, /* firstchar */
@ -472,7 +474,6 @@ vga_init_screen(struct vga_config *vc, struct vgascreen *scr,
scr->pcs.mem = NULL;
wsfont_init();
scr->fontset1 = scr->fontset2 = 0;
if (vga_selectfont(vc, scr, 0, 0)) {
if (scr == &vga_console_screen)
@ -528,6 +529,21 @@ vga_init(struct vga_config *vc, bus_space_tag_t iot, bus_space_tag_t memt)
vc->currenttype = vh->vh_mono ? &vga_25lscreen_mono : &vga_25lscreen;
callout_init(&vc->vc_switch_callout);
wsfont_init();
if (vga_no_builtinfont) {
struct wsdisplay_font *wf;
int cookie;
cookie = wsfont_find(NULL, 8, 16, 0,
WSDISPLAY_FONTORDER_L2R, 0);
if (cookie == -1 || wsfont_lock(cookie, &wf))
panic("vga_init: can't load console font");
vga_loadchars(&vc->hdl, 0, wf->firstchar, wf->numchars,
wf->fontheight, wf->data);
vga_builtinfont.wsfont = wf;
vga_builtinfont.cookie = cookie;
vga_builtinfont.slot = 0;
}
vc->vc_fonts[0] = &vga_builtinfont;
for (i = 1; i < 8; i++)
vc->vc_fonts[i] = 0;
@ -586,12 +602,14 @@ vga_common_attach(struct vga_softc *sc, bus_space_tag_t iot,
KASSERT(vga_builtinfont.slot == 0);
#define BUILTINFONTLOC (0)
#endif
vga_builtinfont.wsfont->data =
malloc(256 * vga_builtinfont.wsfont->fontheight,
M_DEVBUF, M_WAITOK);
vga_readoutchars(&vc->hdl, BUILTINFONTLOC, 0, 256,
vga_builtinfont.wsfont->fontheight,
vga_builtinfont.wsfont->data);
if (!vga_no_builtinfont) {
vga_builtinfont.wsfont->data =
malloc(256 * vga_builtinfont.wsfont->fontheight,
M_DEVBUF, M_WAITOK);
vga_readoutchars(&vc->hdl, BUILTINFONTLOC, 0, 256,
vga_builtinfont.wsfont->fontheight,
vga_builtinfont.wsfont->data);
}
vc->vc_type = type;
vc->vc_funcs = vf;

View File

@ -1,4 +1,4 @@
/* $NetBSD: vga_raster.c,v 1.9 2003/01/27 15:27:44 tsutsui Exp $ */
/* $NetBSD: vga_raster.c,v 1.10 2003/01/31 21:57:26 tsutsui Exp $ */
/*
* Copyright (c) 2001, 2002 Bang Jun-Young
@ -75,6 +75,8 @@
#include <dev/ic/pcdisplay.h>
int vga_no_builtinfont = 0;
u_int8_t builtinfont_data[256 * 16];
struct wsdisplay_font builtinfont = {
@ -394,11 +396,27 @@ vga_raster_init(struct vga_config *vc, bus_space_tag_t iot,
vc->currenttype = vh->vh_mono ? &vga_25lscreen_mono : &vga_25lscreen;
callout_init(&vc->vc_switch_callout);
wsfont_init();
vc->nfonts = 1;
LIST_INIT(&vc->vc_fontlist);
vf = &vga_console_fontset_ascii;
vga_load_builtinfont(vh, builtinfont_data, 0, 256);
vf->font = &builtinfont;
if (vga_no_builtinfont) {
struct wsdisplay_font *wf;
int cookie;
/* prefer 8x16 pixel font */
cookie = wsfont_find(NULL, 8, 16, 0,
WSDISPLAY_FONTORDER_L2R, 0);
if (cookie == -1)
cookie = wsfont_find(NULL, 0, 0, 0,
WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R);
if (cookie == -1 || wsfont_lock(cookie, &wf))
panic("vga_raster_init: can't load console font");
vf->font = wf;
} else {
vga_load_builtinfont(vh, builtinfont_data, 0, 256);
vf->font = &builtinfont;
}
LIST_INSERT_HEAD(&vc->vc_fontlist, vf, next);
}
@ -415,10 +433,8 @@ vga_raster_init_screen(struct vga_config *vc, struct vgascreen *scr,
scr->type = type;
scr->mindispoffset = 0;
scr->maxdispoffset = 0x10000;
scr->encoding = WSDISPLAY_FONTENC_IBM;
vh = &vc->hdl;
wsfont_init();
LIST_INIT(&scr->fontset);
vga_raster_setup_font(vc, scr);
@ -449,7 +465,7 @@ vga_raster_init_screen(struct vga_config *vc, struct vgascreen *scr,
vh->vh_allmemh, 0x18000 + i * 2);
scr->mem[i].attr = bus_space_read_1(vh->vh_memt,
vh->vh_allmemh, 0x18000 + i * 2 + 1);
scr->mem[i].enc = WSDISPLAY_FONTENC_IBM;
scr->mem[i].enc = scr->encoding;
}
vga_raster_setscreentype(vc, type);
@ -782,6 +798,7 @@ vga_raster_setup_font(struct vga_config *vc, struct vgascreen *scr)
LIST_FOREACH(vf, &vc->vc_fontlist, next) {
if (wsfont_matches(vf->font, 0, 0, scr->type->fontheight, 0)) {
scr->encoding = vf->font->encoding;
LIST_INSERT_HEAD(&scr->fontset, vf, next);
return;
}
@ -802,6 +819,7 @@ vga_raster_setup_font(struct vga_config *vc, struct vgascreen *scr)
}
vf->font = wf;
scr->encoding = vf->font->encoding;
LIST_INSERT_HEAD(&scr->fontset, vf, next);
}
@ -993,7 +1011,7 @@ vga_raster_cursor_init(struct vgascreen *scr, int existing)
scr->cursortmp.ch = 0;
scr->cursortmp.attr = 0;
scr->cursortmp.second = 0;
scr->cursortmp.enc = WSDISPLAY_FONTENC_IBM;
scr->cursortmp.enc = scr->encoding;
}
scr->cursoron = 1;
@ -1109,7 +1127,7 @@ vga_raster_putchar(void *id, int row, int col, u_int c, long attr)
scr->mem[off].ch = c;
scr->mem[off].attr = attr;
scr->mem[off].second = 0;
scr->mem[off].enc = WSDISPLAY_FONTENC_IBM;
scr->mem[off].enc = scr->encoding;
}
static void
@ -1323,7 +1341,7 @@ vga_raster_eraserows(void *id, int startrow, int nrows, long fillattr)
scr->mem[off + i].ch = ' ';
scr->mem[off + i].attr = fillattr;
scr->mem[off + i].second = 0;
scr->mem[off + i].enc = WSDISPLAY_FONTENC_IBM;
scr->mem[off + i].enc = scr->encoding;
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vga_subr.c,v 1.13 2003/01/27 15:22:47 tsutsui Exp $ */
/* $NetBSD: vga_subr.c,v 1.14 2003/01/31 21:57:26 tsutsui Exp $ */
/*
* Copyright (c) 1998
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vga_subr.c,v 1.13 2003/01/27 15:22:47 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: vga_subr.c,v 1.14 2003/01/31 21:57:26 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: vga_subr.c,v 1.13 2003/01/27 15:22:47 tsutsui Exp $"
#include <machine/bus.h>
#include <dev/ic/mc6845reg.h>
#include <dev/ic/pcdisplay.h>
#include <dev/ic/pcdisplayvar.h>
#include <dev/ic/vgareg.h>
#include <dev/ic/vgavar.h>
@ -50,6 +51,9 @@ __KERNEL_RCSID(0, "$NetBSD: vga_subr.c,v 1.13 2003/01/27 15:22:47 tsutsui Exp $"
static void fontram(struct vga_handle *);
static void textram(struct vga_handle *);
#ifdef VGA_RESET
static void vga_initregs(struct vga_handle *);
#endif
static void
fontram(struct vga_handle *vh)
@ -212,3 +216,218 @@ vga_load_builtinfont(struct vga_handle *vh, u_int8_t *font, int firstchar,
splx(s);
}
#endif /* !VGA_RASTERCONSOLE */
#ifdef VGA_RESET
/*
* vga_reset():
* Reset VGA registers to put it into 80x25 text mode. (mode 3)
* This function should be called from MD consinit() on ports
* whose firmware does not use text mode at boot time.
*/
void
vga_reset(vh, md_initfunc)
struct vga_handle *vh;
void (*md_initfunc)(struct vga_handle *);
{
u_int8_t reg;
if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
return;
reg = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAR);
vh->vh_mono = !(reg & 0x01);
if (bus_space_map(vh->vh_iot, vh->vh_mono ? 0x3b0 : 0x3d0, 0x10,
0, &vh->vh_ioh_6845))
goto out1;
if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 0, &vh->vh_allmemh))
goto out2;
if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh,
vh->vh_mono ? 0x10000 : 0x18000, 0x8000, &vh->vh_memh))
goto out3;
/* check if VGA already in text mode. */
if ((vga_gdc_read(vh, misc) & 0x01) == 0)
goto out3;
/* initialize common VGA registers */
vga_initregs(vh);
/* initialize chipset specific registers */
if (md_initfunc != NULL)
(*md_initfunc)(vh);
delay(10000);
/* clear text buffer RAM */
bus_space_set_region_2(vh->vh_memt, vh->vh_memh, 0,
((BG_BLACK | FG_LIGHTGREY) << 8) | ' ', 80 * 25 /*XXX*/);
out3:
bus_space_unmap(vh->vh_memt, vh->vh_allmemh, 0x20000);
out2:
bus_space_unmap(vh->vh_iot, vh->vh_ioh_6845, 0x10);
out1:
bus_space_unmap(vh->vh_iot, vh->vh_ioh_vga, 0x10);
}
/*
* values to initialize registers.
*/
/* miscellaneous output register */
#define VGA_MISCOUT 0x66
/* sequencer registers */
static const u_int8_t vga_ts[] = {
0x03, /* 00: reset */
0x00, /* 01: clocking mode */
0x03, /* 02: map mask */
0x00, /* 03: character map select */
0x02 /* 04: memory mode */
};
/* CRT controller registers */
static const u_int8_t vga_crtc[] = {
0x5f, /* 00: horizontal total */
0x4f, /* 01: horizontal display-enable end */
0x50, /* 02: start horizontal blanking */
0x82, /* 03: display skew control / end horizontal blanking */
0x55, /* 04: start horizontal retrace pulse */
0x81, /* 05: horizontal retrace delay / end horizontal retrace */
0xbf, /* 06: vetical total */
0x1f, /* 07: overflow register */
0x00, /* 08: preset row scan */
0x4f, /* 09: overflow / maximum scan line */
0x0d, /* 0A: cursor off / cursor start */
0x0e, /* 0B: cursor skew / cursor end */
0x00, /* 0C: start regenerative buffer address high */
0x00, /* 0D: start regenerative buffer address low */
0x00, /* 0E: cursor location high */
0x00, /* 0F: cursor location low */
0x9c, /* 10: vertical retrace start */
0x8e, /* 11: vertical interrupt / vertical retrace end */
0x8f, /* 12: vertical display enable end */
0x28, /* 13: logical line width */
0x00, /* 14: underline location */
0x96, /* 15: start vertical blanking */
0xb9, /* 16: end vertical blanking */
0xa3, /* 17: CRT mode control */
0xff /* 18: line compare */
};
/* graphics controller registers */
static const u_int8_t vga_gdc[] = {
0x00, /* 00: set/reset map */
0x00, /* 01: enable set/reset */
0x00, /* 02: color compare */
0x00, /* 03: data rotate */
0x00, /* 04: read map select */
0x10, /* 05: graphics mode */
0x0e, /* 06: miscellaneous */
0x00, /* 07: color don't care */
0xff /* 08: bit mask */
};
/* attribute controller registers */
static const u_int8_t vga_atc[] = {
0x00, /* 00: internal palette 0 */
0x01, /* 01: internal palette 1 */
0x02, /* 02: internal palette 2 */
0x03, /* 03: internal palette 3 */
0x04, /* 04: internal palette 4 */
0x05, /* 05: internal palette 5 */
0x14, /* 06: internal palette 6 */
0x07, /* 07: internal palette 7 */
0x38, /* 08: internal palette 8 */
0x39, /* 09: internal palette 9 */
0x3a, /* 0A: internal palette 10 */
0x3b, /* 0B: internal palette 11 */
0x3c, /* 0C: internal palette 12 */
0x3d, /* 0D: internal palette 13 */
0x3e, /* 0E: internal palette 14 */
0x3f, /* 0F: internal palette 15 */
0x0c, /* 10: attribute mode control */
0x00, /* 11: overscan color */
0x0f, /* 12: color plane enable */
0x08, /* 13: horizontal PEL panning */
0x00 /* 14: color select */
};
/* video DAC palette registers */
/* XXX only set up 16 colors used by internal palette in ATC regsters */
static const u_int8_t vga_dacpal[] = {
/* R G B */
0x00, 0x00, 0x00, /* BLACK */
0x00, 0x00, 0x2a, /* BLUE */
0x00, 0x2a, 0x00, /* GREEN */
0x00, 0x2a, 0x2a, /* CYAN */
0x2a, 0x00, 0x00, /* RED */
0x2a, 0x00, 0x2a, /* MAGENTA */
0x2a, 0x15, 0x00, /* BROWN */
0x2a, 0x2a, 0x2a, /* LIGHTGREY */
0x15, 0x15, 0x15, /* DARKGREY */
0x15, 0x15, 0x3f, /* LIGHTBLUE */
0x15, 0x3f, 0x15, /* LIGHTGREEN */
0x15, 0x3f, 0x3f, /* LIGHTCYAN */
0x3f, 0x15, 0x15, /* LIGHTRED */
0x3f, 0x15, 0x3f, /* LIGHTMAGENTA */
0x3f, 0x3f, 0x15, /* YELLOW */
0x3f, 0x3f, 0x3f /* WHITE */
};
static void
vga_initregs(vh)
struct vga_handle *vh;
{
int i;
/* disable video */
vga_ts_write(vh, mode, vga_ts[1] | VGA_TS_MODE_BLANK);
/* synchronous reset */
vga_ts_write(vh, syncreset, 0x01);
/* set TS regsters */
for (i = 2; i < VGA_TS_NREGS; i++)
_vga_ts_write(vh, i, vga_ts[i]);
/* clear synchronous reset */
vga_ts_write(vh, syncreset, 0x03);
/* unprotect CRTC regsters */
vga_6845_write(vh, vsynce, vga_6845_read(vh, vsynce) & ~0x80);
/* set CRTC regsters */
for (i = 0; i < MC6845_NREGS; i++)
_vga_6845_write(vh, i, vga_crtc[i]);
/* set GDC regsters */
for (i = 0; i < VGA_GDC_NREGS; i++)
_vga_gdc_write(vh, i, vga_gdc[i]);
/* set ATC regsters */
for (i = 0; i < VGA_ATC_NREGS; i++)
_vga_attr_write(vh, i, vga_atc[i]);
/* set DAC palette */
if (!vh->vh_mono) {
for (i = 0; i < 16; i++) {
bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
VGA_DAC_ADDRW, vga_atc[i]);
bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
VGA_DAC_PALETTE, vga_dacpal[i * 3 + 0]);
bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
VGA_DAC_PALETTE, vga_dacpal[i * 3 + 1]);
bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
VGA_DAC_PALETTE, vga_dacpal[i * 3 + 2]);
}
}
/* set misc output register */
bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
VGA_MISC_DATAW, VGA_MISCOUT | (vh->vh_mono ? 0 : 0x01));
/* reenable video */
vga_ts_write(vh, mode, vga_ts[1] & ~VGA_TS_MODE_BLANK);
}
#endif /* VGA_RESET */

View File

@ -1,4 +1,4 @@
/* $NetBSD: vgareg.h,v 1.5 2003/01/27 15:16:12 tsutsui Exp $ */
/* $NetBSD: vgareg.h,v 1.6 2003/01/31 21:57:27 tsutsui Exp $ */
/*
* Copyright (c) 1998
@ -64,6 +64,13 @@ struct reg_vgagdc { /* indexed via port 0x3ce */
* CRTC registers are defined in sys/dev/ic/mc6845reg.h
*/
/* video DAC palette registers */
#define VGA_DAC_PELMASK 0x6
#define VGA_DAC_STATE 0x7
#define VGA_DAC_ADDRR 0x7
#define VGA_DAC_ADDRW 0x8
#define VGA_DAC_PALETTE 0x9
/* misc output register */
#define VGA_MISC_DATAR 0xc
#define VGA_MISC_DATAW 0x2

View File

@ -1,4 +1,4 @@
/* $NetBSD: vgavar.h,v 1.17 2003/01/27 15:16:12 tsutsui Exp $ */
/* $NetBSD: vgavar.h,v 1.18 2003/01/31 21:57:27 tsutsui Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@ -203,3 +203,8 @@ void vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *);
#else /* !VGA_RASTERCONSOLE */
void vga_load_builtinfont(struct vga_handle *, u_int8_t *, int, int);
#endif /* !VGA_RASTERCONSOLE */
#ifdef VGA_RESET
void vga_reset(struct vga_handle *, void (*)(struct vga_handle *));
#endif
extern int vga_no_builtinfont;