Skip to contentSkip to conversation

Rework ISA/PCI video card initialization

PATCH In review Aurelien Jarno 2 participants 19 messages Sep 11, 2012 – Sep 12, 2012

lore
Share & tools
lore
#17 lore raw

PATCH v3 16/17 mips/r4k: use the new is_vga_init() function

In reply to Aurelien Jarno
---
 hw/mips_r4k.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/mips_r4k.c +1 -1
index 2115f7f..967a76e 100644
@@ -281,7 +281,7 @@ void mips_r4k_init (ram_addr_t ram_size,
         }
     }
 
-    isa_std_vga_init(isa_bus);
+    isa_vga_init(isa_bus);
 
     if (nd_table[0].used)
         isa_ne2000_init(isa_bus, 0x300, 9, &nd_table[0]);
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v3 2/17 vga: rename isa_vga_init() to isa_std_vga_init()

In reply to Aurelien Jarno

This better explains what is this function about. Adjust all callers.

---
 hw/mips_r4k.c |    2 +-
 hw/pc.c       |    2 +-
 hw/pc.h       |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
hw/mips_r4k.c +1 -1
index 967a76e..2115f7f 100644
@@ -281,7 +281,7 @@ void mips_r4k_init (ram_addr_t ram_size,
         }
     }
 
-    isa_vga_init(isa_bus);
+    isa_std_vga_init(isa_bus);
 
     if (nd_table[0].used)
         isa_ne2000_init(isa_bus, 0x300, 9, &nd_table[0]);
hw/pc.c +1 -1
index 8736a30..e3d4631 100644
@@ -1043,7 +1043,7 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)
         if (pci_bus) {
             dev = pci_std_vga_init(pci_bus);
         } else {
-            dev = isa_vga_init(isa_bus);
+            dev = isa_std_vga_init(isa_bus);
         }
     }
 
