qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC 1/2] target-arm: Don't hardcode KVM target CPU to be A


From: Peter Maydell
Subject: [Qemu-devel] [RFC 1/2] target-arm: Don't hardcode KVM target CPU to be A15
Date: Tue, 13 Aug 2013 19:03:02 +0100

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 <address@hidden>
---
 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;
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]