From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson Subject: Re: [kvm-unit-tests PATCH v5 17/18] powerpc/ppc64: add RTAS support Date: Fri, 19 Feb 2016 15:08:54 +1100 Message-ID: <20160219040854.GX15224@voom.fritz.box> References: <1455734459-31902-1-git-send-email-drjones@redhat.com> <1455734459-31902-18-git-send-email-drjones@redhat.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="b2s+RKoBicgQlNJs" 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]:55353 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424428AbcBSE1h (ORCPT ); Thu, 18 Feb 2016 23:27:37 -0500 Content-Disposition: inline In-Reply-To: <1455734459-31902-18-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: --b2s+RKoBicgQlNJs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 17, 2016 at 07:40:58PM +0100, Andrew Jones wrote: > Add enough RTAS support to start adding RTAS commands. Just add > power-off for now. >=20 > Signed-off-by: Andrew Jones > Reviewed-by: Thomas Huth > Tested-by: Laurent Vivier Reviewed-by: David Gibson apart from one nit below. > --- > lib/powerpc/asm/rtas.h | 26 +++++++++ > lib/powerpc/io.c | 2 + > lib/powerpc/rtas.c | 139 ++++++++++++++++++++++++++++++++++++++++++= ++++++ > lib/ppc64/asm/rtas.h | 1 + > powerpc/Makefile.common | 1 + > 5 files changed, 169 insertions(+) > create mode 100644 lib/powerpc/asm/rtas.h > create mode 100644 lib/powerpc/rtas.c > create mode 100644 lib/ppc64/asm/rtas.h >=20 > diff --git a/lib/powerpc/asm/rtas.h b/lib/powerpc/asm/rtas.h > new file mode 100644 > index 0000000000000..522225bcb6de3 > --- /dev/null > +++ b/lib/powerpc/asm/rtas.h > @@ -0,0 +1,26 @@ > +#ifndef _ASMPOWERPC_RTAS_H_ > +#define _ASMPOWERPC_RTAS_H_ > +/* > + * Copyright (C) 2016, Red Hat Inc, Andrew Jones > + * > + * This work is licensed under the terms of the GNU LGPL, version 2. > + */ > +#include > + > +#define RTAS_UNKNOWN_SERVICE (-1) > + > +struct rtas_args { > + u32 token; > + u32 nargs; > + u32 nret; > + u32 args[16]; > + u32 *rets; > +}; > + > +extern void rtas_init(void); > +extern int rtas_token(const char *service); > +extern int rtas_call(int token, int nargs, int nret, int *outputs, ...); > + > +extern void rtas_power_off(void); > + > +#endif /* _ASMPOWERPC_RTAS_H_ */ > diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c > index ef90946fb1131..c4c61ea8ac1cf 100644 > --- a/lib/powerpc/io.c > +++ b/lib/powerpc/io.c > @@ -7,6 +7,7 @@ > */ > #include > #include > +#include > =20 > extern void halt(int code); > extern void putchar(int c); > @@ -15,6 +16,7 @@ static struct spinlock print_lock; > =20 > void io_init(void) > { > + rtas_init(); > } > =20 > void puts(const char *s) > diff --git a/lib/powerpc/rtas.c b/lib/powerpc/rtas.c > new file mode 100644 > index 0000000000000..c51c52c734b38 > --- /dev/null > +++ b/lib/powerpc/rtas.c > @@ -0,0 +1,139 @@ > +/* > + * powerpc RTAS > + * > + * 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 > +#include > + > +#if defined(__powerpc64__) > +struct func_ptr { > + unsigned long ptr; > + unsigned long toc; > +}; > +static struct func_ptr rtas_entry_funcptr; > +#endif > +typedef void (*rtas_entry_t)(unsigned long); > +static rtas_entry_t enter_rtas; > +static struct rtas_args rtas_args; > +static struct spinlock rtas_lock; > + > +static int rtas_node(void) > +{ > + int node =3D fdt_path_offset(dt_fdt(), "/rtas"); > + > + if (node < 0) { > + printf("%s: /rtas: %s\n", __func__, fdt_strerror(node)); > + abort(); > + } > + > + return node; > +} > + > +void rtas_init(void) > +{ > + const struct fdt_property *prop; > + int node =3D rtas_node(), len; > + unsigned long entry; > + u32 *data; > + > + if (!dt_available()) { > + printf("%s: No device tree!\n", __func__); > + abort(); > + } > + > + prop =3D fdt_get_property(dt_fdt(), node, > + "linux,rtas-entry", &len); > + if (!prop) { > + printf("%s: /rtas/linux,rtas-entry: %s\n", > + __func__, fdt_strerror(len)); > + abort(); > + } > + > + data =3D (u32 *)prop->data; > + entry =3D (unsigned long)fdt32_to_cpu(*data); > + > + if (hcall_have_broken_sc1()) { > + u32 *insn =3D (u32 *)entry; > + int size, i; > + > + prop =3D fdt_get_property(dt_fdt(), node, > + "rtas-size", &len); > + if (!prop) { > + printf("%s: /rtas/rtas-size: %s\n", > + __func__, fdt_strerror(len)); > + abort(); > + } > + data =3D (u32 *)prop->data; > + size =3D (int)fdt32_to_cpu(*data); > + > + for (i =3D 0; i < size/4; ++i) > + if (insn[i] =3D=3D SC1) > + insn[i] =3D SC1_REPLACEMENT; Hm, technically you need some byteswapping here - cpu mode changes the byteorder of instructions as well on Power. I know you're only supporting BE systems for now, but you do have byteswapping for the rtas args and so forth below, so.. > + } > + > +#if defined(__powerpc64__) > + rtas_entry_funcptr.ptr =3D entry; > + enter_rtas =3D (rtas_entry_t)&rtas_entry_funcptr; > +#else > + enter_rtas =3D (rtas_entry_t)entry; > +#endif > +} > + > +int rtas_token(const char *service) > +{ > + const struct fdt_property *prop; > + u32 *token; > + > + prop =3D fdt_get_property(dt_fdt(), rtas_node(), service, NULL); > + if (prop) { > + token =3D (u32 *)prop->data; > + return fdt32_to_cpu(*token); > + } > + return RTAS_UNKNOWN_SERVICE; > +} > + > +int rtas_call(int token, int nargs, int nret, int *outputs, ...) > +{ > + va_list list; > + int ret, i; > + > + spin_lock(&rtas_lock); > + > + rtas_args.token =3D cpu_to_be32(token); > + rtas_args.nargs =3D cpu_to_be32(nargs); > + rtas_args.nret =3D cpu_to_be32(nret); > + rtas_args.rets =3D &rtas_args.args[nargs]; > + > + va_start(list, outputs); > + for (i =3D 0; i < nargs; ++i) > + rtas_args.args[i] =3D cpu_to_be32(va_arg(list, u32)); > + va_end(list); > + > + for (i =3D 0; i < nret; ++i) > + rtas_args.rets[i] =3D 0; > + > + enter_rtas(__pa(&rtas_args)); > + > + if (nret > 1 && outputs !=3D NULL) > + for (i =3D 0; i < nret - 1; ++i) > + outputs[i] =3D be32_to_cpu(rtas_args.rets[i + 1]); > + > + ret =3D nret > 0 ? be32_to_cpu(rtas_args.rets[0]) : 0; > + > + spin_unlock(&rtas_lock); > + return ret; > +} > + > +void rtas_power_off(void) > +{ > + int ret =3D rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1); > + printf("RTAS power-off returned %d\n", ret); > +} > diff --git a/lib/ppc64/asm/rtas.h b/lib/ppc64/asm/rtas.h > new file mode 100644 > index 0000000000000..fe77f635cd860 > --- /dev/null > +++ b/lib/ppc64/asm/rtas.h > @@ -0,0 +1 @@ > +#include "../../powerpc/asm/rtas.h" > diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common > index 07ba135f77110..cad728ecbe269 100644 > --- a/powerpc/Makefile.common > +++ b/powerpc/Makefile.common > @@ -28,6 +28,7 @@ cflatobjs +=3D lib/devicetree.o > cflatobjs +=3D lib/powerpc/io.o > cflatobjs +=3D lib/powerpc/hcall.o > cflatobjs +=3D lib/powerpc/setup.o > +cflatobjs +=3D lib/powerpc/rtas.o > =20 > libgcc :=3D $(shell $(CC) $(machine) --print-libgcc-file-name) > =20 --=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 --b2s+RKoBicgQlNJs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWxpVWAAoJEGw4ysog2bOSM4AQAKoPk81MswYwueocCot6KFpC 0+8LrREwvbWDrYIWm/P61yXpGUqWfMMgNsOBA6NCZs7+537C3k/RvElQx3Q4xlA/ LkVuzcLwJKvkEZrP4zwVdGJ0iCv23mpFzvu80gw/NYVgCbpmwcs2VdZxFvPTJMr5 Sy2RMRiz0AcITUzuvhCrtMwvwuM1lI2ccXcxfl/Yf0aZfgAqhK9faKTIvXPKrouh RLCET/mnU6Dv6HIV2sVI9tnxaHuJdrZizMeieCtYPYsmhj12MYWLuueXhrvhALme W/d/NBqwLIcQ17/ZTyCfe4UF4Gh3kjTYx+jsO5pweRYyhuSEUcpxaVnxJQLNrAQw Pm3lR+yBJXm2v5/G8fB7oVJeZwguRc9iXAyMCh80xZ45SfJQcU905VKvGrnGcXwi BOCZXwcwxnA03ZNWkdGr6PLLhNCgdq/q03Eg/Jm8TImS9BgioHpa1E5Rsvwi4J6j AUYWnyK6p2GVgGNa52hwL6lpNppX9uAXwpFrCvX8jjN8nlQ+DlV/UAI/nZo9OckD mAknUMndMRXbHU1iC5701yL9Yx6bGU8d7HZ2F5TCdcK4sYJQ4chfeYETe5h817+s O1oE3r+2eqMncA0G/C+uk3119pj3HoOR05UUxk61jcwAmiz1wmJ3PT+PETWvE5au s5n+mm9LEgUyYnmcDhUz =FTJC -----END PGP SIGNATURE----- --b2s+RKoBicgQlNJs--