hw/pc.h +1 -1
index e4db071..77c38d6 100644
@@ -176,7 +176,7 @@ enum vga_retrace_method {
 
 extern enum vga_retrace_method vga_retrace_method;
 
-static inline DeviceState *isa_vga_init(ISABus *bus)
+static inline DeviceState *isa_std_vga_init(ISABus *bus)
 {
     ISADevice *dev;
 
Signature · 1 line
1.7.10.4
#16 lore raw

PATCH v3 15/17 pc: use the new pci_vga_init() and isa_vga_init() functions

In reply to Aurelien Jarno

The CONFIG_SPICE is now tested in vl.c and thus not needed anymore.

---
 hw/pc.c |   35 ++++++-----------------------------
 1 file changed, 6 insertions(+), 29 deletions(-)
hw/pc.c +6 -29
index e3d4631..562d288 100644
@@ -27,7 +27,6 @@
 #include "fdc.h"
 #include "ide.h"
 #include "pci.h"
-#include "vmware_vga.h"
 #include "monitor.h"
 #include "fw_cfg.h"
 #include "hpet_emul.h"
@@ -51,7 +50,6 @@
 #include "exec-memory.h"
 #include "arch_init.h"
 #include "bitmap.h"
-#include "vga-pci.h"
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -1019,34 +1017,13 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)
 {
     DeviceState *dev = NULL;
 
-    if (cirrus_vga_enabled) {
-        if (pci_bus) {
-            dev = pci_cirrus_vga_init(pci_bus);
-        } else {
-            dev = &isa_create_simple(isa_bus, "isa-cirrus-vga")->qdev;
-        }
-    } else if (vmsvga_enabled) {
-        if (pci_bus) {
-            dev = pci_vmsvga_init(pci_bus);
-        } else {
-            fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
-        }
-#ifdef CONFIG_SPICE
-    } else if (qxl_enabled) {
-        if (pci_bus) {
-            dev = &pci_create_simple(pci_bus, -1, "qxl-vga")->qdev;
-        } else {
-            fprintf(stderr, "%s: qxl: no PCI bus\n", __FUNCTION__);
-        }
-#endif
-    } else if (std_vga_enabled) {
-        if (pci_bus) {
-            dev = pci_std_vga_init(pci_bus);
-        } else {
-            dev = isa_std_vga_init(isa_bus);
-        }
+    if (pci_bus) {
+        PCIDevice *pcidev = pci_vga_init(pci_bus);
+        dev = pcidev ? &pcidev->qdev : NULL;
+    } else if (isa_bus) {
+        ISADevice *isadev = isa_vga_init(isa_bus);
+        dev = isadev ? &isadev->qdev : NULL;
     }
-
     return dev;
 }
 
Signature · 1 line
1.7.10.4
#15 lore raw

PATCH v3 14/17 sun/sun4u: use the new pci_vga_init() function

In reply to Aurelien Jarno

As a bonus it allows new vga card types (including none).

---
 hw/sun4u.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/sun4u.c +1 -2
index cca090f..137a7c6 100644
@@ -39,7 +39,6 @@
 #include "elf.h"
 #include "blockdev.h"
 #include "exec-memory.h"
-#include "vga-pci.h"
 
 //#define DEBUG_IRQ
 //#define DEBUG_EBUS
@@ -821,7 +820,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
     ivec_irqs = qemu_allocate_irqs(cpu_set_ivec_irq, env, IVEC_MAX);
     pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, ivec_irqs, &pci_bus2,
                            &pci_bus3, &pbm_irqs);
-    pci_std_vga_init(pci_bus);
+    pci_vga_init(pci_bus);
 
     // XXX Should be pci_bus3
     isa_bus = pci_ebus_init(pci_bus, -1, pbm_irqs);
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH v3 13/17 ppc/pSeries: use the new pci_vga_init() function

In reply to Aurelien Jarno

Keep the case to prevent some vga card to be selected.

Cc Alexander Graf <[email protected]>
Cc David Gibson <[email protected]>
---
 hw/spapr.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
hw/spapr.c +2 -5
index 80735d6..8b0c390 100644
@@ -46,7 +46,6 @@
 #include "kvm.h"
 #include "kvm_ppc.h"
 #include "pci.h"
-#include "vga-pci.h"
 
 #include "exec-memory.h"
 #include "hw/usb.h"
@@ -589,11 +588,9 @@ static void spapr_cpu_reset(void *opaque)
 static int spapr_vga_init(PCIBus *pci_bus)
 {
     switch (vga_interface_type) {
-    case VGA_STD:
-        pci_std_vga_init(pci_bus);
-        return 1;
     case VGA_NONE:
-        return 0;
+    case VGA_STD:
+        return pci_vga_init(pci_bus) != NULL;
     default:
         fprintf(stderr, "This vga model is not supported,"
                 "currently it only supports -vga std\n");
Signature · 1 line
1.7.10.4
#13 lore raw

PATCH v3 12/17 ppc/prep: use the new pci_vga_init() function

In reply to Aurelien Jarno

As a bonus it allows new vga card types (including none).

---
 hw/ppc_prep.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc_prep.c +1 -2
index 1fa7609..1544430 100644
@@ -39,7 +39,6 @@
 #include "blockdev.h"
 #include "arch_init.h"
 #include "exec-memory.h"
-#include "vga-pci.h"
 
 //#define HARD_DEBUG_PPC_IO
 //#define DEBUG_PPC_IO
@@ -611,7 +610,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
     memory_region_add_subregion(sysmem, 0x80000000, PPC_io_memory);
 
     /* init basic PC hardware */
-    pci_std_vga_init(pci_bus);
+    pci_vga_init(pci_bus);
 
     if (serial_hds[0])
         serial_isa_init(isa_bus, 0, serial_hds[0]);
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH v3 11/17 ppc/oldworld: use the new pci_vga_init() function

In reply to Aurelien Jarno

As a bonus it allows new vga card types (including none).

---
 hw/ppc_oldworld.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc_oldworld.c +1 -2
index 8267eb4..2c4a478 100644
@@ -43,7 +43,6 @@
 #include "kvm_ppc.h"
 #include "blockdev.h"
 #include "exec-memory.h"
-#include "vga-pci.h"
 
 #define MAX_IDE_BUS 2
 #define CFG_ADDR 0xf0000510
@@ -250,7 +249,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
     pci_bus = pci_grackle_init(0xfec00000, pic,
                                get_system_memory(),
                                get_system_io());
-    pci_std_vga_init(pci_bus);
+    pci_vga_init(pci_bus);
 
     escc_mem = escc_init(0, pic[0x0f], pic[0x10], serial_hds[0],
                                serial_hds[1], ESCC_CLOCK, 4);
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH v3 10/17 ppc/newworld: use the new pci_vga_init() function

In reply to Aurelien Jarno

As a bonus it allows new vga card types (including none).

---
 hw/ppc_newworld.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc_newworld.c +1 -2
index 84af948..b8d3c9c 100644
@@ -67,7 +67,6 @@
 #include "hw/usb.h"
 #include "blockdev.h"
 #include "exec-memory.h"
-#include "vga-pci.h"
 
 #define MAX_IDE_BUS 2
 #define CFG_ADDR 0xf0000510
@@ -330,7 +329,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
         machine_arch = ARCH_MAC99;
     }
     /* init basic PC hardware */
-    pci_std_vga_init(pci_bus);
+    pci_vga_init(pci_bus);
 
     escc_mem = escc_init(0, pic[0x25], pic[0x24],
                          serial_hds[0], serial_hds[1], ESCC_CLOCK, 4);
Signature · 1 line
1.7.10.4
#10 lore raw

PATCH v3 9/17 alpha: use the new pci_vga_init() function

In reply to Aurelien Jarno

This remove the fallback to std-vga in case, as availability of the requested vga device is now tested in vl.c, and returns an error message to the user.

---
 hw/alpha_dp264.c |    2 +-
 hw/alpha_pci.c   |   24 ------------------------
 hw/alpha_sys.h   |    2 --
 3 files changed, 1 insertion(+), 27 deletions(-)
hw/alpha_dp264.c +1 -1
index 9eb939f..5ea04c7 100644
@@ -77,7 +77,7 @@ static void clipper_init(ram_addr_t ram_size,
     isa_create_simple(isa_bus, "i8042");
 
     /* VGA setup.  Don't bother loading the bios.  */
-    alpha_pci_vga_setup(pci_bus);
+    pci_vga_init(pci_bus);
 
     /* Serial code setup.  */
     for (i = 0; i < MAX_SERIAL_PORTS; ++i) {
hw/alpha_pci.c +0 -3
index 0352e72..8079a46 100644
@@ -10,8 +10,6 @@
 #include "alpha_sys.h"
 #include "qemu-log.h"
 #include "sysemu.h"
-#include "vmware_vga.h"
-#include "vga-pci.h"
 
 
 /* PCI IO reads/writes, to byte-word addressable memory.  */
@@ -109,25 +107,3 @@ const MemoryRegionOps alpha_pci_iack_ops = {
         .max_access_size = 4,
     },
 };
-

-void alpha_pci_vga_setup(PCIBus *pci_bus)
-{
- switch (vga_interface_type) {
-#ifdef CONFIG_SPICE
- case VGA_QXL:
- pci_create_simple(pci_bus, -1, "qxl-vga");
- return;
-#endif
- case VGA_CIRRUS:
- pci_cirrus_vga_init(pci_bus);
- return;
- case VGA_VMWARE:
- pci_vmsvga_init(pci_bus);
- return;
- }
- /* If VGA is enabled at all, and one of the above didn't work, then
- fallback to Standard VGA. */
- if (vga_interface_type != VGA_NONE) {
- pci_std_vga_init(pci_bus);
- }
-}

hw/alpha_sys.h +0 -2
index de40f8b..7604d09 100644
@@ -19,6 +19,4 @@ extern const MemoryRegionOps alpha_pci_bw_io_ops;
 extern const MemoryRegionOps alpha_pci_conf1_ops;
 extern const MemoryRegionOps alpha_pci_iack_ops;
 
-void alpha_pci_vga_setup(PCIBus *pci_bus);
-
 #endif
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH v3 8/17 mips/malta: use the new pci_vga_init() function

In reply to Aurelien Jarno
---
 hw/mips_malta.c |   10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
hw/mips_malta.c +1 -9
index c39dee5..632b466 100644
@@ -33,7 +33,6 @@
 #include "mips.h"
 #include "mips_cpudevs.h"
 #include "pci.h"
-#include "vmware_vga.h"
 #include "qemu-char.h"
 #include "sysemu.h"
 #include "arch_init.h"
@@ -48,7 +47,6 @@
 #include "blockdev.h"
 #include "exec-memory.h"
 #include "sysbus.h"             /* SysBusDevice */
-#include "vga-pci.h"
 
 //#define DEBUG_BOARD_INIT
 
@@ -987,13 +985,7 @@ void mips_malta_init (ram_addr_t ram_size,
     network_init();
 
     /* Optional PCI video card */
-    if (cirrus_vga_enabled) {
-        pci_cirrus_vga_init(pci_bus);
-    } else if (vmsvga_enabled) {
-        pci_vmsvga_init(pci_bus);
-    } else if (std_vga_enabled) {
-        pci_std_vga_init(pci_bus);
-    }
+    pci_vga_init(pci_bus);
 }
 
 static int mips_malta_sysbus_device_init(SysBusDevice *sysbusdev)
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH v3 7/17 isa: add a isa_vga_init() function

In reply to Aurelien Jarno

This function create a ISA VGA device according to the value of vga_interface_type. It returns a ISADevice (and not a DeviceState).

---
 hw/isa-bus.c |   20 ++++++++++++++++++++
 hw/isa.h     |    2 ++
 2 files changed, 22 insertions(+)
hw/isa-bus.c +20 -0
index f9b2373..00de20a 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "monitor.h"
 #include "sysbus.h"
+#include "sysemu.h"
 #include "isa.h"
 #include "exec-memory.h"
 
@@ -166,6 +167,25 @@ ISADevice *isa_create_simple(ISABus *bus, const char *name)
     return dev;
 }
 
+ISADevice *isa_vga_init(ISABus *bus)
+{
+    switch (vga_interface_type) {
+    case VGA_CIRRUS:
+        return isa_create_simple(bus, "isa-cirrus-vga");
+    case VGA_QXL:
+        fprintf(stderr, "%s: qxl: no PCI bus\n", __func__);
+        return NULL;
+    case VGA_STD:
+        return isa_create_simple(bus, "isa-vga");
+    case VGA_VMWARE:
+        fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __func__);
+        return NULL;
+    case VGA_NONE:
+    default:
+        return NULL;
+    }
+}
+
 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
 {
     ISADevice *d = ISA_DEVICE(dev);
hw/isa.h +2 -0
index dc97052..8fb498a 100644
@@ -47,6 +47,8 @@ ISADevice *isa_create(ISABus *bus, const char *name);
 ISADevice *isa_try_create(ISABus *bus, const char *name);
 ISADevice *isa_create_simple(ISABus *bus, const char *name);
 
+ISADevice *isa_vga_init(ISABus *bus);
+
 /**
  * isa_register_ioport: Install an I/O port region on the ISA bus.
  *
Signature · 1 line
1.7.10.4
#18 lore raw

PATCH v3 17/17 vga: cleanup after isa_vga_init() and pci_vga_init() conversion

In reply to Aurelien Jarno

Now that all machines call isa_vga_init() or pci_vga_init(), some unused code can be removed.

---
 hw/cirrus_vga.c |    6 ------
 hw/pc.h         |   13 -------------
 hw/vga-pci.c    |    6 ------
 hw/vga-pci.h    |   12 ------------
 hw/vmware_vga.c |    1 -
 hw/vmware_vga.h |   15 ---------------
 sysemu.h        |    3 ---
 7 files changed, 56 deletions(-)
 delete mode 100644 hw/vga-pci.h
 delete mode 100644 hw/vmware_vga.h
hw/cirrus_vga.c +0 -6
index e8dcc6b..5d1d42f 100644
@@ -28,7 +28,6 @@
  */
 #include "hw.h"
 #include "pci.h"
-#include "vga-pci.h"
 #include "console.h"
 #include "vga_int.h"
 #include "loader.h"
@@ -2963,11 +2962,6 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
      return 0;
 }
 
-DeviceState *pci_cirrus_vga_init(PCIBus *bus)
-{
-    return &pci_create_simple(bus, -1, "cirrus-vga")->qdev;
-}
-
 static void cirrus_vga_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
hw/pc.h +0 -13
index 77c38d6..9923d96 100644
@@ -176,19 +176,6 @@ enum vga_retrace_method {
 
 extern enum vga_retrace_method vga_retrace_method;
 
-static inline DeviceState *isa_std_vga_init(ISABus *bus)
-{
-    ISADevice *dev;
-
-    dev = isa_try_create(bus, "isa-vga");
-    if (!dev) {
-        fprintf(stderr, "Warning: isa-vga not available\n");
-        return NULL;
-    }
-    qdev_init_nofail(&dev->qdev);
-    return &dev->qdev;
-}
-
 int isa_vga_mm_init(target_phys_addr_t vram_base,
                     target_phys_addr_t ctrl_base, int it_shift,
                     MemoryRegion *address_space);
hw/vga-pci.c +0 -6
index 992ffd9..996d47f 100644
@@ -24,7 +24,6 @@
 #include "hw.h"
 #include "console.h"
 #include "pci.h"
-#include "vga-pci.h"
 #include "vga_int.h"
 #include "pixel_ops.h"
 #include "qemu-timer.h"
@@ -70,11 +69,6 @@ static int pci_std_vga_initfn(PCIDevice *dev)
      return 0;
 }
 
-DeviceState *pci_std_vga_init(PCIBus *bus)
-{
-    return &pci_create_simple(bus, -1, "VGA")->qdev;
-}
-
 static Property vga_pci_properties[] = {
     DEFINE_PROP_UINT32("vgamem_mb", PCIVGAState, vga.vram_size_mb, 16),
     DEFINE_PROP_END_OF_LIST(),
hw/vga-pci.h deleted +0 -12
deleted file mode 100644
index d111cdc..0000000
@@ -1,12 +0,0 @@
-#ifndef VGA_PCI_H
-#define VGA_PCI_H
-
-#include "qemu-common.h"
-
-/* vga-pci.c */
-DeviceState *pci_std_vga_init(PCIBus *bus);
-
-/* cirrus_vga.c */
-DeviceState *pci_cirrus_vga_init(PCIBus *bus);
-
-#endif
hw/vmware_vga.c +0 -1
index b68e883..784a67b 100644
@@ -25,7 +25,6 @@
 #include "loader.h"
 #include "console.h"
 #include "pci.h"
-#include "vmware_vga.h"
 
 #undef VERBOSE
 #define HW_RECT_ACCEL
hw/vmware_vga.h deleted +0 -15
deleted file mode 100644
index 000fbdd..0000000
@@ -1,15 +0,0 @@
-#ifndef QEMU_VMWARE_VGA_H
-#define QEMU_VMWARE_VGA_H
-
-#include "qemu-common.h"
-
-/* vmware_vga.c */
-static inline DeviceState *pci_vmsvga_init(PCIBus *bus)
-{
-    PCIDevice *dev;
-
-    dev = pci_create_simple(bus, -1, "vmware-svga");
-    return &dev->qdev;
-}
-
-#endif
sysemu.h +0 -3
index 65552ac..c0ab3ed 100644
@@ -105,10 +105,7 @@ typedef enum {
 } VGAInterfaceType;
 
 extern int vga_interface_type;
-#define cirrus_vga_enabled (vga_interface_type == VGA_CIRRUS)
-#define std_vga_enabled (vga_interface_type == VGA_STD)
 #define xenfb_enabled (vga_interface_type == VGA_XENFB)
-#define vmsvga_enabled (vga_interface_type == VGA_VMWARE)
 #define qxl_enabled (vga_interface_type == VGA_QXL)
 
 extern int graphic_width;
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v3 1/17 vga: rename pci_vga_init() into pci_std_vga_init()

In reply to Aurelien Jarno

This better explains what is this function about. Adjust all callers.

Cc Richard Henderson <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Andreas Färber <[email protected]>
Cc David Gibson <[email protected]>
Cc Anthony Liguori <[email protected]>
---
 hw/alpha_pci.c    |    2 +-
 hw/mips_malta.c   |    2 +-
 hw/pc.c           |    2 +-
 hw/ppc_newworld.c |    2 +-
 hw/ppc_oldworld.c |    2 +-
 hw/ppc_prep.c     |    2 +-
 hw/spapr.c        |    2 +-
 hw/sun4u.c        |    2 +-
 hw/vga-pci.c      |    6 +++---
 hw/vga-pci.h      |    2 +-
 10 files changed, 12 insertions(+), 12 deletions(-)
hw/alpha_pci.c +1 -1
index ea546f8..0352e72 100644
@@ -128,6 +128,6 @@ void alpha_pci_vga_setup(PCIBus *pci_bus)
     /* If VGA is enabled at all, and one of the above didn't work, then
        fallback to Standard VGA.  */
     if (vga_interface_type != VGA_NONE) {
-        pci_vga_init(pci_bus);
+        pci_std_vga_init(pci_bus);
     }
 }
hw/mips_malta.c +1 -1
index ad23f26..c39dee5 100644
@@ -992,7 +992,7 @@ void mips_malta_init (ram_addr_t ram_size,
     } else if (vmsvga_enabled) {
         pci_vmsvga_init(pci_bus);
     } else if (std_vga_enabled) {
-        pci_vga_init(pci_bus);
+        pci_std_vga_init(pci_bus);
     }
 }
 
