public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: kvm@vger.kernel.org
Cc: penberg@kernel.org, sasha.levin@oracle.com, marc.zyngier@arm.com,
	Marc Zyngier <Marc.Zyngier@arm.com>,
	Will Deacon <will.deacon@arm.com>
Subject: [PATCH 2/5] kvm tools: arm: add CPU compatible string to target structure
Date: Thu, 11 Apr 2013 17:36:23 +0100	[thread overview]
Message-ID: <1365698186-27355-3-git-send-email-will.deacon@arm.com> (raw)
In-Reply-To: <1365698186-27355-1-git-send-email-will.deacon@arm.com>

From: Marc Zyngier <Marc.Zyngier@arm.com>

Instead of hardcoding the CPU compatible string, store it in
the target descriptor. This allows similar CPUs to be managed
by the same backend, and yet have different compatible
properties.

Also remove a check for a condition that can never occur in both
A15 and A57 backends.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 tools/kvm/arm/aarch32/cortex-a15.c              | 12 ++++--------
 tools/kvm/arm/aarch64/cortex-a57.c              | 12 ++++--------
 tools/kvm/arm/include/arm-common/kvm-cpu-arch.h |  6 ++++--
 tools/kvm/arm/kvm-cpu.c                         |  9 ++++++---
 4 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/tools/kvm/arm/aarch32/cortex-a15.c b/tools/kvm/arm/aarch32/cortex-a15.c
index 8031747..4030e53 100644
--- a/tools/kvm/arm/aarch32/cortex-a15.c
+++ b/tools/kvm/arm/aarch32/cortex-a15.c
@@ -20,16 +20,11 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
 	for (cpu = 0; cpu < kvm->nrcpus; ++cpu) {
 		char cpu_name[CPU_NAME_MAX_LEN];
 
-		if (kvm->cpus[cpu]->cpu_type != KVM_ARM_TARGET_CORTEX_A15) {
-			pr_warning("Ignoring unknown type for CPU %d\n", cpu);
-			continue;
-		}
-
 		snprintf(cpu_name, CPU_NAME_MAX_LEN, "cpu@%d", cpu);
 
 		_FDT(fdt_begin_node(fdt, cpu_name));
 		_FDT(fdt_property_string(fdt, "device_type", "cpu"));
-		_FDT(fdt_property_string(fdt, "compatible", "arm,cortex-a15"));
+		_FDT(fdt_property_string(fdt, "compatible", kvm->cpus[cpu]->cpu_compatible));
 
 		if (kvm->nrcpus > 1)
 			_FDT(fdt_property_string(fdt, "enable-method", "psci"));
@@ -83,8 +78,9 @@ static int cortex_a15__vcpu_init(struct kvm_cpu *vcpu)
 }
 
 static struct kvm_arm_target target_cortex_a15 = {
-	.id	= KVM_ARM_TARGET_CORTEX_A15,
-	.init	= cortex_a15__vcpu_init,
+	.id		= KVM_ARM_TARGET_CORTEX_A15,
+	.compatible	= "arm,cortex-a15",
+	.init		= cortex_a15__vcpu_init,
 };
 
 static int cortex_a15__core_init(struct kvm *kvm)
diff --git a/tools/kvm/arm/aarch64/cortex-a57.c b/tools/kvm/arm/aarch64/cortex-a57.c
index 4fd11ba..f636ef7 100644
--- a/tools/kvm/arm/aarch64/cortex-a57.c
+++ b/tools/kvm/arm/aarch64/cortex-a57.c
@@ -20,16 +20,11 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
 	for (cpu = 0; cpu < kvm->nrcpus; ++cpu) {
 		char cpu_name[CPU_NAME_MAX_LEN];
 
-		if (kvm->cpus[cpu]->cpu_type != KVM_ARM_TARGET_CORTEX_A57) {
-			pr_warning("Ignoring unknown type for CPU %d\n", cpu);
-			continue;
-		}
-
 		snprintf(cpu_name, CPU_NAME_MAX_LEN, "cpu@%d", cpu);
 
 		_FDT(fdt_begin_node(fdt, cpu_name));
 		_FDT(fdt_property_string(fdt, "device_type", "cpu"));
-		_FDT(fdt_property_string(fdt, "compatible", "arm,cortex-a57"));
+		_FDT(fdt_property_string(fdt, "compatible", kvm->cpus[cpu]->cpu_compatible));
 
 		if (kvm->nrcpus > 1)
 			_FDT(fdt_property_string(fdt, "enable-method", "psci"));
@@ -84,8 +79,9 @@ static int cortex_a57__vcpu_init(struct kvm_cpu *vcpu)
 }
 
 static struct kvm_arm_target target_cortex_a57 = {
-	.id	= KVM_ARM_TARGET_CORTEX_A57,
-	.init	= cortex_a57__vcpu_init,
+	.id		= KVM_ARM_TARGET_CORTEX_A57,
+	.compatible	= "arm,cortex-a57",
+	.init		= cortex_a57__vcpu_init,
 };
 
 static int cortex_a57__core_init(struct kvm *kvm)
