All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Hervé Poussineau" <hpoussin@reactos.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Add VMware machine
Date: Sun, 24 Aug 2008 18:16:11 +0200	[thread overview]
Message-ID: <48B1894B.9000602@reactos.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

Hi,

Attached patch adds a 'vmware' machine type.
This one automatically uses VMware display card, and enables VMware mouse.
In non VMware machine types (ie 'pc' and 'isapc' types), VMware backdoor
and VMware mouse are disabled [1]

I added an enum with PC types in pc.c . This system can be extended
later to add more PC types.

Please comment.

Hervé

[1] This has the same effect that the switch '-no-vmport' proposed by
Ian Kirk in http://marc.info/?l=qemu-devel&m=121957847306185&w=2

[-- Attachment #2: vmware_machine.diff --]
[-- Type: text/plain, Size: 11684 bytes --]

Index: hw/boards.h
===================================================================
--- hw/boards.h	(revision 5075)
+++ hw/boards.h	(working copy)
@@ -29,6 +29,7 @@
 /* pc.c */
 extern QEMUMachine pc_machine;
 extern QEMUMachine isapc_machine;
+extern QEMUMachine vmware_machine;
 
 /* ppc.c */
 extern QEMUMachine prep_machine;
Index: hw/pc.c
===================================================================
--- hw/pc.c	(revision 5075)
+++ hw/pc.c	(working copy)
@@ -53,6 +53,12 @@
 static IOAPICState *ioapic;
 static PCIDevice *i440fx_state;
 
+typedef enum pc_model {
+    MODEL_ISA = 0,
+    MODEL_PCI = 1,
+    MODEL_VMWARE = 2,
+} pc_model;
+
 static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
 {
 }
@@ -721,14 +727,14 @@
                      const char *boot_device, DisplayState *ds,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename,
-                     int pci_enabled, const char *cpu_model)
+                     pc_model model, const char *cpu_model)
 {
     char buf[1024];
     int ret, linux_boot, i;
     ram_addr_t ram_addr, vga_ram_addr, bios_offset, vga_bios_offset;
     ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
     int bios_size, isa_bios_size, vga_bios_size;
-    PCIBus *pci_bus;
+    PCIBus *pci_bus = NULL;
     int piix3_devfn = -1;
     CPUState *env;
     NICInfo *nd;
@@ -769,12 +775,14 @@
             env->cpuid_features |= CPUID_APIC;
         }
         qemu_register_reset(main_cpu_reset, env);
-        if (pci_enabled) {
+        if (model != MODEL_ISA) {
             apic_init(env);
         }
     }
 
-    vmport_init();
+    /* VMware backdoor */
+    if (model == MODEL_VMWARE)
+        vmport_init();
 
     /* allocate RAM */
     ram_addr = qemu_ram_alloc(ram_size);
@@ -880,11 +888,15 @@
     i8259 = i8259_init(cpu_irq[0]);
     ferr_irq = i8259[13];
 
-    if (pci_enabled) {
+    /* PCI bus */
+    switch (model) {
+    case MODEL_PCI:
+    case MODEL_VMWARE:
         pci_bus = i440fx_init(&i440fx_state, i8259);
         piix3_devfn = piix3_init(pci_bus, -1);
-    } else {
-        pci_bus = NULL;
+        break;
+    default:
+        break;
     }
 
     /* init basic PC hardware */
@@ -892,29 +904,38 @@
 
     register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL);
 