hw/pc.c +1 -1
index 112739a..8736a30 100644
@@ -1041,7 +1041,7 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)
 #endif
     } else if (std_vga_enabled) {
         if (pci_bus) {
-            dev = pci_vga_init(pci_bus);
+            dev = pci_std_vga_init(pci_bus);
         } else {
             dev = isa_vga_init(isa_bus);
         }
hw/ppc_newworld.c +1 -1
index e95cfe8..84af948 100644
@@ -330,7 +330,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
         machine_arch = ARCH_MAC99;
     }
     /* init basic PC hardware */
-    pci_vga_init(pci_bus);
+    pci_std_vga_init(pci_bus);
 
     escc_mem = escc_init(0, pic[0x25], pic[0x24],
                          serial_hds[0], serial_hds[1], ESCC_CLOCK, 4);
hw/ppc_oldworld.c +1 -1
index 1dcd8a6..8267eb4 100644
@@ -250,7 +250,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
     pci_bus = pci_grackle_init(0xfec00000, pic,
                                get_system_memory(),
                                get_system_io());
-    pci_vga_init(pci_bus);
+    pci_std_vga_init(pci_bus);
 
     escc_mem = escc_init(0, pic[0x0f], pic[0x10], serial_hds[0],
                                serial_hds[1], ESCC_CLOCK, 4);
