Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic - Replace some magic numbers with proper macro.



details:   https://anonhg.NetBSD.org/src/rev/866116da138a
branches:  trunk
changeset: 542377:866116da138a
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Mon Jan 27 15:16:10 2003 +0000

description:
- Replace some magic numbers with proper macro.
- Use vga_6845_{read,write}() defined in pcdisplayvar.h and
  remove vga_crtc_{read,write}() macros in vgareg.h.

diffstat:

 sys/dev/ic/vga.c        |  15 +++++++--------
 sys/dev/ic/vga_common.c |   4 ++--
 sys/dev/ic/vga_raster.c |  29 ++++++++++++++---------------
 sys/dev/ic/vgareg.h     |  28 +++++++++++++---------------
 sys/dev/ic/vgavar.h     |  24 +++++-------------------
 5 files changed, 41 insertions(+), 59 deletions(-)

diffs (290 lines):

diff -r 80794c79d8b8 -r 866116da138a sys/dev/ic/vga.c
--- a/sys/dev/ic/vga.c  Mon Jan 27 14:54:39 2003 +0000
+++ b/sys/dev/ic/vga.c  Mon Jan 27 15:16:10 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vga.c,v 1.66 2003/01/27 14:46:10 tsutsui Exp $ */
+/* $NetBSD: vga.c,v 1.67 2003/01/27 15:16:10 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.66 2003/01/27 14:46:10 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vga.c,v 1.67 2003/01/27 15:16:10 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -501,7 +501,7 @@
                panic("vga_init: couldn't map vga io");
 
        /* read "misc output register" */
-       mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, 0xc);
+       mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAR);
        vh->vh_mono = !(mor & 1);
 
        if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
@@ -665,12 +665,11 @@
        return (0);
 }
 
-#define        VGA_TS_BLANK    0x20
-
 static int
 vga_get_video(struct vga_config *vc)
 {
-       return (vga_ts_read(&vc->hdl, mode) & VGA_TS_BLANK) == 0;
+
+       return (vga_ts_read(&vc->hdl, mode) & VGA_TS_MODE_BLANK) == 0;
 }
 
 static void
@@ -681,14 +680,14 @@
        vga_ts_write(&vc->hdl, syncreset, 0x01);
        if (state) {                                    /* unblank screen */
                val = vga_ts_read(&vc->hdl, mode);
-               vga_ts_write(&vc->hdl, mode, val & ~VGA_TS_BLANK);
+               vga_ts_write(&vc->hdl, mode, val & ~VGA_TS_MODE_BLANK);
 #ifndef VGA_NO_VBLANK
                val = vga_6845_read(&vc->hdl, mode);
                vga_6845_write(&vc->hdl, mode, val | 0x80);
 #endif
        } else {                                        /* blank screen */
                val = vga_ts_read(&vc->hdl, mode);
-               vga_ts_write(&vc->hdl, mode, val | VGA_TS_BLANK);
+               vga_ts_write(&vc->hdl, mode, val | VGA_TS_MODE_BLANK);
 #ifndef VGA_NO_VBLANK
                val = vga_6845_read(&vc->hdl, mode);
                vga_6845_write(&vc->hdl, mode, val & ~0x80);
diff -r 80794c79d8b8 -r 866116da138a sys/dev/ic/vga_common.c
--- a/sys/dev/ic/vga_common.c   Mon Jan 27 14:54:39 2003 +0000
+++ b/sys/dev/ic/vga_common.c   Mon Jan 27 15:16:10 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vga_common.c,v 1.2 2003/01/27 14:46:10 tsutsui Exp $ */
+/* $NetBSD: vga_common.c,v 1.3 2003/01/27 15:16:11 tsutsui Exp $ */
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -56,7 +56,7 @@
        gotio_vga = 1;
 
        /* read "misc output register" */
-       regval = bus_space_read_1(iot, ioh_vga, 0xc);
+       regval = bus_space_read_1(iot, ioh_vga, VGA_MISC_DATAR);
        mono = !(regval & 1);
 
        if (bus_space_map(iot, (mono ? 0x3b0 : 0x3d0), 0x10, 0, &ioh_6845))
diff -r 80794c79d8b8 -r 866116da138a sys/dev/ic/vga_raster.c
--- a/sys/dev/ic/vga_raster.c   Mon Jan 27 14:54:39 2003 +0000
+++ b/sys/dev/ic/vga_raster.c   Mon Jan 27 15:16:10 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vga_raster.c,v 1.6 2003/01/27 14:46:11 tsutsui Exp $   */
+/*     $NetBSD: vga_raster.c,v 1.7 2003/01/27 15:16:11 tsutsui Exp $   */
 
 /*
  * Copyright (c) 2001, 2002 Bang Jun-Young
@@ -135,7 +135,7 @@
 
 struct vga_moderegs {
        u_int8_t miscout;               /* Misc. output */
-       u_int8_t crtc[VGA_CRTC_NREGS];  /* CRTC controller */
+       u_int8_t crtc[MC6845_NREGS];    /* CRTC controller */
        u_int8_t atc[VGA_ATC_NREGS];    /* Attribute controller */
        u_int8_t ts[VGA_TS_NREGS];      /* Time sequencer */
        u_int8_t gdc[VGA_GDC_NREGS];    /* Graphics display controller */
@@ -367,7 +367,7 @@
                panic("vga_raster_init: couldn't map vga io");
 
        /* read "misc output register" */
-       mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, 0xc);
+       mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAR);
        vh->vh_mono = !(mor & 1);
 
        if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
