kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org
Cc: thuth@redhat.com, dgibson@redhat.com,
	david@gibson.dropbear.id.au, agraf@suse.de, lvivier@redhat.com,
	pbonzini@redhat.com
Subject: [kvm-unit-tests PATCH v3 05/17] arm/arm64: setup improvements
Date: Sat, 13 Feb 2016 17:28:18 +0100	[thread overview]
Message-ID: <1455380910-30604-6-git-send-email-drjones@redhat.com> (raw)
In-Reply-To: <1455380910-30604-1-git-send-email-drjones@redhat.com>

Handle multiple memory regions being described in the DT. Also
add a more informative error message for when a user does -smp N,
N > NR_CPUS.

Signed-off-by: Andrew Jones <drjones@redhat.com>

---
powerpc will adapt arm's setup to be used as it's own, and it
needs these changes. There's no reason to only do them for power,
so we do them in arm first, getting them ready to be adapted.
---
 lib/arm/asm/setup.h |  9 ++++++++
 lib/arm/setup.c     | 66 ++++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 56 insertions(+), 19 deletions(-)

diff --git a/lib/arm/asm/setup.h b/lib/arm/asm/setup.h
index 02b668672fca4..cb8fdbd38dd5d 100644
--- a/lib/arm/asm/setup.h
+++ b/lib/arm/asm/setup.h
@@ -6,6 +6,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #include <libcflat.h>
+#include <alloc.h>	/* phys_addr_t */
 #include <asm/page.h>
 #include <asm/pgtable-hwdef.h>
 
@@ -13,6 +14,14 @@
 extern u32 cpus[NR_CPUS];
 extern int nr_cpus;
 
+#define NR_MEM_REGIONS		8
+#define MR_F_PRIMARY		(1U << 0)
+struct mem_region {
+	phys_addr_t start;
+	phys_addr_t end;
+	unsigned int flags;
+};
+extern struct mem_region mem_regions[NR_MEM_REGIONS];
 extern phys_addr_t __phys_offset, __phys_end;
 
 #define PHYS_OFFSET		(__phys_offset)
diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index da6edc1f9d8ff..8c6172ff94106 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -27,12 +27,18 @@ extern void setup_args(const char *args);
 u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
 int nr_cpus;
 
+struct mem_region mem_regions[NR_MEM_REGIONS];
 phys_addr_t __phys_offset, __phys_end;
 
 static void cpu_set(int fdtnode __unused, u32 regval, void *info __unused)
 {
 	int cpu = nr_cpus++;
-	assert(cpu < NR_CPUS);
+
+	if (cpu >= NR_CPUS) {
+		printf("Number cpus exceeds maximum supported (%d).\n",
+			NR_CPUS);
+		assert(0);
+	}
 	cpus[cpu] = regval;
 	set_cpu_present(cpu, true);
 }