diff --git a/tools/kvm/arm/include/arm-common/kvm-cpu-arch.h b/tools/kvm/arm/include/arm-common/kvm-cpu-arch.h
index 351fbe6..b514dd5 100644
--- a/tools/kvm/arm/include/arm-common/kvm-cpu-arch.h
+++ b/tools/kvm/arm/include/arm-common/kvm-cpu-arch.h
@@ -12,6 +12,7 @@ struct kvm_cpu {
 
 	unsigned long	cpu_id;
 	unsigned long	cpu_type;
+	const char	*cpu_compatible;
 
 	struct kvm	*kvm;
 	int		vcpu_fd;
@@ -28,8 +29,9 @@ struct kvm_cpu {
 };
 
 struct kvm_arm_target {
-	u32	id;
-	int	(*init)(struct kvm_cpu *vcpu);
+	u32		id;
+	const char 	*compatible;
+	int		(*init)(struct kvm_cpu *vcpu);
 };
 
 int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target);
diff --git a/tools/kvm/arm/kvm-cpu.c b/tools/kvm/arm/kvm-cpu.c
index 2716690..6d4f306 100644
--- a/tools/kvm/arm/kvm-cpu.c
+++ b/tools/kvm/arm/kvm-cpu.c
@@ -30,6 +30,7 @@ int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target)
 
 struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
 {
+	struct kvm_arm_target *target;
 	struct kvm_cpu *vcpu;
 	int coalesced_offset, mmap_size, err = -1;
 	unsigned int i;
@@ -58,13 +59,14 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
 	for (i = 0; i < ARRAY_SIZE(kvm_arm_targets); ++i) {
 		if (!kvm_arm_targets[i])
 			continue;
-		vcpu_init.target = kvm_arm_targets[i]->id;
+		target = kvm_arm_targets[i];
+		vcpu_init.target = target->id;
 		err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init);
 		if (!err)
 			break;
 	}
 
-	if (err || kvm_arm_targets[i]->init(vcpu))
+	if (err || target->init(vcpu))
 		die("Unable to initialise ARM vcpu");
 
 	coalesced_offset = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION,
@@ -76,7 +78,8 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
 	/* Populate the vcpu structure. */
 	vcpu->kvm		= kvm;
 	vcpu->cpu_id		= cpu_id;
-	vcpu->cpu_type		= vcpu_init.target;
+	vcpu->cpu_type		= target->id;
+	vcpu->cpu_compatible	= target->compatible;
 	vcpu->is_running	= true;
 	return vcpu;
 }
-- 
1.8.0


  parent reply	other threads:[~2013-04-11 16:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 16:36 [PATCH 0/5] Usual batch of random ARM fixes for kvmtool Will Deacon
2013-04-11 16:36 ` [PATCH 1/5] kvm tools: arm: don't crash when no compatible CPU is found Will Deacon
2013-04-11 16:36 ` Will Deacon [this message]
2013-04-11 16:36 ` [PATCH 3/5] kvm tools: arm: consolidate CPU node generation Will Deacon
2013-04-11 16:36 ` [PATCH 4/5] kvm tools: arm64: add support for AEM and Foundation models Will Deacon
2013-04-11 16:36 ` [PATCH 5/5] kvm tools: bump number of virtio MMIO vqueues Will Deacon
2013-04-11 16:45 ` [PATCH 0/5] Usual batch of random ARM fixes for kvmtool Sasha Levin
2013-04-12  6:52   ` Pekka Enberg
2013-04-12  8:30     ` Marc Zyngier
2013-04-12  8:50       ` Will Deacon
2013-04-11 20:02 ` virtio-net mq vq initialization (was: [PATCH 0/5] Usual batch of random ARM fixes for kvmtool) Sasha Levin
2013-04-12 11:36   ` Rusty Russell
2013-04-12 12:41     ` Will Deacon
2013-04-14 10:03       ` Michael S. Tsirkin
2013-04-13 21:23     ` virtio-net mq vq initialization Sasha Levin
2013-04-14 10:01       ` Michael S. Tsirkin
2013-04-14 15:16         ` Sasha Levin
2013-04-14 15:53           ` Michael S. Tsirkin
2013-04-14 15:59             ` Sasha Levin
2013-04-14 18:35               ` Michael S. Tsirkin
2013-04-15  2:55                 ` Rusty Russell
2013-04-15  5:58           ` Jason Wang
2013-04-22 18:32             ` Sasha Levin
2013-04-12  7:12 ` [PATCH 0/5] Usual batch of random ARM fixes for kvmtool Pekka Enberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365698186-27355-3-git-send-email-will.deacon@arm.com \
    --to=will.deacon@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=penberg@kernel.org \
    --cc=sasha.levin@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox