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 3/5] kvm tools: arm: consolidate CPU node generation
Date: Thu, 11 Apr 2013 17:36:24 +0100	[thread overview]
Message-ID: <1365698186-27355-4-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>

Now that generate_cpu_nodes uses the cpu_compatible field to
output the compatible property, we can unify the A15 and A57
implementations, as they are strictly identical.

Move the function to fdt.c, together with most of the device
tree generation.

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 | 29 -----------------------------
 tools/kvm/arm/aarch64/cortex-a57.c | 29 -----------------------------
 tools/kvm/arm/fdt.c                | 35 ++++++++++++++++++++++++++++++++---
 3 files changed, 32 insertions(+), 61 deletions(-)

diff --git a/tools/kvm/arm/aarch32/cortex-a15.c b/tools/kvm/arm/aarch32/cortex-a15.c
index 4030e53..ca65af7 100644
--- a/tools/kvm/arm/aarch32/cortex-a15.c
+++ b/tools/kvm/arm/aarch32/cortex-a15.c
@@ -8,34 +8,6 @@
 #include <linux/byteorder.h>
 #include <linux/types.h>
 
-#define CPU_NAME_MAX_LEN 8
-static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
-{
-	int cpu;
-
-	_FDT(fdt_begin_node(fdt, "cpus"));
-	_FDT(fdt_property_cell(fdt, "#address-cells", 0x1));
-	_FDT(fdt_property_cell(fdt, "#size-cells", 0x0));
-
-	for (cpu = 0; cpu < kvm->nrcpus; ++cpu) {
-		char cpu_name[CPU_NAME_MAX_LEN];
-
-		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", kvm->cpus[cpu]->cpu_compatible));
-
-		if (kvm->nrcpus > 1)
-			_FDT(fdt_property_string(fdt, "enable-method", "psci"));
-
-		_FDT(fdt_property_cell(fdt, "reg", cpu));
-		_FDT(fdt_end_node(fdt));
-	}
-
-	_FDT(fdt_end_node(fdt));
-}
-
 static void generate_timer_nodes(void *fdt, struct kvm *kvm)
 {
 	u32 cpu_mask = (((1 << kvm->nrcpus) - 1) << GIC_FDT_IRQ_PPI_CPU_SHIFT) \
@@ -66,7 +38,6 @@ static void generate_timer_nodes(void *fdt, struct kvm *kvm)
 
 static void generate_fdt_nodes(void *fdt, struct kvm *kvm, u32 gic_phandle)
 {
-	generate_cpu_nodes(fdt, kvm);
 	gic__generate_fdt_nodes(fdt, gic_phandle);
 	generate_timer_nodes(fdt, kvm);
 }
diff --git a/tools/kvm/arm/aarch64/cortex-a57.c b/tools/kvm/arm/aarch64/cortex-a57.c
index f636ef7..5b0dc4c 100644
--- a/tools/kvm/arm/aarch64/cortex-a57.c
+++ b/tools/kvm/arm/aarch64/cortex-a57.c
@@ -8,34 +8,6 @@
 #include <linux/byteorder.h>
 #include <linux/types.h>
 
-#define CPU_NAME_MAX_LEN 8
-static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
-{
-	int cpu;
-
-	_FDT(fdt_begin_node(fdt, "cpus"));
-	_FDT(fdt_property_cell(fdt, "#address-cells", 0x1));
-	_FDT(fdt_property_cell(fdt, "#size-cells", 0x0));
-
-	for (cpu = 0; cpu < kvm->nrcpus; ++cpu) {
-		char cpu_name[CPU_NAME_MAX_LEN];
-
-		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", kvm->cpus[cpu]->cpu_compatible));
-
-		if (kvm->nrcpus > 1)
-			_FDT(fdt_property_string(fdt, "enable-method", "psci"));
-
-		_FDT(fdt_property_cell(fdt, "reg", cpu));
-		_FDT(fdt_end_node(fdt));
-	}
-
-	_FDT(fdt_end_node(fdt));
-}
-
 static void generate_timer_nodes(void *fdt, struct kvm *kvm)
 {
 	u32 cpu_mask = (((1 << kvm->nrcpus) - 1) << GIC_FDT_IRQ_PPI_CPU_SHIFT) \
@@ -66,7 +38,6 @@ static void generate_timer_nodes(void *fdt, struct kvm *kvm)
 
 static void generate_fdt_nodes(void *fdt, struct kvm *kvm, u32 gic_phandle)
 {
-	generate_cpu_nodes(fdt, kvm);
 	gic__generate_fdt_nodes(fdt, gic_phandle);
 	generate_timer_nodes(fdt, kvm);
 }
diff --git a/tools/kvm/arm/fdt.c b/tools/kvm/arm/fdt.c
index 20e0308..c61bf58 100644
--- a/tools/kvm/arm/fdt.c
+++ b/tools/kvm/arm/fdt.c
@@ -41,6 +41,34 @@ static void dump_fdt(const char *dtb_file, void *fdt)
 	close(fd);
 }
 
+#define CPU_NAME_MAX_LEN 8
+static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
+{
+	int cpu;
+
+	_FDT(fdt_begin_node(fdt, "cpus"));
+	_FDT(fdt_property_cell(fdt, "#address-cells", 0x1));
+	_FDT(fdt_property_cell(fdt, "#size-cells", 0x0));
+
+	for (cpu = 0; cpu < kvm->nrcpus; ++cpu) {
+		char cpu_name[CPU_NAME_MAX_LEN];
+
+		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", kvm->cpus[cpu]->cpu_compatible));
+
+		if (kvm->nrcpus > 1)
+			_FDT(fdt_property_string(fdt, "enable-method", "psci"));
+
+		_FDT(fdt_property_cell(fdt, "reg", cpu));
+		_FDT(fdt_end_node(fdt));
+	}
+
+	_FDT(fdt_end_node(fdt));
+}
+
 #define DEVICE_NAME_MAX_LEN 32
 static void generate_virtio_mmio_node(void *fdt, struct virtio_mmio *vmmio)
 {
@@ -77,7 +105,7 @@ static int setup_fdt(struct kvm *kvm)
 	void *fdt		= staging_fdt;
 	void *fdt_dest		= guest_flat_to_host(kvm,
 						     kvm->arch.dtb_guest_start);
-	void (*generate_cpu_nodes)(void *, struct kvm *, u32)
+	void (*generate_fdt_nodes)(void *, struct kvm *, u32)
 				= kvm->cpus[0]->generate_fdt_nodes;
 
 	/* Create new tree without a reserve map */
@@ -115,8 +143,9 @@ static int setup_fdt(struct kvm *kvm)
 	_FDT(fdt_end_node(fdt));
 
 	/* CPU and peripherals (interrupt controller, timers, etc) */
-	if (generate_cpu_nodes)
-		generate_cpu_nodes(fdt, kvm, gic_phandle);
+	generate_cpu_nodes(fdt, kvm);
+	if (generate_fdt_nodes)
+		generate_fdt_nodes(fdt, kvm, gic_phandle);
 
 	/* Virtio MMIO devices */
 	dev_hdr = device__first_dev(DEVICE_BUS_MMIO);
-- 
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 ` [PATCH 2/5] kvm tools: arm: add CPU compatible string to target structure Will Deacon
2013-04-11 16:36 ` Will Deacon [this message]
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-4-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