qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes
@ 2014-08-14 19:25 Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 01/33] pc: Replace tabs with spaces on pc.h Eduardo Habkost
                   ` (32 more replies)
  0 siblings, 33 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Now all the PC machine-types are declared using only a class_init + TypeInfo
pair, and nothing else. In order to do that, all the code that was in the old
pc_compat_*() functions are represented using PCMachineClass fields.

Git tree:
    https://github.com/ehabkost/qemu-hacks/tree/pc-machine-class.v4

Changes v3 -> v4:
* Include CPU feature properties, so compat_props may be used for CPUID compat
  bits.
* Move KVM defaults to PCMachineClass.
* Use GList for compat_props instead of reusing GlobalProperty.next (we need to
  do that to allow the same GlobalProperty to be used on multiple subclasses).
* Finally eliminate all pc_compat_*() functions, and don't require a different
  init function for each PC machine-type version.

Eduardo Habkost (32):
  pc: Replace tabs with spaces on pc.h
  vl.c: Use qdev_prop_register_global() for single globals
  pc: Eliminate has_pci_info global variable
  piix: Add kvmclock_enabled, pci_enabled globals
  piix: Eliminate pc_init_pci()
  piix: Move pc-0.14 qxl compat properties to PC_COMPAT_0_14
  piix: Move pc-0.13 virtio-9p-pci compat to PC_COMPAT_0_13
  piix: Move pc-0.1[23] rombar compat props to PC_COMPAT_0_13
  piix: Move pc-0.11 drive version compat props to PC_COMPAT_0_11
  machine: Make compat_props a linked list
  pc: Register machine classes directly instead of using QEMUMachine
  pc: Eliminate pc_common_machine_options()
  pc: Eliminate pc_default_machine_options()
  piix: Eliminate pc_i440fx_machine_options()
  q35: Eliminate pc_q35_machine_options()
  q35: Eliminate pc_q35_1_4_machine_options()
  pc: Eliminate all *_machine_options() functions
  machine: Eliminate QEMUMachine.compat_props
  pc: Rename pc_machine variable to pcms
  pc: Pass PCMachineState argument to pc_cpus_init()
  machine: Add MachineClass.default_cpu_model field
  pc: Move globals to PCMachineClass
  pc: Move option_rom_has_mr/rom_file_has_mr to MachineClass
  pc: Add PCMachineClass.compat_apic_id_mode field
  target-i386: Move error handling to end of x86_cpu_parse_featurestr()
  target-i386: Renove underscores from feature names
  target-i386: Register X86CPU "feat-kvmclock" feature
  pc: Use compat_props for CPUID compat bits
  target-i386: Move some declarations to hw/i386/cpu.h
  pc: Add default KVM features fields to PCMachineClass
  pc: Eliminate pc_compat_*() functions
  piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init()

Igor Mammedov (1):
  target-i386: set [+-]feature using QOM properties

 hw/core/loader.c             |  12 +-
 hw/core/machine.c            |  26 ++
 hw/core/qdev-properties.c    |   9 -
 hw/i386/pc.c                 |  86 ++---
 hw/i386/pc_piix.c            | 764 ++++++++++++++++++++++---------------------
 hw/i386/pc_q35.c             | 271 +++++++--------
 include/hw/boards.h          |  25 +-
 include/hw/i386/cpu.h        | 564 ++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h         |  51 +--
 include/hw/qdev-properties.h |   1 -
 target-i386/cpu.c            | 300 ++++++++---------
 target-i386/cpu.h            | 565 +-------------------------------
 vl.c                         |  47 +--
 13 files changed, 1378 insertions(+), 1343 deletions(-)
 create mode 100644 include/hw/i386/cpu.h

-- 
1.9.3

^ permalink raw reply	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 01/33] pc: Replace tabs with spaces on pc.h
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 02/33] vl.c: Use qdev_prop_register_global() for single globals Eduardo Habkost
                   ` (31 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 include/hw/i386/pc.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 863eefb..9fb7144 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -446,23 +446,23 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
             .driver   = "scsi-hd",\
             .property = "discard_granularity",\
             .value    = stringify(0),\
-	},{\
+        },{\
             .driver   = "scsi-cd",\
             .property = "discard_granularity",\
             .value    = stringify(0),\
-	},{\
+        },{\
             .driver   = "scsi-disk",\
             .property = "discard_granularity",\
             .value    = stringify(0),\
-	},{\
+        },{\
             .driver   = "ide-hd",\
             .property = "discard_granularity",\
             .value    = stringify(0),\
-	},{\
+        },{\
             .driver   = "ide-cd",\
             .property = "discard_granularity",\
             .value    = stringify(0),\
-	},{\
+        },{\
             .driver   = "ide-drive",\
             .property = "discard_granularity",\
             .value    = stringify(0),\
@@ -470,7 +470,7 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
             .driver   = "virtio-blk-pci",\
             .property = "discard_granularity",\
             .value    = stringify(0),\
-	},{\
+        },{\
             .driver   = "virtio-serial-pci",\
             .property = "vectors",\
             /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string */\
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 02/33] vl.c: Use qdev_prop_register_global() for single globals
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 01/33] pc: Replace tabs with spaces on pc.h Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 03/33] pc: Eliminate has_pci_info global variable Eduardo Habkost
                   ` (30 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Instead of using an array when registering a single global, simply call
qdev_prop_register().

Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 vl.c | 39 +++++++++++++++------------------------
 1 file changed, 15 insertions(+), 24 deletions(-)

diff --git a/vl.c b/vl.c
index a8029d5..1dd12a8 100644
--- a/vl.c
+++ b/vl.c
@@ -879,16 +879,13 @@ static void configure_rtc(QemuOpts *opts)
     value = qemu_opt_get(opts, "driftfix");
     if (value) {
         if (!strcmp(value, "slew")) {
-            static GlobalProperty slew_lost_ticks[] = {
-                {
-                    .driver   = "mc146818rtc",
-                    .property = "lost_tick_policy",
-                    .value    = "slew",
-                },
-                { /* end of list */ }
+            static GlobalProperty slew_lost_ticks = {
+                .driver   = "mc146818rtc",
+                .property = "lost_tick_policy",
+                .value    = "slew",
             };
 
-            qdev_prop_register_global_list(slew_lost_ticks);
+            qdev_prop_register_global(&slew_lost_ticks);
         } else if (!strcmp(value, "none")) {
             /* discard is default */
         } else {
@@ -3662,16 +3659,13 @@ int main(int argc, char **argv, char **envp)
                 win2k_install_hack = 1;
                 break;
             case QEMU_OPTION_rtc_td_hack: {
-                static GlobalProperty slew_lost_ticks[] = {
-                    {
-                        .driver   = "mc146818rtc",
-                        .property = "lost_tick_policy",
-                        .value    = "slew",
-                    },
-                    { /* end of list */ }
+                static GlobalProperty slew_lost_ticks = {
+                    .driver   = "mc146818rtc",
+                    .property = "lost_tick_policy",
+                    .value    = "slew",
                 };
 
-                qdev_prop_register_global_list(slew_lost_ticks);
+                qdev_prop_register_global(&slew_lost_ticks);
                 break;
             }
             case QEMU_OPTION_acpitable:
@@ -3713,18 +3707,15 @@ int main(int argc, char **argv, char **envp)
                 break;
             }
             case QEMU_OPTION_no_kvm_pit_reinjection: {
-                static GlobalProperty kvm_pit_lost_tick_policy[] = {
-                    {
-                        .driver   = "kvm-pit",
-                        .property = "lost_tick_policy",
-                        .value    = "discard",
-                    },
-                    { /* end of list */ }
+                static GlobalProperty kvm_pit_lost_tick_policy = {
+                    .driver   = "kvm-pit",
+                    .property = "lost_tick_policy",
+                    .value    = "discard",
                 };
 
                 fprintf(stderr, "Warning: option deprecated, use "
                         "lost_tick_policy property of kvm-pit instead.\n");
-                qdev_prop_register_global_list(kvm_pit_lost_tick_policy);
+                qdev_prop_register_global(&kvm_pit_lost_tick_policy);
                 break;
             }
             case QEMU_OPTION_usb:
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 03/33] pc: Eliminate has_pci_info global variable
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 01/33] pc: Replace tabs with spaces on pc.h Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 02/33] vl.c: Use qdev_prop_register_global() for single globals Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 04/33] piix: Add kvmclock_enabled, pci_enabled globals Eduardo Habkost
                   ` (29 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

The variable is always set to false and never changed, so we simply
don't need it.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c | 5 +----
 hw/i386/pc_q35.c  | 4 +---
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 4f22be8..5287a84 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -59,7 +59,6 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
-static bool has_pci_info;
 static bool has_acpi_build = true;
 static int legacy_acpi_table_size;
 static bool smbios_defaults = true;
@@ -166,7 +165,7 @@ static void pc_init1(MachineState *machine,
     guest_info->has_acpi_build = has_acpi_build;
     guest_info->legacy_acpi_table_size = legacy_acpi_table_size;
 
-    guest_info->has_pci_info = has_pci_info;
+    guest_info->has_pci_info = false;
     guest_info->isapc_ram_fw = !pci_enabled;
     guest_info->has_reserved_memory = has_reserved_memory;
 
@@ -340,7 +339,6 @@ static void pc_compat_1_7(MachineState *machine)
 static void pc_compat_1_6(MachineState *machine)
 {
     pc_compat_1_7(machine);
-    has_pci_info = false;
     rom_file_has_mr = false;
     has_acpi_build = false;
 }
@@ -422,7 +420,6 @@ static void pc_init_pci_no_kvmclock(MachineState *machine)
 
 static void pc_init_isa(MachineState *machine)
 {
-    has_pci_info = false;
     has_acpi_build = false;
     smbios_defaults = false;
     gigabyte_align = false;
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index c39ee98..0abd56c 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -49,7 +49,6 @@
 /* ICH9 AHCI has 6 ports */
 #define MAX_SATA_PORTS     6
 
-static bool has_pci_info;
 static bool has_acpi_build = true;
 static bool smbios_defaults = true;
 static bool smbios_legacy_mode;
@@ -150,7 +149,7 @@ static void pc_q35_init(MachineState *machine)
     }
 
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
-    guest_info->has_pci_info = has_pci_info;
+    guest_info->has_pci_info = false;
     guest_info->isapc_ram_fw = false;
     guest_info->has_acpi_build = has_acpi_build;
     guest_info->has_reserved_memory = has_reserved_memory;
@@ -296,7 +295,6 @@ static void pc_compat_1_7(MachineState *machine)
 static void pc_compat_1_6(MachineState *machine)
 {
     pc_compat_1_7(machine);
-    has_pci_info = false;
     rom_file_has_mr = false;
     has_acpi_build = false;
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 04/33] piix: Add kvmclock_enabled, pci_enabled globals
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (2 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 03/33] pc: Eliminate has_pci_info global variable Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 05/33] piix: Eliminate pc_init_pci() Eduardo Habkost
                   ` (28 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

This looks like a step backwards, but it will allow pc-0.1[0123] and
isapc to follow the same compat+init pattern used by the other
machine-types, making it easier to convert them to QOM and reduce
duplicated code.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 5287a84..02c99a4 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -59,6 +59,7 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
+static bool pci_enabled = true;
 static bool has_acpi_build = true;
 static int legacy_acpi_table_size;
 static bool smbios_defaults = true;
@@ -69,11 +70,10 @@ static bool smbios_legacy_mode;
  */
 static bool gigabyte_align = true;
 static bool has_reserved_memory = true;
+static bool kvmclock_enabled = true;
 
 /* PC hardware initialisation */
-static void pc_init1(MachineState *machine,
-                     int pci_enabled,
-                     int kvmclock_enabled)
+static void pc_init1(MachineState *machine)
 {
     PCMachineState *pc_machine = PC_MACHINE(machine);
     MemoryRegion *system_memory = get_system_memory();
@@ -300,7 +300,7 @@ static void pc_init1(MachineState *machine,
 
 static void pc_init_pci(MachineState *machine)
 {
-    pc_init1(machine, 1, 1);
+    pc_init1(machine);
 }
 
 static void pc_compat_2_0(MachineState *machine)
@@ -368,6 +368,13 @@ static void pc_compat_1_2(MachineState *machine)
     x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
 }
 
+/* PC compat function for pc-0.10 to pc-0.13 */
+static void pc_compat_0_13(MachineState *machine)
+{
+    pc_compat_1_2(machine);
+    kvmclock_enabled = false;
+}
+
 static void pc_init_pci_2_0(MachineState *machine)
 {
     pc_compat_2_0(machine);
@@ -414,12 +421,13 @@ static void pc_init_pci_1_2(MachineState *machine)
 /* PC init function for pc-0.10 to pc-0.13 */
 static void pc_init_pci_no_kvmclock(MachineState *machine)
 {
-    pc_compat_1_2(machine);
-    pc_init1(machine, 1, 0);
+    pc_compat_0_13(machine);
+    pc_init_pci(machine);
 }
 
 static void pc_init_isa(MachineState *machine)
 {
+    pci_enabled = false;
     has_acpi_build = false;
     smbios_defaults = false;
     gigabyte_align = false;
@@ -432,7 +440,7 @@ static void pc_init_isa(MachineState *machine)
     }
     x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
     enable_compat_apic_id_mode();
-    pc_init1(machine, 0, 1);
+    pc_init1(machine);
 }
 
 #ifdef CONFIG_XEN
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 05/33] piix: Eliminate pc_init_pci()
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (3 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 04/33] piix: Add kvmclock_enabled, pci_enabled globals Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 06/33] piix: Move pc-0.14 qxl compat properties to PC_COMPAT_0_14 Eduardo Habkost
                   ` (27 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Now we can use pc_init1() directly.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 02c99a4..ff75ca1 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -298,11 +298,6 @@ static void pc_init1(MachineState *machine)
     }
 }
 
-static void pc_init_pci(MachineState *machine)
-{
-    pc_init1(machine);
-}
-
 static void pc_compat_2_0(MachineState *machine)
 {
     /* This value depends on the actual DSDT and SSDT compiled into
@@ -378,51 +373,51 @@ static void pc_compat_0_13(MachineState *machine)
 static void pc_init_pci_2_0(MachineState *machine)
 {
     pc_compat_2_0(machine);
-    pc_init_pci(machine);
+    pc_init1(machine);
 }
 
 static void pc_init_pci_1_7(MachineState *machine)
 {
     pc_compat_1_7(machine);
-    pc_init_pci(machine);
+    pc_init1(machine);
 }
 
 static void pc_init_pci_1_6(MachineState *machine)
 {
     pc_compat_1_6(machine);
-    pc_init_pci(machine);
+    pc_init1(machine);
 }
 
 static void pc_init_pci_1_5(MachineState *machine)
 {
     pc_compat_1_5(machine);
-    pc_init_pci(machine);
+    pc_init1(machine);
 }
 
 static void pc_init_pci_1_4(MachineState *machine)
 {
     pc_compat_1_4(machine);
-    pc_init_pci(machine);
+    pc_init1(machine);
 }
 
 static void pc_init_pci_1_3(MachineState *machine)
 {
     pc_compat_1_3(machine);
-    pc_init_pci(machine);
+    pc_init1(machine);
 }
 
 /* PC machine init function for pc-0.14 to pc-1.2 */
 static void pc_init_pci_1_2(MachineState *machine)
 {
     pc_compat_1_2(machine);
-    pc_init_pci(machine);
+    pc_init1(machine);
 }
 
 /* PC init function for pc-0.10 to pc-0.13 */
 static void pc_init_pci_no_kvmclock(MachineState *machine)
 {
     pc_compat_0_13(machine);
-    pc_init_pci(machine);
+    pc_init1(machine);
 }
 
 static void pc_init_isa(MachineState *machine)
@@ -448,7 +443,7 @@ static void pc_xen_hvm_init(MachineState *machine)
 {
     PCIBus *bus;
 
-    pc_init_pci(machine);
+    pc_init1(machine);
 
     bus = pci_find_primary_bus();
     if (bus != NULL) {
@@ -470,7 +465,7 @@ static QEMUMachine pc_i440fx_machine_v2_1 = {
     PC_I440FX_2_1_MACHINE_OPTIONS,
     .name = "pc-i440fx-2.1",
     .alias = "pc",
-    .init = pc_init_pci,
+    .init = pc_init1,
     .is_default = 1,
 };
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 06/33] piix: Move pc-0.14 qxl compat properties to PC_COMPAT_0_14
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (4 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 05/33] piix: Eliminate pc_init_pci() Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 07/33] piix: Move pc-0.13 virtio-9p-pci compat to PC_COMPAT_0_13 Eduardo Habkost
                   ` (26 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Gerd Hoffmann, Igor Mammedov, Andreas Färber

Those properties were introduced by commit
3827cdb1c3aa17a792d1658161195b9d7173c26b. They were not duplicated into
pc-0.13 and older because 0.14 was the first QEMU version supporting
qxl. The only problem is that this breaks the PC_COMPAT_* nesting
pattern we currently use.

So, move the properties to PC_COMPAT_0_14. This makes pc-0.13 and older
inherit them, but that shouldn't be an issue as QEMU 0.13 didn't support
qxl.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/i386/pc_piix.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index ff75ca1..c895dc9 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -702,6 +702,14 @@ static QEMUMachine pc_machine_v0_15 = {
             .driver   = "virtio-balloon-pci",\
             .property = "event_idx",\
             .value    = "off",\
+        },{\
+            .driver   = "qxl",\
+            .property = "revision",\
+            .value    = stringify(2),\
+        },{\
+            .driver   = "qxl-vga",\
+            .property = "revision",\
+            .value    = stringify(2),\
         }
 
 static QEMUMachine pc_machine_v0_14 = {
@@ -709,15 +717,6 @@ static QEMUMachine pc_machine_v0_14 = {
     .name = "pc-0.14",
     .compat_props = (GlobalProperty[]) {
         PC_COMPAT_0_14, 
-        {
-            .driver   = "qxl",
-            .property = "revision",
-            .value    = stringify(2),
-        },{
-            .driver   = "qxl-vga",
-            .property = "revision",
-            .value    = stringify(2),
-        },
         { /* end of list */ }
     },
     .hw_version = "0.14",
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 07/33] piix: Move pc-0.13 virtio-9p-pci compat to PC_COMPAT_0_13
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (5 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 06/33] piix: Move pc-0.14 qxl compat properties to PC_COMPAT_0_14 Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 08/33] piix: Move pc-0.1[23] rombar compat props " Eduardo Habkost
                   ` (25 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Gerd Hoffmann, Igor Mammedov, Andreas Färber,
	Aneesh Kumar K.V

The compat property was added by commit
9dbcca5aa13cb9ab40788ac4c56bc227d94ca920, and the pc-0.12 and older
machine-types were not changed because virtio-9p-pci was introduced on QEMU
0.13 (commit 9f10751365b26b13b8a9b67e0e90536ae3d282df). The only problem is
that this breaks the PC_COMPAT_* nesting pattern we currently use.

So, move the property to PC_COMPAT_0_13. This make pc-0.12 and older inherit
it, but that shouldn't be an issue as QEMU 0.12 didn't have virtio-9p-pci.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 hw/i386/pc_piix.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index c895dc9..c11abc8 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -732,6 +732,10 @@ static QEMUMachine pc_machine_v0_14 = {
             .driver   = "AC97",\
             .property = "use_broken_id",\
             .value    = stringify(1),\
+        },{\
+            .driver   = "virtio-9p-pci",\
+            .property = "vectors",\
+            .value    = stringify(0),\
         }
 
 #define PC_I440FX_0_13_MACHINE_OPTIONS \
@@ -744,10 +748,6 @@ static QEMUMachine pc_machine_v0_13 = {
     .compat_props = (GlobalProperty[]) {
         PC_COMPAT_0_13,
         {
-            .driver   = "virtio-9p-pci",
-            .property = "vectors",
-            .value    = stringify(0),
-        },{
             .driver   = "VGA",
             .property = "rombar",
             .value    = stringify(0),
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 08/33] piix: Move pc-0.1[23] rombar compat props to PC_COMPAT_0_13
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (6 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 07/33] piix: Move pc-0.13 virtio-9p-pci compat to PC_COMPAT_0_13 Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 09/33] piix: Move pc-0.11 drive version compat props to PC_COMPAT_0_11 Eduardo Habkost
                   ` (24 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Stefan Weil, Michael S. Tsirkin, Alexander Graf,
	Don Slutz, Gerd Hoffmann, Igor Mammedov, Andreas Färber

The VGA and vmware-svga rombar compat properties were added by commit
281a26b15b4adcecb8604216738975abd754bea8, but only to pc-0.13 and
pc-0.12. This breaks the PC_COMPAT_* nesting pattern we currently
follow.

The new variables will now be inherited by pc-0.11 and older, but
pc-0.11 and pc-0.10 already have PCI.rombar=0 on compat_props, so they
shouldn't be affected at all.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Cc: Stefan Weil <sw@weilnetz.de>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/i386/pc_piix.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index c11abc8..a7b0c34 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -736,6 +736,14 @@ static QEMUMachine pc_machine_v0_14 = {
             .driver   = "virtio-9p-pci",\
             .property = "vectors",\
             .value    = stringify(0),\
+        },{\
+            .driver   = "VGA",\
+            .property = "rombar",\
+            .value    = stringify(0),\
+        },{\
+            .driver   = "vmware-svga",\
+            .property = "rombar",\
+            .value    = stringify(0),\
         }
 
 #define PC_I440FX_0_13_MACHINE_OPTIONS \
@@ -747,15 +755,6 @@ static QEMUMachine pc_machine_v0_13 = {
     .name = "pc-0.13",
     .compat_props = (GlobalProperty[]) {
         PC_COMPAT_0_13,
-        {
-            .driver   = "VGA",
-            .property = "rombar",
-            .value    = stringify(0),
-        },{
-            .driver   = "vmware-svga",
-            .property = "rombar",
-            .value    = stringify(0),
-        },
         { /* end of list */ }
     },
     .hw_version = "0.13",
@@ -790,15 +789,6 @@ static QEMUMachine pc_machine_v0_12 = {
     .name = "pc-0.12",
     .compat_props = (GlobalProperty[]) {
         PC_COMPAT_0_12,
-        {
-            .driver   = "VGA",
-            .property = "rombar",
-            .value    = stringify(0),
-        },{
-            .driver   = "vmware-svga",
-            .property = "rombar",
-            .value    = stringify(0),
-        },
         { /* end of list */ }
     },
     .hw_version = "0.12",
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 09/33] piix: Move pc-0.11 drive version compat props to PC_COMPAT_0_11
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (7 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 08/33] piix: Move pc-0.1[23] rombar compat props " Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 10/33] machine: Make compat_props a linked list Eduardo Habkost
                   ` (23 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Gerd Hoffmann, Igor Mammedov, Andreas Färber

The current code setting ide-drive.ver and scsi-disk.ver on pc-0.11
breaks the PC_COMPAT_* nesting pattern we currently use.

As those variables are overwritten in pc-0.10 too, they can be inherited
by pc-0.10 with no side-effects at all.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/i386/pc_piix.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index a7b0c34..1127c54 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -804,6 +804,14 @@ static QEMUMachine pc_machine_v0_12 = {
             .driver   = TYPE_PCI_DEVICE,\
             .property = "rombar",\
             .value    = stringify(0),\
+        },{\
+            .driver   = "ide-drive",\
+            .property = "ver",\
+            .value    = "0.11",\
+        },{\
+            .driver   = "scsi-disk",\
+            .property = "ver",\
+            .value    = "0.11",\
         }
 
 static QEMUMachine pc_machine_v0_11 = {
@@ -811,15 +819,6 @@ static QEMUMachine pc_machine_v0_11 = {
     .name = "pc-0.11",
     .compat_props = (GlobalProperty[]) {
         PC_COMPAT_0_11,
-        {
-            .driver   = "ide-drive",
-            .property = "ver",
-            .value    = "0.11",
-        },{
-            .driver   = "scsi-disk",
-            .property = "ver",
-            .value    = "0.11",
-        },
         { /* end of list */ }
     },
     .hw_version = "0.11",
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 10/33] machine: Make compat_props a linked list
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (8 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 09/33] piix: Move pc-0.11 drive version compat props to PC_COMPAT_0_11 Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 11/33] pc: Register machine classes directly instead of using QEMUMachine Eduardo Habkost
                   ` (22 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

This will make it easier to write reusable class_init code which adds
properties to MachineClass.compat_props.

Use GList instead of reusing GlobalProperty.next, because the same
GlobalProperty can appear on multiple machine subclasses.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v3 -> v4:
* Use GList instead of reusing the "next" field on GlobalProperty,
  so the same GlobalProperty elements may be added to multiple classes.
---
 hw/core/machine.c            | 25 +++++++++++++++++++++++++
 hw/core/qdev-properties.c    |  9 ---------
 hw/i386/pc.c                 |  4 +++-
 include/hw/boards.h          | 19 ++++++++++++++++++-
 include/hw/qdev-properties.h |  1 -
 vl.c                         |  8 ++++----
 6 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index 7a66c57..3eeb0a9 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -290,12 +290,37 @@ static void machine_finalize(Object *obj)
     g_free(ms->firmware);
 }
 
+void machine_class_add_compat_props(MachineClass *mc, GlobalProperty *props)
+{
+    int i;
+    for (i = 0; props[i].driver; i++) {
+        mc->compat_props = g_list_append(mc->compat_props, &props[i]);
+    }
+}
+
+void machine_class_register_compat_props(MachineClass *mc)
+{
+    GList *l;
+    for (l = mc->compat_props; l; l = l->next) {
+        GlobalProperty *prop = l->data;
+        qdev_prop_register_global(prop);
+    }
+}
+
+static void machine_class_base_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    /* compat_props can't be simply memcpy()ed */
+    mc->compat_props = g_list_copy(mc->compat_props);
+}
+
 static const TypeInfo machine_info = {
     .name = TYPE_MACHINE,
     .parent = TYPE_OBJECT,
     .abstract = true,
     .class_size = sizeof(MachineClass),
     .instance_size = sizeof(MachineState),
+    .class_base_init = machine_class_base_init,
     .instance_init = machine_initfn,
     .instance_finalize = machine_finalize,
 };
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 3d12560..4dd9faa 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -946,15 +946,6 @@ void qdev_prop_register_global(GlobalProperty *prop)
     QTAILQ_INSERT_TAIL(&global_props, prop, next);
 }
 
-void qdev_prop_register_global_list(GlobalProperty *props)
-{
-    int i;
-
-    for (i = 0; props[i].driver != NULL; i++) {
-        qdev_prop_register_global(props+i);
-    }
-}
-
 int qdev_prop_check_global(void)
 {
     GlobalProperty *prop;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 9e58982..301b127 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1556,8 +1556,10 @@ static void pc_generic_machine_class_init(ObjectClass *oc, void *data)
     mc->is_default = qm->is_default;
     mc->default_machine_opts = qm->default_machine_opts;
     mc->default_boot_order = qm->default_boot_order;
-    mc->compat_props = qm->compat_props;
     mc->hw_version = qm->hw_version;
+    if (qm->compat_props) {
+        machine_class_add_compat_props(mc, qm->compat_props);
+    }
 }
 
 void qemu_register_pc_machine(QEMUMachine *m)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 605a970..e9ddbc9 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -3,6 +3,8 @@
 #ifndef HW_BOARDS_H
 #define HW_BOARDS_H
 
+#include <glib.h>
+
 #include "qemu/typedefs.h"
 #include "sysemu/blockdev.h"
 #include "hw/qdev.h"
@@ -97,7 +99,7 @@ struct MachineClass {
     int is_default;
     const char *default_machine_opts;
     const char *default_boot_order;
-    GlobalProperty *compat_props;
+    GList *compat_props;
     const char *hw_version;
 
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
@@ -105,6 +107,21 @@ struct MachineClass {
 };
 
 /**
+ * machine_class_add_compat_props:
+ *
+ * Adds compat props from an array to the MachineClass compat_props list.
+ */
+void machine_class_add_compat_props(MachineClass *mc, GlobalProperty *props);
+
+/**
+ * machine_class_register_compat_props:
+ *
+ * Register the compat props that were added using
+ * machine_class_add_compat_props().
+ */
+void machine_class_register_compat_props(MachineClass *mc);
+
+/**
  * MachineState:
  */
 struct MachineState {
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 77fe3a1..4480b3e 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -176,7 +176,6 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 
 void qdev_prop_register_global(GlobalProperty *prop);
-void qdev_prop_register_global_list(GlobalProperty *props);
 int qdev_prop_check_global(void);
 void qdev_prop_set_globals(DeviceState *dev, Error **errp);
 void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
diff --git a/vl.c b/vl.c
index 1dd12a8..140fea4 100644
--- a/vl.c
+++ b/vl.c
@@ -1587,8 +1587,10 @@ static void machine_class_init(ObjectClass *oc, void *data)
     mc->is_default = qm->is_default;
     mc->default_machine_opts = qm->default_machine_opts;
     mc->default_boot_order = qm->default_boot_order;
-    mc->compat_props = qm->compat_props;
     mc->hw_version = qm->hw_version;
+    if (qm->compat_props) {
+        machine_class_add_compat_props(mc, qm->compat_props);
+    }
 }
 
 int qemu_register_machine(QEMUMachine *m)
@@ -4410,9 +4412,7 @@ int main(int argc, char **argv, char **envp)
             exit (i == 1 ? 1 : 0);
     }
 
-    if (machine_class->compat_props) {
-        qdev_prop_register_global_list(machine_class->compat_props);
-    }
+    machine_class_register_compat_props(machine_class);
     qemu_add_globals();
 
     qdev_machine_init();
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 11/33] pc: Register machine classes directly instead of using QEMUMachine
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (9 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 10/33] machine: Make compat_props a linked list Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 12/33] pc: Eliminate pc_common_machine_options() Eduardo Habkost
                   ` (21 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

This is a (mostly) blind and mechanical conversion of the PC QEMUMachine
definitions to corresponding class registration code.

Existing duplication and unnecessary complexity on macro/function reuse
is being kept, to keep the conversion simple to review. The complexity
and duplication will be gradually removed by the next patches.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
---
Changes v1 -> v2:
 * Remove unused PC_DEFAULT_MACHINE_OPTIONS macro leftover
 * Use machine_class_register_global_props_array()
 * Rebase on top of Michael's pci tree
 * Eliminate qemu_register_pc_machine(), as it is not needed anymore
Changes v2 -> v3:
 * Make static TypeInfo structs const
   Suggested-by: Andreas Färber <afaerber@suse.de>
---
 hw/i386/pc.c         |  44 -----
 hw/i386/pc_piix.c    | 473 +++++++++++++++++++++++++++++++++++----------------
 hw/i386/pc_q35.c     | 171 +++++++++++++------
 include/hw/i386/pc.h |  17 +-
 4 files changed, 448 insertions(+), 257 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 301b127..e56716f 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1532,50 +1532,6 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
     }
 }
 
-static void pc_generic_machine_class_init(ObjectClass *oc, void *data)
-{
-    MachineClass *mc = MACHINE_CLASS(oc);
-    QEMUMachine *qm = data;
-
-    mc->name = qm->name;
-    mc->alias = qm->alias;
-    mc->desc = qm->desc;
-    mc->init = qm->init;
-    mc->reset = qm->reset;
-    mc->hot_add_cpu = qm->hot_add_cpu;
-    mc->kvm_type = qm->kvm_type;
-    mc->block_default_type = qm->block_default_type;
-    mc->max_cpus = qm->max_cpus;
-    mc->no_serial = qm->no_serial;
-    mc->no_parallel = qm->no_parallel;
-    mc->use_virtcon = qm->use_virtcon;
-    mc->use_sclp = qm->use_sclp;
-    mc->no_floppy = qm->no_floppy;
-    mc->no_cdrom = qm->no_cdrom;
-    mc->no_sdcard = qm->no_sdcard;
-    mc->is_default = qm->is_default;
-    mc->default_machine_opts = qm->default_machine_opts;
-    mc->default_boot_order = qm->default_boot_order;
-    mc->hw_version = qm->hw_version;
-    if (qm->compat_props) {
-        machine_class_add_compat_props(mc, qm->compat_props);
-    }
-}
-
-void qemu_register_pc_machine(QEMUMachine *m)
-{
-    char *name = g_strconcat(m->name, TYPE_MACHINE_SUFFIX, NULL);
-    TypeInfo ti = {
-        .name       = name,
-        .parent     = TYPE_PC_MACHINE,
-        .class_init = pc_generic_machine_class_init,
-        .class_data = (void *)m,
-    };
-
-    type_register(&ti);
-    g_free(name);
-}
-
 static void pc_dimm_plug(HotplugHandler *hotplug_dev,
                          DeviceState *dev, Error **errp)
 {
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 1127c54..a2ff925 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -452,81 +452,140 @@ static void pc_xen_hvm_init(MachineState *machine)
 }
 #endif
 
-#define PC_I440FX_MACHINE_OPTIONS \
-    PC_DEFAULT_MACHINE_OPTIONS, \
-    .desc = "Standard PC (i440FX + PIIX, 1996)", \
-    .hot_add_cpu = pc_hot_add_cpu
-
-#define PC_I440FX_2_1_MACHINE_OPTIONS                           \
-    PC_I440FX_MACHINE_OPTIONS,                                  \
-    .default_machine_opts = "firmware=bios-256k.bin"
-
-static QEMUMachine pc_i440fx_machine_v2_1 = {
-    PC_I440FX_2_1_MACHINE_OPTIONS,
-    .name = "pc-i440fx-2.1",
-    .alias = "pc",
-    .init = pc_init1,
-    .is_default = 1,
+static void pc_i440fx_machine_options(MachineClass *mc)
+{
+    pc_default_machine_options(mc);
+    mc->desc = "Standard PC (i440FX + PIIX, 1996)";
+    mc->hot_add_cpu = pc_hot_add_cpu;
+}
+
+static void pc_i440fx_2_1_machine_options(MachineClass *mc)
+{
+    pc_i440fx_machine_options(mc);
+    mc->default_machine_opts = "firmware=bios-256k.bin";
+}
+
+static void pc_i440fx_machine_v2_1_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    pc_i440fx_2_1_machine_options(mc);
+    mc->alias = "pc";
+    mc->init = pc_init1;
+    mc->is_default = 1;
+    mc->name = "pc-i440fx-2.1";
+}
+
+static const TypeInfo pc_i440fx_machine_v2_1_type_info = {
+    .name = "pc-i440fx-2.1" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_i440fx_machine_v2_1_class_init,
 };
 
-#define PC_I440FX_2_0_MACHINE_OPTIONS PC_I440FX_2_1_MACHINE_OPTIONS
+#define pc_i440fx_2_0_machine_options pc_i440fx_2_1_machine_options
 
-static QEMUMachine pc_i440fx_machine_v2_0 = {
-    PC_I440FX_2_0_MACHINE_OPTIONS,
-    .name = "pc-i440fx-2.0",
-    .init = pc_init_pci_2_0,
-    .compat_props = (GlobalProperty[]) {
+static void pc_i440fx_machine_v2_0_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_2_0,
         { /* end of list */ }
-    },
+    };
+    pc_i440fx_2_0_machine_options(mc);
+    mc->init = pc_init_pci_2_0;
+    mc->name = "pc-i440fx-2.0";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_i440fx_machine_v2_0_type_info = {
+    .name = "pc-i440fx-2.0" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_i440fx_machine_v2_0_class_init,
 };
 
-#define PC_I440FX_1_7_MACHINE_OPTIONS PC_I440FX_MACHINE_OPTIONS
+#define pc_i440fx_1_7_machine_options pc_i440fx_machine_options
 
-static QEMUMachine pc_i440fx_machine_v1_7 = {
-    PC_I440FX_1_7_MACHINE_OPTIONS,
-    .name = "pc-i440fx-1.7",
-    .init = pc_init_pci_1_7,
-    .compat_props = (GlobalProperty[]) {
+static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_7,
         { /* end of list */ }
-    },
+    };
+    pc_i440fx_1_7_machine_options(mc);
+    mc->init = pc_init_pci_1_7;
+    mc->name = "pc-i440fx-1.7";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_i440fx_machine_v1_7_type_info = {
+    .name = "pc-i440fx-1.7" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_i440fx_machine_v1_7_class_init,
 };
 
-#define PC_I440FX_1_6_MACHINE_OPTIONS PC_I440FX_MACHINE_OPTIONS
+#define pc_i440fx_1_6_machine_options pc_i440fx_machine_options
 
-static QEMUMachine pc_i440fx_machine_v1_6 = {
-    PC_I440FX_1_6_MACHINE_OPTIONS,
-    .name = "pc-i440fx-1.6",
-    .init = pc_init_pci_1_6,
-    .compat_props = (GlobalProperty[]) {
+static void pc_i440fx_machine_v1_6_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_6,
         { /* end of list */ }
-    },
+    };
+    pc_i440fx_1_6_machine_options(mc);
+    mc->init = pc_init_pci_1_6;
+    mc->name = "pc-i440fx-1.6";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_i440fx_machine_v1_6_type_info = {
+    .name = "pc-i440fx-1.6" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_i440fx_machine_v1_6_class_init,
 };
 
-static QEMUMachine pc_i440fx_machine_v1_5 = {
-    PC_I440FX_1_6_MACHINE_OPTIONS,
-    .name = "pc-i440fx-1.5",
-    .init = pc_init_pci_1_5,
-    .compat_props = (GlobalProperty[]) {
+static void pc_i440fx_machine_v1_5_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_5,
         { /* end of list */ }
-    },
+    };
+    pc_i440fx_1_6_machine_options(mc);
+    mc->init = pc_init_pci_1_5;
+    mc->name = "pc-i440fx-1.5";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_i440fx_machine_v1_5_type_info = {
+    .name = "pc-i440fx-1.5" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_i440fx_machine_v1_5_class_init,
 };
 
-#define PC_I440FX_1_4_MACHINE_OPTIONS \
-    PC_I440FX_1_6_MACHINE_OPTIONS, \
-    .hot_add_cpu = NULL
+static void pc_i440fx_1_4_machine_options(MachineClass *mc)
+{
+    pc_i440fx_1_6_machine_options(mc);
+    mc->hot_add_cpu = NULL;
+}
 
-static QEMUMachine pc_i440fx_machine_v1_4 = {
-    PC_I440FX_1_4_MACHINE_OPTIONS,
-    .name = "pc-i440fx-1.4",
-    .init = pc_init_pci_1_4,
-    .compat_props = (GlobalProperty[]) {
+static void pc_i440fx_machine_v1_4_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_4,
         { /* end of list */ }
-    },
+    };
+    pc_i440fx_1_4_machine_options(mc);
+    mc->init = pc_init_pci_1_4;
+    mc->name = "pc-i440fx-1.4";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_i440fx_machine_v1_4_type_info = {
+    .name = "pc-i440fx-1.4" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_i440fx_machine_v1_4_class_init,
 };
 
 #define PC_COMPAT_1_3 \
@@ -549,14 +608,23 @@ static QEMUMachine pc_i440fx_machine_v1_4 = {
             .value    = "off",\
         }
 
-static QEMUMachine pc_machine_v1_3 = {
-    PC_I440FX_1_4_MACHINE_OPTIONS,
-    .name = "pc-1.3",
-    .init = pc_init_pci_1_3,
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v1_3_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_3,
         { /* end of list */ }
-    },
+    };
+    pc_i440fx_1_4_machine_options(mc);
+    mc->init = pc_init_pci_1_3;
+    mc->name = "pc-1.3";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v1_3_type_info = {
+    .name = "pc-1.3" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v1_3_class_init,
 };
 
 #define PC_COMPAT_1_2 \
@@ -587,17 +655,28 @@ static QEMUMachine pc_machine_v1_3 = {
             .value    = "off",\
         }
 
-#define PC_I440FX_1_2_MACHINE_OPTIONS \
-    PC_I440FX_1_4_MACHINE_OPTIONS, \
-    .init = pc_init_pci_1_2
+static void pc_i440fx_1_2_machine_options(MachineClass *mc)
+{
+    pc_i440fx_1_4_machine_options(mc);
+    mc->init = pc_init_pci_1_2;
+}
 
-static QEMUMachine pc_machine_v1_2 = {
-    PC_I440FX_1_2_MACHINE_OPTIONS,
-    .name = "pc-1.2",
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v1_2_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_2,
         { /* end of list */ }
-    },
+    };
+    pc_i440fx_1_2_machine_options(mc);
+    mc->name = "pc-1.2";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v1_2_type_info = {
+    .name = "pc-1.2" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v1_2_class_init,
 };
 
 #define PC_COMPAT_1_1 \
@@ -632,13 +711,22 @@ static QEMUMachine pc_machine_v1_2 = {
             .value    = "off",\
         }
 
-static QEMUMachine pc_machine_v1_1 = {
-    PC_I440FX_1_2_MACHINE_OPTIONS,
-    .name = "pc-1.1",
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v1_1_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_1,
         { /* end of list */ }
-    },
+    };
+    pc_i440fx_1_2_machine_options(mc);
+    mc->name = "pc-1.1";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v1_1_type_info = {
+    .name = "pc-1.1" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v1_1_class_init,
 };
 
 #define PC_COMPAT_1_0 \