-    if (cirrus_vga_enabled) {
-        if (pci_enabled) {
+    /* Graphic card */
+    switch (model) {
+    case MODEL_ISA:
+        if (cirrus_vga_enabled) {
+            isa_cirrus_vga_init(ds, phys_ram_base + vga_ram_addr,
+                                vga_ram_addr, vga_ram_size);
+        } else if (vmsvga_enabled) {
+            fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
+        } else {
+            isa_vga_init(ds, phys_ram_base + vga_ram_addr,
+                         vga_ram_addr, vga_ram_size);
+        }
+        break;
+    case MODEL_PCI:
+        if (cirrus_vga_enabled) {
             pci_cirrus_vga_init(pci_bus,
                                 ds, phys_ram_base + vga_ram_addr,
                                 vga_ram_addr, vga_ram_size);
-        } else {
-            isa_cirrus_vga_init(ds, phys_ram_base + vga_ram_addr,
-                                vga_ram_addr, vga_ram_size);
-        }
-    } else if (vmsvga_enabled) {
-        if (pci_enabled)
+        } else if (vmsvga_enabled) {
             pci_vmsvga_init(pci_bus, ds, phys_ram_base + vga_ram_addr,
                             vga_ram_addr, vga_ram_size);
-        else
-            fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
-    } else {
-        if (pci_enabled) {
+        } else {
             pci_vga_init(pci_bus, ds, phys_ram_base + vga_ram_addr,
                          vga_ram_addr, vga_ram_size, 0, 0);
-        } else {
-            isa_vga_init(ds, phys_ram_base + vga_ram_addr,
-                         vga_ram_addr, vga_ram_size);
         }
+        break;
+    case MODEL_VMWARE:
+        pci_vmsvga_init(pci_bus, ds, phys_ram_base + vga_ram_addr,
+                        vga_ram_addr, vga_ram_size);
+        break;
+    default:
+        break;
     }
 
     rtc_state = rtc_init(0x70, i8259[8]);
@@ -924,12 +945,12 @@
     register_ioport_read(0x92, 1, 1, ioport92_read, NULL);
     register_ioport_write(0x92, 1, 1, ioport92_write, NULL);
 
-    if (pci_enabled) {
+    if (model != MODEL_ISA) {
         ioapic = ioapic_init();
     }
     pit = pit_init(0x40, i8259[0]);
     pcspk_init(pit);
-    if (pci_enabled) {
+    if (model != MODEL_ISA) {
         pic_set_alt_irq_func(isa_pic, ioapic_set_irq, ioapic);
     }
 
@@ -947,56 +968,61 @@
         }
     }
 
+    /* Network cards */
     for(i = 0; i < nb_nics; i++) {
         nd = &nd_table[i];
         if (!nd->model) {
-            if (pci_enabled) {
+            if (pci_bus)
                 nd->model = "ne2k_pci";
-            } else {
+            else
                 nd->model = "ne2k_isa";
-            }
         }
-        if (strcmp(nd->model, "ne2k_isa") == 0) {
+        if (strcmp(nd->model, "?") == 0) {
+            fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n");
+            if (pci_bus)
+                pci_nic_init(pci_bus, nd, -1);
+            exit(1);
+        } else if (strcmp(nd->model, "ne2k_isa") == 0) {
             pc_init_ne2k_isa(nd, i8259);
-        } else if (pci_enabled) {
-            if (strcmp(nd->model, "?") == 0)
-                fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n");
+        } else if (pci_bus) {
             pci_nic_init(pci_bus, nd, -1);
-        } else if (strcmp(nd->model, "?") == 0) {
-            fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n");
-            exit(1);
         } else {
             fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd->model);
             exit(1);
         }
     }
 
+    /* IDE devices */
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
         fprintf(stderr, "qemu: too many IDE bus\n");
         exit(1);
     }
-
-    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
+    for (i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
         index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
-	if (index != -1)
-	    hd[i] = drives_table[index].bdrv;
-	else
-	    hd[i] = NULL;
+        hd[i] = (index == -1) ? NULL : drives_table[index].bdrv;
     }
-
-    if (pci_enabled) {
+    switch (model) {
+    case MODEL_ISA:
+        for (i = 0; i < MAX_IDE_BUS; i++)
+            isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
+                         hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
+        break;
+    case MODEL_PCI:
+    case MODEL_VMWARE:
         pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1, i8259);
-    } else {
-        for(i = 0; i < MAX_IDE_BUS; i++) {
-            isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
-	                 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
-        }
+    default:
+        break;
     }
 
-    i8042_init(i8259[1], i8259[12], 0x60);
+    /* Keyboard/mouse */
+    if (model != MODEL_VMWARE)
+        i8042_init(i8259[1], i8259[12], 0x60, 0);
+    else
+        i8042_init(i8259[1], i8259[12], 0x60, 1);
+
     DMA_init(0);
 #ifdef HAS_AUDIO
-    audio_init(pci_enabled ? pci_bus : NULL, i8259);
+    audio_init(pci_bus, i8259);
 #endif
 
     for(i = 0; i < MAX_FD; i++) {
@@ -1010,11 +1036,11 @@
 
     cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, hd);
 
-    if (pci_enabled && usb_enabled) {
+    if (pci_bus && usb_enabled) {
         usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
     }
 
-    if (pci_enabled && acpi_enabled) {
+    if (pci_bus && acpi_enabled) {
         uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
         i2c_bus *smbus;
 
@@ -1029,7 +1055,7 @@
         i440fx_init_memory_mappings(i440fx_state);
     }
 
-    if (pci_enabled) {
+    if (pci_bus) {
 	int max_bus;
         int bus, unit;
         void *scsi;
@@ -1057,7 +1083,7 @@
 {
     pc_init1(ram_size, vga_ram_size, boot_device, ds,
              kernel_filename, kernel_cmdline,
-             initrd_filename, 1, cpu_model);
+             initrd_filename, MODEL_PCI, cpu_model);
 }
 
 static void pc_init_isa(ram_addr_t ram_size, int vga_ram_size,
@@ -1069,9 +1095,21 @@
 {
     pc_init1(ram_size, vga_ram_size, boot_device, ds,
              kernel_filename, kernel_cmdline,
-             initrd_filename, 0, cpu_model);
+             initrd_filename, MODEL_ISA, cpu_model);
 }
 
+static void pc_init_vmware(ram_addr_t ram_size, int vga_ram_size,
+                           const char *boot_device, DisplayState *ds,
+                           const char *kernel_filename,
+                           const char *kernel_cmdline,
+                           const char *initrd_filename,
+                           const char *cpu_model)
+{
+    pc_init1(ram_size, vga_ram_size, boot_device, ds,
+             kernel_filename, kernel_cmdline,
+             initrd_filename, MODEL_VMWARE, cpu_model);
+}
+
 QEMUMachine pc_machine = {
     .name = "pc",
     .desc = "Standard PC",
@@ -1085,3 +1123,10 @@
     .init = pc_init_isa,
     .ram_require = VGA_RAM_SIZE + PC_MAX_BIOS_SIZE,
 };
+
+QEMUMachine vmware_machine = {
+    .name = "vmware",
+    .desc = "VMWare PC",
+    .init = pc_init_vmware,
+    .ram_require = VGA_RAM_SIZE + PC_MAX_BIOS_SIZE,
+};
Index: hw/pc.h
===================================================================
--- hw/pc.h	(revision 5075)
+++ hw/pc.h	(working copy)
@@ -69,7 +69,8 @@
 
 /* pckbd.c */
 
-void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base);
+void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base,
+                int vmmouse);
 void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
                    target_phys_addr_t base, int it_shift);
 
Index: hw/pckbd.c
===================================================================
--- hw/pckbd.c	(revision 5075)
+++ hw/pckbd.c	(working copy)
@@ -365,7 +365,8 @@
     return 0;
 }
 
