From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LV6R8-0007s1-1W for qemu-devel@nongnu.org; Thu, 05 Feb 2009 10:46:42 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LV6R7-0007rT-EO for qemu-devel@nongnu.org; Thu, 05 Feb 2009 10:46:41 -0500 Received: from [199.232.76.173] (port=37640 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LV6R7-0007rG-72 for qemu-devel@nongnu.org; Thu, 05 Feb 2009 10:46:41 -0500 Received: from mx2.redhat.com ([66.187.237.31]:46362) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LV6R6-0005Ep-Ih for qemu-devel@nongnu.org; Thu, 05 Feb 2009 10:46:40 -0500 From: Glauber Costa Date: Thu, 5 Feb 2009 10:35:06 -0500 Message-Id: <1233848107-9331-2-git-send-email-glommer@redhat.com> In-Reply-To: <1233848107-9331-1-git-send-email-glommer@redhat.com> References: <1233848107-9331-1-git-send-email-glommer@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] Factor out common code in filling cpuid code Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com Use kvm_fill_cpuid to query qemu for cpuid data. There are two exactly equal instances of this code, and the future introduction of kvm paravirt features will make it three. Signed-off-by: Glauber Costa --- target-i386/kvm.c | 49 ++++++++++++++++++++++++------------------------- 1 files changed, 24 insertions(+), 25 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 49766e2..4a55931 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -33,22 +33,19 @@ do { } while (0) #endif -int kvm_arch_init_vcpu(CPUState *env) +typedef struct { + struct kvm_cpuid cpuid; + struct kvm_cpuid_entry entries[100]; +} KVMCpuid; + +static void kvm_fill_cpuid(CPUState *env, KVMCpuid *cpuid_data, + uint32_t start, uint32_t limit) { - struct { - struct kvm_cpuid cpuid; - struct kvm_cpuid_entry entries[100]; - } __attribute__((packed)) cpuid_data; - uint32_t limit, i, cpuid_i; + int i; uint32_t eax, ebx, ecx, edx; - cpuid_i = 0; - - cpu_x86_cpuid(env, 0, &eax, &ebx, &ecx, &edx); - limit = eax; - - for (i = 0; i <= limit; i++) { - struct kvm_cpuid_entry *c = &cpuid_data.entries[cpuid_i++]; + for (i = start; i <= limit; i++) { + struct kvm_cpuid_entry *c = &cpuid_data->entries[cpuid_data->cpuid.nent++]; cpu_x86_cpuid(env, i, &eax, &ebx, &ecx, &edx); c->function = i; @@ -57,22 +54,24 @@ int kvm_arch_init_vcpu(CPUState *env) c->ecx = ecx; c->edx = edx; } +} - cpu_x86_cpuid(env, 0x80000000, &eax, &ebx, &ecx, &edx); - limit = eax; +int kvm_arch_init_vcpu(CPUState *env) +{ + KVMCpuid cpuid_data; + uint32_t limit; + uint32_t eax, ebx, ecx, edx; - for (i = 0x80000000; i <= limit; i++) { - struct kvm_cpuid_entry *c = &cpuid_data.entries[cpuid_i++]; + cpuid_data.cpuid.nent = 0; - cpu_x86_cpuid(env, i, &eax, &ebx, &ecx, &edx); - c->function = i; - c->eax = eax; - c->ebx = ebx; - c->ecx = ecx; - c->edx = edx; - } + cpu_x86_cpuid(env, 0, &eax, &ebx, &ecx, &edx); + limit = eax; - cpuid_data.cpuid.nent = cpuid_i; + kvm_fill_cpuid(env, &cpuid_data, 0, limit); + + cpu_x86_cpuid(env, 0x80000000, &eax, &ebx, &ecx, &edx); + limit = eax; + kvm_fill_cpuid(env, &cpuid_data, 0x80000000, limit); return kvm_vcpu_ioctl(env, KVM_SET_CPUID, &cpuid_data); } -- 1.5.6.5