Received: from eggs.gnu.org ([2001:4830:134:3::10]:38008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c50Gx-0002Qu-JN for qemu-devel@nongnu.org; Thu, 10 Nov 2016 20:04:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c50Gv-0007dB-RG for qemu-devel@nongnu.org; Thu, 10 Nov 2016 20:04:51 -0500 Date: Fri, 11 Nov 2016 11:16:04 +1100 From: David Gibson Message-ID: <20161111001604.GG18868@umbus.fritz.box> References: <1478780230-31402-1-git-send-email-clg@kaod.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="bO4vSxwwZtUjUWHo" Content-Disposition: inline In-Reply-To: <1478780230-31402-1-git-send-email-clg@kaod.org> Subject: Re: [Qemu-devel] [PATCH] tests: add XSCOM tests for the PowerNV machine List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?C=E9dric?= Le Goater Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Alexander Graf , Thomas Huth --bO4vSxwwZtUjUWHo Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 10, 2016 at 01:17:10PM +0100, C=E9dric Le Goater wrote: > Add a couple of tests on the XSCOM bus of the PowerNV machine for the > the POWER8 and POWER9 CPUs. The first tests reads the CFAM identifier > of the chip. The second test goes further in the XSCOM address space > and reaches the cores to read their DTS registers. This last one is > disabled on P9 for the moment as the EQ/EX/EC XSCOM mapping needs more > work to be functional. >=20 > Signed-off-by: C=E9dric Le Goater > --- > tests/Makefile.include | 1 + > tests/pnv-xscom-test.c | 138 +++++++++++++++++++++++++++++++++++++++++++= ++++++ > 2 files changed, 139 insertions(+) > create mode 100644 tests/pnv-xscom-test.c >=20 > diff --git a/tests/Makefile.include b/tests/Makefile.include > index de516341fd44..90c9ad9ac6e1 100644 > --- a/tests/Makefile.include > +++ b/tests/Makefile.include > @@ -270,6 +270,7 @@ gcov-files-ppc64-y =3D ppc64-softmmu/hw/ppc/spapr_pci= =2Ec > check-qtest-ppc64-y +=3D tests/endianness-test$(EXESUF) > check-qtest-ppc64-y +=3D tests/boot-order-test$(EXESUF) > check-qtest-ppc64-y +=3D tests/prom-env-test$(EXESUF) > +check-qtest-ppc64-y +=3D tests/pnv-xscom-test$(EXESUF) > check-qtest-ppc64-y +=3D tests/drive_del-test$(EXESUF) > check-qtest-ppc64-y +=3D tests/postcopy-test$(EXESUF) > check-qtest-ppc64-y +=3D tests/boot-serial-test$(EXESUF) > diff --git a/tests/pnv-xscom-test.c b/tests/pnv-xscom-test.c > new file mode 100644 > index 000000000000..994dd015c425 > --- /dev/null > +++ b/tests/pnv-xscom-test.c > @@ -0,0 +1,138 @@ > +/* > + * QTest testcase for PowerNV XSCOM bus > + * > + * Copyright (c) 2016, IBM Corporation. > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or > + * later. See the COPYING file in the top-level directory. > + */ > +#include "qemu/osdep.h" > + > +#include "libqtest.h" > + > +typedef enum PnvChipType { > + PNV_CHIP_POWER8E, /* AKA Murano (default) */ > + PNV_CHIP_POWER8, /* AKA Venice */ > + PNV_CHIP_POWER8NVL, /* AKA Naples */ > + PNV_CHIP_POWER9, /* AKA Nimbus */ > +} PnvChipType; > + > +#define PNV_XSCOM_EX_BASE 0x10000000 > +#define PNV_XSCOM_EX_CORE_BASE(i) (PNV_XSCOM_EX_BASE | (((uint64_t)i) <<= 24)) > + > +static const struct pnv_chip { > + PnvChipType chip_type; > + const char *cpu_model; > + uint64_t xscom_base; > + uint64_t cfam_id; > + uint32_t first_core; > +} pnv_chips[] =3D { > + { > + .chip_type =3D PNV_CHIP_POWER8, > + .cpu_model =3D "POWER8", > + .xscom_base =3D 0x003fc0000000000ull, > + .cfam_id =3D 0x220ea04980000000ull, > + .first_core =3D 0x1, > + }, > + { > + .chip_type =3D PNV_CHIP_POWER8NVL, > + .cpu_model =3D "POWER8NVL", > + .xscom_base =3D 0x003fc0000000000ull, > + .cfam_id =3D 0x120d304980000000ull, > + .first_core =3D 0x1, > + }, > + { > + .chip_type =3D PNV_CHIP_POWER9, > + .cpu_model =3D "POWER9", > + .xscom_base =3D 0x00603fc00000000ull, > + .cfam_id =3D 0x100d104980000000ull, > + .first_core =3D 0x20, > + }, > +}; > + > +static uint64_t pnv_xscom_addr(const struct pnv_chip *chip, uint32_t pcb= a) > +{ > + uint64_t addr =3D chip->xscom_base; > + > + if (chip->chip_type =3D=3D PNV_CHIP_POWER9) { > + return addr | ((uint64_t) pcba << 3); > + } else { > + return addr | (((uint64_t) pcba << 4) & ~0xfful) | > + (((uint64_t) pcba << 3) & 0x78); > + } > +} To make writing future tests which use XSCOM easier, I think it would be better to actually have xscom_read / xscom_write helper functions. > +static void test_xscom_cfam_id(const struct pnv_chip *chip) > +{ > + uint64_t f000f =3D readq(pnv_xscom_addr(chip, 0xf000f)); > + > + g_assert_cmphex(f000f, =3D=3D, chip->cfam_id); > +} > + > +static void test_cfam_id(const void *data) > +{ > + char *args; > + const struct pnv_chip *chip =3D data; > + > + args =3D g_strdup_printf("-M powernv,accel=3Dtcg -cpu %s", chip->cpu= _model); > + > + qtest_start(args); > + test_xscom_cfam_id(chip); > + qtest_quit(global_qtest); > + > + g_free(args); > +} > + > +static void test_xscom_core(const struct pnv_chip *chip) > +{ > + uint32_t first_core_dts0 =3D > + PNV_XSCOM_EX_CORE_BASE(chip->first_core) | 0x50000; > + uint64_t dts0 =3D readq(pnv_xscom_addr(chip, first_core_dts0)); > + > + g_assert_cmphex(dts0, =3D=3D, 0x26f024f023f0000ull); > +} > + > +static void test_core(const void *data) > +{ > + char *args; > + const struct pnv_chip *chip =3D data; > + > + args =3D g_strdup_printf("-M powernv,accel=3Dtcg -cpu %s", chip->cpu= _model); > + > + qtest_start(args); > + test_xscom_core(chip); > + qtest_quit(global_qtest); > + > + g_free(args); > +} > + > +int main(int argc, char **argv) > +{ > + int i; > + > + g_test_init(&argc, &argv, NULL); > + > + for (i =3D 0; i < ARRAY_SIZE(pnv_chips); i++) { > + char *name =3D g_strdup_printf("pnv-xscom/cfam_id/%s", > + pnv_chips[i].cpu_model); > + qtest_add_data_func(name, &pnv_chips[i], test_cfam_id); > + g_free(name); > + } > + > + for (i =3D 0; i < ARRAY_SIZE(pnv_chips); i++) { > + /* > + * Discard P9 for the moment as EQ/EX/EC XSCOM mapping needs a > + * rework > + */ > + if (pnv_chips[i].chip_type =3D=3D PNV_CHIP_POWER9) { > + continue; > + } > + > + char *name =3D g_strdup_printf("pnv-xscom/core/%s", > + pnv_chips[i].cpu_model); > + qtest_add_data_func(name, &pnv_chips[i], test_core); > + g_free(name); > + } > + > + return g_test_run(); > +} --=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 --bO4vSxwwZtUjUWHo Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYJQ3CAAoJEGw4ysog2bOSQksP/RruNoxA+75K8J5LnYr9PVZd uhjHd49A2NsmS3QS5XQ7fpthDx4xOS3CZKETvwzYTk5XMnvJlF6//CrV6jJx7W1F JQ/HBwDdamqGpHADX9W3mhf0tkcguqNgu2v8QIrWbxlQD2UJ/3TfFYLJPNXnXVtv IjrI9/QKIe6rLUFEFnHrwfUYEZW36sWT/kFTb0vz2xkcPu68HnaBNa/tM3eiebmv MVLsrdbEJI3cE9wWfYgMpMWDaVUlRreo8yTVRdMt8CNRu42hZASQWsiA3yI6Pf97 6gyHvKo5cO3XcqBVLUscE2eSJZ/vazmdMsusmw6mehshTLJkSD/ME9N5SdplcVP8 4yaxHfT4kz22h5h8twksVVlXRZrwnWDjwv3dVelVPo8YVClDb+uTrSH809MNM/L4 2QBpkISJ4Sx3h2F34cbln5kCwgn/aKHj8a72EtvMipLRtqFX0XXdlp4+e4L+13LM 6a0nJ3GqMxgpfiMq/awMsJdkyEEnyqpyrK7ZhUwdUSa85WsxS+MS6y0HJldKd+Qq cwKMswuYH7gprlCWYQWkgGFMu4wXWgFnwtsFX9YAtVLu77vhpyupYn0hTuOPbuL7 G77Nfl3/L3HGT7B/g30HHY89oevZwdI0VeK14wy7qHiH2CO7yDEzxOea94tvnpBw Bn0ezQ40Z5ra5ggcmpCj =rvqI -----END PGP SIGNATURE----- --bO4vSxwwZtUjUWHo--