@@ -661,27 +749,45 @@ static QEMUMachine pc_machine_v1_1 = {
             .value    = "no",\
         }
 
-static QEMUMachine pc_machine_v1_0 = {
-    PC_I440FX_1_2_MACHINE_OPTIONS,
-    .name = "pc-1.0",
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v1_0_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_0,
         { /* end of list */ }
-    },
-    .hw_version = "1.0",
+    };
+    pc_i440fx_1_2_machine_options(mc);
+    mc->hw_version = "1.0";
+    mc->name = "pc-1.0";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v1_0_type_info = {
+    .name = "pc-1.0" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v1_0_class_init,
 };
 
 #define PC_COMPAT_0_15 \
         PC_COMPAT_1_0
 
-static QEMUMachine pc_machine_v0_15 = {
-    PC_I440FX_1_2_MACHINE_OPTIONS,
-    .name = "pc-0.15",
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v0_15_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_0_15,
         { /* end of list */ }
-    },
-    .hw_version = "0.15",
+    };
+    pc_i440fx_1_2_machine_options(mc);
+    mc->hw_version = "0.15";
+    mc->name = "pc-0.15";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v0_15_type_info = {
+    .name = "pc-0.15" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v0_15_class_init,
 };
 
 #define PC_COMPAT_0_14 \
@@ -712,14 +818,23 @@ static QEMUMachine pc_machine_v0_15 = {
             .value    = stringify(2),\
         }
 
-static QEMUMachine pc_machine_v0_14 = {
-    PC_I440FX_1_2_MACHINE_OPTIONS,
-    .name = "pc-0.14",
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v0_14_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_0_14, 
         { /* end of list */ }
-    },
-    .hw_version = "0.14",
+    };
+    pc_i440fx_1_2_machine_options(mc);
+    mc->hw_version = "0.14";
+    mc->name = "pc-0.14";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v0_14_type_info = {
+    .name = "pc-0.14" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v0_14_class_init,
 };
 
 #define PC_COMPAT_0_13 \
@@ -746,18 +861,29 @@ static QEMUMachine pc_machine_v0_14 = {
             .value    = stringify(0),\
         }
 
-#define PC_I440FX_0_13_MACHINE_OPTIONS \
-    PC_I440FX_1_2_MACHINE_OPTIONS, \
-    .init = pc_init_pci_no_kvmclock
+static void pc_i440fx_0_13_machine_options(MachineClass *mc)
+{
+    pc_i440fx_1_2_machine_options(mc);
+    mc->init = pc_init_pci_no_kvmclock;
+}
 
-static QEMUMachine pc_machine_v0_13 = {
-    PC_I440FX_0_13_MACHINE_OPTIONS,
-    .name = "pc-0.13",
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v0_13_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_0_13,
         { /* end of list */ }
-    },
-    .hw_version = "0.13",
+    };
+    pc_i440fx_0_13_machine_options(mc);
+    mc->hw_version = "0.13";
+    mc->name = "pc-0.13";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v0_13_type_info = {
+    .name = "pc-0.13" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v0_13_class_init,
 };
 
 #define PC_COMPAT_0_12 \
@@ -784,14 +910,23 @@ static QEMUMachine pc_machine_v0_13 = {
             .value    = "1",\
         }
 
-static QEMUMachine pc_machine_v0_12 = {
-    PC_I440FX_0_13_MACHINE_OPTIONS,
-    .name = "pc-0.12",
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v0_12_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_0_12,
         { /* end of list */ }
-    },
-    .hw_version = "0.12",
+    };
+    pc_i440fx_0_13_machine_options(mc);
+    mc->hw_version = "0.12";
+    mc->name = "pc-0.12";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v0_12_type_info = {
+    .name = "pc-0.12" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v0_12_class_init,
 };
 
 #define PC_COMPAT_0_11 \
@@ -814,20 +949,29 @@ static QEMUMachine pc_machine_v0_12 = {
             .value    = "0.11",\
         }
 
-static QEMUMachine pc_machine_v0_11 = {
-    PC_I440FX_0_13_MACHINE_OPTIONS,
-    .name = "pc-0.11",
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v0_11_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_0_11,
         { /* end of list */ }
-    },
-    .hw_version = "0.11",
+    };
+    pc_i440fx_0_13_machine_options(mc);
+    mc->hw_version = "0.11";
+    mc->name = "pc-0.11";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v0_11_type_info = {
+    .name = "pc-0.11" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v0_11_class_init,
 };
 
-static QEMUMachine pc_machine_v0_10 = {
-    PC_I440FX_0_13_MACHINE_OPTIONS,
-    .name = "pc-0.10",
-    .compat_props = (GlobalProperty[]) {
+static void pc_machine_v0_10_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_0_11,
         {
             .driver   = "virtio-blk-pci",
@@ -851,31 +995,44 @@ static QEMUMachine pc_machine_v0_10 = {
             .value    = "0.10",
         },
         { /* end of list */ }
-    },
-    .hw_version = "0.10",
+    };
+    pc_i440fx_0_13_machine_options(mc);
+    mc->hw_version = "0.10";
+    mc->name = "pc-0.10";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo pc_machine_v0_10_type_info = {
+    .name = "pc-0.10" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_machine_v0_10_class_init,
 };
 
-static QEMUMachine isapc_machine = {
-    PC_COMMON_MACHINE_OPTIONS,
-    .name = "isapc",
-    .desc = "ISA-only PC",
-    .init = pc_init_isa,
-    .max_cpus = 1,
-    .compat_props = (GlobalProperty[]) {
+static void isapc_machine_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         { /* end of list */ }
-    },
+    };
+    pc_common_machine_options(mc);
+    mc->desc = "ISA-only PC";
+    mc->init = pc_init_isa;
+    mc->max_cpus = 1;
+    mc->name = "isapc";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo isapc_machine_type_info = {
+    .name = "isapc" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = isapc_machine_class_init,
 };
 
 #ifdef CONFIG_XEN
-static QEMUMachine xenfv_machine = {
-    PC_COMMON_MACHINE_OPTIONS,
-    .name = "xenfv",
-    .desc = "Xen Fully-virtualized PC",
-    .init = pc_xen_hvm_init,
-    .max_cpus = HVM_MAX_VCPUS,
-    .default_machine_opts = "accel=xen",
-    .hot_add_cpu = pc_hot_add_cpu,
-    .compat_props = (GlobalProperty[]) {
+static void xenfv_machine_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         /* xenfv has no fwcfg and so does not load acpi from QEMU.
          * as such new acpi features don't work.
          */
@@ -885,31 +1042,45 @@ static QEMUMachine xenfv_machine = {
             .value    = "off",
         },
         { /* end of list */ }
-    },
+    };
+    pc_common_machine_options(mc);
+    mc->desc = "Xen Fully-virtualized PC";
+    mc->init = pc_xen_hvm_init;
+    mc->max_cpus = HVM_MAX_VCPUS;
+    mc->default_machine_opts = "accel=xen";
+    mc->hot_add_cpu = pc_hot_add_cpu;
+    mc->name = "xenfv";
+    machine_class_add_compat_props(mc, compat_props);
+}
+
+static const TypeInfo xenfv_machine_type_info = {
+    .name = "xenfv" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = xenfv_machine_class_init,
 };
 #endif
 
 static void pc_machine_init(void)
 {
-    qemu_register_pc_machine(&pc_i440fx_machine_v2_1);
-    qemu_register_pc_machine(&pc_i440fx_machine_v2_0);
-    qemu_register_pc_machine(&pc_i440fx_machine_v1_7);
-    qemu_register_pc_machine(&pc_i440fx_machine_v1_6);
-    qemu_register_pc_machine(&pc_i440fx_machine_v1_5);
-    qemu_register_pc_machine(&pc_i440fx_machine_v1_4);
-    qemu_register_pc_machine(&pc_machine_v1_3);
-    qemu_register_pc_machine(&pc_machine_v1_2);
-    qemu_register_pc_machine(&pc_machine_v1_1);
-    qemu_register_pc_machine(&pc_machine_v1_0);
-    qemu_register_pc_machine(&pc_machine_v0_15);
-    qemu_register_pc_machine(&pc_machine_v0_14);
-    qemu_register_pc_machine(&pc_machine_v0_13);
-    qemu_register_pc_machine(&pc_machine_v0_12);
-    qemu_register_pc_machine(&pc_machine_v0_11);
-    qemu_register_pc_machine(&pc_machine_v0_10);
-    qemu_register_pc_machine(&isapc_machine);
+    type_register_static(&pc_i440fx_machine_v2_1_type_info);
+    type_register_static(&pc_i440fx_machine_v2_0_type_info);
+    type_register_static(&pc_i440fx_machine_v1_7_type_info);
+    type_register_static(&pc_i440fx_machine_v1_6_type_info);
+    type_register_static(&pc_i440fx_machine_v1_5_type_info);
+    type_register_static(&pc_i440fx_machine_v1_4_type_info);
+    type_register_static(&pc_machine_v1_3_type_info);
+    type_register_static(&pc_machine_v1_2_type_info);
+    type_register_static(&pc_machine_v1_1_type_info);
+    type_register_static(&pc_machine_v1_0_type_info);
+    type_register_static(&pc_machine_v0_15_type_info);
+    type_register_static(&pc_machine_v0_14_type_info);
+    type_register_static(&pc_machine_v0_13_type_info);
+    type_register_static(&pc_machine_v0_12_type_info);
+    type_register_static(&pc_machine_v0_11_type_info);
+    type_register_static(&pc_machine_v0_10_type_info);
+    type_register_static(&isapc_machine_type_info);
 #ifdef CONFIG_XEN
-    qemu_register_pc_machine(&xenfv_machine);
+    type_register_static(&xenfv_machine_type_info);
 #endif
 }
 
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 0abd56c..3b923b7 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -341,90 +341,149 @@ static void pc_q35_init_1_4(MachineState *machine)
     pc_q35_init(machine);
 }
 
-#define PC_Q35_MACHINE_OPTIONS \
-    PC_DEFAULT_MACHINE_OPTIONS, \
-    .desc = "Standard PC (Q35 + ICH9, 2009)", \
-    .hot_add_cpu = pc_hot_add_cpu
-
-#define PC_Q35_2_1_MACHINE_OPTIONS                      \
-    PC_Q35_MACHINE_OPTIONS,                             \
-    .default_machine_opts = "firmware=bios-256k.bin"
-
-static QEMUMachine pc_q35_machine_v2_1 = {
-    PC_Q35_2_1_MACHINE_OPTIONS,
-    .name = "pc-q35-2.1",
-    .alias = "q35",
-    .init = pc_q35_init,
+static void pc_q35_machine_options(MachineClass *mc)
+{
+    pc_default_machine_options(mc);
+    mc->desc = "Standard PC (Q35 + ICH9, 2009)";
+    mc->hot_add_cpu = pc_hot_add_cpu;
+}
+
+static void pc_q35_2_1_machine_options(MachineClass *mc)
+{
+    pc_q35_machine_options(mc);
+    mc->default_machine_opts = "firmware=bios-256k.bin";
+}
+
+static void pc_q35_machine_v2_1_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    pc_q35_2_1_machine_options(mc);
+    mc->alias = "q35";
+    mc->init = pc_q35_init;
+    mc->name = "pc-q35-2.1";
+}
+
+static TypeInfo pc_q35_machine_v2_1_type_info = {
+    .name = "pc-q35-2.1" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_q35_machine_v2_1_class_init,
 };
 
-#define PC_Q35_2_0_MACHINE_OPTIONS PC_Q35_2_1_MACHINE_OPTIONS
+#define pc_q35_2_0_machine_options pc_q35_2_1_machine_options
 
-static QEMUMachine pc_q35_machine_v2_0 = {
-    PC_Q35_2_0_MACHINE_OPTIONS,
-    .name = "pc-q35-2.0",
-    .init = pc_q35_init_2_0,
-    .compat_props = (GlobalProperty[]) {
+static void pc_q35_machine_v2_0_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_2_0,
         { /* end of list */ }
-    },
+    };
+    pc_q35_2_0_machine_options(mc);
+    mc->init = pc_q35_init_2_0;
+    machine_class_add_compat_props(mc, compat_props);
+    mc->name = "pc-q35-2.0";
+}
+
+static TypeInfo pc_q35_machine_v2_0_type_info = {
+    .name = "pc-q35-2.0" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_q35_machine_v2_0_class_init,
 };
 
-#define PC_Q35_1_7_MACHINE_OPTIONS PC_Q35_MACHINE_OPTIONS
+#define pc_q35_1_7_machine_options pc_q35_machine_options
 
-static QEMUMachine pc_q35_machine_v1_7 = {
-    PC_Q35_1_7_MACHINE_OPTIONS,
-    .name = "pc-q35-1.7",
-    .init = pc_q35_init_1_7,
-    .compat_props = (GlobalProperty[]) {
+static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_7,
         { /* end of list */ }
-    },
+    };
+    pc_q35_1_7_machine_options(mc);
+    mc->init = pc_q35_init_1_7;
+    machine_class_add_compat_props(mc, compat_props);
+    mc->name = "pc-q35-1.7";
+}
+
+static TypeInfo pc_q35_machine_v1_7_type_info = {
+    .name = "pc-q35-1.7" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_q35_machine_v1_7_class_init,
 };
 
-#define PC_Q35_1_6_MACHINE_OPTIONS PC_Q35_MACHINE_OPTIONS
+#define pc_q35_1_6_machine_options pc_q35_machine_options
 
-static QEMUMachine pc_q35_machine_v1_6 = {
-    PC_Q35_1_6_MACHINE_OPTIONS,
-    .name = "pc-q35-1.6",
-    .init = pc_q35_init_1_6,
-    .compat_props = (GlobalProperty[]) {
+static void pc_q35_machine_v1_6_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_6,
         { /* end of list */ }
-    },
+    };
+    pc_q35_1_6_machine_options(mc);
+    mc->init = pc_q35_init_1_6;
+    machine_class_add_compat_props(mc, compat_props);
+    mc->name = "pc-q35-1.6";
+}
+
+static TypeInfo pc_q35_machine_v1_6_type_info = {
+    .name = "pc-q35-1.6" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_q35_machine_v1_6_class_init,
 };
 
-static QEMUMachine pc_q35_machine_v1_5 = {
-    PC_Q35_1_6_MACHINE_OPTIONS,
-    .name = "pc-q35-1.5",
-    .init = pc_q35_init_1_5,
-    .compat_props = (GlobalProperty[]) {
+static void pc_q35_machine_v1_5_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_5,
         { /* end of list */ }
-    },
+    };
+    pc_q35_1_6_machine_options(mc);
+    mc->init = pc_q35_init_1_5;
+    machine_class_add_compat_props(mc, compat_props);
+    mc->name = "pc-q35-1.5";
+}
+
+static TypeInfo pc_q35_machine_v1_5_type_info = {
+    .name = "pc-q35-1.5" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_q35_machine_v1_5_class_init,
 };
 
-#define PC_Q35_1_4_MACHINE_OPTIONS \
-    PC_Q35_1_6_MACHINE_OPTIONS, \
-    .hot_add_cpu = NULL
+static void pc_q35_1_4_machine_options(MachineClass *mc)
+{
+    pc_q35_1_6_machine_options(mc);
+    mc->hot_add_cpu = NULL;
+}
 
-static QEMUMachine pc_q35_machine_v1_4 = {
-    PC_Q35_1_4_MACHINE_OPTIONS,
-    .name = "pc-q35-1.4",
-    .init = pc_q35_init_1_4,
-    .compat_props = (GlobalProperty[]) {
+static void pc_q35_machine_v1_4_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
         PC_COMPAT_1_4,
         { /* end of list */ }
-    },
+    };
+    pc_q35_1_4_machine_options(mc);
+    mc->init = pc_q35_init_1_4;
+    machine_class_add_compat_props(mc, compat_props);
+    mc->name = "pc-q35-1.4";
+}
+
+static TypeInfo pc_q35_machine_v1_4_type_info = {
+    .name = "pc-q35-1.4" TYPE_MACHINE_SUFFIX,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_q35_machine_v1_4_class_init,
 };
 
 static void pc_q35_machine_init(void)
 {
-    qemu_register_pc_machine(&pc_q35_machine_v2_1);
-    qemu_register_pc_machine(&pc_q35_machine_v2_0);
-    qemu_register_pc_machine(&pc_q35_machine_v1_7);
-    qemu_register_pc_machine(&pc_q35_machine_v1_6);
-    qemu_register_pc_machine(&pc_q35_machine_v1_5);
-    qemu_register_pc_machine(&pc_q35_machine_v1_4);
+    type_register_static(&pc_q35_machine_v2_1_type_info);
+    type_register_static(&pc_q35_machine_v2_0_type_info);
+    type_register_static(&pc_q35_machine_v1_7_type_info);
+    type_register_static(&pc_q35_machine_v1_6_type_info);
+    type_register_static(&pc_q35_machine_v1_5_type_info);
+    type_register_static(&pc_q35_machine_v1_4_type_info);
 }
 
 machine_init(pc_q35_machine_init);
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 9fb7144..46bbf48 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -8,6 +8,7 @@
 #include "hw/block/fdc.h"
 #include "net/net.h"
 #include "hw/i386/ioapic.h"
+#include "hw/boards.h"
 
 #include "qemu/range.h"
 #include "qemu/bitmap.h"
@@ -505,12 +506,16 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
             .value    = stringify(0),\
         }
 
-#define PC_COMMON_MACHINE_OPTIONS \
-    .default_boot_order = "cad"
+static inline void pc_common_machine_options(MachineClass *mc)
+{
+    mc->default_boot_order = "cad";
+}
 
-#define PC_DEFAULT_MACHINE_OPTIONS \
-    PC_COMMON_MACHINE_OPTIONS, \
-    .hot_add_cpu = pc_hot_add_cpu, \
-    .max_cpus = 255
+static inline void pc_default_machine_options(MachineClass *mc)
+{
+    pc_common_machine_options(mc);
+    mc->hot_add_cpu = pc_hot_add_cpu;
+    mc->max_cpus = 255;
+}
 
 #endif
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 12/33] pc: Eliminate pc_common_machine_options()
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (10 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 11/33] pc: Register machine classes directly instead of using QEMUMachine Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 13/33] pc: Eliminate pc_default_machine_options() Eduardo Habkost
                   ` (20 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

The TYPE_PC_MACHINE parent class can initialize the common options for
all PC machines.

Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc.c         | 1 +
 hw/i386/pc_piix.c    | 2 --
 include/hw/i386/pc.h | 6 ------
 3 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index e56716f..f61eade 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1688,6 +1688,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
 
     pcmc->get_hotplug_handler = mc->get_hotplug_handler;
     mc->get_hotplug_handler = pc_get_hotpug_handler;
+    mc->default_boot_order = "cad";
     hc->plug = pc_machine_device_plug_cb;
 }
 
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index a2ff925..4bc2d8b 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -1014,7 +1014,6 @@ static void isapc_machine_class_init(ObjectClass *oc, void *data)
     static GlobalProperty compat_props[] = {
         { /* end of list */ }
     };
-    pc_common_machine_options(mc);
     mc->desc = "ISA-only PC";
     mc->init = pc_init_isa;
     mc->max_cpus = 1;
@@ -1043,7 +1042,6 @@ static void xenfv_machine_class_init(ObjectClass *oc, void *data)
         },
         { /* end of list */ }
     };
-    pc_common_machine_options(mc);
     mc->desc = "Xen Fully-virtualized PC";
     mc->init = pc_xen_hvm_init;
     mc->max_cpus = HVM_MAX_VCPUS;
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 46bbf48..b3dd3ed 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -506,14 +506,8 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
             .value    = stringify(0),\
         }
 
-static inline void pc_common_machine_options(MachineClass *mc)
-{
-    mc->default_boot_order = "cad";
-}
-
 static inline void pc_default_machine_options(MachineClass *mc)
 {
-    pc_common_machine_options(mc);
     mc->hot_add_cpu = pc_hot_add_cpu;
     mc->max_cpus = 255;
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 13/33] pc: Eliminate pc_default_machine_options()
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (11 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 12/33] pc: Eliminate pc_common_machine_options() Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 14/33] piix: Eliminate pc_i440fx_machine_options() Eduardo Habkost
                   ` (19 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

The only PC machines that didn't call pc_default_machine_options() were
isaps and xenfv. Both were already overwriting max_cpus, and only isapc
was not overwriting hot_add_cpu.

After making isapc set hot_add_cpu to NULL, we can move the
pc_default_machine_options() code the PC common class_init.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc.c         | 2 ++
 hw/i386/pc_piix.c    | 2 +-
 hw/i386/pc_q35.c     | 1 -
 include/hw/i386/pc.h | 6 ------
 4 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index f61eade..53c39cb 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1689,6 +1689,8 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     pcmc->get_hotplug_handler = mc->get_hotplug_handler;
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     mc->default_boot_order = "cad";
+    mc->hot_add_cpu = pc_hot_add_cpu;
+    mc->max_cpus = 255;
     hc->plug = pc_machine_device_plug_cb;
 }
 
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 4bc2d8b..5688b10 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -454,7 +454,6 @@ static void pc_xen_hvm_init(MachineState *machine)
 
 static void pc_i440fx_machine_options(MachineClass *mc)
 {
-    pc_default_machine_options(mc);
     mc->desc = "Standard PC (i440FX + PIIX, 1996)";
     mc->hot_add_cpu = pc_hot_add_cpu;
 }
@@ -1017,6 +1016,7 @@ static void isapc_machine_class_init(ObjectClass *oc, void *data)
     mc->desc = "ISA-only PC";
     mc->init = pc_init_isa;
     mc->max_cpus = 1;
+    mc->hot_add_cpu = NULL;
     mc->name = "isapc";
     machine_class_add_compat_props(mc, compat_props);
 }
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 3b923b7..0074640 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -343,7 +343,6 @@ static void pc_q35_init_1_4(MachineState *machine)
 
 static void pc_q35_machine_options(MachineClass *mc)
 {
-    pc_default_machine_options(mc);
     mc->desc = "Standard PC (Q35 + ICH9, 2009)";
     mc->hot_add_cpu = pc_hot_add_cpu;
 }
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index b3dd3ed..fa4cf3c 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -506,10 +506,4 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
             .value    = stringify(0),\
         }
 