hw/ppc_prep.c +1 -1
index 592b7b2..1fa7609 100644
@@ -611,7 +611,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
     memory_region_add_subregion(sysmem, 0x80000000, PPC_io_memory);
 
     /* init basic PC hardware */
-    pci_vga_init(pci_bus);
+    pci_std_vga_init(pci_bus);
 
     if (serial_hds[0])
         serial_isa_init(isa_bus, 0, serial_hds[0]);
hw/spapr.c +1 -1
index c34b767..80735d6 100644
@@ -590,7 +590,7 @@ static int spapr_vga_init(PCIBus *pci_bus)
 {
     switch (vga_interface_type) {
     case VGA_STD:
-        pci_vga_init(pci_bus);
+        pci_std_vga_init(pci_bus);
         return 1;
     case VGA_NONE:
         return 0;
hw/sun4u.c +1 -1
index 07cd042..cca090f 100644
@@ -821,7 +821,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
     ivec_irqs = qemu_allocate_irqs(cpu_set_ivec_irq, env, IVEC_MAX);
     pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, ivec_irqs, &pci_bus2,
                            &pci_bus3, &pbm_irqs);
-    pci_vga_init(pci_bus);
+    pci_std_vga_init(pci_bus);
 
     // XXX Should be pci_bus3
     isa_bus = pci_ebus_init(pci_bus, -1, pbm_irqs);
hw/vga-pci.c +3 -3
index 9abbada..992ffd9 100644
@@ -47,7 +47,7 @@ static const VMStateDescription vmstate_vga_pci = {
     }
 };
 
