From patchwork Mon Apr 14 12:12:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 338934 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0BA0E1400F3 for ; Mon, 14 Apr 2014 22:13:04 +1000 (EST) Received: from localhost ([::1]:42724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WZfkz-0007nf-Qn for incoming@patchwork.ozlabs.org; Mon, 14 Apr 2014 08:13:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WZfka-0007Fj-8o for qemu-devel@nongnu.org; Mon, 14 Apr 2014 08:12:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WZfkR-0001LP-M1 for qemu-devel@nongnu.org; Mon, 14 Apr 2014 08:12:36 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:44604) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WZfkR-0001LC-Cg for qemu-devel@nongnu.org; Mon, 14 Apr 2014 08:12:27 -0400 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 14 Apr 2014 13:12:26 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 14 Apr 2014 13:12:23 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id E47DF2190046; Mon, 14 Apr 2014 13:12:15 +0100 (BST) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s3ECCMkh66060414; Mon, 14 Apr 2014 12:12:22 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s3ECCLm8015701; Mon, 14 Apr 2014 06:12:22 -0600 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s3ECCLdB015691; Mon, 14 Apr 2014 06:12:21 -0600 Received: from bahia.local (bahia.lab.toulouse-stg.fr.ibm.com [9.101.4.41]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id ECAE3210FFE; Mon, 14 Apr 2014 14:12:20 +0200 (CEST) To: agraf@suse.de From: Greg Kurz Date: Mon, 14 Apr 2014 14:12:15 +0200 Message-ID: <20140414121020.5987.68525.stgit@bahia.local> In-Reply-To: <20140414112942.32507.38267.stgit@bahia.local> References: <20140414112942.32507.38267.stgit@bahia.local> User-Agent: StGit/0.16 MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14041412-0542-0000-0000-000008A7B697 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.113 Cc: kwolf@redhat.com, peter.maydell@linaro.org, thuth@linux.vnet.ibm.com, mst@redhat.com, marc.zyngier@arm.com, rusty@rustcorp.com.au, qemu-devel@nongnu.org, amit.shah@redhat.com, qemu-ppc@nongnu.org, aneesh.kumar@linux.vnet.ibm.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com, anthony@codemonkey.ws, afaerber@suse.de Subject: [Qemu-devel] [PATCH v5] target-ppc: ppc64 target's virtio can be either endian X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We turn the virtio_is_big_endian() helper into a target dependant hook to compute endianness for legacy virtio devices. We base it on the OS endian, as reflected by the endianness of the interrupt vectors (handled through the ILE bit in the LPCR register). Using first_cpu to fetch the registers from KVM may look arbitrary and awkward, but it is okay because KVM sets/unsets the ILE bit on all CPUs. Note that Book3e has no LPCR and worse, has a unrelated spr at the same index... I did not find better than strcmp() to ensure we are using the correct register. Suggested-by: Benjamin Herrenschmidt Signed-off-by: Rusty Russell [ re-use the existing virito_is_big_endian() helper, check we have LPCR, Greg Kurz ] Signed-off-by: Greg Kurz Reviewed-by: Alexander Graf --- Changes since v5: - merged with the existing virtio_is_big_endian() helper - ensure cpu has LPCR exec.c | 2 +- target-ppc/misc_helper.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index e6777d0..cf98d42 100644 --- a/exec.c +++ b/exec.c @@ -2740,7 +2740,7 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, } #endif -#if !defined(CONFIG_USER_ONLY) +#if !defined(CONFIG_USER_ONLY) && !defined(TARGET_PPC) /* * A helper function for the _utterly broken_ virtio device model to find out if diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c index 2eb2fa6..971cafe 100644 --- a/target-ppc/misc_helper.c +++ b/target-ppc/misc_helper.c @@ -20,6 +20,8 @@ #include "helper.h" #include "helper_regs.h" +#include "hw/virtio/virtio.h" +#include "sysemu/kvm.h" /*****************************************************************************/ /* SPR accesses */ @@ -120,3 +122,19 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value) { hreg_store_msr(env, value, 0); } + +#if !defined(CONFIG_USER_ONLY) +bool virtio_is_big_endian(void) +{ + PowerPCCPU *cp = POWERPC_CPU(first_cpu); + CPUPPCState *env = &cp->env; + + /* NOTE: booke uses the same number for another unrelated spr. + */ + if (strcmp(env->spr_cb[SPR_LPCR].name, "LPCR")) { + return TARGET_WORDS_BIGENDIAN; + } else { + return !(env->spr[SPR_LPCR] & LPCR_ILE); + } +} +#endif