-static inline void pc_default_machine_options(MachineClass *mc)
-{
-    mc->hot_add_cpu = pc_hot_add_cpu;
-    mc->max_cpus = 255;
-}
-
 #endif
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 14/33] piix: Eliminate pc_i440fx_machine_options()
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (12 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 13/33] pc: Eliminate pc_default_machine_options() Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 15/33] q35: Eliminate pc_q35_machine_options() Eduardo Habkost
                   ` (18 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Instead of calling it on every i440fx class_init function, just register
a common parent class for all i440fx machine-types.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c | 55 +++++++++++++++++++++++++++++--------------------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 5688b10..75c05bb 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -452,15 +452,25 @@ static void pc_xen_hvm_init(MachineState *machine)
 }
 #endif
 
-static void pc_i440fx_machine_options(MachineClass *mc)
+static void pc_i440fx_machine_class_init(ObjectClass *oc, void *data)
 {
+    MachineClass *mc = MACHINE_CLASS(oc);
     mc->desc = "Standard PC (i440FX + PIIX, 1996)";
     mc->hot_add_cpu = pc_hot_add_cpu;
 }
 
+#define TYPE_PC_I440FX_MACHINE "pc-i440fx" TYPE_MACHINE_SUFFIX
+
+static TypeInfo pc_i440fx_machine_type_info = {
+    .name = TYPE_PC_I440FX_MACHINE,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_i440fx_machine_class_init,
+    .abstract = true,
+};
+
+
 static void pc_i440fx_2_1_machine_options(MachineClass *mc)
 {
-    pc_i440fx_machine_options(mc);
     mc->default_machine_opts = "firmware=bios-256k.bin";
 }
 
@@ -476,7 +486,7 @@ static void pc_i440fx_machine_v2_1_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_i440fx_machine_v2_1_type_info = {
     .name = "pc-i440fx-2.1" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_i440fx_machine_v2_1_class_init,
 };
 
@@ -497,12 +507,10 @@ static void pc_i440fx_machine_v2_0_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_i440fx_machine_v2_0_type_info = {
     .name = "pc-i440fx-2.0" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_i440fx_machine_v2_0_class_init,
 };
 
-#define pc_i440fx_1_7_machine_options pc_i440fx_machine_options
-
 static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -510,7 +518,6 @@ static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_7,
         { /* end of list */ }
     };
-    pc_i440fx_1_7_machine_options(mc);
     mc->init = pc_init_pci_1_7;
     mc->name = "pc-i440fx-1.7";
     machine_class_add_compat_props(mc, compat_props);
@@ -518,12 +525,10 @@ static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_i440fx_machine_v1_7_type_info = {
     .name = "pc-i440fx-1.7" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_i440fx_machine_v1_7_class_init,
 };
 
-#define pc_i440fx_1_6_machine_options pc_i440fx_machine_options
-
 static void pc_i440fx_machine_v1_6_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -531,7 +536,6 @@ static void pc_i440fx_machine_v1_6_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_6,
         { /* end of list */ }
     };
-    pc_i440fx_1_6_machine_options(mc);
     mc->init = pc_init_pci_1_6;
     mc->name = "pc-i440fx-1.6";
     machine_class_add_compat_props(mc, compat_props);
@@ -539,7 +543,7 @@ static void pc_i440fx_machine_v1_6_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_i440fx_machine_v1_6_type_info = {
     .name = "pc-i440fx-1.6" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_i440fx_machine_v1_6_class_init,
 };
 
@@ -550,7 +554,6 @@ static void pc_i440fx_machine_v1_5_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_5,
         { /* end of list */ }
     };
-    pc_i440fx_1_6_machine_options(mc);
     mc->init = pc_init_pci_1_5;
     mc->name = "pc-i440fx-1.5";
     machine_class_add_compat_props(mc, compat_props);
@@ -558,13 +561,12 @@ static void pc_i440fx_machine_v1_5_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_i440fx_machine_v1_5_type_info = {
     .name = "pc-i440fx-1.5" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_i440fx_machine_v1_5_class_init,
 };
 
 static void pc_i440fx_1_4_machine_options(MachineClass *mc)
 {
-    pc_i440fx_1_6_machine_options(mc);
     mc->hot_add_cpu = NULL;
 }
 
@@ -583,7 +585,7 @@ static void pc_i440fx_machine_v1_4_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_i440fx_machine_v1_4_type_info = {
     .name = "pc-i440fx-1.4" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_i440fx_machine_v1_4_class_init,
 };
 
@@ -622,7 +624,7 @@ static void pc_machine_v1_3_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v1_3_type_info = {
     .name = "pc-1.3" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v1_3_class_init,
 };
 
@@ -674,7 +676,7 @@ static void pc_machine_v1_2_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v1_2_type_info = {
     .name = "pc-1.2" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v1_2_class_init,
 };
 
@@ -724,7 +726,7 @@ static void pc_machine_v1_1_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v1_1_type_info = {
     .name = "pc-1.1" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v1_1_class_init,
 };
 
@@ -763,7 +765,7 @@ static void pc_machine_v1_0_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v1_0_type_info = {
     .name = "pc-1.0" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v1_0_class_init,
 };
 
@@ -785,7 +787,7 @@ static void pc_machine_v0_15_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v0_15_type_info = {
     .name = "pc-0.15" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v0_15_class_init,
 };
 
@@ -832,7 +834,7 @@ static void pc_machine_v0_14_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v0_14_type_info = {
     .name = "pc-0.14" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v0_14_class_init,
 };
 
@@ -881,7 +883,7 @@ static void pc_machine_v0_13_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v0_13_type_info = {
     .name = "pc-0.13" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v0_13_class_init,
 };
 
@@ -924,7 +926,7 @@ static void pc_machine_v0_12_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v0_12_type_info = {
     .name = "pc-0.12" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v0_12_class_init,
 };
 
@@ -963,7 +965,7 @@ static void pc_machine_v0_11_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v0_11_type_info = {
     .name = "pc-0.11" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v0_11_class_init,
 };
 
@@ -1003,7 +1005,7 @@ static void pc_machine_v0_10_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo pc_machine_v0_10_type_info = {
     .name = "pc-0.10" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_I440FX_MACHINE,
     .class_init = pc_machine_v0_10_class_init,
 };
 
@@ -1060,6 +1062,7 @@ static const TypeInfo xenfv_machine_type_info = {
 
 static void pc_machine_init(void)
 {
+    type_register_static(&pc_i440fx_machine_type_info);
     type_register_static(&pc_i440fx_machine_v2_1_type_info);
     type_register_static(&pc_i440fx_machine_v2_0_type_info);
     type_register_static(&pc_i440fx_machine_v1_7_type_info);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 15/33] q35: Eliminate pc_q35_machine_options()
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (13 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 14/33] piix: Eliminate pc_i440fx_machine_options() Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 16/33] q35: Eliminate pc_q35_1_4_machine_options() Eduardo Habkost
                   ` (17 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Instead of calling it on every q35 class_init function, just register a
common parent class for all q35 machine-types.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_q35.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 0074640..2aa1c43 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -341,15 +341,24 @@ static void pc_q35_init_1_4(MachineState *machine)
     pc_q35_init(machine);
 }
 
-static void pc_q35_machine_options(MachineClass *mc)
+static void pc_q35_machine_class_init(ObjectClass *oc, void *data)
 {
+    MachineClass *mc = MACHINE_CLASS(oc);
     mc->desc = "Standard PC (Q35 + ICH9, 2009)";
     mc->hot_add_cpu = pc_hot_add_cpu;
 }
 
+#define TYPE_PC_Q35_MACHINE "pc-q35" TYPE_MACHINE_SUFFIX
+
+static TypeInfo pc_q35_machine_type_info = {
+    .name = TYPE_PC_Q35_MACHINE,
+    .parent = TYPE_PC_MACHINE,
+    .class_init = pc_q35_machine_class_init,
+    .abstract = true,
+};
+
 static void pc_q35_2_1_machine_options(MachineClass *mc)
 {
-    pc_q35_machine_options(mc);
     mc->default_machine_opts = "firmware=bios-256k.bin";
 }
 
@@ -364,7 +373,7 @@ static void pc_q35_machine_v2_1_class_init(ObjectClass *oc, void *data)
 
 static TypeInfo pc_q35_machine_v2_1_type_info = {
     .name = "pc-q35-2.1" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_Q35_MACHINE,
     .class_init = pc_q35_machine_v2_1_class_init,
 };
 
@@ -385,12 +394,10 @@ static void pc_q35_machine_v2_0_class_init(ObjectClass *oc, void *data)
 
 static TypeInfo pc_q35_machine_v2_0_type_info = {
     .name = "pc-q35-2.0" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_Q35_MACHINE,
     .class_init = pc_q35_machine_v2_0_class_init,
 };
 
-#define pc_q35_1_7_machine_options pc_q35_machine_options
-
 static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -398,7 +405,6 @@ static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_7,
         { /* end of list */ }
     };
-    pc_q35_1_7_machine_options(mc);
     mc->init = pc_q35_init_1_7;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.7";
@@ -406,12 +412,10 @@ static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
 
 static TypeInfo pc_q35_machine_v1_7_type_info = {
     .name = "pc-q35-1.7" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_Q35_MACHINE,
     .class_init = pc_q35_machine_v1_7_class_init,
 };
 
-#define pc_q35_1_6_machine_options pc_q35_machine_options
-
 static void pc_q35_machine_v1_6_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -419,7 +423,6 @@ static void pc_q35_machine_v1_6_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_6,
         { /* end of list */ }
     };
-    pc_q35_1_6_machine_options(mc);
     mc->init = pc_q35_init_1_6;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.6";
@@ -427,7 +430,7 @@ static void pc_q35_machine_v1_6_class_init(ObjectClass *oc, void *data)
 
 static TypeInfo pc_q35_machine_v1_6_type_info = {
     .name = "pc-q35-1.6" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_Q35_MACHINE,
     .class_init = pc_q35_machine_v1_6_class_init,
 };
 
@@ -438,7 +441,6 @@ static void pc_q35_machine_v1_5_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_5,
         { /* end of list */ }
     };
-    pc_q35_1_6_machine_options(mc);
     mc->init = pc_q35_init_1_5;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.5";
@@ -446,13 +448,12 @@ static void pc_q35_machine_v1_5_class_init(ObjectClass *oc, void *data)
 
 static TypeInfo pc_q35_machine_v1_5_type_info = {
     .name = "pc-q35-1.5" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_Q35_MACHINE,
     .class_init = pc_q35_machine_v1_5_class_init,
 };
 
 static void pc_q35_1_4_machine_options(MachineClass *mc)
 {
-    pc_q35_1_6_machine_options(mc);
     mc->hot_add_cpu = NULL;
 }
 
@@ -471,12 +472,13 @@ static void pc_q35_machine_v1_4_class_init(ObjectClass *oc, void *data)
 
 static TypeInfo pc_q35_machine_v1_4_type_info = {
     .name = "pc-q35-1.4" TYPE_MACHINE_SUFFIX,
-    .parent = TYPE_PC_MACHINE,
+    .parent = TYPE_PC_Q35_MACHINE,
     .class_init = pc_q35_machine_v1_4_class_init,
 };
 
 static void pc_q35_machine_init(void)
 {
+    type_register_static(&pc_q35_machine_type_info);
     type_register_static(&pc_q35_machine_v2_1_type_info);
     type_register_static(&pc_q35_machine_v2_0_type_info);
     type_register_static(&pc_q35_machine_v1_7_type_info);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 16/33] q35: Eliminate pc_q35_1_4_machine_options()
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (14 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 15/33] q35: Eliminate pc_q35_machine_options() Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 17/33] pc: Eliminate all *_machine_options() functions Eduardo Habkost
                   ` (16 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

The function was used only in a single place.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_q35.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 2aa1c43..c3456ab 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -452,11 +452,6 @@ static TypeInfo pc_q35_machine_v1_5_type_info = {
     .class_init = pc_q35_machine_v1_5_class_init,
 };
 
-static void pc_q35_1_4_machine_options(MachineClass *mc)
-{
-    mc->hot_add_cpu = NULL;
-}
-
 static void pc_q35_machine_v1_4_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -464,7 +459,7 @@ static void pc_q35_machine_v1_4_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_4,
         { /* end of list */ }
     };
-    pc_q35_1_4_machine_options(mc);
+    mc->hot_add_cpu = NULL;
     mc->init = pc_q35_init_1_4;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.4";
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 17/33] pc: Eliminate all *_machine_options() functions
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (15 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 16/33] q35: Eliminate pc_q35_1_4_machine_options() Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 18/33] machine: Eliminate QEMUMachine.compat_props Eduardo Habkost
                   ` (15 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Finally eliminate all *_machine_options() functions, and make the
class_init functions for older machine-types simply reuse the class_init
functions from newer machine-types.

To allow compat_props reuse, the the PC_COMPAT_* macros were changed to
not nest within the older PC_COMPAT_* macros anymore.

We can now make all pc-{i440fx,q36}-* class_init functions call the previous
one.

For reference (to help ensure the reuse of previous class_init functions
won't change any behavior), these are the fields that are touched by the
class_init functions:

* name: All machine-types set it, class_init reuse won't affect it.
* hw_version: All machines older than pc*-1.0 already set it, class_init reuse
  won't affect it.
* desc: Only the base pc-{i440fx,q35} classes set it, so all classes already
  reused it.
* hot_add_cpu:
  * The base pc-{i440fx,q35} classes set it (so it was already reused by all
    subclasses).
  * pc-i440fx-1.4 was already overriding it inside
    pc_i440fx_1_4_machine_options() (and all older machine-types already
    reused it).
  * On pc_q35.c, only pc-q-35-1.4 (which is the oldest pc-q35 subclass) set it.
* alias: Only pc*-2.1 was setting it, pc*-2.0 was now changed to unset
  it, so only pc*-2.1 still have it set.
* is_default: Only pc-i440fx-2.1 was setting it, pc-i440fx-2.0 was now
  changed to unset it, so only pc-i440fx-2.1 still have it set.
* init: pc*-1.3 to pc*-2.1 were already setting it. The only ones that didn't
  set it were using the one set by previous *machine_options() functions.
* compat_props: All machine-types used PC_COMPAT_* macros that reused the
  previous one. Now they will simply append to the compat_props list added by
  the previous class_init function, and PC_COMPAT_* won't include the previous
  macros inside them.
* default_machine_opts: It was set by pc_*_2_1_machine_options() and is
  now set by pc-*-2.1 class_init(). pc*-1.7 and older didn't reuse
  pc_*_2_1_machine_options(), so now pc*-1.7 class_init() set
  default_machine_opts to NULL to ensure pc-*1.7 and older don't inherit
  it.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c    | 76 +++++++++++++++-------------------------------------
 hw/i386/pc_q35.c     | 17 ++++++------
 include/hw/i386/pc.h |  4 ---
 3 files changed, 30 insertions(+), 67 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 75c05bb..eb148f9 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -468,16 +468,10 @@ static TypeInfo pc_i440fx_machine_type_info = {
     .abstract = true,
 };
 
-
-static void pc_i440fx_2_1_machine_options(MachineClass *mc)
-{
-    mc->default_machine_opts = "firmware=bios-256k.bin";
-}
-
 static void pc_i440fx_machine_v2_1_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
-    pc_i440fx_2_1_machine_options(mc);
+    mc->default_machine_opts = "firmware=bios-256k.bin";
     mc->alias = "pc";
     mc->init = pc_init1;
     mc->is_default = 1;
@@ -490,8 +484,6 @@ static const TypeInfo pc_i440fx_machine_v2_1_type_info = {
     .class_init = pc_i440fx_machine_v2_1_class_init,
 };
 
-#define pc_i440fx_2_0_machine_options pc_i440fx_2_1_machine_options
-
 static void pc_i440fx_machine_v2_0_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -499,7 +491,9 @@ static void pc_i440fx_machine_v2_0_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_2_0,
         { /* end of list */ }
     };
-    pc_i440fx_2_0_machine_options(mc);
+    pc_i440fx_machine_v2_1_class_init(oc, data);
+    mc->alias = NULL;
+    mc->is_default = false;
     mc->init = pc_init_pci_2_0;
     mc->name = "pc-i440fx-2.0";
     machine_class_add_compat_props(mc, compat_props);
@@ -518,6 +512,8 @@ static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_7,
         { /* end of list */ }
     };
+    pc_i440fx_machine_v2_0_class_init(oc, data);
+    mc->default_machine_opts = NULL;
     mc->init = pc_init_pci_1_7;
     mc->name = "pc-i440fx-1.7";
     machine_class_add_compat_props(mc, compat_props);
@@ -536,6 +532,7 @@ static void pc_i440fx_machine_v1_6_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_6,
         { /* end of list */ }
     };
+    pc_i440fx_machine_v1_7_class_init(oc, data);
     mc->init = pc_init_pci_1_6;
     mc->name = "pc-i440fx-1.6";
     machine_class_add_compat_props(mc, compat_props);
@@ -554,6 +551,7 @@ static void pc_i440fx_machine_v1_5_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_5,
         { /* end of list */ }
     };
+    pc_i440fx_machine_v1_6_class_init(oc, data);
     mc->init = pc_init_pci_1_5;
     mc->name = "pc-i440fx-1.5";
     machine_class_add_compat_props(mc, compat_props);
@@ -565,11 +563,6 @@ static const TypeInfo pc_i440fx_machine_v1_5_type_info = {
     .class_init = pc_i440fx_machine_v1_5_class_init,
 };
 
-static void pc_i440fx_1_4_machine_options(MachineClass *mc)
-{
-    mc->hot_add_cpu = NULL;
-}
-
 static void pc_i440fx_machine_v1_4_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -577,7 +570,8 @@ static void pc_i440fx_machine_v1_4_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_4,
         { /* end of list */ }
     };
-    pc_i440fx_1_4_machine_options(mc);
+    pc_i440fx_machine_v1_5_class_init(oc, data);
+    mc->hot_add_cpu = NULL;
     mc->init = pc_init_pci_1_4;
     mc->name = "pc-i440fx-1.4";
     machine_class_add_compat_props(mc, compat_props);
@@ -590,7 +584,6 @@ static const TypeInfo pc_i440fx_machine_v1_4_type_info = {
 };
 
 #define PC_COMPAT_1_3 \
-	PC_COMPAT_1_4, \
         {\
             .driver   = "usb-tablet",\
             .property = "usb_version",\
@@ -616,7 +609,7 @@ static void pc_machine_v1_3_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_3,
         { /* end of list */ }
     };
-    pc_i440fx_1_4_machine_options(mc);
+    pc_i440fx_machine_v1_4_class_init(oc, data);
     mc->init = pc_init_pci_1_3;
     mc->name = "pc-1.3";
     machine_class_add_compat_props(mc, compat_props);
@@ -629,7 +622,6 @@ static const TypeInfo pc_machine_v1_3_type_info = {
 };
 
 #define PC_COMPAT_1_2 \
-        PC_COMPAT_1_3,\
         {\
             .driver   = "nec-usb-xhci",\
             .property = "msi",\
@@ -656,12 +648,6 @@ static const TypeInfo pc_machine_v1_3_type_info = {
             .value    = "off",\
         }
 
-static void pc_i440fx_1_2_machine_options(MachineClass *mc)
-{
-    pc_i440fx_1_4_machine_options(mc);
-    mc->init = pc_init_pci_1_2;
-}
-
 static void pc_machine_v1_2_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -669,7 +655,8 @@ static void pc_machine_v1_2_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_2,
         { /* end of list */ }
     };
-    pc_i440fx_1_2_machine_options(mc);
+    pc_machine_v1_3_class_init(oc, data);
+    mc->init = pc_init_pci_1_2;
     mc->name = "pc-1.2";
     machine_class_add_compat_props(mc, compat_props);
 }
@@ -681,7 +668,6 @@ static const TypeInfo pc_machine_v1_2_type_info = {
 };
 
 #define PC_COMPAT_1_1 \
-        PC_COMPAT_1_2,\
         {\
             .driver   = "virtio-scsi-pci",\
             .property = "hotplug",\
@@ -719,7 +705,7 @@ static void pc_machine_v1_1_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_1,
         { /* end of list */ }
     };
-    pc_i440fx_1_2_machine_options(mc);
+    pc_machine_v1_2_class_init(oc, data);
     mc->name = "pc-1.1";
     machine_class_add_compat_props(mc, compat_props);
 }
@@ -757,7 +743,7 @@ static void pc_machine_v1_0_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_0,
         { /* end of list */ }
     };
-    pc_i440fx_1_2_machine_options(mc);
+    pc_machine_v1_1_class_init(oc, data);
     mc->hw_version = "1.0";
     mc->name = "pc-1.0";
     machine_class_add_compat_props(mc, compat_props);
@@ -769,20 +755,12 @@ static const TypeInfo pc_machine_v1_0_type_info = {
     .class_init = pc_machine_v1_0_class_init,
 };
 
-#define PC_COMPAT_0_15 \
-        PC_COMPAT_1_0
-
 static void pc_machine_v0_15_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
-    static GlobalProperty compat_props[] = {
-        PC_COMPAT_0_15,
-        { /* end of list */ }
-    };
-    pc_i440fx_1_2_machine_options(mc);
+    pc_machine_v1_0_class_init(oc, data);
     mc->hw_version = "0.15";
     mc->name = "pc-0.15";
-    machine_class_add_compat_props(mc, compat_props);
 }
 
 static const TypeInfo pc_machine_v0_15_type_info = {
@@ -792,7 +770,6 @@ static const TypeInfo pc_machine_v0_15_type_info = {
 };
 
 #define PC_COMPAT_0_14 \
-        PC_COMPAT_0_15,\
         {\
             .driver   = "virtio-blk-pci",\
             .property = "event_idx",\
@@ -826,7 +803,7 @@ static void pc_machine_v0_14_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_0_14, 
         { /* end of list */ }
     };
-    pc_i440fx_1_2_machine_options(mc);
+    pc_machine_v0_15_class_init(oc, data);
     mc->hw_version = "0.14";
     mc->name = "pc-0.14";
     machine_class_add_compat_props(mc, compat_props);
@@ -839,7 +816,6 @@ static const TypeInfo pc_machine_v0_14_type_info = {
 };
 
 #define PC_COMPAT_0_13 \
-        PC_COMPAT_0_14,\
         {\
             .driver   = TYPE_PCI_DEVICE,\
             .property = "command_serr_enable",\
@@ -862,12 +838,6 @@ static const TypeInfo pc_machine_v0_14_type_info = {
             .value    = stringify(0),\
         }
 
-static void pc_i440fx_0_13_machine_options(MachineClass *mc)
-{
-    pc_i440fx_1_2_machine_options(mc);
-    mc->init = pc_init_pci_no_kvmclock;
-}
-
 static void pc_machine_v0_13_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -875,7 +845,8 @@ static void pc_machine_v0_13_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_0_13,
         { /* end of list */ }
     };
-    pc_i440fx_0_13_machine_options(mc);
+    pc_machine_v0_14_class_init(oc, data);
+    mc->init = pc_init_pci_no_kvmclock;
     mc->hw_version = "0.13";
     mc->name = "pc-0.13";
     machine_class_add_compat_props(mc, compat_props);
@@ -888,7 +859,6 @@ static const TypeInfo pc_machine_v0_13_type_info = {
 };
 
 #define PC_COMPAT_0_12 \
-        PC_COMPAT_0_13,\
         {\
             .driver   = "virtio-serial-pci",\
             .property = "max_ports",\
@@ -918,7 +888,7 @@ static void pc_machine_v0_12_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_0_12,
         { /* end of list */ }
     };
-    pc_i440fx_0_13_machine_options(mc);
+    pc_machine_v0_13_class_init(oc, data);
     mc->hw_version = "0.12";
     mc->name = "pc-0.12";
     machine_class_add_compat_props(mc, compat_props);
@@ -931,7 +901,6 @@ static const TypeInfo pc_machine_v0_12_type_info = {
 };
 
 #define PC_COMPAT_0_11 \
-        PC_COMPAT_0_12,\
         {\
             .driver   = "virtio-blk-pci",\
             .property = "vectors",\
@@ -957,7 +926,7 @@ static void pc_machine_v0_11_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_0_11,
         { /* end of list */ }
     };
-    pc_i440fx_0_13_machine_options(mc);
+    pc_machine_v0_12_class_init(oc, data);
     mc->hw_version = "0.11";
     mc->name = "pc-0.11";
     machine_class_add_compat_props(mc, compat_props);
@@ -973,7 +942,6 @@ static void pc_machine_v0_10_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
-        PC_COMPAT_0_11,
         {
             .driver   = "virtio-blk-pci",
             .property = "class",
@@ -997,7 +965,7 @@ static void pc_machine_v0_10_class_init(ObjectClass *oc, void *data)
         },
         { /* end of list */ }
     };
-    pc_i440fx_0_13_machine_options(mc);
+    pc_machine_v0_11_class_init(oc, data);
     mc->hw_version = "0.10";
     mc->name = "pc-0.10";
     machine_class_add_compat_props(mc, compat_props);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index c3456ab..c84e686 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -357,15 +357,10 @@ static TypeInfo pc_q35_machine_type_info = {
     .abstract = true,
 };
 
-static void pc_q35_2_1_machine_options(MachineClass *mc)
-{
-    mc->default_machine_opts = "firmware=bios-256k.bin";
-}
-
 static void pc_q35_machine_v2_1_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
-    pc_q35_2_1_machine_options(mc);
+    mc->default_machine_opts = "firmware=bios-256k.bin";
     mc->alias = "q35";
     mc->init = pc_q35_init;
     mc->name = "pc-q35-2.1";
@@ -377,8 +372,6 @@ static TypeInfo pc_q35_machine_v2_1_type_info = {
     .class_init = pc_q35_machine_v2_1_class_init,
 };
 
-#define pc_q35_2_0_machine_options pc_q35_2_1_machine_options
-
 static void pc_q35_machine_v2_0_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -386,7 +379,8 @@ static void pc_q35_machine_v2_0_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_2_0,
         { /* end of list */ }
     };
-    pc_q35_2_0_machine_options(mc);
+    pc_q35_machine_v2_1_class_init(oc, data);
+    mc->alias = NULL;
     mc->init = pc_q35_init_2_0;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-2.0";
@@ -405,6 +399,8 @@ static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_7,
         { /* end of list */ }
     };
+    pc_q35_machine_v2_0_class_init(oc, data);
+    mc->default_machine_opts = NULL;
     mc->init = pc_q35_init_1_7;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.7";
@@ -423,6 +419,7 @@ static void pc_q35_machine_v1_6_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_6,
         { /* end of list */ }
     };
+    pc_q35_machine_v1_7_class_init(oc, data);
     mc->init = pc_q35_init_1_6;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.6";
@@ -441,6 +438,7 @@ static void pc_q35_machine_v1_5_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_5,
         { /* end of list */ }
     };
+    pc_q35_machine_v1_6_class_init(oc, data);
     mc->init = pc_q35_init_1_5;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.5";
@@ -459,6 +457,7 @@ static void pc_q35_machine_v1_4_class_init(ObjectClass *oc, void *data)
         PC_COMPAT_1_4,
         { /* end of list */ }
     };
+    pc_q35_machine_v1_5_class_init(oc, data);
     mc->hot_add_cpu = NULL;
     mc->init = pc_q35_init_1_4;
     machine_class_add_compat_props(mc, compat_props);
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index fa4cf3c..2a0dcd9 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -356,7 +356,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
         }
 
 #define PC_COMPAT_1_7 \
-        PC_COMPAT_2_0, \
         {\
             .driver   = TYPE_USB_DEVICE,\
             .property = "msos-desc",\
@@ -374,7 +373,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
         }
 
 #define PC_COMPAT_1_6 \
-        PC_COMPAT_1_7, \
         {\
             .driver   = "e1000",\
             .property = "mitigation",\
@@ -398,7 +396,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
         }
 
 #define PC_COMPAT_1_5 \
-        PC_COMPAT_1_6, \
         {\
             .driver   = "Conroe-" TYPE_X86_CPU,\
             .property = "model",\
@@ -442,7 +439,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
         }
 
 #define PC_COMPAT_1_4 \
