diff mbox

[V2] target-ppc: ppc64 target's virtio can be either endian.

Message ID 20131211155716.8373.27979.stgit@bahia.local
State New
Headers show

Commit Message

Greg Kurz Dec. 11, 2013, 3:59 p.m. UTC
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

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.

Changes in v2:
- call cpu_synchronize_state() instead of kvm_arch_get_registers().

Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---

Alex,

If you are interested, I can resend the whole virtio+endian serie or
setup a git tree for you to pull from.

--
Greg

 target-ppc/kvm.c         |    4 ++++
 target-ppc/misc_helper.c |   12 ++++++++++++
 2 files changed, 16 insertions(+)

Comments

Alexander Graf Dec. 11, 2013, 4:11 p.m. UTC | #1
On 11.12.2013, at 16:59, Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:

> 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
> 
> 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.
> 
> Changes in v2:
> - call cpu_synchronize_state() instead of kvm_arch_get_registers().
> 
> Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> ---
> 
> Alex,
> 
> If you are interested, I can resend the whole virtio+endian serie or
> setup a git tree for you to pull from.

I think this patch should really go in after / with the virtio-endian series, since as it is it would be dead code. So I'll just give you my ack here and hope whoever gets the virtio-endianness bits in also includes that with my reviewed-by line.

Reviewed-by: Alexander Graf <agraf@suse.de>


Alex

> 
> --
> Greg
> 
> target-ppc/kvm.c         |    4 ++++
> target-ppc/misc_helper.c |   12 ++++++++++++
> 2 files changed, 16 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..e8fc8a3 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,13 @@ 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;
> +
> +    cpu_synchronize_state(first_cpu);
> +
> +    return env->spr[SPR_LPCR] & LPCR_ILE;
> +}
>
Greg Kurz Dec. 11, 2013, 5:18 p.m. UTC | #2
On Wed, 11 Dec 2013 17:11:49 +0100
Alexander Graf <agraf@suse.de> wrote:
> 
> I think this patch should really go in after / with the virtio-endian
> series, since as it is it would be dead code. So I'll just give you my
> ack here and hope whoever gets the virtio-endianness bits in also
> includes that with my reviewed-by line.
> 
> Reviewed-by: Alexander Graf <agraf@suse.de>
> 
> 
> Alex
> 

Thanks for your time Alex.

Anthony,

Would you have time to review the virtio-endian patchset from Rusty and I ?
I have made a bundle out of the patches that were sent to qemu-devel@:

http://patchwork.ozlabs.org/bundle/groug/qemu-virtio-endian/?order=date

The last patch (ppc64 target's virtio can be either endian) is the
enablement for ppc64: it supports both TCG and KVM.

Thanks.

--
Greg
diff mbox

Patch

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..e8fc8a3 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,13 @@  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;
+
+    cpu_synchronize_state(first_cpu);
+
+    return env->spr[SPR_LPCR] & LPCR_ILE;
+}