Received: from eggs.gnu.org ([2001:4830:134:3::10]:37497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c41SY-0002zG-K7 for qemu-devel@nongnu.org; Tue, 08 Nov 2016 03:08:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c41SV-0007f4-By for qemu-devel@nongnu.org; Tue, 08 Nov 2016 03:08:46 -0500 Received: from 5.mo5.mail-out.ovh.net ([87.98.173.103]:50555) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c41SV-0007em-5d for qemu-devel@nongnu.org; Tue, 08 Nov 2016 03:08:43 -0500 Received: from player688.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id ABCEE132A1 for ; Tue, 8 Nov 2016 09:08:41 +0100 (CET) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Date: Tue, 8 Nov 2016 09:08:02 +0100 Message-Id: <1478592490-29673-3-git-send-email-clg@kaod.org> In-Reply-To: <1478592490-29673-1-git-send-email-clg@kaod.org> References: <1478592490-29673-1-git-send-email-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v6 02/10] ppc/xics: add a xics_get_cpu_index_by_pir helper List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-ppc@nongnu.org Cc: David Gibson , Benjamin Herrenschmidt , qemu-devel@nongnu.org, Alexander Graf , Cedric Le Goater We will need this helper to translate the server number of the XIVE (which is a PIR) into an ICPState index number (which is a cpu index). Signed-off-by: C=C3=A9dric Le Goater --- Changes since v5: - removed the dependency on XICS. The routine now uses a loop on all CPUs of the machine like this is done in ppc_get_vcpu_by_dt_id() hw/intc/xics.c | 11 +++++++++++ hw/ppc/ppc.c | 16 ++++++++++++++++ include/hw/ppc/xics.h | 1 + target-ppc/cpu.h | 10 ++++++++++ 4 files changed, 38 insertions(+) diff --git a/hw/intc/xics.c b/hw/intc/xics.c index f24787e95013..cab8837245b3 100644 --- a/hw/intc/xics.c +++ b/hw/intc/xics.c @@ -49,6 +49,17 @@ int xics_get_cpu_index_by_dt_id(int cpu_dt_id) return -1; } =20 +int xics_get_cpu_index_by_pir(int pir) +{ + PowerPCCPU *cpu =3D ppc_get_vcpu_by_pir(pir); + + if (cpu) { + return cpu->parent_obj.cpu_index; + } + + return -1; +} + void xics_cpu_destroy(XICSState *xics, PowerPCCPU *cpu) { CPUState *cs =3D CPU(cpu); diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 89458690097f..9386bda6f327 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -1352,6 +1352,22 @@ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id) return NULL; } =20 +PowerPCCPU *ppc_get_vcpu_by_pir(int pir) +{ + CPUState *cs; + + CPU_FOREACH(cs) { + PowerPCCPU *cpu =3D POWERPC_CPU(cs); + CPUPPCState *env =3D &cpu->env; + + if (env->spr_cb[SPR_PIR].default_value =3D=3D pir) { + return cpu; + } + } + + return NULL; +} + void ppc_cpu_parse_features(const char *cpu_model) { CPUClass *cc; diff --git a/include/hw/ppc/xics.h b/include/hw/ppc/xics.h index 1ee8663e9889..1dbcdf02b43c 100644 --- a/include/hw/ppc/xics.h +++ b/include/hw/ppc/xics.h @@ -196,6 +196,7 @@ void xics_set_nr_servers(XICSState *xics, uint32_t nr= _servers, =20 /* Internal XICS interfaces */ int xics_get_cpu_index_by_dt_id(int cpu_dt_id); +int xics_get_cpu_index_by_pir(int pir); =20 void icp_set_cppr(ICPState *icp, uint8_t cppr); void icp_set_mfrr(ICPState *icp, uint8_t mfrr); diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h index 1c90adb5d7b8..f05f73e1581f 100644 --- a/target-ppc/cpu.h +++ b/target-ppc/cpu.h @@ -2443,5 +2443,15 @@ int ppc_get_vcpu_dt_id(PowerPCCPU *cpu); */ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id); =20 +/** + * ppc_get_vcpu_by_pir_id: + * @pir: Processor Identifier Register (SPR_PIR) + * + * Searches for a CPU by @pir. + * + * Returns: a PowerPCCPU struct + */ +PowerPCCPU *ppc_get_vcpu_by_pir(int pir); + void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int le= n); #endif /* PPC_CPU_H */ --=20 2.7.4