-        PC_COMPAT_1_5, \
         {\
             .driver   = "scsi-hd",\
             .property = "discard_granularity",\
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 18/33] machine: Eliminate QEMUMachine.compat_props
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (16 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 17/33] pc: Eliminate all *_machine_options() functions Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 19/33] pc: Rename pc_machine variable to pcms Eduardo Habkost
                   ` (14 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

The only user of QEMUMachine.compat_props was the PC code, that was
already converted to QOM. We don't need that field anymore.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 include/hw/boards.h | 1 -
 vl.c                | 3 ---
 2 files changed, 4 deletions(-)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index e9ddbc9..bbc7a9d 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -41,7 +41,6 @@ struct QEMUMachine {
     int is_default;
     const char *default_machine_opts;
     const char *default_boot_order;
-    GlobalProperty *compat_props;
     const char *hw_version;
 };
 
diff --git a/vl.c b/vl.c
index 140fea4..b004f84 100644
--- a/vl.c
+++ b/vl.c
@@ -1588,9 +1588,6 @@ static void machine_class_init(ObjectClass *oc, void *data)
     mc->default_machine_opts = qm->default_machine_opts;
     mc->default_boot_order = qm->default_boot_order;
     mc->hw_version = qm->hw_version;
-    if (qm->compat_props) {
-        machine_class_add_compat_props(mc, qm->compat_props);
-    }
 }
 
 int qemu_register_machine(QEMUMachine *m)
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 19/33] pc: Rename pc_machine variable to pcms
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (17 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 18/33] machine: Eliminate QEMUMachine.compat_props Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 20/33] pc: Pass PCMachineState argument to pc_cpus_init() Eduardo Habkost
                   ` (13 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

"pcms" being the initials of "PCMachineState". The variable will be used
a lot, so it's better to make it short.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c | 10 +++++-----
 hw/i386/pc_q35.c  | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index eb148f9..d728de9 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -75,7 +75,7 @@ static bool kvmclock_enabled = true;
 /* PC hardware initialisation */
 static void pc_init1(MachineState *machine)
 {
-    PCMachineState *pc_machine = PC_MACHINE(machine);
+    PCMachineState *pcms = PC_MACHINE(machine);
     MemoryRegion *system_memory = get_system_memory();
     MemoryRegion *system_io = get_system_io();
     int i;
@@ -117,13 +117,13 @@ static void pc_init1(MachineState *machine)
     /* Handle the machine opt max-ram-below-4g.  It is basically doing
      * min(qemu limit, user limit).
      */
-    if (lowmem > pc_machine->max_ram_below_4g) {
-        lowmem = pc_machine->max_ram_below_4g;
+    if (lowmem > pcms->max_ram_below_4g) {
+        lowmem = pcms->max_ram_below_4g;
         if (machine->ram_size - lowmem > lowmem &&
             lowmem & ((1ULL << 30) - 1)) {
             error_report("Warning: Large machine and max_ram_below_4g(%"PRIu64
                          ") not a multiple of 1G; possible bad performance.",
-                         pc_machine->max_ram_below_4g);
+                         pcms->max_ram_below_4g);
         }
     }
 
@@ -286,7 +286,7 @@ static void pc_init1(MachineState *machine)
 
         object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
                                  TYPE_HOTPLUG_HANDLER,
-                                 (Object **)&pc_machine->acpi_dev,
+                                 (Object **)&pcms->acpi_dev,
                                  object_property_allow_set_link,
                                  OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
         object_property_set_link(OBJECT(machine), OBJECT(piix4_pm),
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index c84e686..3a1adc5 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -62,7 +62,7 @@ static bool has_reserved_memory = true;
 /* PC hardware initialisation */
 static void pc_q35_init(MachineState *machine)
 {
-    PCMachineState *pc_machine = PC_MACHINE(machine);
+    PCMachineState *pcms = PC_MACHINE(machine);
     ram_addr_t below_4g_mem_size, above_4g_mem_size;
     Q35PCIHost *q35_host;
     PCIHostState *phb;
@@ -105,13 +105,13 @@ static void pc_q35_init(MachineState *machine)
     /* Handle the machine opt max-ram-below-4g.  It is basically doing
      * min(qemu limit, user limit).
      */
-    if (lowmem > pc_machine->max_ram_below_4g) {
-        lowmem = pc_machine->max_ram_below_4g;
+    if (lowmem > pcms->max_ram_below_4g) {
+        lowmem = pcms->max_ram_below_4g;
         if (machine->ram_size - lowmem > lowmem &&
             lowmem & ((1ULL << 30) - 1)) {
             error_report("Warning: Large machine and max_ram_below_4g(%"PRIu64
                          ") not a multiple of 1G; possible bad performance.",
-                         pc_machine->max_ram_below_4g);
+                         pcms->max_ram_below_4g);
         }
     }
 
@@ -205,7 +205,7 @@ static void pc_q35_init(MachineState *machine)
 
     object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
                              TYPE_HOTPLUG_HANDLER,
-                             (Object **)&pc_machine->acpi_dev,
+                             (Object **)&pcms->acpi_dev,
                              object_property_allow_set_link,
                              OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
     object_property_set_link(OBJECT(machine), OBJECT(lpc),
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 20/33] pc: Pass PCMachineState argument to pc_cpus_init()
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (18 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 19/33] pc: Rename pc_machine variable to pcms Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 21/33] machine: Add MachineClass.default_cpu_model field Eduardo Habkost
                   ` (12 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc.c         | 13 +++++++------
 hw/i386/pc_piix.c    |  2 +-
 hw/i386/pc_q35.c     |  2 +-
 include/hw/i386/pc.h |  2 +-
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 53c39cb..b42ff69 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1013,22 +1013,23 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)
     pc_new_cpu(current_cpu_model, apic_id, icc_bridge, errp);
 }
 
-void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
+void pc_cpus_init(PCMachineState *pcms, DeviceState *icc_bridge)
 {
     int i;
     X86CPU *cpu = NULL;
     Error *error = NULL;
     unsigned long apic_id_limit;
+    MachineState *machine = MACHINE(pcms);
 
     /* init CPUs */
-    if (cpu_model == NULL) {
+    if (machine->cpu_model == NULL) {
 #ifdef TARGET_X86_64
-        cpu_model = "qemu64";
+        machine->cpu_model = "qemu64";
 #else
-        cpu_model = "qemu32";
+        machine->cpu_model = "qemu32";
 #endif
     }
-    current_cpu_model = cpu_model;
+    current_cpu_model = machine->cpu_model;
 
     apic_id_limit = pc_apic_id_limit(max_cpus);
     if (apic_id_limit > ACPI_CPU_HOTPLUG_ID_LIMIT) {
@@ -1038,7 +1039,7 @@ void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
     }
 
     for (i = 0; i < smp_cpus; i++) {
-        cpu = pc_new_cpu(cpu_model, x86_cpu_apic_id_from_index(i),
+        cpu = pc_new_cpu(machine->cpu_model, x86_cpu_apic_id_from_index(i),
                          icc_bridge, &error);
         if (error) {
             error_report("%s", error_get_pretty(error));
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index d728de9..8045fee 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -145,7 +145,7 @@ static void pc_init1(MachineState *machine)
     object_property_add_child(qdev_get_machine(), "icc-bridge",
                               OBJECT(icc_bridge), NULL);
 
-    pc_cpus_init(machine->cpu_model, icc_bridge);
+    pc_cpus_init(pcms, icc_bridge);
 
     if (kvm_enabled() && kvmclock_enabled) {
         kvmclock_create();
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 3a1adc5..fb88b6e 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -133,7 +133,7 @@ static void pc_q35_init(MachineState *machine)
     object_property_add_child(qdev_get_machine(), "icc-bridge",
                               OBJECT(icc_bridge), NULL);
 
-    pc_cpus_init(machine->cpu_model, icc_bridge);
+    pc_cpus_init(pcms, icc_bridge);
     pc_acpi_init("q35-acpi-dsdt.aml");
 
     kvmclock_create();
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 2a0dcd9..4a21d83 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -171,7 +171,7 @@ extern int fd_bootchk;
 void pc_register_ferr_irq(qemu_irq irq);
 void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 
-void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge);
+void pc_cpus_init(PCMachineState *machine, DeviceState *icc_bridge);
 void pc_hot_add_cpu(const int64_t id, Error **errp);
 void pc_acpi_init(const char *default_dsdt);
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 21/33] machine: Add MachineClass.default_cpu_model field
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (19 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 20/33] pc: Pass PCMachineState argument to pc_cpus_init() Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 22/33] pc: Move globals to PCMachineClass Eduardo Habkost
                   ` (11 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Instead of making the machine-specific init code set a default CPU
model, make the generic machine init code set cpu_model to a
class-specific default if it is not set.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc.c        | 12 +++++-------
 hw/i386/pc_piix.c   |  4 +---
 include/hw/boards.h |  3 +++
 vl.c                |  3 ++-
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index b42ff69..1aec670 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1022,13 +1022,6 @@ void pc_cpus_init(PCMachineState *pcms, DeviceState *icc_bridge)
     MachineState *machine = MACHINE(pcms);
 
     /* init CPUs */
-    if (machine->cpu_model == NULL) {
-#ifdef TARGET_X86_64
-        machine->cpu_model = "qemu64";
-#else
-        machine->cpu_model = "qemu32";
-#endif
-    }
     current_cpu_model = machine->cpu_model;
 
     apic_id_limit = pc_apic_id_limit(max_cpus);
@@ -1692,6 +1685,11 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     mc->default_boot_order = "cad";
     mc->hot_add_cpu = pc_hot_add_cpu;
     mc->max_cpus = 255;
+#ifdef TARGET_X86_64
+    mc->default_cpu_model = "qemu64";
+#else
+    mc->default_cpu_model = "qemu32";
+#endif
     hc->plug = pc_machine_device_plug_cb;
 }
 
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 8045fee..ad364b0 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -430,9 +430,6 @@ static void pc_init_isa(MachineState *machine)
     has_reserved_memory = false;
     option_rom_has_mr = true;
     rom_file_has_mr = false;
-    if (!machine->cpu_model) {
-        machine->cpu_model = "486";
-    }
     x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
     enable_compat_apic_id_mode();
     pc_init1(machine);
@@ -988,6 +985,7 @@ static void isapc_machine_class_init(ObjectClass *oc, void *data)
     mc->max_cpus = 1;
     mc->hot_add_cpu = NULL;
     mc->name = "isapc";
+    mc->default_cpu_model = "486";
     machine_class_add_compat_props(mc, compat_props);
 }
 
diff --git a/include/hw/boards.h b/include/hw/boards.h
index bbc7a9d..ca78f46 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -66,6 +66,8 @@ extern MachineState *current_machine;
 /**
  * MachineClass:
  * @qemu_machine: #QEMUMachine
+ * @default_cpu_model: CPU model to be used if no CPU model is provided
+ *    by the user.
  * @get_hotplug_handler: this function is called during bus-less
  *    device hotplug. If defined it returns pointer to an instance
  *    of HotplugHandler object, which handles hotplug operation
@@ -100,6 +102,7 @@ struct MachineClass {
     const char *default_boot_order;
     GList *compat_props;
     const char *hw_version;
+    const char *default_cpu_model;
 
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
                                            DeviceState *dev);
diff --git a/vl.c b/vl.c
index b004f84..c1c5ac8 100644
--- a/vl.c
+++ b/vl.c
@@ -4418,7 +4418,8 @@ int main(int argc, char **argv, char **envp)
     current_machine->maxram_size = maxram_size;
     current_machine->ram_slots = ram_slots;
     current_machine->boot_order = boot_order;
-    current_machine->cpu_model = cpu_model;
+    current_machine->cpu_model =
+        cpu_model ? cpu_model : machine_class->default_cpu_model;
 
     machine_class->init(current_machine);
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 22/33] pc: Move globals to PCMachineClass
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (20 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 21/33] machine: Add MachineClass.default_cpu_model field Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 23/33] pc: Move option_rom_has_mr/rom_file_has_mr to MachineClass Eduardo Habkost
                   ` (10 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Move pci_enabled, has_acpi_build, legacy_acpi_table_size,
smbios_defaults, smbios_legacy_mode, gigabyte_align,
has_reserved_memory, and kvmclock_enabled to PCMachineClass, so they can
be configured on class_init instead of requiring a separate PC init
function.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v3 -> v4:
* v3 had this in multiple patches, but I decided to move all variables
  in a single patch to make the series shorter.
---
 hw/i386/pc.c         |  7 ++++
 hw/i386/pc_piix.c    | 94 ++++++++++++++++++++++++----------------------------
 hw/i386/pc_q35.c     | 40 +++++++++-------------
 include/hw/i386/pc.h | 12 +++++++
 4 files changed, 78 insertions(+), 75 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 1aec670..dba7f62 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1681,6 +1681,13 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
 
     pcmc->get_hotplug_handler = mc->get_hotplug_handler;
+    pcmc->pci_enabled = true;
+    pcmc->has_acpi_build = true;
+    pcmc->smbios_defaults = true;
+    pcmc->gigabyte_align = true;
+    pcmc->has_reserved_memory = true;
+    pcmc->kvmclock_enabled = true;
+
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     mc->default_boot_order = "cad";
     mc->hot_add_cpu = pc_hot_add_cpu;
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index ad364b0..2de8ec3 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -59,23 +59,12 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
-static bool pci_enabled = true;
-static bool has_acpi_build = true;
-static int legacy_acpi_table_size;
-static bool smbios_defaults = true;
-static bool smbios_legacy_mode;
-/* Make sure that guest addresses aligned at 1Gbyte boundaries get mapped to
- * host addresses aligned at 1Gbyte boundaries.  This way we can use 1GByte
- * pages in the host.
- */
-static bool gigabyte_align = true;
-static bool has_reserved_memory = true;
-static bool kvmclock_enabled = true;
-
 /* PC hardware initialisation */
 static void pc_init1(MachineState *machine)
 {
     PCMachineState *pcms = PC_MACHINE(machine);
+    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
+    bool pci_enabled = pcmc->pci_enabled;
     MemoryRegion *system_memory = get_system_memory();
     MemoryRegion *system_io = get_system_io();
     int i;
@@ -109,7 +98,7 @@ static void pc_init1(MachineState *machine)
      * breaking migration.
      */
     if (machine->ram_size >= 0xe0000000) {
-        lowmem = gigabyte_align ? 0xc0000000 : 0xe0000000;
+        lowmem = pcmc->gigabyte_align ? 0xc0000000 : 0xe0000000;
     } else {
         lowmem = 0xe0000000;
     }
@@ -147,7 +136,7 @@ static void pc_init1(MachineState *machine)
 
     pc_cpus_init(pcms, icc_bridge);
 
-    if (kvm_enabled() && kvmclock_enabled) {
+    if (kvm_enabled() && pcmc->kvmclock_enabled) {
         kvmclock_create();
     }
 
@@ -162,18 +151,18 @@ static void pc_init1(MachineState *machine)
 
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
 
-    guest_info->has_acpi_build = has_acpi_build;
-    guest_info->legacy_acpi_table_size = legacy_acpi_table_size;
+    guest_info->has_acpi_build = pcmc->has_acpi_build;
+    guest_info->legacy_acpi_table_size = pcmc->legacy_acpi_table_size;
 
     guest_info->has_pci_info = false;
     guest_info->isapc_ram_fw = !pci_enabled;
-    guest_info->has_reserved_memory = has_reserved_memory;
+    guest_info->has_reserved_memory = pcmc->has_reserved_memory;
 
-    if (smbios_defaults) {
+    if (pcmc->smbios_defaults) {
         MachineClass *mc = MACHINE_GET_CLASS(machine);
         /* These values are guest ABI, do not change */
         smbios_set_defaults("QEMU", "Standard PC (i440FX + PIIX, 1996)",
-                            mc->name, smbios_legacy_mode);
+                            mc->name, pcmc->smbios_legacy_mode);
     }
 
     /* allocate ram and load rom/bios */
@@ -300,34 +289,12 @@ static void pc_init1(MachineState *machine)
 
 static void pc_compat_2_0(MachineState *machine)
 {
-    /* This value depends on the actual DSDT and SSDT compiled into
-     * the source QEMU; unfortunately it depends on the binary and
-     * not on the machine type, so we cannot make pc-i440fx-1.7 work on
-     * both QEMU 1.7 and QEMU 2.0.
-     *
-     * Large variations cause migration to fail for more than one
-     * consecutive value of the "-smp" maxcpus option.
-     *
-     * For small variations of the kind caused by different iasl versions,
-     * the 4k rounding usually leaves slack.  However, there could be still
-     * one or two values that break.  For QEMU 1.7 and QEMU 2.0 the
-     * slack is only ~10 bytes before one "-smp maxcpus" value breaks!
-     *
-     * 6652 is valid for QEMU 2.0, the right value for pc-i440fx-1.7 on
-     * QEMU 1.7 it is 6414.  For RHEL/CentOS 7.0 it is 6418.
-     */
-    legacy_acpi_table_size = 6652;
-    smbios_legacy_mode = true;
-    has_reserved_memory = false;
 }
 
 static void pc_compat_1_7(MachineState *machine)
 {
     pc_compat_2_0(machine);
-    smbios_defaults = false;
-    gigabyte_align = false;
     option_rom_has_mr = true;
-    legacy_acpi_table_size = 6414;
     x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
 }
 
@@ -335,7 +302,6 @@ static void pc_compat_1_6(MachineState *machine)
 {
     pc_compat_1_7(machine);
     rom_file_has_mr = false;
-    has_acpi_build = false;
 }
 
 static void pc_compat_1_5(MachineState *machine)
@@ -367,7 +333,6 @@ static void pc_compat_1_2(MachineState *machine)
 static void pc_compat_0_13(MachineState *machine)
 {
     pc_compat_1_2(machine);
-    kvmclock_enabled = false;
 }
 
 static void pc_init_pci_2_0(MachineState *machine)
@@ -422,12 +387,6 @@ static void pc_init_pci_no_kvmclock(MachineState *machine)
 
 static void pc_init_isa(MachineState *machine)
 {
-    pci_enabled = false;
-    has_acpi_build = false;
-    smbios_defaults = false;
-    gigabyte_align = false;
-    smbios_legacy_mode = true;
-    has_reserved_memory = false;
     option_rom_has_mr = true;
     rom_file_has_mr = false;
     x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
@@ -484,6 +443,7 @@ static const TypeInfo pc_i440fx_machine_v2_1_type_info = {
 static void pc_i440fx_machine_v2_0_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         PC_COMPAT_2_0,
         { /* end of list */ }
@@ -494,6 +454,25 @@ static void pc_i440fx_machine_v2_0_class_init(ObjectClass *oc, void *data)
     mc->init = pc_init_pci_2_0;
     mc->name = "pc-i440fx-2.0";
     machine_class_add_compat_props(mc, compat_props);
+    /* This value depends on the actual DSDT and SSDT compiled into
+     * the source QEMU; unfortunately it depends on the binary and
+     * not on the machine type, so we cannot make pc-i440fx-1.7 work on
+     * both QEMU 1.7 and QEMU 2.0.
+     *
+     * Large variations cause migration to fail for more than one
+     * consecutive value of the "-smp" maxcpus option.
+     *
+     * For small variations of the kind caused by different iasl versions,
+     * the 4k rounding usually leaves slack.  However, there could be still
+     * one or two values that break.  For QEMU 1.7 and QEMU 2.0 the
+     * slack is only ~10 bytes before one "-smp maxcpus" value breaks!
+     *
+     * 6652 is valid for QEMU 2.0, the right value for pc-i440fx-1.7 on
+     * QEMU 1.7 it is 6414.  For RHEL/CentOS 7.0 it is 6418.
+     */
+    pcmc->legacy_acpi_table_size = 6652;
+    pcmc->smbios_legacy_mode = true;
+    pcmc->has_reserved_memory = false;
 }
 
 static const TypeInfo pc_i440fx_machine_v2_0_type_info = {
@@ -505,6 +484,7 @@ static const TypeInfo pc_i440fx_machine_v2_0_type_info = {
 static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         PC_COMPAT_1_7,
         { /* end of list */ }
@@ -514,6 +494,9 @@ static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
     mc->init = pc_init_pci_1_7;
     mc->name = "pc-i440fx-1.7";
     machine_class_add_compat_props(mc, compat_props);
+    pcmc->smbios_defaults = false;
+    pcmc->gigabyte_align = false;
+    pcmc->legacy_acpi_table_size = 6414;
 }
 
 static const TypeInfo pc_i440fx_machine_v1_7_type_info = {
@@ -525,6 +508,7 @@ static const TypeInfo pc_i440fx_machine_v1_7_type_info = {
 static void pc_i440fx_machine_v1_6_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         PC_COMPAT_1_6,
         { /* end of list */ }
@@ -533,6 +517,7 @@ static void pc_i440fx_machine_v1_6_class_init(ObjectClass *oc, void *data)
     mc->init = pc_init_pci_1_6;
     mc->name = "pc-i440fx-1.6";
     machine_class_add_compat_props(mc, compat_props);
+    pcmc->has_acpi_build = false;
 }
 
 static const TypeInfo pc_i440fx_machine_v1_6_type_info = {
@@ -838,6 +823,7 @@ static const TypeInfo pc_machine_v0_14_type_info = {
 static void pc_machine_v0_13_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         PC_COMPAT_0_13,
         { /* end of list */ }
@@ -847,6 +833,7 @@ static void pc_machine_v0_13_class_init(ObjectClass *oc, void *data)
     mc->hw_version = "0.13";
     mc->name = "pc-0.13";
     machine_class_add_compat_props(mc, compat_props);
+    pcmc->kvmclock_enabled = false;
 }
 
 static const TypeInfo pc_machine_v0_13_type_info = {
@@ -977,6 +964,7 @@ static const TypeInfo pc_machine_v0_10_type_info = {
 static void isapc_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         { /* end of list */ }
     };
@@ -987,6 +975,12 @@ static void isapc_machine_class_init(ObjectClass *oc, void *data)
     mc->name = "isapc";
     mc->default_cpu_model = "486";
     machine_class_add_compat_props(mc, compat_props);
+    pcmc->pci_enabled = false;
+    pcmc->has_acpi_build = false;
+    pcmc->smbios_defaults = false;
+    pcmc->gigabyte_align = false;
+    pcmc->smbios_legacy_mode = true;
+    pcmc->has_reserved_memory = false;
 }
 
 static const TypeInfo isapc_machine_type_info = {
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index fb88b6e..d6f2053 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -49,20 +49,11 @@
 /* ICH9 AHCI has 6 ports */
 #define MAX_SATA_PORTS     6
 
-static bool has_acpi_build = true;
-static bool smbios_defaults = true;
-static bool smbios_legacy_mode;
-/* Make sure that guest addresses aligned at 1Gbyte boundaries get mapped to
- * host addresses aligned at 1Gbyte boundaries.  This way we can use 1GByte
- * pages in the host.
- */
-static bool gigabyte_align = true;
-static bool has_reserved_memory = true;
-
 /* PC hardware initialisation */
 static void pc_q35_init(MachineState *machine)
 {
     PCMachineState *pcms = PC_MACHINE(machine);
+    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     ram_addr_t below_4g_mem_size, above_4g_mem_size;
     Q35PCIHost *q35_host;
     PCIHostState *phb;
@@ -97,7 +88,7 @@ static void pc_q35_init(MachineState *machine)
      * breaking migration.
      */
     if (machine->ram_size >= 0xb0000000) {
-        lowmem = gigabyte_align ? 0x80000000 : 0xb0000000;
+        lowmem = pcmc->gigabyte_align ? 0x80000000 : 0xb0000000;
     } else {
         lowmem = 0xb0000000;
     }
@@ -151,19 +142,15 @@ static void pc_q35_init(MachineState *machine)
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
     guest_info->has_pci_info = false;
     guest_info->isapc_ram_fw = false;
-    guest_info->has_acpi_build = has_acpi_build;
-    guest_info->has_reserved_memory = has_reserved_memory;
-
-    /* Migration was not supported in 2.0 for Q35, so do not bother
-     * with this hack (see hw/i386/acpi-build.c).
-     */
-    guest_info->legacy_acpi_table_size = 0;
+    guest_info->has_acpi_build = pcmc->has_acpi_build;
+    guest_info->has_reserved_memory = pcmc->has_reserved_memory;
+    guest_info->legacy_acpi_table_size = pcmc->legacy_acpi_table_size;
 
-    if (smbios_defaults) {
+    if (pcmc->smbios_defaults) {
         MachineClass *mc = MACHINE_GET_CLASS(machine);
         /* These values are guest ABI, do not change */
         smbios_set_defaults("QEMU", "Standard PC (Q35 + ICH9, 2009)",
-                            mc->name, smbios_legacy_mode);
+                            mc->name, pcmc->smbios_legacy_mode);
     }
 
     /* allocate ram and load rom/bios */
@@ -279,15 +266,11 @@ static void pc_q35_init(MachineState *machine)
 
 static void pc_compat_2_0(MachineState *machine)
 {
-    smbios_legacy_mode = true;
-    has_reserved_memory = false;
 }
 
 static void pc_compat_1_7(MachineState *machine)
 {
     pc_compat_2_0(machine);
-    smbios_defaults = false;
-    gigabyte_align = false;
     option_rom_has_mr = true;
     x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
 }
@@ -296,7 +279,6 @@ static void pc_compat_1_6(MachineState *machine)
 {
     pc_compat_1_7(machine);
     rom_file_has_mr = false;
-    has_acpi_build = false;
 }
 
 static void pc_compat_1_5(MachineState *machine)
@@ -375,6 +357,7 @@ static TypeInfo pc_q35_machine_v2_1_type_info = {
 static void pc_q35_machine_v2_0_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         PC_COMPAT_2_0,
         { /* end of list */ }
@@ -384,6 +367,8 @@ static void pc_q35_machine_v2_0_class_init(ObjectClass *oc, void *data)
     mc->init = pc_q35_init_2_0;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-2.0";
+    pcmc->smbios_legacy_mode = true;
+    pcmc->has_reserved_memory = false;
 }
 
 static TypeInfo pc_q35_machine_v2_0_type_info = {
@@ -395,6 +380,7 @@ static TypeInfo pc_q35_machine_v2_0_type_info = {
 static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         PC_COMPAT_1_7,
         { /* end of list */ }
@@ -404,6 +390,8 @@ static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
     mc->init = pc_q35_init_1_7;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.7";
+    pcmc->smbios_defaults = false;
+    pcmc->gigabyte_align = false;
 }
 
 static TypeInfo pc_q35_machine_v1_7_type_info = {
@@ -415,6 +403,7 @@ static TypeInfo pc_q35_machine_v1_7_type_info = {
 static void pc_q35_machine_v1_6_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         PC_COMPAT_1_6,
         { /* end of list */ }
@@ -423,6 +412,7 @@ static void pc_q35_machine_v1_6_class_init(ObjectClass *oc, void *data)
     mc->init = pc_q35_init_1_6;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.6";
+    pcmc->has_acpi_build = false;
 }
 
 static TypeInfo pc_q35_machine_v1_6_type_info = {
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 4a21d83..3a50298 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -53,6 +53,18 @@ struct PCMachineClass {
     /*< public >*/
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
                                            DeviceState *dev);
+    bool pci_enabled;
+    bool has_acpi_build;
+    int legacy_acpi_table_size;
+    bool smbios_defaults;
+    bool smbios_legacy_mode;
+    /* Make sure that guest addresses aligned at 1Gbyte boundaries get mapped to
+     * host addresses aligned at 1Gbyte boundaries.  This way we can use 1GByte
+     * pages in the host.
+     */
+    bool gigabyte_align;
+    bool has_reserved_memory;
+    bool kvmclock_enabled;
 };
 
 typedef struct PCMachineState PCMachineState;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 23/33] pc: Move option_rom_has_mr/rom_file_has_mr to MachineClass
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (21 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 22/33] pc: Move globals to PCMachineClass Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 24/33] pc: Add PCMachineClass.compat_apic_id_mode field Eduardo Habkost
                   ` (9 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

This way, these settings can be simply set on the class_init function,
instead of requiring a separate machine init function just to set global
variables.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/loader.c    | 12 +++++++-----
 hw/core/machine.c   |  1 +
 hw/i386/pc_piix.c   |  8 ++++----
 hw/i386/pc_q35.c    |  4 ++--
 include/hw/boards.h |  2 ++
 5 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index 2bf6b8f..d1d1e72 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -51,12 +51,10 @@
 #include "hw/nvram/fw_cfg.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
+#include "hw/boards.h"
 
 #include <zlib.h>
 
-bool option_rom_has_mr = false;
-bool rom_file_has_mr = true;
-
 static int roms_loaded;
 
 /* return the size or -1 if error */
@@ -646,6 +644,8 @@ int rom_add_file(const char *file, const char *fw_dir,
                  hwaddr addr, int32_t bootindex,
                  bool option_rom)
 {
+    MachineState *machine = current_machine;
+    MachineClass *mc = MACHINE_GET_CLASS(machine);
     Rom *rom;
     int rc, fd = -1;
     char devpath[100];
@@ -696,7 +696,7 @@ int rom_add_file(const char *file, const char *fw_dir,
                  basename);
         snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
 
-        if ((!option_rom || option_rom_has_mr) && rom_file_has_mr) {
+        if ((!option_rom || mc->option_rom_has_mr) && mc->rom_file_has_mr) {
             data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
         } else {
             data = rom->data;
@@ -724,6 +724,8 @@ void *rom_add_blob(const char *name, const void *blob, size_t len,
                    hwaddr addr, const char *fw_file_name,
                    FWCfgReadCallback fw_callback, void *callback_opaque)
 {
+    MachineState *machine = current_machine;
+    MachineClass *mc = MACHINE_GET_CLASS(machine);
     Rom *rom;
     void *data = NULL;
 
@@ -740,7 +742,7 @@ void *rom_add_blob(const char *name, const void *blob, size_t len,
 
         snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
 
-        if (rom_file_has_mr) {
+        if (mc->rom_file_has_mr) {
             data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
         } else {
             data = rom->data;
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 3eeb0a9..648e7fc 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -312,6 +312,7 @@ static void machine_class_base_init(ObjectClass *oc, void *data)
     MachineClass *mc = MACHINE_CLASS(oc);
     /* compat_props can't be simply memcpy()ed */
     mc->compat_props = g_list_copy(mc->compat_props);
+    mc->rom_file_has_mr = true;
 }
 
 static const TypeInfo machine_info = {
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 2de8ec3..e14b78e 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -294,14 +294,12 @@ static void pc_compat_2_0(MachineState *machine)
 static void pc_compat_1_7(MachineState *machine)
 {
     pc_compat_2_0(machine);
-    option_rom_has_mr = true;
     x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
 }
 
 static void pc_compat_1_6(MachineState *machine)
 {
     pc_compat_1_7(machine);
-    rom_file_has_mr = false;
 }
 
 static void pc_compat_1_5(MachineState *machine)
@@ -387,8 +385,6 @@ static void pc_init_pci_no_kvmclock(MachineState *machine)
 
 static void pc_init_isa(MachineState *machine)
 {
-    option_rom_has_mr = true;
-    rom_file_has_mr = false;
     x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
     enable_compat_apic_id_mode();
     pc_init1(machine);
@@ -493,6 +489,7 @@ static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
     mc->default_machine_opts = NULL;
     mc->init = pc_init_pci_1_7;
     mc->name = "pc-i440fx-1.7";
+    mc->option_rom_has_mr = true;
     machine_class_add_compat_props(mc, compat_props);
     pcmc->smbios_defaults = false;
     pcmc->gigabyte_align = false;
@@ -516,6 +513,7 @@ static void pc_i440fx_machine_v1_6_class_init(ObjectClass *oc, void *data)
     pc_i440fx_machine_v1_7_class_init(oc, data);
     mc->init = pc_init_pci_1_6;
     mc->name = "pc-i440fx-1.6";
+    mc->rom_file_has_mr = false;
     machine_class_add_compat_props(mc, compat_props);
     pcmc->has_acpi_build = false;
 }
@@ -974,6 +972,8 @@ static void isapc_machine_class_init(ObjectClass *oc, void *data)
     mc->hot_add_cpu = NULL;
     mc->name = "isapc";
     mc->default_cpu_model = "486";
+    mc->option_rom_has_mr = true;
+    mc->rom_file_has_mr = false;
     machine_class_add_compat_props(mc, compat_props);
     pcmc->pci_enabled = false;
     pcmc->has_acpi_build = false;
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index d6f2053..0a637cb 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -271,14 +271,12 @@ static void pc_compat_2_0(MachineState *machine)
 static void pc_compat_1_7(MachineState *machine)
 {
     pc_compat_2_0(machine);
-    option_rom_has_mr = true;
     x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
 }
 
 static void pc_compat_1_6(MachineState *machine)
 {
     pc_compat_1_7(machine);
-    rom_file_has_mr = false;
 }
 
 static void pc_compat_1_5(MachineState *machine)
@@ -388,6 +386,7 @@ static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
     pc_q35_machine_v2_0_class_init(oc, data);
     mc->default_machine_opts = NULL;
     mc->init = pc_q35_init_1_7;
+    mc->option_rom_has_mr = true;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.7";
     pcmc->smbios_defaults = false;
@@ -410,6 +409,7 @@ static void pc_q35_machine_v1_6_class_init(ObjectClass *oc, void *data)
     };
     pc_q35_machine_v1_7_class_init(oc, data);
     mc->init = pc_q35_init_1_6;
+    mc->rom_file_has_mr = false;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.6";
     pcmc->has_acpi_build = false;
diff --git a/include/hw/boards.h b/include/hw/boards.h
index ca78f46..c50fcc3 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -103,6 +103,8 @@ struct MachineClass {
     GList *compat_props;
     const char *hw_version;
     const char *default_cpu_model;
+    bool option_rom_has_mr;
+    bool rom_file_has_mr;
 
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
                                            DeviceState *dev);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 24/33] pc: Add PCMachineClass.compat_apic_id_mode field
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (22 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 23/33] pc: Move option_rom_has_mr/rom_file_has_mr to MachineClass Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 25/33] target-i386: Move error handling to end of x86_cpu_parse_featurestr() Eduardo Habkost
                   ` (8 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

This way we can move the enable_compat_apic_id_mode() calls from
pc_compat_*() to pc_init1().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c    | 9 +++++++--
 include/hw/i386/pc.h | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index e14b78e..0d13919 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -90,6 +90,10 @@ static void pc_init1(MachineState *machine)
     PcGuestInfo *guest_info;
     ram_addr_t lowmem;
 
+    if (pcmc->compat_apic_id_mode) {
+        enable_compat_apic_id_mode();
+    }
+
     /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory).
      * If it doesn't, we need to split it in chunks below and above 4G.
      * In any case, try to make sure that guest addresses aligned at
@@ -317,7 +321,6 @@ static void pc_compat_1_4(MachineState *machine)
 static void pc_compat_1_3(MachineState *machine)
 {
     pc_compat_1_4(machine);
-    enable_compat_apic_id_mode();
 }
 
 /* PC compat function for pc-0.14 to pc-1.2 */
@@ -386,7 +389,6 @@ static void pc_init_pci_no_kvmclock(MachineState *machine)
 static void pc_init_isa(MachineState *machine)
 {
     x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
-    enable_compat_apic_id_mode();
     pc_init1(machine);
 }
 
@@ -585,6 +587,7 @@ static const TypeInfo pc_i440fx_machine_v1_4_type_info = {
 static void pc_machine_v1_3_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         PC_COMPAT_1_3,
         { /* end of list */ }
@@ -593,6 +596,7 @@ static void pc_machine_v1_3_class_init(ObjectClass *oc, void *data)
     mc->init = pc_init_pci_1_3;
     mc->name = "pc-1.3";
     machine_class_add_compat_props(mc, compat_props);
+    pcmc->compat_apic_id_mode = true;
 }
 
 static const TypeInfo pc_machine_v1_3_type_info = {
@@ -981,6 +985,7 @@ static void isapc_machine_class_init(ObjectClass *oc, void *data)
     pcmc->gigabyte_align = false;
     pcmc->smbios_legacy_mode = true;
     pcmc->has_reserved_memory = false;
+    pcmc->compat_apic_id_mode = true;
 }
 
 static const TypeInfo isapc_machine_type_info = {
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 3a50298..b460530 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -65,6 +65,7 @@ struct PCMachineClass {
     bool gigabyte_align;
     bool has_reserved_memory;
     bool kvmclock_enabled;
+    bool compat_apic_id_mode;
 };
 
 typedef struct PCMachineState PCMachineState;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 25/33] target-i386: Move error handling to end of x86_cpu_parse_featurestr()
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (23 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 24/33] pc: Add PCMachineClass.compat_apic_id_mode field Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 26/33] target-i386: Renove underscores from feature names Eduardo Habkost
                   ` (7 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 6d008ab..c093168 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1822,8 +1822,7 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
             object_property_parse(OBJECT(cpu), "on", featurestr, &local_err);
         }
         if (local_err) {
-            error_propagate(errp, local_err);
-            return;
+            goto out;
         }
         featurestr = strtok(NULL, ",");
     }
@@ -1832,6 +1831,11 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
         env->features[w] |= plus_features[w];
         env->features[w] &= ~minus_features[w];
     }
+
+out:
+    if (local_err) {
+        error_propagate(errp, local_err);
+    }
 }
 
 /* generate a composite string into buf of all cpuid names in featureset
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 26/33] target-i386: Renove underscores from feature names
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (24 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 25/33] target-i386: Move error handling to end of x86_cpu_parse_featurestr() Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:31   ` Michael S. Tsirkin
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature Eduardo Habkost
                   ` (6 subsequent siblings)
  32 siblings, 1 reply; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

The underscores will be translated by x86_cpu_parse_featurestr().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index c093168..b005b0d 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -189,7 +189,7 @@ static const char *feature_name[] = {
 };
 static const char *ext_feature_name[] = {
     "pni|sse3" /* Intel,AMD sse3 */, "pclmulqdq|pclmuldq", "dtes64", "monitor",
-    "ds_cpl", "vmx", "smx", "est",
+    "ds-cpl", "vmx", "smx", "est",
     "tm2", "ssse3", "cid", NULL,
     "fma", "cx16", "xtpr", "pdcm",
     NULL, "pcid", "dca", "sse4.1|sse4_1",
@@ -209,17 +209,17 @@ static const char *ext2_feature_name[] = {
     NULL /* mtrr */, NULL /* pge */, NULL /* mca */, NULL /* cmov */,
     NULL /* pat */, NULL /* pse36 */, NULL, NULL /* Linux mp */,
     "nx|xd", NULL, "mmxext", NULL /* mmx */,
-    NULL /* fxsr */, "fxsr_opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
+    NULL /* fxsr */, "fxsr-opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
     NULL, "lm|i64", "3dnowext", "3dnow",
 };
 static const char *ext3_feature_name[] = {
-    "lahf_lm" /* AMD LahfSahf */, "cmp_legacy", "svm", "extapic" /* AMD ExtApicSpace */,
+    "lahf-lm" /* AMD LahfSahf */, "cmp-legacy", "svm", "extapic" /* AMD ExtApicSpace */,
     "cr8legacy" /* AMD AltMovCr8 */, "abm", "sse4a", "misalignsse",
     "3dnowprefetch", "osvw", "ibs", "xop",
     "skinit", "wdt", NULL, "lwp",
-    "fma4", "tce", NULL, "nodeid_msr",
-    NULL, "tbm", "topoext", "perfctr_core",
-    "perfctr_nb", NULL, NULL, NULL,
+    "fma4", "tce", NULL, "nodeid-msr",
+    NULL, "tbm", "topoext", "perfctr-core",
+    "perfctr-nb", NULL, NULL, NULL,
     NULL, NULL, NULL, NULL,
 };
 
@@ -235,8 +235,8 @@ static const char *ext4_feature_name[] = {
 };
 
 static const char *kvm_feature_name[] = {
-    "kvmclock", "kvm_nopiodelay", "kvm_mmu", "kvmclock",
-    "kvm_asyncpf", "kvm_steal_time", "kvm_pv_eoi", "kvm_pv_unhalt",
+    "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
+    "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
     NULL, NULL, NULL, NULL,
     NULL, NULL, NULL, NULL,
     NULL, NULL, NULL, NULL,
@@ -246,9 +246,9 @@ static const char *kvm_feature_name[] = {
 };
 
 static const char *svm_feature_name[] = {
-    "npt", "lbrv", "svm_lock", "nrip_save",
-    "tsc_scale", "vmcb_clean",  "flushbyasid", "decodeassists",
-    NULL, NULL, "pause_filter", NULL,
+    "npt", "lbrv", "svm-lock", "nrip-save",
+    "tsc-scale", "vmcb-clean",  "flushbyasid", "decodeassists",
+    NULL, NULL, "pause-filter", NULL,
     "pfthreshold", NULL, NULL, NULL,
     NULL, NULL, NULL, NULL,
     NULL, NULL, NULL, NULL,
@@ -1760,13 +1760,13 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
 
     while (featurestr) {
         char *val;
+        feat2prop(featurestr);
         if (featurestr[0] == '+') {
             add_flagname_to_bitmaps(featurestr + 1, plus_features);
         } else if (featurestr[0] == '-') {
             add_flagname_to_bitmaps(featurestr + 1, minus_features);
         } else if ((val = strchr(featurestr, '='))) {
             *val = 0; val++;
-            feat2prop(featurestr);
             if (!strcmp(featurestr, "xlevel")) {
                 char *err;
                 char num[32];
@@ -1818,7 +1818,6 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
                 object_property_parse(OBJECT(cpu), val, featurestr, &local_err);
             }
         } else {
-            feat2prop(featurestr);
             object_property_parse(OBJECT(cpu), "on", featurestr, &local_err);
         }
         if (local_err) {
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (25 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 26/33] target-i386: Renove underscores from feature names Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 21:08   ` Michael S. Tsirkin
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 28/33] target-i386: set [+-]feature using QOM properties Eduardo Habkost
                   ` (5 subsequent siblings)
  32 siblings, 1 reply; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

The "kvmclock" feature is special because it affects two bits in the KVM
CPUID leaf, so it has to be handled differently from the other feature
properties that will be added.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b005b0d..0eb401b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2774,6 +2774,61 @@ uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index)
     }
 }
 
+typedef struct FeatureProperty {
+    FeatureWord word;
+    uint32_t mask;
+} FeatureProperty;
+
+
+static void x86_cpu_get_feature_prop(Object *obj,
+                                     struct Visitor *v,
+                                     void *opaque,
+                                     const char *name,
+                                     Error **errp)
+{
+    X86CPU *cpu = X86_CPU(obj);
+    CPUX86State *env = &cpu->env;
+    FeatureProperty *fp = opaque;
+    bool value = (env->features[fp->word] & fp->mask) == fp->mask;
+    visit_type_bool(v, &value, name, errp);
+}
+
+static void x86_cpu_set_feature_prop(Object *obj,
+                                     struct Visitor *v,
+                                     void *opaque,
+                                     const char *name,
+                                     Error **errp)
+{
+    X86CPU *cpu = X86_CPU(obj);
+    CPUX86State *env = &cpu->env;
+    FeatureProperty *fp = opaque;
+    bool value;
+    visit_type_bool(v, &value, name, errp);
+    if (value) {
+        env->features[fp->word] |= fp->mask;
+    } else {
+        env->features[fp->word] &= ~fp->mask;
+    }
+}
+
+/* Register a boolean feature-bits property.
+ * If mask has multiple bits, all must be set for the property to return true.
+ */
+static void x86_cpu_register_feature_prop(X86CPU *cpu,
+                                          const char *prop_name,
+                                          FeatureWord w,
+                                          uint32_t mask)
+{
+    FeatureProperty *fp;
+    fp = g_new0(FeatureProperty, 1);
+    fp->word = w;
+    fp->mask = mask;
+    object_property_add(OBJECT(cpu), prop_name, "bool",
+                        x86_cpu_set_feature_prop,
+                        x86_cpu_get_feature_prop,
+                        NULL, fp, &error_abort);
+}
+
 static void x86_cpu_initfn(Object *obj)
 {
     CPUState *cs = CPU(obj);
@@ -2819,6 +2874,12 @@ static void x86_cpu_initfn(Object *obj)
                         x86_cpu_get_feature_words,
                         NULL, NULL, (void *)cpu->filtered_features, NULL);
 
+    /* "feat-kvmclock" will affect both kvmclock feature bits */
+    x86_cpu_register_feature_prop(cpu, "feat-kvmclock", FEAT_KVM,
+                                  (1UL << KVM_FEATURE_CLOCKSOURCE) |
+                                  (1UL << KVM_FEATURE_CLOCKSOURCE2));
+
+
     cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
     env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 28/33] target-i386: set [+-]feature using QOM properties
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (26 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 29/33] pc: Use compat_props for CPUID compat bits Eduardo Habkost
                   ` (4 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

From: Igor Mammedov <imammedo@redhat.com>

 * Define properties for cpuid feature bits
    * property names of CPUID feature bits are changed to have "feat-"
      prefix, so that it would be easy to distinguish them from other
      properties.

 * Convert [+-]cpuid_features to a set(QDict) of key, value pairs, where
     +foo => (feat-foo, on)
     -foo => (feat-foo, off)
     [+-] unknown foo => (feat-foo, on/off) - it's expected to be rejected
                                              by property setter later
   QDict is used as convinience sturcture to keep '-foo' semantic.
   Once all +-foo are parsed, collected features are applied to CPU instance.

 * The duplicate "kvmclock" bits were renamed to "kvmclock1" and
   "kvmclock2". The new "feat-kvmclock" property will set/clear both
   bits, keeping backwards compatibility.

 * Remove functions that are not used anymore:
     add_flagname_to_bitmaps(), lookup_feature(), altcmp(), sstrcmp(),

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
[small tweaks to error handling in x86_cpu_parse_featurestr() -Eduardo]
[Removed kvmclock special case -Eduardo]
[Register feature properties dynamically on instance_init -Eduardo]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 159 ++++++++++++++++++++++--------------------------------
 1 file changed, 65 insertions(+), 94 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 0eb401b..e058c1a 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -235,7 +235,7 @@ static const char *ext4_feature_name[] = {
 };
 
 static const char *kvm_feature_name[] = {
-    "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
+    "kvmclock1", "kvm-nopiodelay", "kvm-mmu", "kvmclock2",
     "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
     NULL, NULL, NULL, NULL,
     NULL, NULL, NULL, NULL,
@@ -528,85 +528,6 @@ void host_cpuid(uint32_t function, uint32_t count,
         *edx = vec[3];
 }
 
-#define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
-
-/* general substring compare of *[s1..e1) and *[s2..e2).  sx is start of
- * a substring.  ex if !NULL points to the first char after a substring,
- * otherwise the string is assumed to sized by a terminating nul.
- * Return lexical ordering of *s1:*s2.
- */
-static int sstrcmp(const char *s1, const char *e1, const char *s2,
-    const char *e2)
-{
-    for (;;) {
-        if (!*s1 || !*s2 || *s1 != *s2)
-            return (*s1 - *s2);
-        ++s1, ++s2;
-        if (s1 == e1 && s2 == e2)
-            return (0);
-        else if (s1 == e1)
-            return (*s2);
-        else if (s2 == e2)
-            return (*s1);
-    }
-}
-
-/* compare *[s..e) to *altstr.  *altstr may be a simple string or multiple
- * '|' delimited (possibly empty) strings in which case search for a match
- * within the alternatives proceeds left to right.  Return 0 for success,
- * non-zero otherwise.
- */
-static int altcmp(const char *s, const char *e, const char *altstr)
-{
-    const char *p, *q;
-
-    for (q = p = altstr; ; ) {
-        while (*p && *p != '|')
-            ++p;
-        if ((q == p && !*s) || (q != p && !sstrcmp(s, e, q, p)))
-            return (0);
-        if (!*p)
-            return (1);
-        else
-            q = ++p;
-    }
-}
-
-/* search featureset for flag *[s..e), if found set corresponding bit in
- * *pval and return true, otherwise return false
- */
-static bool lookup_feature(uint32_t *pval, const char *s, const char *e,
-                           const char **featureset)
-{
-    uint32_t mask;
-    const char **ppc;
-    bool found = false;
-
-    for (mask = 1, ppc = featureset; mask; mask <<= 1, ++ppc) {
-        if (*ppc && !altcmp(s, e, *ppc)) {
-            *pval |= mask;
-            found = true;
-        }
-    }
-    return found;
-}
-
-static void add_flagname_to_bitmaps(const char *flagname,
-                                    FeatureWordArray words)
-{
-    FeatureWord w;
-    for (w = 0; w < FEATURE_WORDS; w++) {
-        FeatureWordInfo *wi = &feature_word_info[w];
-        if (wi->feat_names &&
-            lookup_feature(&words[w], flagname, NULL, wi->feat_names)) {
-            break;
-        }
-    }
-    if (w == FEATURE_WORDS) {
-        fprintf(stderr, "CPU feature %s not found\n", flagname);
-    }
-}
-
 /* CPU class name definitions: */
 
 #define X86_CPU_TYPE_SUFFIX "-" TYPE_X86_CPU
@@ -1747,24 +1668,35 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
 {
     X86CPU *cpu = X86_CPU(cs);
     char *featurestr; /* Single 'key=value" string being parsed */
-    FeatureWord w;
-    /* Features to be added */
-    FeatureWordArray plus_features = { 0 };
-    /* Features to be removed */
-    FeatureWordArray minus_features = { 0 };
     uint32_t numvalue;
-    CPUX86State *env = &cpu->env;
     Error *local_err = NULL;
+    QDict *props = qdict_new();
+    const QDictEntry *ent;
 
     featurestr = features ? strtok(features, ",") : NULL;
 
     while (featurestr) {
         char *val;
         feat2prop(featurestr);
-        if (featurestr[0] == '+') {
-            add_flagname_to_bitmaps(featurestr + 1, plus_features);
-        } else if (featurestr[0] == '-') {
-            add_flagname_to_bitmaps(featurestr + 1, minus_features);
+        if (featurestr[0] == '+' || featurestr[0] == '-') {
+            const gchar *feat = featurestr + 1;
+            gchar *cpuid_fname = NULL;
+
+            if (strncmp(feat, "feat-", 5)) {
+                cpuid_fname = g_strconcat("feat-", feat, NULL);
+                feat = cpuid_fname;
+            }
+
+            if (featurestr[0] == '+') {
+                /* preseve legacy behaviour, if feature was disabled once
+                 * do not allow to enable it again */
+                if (!qdict_haskey(props, feat)) {
+                    qdict_put(props, feat, qstring_from_str("on"));
+                }
+            } else {
+                qdict_put(props, feat, qstring_from_str("off"));
+            }
+            g_free(cpuid_fname);
         } else if ((val = strchr(featurestr, '='))) {
             *val = 0; val++;
             if (!strcmp(featurestr, "xlevel")) {
@@ -1826,15 +1758,21 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
         featurestr = strtok(NULL, ",");
     }
 
-    for (w = 0; w < FEATURE_WORDS; w++) {
-        env->features[w] |= plus_features[w];
-        env->features[w] &= ~minus_features[w];
+    for (ent = qdict_first(props); ent; ent = qdict_next(props, ent)) {
+        const QString *qval = qobject_to_qstring(qdict_entry_value(ent));
+        /* TODO: switch to using global properties after subclasses are done */
+        object_property_parse(OBJECT(cpu), qstring_get_str(qval),
+                              qdict_entry_key(ent), &local_err);
+        if (local_err) {
+            goto out;
+        }
     }
 
 out:
     if (local_err) {
         error_propagate(errp, local_err);
     }
+    QDECREF(props);
 }
 
 /* generate a composite string into buf of all cpuid names in featureset
@@ -2824,17 +2762,43 @@ static void x86_cpu_register_feature_prop(X86CPU *cpu,
     fp->word = w;
     fp->mask = mask;
     object_property_add(OBJECT(cpu), prop_name, "bool",
-                        x86_cpu_set_feature_prop,
                         x86_cpu_get_feature_prop,
+                        x86_cpu_set_feature_prop,
                         NULL, fp, &error_abort);
 }
 
+static void x86_cpu_register_feature_bit_props(X86CPU *cpu,
+                                               FeatureWord w,
+                                               int bit)
+{
+    int i;
+    char **names;
+    FeatureWordInfo *fi = &feature_word_info[w];
+
+    if (!fi->feat_names) {
+        return;
+    }
+    if (!fi->feat_names[bit]) {
+        return;
+    }
+
+    names = g_strsplit(fi->feat_names[bit], "|", 0);
+    for (i = 0; names[i]; i++) {
+        char *feat_name = names[i];
+        char *prop_name = g_strdup_printf("feat-%s", feat_name);
+        x86_cpu_register_feature_prop(cpu, prop_name, w, (1UL << bit));
+        g_free(prop_name);
+    }
+    g_strfreev(names);
+}
+
 static void x86_cpu_initfn(Object *obj)
 {
     CPUState *cs = CPU(obj);
     X86CPU *cpu = X86_CPU(obj);
     X86CPUClass *xcc = X86_CPU_GET_CLASS(obj);
     CPUX86State *env = &cpu->env;
+    FeatureWord w;
     static int inited;
 
     cs->env_ptr = env;
@@ -2883,6 +2847,13 @@ static void x86_cpu_initfn(Object *obj)
     cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
     env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
 
+    for (w = 0; w < FEATURE_WORDS; w++) {
+        int bit;
+        for (bit = 0; bit < 32; bit++) {
+            x86_cpu_register_feature_bit_props(cpu, w, bit);
+        }
+    }
+
     x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort);
 
     /* init various static tables used in TCG mode */
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 29/33] pc: Use compat_props for CPUID compat bits
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (27 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 28/33] target-i386: set [+-]feature using QOM properties Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 30/33] target-i386: Move some declarations to hw/i386/cpu.h Eduardo Habkost
                   ` (3 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

x86_cpu_compat_set_features() is not necessary anymore, as now we can
simply use compat_props.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c    |  2 --
 hw/i386/pc_q35.c     |  2 --
 include/hw/i386/pc.h |  8 ++++++++
 target-i386/cpu.c    | 26 --------------------------
 target-i386/cpu.h    |  3 ---
 5 files changed, 8 insertions(+), 33 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 0d13919..988583c 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -314,8 +314,6 @@ static void pc_compat_1_5(MachineState *machine)
 static void pc_compat_1_4(MachineState *machine)
 {
     pc_compat_1_5(machine);
-    x86_cpu_compat_set_features("n270", FEAT_1_ECX, 0, CPUID_EXT_MOVBE);
-    x86_cpu_compat_set_features("Westmere", FEAT_1_ECX, 0, CPUID_EXT_PCLMULQDQ);
 }
 
 static void pc_compat_1_3(MachineState *machine)
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 0a637cb..2ebd598 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -287,8 +287,6 @@ static void pc_compat_1_5(MachineState *machine)
 static void pc_compat_1_4(MachineState *machine)
 {
     pc_compat_1_5(machine);
-    x86_cpu_compat_set_features("n270", FEAT_1_ECX, 0, CPUID_EXT_MOVBE);
-    x86_cpu_compat_set_features("Westmere", FEAT_1_ECX, 0, CPUID_EXT_PCLMULQDQ);
 }
 
 static void pc_q35_init_2_0(MachineState *machine)
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index b460530..460ff21 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -513,6 +513,14 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
             .driver   = "486-" TYPE_X86_CPU,\
             .property = "model",\
             .value    = stringify(0),\
+        },{\
+            .driver   = "n270-" TYPE_X86_CPU,\
+            .property = "feat-movbe",\
+            .value    = "off",\
+        },{\
+            .driver   = "Westmere-" TYPE_X86_CPU,\
+            .property = "feat-pclmulqdq",\
+            .value    = "off",\
         }
 
 #endif
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e058c1a..e86f99e 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1149,32 +1149,6 @@ static X86CPUDefinition builtin_x86_defs[] = {
     },
 };
 
-/**
- * x86_cpu_compat_set_features:
- * @cpu_model: CPU model name to be changed. If NULL, all CPU models are changed
- * @w: Identifies the feature word to be changed.
- * @feat_add: Feature bits to be added to feature word
- * @feat_remove: Feature bits to be removed from feature word
- *
- * Change CPU model feature bits for compatibility.
- *
- * This function may be used by machine-type compatibility functions
- * to enable or disable feature bits on specific CPU models.
- */
-void x86_cpu_compat_set_features(const char *cpu_model, FeatureWord w,
-                                 uint32_t feat_add, uint32_t feat_remove)
-{
-    X86CPUDefinition *def;
-    int i;
-    for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
-        def = &builtin_x86_defs[i];
-        if (!cpu_model || !strcmp(cpu_model, def->name)) {
-            def->features[w] |= feat_add;
-            def->features[w] &= ~feat_remove;
-        }
-    }
-}
-
 #ifdef CONFIG_KVM
 
 static int cpu_x86_fill_model_id(char *str)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index e634d83..7ff2a3f 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1297,9 +1297,6 @@ void do_smm_enter(X86CPU *cpu);
 
 void cpu_report_tpr_access(CPUX86State *env, TPRAccess access);
 
-void x86_cpu_compat_set_features(const char *cpu_model, FeatureWord w,
-                                 uint32_t feat_add, uint32_t feat_remove);
-
 void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features);
 
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 30/33] target-i386: Move some declarations to hw/i386/cpu.h
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (28 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 29/33] pc: Use compat_props for CPUID compat bits Eduardo Habkost
@ 2014-08-14 19:25 ` Eduardo Habkost
  2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 31/33] pc: Add default KVM features fields to PCMachineClass Eduardo Habkost
                   ` (2 subsequent siblings)
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

This will allow the PC machine declarations (which must not depend on
target-specific cpu.h because pc.h is included from target-independent
code) to use i386-specific types.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 include/hw/i386/cpu.h | 564 ++++++++++++++++++++++++++++++++++++++++++++++++++
 target-i386/cpu.h     | 560 +------------------------------------------------
 2 files changed, 566 insertions(+), 558 deletions(-)
 create mode 100644 include/hw/i386/cpu.h

diff --git a/include/hw/i386/cpu.h b/include/hw/i386/cpu.h
new file mode 100644
index 0000000..e569f6b
--- /dev/null
+++ b/include/hw/i386/cpu.h
@@ -0,0 +1,564 @@
+/* i386 CPU types and declarations that don't depend on target-i386/cpu.h
+ */
+#ifndef HW_I386_CPU_H
+#define HW_I386_CPU_H
+
+#define R_EAX 0
+#define R_ECX 1
+#define R_EDX 2
+#define R_EBX 3
+#define R_ESP 4
+#define R_EBP 5
+#define R_ESI 6
+#define R_EDI 7
+
+#define R_AL 0
+#define R_CL 1
+#define R_DL 2
+#define R_BL 3
+#define R_AH 4
+#define R_CH 5
+#define R_DH 6
+#define R_BH 7
+
+#define R_ES 0
+#define R_CS 1
+#define R_SS 2
+#define R_DS 3
+#define R_FS 4
+#define R_GS 5
+
+/* segment descriptor fields */
+#define DESC_G_MASK     (1 << 23)
+#define DESC_B_SHIFT    22
+#define DESC_B_MASK     (1 << DESC_B_SHIFT)
+#define DESC_L_SHIFT    21 /* x86_64 only : 64 bit code segment */
+#define DESC_L_MASK     (1 << DESC_L_SHIFT)
+#define DESC_AVL_MASK   (1 << 20)
+#define DESC_P_MASK     (1 << 15)
+#define DESC_DPL_SHIFT  13
+#define DESC_DPL_MASK   (3 << DESC_DPL_SHIFT)
+#define DESC_S_MASK     (1 << 12)
+#define DESC_TYPE_SHIFT 8
+#define DESC_TYPE_MASK  (15 << DESC_TYPE_SHIFT)
+#define DESC_A_MASK     (1 << 8)
+
+#define DESC_CS_MASK    (1 << 11) /* 1=code segment 0=data segment */
+#define DESC_C_MASK     (1 << 10) /* code: conforming */
+#define DESC_R_MASK     (1 << 9)  /* code: readable */
+
+#define DESC_E_MASK     (1 << 10) /* data: expansion direction */
+#define DESC_W_MASK     (1 << 9)  /* data: writable */
+
+#define DESC_TSS_BUSY_MASK (1 << 9)
+
+/* eflags masks */
+#define CC_C    0x0001
+#define CC_P    0x0004
+#define CC_A    0x0010
+#define CC_Z    0x0040
+#define CC_S    0x0080
+#define CC_O    0x0800
+
+#define TF_SHIFT   8
+#define IOPL_SHIFT 12
+#define VM_SHIFT   17
+
+#define TF_MASK                 0x00000100
+#define IF_MASK                 0x00000200
+#define DF_MASK                 0x00000400
+#define IOPL_MASK               0x00003000
+#define NT_MASK                 0x00004000
+#define RF_MASK                 0x00010000
+#define VM_MASK                 0x00020000
+#define AC_MASK                 0x00040000
+#define VIF_MASK                0x00080000
+#define VIP_MASK                0x00100000
+#define ID_MASK                 0x00200000
+
+/* hidden flags - used internally by qemu to represent additional cpu
+   states. Only the INHIBIT_IRQ, SMM and SVMI are not redundant. We
+   avoid using the IOPL_MASK, TF_MASK, VM_MASK and AC_MASK bit
+   positions to ease oring with eflags. */
+/* current cpl */
+#define HF_CPL_SHIFT         0
+/* true if soft mmu is being used */
+#define HF_SOFTMMU_SHIFT     2
+/* true if hardware interrupts must be disabled for next instruction */
+#define HF_INHIBIT_IRQ_SHIFT 3
+/* 16 or 32 segments */
+#define HF_CS32_SHIFT        4
+#define HF_SS32_SHIFT        5
+/* zero base for DS, ES and SS : can be '0' only in 32 bit CS segment */
+#define HF_ADDSEG_SHIFT      6
+/* copy of CR0.PE (protected mode) */
+#define HF_PE_SHIFT          7
+#define HF_TF_SHIFT          8 /* must be same as eflags */
+#define HF_MP_SHIFT          9 /* the order must be MP, EM, TS */
+#define HF_EM_SHIFT         10
+#define HF_TS_SHIFT         11
+#define HF_IOPL_SHIFT       12 /* must be same as eflags */
+#define HF_LMA_SHIFT        14 /* only used on x86_64: long mode active */
+#define HF_CS64_SHIFT       15 /* only used on x86_64: 64 bit code segment  */
+#define HF_RF_SHIFT         16 /* must be same as eflags */
+#define HF_VM_SHIFT         17 /* must be same as eflags */
+#define HF_AC_SHIFT         18 /* must be same as eflags */
+#define HF_SMM_SHIFT        19 /* CPU in SMM mode */
+#define HF_SVME_SHIFT       20 /* SVME enabled (copy of EFER.SVME) */
+#define HF_SVMI_SHIFT       21 /* SVM intercepts are active */
+#define HF_OSFXSR_SHIFT     22 /* CR4.OSFXSR */
+#define HF_SMAP_SHIFT       23 /* CR4.SMAP */
+
+#define HF_CPL_MASK          (3 << HF_CPL_SHIFT)
+#define HF_SOFTMMU_MASK      (1 << HF_SOFTMMU_SHIFT)
+#define HF_INHIBIT_IRQ_MASK  (1 << HF_INHIBIT_IRQ_SHIFT)
+#define HF_CS32_MASK         (1 << HF_CS32_SHIFT)
+#define HF_SS32_MASK         (1 << HF_SS32_SHIFT)
+#define HF_ADDSEG_MASK       (1 << HF_ADDSEG_SHIFT)
+#define HF_PE_MASK           (1 << HF_PE_SHIFT)
+#define HF_TF_MASK           (1 << HF_TF_SHIFT)
+#define HF_MP_MASK           (1 << HF_MP_SHIFT)
+#define HF_EM_MASK           (1 << HF_EM_SHIFT)
+#define HF_TS_MASK           (1 << HF_TS_SHIFT)
+#define HF_IOPL_MASK         (3 << HF_IOPL_SHIFT)
+#define HF_LMA_MASK          (1 << HF_LMA_SHIFT)
+#define HF_CS64_MASK         (1 << HF_CS64_SHIFT)
+#define HF_RF_MASK           (1 << HF_RF_SHIFT)
+#define HF_VM_MASK           (1 << HF_VM_SHIFT)
+#define HF_AC_MASK           (1 << HF_AC_SHIFT)
+#define HF_SMM_MASK          (1 << HF_SMM_SHIFT)
+#define HF_SVME_MASK         (1 << HF_SVME_SHIFT)
+#define HF_SVMI_MASK         (1 << HF_SVMI_SHIFT)
+#define HF_OSFXSR_MASK       (1 << HF_OSFXSR_SHIFT)
+#define HF_SMAP_MASK         (1 << HF_SMAP_SHIFT)
+
+/* hflags2 */
+
+#define HF2_GIF_SHIFT        0 /* if set CPU takes interrupts */
+#define HF2_HIF_SHIFT        1 /* value of IF_MASK when entering SVM */
+#define HF2_NMI_SHIFT        2 /* CPU serving NMI */
+#define HF2_VINTR_SHIFT      3 /* value of V_INTR_MASKING bit */
+
+#define HF2_GIF_MASK          (1 << HF2_GIF_SHIFT)
+#define HF2_HIF_MASK          (1 << HF2_HIF_SHIFT)
+#define HF2_NMI_MASK          (1 << HF2_NMI_SHIFT)
+#define HF2_VINTR_MASK        (1 << HF2_VINTR_SHIFT)
+
+#define CR0_PE_SHIFT 0
+#define CR0_MP_SHIFT 1
+
+#define CR0_PE_MASK  (1U << 0)
+#define CR0_MP_MASK  (1U << 1)
+#define CR0_EM_MASK  (1U << 2)
+#define CR0_TS_MASK  (1U << 3)
+#define CR0_ET_MASK  (1U << 4)
+#define CR0_NE_MASK  (1U << 5)
+#define CR0_WP_MASK  (1U << 16)
+#define CR0_AM_MASK  (1U << 18)
+#define CR0_PG_MASK  (1U << 31)
+
+#define CR4_VME_MASK  (1U << 0)
+#define CR4_PVI_MASK  (1U << 1)
+#define CR4_TSD_MASK  (1U << 2)
+#define CR4_DE_MASK   (1U << 3)
+#define CR4_PSE_MASK  (1U << 4)
+#define CR4_PAE_MASK  (1U << 5)
+#define CR4_MCE_MASK  (1U << 6)
+#define CR4_PGE_MASK  (1U << 7)
+#define CR4_PCE_MASK  (1U << 8)
+#define CR4_OSFXSR_SHIFT 9
+#define CR4_OSFXSR_MASK (1U << CR4_OSFXSR_SHIFT)
+#define CR4_OSXMMEXCPT_MASK  (1U << 10)
+#define CR4_VMXE_MASK   (1U << 13)
+#define CR4_SMXE_MASK   (1U << 14)
+#define CR4_FSGSBASE_MASK (1U << 16)
+#define CR4_PCIDE_MASK  (1U << 17)
+#define CR4_OSXSAVE_MASK (1U << 18)
+#define CR4_SMEP_MASK   (1U << 20)
+#define CR4_SMAP_MASK   (1U << 21)
+
+#define DR6_BD          (1 << 13)
+#define DR6_BS          (1 << 14)
+#define DR6_BT          (1 << 15)
+#define DR6_FIXED_1     0xffff0ff0
+
+#define DR7_GD          (1 << 13)
+#define DR7_TYPE_SHIFT  16
+#define DR7_LEN_SHIFT   18
+#define DR7_FIXED_1     0x00000400
+#define DR7_LOCAL_BP_MASK    0x55
+#define DR7_MAX_BP           4
+#define DR7_TYPE_BP_INST     0x0
+#define DR7_TYPE_DATA_WR     0x1
+#define DR7_TYPE_IO_RW       0x2
+#define DR7_TYPE_DATA_RW     0x3
+
+#define PG_PRESENT_BIT  0
+#define PG_RW_BIT       1
+#define PG_USER_BIT     2
+#define PG_PWT_BIT      3
+#define PG_PCD_BIT      4
+#define PG_ACCESSED_BIT 5
+#define PG_DIRTY_BIT    6
+#define PG_PSE_BIT      7
+#define PG_GLOBAL_BIT   8
+#define PG_PSE_PAT_BIT  12
+#define PG_NX_BIT       63
+
+#define PG_PRESENT_MASK  (1 << PG_PRESENT_BIT)
+#define PG_RW_MASK       (1 << PG_RW_BIT)
+#define PG_USER_MASK     (1 << PG_USER_BIT)
+#define PG_PWT_MASK      (1 << PG_PWT_BIT)
+#define PG_PCD_MASK      (1 << PG_PCD_BIT)
+#define PG_ACCESSED_MASK (1 << PG_ACCESSED_BIT)
+#define PG_DIRTY_MASK    (1 << PG_DIRTY_BIT)
+#define PG_PSE_MASK      (1 << PG_PSE_BIT)
+#define PG_GLOBAL_MASK   (1 << PG_GLOBAL_BIT)
+#define PG_PSE_PAT_MASK  (1 << PG_PSE_PAT_BIT)
+#define PG_ADDRESS_MASK  0x000ffffffffff000LL
+#define PG_HI_RSVD_MASK  (PG_ADDRESS_MASK & ~PHYS_ADDR_MASK)
+#define PG_HI_USER_MASK  0x7ff0000000000000LL
+#define PG_NX_MASK       (1LL << PG_NX_BIT)
+
+#define PG_ERROR_W_BIT     1
+
+#define PG_ERROR_P_MASK    0x01
+#define PG_ERROR_W_MASK    (1 << PG_ERROR_W_BIT)
+#define PG_ERROR_U_MASK    0x04
+#define PG_ERROR_RSVD_MASK 0x08
+#define PG_ERROR_I_D_MASK  0x10
+
+#define MCG_CTL_P       (1ULL<<8)   /* MCG_CAP register available */
+#define MCG_SER_P       (1ULL<<24) /* MCA recovery/new status bits */
+
+#define MCE_CAP_DEF     (MCG_CTL_P|MCG_SER_P)
+#define MCE_BANKS_DEF   10
+
+#define MCG_STATUS_RIPV (1ULL<<0)   /* restart ip valid */
+#define MCG_STATUS_EIPV (1ULL<<1)   /* ip points to correct instruction */
+#define MCG_STATUS_MCIP (1ULL<<2)   /* machine check in progress */
+
+#define MCI_STATUS_VAL   (1ULL<<63)  /* valid error */
+#define MCI_STATUS_OVER  (1ULL<<62)  /* previous errors lost */
+#define MCI_STATUS_UC    (1ULL<<61)  /* uncorrected error */
+#define MCI_STATUS_EN    (1ULL<<60)  /* error enabled */
+#define MCI_STATUS_MISCV (1ULL<<59)  /* misc error reg. valid */
+#define MCI_STATUS_ADDRV (1ULL<<58)  /* addr reg. valid */
+#define MCI_STATUS_PCC   (1ULL<<57)  /* processor context corrupt */
+#define MCI_STATUS_S     (1ULL<<56)  /* Signaled machine check */
+#define MCI_STATUS_AR    (1ULL<<55)  /* Action required */
+
+/* MISC register defines */
+#define MCM_ADDR_SEGOFF  0      /* segment offset */
+#define MCM_ADDR_LINEAR  1      /* linear address */
+#define MCM_ADDR_PHYS    2      /* physical address */
+#define MCM_ADDR_MEM     3      /* memory address */
+#define MCM_ADDR_GENERIC 7      /* generic */
+
+#define MSR_IA32_TSC                    0x10
+#define MSR_IA32_APICBASE               0x1b
+#define MSR_IA32_APICBASE_BSP           (1<<8)
+#define MSR_IA32_APICBASE_ENABLE        (1<<11)
+#define MSR_IA32_APICBASE_BASE          (0xfffff<<12)
+#define MSR_IA32_FEATURE_CONTROL        0x0000003a
+#define MSR_TSC_ADJUST                  0x0000003b
+#define MSR_IA32_TSCDEADLINE            0x6e0
+
+#define MSR_P6_PERFCTR0                 0xc1
+
+#define MSR_MTRRcap                     0xfe
+#define MSR_MTRRcap_VCNT                8
+#define MSR_MTRRcap_FIXRANGE_SUPPORT    (1 << 8)
+#define MSR_MTRRcap_WC_SUPPORTED        (1 << 10)
+
+#define MSR_IA32_SYSENTER_CS            0x174
+#define MSR_IA32_SYSENTER_ESP           0x175
+#define MSR_IA32_SYSENTER_EIP           0x176
+
+#define MSR_MCG_CAP                     0x179
+#define MSR_MCG_STATUS                  0x17a
+#define MSR_MCG_CTL                     0x17b
+
+#define MSR_P6_EVNTSEL0                 0x186
+
+#define MSR_IA32_PERF_STATUS            0x198
+
+#define MSR_IA32_MISC_ENABLE            0x1a0
+/* Indicates good rep/movs microcode on some processors: */
+#define MSR_IA32_MISC_ENABLE_DEFAULT    1
+
+#define MSR_MTRRphysBase(reg)           (0x200 + 2 * (reg))
+#define MSR_MTRRphysMask(reg)           (0x200 + 2 * (reg) + 1)
+
+#define MSR_MTRRfix64K_00000            0x250
+#define MSR_MTRRfix16K_80000            0x258
+#define MSR_MTRRfix16K_A0000            0x259
+#define MSR_MTRRfix4K_C0000             0x268
+#define MSR_MTRRfix4K_C8000             0x269
+#define MSR_MTRRfix4K_D0000             0x26a
+#define MSR_MTRRfix4K_D8000             0x26b
+#define MSR_MTRRfix4K_E0000             0x26c
+#define MSR_MTRRfix4K_E8000             0x26d
+#define MSR_MTRRfix4K_F0000             0x26e
+#define MSR_MTRRfix4K_F8000             0x26f
+
+#define MSR_PAT                         0x277
+
+#define MSR_MTRRdefType                 0x2ff
+
+#define MSR_CORE_PERF_FIXED_CTR0        0x309
+#define MSR_CORE_PERF_FIXED_CTR1        0x30a
+#define MSR_CORE_PERF_FIXED_CTR2        0x30b
+#define MSR_CORE_PERF_FIXED_CTR_CTRL    0x38d
+#define MSR_CORE_PERF_GLOBAL_STATUS     0x38e
+#define MSR_CORE_PERF_GLOBAL_CTRL       0x38f
+#define MSR_CORE_PERF_GLOBAL_OVF_CTRL   0x390
+
+#define MSR_MC0_CTL                     0x400
+#define MSR_MC0_STATUS                  0x401
+#define MSR_MC0_ADDR                    0x402
+#define MSR_MC0_MISC                    0x403
+
+#define MSR_EFER                        0xc0000080
+
+#define MSR_EFER_SCE   (1 << 0)
+#define MSR_EFER_LME   (1 << 8)
+#define MSR_EFER_LMA   (1 << 10)
+#define MSR_EFER_NXE   (1 << 11)
+#define MSR_EFER_SVME  (1 << 12)
+#define MSR_EFER_FFXSR (1 << 14)
+
+#define MSR_STAR                        0xc0000081
+#define MSR_LSTAR                       0xc0000082
+#define MSR_CSTAR                       0xc0000083
+#define MSR_FMASK                       0xc0000084
+#define MSR_FSBASE                      0xc0000100
+#define MSR_GSBASE                      0xc0000101
+#define MSR_KERNELGSBASE                0xc0000102
+#define MSR_TSC_AUX                     0xc0000103
+
+#define MSR_VM_HSAVE_PA                 0xc0010117
+
+#define MSR_IA32_BNDCFGS                0x00000d90
+
+#define XSTATE_FP                       (1ULL << 0)
+#define XSTATE_SSE                      (1ULL << 1)
+#define XSTATE_YMM                      (1ULL << 2)
+#define XSTATE_BNDREGS                  (1ULL << 3)
+#define XSTATE_BNDCSR                   (1ULL << 4)
+
+
+/* CPUID feature words */
+typedef enum FeatureWord {
+    FEAT_1_EDX,         /* CPUID[1].EDX */
+    FEAT_1_ECX,         /* CPUID[1].ECX */
+    FEAT_7_0_EBX,       /* CPUID[EAX=7,ECX=0].EBX */
+    FEAT_8000_0001_EDX, /* CPUID[8000_0001].EDX */
+    FEAT_8000_0001_ECX, /* CPUID[8000_0001].ECX */
+    FEAT_8000_0007_EDX, /* CPUID[8000_0007].EDX */
+    FEAT_C000_0001_EDX, /* CPUID[C000_0001].EDX */
+    FEAT_KVM,           /* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */
+    FEAT_SVM,           /* CPUID[8000_000A].EDX */
+    FEATURE_WORDS,
+} FeatureWord;
+
+typedef uint32_t FeatureWordArray[FEATURE_WORDS];
+
+/* cpuid_features bits */
+#define CPUID_FP87 (1U << 0)
+#define CPUID_VME  (1U << 1)
+#define CPUID_DE   (1U << 2)
+#define CPUID_PSE  (1U << 3)
+#define CPUID_TSC  (1U << 4)
+#define CPUID_MSR  (1U << 5)
+#define CPUID_PAE  (1U << 6)
+#define CPUID_MCE  (1U << 7)
+#define CPUID_CX8  (1U << 8)
+#define CPUID_APIC (1U << 9)
+#define CPUID_SEP  (1U << 11) /* sysenter/sysexit */
+#define CPUID_MTRR (1U << 12)
+#define CPUID_PGE  (1U << 13)
+#define CPUID_MCA  (1U << 14)
+#define CPUID_CMOV (1U << 15)
+#define CPUID_PAT  (1U << 16)
+#define CPUID_PSE36   (1U << 17)
+#define CPUID_PN   (1U << 18)
+#define CPUID_CLFLUSH (1U << 19)
+#define CPUID_DTS (1U << 21)
+#define CPUID_ACPI (1U << 22)
+#define CPUID_MMX  (1U << 23)
+#define CPUID_FXSR (1U << 24)
+#define CPUID_SSE  (1U << 25)
+#define CPUID_SSE2 (1U << 26)
+#define CPUID_SS (1U << 27)
+#define CPUID_HT (1U << 28)
+#define CPUID_TM (1U << 29)
+#define CPUID_IA64 (1U << 30)
+#define CPUID_PBE (1U << 31)
+
+#define CPUID_EXT_SSE3     (1U << 0)
+#define CPUID_EXT_PCLMULQDQ (1U << 1)
+#define CPUID_EXT_DTES64   (1U << 2)
+#define CPUID_EXT_MONITOR  (1U << 3)
+#define CPUID_EXT_DSCPL    (1U << 4)
+#define CPUID_EXT_VMX      (1U << 5)
+#define CPUID_EXT_SMX      (1U << 6)
+#define CPUID_EXT_EST      (1U << 7)
+#define CPUID_EXT_TM2      (1U << 8)
+#define CPUID_EXT_SSSE3    (1U << 9)
+#define CPUID_EXT_CID      (1U << 10)
+#define CPUID_EXT_FMA      (1U << 12)
+#define CPUID_EXT_CX16     (1U << 13)
+#define CPUID_EXT_XTPR     (1U << 14)
+#define CPUID_EXT_PDCM     (1U << 15)
+#define CPUID_EXT_PCID     (1U << 17)
+#define CPUID_EXT_DCA      (1U << 18)
+#define CPUID_EXT_SSE41    (1U << 19)
+#define CPUID_EXT_SSE42    (1U << 20)
+#define CPUID_EXT_X2APIC   (1U << 21)
+#define CPUID_EXT_MOVBE    (1U << 22)
+#define CPUID_EXT_POPCNT   (1U << 23)
+#define CPUID_EXT_TSC_DEADLINE_TIMER (1U << 24)
+#define CPUID_EXT_AES      (1U << 25)
+#define CPUID_EXT_XSAVE    (1U << 26)
+#define CPUID_EXT_OSXSAVE  (1U << 27)
+#define CPUID_EXT_AVX      (1U << 28)
+#define CPUID_EXT_F16C     (1U << 29)
+#define CPUID_EXT_RDRAND   (1U << 30)
+#define CPUID_EXT_HYPERVISOR  (1U << 31)
+
+#define CPUID_EXT2_FPU     (1U << 0)
+#define CPUID_EXT2_VME     (1U << 1)
+#define CPUID_EXT2_DE      (1U << 2)
+#define CPUID_EXT2_PSE     (1U << 3)
+#define CPUID_EXT2_TSC     (1U << 4)
+#define CPUID_EXT2_MSR     (1U << 5)
+#define CPUID_EXT2_PAE     (1U << 6)
+#define CPUID_EXT2_MCE     (1U << 7)
+#define CPUID_EXT2_CX8     (1U << 8)
+#define CPUID_EXT2_APIC    (1U << 9)
+#define CPUID_EXT2_SYSCALL (1U << 11)
+#define CPUID_EXT2_MTRR    (1U << 12)
+#define CPUID_EXT2_PGE     (1U << 13)
+#define CPUID_EXT2_MCA     (1U << 14)
+#define CPUID_EXT2_CMOV    (1U << 15)
+#define CPUID_EXT2_PAT     (1U << 16)
+#define CPUID_EXT2_PSE36   (1U << 17)
+#define CPUID_EXT2_MP      (1U << 19)
+#define CPUID_EXT2_NX      (1U << 20)
+#define CPUID_EXT2_MMXEXT  (1U << 22)
+#define CPUID_EXT2_MMX     (1U << 23)
+#define CPUID_EXT2_FXSR    (1U << 24)
+#define CPUID_EXT2_FFXSR   (1U << 25)
+#define CPUID_EXT2_PDPE1GB (1U << 26)
+#define CPUID_EXT2_RDTSCP  (1U << 27)
+#define CPUID_EXT2_LM      (1U << 29)
+#define CPUID_EXT2_3DNOWEXT (1U << 30)
+#define CPUID_EXT2_3DNOW   (1U << 31)
+
+/* CPUID[8000_0001].EDX bits that are aliase of CPUID[1].EDX bits on AMD CPUs */
+#define CPUID_EXT2_AMD_ALIASES (CPUID_EXT2_FPU | CPUID_EXT2_VME | \
+                                CPUID_EXT2_DE | CPUID_EXT2_PSE | \
+                                CPUID_EXT2_TSC | CPUID_EXT2_MSR | \
+                                CPUID_EXT2_PAE | CPUID_EXT2_MCE | \
+                                CPUID_EXT2_CX8 | CPUID_EXT2_APIC | \
+                                CPUID_EXT2_MTRR | CPUID_EXT2_PGE | \
+                                CPUID_EXT2_MCA | CPUID_EXT2_CMOV | \
+                                CPUID_EXT2_PAT | CPUID_EXT2_PSE36 | \
+                                CPUID_EXT2_MMX | CPUID_EXT2_FXSR)
+
+#define CPUID_EXT3_LAHF_LM (1U << 0)
+#define CPUID_EXT3_CMP_LEG (1U << 1)
+#define CPUID_EXT3_SVM     (1U << 2)
+#define CPUID_EXT3_EXTAPIC (1U << 3)
+#define CPUID_EXT3_CR8LEG  (1U << 4)
+#define CPUID_EXT3_ABM     (1U << 5)
+#define CPUID_EXT3_SSE4A   (1U << 6)
+#define CPUID_EXT3_MISALIGNSSE (1U << 7)
+#define CPUID_EXT3_3DNOWPREFETCH (1U << 8)
+#define CPUID_EXT3_OSVW    (1U << 9)
+#define CPUID_EXT3_IBS     (1U << 10)
+#define CPUID_EXT3_XOP     (1U << 11)
+#define CPUID_EXT3_SKINIT  (1U << 12)
+#define CPUID_EXT3_WDT     (1U << 13)
+#define CPUID_EXT3_LWP     (1U << 15)
+#define CPUID_EXT3_FMA4    (1U << 16)
+#define CPUID_EXT3_TCE     (1U << 17)
+#define CPUID_EXT3_NODEID  (1U << 19)
+#define CPUID_EXT3_TBM     (1U << 21)
+#define CPUID_EXT3_TOPOEXT (1U << 22)
+#define CPUID_EXT3_PERFCORE (1U << 23)
+#define CPUID_EXT3_PERFNB  (1U << 24)
+
+#define CPUID_SVM_NPT          (1U << 0)
+#define CPUID_SVM_LBRV         (1U << 1)
+#define CPUID_SVM_SVMLOCK      (1U << 2)
+#define CPUID_SVM_NRIPSAVE     (1U << 3)
+#define CPUID_SVM_TSCSCALE     (1U << 4)
+#define CPUID_SVM_VMCBCLEAN    (1U << 5)
+#define CPUID_SVM_FLUSHASID    (1U << 6)
+#define CPUID_SVM_DECODEASSIST (1U << 7)
+#define CPUID_SVM_PAUSEFILTER  (1U << 10)
+#define CPUID_SVM_PFTHRESHOLD  (1U << 12)
+
+#define CPUID_7_0_EBX_FSGSBASE (1U << 0)
+#define CPUID_7_0_EBX_BMI1     (1U << 3)
+#define CPUID_7_0_EBX_HLE      (1U << 4)
+#define CPUID_7_0_EBX_AVX2     (1U << 5)
+#define CPUID_7_0_EBX_SMEP     (1U << 7)
+#define CPUID_7_0_EBX_BMI2     (1U << 8)
+#define CPUID_7_0_EBX_ERMS     (1U << 9)
+#define CPUID_7_0_EBX_INVPCID  (1U << 10)
+#define CPUID_7_0_EBX_RTM      (1U << 11)
+#define CPUID_7_0_EBX_MPX      (1U << 14)
+#define CPUID_7_0_EBX_RDSEED   (1U << 18)
+#define CPUID_7_0_EBX_ADX      (1U << 19)
+#define CPUID_7_0_EBX_SMAP     (1U << 20)
+
+/* CPUID[0x80000007].EDX flags: */
+#define CPUID_APM_INVTSC       (1U << 8)
+
+#define CPUID_VENDOR_SZ      12
+
+#define CPUID_VENDOR_INTEL_1 0x756e6547 /* "Genu" */
+#define CPUID_VENDOR_INTEL_2 0x49656e69 /* "ineI" */
+#define CPUID_VENDOR_INTEL_3 0x6c65746e /* "ntel" */
+#define CPUID_VENDOR_INTEL "GenuineIntel"
+
+#define CPUID_VENDOR_AMD_1   0x68747541 /* "Auth" */
+#define CPUID_VENDOR_AMD_2   0x69746e65 /* "enti" */
+#define CPUID_VENDOR_AMD_3   0x444d4163 /* "cAMD" */
+#define CPUID_VENDOR_AMD   "AuthenticAMD"
+
+#define CPUID_VENDOR_VIA   "CentaurHauls"
+
+#define CPUID_MWAIT_IBE     (1U << 1) /* Interrupts can exit capability */
+#define CPUID_MWAIT_EMX     (1U << 0) /* enumeration supported */
+
+#ifndef HYPERV_SPINLOCK_NEVER_RETRY
+#define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
+#endif
+
+#define EXCP00_DIVZ	0
+#define EXCP01_DB	1
+#define EXCP02_NMI	2
+#define EXCP03_INT3	3
+#define EXCP04_INTO	4
+#define EXCP05_BOUND	5
+#define EXCP06_ILLOP	6
+#define EXCP07_PREX	7
+#define EXCP08_DBLE	8
+#define EXCP09_XERR	9
+#define EXCP0A_TSS	10
+#define EXCP0B_NOSEG	11
+#define EXCP0C_STACK	12
+#define EXCP0D_GPF	13
+#define EXCP0E_PAGE	14
+#define EXCP10_COPR	16
+#define EXCP11_ALGN	17
+#define EXCP12_MCHK	18
+
+#define EXCP_SYSCALL    0x100 /* only happens in user only emulation
+                                 for syscall instruction */
+
+#endif
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 7ff2a3f..3f299d7 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -22,6 +22,8 @@
 #include "config.h"
 #include "qemu-common.h"
 
+#include "hw/i386/cpu.h"
+
 #ifdef TARGET_X86_64
 #define TARGET_LONG_BITS 64
 #else
@@ -50,564 +52,6 @@
 
 #include "fpu/softfloat.h"
 
-#define R_EAX 0
-#define R_ECX 1
-#define R_EDX 2
-#define R_EBX 3
-#define R_ESP 4
-#define R_EBP 5
-#define R_ESI 6
-#define R_EDI 7
-
-#define R_AL 0
-#define R_CL 1
-#define R_DL 2
-#define R_BL 3
-#define R_AH 4
-#define R_CH 5
-#define R_DH 6
-#define R_BH 7
-
-#define R_ES 0
-#define R_CS 1
-#define R_SS 2
-#define R_DS 3
-#define R_FS 4
-#define R_GS 5
-
-/* segment descriptor fields */
-#define DESC_G_MASK     (1 << 23)
-#define DESC_B_SHIFT    22
-#define DESC_B_MASK     (1 << DESC_B_SHIFT)
-#define DESC_L_SHIFT    21 /* x86_64 only : 64 bit code segment */
-#define DESC_L_MASK     (1 << DESC_L_SHIFT)
-#define DESC_AVL_MASK   (1 << 20)
-#define DESC_P_MASK     (1 << 15)
-#define DESC_DPL_SHIFT  13
-#define DESC_DPL_MASK   (3 << DESC_DPL_SHIFT)
-#define DESC_S_MASK     (1 << 12)
-#define DESC_TYPE_SHIFT 8
-#define DESC_TYPE_MASK  (15 << DESC_TYPE_SHIFT)
-#define DESC_A_MASK     (1 << 8)
-
-#define DESC_CS_MASK    (1 << 11) /* 1=code segment 0=data segment */
-#define DESC_C_MASK     (1 << 10) /* code: conforming */
-#define DESC_R_MASK     (1 << 9)  /* code: readable */
-
-#define DESC_E_MASK     (1 << 10) /* data: expansion direction */
-#define DESC_W_MASK     (1 << 9)  /* data: writable */
-
-#define DESC_TSS_BUSY_MASK (1 << 9)
-
-/* eflags masks */
-#define CC_C    0x0001
-#define CC_P    0x0004
-#define CC_A    0x0010
-#define CC_Z    0x0040
-#define CC_S    0x0080
-#define CC_O    0x0800
-
-#define TF_SHIFT   8
-#define IOPL_SHIFT 12
-#define VM_SHIFT   17
-
-#define TF_MASK                 0x00000100
-#define IF_MASK                 0x00000200
-#define DF_MASK                 0x00000400
-#define IOPL_MASK               0x00003000
-#define NT_MASK                 0x00004000
-#define RF_MASK                 0x00010000
-#define VM_MASK                 0x00020000
-#define AC_MASK                 0x00040000
-#define VIF_MASK                0x00080000
-#define VIP_MASK                0x00100000
-#define ID_MASK                 0x00200000
-
-/* hidden flags - used internally by qemu to represent additional cpu
-   states. Only the INHIBIT_IRQ, SMM and SVMI are not redundant. We
-   avoid using the IOPL_MASK, TF_MASK, VM_MASK and AC_MASK bit
-   positions to ease oring with eflags. */
-/* current cpl */
-#define HF_CPL_SHIFT         0
-/* true if soft mmu is being used */
-#define HF_SOFTMMU_SHIFT     2
-/* true if hardware interrupts must be disabled for next instruction */
-#define HF_INHIBIT_IRQ_SHIFT 3
-/* 16 or 32 segments */
-#define HF_CS32_SHIFT        4
-#define HF_SS32_SHIFT        5
-/* zero base for DS, ES and SS : can be '0' only in 32 bit CS segment */
-#define HF_ADDSEG_SHIFT      6
-/* copy of CR0.PE (protected mode) */
-#define HF_PE_SHIFT          7
-#define HF_TF_SHIFT          8 /* must be same as eflags */
-#define HF_MP_SHIFT          9 /* the order must be MP, EM, TS */
-#define HF_EM_SHIFT         10
-#define HF_TS_SHIFT         11
-#define HF_IOPL_SHIFT       12 /* must be same as eflags */
-#define HF_LMA_SHIFT        14 /* only used on x86_64: long mode active */
-#define HF_CS64_SHIFT       15 /* only used on x86_64: 64 bit code segment  */
-#define HF_RF_SHIFT         16 /* must be same as eflags */
-#define HF_VM_SHIFT         17 /* must be same as eflags */
-#define HF_AC_SHIFT         18 /* must be same as eflags */
-#define HF_SMM_SHIFT        19 /* CPU in SMM mode */
-#define HF_SVME_SHIFT       20 /* SVME enabled (copy of EFER.SVME) */
-#define HF_SVMI_SHIFT       21 /* SVM intercepts are active */
-#define HF_OSFXSR_SHIFT     22 /* CR4.OSFXSR */
-#define HF_SMAP_SHIFT       23 /* CR4.SMAP */
-
-#define HF_CPL_MASK          (3 << HF_CPL_SHIFT)
-#define HF_SOFTMMU_MASK      (1 << HF_SOFTMMU_SHIFT)
-#define HF_INHIBIT_IRQ_MASK  (1 << HF_INHIBIT_IRQ_SHIFT)
-#define HF_CS32_MASK         (1 << HF_CS32_SHIFT)
-#define HF_SS32_MASK         (1 << HF_SS32_SHIFT)
-#define HF_ADDSEG_MASK       (1 << HF_ADDSEG_SHIFT)
-#define HF_PE_MASK           (1 << HF_PE_SHIFT)
-#define HF_TF_MASK           (1 << HF_TF_SHIFT)
-#define HF_MP_MASK           (1 << HF_MP_SHIFT)
-#define HF_EM_MASK           (1 << HF_EM_SHIFT)
-#define HF_TS_MASK           (1 << HF_TS_SHIFT)
-#define HF_IOPL_MASK         (3 << HF_IOPL_SHIFT)
-#define HF_LMA_MASK          (1 << HF_LMA_SHIFT)
-#define HF_CS64_MASK         (1 << HF_CS64_SHIFT)
-#define HF_RF_MASK           (1 << HF_RF_SHIFT)
-#define HF_VM_MASK           (1 << HF_VM_SHIFT)
-#define HF_AC_MASK           (1 << HF_AC_SHIFT)
-#define HF_SMM_MASK          (1 << HF_SMM_SHIFT)
-#define HF_SVME_MASK         (1 << HF_SVME_SHIFT)
-#define HF_SVMI_MASK         (1 << HF_SVMI_SHIFT)
-#define HF_OSFXSR_MASK       (1 << HF_OSFXSR_SHIFT)
-#define HF_SMAP_MASK         (1 << HF_SMAP_SHIFT)
-
-/* hflags2 */
-
-#define HF2_GIF_SHIFT        0 /* if set CPU takes interrupts */
-#define HF2_HIF_SHIFT        1 /* value of IF_MASK when entering SVM */
-#define HF2_NMI_SHIFT        2 /* CPU serving NMI */
-#define HF2_VINTR_SHIFT      3 /* value of V_INTR_MASKING bit */
-
-#define HF2_GIF_MASK          (1 << HF2_GIF_SHIFT)
-#define HF2_HIF_MASK          (1 << HF2_HIF_SHIFT)
-#define HF2_NMI_MASK          (1 << HF2_NMI_SHIFT)
-#define HF2_VINTR_MASK        (1 << HF2_VINTR_SHIFT)
-
-#define CR0_PE_SHIFT 0
-#define CR0_MP_SHIFT 1
-
-#define CR0_PE_MASK  (1U << 0)
-#define CR0_MP_MASK  (1U << 1)
-#define CR0_EM_MASK  (1U << 2)
-#define CR0_TS_MASK  (1U << 3)
-#define CR0_ET_MASK  (1U << 4)
-#define CR0_NE_MASK  (1U << 5)
-#define CR0_WP_MASK  (1U << 16)
-#define CR0_AM_MASK  (1U << 18)
-#define CR0_PG_MASK  (1U << 31)
-
-#define CR4_VME_MASK  (1U << 0)
-#define CR4_PVI_MASK  (1U << 1)
-#define CR4_TSD_MASK  (1U << 2)
-#define CR4_DE_MASK   (1U << 3)
-#define CR4_PSE_MASK  (1U << 4)
-#define CR4_PAE_MASK  (1U << 5)
-#define CR4_MCE_MASK  (1U << 6)
-#define CR4_PGE_MASK  (1U << 7)
-#define CR4_PCE_MASK  (1U << 8)
-#define CR4_OSFXSR_SHIFT 9
-#define CR4_OSFXSR_MASK (1U << CR4_OSFXSR_SHIFT)
-#define CR4_OSXMMEXCPT_MASK  (1U << 10)
-#define CR4_VMXE_MASK   (1U << 13)
-#define CR4_SMXE_MASK   (1U << 14)
-#define CR4_FSGSBASE_MASK (1U << 16)
-#define CR4_PCIDE_MASK  (1U << 17)
-#define CR4_OSXSAVE_MASK (1U << 18)
-#define CR4_SMEP_MASK   (1U << 20)
-#define CR4_SMAP_MASK   (1U << 21)
-
-#define DR6_BD          (1 << 13)
-#define DR6_BS          (1 << 14)
-#define DR6_BT          (1 << 15)
-#define DR6_FIXED_1     0xffff0ff0
-
-#define DR7_GD          (1 << 13)
-#define DR7_TYPE_SHIFT  16
-#define DR7_LEN_SHIFT   18
-#define DR7_FIXED_1     0x00000400
-#define DR7_LOCAL_BP_MASK    0x55
-#define DR7_MAX_BP           4
-#define DR7_TYPE_BP_INST     0x0
-#define DR7_TYPE_DATA_WR     0x1
-#define DR7_TYPE_IO_RW       0x2
-#define DR7_TYPE_DATA_RW     0x3
-
-#define PG_PRESENT_BIT  0
-#define PG_RW_BIT       1
-#define PG_USER_BIT     2
-#define PG_PWT_BIT      3
-#define PG_PCD_BIT      4
-#define PG_ACCESSED_BIT 5
-#define PG_DIRTY_BIT    6
-#define PG_PSE_BIT      7
-#define PG_GLOBAL_BIT   8
-#define PG_PSE_PAT_BIT  12
-#define PG_NX_BIT       63
-
-#define PG_PRESENT_MASK  (1 << PG_PRESENT_BIT)
-#define PG_RW_MASK       (1 << PG_RW_BIT)
-#define PG_USER_MASK     (1 << PG_USER_BIT)
-#define PG_PWT_MASK      (1 << PG_PWT_BIT)
-#define PG_PCD_MASK      (1 << PG_PCD_BIT)
-#define PG_ACCESSED_MASK (1 << PG_ACCESSED_BIT)
-#define PG_DIRTY_MASK    (1 << PG_DIRTY_BIT)
-#define PG_PSE_MASK      (1 << PG_PSE_BIT)
-#define PG_GLOBAL_MASK   (1 << PG_GLOBAL_BIT)
-#define PG_PSE_PAT_MASK  (1 << PG_PSE_PAT_BIT)
-#define PG_ADDRESS_MASK  0x000ffffffffff000LL
-#define PG_HI_RSVD_MASK  (PG_ADDRESS_MASK & ~PHYS_ADDR_MASK)
-#define PG_HI_USER_MASK  0x7ff0000000000000LL
-#define PG_NX_MASK       (1LL << PG_NX_BIT)
-
-#define PG_ERROR_W_BIT     1
-
-#define PG_ERROR_P_MASK    0x01
-#define PG_ERROR_W_MASK    (1 << PG_ERROR_W_BIT)
-#define PG_ERROR_U_MASK    0x04
-#define PG_ERROR_RSVD_MASK 0x08
-#define PG_ERROR_I_D_MASK  0x10
-
-#define MCG_CTL_P       (1ULL<<8)   /* MCG_CAP register available */
-#define MCG_SER_P       (1ULL<<24) /* MCA recovery/new status bits */
-
-#define MCE_CAP_DEF     (MCG_CTL_P|MCG_SER_P)
-#define MCE_BANKS_DEF   10
-
-#define MCG_STATUS_RIPV (1ULL<<0)   /* restart ip valid */
-#define MCG_STATUS_EIPV (1ULL<<1)   /* ip points to correct instruction */
-#define MCG_STATUS_MCIP (1ULL<<2)   /* machine check in progress */
-
-#define MCI_STATUS_VAL   (1ULL<<63)  /* valid error */
-#define MCI_STATUS_OVER  (1ULL<<62)  /* previous errors lost */
-#define MCI_STATUS_UC    (1ULL<<61)  /* uncorrected error */
-#define MCI_STATUS_EN    (1ULL<<60)  /* error enabled */
-#define MCI_STATUS_MISCV (1ULL<<59)  /* misc error reg. valid */
-#define MCI_STATUS_ADDRV (1ULL<<58)  /* addr reg. valid */
-#define MCI_STATUS_PCC   (1ULL<<57)  /* processor context corrupt */
-#define MCI_STATUS_S     (1ULL<<56)  /* Signaled machine check */
-#define MCI_STATUS_AR    (1ULL<<55)  /* Action required */
-
-/* MISC register defines */
-#define MCM_ADDR_SEGOFF  0      /* segment offset */
-#define MCM_ADDR_LINEAR  1      /* linear address */
-#define MCM_ADDR_PHYS    2      /* physical address */
-#define MCM_ADDR_MEM     3      /* memory address */
-#define MCM_ADDR_GENERIC 7      /* generic */
-
-#define MSR_IA32_TSC                    0x10
-#define MSR_IA32_APICBASE               0x1b
-#define MSR_IA32_APICBASE_BSP           (1<<8)
-#define MSR_IA32_APICBASE_ENABLE        (1<<11)
-#define MSR_IA32_APICBASE_BASE          (0xfffff<<12)
-#define MSR_IA32_FEATURE_CONTROL        0x0000003a
-#define MSR_TSC_ADJUST                  0x0000003b
-#define MSR_IA32_TSCDEADLINE            0x6e0
-
-#define MSR_P6_PERFCTR0                 0xc1
-
-#define MSR_MTRRcap                     0xfe
-#define MSR_MTRRcap_VCNT                8
-#define MSR_MTRRcap_FIXRANGE_SUPPORT    (1 << 8)
-#define MSR_MTRRcap_WC_SUPPORTED        (1 << 10)
-
-#define MSR_IA32_SYSENTER_CS            0x174
-#define MSR_IA32_SYSENTER_ESP           0x175
-#define MSR_IA32_SYSENTER_EIP           0x176
-
-#define MSR_MCG_CAP                     0x179
-#define MSR_MCG_STATUS                  0x17a
-#define MSR_MCG_CTL                     0x17b
-
-#define MSR_P6_EVNTSEL0                 0x186
-
-#define MSR_IA32_PERF_STATUS            0x198
-
-#define MSR_IA32_MISC_ENABLE            0x1a0
-/* Indicates good rep/movs microcode on some processors: */
-#define MSR_IA32_MISC_ENABLE_DEFAULT    1
-
-#define MSR_MTRRphysBase(reg)           (0x200 + 2 * (reg))
-#define MSR_MTRRphysMask(reg)           (0x200 + 2 * (reg) + 1)
-
-#define MSR_MTRRfix64K_00000            0x250
-#define MSR_MTRRfix16K_80000            0x258
-#define MSR_MTRRfix16K_A0000            0x259
-#define MSR_MTRRfix4K_C0000             0x268
-#define MSR_MTRRfix4K_C8000             0x269
-#define MSR_MTRRfix4K_D0000             0x26a
-#define MSR_MTRRfix4K_D8000             0x26b
-#define MSR_MTRRfix4K_E0000             0x26c
-#define MSR_MTRRfix4K_E8000             0x26d
-#define MSR_MTRRfix4K_F0000             0x26e
-#define MSR_MTRRfix4K_F8000             0x26f
-
-#define MSR_PAT                         0x277
-
-#define MSR_MTRRdefType                 0x2ff
-
-#define MSR_CORE_PERF_FIXED_CTR0        0x309
-#define MSR_CORE_PERF_FIXED_CTR1        0x30a
-#define MSR_CORE_PERF_FIXED_CTR2        0x30b
-#define MSR_CORE_PERF_FIXED_CTR_CTRL    0x38d
-#define MSR_CORE_PERF_GLOBAL_STATUS     0x38e
-#define MSR_CORE_PERF_GLOBAL_CTRL       0x38f
-#define MSR_CORE_PERF_GLOBAL_OVF_CTRL   0x390
-
-#define MSR_MC0_CTL                     0x400
-#define MSR_MC0_STATUS                  0x401
-#define MSR_MC0_ADDR                    0x402
-#define MSR_MC0_MISC                    0x403
-
-#define MSR_EFER                        0xc0000080
-
-#define MSR_EFER_SCE   (1 << 0)
-#define MSR_EFER_LME   (1 << 8)
-#define MSR_EFER_LMA   (1 << 10)
-#define MSR_EFER_NXE   (1 << 11)
-#define MSR_EFER_SVME  (1 << 12)
-#define MSR_EFER_FFXSR (1 << 14)
-
-#define MSR_STAR                        0xc0000081
-#define MSR_LSTAR                       0xc0000082
-#define MSR_CSTAR                       0xc0000083
-#define MSR_FMASK                       0xc0000084
-#define MSR_FSBASE                      0xc0000100
-#define MSR_GSBASE                      0xc0000101
-#define MSR_KERNELGSBASE                0xc0000102
-#define MSR_TSC_AUX                     0xc0000103
-
-#define MSR_VM_HSAVE_PA                 0xc0010117
-
-#define MSR_IA32_BNDCFGS                0x00000d90
-
-#define XSTATE_FP                       (1ULL << 0)
-#define XSTATE_SSE                      (1ULL << 1)
-#define XSTATE_YMM                      (1ULL << 2)
-#define XSTATE_BNDREGS                  (1ULL << 3)
-#define XSTATE_BNDCSR                   (1ULL << 4)
-
-
-/* CPUID feature words */
-typedef enum FeatureWord {
-    FEAT_1_EDX,         /* CPUID[1].EDX */
-    FEAT_1_ECX,         /* CPUID[1].ECX */
-    FEAT_7_0_EBX,       /* CPUID[EAX=7,ECX=0].EBX */
-    FEAT_8000_0001_EDX, /* CPUID[8000_0001].EDX */
-    FEAT_8000_0001_ECX, /* CPUID[8000_0001].ECX */
-    FEAT_8000_0007_EDX, /* CPUID[8000_0007].EDX */
-    FEAT_C000_0001_EDX, /* CPUID[C000_0001].EDX */
-    FEAT_KVM,           /* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */
-    FEAT_SVM,           /* CPUID[8000_000A].EDX */
-    FEATURE_WORDS,
-} FeatureWord;
-
-typedef uint32_t FeatureWordArray[FEATURE_WORDS];
-
-/* cpuid_features bits */
-#define CPUID_FP87 (1U << 0)
-#define CPUID_VME  (1U << 1)
-#define CPUID_DE   (1U << 2)
-#define CPUID_PSE  (1U << 3)
-#define CPUID_TSC  (1U << 4)
-#define CPUID_MSR  (1U << 5)
-#define CPUID_PAE  (1U << 6)
-#define CPUID_MCE  (1U << 7)
-#define CPUID_CX8  (1U << 8)
-#define CPUID_APIC (1U << 9)
-#define CPUID_SEP  (1U << 11) /* sysenter/sysexit */
-#define CPUID_MTRR (1U << 12)
-#define CPUID_PGE  (1U << 13)
-#define CPUID_MCA  (1U << 14)
-#define CPUID_CMOV (1U << 15)
-#define CPUID_PAT  (1U << 16)
-#define CPUID_PSE36   (1U << 17)
-#define CPUID_PN   (1U << 18)
-#define CPUID_CLFLUSH (1U << 19)
-#define CPUID_DTS (1U << 21)
-#define CPUID_ACPI (1U << 22)
-#define CPUID_MMX  (1U << 23)
-#define CPUID_FXSR (1U << 24)
-#define CPUID_SSE  (1U << 25)
-#define CPUID_SSE2 (1U << 26)
-#define CPUID_SS (1U << 27)
-#define CPUID_HT (1U << 28)
-#define CPUID_TM (1U << 29)
-#define CPUID_IA64 (1U << 30)
-#define CPUID_PBE (1U << 31)
-
-#define CPUID_EXT_SSE3     (1U << 0)
-#define CPUID_EXT_PCLMULQDQ (1U << 1)
-#define CPUID_EXT_DTES64   (1U << 2)
-#define CPUID_EXT_MONITOR  (1U << 3)
-#define CPUID_EXT_DSCPL    (1U << 4)
-#define CPUID_EXT_VMX      (1U << 5)
-#define CPUID_EXT_SMX      (1U << 6)
-#define CPUID_EXT_EST      (1U << 7)
-#define CPUID_EXT_TM2      (1U << 8)
-#define CPUID_EXT_SSSE3    (1U << 9)
-#define CPUID_EXT_CID      (1U << 10)
-#define CPUID_EXT_FMA      (1U << 12)
-#define CPUID_EXT_CX16     (1U << 13)
-#define CPUID_EXT_XTPR     (1U << 14)
-#define CPUID_EXT_PDCM     (1U << 15)
-#define CPUID_EXT_PCID     (1U << 17)
-#define CPUID_EXT_DCA      (1U << 18)
-#define CPUID_EXT_SSE41    (1U << 19)
-#define CPUID_EXT_SSE42    (1U << 20)
-#define CPUID_EXT_X2APIC   (1U << 21)
-#define CPUID_EXT_MOVBE    (1U << 22)
-#define CPUID_EXT_POPCNT   (1U << 23)
-#define CPUID_EXT_TSC_DEADLINE_TIMER (1U << 24)
-#define CPUID_EXT_AES      (1U << 25)
-#define CPUID_EXT_XSAVE    (1U << 26)
-#define CPUID_EXT_OSXSAVE  (1U << 27)
-#define CPUID_EXT_AVX      (1U << 28)
-#define CPUID_EXT_F16C     (1U << 29)
-#define CPUID_EXT_RDRAND   (1U << 30)
-#define CPUID_EXT_HYPERVISOR  (1U << 31)
-
-#define CPUID_EXT2_FPU     (1U << 0)
-#define CPUID_EXT2_VME     (1U << 1)
-#define CPUID_EXT2_DE      (1U << 2)
-#define CPUID_EXT2_PSE     (1U << 3)
-#define CPUID_EXT2_TSC     (1U << 4)
-#define CPUID_EXT2_MSR     (1U << 5)
-#define CPUID_EXT2_PAE     (1U << 6)
-#define CPUID_EXT2_MCE     (1U << 7)
-#define CPUID_EXT2_CX8     (1U << 8)
-#define CPUID_EXT2_APIC    (1U << 9)
-#define CPUID_EXT2_SYSCALL (1U << 11)
-#define CPUID_EXT2_MTRR    (1U << 12)
-#define CPUID_EXT2_PGE     (1U << 13)
-#define CPUID_EXT2_MCA     (1U << 14)
-#define CPUID_EXT2_CMOV    (1U << 15)
-#define CPUID_EXT2_PAT     (1U << 16)
-#define CPUID_EXT2_PSE36   (1U << 17)
-#define CPUID_EXT2_MP      (1U << 19)
-#define CPUID_EXT2_NX      (1U << 20)
-#define CPUID_EXT2_MMXEXT  (1U << 22)
-#define CPUID_EXT2_MMX     (1U << 23)
-#define CPUID_EXT2_FXSR    (1U << 24)
-#define CPUID_EXT2_FFXSR   (1U << 25)
-#define CPUID_EXT2_PDPE1GB (1U << 26)
-#define CPUID_EXT2_RDTSCP  (1U << 27)
-#define CPUID_EXT2_LM      (1U << 29)
-#define CPUID_EXT2_3DNOWEXT (1U << 30)
-#define CPUID_EXT2_3DNOW   (1U << 31)
-
-/* CPUID[8000_0001].EDX bits that are aliase of CPUID[1].EDX bits on AMD CPUs */
-#define CPUID_EXT2_AMD_ALIASES (CPUID_EXT2_FPU | CPUID_EXT2_VME | \
-                                CPUID_EXT2_DE | CPUID_EXT2_PSE | \
-                                CPUID_EXT2_TSC | CPUID_EXT2_MSR | \
-                                CPUID_EXT2_PAE | CPUID_EXT2_MCE | \
-                                CPUID_EXT2_CX8 | CPUID_EXT2_APIC | \
-                                CPUID_EXT2_MTRR | CPUID_EXT2_PGE | \
-                                CPUID_EXT2_MCA | CPUID_EXT2_CMOV | \
-                                CPUID_EXT2_PAT | CPUID_EXT2_PSE36 | \
-                                CPUID_EXT2_MMX | CPUID_EXT2_FXSR)
-
-#define CPUID_EXT3_LAHF_LM (1U << 0)
-#define CPUID_EXT3_CMP_LEG (1U << 1)
-#define CPUID_EXT3_SVM     (1U << 2)
-#define CPUID_EXT3_EXTAPIC (1U << 3)
-#define CPUID_EXT3_CR8LEG  (1U << 4)
-#define CPUID_EXT3_ABM     (1U << 5)
-#define CPUID_EXT3_SSE4A   (1U << 6)
-#define CPUID_EXT3_MISALIGNSSE (1U << 7)
-#define CPUID_EXT3_3DNOWPREFETCH (1U << 8)
-#define CPUID_EXT3_OSVW    (1U << 9)
-#define CPUID_EXT3_IBS     (1U << 10)
-#define CPUID_EXT3_XOP     (1U << 11)
-#define CPUID_EXT3_SKINIT  (1U << 12)
-#define CPUID_EXT3_WDT     (1U << 13)
-#define CPUID_EXT3_LWP     (1U << 15)
-#define CPUID_EXT3_FMA4    (1U << 16)
-#define CPUID_EXT3_TCE     (1U << 17)
-#define CPUID_EXT3_NODEID  (1U << 19)
-#define CPUID_EXT3_TBM     (1U << 21)
-#define CPUID_EXT3_TOPOEXT (1U << 22)
-#define CPUID_EXT3_PERFCORE (1U << 23)
-#define CPUID_EXT3_PERFNB  (1U << 24)
-
-#define CPUID_SVM_NPT          (1U << 0)
-#define CPUID_SVM_LBRV         (1U << 1)
-#define CPUID_SVM_SVMLOCK      (1U << 2)
-#define CPUID_SVM_NRIPSAVE     (1U << 3)
-#define CPUID_SVM_TSCSCALE     (1U << 4)
-#define CPUID_SVM_VMCBCLEAN    (1U << 5)
-#define CPUID_SVM_FLUSHASID    (1U << 6)
-#define CPUID_SVM_DECODEASSIST (1U << 7)
-#define CPUID_SVM_PAUSEFILTER  (1U << 10)
-#define CPUID_SVM_PFTHRESHOLD  (1U << 12)
-
-#define CPUID_7_0_EBX_FSGSBASE (1U << 0)
-#define CPUID_7_0_EBX_BMI1     (1U << 3)
-#define CPUID_7_0_EBX_HLE      (1U << 4)
-#define CPUID_7_0_EBX_AVX2     (1U << 5)
-#define CPUID_7_0_EBX_SMEP     (1U << 7)
-#define CPUID_7_0_EBX_BMI2     (1U << 8)
-#define CPUID_7_0_EBX_ERMS     (1U << 9)
-#define CPUID_7_0_EBX_INVPCID  (1U << 10)
-#define CPUID_7_0_EBX_RTM      (1U << 11)
-#define CPUID_7_0_EBX_MPX      (1U << 14)
-#define CPUID_7_0_EBX_RDSEED   (1U << 18)
-#define CPUID_7_0_EBX_ADX      (1U << 19)
-#define CPUID_7_0_EBX_SMAP     (1U << 20)
-
-/* CPUID[0x80000007].EDX flags: */
-#define CPUID_APM_INVTSC       (1U << 8)
-
-#define CPUID_VENDOR_SZ      12
-
-#define CPUID_VENDOR_INTEL_1 0x756e6547 /* "Genu" */
-#define CPUID_VENDOR_INTEL_2 0x49656e69 /* "ineI" */
-#define CPUID_VENDOR_INTEL_3 0x6c65746e /* "ntel" */
-#define CPUID_VENDOR_INTEL "GenuineIntel"
-
-#define CPUID_VENDOR_AMD_1   0x68747541 /* "Auth" */
-#define CPUID_VENDOR_AMD_2   0x69746e65 /* "enti" */
-#define CPUID_VENDOR_AMD_3   0x444d4163 /* "cAMD" */
-#define CPUID_VENDOR_AMD   "AuthenticAMD"
-
-#define CPUID_VENDOR_VIA   "CentaurHauls"
-
-#define CPUID_MWAIT_IBE     (1U << 1) /* Interrupts can exit capability */
-#define CPUID_MWAIT_EMX     (1U << 0) /* enumeration supported */
-
-#ifndef HYPERV_SPINLOCK_NEVER_RETRY
-#define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
-#endif
-
-#define EXCP00_DIVZ	0
-#define EXCP01_DB	1
-#define EXCP02_NMI	2
-#define EXCP03_INT3	3
-#define EXCP04_INTO	4
-#define EXCP05_BOUND	5
-#define EXCP06_ILLOP	6
-#define EXCP07_PREX	7
-#define EXCP08_DBLE	8
-#define EXCP09_XERR	9
-#define EXCP0A_TSS	10
-#define EXCP0B_NOSEG	11
-#define EXCP0C_STACK	12
-#define EXCP0D_GPF	13
-#define EXCP0E_PAGE	14
-#define EXCP10_COPR	16
-#define EXCP11_ALGN	17
-#define EXCP12_MCHK	18
-
-#define EXCP_SYSCALL    0x100 /* only happens in user only emulation
-                                 for syscall instruction */
-
 /* i386-specific interrupt pending bits.  */
 #define CPU_INTERRUPT_POLL      CPU_INTERRUPT_TGT_EXT_1
 #define CPU_INTERRUPT_SMI       CPU_INTERRUPT_TGT_EXT_2
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 31/33] pc: Add default KVM features fields to PCMachineClass
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (29 preceding siblings ...)
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 30/33] target-i386: Move some declarations to hw/i386/cpu.h Eduardo Habkost
@ 2014-08-14 19:26 ` Eduardo Habkost
  2014-08-14 21:09   ` Michael S. Tsirkin
  2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 32/33] pc: Eliminate pc_compat_*() functions Eduardo Habkost
  2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 33/33] piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init() Eduardo Habkost
  32 siblings, 1 reply; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

With the new fields, the x86_cpu_compat_disable_kvm_features() calls on
pc_compat_*() functions can be replace by simple field initialization on
class_init functions. This gets us one step closer to eliminating all
pc_compat_*() functions.

Those new fields may eventually become simple compat_props properties,
if we QOMify the accelerator code, and move the KVM-specific CPUID code
to a x86-kvm-accel class.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc.c         | 15 +++++++++++++++
 hw/i386/pc_piix.c    |  7 ++++---
 hw/i386/pc_q35.c     |  2 +-
 include/hw/i386/pc.h |  3 +++
 target-i386/cpu.c    | 25 ++++++++++++-------------
 target-i386/cpu.h    |  2 +-
 6 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index dba7f62..a0eaaf6 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -24,6 +24,7 @@
 #include "hw/hw.h"
 #include "hw/i386/pc.h"
 #include "hw/char/serial.h"
+#include "hw/i386/cpu.h"
 #include "hw/i386/apic.h"
 #include "hw/block/fdc.h"
 #include "hw/ide.h"
@@ -1020,6 +1021,10 @@ void pc_cpus_init(PCMachineState *pcms, DeviceState *icc_bridge)
     Error *error = NULL;
     unsigned long apic_id_limit;
     MachineState *machine = MACHINE(pcms);
+    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
+
+    x86_cpu_set_kvm_defaults(pcmc->kvm_default_features,
+                             pcmc->kvm_default_unset_features);
 
     /* init CPUs */
     current_cpu_model = machine->cpu_model;
@@ -1687,6 +1692,16 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     pcmc->gigabyte_align = true;
     pcmc->has_reserved_memory = true;
     pcmc->kvmclock_enabled = true;
+    pcmc->kvm_default_features[FEAT_KVM] =
+        (1 << KVM_FEATURE_CLOCKSOURCE) |
+        (1 << KVM_FEATURE_NOP_IO_DELAY) |
+        (1 << KVM_FEATURE_CLOCKSOURCE2) |
+        (1 << KVM_FEATURE_ASYNC_PF) |
+        (1 << KVM_FEATURE_STEAL_TIME) |
+        (1 << KVM_FEATURE_PV_EOI) |
+        (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT),
+    pcmc->kvm_default_features[FEAT_1_ECX] = CPUID_EXT_X2APIC,
+    pcmc->kvm_default_unset_features[FEAT_1_ECX] = CPUID_EXT_MONITOR,
 
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     mc->default_boot_order = "cad";
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 988583c..9ec63d5 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -298,7 +298,6 @@ static void pc_compat_2_0(MachineState *machine)
 static void pc_compat_1_7(MachineState *machine)
 {
     pc_compat_2_0(machine);
-    x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
 }
 
 static void pc_compat_1_6(MachineState *machine)
@@ -325,7 +324,6 @@ static void pc_compat_1_3(MachineState *machine)
 static void pc_compat_1_2(MachineState *machine)
 {
     pc_compat_1_3(machine);
-    x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
 }
 
 /* PC compat function for pc-0.10 to pc-0.13 */
@@ -386,7 +384,6 @@ static void pc_init_pci_no_kvmclock(MachineState *machine)
 
 static void pc_init_isa(MachineState *machine)
 {
-    x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
     pc_init1(machine);
 }
 
@@ -494,6 +491,7 @@ static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
     pcmc->smbios_defaults = false;
     pcmc->gigabyte_align = false;
     pcmc->legacy_acpi_table_size = 6414;
+    pcmc->kvm_default_features[FEAT_1_ECX] &= ~CPUID_EXT_X2APIC;
 }
 
 static const TypeInfo pc_i440fx_machine_v1_7_type_info = {
@@ -633,6 +631,7 @@ static const TypeInfo pc_machine_v1_3_type_info = {
 static void pc_machine_v1_2_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     static GlobalProperty compat_props[] = {
         PC_COMPAT_1_2,
         { /* end of list */ }
@@ -641,6 +640,7 @@ static void pc_machine_v1_2_class_init(ObjectClass *oc, void *data)
     mc->init = pc_init_pci_1_2;
     mc->name = "pc-1.2";
     machine_class_add_compat_props(mc, compat_props);
+    pcmc->kvm_default_features[FEAT_KVM] &= ~KVM_FEATURE_PV_EOI;
 }
 
 static const TypeInfo pc_machine_v1_2_type_info = {
@@ -984,6 +984,7 @@ static void isapc_machine_class_init(ObjectClass *oc, void *data)
     pcmc->smbios_legacy_mode = true;
     pcmc->has_reserved_memory = false;
     pcmc->compat_apic_id_mode = true;
+    pcmc->kvm_default_features[FEAT_KVM] &= ~KVM_FEATURE_PV_EOI;
 }
 
 static const TypeInfo isapc_machine_type_info = {
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 2ebd598..5878964 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -271,7 +271,6 @@ static void pc_compat_2_0(MachineState *machine)
 static void pc_compat_1_7(MachineState *machine)
 {
     pc_compat_2_0(machine);
-    x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
 }
 
 static void pc_compat_1_6(MachineState *machine)
@@ -389,6 +388,7 @@ static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
     mc->name = "pc-q35-1.7";
     pcmc->smbios_defaults = false;
     pcmc->gigabyte_align = false;
+    pcmc->kvm_default_features[FEAT_1_ECX] &= ~CPUID_EXT_X2APIC;
 }
 
 static TypeInfo pc_q35_machine_v1_7_type_info = {
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 460ff21..b7f36d6 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -8,6 +8,7 @@
 #include "hw/block/fdc.h"
 #include "net/net.h"
 #include "hw/i386/ioapic.h"
+#include "hw/i386/cpu.h"
 #include "hw/boards.h"
 
 #include "qemu/range.h"
@@ -66,6 +67,8 @@ struct PCMachineClass {
     bool has_reserved_memory;
     bool kvmclock_enabled;
     bool compat_apic_id_mode;
+    uint32_t kvm_default_features[FEATURE_WORDS];
+    uint32_t kvm_default_unset_features[FEATURE_WORDS];
 };
 
 typedef struct PCMachineState PCMachineState;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e86f99e..e02b0d9 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -446,27 +446,26 @@ typedef struct model_features_t {
 
 /* KVM-specific features that are automatically added to all CPU models
  * when KVM is enabled.
+ *
+ * The default is to enable all KVM features, but machine-types may override it
+ * to keep a stable ABI. See x86_cpu_set_kvm_defaults().
  */
 static uint32_t kvm_default_features[FEATURE_WORDS] = {
-    [FEAT_KVM] = (1 << KVM_FEATURE_CLOCKSOURCE) |
-        (1 << KVM_FEATURE_NOP_IO_DELAY) |
-        (1 << KVM_FEATURE_CLOCKSOURCE2) |
-        (1 << KVM_FEATURE_ASYNC_PF) |
-        (1 << KVM_FEATURE_STEAL_TIME) |
-        (1 << KVM_FEATURE_PV_EOI) |
-        (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT),
-    [FEAT_1_ECX] = CPUID_EXT_X2APIC,
+    [FEAT_KVM] = ~0,
 };
 
 /* Features that are not added by default to any CPU model when KVM is enabled.
  */
-static uint32_t kvm_default_unset_features[FEATURE_WORDS] = {
-    [FEAT_1_ECX] = CPUID_EXT_MONITOR,
-};
+static uint32_t kvm_default_unset_features[FEATURE_WORDS];
 
-void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features)
+/* Override default-enabled and default-disabled KVM features. Used by
+ * machine-type code to ensure a stable ABI.
+ */
+void x86_cpu_set_kvm_defaults(uint32_t *default_set, uint32_t *default_unset)
 {
-    kvm_default_features[w] &= ~features;
+    memcpy(kvm_default_features, default_set, sizeof(kvm_default_features));
+    memcpy(kvm_default_unset_features, default_unset,
+           sizeof(kvm_default_unset_features));
 }
 
 /*
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 3f299d7..2138996 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -741,7 +741,7 @@ void do_smm_enter(X86CPU *cpu);
 
 void cpu_report_tpr_access(CPUX86State *env, TPRAccess access);
 
-void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features);
+void x86_cpu_set_kvm_defaults(uint32_t *default_set, uint32_t *default_unset);
 
 
 /* Return name of 32-bit register, from a R_* constant */
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 32/33] pc: Eliminate pc_compat_*() functions
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (30 preceding siblings ...)
  2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 31/33] pc: Add default KVM features fields to PCMachineClass Eduardo Habkost
@ 2014-08-14 19:26 ` Eduardo Habkost
  2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 33/33] piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init() Eduardo Habkost
  32 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

The pc_compat_*() functions are finally empty, and we can use the same
init function for all piix and q35 subclasses.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c | 108 +-----------------------------------------------------
 hw/i386/pc_q35.c  |  61 +-----------------------------
 2 files changed, 3 insertions(+), 166 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 9ec63d5..293422b 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -291,102 +291,6 @@ static void pc_init1(MachineState *machine)
     }
 }
 
-static void pc_compat_2_0(MachineState *machine)
-{
-}
-
-static void pc_compat_1_7(MachineState *machine)
-{
-    pc_compat_2_0(machine);
-}
-
-static void pc_compat_1_6(MachineState *machine)
-{
-    pc_compat_1_7(machine);
-}
-
-static void pc_compat_1_5(MachineState *machine)
-{
-    pc_compat_1_6(machine);
-}
-
-static void pc_compat_1_4(MachineState *machine)
-{
-    pc_compat_1_5(machine);
-}
-
-static void pc_compat_1_3(MachineState *machine)
-{
-    pc_compat_1_4(machine);
-}
-
-/* PC compat function for pc-0.14 to pc-1.2 */
-static void pc_compat_1_2(MachineState *machine)
-{
-    pc_compat_1_3(machine);
-}
-
-/* PC compat function for pc-0.10 to pc-0.13 */
-static void pc_compat_0_13(MachineState *machine)
-{
-    pc_compat_1_2(machine);
-}
-
-static void pc_init_pci_2_0(MachineState *machine)
-{
-    pc_compat_2_0(machine);
-    pc_init1(machine);
-}
-
-static void pc_init_pci_1_7(MachineState *machine)
-{
-    pc_compat_1_7(machine);
-    pc_init1(machine);
-}
-
-static void pc_init_pci_1_6(MachineState *machine)
-{
-    pc_compat_1_6(machine);
-    pc_init1(machine);
-}
-
-static void pc_init_pci_1_5(MachineState *machine)
-{
-    pc_compat_1_5(machine);
-    pc_init1(machine);
-}
-
-static void pc_init_pci_1_4(MachineState *machine)
-{
-    pc_compat_1_4(machine);
-    pc_init1(machine);
-}
-
-static void pc_init_pci_1_3(MachineState *machine)
-{
-    pc_compat_1_3(machine);
-    pc_init1(machine);
-}
-
-/* PC machine init function for pc-0.14 to pc-1.2 */
-static void pc_init_pci_1_2(MachineState *machine)
-{
-    pc_compat_1_2(machine);
-    pc_init1(machine);
-}
-
-/* PC init function for pc-0.10 to pc-0.13 */
-static void pc_init_pci_no_kvmclock(MachineState *machine)
-{
-    pc_compat_0_13(machine);
-    pc_init1(machine);
-}
-
-static void pc_init_isa(MachineState *machine)
-{
-    pc_init1(machine);
-}
-
 #ifdef CONFIG_XEN
 static void pc_xen_hvm_init(MachineState *machine)
 {
@@ -406,6 +310,7 @@ static void pc_i440fx_machine_class_init(ObjectClass *oc, void *data)
     MachineClass *mc = MACHINE_CLASS(oc);
     mc->desc = "Standard PC (i440FX + PIIX, 1996)";
     mc->hot_add_cpu = pc_hot_add_cpu;
+    mc->init = pc_init1;
 }
 
 #define TYPE_PC_I440FX_MACHINE "pc-i440fx" TYPE_MACHINE_SUFFIX
@@ -422,7 +327,6 @@ static void pc_i440fx_machine_v2_1_class_init(ObjectClass *oc, void *data)
     MachineClass *mc = MACHINE_CLASS(oc);
     mc->default_machine_opts = "firmware=bios-256k.bin";
     mc->alias = "pc";
-    mc->init = pc_init1;
     mc->is_default = 1;
     mc->name = "pc-i440fx-2.1";
 }
@@ -444,7 +348,6 @@ static void pc_i440fx_machine_v2_0_class_init(ObjectClass *oc, void *data)
     pc_i440fx_machine_v2_1_class_init(oc, data);
     mc->alias = NULL;
     mc->is_default = false;
-    mc->init = pc_init_pci_2_0;
     mc->name = "pc-i440fx-2.0";
     machine_class_add_compat_props(mc, compat_props);
     /* This value depends on the actual DSDT and SSDT compiled into
@@ -484,7 +387,6 @@ static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
     };
     pc_i440fx_machine_v2_0_class_init(oc, data);
     mc->default_machine_opts = NULL;
-    mc->init = pc_init_pci_1_7;
     mc->name = "pc-i440fx-1.7";
     mc->option_rom_has_mr = true;
     machine_class_add_compat_props(mc, compat_props);
@@ -509,7 +411,6 @@ static void pc_i440fx_machine_v1_6_class_init(ObjectClass *oc, void *data)
         { /* end of list */ }
     };
     pc_i440fx_machine_v1_7_class_init(oc, data);
-    mc->init = pc_init_pci_1_6;
     mc->name = "pc-i440fx-1.6";
     mc->rom_file_has_mr = false;
     machine_class_add_compat_props(mc, compat_props);
@@ -530,7 +431,6 @@ static void pc_i440fx_machine_v1_5_class_init(ObjectClass *oc, void *data)
         { /* end of list */ }
     };
     pc_i440fx_machine_v1_6_class_init(oc, data);
-    mc->init = pc_init_pci_1_5;
     mc->name = "pc-i440fx-1.5";
     machine_class_add_compat_props(mc, compat_props);
 }
@@ -550,7 +450,6 @@ static void pc_i440fx_machine_v1_4_class_init(ObjectClass *oc, void *data)
     };
     pc_i440fx_machine_v1_5_class_init(oc, data);
     mc->hot_add_cpu = NULL;
-    mc->init = pc_init_pci_1_4;
     mc->name = "pc-i440fx-1.4";
     machine_class_add_compat_props(mc, compat_props);
 }
@@ -589,7 +488,6 @@ static void pc_machine_v1_3_class_init(ObjectClass *oc, void *data)
         { /* end of list */ }
     };
     pc_i440fx_machine_v1_4_class_init(oc, data);
