From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTUsX-00064U-At for qemu-devel@nongnu.org; Fri, 28 Mar 2014 07:23:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WTUsI-00048O-Cg for qemu-devel@nongnu.org; Fri, 28 Mar 2014 07:23:17 -0400 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:46275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTUsI-00047e-4u for qemu-devel@nongnu.org; Fri, 28 Mar 2014 07:23:02 -0400 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 28 Mar 2014 11:23:01 -0000 From: Greg Kurz Date: Fri, 28 Mar 2014 12:22:52 +0100 Message-ID: <20140328111548.23869.16689.stgit@bahia.local> In-Reply-To: <20140328105709.21018.88000.stgit@bahia.local> References: <20140328105709.21018.88000.stgit@bahia.local> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH v4] target-ppc: ppc64 target's virtio can be either endian List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: afaerber@suse.de, agraf@suse.de 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 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. Suggested-by: Benjamin Herrenschmidt Signed-off-by: Rusty Russell [ rename virtio_get_byteswap to virtio_legacy_get_byteswap, support both LE and BE host, Greg Kurz ] Signed-off-by: Greg Kurz Reviewed-by: Alexander Graf --- Alex, Welcome back ! :) Changes since v3: - rename the helper according to v6 of the main LE virtio patchset - prepare to support LE ppc64 host - tentatively fixed the list of changes embeded in SoB lines Cheers. -- Greg target-ppc/misc_helper.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c index 2eb2fa6..4dbb274 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,15 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value) { hreg_store_msr(env, value, 0); } + +bool virtio_legacy_get_byteswap(void) +{ + PowerPCCPU *cp = POWERPC_CPU(first_cpu); + CPUPPCState *env = &cp->env; + bool ile = env->spr[SPR_LPCR] & LPCR_ILE; +#ifdef HOST_WORDS_BIGENDIAN + return ile; +#else + return !ile; +#endif +}