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: 19095 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4EB7C25E7A for ; Tue, 13 Aug 2013 18:03:11 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id bq6sf719027qab.6 for ; Tue, 13 Aug 2013 11:03:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=R8LXdSa5Ud6qOKRXGQrlEZN+6NKI54ud0libeTxBi+M=; b=lPJssm9fkfqBLzdT8tAnTb8WbmWlvW9/F0VdE9cYz5AJzi1i0DYAuoOtabfl48ItGY /hfrt14/NNANSPjAhf3FP8p9PjUsZJLDHcQcqT8Tq9CdMJpeuwuZChbDpjw8Je6mOLLx JscCn88eeUB6DJg/PZrPzMpf+sXHQeIrhpkQ29LNAPQ3QQaHY7bnpGFjWQ9Dmd1PLEEJ R3z6fNn7toEvqH4dcmIVXPSd8GRajmi+m2+H4dQI8MRhyKLfAVIglTUYi0IdbtbSkhuH 7UhsVrEYXuwxVchFxYjX+gDizfuSEe+bWv5Okzyq9x71ZopQbWewQAhtQ8D1gFk1gOfl 6Ilg== X-Received: by 10.236.74.169 with SMTP id x29mr2119917yhd.34.1376416991018; Tue, 13 Aug 2013 11:03:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.117.129 with SMTP id ke1ls2672314qeb.88.gmail; Tue, 13 Aug 2013 11:03:10 -0700 (PDT) X-Received: by 10.52.65.180 with SMTP id y20mr241483vds.47.1376416990910; Tue, 13 Aug 2013 11:03:10 -0700 (PDT) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id c13si10057486veu.39.2013.08.13.11.03.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 Aug 2013 11:03:10 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.171; Received: by mail-ve0-f171.google.com with SMTP id pa12so6903593veb.30 for ; Tue, 13 Aug 2013 11:03:10 -0700 (PDT) X-Gm-Message-State: ALoCoQn3f4EcFA3WXBApSnw108CrRn7TaJJ5T9F0JHmf+js3J6pUdZli3cAxVcWm/r3z0H+UeQJv X-Received: by 10.52.180.229 with SMTP id dr5mr4602512vdc.20.1376416990803; Tue, 13 Aug 2013 11:03:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp167826vcz; Tue, 13 Aug 2013 11:03:10 -0700 (PDT) X-Received: by 10.205.112.198 with SMTP id et6mr52548bkc.40.1376416987360; Tue, 13 Aug 2013 11:03:07 -0700 (PDT) Received: from mnementh.archaic.org.uk (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]) by mx.google.com with ESMTPS id yk4si5280059bkb.284.2013.08.13.11.03.06 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 13 Aug 2013 11:03:07 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; 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 Cc: patches@linaro.org, kvmarm@lists.cs.columbia.edu, =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [RFC 1/2] target-arm: Don't hardcode KVM target CPU to be A15 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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;