vgabios: Extract out common parts of struct vgamode_s.
authorKevin O'Connor <kevin@koconnor.net>
Tue, 10 Jan 2012 00:19:44 +0000 (19:19 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 14 Jan 2012 22:19:25 +0000 (17:19 -0500)
Extract out the fields in 'struct vgamode_s' that are used in the main
code.  The remaining fields are specific to the standard vga hardware
driver.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
vgasrc/geodevga.c
vgasrc/stdvga.c
vgasrc/stdvga.h
vgasrc/vgabios.c
vgasrc/vgabios.h
vgasrc/vgafb.c
vgasrc/vgahw.h
vgasrc/vgatables.c

index 7735fdca628a2b872cf26a04b08ea128c9428358..c1e4244b56b61bcb472d84e28cc3ce14d1571015 100644 (file)
@@ -367,10 +367,12 @@ int geodevga_init(void)
         u8 *crtc = GET_GLOBAL(new_crtc[i]);
         if (!crtc)
             continue;
-        struct vgamode_s *vmode_g = find_vga_entry(i);
+        struct vgamode_s *vmode_g = stdvga_find_mode(i);
         if (!vmode_g)
             continue;
-        SET_VGA(vmode_g->crtc_regs, crtc);
+        struct stdvga_mode_s *stdmode_g = container_of(
+            vmode_g, struct stdvga_mode_s, info);
+        SET_VGA(stdmode_g->crtc_regs, crtc);
     }
 
     ret |= vp_setup();
index e90d48f0ed7083f05fa1c8cf42cae805ec7c68ef..70d018abb294e48968558b45bcf42a88fb6e2151 100644 (file)
@@ -11,7 +11,6 @@
 #include "biosvar.h" // GET_GLOBAL
 #include "util.h" // memcpy_far
 #include "vbe.h" // VBE_RETURN_STATUS_FAILED
-#include "vgabios.h" // find_vga_entry
 
 // TODO
 //  * replace direct in/out calls with wrapper functions
