diff mbox

[1/4] Add basic little endian support.

Message ID 1458544650-31416-2-git-send-email-bsingharora@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Education Directorate March 21, 2016, 7:17 a.m. UTC
Currently kvmtool works well/was designed for big endian ppc64 systems.
This patch adds support for little endian systems

The system does not yet boot as support for h_set_mode is required to help
with exceptions in big endian mode -- first page fault. The support comes in
the next patch of the series

Signed-off-by: Balbir Singh <bsingharora@gmail.com>
---
 powerpc/kvm.c   | 24 ++++++++++++------------
 powerpc/spapr.h |  5 +++--
 2 files changed, 15 insertions(+), 14 deletions(-)

Comments

Michael Neuling March 21, 2016, 9:55 p.m. UTC | #1
On Mon, 2016-03-21 at 18:17 +1100, Balbir Singh wrote:

> Currently kvmtool works well/was designed for big endian ppc64 systems.
> This patch adds support for little endian systems
> 
> The system does not yet boot as support for h_set_mode is required to help
> with exceptions in big endian mode -- first page fault. The support comes in
> the next patch of the series

Can we define some of the variables below with the appropriate endian?
pft_size_prop, segment_page_sizes_1, and rtas could all be defined as
big endian.

Mikey



> Signed-off-by: Balbir Singh <bsingharora@gmail.com>
> ---
>  powerpc/kvm.c   | 24 ++++++++++++------------
>  powerpc/spapr.h |  5 +++--
>  2 files changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/powerpc/kvm.c b/powerpc/kvm.c
> index b4c3310..d147e0c 100644
> --- a/powerpc/kvm.c
> +++ b/powerpc/kvm.c
> @@ -253,21 +253,21 @@ static void generate_segment_page_sizes(struct kvm_ppc_smu_info *info, struct f
>    	  	  if (sps->page_shift == 0)
>    	  	  	  break;
>  
> -  	  	  *p++ = sps->page_shift;
> -  	  	  *p++ = sps->slb_enc;
> +  	  	  *p++ = cpu_to_be32(sps->page_shift);
> +  	  	  *p++ = cpu_to_be32(sps->slb_enc);
>  
>    	  	  for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++)
>    	  	  	  if (!info->sps[i].enc[j].page_shift)
>    	  	  	  	  break;
>  
> -  	  	  *p++ = j;  	  /* count of enc */
> +  	  	  *p++ = cpu_to_be32(j);  	  /* count of enc */
>  
>    	  	  for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
>    	  	  	  if (!info->sps[i].enc[j].page_shift)
>    	  	  	  	  break;
>  
> -  	  	  	  *p++ = info->sps[i].enc[j].page_shift;
> -  	  	  	  *p++ = info->sps[i].enc[j].pte_enc;
> +  	  	  	  *p++ = cpu_to_be32(info->sps[i].enc[j].page_shift);
> +  	  	  	  *p++ = cpu_to_be32(info->sps[i].enc[j].pte_enc);
>    	  	  }
>    	  }
>  }
> @@ -292,7 +292,7 @@ static int setup_fdt(struct kvm *kvm)
>    	  u8  	  	  staging_fdt[FDT_MAX_SIZE];
>    	  struct cpu_info *cpu_info = find_cpu_info(kvm);
>    	  struct fdt_prop segment_page_sizes;
> -  	  u32 segment_sizes_1T[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
> +  	  u32 segment_sizes_1T[] = {cpu_to_be32(0x1c), cpu_to_be32(0x28), 0xffffffff, 0xffffffff};
>  
>    	  /* Generate an appropriate DT at kvm->arch.fdt_gra */
>    	  void *fdt_dest = guest_flat_to_host(kvm, kvm->arch.fdt_gra);
> @@ -364,7 +364,7 @@ static int setup_fdt(struct kvm *kvm)
>    	  _FDT(fdt_property_cell(fdt, "#size-cells", 0x0));
>  
>    	  for (i = 0; i < smp_cpus; i += SMT_THREADS) {
> -  	  	  int32_t pft_size_prop[] = { 0, HPT_ORDER };
> +  	  	  int32_t pft_size_prop[] = { 0, cpu_to_be32(HPT_ORDER) };
>    	  	  uint32_t servers_prop[SMT_THREADS];
>    	  	  uint32_t gservers_prop[SMT_THREADS * 2];
>    	  	  int threads = (smp_cpus - i) >= SMT_THREADS ? SMT_THREADS :
> @@ -503,11 +503,11 @@ int kvm__arch_setup_firmware(struct kvm *kvm)
>    	   */
>    	  uint32_t *rtas = guest_flat_to_host(kvm, kvm->arch.rtas_gra);
>  
> -  	  rtas[0] = 0x7c641b78;
> -  	  rtas[1] = 0x3c600000;
> -  	  rtas[2] = 0x6063f000;
> -  	  rtas[3] = 0x44000022;
> -  	  rtas[4] = 0x4e800020;
> +  	  rtas[0] = cpu_to_be32(0x7c641b78);
> +  	  rtas[1] = cpu_to_be32(0x3c600000);
> +  	  rtas[2] = cpu_to_be32(0x6063f000);
> +  	  rtas[3] = cpu_to_be32(0x44000022);
> +  	  rtas[4] = cpu_to_be32(0x4e800020);
>    	  kvm->arch.rtas_size = 20;
>  
>    	  pr_info("Set up %ld bytes of RTAS at 0x%lx\n",
> diff --git a/powerpc/spapr.h b/powerpc/spapr.h
> index 7a377d0..8b294d1 100644
> --- a/powerpc/spapr.h
> +++ b/powerpc/spapr.h
> @@ -15,6 +15,7 @@
>  #define __HW_SPAPR_H__
>  
>  #include <inttypes.h>
> +#include <linux/byteorder.h>
>  
>  #include "kvm/kvm.h"
>  #include "kvm/kvm-cpu.h"
> @@ -80,12 +81,12 @@ int spapr_rtas_fdt_setup(struct kvm *kvm, void *fdt);
>  
>  static inline uint32_t rtas_ld(struct kvm *kvm, target_ulong phys, int n)
>  {
> -  	  return *((uint32_t *)guest_flat_to_host(kvm, phys + 4*n));
> +  	  return cpu_to_be32(*((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)));
>  }
>  
>  static inline void rtas_st(struct kvm *kvm, target_ulong phys, int n, uint32_t val)
>  {
> -  	  *((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)) = val;
> +  	  *((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)) = cpu_to_be32(val);
>  }
>  
>  typedef void (*spapr_rtas_fn)(struct kvm_cpu *vcpu, uint32_t token,
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michael Ellerman March 21, 2016, 10:30 p.m. UTC | #2
On Tue, 2016-03-22 at 08:55 +1100, Michael Neuling wrote:
> On Mon, 2016-03-21 at 18:17 +1100, Balbir Singh wrote:
>
> > Currently kvmtool works well/was designed for big endian ppc64 systems.
> > This patch adds support for little endian systems
> >
> > The system does not yet boot as support for h_set_mode is required to help
> > with exceptions in big endian mode -- first page fault. The support comes in
> > the next patch of the series
>
> Can we define some of the variables below with the appropriate endian?
> pft_size_prop, segment_page_sizes_1, and rtas could all be defined as
> big endian.

Yeah that would be good.

kvmtool does have the definitions for __be32 etc.

I can't see any support in the Makefiles for running sparse, but you can always
run it manually and/or add support.

cheers

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/powerpc/kvm.c b/powerpc/kvm.c
index b4c3310..d147e0c 100644
--- a/powerpc/kvm.c
+++ b/powerpc/kvm.c
@@ -253,21 +253,21 @@  static void generate_segment_page_sizes(struct kvm_ppc_smmu_info *info, struct f
 		if (sps->page_shift == 0)
 			break;
 
-		*p++ = sps->page_shift;
-		*p++ = sps->slb_enc;
+		*p++ = cpu_to_be32(sps->page_shift);
+		*p++ = cpu_to_be32(sps->slb_enc);
 
 		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++)
 			if (!info->sps[i].enc[j].page_shift)
 				break;
 
-		*p++ = j;	/* count of enc */
+		*p++ = cpu_to_be32(j);	/* count of enc */
 
 		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
 			if (!info->sps[i].enc[j].page_shift)
 				break;
 
-			*p++ = info->sps[i].enc[j].page_shift;
-			*p++ = info->sps[i].enc[j].pte_enc;
+			*p++ = cpu_to_be32(info->sps[i].enc[j].page_shift);
+			*p++ = cpu_to_be32(info->sps[i].enc[j].pte_enc);
 		}
 	}
 }
@@ -292,7 +292,7 @@  static int setup_fdt(struct kvm *kvm)
 	u8		staging_fdt[FDT_MAX_SIZE];
 	struct cpu_info *cpu_info = find_cpu_info(kvm);
 	struct fdt_prop segment_page_sizes;
-	u32 segment_sizes_1T[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
+	u32 segment_sizes_1T[] = {cpu_to_be32(0x1c), cpu_to_be32(0x28), 0xffffffff, 0xffffffff};
 
 	/* Generate an appropriate DT at kvm->arch.fdt_gra */
 	void *fdt_dest = guest_flat_to_host(kvm, kvm->arch.fdt_gra);
@@ -364,7 +364,7 @@  static int setup_fdt(struct kvm *kvm)
 	_FDT(fdt_property_cell(fdt, "#size-cells", 0x0));
 
 	for (i = 0; i < smp_cpus; i += SMT_THREADS) {
-		int32_t pft_size_prop[] = { 0, HPT_ORDER };
+		int32_t pft_size_prop[] = { 0, cpu_to_be32(HPT_ORDER) };
 		uint32_t servers_prop[SMT_THREADS];
 		uint32_t gservers_prop[SMT_THREADS * 2];
 		int threads = (smp_cpus - i) >= SMT_THREADS ? SMT_THREADS :
@@ -503,11 +503,11 @@  int kvm__arch_setup_firmware(struct kvm *kvm)
 	 */
 	uint32_t *rtas = guest_flat_to_host(kvm, kvm->arch.rtas_gra);
 
-	rtas[0] = 0x7c641b78;
-	rtas[1] = 0x3c600000;
-	rtas[2] = 0x6063f000;
-	rtas[3] = 0x44000022;
-	rtas[4] = 0x4e800020;
+	rtas[0] = cpu_to_be32(0x7c641b78);
+	rtas[1] = cpu_to_be32(0x3c600000);
+	rtas[2] = cpu_to_be32(0x6063f000);
+	rtas[3] = cpu_to_be32(0x44000022);
+	rtas[4] = cpu_to_be32(0x4e800020);
 	kvm->arch.rtas_size = 20;
 
 	pr_info("Set up %ld bytes of RTAS at 0x%lx\n",
diff --git a/powerpc/spapr.h b/powerpc/spapr.h
index 7a377d0..8b294d1 100644
--- a/powerpc/spapr.h
+++ b/powerpc/spapr.h
@@ -15,6 +15,7 @@ 
 #define __HW_SPAPR_H__
 
 #include <inttypes.h>
+#include <linux/byteorder.h>
 
 #include "kvm/kvm.h"
 #include "kvm/kvm-cpu.h"
@@ -80,12 +81,12 @@  int spapr_rtas_fdt_setup(struct kvm *kvm, void *fdt);
 
 static inline uint32_t rtas_ld(struct kvm *kvm, target_ulong phys, int n)
 {
-	return *((uint32_t *)guest_flat_to_host(kvm, phys + 4*n));
+	return cpu_to_be32(*((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)));
 }
 
 static inline void rtas_st(struct kvm *kvm, target_ulong phys, int n, uint32_t val)
 {
-	*((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)) = val;
+	*((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)) = cpu_to_be32(val);
 }
 
 typedef void (*spapr_rtas_fn)(struct kvm_cpu *vcpu, uint32_t token,