Sparse fixes: NULL use, header order, ANSI prototypes, static
[qemu] / hw / vmware_vga.c
index efbcd96..5c271e6 100644 (file)
@@ -57,7 +57,6 @@ struct vmsvga_state_s {
 
 #ifndef EMBED_STDVGA
     DisplayState *ds;
-    QEMUConsole *console;
     int vram_size;
     ram_addr_t vram_offset;
 #endif
@@ -231,7 +230,6 @@ enum {
 #ifdef VERBOSE
 # define GUEST_OS_BASE         0x5001
 static const char *vmsvga_guest_id[] = {
-    [0x00 ... 0x15] = "an unknown OS",
     [0x00] = "Dos",
     [0x01] = "Windows 3.1",
     [0x02] = "Windows 95",
@@ -241,8 +239,18 @@ static const char *vmsvga_guest_id[] = {
     [0x06] = "Windows 2000",
     [0x07] = "Linux",
     [0x08] = "OS/2",
+    [0x09] = "an unknown OS",
     [0x0a] = "BSD",
     [0x0b] = "Whistler",
+    [0x0c] = "an unknown OS",
+    [0x0d] = "an unknown OS",
+    [0x0e] = "an unknown OS",
+    [0x0f] = "an unknown OS",
+    [0x10] = "an unknown OS",
+    [0x11] = "an unknown OS",
+    [0x12] = "an unknown OS",
+    [0x13] = "an unknown OS",
+    [0x14] = "an unknown OS",
     [0x15] = "Windows 2003",
 };
 #endif
@@ -319,7 +327,7 @@ static inline void vmsvga_update_rect(struct vmsvga_state_s *s,
     width = s->bypp * w;
     start = s->bypp * x + bypl * y;
     src = s->vram + start;
-    dst = s->ds->data + start;
+    dst = ds_get_data(s->ds) + start;
 
     for (; line > 0; line --, src += bypl, dst += bypl)
         memcpy(dst, src, width);
@@ -331,7 +339,7 @@ static inline void vmsvga_update_rect(struct vmsvga_state_s *s,
 static inline void vmsvga_update_screen(struct vmsvga_state_s *s)
 {
 #ifndef DIRECT_VRAM
-    memcpy(s->ds->data, s->vram, s->bypp * s->width * s->height);
+    memcpy(ds_get_data(s->ds), s->vram, s->bypp * s->width * s->height);
 #endif
 
     dpy_update(s->ds, 0, 0, s->width, s->height);
@@ -373,7 +381,7 @@ static inline void vmsvga_copy_rect(struct vmsvga_state_s *s,
                 int x0, int y0, int x1, int y1, int w, int h)
 {
 # ifdef DIRECT_VRAM
-    uint8_t *vram = s->ds->data;
+    uint8_t *vram = ds_get_data(s->ds);
 # else
     uint8_t *vram = s->vram;
 # endif
@@ -384,7 +392,7 @@ static inline void vmsvga_copy_rect(struct vmsvga_state_s *s,
 
 # ifdef DIRECT_VRAM
     if (s->ds->dpy_copy)
-        s->ds->dpy_copy(s->ds, x0, y0, x1, y1, w, h);
+        qemu_console_copy(s->ds, x0, y0, x1, y1, w, h);
     else
 # endif
     {
@@ -410,7 +418,7 @@ static inline void vmsvga_fill_rect(struct vmsvga_state_s *s,
                 uint32_t c, int x, int y, int w, int h)
 {
 # ifdef DIRECT_VRAM
-    uint8_t *vram = s->ds->data;
+    uint8_t *vram = ds_get_data(s->ds);
 # else
     uint8_t *vram = s->vram;
 # endif
@@ -817,7 +825,7 @@ static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)
         s->guest = value;
 #ifdef VERBOSE
         if (value >= GUEST_OS_BASE && value < GUEST_OS_BASE +
-                sizeof(vmsvga_guest_id) / sizeof(*vmsvga_guest_id))
+                ARRAY_SIZE(vmsvga_guest_id))
             printf("%s: guest runs %s.\n", __FUNCTION__,
                             vmsvga_guest_id[value - GUEST_OS_BASE]);
 #endif
@@ -877,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->console, s->width, s->height);
+        qemu_console_resize(s->ds, s->width, s->height);
         s->invalidated = 1;
     }
 }
@@ -915,7 +923,7 @@ static void vmsvga_reset(struct vmsvga_state_s *s)
     s->width = -1;
     s->height = -1;
     s->svgaid = SVGA_ID;
-    s->depth = s->ds->depth ? s->ds->depth : 24;
+    s->depth = 24;
     s->bypp = (s->depth + 7) >> 3;
     s->cursor.on = 0;
     s->redraw_fifo_first = 0;
@@ -976,7 +984,10 @@ static void vmsvga_screen_dump(void *opaque, const char *filename)
     }
 
     if (s->depth == 32) {
-        ppm_save(filename, s->vram, s->width, s->height, s->ds->linesize);
+        DisplaySurface *ds = qemu_create_displaysurface_from(s->width,
+                s->height, 32, ds_get_linesize(s->ds), s->vram);
+        ppm_save(filename, ds);
+        qemu_free(ds);
     }
 }
 
@@ -992,9 +1003,8 @@ static void vmsvga_text_update(void *opaque, console_ch_t *chardata)
 static uint32_t vmsvga_vram_readb(void *opaque, target_phys_addr_t addr)
 {
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
-    addr -= s->vram_base;
     if (addr < s->fb_size)
-        return *(uint8_t *) (s->ds->data + addr);
+        return *(uint8_t *) (ds_get_data(s->ds) + addr);
     else
         return *(uint8_t *) (s->vram + addr);
 }
@@ -1002,9 +1012,8 @@ static uint32_t vmsvga_vram_readb(void *opaque, target_phys_addr_t addr)
 static uint32_t vmsvga_vram_readw(void *opaque, target_phys_addr_t addr)
 {
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
-    addr -= s->vram_base;
     if (addr < s->fb_size)
-        return *(uint16_t *) (s->ds->data + addr);
+        return *(uint16_t *) (ds_get_data(s->ds) + addr);
     else
         return *(uint16_t *) (s->vram + addr);
 }
@@ -1012,9 +1021,8 @@ static uint32_t vmsvga_vram_readw(void *opaque, target_phys_addr_t addr)
 static uint32_t vmsvga_vram_readl(void *opaque, target_phys_addr_t addr)
 {
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
-    addr -= s->vram_base;
     if (addr < s->fb_size)
-        return *(uint32_t *) (s->ds->data + addr);
+        return *(uint32_t *) (ds_get_data(s->ds) + addr);
     else
         return *(uint32_t *) (s->vram + addr);
 }
@@ -1023,9 +1031,8 @@ static void vmsvga_vram_writeb(void *opaque, target_phys_addr_t addr,
                 uint32_t value)
 {
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
-    addr -= s->vram_base;
     if (addr < s->fb_size)
-        *(uint8_t *) (s->ds->data + addr) = value;
+        *(uint8_t *) (ds_get_data(s->ds) + addr) = value;
     else
         *(uint8_t *) (s->vram + addr) = value;
 }
@@ -1034,9 +1041,8 @@ static void vmsvga_vram_writew(void *opaque, target_phys_addr_t addr,
                 uint32_t value)
 {
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
-    addr -= s->vram_base;
     if (addr < s->fb_size)
-        *(uint16_t *) (s->ds->data + addr) = value;
+        *(uint16_t *) (ds_get_data(s->ds) + addr) = value;
     else
         *(uint16_t *) (s->vram + addr) = value;
 }
@@ -1045,9 +1051,8 @@ static void vmsvga_vram_writel(void *opaque, target_phys_addr_t addr,
                 uint32_t value)
 {
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
-    addr -= s->vram_base;
     if (addr < s->fb_size)
-        *(uint32_t *) (s->ds->data + addr) = value;
+        *(uint32_t *) (ds_get_data(s->ds) + addr) = value;
     else
         *(uint32_t *) (s->vram + addr) = value;
 }
@@ -1116,11 +1121,10 @@ static int vmsvga_load(struct vmsvga_state_s *s, QEMUFile *f)
     return 0;
 }
 
-static void vmsvga_init(struct vmsvga_state_s *s, DisplayState *ds,
+static void vmsvga_init(struct vmsvga_state_s *s,
                 uint8_t *vga_ram_base, unsigned long vga_ram_offset,
                 int vga_ram_size)
 {
-    s->ds = ds;
     s->vram = vga_ram_base;
     s->vram_size = vga_ram_size;
     s->vram_offset = vga_ram_offset;
@@ -1131,15 +1135,15 @@ static void vmsvga_init(struct vmsvga_state_s *s, DisplayState *ds,
     vmsvga_reset(s);
 
 #ifdef EMBED_STDVGA
-    vga_common_init((VGAState *) s, ds,
+    vga_common_init((VGAState *) s,
                     vga_ram_base, vga_ram_offset, vga_ram_size);
     vga_init((VGAState *) s);
 #endif
 
-    s->console = graphic_console_init(ds, vmsvga_update_display,
-                                      vmsvga_invalidate_display,
-                                      vmsvga_screen_dump,
-                                      vmsvga_text_update, s);
+    s->ds = graphic_console_init(vmsvga_update_display,
+                                 vmsvga_invalidate_display,
+                                 vmsvga_screen_dump,
+                                 vmsvga_text_update, s);
 
 #ifdef CONFIG_BOCHS_VBE
     /* XXX: use optimized standard vga accesses */
@@ -1209,17 +1213,9 @@ static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num,
                     iomemtype);
 }
 
-#define PCI_VENDOR_ID_VMWARE           0x15ad
-#define PCI_DEVICE_ID_VMWARE_SVGA2     0x0405
-#define PCI_DEVICE_ID_VMWARE_SVGA      0x0710
-#define PCI_DEVICE_ID_VMWARE_NET       0x0720
-#define PCI_DEVICE_ID_VMWARE_SCSI      0x0730
-#define PCI_DEVICE_ID_VMWARE_IDE       0x1729
-#define PCI_CLASS_BASE_DISPLAY         0x03
-#define PCI_CLASS_SUB_VGA              0x00
 #define PCI_CLASS_HEADERTYPE_00h       0x00
 
-void pci_vmsvga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
+void pci_vmsvga_init(PCIBus *bus, uint8_t *vga_ram_base,
                      unsigned long vga_ram_offset, int vga_ram_size)
 {
     struct pci_vmsvga_state_s *s;
@@ -1228,13 +1224,10 @@ void pci_vmsvga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
     s = (struct pci_vmsvga_state_s *)
         pci_register_device(bus, "QEMUware SVGA",
                 sizeof(struct pci_vmsvga_state_s), -1, 0, 0);
-    s->card.config[PCI_VENDOR_ID]      = PCI_VENDOR_ID_VMWARE & 0xff;
-    s->card.config[PCI_VENDOR_ID + 1]  = PCI_VENDOR_ID_VMWARE >> 8;
-    s->card.config[PCI_DEVICE_ID]      = SVGA_PCI_DEVICE_ID & 0xff;
-    s->card.config[PCI_DEVICE_ID + 1]  = SVGA_PCI_DEVICE_ID >> 8;
+    pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE);
+    pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID);
     s->card.config[PCI_COMMAND]                = 0x07;         /* I/O + Memory */
-    s->card.config[PCI_CLASS_DEVICE]   = PCI_CLASS_SUB_VGA;
-    s->card.config[0x0b]               = PCI_CLASS_BASE_DISPLAY;
+    pci_config_set_class(s->card.config, PCI_CLASS_DISPLAY_VGA);
     s->card.config[0x0c]               = 0x08;         /* Cache line size */
     s->card.config[0x0d]               = 0x40;         /* Latency timer */
     s->card.config[0x0e]               = PCI_CLASS_HEADERTYPE_00h;
@@ -1249,7 +1242,7 @@ void pci_vmsvga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
     pci_register_io_region(&s->card, 1, vga_ram_size,
                     PCI_ADDRESS_SPACE_MEM_PREFETCH, pci_vmsvga_map_mem);
 
-    vmsvga_init(&s->chip, ds, vga_ram_base, vga_ram_offset, vga_ram_size);
+    vmsvga_init(&s->chip, vga_ram_base, vga_ram_offset, vga_ram_size);
 
     register_savevm("vmware_vga", 0, 0, pci_vmsvga_save, pci_vmsvga_load, s);
 }