-    mc->init = pc_init_pci_1_3;
     mc->name = "pc-1.3";
     machine_class_add_compat_props(mc, compat_props);
     pcmc->compat_apic_id_mode = true;
@@ -637,7 +535,6 @@ static void pc_machine_v1_2_class_init(ObjectClass *oc, void *data)
         { /* end of list */ }
     };
     pc_machine_v1_3_class_init(oc, data);
-    mc->init = pc_init_pci_1_2;
     mc->name = "pc-1.2";
     machine_class_add_compat_props(mc, compat_props);
     pcmc->kvm_default_features[FEAT_KVM] &= ~KVM_FEATURE_PV_EOI;
@@ -829,7 +726,6 @@ static void pc_machine_v0_13_class_init(ObjectClass *oc, void *data)
         { /* end of list */ }
     };
     pc_machine_v0_14_class_init(oc, data);
-    mc->init = pc_init_pci_no_kvmclock;
     mc->hw_version = "0.13";
     mc->name = "pc-0.13";
     machine_class_add_compat_props(mc, compat_props);
@@ -969,7 +865,7 @@ static void isapc_machine_class_init(ObjectClass *oc, void *data)
         { /* end of list */ }
     };
     mc->desc = "ISA-only PC";
-    mc->init = pc_init_isa;
+    mc->init = pc_init1;
     mc->max_cpus = 1;
     mc->hot_add_cpu = NULL;
     mc->name = "isapc";
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 5878964..771312b 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -264,65 +264,12 @@ static void pc_q35_init(MachineState *machine)
     }
 }
 
