From patchwork Wed Mar 8 10:52:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 736527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vdVnY2SjXz9sCX for ; Wed, 8 Mar 2017 21:56:17 +1100 (AEDT) Received: from localhost ([::1]:55529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clZGQ-00019E-P9 for incoming@patchwork.ozlabs.org; Wed, 08 Mar 2017 05:56:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clZDW-0007ao-5I for qemu-devel@nongnu.org; Wed, 08 Mar 2017 05:53:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clZDR-00036M-W9 for qemu-devel@nongnu.org; Wed, 08 Mar 2017 05:53:14 -0500 Received: from 6.mo177.mail-out.ovh.net ([46.105.51.249]:51672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clZDR-00034d-PY for qemu-devel@nongnu.org; Wed, 08 Mar 2017 05:53:09 -0500 Received: from player714.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo177.mail-out.ovh.net (Postfix) with ESMTP id 7C4F73BD6F for ; Wed, 8 Mar 2017 11:53:01 +0100 (CET) Received: from zorba.kaod.org.com (LFbn-1-10647-27.w90-89.abo.wanadoo.fr [90.89.233.27]) (Authenticated sender: clg@kaod.org) by player714.ha.ovh.net (Postfix) with ESMTPSA id 56AEA3C0093; Wed, 8 Mar 2017 11:52:57 +0100 (CET) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Date: Wed, 8 Mar 2017 11:52:44 +0100 Message-Id: <1488970371-8865-2-git-send-email-clg@kaod.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488970371-8865-1-git-send-email-clg@kaod.org> References: <1488970371-8865-1-git-send-email-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 16324704224644336614 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrgeeggddujecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.51.249 Subject: [Qemu-devel] [PATCH for-2.10 1/8] ppc/xics: add a xics_get_cpu_index_by_pir() helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This helper will be used 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édric Le Goater --- 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 e740989a1162..209e1a75ecb9 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; } +int xics_get_cpu_index_by_pir(int pir) +{ + PowerPCCPU *cpu = ppc_get_vcpu_by_pir(pir); + + if (cpu) { + return cpu->parent_obj.cpu_index; + } + + return -1; +} + void xics_cpu_destroy(XICSFabric *xi, PowerPCCPU *cpu) { CPUState *cs = CPU(cpu); diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 5f93083d4a16..94bbe382a73a 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -1379,6 +1379,22 @@ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id) return NULL; } +PowerPCCPU *ppc_get_vcpu_by_pir(int pir) +{ + CPUState *cs; + + CPU_FOREACH(cs) { + PowerPCCPU *cpu = POWERPC_CPU(cs); + CPUPPCState *env = &cpu->env; + + if (env->spr_cb[SPR_PIR].default_value == 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 9a5e715fe553..42bd24e975cb 100644 --- a/include/hw/ppc/xics.h +++ b/include/hw/ppc/xics.h @@ -173,6 +173,7 @@ void xics_cpu_destroy(XICSFabric *xi, PowerPCCPU *cpu); /* Internal XICS interfaces */ int xics_get_cpu_index_by_dt_id(int cpu_dt_id); +int xics_get_cpu_index_by_pir(int pir); 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 7c4a1f50b38b..24a5af95cb45 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -2518,5 +2518,15 @@ int ppc_get_vcpu_dt_id(PowerPCCPU *cpu); */ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id); +/** + * 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 len); #endif /* PPC_CPU_H */