From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson Subject: Re: [kvm-unit-tests PATCH v5 13/18] powerpc/ppc64: adapt arm's setup Date: Mon, 22 Feb 2016 12:00:13 +1100 Message-ID: <20160222010013.GA2808@voom.fritz.box> References: <1455734459-31902-1-git-send-email-drjones@redhat.com> <1455734459-31902-14-git-send-email-drjones@redhat.com> <20160219034053.GU15224@voom.fritz.box> <20160219074933.r2uz3jwnnbnjxxjj@hawk.localdomain> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="h31gzZEtNLTqOjlF" 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, rkrcmar@redhat.com To: Andrew Jones Return-path: Received: from ozlabs.org ([103.22.144.67]:57795 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752304AbcBVBIN (ORCPT ); Sun, 21 Feb 2016 20:08:13 -0500 Content-Disposition: inline In-Reply-To: <20160219074933.r2uz3jwnnbnjxxjj@hawk.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 19, 2016 at 08:49:33AM +0100, Andrew Jones wrote: > On Fri, Feb 19, 2016 at 02:40:53PM +1100, David Gibson wrote: > > On Wed, Feb 17, 2016 at 07:40:54PM +0100, Andrew Jones wrote: > > > Copy arm's setup code (also DT based) over to powerpc, adapting > > > it a bit. Also bring over arm's setup selftest, giving powerpc > > > its first test. > > >=20 > > > The largest change from arm's setup.c is that instead of using a > > > hardcoded SMP_CACHE_BYTES, cpu_set() is extended to extract the > > > line size from the cpu DT nodes. That change also requires that > > > we call cpu_init() before mem_init() in setup(). > > >=20 > > > Signed-off-by: Andrew Jones > > > Reviewed-by: Thomas Huth > > > Tested-by: Laurent Vivier > > > --- > > > lib/powerpc/asm/setup.h | 30 +++++++++++ > > > lib/powerpc/setup.c | 141 ++++++++++++++++++++++++++++++++++++++= ++++++++++ > > > lib/ppc64/asm/setup.h | 1 + > > > powerpc/Makefile.common | 1 + > > > powerpc/cstart64.S | 16 +++++- > > > powerpc/selftest.c | 63 ++++++++++++++++++++-- > > > 6 files changed, 248 insertions(+), 4 deletions(-) > > > create mode 100644 lib/powerpc/asm/setup.h > > > create mode 100644 lib/powerpc/setup.c > > > create mode 100644 lib/ppc64/asm/setup.h > > >=20 > > > diff --git a/lib/powerpc/asm/setup.h b/lib/powerpc/asm/setup.h > > > new file mode 100644 > > > index 0000000000000..8288ff37ff1b9 > > > --- /dev/null > > > +++ b/lib/powerpc/asm/setup.h > > > @@ -0,0 +1,30 @@ > > > +#ifndef _ASMPOWERPC_SETUP_H_ > > > +#define _ASMPOWERPC_SETUP_H_ > > > +/* > > > + * Copyright (C) 2016, Red Hat Inc, Andrew Jones > > > + * > > > + * This work is licensed under the terms of the GNU LGPL, version 2. > > > + */ > > > +#include > > > +#include /* phys_addr_t */ > > > + > > > +#define NR_CPUS 8 /* arbitrarily set for now */ > >=20 > > We probably want to set this larger sooner rather than later. The > > test machines the virt dev team uses have 160 logical CPUs, and > > they're not particularly large as Power systems go. >=20 > One of the changes that the "Add SMP support" follow-on series will > make is to change this to whatever qemu-kvm/spapr supports. Ok, great. > > > +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 __physical_start, __physical_end; > > > +extern unsigned __smp_cache_bytes; > > > + > > > +#define PHYSICAL_START (__physical_start) > > > +#define PHYSICAL_END (__physical_end) > > > +#define SMP_CACHE_BYTES (__smp_cache_bytes) > > > + > > > +#endif /* _ASMPOWERPC_SETUP_H_ */ > > > diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c > > > new file mode 100644 > > > index 0000000000000..70f50deb9bacf > > > --- /dev/null > > > +++ b/lib/powerpc/setup.c > > > @@ -0,0 +1,141 @@ > > > +/* > > > + * Initialize machine setup information and I/O. > > > + * > > > + * After running setup() unit tests may query how many cpus they have > > > + * (nr_cpus), how much memory they have (PHYSICAL_END - PHYSICAL_STA= RT), > > > + * may use dynamic memory allocation (malloc, etc.), printf, and exi= t. > > > + * Finally, argc and argv are also ready to be passed to main(). > > > + * > > > + * Copyright (C) 2016, Red Hat Inc, Andrew Jones > > > + * > > > + * This work is licensed under the terms of the GNU LGPL, version 2. > > > + */ > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > + > > > +extern unsigned long stacktop; > > > +extern void io_init(void); > > > +extern void setup_args(const char *args); > > > + > > > +u32 cpus[NR_CPUS] =3D { [0 ... NR_CPUS-1] =3D (~0U) }; > > > +int nr_cpus; > > > + > > > +struct mem_region mem_regions[NR_MEM_REGIONS]; > > > +phys_addr_t __physical_start, __physical_end; > > > +unsigned __smp_cache_bytes; > > > + > > > +static void cpu_set(int fdtnode, u32 regval, void *info) > > > +{ > > > + const struct fdt_property *prop; > > > + unsigned *max_linesz =3D (unsigned *)info, sz; > > > + int cpu =3D nr_cpus++; > > > + u32 *data; > > > + > > > + if (cpu >=3D NR_CPUS) { > > > + printf("Number cpus exceeds maximum supported (%d).\n", > > > + NR_CPUS); > > > + assert(0); > > > + } > > > + cpus[cpu] =3D regval; > > > + > > > + prop =3D fdt_get_property(dt_fdt(), fdtnode, "i-cache-line-size", N= ULL); > > > + assert(prop !=3D NULL); > > > + data =3D (u32 *)prop->data; > > > + sz =3D fdt32_to_cpu(*data); > > > + > > > + if (*max_linesz < sz) > > > + *max_linesz =3D sz; > > > + > > > + prop =3D fdt_get_property(dt_fdt(), fdtnode, "d-cache-line-size", N= ULL); > > > + assert(prop !=3D NULL); > > > + data =3D (u32 *)prop->data; > > > + sz =3D fdt32_to_cpu(*data); > > > + > > > + if (*max_linesz < sz) > > > + *max_linesz =3D sz; > >=20 > > Hmm.. what is __smp_cache_bytes used for, exactly? > >=20 > > If you're just trying to get cacheline alignment, then this is > > correct. > >=20 > > However, if you're using this to control loops which step over each > > cacheline to invalidate / flush / whatever, then you'd need the > > minimum cacheline size instead. >=20 > OK, I can just save both to respective icache, dcache variables, > deferring the decision on which, or max, or min, to use. Or... you could just abort if they're not the same and worry about it when we actually get a machine where they're different (i.e. probably never). --=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 --h31gzZEtNLTqOjlF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWyl2dAAoJEGw4ysog2bOSkK0QALg8aho9EOf8Ce13WmOtlGLh sZps1YKehds7mzrxgid+ipQ5poqin0lNEdc62wFzQe6l+Zxe2zUGd4RLh+ldGTpo /xgnS6z24etEUGlQ4odjYOHmrwlYn54ul0V0W+GKG34rJrCuWeYOHO9191jgGgR1 HFocGyimeyRnEXVh1HttOOUFrwx0xShrTGtnj95VBgXISwwl5H1X0uSq78U4w2ut IFqxPOmdueaVMHzwe6mwYkAlaKZo/W8g+EYpTlBEAVMOabfQ4WRKTbafDsLD2crr Sc8p3ysB0ptwlaF////NNV3B6hXdTcnuQMdQG8+ZS2DL8WXFdEQ4hy3/YZTjGgyT D6rHWSIOMi1wL2yuQL+ijBGRVddUzmfmXpedFIvut29UE5gCNp2T+fx+URho2nwO ZxwMMrRaph0Oko4UgGcyOqpJCD2GiASLll5/dqt3rJtERs9KcDkn0FXjd79qzQe5 3JcQQGR6gqNaexsFHTuXR6Lrl1i17Kc1Q1NuQ6ANVMZBE7IGN06LGYiyzl3p3nh/ zDCh4/HWjT0AwvdDL6Kax7wE9E6JUvgfYEBaePPg/kEUGbWMUmJpSrOhP7j5E58w igOkrn2Tzp5taST+keRCs/8EGbMkmU6Dul+LvX0oZnuCM+b+HZujRELfMeUzanyB UQ7y2w0EuG8emWQyoHU1 =i+XK -----END PGP SIGNATURE----- --h31gzZEtNLTqOjlF--