-static int pci_vga_initfn(PCIDevice *dev)
+static int pci_std_vga_initfn(PCIDevice *dev)
 {
      PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
      VGACommonState *s = &d->vga;
@@ -70,7 +70,7 @@ static int pci_vga_initfn(PCIDevice *dev)
      return 0;
 }
 
-DeviceState *pci_vga_init(PCIBus *bus)
+DeviceState *pci_std_vga_init(PCIBus *bus)
 {
     return &pci_create_simple(bus, -1, "VGA")->qdev;
 }
@@ -86,7 +86,7 @@ static void vga_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->no_hotplug = 1;
-    k->init = pci_vga_initfn;
+    k->init = pci_std_vga_initfn;
     k->romfile = "vgabios-stdvga.bin";
     k->vendor_id = PCI_VENDOR_ID_QEMU;
     k->device_id = PCI_DEVICE_ID_QEMU_VGA;
hw/vga-pci.h +1 -1
index 49abf13..d111cdc 100644
@@ -4,7 +4,7 @@
 #include "qemu-common.h"
 
 /* vga-pci.c */
-DeviceState *pci_vga_init(PCIBus *bus);
+DeviceState *pci_std_vga_init(PCIBus *bus);
 
 /* cirrus_vga.c */
 DeviceState *pci_cirrus_vga_init(PCIBus *bus);
