From patchwork Mon Nov 25 15:35:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 294022 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B1F332C00BE for ; Tue, 26 Nov 2013 02:36:38 +1100 (EST) Received: from localhost ([::1]:53358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VkyDD-0005jo-Id for incoming@patchwork.ozlabs.org; Mon, 25 Nov 2013 10:36:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VkyCo-0005iR-HG for qemu-devel@nongnu.org; Mon, 25 Nov 2013 10:36:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VkyCh-0002fU-31 for qemu-devel@nongnu.org; Mon, 25 Nov 2013 10:36:10 -0500 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:44536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VkyCg-0002eU-QX for qemu-devel@nongnu.org; Mon, 25 Nov 2013 10:36:03 -0500 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 25 Nov 2013 15:36:01 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 25 Nov 2013 15:35:58 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2351817D805F; Mon, 25 Nov 2013 15:35:45 +0000 (GMT) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rAPFZjqm60358904; Mon, 25 Nov 2013 15:35:45 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rAPFZvrV012842; Mon, 25 Nov 2013 08:35:57 -0700 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id rAPFZvIf012832; Mon, 25 Nov 2013 08:35:57 -0700 Received: from bahia.lab.toulouse-stg.fr.ibm.com (bahia.lab.toulouse-stg.fr.ibm.com [9.101.4.41]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id A5438210FFE; Mon, 25 Nov 2013 16:35:56 +0100 (CET) To: rusty@rustcorp.com.au From: Greg Kurz Date: Mon, 25 Nov 2013 16:35:56 +0100 Message-ID: <20131125153556.12615.63598.stgit@bahia.lab.toulouse-stg.fr.ibm.com> User-Agent: StGit/0.16 MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13112515-2966-0000-0000-000009782D85 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.109 Cc: qemu-ppc@nongnu.org, agraf@suse.de, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] 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 base it on the OS endian, as reflected by the endianness of the interrupt vectors (handled through the ILE bit in the LPCR register). This patch does two things: - make LPCR a KVM register - implement virtio_get_byteswap() over LPCR This patch requires to have the following defined in the linux headers: $ grep LPCR linux-headers/asm-powerpc/kvm.h #define KVM_REG_PPC_LPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5) Suggested-by: Benjamin Herrenschmidt Signed-off-by: Rusty Russell Signed-off-by: Greg Kurz --- target-ppc/kvm.c | 4 ++++ target-ppc/misc_helper.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 10d0cd9..b450a22 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -869,6 +869,8 @@ int kvm_arch_put_registers(CPUState *cs, int level) DPRINTF("Warning: Unable to set VPA information to KVM\n"); } } + + kvm_put_one_spr(cs, KVM_REG_PPC_LPCR, SPR_LPCR); #endif /* TARGET_PPC64 */ } @@ -1091,6 +1093,8 @@ int kvm_arch_get_registers(CPUState *cs) DPRINTF("Warning: Unable to get VPA information from KVM\n"); } } + + kvm_get_one_spr(cs, KVM_REG_PPC_LPCR, SPR_LPCR); #endif } diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c index 616aab6..0e0743a 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 */ @@ -116,3 +118,15 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value) { hreg_store_msr(env, value, 0); } + +bool virtio_get_byteswap(void) +{ + PowerPCCPU *cp = POWERPC_CPU(first_cpu); + CPUPPCState *env = &cp->env; + + if (kvm_enabled()) { + kvm_arch_get_registers(first_cpu); + } + + return env->spr[SPR_LPCR] & LPCR_ILE; +}