-static void pc_compat_2_0(MachineState *machine)
-{
-}
-
-static void pc_compat_1_7(MachineState *machine)
-{
-    pc_compat_2_0(machine);
-}
-
-static void pc_compat_1_6(MachineState *machine)
-{
-    pc_compat_1_7(machine);
-}
-
-static void pc_compat_1_5(MachineState *machine)
-{
-    pc_compat_1_6(machine);
-}
-
-static void pc_compat_1_4(MachineState *machine)
-{
-    pc_compat_1_5(machine);
-}
-
-static void pc_q35_init_2_0(MachineState *machine)
-{
-    pc_compat_2_0(machine);
-    pc_q35_init(machine);
-}
-
-static void pc_q35_init_1_7(MachineState *machine)
-{
-    pc_compat_1_7(machine);
-    pc_q35_init(machine);
-}
-
-static void pc_q35_init_1_6(MachineState *machine)
-{
-    pc_compat_1_6(machine);
-    pc_q35_init(machine);
-}
-
-static void pc_q35_init_1_5(MachineState *machine)
-{
-    pc_compat_1_5(machine);
-    pc_q35_init(machine);
-}
-
-static void pc_q35_init_1_4(MachineState *machine)
-{
-    pc_compat_1_4(machine);
-    pc_q35_init(machine);
-}
-
 static void pc_q35_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
     mc->desc = "Standard PC (Q35 + ICH9, 2009)";
     mc->hot_add_cpu = pc_hot_add_cpu;
