piix: Move pc-0.11 drive version compat props to PC_COMPAT_0_11

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>
machine: Make compat_props a linked list

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.
pc: Register machine classes directly instead of using QEMUMachine

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>
pc: Eliminate pc_common_machine_options()

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>
pc: Eliminate pc_default_machine_options()

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>
piix: Eliminate pc_i440fx_machine_options()

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>
q35: Eliminate pc_q35_machine_options()

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>
q35: Eliminate pc_q35_1_4_machine_options()

The function was used only in a single place.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
pc: Eliminate all *_machine_options() functions

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>
machine: Eliminate QEMUMachine.compat_props

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>
pc: Rename pc_machine variable to pcms

"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>
pc: Pass PCMachineState argument to pc_cpus_init()

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
machine: Add MachineClass.default_cpu_model field

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>
pc: Move globals to PCMachineClass

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.
pc: Move option_rom_has_mr/rom_file_has_mr to MachineClass

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>
pc: Add PCMachineClass.compat_apic_id_mode field

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>
target-i386: Move error handling to end of x86_cpu_parse_featurestr()

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: Renove underscores from feature names

The underscores will be translated by x86_cpu_parse_featurestr().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: Register X86CPU "feat-kvmclock" feature

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: set [+-]feature using QOM properties

 * 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>