From 89e0e9c71e608f3679f30e88d988903536c6f7f3 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 23 Oct 2012 20:42:56 -0200 Subject: [PATCH 01/13] user: Move *-user/qemu-types.h to main directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bsd-user/qemu-types.h and linux-user/qemu-types.h files are almost the same, but linux-user has the additional definitions of tswapal(). This moves the linux-user file to the main directory, so the same file can be used by linux-user and bsd-user. Signed-off-by: Eduardo Habkost Signed-off-by: Andreas Färber --- bsd-user/qemu-types.h | 24 ------------------------ linux-user/qemu-types.h => qemu-types.h | 0 2 files changed, 24 deletions(-) delete mode 100644 bsd-user/qemu-types.h rename linux-user/qemu-types.h => qemu-types.h (100%) diff --git a/bsd-user/qemu-types.h b/bsd-user/qemu-types.h deleted file mode 100644 index 1adda9fbdb..0000000000 --- a/bsd-user/qemu-types.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef QEMU_TYPES_H -#define QEMU_TYPES_H -#include "cpu.h" - -#ifdef TARGET_ABI32 -typedef uint32_t abi_ulong; -typedef int32_t abi_long; -#define TARGET_ABI_FMT_lx "%08x" -#define TARGET_ABI_FMT_ld "%d" -#define TARGET_ABI_FMT_lu "%u" -#define TARGET_ABI_BITS 32 -#else -typedef target_ulong abi_ulong; -typedef target_long abi_long; -#define TARGET_ABI_FMT_lx TARGET_FMT_lx -#define TARGET_ABI_FMT_ld TARGET_FMT_ld -#define TARGET_ABI_FMT_lu TARGET_FMT_lu -#define TARGET_ABI_BITS TARGET_LONG_BITS -/* for consistency, define ABI32 too */ -#if TARGET_ABI_BITS == 32 -#define TARGET_ABI32 1 -#endif -#endif -#endif diff --git a/linux-user/qemu-types.h b/qemu-types.h similarity index 100% rename from linux-user/qemu-types.h rename to qemu-types.h From ee9baa00f2623f1f627913f62d60f2888286319a Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 23 Oct 2012 22:54:34 -0200 Subject: [PATCH 02/13] user: Rename qemu-types.h to qemu-user-types.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The header file is specific for *-user, but I plan to introduce a more generic qemu-types.h file, so I'm renaming it. Signed-off-by: Eduardo Habkost Signed-off-by: Andreas Färber --- bsd-user/qemu.h | 2 +- cpu-all.h | 2 +- linux-user/qemu.h | 2 +- qemu-types.h => qemu-user-types.h | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename qemu-types.h => qemu-user-types.h (100%) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 8a5ee3d81f..d2688995bd 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -11,7 +11,7 @@ #include #endif /* DEBUG_REMAP */ -#include "qemu-types.h" +#include "qemu-user-types.h" enum BSDType { target_freebsd, diff --git a/cpu-all.h b/cpu-all.h index c9c51b83ac..d6b2b19743 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -180,7 +180,7 @@ static inline void tswap64s(uint64_t *s) #if defined(CONFIG_USER_ONLY) #include -#include "qemu-types.h" +#include "qemu-user-types.h" /* On some host systems the guest address space is reserved on the host. * This allows the guest address space to be offset to a convenient location. diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 5e53dca09e..ceddb3ce72 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -11,7 +11,7 @@ #include #endif /* DEBUG_REMAP */ -#include "qemu-types.h" +#include "qemu-user-types.h" #include "thunk.h" #include "syscall_defs.h" diff --git a/qemu-types.h b/qemu-user-types.h similarity index 100% rename from qemu-types.h rename to qemu-user-types.h From 90f0cfa410544727ac4e9c130f9e5032e1fb9b71 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 23 Oct 2012 21:19:18 -0200 Subject: [PATCH 03/13] ui/vnc-palette.c: Include headers it needs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Include: - for g_malloc0() - for memset() Some of those headers were probably being included by accident because some other headers were including qemu-common.h, but those headers should eventually stop including qemu-common.h. Signed-off-by: Eduardo Habkost Signed-off-by: Andreas Färber --- ui/vnc-palette.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c index 63d5f64917..c130deee9d 100644 --- a/ui/vnc-palette.c +++ b/ui/vnc-palette.c @@ -27,6 +27,8 @@ */ #include "vnc-palette.h" +#include +#include static VncPaletteEntry *palette_find(const VncPalette *palette, uint32_t color, unsigned int hash) From ccff63cac4f0d391187c9ee9aa2cab754df80c41 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 23 Oct 2012 21:35:44 -0200 Subject: [PATCH 04/13] qapi/qmp-registry.c: Include headers it needs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Include: - for g_malloc0() - for strcmp() Some of those headers were probably being included by accident because some other headers were including qemu-common.h, but those headers should eventually stop including qemu-common.h. Signed-off-by: Eduardo Habkost Signed-off-by: Andreas Färber --- qapi/qmp-registry.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c index 5414613377..c2c31b420d 100644 --- a/qapi/qmp-registry.c +++ b/qapi/qmp-registry.c @@ -12,6 +12,8 @@ * */ +#include +#include #include "qapi/qmp-core.h" static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands = From 4d4922c339abf67e47c79068d343ed41a020b8e2 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 23 Oct 2012 21:37:20 -0200 Subject: [PATCH 05/13] qga/channel-posix.c: Include headers it needs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Include: - for errno - & for fcntl() - for exit() - "osdep.h" for qemu_open() Some of those headers were probably being included by accident because some other headers were including qemu-common.h, but those headers should eventually stop including qemu-common.h. Signed-off-by: Eduardo Habkost Signed-off-by: Igor Mammedov Signed-off-by: Andreas Färber --- qga/channel-posix.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qga/channel-posix.c b/qga/channel-posix.c index d152827bcf..769a559456 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -1,5 +1,10 @@ #include #include +#include +#include +#include +#include +#include "osdep.h" #include "qemu_socket.h" #include "qga/channel.h" From cad32159663c5910098e10d64f4b5b10648b0095 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 23 Oct 2012 21:55:19 -0200 Subject: [PATCH 06/13] qlist.h: Do not include qemu-common.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I don't know why it was including it, as I don't see any code that depends on anything from qemu-common.h. Signed-off-by: Eduardo Habkost Signed-off-by: Andreas Färber --- qlist.h | 1 - 1 file changed, 1 deletion(-) diff --git a/qlist.h b/qlist.h index ae776f99c3..74089471df 100644 --- a/qlist.h +++ b/qlist.h @@ -15,7 +15,6 @@ #include "qobject.h" #include "qemu-queue.h" -#include "qemu-common.h" #include "qemu-queue.h" typedef struct QListEntry { From 394e1bb79591c2fbfc873e5ccc38e92a3ba992cf Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 23 Oct 2012 21:41:52 -0200 Subject: [PATCH 07/13] Create qemu-types.h for struct typedefs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of keeping all those struct typedefs in qemu-common.h, move it to a header that can be safely included by other headers, containing only the struct typedefs and not pulling in other dependencies. Also, move some of the qdev-core.h typedefs to the new file, too, so other headers don't need to include qdev-core.h only because of DeviceState and other typedefs. This will help us remove qemu-common.h dependencies from some headers later. Signed-off-by: Eduardo Habkost Signed-off-by: Andreas Färber --- hw/qdev-core.h | 11 +-------- qemu-common.h | 52 +----------------------------------------- qemu-types.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 61 deletions(-) create mode 100644 qemu-types.h diff --git a/hw/qdev-core.h b/hw/qdev-core.h index fff7f0f5ab..d672ccafe6 100644 --- a/hw/qdev-core.h +++ b/hw/qdev-core.h @@ -3,20 +3,11 @@ #include "qemu-queue.h" #include "qemu-option.h" +#include "qemu-types.h" #include "qemu/object.h" #include "hw/irq.h" #include "error.h" -typedef struct Property Property; - -typedef struct PropertyInfo PropertyInfo; - -typedef struct CompatProperty CompatProperty; - -typedef struct BusState BusState; - -typedef struct BusClass BusClass; - enum DevState { DEV_STATE_CREATED = 1, DEV_STATE_INITIALIZED, diff --git a/qemu-common.h b/qemu-common.h index cef264cc85..e67478607b 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -14,6 +14,7 @@ #include "compiler.h" #include "config-host.h" +#include "qemu-types.h" #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__) #define WORDS_ALIGNED @@ -21,15 +22,6 @@ #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) -typedef struct QEMUTimer QEMUTimer; -typedef struct QEMUFile QEMUFile; -typedef struct QEMUBH QEMUBH; -typedef struct DeviceState DeviceState; - -struct Monitor; -typedef struct Monitor Monitor; -typedef struct MigrationParams MigrationParams; - /* we put basic includes here to avoid repeating them in device drivers */ #include #include @@ -258,48 +250,6 @@ struct ParallelIOArg { typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size); -/* A load of opaque types so that device init declarations don't have to - pull in all the real definitions. */ -typedef struct NICInfo NICInfo; -typedef struct HCIInfo HCIInfo; -typedef struct AudioState AudioState; -typedef struct BlockDriverState BlockDriverState; -typedef struct DriveInfo DriveInfo; -typedef struct DisplayState DisplayState; -typedef struct DisplayChangeListener DisplayChangeListener; -typedef struct DisplaySurface DisplaySurface; -typedef struct PixelFormat PixelFormat; -typedef struct QemuConsole QemuConsole; -typedef struct CharDriverState CharDriverState; -typedef struct MACAddr MACAddr; -typedef struct NetClientState NetClientState; -typedef struct i2c_bus i2c_bus; -typedef struct ISABus ISABus; -typedef struct ISADevice ISADevice; -typedef struct SMBusDevice SMBusDevice; -typedef struct PCIHostState PCIHostState; -typedef struct PCIExpressHost PCIExpressHost; -typedef struct PCIBus PCIBus; -typedef struct PCIDevice PCIDevice; -typedef struct PCIExpressDevice PCIExpressDevice; -typedef struct PCIBridge PCIBridge; -typedef struct PCIEAERMsg PCIEAERMsg; -typedef struct PCIEAERLog PCIEAERLog; -typedef struct PCIEAERErr PCIEAERErr; -typedef struct PCIEPort PCIEPort; -typedef struct PCIESlot PCIESlot; -typedef struct MSIMessage MSIMessage; -typedef struct SerialState SerialState; -typedef struct PCMCIACardState PCMCIACardState; -typedef struct MouseTransformInfo MouseTransformInfo; -typedef struct uWireSlave uWireSlave; -typedef struct I2SCodec I2SCodec; -typedef struct SSIBus SSIBus; -typedef struct EventNotifier EventNotifier; -typedef struct VirtIODevice VirtIODevice; -typedef struct QEMUSGList QEMUSGList; -typedef struct SHPCDevice SHPCDevice; - typedef uint64_t pcibus_t; typedef enum LostTickPolicy { diff --git a/qemu-types.h b/qemu-types.h new file mode 100644 index 0000000000..fd532a268d --- /dev/null +++ b/qemu-types.h @@ -0,0 +1,61 @@ +#ifndef QEMU_TYPEDEFS_H +#define QEMU_TYPEDEFS_H + +/* A load of opaque types so that device init declarations don't have to + pull in all the real definitions. */ +typedef struct QEMUTimer QEMUTimer; +typedef struct QEMUFile QEMUFile; +typedef struct QEMUBH QEMUBH; + +struct Monitor; +typedef struct Monitor Monitor; +typedef struct MigrationParams MigrationParams; + +typedef struct Property Property; +typedef struct PropertyInfo PropertyInfo; +typedef struct CompatProperty CompatProperty; +typedef struct DeviceState DeviceState; +typedef struct BusState BusState; +typedef struct BusClass BusClass; + +typedef struct NICInfo NICInfo; +typedef struct HCIInfo HCIInfo; +typedef struct AudioState AudioState; +typedef struct BlockDriverState BlockDriverState; +typedef struct DriveInfo DriveInfo; +typedef struct DisplayState DisplayState; +typedef struct DisplayChangeListener DisplayChangeListener; +typedef struct DisplaySurface DisplaySurface; +typedef struct PixelFormat PixelFormat; +typedef struct QemuConsole QemuConsole; +typedef struct CharDriverState CharDriverState; +typedef struct MACAddr MACAddr; +typedef struct NetClientState NetClientState; +typedef struct i2c_bus i2c_bus; +typedef struct ISABus ISABus; +typedef struct ISADevice ISADevice; +typedef struct SMBusDevice SMBusDevice; +typedef struct PCIHostState PCIHostState; +typedef struct PCIExpressHost PCIExpressHost; +typedef struct PCIBus PCIBus; +typedef struct PCIDevice PCIDevice; +typedef struct PCIExpressDevice PCIExpressDevice; +typedef struct PCIBridge PCIBridge; +typedef struct PCIEAERMsg PCIEAERMsg; +typedef struct PCIEAERLog PCIEAERLog; +typedef struct PCIEAERErr PCIEAERErr; +typedef struct PCIEPort PCIEPort; +typedef struct PCIESlot PCIESlot; +typedef struct MSIMessage MSIMessage; +typedef struct SerialState SerialState; +typedef struct PCMCIACardState PCMCIACardState; +typedef struct MouseTransformInfo MouseTransformInfo; +typedef struct uWireSlave uWireSlave; +typedef struct I2SCodec I2SCodec; +typedef struct SSIBus SSIBus; +typedef struct EventNotifier EventNotifier; +typedef struct VirtIODevice VirtIODevice; +typedef struct QEMUSGList QEMUSGList; +typedef struct SHPCDevice SHPCDevice; + +#endif /* QEMU_TYPEDEFS_H */ From bcf7930105c26d09ae83cbd8b982d01bb421f215 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 23 Oct 2012 21:44:08 -0200 Subject: [PATCH 08/13] sysemu.h: Include qemu-types.h instead of qemu-common.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It just needs the Monitor and DeviceState typedefs, so it doesn't need all of qemu-common.h. Signed-off-by: Eduardo Habkost Signed-off-by: Andreas Färber --- sysemu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysemu.h b/sysemu.h index f5ac664067..ab1ef8be5f 100644 --- a/sysemu.h +++ b/sysemu.h @@ -2,7 +2,7 @@ #define SYSEMU_H /* Misc. things related to the system emulator. */ -#include "qemu-common.h" +#include "qemu-types.h" #include "qemu-option.h" #include "qemu-queue.h" #include "qemu-timer.h" From 23e3fbec3355e67dbf26e98bbe33ef354097df8e Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 4 Dec 2012 11:19:34 -0200 Subject: [PATCH 09/13] qdev: qdev_create(): use error_report() instead of hw_error() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hw_error() is specific for fatal hardware emulation errors, not for internal errors related to the qdev object/class abstraction or object initialization. Replace it with an error_report() call, followed by abort(). This will also help reduce dependencies of the qdev code (as hw_error() is from cpus.o, and depends on the CPU list from exec.o). Signed-off-by: Eduardo Habkost Signed-off-by: Andreas Färber --- hw/qdev.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 788b4da55c..599382cab2 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -109,10 +109,12 @@ DeviceState *qdev_create(BusState *bus, const char *name) dev = qdev_try_create(bus, name); if (!dev) { if (bus) { - hw_error("Unknown device '%s' for bus '%s'\n", name, - object_get_typename(OBJECT(bus))); + error_report("Unknown device '%s' for bus '%s'\n", name, + object_get_typename(OBJECT(bus))); + abort(); } else { - hw_error("Unknown device '%s' for default sysbus\n", name); + error_report("Unknown device '%s' for default sysbus\n", name); + abort(); } } From 9f3fb5657b2133a408ccf40b4ab57dec9b4ce771 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 4 Dec 2012 17:34:38 -0200 Subject: [PATCH 10/13] target-i386/cpu.c: Coding style fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use spaces instead of tabs on cpu_x86_cpuid(). - Use braces on 'if' statement cpu_x86_find_by_name(). Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov Signed-off-by: Andreas Färber --- target-i386/cpu.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index c6c2ca03a1..754af6840b 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1215,7 +1215,7 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) char *s = g_strdup(cpu_model); char *featurestr, *name = strtok(s, ","); - /* Features to be added*/ + /* Features to be added */ uint32_t plus_features = 0, plus_ext_features = 0; uint32_t plus_ext2_features = 0, plus_ext3_features = 0; uint32_t plus_kvm_features = kvm_default_features, plus_svm_features = 0; @@ -1227,9 +1227,11 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) uint32_t minus_7_0_ebx_features = 0; uint32_t numvalue; - for (def = x86_defs; def; def = def->next) - if (name && !strcmp(name, def->name)) + for (def = x86_defs; def; def = def->next) { + if (name && !strcmp(name, def->name)) { break; + } + } if (kvm_enabled() && name && strcmp(name, "host") == 0) { kvm_cpu_fill_host(x86_cpu_def); } else if (!def) { @@ -1835,17 +1837,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } break; case 0x8000000A: - if (env->cpuid_ext3_features & CPUID_EXT3_SVM) { - *eax = 0x00000001; /* SVM Revision */ - *ebx = 0x00000010; /* nr of ASIDs */ - *ecx = 0; - *edx = env->cpuid_svm_features; /* optional features */ - } else { - *eax = 0; - *ebx = 0; - *ecx = 0; - *edx = 0; - } + if (env->cpuid_ext3_features & CPUID_EXT3_SVM) { + *eax = 0x00000001; /* SVM Revision */ + *ebx = 0x00000010; /* nr of ASIDs */ + *ecx = 0; + *edx = env->cpuid_svm_features; /* optional features */ + } else { + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; + } break; case 0xC0000000: *eax = env->cpuid_xlevel2; From 8f961357d06a0beeb7d3efbde1d754d82ff6a300 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 4 Dec 2012 17:34:39 -0200 Subject: [PATCH 11/13] target-i386: Separate feature string parsing from CPU model lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of parsing the whole cpu_model string inside cpu_x86_find_by_name(), 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. This should also help on the CPU properties work, that will just need to replace the cpu_x86_parse_featurestr() logic (and can keep the CPU model lookup code as-is). Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov Signed-off-by: Andreas Färber --- target-i386/cpu.c | 69 +++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 754af6840b..7877df174e 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1208,13 +1208,32 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, cpu->env.tsc_khz = value / 1000; } -static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) +static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name) { - unsigned int i; x86_def_t *def; - char *s = g_strdup(cpu_model); - char *featurestr, *name = strtok(s, ","); + for (def = x86_defs; def; def = def->next) { + if (name && !strcmp(name, def->name)) { + break; + } + } + if (kvm_enabled() && name && strcmp(name, "host") == 0) { + kvm_cpu_fill_host(x86_cpu_def); + } else if (!def) { + return -1; + } else { + memcpy(x86_cpu_def, def, sizeof(*def)); + } + + return 0; +} + +/* Parse "+feature,-feature,feature=foo" CPU feature string + */ +static int cpu_x86_parse_featurestr(x86_def_t *x86_cpu_def, char *features) +{ + unsigned int i; + char *featurestr; /* Single 'key=value" string being parsed */ /* Features to be added */ uint32_t plus_features = 0, plus_ext_features = 0; uint32_t plus_ext2_features = 0, plus_ext3_features = 0; @@ -1227,24 +1246,11 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) uint32_t minus_7_0_ebx_features = 0; uint32_t numvalue; - for (def = x86_defs; def; def = def->next) { - if (name && !strcmp(name, def->name)) { - break; - } - } - if (kvm_enabled() && name && strcmp(name, "host") == 0) { - kvm_cpu_fill_host(x86_cpu_def); - } else if (!def) { - goto error; - } else { - memcpy(x86_cpu_def, def, sizeof(*def)); - } - add_flagname_to_bitmaps("hypervisor", &plus_features, &plus_ext_features, &plus_ext2_features, &plus_ext3_features, &plus_kvm_features, &plus_svm_features, &plus_7_0_ebx_features); - featurestr = strtok(NULL, ","); + featurestr = features ? strtok(features, ",") : NULL; while (featurestr) { char *val; @@ -1378,11 +1384,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) if (x86_cpu_def->cpuid_7_0_ebx_features && x86_cpu_def->level < 7) { x86_cpu_def->level = 7; } - g_free(s); return 0; error: - g_free(s); return -1; } @@ -1492,11 +1496,25 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) CPUX86State *env = &cpu->env; x86_def_t def1, *def = &def1; Error *error = NULL; + char *name, *features; + gchar **model_pieces; memset(def, 0, sizeof(*def)); - if (cpu_x86_find_by_name(def, cpu_model) < 0) - return -1; + model_pieces = g_strsplit(cpu_model, ",", 2); + if (!model_pieces[0]) { + goto error; + } + name = model_pieces[0]; + features = model_pieces[1]; + + if (cpu_x86_find_by_name(def, name) < 0) { + goto error; + } + + if (cpu_x86_parse_featurestr(def, features) < 0) { + goto error; + } if (def->vendor1) { env->cpuid_vendor1 = def->vendor1; env->cpuid_vendor2 = def->vendor2; @@ -1553,9 +1571,14 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) if (error) { fprintf(stderr, "%s\n", error_get_pretty(error)); error_free(error); - return -1; + goto error; } + + g_strfreev(model_pieces); return 0; +error: + g_strfreev(model_pieces); + return -1; } #if !defined(CONFIG_USER_ONLY) From 9df694eeb8447ae5a302b4d40df9a8b91dfc61da Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 22 Oct 2012 17:03:10 +0200 Subject: [PATCH 12/13] target-i386: Use define for cpuid vendor string size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Igor Mammedov Reviewed-by: Eduardo Habkost Signed-off-by: Andreas Färber --- target-i386/cpu.c | 6 +++--- target-i386/cpu.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 7877df174e..a631ae9c87 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1106,13 +1106,13 @@ static char *x86_cpuid_get_vendor(Object *obj, Error **errp) char *value; int i; - value = (char *)g_malloc(12 + 1); + value = (char *)g_malloc(CPUID_VENDOR_SZ + 1); for (i = 0; i < 4; i++) { value[i ] = env->cpuid_vendor1 >> (8 * i); value[i + 4] = env->cpuid_vendor2 >> (8 * i); value[i + 8] = env->cpuid_vendor3 >> (8 * i); } - value[12] = '\0'; + value[CPUID_VENDOR_SZ] = '\0'; return value; } @@ -1123,7 +1123,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value, CPUX86State *env = &cpu->env; int i; - if (strlen(value) != 12) { + if (strlen(value) != CPUID_VENDOR_SZ) { error_set(errp, QERR_PROPERTY_VALUE_BAD, "", "vendor", value); return; diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 90ef1ff1e2..386c4f6d98 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -510,6 +510,8 @@ #define CPUID_7_0_EBX_ADX (1 << 19) #define CPUID_7_0_EBX_SMAP (1 << 20) +#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" */ From b34d12d153e6e5c5e5e00eac510b054a94409deb Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 22 Oct 2012 17:03:00 +0200 Subject: [PATCH 13/13] target-i386: Postpone cpuid_level update to realize time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delay capping cpuid_level to 7 to realize time so property setters for cpuid_7_0_ebx_features and "level" could be used in any order/time between x86_cpu_initfn() and x86_cpu_realize(). Signed-off-by: Igor Mammedov Signed-off-by: Eduardo Habkost Signed-off-by: Andreas Färber --- target-i386/cpu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index a631ae9c87..7be3ad82cb 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1381,9 +1381,6 @@ static int cpu_x86_parse_featurestr(x86_def_t *x86_cpu_def, char *features) if (kvm_check_features_against_host(x86_cpu_def) && enforce_cpuid) goto error; } - if (x86_cpu_def->cpuid_7_0_ebx_features && x86_cpu_def->level < 7) { - x86_cpu_def->level = 7; - } return 0; error: @@ -2074,6 +2071,11 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp) void x86_cpu_realize(Object *obj, Error **errp) { X86CPU *cpu = X86_CPU(obj); + CPUX86State *env = &cpu->env; + + if (env->cpuid_7_0_ebx_features && env->cpuid_level < 7) { + env->cpuid_level = 7; + } #ifndef CONFIG_USER_ONLY qemu_register_reset(x86_cpu_machine_reset_cb, cpu);