From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson Subject: Re: [kvm-unit-tests PATCH v4 05/17] arm/arm64: setup improvements Date: Tue, 16 Feb 2016 17:15:03 +1100 Message-ID: <20160216061503.GP2269@voom.redhat.com> References: <1455544166-19766-1-git-send-email-drjones@redhat.com> <1455544166-19766-6-git-send-email-drjones@redhat.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7PAM/4G1BR2SfWzg" Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, thuth@redhat.com, dgibson@redhat.com, agraf@suse.de, lvivier@redhat.com, pbonzini@redhat.com To: Andrew Jones Return-path: Received: from ozlabs.org ([103.22.144.67]:55503 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754544AbcBPKES (ORCPT ); Tue, 16 Feb 2016 05:04:18 -0500 Content-Disposition: inline In-Reply-To: <1455544166-19766-6-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: --7PAM/4G1BR2SfWzg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 15, 2016 at 02:49:14PM +0100, Andrew Jones wrote: > 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. >=20 > Signed-off-by: Andrew Jones Reviewed-by: David Gibson For whatever that's worth, given that I don't know ARM or kvm-unit-tests at all well. >=20 > --- > 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(-) >=20 > 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 > +#include /* phys_addr_t */ > #include > #include > =20 > @@ -13,6 +14,14 @@ > extern u32 cpus[NR_CPUS]; > extern int nr_cpus; > =20 > +#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; > =20 > #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] =3D { [0 ... NR_CPUS-1] =3D (~0U) }; > int nr_cpus; > =20 > +struct mem_region mem_regions[NR_MEM_REGIONS]; > phys_addr_t __phys_offset, __phys_end; > =20 > static void cpu_set(int fdtnode __unused, u32 regval, void *info __unuse= d) > { > int cpu =3D nr_cpus++; > - assert(cpu < NR_CPUS); > + > + if (cpu >=3D NR_CPUS) { > + printf("Number cpus exceeds maximum supported (%d).\n", > + NR_CPUS); > + assert(0); > + } > cpus[cpu] =3D regval; > set_cpu_present(cpu, true); > } > @@ -49,24 +55,46 @@ static void cpu_init(void) > =20 > 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 =3D dt_get_memory_params(regs, 1); > - assert(ret !=3D 0); > - > - mem_start =3D regs[0].addr; > - mem_end =3D mem_start + regs[0].size; > - > - assert(!(mem_start & ~PHYS_MASK) && !((mem_end-1) & ~PHYS_MASK)); > - assert(freemem_start >=3D mem_start && freemem_start < mem_end); > - > - __phys_offset =3D mem_start; /* PHYS_OFFSET */ > - __phys_end =3D 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 =3D { > + .start =3D (phys_addr_t)-1, > + }; > + int nr_regs, i; > + > + nr_regs =3D dt_get_memory_params(regs, NR_MEM_REGIONS); > + assert(nr_regs > 0); > + > + primary.end =3D 0; > + > + for (i =3D 0; i < nr_regs; ++i) { > + mem_regions[i].start =3D regs[i].addr; > + mem_regions[i].end =3D regs[i].addr + regs[i].size; > + > + /* > + * pick the region we're in for our primary region > + */ > + if (freemem_start >=3D mem_regions[i].start > + && freemem_start < mem_regions[i].end) { > + mem_regions[i].flags |=3D MR_F_PRIMARY; > + primary =3D mem_regions[i]; > + } > + > + /* > + * set the lowest and highest addresses found, > + * ignoring potential gaps > + */ > + if (mem_regions[i].start < mem.start) > + mem.start =3D mem_regions[i].start; > + if (mem_regions[i].end > mem.end) > + mem.end =3D mem_regions[i].end; > + } > + assert(primary.end !=3D 0); > + assert(!(mem.start & ~PHYS_MASK) && !((mem.end - 1) & ~PHYS_MASK)); > + > + __phys_offset =3D mem.start; /* PHYS_OFFSET */ > + __phys_end =3D mem.end; /* PHYS_END */ > + > + phys_alloc_init(freemem_start, primary.end - freemem_start); > phys_alloc_set_minimum_alignment(SMP_CACHE_BYTES); > =20 > mmu_enable_idmap(); --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --7PAM/4G1BR2SfWzg Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWwr5nAAoJEGw4ysog2bOSis0QALEk68JnvkSOHUl0GsfDBqp2 xwXLUfBUfqAxYEQArk+CSKLCOsFWZEsVWF6tyiAskJQvAhA03nakepMMVUIv9AdE RwN2qTPqENNChhu+wjNj26aDm84YF2/x2Pa4Qbv/POXJY2kJJXraCq88QN2hhwpO PTQC0KAbefiXAKQX441OZ4Ve/bmUgnJcBWo7x3SDrY6jzqrnupI06LzPn1I0QkYZ ZBVdVtUDCI9zKw4vYt/0gI3NFgGfTS7foM2oTiyFyuFQHcYV4dAnSXxpooZxcJtG 0Xx8zciyGbvxhvL5QoKTBxMAOHNFh1fifh2EjMTlq4zWnz9YTJdVFH++c+Dn+NQR tA2x1P0XHZgtZ65t6WQKPcXLWeQbIzc2OuUN4JK+tmwjxwuzzf5ATwUj1vQQYO6v ehLtHf/imViiwnmQnpW1tvAhL9Xks7IHzGxSN37NjwwfJeLoz4TKrpSE8Uczol8u 455FaYTR59vcOe8gIfW3+LyYX1ovkIP2u7B4FZAtznQBusMLNGD2hrVvuwhPF7mt bQzftWB75cZiXRaqweKtFCtWzd8dUTjKgE3TjeFvjzo2bpm6+rW36PlNWKszur/V ujQ4K+qL1blPh5qgLGeaq2bMNusS+M3lIIsq47ctnOS9Gxet0owgSIbDWXQbhUIA Vm07U52cVKPDaWm1iW5f =I2Bf -----END PGP SIGNATURE----- --7PAM/4G1BR2SfWzg--