+    mc->init = pc_q35_init;
 }
 
 #define TYPE_PC_Q35_MACHINE "pc-q35" TYPE_MACHINE_SUFFIX
@@ -339,7 +286,6 @@ static void pc_q35_machine_v2_1_class_init(ObjectClass *oc, void *data)
     MachineClass *mc = MACHINE_CLASS(oc);
     mc->default_machine_opts = "firmware=bios-256k.bin";
     mc->alias = "q35";
-    mc->init = pc_q35_init;
     mc->name = "pc-q35-2.1";
 }
 
@@ -359,7 +305,6 @@ static void pc_q35_machine_v2_0_class_init(ObjectClass *oc, void *data)
     };
     pc_q35_machine_v2_1_class_init(oc, data);
     mc->alias = NULL;
-    mc->init = pc_q35_init_2_0;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-2.0";
     pcmc->smbios_legacy_mode = true;
@@ -382,7 +327,6 @@ static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
     };
     pc_q35_machine_v2_0_class_init(oc, data);
     mc->default_machine_opts = NULL;
-    mc->init = pc_q35_init_1_7;
     mc->option_rom_has_mr = true;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.7";
@@ -406,7 +350,6 @@ static void pc_q35_machine_v1_6_class_init(ObjectClass *oc, void *data)
         { /* end of list */ }
     };
     pc_q35_machine_v1_7_class_init(oc, data);
-    mc->init = pc_q35_init_1_6;
     mc->rom_file_has_mr = false;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.6";
@@ -427,7 +370,6 @@ static void pc_q35_machine_v1_5_class_init(ObjectClass *oc, void *data)
         { /* end of list */ }
     };
     pc_q35_machine_v1_6_class_init(oc, data);
-    mc->init = pc_q35_init_1_5;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.5";
 }
@@ -447,7 +389,6 @@ static void pc_q35_machine_v1_4_class_init(ObjectClass *oc, void *data)
     };
     pc_q35_machine_v1_5_class_init(oc, data);
     mc->hot_add_cpu = NULL;