Signature · 1 line
1.7.10.4
#0 lore raw

v3 cover Rework ISA/PCI video card initialization

This patch series tries to simplify ISA/PCI video card initialization and to avoid having the same (buggy) code more or less duplicated in various machines.

It creates a new isa_vga_init() and a new pci_vga_init() functions that take care of initializing the requested ISA/PCI video card. It avoid duplication and also has the advantage that newly added PCI video cards are available to all machines without having to touch machine specific code, and that selecting a disabled video card returns an error message to the user.

Changes v1 -> v2:
- Do the same for ISA in addition to PCI, and use that in pc and mips_r4k machines
- Query availability of video cards with QOM instead of qdev_exists() and get rid of the latter function at the same time.
- Default to std if cirrus is not available

Aurelien Jarno (17):
vga: rename pci_vga_init() into pci_std_vga_init()
vga: rename isa_vga_init() to isa_std_vga_init() vl.c: convert *vga_enabled functions to QOM
vl.c: check for qxl availability
vl.c: default to std if cirrus is not available
pci: add a pci_vga_init() function
isa: add a isa_vga_init() function
mips/malta: use the new pci_vga_init() function
alpha: use the new pci_vga_init() function ppc/newworld: use the new pci_vga_init() function ppc/oldworld: use the new pci_vga_init() function ppc/prep: use the new pci_vga_init() function ppc/pSeries: use the new pci_vga_init() function sun/sun4u: use the new pci_vga_init() function
pc: use the new pci_vga_init() and isa_vga_init() functions mips/r4k: use the new is_vga_init() function
vga: cleanup after isa_vga_init() and pci_vga_init() conversion

 hw/alpha_dp264.c  |    2 +-
 hw/alpha_pci.c    |   24 ------------------------
 hw/alpha_sys.h    |    2 --
 hw/cirrus_vga.c   |    6 ------
 hw/isa-bus.c      |   20 ++++++++++++++++++++
 hw/isa.h          |    2 ++
 hw/mips_malta.c   |   10 +---------
 hw/pc.c           |   35 ++++++-----------------------------
 hw/pc.h           |   13 -------------
 hw/pci.c          |   18 ++++++++++++++++++
 hw/pci.h          |    3 +++
 hw/ppc_newworld.c |    1 -
 hw/ppc_oldworld.c |    1 -
 hw/ppc_prep.c     |    1 -
 hw/qdev.c         |    5 -----
 hw/qdev.h         |    1 -
 hw/spapr.c        |    7 ++-----
 hw/sun4u.c        |    1 -
 hw/vga-pci.c      |   10 ++--------
 hw/vga-pci.h      |   12 ------------
 hw/vmware_vga.c   |    1 -
 hw/vmware_vga.h   |   15 ---------------
 sysemu.h          |    3 ---
 vl.c              |   27 +++++++++++++++++++++------
 24 files changed, 76 insertions(+), 144 deletions(-)
 delete mode 100644 hw/vga-pci.h
 delete mode 100644 hw/vmware_vga.h