@@ -537,12 +537,11 @@
        return (0);
 }
 
-#define        VGA_TS_BLANK    0x20
-
 static int
 vga_get_video(struct vga_config *vc)
 {
-       return (vga_ts_read(&vc->hdl, mode) & VGA_TS_BLANK) == 0;
+
+       return (vga_ts_read(&vc->hdl, mode) & VGA_TS_MODE_BLANK) == 0;
 }
 
 static void
@@ -553,14 +552,14 @@
        vga_ts_write(&vc->hdl, syncreset, 0x01);
        if (state) {                                    /* unblank screen */
                val = vga_ts_read(&vc->hdl, mode);
-               vga_ts_write(&vc->hdl, mode, val & ~VGA_TS_BLANK);
+               vga_ts_write(&vc->hdl, mode, val & ~VGA_TS_MODE_BLANK);
 #ifndef VGA_NO_VBLANK
                val = vga_6845_read(&vc->hdl, mode);
                vga_6845_write(&vc->hdl, mode, val | 0x80);
 #endif
        } else {                                        /* blank screen */
                val = vga_ts_read(&vc->hdl, mode);
-               vga_ts_write(&vc->hdl, mode, val | VGA_TS_BLANK);
+               vga_ts_write(&vc->hdl, mode, val | VGA_TS_MODE_BLANK);
 #ifndef VGA_NO_VBLANK
                val = vga_6845_read(&vc->hdl, mode);
                vga_6845_write(&vc->hdl, mode, val & ~0x80);
@@ -937,7 +936,7 @@
        int i;
 
        /* Disable display. */
-       vga_ts_write(vh, mode, vga_ts_read(vh, mode) | 0x20);
+       vga_ts_write(vh, mode, vga_ts_read(vh, mode) | VGA_TS_MODE_BLANK);
 
        /* Write misc output register. */
        bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAW,
@@ -945,17 +944,17 @@
 
        /* Set synchronous reset. */
        vga_ts_write(vh, syncreset, 0x01);
-       vga_ts_write(vh, mode, regs->ts[1] | 0x20);
+       vga_ts_write(vh, mode, regs->ts[1] | VGA_TS_MODE_BLANK);
        for (i = 2; i < VGA_TS_NREGS; i++)
                _vga_ts_write(vh, i, regs->ts[i]);
        /* Clear synchronous reset. */
        vga_ts_write(vh, syncreset, 0x03);
 
        /* Unprotect CRTC registers 0-7. */
-       _vga_crtc_write(vh, 17, _vga_crtc_read(vh, 17) & 0x7f);
+       vga_6845_write(vh, vsynce, vga_6845_read(vh, vsynce) & ~0x80);
        /* Write CRTC registers. */
-       for (i = 0; i < VGA_CRTC_NREGS; i++)
-               _vga_crtc_write(vh, i, regs->crtc[i]);
+       for (i = 0; i < MC6845_NREGS; i++)
+               _vga_6845_write(vh, i, regs->crtc[i]);
 
        /* Write graphics display registers. */
        for (i = 0; i < VGA_GDC_NREGS; i++)
@@ -966,7 +965,7 @@
                _vga_attr_write(vh, i, regs->atc[i]);
 
        /* Enable display. */
-       vga_ts_write(vh, mode, vga_ts_read(vh, mode) & 0xdf);
+       vga_ts_write(vh, mode, vga_ts_read(vh, mode) & ~VGA_TS_MODE_BLANK);
 }
 
 void
@@ -1105,7 +1104,7 @@
                 * Put a single width space character no matter what the
                 * actual width of the character is.
                 */
