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 | 6 +++- vgasrc/stdvga.c | 21 +++++++++--------- vgasrc/stdvga.h | 15 ++++++------- vgasrc/vgabios.c | 6 ++-- vgasrc/vgabios.h | 12 +++++++++- vgasrc/vgafb.c | 12 +++++----- vgasrc/vgahw.h | 4 +++ vgasrc/vgatables.c | 58 ++++++++++++++++++++++++++------------------------- 8 files changed, 75 insertions(+), 59 deletions(-)
diff --git a/vgasrc/geodevga.c b/vgasrc/geodevga.c index 7735fdc..c1e4244 100644 --- a/vgasrc/geodevga.c +++ b/vgasrc/geodevga.c @@ -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(); diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index e90d48f..70d018a 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -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); diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h index 2aabf1b..4cef89f 100644 --- a/vgasrc/stdvga.h +++ b/vgasrc/stdvga.h @@ -2,6 +2,7 @@ #define __STDVGA_H
#include "types.h" // u8 +#include "vgabios.h" // struct vgamode_s
// VGA registers #define VGAREG_ACTL_ADDRESS 0x3c0 @@ -44,15 +45,9 @@ #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); diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index 854ed38..f351107 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -14,10 +14,10 @@ #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;
diff --git a/vgasrc/vgabios.h b/vgasrc/vgabios.h index 8b806ff..3416b98 100644 --- a/vgasrc/vgabios.h +++ b/vgasrc/vgabios.h @@ -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[]; diff --git a/vgasrc/vgafb.c b/vgasrc/vgafb.c index b933738..b6daba6 100644 --- a/vgasrc/vgafb.c +++ b/vgasrc/vgafb.c @@ -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;
diff --git a/vgasrc/vgahw.h b/vgasrc/vgahw.h index 23b4f13..55e3bc4 100644 --- a/vgasrc/vgahw.h +++ b/vgasrc/vgahw.h @@ -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); diff --git a/vgasrc/vgatables.c b/vgasrc/vgatables.c index 4fd9964..e62b11e 100644 --- a/vgasrc/vgatables.c +++ b/vgasrc/vgatables.c @@ -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; }