--
1.7.10.4

#4 lore raw

PATCH v3 3/17 vl.c: convert *vga_enabled functions to QOM

And get rid of qdev_exists().

---
 hw/qdev.c |    5 -----
 hw/qdev.h |    1 -
 vl.c      |    7 ++++---
 3 files changed, 4 insertions(+), 9 deletions(-)
hw/qdev.c +0 -5
index b5a52ac..0eb30a2 100644
@@ -52,11 +52,6 @@ const char *qdev_fw_name(DeviceState *dev)
     return object_get_typename(OBJECT(dev));
 }
 
-bool qdev_exists(const char *name)
-{
-    return !!object_class_by_name(name);
-}
-
 static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
                                      Error **errp);
 
hw/qdev.h +0 -1
index d699194..c6ac636 100644
@@ -153,7 +153,6 @@ typedef struct GlobalProperty {
 
 DeviceState *qdev_create(BusState *bus, const char *name);
 DeviceState *qdev_try_create(BusState *bus, const char *name);
-bool qdev_exists(const char *name);
 int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts);
 int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
vl.c +4 -3
index 7c577fa..f7eed7a 100644
@@ -1690,17 +1690,18 @@ static const QEMUOption qemu_options[] = {
 
 static bool vga_available(void)
 {
-    return qdev_exists("VGA") || qdev_exists("isa-vga");
+    return object_class_by_name("VGA") || object_class_by_name("isa-vga");
 }
 
 static bool cirrus_vga_available(void)
 {
-    return qdev_exists("cirrus-vga") || qdev_exists("isa-cirrus-vga");
+    return object_class_by_name("cirrus-vga")
+           || object_class_by_name("isa-cirrus-vga");
 }
 
 static bool vmware_vga_available(void)
 {
-    return qdev_exists("vmware-svga");
+    return object_class_by_name("vmware-svga");
 }
 
 static void select_vgahw (const char *p)
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH v3 6/17 pci: add a pci_vga_init() function

In reply to Aurelien Jarno

This function create a PCI VGA device according to the value of vga_interface_type. It returns a PCIDevice (and not a DeviceState).

---
 hw/pci.c |   18 ++++++++++++++++++
 hw/pci.h |    3 +++
 2 files changed, 21 insertions(+)
hw/pci.c +18 -0
index f855cf3..e5cee87 100644
@@ -1474,6 +1474,24 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,
     return res;
 }
 