-               _vga_raster_putchar(scr, row, col, 0x20, attr,
+               _vga_raster_putchar(scr, row, col, ' ', attr,
                    &vga_console_fontset_ascii);
        scr->mem[off].ch = c;
        scr->mem[off].attr = attr;
diff -r 80794c79d8b8 -r 866116da138a sys/dev/ic/vgareg.h
--- a/sys/dev/ic/vgareg.h       Mon Jan 27 14:54:39 2003 +0000
+++ b/sys/dev/ic/vgareg.h       Mon Jan 27 15:16:10 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vgareg.h,v 1.4 2001/12/30 13:13:04 junyoung Exp $ */
+/* $NetBSD: vgareg.h,v 1.5 2003/01/27 15:16:12 tsutsui Exp $ */
 
 /*
  * Copyright (c) 1998
@@ -38,16 +38,18 @@
        u_int8_t colreset, misc;
 };
 #define VGA_ATC_NREGS  21
-#define VGA_ATC_INDEX  0
-#define VGA_ATC_DATAW  0
-#define VGA_ATC_DATAR  1
+#define VGA_ATC_INDEX  0x0
+#define VGA_ATC_DATAW  0x0
+#define VGA_ATC_DATAR  0x1
 
 struct reg_vgats { /* indexed via port 0x3c4 */
        u_int8_t syncreset, mode, wrplmask, fontsel, memmode;
 };
-#define VGA_TS_NREGS   5 
-#define VGA_TS_INDEX   4
-#define VGA_TS_DATA    5
+#define VGA_TS_MODE_BLANK      0x20
+
+#define VGA_TS_NREGS   5
+#define VGA_TS_INDEX   0x4
+#define VGA_TS_DATA    0x5
 
 struct reg_vgagdc { /* indexed via port 0x3ce */
        u_int8_t setres, ensetres, colorcomp, rotfunc;
@@ -58,14 +60,10 @@
 #define VGA_GDC_INDEX  0xe
 #define VGA_GDC_DATA   0xf
 
-struct reg_vgacrtc { /* indexed via port 0x3d4 */
-       u_int8_t index[25];
-};
-#define VGA_CRTC_NREGS 25
-#define VGA_CRTC_INDEX 0x14
-#define VGA_CRTC_DATA  0x15
+/*
+ * CRTC registers are defined in sys/dev/ic/mc6845reg.h
+ */
 
 /* misc output register */
-#define VGA_MISC_INDEX 2
 #define VGA_MISC_DATAR 0xc
-#define VGA_MISC_DATAW 2
+#define VGA_MISC_DATAW 0x2
diff -r 80794c79d8b8 -r 866116da138a sys/dev/ic/vgavar.h
--- a/sys/dev/ic/vgavar.h       Mon Jan 27 14:54:39 2003 +0000
+++ b/sys/dev/ic/vgavar.h       Mon Jan 27 15:16:10 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vgavar.h,v 1.16 2003/01/27 14:46:11 tsutsui Exp $ */
+/* $NetBSD: vgavar.h,v 1.17 2003/01/27 15:16:12 tsutsui Exp $ */
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -90,8 +90,6 @@
 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);
-static inline u_int8_t         _vga_crtc_read(struct vga_handle *, int);
-static inline void     _vga_crtc_write(struct vga_handle *, int, u_int8_t);
 
 static inline u_int8_t
 _vga_attr_read(struct vga_handle *vh, int reg)
@@ -162,22 +160,6 @@
        bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA, val);
 }
 
-static inline u_int8_t
-_vga_crtc_read(struct vga_handle *vh, int reg)
-{
-
-       bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
-       return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA));
-}
-
-static inline void
-_vga_crtc_write(struct vga_handle *vh, int reg, u_int8_t val)
-{
-
-       bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
-       bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA, val);
-}
-
 #define vga_attr_read(vh, reg) \
        _vga_attr_read(vh, offsetof(struct reg_vgaattr, reg))
 #define vga_attr_write(vh, reg, val) \
@@ -195,6 +177,10 @@
        pcdisplay_6845_read(&(vh)->vh_ph, reg)
 #define vga_6845_write(vh, reg, val) \
        pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
+#define _vga_6845_read(vh, reg) \
+       _pcdisplay_6845_read(&(vh)->vh_ph, reg)
+#define _vga_6845_write(vh, reg, val) \
+       _pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
 
 int    vga_common_probe(bus_space_tag_t, bus_space_tag_t);
 void   vga_common_attach(struct vga_softc *, bus_space_tag_t,



Home | Main Index | Thread Index | Old Index