@@ -49,24 +55,46 @@ static void cpu_init(void)
 
 static void mem_init(phys_addr_t freemem_start)
 {
-	/* we only expect one membank to be defined in the DT */
-	struct dt_pbus_reg regs[1];
-	phys_addr_t mem_start, mem_end;
-	int ret;
-
-	ret = dt_get_memory_params(regs, 1);
-	assert(ret != 0);
-
-	mem_start = regs[0].addr;
-	mem_end = mem_start + regs[0].size;
-
-	assert(!(mem_start & ~PHYS_MASK) && !((mem_end-1) & ~PHYS_MASK));
-	assert(freemem_start >= mem_start && freemem_start < mem_end);
-
-	__phys_offset = mem_start;	/* PHYS_OFFSET */
-	__phys_end = mem_end;		/* PHYS_END */
-
-	phys_alloc_init(freemem_start, mem_end - freemem_start);
+	struct dt_pbus_reg regs[NR_MEM_REGIONS];
+	struct mem_region primary, mem = {
+		.start = (phys_addr_t)-1,
+	};
+	int nr_regs, i;
+
+	nr_regs = dt_get_memory_params(regs, NR_MEM_REGIONS);
+	assert(nr_regs > 0);
+
+	primary.end = 0;
+
+	for (i = 0; i < nr_regs; ++i) {
+		mem_regions[i].start = regs[i].addr;
+		mem_regions[i].end = regs[i].addr + regs[i].size;
+
+		/*
+		 * pick the region we're in for our primary region
+		 */
+		if (freemem_start >= mem_regions[i].start
+				&& freemem_start < mem_regions[i].end) {
+			mem_regions[i].flags |= MR_F_PRIMARY;
+			primary = mem_regions[i];
+		}
+
+		/*
+		 * set the lowest and highest addresses found,
+		 * ignoring potential gaps
+		 */
+		if (mem_regions[i].start < mem.start)
+			mem.start = mem_regions[i].start;
+		if (mem_regions[i].end > mem.end)
+			mem.end = mem_regions[i].end;
+	}
+	assert(primary.end != 0);
+	assert(!(mem.start & ~PHYS_MASK) && !((mem.end - 1) & ~PHYS_MASK));
+
+	__phys_offset = mem.start;	/* PHYS_OFFSET */
+	__phys_end = mem.end;		/* PHYS_END */
+
+	phys_alloc_init(freemem_start, primary.end - freemem_start);
 	phys_alloc_set_minimum_alignment(SMP_CACHE_BYTES);
 
 	mmu_enable_idmap();
-- 
2.4.3


  parent reply	other threads:[~2016-02-13 16:28 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-13 16:28 [kvm-unit-tests PATCH v3 00/17] ppc64: initial drop Andrew Jones
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 01/17] arm/arm64: trivial: another assert fix Andrew Jones
2016-02-14 22:55   ` David Gibson
2016-02-15  6:38   ` Thomas Huth
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 02/17] Makefile: cscope: also look in arch shared asm Andrew Jones
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 03/17] lib: asm-generic: add missing casts Andrew Jones
2016-02-14 22:57   ` David Gibson
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 04/17] devicetree: fix dt_get_memory_params Andrew Jones
2016-02-14 23:00   ` David Gibson
2016-02-15  7:22     ` Thomas Huth
2016-02-13 16:28 ` Andrew Jones [this message]
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 06/17] lib: share arm-selftest utility functions Andrew Jones
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 07/17] config: no need to mix arch makefiles Andrew Jones
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 08/17] powerpc/ppc64: start skeleton framework Andrew Jones
2016-02-15  7:28   ` Thomas Huth
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 09/17] powerpc/ppc64: ppc-ify makefiles and linker script Andrew Jones
2016-02-15  7:46   ` Thomas Huth
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 10/17] powerpc/ppc64: add a boot rom Andrew Jones
2016-02-15  8:00   ` Thomas Huth
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 11/17] powerpc/ppc64: add hcall support and putchar Andrew Jones
2016-02-14 23:29   ` David Gibson
2016-02-15  8:44     ` Thomas Huth
2016-02-15  8:54     ` Andrew Jones
2016-02-15  8:58       ` Thomas Huth
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 12/17] powerpc/ppc64: adapt arm's setup Andrew Jones
2016-02-15  9:01   ` Thomas Huth
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 13/17] powerpc/ppc64: relocate linker VMAs Andrew Jones
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 14/17] powerpc/ppc64: add run script and unittests.cfg Andrew Jones
2016-02-15  9:36   ` Thomas Huth
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 15/17] mkstandalone: add support for powerpc Andrew Jones
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 16/17] powerpc/ppc64: add RTAS support Andrew Jones
2016-02-13 17:18   ` Andrew Jones
2016-02-15  9:59   ` Thomas Huth
2016-02-15 12:00     ` Andrew Jones
2016-02-15 12:15       ` Thomas Huth
2016-02-13 16:28 ` [kvm-unit-tests PATCH v3 17/17] powerpc/ppc64: make a fake debug-exit Andrew Jones
2016-02-15 10:01   ` Thomas Huth
2016-02-15 10:37 ` [kvm-unit-tests PATCH v3 00/17] ppc64: initial drop Laurent Vivier
2016-02-15 12:08   ` Andrew Jones
2016-02-15 12:12     ` Laurent Vivier

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=1455380910-30604-6-git-send-email-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=agraf@suse.de \
    --cc=david@gibson.dropbear.id.au \
    --cc=dgibson@redhat.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=thuth@redhat.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;
as well as URLs for NNTP newsgroup(s).