-    mc->init = pc_q35_init_1_4;
     machine_class_add_compat_props(mc, compat_props);
     mc->name = "pc-q35-1.4";
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH v4 33/33] piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init()
  2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
                   ` (31 preceding siblings ...)
  2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 32/33] pc: Eliminate pc_compat_*() functions Eduardo Habkost
@ 2014-08-14 19:26 ` Eduardo Habkost
  2014-08-14 20:03   ` Michael S. Tsirkin
  32 siblings, 1 reply; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Alexander Graf, Don Slutz,
	Igor Mammedov, Andreas Färber

Put all the Xen code in a single place.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/i386/pc_piix.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 293422b..89ecb54 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -291,20 +291,6 @@ static void pc_init1(MachineState *machine)
     }
 }
 
-#ifdef CONFIG_XEN
-static void pc_xen_hvm_init(MachineState *machine)
-{
-    PCIBus *bus;
-
-    pc_init1(machine);
-
-    bus = pci_find_primary_bus();
-    if (bus != NULL) {
-        pci_create_simple(bus, -1, "xen-platform");
-    }
-}
-#endif
-
 static void pc_i440fx_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -890,6 +876,18 @@ static const TypeInfo isapc_machine_type_info = {
 };
 
 #ifdef CONFIG_XEN
+static void pc_xen_hvm_init(MachineState *machine)
+{
+    PCIBus *bus;
+
+    pc_init1(machine);
+
+    bus = pci_find_primary_bus();
+    if (bus != NULL) {
+        pci_create_simple(bus, -1, "xen-platform");
+    }
+}
+
 static void xenfv_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH v4 26/33] target-i386: Renove underscores from feature names
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 26/33] target-i386: Renove underscores from feature names Eduardo Habkost
@ 2014-08-14 19:31   ` Michael S. Tsirkin
  2014-08-14 19:32     ` Eduardo Habkost
  0 siblings, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2014-08-14 19:31 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Marcel Apfelbaum, Alexander Graf, Don Slutz, qemu-devel,
	Igor Mammedov, Andreas Färber

s/Renove/Remove/ ?

not that it matters ...

On Thu, Aug 14, 2014 at 04:25:55PM -0300, Eduardo Habkost wrote:
> The underscores will be translated by x86_cpu_parse_featurestr().
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  target-i386/cpu.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index c093168..b005b0d 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -189,7 +189,7 @@ static const char *feature_name[] = {
>  };
>  static const char *ext_feature_name[] = {
>      "pni|sse3" /* Intel,AMD sse3 */, "pclmulqdq|pclmuldq", "dtes64", "monitor",
> -    "ds_cpl", "vmx", "smx", "est",
> +    "ds-cpl", "vmx", "smx", "est",
>      "tm2", "ssse3", "cid", NULL,
>      "fma", "cx16", "xtpr", "pdcm",
>      NULL, "pcid", "dca", "sse4.1|sse4_1",
> @@ -209,17 +209,17 @@ static const char *ext2_feature_name[] = {
>      NULL /* mtrr */, NULL /* pge */, NULL /* mca */, NULL /* cmov */,
>      NULL /* pat */, NULL /* pse36 */, NULL, NULL /* Linux mp */,
>      "nx|xd", NULL, "mmxext", NULL /* mmx */,
> -    NULL /* fxsr */, "fxsr_opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
> +    NULL /* fxsr */, "fxsr-opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
>      NULL, "lm|i64", "3dnowext", "3dnow",
>  };
>  static const char *ext3_feature_name[] = {
> -    "lahf_lm" /* AMD LahfSahf */, "cmp_legacy", "svm", "extapic" /* AMD ExtApicSpace */,
> +    "lahf-lm" /* AMD LahfSahf */, "cmp-legacy", "svm", "extapic" /* AMD ExtApicSpace */,
>      "cr8legacy" /* AMD AltMovCr8 */, "abm", "sse4a", "misalignsse",
>      "3dnowprefetch", "osvw", "ibs", "xop",
>      "skinit", "wdt", NULL, "lwp",
> -    "fma4", "tce", NULL, "nodeid_msr",
> -    NULL, "tbm", "topoext", "perfctr_core",
> -    "perfctr_nb", NULL, NULL, NULL,
> +    "fma4", "tce", NULL, "nodeid-msr",
> +    NULL, "tbm", "topoext", "perfctr-core",
> +    "perfctr-nb", NULL, NULL, NULL,
>      NULL, NULL, NULL, NULL,
>  };
>  
> @@ -235,8 +235,8 @@ static const char *ext4_feature_name[] = {
>  };
>  
>  static const char *kvm_feature_name[] = {
> -    "kvmclock", "kvm_nopiodelay", "kvm_mmu", "kvmclock",
> -    "kvm_asyncpf", "kvm_steal_time", "kvm_pv_eoi", "kvm_pv_unhalt",
> +    "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
> +    "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
>      NULL, NULL, NULL, NULL,
>      NULL, NULL, NULL, NULL,
>      NULL, NULL, NULL, NULL,
> @@ -246,9 +246,9 @@ static const char *kvm_feature_name[] = {
>  };
>  
>  static const char *svm_feature_name[] = {
> -    "npt", "lbrv", "svm_lock", "nrip_save",
> -    "tsc_scale", "vmcb_clean",  "flushbyasid", "decodeassists",
> -    NULL, NULL, "pause_filter", NULL,
> +    "npt", "lbrv", "svm-lock", "nrip-save",
> +    "tsc-scale", "vmcb-clean",  "flushbyasid", "decodeassists",
> +    NULL, NULL, "pause-filter", NULL,
>      "pfthreshold", NULL, NULL, NULL,
>      NULL, NULL, NULL, NULL,
>      NULL, NULL, NULL, NULL,
> @@ -1760,13 +1760,13 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
>  
>      while (featurestr) {
>          char *val;
> +        feat2prop(featurestr);
>          if (featurestr[0] == '+') {
>              add_flagname_to_bitmaps(featurestr + 1, plus_features);
>          } else if (featurestr[0] == '-') {
>              add_flagname_to_bitmaps(featurestr + 1, minus_features);
>          } else if ((val = strchr(featurestr, '='))) {
>              *val = 0; val++;
> -            feat2prop(featurestr);
>              if (!strcmp(featurestr, "xlevel")) {
>                  char *err;
>                  char num[32];
> @@ -1818,7 +1818,6 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
>                  object_property_parse(OBJECT(cpu), val, featurestr, &local_err);
>              }
>          } else {
> -            feat2prop(featurestr);
>              object_property_parse(OBJECT(cpu), "on", featurestr, &local_err);
>          }
>          if (local_err) {
> -- 
> 1.9.3

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH v4 26/33] target-i386: Renove underscores from feature names
  2014-08-14 19:31   ` Michael S. Tsirkin
@ 2014-08-14 19:32     ` Eduardo Habkost
  0 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 19:32 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Marcel Apfelbaum, Alexander Graf, Don Slutz, qemu-devel,
	Igor Mammedov, Andreas Färber

On Thu, Aug 14, 2014 at 09:31:46PM +0200, Michael S. Tsirkin wrote:
> s/Renove/Remove/ ?
> 
> not that it matters ...

Thanks. I will fix it in the next version.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH v4 33/33] piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init()
  2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 33/33] piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init() Eduardo Habkost
@ 2014-08-14 20:03   ` Michael S. Tsirkin
  2014-08-15  0:03     ` Eduardo Habkost
  0 siblings, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2014-08-14 20:03 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Marcel Apfelbaum, Alexander Graf, Don Slutz, qemu-devel,
	Igor Mammedov, Andreas Färber

On Thu, Aug 14, 2014 at 04:26:02PM -0300, Eduardo Habkost wrote:
> Put all the Xen code in a single place.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Would apply to the new igd passthrough machine type as well?

> ---
>  hw/i386/pc_piix.c | 26 ++++++++++++--------------
>  1 file changed, 12 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 293422b..89ecb54 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -291,20 +291,6 @@ static void pc_init1(MachineState *machine)
>      }
>  }
>  
> -#ifdef CONFIG_XEN
> -static void pc_xen_hvm_init(MachineState *machine)
> -{
> -    PCIBus *bus;
> -
> -    pc_init1(machine);
> -
> -    bus = pci_find_primary_bus();
> -    if (bus != NULL) {
> -        pci_create_simple(bus, -1, "xen-platform");
> -    }
> -}
> -#endif
> -
>  static void pc_i440fx_machine_class_init(ObjectClass *oc, void *data)
>  {
>      MachineClass *mc = MACHINE_CLASS(oc);
> @@ -890,6 +876,18 @@ static const TypeInfo isapc_machine_type_info = {
>  };
>  
>  #ifdef CONFIG_XEN
> +static void pc_xen_hvm_init(MachineState *machine)
> +{
> +    PCIBus *bus;
> +
> +    pc_init1(machine);
> +
> +    bus = pci_find_primary_bus();
> +    if (bus != NULL) {
> +        pci_create_simple(bus, -1, "xen-platform");
> +    }
> +}
> +
>  static void xenfv_machine_class_init(ObjectClass *oc, void *data)
>  {
>      MachineClass *mc = MACHINE_CLASS(oc);
> -- 
> 1.9.3

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature
  2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature Eduardo Habkost
@ 2014-08-14 21:08   ` Michael S. Tsirkin
  2014-08-14 23:59     ` Eduardo Habkost
  0 siblings, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2014-08-14 21:08 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Marcel Apfelbaum, Alexander Graf, Don Slutz, qemu-devel,
	Igor Mammedov, Andreas Färber

On Thu, Aug 14, 2014 at 04:25:56PM -0300, Eduardo Habkost wrote:
> The "kvmclock" feature is special because it affects two bits in the KVM
> CPUID leaf, so it has to be handled differently from the other feature
> properties that will be added.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  target-i386/cpu.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index b005b0d..0eb401b 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2774,6 +2774,61 @@ uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index)
>      }
>  }
>  
> +typedef struct FeatureProperty {
> +    FeatureWord word;
> +    uint32_t mask;
> +} FeatureProperty;
> +
> +
> +static void x86_cpu_get_feature_prop(Object *obj,
> +                                     struct Visitor *v,
> +                                     void *opaque,
> +                                     const char *name,
> +                                     Error **errp)
> +{
> +    X86CPU *cpu = X86_CPU(obj);
> +    CPUX86State *env = &cpu->env;
> +    FeatureProperty *fp = opaque;
> +    bool value = (env->features[fp->word] & fp->mask) == fp->mask;
> +    visit_type_bool(v, &value, name, errp);
> +}
> +
> +static void x86_cpu_set_feature_prop(Object *obj,
> +                                     struct Visitor *v,
> +                                     void *opaque,
> +                                     const char *name,
> +                                     Error **errp)
> +{
> +    X86CPU *cpu = X86_CPU(obj);
> +    CPUX86State *env = &cpu->env;
> +    FeatureProperty *fp = opaque;
> +    bool value;
> +    visit_type_bool(v, &value, name, errp);
> +    if (value) {
> +        env->features[fp->word] |= fp->mask;
> +    } else {
> +        env->features[fp->word] &= ~fp->mask;
> +    }
> +}
> +
> +/* Register a boolean feature-bits property.
> + * If mask has multiple bits, all must be set for the property to return true.
> + */
> +static void x86_cpu_register_feature_prop(X86CPU *cpu,
> +                                          const char *prop_name,
> +                                          FeatureWord w,
> +                                          uint32_t mask)
> +{
> +    FeatureProperty *fp;
> +    fp = g_new0(FeatureProperty, 1);
> +    fp->word = w;
> +    fp->mask = mask;
> +    object_property_add(OBJECT(cpu), prop_name, "bool",
> +                        x86_cpu_set_feature_prop,
> +                        x86_cpu_get_feature_prop,
> +                        NULL, fp, &error_abort);
> +}
> +

This looks similar to what what DEFINE_PROP_BIT does.
Can't this be reused in some way?


>  static void x86_cpu_initfn(Object *obj)
>  {
>      CPUState *cs = CPU(obj);
> @@ -2819,6 +2874,12 @@ static void x86_cpu_initfn(Object *obj)
>                          x86_cpu_get_feature_words,
>                          NULL, NULL, (void *)cpu->filtered_features, NULL);
>  
> +    /* "feat-kvmclock" will affect both kvmclock feature bits */
> +    x86_cpu_register_feature_prop(cpu, "feat-kvmclock", FEAT_KVM,
> +                                  (1UL << KVM_FEATURE_CLOCKSOURCE) |
> +                                  (1UL << KVM_FEATURE_CLOCKSOURCE2));
> +
> +
>      cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
>      env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
>  
> -- 
> 1.9.3

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH v4 31/33] pc: Add default KVM features fields to PCMachineClass
  2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 31/33] pc: Add default KVM features fields to PCMachineClass Eduardo Habkost
@ 2014-08-14 21:09   ` Michael S. Tsirkin
  2014-08-15  0:04     ` Eduardo Habkost
  0 siblings, 1 reply; 43+ messages in thread
From: Michael S. Tsirkin @ 2014-08-14 21:09 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Marcel Apfelbaum, Alexander Graf, Don Slutz, qemu-devel,
	Igor Mammedov, Andreas Färber

On Thu, Aug 14, 2014 at 04:26:00PM -0300, Eduardo Habkost wrote:
> With the new fields, the x86_cpu_compat_disable_kvm_features() calls on
> pc_compat_*() functions can be replace 

be replaced

> by simple field initialization on
> class_init functions. This gets us one step closer to eliminating all
> pc_compat_*() functions.
> 
> Those new fields may eventually become simple compat_props properties,
> if we QOMify the accelerator code, and move the KVM-specific CPUID code
> to a x86-kvm-accel class.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/i386/pc.c         | 15 +++++++++++++++
>  hw/i386/pc_piix.c    |  7 ++++---
>  hw/i386/pc_q35.c     |  2 +-
>  include/hw/i386/pc.h |  3 +++
>  target-i386/cpu.c    | 25 ++++++++++++-------------
>  target-i386/cpu.h    |  2 +-
>  6 files changed, 36 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index dba7f62..a0eaaf6 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -24,6 +24,7 @@
>  #include "hw/hw.h"
>  #include "hw/i386/pc.h"
>  #include "hw/char/serial.h"
> +#include "hw/i386/cpu.h"
>  #include "hw/i386/apic.h"
>  #include "hw/block/fdc.h"
>  #include "hw/ide.h"
> @@ -1020,6 +1021,10 @@ void pc_cpus_init(PCMachineState *pcms, DeviceState *icc_bridge)
>      Error *error = NULL;
>      unsigned long apic_id_limit;
>      MachineState *machine = MACHINE(pcms);
> +    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
> +
> +    x86_cpu_set_kvm_defaults(pcmc->kvm_default_features,
> +                             pcmc->kvm_default_unset_features);
>  
>      /* init CPUs */
>      current_cpu_model = machine->cpu_model;
> @@ -1687,6 +1692,16 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
>      pcmc->gigabyte_align = true;
>      pcmc->has_reserved_memory = true;
>      pcmc->kvmclock_enabled = true;
> +    pcmc->kvm_default_features[FEAT_KVM] =
> +        (1 << KVM_FEATURE_CLOCKSOURCE) |
> +        (1 << KVM_FEATURE_NOP_IO_DELAY) |
> +        (1 << KVM_FEATURE_CLOCKSOURCE2) |
> +        (1 << KVM_FEATURE_ASYNC_PF) |
> +        (1 << KVM_FEATURE_STEAL_TIME) |
> +        (1 << KVM_FEATURE_PV_EOI) |
> +        (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT),
> +    pcmc->kvm_default_features[FEAT_1_ECX] = CPUID_EXT_X2APIC,
> +    pcmc->kvm_default_unset_features[FEAT_1_ECX] = CPUID_EXT_MONITOR,
>  
>      mc->get_hotplug_handler = pc_get_hotpug_handler;
>      mc->default_boot_order = "cad";
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 988583c..9ec63d5 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -298,7 +298,6 @@ static void pc_compat_2_0(MachineState *machine)
>  static void pc_compat_1_7(MachineState *machine)
>  {
>      pc_compat_2_0(machine);
> -    x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
>  }
>  
>  static void pc_compat_1_6(MachineState *machine)
> @@ -325,7 +324,6 @@ static void pc_compat_1_3(MachineState *machine)
>  static void pc_compat_1_2(MachineState *machine)
>  {
>      pc_compat_1_3(machine);
> -    x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
>  }
>  
>  /* PC compat function for pc-0.10 to pc-0.13 */
> @@ -386,7 +384,6 @@ static void pc_init_pci_no_kvmclock(MachineState *machine)
>  
>  static void pc_init_isa(MachineState *machine)
>  {
> -    x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
>      pc_init1(machine);
>  }
>  
> @@ -494,6 +491,7 @@ static void pc_i440fx_machine_v1_7_class_init(ObjectClass *oc, void *data)
>      pcmc->smbios_defaults = false;
>      pcmc->gigabyte_align = false;
>      pcmc->legacy_acpi_table_size = 6414;
> +    pcmc->kvm_default_features[FEAT_1_ECX] &= ~CPUID_EXT_X2APIC;
>  }
>  
>  static const TypeInfo pc_i440fx_machine_v1_7_type_info = {
> @@ -633,6 +631,7 @@ static const TypeInfo pc_machine_v1_3_type_info = {
>  static void pc_machine_v1_2_class_init(ObjectClass *oc, void *data)
>  {
>      MachineClass *mc = MACHINE_CLASS(oc);
> +    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
>      static GlobalProperty compat_props[] = {
>          PC_COMPAT_1_2,
>          { /* end of list */ }
> @@ -641,6 +640,7 @@ static void pc_machine_v1_2_class_init(ObjectClass *oc, void *data)
>      mc->init = pc_init_pci_1_2;
>      mc->name = "pc-1.2";
>      machine_class_add_compat_props(mc, compat_props);
> +    pcmc->kvm_default_features[FEAT_KVM] &= ~KVM_FEATURE_PV_EOI;
>  }
>  
>  static const TypeInfo pc_machine_v1_2_type_info = {
> @@ -984,6 +984,7 @@ static void isapc_machine_class_init(ObjectClass *oc, void *data)
>      pcmc->smbios_legacy_mode = true;
>      pcmc->has_reserved_memory = false;
>      pcmc->compat_apic_id_mode = true;
> +    pcmc->kvm_default_features[FEAT_KVM] &= ~KVM_FEATURE_PV_EOI;
>  }
>  
>  static const TypeInfo isapc_machine_type_info = {
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 2ebd598..5878964 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -271,7 +271,6 @@ static void pc_compat_2_0(MachineState *machine)
>  static void pc_compat_1_7(MachineState *machine)
>  {
>      pc_compat_2_0(machine);
> -    x86_cpu_compat_disable_kvm_features(FEAT_1_ECX, CPUID_EXT_X2APIC);
>  }
>  
>  static void pc_compat_1_6(MachineState *machine)
> @@ -389,6 +388,7 @@ static void pc_q35_machine_v1_7_class_init(ObjectClass *oc, void *data)
>      mc->name = "pc-q35-1.7";
>      pcmc->smbios_defaults = false;
>      pcmc->gigabyte_align = false;
> +    pcmc->kvm_default_features[FEAT_1_ECX] &= ~CPUID_EXT_X2APIC;
>  }
>  
>  static TypeInfo pc_q35_machine_v1_7_type_info = {
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index 460ff21..b7f36d6 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -8,6 +8,7 @@
>  #include "hw/block/fdc.h"
>  #include "net/net.h"
>  #include "hw/i386/ioapic.h"
> +#include "hw/i386/cpu.h"
>  #include "hw/boards.h"
>  
>  #include "qemu/range.h"
> @@ -66,6 +67,8 @@ struct PCMachineClass {
>      bool has_reserved_memory;
>      bool kvmclock_enabled;
>      bool compat_apic_id_mode;
> +    uint32_t kvm_default_features[FEATURE_WORDS];
> +    uint32_t kvm_default_unset_features[FEATURE_WORDS];
>  };
>  
>  typedef struct PCMachineState PCMachineState;
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index e86f99e..e02b0d9 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -446,27 +446,26 @@ typedef struct model_features_t {
>  
>  /* KVM-specific features that are automatically added to all CPU models
>   * when KVM is enabled.
> + *
> + * The default is to enable all KVM features, but machine-types may override it
> + * to keep a stable ABI. See x86_cpu_set_kvm_defaults().
>   */
>  static uint32_t kvm_default_features[FEATURE_WORDS] = {
> -    [FEAT_KVM] = (1 << KVM_FEATURE_CLOCKSOURCE) |
> -        (1 << KVM_FEATURE_NOP_IO_DELAY) |
> -        (1 << KVM_FEATURE_CLOCKSOURCE2) |
> -        (1 << KVM_FEATURE_ASYNC_PF) |
> -        (1 << KVM_FEATURE_STEAL_TIME) |
> -        (1 << KVM_FEATURE_PV_EOI) |
> -        (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT),
> -    [FEAT_1_ECX] = CPUID_EXT_X2APIC,
> +    [FEAT_KVM] = ~0,
>  };
>  
>  /* Features that are not added by default to any CPU model when KVM is enabled.
>   */
> -static uint32_t kvm_default_unset_features[FEATURE_WORDS] = {
> -    [FEAT_1_ECX] = CPUID_EXT_MONITOR,
> -};
> +static uint32_t kvm_default_unset_features[FEATURE_WORDS];
>  
> -void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features)
> +/* Override default-enabled and default-disabled KVM features. Used by
> + * machine-type code to ensure a stable ABI.
> + */
> +void x86_cpu_set_kvm_defaults(uint32_t *default_set, uint32_t *default_unset)
>  {
> -    kvm_default_features[w] &= ~features;
> +    memcpy(kvm_default_features, default_set, sizeof(kvm_default_features));
> +    memcpy(kvm_default_unset_features, default_unset,
> +           sizeof(kvm_default_unset_features));
>  }
>  
>  /*
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index 3f299d7..2138996 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -741,7 +741,7 @@ void do_smm_enter(X86CPU *cpu);
>  
>  void cpu_report_tpr_access(CPUX86State *env, TPRAccess access);
>  
> -void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features);
> +void x86_cpu_set_kvm_defaults(uint32_t *default_set, uint32_t *default_unset);
>  
>  
>  /* Return name of 32-bit register, from a R_* constant */
> -- 
> 1.9.3

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature
  2014-08-14 21:08   ` Michael S. Tsirkin
@ 2014-08-14 23:59     ` Eduardo Habkost
  2014-08-16 21:03       ` Michael S. Tsirkin
  0 siblings, 1 reply; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-14 23:59 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Marcel Apfelbaum, Alexander Graf, Don Slutz, qemu-devel,
	Igor Mammedov, Andreas Färber

On Thu, Aug 14, 2014 at 11:08:30PM +0200, Michael S. Tsirkin wrote:
> On Thu, Aug 14, 2014 at 04:25:56PM -0300, Eduardo Habkost wrote:
> > The "kvmclock" feature is special because it affects two bits in the KVM
> > CPUID leaf, so it has to be handled differently from the other feature
> > properties that will be added.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  target-i386/cpu.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 61 insertions(+)
> > 
> > diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> > index b005b0d..0eb401b 100644
> > --- a/target-i386/cpu.c
> > +++ b/target-i386/cpu.c
> > @@ -2774,6 +2774,61 @@ uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index)
> >      }
> >  }
> >  
> > +typedef struct FeatureProperty {
> > +    FeatureWord word;
> > +    uint32_t mask;
> > +} FeatureProperty;
> > +
> > +
> > +static void x86_cpu_get_feature_prop(Object *obj,
> > +                                     struct Visitor *v,
> > +                                     void *opaque,
> > +                                     const char *name,
> > +                                     Error **errp)
> > +{
> > +    X86CPU *cpu = X86_CPU(obj);
> > +    CPUX86State *env = &cpu->env;
> > +    FeatureProperty *fp = opaque;
> > +    bool value = (env->features[fp->word] & fp->mask) == fp->mask;
> > +    visit_type_bool(v, &value, name, errp);
> > +}
> > +
> > +static void x86_cpu_set_feature_prop(Object *obj,
> > +                                     struct Visitor *v,
> > +                                     void *opaque,
> > +                                     const char *name,
> > +                                     Error **errp)
> > +{
> > +    X86CPU *cpu = X86_CPU(obj);
> > +    CPUX86State *env = &cpu->env;
> > +    FeatureProperty *fp = opaque;
> > +    bool value;
> > +    visit_type_bool(v, &value, name, errp);
> > +    if (value) {
> > +        env->features[fp->word] |= fp->mask;
> > +    } else {
> > +        env->features[fp->word] &= ~fp->mask;
> > +    }
> > +}
> > +
> > +/* Register a boolean feature-bits property.
> > + * If mask has multiple bits, all must be set for the property to return true.
> > + */
> > +static void x86_cpu_register_feature_prop(X86CPU *cpu,
> > +                                          const char *prop_name,
> > +                                          FeatureWord w,
> > +                                          uint32_t mask)
> > +{
> > +    FeatureProperty *fp;
> > +    fp = g_new0(FeatureProperty, 1);
> > +    fp->word = w;
> > +    fp->mask = mask;
> > +    object_property_add(OBJECT(cpu), prop_name, "bool",
> > +                        x86_cpu_set_feature_prop,
> > +                        x86_cpu_get_feature_prop,
> > +                        NULL, fp, &error_abort);
> > +}
> > +
> 
> This looks similar to what what DEFINE_PROP_BIT does.
> Can't this be reused in some way?

DEFINE_PROP_BIT is from the static property system, and I understand we
are preferring using object_property_add*() instead (and in the X86CPU
features case, registering the properties dynamically using the feature
name arrays saves us a lot of work).

I will take a look at the DEFINE_PROP_BIT code to see if anything from
that code can be reused, but I doubt so. It seems to be tightly coupled
to the static property system.

> 
> 
> >  static void x86_cpu_initfn(Object *obj)
> >  {
> >      CPUState *cs = CPU(obj);
> > @@ -2819,6 +2874,12 @@ static void x86_cpu_initfn(Object *obj)
> >                          x86_cpu_get_feature_words,
> >                          NULL, NULL, (void *)cpu->filtered_features, NULL);
> >  
> > +    /* "feat-kvmclock" will affect both kvmclock feature bits */
> > +    x86_cpu_register_feature_prop(cpu, "feat-kvmclock", FEAT_KVM,
> > +                                  (1UL << KVM_FEATURE_CLOCKSOURCE) |
> > +                                  (1UL << KVM_FEATURE_CLOCKSOURCE2));
> > +
> > +
> >      cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
> >      env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
> >  
> > -- 
> > 1.9.3

-- 
Eduardo

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH v4 33/33] piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init()
  2014-08-14 20:03   ` Michael S. Tsirkin
@ 2014-08-15  0:03     ` Eduardo Habkost
  0 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-15  0:03 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Marcel Apfelbaum, Alexander Graf, Don Slutz, qemu-devel,
	Igor Mammedov, Andreas Färber

On Thu, Aug 14, 2014 at 10:03:49PM +0200, Michael S. Tsirkin wrote:
> On Thu, Aug 14, 2014 at 04:26:02PM -0300, Eduardo Habkost wrote:
> > Put all the Xen code in a single place.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> 
> Would apply to the new igd passthrough machine type as well?

Yes, but the igd passthrough series and this one conflict with each
other, anyway. In case I get to rebase this series on top of the igd
passthrough code, this patch will be changed to move the igd code as
well.

Should I rebase my series on top of your queue, to get it applied after
the igd passthrough series?

-- 
Eduardo

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH v4 31/33] pc: Add default KVM features fields to PCMachineClass
  2014-08-14 21:09   ` Michael S. Tsirkin
@ 2014-08-15  0:04     ` Eduardo Habkost
  0 siblings, 0 replies; 43+ messages in thread
From: Eduardo Habkost @ 2014-08-15  0:04 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Marcel Apfelbaum, Alexander Graf, Don Slutz, qemu-devel,
	Igor Mammedov, Andreas Färber

On Thu, Aug 14, 2014 at 11:09:59PM +0200, Michael S. Tsirkin wrote:
> On Thu, Aug 14, 2014 at 04:26:00PM -0300, Eduardo Habkost wrote:
> > With the new fields, the x86_cpu_compat_disable_kvm_features() calls on
> > pc_compat_*() functions can be replace 
> 
> be replaced

Thanks. Will be fixed on the next version.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature
  2014-08-14 23:59     ` Eduardo Habkost
@ 2014-08-16 21:03       ` Michael S. Tsirkin
  0 siblings, 0 replies; 43+ messages in thread
From: Michael S. Tsirkin @ 2014-08-16 21:03 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Marcel Apfelbaum, Alexander Graf, Don Slutz, qemu-devel,
	Igor Mammedov, Andreas Färber

On Thu, Aug 14, 2014 at 08:59:17PM -0300, Eduardo Habkost wrote:
> On Thu, Aug 14, 2014 at 11:08:30PM +0200, Michael S. Tsirkin wrote:
> > On Thu, Aug 14, 2014 at 04:25:56PM -0300, Eduardo Habkost wrote:
> > > The "kvmclock" feature is special because it affects two bits in the KVM
> > > CPUID leaf, so it has to be handled differently from the other feature
> > > properties that will be added.
> > > 
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > >  target-i386/cpu.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 61 insertions(+)
> > > 
> > > diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> > > index b005b0d..0eb401b 100644
> > > --- a/target-i386/cpu.c
> > > +++ b/target-i386/cpu.c
> > > @@ -2774,6 +2774,61 @@ uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index)
> > >      }
> > >  }
> > >  
> > > +typedef struct FeatureProperty {
> > > +    FeatureWord word;
> > > +    uint32_t mask;
> > > +} FeatureProperty;
> > > +
> > > +
> > > +static void x86_cpu_get_feature_prop(Object *obj,
> > > +                                     struct Visitor *v,
> > > +                                     void *opaque,
> > > +                                     const char *name,
> > > +                                     Error **errp)
> > > +{
> > > +    X86CPU *cpu = X86_CPU(obj);
> > > +    CPUX86State *env = &cpu->env;
> > > +    FeatureProperty *fp = opaque;
> > > +    bool value = (env->features[fp->word] & fp->mask) == fp->mask;
> > > +    visit_type_bool(v, &value, name, errp);
> > > +}
> > > +
> > > +static void x86_cpu_set_feature_prop(Object *obj,
> > > +                                     struct Visitor *v,
> > > +                                     void *opaque,
> > > +                                     const char *name,
> > > +                                     Error **errp)
> > > +{
> > > +    X86CPU *cpu = X86_CPU(obj);
> > > +    CPUX86State *env = &cpu->env;
> > > +    FeatureProperty *fp = opaque;
> > > +    bool value;
> > > +    visit_type_bool(v, &value, name, errp);
> > > +    if (value) {
> > > +        env->features[fp->word] |= fp->mask;
> > > +    } else {
> > > +        env->features[fp->word] &= ~fp->mask;
> > > +    }
> > > +}
> > > +
> > > +/* Register a boolean feature-bits property.
> > > + * If mask has multiple bits, all must be set for the property to return true.
> > > + */
> > > +static void x86_cpu_register_feature_prop(X86CPU *cpu,
> > > +                                          const char *prop_name,
> > > +                                          FeatureWord w,
> > > +                                          uint32_t mask)
> > > +{
> > > +    FeatureProperty *fp;
> > > +    fp = g_new0(FeatureProperty, 1);
> > > +    fp->word = w;
> > > +    fp->mask = mask;
> > > +    object_property_add(OBJECT(cpu), prop_name, "bool",
> > > +                        x86_cpu_set_feature_prop,
> > > +                        x86_cpu_get_feature_prop,
> > > +                        NULL, fp, &error_abort);
> > > +}
> > > +
> > 
> > This looks similar to what what DEFINE_PROP_BIT does.
> > Can't this be reused in some way?
> 
> DEFINE_PROP_BIT is from the static property system, and I understand we
> are preferring using object_property_add*() instead (and in the X86CPU
> features case, registering the properties dynamically using the feature
> name arrays saves us a lot of work).
> 
> I will take a look at the DEFINE_PROP_BIT code to see if anything from
> that code can be reused, but I doubt so. It seems to be tightly coupled
> to the static property system.

Main point is, can't we find a way to reduce code duplication?
It doesn't seem reasonable that we basically open-code
each property from scratch.

> > 
> > 
> > >  static void x86_cpu_initfn(Object *obj)
> > >  {
> > >      CPUState *cs = CPU(obj);
> > > @@ -2819,6 +2874,12 @@ static void x86_cpu_initfn(Object *obj)
> > >                          x86_cpu_get_feature_words,
> > >                          NULL, NULL, (void *)cpu->filtered_features, NULL);
> > >  
> > > +    /* "feat-kvmclock" will affect both kvmclock feature bits */
> > > +    x86_cpu_register_feature_prop(cpu, "feat-kvmclock", FEAT_KVM,
> > > +                                  (1UL << KVM_FEATURE_CLOCKSOURCE) |
> > > +                                  (1UL << KVM_FEATURE_CLOCKSOURCE2));
> > > +
> > > +
> > >      cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
> > >      env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
> > >  
> > > -- 
> > > 1.9.3
> 
> -- 
> Eduardo

^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2014-08-16 21:02 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 01/33] pc: Replace tabs with spaces on pc.h Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 02/33] vl.c: Use qdev_prop_register_global() for single globals Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 03/33] pc: Eliminate has_pci_info global variable Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 04/33] piix: Add kvmclock_enabled, pci_enabled globals Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 05/33] piix: Eliminate pc_init_pci() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 06/33] piix: Move pc-0.14 qxl compat properties to PC_COMPAT_0_14 Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 07/33] piix: Move pc-0.13 virtio-9p-pci compat to PC_COMPAT_0_13 Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 08/33] piix: Move pc-0.1[23] rombar compat props " Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 09/33] piix: Move pc-0.11 drive version compat props to PC_COMPAT_0_11 Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 10/33] machine: Make compat_props a linked list Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 11/33] pc: Register machine classes directly instead of using QEMUMachine Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 12/33] pc: Eliminate pc_common_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 13/33] pc: Eliminate pc_default_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 14/33] piix: Eliminate pc_i440fx_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 15/33] q35: Eliminate pc_q35_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 16/33] q35: Eliminate pc_q35_1_4_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 17/33] pc: Eliminate all *_machine_options() functions Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 18/33] machine: Eliminate QEMUMachine.compat_props Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 19/33] pc: Rename pc_machine variable to pcms Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 20/33] pc: Pass PCMachineState argument to pc_cpus_init() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 21/33] machine: Add MachineClass.default_cpu_model field Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 22/33] pc: Move globals to PCMachineClass Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 23/33] pc: Move option_rom_has_mr/rom_file_has_mr to MachineClass Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 24/33] pc: Add PCMachineClass.compat_apic_id_mode field Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 25/33] target-i386: Move error handling to end of x86_cpu_parse_featurestr() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 26/33] target-i386: Renove underscores from feature names Eduardo Habkost
2014-08-14 19:31   ` Michael S. Tsirkin
2014-08-14 19:32     ` Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature Eduardo Habkost
2014-08-14 21:08   ` Michael S. Tsirkin
2014-08-14 23:59     ` Eduardo Habkost
2014-08-16 21:03       ` Michael S. Tsirkin
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 28/33] target-i386: set [+-]feature using QOM properties Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 29/33] pc: Use compat_props for CPUID compat bits Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 30/33] target-i386: Move some declarations to hw/i386/cpu.h Eduardo Habkost
2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 31/33] pc: Add default KVM features fields to PCMachineClass Eduardo Habkost
2014-08-14 21:09   ` Michael S. Tsirkin
2014-08-15  0:04     ` Eduardo Habkost
2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 32/33] pc: Eliminate pc_compat_*() functions Eduardo Habkost
2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 33/33] piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init() Eduardo Habkost
2014-08-14 20:03   ` Michael S. Tsirkin
2014-08-15  0:03     ` Eduardo Habkost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).