-void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base)
+void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base,
+                int vmmouse)
 {
     KBDState *s = &kbd_state;
 
@@ -382,7 +383,8 @@
     s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
     s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
 #ifdef TARGET_I386
-    vmmouse_init(s->mouse);
+    if (vmmouse)
+        vmmouse_init(s->mouse);
 #endif
     qemu_register_reset(kbd_reset, s);
 }
@@ -446,8 +448,5 @@
 
     s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
     s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
-#ifdef TARGET_I386
-    vmmouse_init(s->mouse);
-#endif
     qemu_register_reset(kbd_reset, s);
 }
Index: target-i386/machine.c
===================================================================
--- target-i386/machine.c	(revision 5074)
+++ target-i386/machine.c	(working copy)
@@ -9,6 +9,7 @@
 {
     qemu_register_machine(&pc_machine);
     qemu_register_machine(&isapc_machine);
+    qemu_register_machine(&vmware_machine);
 }
 
 static void cpu_put_seg(QEMUFile *f, SegmentCache *dt)
Index: vl.c
===================================================================
--- vl.c	(revision 5074)
+++ vl.c	(working copy)
@@ -8632,6 +8632,7 @@
                 vmsvga_enabled = 0;
                 break;
             case QEMU_OPTION_vmsvga:
+                printf("qemu: you should use 'vmware' machine type instead (see -M option)\n");
                 cirrus_vga_enabled = 0;
                 vmsvga_enabled = 1;
                 break;

             reply	other threads:[~2008-08-24 16:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-24 16:16 Hervé Poussineau [this message]
2008-08-24 17:24 ` [Qemu-devel] [PATCH] Add VMware machine Blue Swirl
2008-08-24 19:38 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48B1894B.9000602@reactos.org \
    --to=hpoussin@reactos.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.