target-i386: move cpu_x86_init() to cpu.c

Eventually all of the CPU init code will probably become just a simple
object_new() call, with some arch-independent function that handles the
CPU model string parsing. But right now we need to reorder and split
many of the steps invoved in the CPU model string parsing and CPU object
creation, and it will be easier to do that inside cpu.c, by now.

Also, make cpu_x86_register() static, as now it is only used inside
cpu.c.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu: rename x86_def_t to X86CPUDefinition

Change to match QEMU coding style.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: x86_cpudef_setup(): cosmetic change on comment

There are no "cpudef" models, all of them are builtin, now.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu_x86_init(): move error handling to end of function

Doing error handling on a single place will make it easier to make sure
memory is freed, and that error information is properly printed or
returned to the caller.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu_x86_init(): print error message in case of error

Error information is being ignored and never returned to the caller.

While we don't change cpu_x86_init() to not return error information, print
error message inside cpu_x86_init() in case of error.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v2:
 - Use error_report()
 - Add "cpu_x86_init:" prefix to error message
target-i386: cpu_x86_register(): report errors using Error parameter

Do it using a local Error variable and error_propagate(), so we don't
miss any error reported by the property setters in case errp is NULL.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu_x86_register(): reorder CPU property setting

Trivial code movement, before moving the code to another function.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: move out CPU features initialization to separate func

Later it will be used in cpu_x86_init() to init CPU from found cpudef.

This is will make it easier to reorder and clean up the cpu_x86_init()
code later.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
[ehabkost: added error reporting to function]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
v2:
 - rebased on top of  "i386: cpu: remove duplicate feature names"
   http://www.mail-archive.com/qemu-devel@nongnu.org/msg129458.html

v3 (ehabkost):
 - Rebased on top of CPU model classes work in progress
 - Added error reporting to new function
 - Changed commit message

v4 (ehabkost)
 - coding style fix
target-i386: kill cpu_x86_register()

Move the cpu_x86_register() code inside cpu_x86_init(), as the initialization
steps are going to be reordered.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: return Error from cpu_x86_find_by_name()

It will allow us to use property setters there later.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
[ehabkost: rebased on top of CPU classes work in progress]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
v2:
    - style change, add braces (requested by Blue Swirl)
    - removed unused error_is_set(errp) in properties set loop
v3:
    - removed unnecessary whitespace change

v4 (ehabkost):
    - rebased on top of CPU classes work in progress
    - reworded commit message
target-i386: cpu_x86_find_by_name(): split CPU model and feature string first

Instead of using strtok() for the whole cpu_model string, first split it
into the CPU model name and the full feature string, then parse the
feature string into pieces.

When using CPU model classes, those two pieces of information will be
used at different moments (CPU model name will be used to find CPU
class, feature string will be used after CPU object was created), so
making the split in two steps will make it easier to refactor the code
later.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu: create cpu_x86_find_cpudef() function

Move the code that looks for a given CPU model to a separate function.

This will make it easier to separate the cpudef lookup code and the
feature string parsing code, later.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu_x86_init(): rename cpu_model to cpu_string

Rename the variable, to avoid confusion between the actual CPU model
name and the -cpu string argument (that may contain additional
parameters).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu_x86_init(): eliminate extra 'def1' variable

Just use '&def' where a pointer to the under-construction
X86CPUDefinition struct is being used.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu: separate cpudef lookup from feature string parsing

- Move the CPU string split and cpudef lookup to cpu_x86_init();
- Rename cpu_x86_find_by_name() to cpu_x86_parse_feature_string(),
  and make it just get the feature string as input.

This will allow us to use the CPU model name for the CPU class lookup,
inside cpu_x86_init().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu_x86_init(): reorder split of CPU string and creation of CPU object

A step towards making the creation of CPU objects use the CPU model name
as class name.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: use specific error code for missing host capabiities

Instead of using a generic QERR_INVALID_PARAMETER_COMBINATION error, define a
QERR_MISSING_HOST_CAP error class, for those cases.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: pass cpu object to cpu_x86_parse_featurestr()

It will be used later, while changing the host feature check code to use
the CPU object instead of X86CPUDefinition.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: kvm_check_features_against_host: get CPU object as input

Instead of getting a X86CPUDefinition struct (that we want to eventually
kill), uses the CPU object as input, when checking for host feature
support.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
target-i386: cpu: move host feature check to x86_cpu_realize()

This has nothing to do with feature string parsing, so it doesn't belong
to cpu_x86_parse_featurestr().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>