VGA cleanups and endian control
cover VGA cleanups and endian control
This series cleans up VGA and a bit of cirrus to remove all the now unused conversions to non-32bpp surfaces. Then the last two patches add a proposed variant of the endian control register and the (still somewhat controversial) trick to auto-switch VGA endian on powerpc SPAPR platforms.
They apply on top of Gerd pixel format series
RFC 2/14 ui: Remove unused QEMU_BIG_ENDIAN_FLAG
If we need to, we should use the pixman formats instead but for now this is unused except in commented out code so take it out to avoid further confusion about surface endianness.
--- include/ui/console.h | 3 +-- ui/console.c | 7 ------- ui/vnc-enc-tight.c | 12 ++++-------- 3 files changed, 5 insertions(+), 17 deletions(-)
include/ui/console.h +1 -2
@@ -102,8 +102,7 @@ struct QemuConsoleClass {ObjectClass parent_class; }; -#define QEMU_BIG_ENDIAN_FLAG 0x01 -#define QEMU_ALLOCATED_FLAG 0x02 +#define QEMU_ALLOCATED_FLAG 0x01struct PixelFormat {uint8_t bits_per_pixel;
ui/console.c +0 -7
@@ -1236,9 +1236,6 @@ static void qemu_alloc_display(DisplaySurface *surface, int width, int height)assert (surface->image !=NULL ); surface->flags =QEMU_ALLOCATED_FLAG ; -#ifdef HOST_WORDS_BIGENDIAN - surface->flags |=QEMU_BIG_ENDIAN_FLAG ; -#endif }DisplaySurface *qemu_create_displaysurface (int width,int height)
@@ -1263,10 +1260,6 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height, (void *)data, linesize);assert (surface->image !=NULL ); -#ifdef HOST_WORDS_BIGENDIAN - surface->flags =QEMU_BIG_ENDIAN_FLAG ; -#endif -return surface; }
ui/vnc-enc-tight.c +4 -8
@@ -220,8 +220,7 @@ tight_detect_smooth_image24(VncState *vs, int w, int h)unsigned int errors; \unsigned char *buf = vs->tight.tight.buffer; \ \ - endian =0 ;/* FIXME: ((vs->clientds.flags & QEMU_BIG_ENDIAN_FLAG) != \ -(vs->ds->surface->flags & QEMU_BIG_ENDIAN_FLAG)); */ \ + endian =0 ;/* FIXME */ \ \ \ max[0 ] = vs->client_pf.rmax; \
@@ -563,8 +562,7 @@ tight_filter_gradient24(VncState *vs, uint8_t *buf, int w, int h) buf32 = (uint32_t *)buf;memset (vs->tight.gradient.buffer,0 , w *3 *sizeof (int )); -if (1 /* FIXME: (vs->clientds.flags & QEMU_BIG_ENDIAN_FLAG) == -(vs->ds->surface->flags & QEMU_BIG_ENDIAN_FLAG) */ ) { +if (1 /* FIXME */ ) { shift[0 ] = vs->client_pf.rshift; shift[1 ] = vs->client_pf.gshift; shift[2 ] = vs->client_pf.bshift;
@@ -621,8 +619,7 @@ tight_filter_gradient24(VncState *vs, uint8_t *buf, int w, int h) \memset (vs->tight.gradient.buffer,0 , w *3 *sizeof (int )); \ \ - endian =0 ;/* FIXME: ((vs->clientds.flags & QEMU_BIG_ENDIAN_FLAG) != \ -(vs->ds->surface->flags & QEMU_BIG_ENDIAN_FLAG)); */ \ + endian =0 ;/* FIXME */ \ \ max[0 ] = vs->client_pf.rmax; \ max[1 ] = vs->client_pf.gmax; \
@@ -898,8 +895,7 @@ static void tight_pack24(VncState *vs, uint8_t *buf, size_t count, size_t *ret) buf32 = (uint32_t *)buf; -if (1 /* FIXME: (vs->clientds.flags & QEMU_BIG_ENDIAN_FLAG) == -(vs->ds->surface->flags & QEMU_BIG_ENDIAN_FLAG) */ ) { +if (1 /* FIXME */ ) { rshift = vs->client_pf.rshift; gshift = vs->client_pf.gshift; bshift = vs->client_pf.bshift;
Signature · 1 line
1.9.1
RFC 9/14 cirrus: Remove non-32bpp cursor drawing
In reply to Benjamin HerrenschmidtWe only draw cursor on non-shared surfaces (so it seems...) and these are always 32bpp
--- hw/display/cirrus_vga.c | 64 +++++++++++++----------- hw/display/cirrus_vga_template.h | 102 --------------------------------------- 2 files changed, 36 insertions(+), 130 deletions(-) delete mode 100644 hw/display/cirrus_vga_template.h
hw/display/cirrus_vga.c +36 -28
@@ -2171,20 +2171,44 @@ static void cirrus_cursor_invalidate(VGACommonState *s1) } } -#define DEPTH 8 -#include "cirrus_vga_template.h" - -#define DEPTH 16 -#include "cirrus_vga_template.h" - -#define DEPTH 32 -#include "cirrus_vga_template.h" +static void vga_draw_cursor_line (uint8_t *d1, +const uint8_t *src1, +int poffset,int w, +unsigned int color0, +unsigned int color1, +unsigned int color_xor) +{ +const uint8_t *plane0, *plane1; +int x, b0, b1; +uint8_t *d; + + d = d1; + plane0 = src1; + plane1 = src1 + poffset; +for (x =0 ; x < w; x++) { + b0 = (plane0[x >>3 ] >> (7 - (x &7 ))) &1 ; + b1 = (plane1[x >>3 ] >> (7 - (x &7 ))) &1 ; +switch (b0 | (b1 <<1 )) { +case 0 : +break ; +case 1 : + ((uint32_t *)d)[0 ] ^= color_xor; +break ; +case 2 : + ((uint32_t *)d)[0 ] = color0; +break ; +case 3 : + ((uint32_t *)d)[0 ] = color1; +break ; + } + d +=4 ; + } +}static void cirrus_cursor_draw_line (VGACommonState *s1,uint8_t *d1,int scr_y) {CirrusVGAState *s =container_of (s1, CirrusVGAState, vga); -DisplaySurface *surface =qemu_console_surface (s->vga.con); -int w, h, bpp, x1, x2, poffset; +int w, h, x1, x2, poffset;unsigned int color0, color1;const uint8_t *palette, *src;uint32_t content;
@@ -2238,24 +2262,8 @@ static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y) color1 =rgb_to_pixel32 (c6_to_8 (palette[0xf *3 ]),c6_to_8 (palette[0xf *3 +1 ]),c6_to_8 (palette[0xf *3 +2 ])); - bpp =surface_bytes_per_pixel (surface); - d1 += x1 * bpp; -switch (surface_bits_per_pixel (surface)) { -default : -break ; -case 8 : -vga_draw_cursor_line_8 (d1, src, poffset, w, color0, color1,0xff ); -break ; -case 15 : -vga_draw_cursor_line_16 (d1, src, poffset, w, color0, color1,0x7fff ); -break ; -case 16 : -vga_draw_cursor_line_16 (d1, src, poffset, w, color0, color1,0xffff ); -break ; -case 32 : -vga_draw_cursor_line_32 (d1, src, poffset, w, color0, color1,0xffffff ); -break ; - } + d1 += x1 *4 ; +vga_draw_cursor_line (d1, src, poffset, w, color0, color1,0xffffff ); }/***************************************
hw/display/cirrus_vga_template.h deleted +0 -102
102 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC 1/14 vga: Create direct sufaces for depth 24 too
In reply to Benjamin Herrenschmidtpixman supports 24bpp directly, let's share surfaces For both endians even !
--- hw/display/vga.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/display/vga.c +2 -1
@@ -1692,7 +1692,8 @@ static void vga_draw_graphic(VGACommonState *s, int full_update) disp_width != s->last_width || height != s->last_height || s->last_depth != depth) { -if (depth ==32 || ((depth ==16 || depth ==15 ) && !byteswap)) { +if (depth ==32 || depth ==24 || + ((depth ==16 || depth ==15 ) && !byteswap)) {pixman_format_code_t format =qemu_default_pixman_format (depth, !byteswap); surface = qemu_create_displaysurface_from(disp_width,
Signature · 1 line
1.9.1
RFC 4/14 vga: Remove remainder of old conversion cruft
In reply to Benjamin HerrenschmidtAll the macros used to generate different versions of vga_template.h are now unnecessary, take them all out and remove the _32 suffix from most functions.
--- hw/display/vga.c | 46 +++++----- hw/display/vga_template.h | 226 +++++++++++++++------------------------------- 2 files changed, 95 insertions(+), 177 deletions(-)
hw/display/vga.c +22 -24
@@ -977,10 +977,8 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, uint32_t val)typedef void vga_draw_line_func (VGACommonState *s1,uint8_t *d,const uint8_t *s,int width); -#define DEPTH 32#include "vga_template.h" -static unsigned int rgb_to_pixel32_dup (unsigned int r,unsigned int g,unsigned b) {unsigned int col;
@@ -1279,19 +1277,19 @@ static void vga_draw_text(VGACommonState *s, int full_update) bgcol = palette[cattr >>4 ]; fgcol = palette[cattr &0x0f ];if (cw ==16 ) { -vga_draw_glyph16_32 (d1, linesize, - font_ptr, cheight, fgcol, bgcol); +vga_draw_glyph16 (d1, linesize, + font_ptr, cheight, fgcol, bgcol); }else if (cw !=9 ) { -vga_draw_glyph8_32 (d1, linesize, - font_ptr, cheight, fgcol, bgcol); +vga_draw_glyph8 (d1, linesize, + font_ptr, cheight, fgcol, bgcol); }else { dup9 =0 ;if (ch >=0xb0 && ch <=0xdf && (s->ar[VGA_ATC_MODE ] &0x04 )) { dup9 =1 ; } -vga_draw_glyph9_32 (d1, linesize, - font_ptr, cheight, fgcol, bgcol, dup9); +vga_draw_glyph9 (d1, linesize, + font_ptr, cheight, fgcol, bgcol, dup9); } if (src == cursor_ptr && !(s->cr[VGA_CRTC_CURSOR_START] & 0x20) &&
@@ -1307,14 +1305,14 @@ static void vga_draw_text(VGACommonState *s, int full_update) h = line_last - line_start +1 ; d = d1 + linesize * line_start;if (cw ==16 ) { -vga_draw_glyph16_32 (d, linesize, - cursor_glyph, h, fgcol, bgcol); +vga_draw_glyph16 (d, linesize, + cursor_glyph, h, fgcol, bgcol); }else if (cw !=9 ) { -vga_draw_glyph8_32 (d, linesize, - cursor_glyph, h, fgcol, bgcol); +vga_draw_glyph8 (d, linesize, + cursor_glyph, h, fgcol, bgcol); }else { -vga_draw_glyph9_32 (d, linesize, - cursor_glyph, h, fgcol, bgcol,1 ); +vga_draw_glyph9 (d, linesize, + cursor_glyph, h, fgcol, bgcol,1 ); } } }
@@ -1352,16 +1350,16 @@ enum { };static vga_draw_line_func *const vga_draw_line_table[VGA_DRAW_LINE_NB ] = { - vga_draw_line2_32, - vga_draw_line2d2_32, - vga_draw_line4_32, - vga_draw_line4d2_32, - vga_draw_line8d2_32, - vga_draw_line8_32, - vga_draw_line15_32, - vga_draw_line16_32, - vga_draw_line24_32, - vga_draw_line32_32, + vga_draw_line2, + vga_draw_line2d2, + vga_draw_line4, + vga_draw_line4d2, + vga_draw_line8d2, + vga_draw_line8, + vga_draw_line15, + vga_draw_line16, + vga_draw_line24, + vga_draw_line32, };static int vga_get_bpp (VGACommonState *s)
hw/display/vga_template.h +73 -153
414 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC 6/14 vga: 15 and 16bpp draw functions are "swapping" only
In reply to Benjamin HerrenschmidtWe now only use vga_draw_line15() and vga_draw_line16() when byteswapping. Otherwise we have a shared surface. Make this explicit and remove the reliance on lduw_p which uses TARGET_WORDS_ENDIAN. We now only rely on the "byteswap" variable in vga_draw_graphic().
--- hw/display/vga.c | 22 +++++++++++++--------- hw/display/vga_template.h | 23 ++++++++++++++++------- 2 files changed, 29 insertions(+), 16 deletions(-)
hw/display/vga.c +13 -9
@@ -1342,8 +1342,8 @@ enum {VGA_DRAW_LINE4D2 ,VGA_DRAW_LINE8D2 ,VGA_DRAW_LINE8 , -VGA_DRAW_LINE15 , -VGA_DRAW_LINE16 , +VGA_DRAW_LINE15_SWAP , +VGA_DRAW_LINE16_SWAP , VGA_DRAW_LINE_NB, };
@@ -1354,8 +1354,8 @@ static vga_draw_line_func * const vga_draw_line_table[VGA_DRAW_LINE_NB] = { vga_draw_line4d2, vga_draw_line8d2, vga_draw_line8, - vga_draw_line15, - vga_draw_line16, + vga_draw_line15_swap, + vga_draw_line16_swap, };static int vga_get_bpp (VGACommonState *s)
@@ -1537,12 +1537,15 @@ static void vga_draw_graphic(VGACommonState *s, int full_update) bits =8 ;break ;case 15 : - v =VGA_DRAW_LINE15 ; - bits =16 ; -break ;case 16 : - v =VGA_DRAW_LINE16 ; - bits =16 ; +if (byteswap) { + v = depth ==15 ?VGA_DRAW_LINE15_SWAP :VGA_DRAW_LINE16_SWAP ; + }else if (!is_buffer_shared (surface)) { +fprintf (stderr, +"vga: Non-shared surface at %dbpp unsupported !\n" , depth); +return ; + } + bits = depth;break ;case 24 :case 32 :
@@ -1552,6 +1555,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)return ; } bits = depth; +break ; } }if (!is_buffer_shared (surface)) {
hw/display/vga_template.h +16 -7
@@ -281,18 +281,28 @@ static void vga_draw_line8(VGACommonState *s1, uint8_t *d,/* XXX: optimize */ +/* We have lduw_he_p, lduw_be_p, lduw_le_p but we don't have +* lduw_sw_p, as in unconditionally swap :) So let's make it +* up here +*/ +#if defined(HOST_WORDS_BIGENDIAN ) +#define ld_sw_pixel16 lduw_le_p +#else +#define ld_sw_pixel16 lduw_be_p +#endif +/* * 15 bit color */ -static void vga_draw_line15 (VGACommonState *s1,uint8_t *d, -const uint8_t *s,int width) +static void vga_draw_line15_swap (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) {int w;uint32_t v, r, g, b; w = width; do { - v = lduw_p((void *)s); + v = ld_sw_pixel16((void *)s); r = (v >> 7) & 0xf8; g = (v >> 2) & 0xf8; b = (v << 3) & 0xf8;
@@ -305,15 +315,15 @@ static void vga_draw_line15(VGACommonState *s1, uint8_t *d,/* * 16 bit color */ -static void vga_draw_line16 (VGACommonState *s1,uint8_t *d, -const uint8_t *s,int width) +static void vga_draw_line16_swap (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) {int w;uint32_t v, r, g, b; w = width; do { - v = lduw_p((void *)s); + v = ld_sw_pixel16((void *)s); r = (v >> 8) & 0xf8; g = (v >> 3) & 0xfc; b = (v << 3) & 0xf8;
@@ -322,4 +332,3 @@ static void vga_draw_line16(VGACommonState *s1, uint8_t *d, d +=4 ; }while (--w !=0 ); } -
Signature · 1 line
1.9.1
RFC 3/14 vga: Start cutting out non-32bpp conversion support
In reply to Benjamin HerrenschmidtNowadays, we either share a surface with the host, or we create a 32bpp ARGB console surface.
So we only need to draw/convert to 32bpp, enabling us to remove all but one instance of vga_template.h inclusion (to be further cleaned up), rgb_to_pixel_* etc...
--- hw/display/vga.c | 258 +++++-------------------------------------------------- 1 file changed, 22 insertions(+), 236 deletions(-)
hw/display/vga.c +22 -236
@@ -974,81 +974,12 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, uint32_t val) } } -typedef void vga_draw_glyph8_func (uint8_t *d,int linesize, -const uint8_t *font_ptr,int h, -uint32_t fgcol,uint32_t bgcol); -typedef void vga_draw_glyph9_func (uint8_t *d,int linesize, -const uint8_t *font_ptr,int h, -uint32_t fgcol,uint32_t bgcol,int dup9);typedef void vga_draw_line_func (VGACommonState *s1,uint8_t *d,const uint8_t *s,int width); -#define DEPTH 8 -#include "vga_template.h" - -#define DEPTH 15 -#include "vga_template.h" - -#define BGR_FORMAT -#define DEPTH 15 -#include "vga_template.h" - -#define DEPTH 16 -#include "vga_template.h" - -#define BGR_FORMAT -#define DEPTH 16 -#include "vga_template.h" -#define DEPTH 32#include "vga_template.h" -#define BGR_FORMAT -#define DEPTH 32 -#include "vga_template.h" - -static unsigned int rgb_to_pixel8_dup (unsigned int r,unsigned int g,unsigned b) -{ -unsigned int col; - col =rgb_to_pixel8 (r, g, b); - col |= col <<8 ; - col |= col <<16 ; -return col; -} - -static unsigned int rgb_to_pixel15_dup (unsigned int r,unsigned int g,unsigned b) -{ -unsigned int col; - col =rgb_to_pixel15 (r, g, b); - col |= col <<16 ; -return col; -} - -static unsigned int rgb_to_pixel15bgr_dup (unsigned int r,unsigned int g, -unsigned int b) -{ -unsigned int col; - col =rgb_to_pixel15bgr (r, g, b); - col |= col <<16 ; -return col; -} - -static unsigned int rgb_to_pixel16_dup (unsigned int r,unsigned int g,unsigned b) -{ -unsigned int col; - col =rgb_to_pixel16 (r, g, b); - col |= col <<16 ; -return col; -} - -static unsigned int rgb_to_pixel16bgr_dup (unsigned int r,unsigned int g, -unsigned int b) -{ -unsigned int col; - col =rgb_to_pixel16bgr (r, g, b); - col |= col <<16 ; -return col; -}static unsigned int rgb_to_pixel32_dup (unsigned int r,unsigned int g,unsigned b) {
@@ -1057,13 +988,6 @@ static unsigned int rgb_to_pixel32_dup(unsigned int r, unsigned int g, unsignedreturn col; } -static unsigned int rgb_to_pixel32bgr_dup (unsigned int r,unsigned int g,unsigned b) -{ -unsigned int col; - col =rgb_to_pixel32bgr (r, g, b); -return col; -} -/* return true if the palette was modified */ static int update_palette16 (VGACommonState *s) {
@@ -1170,56 +1094,6 @@ static int update_basic_params(VGACommonState *s)return full_update; } -#define NB_DEPTHS 7 - -static inline int get_depth_index (DisplaySurface *s) -{ -switch (surface_bits_per_pixel (s)) { -default : -case 8 : -return 0 ; -case 15 : -return 1 ; -case 16 : -return 2 ; -case 32 : -if (is_surface_bgr (s)) { -return 4 ; - }else { -return 3 ; - } - } -} - -static vga_draw_glyph8_func *const vga_draw_glyph8_table[NB_DEPTHS ] = { - vga_draw_glyph8_8, - vga_draw_glyph8_16, - vga_draw_glyph8_16, - vga_draw_glyph8_32, - vga_draw_glyph8_32, - vga_draw_glyph8_16, - vga_draw_glyph8_16, -}; - -static vga_draw_glyph8_func *const vga_draw_glyph16_table[NB_DEPTHS ] = { - vga_draw_glyph16_8, - vga_draw_glyph16_16, - vga_draw_glyph16_16, - vga_draw_glyph16_32, - vga_draw_glyph16_32, - vga_draw_glyph16_16, - vga_draw_glyph16_16, -}; - -static vga_draw_glyph9_func *const vga_draw_glyph9_table[NB_DEPTHS ] = { - vga_draw_glyph9_8, - vga_draw_glyph9_16, - vga_draw_glyph9_16, - vga_draw_glyph9_32, - vga_draw_glyph9_32, - vga_draw_glyph9_16, - vga_draw_glyph9_16, -};static const uint8_t cursor_glyph[32 *4 ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,
@@ -1271,18 +1145,6 @@ static void vga_get_text_resolution(VGACommonState *s, int *pwidth, int *pheight *pcheight = cheight; } -typedef unsigned int rgb_to_pixel_dup_func (unsigned int r,unsigned int g,unsigned b); - -static rgb_to_pixel_dup_func *const rgb_to_pixel_dup_table[NB_DEPTHS ] = { - rgb_to_pixel8_dup, - rgb_to_pixel15_dup, - rgb_to_pixel16_dup, - rgb_to_pixel32_dup, - rgb_to_pixel32bgr_dup, - rgb_to_pixel15bgr_dup, - rgb_to_pixel16bgr_dup, -}; -/* * Text mode update * Missing:
@@ -1299,11 +1161,9 @@ static void vga_draw_text(VGACommonState *s, int full_update)uint32_t offset, fgcol, bgcol, v, cursor_offset;uint8_t *d1, *d, *src, *dest, *cursor_ptr;const uint8_t *font_ptr, *font_base[2 ]; -int dup9, line_offset, depth_index; +int dup9, line_offset;uint32_t *palette;uint32_t *ch_attr_ptr; -vga_draw_glyph8_func *vga_draw_glyph8; -vga_draw_glyph9_func *vga_draw_glyph9;int64_t now =qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL );/* compute font data address (in plane 2) */
@@ -1355,8 +1215,7 @@ static void vga_draw_text(VGACommonState *s, int full_update) s->last_cw = cw; full_update =1 ; } - s->rgb_to_pixel = - rgb_to_pixel_dup_table[get_depth_index (surface)]; + s->rgb_to_pixel = rgb_to_pixel32_dup; full_update |=update_palette16 (s); palette = s->last_palette; x_incr = cw *surface_bytes_per_pixel (surface);
@@ -1390,13 +1249,6 @@ static void vga_draw_text(VGACommonState *s, int full_update) s->cursor_visible_phase = !s->cursor_visible_phase; } - depth_index =get_depth_index (surface); -if (cw ==16 ) - vga_draw_glyph8 = vga_draw_glyph16_table[depth_index]; -else - vga_draw_glyph8 = vga_draw_glyph8_table[depth_index]; - vga_draw_glyph9 = vga_draw_glyph9_table[depth_index]; - dest =surface_data (surface); linesize =surface_stride (surface); ch_attr_ptr = s->last_ch_attr;
@@ -1426,17 +1278,20 @@ static void vga_draw_text(VGACommonState *s, int full_update) font_ptr +=32 *4 * ch; bgcol = palette[cattr >>4 ]; fgcol = palette[cattr &0x0f ]; -if (cw !=9 ) { -vga_draw_glyph8 (d1, linesize, - font_ptr, cheight, fgcol, bgcol); +if (cw ==16 ) { +vga_draw_glyph16_32 (d1, linesize, + font_ptr, cheight, fgcol, bgcol); + }else if (cw !=9 ) { +vga_draw_glyph8_32 (d1, linesize, + font_ptr, cheight, fgcol, bgcol); }else { dup9 =0 ;if (ch >=0xb0 && ch <=0xdf && (s->ar[VGA_ATC_MODE ] &0x04 )) { dup9 =1 ; } -vga_draw_glyph9 (d1, linesize, - font_ptr, cheight, fgcol, bgcol, dup9); +vga_draw_glyph9_32 (d1, linesize, + font_ptr, cheight, fgcol, bgcol, dup9); } if (src == cursor_ptr && !(s->cr[VGA_CRTC_CURSOR_START] & 0x20) &&
@@ -1451,12 +1306,15 @@ static void vga_draw_text(VGACommonState *s, int full_update)if (line_last >= line_start && line_start < cheight) { h = line_last - line_start +1 ; d = d1 + linesize * line_start; -if (cw !=9 ) { -vga_draw_glyph8 (d, linesize, - cursor_glyph, h, fgcol, bgcol); +if (cw ==16 ) { +vga_draw_glyph16_32 (d, linesize, + cursor_glyph, h, fgcol, bgcol); + }else if (cw !=9 ) { +vga_draw_glyph8_32 (d, linesize, + cursor_glyph, h, fgcol, bgcol); }else { -vga_draw_glyph9 (d, linesize, - cursor_glyph, h, fgcol, bgcol,1 ); +vga_draw_glyph9_32 (d, linesize, + cursor_glyph, h, fgcol, bgcol,1 ); } } }
@@ -1493,86 +1351,17 @@ enum { VGA_DRAW_LINE_NB, }; -static vga_draw_line_func *const vga_draw_line_table[NB_DEPTHS *VGA_DRAW_LINE_NB ] = { - vga_draw_line2_8, - vga_draw_line2_16, - vga_draw_line2_16, +static vga_draw_line_func *const vga_draw_line_table[VGA_DRAW_LINE_NB ] = { vga_draw_line2_32, - vga_draw_line2_32, - vga_draw_line2_16, - vga_draw_line2_16, - - vga_draw_line2d2_8, - vga_draw_line2d2_16, - vga_draw_line2d2_16, vga_draw_line2d2_32, - vga_draw_line2d2_32, - vga_draw_line2d2_16, - vga_draw_line2d2_16, - - vga_draw_line4_8, - vga_draw_line4_16, - vga_draw_line4_16, vga_draw_line4_32, - vga_draw_line4_32, - vga_draw_line4_16, - vga_draw_line4_16, - - vga_draw_line4d2_8, - vga_draw_line4d2_16, - vga_draw_line4d2_16, vga_draw_line4d2_32, - vga_draw_line4d2_32, - vga_draw_line4d2_16, - vga_draw_line4d2_16, - - vga_draw_line8d2_8, - vga_draw_line8d2_16, - vga_draw_line8d2_16, - vga_draw_line8d2_32, vga_draw_line8d2_32, - vga_draw_line8d2_16, - vga_draw_line8d2_16, - - vga_draw_line8_8, - vga_draw_line8_16, - vga_draw_line8_16, - vga_draw_line8_32, vga_draw_line8_32, - vga_draw_line8_16, - vga_draw_line8_16, - - vga_draw_line15_8, - vga_draw_line15_15, - vga_draw_line15_16, vga_draw_line15_32, - vga_draw_line15_32bgr, - vga_draw_line15_15bgr, - vga_draw_line15_16bgr, - - vga_draw_line16_8, - vga_draw_line16_15, - vga_draw_line16_16, vga_draw_line16_32, - vga_draw_line16_32bgr, - vga_draw_line16_15bgr, - vga_draw_line16_16bgr, - - vga_draw_line24_8, - vga_draw_line24_15, - vga_draw_line24_16, vga_draw_line24_32, - vga_draw_line24_32bgr, - vga_draw_line24_15bgr, - vga_draw_line24_16bgr, - - vga_draw_line32_8, - vga_draw_line32_15, - vga_draw_line32_16, vga_draw_line32_32, - vga_draw_line32_32bgr, - vga_draw_line32_15bgr, - vga_draw_line32_16bgr, };static int vga_get_bpp (VGACommonState *s)
@@ -1722,8 +1511,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)dpy_gfx_replace_surface (s->con, surface); } - s->rgb_to_pixel = - rgb_to_pixel_dup_table[get_depth_index (surface)]; + s->rgb_to_pixel = rgb_to_pixel32_dup;if (shift_control ==0 ) { full_update |=update_palette16 (s);
@@ -1772,8 +1560,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)break ; } } - vga_draw_line = vga_draw_line_table[v *NB_DEPTHS + -get_depth_index (surface)]; + vga_draw_line = vga_draw_line_table[v];if (!is_buffer_shared (surface) && s->cursor_invalidate) { s->cursor_invalidate (s);
@@ -1871,8 +1658,7 @@ static void vga_draw_blank(VGACommonState *s, int full_update)if (s->last_scr_width <=0 || s->last_scr_height <=0 )return ; - s->rgb_to_pixel = - rgb_to_pixel_dup_table[get_depth_index (surface)]; + s->rgb_to_pixel = rgb_to_pixel32_dup;if (surface_bits_per_pixel (surface) ==8 ) { val = s->rgb_to_pixel (0 ,0 ,0 ); }else {
Signature · 1 line
1.9.1
RFC 8/14 vga: Simplify vga_draw_blank() a bit
In reply to Benjamin HerrenschmidtThe test for surface_bits_per_pixel() isn't necessary anymore, the 8bpp case never happens.
--- hw/display/vga.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
hw/display/vga.c +2 -7
@@ -1639,7 +1639,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)static void vga_draw_blank (VGACommonState *s,int full_update) {DisplaySurface *surface =qemu_console_surface (s->con); -int i, w, val; +int i, w;uint8_t *d;if (!full_update)
@@ -1647,15 +1647,10 @@ static void vga_draw_blank(VGACommonState *s, int full_update)if (s->last_scr_width <=0 || s->last_scr_height <=0 )return ; -if (surface_bits_per_pixel (surface) ==8 ) { - val =rgb_to_pixel32 (0 ,0 ,0 ); - }else { - val =0 ; - } w = s->last_scr_width *surface_bytes_per_pixel (surface); d =surface_data (surface);for (i =0 ; i < s->last_scr_height; i++) { -memset (d, val, w); +memset (d,0 , w); d +=surface_stride (surface); } dpy_gfx_update(s->con, 0, 0,
Signature · 1 line
1.9.1
RFC 7/14 vga: Remove rgb_to_pixel indirection
In reply to Benjamin HerrenschmidtWe always use rgb_to_pixel32 nowadays.
--- hw/display/cirrus_vga.c | 15 +++++++++------ hw/display/vga.c | 31 ++++++++++--------------------- hw/display/vga_int.h | 2 -- 3 files changed, 19 insertions(+), 29 deletions(-)
hw/display/cirrus_vga.c +9 -6
@@ -29,6 +29,7 @@#include "hw/hw.h" #include "hw/pci/pci.h" #include "ui/console.h" +#include "ui/pixel_ops.h" #include "vga_int.h" #include "hw/loader.h"
@@ -2212,6 +2213,8 @@ static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y) }else { src += (s->vga.sr[0x13 ] &0x3f ) *256 ; src += (scr_y - s->hw_cursor_y) *4 ; + + poffset =128 ; content = ((uint32_t *)src)[0 ] | ((uint32_t *)(src +128 ))[0 ];
@@ -2229,12 +2232,12 @@ static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y) x2 = s->vga.last_scr_width; w = x2 - x1; palette = s->cirrus_hidden_palette; - color0 = s->vga.rgb_to_pixel (c6_to_8 (palette[0x0 *3 ]), -c6_to_8 (palette[0x0 *3 +1 ]), -c6_to_8 (palette[0x0 *3 +2 ])); - color1 = s->vga.rgb_to_pixel (c6_to_8 (palette[0xf *3 ]), -c6_to_8 (palette[0xf *3 +1 ]), -c6_to_8 (palette[0xf *3 +2 ])); + color0 =rgb_to_pixel32 (c6_to_8 (palette[0x0 *3 ]), +c6_to_8 (palette[0x0 *3 +1 ]), +c6_to_8 (palette[0x0 *3 +2 ])); + color1 =rgb_to_pixel32 (c6_to_8 (palette[0xf *3 ]), +c6_to_8 (palette[0xf *3 +1 ]), +c6_to_8 (palette[0xf *3 +2 ])); bpp =surface_bytes_per_pixel (surface); d1 += x1 * bpp;switch (surface_bits_per_pixel (surface)) {
hw/display/vga.c +10 -21
@@ -979,13 +979,6 @@ typedef void vga_draw_line_func(VGACommonState *s1, uint8_t *d,#include "vga_template.h" -static unsigned int rgb_to_pixel32_dup (unsigned int r,unsigned int g,unsigned b) -{ -unsigned int col; - col =rgb_to_pixel32 (r, g, b); -return col; -} -/* return true if the palette was modified */ static int update_palette16 (VGACommonState *s) {
@@ -1002,9 +995,9 @@ static int update_palette16(VGACommonState *s) v = ((s->ar[VGA_ATC_COLOR_PAGE ] &0xc ) <<4 ) | (v &0x3f ); } v = v *3 ; - col = s->rgb_to_pixel (c6_to_8 (s->palette[v]), -c6_to_8 (s->palette[v +1 ]), -c6_to_8 (s->palette[v +2 ])); + col =rgb_to_pixel32 (c6_to_8 (s->palette[v]), +c6_to_8 (s->palette[v +1 ]), +c6_to_8 (s->palette[v +2 ]));if (col != palette[i]) { full_update =1 ; palette[i] = col;
@@ -1024,13 +1017,13 @@ static int update_palette256(VGACommonState *s) v =0 ;for (i =0 ; i <256 ; i++) {if (s->dac_8bit) { - col = s->rgb_to_pixel (s->palette[v], - s->palette[v +1 ], - s->palette[v +2 ]); + col =rgb_to_pixel32 (s->palette[v], + s->palette[v +1 ], + s->palette[v +2 ]); }else { - col = s->rgb_to_pixel (c6_to_8 (s->palette[v]), -c6_to_8 (s->palette[v +1 ]), -c6_to_8 (s->palette[v +2 ])); + col =rgb_to_pixel32 (c6_to_8 (s->palette[v]), +c6_to_8 (s->palette[v +1 ]), +c6_to_8 (s->palette[v +2 ])); }if (col != palette[i]) { full_update =1 ;
@@ -1213,7 +1206,6 @@ static void vga_draw_text(VGACommonState *s, int full_update) s->last_cw = cw; full_update =1 ; } - s->rgb_to_pixel = rgb_to_pixel32_dup; full_update |=update_palette16 (s); palette = s->last_palette; x_incr = cw *surface_bytes_per_pixel (surface);
@@ -1505,8 +1497,6 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)dpy_gfx_replace_surface (s->con, surface); } - s->rgb_to_pixel = rgb_to_pixel32_dup; -if (shift_control ==0 ) { full_update |=update_palette16 (s);if (s->sr[VGA_SEQ_CLOCK_MODE ] &8 ) {
@@ -1657,9 +1647,8 @@ static void vga_draw_blank(VGACommonState *s, int full_update)if (s->last_scr_width <=0 || s->last_scr_height <=0 )return ; - s->rgb_to_pixel = rgb_to_pixel32_dup;if (surface_bits_per_pixel (surface) ==8 ) { - val = s->rgb_to_pixel (0 ,0 ,0 ); + val =rgb_to_pixel32 (0 ,0 ,0 ); }else { val =0 ; }
hw/display/vga_int.h +0 -2
@@ -152,8 +152,6 @@ typedef struct VGACommonState {bool cursor_visible_phase;int64_t cursor_blink_time;uint32_t cursor_offset; -unsigned int (*rgb_to_pixel)(unsigned int r, -unsigned int g,unsigned b);const GraphicHwOps *hw_ops;bool full_update_text;bool full_update_gfx;
Signature · 1 line
1.9.1
RFC 10/14 vga: Remove some "should be done in BIOS" comments
In reply to Benjamin HerrenschmidtNot all platforms have a VGA BIOS, powerpc typically relies on using the DISPI interface to initialize the card.
--- hw/display/vga.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/display/vga.c +2 -4
@@ -695,14 +695,13 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) ((s->vbe_regs[VBE_DISPI_INDEX_BPP ] +7 ) >>3 ); s->vbe_start_addr =0 ; -/* clear the screen (should be done in BIOS) */ +/* clear the screen */ if (!(val &VBE_DISPI_NOCLEARMEM )) {memset (s->vram_ptr,0 , s->vbe_regs[VBE_DISPI_INDEX_YRES ] * s->vbe_line_offset); } -/* we initialize the VGA graphic mode (should be done -in BIOS) */ +/* we initialize the VGA graphic mode */ /* graphic mode + memory map 1 */ s->gr[VGA_GFX_MISC ] = (s->gr[VGA_GFX_MISC ] & ~0x0c ) |0x04 |VGA_GR06_GRAPHICS_MODE ;
@@ -735,7 +734,6 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) (shift_control <<5 ); s->cr[VGA_CRTC_MAX_SCAN ] &= ~0x9f ;/* no double scan */ }else { -/* XXX: the bios should do that */ s->bank_offset =0 ; } s->dac_8bit = (val &VBE_DISPI_8BIT_DAC ) >0 ;
Signature · 1 line
1.9.1
RFC 13/14 vga: Add endian control register
In reply to Benjamin HerrenschmidtInclude the endian state in the migration stream as an optional subsection which we only include when the endian isn't the default, thus enabling backward compatibility of the common case.
--- hw/display/vga.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++------ hw/display/vga_int.h | 15 +++++++++++++- 2 files changed, 63 insertions(+), 7 deletions(-)
hw/display/vga.c +49 -6
@@ -615,6 +615,11 @@ uint32_t vbe_ioport_read_data(void *opaque, uint32_t addr) } }else if (s->vbe_index ==VBE_DISPI_INDEX_VIDEO_MEMORY_64K ) { val = s->vram_size / (64 *1024 ); + }else if (s->vbe_index ==VBE_DISPI_INDEX_EXTENDED_CAPS ) { + val =VBE_DISPI_HAS_ENDIAN_CTRL ; + }else if (s->vbe_index ==VBE_DISPI_INDEX_ENDIAN_CTRL ) { + val = s->big_endian_fb ?VBE_DISPI_BIG_ENDIAN : +VBE_DISPI_LITTLE_ENDIAN ; }else { val =0 ; }
@@ -634,7 +639,8 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) {VGACommonState *s = opaque; -if (s->vbe_index <=VBE_DISPI_INDEX_NB ) { +if (s->vbe_index <=VBE_DISPI_INDEX_NB || + s->vbe_index ==VBE_DISPI_INDEX_ENDIAN_CTRL ) {#ifdef DEBUG_BOCHS_VBE printf ("VBE: write index=0x%x val=0x%x\n" , s->vbe_index, val);#endif
@@ -737,7 +743,7 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) s->bank_offset =0 ; } s->dac_8bit = (val &VBE_DISPI_8BIT_DAC ) >0 ; - s->vbe_regs[s->vbe_index] = val; + s->vbe_regs[s->vbe_index] = val |VBE_DISPI_EXTCAPS ;vga_update_memory_access (s);break ;case VBE_DISPI_INDEX_VIRT_WIDTH :
@@ -774,6 +780,9 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) s->vbe_start_addr >>=2 ; }break ; +case VBE_DISPI_INDEX_ENDIAN_CTRL : + s->big_endian_fb = !!(val &VBE_DISPI_BIG_ENDIAN ); +break ;default :break ; }
@@ -1464,7 +1473,8 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)if (s->line_offset != s->last_line_offset || disp_width != s->last_width || height != s->last_height || - s->last_depth != depth) { + s->last_depth != depth || + s->last_byteswap != byteswap) {if (depth ==32 || depth ==24 || ((depth ==16 || depth ==15 ) && !byteswap)) { pixman_format_code_t format =
@@ -1483,6 +1493,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update) s->last_height = height; s->last_line_offset = s->line_offset; s->last_depth = depth; + s->last_byteswap = byteswap; full_update =1 ; } else if (is_buffer_shared(surface) && (full_update || surface_data(surface) != s->vram_ptr
@@ -1731,6 +1742,7 @@ void vga_common_reset(VGACommonState *s) s->vbe_index =0 ;memset (s->vbe_regs,'\0' ,sizeof (s->vbe_regs)); s->vbe_regs[VBE_DISPI_INDEX_ID ] =VBE_DISPI_ID5 ; + s->vbe_regs[VBE_DISPI_INDEX_ENABLE ] =VBE_DISPI_EXTCAPS ; s->vbe_start_addr =0 ; s->vbe_line_offset =0 ; s->vbe_bank_mask = (s->vram_size >>16 ) -1 ;
@@ -1751,6 +1763,7 @@ void vga_common_reset(VGACommonState *s) s->cursor_start =0 ; s->cursor_end =0 ; s->cursor_offset =0 ; + s->big_endian_fb = s->default_endian_fb;memset (s->invalidated_y_table,'\0' ,sizeof (s->invalidated_y_table));memset (s->last_palette,'\0' ,sizeof (s->last_palette));memset (s->last_ch_attr,'\0' ,sizeof (s->last_ch_attr));
@@ -1982,6 +1995,28 @@ static int vga_common_post_load(void *opaque, int version_id)return 0 ; } +static bool vga_endian_state_needed (void *opaque) +{ +VGACommonState *s = opaque; + +/* +* Only send the endian state if it's different from the +* default one, thus ensuring backward compatibility for +* migration of the common case +*/ +return s->default_endian_fb != s->big_endian_fb; +} + +const VMStateDescription vmstate_vga_endian = { + .name ="vga.endian" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8_EQUAL (big_endian_fb, VGACommonState), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_vga_common = { .name ="vga" , .version_id =2 ,
@@ -2018,6 +2053,14 @@ const VMStateDescription vmstate_vga_common = { VMSTATE_UINT32(vbe_line_offset, VGACommonState), VMSTATE_UINT32(vbe_bank_mask, VGACommonState),VMSTATE_END_OF_LIST () + }, + .subsections = (VMStateSubsection []) { + { + .vmsd = &vmstate_vga_endian, + .needed = vga_endian_state_needed, + }, { +/* empty */ + } } };
@@ -2084,14 +2127,14 @@ void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate) }/* -* Set default fb endian based on target, should probably be turned +* Set default fb endian based on target, could probably be turned * into a device attribute set by the machine/platform to remove * all target endian dependencies from this file. */ #ifdef TARGET_WORDS_BIGENDIAN - s->big_endian_fb = true; + s->default_endian_fb = true;#else - s->big_endian_fb = false; + s->default_endian_fb = false;#endif vga_dirty_log_start (s); }
hw/display/vga_int.h +14 -1
@@ -47,6 +47,8 @@#define VBE_DISPI_INDEX_Y_OFFSET 0x9#define VBE_DISPI_INDEX_NB 0xa/* size of vbe_regs[] */ #define VBE_DISPI_INDEX_VIDEO_MEMORY_64K 0xa/* read-only, not in vbe_regs */ +#define VBE_DISPI_INDEX_EXTENDED_CAPS 0xb/* read-only, not in vbe_regs */ +#define VBE_DISPI_INDEX_ENDIAN_CTRL 0xc/* not in vbe_regs */ #define VBE_DISPI_ID0 0xB0C0#define VBE_DISPI_ID1 0xB0C1
@@ -55,13 +57,22 @@#define VBE_DISPI_ID4 0xB0C4#define VBE_DISPI_ID5 0xB0C5 +/* VBE_DISPI_INDEX_ENABLE fields */ #define VBE_DISPI_DISABLED 0x00#define VBE_DISPI_ENABLED 0x01#define VBE_DISPI_GETCAPS 0x02 +#define VBE_DISPI_EXTCAPS 0x10/* RO: set when 0xb present */ #define VBE_DISPI_8BIT_DAC 0x20#define VBE_DISPI_LFB_ENABLED 0x40#define VBE_DISPI_NOCLEARMEM 0x80 +/* VBE_DISPI_INDEX_EXTENDED_CAPS fields */ +#define VBE_DISPI_HAS_ENDIAN_CTRL 0x01/* RO: has endian control reg */ + +/* VBE_DISPI_INDEX_ENDIAN_CTRL */ +#define VBE_DISPI_LITTLE_ENDIAN 0x00 +#define VBE_DISPI_BIG_ENDIAN 0x01 +#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000#define CH_ATTR_SIZE (160 * 100)
@@ -148,6 +159,7 @@ typedef struct VGACommonState {uint32_t last_width, last_height;/* in chars or pixels */ uint32_t last_scr_width, last_scr_height;/* in pixels */ uint32_t last_depth;/* in bits */ +bool last_byteswap;uint8_t cursor_start, cursor_end;bool cursor_visible_phase;int64_t cursor_blink_time;
@@ -155,7 +167,8 @@ typedef struct VGACommonState {const GraphicHwOps *hw_ops;bool full_update_text;bool full_update_gfx; -bool big_endian_fb; +uint8_t big_endian_fb; +uint8_t default_endian_fb;/* hardware mouse cursor support */ uint32_t invalidated_y_table[VGA_MAX_HEIGHT /32 ];void (*cursor_invalidate)(struct VGACommonState *s);
Signature · 1 line
1.9.1
RFC 5/14 vga: Remove unused vga_draw_line24() and vga_draw_line32()
In reply to Benjamin Herrenschmidt24 and 32bpp surfaces are always shared, we never "draw" them anymore
--- hw/display/vga.c | 29 +++++++++++------------- hw/display/vga_template.h | 56 ----------------------------------------------- 2 files changed, 13 insertions(+), 72 deletions(-)
hw/display/vga.c +13 -16
@@ -1344,8 +1344,6 @@ enum {VGA_DRAW_LINE8 ,VGA_DRAW_LINE15 ,VGA_DRAW_LINE16 , -VGA_DRAW_LINE24 , -VGA_DRAW_LINE32 , VGA_DRAW_LINE_NB, };
@@ -1358,8 +1356,6 @@ static vga_draw_line_func * const vga_draw_line_table[VGA_DRAW_LINE_NB] = { vga_draw_line8, vga_draw_line15, vga_draw_line16, - vga_draw_line24, - vga_draw_line32, };static int vga_get_bpp (VGACommonState *s)
@@ -1431,7 +1427,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)int disp_width, multi_scan, multi_run;uint8_t *d;uint32_t v, addr1, addr; -vga_draw_line_func *vga_draw_line; +vga_draw_line_func *vga_draw_line =NULL ;#if defined(HOST_WORDS_BIGENDIAN ) == defined(TARGET_WORDS_BIGENDIAN )static const bool byteswap = false;#else
@@ -1528,7 +1524,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update) } bits =4 ; }else { -switch (s->get_bpp (s)) { +switch (depth) {default :case 0 : full_update |=update_palette256 (s);
@@ -1549,19 +1545,20 @@ static void vga_draw_graphic(VGACommonState *s, int full_update) bits =16 ;break ;case 24 : - v =VGA_DRAW_LINE24 ; - bits =24 ; -break ;case 32 : - v =VGA_DRAW_LINE32 ; - bits =32 ; -break ; +if (!is_buffer_shared (surface)) { +fprintf (stderr, +"vga: Non-shared surface at %dbpp unsupported !\n" , depth); +return ; + } + bits = depth; } } - vga_draw_line = vga_draw_line_table[v]; - -if (!is_buffer_shared (surface) && s->cursor_invalidate) { - s->cursor_invalidate (s); +if (!is_buffer_shared (surface)) { + vga_draw_line = vga_draw_line_table[v]; +if (s->cursor_invalidate) { + s->cursor_invalidate (s); + } } line_offset = s->line_offset;
hw/display/vga_template.h +0 -56
59 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC 12/14 vga: Rename vga_template.h to vga-helpers.h
In reply to Benjamin HerrenschmidtIt's no longer a template, we only instanciate the file once.
Keep it a #included file so the functions remain static.
--- hw/display/vga-helpers.h | 334 ++++++++++++++++++++++++++++++++++++++++++++++ hw/display/vga.c | 2 +- hw/display/vga_template.h | 334 ---------------------------------------------- 3 files changed, 335 insertions(+), 335 deletions(-) create mode 100644 hw/display/vga-helpers.h delete mode 100644 hw/display/vga_template.h
hw/display/vga-helpers.h new file +334 -0
@@ -0,0 +1,334 @@ +/* +* QEMU VGA Emulator templates +* +* Copyright (c) 2003 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +static inline void vga_draw_glyph_line (uint8_t *d,uint32_t font_data, +uint32_t xorcol,uint32_t bgcol) +{ + ((uint32_t *)d)[0 ] = (-((font_data >>7 )) & xorcol) ^ bgcol; + ((uint32_t *)d)[1 ] = (-((font_data >>6 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[2 ] = (-((font_data >>5 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[3 ] = (-((font_data >>4 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[4 ] = (-((font_data >>3 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[5 ] = (-((font_data >>2 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[6 ] = (-((font_data >>1 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[7 ] = (-((font_data >>0 ) &1 ) & xorcol) ^ bgcol; +} + +static void vga_draw_glyph8 (uint8_t *d,int linesize, +const uint8_t *font_ptr,int h, +uint32_t fgcol,uint32_t bgcol) +{ +uint32_t font_data, xorcol; + + xorcol = bgcol ^ fgcol; +do { + font_data = font_ptr[0 ]; +vga_draw_glyph_line (d, font_data, xorcol, bgcol); + font_ptr +=4 ; + d += linesize; + }while (--h); +} + +static void vga_draw_glyph16 (uint8_t *d,int linesize, +const uint8_t *font_ptr,int h, +uint32_t fgcol,uint32_t bgcol) +{ +uint32_t font_data, xorcol; + + xorcol = bgcol ^ fgcol; +do { + font_data = font_ptr[0 ]; +vga_draw_glyph_line (d, expand4to8[font_data >>4 ], + xorcol, bgcol); +vga_draw_glyph_line (d +32 , expand4to8[font_data &0x0f ], + xorcol, bgcol); + font_ptr +=4 ; + d += linesize; + }while (--h); +} + +static void vga_draw_glyph9 (uint8_t *d,int linesize, +const uint8_t *font_ptr,int h, +uint32_t fgcol,uint32_t bgcol,int dup9) +{ +uint32_t font_data, xorcol, v; + + xorcol = bgcol ^ fgcol; +do { + font_data = font_ptr[0 ]; + ((uint32_t *)d)[0 ] = (-((font_data >>7 )) & xorcol) ^ bgcol; + ((uint32_t *)d)[1 ] = (-((font_data >>6 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[2 ] = (-((font_data >>5 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[3 ] = (-((font_data >>4 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[4 ] = (-((font_data >>3 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[5 ] = (-((font_data >>2 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[6 ] = (-((font_data >>1 ) &1 ) & xorcol) ^ bgcol; + v = (-((font_data >>0 ) &1 ) & xorcol) ^ bgcol; + ((uint32_t *)d)[7 ] = v; +if (dup9) + ((uint32_t *)d)[8 ] = v; +else + ((uint32_t *)d)[8 ] = bgcol; + font_ptr +=4 ; + d += linesize; + }while (--h); +} + +/* +* 4 color mode +*/ +static void vga_draw_line2 (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) +{ +uint32_t plane_mask, *palette, data, v; +int x; + + palette = s1->last_palette; + plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE ] &0xf ]; + width >>=3 ; +for (x =0 ; x < width; x++) { + data = ((uint32_t *)s)[0 ]; + data &= plane_mask; + v = expand2[GET_PLANE (data,0 )]; + v |= expand2[GET_PLANE (data,2 )] <<2 ; + ((uint32_t *)d)[0 ] = palette[v >>12 ]; + ((uint32_t *)d)[1 ] = palette[(v >>8 ) &0xf ]; + ((uint32_t *)d)[2 ] = palette[(v >>4 ) &0xf ]; + ((uint32_t *)d)[3 ] = palette[(v >>0 ) &0xf ]; + + v = expand2[GET_PLANE (data,1 )]; + v |= expand2[GET_PLANE (data,3 )] <<2 ; + ((uint32_t *)d)[4 ] = palette[v >>12 ]; + ((uint32_t *)d)[5 ] = palette[(v >>8 ) &0xf ]; + ((uint32_t *)d)[6 ] = palette[(v >>4 ) &0xf ]; + ((uint32_t *)d)[7 ] = palette[(v >>0 ) &0xf ]; + d +=32 ; + s +=4 ; + } +} + +#define PUT_PIXEL2 (d, n, v) \ +((uint32_t *)d)[2*(n)] = ((uint32_t *)d)[2*(n)+1] = (v) + +/* +* 4 color mode, dup2 horizontal +*/ +static void vga_draw_line2d2 (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) +{ +uint32_t plane_mask, *palette, data, v; +int x; + + palette = s1->last_palette; + plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE ] &0xf ]; + width >>=3 ; +for (x =0 ; x < width; x++) { + data = ((uint32_t *)s)[0 ]; + data &= plane_mask; + v = expand2[GET_PLANE (data,0 )]; + v |= expand2[GET_PLANE (data,2 )] <<2 ; +PUT_PIXEL2 (d,0 , palette[v >>12 ]); +PUT_PIXEL2 (d,1 , palette[(v >>8 ) &0xf ]); +PUT_PIXEL2 (d,2 , palette[(v >>4 ) &0xf ]); +PUT_PIXEL2 (d,3 , palette[(v >>0 ) &0xf ]); + + v = expand2[GET_PLANE (data,1 )]; + v |= expand2[GET_PLANE (data,3 )] <<2 ; +PUT_PIXEL2 (d,4 , palette[v >>12 ]); +PUT_PIXEL2 (d,5 , palette[(v >>8 ) &0xf ]); +PUT_PIXEL2 (d,6 , palette[(v >>4 ) &0xf ]); +PUT_PIXEL2 (d,7 , palette[(v >>0 ) &0xf ]); + d +=64 ; + s +=4 ; + } +} + +/* +* 16 color mode +*/ +static void vga_draw_line4 (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) +{ +uint32_t plane_mask, data, v, *palette; +int x; + + palette = s1->last_palette; + plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE ] &0xf ]; + width >>=3 ; +for (x =0 ; x < width; x++) { + data = ((uint32_t *)s)[0 ]; + data &= plane_mask; + v = expand4[GET_PLANE (data,0 )]; + v |= expand4[GET_PLANE (data,1 )] <<1 ; + v |= expand4[GET_PLANE (data,2 )] <<2 ; + v |= expand4[GET_PLANE (data,3 )] <<3 ; + ((uint32_t *)d)[0 ] = palette[v >>28 ]; + ((uint32_t *)d)[1 ] = palette[(v >>24 ) &0xf ]; + ((uint32_t *)d)[2 ] = palette[(v >>20 ) &0xf ]; + ((uint32_t *)d)[3 ] = palette[(v >>16 ) &0xf ]; + ((uint32_t *)d)[4 ] = palette[(v >>12 ) &0xf ]; + ((uint32_t *)d)[5 ] = palette[(v >>8 ) &0xf ]; + ((uint32_t *)d)[6 ] = palette[(v >>4 ) &0xf ]; + ((uint32_t *)d)[7 ] = palette[(v >>0 ) &0xf ]; + d +=32 ; + s +=4 ; + } +} + +/* +* 16 color mode, dup2 horizontal +*/ +static void vga_draw_line4d2 (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) +{ +uint32_t plane_mask, data, v, *palette; +int x; + + palette = s1->last_palette; + plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE ] &0xf ]; + width >>=3 ; +for (x =0 ; x < width; x++) { + data = ((uint32_t *)s)[0 ]; + data &= plane_mask; + v = expand4[GET_PLANE (data,0 )]; + v |= expand4[GET_PLANE (data,1 )] <<1 ; + v |= expand4[GET_PLANE (data,2 )] <<2 ; + v |= expand4[GET_PLANE (data,3 )] <<3 ; +PUT_PIXEL2 (d,0 , palette[v >>28 ]); +PUT_PIXEL2 (d,1 , palette[(v >>24 ) &0xf ]); +PUT_PIXEL2 (d,2 , palette[(v >>20 ) &0xf ]); +PUT_PIXEL2 (d,3 , palette[(v >>16 ) &0xf ]); +PUT_PIXEL2 (d,4 , palette[(v >>12 ) &0xf ]); +PUT_PIXEL2 (d,5 , palette[(v >>8 ) &0xf ]); +PUT_PIXEL2 (d,6 , palette[(v >>4 ) &0xf ]); +PUT_PIXEL2 (d,7 , palette[(v >>0 ) &0xf ]); + d +=64 ; + s +=4 ; + } +} + +/* +* 256 color mode, double pixels +* +* XXX: add plane_mask support (never used in standard VGA modes) +*/ +static void vga_draw_line8d2 (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) +{ +uint32_t *palette; +int x; + + palette = s1->last_palette; + width >>=3 ; +for (x =0 ; x < width; x++) { +PUT_PIXEL2 (d,0 , palette[s[0 ]]); +PUT_PIXEL2 (d,1 , palette[s[1 ]]); +PUT_PIXEL2 (d,2 , palette[s[2 ]]); +PUT_PIXEL2 (d,3 , palette[s[3 ]]); + d +=32 ; + s +=4 ; + } +} + +/* +* standard 256 color mode +* +* XXX: add plane_mask support (never used in standard VGA modes) +*/ +static void vga_draw_line8 (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) +{ +uint32_t *palette; +int x; + + palette = s1->last_palette; + width >>=3 ; +for (x =0 ; x < width; x++) { + ((uint32_t *)d)[0 ] = palette[s[0 ]]; + ((uint32_t *)d)[1 ] = palette[s[1 ]]; + ((uint32_t *)d)[2 ] = palette[s[2 ]]; + ((uint32_t *)d)[3 ] = palette[s[3 ]]; + ((uint32_t *)d)[4 ] = palette[s[4 ]]; + ((uint32_t *)d)[5 ] = palette[s[5 ]]; + ((uint32_t *)d)[6 ] = palette[s[6 ]]; + ((uint32_t *)d)[7 ] = palette[s[7 ]]; + d +=32 ; + s +=8 ; + } +} + + +/* XXX: optimize */ + +/* We have lduw_he_p, lduw_be_p, lduw_le_p but we don't have +* lduw_sw_p, as in unconditionally swap :) So let's make it +* up here +*/ +#if defined(HOST_WORDS_BIGENDIAN ) +#define ld_sw_pixel16 lduw_le_p +#else +#define ld_sw_pixel16 lduw_be_p +#endif + +/* +* 15 bit color +*/ +static void vga_draw_line15_swap (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) +{ +int w; +uint32_t v, r, g, b; + + w = width; +do { + v =ld_sw_pixel16 ((void *)s); + r = (v >>7 ) &0xf8 ; + g = (v >>2 ) &0xf8 ; + b = (v <<3 ) &0xf8 ; + ((uint32_t *)d)[0 ] =rgb_to_pixel32 (r, g, b); + s +=2 ; + d +=4 ; + }while (--w !=0 ); +} + +/* +* 16 bit color +*/ +static void vga_draw_line16_swap (VGACommonState *s1,uint8_t *d, +const uint8_t *s,int width) +{ +int w; +uint32_t v, r, g, b; + + w = width; +do { + v =ld_sw_pixel16 ((void *)s); + r = (v >>8 ) &0xf8 ; + g = (v >>3 ) &0xfc ; + b = (v <<3 ) &0xf8 ; + ((uint32_t *)d)[0 ] =rgb_to_pixel32 (r, g, b); + s +=2 ; + d +=4 ; + }while (--w !=0 ); +}
hw/display/vga.c +1 -1
@@ -975,7 +975,7 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, uint32_t val)typedef void vga_draw_line_func (VGACommonState *s1,uint8_t *d,const uint8_t *s,int width); -#include "vga_template.h" +#include "vga-helpers.h" /* return true if the palette was modified */ static int update_palette16 (VGACommonState *s)
hw/display/vga_template.h deleted +0 -334
334 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC 11/14 vga: Make fb endian a common state variable
In reply to Benjamin HerrenschmidtAnd initialize it based on target endian
--- hw/display/vga.c | 17 ++++++++++++++--- hw/display/vga_int.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-)
hw/display/vga.c +14 -3
@@ -1418,10 +1418,10 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)uint8_t *d;uint32_t v, addr1, addr;vga_draw_line_func *vga_draw_line =NULL ; -#if defined(HOST_WORDS_BIGENDIAN ) == defined(TARGET_WORDS_BIGENDIAN ) -static const bool byteswap = false; +#ifdef HOST_WORDS_BIGENDIAN +bool byteswap = !s->big_endian_fb;#else -static const bool byteswap = true; +bool byteswap = s->big_endian_fb;#endif full_update |=update_basic_params (s);
@@ -2082,6 +2082,17 @@ void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate) s->update_retrace_info = vga_precise_update_retrace_info;break ; } + +/* +* Set default fb endian based on target, should probably be turned +* into a device attribute set by the machine/platform to remove +* all target endian dependencies from this file. +*/ +#ifdef TARGET_WORDS_BIGENDIAN + s->big_endian_fb = true; +#else + s->big_endian_fb = false; +#endif vga_dirty_log_start (s); }
hw/display/vga_int.h +1 -0
@@ -155,6 +155,7 @@ typedef struct VGACommonState {const GraphicHwOps *hw_ops;bool full_update_text;bool full_update_gfx; +bool big_endian_fb;/* hardware mouse cursor support */ uint32_t invalidated_y_table[VGA_MAX_HEIGHT /32 ];void (*cursor_invalidate)(struct VGACommonState *s);
Signature · 1 line
1.9.1
RFC 14/14 ppc/spapr/vga: Switch VGA endian on H_SET_MODE
In reply to Benjamin HerrenschmidtWhen the guest switches the interrupt endian mode, which essentially means a global machine endian switch, we want to change the VGA framebuffer endian mode as well in order to be backward compatible with existing guests who don't know about the new endian control register.
--- hw/display/vga-pci.c | 8 ++++++++ hw/ppc/spapr_hcall.c | 2 ++ hw/ppc/spapr_pci.c | 26 ++++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + include/hw/ppc/spapr.h | 1 + 5 files changed, 38 insertions(+)
hw/display/vga-pci.c +8 -0
@@ -212,6 +212,14 @@ static void pci_secondary_vga_reset(DeviceState *dev)vga_common_reset (&d->vga); } +void pci_vga_switch_fb_endian (DeviceState *dev,bool big_endian) +{ +PCIVGAState *d =DO_UPCAST (PCIVGAState, dev.qdev, dev); +VGACommonState *s = &d->vga; + + s->big_endian_fb = big_endian; +} +static Property vga_pci_properties[] = {DEFINE_PROP_UINT32 ("vgamem_mb" , PCIVGAState, vga.vram_size_mb,16 ),DEFINE_PROP_BIT ("mmio" , PCIVGAState, flags,PCI_VGA_FLAG_ENABLE_MMIO , true),
hw/ppc/spapr_hcall.c +2 -0
@@ -731,12 +731,14 @@ static target_ulong h_set_mode_resouce_le(PowerPCCPU *cpu,CPU_FOREACH (cs) {set_spr (cs,SPR_LPCR ,0 ,LPCR_ILE ); } +spapr_pci_switch_vga (true);return H_SUCCESS ;case H_SET_MODE_ENDIAN_LITTLE : CPU_FOREACH(cs) {set_spr (cs,SPR_LPCR ,LPCR_ILE ,LPCR_ILE ); } +spapr_pci_switch_vga (false);return H_SUCCESS ; }
hw/ppc/spapr_pci.c +26 -0
@@ -926,3 +926,29 @@ static void spapr_pci_register_types(void) }type_init (spapr_pci_register_types) + +static int spapr_switch_one_vga(DeviceState *dev, void *opaque) +{ +bool be = *(bool *)opaque; + +if (!strcmp (object_get_typename (OBJECT (dev)),"VGA" )) { +pci_vga_switch_fb_endian (dev, be); + } +return 0 ; +} + +void spapr_pci_switch_vga (bool big_endian) +{ +sPAPRPHBState *sphb; + +/* +* For backward compatibility with existing guests, we switch +* the endianness of the VGA controller when changing the guest +* interrupt mode +*/ + QLIST_FOREACH(sphb, &spapr->phbs, list) { +BusState *bus = &PCI_HOST_BRIDGE (sphb)->bus->qbus; +qbus_walk_children (bus, spapr_switch_one_vga,NULL ,NULL ,NULL , + &big_endian); + } +}
include/hw/pci/pci.h +1 -0
@@ -373,6 +373,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, const char *default_devaddr);PCIDevice *pci_vga_init (PCIBus *bus); +void pci_vga_switch_fb_endian (DeviceState *dev,bool big_endian);int pci_bus_num (PCIBus *s); void pci_for_each_device(PCIBus *bus, int bus_num,
include/hw/ppc/spapr.h +1 -0
@@ -425,5 +425,6 @@ int spapr_dma_dt(void *fdt, int node_off, const char *propname, uint32_t liobn, uint64_t window, uint32_t size);int spapr_tcet_dma_dt (void *fdt,int node_off,const char *propname,sPAPRTCETable *tcet); +void spapr_pci_switch_vga (bool big_endian);#endif /* !defined (__HW_SPAPR_H__) */
Signature · 1 line
1.9.1
Re: [Qemu-devel] [RFC 11/14] vga: Make fb endian a common state variable
In reply to Benjamin Herrenschmidthw/display/vga_int.h typedef struct VGACommonState { · line 158
Quoted 6 lines · Benjamin Herrenschmidt
And initialize it based on target endian
hw/display/vga_int.h +1
-0@@ -155,6 +155,7 @@ typedef struct VGACommonState {const GraphicHwOps *hw_ops;bool full_update_text;bool full_update_gfx; +bool big_endian_fb;
Don't we need to migrate this new state somehow?
thanks
-- PMM
Re: [Qemu-devel] [RFC 11/14] vga: Make fb endian a common state variable
Quoted 9 lines · Peter Maydell
hw/display/vga_int.h typedef struct VGACommonState { · line 158
Quoted 6 lines · Benjamin Herrenschmidt
And initialize it based on target endian
hw/display/vga_int.h +1
-0@@ -155,6 +155,7 @@ typedef struct VGACommonState {const GraphicHwOps *hw_ops;bool full_update_text;bool full_update_gfx; +bool big_endian_fb;Don't we need to migrate this new state somehow?
Only when it can change, which is done in patch 13
This patch (11) just moves it around to the state but its value is still fixed at this point in the series.
Cheers,
Ben.
Re: [Qemu-devel] [RFC 13/14] vga: Add endian control register
In reply to Benjamin HerrenschmidtQuoted 3 lines · Benjamin Herrenschmidt
Include the endian state in the migration stream as an optional subsection which we only include when the endian isn't the default, thus enabling backward compatibility of the common case.
Note: This description is a bit too terse, sorry about that....
This is based on the proposed register addition that I've discussed in a separate email, adding an "extended capabilities" register and using it to expose the endian control.
Arguably, this could be split into 2 patches...
At this point however, I'd first want to make sure we all agree on the approach before going down into the details.
I haven't been successful contacting the Bochs folks, either on their mailing list or on IRC.
Ben.
Quoted 201 lines
Signed-off-by Benjamin Herrenschmidt <[email protected]>--- hw/display/vga.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++------ hw/display/vga_int.h | 15 +++++++++++++- 2 files changed, 63 insertions(+), 7 deletions(-)hw/display/vga.c +49
-6@@ -615,6 +615,11 @@ uint32_t vbe_ioport_read_data(void *opaque, uint32_t addr) } }else if (s->vbe_index ==VBE_DISPI_INDEX_VIDEO_MEMORY_64K ) { val = s->vram_size / (64 *1024 ); + }else if (s->vbe_index ==VBE_DISPI_INDEX_EXTENDED_CAPS ) { + val =VBE_DISPI_HAS_ENDIAN_CTRL ; + }else if (s->vbe_index ==VBE_DISPI_INDEX_ENDIAN_CTRL ) { + val = s->big_endian_fb ?VBE_DISPI_BIG_ENDIAN : +VBE_DISPI_LITTLE_ENDIAN ; }else { val =0 ; }@@ -634,7 +639,8 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) {VGACommonState *s = opaque; -if (s->vbe_index <=VBE_DISPI_INDEX_NB ) { +if (s->vbe_index <=VBE_DISPI_INDEX_NB || + s->vbe_index ==VBE_DISPI_INDEX_ENDIAN_CTRL ) {#ifdef DEBUG_BOCHS_VBE printf ("VBE: write index=0x%x val=0x%x\n" , s->vbe_index, val);#endif @@ -737,7 +743,7 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) s->bank_offset =0 ; } s->dac_8bit = (val &VBE_DISPI_8BIT_DAC ) >0 ; - s->vbe_regs[s->vbe_index] = val; + s->vbe_regs[s->vbe_index] = val |VBE_DISPI_EXTCAPS ;vga_update_memory_access (s);break ;case VBE_DISPI_INDEX_VIRT_WIDTH :@@ -774,6 +780,9 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val) s->vbe_start_addr >>=2 ; }break ; +case VBE_DISPI_INDEX_ENDIAN_CTRL : + s->big_endian_fb = !!(val &VBE_DISPI_BIG_ENDIAN ); +break ;default :break ; }@@ -1464,7 +1473,8 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)if (s->line_offset != s->last_line_offset || disp_width != s->last_width || height != s->last_height || - s->last_depth != depth) { + s->last_depth != depth || + s->last_byteswap != byteswap) {if (depth ==32 || depth ==24 || ((depth ==16 || depth ==15 ) && !byteswap)) { pixman_format_code_t format =@@ -1483,6 +1493,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update) s->last_height = height; s->last_line_offset = s->line_offset; s->last_depth = depth; + s->last_byteswap = byteswap; full_update =1 ; } else if (is_buffer_shared(surface) && (full_update || surface_data(surface) != s->vram_ptr@@ -1731,6 +1742,7 @@ void vga_common_reset(VGACommonState *s) s->vbe_index =0 ;memset (s->vbe_regs,'\0' ,sizeof (s->vbe_regs)); s->vbe_regs[VBE_DISPI_INDEX_ID ] =VBE_DISPI_ID5 ; + s->vbe_regs[VBE_DISPI_INDEX_ENABLE ] =VBE_DISPI_EXTCAPS ; s->vbe_start_addr =0 ; s->vbe_line_offset =0 ; s->vbe_bank_mask = (s->vram_size >>16 ) -1 ;@@ -1751,6 +1763,7 @@ void vga_common_reset(VGACommonState *s) s->cursor_start =0 ; s->cursor_end =0 ; s->cursor_offset =0 ; + s->big_endian_fb = s->default_endian_fb;memset (s->invalidated_y_table,'\0' ,sizeof (s->invalidated_y_table));memset (s->last_palette,'\0' ,sizeof (s->last_palette));memset (s->last_ch_attr,'\0' ,sizeof (s->last_ch_attr));@@ -1982,6 +1995,28 @@ static int vga_common_post_load(void *opaque, int version_id)return 0 ; } +static bool vga_endian_state_needed (void *opaque) +{ +VGACommonState *s = opaque; + +/* +* Only send the endian state if it's different from the +* default one, thus ensuring backward compatibility for +* migration of the common case +*/ +return s->default_endian_fb != s->big_endian_fb; +} + +const VMStateDescription vmstate_vga_endian = { + .name ="vga.endian" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8_EQUAL (big_endian_fb, VGACommonState), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_vga_common = { .name ="vga" , .version_id =2 ,@@ -2018,6 +2053,14 @@ const VMStateDescription vmstate_vga_common = { VMSTATE_UINT32(vbe_line_offset, VGACommonState), VMSTATE_UINT32(vbe_bank_mask, VGACommonState),VMSTATE_END_OF_LIST () + }, + .subsections = (VMStateSubsection []) { + { + .vmsd = &vmstate_vga_endian, + .needed = vga_endian_state_needed, + }, { +/* empty */ + } } };@@ -2084,14 +2127,14 @@ void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate) }/* -* Set default fb endian based on target, should probably be turned +* Set default fb endian based on target, could probably be turned * into a device attribute set by the machine/platform to remove * all target endian dependencies from this file. */ #ifdef TARGET_WORDS_BIGENDIAN - s->big_endian_fb = true; + s->default_endian_fb = true;#else - s->big_endian_fb = false; + s->default_endian_fb = false;#endif vga_dirty_log_start (s); }hw/display/vga_int.h +14
-1@@ -47,6 +47,8 @@#define VBE_DISPI_INDEX_Y_OFFSET 0x9#define VBE_DISPI_INDEX_NB 0xa/* size of vbe_regs[] */ #define VBE_DISPI_INDEX_VIDEO_MEMORY_64K 0xa/* read-only, not in vbe_regs */ +#define VBE_DISPI_INDEX_EXTENDED_CAPS 0xb/* read-only, not in vbe_regs */ +#define VBE_DISPI_INDEX_ENDIAN_CTRL 0xc/* not in vbe_regs */ #define VBE_DISPI_ID0 0xB0C0#define VBE_DISPI_ID1 0xB0C1@@ -55,13 +57,22 @@#define VBE_DISPI_ID4 0xB0C4#define VBE_DISPI_ID5 0xB0C5 +/* VBE_DISPI_INDEX_ENABLE fields */ #define VBE_DISPI_DISABLED 0x00#define VBE_DISPI_ENABLED 0x01#define VBE_DISPI_GETCAPS 0x02 +#define VBE_DISPI_EXTCAPS 0x10/* RO: set when 0xb present */ #define VBE_DISPI_8BIT_DAC 0x20#define VBE_DISPI_LFB_ENABLED 0x40#define VBE_DISPI_NOCLEARMEM 0x80 +/* VBE_DISPI_INDEX_EXTENDED_CAPS fields */ +#define VBE_DISPI_HAS_ENDIAN_CTRL 0x01/* RO: has endian control reg */ + +/* VBE_DISPI_INDEX_ENDIAN_CTRL */ +#define VBE_DISPI_LITTLE_ENDIAN 0x00 +#define VBE_DISPI_BIG_ENDIAN 0x01 +#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000#define CH_ATTR_SIZE (160 * 100)@@ -148,6 +159,7 @@ typedef struct VGACommonState {uint32_t last_width, last_height;/* in chars or pixels */ uint32_t last_scr_width, last_scr_height;/* in pixels */ uint32_t last_depth;/* in bits */ +bool last_byteswap;uint8_t cursor_start, cursor_end;bool cursor_visible_phase;int64_t cursor_blink_time;@@ -155,7 +167,8 @@ typedef struct VGACommonState {const GraphicHwOps *hw_ops;bool full_update_text;bool full_update_gfx; -bool big_endian_fb; +uint8_t big_endian_fb; +uint8_t default_endian_fb;/* hardware mouse cursor support */ uint32_t invalidated_y_table[VGA_MAX_HEIGHT /32 ];void (*cursor_invalidate)(struct VGACommonState *s);
Re: [Qemu-devel] [RFC 10/14] vga: Remove some "should be done in BIOS" comments
In reply to Benjamin HerrenschmidtQuoted 2 lines · Benjamin Herrenschmidt
Not all platforms have a VGA BIOS, powerpc typically relies on using the DISPI interface to initialize the card.
s/bios/guest/ and it would hold ;)
But the dispi interface is defined the way it is. We are not going to change it, even if it isn't perfect, as it is guest/host abi. So the comments are not very useful indeed ...
cheers,
Gerd
Re: [Qemu-devel] [RFC 13/14] vga: Add endian control register
In reply to Benjamin HerrenschmidtHi,
Quoted 14 lines
hw/display/vga_int.h +2
-0@@ -47,6 +47,8 @@#define VBE_DISPI_INDEX_Y_OFFSET 0x9#define VBE_DISPI_INDEX_NB 0xa/* size of vbe_regs[] */ #define VBE_DISPI_INDEX_VIDEO_MEMORY_64K 0xa/* read-only, not in vbe_regs */ +#define VBE_DISPI_INDEX_EXTENDED_CAPS 0xb/* read-only, not in vbe_regs */ +#define VBE_DISPI_INDEX_ENDIAN_CTRL 0xc/* not in vbe_regs */ #define VBE_DISPI_ID0 0xB0C0#define VBE_DISPI_ID1 0xB0C1
hw/display/vga_int.h line 58
Quoted 2 lines
hw/display/vga_int.h +0
-0@@ -55,13 +57,22 @@#define VBE_DISPI_ID4 0xB0C4#define VBE_DISPI_ID5 0xB0C5
I was more thinking to add ID6 to indicate the new interface revision with the additional VBE_DISPI_INDEX_ENDIAN_CTRL register.
I'm a bit worried that there is no response from the bochs guys yet, I don't want have two incompatible rev6 interfaces. At least nobody seems to have defined one so far, google finds nothing for "bochs dispi 0xB0C6".
cheers,
Gerd
Re: [Qemu-devel] [RFC 14/14] ppc/spapr/vga: Switch VGA endian on H_SET_MODE
In reply to Benjamin HerrenschmidtQuoted 5 lines · Benjamin Herrenschmidt
When the guest switches the interrupt endian mode, which essentially means a global machine endian switch, we want to change the VGA framebuffer endian mode as well in order to be backward compatible with existing guests who don't know about the new endian control register.
I'd tend to add a notifier (see include/qemu/notify.h) for endian switches instead, so anybody interested could register himself.
cheers,
Gerd
Quoted 7 lines · Benjamin Herrenschmidt
This series cleans up VGA and a bit of cirrus to remove all the now unused conversions to non-32bpp surfaces. Then the last two patches add a proposed variant of the endian control register and the (still somewhat controversial) trick to auto-switch VGA endian on powerpc SPAPR platforms.
They apply on top of Gerd pixel format series
Looks good overall. I'll go test this when I find time, after flushing my email backlog ...
cheers,
Gerd
Re: [Qemu-devel] [RFC 13/14] vga: Add endian control register
In reply to Gerd HoffmannQuoted 22 lines · Gerd Hoffmann
Hi,
Quoted 14 lines
hw/display/vga_int.h +2
-0@@ -47,6 +47,8 @@#define VBE_DISPI_INDEX_Y_OFFSET 0x9#define VBE_DISPI_INDEX_NB 0xa/* size of vbe_regs[] */ #define VBE_DISPI_INDEX_VIDEO_MEMORY_64K 0xa/* read-only, not in vbe_regs */ +#define VBE_DISPI_INDEX_EXTENDED_CAPS 0xb/* read-only, not in vbe_regs */ +#define VBE_DISPI_INDEX_ENDIAN_CTRL 0xc/* not in vbe_regs */ #define VBE_DISPI_ID0 0xB0C0#define VBE_DISPI_ID1 0xB0C1hw/display/vga_int.h line 58
Quoted 2 lines
hw/display/vga_int.h +0
-0@@ -55,13 +57,22 @@#define VBE_DISPI_ID4 0xB0C4#define VBE_DISPI_ID5 0xB0C5I was more thinking to add ID6 to indicate the new interface revision with the additional
VBE_DISPI_INDEX_ENDIAN_CTRLregister.
Quoted 4 lines
I'm a bit worried that there is no response from the bochs guys yet, I don't want have two incompatible rev6 interfaces. At least nobody seems to have defined one so far, google finds nothing for "bochs dispi
0xB0C6".
Ah ok, I haven't quite figured out how that DISPI_ID stuff works, I'll dig a bit. Definitely an option though I like the idea of an "capability" register in the new revision so we can easily add features that don't have to be implemented by the host (for example there's little point for Bochs to implement endian control).
The lack of response from Bochs worries me too. I've tried hanging out on their IRC as well with no result so far.
Cheers,
Ben.
Re: [Qemu-devel] [RFC 14/14] ppc/spapr/vga: Switch VGA endian on H_SET_MODE
In reply to Gerd HoffmannQuoted 9 lines · Gerd Hoffmann
Quoted 5 lines · Benjamin Herrenschmidt
When the guest switches the interrupt endian mode, which essentially means a global machine endian switch, we want to change the VGA framebuffer endian mode as well in order to be backward compatible with existing guests who don't know about the new endian control register.
I'd tend to add a notifier (see
include/qemu/notify.h) for endian switches instead, so anybody interested could register himself.
Ok thanks, I'll have a look.
Cheers,
Ben.
Quoted 11 lines · Gerd Hoffmann
Quoted 7 lines · Benjamin Herrenschmidt
This series cleans up VGA and a bit of cirrus to remove all the now unused conversions to non-32bpp surfaces. Then the last two patches add a proposed variant of the endian control register and the (still somewhat controversial) trick to auto-switch VGA endian on powerpc SPAPR platforms.
They apply on top of Gerd pixel format series
Looks good overall. I'll go test this when I find time, after flushing my email backlog ...
Thanks. The main issues I know of at this point are the HW cursor vs. cirrus and the lack of response from the Bochs guys...
I'll respin based on your other comments some time this or next week, let me know if there's any other low hanging fruit in that area that I can take care of while I'm at it.
Cheers,
Ben.
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 11 lines · Gerd Hoffmann
Quoted 7 lines · Benjamin Herrenschmidt
This series cleans up VGA and a bit of cirrus to remove all the now unused conversions to non-32bpp surfaces. Then the last two patches add a proposed variant of the endian control register and the (still somewhat controversial) trick to auto-switch VGA endian on powerpc SPAPR platforms.
They apply on top of Gerd pixel format series
Looks good overall. I'll go test this when I find time, after flushing my email backlog ...
Quoted 6 lines
Thanks. The main issues I know of at this point are the HW cursor vs. cirrus and the lack of response from the Bochs guys...
I'll respin based on your other comments some time this or next week, let me know if there's any other low hanging fruit in that area that I can take care of while I'm at it.
One thing I've planed to do is rewrite text mode rendering. There are some helpers for that in ui/qemu-pixman.c. They are used by the qemu text console today (i.e. "-chardev vc" + Ctrl-Alt-$nr console switching, see ui/console.c). In theory these helpers should work as-is for vga text mode rendering too, allowing to zap a whole bunch of glyph drawing code from vga.c.
Not sure how low hanging that actually is though ...
cheers,
Gerd
Quoted 4 lines · Gerd Hoffmann
Quoted 3 lines
I'll respin based on your other comments some time this or next week, let me know if there's any other low hanging fruit in that area that I can take care of while I'm at it.
Quoted 8 lines
One thing I've planed to do is rewrite text mode rendering. There are some helpers for that in
ui/qemu-pixman.c. They are used by the qemu text console today (i.e. "-chardev vc" + Ctrl-Alt-$nr console switching, seeui/console.c). In theory these helpers should work as-is for vga text mode rendering too, allowing to zap a whole bunch of glyph drawing code fromvga.c.Not sure how low hanging that actually is though ...
That might be a bit more than I'm willing to swallow right now :-) I'm actually quite busy otherwise... anyway, I'll have a quick look just in case but don't get your hopes too high up on that one.
Let me know if you find a test case for the cirrus HW cursor, I'll have a look at older X DDX on my side, or some other OS that might make use of it (I tried Haiku but that didn't seem to have a problem so I suspect they just do standard VESA).
Cheers,
Ben.
Re: [Qemu-devel] [RFC 01/14] vga: Create direct sufaces for depth 24 too
In reply to Benjamin HerrenschmidtHi,
hw/display/vga.c static void vga_draw_graphic(VGACommonState *s, int full_update) · line 1696
Quoted 3 lines
hw/display/vga.c +2
-1-if (depth ==32 || ((depth ==16 || depth ==15 ) && !byteswap)) { +if (depth ==32 || depth ==24 || + ((depth ==16 || depth ==15 ) && !byteswap)) {
Doesn't apply. depth == 15 isn't upstream. Guess you have some more local changes? Also the whitespace looks fishy (tabs vs. spaces?). Note that the qemu whitespace codestyle (spaces only) differs from linux kernel ...
cheers,
Gerd
Re: [Qemu-devel] [RFC 01/14] vga: Create direct sufaces for depth 24 too
Quoted 9 lines · Gerd Hoffmann
Hi,
hw/display/vga.c static void vga_draw_graphic(VGACommonState *s, int full_update) · line 1696
Quoted 3 lines
hw/display/vga.c +2
-1-if (depth ==32 || ((depth ==16 || depth ==15 ) && !byteswap)) { +if (depth ==32 || depth ==24 || + ((depth ==16 || depth ==15 ) && !byteswap)) {Doesn't apply.
depth == 15 isn't upstream.
It's added by the previous patch, I just git send-email'ed the series with the wrong starting point :-) I'll resend when I've addressed the other comments.
If you want to see the whole lot (including my fix to one of your patches) it's at https://github.com/ozbenh/qemu/commits/vga-work
Quoted 6 lines
Guess you have some more
local changes?Also the whitespace looks fishy (tabs vs. spaces?).
Note that the qemu whitespace codestyle (spaces only) differs from linux kernel ...
Yes, I am aware of that, I might have accidentally left a tab slip in, my emacs is still configured for Linux and I'm fixing them up "by hand" but that's obviously sub-optimal, I'll look into fixing that.
Cheers,
Ben.
Quoted 3 lines
cheers,
Gerd