+PCIDevice *pci_vga_init(PCIBus *bus)
+{
+    switch (vga_interface_type) {
+    case VGA_CIRRUS:
+        return pci_create_simple(bus, -1, "cirrus-vga");
+    case VGA_QXL:
+        return pci_create_simple(bus, -1, "qxl-vga");
+    case VGA_STD:
+        return pci_create_simple(bus, -1, "VGA");
+    case VGA_VMWARE:
+        return pci_create_simple(bus, -1, "vmware-svga");
+    case VGA_NONE:
+    default: /* Other non-PCI types. Checking for unsupported types is already
+                done in vl.c. */
+        return NULL;
+    }
+}
+
 /* Whether a given bus number is in range of the secondary
  * bus of the given bridge device. */
 static bool pci_secondary_bus_in_range(PCIDevice *dev, int bus_num)
hw/pci.h +3 -0
index 4b6ab3d..d50d26c 100644
@@ -334,6 +334,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
                         const char *default_devaddr);
 PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,
                                const char *default_devaddr);
+
+PCIDevice *pci_vga_init(PCIBus *bus);
+
 int pci_bus_num(PCIBus *s);
 void pci_for_each_device(PCIBus *bus, int bus_num,
                          void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH v3 4/17 vl.c: check for qxl availability

In reply to Aurelien Jarno

Check for qxl availability in vl.c. This will allow to remove #ifdef CONFIG_SPICE .. #endif later in this series

Cc Anthony Liguori <[email protected]>
Cc Gerd Hoffmann <[email protected]>
---
 vl.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
vl.c +11 -1
index f7eed7a..ba2fa9f 100644
@@ -1704,6 +1704,11 @@ static bool vmware_vga_available(void)
     return object_class_by_name("vmware-svga");
 }
 
+static bool qxl_vga_available(void)
+{
+    return object_class_by_name("qxl-vga");
+}
+
 static void select_vgahw (const char *p)
 {
     const char *opts;
@@ -1733,7 +1738,12 @@ static void select_vgahw (const char *p)
     } else if (strstart(p, "xenfb", &opts)) {
         vga_interface_type = VGA_XENFB;
     } else if (strstart(p, "qxl", &opts)) {
-        vga_interface_type = VGA_QXL;
+        if (qxl_vga_available()) {
+            vga_interface_type = VGA_QXL;
+        } else {
+            fprintf(stderr, "Error: QXL VGA not available\n");
+            exit(0);
+        }
     } else if (!strstart(p, "none", &opts)) {
     invalid_vga:
         fprintf(stderr, "Unknown vga type: %s\n", p);
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH v3 5/17 vl.c: default to std if cirrus is not available

In reply to Aurelien Jarno
---
 vl.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
vl.c +6 -2
index ba2fa9f..6ca27f5 100644
@@ -3606,8 +3606,12 @@ int main(int argc, char **argv, char **envp)
         exit(1);
 
     /* If no default VGA is requested, the default is "none".  */
-    if (default_vga && cirrus_vga_available()) {
-        vga_model = "cirrus";
+    if (default_vga) {
+        if (cirrus_vga_available()) {
+            vga_model = "cirrus";
+        } else if (vga_available()) {
+            vga_model = "std";
+        }
     }
     select_vgahw(vga_model);
 
Signature · 1 line
1.7.10.4
Acked-by on v3 1/17
#2 lore raw

Re: [Qemu-devel] [PATCH v3 01/17] vga: rename pci_vga_init() into pci_std_vga_init()

In reply to Aurelien Jarno
Quoted 10 lines · Aurelien Jarno

This better explains what is this function about. Adjust all callers.

Cc Richard Henderson <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Andreas Färber <[email protected]>
Cc David Gibson <[email protected]>
Cc Anthony Liguori <[email protected]>

r~