@@ -544,18 +543,20 @@ int
 stdvga_set_mode(int mode, int flags)
 {
     // find the entry in the video modes
-    struct vgamode_s *vmode_g = find_vga_entry(mode);
+    struct vgamode_s *vmode_g = stdvga_find_mode(mode);
     dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
     if (!vmode_g)
         return VBE_RETURN_STATUS_FAILED;
+    struct stdvga_mode_s *stdmode_g = container_of(
+        vmode_g, struct stdvga_mode_s, info);
 
     // if palette loading (bit 3 of modeset ctl = 0)
     if (!(flags & MF_NOPALETTE)) {    // Set the PEL mask
-        stdvga_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
+        stdvga_set_pel_mask(GET_GLOBAL(stdmode_g->pelmask));
 
         // From which palette
-        u8 *palette_g = GET_GLOBAL(vmode_g->dac);
-        u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
+        u8 *palette_g = GET_GLOBAL(stdmode_g->dac);
+        u16 palsize = GET_GLOBAL(stdmode_g->dacsize) / 3;
 
         // Always 256*3 values
         stdvga_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
@@ -573,7 +574,7 @@ stdvga_set_mode(int mode, int flags)
     inb(VGAREG_ACTL_RESET);
 
     // Set Attribute Ctl
-    u8 *regs = GET_GLOBAL(vmode_g->actl_regs);
+    u8 *regs = GET_GLOBAL(stdmode_g->actl_regs);
     u16 i;
     for (i = 0; i <= 0x13; i++) {
         outb(i, VGAREG_ACTL_ADDRESS);
@@ -585,21 +586,21 @@ stdvga_set_mode(int mode, int flags)
     // Set Sequencer Ctl
     outb(0, VGAREG_SEQU_ADDRESS);
     outb(0x03, VGAREG_SEQU_DATA);
-    regs = GET_GLOBAL(vmode_g->sequ_regs);
+    regs = GET_GLOBAL(stdmode_g->sequ_regs);
     for (i = 1; i <= 4; i++) {
         outb(i, VGAREG_SEQU_ADDRESS);
         outb(GET_GLOBAL(regs[i - 1]), VGAREG_SEQU_DATA);
     }
 
     // Set Grafx Ctl
-    regs = GET_GLOBAL(vmode_g->grdc_regs);
+    regs = GET_GLOBAL(stdmode_g->grdc_regs);
     for (i = 0; i <= 8; i++) {
         outb(i, VGAREG_GRDC_ADDRESS);
         outb(GET_GLOBAL(regs[i]), VGAREG_GRDC_DATA);
     }
 
     // Set CRTC address VGA or MDA
-    u8 miscreg = GET_GLOBAL(vmode_g->miscreg);
+    u8 miscreg = GET_GLOBAL(stdmode_g->miscreg);
     u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
     if (!(miscreg & 1))
         crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
@@ -607,7 +608,7 @@ stdvga_set_mode(int mode, int flags)
     // Disable CRTC write protection
     outw(0x0011, crtc_addr);
     // Set CRTC regs
-    regs = GET_GLOBAL(vmode_g->crtc_regs);
+    regs = GET_GLOBAL(stdmode_g->crtc_regs);
     for (i = 0; i <= 0x18; i++) {
         outb(i, crtc_addr);
         outb(GET_GLOBAL(regs[i]), crtc_addr + 1);
index 2aabf1bb0294481fe4592689c033c675b0c7e7c5..4cef89f2e02ea84d5bd0882e3ad9497f3b185b41 100644 (file)
@@ -2,6 +2,7 @@
 #define __STDVGA_H
 
 #include "types.h" // u8
+#include "vgabios.h" // struct vgamode_s
 
 // VGA registers
 #define VGAREG_ACTL_ADDRESS            0x3c0
 #define SEG_CTEXT 0xB800
 #define SEG_MTEXT 0xB000
 
-struct vgamode_s {
+struct stdvga_mode_s {
     u16 mode;
-    u8 memmodel;
-    u16 width;
-    u16 height;
-    u8 depth;
-    u8 cwidth;
-    u8 cheight;
-    u16 sstart;
+    struct vgamode_s info;
 
     u8 pelmask;
     u8 *dac;
@@ -87,6 +82,10 @@ struct saveDACcolors {
     u8 color_select;
 };
 
+// vgatables.c
+struct vgamode_s *stdvga_find_mode(int mode);
+
+// stdvga.c
 void stdvga_set_border_color(u8 color);
 void stdvga_set_overscan_border_color(u8 color);
 u8 stdvga_get_overscan_border_color(void);
index 854ed38d63247b70ec8a6457d4d344ae49e61df6..f35110787b5a470f0daa15f1aa8d62345bf095fa 100644 (file)
 #include "bregs.h" // struct bregs
 #include "biosvar.h" // GET_BDA
 #include "util.h" // memset
-#include "vgabios.h" // find_vga_entry
+#include "vgabios.h" // calc_page_size
 #include "optionroms.h" // struct pci_data
 #include "config.h" // CONFIG_*
-#include "stdvga.h" // stdvga_set_mode
+#include "stdvga.h" // stdvga_set_cursor_shape
 #include "geodevga.h" // geodevga_init
 #include "bochsvga.h" // bochsvga_init
 #include "clext.h" // clext_init
@@ -137,7 +137,7 @@ set_active_page(u8 page)
         return;
 
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         return;
 
index 8b806ff144b0aaca59ff40cca678fb7426dc0717..3416b98f9ebccb27ce832ef549b8623d95ed982b 100644 (file)
@@ -40,9 +40,17 @@ struct saveBDAstate {
 #define MM_DIRECT          0x06
 #define MM_YUV             0x07
 
+struct vgamode_s {
+    u8 memmodel;
+    u16 width;
+    u16 height;
+    u8 depth;
+    u8 cwidth;
+    u8 cheight;
+    u16 sstart;
+};
+
 // vgatables.c
-struct vgamode_s;
-struct vgamode_s *find_vga_entry(u8 mode);
 void build_video_param(void);
 extern struct VideoSavePointer_s video_save_pointer_table;
 extern u8 static_functionality[];
index b93373821a01f1f249b48134b8d4b118b230d998..b6daba651ca26544caacae489610ab38571f1fcc 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "biosvar.h" // GET_BDA
 #include "util.h" // memset_far
-#include "vgabios.h" // find_vga_entry
+#include "vgahw.h" // vgahw_find_mode
 #include "stdvga.h" // stdvga_grdc_write
 
 
@@ -168,7 +168,7 @@ void
 vgafb_scroll(int nblines, int attr, struct cursorpos ul, struct cursorpos lr)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         return;
 
@@ -345,7 +345,7 @@ void
 vgafb_write_char(struct cursorpos cp, struct carattr ca)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         return;
 
@@ -371,7 +371,7 @@ struct carattr
 vgafb_read_char(struct cursorpos cp)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         goto fail;
 
@@ -403,7 +403,7 @@ void
 vgafb_write_pixel(u8 color, u16 x, u16 y)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         return;
 
@@ -459,7 +459,7 @@ u8
 vgafb_read_pixel(u16 x, u16 y)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         return 0;
 
index 23b4f135b310e9c459c77081b2067b9ef80b8ac6..55e3bc4cac9d5bf9078c28b5987e09652d6d7400 100644 (file)
@@ -9,6 +9,10 @@
 #include "stdvga.h" // stdvga_set_mode
 #include "geodevga.h" // geodevga_init
 
+static inline struct vgamode_s *vgahw_find_mode(int mode) {
+    return stdvga_find_mode(mode);
+}
+
 static inline int vgahw_set_mode(int mode, int flags) {
     if (CONFIG_VGA_CIRRUS)
         return clext_set_mode(mode, flags);
index 4fd99642433e630a422e1640c1f66783f29a206f..e62b11ebd7dabe5b54c5bdfe97824f6a7a15b967 100644 (file)
@@ -58,7 +58,7 @@ build_video_param(void)
         if (! mode)
             continue;
         struct VideoParam_s *vparam_g = &video_param_table[i];
-        struct vgamode_s *vmode_g = find_vga_entry(mode);
+        struct vgamode_s *vmode_g = stdvga_find_mode(mode);
         if (!vmode_g)
             continue;
         int width = GET_GLOBAL(vmode_g->width);
@@ -75,18 +75,20 @@ build_video_param(void)
         }
         SET_VGA(vparam_g->cheight, cheight);
         SET_VGA(vparam_g->slength, calc_page_size(memmodel, width, height));
+        struct stdvga_mode_s *stdmode_g = container_of(
+            vmode_g, struct stdvga_mode_s, info);
         memcpy_far(get_global_seg(), vparam_g->sequ_regs
-                   , get_global_seg(), GET_GLOBAL(vmode_g->sequ_regs)
+                   , get_global_seg(), GET_GLOBAL(stdmode_g->sequ_regs)
                    , ARRAY_SIZE(vparam_g->sequ_regs));
-        SET_VGA(vparam_g->miscreg, GET_GLOBAL(vmode_g->miscreg));
+        SET_VGA(vparam_g->miscreg, GET_GLOBAL(stdmode_g->miscreg));
         memcpy_far(get_global_seg(), vparam_g->crtc_regs
-                   , get_global_seg(), GET_GLOBAL(vmode_g->crtc_regs)
+                   , get_global_seg(), GET_GLOBAL(stdmode_g->crtc_regs)
                    , ARRAY_SIZE(vparam_g->crtc_regs));
         memcpy_far(get_global_seg(), vparam_g->actl_regs
-                   , get_global_seg(), GET_GLOBAL(vmode_g->actl_regs)
+                   , get_global_seg(), GET_GLOBAL(stdmode_g->actl_regs)
                    , ARRAY_SIZE(vparam_g->actl_regs));
         memcpy_far(get_global_seg(), vparam_g->grdc_regs
-                   , get_global_seg(), GET_GLOBAL(vmode_g->grdc_regs)
+                   , get_global_seg(), GET_GLOBAL(stdmode_g->grdc_regs)
                    , ARRAY_SIZE(vparam_g->grdc_regs));
     }
 
@@ -346,51 +348,51 @@ static u8 crtc_6A[] VAR16 = {
 #define PAL(x) x, sizeof(x)
 #define VPARAM(x) &video_param_table[x]
 
-static struct vgamode_s vga_modes[] VAR16 = {
-    //mode model       tx   ty bpp cw ch  sstart
+static struct stdvga_mode_s vga_modes[] VAR16 = {
+    //mode { model       tx   ty bpp cw ch  sstart    }
     // pelm  dac            sequ     misc  crtc     actl     grdc
-    {0x00, MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT
+    {0x00, { MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT }
      , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
-    {0x01, MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT
+    {0x01, { MM_TEXT,    40,  25, 4, 9, 16, SEG_CTEXT }
      , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
-    {0x02, MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT
+    {0x02, { MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT }
      , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
-    {0x03, MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT
+    {0x03, { MM_TEXT,    80,  25, 4, 9, 16, SEG_CTEXT }
      , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
-    {0x04, MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT
+    {0x04, { MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT }
      , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
-    {0x05, MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT
+    {0x05, { MM_CGA,    320, 200, 2, 8,  8, SEG_CTEXT }
      , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
-    {0x06, MM_CGA,    640, 200, 1, 8,  8, SEG_CTEXT
+    {0x06, { MM_CGA,    640, 200, 1, 8,  8, SEG_CTEXT }
      , 0xFF, PAL(palette1), sequ_06, 0x63, crtc_06, actl_06, grdc_06},
-    {0x07, MM_TEXT,    80,  25, 4, 9, 16, SEG_MTEXT
+    {0x07, { MM_TEXT,    80,  25, 4, 9, 16, SEG_MTEXT }
      , 0xFF, PAL(palette0), sequ_03, 0x66, crtc_07, actl_07, grdc_07},
-    {0x0D, MM_PLANAR, 320, 200, 4, 8,  8, SEG_GRAPH
+    {0x0D, { MM_PLANAR, 320, 200, 4, 8,  8, SEG_GRAPH }
      , 0xFF, PAL(palette1), sequ_0d, 0x63, crtc_0d, actl_0d, grdc_0d},
-    {0x0E, MM_PLANAR, 640, 200, 4, 8,  8, SEG_GRAPH
+    {0x0E, { MM_PLANAR, 640, 200, 4, 8,  8, SEG_GRAPH }
      , 0xFF, PAL(palette1), sequ_0e, 0x63, crtc_0e, actl_0d, grdc_0d},
-    {0x0F, MM_PLANAR, 640, 350, 1, 8, 14, SEG_GRAPH
+    {0x0F, { MM_PLANAR, 640, 350, 1, 8, 14, SEG_GRAPH }
      , 0xFF, PAL(palette0), sequ_0e, 0xa3, crtc_0f, actl_0f, grdc_0d},
-    {0x10, MM_PLANAR, 640, 350, 4, 8, 14, SEG_GRAPH
+    {0x10, { MM_PLANAR, 640, 350, 4, 8, 14, SEG_GRAPH }
      , 0xFF, PAL(palette2), sequ_0e, 0xa3, crtc_0f, actl_10, grdc_0d},
-    {0x11, MM_PLANAR, 640, 480, 1, 8, 16, SEG_GRAPH
+    {0x11, { MM_PLANAR, 640, 480, 1, 8, 16, SEG_GRAPH }
      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_11, grdc_0d},
-    {0x12, MM_PLANAR, 640, 480, 4, 8, 16, SEG_GRAPH
+    {0x12, { MM_PLANAR, 640, 480, 4, 8, 16, SEG_GRAPH }
      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_10, grdc_0d},
-    {0x13, MM_PACKED, 320, 200, 8, 8,  8, SEG_GRAPH
+    {0x13, { MM_PACKED, 320, 200, 8, 8,  8, SEG_GRAPH }
      , 0xFF, PAL(palette3), sequ_13, 0x63, crtc_13, actl_13, grdc_13},
-    {0x6A, MM_PLANAR, 800, 600, 4, 8, 16, SEG_GRAPH
+    {0x6A, { MM_PLANAR, 800, 600, 4, 8, 16, SEG_GRAPH }
      , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_6A, actl_10, grdc_0d},
 };
 
 struct vgamode_s *
-find_vga_entry(u8 mode)
+stdvga_find_mode(int mode)
 {
     int i;
     for (i = 0; i < ARRAY_SIZE(vga_modes); i++) {
-        struct vgamode_s *vmode_g = &vga_modes[i];
-        if (GET_GLOBAL(vmode_g->mode) == mode)
-            return vmode_g;
+        struct stdvga_mode_s *stdmode_g = &vga_modes[i];
+        if (GET_GLOBAL(stdmode_g->mode) == mode)
+            return &stdmode_g->info;
     }
     return NULL;
 }