vga: Replace VGA_COMMON with a structure

All VGA devices share a common field subset; currently they do so by
a macro which defines the common fields inline their state structures,
relying on the the common state being placed at offset 0 in the structure.
This makes refactoring the code difficult and requires a lot of error prone
casts.

Replace the macro by a new VGACommonState structure, and the casts by
regular field access and container_of() for upcasts.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Avi Kivity 2009-05-03 22:25:16 +03:00 committed by Anthony Liguori
parent fbb7b4e080
commit 4e12cd946f
5 changed files with 467 additions and 467 deletions

File diff suppressed because it is too large Load Diff

View File

@ -82,7 +82,7 @@ glue(glue(cirrus_bitblt_rop_fwd_transp_, ROP_NAME),_8)(CirrusVGAState *s,
for (x = 0; x < bltwidth; x++) {
p = *dst;
ROP_OP(p, *src);
if (p != s->gr[0x34]) *dst = p;
if (p != s->vga.gr[0x34]) *dst = p;
dst++;
src++;
}
@ -105,7 +105,7 @@ glue(glue(cirrus_bitblt_rop_bkwd_transp_, ROP_NAME),_8)(CirrusVGAState *s,
for (x = 0; x < bltwidth; x++) {
p = *dst;
ROP_OP(p, *src);
if (p != s->gr[0x34]) *dst = p;
if (p != s->vga.gr[0x34]) *dst = p;
dst--;
src--;
}
@ -130,7 +130,7 @@ glue(glue(cirrus_bitblt_rop_fwd_transp_, ROP_NAME),_16)(CirrusVGAState *s,
p2 = *(dst+1);
ROP_OP(p1, *src);
ROP_OP(p2, *(src+1));
if ((p1 != s->gr[0x34]) || (p2 != s->gr[0x35])) {
if ((p1 != s->vga.gr[0x34]) || (p2 != s->vga.gr[0x35])) {
*dst = p1;
*(dst+1) = p2;
}
@ -158,7 +158,7 @@ glue(glue(cirrus_bitblt_rop_bkwd_transp_, ROP_NAME),_16)(CirrusVGAState *s,
p2 = *dst;
ROP_OP(p1, *(src-1));
ROP_OP(p2, *src);
if ((p1 != s->gr[0x34]) || (p2 != s->gr[0x35])) {
if ((p1 != s->vga.gr[0x34]) || (p2 != s->vga.gr[0x35])) {
*(dst-1) = p1;
*dst = p2;
}

View File

@ -48,9 +48,9 @@ glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
unsigned int col;
const uint8_t *src1;
#if DEPTH == 24
int skipleft = s->gr[0x2f] & 0x1f;
int skipleft = s->vga.gr[0x2f] & 0x1f;
#else
int skipleft = (s->gr[0x2f] & 0x07) * (DEPTH / 8);
int skipleft = (s->vga.gr[0x2f] & 0x07) * (DEPTH / 8);
#endif
#if DEPTH == 8
@ -105,10 +105,10 @@ glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
unsigned bitmask;
unsigned index;
#if DEPTH == 24
int dstskipleft = s->gr[0x2f] & 0x1f;
int dstskipleft = s->vga.gr[0x2f] & 0x1f;
int srcskipleft = dstskipleft / 3;
#else
int srcskipleft = s->gr[0x2f] & 0x07;
int srcskipleft = s->vga.gr[0x2f] & 0x07;
int dstskipleft = srcskipleft * (DEPTH / 8);
#endif
@ -153,7 +153,7 @@ glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
unsigned bits;
unsigned int col;
unsigned bitmask;
int srcskipleft = s->gr[0x2f] & 0x07;
int srcskipleft = s->vga.gr[0x2f] & 0x07;
int dstskipleft = srcskipleft * (DEPTH / 8);
colors[0] = s->cirrus_blt_bgcol;
@ -188,10 +188,10 @@ glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
unsigned int bits, bits_xor;
unsigned int col;
#if DEPTH == 24
int dstskipleft = s->gr[0x2f] & 0x1f;
int dstskipleft = s->vga.gr[0x2f] & 0x1f;
int srcskipleft = dstskipleft / 3;
#else
int srcskipleft = s->gr[0x2f] & 0x07;
int srcskipleft = s->vga.gr[0x2f] & 0x07;
int dstskipleft = srcskipleft * (DEPTH / 8);
#endif
@ -232,7 +232,7 @@ glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
int x, y, bitpos, pattern_y;
unsigned int bits;
unsigned int col;
int srcskipleft = s->gr[0x2f] & 0x07;
int srcskipleft = s->vga.gr[0x2f] & 0x07;
int dstskipleft = srcskipleft * (DEPTH / 8);
colors[0] = s->cirrus_blt_bgcol;

View File

@ -94,94 +94,92 @@ union vga_retrace {
struct vga_precise_retrace precise;
};
struct VGAState;
typedef uint8_t (* vga_retrace_fn)(struct VGAState *s);
typedef void (* vga_update_retrace_info_fn)(struct VGAState *s);
struct VGACommonState;
typedef uint8_t (* vga_retrace_fn)(struct VGACommonState *s);
typedef void (* vga_update_retrace_info_fn)(struct VGACommonState *s);
#define VGA_STATE_COMMON \
uint8_t *vram_ptr; \
ram_addr_t vram_offset; \
unsigned int vram_size; \
uint32_t lfb_addr; \
uint32_t lfb_end; \
uint32_t map_addr; \
uint32_t map_end; \
uint32_t lfb_vram_mapped; /* whether 0xa0000 is mapped as ram */ \
unsigned long bios_offset; \
unsigned int bios_size; \
int it_shift; \
PCIDevice *pci_dev; \
uint32_t latch; \
uint8_t sr_index; \
uint8_t sr[256]; \
uint8_t gr_index; \
uint8_t gr[256]; \
uint8_t ar_index; \
uint8_t ar[21]; \
int ar_flip_flop; \
uint8_t cr_index; \
uint8_t cr[256]; /* CRT registers */ \
uint8_t msr; /* Misc Output Register */ \
uint8_t fcr; /* Feature Control Register */ \
uint8_t st00; /* status 0 */ \
uint8_t st01; /* status 1 */ \
uint8_t dac_state; \
uint8_t dac_sub_index; \
uint8_t dac_read_index; \
uint8_t dac_write_index; \
uint8_t dac_cache[3]; /* used when writing */ \
int dac_8bit; \
uint8_t palette[768]; \
int32_t bank_offset; \
int vga_io_memory; \
int (*get_bpp)(struct VGAState *s); \
void (*get_offsets)(struct VGAState *s, \
uint32_t *pline_offset, \
uint32_t *pstart_addr, \
uint32_t *pline_compare); \
void (*get_resolution)(struct VGAState *s, \
int *pwidth, \
int *pheight); \
VGA_STATE_COMMON_BOCHS_VBE \
/* display refresh support */ \
DisplayState *ds; \
uint32_t font_offsets[2]; \
int graphic_mode; \
uint8_t shift_control; \
uint8_t double_scan; \
uint32_t line_offset; \
uint32_t line_compare; \
uint32_t start_addr; \
uint32_t plane_updated; \
uint32_t last_line_offset; \
uint8_t last_cw, last_ch; \
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 */ \
uint8_t cursor_start, cursor_end; \
uint32_t cursor_offset; \
unsigned int (*rgb_to_pixel)(unsigned int r, \
unsigned int g, unsigned b); \
vga_hw_update_ptr update; \
vga_hw_invalidate_ptr invalidate; \
vga_hw_screen_dump_ptr screen_dump; \
vga_hw_text_update_ptr text_update; \
/* hardware mouse cursor support */ \
uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
void (*cursor_invalidate)(struct VGAState *s); \
void (*cursor_draw_line)(struct VGAState *s, uint8_t *d, int y); \
/* tell for each page if it has been updated since the last time */ \
uint32_t last_palette[256]; \
uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */ \
/* retrace */ \
vga_retrace_fn retrace; \
vga_update_retrace_info_fn update_retrace_info; \
typedef struct VGACommonState {
uint8_t *vram_ptr;
ram_addr_t vram_offset;
unsigned int vram_size;
uint32_t lfb_addr;
uint32_t lfb_end;
uint32_t map_addr;
uint32_t map_end;
uint32_t lfb_vram_mapped; /* whether 0xa0000 is mapped as ram */
unsigned long bios_offset;
unsigned int bios_size;
int it_shift;
PCIDevice *pci_dev;
uint32_t latch;
uint8_t sr_index;
uint8_t sr[256];
uint8_t gr_index;
uint8_t gr[256];
uint8_t ar_index;
uint8_t ar[21];
int ar_flip_flop;
uint8_t cr_index;
uint8_t cr[256]; /* CRT registers */
uint8_t msr; /* Misc Output Register */
uint8_t fcr; /* Feature Control Register */
uint8_t st00; /* status 0 */
uint8_t st01; /* status 1 */
uint8_t dac_state;
uint8_t dac_sub_index;
uint8_t dac_read_index;
uint8_t dac_write_index;
uint8_t dac_cache[3]; /* used when writing */
int dac_8bit;
uint8_t palette[768];
int32_t bank_offset;
int vga_io_memory;
int (*get_bpp)(struct VGACommonState *s);
void (*get_offsets)(struct VGACommonState *s,
uint32_t *pline_offset,
uint32_t *pstart_addr,
uint32_t *pline_compare);
void (*get_resolution)(struct VGACommonState *s,
int *pwidth,
int *pheight);
VGA_STATE_COMMON_BOCHS_VBE
/* display refresh support */
DisplayState *ds;
uint32_t font_offsets[2];
int graphic_mode;
uint8_t shift_control;
uint8_t double_scan;
uint32_t line_offset;
uint32_t line_compare;
uint32_t start_addr;
uint32_t plane_updated;
uint32_t last_line_offset;
uint8_t last_cw, last_ch;
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 */
uint8_t cursor_start, cursor_end;
uint32_t cursor_offset;
unsigned int (*rgb_to_pixel)(unsigned int r,
unsigned int g, unsigned b);
vga_hw_update_ptr update;
vga_hw_invalidate_ptr invalidate;
vga_hw_screen_dump_ptr screen_dump;
vga_hw_text_update_ptr text_update;
/* hardware mouse cursor support */
uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32];
void (*cursor_invalidate)(struct VGACommonState *s);
void (*cursor_draw_line)(struct VGACommonState *s, uint8_t *d, int y);
/* tell for each page if it has been updated since the last time */
uint32_t last_palette[256];
uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
/* retrace */
vga_retrace_fn retrace;
vga_update_retrace_info_fn update_retrace_info;
union vga_retrace retrace_info;
} VGACommonState;
typedef struct VGAState {
VGA_STATE_COMMON
} VGAState;
typedef VGACommonState VGAState;
static inline int c6_to_8(int v)
{

View File

@ -38,7 +38,7 @@
struct vmsvga_state_s {
#ifdef EMBED_STDVGA
VGA_STATE_COMMON
VGACommonState vga;
#endif
int width;
@ -326,23 +326,23 @@ static inline void vmsvga_update_rect(struct vmsvga_state_s *s,
bypl = s->bypp * s->width;
width = s->bypp * w;
start = s->bypp * x + bypl * y;
src = s->vram_ptr + start;
dst = ds_get_data(s->ds) + start;
src = s->vga.vram_ptr + start;
dst = ds_get_data(s->vga.ds) + start;
for (; line > 0; line --, src += bypl, dst += bypl)
memcpy(dst, src, width);
#endif
dpy_update(s->ds, x, y, w, h);
dpy_update(s->vga.ds, x, y, w, h);
}
static inline void vmsvga_update_screen(struct vmsvga_state_s *s)
{
#ifndef DIRECT_VRAM
memcpy(ds_get_data(s->ds), s->vram_ptr, s->bypp * s->width * s->height);
memcpy(ds_get_data(s->vga.ds), s->vga.vram_ptr, s->bypp * s->width * s->height);
#endif
dpy_update(s->ds, 0, 0, s->width, s->height);
dpy_update(s->vga.ds, 0, 0, s->width, s->height);
}
#ifdef DIRECT_VRAM
@ -383,7 +383,7 @@ static inline void vmsvga_copy_rect(struct vmsvga_state_s *s,
# ifdef DIRECT_VRAM
uint8_t *vram = ds_get_data(s->ds);
# else
uint8_t *vram = s->vram_ptr;
uint8_t *vram = s->vga.vram_ptr;
# endif
int bypl = s->bypp * s->width;
int width = s->bypp * w;
@ -420,7 +420,7 @@ static inline void vmsvga_fill_rect(struct vmsvga_state_s *s,
# ifdef DIRECT_VRAM
uint8_t *vram = ds_get_data(s->ds);
# else
uint8_t *vram = s->vram_ptr;
uint8_t *vram = s->vga.vram_ptr;
# endif
int bypp = s->bypp;
int bypl = bypp * s->width;
@ -485,8 +485,8 @@ static inline void vmsvga_cursor_define(struct vmsvga_state_s *s,
for (i = SVGA_BITMAP_SIZE(c->width, c->height) - 1; i >= 0; i --)
c->mask[i] = ~c->mask[i];
if (s->ds->cursor_define)
s->ds->cursor_define(c->width, c->height, c->bpp, c->hot_x, c->hot_y,
if (s->vga.ds->cursor_define)
s->vga.ds->cursor_define(c->width, c->height, c->bpp, c->hot_x, c->hot_y,
(uint8_t *) c->image, (uint8_t *) c->mask);
}
#endif
@ -689,7 +689,7 @@ static uint32_t vmsvga_value_read(void *opaque, uint32_t address)
return 0x0;
case SVGA_REG_VRAM_SIZE:
return s->vram_size - SVGA_FIFO_SIZE;
return s->vga.vram_size - SVGA_FIFO_SIZE;
case SVGA_REG_FB_SIZE:
return s->fb_size;
@ -703,14 +703,14 @@ static uint32_t vmsvga_value_read(void *opaque, uint32_t address)
caps |= SVGA_CAP_RECT_FILL;
#endif
#ifdef HW_MOUSE_ACCEL
if (s->ds->mouse_set)
if (s->vga.ds->mouse_set)
caps |= SVGA_CAP_CURSOR | SVGA_CAP_CURSOR_BYPASS_2 |
SVGA_CAP_CURSOR_BYPASS;
#endif
return caps;
case SVGA_REG_MEM_START:
return s->vram_base + s->vram_size - SVGA_FIFO_SIZE;
return s->vram_base + s->vga.vram_size - SVGA_FIFO_SIZE;
case SVGA_REG_MEM_SIZE:
return SVGA_FIFO_SIZE;
@ -775,7 +775,7 @@ static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)
s->height = -1;
s->invalidated = 1;
#ifdef EMBED_STDVGA
s->invalidate(opaque);
s->vga.invalidate(&s->vga);
#endif
if (s->enable)
s->fb_size = ((s->depth + 7) >> 3) * s->new_width * s->new_height;
@ -801,7 +801,7 @@ static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)
case SVGA_REG_CONFIG_DONE:
if (value) {
s->fifo = (uint32_t *) &s->vram_ptr[s->vram_size - SVGA_FIFO_SIZE];
s->fifo = (uint32_t *) &s->vga.vram_ptr[s->vga.vram_size - SVGA_FIFO_SIZE];
/* Check range and alignment. */
if ((CMD(min) | CMD(max) |
CMD(next_cmd) | CMD(stop)) & 3)
@ -847,8 +847,8 @@ static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)
s->cursor.on |= (value == SVGA_CURSOR_ON_SHOW);
s->cursor.on &= (value != SVGA_CURSOR_ON_HIDE);
#ifdef HW_MOUSE_ACCEL
if (s->ds->mouse_set && value <= SVGA_CURSOR_ON_SHOW)
s->ds->mouse_set(s->cursor.x, s->cursor.y, s->cursor.on);
if (s->vga.ds->mouse_set && value <= SVGA_CURSOR_ON_SHOW)
s->vga.ds->mouse_set(s->cursor.x, s->cursor.y, s->cursor.on);
#endif
break;
@ -885,7 +885,7 @@ static inline void vmsvga_size(struct vmsvga_state_s *s)
if (s->new_width != s->width || s->new_height != s->height) {
s->width = s->new_width;
s->height = s->new_height;
qemu_console_resize(s->ds, s->width, s->height);
qemu_console_resize(s->vga.ds, s->width, s->height);
s->invalidated = 1;
}
}
@ -895,7 +895,7 @@ static void vmsvga_update_display(void *opaque)
struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
if (!s->enable) {
#ifdef EMBED_STDVGA
s->update(opaque);
s->vga.update(&s->vga);
#endif
return;
}
@ -963,7 +963,7 @@ static void vmsvga_invalidate_display(void *opaque)
struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
if (!s->enable) {
#ifdef EMBED_STDVGA
s->invalidate(opaque);
s->vga.invalidate(&s->vga);
#endif
return;
}
@ -978,14 +978,14 @@ static void vmsvga_screen_dump(void *opaque, const char *filename)
struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
if (!s->enable) {
#ifdef EMBED_STDVGA
s->screen_dump(opaque, filename);
s->vga.screen_dump(&s->vga, filename);
#endif
return;
}
if (s->depth == 32) {
DisplaySurface *ds = qemu_create_displaysurface_from(s->width,
s->height, 32, ds_get_linesize(s->ds), s->vram_ptr);
s->height, 32, ds_get_linesize(s->vga.ds), s->vga.vram_ptr);
ppm_save(filename, ds);
qemu_free(ds);
}
@ -995,8 +995,8 @@ static void vmsvga_text_update(void *opaque, console_ch_t *chardata)
{
struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
if (s->text_update)
s->text_update(opaque, chardata);
if (s->vga.text_update)
s->vga.text_update(&s->vga, chardata);
}
#ifdef DIRECT_VRAM
@ -1116,7 +1116,7 @@ static int vmsvga_load(struct vmsvga_state_s *s, QEMUFile *f)
s->invalidated = 1;
if (s->config)
s->fifo = (uint32_t *) &s->vram_ptr[s->vram_size - SVGA_FIFO_SIZE];
s->fifo = (uint32_t *) &s->vga.vram_ptr[s->vga.vram_size - SVGA_FIFO_SIZE];
return 0;
}
@ -1137,15 +1137,15 @@ static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size)
s->vram_ptr = qemu_get_ram_ptr(s->vram_offset);
#endif
s->ds = graphic_console_init(vmsvga_update_display,
s->vga.ds = graphic_console_init(vmsvga_update_display,
vmsvga_invalidate_display,
vmsvga_screen_dump,
vmsvga_text_update, s);
vmsvga_text_update, &s->vga);
#ifdef CONFIG_BOCHS_VBE
/* XXX: use optimized standard vga accesses */
cpu_register_physical_memory(VBE_DISPI_LFB_PHYSICAL_ADDRESS,
vga_ram_size, s->vram_offset);
vga_ram_size, s->vga.vram_offset);
#endif
}
@ -1204,9 +1204,9 @@ static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num,
iomemtype = cpu_register_io_memory(0, vmsvga_vram_read,
vmsvga_vram_write, s);
#else
iomemtype = s->vram_offset | IO_MEM_RAM;
iomemtype = s->vga.vram_offset | IO_MEM_RAM;
#endif
cpu_register_physical_memory(s->vram_base, s->vram_size,
cpu_register_physical_memory(s->vram_base, s->vga.vram_size,
iomemtype);
}