From patchwork Tue Aug 13 18:03:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 266901 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (unknown [IPv6:2001:4830:134:3::12]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CA88D2C0148 for ; Wed, 14 Aug 2013 04:24:39 +1000 (EST) Received: from localhost ([::1]:59881 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9JGl-0003JK-W5 for incoming@patchwork.ozlabs.org; Tue, 13 Aug 2013 14:24:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9JGT-0003I7-OK for qemu-devel@nongnu.org; Tue, 13 Aug 2013 14:24:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V9JGQ-000587-TV for qemu-devel@nongnu.org; Tue, 13 Aug 2013 14:24:17 -0400 Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:1d0::1]:59223 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9JGQ-00057t-MA for qemu-devel@nongnu.org; Tue, 13 Aug 2013 14:24:14 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1V9Ivv-00081v-Eo; Tue, 13 Aug 2013 19:03:03 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 13 Aug 2013 19:03:02 +0100 Message-Id: <1376416983-30838-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1376416983-30838-1-git-send-email-peter.maydell@linaro.org> References: <1376416983-30838-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: kvmarm@lists.cs.columbia.edu, =?UTF-8?q?Andreas=20F=C3=A4rber?= , patches@linaro.org Subject: [Qemu-devel] [RFC 1/2] target-arm: Don't hardcode KVM target CPU to be A15 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Instead of assuming that a KVM target CPU must always be a Cortex-A15 and hardcoding this in kvm_arch_init_vcpu(), look up the KVM_ARM_TARGET_* value based on the ARMCPU object type. This is slightly overengineered for a single supported CPU but provides a place to put support for future CPUs and for "-cpu host". Signed-off-by: Peter Maydell --- target-arm/kvm.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/target-arm/kvm.c b/target-arm/kvm.c index b92e00d..0e33efc 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -70,6 +70,32 @@ static int compare_u64(const void *a, const void *b) return *(uint64_t *)a - *(uint64_t *)b; } +static bool kvm_arm_get_init_args(ARMCPU *cpu, struct kvm_vcpu_init *init) +{ + /* Fill in the kvm_vcpu_init struct appropriately for this CPU. + * Return true on success, false on failure (ie unsupported CPU). + */ + Object *obj = OBJECT(cpu); + int i; + static const struct { + const char *name; + uint32_t target; + } kvm_cpus[] = { + { "cortex-a15-" TYPE_ARM_CPU, KVM_ARM_TARGET_CORTEX_A15 }, + }; + + memset(init->features, 0, sizeof(init->features)); + + for (i = 0; i < ARRAY_SIZE(kvm_cpus); i++) { + if (object_dynamic_cast(obj, kvm_cpus[i].name)) { + init->target = kvm_cpus[i].target; + return true; + } + } + + return false; +} + int kvm_arch_init_vcpu(CPUState *cs) { struct kvm_vcpu_init init; @@ -80,8 +106,10 @@ int kvm_arch_init_vcpu(CPUState *cs) struct kvm_reg_list *rlp; ARMCPU *cpu = ARM_CPU(cs); - init.target = KVM_ARM_TARGET_CORTEX_A15; - memset(init.features, 0, sizeof(init.features)); + if (!kvm_arm_get_init_args(cpu, &init)) { + fprintf(stderr, "KVM is not supported for this guest CPU type\n"); + return -EINVAL; + } ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init); if (ret) { return ret;