summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2009-02-01 14:37:23 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2009-02-01 14:37:23 +0000
commit431ad02309f63a5909d5c6b47ebb1a1208566516 (patch)
tree0db9a018c3a6738ecfeeaf8bfc547240cb615023 /sys/dev
parent89cf7f4aaa4684732ec9fd56edd086028ed5ed4d (diff)
Save the text mode color palette upon startup, and restore it when
switching consoles or when X11 exits. Almost all other operating systems do this, and thus do not suffer from palette bugs in some X11 drivers. From FreeBSD.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ic/vga.c81
-rw-r--r--sys/dev/ic/vgareg.h7
-rw-r--r--sys/dev/ic/vgavar.h52
3 files changed, 114 insertions, 26 deletions
diff --git a/sys/dev/ic/vga.c b/sys/dev/ic/vga.c
index 0f64441b4a0..511a480278c 100644
--- a/sys/dev/ic/vga.c
+++ b/sys/dev/ic/vga.c
@@ -1,6 +1,35 @@
-/* $OpenBSD: vga.c,v 1.47 2008/03/16 19:00:28 oga Exp $ */
+/* $OpenBSD: vga.c,v 1.48 2009/02/01 14:37:22 miod Exp $ */
/* $NetBSD: vga.c,v 1.28.2.1 2000/06/30 16:27:47 simonb Exp $ */
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * Copyright (c) 1992-1998 Søren Schmidt
+ * 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 AUTHORS ``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 AUTHORS 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.
+ *
+ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
* All rights reserved.
@@ -77,7 +106,6 @@ struct vgascreen {
/* videostate */
struct vgafont *fontset1, *fontset2;
/* font data */
- /* palette */
int mindispoffset, maxdispoffset;
int vga_rollover;
@@ -503,6 +531,8 @@ vga_init(vc, iot, memt)
vc->vc_fonts[i] = 0;
vc->currentfontset1 = vc->currentfontset2 = 0;
+
+ vga_save_palette(vc);
}
void
@@ -613,6 +643,7 @@ vga_ioctl(v, cmd, data, flag, p)
struct proc *p;
{
struct vga_config *vc = v;
+ int mode;
#if NVGA_PCI > 0
int error;
@@ -627,6 +658,12 @@ vga_ioctl(v, cmd, data, flag, p)
/* XXX should get detailed hardware information here */
break;
+ case WSDISPLAYIO_SMODE:
+ mode = *(u_int *)data;
+ if (mode == WSDISPLAYIO_MODE_EMUL)
+ vga_restore_palette(vc);
+ break;
+
case WSDISPLAYIO_GVIDEO:
case WSDISPLAYIO_SVIDEO:
break;
@@ -828,7 +865,7 @@ vga_doswitch(vc)
}
vga_setfont(vc, scr);
- /* XXX switch colours! */
+ vga_restore_palette(vc);
scr->pcs.visibleoffset = scr->pcs.dispoffset = scr->mindispoffset;
if (!oldscr || (scr->pcs.dispoffset != oldscr->pcs.dispoffset)) {
@@ -1339,6 +1376,44 @@ vga_getchar(c, row, col, cell)
return (pcdisplay_getchar(vc->active, row, col, cell));
}
+void
+vga_save_palette(struct vga_config *vc)
+{
+ struct vga_handle *vh = &vc->hdl;
+ uint i;
+ uint8_t *palette = vc->vc_palette;
+
+ if (vh->vh_mono)
+ return;
+
+ vga_raw_write(vh, VGA_DAC_MASK, 0xff);
+ vga_raw_write(vh, VGA_DAC_READ, 0x00);
+ for (i = 0; i < 3 * 256; i++)
+ *palette++ = vga_raw_read(vh, VGA_DAC_DATA);
+
+ vga_raw_read(vh, 0x0a); /* reset flip/flop */
+}
+
+void
+vga_restore_palette(struct vga_config *vc)
+{
+ struct vga_handle *vh = &vc->hdl;
+ uint i;
+ uint8_t *palette = vc->vc_palette;
+
+ if (vh->vh_mono)
+ return;
+
+ vga_raw_write(vh, VGA_DAC_MASK, 0xff);
+ vga_raw_write(vh, VGA_DAC_WRITE, 0x00);
+ for (i = 0; i < 3 * 256; i++)
+ vga_raw_write(vh, VGA_DAC_DATA, *palette++);
+
+ vga_raw_read(vh, 0x0a); /* reset flip/flop */
+
+ vga_enable(vh);
+}
+
struct cfdriver vga_cd = {
NULL, "vga", DV_DULL
};
diff --git a/sys/dev/ic/vgareg.h b/sys/dev/ic/vgareg.h
index bcaee1c3059..4e5dc272754 100644
--- a/sys/dev/ic/vgareg.h
+++ b/sys/dev/ic/vgareg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vgareg.h,v 1.4 2008/09/01 17:30:56 deraadt Exp $ */
+/* $OpenBSD: vgareg.h,v 1.5 2009/02/01 14:37:22 miod Exp $ */
/* $NetBSD: vgareg.h,v 1.2 1998/05/28 16:48:41 drochner Exp $ */
/*
@@ -49,3 +49,8 @@ struct reg_vgagdc { /* indexed via port 0x3ce */
} __packed;
#define VGA_GDC_INDEX 0xe
#define VGA_GDC_DATA 0xf
+
+#define VGA_DAC_MASK 0x06 /* pixel write mask */
+#define VGA_DAC_READ 0x07 /* palette read address */
+#define VGA_DAC_WRITE 0x08 /* palette write address */
+#define VGA_DAC_DATA 0x09 /* palette data register */
diff --git a/sys/dev/ic/vgavar.h b/sys/dev/ic/vgavar.h
index 7bac3e67bbc..c018b7bcf03 100644
--- a/sys/dev/ic/vgavar.h
+++ b/sys/dev/ic/vgavar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vgavar.h,v 1.8 2002/07/12 20:17:03 mickey Exp $ */
+/* $OpenBSD: vgavar.h,v 1.9 2009/02/01 14:37:22 miod Exp $ */
/* $NetBSD: vgavar.h,v 1.4 2000/06/17 07:11:50 soda Exp $ */
/*
@@ -52,6 +52,7 @@ struct vga_config {
int currentfontset1, currentfontset2;
struct vgafont *vc_fonts[8];
+ uint8_t vc_palette[256 * 3];
struct vgascreen *wantedscreen;
void (*switchcb)(void *, int, int);
@@ -69,6 +70,14 @@ static inline void _vga_ts_write(struct vga_handle *, int, u_int8_t);
static inline u_int8_t _vga_gdc_read(struct vga_handle *, int);
static inline void _vga_gdc_write(struct vga_handle *, int, u_int8_t);
+#define vga_raw_read(vh, reg) \
+ bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, reg)
+#define vga_raw_write(vh, reg, value) \
+ bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, reg, value)
+
+#define vga_enable(vh) \
+ vga_raw_write(vh, 0, 0x20);
+
static inline u_int8_t _vga_attr_read(vh, reg)
struct vga_handle *vh;
int reg;
@@ -78,14 +87,13 @@ static inline u_int8_t _vga_attr_read(vh, reg)
/* reset state */
(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
- res = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAR);
+ vga_raw_write(vh, VGA_ATC_INDEX, reg);
+ res = vga_raw_read(vh, VGA_ATC_DATAR);
/* reset state XXX unneeded? */
(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
- /* enable */
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
+ vga_enable(vh);
return (res);
}
@@ -98,22 +106,21 @@ static inline void _vga_attr_write(vh, reg, val)
/* reset state */
(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAW, val);
+ vga_raw_write(vh, VGA_ATC_INDEX, reg);
+ vga_raw_write(vh, VGA_ATC_DATAW, val);
/* reset state XXX unneeded? */
(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
- /* enable */
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
+ vga_enable(vh);
}
static inline u_int8_t _vga_ts_read(vh, reg)
struct vga_handle *vh;
int reg;
{
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
- return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA));
+ vga_raw_write(vh, VGA_TS_INDEX, reg);
+ return (vga_raw_read(vh, VGA_TS_DATA));
}
static inline void _vga_ts_write(vh, reg, val)
@@ -121,16 +128,16 @@ static inline void _vga_ts_write(vh, reg, val)
int reg;
u_int8_t val;
{
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA, val);
+ vga_raw_write(vh, VGA_TS_INDEX, reg);
+ vga_raw_write(vh, VGA_TS_DATA, val);
}
static inline u_int8_t _vga_gdc_read(vh, reg)
struct vga_handle *vh;
int reg;
{
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
- return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA));
+ vga_raw_write(vh, VGA_GDC_INDEX, reg);
+ return (vga_raw_read(vh, VGA_GDC_DATA));
}
static inline void _vga_gdc_write(vh, reg, val)
@@ -138,8 +145,8 @@ static inline void _vga_gdc_write(vh, reg, val)
int reg;
u_int8_t val;
{
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
- bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA, val);
+ vga_raw_write(vh, VGA_GDC_INDEX, reg);
+ vga_raw_write(vh, VGA_GDC_DATA, val);
}
#define vga_attr_read(vh, reg) \
@@ -169,10 +176,11 @@ int vga_is_console(bus_space_tag_t, int);
int vga_cnattach(bus_space_tag_t, bus_space_tag_t, int, int);
struct wsscreen_descr;
-void vga_loadchars(struct vga_handle *, int, int, int, int, char *);
-void vga_setfontset(struct vga_handle *, int, int);
-void vga_setscreentype(struct vga_handle *,
- const struct wsscreen_descr *);
+void vga_loadchars(struct vga_handle *, int, int, int, int, char *);
+void vga_restore_palette(struct vga_config *);
+void vga_save_palette(struct vga_config *);
+void vga_setfontset(struct vga_handle *, int, int);
+void vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *);
#if NVGA_PCI > 0
-int vga_pci_ioctl(void *, u_long, caddr_t, int, struct proc *);
+int vga_pci_ioctl(void *, u_long, caddr_t, int, struct proc *);
#endif