RE: [PATCH 03/11] Use arch.pid as shadow pid for E500

2008-12-11 Thread Liu Yu

> -Original Message-
> From: kvm-ppc-ow...@vger.kernel.org 
> [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Hollis Blanchard
> Sent: Friday, December 12, 2008 5:02 AM
> To: Liu Yu-B13201
> Cc: kvm-ppc@vger.kernel.org
> Subject: Re: [PATCH 03/11] Use arch.pid as shadow pid for E500
> 
> On Thu, 2008-12-11 at 17:11 +0800, Liu Yu wrote:
> > Signed-off-by: Liu Yu 
> > ---
> >  arch/powerpc/kernel/asm-offsets.c |8 +++-
> >  1 files changed, 7 insertions(+), 1 deletions(-)
> > 
> > diff --git a/arch/powerpc/kernel/asm-offsets.c 
> b/arch/powerpc/kernel/asm-offsets.c
> > index 544a27f..79fe94c 100644
> > --- a/arch/powerpc/kernel/asm-offsets.c
> > +++ b/arch/powerpc/kernel/asm-offsets.c
> > @@ -355,6 +355,13 @@ int main(void)
> > DEFINE(PTE_SIZE, sizeof(pte_t));
> > 
> >  #ifdef CONFIG_KVM
> > +#ifdef CONFIG_44x
> > +   DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, 
> arch.shadow_pid));
> > +#endif
> > +#ifdef CONFIG_FSL_BOOKE
> > +   DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.pid));
> > +#endif
> > +
> > DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, 
> arch.host_stack));
> > DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid));
> > DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr));
> > @@ -368,7 +375,6 @@ int main(void)
> > DEFINE(VCPU_SPRG5, offsetof(struct kvm_vcpu, arch.sprg5));
> > DEFINE(VCPU_SPRG6, offsetof(struct kvm_vcpu, arch.sprg6));
> > DEFINE(VCPU_SPRG7, offsetof(struct kvm_vcpu, arch.sprg7));
> > -   DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, 
> arch.shadow_pid));
> > 
> > DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, 
> arch.last_inst));
> > DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, 
> arch.fault_dear));
> 
> I can commit this, but we got a significant performance boost from
> implementing the shadow_pid scheme. Do you think implementing 
> that would
> be difficult?
> 

Not difficult.
But I want to compare it with some other ways before apply it.

As you know, E500 has a large TLB0, so it has more room to handle
multi-VMs on a single core.
Current shadow pid trick indeed boost performance in the case of one VM,
but for multi-VMs, your pid mapping idea seems better for E500.
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH 6/6] IBM PowerPC 440EP Bamboo reference board emulation

2008-12-11 Thread Hollis Blanchard
On Thu, 2008-12-11 at 15:39 -0600, Anthony Liguori wrote:
> Hollis Blanchard wrote:
> > +
> > +#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
> > +
> > +static void *bamboo_load_device_tree(void *addr,
> > + uint32_t ramsize,
> > + target_phys_addr_t initrd_base,
> > + target_phys_addr_t initrd_size,
> > + const char *kernel_cmdline)
> > +{
> > +void *fdt = NULL;
> > +#ifdef HAVE_FDT
> >   
> 
> Is this at all usable without libfdt?  If not, just don't compile this 
> board in unless libfdt is present.

In practice, we've only tested with the -kernel option, which does
require libfdt.

However, in theory there is nothing that precludes running a firmware
(such as u-boot) inside the KVM guest. Jean-Christophe is working on
improving the ppc4xx device emulation so that becomes possible in the
future.

-- 
Hollis Blanchard
IBM Linux Technology Center

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


Re: [Qemu-devel] [PATCH 3/6] Enable KVM for ppcemb.

2008-12-11 Thread Hollis Blanchard
On Thu, 2008-12-11 at 15:30 -0600, Anthony Liguori wrote:
> Hollis Blanchard wrote:
> > +int kvm_arch_get_registers(CPUState *env)
> > +{
> > +   struct kvm_regs regs;
> > +   uint32_t i, ret;
> > +
> > +   ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s);
> > +   if (ret < 0)
> > +   return ret;
> > +
> > +   env->ctr = regs.ctr;
> > +   env->lr = regs.lr;
> > +   env->xer = regs.xer;
> > +   env->msr = regs.msr;
> > +   /* calculate hflags based on the current msr using the ppc qemu helper 
> > */
> > +   hreg_compute_hflags(env);
> >   
> 
> Do you need this?  Practically speaking, I don't even think we need to 
> maintain them on x86 anymore.

Ah, it seems you're right. That's good.

> > diff --git a/target-ppc/kvm_ppc.c b/target-ppc/kvm_ppc.c
> > new file mode 100644
> > index 000..b2b56df
> > --- /dev/null
> > +++ b/target-ppc/kvm_ppc.c
> >   
> 
> Hence my confusion.  These are just kvm related helper?
> 
> I don't know that kvm_ppc.c is a very information name for this sort of 
> stuff.  Since this is really host specific, not target specific, why not 
> move it out of target-ppc.

I could combine kvm_ppc.c into target-ppc/kvm.c. However, they're really
two different things, and I thought it would cause the least confusion
if they were logically separate. Most of it is hooks required by common
code, and then some of it isn't. (I'm thinking about e.g. IA64 doing a
copy/paste, and then wondering which functions they actually need to
implement.) Regardless, I will still need a kvm_ppc.h, so kvm_ppc.c
seemed like a good place to match.

I don't see that you can call any KVM code either host- or
target-specific, since by definition they are the same.

-- 
Hollis Blanchard
IBM Linux Technology Center

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


Re: [Qemu-devel] [PATCH 6/6] IBM PowerPC 440EP Bamboo reference board emulation

2008-12-11 Thread Anthony Liguori

Hollis Blanchard wrote:

Since most IO devices are integrated into the 440EP chip, "Bamboo support"
mostly entails implementing the -kernel, -initrd, and -append options.

These options are implemented by loading the guest as if u-boot had done it,
i.e. loading a flat device tree, updating it to hold initrd addresses, ram
size, and command line, and passing the FDT address in r3.

Since we use it with KVM, we enable the virtio block driver and include hooks
necessary for KVM support.

Signed-off-by: Hollis Blanchard 
---
 Makefile |2 +-
 Makefile.target  |2 +-
 hw/boards.h  |1 +
 hw/ppc440_bamboo.c   |  190 
 pc-bios/bamboo.dtb   |  Bin 0 -> 3163 bytes
 pc-bios/bamboo.dts   |  234 ++
 target-ppc/machine.c |2 +
 7 files changed, 429 insertions(+), 2 deletions(-)
 create mode 100644 hw/ppc440_bamboo.c
 create mode 100644 pc-bios/bamboo.dtb
 create mode 100644 pc-bios/bamboo.dts

diff --git a/Makefile b/Makefile
index a2a03ec..f9496fe 100644
--- a/Makefile
+++ b/Makefile
@@ -219,7 +219,7 @@ common  de-ch  es fo  fr-ca  hu ja  mk  nl-be  
pt  sl tr
 ifdef INSTALL_BLOBS
 BLOBS=bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
 video.x openbios-sparc32 openbios-sparc64 pxe-ne2k_pci.bin \
-pxe-rtl8139.bin pxe-pcnet.bin pxe-e1000.bin
+pxe-rtl8139.bin pxe-pcnet.bin pxe-e1000.bin bamboo.dtb
 else
 BLOBS=
 endif
diff --git a/Makefile.target b/Makefile.target
index 6032af0..82bc746 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -652,7 +652,7 @@ OBJS+= heathrow_pic.o grackle_pci.o ppc_oldworld.o
 OBJS+= unin_pci.o ppc_chrp.o
 # PowerPC 4xx boards
 OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
-OBJS+= ppc440.o
+OBJS+= ppc440.o ppc440_bamboo.o
 ifdef CONFIG_KVM
 OBJS+= kvm_ppc.o
 endif
diff --git a/hw/boards.h b/hw/boards.h
index d30c0fc..debe9a6 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -38,6 +38,7 @@ extern QEMUMachine core99_machine;
 extern QEMUMachine heathrow_machine;
 extern QEMUMachine ref405ep_machine;
 extern QEMUMachine taihu_machine;
+extern QEMUMachine bamboo_machine;
 
 /* mips_r4k.c */

 extern QEMUMachine mips_machine;
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
new file mode 100644
index 000..b0e3106
--- /dev/null
+++ b/hw/ppc440_bamboo.c
@@ -0,0 +1,190 @@
+/*
+ * Qemu PowerPC 440 board emulation
+ *
+ * Copyright 2007 IBM Corporation.
+ * Authors:
+ * Jerone Young 
+ * Christian Ehrhardt 
+ * Hollis Blanchard 
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include "config.h"
+#include "qemu-common.h"
+#include "net.h"
+#include "hw.h"
+#include "pci.h"
+#include "virtio-blk.h"
+#include "boards.h"
+#include "sysemu.h"
+#include "ppc440.h"
+#include "kvm.h"
+#include "kvm_ppc.h"
+#include "device_tree.h"
+
+#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
+
+static void *bamboo_load_device_tree(void *addr,
+ uint32_t ramsize,
+ target_phys_addr_t initrd_base,
+ target_phys_addr_t initrd_size,
+ const char *kernel_cmdline)
+{
+void *fdt = NULL;
+#ifdef HAVE_FDT
  


Is this at all usable without libfdt?  If not, just don't compile this 
board in unless libfdt is present.



+uint32_t mem_reg_property[] = { 0, 0, ramsize };
+char *path = NULL;
+int len;
+int ret;
+
+len = asprintf(&path, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
  


asprintf() is a GNU-ism and won't compile on Win32.


diff --git a/target-ppc/machine.c b/target-ppc/machine.c
index be0cbe1..72f67d0 100644
--- a/target-ppc/machine.c
+++ b/target-ppc/machine.c
@@ -1,5 +1,6 @@
 #include "hw/hw.h"
 #include "hw/boards.h"
+#include "kvm.h"


Is this necessary?

 
 void register_machines(void)

 {
@@ -8,6 +9,7 @@ void register_machines(void)
 qemu_register_machine(&prep_machine);
 qemu_register_machine(&ref405ep_machine);
 qemu_register_machine(&taihu_machine);
+qemu_register_machine(&bamboo_machine);
 }
 
 void cpu_save(QEMUFile *f, void *opaque)
  



Regards,

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


Re: [Qemu-devel] [PATCH 6/6] IBM PowerPC 440EP Bamboo reference board emulation

2008-12-11 Thread Blue Swirl
On 12/11/08, Hollis Blanchard  wrote:
> Since most IO devices are integrated into the 440EP chip, "Bamboo support"
>  mostly entails implementing the -kernel, -initrd, and -append options.
>
>  These options are implemented by loading the guest as if u-boot had done it,
>  i.e. loading a flat device tree, updating it to hold initrd addresses, ram
>  size, and command line, and passing the FDT address in r3.
>
>  Since we use it with KVM, we enable the virtio block driver and include hooks
>  necessary for KVM support.
>
>  Signed-off-by: Hollis Blanchard 

>  --- a/target-ppc/machine.c
>  +++ b/target-ppc/machine.c
>  @@ -1,5 +1,6 @@
>   #include "hw/hw.h"
>   #include "hw/boards.h"
>  +#include "kvm.h"

Shouldn't be necessary?
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH 4/6] Implement device tree support needed for Bamboo emulation

2008-12-11 Thread Anthony Liguori

Hollis Blanchard wrote:

diff --git a/device_tree.c b/device_tree.c
new file mode 100644
index 000..d7350e3
--- /dev/null
+++ b/device_tree.c
@@ -0,0 +1,116 @@
+/*
+ * Functions to help device tree manipulation using libfdt.
+ * It also provides functions to read entries from device tree proc
+ * interface.
+ *
+ * Copyright 2008 IBM Corporation.
+ * Authors: Jerone Young 
+ *  Hollis Blanchard 
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "config.h"
+#include "qemu-common.h"
+#include "sysemu.h"
+#include "device_tree.h"
+
+#include "libfdt.h"
  


#include 


+void *load_device_tree(const char *filename_path, void *load_addr)
+{
+   int dt_file_size;
+   int dt_file_load_size;
+   int new_dt_size;
+   int ret;
+   void *dt_file = NULL;
+   void *fdt;
+
+   dt_file_size = get_image_size(filename_path);
+   if (dt_file_size < 0) {
+   printf("Unable to get size of device tree file '%s'\n",
+   filename_path);
+   goto fail;
+   }
+
+   /* First allocate space in qemu for device tree */
+   dt_file = qemu_malloc(dt_file_size);
+   if (dt_file == NULL) {
+   printf("Unable to allocate memory in qemu for device tree\n");
+   goto fail;
+   }
+   memset(dt_file, 0, dt_file_size);

  


qemu_mallocz().  Indent is still bad.


+   dt_file_load_size = load_image(filename_path, dt_file);
+
+   /* Second we place new copy of 2x size in guest memory
+* This give us enough room for manipulation.
+*/
+   new_dt_size = dt_file_size * 2;
+
+   fdt = load_addr;
+   ret = fdt_open_into(dt_file, fdt, new_dt_size);
+   if (ret) {
+   printf("Unable to copy device tree in memory\n");
+   goto fail;
+   }
+
+   /* Check sanity of device tree */
+   if (fdt_check_header(fdt)) {
+   printf ("Device tree file loaded into memory is invalid: %s\n",
+   filename_path);
+   goto fail;
+   }
+   /* free qemu memory with old device tree */
+   qemu_free(dt_file);
+   return fdt;
+
+fail:
+   if (dt_file)
+   qemu_free(dt_file);
  


free() can safely take a NULL value.


+   return NULL;
+}
+
+int qemu_devtree_setprop(void *fdt, const char *node_path,
+ const char *property, uint32_t *val_array, int size)
+{
+   int offset;
+
+   offset = fdt_path_offset(fdt, node_path);
+if (offset < 0)
+return offset;
  


This is just goofy :-)


diff --git a/device_tree.h b/device_tree.h
new file mode 100644
index 000..9e6ef3d
--- /dev/null
+++ b/device_tree.h
@@ -0,0 +1,26 @@
+/*
+ * Header with function prototypes to help device tree manipulation using
+ * libfdt. It also provides functions to read entries from device tree proc
+ * interface.
+ *
+ * Copyright 2008 IBM Corporation.
+ * Authors: Jerone Young 
+ *  Hollis Blanchard 
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#ifndef __DEVICE_TREE_H__
+#define __DEVICE_TREE_H__
+
+void *load_device_tree(const char *filename_path, void *load_addr);
+
+int qemu_devtree_setprop(void *fdt, const char *node_path,
+ const char *property, uint32_t *val_array, int size);
+int qemu_devtree_setprop_cell(void *fdt, const char *node_path,
+  const char *property, uint32_t val);
+int qemu_devtree_setprop_string(void *fdt, const char *node_path,
+const char *property, const char *string);
+
+#endif /* __DEVICE_TREE_H__ */
diff --git a/libfdt_env.h b/libfdt_env.h
new file mode 100644
index 000..59f2536
--- /dev/null
+++ b/libfdt_env.h
  


Missing copyright?

Regards,

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


Re: [Qemu-devel] [PATCH 3/6] Enable KVM for ppcemb.

2008-12-11 Thread Anthony Liguori

Hollis Blanchard wrote:

Implement hooks called by generic KVM code.

Also add code that will copy the host's CPU and timebase frequencies to the
guest, which is necessary on KVM because the guest can directly access the
timebase.

Signed-off-by: Hollis Blanchard 
---
 Makefile.target  |3 +
 configure|6 ++
 target-ppc/helper.c  |5 +
 target-ppc/kvm.c |  212 ++
 target-ppc/kvm_ppc.c |  105 +
 target-ppc/kvm_ppc.h |   15 
 6 files changed, 346 insertions(+), 0 deletions(-)
 create mode 100644 target-ppc/kvm.c
 create mode 100644 target-ppc/kvm_ppc.c
 create mode 100644 target-ppc/kvm_ppc.h

diff --git a/Makefile.target b/Makefile.target
index 7152dff..d01231d 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -652,6 +652,9 @@ OBJS+= heathrow_pic.o grackle_pci.o ppc_oldworld.o
 OBJS+= unin_pci.o ppc_chrp.o
 # PowerPC 4xx boards
 OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
+ifdef CONFIG_KVM
+OBJS+= kvm_ppc.o
+endif
  


Shouldn't you be kvm.o?  If your file lives in target-ppc/kvm.c, it'll 
just work.



 diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
new file mode 100644
index 000..90b943b
--- /dev/null
+++ b/target-ppc/kvm.c
@@ -0,0 +1,212 @@
+int kvm_arch_put_registers(CPUState *env)
+{
+   struct kvm_regs regs;
+   int ret;
+   int i;
  


Your indent is off.


+int kvm_arch_get_registers(CPUState *env)
+{
+   struct kvm_regs regs;
+   uint32_t i, ret;
+
+   ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s);
+   if (ret < 0)
+   return ret;
+
+   env->ctr = regs.ctr;
+   env->lr = regs.lr;
+   env->xer = regs.xer;
+   env->msr = regs.msr;
+   /* calculate hflags based on the current msr using the ppc qemu helper 
*/
+   hreg_compute_hflags(env);
  


Do you need this?  Practically speaking, I don't even think we need to 
maintain them on x86 anymore.



diff --git a/target-ppc/kvm_ppc.c b/target-ppc/kvm_ppc.c
new file mode 100644
index 000..b2b56df
--- /dev/null
+++ b/target-ppc/kvm_ppc.c
  


Hence my confusion.  These are just kvm related helper?

I don't know that kvm_ppc.c is a very information name for this sort of 
stuff.  Since this is really host specific, not target specific, why not 
move it out of target-ppc.


Regards,

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


Re: [Qemu-devel] [PATCH 2/6] kvm: sync vcpu state during initialization

2008-12-11 Thread Anthony Liguori

Hollis Blanchard wrote:

Currently on x86, qemu initializes CPUState but KVM ignores it and does its
own vcpu initialization. However, PowerPC KVM needs to be able to set the
initial register state to support the -kernel and -append options.

Signed-off-by: Hollis Blanchard 
  


Segv's x86 when using -enable-kvm.

Regards,

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


Re: [PATCH 03/11] Use arch.pid as shadow pid for E500

2008-12-11 Thread Hollis Blanchard
On Thu, 2008-12-11 at 17:11 +0800, Liu Yu wrote:
> Signed-off-by: Liu Yu 
> ---
>  arch/powerpc/kernel/asm-offsets.c |8 +++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/asm-offsets.c 
> b/arch/powerpc/kernel/asm-offsets.c
> index 544a27f..79fe94c 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -355,6 +355,13 @@ int main(void)
>   DEFINE(PTE_SIZE, sizeof(pte_t));
> 
>  #ifdef CONFIG_KVM
> +#ifdef CONFIG_44x
> + DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
> +#endif
> +#ifdef CONFIG_FSL_BOOKE
> + DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.pid));
> +#endif
> +
>   DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack));
>   DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid));
>   DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr));
> @@ -368,7 +375,6 @@ int main(void)
>   DEFINE(VCPU_SPRG5, offsetof(struct kvm_vcpu, arch.sprg5));
>   DEFINE(VCPU_SPRG6, offsetof(struct kvm_vcpu, arch.sprg6));
>   DEFINE(VCPU_SPRG7, offsetof(struct kvm_vcpu, arch.sprg7));
> - DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
> 
>   DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
>   DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));

I can commit this, but we got a significant performance boost from
implementing the shadow_pid scheme. Do you think implementing that would
be difficult?

-- 
Hollis Blanchard
IBM Linux Technology Center

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


Re: [PATCH 2/6] kvm: sync vcpu state during initialization

2008-12-11 Thread Hollis Blanchard
On Thu, 2008-12-11 at 14:52 -0600, Hollis Blanchard wrote:
> Currently on x86, qemu initializes CPUState but KVM ignores it and does its
> own vcpu initialization. However, PowerPC KVM needs to be able to set the
> initial register state to support the -kernel and -append options.
> 
> Signed-off-by: Hollis Blanchard 

I forgot to comment that since this changes x86 code flow, it's worth
testing with x86 KVM before committing.

-- 
Hollis Blanchard
IBM Linux Technology Center

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


[PATCH 6/6] IBM PowerPC 440EP Bamboo reference board emulation

2008-12-11 Thread Hollis Blanchard
Since most IO devices are integrated into the 440EP chip, "Bamboo support"
mostly entails implementing the -kernel, -initrd, and -append options.

These options are implemented by loading the guest as if u-boot had done it,
i.e. loading a flat device tree, updating it to hold initrd addresses, ram
size, and command line, and passing the FDT address in r3.

Since we use it with KVM, we enable the virtio block driver and include hooks
necessary for KVM support.

Signed-off-by: Hollis Blanchard 
---
 Makefile |2 +-
 Makefile.target  |2 +-
 hw/boards.h  |1 +
 hw/ppc440_bamboo.c   |  190 
 pc-bios/bamboo.dtb   |  Bin 0 -> 3163 bytes
 pc-bios/bamboo.dts   |  234 ++
 target-ppc/machine.c |2 +
 7 files changed, 429 insertions(+), 2 deletions(-)
 create mode 100644 hw/ppc440_bamboo.c
 create mode 100644 pc-bios/bamboo.dtb
 create mode 100644 pc-bios/bamboo.dts

diff --git a/Makefile b/Makefile
index a2a03ec..f9496fe 100644
--- a/Makefile
+++ b/Makefile
@@ -219,7 +219,7 @@ common  de-ch  es fo  fr-ca  hu ja  mk  nl-be  
pt  sl tr
 ifdef INSTALL_BLOBS
 BLOBS=bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
 video.x openbios-sparc32 openbios-sparc64 pxe-ne2k_pci.bin \
-pxe-rtl8139.bin pxe-pcnet.bin pxe-e1000.bin
+pxe-rtl8139.bin pxe-pcnet.bin pxe-e1000.bin bamboo.dtb
 else
 BLOBS=
 endif
diff --git a/Makefile.target b/Makefile.target
index 6032af0..82bc746 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -652,7 +652,7 @@ OBJS+= heathrow_pic.o grackle_pci.o ppc_oldworld.o
 OBJS+= unin_pci.o ppc_chrp.o
 # PowerPC 4xx boards
 OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
-OBJS+= ppc440.o
+OBJS+= ppc440.o ppc440_bamboo.o
 ifdef CONFIG_KVM
 OBJS+= kvm_ppc.o
 endif
diff --git a/hw/boards.h b/hw/boards.h
index d30c0fc..debe9a6 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -38,6 +38,7 @@ extern QEMUMachine core99_machine;
 extern QEMUMachine heathrow_machine;
 extern QEMUMachine ref405ep_machine;
 extern QEMUMachine taihu_machine;
+extern QEMUMachine bamboo_machine;
 
 /* mips_r4k.c */
 extern QEMUMachine mips_machine;
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
new file mode 100644
index 000..b0e3106
--- /dev/null
+++ b/hw/ppc440_bamboo.c
@@ -0,0 +1,190 @@
+/*
+ * Qemu PowerPC 440 board emulation
+ *
+ * Copyright 2007 IBM Corporation.
+ * Authors:
+ * Jerone Young 
+ * Christian Ehrhardt 
+ * Hollis Blanchard 
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include "config.h"
+#include "qemu-common.h"
+#include "net.h"
+#include "hw.h"
+#include "pci.h"
+#include "virtio-blk.h"
+#include "boards.h"
+#include "sysemu.h"
+#include "ppc440.h"
+#include "kvm.h"
+#include "kvm_ppc.h"
+#include "device_tree.h"
+
+#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
+
+static void *bamboo_load_device_tree(void *addr,
+ uint32_t ramsize,
+ target_phys_addr_t initrd_base,
+ target_phys_addr_t initrd_size,
+ const char *kernel_cmdline)
+{
+void *fdt = NULL;
+#ifdef HAVE_FDT
+uint32_t mem_reg_property[] = { 0, 0, ramsize };
+char *path = NULL;
+int len;
+int ret;
+
+len = asprintf(&path, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
+if (len < 0) {
+perror("asprintf");
+return NULL;
+}
+
+fdt = load_device_tree(path, addr);
+free(path);
+if (fdt == NULL)
+goto out;
+
+/* Manipulate device tree in memory. */
+
+ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
+   sizeof(mem_reg_property));
+if (ret < 0)
+fprintf(stderr, "couldn't set /memory/reg\n");
+
+ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
+initrd_base);
+if (ret < 0)
+fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
+
+ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
+(initrd_base + initrd_size));
+if (ret < 0)
+fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
+
+ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
+  kernel_cmdline);
+if (ret < 0)
+fprintf(stderr, "couldn't set /chosen/bootargs\n");
+
+if (kvm_enabled())
+kvmppc_fdt_update(fdt);
+
+out:
+#endif
+
+return fdt;
+}
+
+static void bamboo_init(ram_addr_t ram_size, int vga_ram_size,
+const char *boot_device, DisplayState *ds,
+const char *kernel_filename,
+const char *kernel_cmdline,
+const char *initrd_filename,
+const char *cpu_model)
+{
+ 

[PATCH 5/6] PowerPC 440EP SoC emulation

2008-12-11 Thread Hollis Blanchard
Wire up the system-on-chip devices present on 440EP chips.

This patch is a little unusual in that qemu doesn't actually emulate the 440
core, but we use this board code with KVM (which does). If/when 440 core
emulation is supported, the kvm_enabled() hack can be removed.

Signed-off-by: Hollis Blanchard 
---
 Makefile.target |1 +
 hw/ppc440.c |  144 +++
 hw/ppc440.h |   20 
 3 files changed, 165 insertions(+), 0 deletions(-)
 create mode 100644 hw/ppc440.c
 create mode 100644 hw/ppc440.h

diff --git a/Makefile.target b/Makefile.target
index 5da4994..6032af0 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -652,6 +652,7 @@ OBJS+= heathrow_pic.o grackle_pci.o ppc_oldworld.o
 OBJS+= unin_pci.o ppc_chrp.o
 # PowerPC 4xx boards
 OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
+OBJS+= ppc440.o
 ifdef CONFIG_KVM
 OBJS+= kvm_ppc.o
 endif
diff --git a/hw/ppc440.c b/hw/ppc440.c
new file mode 100644
index 000..654249f
--- /dev/null
+++ b/hw/ppc440.c
@@ -0,0 +1,144 @@
+/*
+ * Qemu PowerPC 440 chip emulation
+ *
+ * Copyright 2007 IBM Corporation.
+ * Authors:
+ * Jerone Young 
+ * Christian Ehrhardt 
+ * Hollis Blanchard 
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include "hw.h"
+#include "isa.h"
+#include "ppc.h"
+#include "ppc4xx.h"
+#include "ppc440.h"
+#include "ppc405.h"
+#include "sysemu.h"
+#include "kvm.h"
+
+#define PPC440EP_SDRAM_NR_BANKS 4
+
+#define PPC440EP_PCI_CONFIG 0xeec0
+#define PPC440EP_PCI_INTACK 0xeed0
+#define PPC440EP_PCI_SPECIAL0xeed0
+#define PPC440EP_PCI_REGS   0xef40
+#define PPC440EP_PCI_IO 0xe800
+#define PPC440EP_PCI_IOLEN  0x0001
+
+static const unsigned int ppc440ep_sdram_bank_sizes[] = {
+256<<20, 128<<20, 64<<20, 32<<20, 16<<20, 8<<20, 0
+};
+
+/* XXX move to ppc4xx_devs.c */
+/* Fill in consecutive SDRAM banks with 'ram_size' bytes of memory.
+ *
+ * The SDRAM controller supports a small number of banks, and each bank must be
+ * one of a small set of sizes. The number of banks and the supported sizes
+ * varies by SoC. */
+ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,
+   target_phys_addr_t ram_bases[],
+   target_phys_addr_t ram_sizes[],
+   const unsigned int sdram_bank_sizes[])
+{
+ram_addr_t ram_end = 0;
+int i;
+int j;
+
+for (i = 0; i < nr_banks; i++) {
+for (j = 0; sdram_bank_sizes[j] != 0; j++) {
+unsigned int bank_size = sdram_bank_sizes[j];
+
+if (bank_size <= ram_size) {
+ram_bases[i] = ram_end;
+ram_sizes[i] = bank_size;
+ram_end += bank_size;
+ram_size -= bank_size;
+break;
+}
+}
+
+if (!ram_size) {
+/* No need to use the remaining banks. */
+break;
+}
+}
+
+if (ram_size)
+printf("Truncating memory to %d MiB to fit SDRAM controller limits.\n",
+   (int)(ram_end >> 20));
+
+return ram_end;
+}
+
+CPUState *ppc440ep_init(ram_addr_t *ram_size, PCIBus **pcip,
+const unsigned int pci_irq_nrs[4], int do_init)
+{
+target_phys_addr_t ram_bases[PPC440EP_SDRAM_NR_BANKS];
+target_phys_addr_t ram_sizes[PPC440EP_SDRAM_NR_BANKS];
+CPUState *env;
+ppc4xx_mmio_t *mmio;
+qemu_irq *pic;
+qemu_irq *irqs;
+qemu_irq *pci_irqs;
+
+env = cpu_ppc_init("440EP");
+if (!env && kvm_enabled()) {
+/* XXX Since qemu doesn't yet emulate 440, we just say it's a 405.
+ * Since KVM doesn't use qemu's CPU emulation it seems to be working
+ * OK. */
+env = cpu_ppc_init("405");
+}
+if (!env) {
+fprintf(stderr, "Unable to initialize CPU!\n");
+exit(1);
+}
+
+ppc_dcr_init(env, NULL, NULL);
+
+/* interrupt controller */
+irqs = qemu_mallocz(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
+irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq 
*)env->irq_inputs)[PPC40x_INPUT_CINT];
+pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);
+
+/* SDRAM controller */
+memset(ram_bases, 0, sizeof(ram_bases));
+memset(ram_sizes, 0, sizeof(ram_sizes));
+*ram_size = ppc4xx_sdram_adjust(*ram_size, PPC440EP_SDRAM_NR_BANKS,
+ram_bases, ram_sizes,
+ppc440ep_sdram_bank_sizes);
+/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */
+ppc405_sdram_init(env, pic[14], PPC440EP_SDRAM_NR_BANKS, ram_bases,
+  ram_sizes, do_init);
+
+/* PCI */
+pci_irqs = qemu_malloc(sizeof(qemu_irq) * 4);
+pci_irqs[0] = pic[pci_irq_nrs[0]];
+pci_irqs[1] = pic[pci_irq_nrs[1]];
+pc

[PATCH 4/6] Implement device tree support needed for Bamboo emulation

2008-12-11 Thread Hollis Blanchard
To implement the -kernel, -initrd, and -append options, 4xx board emulation
must load the guest kernel as if firmware had loaded it. Where u-boot would be
the firmware, we must load the flat device tree into memory and set key fields
such as /chosen/bootargs.

This patch introduces a dependency on libfdt for flat device tree support.

Signed-off-by: Hollis Blanchard 
---
 Makefile.target |4 ++
 configure   |   18 
 device_tree.c   |  116 +++
 device_tree.h   |   26 
 libfdt_env.h|   22 ++
 5 files changed, 186 insertions(+), 0 deletions(-)
 create mode 100644 device_tree.c
 create mode 100644 device_tree.h
 create mode 100644 libfdt_env.h

diff --git a/Makefile.target b/Makefile.target
index d01231d..5da4994 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -655,6 +655,10 @@ OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc4xx_pci.o 
ppc405_uc.o ppc405_boards.o
 ifdef CONFIG_KVM
 OBJS+= kvm_ppc.o
 endif
+ifdef FDT_LIBS
+OBJS+= device_tree.o
+LIBS+= $(FDT_LIBS)
+endif
 # virtio support
 OBJS+= virtio.o virtio-blk.o virtio-balloon.o
 endif
diff --git a/configure b/configure
index c534441..b54c15d 100755
--- a/configure
+++ b/configure
@@ -119,6 +119,7 @@ kvm="yes"
 kerneldir=""
 aix="no"
 blobs="yes"
+fdt="yes"
 
 # OS specific
 targetos=`uname -s`
@@ -976,6 +977,18 @@ if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
   iovec=yes
 fi
 
+##
+# fdt probe
+if test "$fdt" = "yes" ; then
+fdt=no
+cat > $TMPC << EOF
+int main(void) { return 0; }
+EOF
+  if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $TMPC -lfdt 2> /dev/null ; then
+fdt=yes
+  fi
+fi
+
 # Check if tools are available to build documentation.
 if [ -x "`which texi2html 2>/dev/null`" ] && \
[ -x "`which pod2man 2>/dev/null`" ]; then
@@ -1051,6 +1064,7 @@ echo "vde support   $vde"
 echo "AIO support   $aio"
 echo "Install blobs $blobs"
 echo "KVM support   $kvm"
+echo "fdt support   $kvm"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -1340,6 +1354,10 @@ fi
 if test "$iovec" = "yes" ; then
   echo "#define HAVE_IOVEC 1" >> $config_h
 fi
+if test "$fdt" = "yes" ; then
+  echo "#define HAVE_FDT 1" >> $config_h
+  echo "FDT_LIBS=-lfdt" >> $config_mak
+fi
 
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then
diff --git a/device_tree.c b/device_tree.c
new file mode 100644
index 000..d7350e3
--- /dev/null
+++ b/device_tree.c
@@ -0,0 +1,116 @@
+/*
+ * Functions to help device tree manipulation using libfdt.
+ * It also provides functions to read entries from device tree proc
+ * interface.
+ *
+ * Copyright 2008 IBM Corporation.
+ * Authors: Jerone Young 
+ *  Hollis Blanchard 
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "config.h"
+#include "qemu-common.h"
+#include "sysemu.h"
+#include "device_tree.h"
+
+#include "libfdt.h"
+
+void *load_device_tree(const char *filename_path, void *load_addr)
+{
+   int dt_file_size;
+   int dt_file_load_size;
+   int new_dt_size;
+   int ret;
+   void *dt_file = NULL;
+   void *fdt;
+
+   dt_file_size = get_image_size(filename_path);
+   if (dt_file_size < 0) {
+   printf("Unable to get size of device tree file '%s'\n",
+   filename_path);
+   goto fail;
+   }
+
+   /* First allocate space in qemu for device tree */
+   dt_file = qemu_malloc(dt_file_size);
+   if (dt_file == NULL) {
+   printf("Unable to allocate memory in qemu for device tree\n");
+   goto fail;
+   }
+   memset(dt_file, 0, dt_file_size);
+
+   dt_file_load_size = load_image(filename_path, dt_file);
+
+   /* Second we place new copy of 2x size in guest memory
+* This give us enough room for manipulation.
+*/
+   new_dt_size = dt_file_size * 2;
+
+   fdt = load_addr;
+   ret = fdt_open_into(dt_file, fdt, new_dt_size);
+   if (ret) {
+   printf("Unable to copy device tree in memory\n");
+   goto fail;
+   }
+
+   /* Check sanity of device tree */
+   if (fdt_check_header(fdt)) {
+   printf ("Device tree file loaded into memory is invalid: %s\n",
+   filename_path);
+   goto fail;
+   }
+   /* free qemu memory with old device tree */
+   qemu_free(dt_file);
+   return fdt;
+
+fail:
+   if (dt_file)
+   qemu_free(dt_file);
+   return NULL;
+}
+
+int qemu_devtree_setprop(void *fdt, const char *node_path,
+ const char *property, uint32_t *val_array, int size)
+{
+   int offset;
+
+   offset = fdt_path_offset(fdt, node_path);
+if (offset < 0)
+return offset;
+
+   return fdt_setpro

[PATCH 3/6] Enable KVM for ppcemb.

2008-12-11 Thread Hollis Blanchard
Implement hooks called by generic KVM code.

Also add code that will copy the host's CPU and timebase frequencies to the
guest, which is necessary on KVM because the guest can directly access the
timebase.

Signed-off-by: Hollis Blanchard 
---
 Makefile.target  |3 +
 configure|6 ++
 target-ppc/helper.c  |5 +
 target-ppc/kvm.c |  212 ++
 target-ppc/kvm_ppc.c |  105 +
 target-ppc/kvm_ppc.h |   15 
 6 files changed, 346 insertions(+), 0 deletions(-)
 create mode 100644 target-ppc/kvm.c
 create mode 100644 target-ppc/kvm_ppc.c
 create mode 100644 target-ppc/kvm_ppc.h

diff --git a/Makefile.target b/Makefile.target
index 7152dff..d01231d 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -652,6 +652,9 @@ OBJS+= heathrow_pic.o grackle_pci.o ppc_oldworld.o
 OBJS+= unin_pci.o ppc_chrp.o
 # PowerPC 4xx boards
 OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
+ifdef CONFIG_KVM
+OBJS+= kvm_ppc.o
+endif
 # virtio support
 OBJS+= virtio.o virtio-blk.o virtio-balloon.o
 endif
diff --git a/configure b/configure
index 13f6358..c534441 100755
--- a/configure
+++ b/configure
@@ -1463,6 +1463,7 @@ gdb_xml_files=""
 
 # Make sure the target and host cpus are compatible
 if test "$kvm" = "yes" -a ! \( "$target_cpu" = "$cpu" -o \
+  \( "$target_cpu" = "ppcemb" -a "$cpu" = "powerpc" \) -o \
   \( "$target_cpu" = "x86_64" -a "$cpu" = "i386"   \) -o \
   \( "$target_cpu" = "i386"   -a "$cpu" = "x86_64" \) \) ; then
   kvm="no"
@@ -1557,6 +1558,11 @@ case "$target_cpu" in
 echo "#define TARGET_ARCH \"ppcemb\"" >> $config_h
 echo "#define TARGET_PPC 1" >> $config_h
 echo "#define TARGET_PPCEMB 1" >> $config_h
+if test "$kvm" = "yes" ; then
+  echo "CONFIG_KVM=yes" >> $config_mak
+  echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
+  echo "#define CONFIG_KVM 1" >> $config_h
+fi
   ;;
   ppc64)
 echo "TARGET_ARCH=ppc64" >> $config_mak
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 33e8b3b..0b93f1c 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -30,6 +30,7 @@
 #include "helper_regs.h"
 #include "qemu-common.h"
 #include "helper.h"
+#include "kvm.h"
 
 //#define DEBUG_MMU
 //#define DEBUG_BATS
@@ -2939,6 +2940,10 @@ CPUPPCState *cpu_ppc_init (const char *cpu_model)
 env->cpu_model_str = cpu_model;
 cpu_ppc_register_internal(env, def);
 cpu_ppc_reset(env);
+
+if (kvm_enabled())
+kvm_init_vcpu(env);
+
 return env;
 }
 
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
new file mode 100644
index 000..90b943b
--- /dev/null
+++ b/target-ppc/kvm.c
@@ -0,0 +1,212 @@
+/*
+ * PowerPC implementation of KVM hooks
+ *
+ * Copyright IBM Corp. 2007
+ *
+ * Authors:
+ *  Jerone Young 
+ *  Christian Ehrhardt 
+ *  Hollis Blanchard 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+
+#include "helper_regs.h"
+#include "qemu-common.h"
+#include "qemu-timer.h"
+#include "sysemu.h"
+#include "kvm.h"
+#include "kvm_ppc.h"
+#include "cpu.h"
+#include "device_tree.h"
+
+//#define DEBUG_KVM
+
+#ifdef DEBUG_KVM
+#define dprintf(fmt, ...) \
+do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
+#else
+#define dprintf(fmt, ...) \
+do { } while (0)
+#endif
+
+int kvm_arch_init(KVMState *s, int smp_cpus)
+{
+   return 0;
+}
+
+int kvm_arch_init_vcpu(CPUState *cenv)
+{
+   return 0;
+}
+
+int kvm_arch_put_registers(CPUState *env)
+{
+   struct kvm_regs regs;
+   int ret;
+   int i;
+
+   ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s);
+   if (ret < 0)
+   return ret;
+
+   /* cr is untouched in qemu and not existant in CPUState fr ppr */
+   /* hflags is a morphed to MSR on ppc, no need to sync that down to kvm 
*/
+
+   regs.pc = env->nip;
+
+   regs.ctr = env->ctr;
+   regs.lr  = env->lr;
+   regs.xer = env->xer;
+   regs.msr = env->msr;
+
+   regs.srr0 = env->spr[SPR_SRR0];
+   regs.srr1 = env->spr[SPR_SRR1];
+
+   regs.sprg0 = env->spr[SPR_SPRG0];
+   regs.sprg1 = env->spr[SPR_SPRG1];
+   regs.sprg2 = env->spr[SPR_SPRG2];
+   regs.sprg3 = env->spr[SPR_SPRG3];
+   regs.sprg4 = env->spr[SPR_SPRG4];
+   regs.sprg5 = env->spr[SPR_SPRG5];
+   regs.sprg6 = env->spr[SPR_SPRG6];
+   regs.sprg7 = env->spr[SPR_SPRG7];
+
+   for (i = 0;i < 32; i++)
+   regs.gpr[i] = env->gpr[i];
+
+   ret = kvm_vcpu_ioctl(env, KVM_SET_REGS, ®s);
+   if (ret < 0)
+   return ret;
+
+   return ret;
+}
+
+int kvm_arch_get_registers(CPUState *env)
+{
+   struct kvm_regs regs;
+   uint32_t i, ret;
+
+   ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s);
+   if (ret < 0)
+   return ret;
+
+   env->ctr = regs.ctr;
+   env->lr = regs.lr;
+   env

[PATCH 2/6] kvm: sync vcpu state during initialization

2008-12-11 Thread Hollis Blanchard
Currently on x86, qemu initializes CPUState but KVM ignores it and does its
own vcpu initialization. However, PowerPC KVM needs to be able to set the
initial register state to support the -kernel and -append options.

Signed-off-by: Hollis Blanchard 
---
 kvm-all.c |   15 +++
 kvm.h |1 +
 vl.c  |   11 +++
 3 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index dad80df..11034df 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -141,6 +141,21 @@ err:
 return ret;
 }
 
+int kvm_sync_vcpus(void)
+{
+CPUState *env;
+
+for (env = first_cpu; env != NULL; env = env->next_cpu) {
+int ret;
+
+ret = kvm_arch_put_registers(env);
+if (ret)
+return ret;
+}
+
+return 0;
+}
+
 /*
  * dirty pages logging control
  */
diff --git a/kvm.h b/kvm.h
index ac464ab..efce145 100644
--- a/kvm.h
+++ b/kvm.h
@@ -31,6 +31,7 @@ struct kvm_run;
 int kvm_init(int smp_cpus);
 
 int kvm_init_vcpu(CPUState *env);
+int kvm_sync_vcpus(void);
 
 int kvm_cpu_exec(CPUState *env);
 
diff --git a/vl.c b/vl.c
index c3a8d8f..0a02151 100644
--- a/vl.c
+++ b/vl.c
@@ -5456,6 +5456,17 @@ int main(int argc, char **argv, char **envp)
 machine->init(ram_size, vga_ram_size, boot_devices, ds,
   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
+/* Set KVM's vcpu state to qemu's initial CPUState. */
+if (kvm_enabled()) {
+int ret;
+
+ret = kvm_sync_vcpus();
+if (ret < 0) {
+fprintf(stderr, "failed to initialize vcpus\n");
+exit(1);
+}
+}
+
 /* init USB devices */
 if (usb_enabled) {
 for(i = 0; i < usb_devices_index; i++) {
-- 
1.5.6.5

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


[PATCH 1/6] Include headers for types used in helper_regs.h

2008-12-11 Thread Hollis Blanchard
helper_regs.h uses "always_inline" and MSR_* constants, which are defined
in osdep.h and cpu.h.

Signed-off-by: Hollis Blanchard 
---
 target-ppc/helper_regs.h |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/target-ppc/helper_regs.h b/target-ppc/helper_regs.h
index 9666d4b..72a3f87 100644
--- a/target-ppc/helper_regs.h
+++ b/target-ppc/helper_regs.h
@@ -21,6 +21,10 @@
 #if !defined(__HELPER_REGS_H__)
 #define __HELPER_REGS_H__
 
+#include "osdep.h"
+#include 
+#include "cpu.h"
+
 /* Swap temporary saved registers with GPRs */
 static always_inline void hreg_swap_gpr_tgpr (CPUPPCState *env)
 {
-- 
1.5.6.5

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


PowerPC KVM support

2008-12-11 Thread Hollis Blanchard
These patches implement KVM support for the PowerPC Bamboo board, a system
built around the 440EP SoC. In the KVM model, the KVM kernel module is
responsible for all instruction execution, so it doesn't matter that TCG
doesn't emulate the 440 core.

We've only tested KVM and Bamboo with the -kernel option. I have no idea what
it would take to run a firmware like u-boot inside the VM, but it's basically
the same problem as running u-boot inside a 405 VM (which I know
Jean-Christophe is working on).

There are a couple issues I'd appreciate feedback on:

- The "bamboo" machine shows up as an option ("-M \?"), but if a user selects
  it without KVM support, they will just get an error. I don't like that, but
  register_machines() is called before --enable-kvm is recognized.

- We call cpu_ppc_init("405") to create a CPUState, because some CPUState
  fields are required outside of TCG. We could instead create a "KVM" CPU
  name, or a cpu_ppc_init_kvm() function. I'd prefer to stay on a common code
  path though, so that if new CPUState fields are introduced in the future,
  there's no KVM-specific path that breaks.

- I'd like to use ppc4xx_sdram_adjust() with the existing 405 targets as well,
  but nobody can tell me how to get a functioning 405 qemu so I can't test it.
  I may submit a separate patch series for this anyways.

-Hollis


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


Re: [PATCH] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

2008-12-11 Thread Hollis Blanchard
On Thu, 2008-12-11 at 17:05 +0100, Jan Kiszka wrote:
> Hollis Blanchard wrote:
> > On Thu, 2008-12-11 at 13:53 +0100, Christian Ehrhardt wrote:
> >> This is v2 as version one had a type in it occured when splitting patches.
> >> Mercurial somehow lost my changes to the patch description explaining 
> >> that, but the patch is right this way.
> >>
> >> Christian Ehrhardt wrote:
> >>> # HG changeset patch
> >>> # User Christian Ehrhardt 
> >>> 
> >>> # Date 1228999833 -3600
> >>> # Node ID dc1466c9077ab162f4637fffee1869f26be02299
> >>> # Parent  4c07fe2a56c7653a9113e05bb08c2de9aec210ce
> >>> [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub
> >>>
> >>> From: Hollis Blanchard 
> >>>
> >>> Add basic KVM PowerPC support to qemu's gdbstub introducing a kvm ppc 
> >>> style
> >>> mmu implementation that uses the kvm_translate ioctl.
> >>> This also requires to save the kvm registers prior to the 'm' gdb 
> >>> operations.
> >>>
> >>> Signed-off-by: Hollis Blanchard 
> >>> 
> >>> Signed-off-by: Christian Ehrhardt 
> >>> 
> > 
> > Let's *not* apply this to kvm-userspace. We will submit this to qemu,
> > and once we work out the right solution there it will be merged
> > naturally.
> > 
> 
> I don't oversee yet what you want to push upstream, but in case it's the
> gdbstub support for kvm (including ppc bits): please note that I plan to
> push the new interface once it is merged into kvm-userspace, avoiding to
> spread the current, limited one as far as possible.
> 
> BTW, would be great if you could have a look / provide patches for ppc
> to support the new interface already. I am open for feedback,
> specifically regarding its suitability beyond x86.

I've been meaning to do this for a while, sorry. We'll take a look soon.

-- 
Hollis Blanchard
IBM Linux Technology Center

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


Re: [PATCH 0/11] Add E500 support in KVM

2008-12-11 Thread Hollis Blanchard
On Thu, 2008-12-11 at 17:11 +0800, Liu Yu wrote:
> This patch set add E500 support in KVM,
> and is already based on Hollis's feedback (a patchset which not yet commit)
> 
> btw: The latest code seems broken with this error.
> ---
>   CC  arch/powerpc/kvm/../../../virt/kvm/kvm_main.o
> arch/powerpc/kvm/../../../virt/kvm/kvm_main.c: In function 
> ‘make_all_cpus_request’:
> arch/powerpc/kvm/../../../virt/kvm/kvm_main.c:577: error: implicit 
> declaration of function ‘smp_call_function_many’
> make[1]: *** [arch/powerpc/kvm/../../../virt/kvm/kvm_main.o] Error 1
> make: *** [arch/powerpc/kvm] Error 2
> --

Looks like this problem was introduced Monday. I submitted a fix for it
a couple hours ago, but forgot to copy kvm-ppc (sorry). Hopefully it
will go in soon.

> Fortunately, I could test these patch based on a commit a couple of days ago.

Great.

-- 
Hollis Blanchard
IBM Linux Technology Center

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


Re: [PATCH] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

2008-12-11 Thread Jan Kiszka
Hollis Blanchard wrote:
> On Thu, 2008-12-11 at 13:53 +0100, Christian Ehrhardt wrote:
>> This is v2 as version one had a type in it occured when splitting patches.
>> Mercurial somehow lost my changes to the patch description explaining 
>> that, but the patch is right this way.
>>
>> Christian Ehrhardt wrote:
>>> # HG changeset patch
>>> # User Christian Ehrhardt <[EMAIL PROTECTED]>
>>> # Date 1228999833 -3600
>>> # Node ID dc1466c9077ab162f4637fffee1869f26be02299
>>> # Parent  4c07fe2a56c7653a9113e05bb08c2de9aec210ce
>>> [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub
>>>
>>> From: Hollis Blanchard 
>>>
>>> Add basic KVM PowerPC support to qemu's gdbstub introducing a kvm ppc style
>>> mmu implementation that uses the kvm_translate ioctl.
>>> This also requires to save the kvm registers prior to the 'm' gdb 
>>> operations.
>>>
>>> Signed-off-by: Hollis Blanchard 
>>> Signed-off-by: Christian Ehrhardt <[EMAIL PROTECTED]>
> 
> Let's *not* apply this to kvm-userspace. We will submit this to qemu,
> and once we work out the right solution there it will be merged
> naturally.
> 

I don't oversee yet what you want to push upstream, but in case it's the
gdbstub support for kvm (including ppc bits): please note that I plan to
push the new interface once it is merged into kvm-userspace, avoiding to
spread the current, limited one as far as possible.

BTW, would be great if you could have a look / provide patches for ppc
to support the new interface already. I am open for feedback,
specifically regarding its suitability beyond x86.

Thanks,
Jan

-- 
Siemens AG, Corporate Technology, CT SE 26
Corporate Competence Center Embedded Linux
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

2008-12-11 Thread Hollis Blanchard
On Thu, 2008-12-11 at 13:53 +0100, Christian Ehrhardt wrote:
> This is v2 as version one had a type in it occured when splitting patches.
> Mercurial somehow lost my changes to the patch description explaining 
> that, but the patch is right this way.
> 
> Christian Ehrhardt wrote:
> > # HG changeset patch
> > # User Christian Ehrhardt <[EMAIL PROTECTED]>
> > # Date 1228999833 -3600
> > # Node ID dc1466c9077ab162f4637fffee1869f26be02299
> > # Parent  4c07fe2a56c7653a9113e05bb08c2de9aec210ce
> > [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub
> >
> > From: Hollis Blanchard <[EMAIL PROTECTED]>
> >
> > Add basic KVM PowerPC support to qemu's gdbstub introducing a kvm ppc style
> > mmu implementation that uses the kvm_translate ioctl.
> > This also requires to save the kvm registers prior to the 'm' gdb 
> > operations.
> >
> > Signed-off-by: Hollis Blanchard <[EMAIL PROTECTED]>
> > Signed-off-by: Christian Ehrhardt <[EMAIL PROTECTED]>

Let's *not* apply this to kvm-userspace. We will submit this to qemu,
and once we work out the right solution there it will be merged
naturally.

-- 
Hollis Blanchard
IBM Linux Technology Center

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

2008-12-11 Thread Christian Ehrhardt
# HG changeset patch
# User Christian Ehrhardt <[EMAIL PROTECTED]>
# Date 1228999833 -3600
# Node ID dc1466c9077ab162f4637fffee1869f26be02299
# Parent  4c07fe2a56c7653a9113e05bb08c2de9aec210ce
[PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

From: Hollis Blanchard <[EMAIL PROTECTED]>

Add basic KVM PowerPC support to qemu's gdbstub introducing a kvm ppc style
mmu implementation that uses the kvm_translate ioctl.
This also requires to save the kvm registers prior to the 'm' gdb operations.

Signed-off-by: Hollis Blanchard <[EMAIL PROTECTED]>
Signed-off-by: Christian Ehrhardt <[EMAIL PROTECTED]>
---

[diffstat]
 gdbstub.c   |2 ++
 hw/ppc440_bamboo.c  |1 +
 qemu-kvm-powerpc.c  |   28 
 target-ppc/cpu.h|2 ++
 target-ppc/helper.c |4 
 target-ppc/translate_init.c |5 +
 6 files changed, 42 insertions(+)

[diff]

diff --git a/qemu/gdbstub.c b/qemu/gdbstub.c
--- a/qemu/gdbstub.c
+++ b/qemu/gdbstub.c
@@ -1374,6 +1374,7 @@ static int gdb_handle_packet(GDBState *s
 if (*p == ',')
 p++;
 len = strtoull(p, NULL, 16);
+kvm_save_registers(s->g_cpu);
 if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 0) != 0) {
 put_packet (s, "E14");
 } else {
@@ -1389,6 +1390,7 @@ static int gdb_handle_packet(GDBState *s
 if (*p == ':')
 p++;
 hextomem(mem_buf, p, len);
+kvm_save_registers(s->g_cpu);
 if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 1) != 0)
 put_packet(s, "E14");
 else
diff --git a/qemu/hw/ppc440_bamboo.c b/qemu/hw/ppc440_bamboo.c
--- a/qemu/hw/ppc440_bamboo.c
+++ b/qemu/hw/ppc440_bamboo.c
@@ -99,6 +99,7 @@ void bamboo_init(ram_addr_t ram_size, in
fprintf(stderr, "Unable to initialize CPU!\n");
exit(1);
}
+   env->mmu_model = POWERPC_MMU_KVM;
 
/* call init */
printf("Calling function ppc440_init\n");
diff --git a/qemu/qemu-kvm-powerpc.c b/qemu/qemu-kvm-powerpc.c
--- a/qemu/qemu-kvm-powerpc.c
+++ b/qemu/qemu-kvm-powerpc.c
@@ -102,6 +102,7 @@ void kvm_arch_save_regs(CPUState *env)
 
 env->spr[SPR_SRR0] = regs.srr0;
 env->spr[SPR_SRR1] = regs.srr1;
+env->spr[SPR_BOOKE_PID] = regs.pid;
 
 env->spr[SPR_SPRG0] = regs.sprg0;
 env->spr[SPR_SPRG1] = regs.sprg1;
@@ -219,6 +220,33 @@ int handle_powerpc_dcr_write(int vcpu, u
 return 0; /* XXX ignore failed DCR ops */
 }
 
+int mmukvm_get_physical_address(CPUState *env, mmu_ctx_t *ctx,
+target_ulong eaddr, int rw, int access_type)
+{
+struct kvm_translation tr;
+uint64_t pid;
+uint64_t as;
+int r;
+
+pid = env->spr[SPR_BOOKE_PID];
+
+if (access_type == ACCESS_CODE)
+as = env->msr & msr_ir;
+else
+as = env->msr & msr_dr;
+
+tr.linear_address = as << 40 | pid << 32 | eaddr;
+r = kvm_translate(kvm_context, env->cpu_index, &tr);
+if (r == -1)
+return r;
+
+if (!tr.valid)
+return -EFAULT;
+
+ctx->raddr = tr.physical_address;
+return 0;
+}
+
 void kvm_arch_cpu_reset(CPUState *env)
 {
 }
diff --git a/qemu/target-ppc/cpu.h b/qemu/target-ppc/cpu.h
--- a/qemu/target-ppc/cpu.h
+++ b/qemu/target-ppc/cpu.h
@@ -98,6 +98,8 @@ enum powerpc_mmu_t {
 POWERPC_MMU_BOOKE_FSL  = 0x0009,
 /* PowerPC 601 MMU model (specific BATs format)*/
 POWERPC_MMU_601= 0x000A,
+/* KVM managing the MMU state  */
+POWERPC_MMU_KVM= 0x000B,
 #if defined(TARGET_PPC64)
 #define POWERPC_MMU_64   0x0001
 /* 64 bits PowerPC MMU */
diff --git a/qemu/target-ppc/helper.c b/qemu/target-ppc/helper.c
--- a/qemu/target-ppc/helper.c
+++ b/qemu/target-ppc/helper.c
@@ -1429,6 +1429,10 @@ int get_physical_address (CPUState *env,
 fprintf(logfile, "%s\n", __func__);
 }
 #endif
+
+if (env->mmu_model == POWERPC_MMU_KVM)
+return mmukvm_get_physical_address(env, ctx, eaddr, rw, access_type);
+
 if ((access_type == ACCESS_CODE && msr_ir == 0) ||
 (access_type != ACCESS_CODE && msr_dr == 0)) {
 /* No address translation */
diff --git a/qemu/target-ppc/translate_init.c b/qemu/target-ppc/translate_init.c
--- a/qemu/target-ppc/translate_init.c
+++ b/qemu/target-ppc/translate_init.c
@@ -9273,6 +9273,11 @@ int cpu_ppc_register_internal (CPUPPCSta
 case POWERPC_MMU_601:
 mmu_model = "PowerPC 601";
 break;
+#ifdef KVM
+case POWERPC_MMU_KVM:
+mmu_model = "PowerPC KVM";
+break;
+#endif
 #if defined (TARGET_PPC64)
 case POWERPC_MMU_64B:
 mmu_model = "PowerPC 64";
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-inf

Re: [PATCH] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

2008-12-11 Thread Christian Ehrhardt

This is v2 as version one had a type in it occured when splitting patches.
Mercurial somehow lost my changes to the patch description explaining 
that, but the patch is right this way.


Christian Ehrhardt wrote:

# HG changeset patch
# User Christian Ehrhardt <[EMAIL PROTECTED]>
# Date 1228999833 -3600
# Node ID dc1466c9077ab162f4637fffee1869f26be02299
# Parent  4c07fe2a56c7653a9113e05bb08c2de9aec210ce
[PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

From: Hollis Blanchard <[EMAIL PROTECTED]>

Add basic KVM PowerPC support to qemu's gdbstub introducing a kvm ppc style
mmu implementation that uses the kvm_translate ioctl.
This also requires to save the kvm registers prior to the 'm' gdb operations.

Signed-off-by: Hollis Blanchard <[EMAIL PROTECTED]>
Signed-off-by: Christian Ehrhardt <[EMAIL PROTECTED]>
---

[diffstat]
 gdbstub.c   |2 ++
 hw/ppc440_bamboo.c  |1 +
 qemu-kvm-powerpc.c  |   28 
 target-ppc/cpu.h|2 ++
 target-ppc/helper.c |4 
 target-ppc/translate_init.c |5 +
 6 files changed, 42 insertions(+)

[diff]

diff --git a/qemu/gdbstub.c b/qemu/gdbstub.c
--- a/qemu/gdbstub.c
+++ b/qemu/gdbstub.c
@@ -1374,6 +1374,7 @@ static int gdb_handle_packet(GDBState *s
 if (*p == ',')
 p++;
 len = strtoull(p, NULL, 16);
+kvm_save_registers(s->g_cpu);
 if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 0) != 0) {
 put_packet (s, "E14");
 } else {
@@ -1389,6 +1390,7 @@ static int gdb_handle_packet(GDBState *s
 if (*p == ':')
 p++;
 hextomem(mem_buf, p, len);
+kvm_save_registers(s->g_cpu);
 if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 1) != 0)
 put_packet(s, "E14");
 else
diff --git a/qemu/hw/ppc440_bamboo.c b/qemu/hw/ppc440_bamboo.c
--- a/qemu/hw/ppc440_bamboo.c
+++ b/qemu/hw/ppc440_bamboo.c
@@ -99,6 +99,7 @@ void bamboo_init(ram_addr_t ram_size, in
fprintf(stderr, "Unable to initialize CPU!\n");
exit(1);
}
+   env->mmu_model = POWERPC_MMU_KVM;

/* call init */
printf("Calling function ppc440_init\n");
diff --git a/qemu/qemu-kvm-powerpc.c b/qemu/qemu-kvm-powerpc.c
--- a/qemu/qemu-kvm-powerpc.c
+++ b/qemu/qemu-kvm-powerpc.c
@@ -102,6 +102,7 @@ void kvm_arch_save_regs(CPUState *env)

 env->spr[SPR_SRR0] = regs.srr0;
 env->spr[SPR_SRR1] = regs.srr1;
+env->spr[SPR_BOOKE_PID] = regs.pid;

 env->spr[SPR_SPRG0] = regs.sprg0;
 env->spr[SPR_SPRG1] = regs.sprg1;
@@ -219,6 +220,33 @@ int handle_powerpc_dcr_write(int vcpu, u
 return 0; /* XXX ignore failed DCR ops */
 }

+int mmukvm_get_physical_address(CPUState *env, mmu_ctx_t *ctx,
+target_ulong eaddr, int rw, int access_type)
+{
+struct kvm_translation tr;
+uint64_t pid;
+uint64_t as;
+int r;
+
+pid = env->spr[SPR_BOOKE_PID];
+
+if (access_type == ACCESS_CODE)
+as = env->msr & msr_ir;
+else
+as = env->msr & msr_dr;
+
+tr.linear_address = as << 40 | pid << 32 | eaddr;
+r = kvm_translate(kvm_context, env->cpu_index, &tr);
+if (r == -1)
+return r;
+
+if (!tr.valid)
+return -EFAULT;
+
+ctx->raddr = tr.physical_address;
+return 0;
+}
+
 void kvm_arch_cpu_reset(CPUState *env)
 {
 }
diff --git a/qemu/target-ppc/cpu.h b/qemu/target-ppc/cpu.h
--- a/qemu/target-ppc/cpu.h
+++ b/qemu/target-ppc/cpu.h
@@ -98,6 +98,8 @@ enum powerpc_mmu_t {
 POWERPC_MMU_BOOKE_FSL  = 0x0009,
 /* PowerPC 601 MMU model (specific BATs format)*/
 POWERPC_MMU_601= 0x000A,
+/* KVM managing the MMU state  */
+POWERPC_MMU_KVM= 0x000B,
 #if defined(TARGET_PPC64)
 #define POWERPC_MMU_64   0x0001
 /* 64 bits PowerPC MMU */
diff --git a/qemu/target-ppc/helper.c b/qemu/target-ppc/helper.c
--- a/qemu/target-ppc/helper.c
+++ b/qemu/target-ppc/helper.c
@@ -1429,6 +1429,10 @@ int get_physical_address (CPUState *env,
 fprintf(logfile, "%s\n", __func__);
 }
 #endif
+
+if (env->mmu_model == POWERPC_MMU_KVM)
+return mmukvm_get_physical_address(env, ctx, eaddr, rw, access_type);
+
 if ((access_type == ACCESS_CODE && msr_ir == 0) ||
 (access_type != ACCESS_CODE && msr_dr == 0)) {
 /* No address translation */
diff --git a/qemu/target-ppc/translate_init.c b/qemu/target-ppc/translate_init.c
--- a/qemu/target-ppc/translate_init.c
+++ b/qemu/target-ppc/translate_init.c
@@ -9273,6 +9273,11 @@ int cpu_ppc_register_internal (CPUPPCSta
 case POWERPC_MMU_601:
 mmu_model = "PowerPC 601";
 break;
+#ifdef KVM
+case POWERPC_MMU_KVM:
+mmu_model = "PowerPC KVM";
+break;
+#endif
 #if defined (TARGET_PPC64)
 case POWERPC_MMU_64B:

[PATCH 3 of 3] [PATCH] kvm-userspace: fix gdbstub kvm integration

2008-12-11 Thread Christian Ehrhardt
# HG changeset patch
# User Christian Ehrhardt <[EMAIL PROTECTED]>
# Date 1228989958 -3600
# Node ID f80fb35de91fe69dae889c70948c9a53212ee444
# Parent  6f228c807ad0b239b7342d2974debfc66418d784
[PATCH] kvm-userspace: fix gdbstub kvm integration

From: Christian Ehrhardt <[EMAIL PROTECTED]>

Some recent qemu upstream merges brought in a new concept to not use "env" as
current cpu in gdb_handle_packet anymore. But the kvm calls still do, this
leads to SIGDEV's as env is not initialized when calling the functions like
kvm_save_registers.

Insted there is now a gdbstate structure holding current cpu for
step/continue and "other" ops splitted.

This patch changes the kvm_save_registers calls to use the right CPUState
variable for the kvm calls in gdb_handle_packet.

Signed-off-by: Christian Ehrhardt <[EMAIL PROTECTED]>
---

[diffstat]
 gdbstub.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

[diff]

diff --git a/qemu/gdbstub.c b/qemu/gdbstub.c
--- a/qemu/gdbstub.c
+++ b/qemu/gdbstub.c
@@ -1348,7 +1348,7 @@ static int gdb_handle_packet(GDBState *s
 }
 break;
 case 'g':
-kvm_save_registers(env);
+kvm_save_registers(s->g_cpu);
 len = 0;
 for (addr = 0; addr < num_g_regs; addr++) {
 reg_size = gdb_read_register(s->g_cpu, mem_buf + len, addr);
@@ -1366,7 +1366,7 @@ static int gdb_handle_packet(GDBState *s
 len -= reg_size;
 registers += reg_size;
 }
-kvm_load_registers(env);
+kvm_load_registers(s->g_cpu);
 put_packet(s, "OK");
 break;
 case 'm':
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1 of 3] [PATCH] kvm-userspace: ppc: Add kvm_translate wrapper

2008-12-11 Thread Christian Ehrhardt
# HG changeset patch
# User Christian Ehrhardt <[EMAIL PROTECTED]>
# Date 1228924564 -3600
# Node ID 38846cef16e56c681da1ddc179e248972c8b2ff9
# Parent  705d874ff7a24484eaa15ed75a748c4e1a70c2ef
[PATCH] kvm-userspace: ppc: Add kvm_translate wrapper

From: Hollis Blanchard <[EMAIL PROTECTED]>

Add kvm_translate() wrapper used to get mmu translations from userspace.

Signed-off-by: Hollis Blanchard <[EMAIL PROTECTED]>
Signed-off-by: Christian Ehrhardt <[EMAIL PROTECTED]>
---

[diffstat]
 libkvm.c |5 +
 libkvm.h |2 ++
 2 files changed, 7 insertions(+)

[diff]

diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -987,6 +987,11 @@ int kvm_guest_debug(kvm_context_t kvm, i
return ioctl(kvm->vcpu_fd[vcpu], KVM_DEBUG_GUEST, dbg);
 }
 
+int kvm_translate(kvm_context_t kvm, int vcpu, struct kvm_translation *tr)
+{
+   return ioctl(kvm->vcpu_fd[vcpu], KVM_TRANSLATE, tr);
+}
+
 int kvm_set_signal_mask(kvm_context_t kvm, int vcpu, const sigset_t *sigset)
 {
struct kvm_signal_mask *sigmask;
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -639,6 +639,8 @@ int kvm_set_pit(kvm_context_t kvm, struc
 int kvm_set_pit(kvm_context_t kvm, struct kvm_pit_state *s);
 #endif
 
+int kvm_translate(kvm_context_t kvm, int vcpu, struct kvm_translation *tr);
+
 #endif
 
 #ifdef KVM_CAP_VAPIC
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2 of 3] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

2008-12-11 Thread Christian Ehrhardt
# HG changeset patch
# User Christian Ehrhardt <[EMAIL PROTECTED]>
# Date 1228989956 -3600
# Node ID 6f228c807ad0b239b7342d2974debfc66418d784
# Parent  38846cef16e56c681da1ddc179e248972c8b2ff9
[PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

From: Hollis Blanchard <[EMAIL PROTECTED]>

Add basic KVM PowerPC support to qemu's gdbstub introducing a kvm ppc style
mmu implementation that uses the kvm_translate ioctl.
This also requires to save the kvm registers prior to the 'm' gdb operations.

Signed-off-by: Hollis Blanchard <[EMAIL PROTECTED]>
Signed-off-by: Christian Ehrhardt <[EMAIL PROTECTED]>
---

[diffstat]
 gdbstub.c   |2 ++
 hw/ppc440_bamboo.c  |1 +
 qemu-kvm-powerpc.c  |   28 
 target-ppc/cpu.h|2 ++
 target-ppc/helper.c |4 
 target-ppc/translate_init.c |5 +
 6 files changed, 42 insertions(+)

[diff]

diff --git a/qemu/gdbstub.c b/qemu/gdbstub.c
--- a/qemu/gdbstub.c
+++ b/qemu/gdbstub.c
@@ -1374,6 +1374,7 @@ static int gdb_handle_packet(GDBState *s
 if (*p == ',')
 p++;
 len = strtoull(p, NULL, 16);
+kvm_save_registers(s->g_cpu);
 if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 0) != 0) {
 put_packet (s, "E14");
 } else {
@@ -1389,6 +1390,7 @@ static int gdb_handle_packet(GDBState *s
 if (*p == ':')
 p++;
 hextomem(mem_buf, p, len);
+kvm_save_registers(s->gcpu);
 if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 1) != 0)
 put_packet(s, "E14");
 else
diff --git a/qemu/hw/ppc440_bamboo.c b/qemu/hw/ppc440_bamboo.c
--- a/qemu/hw/ppc440_bamboo.c
+++ b/qemu/hw/ppc440_bamboo.c
@@ -99,6 +99,7 @@ void bamboo_init(ram_addr_t ram_size, in
fprintf(stderr, "Unable to initialize CPU!\n");
exit(1);
}
+   env->mmu_model = POWERPC_MMU_KVM;
 
/* call init */
printf("Calling function ppc440_init\n");
diff --git a/qemu/qemu-kvm-powerpc.c b/qemu/qemu-kvm-powerpc.c
--- a/qemu/qemu-kvm-powerpc.c
+++ b/qemu/qemu-kvm-powerpc.c
@@ -102,6 +102,7 @@ void kvm_arch_save_regs(CPUState *env)
 
 env->spr[SPR_SRR0] = regs.srr0;
 env->spr[SPR_SRR1] = regs.srr1;
+env->spr[SPR_BOOKE_PID] = regs.pid;
 
 env->spr[SPR_SPRG0] = regs.sprg0;
 env->spr[SPR_SPRG1] = regs.sprg1;
@@ -219,6 +220,33 @@ int handle_powerpc_dcr_write(int vcpu, u
 return 0; /* XXX ignore failed DCR ops */
 }
 
+int mmukvm_get_physical_address(CPUState *env, mmu_ctx_t *ctx,
+target_ulong eaddr, int rw, int access_type)
+{
+struct kvm_translation tr;
+uint64_t pid;
+uint64_t as;
+int r;
+
+pid = env->spr[SPR_BOOKE_PID];
+
+if (access_type == ACCESS_CODE)
+as = env->msr & msr_ir;
+else
+as = env->msr & msr_dr;
+
+tr.linear_address = as << 40 | pid << 32 | eaddr;
+r = kvm_translate(kvm_context, env->cpu_index, &tr);
+if (r == -1)
+return r;
+
+if (!tr.valid)
+return -EFAULT;
+
+ctx->raddr = tr.physical_address;
+return 0;
+}
+
 void kvm_arch_cpu_reset(CPUState *env)
 {
 }
diff --git a/qemu/target-ppc/cpu.h b/qemu/target-ppc/cpu.h
--- a/qemu/target-ppc/cpu.h
+++ b/qemu/target-ppc/cpu.h
@@ -98,6 +98,8 @@ enum powerpc_mmu_t {
 POWERPC_MMU_BOOKE_FSL  = 0x0009,
 /* PowerPC 601 MMU model (specific BATs format)*/
 POWERPC_MMU_601= 0x000A,
+/* KVM managing the MMU state  */
+POWERPC_MMU_KVM= 0x000B,
 #if defined(TARGET_PPC64)
 #define POWERPC_MMU_64   0x0001
 /* 64 bits PowerPC MMU */
diff --git a/qemu/target-ppc/helper.c b/qemu/target-ppc/helper.c
--- a/qemu/target-ppc/helper.c
+++ b/qemu/target-ppc/helper.c
@@ -1429,6 +1429,10 @@ int get_physical_address (CPUState *env,
 fprintf(logfile, "%s\n", __func__);
 }
 #endif
+
+if (env->mmu_model == POWERPC_MMU_KVM)
+return mmukvm_get_physical_address(env, ctx, eaddr, rw, access_type);
+
 if ((access_type == ACCESS_CODE && msr_ir == 0) ||
 (access_type != ACCESS_CODE && msr_dr == 0)) {
 /* No address translation */
diff --git a/qemu/target-ppc/translate_init.c b/qemu/target-ppc/translate_init.c
--- a/qemu/target-ppc/translate_init.c
+++ b/qemu/target-ppc/translate_init.c
@@ -9273,6 +9273,11 @@ int cpu_ppc_register_internal (CPUPPCSta
 case POWERPC_MMU_601:
 mmu_model = "PowerPC 601";
 break;
+#ifdef KVM
+case POWERPC_MMU_KVM:
+mmu_model = "PowerPC KVM";
+break;
+#endif
 #if defined (TARGET_PPC64)
 case POWERPC_MMU_64B:
 mmu_model = "PowerPC 64";
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info

[PATCH 0 of 3] update gdbstub support

2008-12-11 Thread Christian Ehrhardt
This patch series updates the gdbstub support for kvm.
Patch 1&2 introduce basic powerpc support while patch 3 fixes gdbstub generic
code that was broken in a qemu merge.
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/11] Add extra E500 exceptions

2008-12-11 Thread Liu Yu
Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/include/asm/kvm_asm.h  |7 ++-
 arch/powerpc/include/asm/kvm_host.h |2 +-
 arch/powerpc/kvm/booke.c|   18 ++
 arch/powerpc/kvm/booke.h|   30 ++
 arch/powerpc/kvm/booke_interrupts.S |3 +++
 arch/powerpc/kvm/e500.c |   20 +++-
 arch/powerpc/kvm/e500_emulate.c |   24 
 7 files changed, 89 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 2197764..56bfae5 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -42,7 +42,12 @@
 #define BOOKE_INTERRUPT_DTLB_MISS 13
 #define BOOKE_INTERRUPT_ITLB_MISS 14
 #define BOOKE_INTERRUPT_DEBUG 15
-#define BOOKE_MAX_INTERRUPT 15
+
+/* E500 */
+#define BOOKE_INTERRUPT_SPE_UNAVAIL 32
+#define BOOKE_INTERRUPT_SPE_FP_DATA 33
+#define BOOKE_INTERRUPT_SPE_FP_ROUND 34
+#define BOOKE_INTERRUPT_PERFORMANCE_MONITOR 35
 
 #define RESUME_FLAG_NV  (1<<0)  /* Reload guest nonvolatile state? */
 #define RESUME_FLAG_HOST(1<<1)  /* Resume host? */
diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 63962fa..5e22681 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -150,7 +150,7 @@ struct kvm_vcpu_arch {
u32 tbu;
u32 tcr;
u32 tsr;
-   u32 ivor[16];
+   u32 ivor[64];
ulong ivpr;
u32 pir;
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index f192fbe..642e420 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -118,6 +118,9 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
case BOOKE_IRQPRIO_DATA_STORAGE:
case BOOKE_IRQPRIO_INST_STORAGE:
case BOOKE_IRQPRIO_FP_UNAVAIL:
+   case BOOKE_IRQPRIO_SPE_UNAVAIL:
+   case BOOKE_IRQPRIO_SPE_FP_DATA:
+   case BOOKE_IRQPRIO_SPE_FP_ROUND:
case BOOKE_IRQPRIO_AP_UNAVAIL:
case BOOKE_IRQPRIO_ALIGNMENT:
allowed = 1;
@@ -261,6 +264,21 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
r = RESUME_GUEST;
break;
 
+   case BOOKE_INTERRUPT_SPE_UNAVAIL:
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_UNAVAIL);
+   r = RESUME_GUEST;
+   break;
+
+   case BOOKE_INTERRUPT_SPE_FP_DATA:
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA);
+   r = RESUME_GUEST;
+   break;
+
+   case BOOKE_INTERRUPT_SPE_FP_ROUND:
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND);
+   r = RESUME_GUEST;
+   break;
+
case BOOKE_INTERRUPT_DATA_STORAGE:
vcpu->arch.dear = vcpu->arch.fault_dear;
vcpu->arch.esr = vcpu->arch.fault_esr;
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index 52c0b1a..700013a 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -30,18 +30,24 @@
 #define BOOKE_IRQPRIO_ALIGNMENT 2
 #define BOOKE_IRQPRIO_PROGRAM 3
 #define BOOKE_IRQPRIO_FP_UNAVAIL 4
-#define BOOKE_IRQPRIO_SYSCALL 5
-#define BOOKE_IRQPRIO_AP_UNAVAIL 6
-#define BOOKE_IRQPRIO_DTLB_MISS 7
-#define BOOKE_IRQPRIO_ITLB_MISS 8
-#define BOOKE_IRQPRIO_MACHINE_CHECK 9
-#define BOOKE_IRQPRIO_DEBUG 10
-#define BOOKE_IRQPRIO_CRITICAL 11
-#define BOOKE_IRQPRIO_WATCHDOG 12
-#define BOOKE_IRQPRIO_EXTERNAL 13
-#define BOOKE_IRQPRIO_FIT 14
-#define BOOKE_IRQPRIO_DECREMENTER 15
-#define BOOKE_IRQPRIO_MAX 15
+#define BOOKE_IRQPRIO_SPE_UNAVAIL 5
+#define BOOKE_IRQPRIO_SPE_FP_DATA 6
+#define BOOKE_IRQPRIO_SPE_FP_ROUND 7
+#define BOOKE_IRQPRIO_SYSCALL 8
+#define BOOKE_IRQPRIO_AP_UNAVAIL 9
+#define BOOKE_IRQPRIO_DTLB_MISS 10
+#define BOOKE_IRQPRIO_ITLB_MISS 11
+#define BOOKE_IRQPRIO_MACHINE_CHECK 12
+#define BOOKE_IRQPRIO_DEBUG 13
+#define BOOKE_IRQPRIO_CRITICAL 14
+#define BOOKE_IRQPRIO_WATCHDOG 15
+#define BOOKE_IRQPRIO_EXTERNAL 16
+#define BOOKE_IRQPRIO_FIT 17
+#define BOOKE_IRQPRIO_DECREMENTER 18
+#define BOOKE_IRQPRIO_PERFORMANCE_MONITOR 19
+#define BOOKE_IRQPRIO_MAX 19
+
+extern unsigned long kvmppc_booke_handlers;
 
 /* Helper function for "full" MSR writes. No need to call this if only EE is
  * changing. */
diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index 4679ec2..d0c6f84 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -86,6 +86,9 @@ KVM_HANDLER BOOKE_INTERRUPT_WATCHDOG
 KVM_HANDLER BOOKE_INTERRUPT_DTLB_MISS
 KVM_HANDLER BOOKE_INTERRUPT_ITLB_MISS
 KVM_HANDLER BOOKE_INTERRUPT_DEBUG
+KVM_HANDLER BOOKE_INTERRUPT_SPE_UNAVAIL
+KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_DATA
+KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_ROUND
 
 _GLOBAL(kvmppc_handler_len)
.long kvmppc_handler_1 - kvmppc_handler_0
diff

[PATCH 10/11] Fix IRQ priority search bug

2008-12-11 Thread Liu Yu
Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/kvm/booke.c |2 +-
 arch/powerpc/kvm/booke.h |1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 933c406..f192fbe 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -163,7 +163,7 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
unsigned int priority;
 
priority = __ffs(*pending);
-   while (priority <= BOOKE_MAX_INTERRUPT) {
+   while (priority <= BOOKE_IRQPRIO_MAX) {
if (kvmppc_booke_irqprio_deliver(vcpu, priority))
break;
 
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index cf7c94c..52c0b1a 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -41,6 +41,7 @@
 #define BOOKE_IRQPRIO_EXTERNAL 13
 #define BOOKE_IRQPRIO_FIT 14
 #define BOOKE_IRQPRIO_DECREMENTER 15
+#define BOOKE_IRQPRIO_MAX 15
 
 /* Helper function for "full" MSR writes. No need to call this if only EE is
  * changing. */
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/11] Add E500 build support

2008-12-11 Thread Liu Yu
Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/kvm/Kconfig  |   13 +
 arch/powerpc/kvm/Makefile |8 
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 6dbdc48..1465705 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -43,6 +43,19 @@ config KVM_EXIT_TIMING
 
  If unsure, say N.
 
+config KVM_E500
+   bool "KVM support for PowerPC E500 processors"
+   depends on EXPERIMENTAL && E500
+   select KVM
+   ---help---
+ Support running unmodified E500 guest kernels in virtual machines on
+ E500 host processors.
+
+ This module provides access to the hardware capabilities through
+ a character device node named /dev/kvm.
+
+ If unsure, say N.
+
 config KVM_TRACE
bool "KVM trace support"
depends on KVM && MARKERS && SYSFS
diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile
index df7ba59..acd5cef 100644
--- a/arch/powerpc/kvm/Makefile
+++ b/arch/powerpc/kvm/Makefile
@@ -21,3 +21,11 @@ kvm-440-objs := \
44x_tlb.o \
44x_emulate.o
 obj-$(CONFIG_KVM_440) += kvm-440.o
+
+kvm-e500-objs := \
+   booke.o \
+   booke_interrupts.o \
+   e500.o \
+   e500_tlb.o \
+   e500_emulate.o
+obj-$(CONFIG_KVM_E500) += kvm-e500.o
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/11] Add kvmppc_mmu_dtlb/itlb_miss for booke

2008-12-11 Thread Liu Yu
E500 needs to update some mmu registers, when itlb or dtlb miss happens.

Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/include/asm/kvm_ppc.h |2 ++
 arch/powerpc/kvm/44x_tlb.c |8 
 arch/powerpc/kvm/booke.c   |2 ++
 3 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index f4b041b..82547c8 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -63,6 +63,8 @@ extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t 
eaddr);
 extern int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
 extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index,
   gva_t eaddr);
+extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu);
+extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu);
 
 extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm,
 unsigned int id);
diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c
index e67b731..4a16f47 100644
--- a/arch/powerpc/kvm/44x_tlb.c
+++ b/arch/powerpc/kvm/44x_tlb.c
@@ -232,6 +232,14 @@ int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t 
eaddr)
return kvmppc_44x_tlb_index(vcpu, eaddr, vcpu->arch.pid, as);
 }
 
+void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu)
+{
+}
+
+void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu)
+{
+}
+
 static void kvmppc_44x_shadow_release(struct kvmppc_vcpu_44x *vcpu_44x,
   unsigned int stlb_index)
 {
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index a73b395..933c406 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -295,6 +295,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
kvmppc_booke_queue_irqprio(vcpu, 
BOOKE_IRQPRIO_DTLB_MISS);
vcpu->arch.dear = vcpu->arch.fault_dear;
vcpu->arch.esr = vcpu->arch.fault_esr;
+   kvmppc_mmu_dtlb_miss(vcpu);
kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS);
r = RESUME_GUEST;
break;
@@ -337,6 +338,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
if (gtlb_index < 0) {
/* The guest didn't have a mapping for it. */
kvmppc_booke_queue_irqprio(vcpu, 
BOOKE_IRQPRIO_ITLB_MISS);
+   kvmppc_mmu_itlb_miss(vcpu);
kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS);
break;
}
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/11] E500 TLB emulation

2008-12-11 Thread Liu Yu
Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/kvm/e500_tlb.c |  748 +++
 arch/powerpc/kvm/e500_tlb.h |  177 ++
 2 files changed, 925 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/kvm/e500_tlb.c
 create mode 100644 arch/powerpc/kvm/e500_tlb.h

diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
new file mode 100644
index 000..a5858e6
--- /dev/null
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -0,0 +1,748 @@
+/*
+ * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Yu Liu, [EMAIL PROTECTED], Aug, 2008
+ *
+ * Description:
+ * This file is based on arch/powerpc/kvm/44x_tlb.c,
+ * by Hollis Blanchard <[EMAIL PROTECTED]>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "e500_tlb.h"
+
+#define to_htlb1_esel(esel) (tlb1_entry_num - (esel) - 1)
+
+static unsigned int tlb1_entry_num;
+
+void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
+{
+   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
+   struct tlbe *tlbe;
+   int i, tlbsel;
+
+   printk("| %8s | %8s | %8s | %8s | %8s |\n",
+   "nr", "mas1", "mas2", "mas3", "mas7");
+
+   for (tlbsel = 0; tlbsel < 2; tlbsel++) {
+   printk("Guest TLB%d:\n", tlbsel);
+   for (i = 0; i < vcpu_e500->guest_tlb_size[tlbsel]; i++) {
+   tlbe = &vcpu_e500->guest_tlb[tlbsel][i];
+   if (tlbe->mas1 & MAS1_VALID)
+   printk(" G[%d][%3d] |  %08X | %08X | %08X | 
%08X |\n",
+   tlbsel, i, tlbe->mas1, tlbe->mas2,
+   tlbe->mas3, tlbe->mas7);
+   }
+   }
+
+   for (tlbsel = 0; tlbsel < 2; tlbsel++) {
+   printk("Shadow TLB%d:\n", tlbsel);
+   for (i = 0; i < vcpu_e500->shadow_tlb_size[tlbsel]; i++) {
+   tlbe = &vcpu_e500->shadow_tlb[tlbsel][i];
+   if (tlbe->mas1 & MAS1_VALID)
+   printk(" S[%d][%3d] |  %08X | %08X | %08X | 
%08X |\n",
+   tlbsel, i, tlbe->mas1, tlbe->mas2,
+   tlbe->mas3, tlbe->mas7);
+   }
+   }
+}
+
+static inline unsigned int tlb0_get_next_victim(
+   struct kvmppc_vcpu_e500 *vcpu_e500)
+{
+   unsigned int victim;
+
+   victim = vcpu_e500->guest_tlb_nv[0]++;
+   if (unlikely(vcpu_e500->guest_tlb_nv[0] >= KVM_E500_TLB0_WAY_NUM))
+   vcpu_e500->guest_tlb_nv[0] = 0;
+
+   return victim;
+}
+
+static inline unsigned int tlb1_max_shadow_size(void)
+{
+   return tlb1_entry_num - tlbcam_index;
+}
+
+static inline u32 e500_shadow_mas3_attrib(u32 mas3, int usermode)
+{
+   /* Mask off reserved bits. */
+   mas3 &= MAS3_ATTRIB_MASK;
+
+   if (!usermode) {
+   /* Guest is in supervisor mode,
+* so we need to translate guest
+* supervisor permissions into user permissions. */
+   mas3 &= ~E500_TLB_USER_PERM_MASK;
+   mas3 |= (mas3 & E500_TLB_SUPER_PERM_MASK) << 1;
+   }
+
+   return mas3 | E500_TLB_SUPER_PERM_MASK;
+}
+
+static inline u32 e500_shadow_mas2_attrib(u32 mas2, int usermode)
+{
+   return mas2 & MAS2_ATTRIB_MASK;
+}
+
+/*
+ * writing shadow tlb entry to host TLB
+ */
+static inline void __write_host_tlbe(struct tlbe *stlbe)
+{
+   mtspr(SPRN_MAS1, stlbe->mas1);
+   mtspr(SPRN_MAS2, stlbe->mas2);
+   mtspr(SPRN_MAS3, stlbe->mas3);
+   mtspr(SPRN_MAS7, stlbe->mas7);
+   __asm__ __volatile__ ("tlbwe\n" : : );
+}
+
+static inline void write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500,
+   int tlbsel, int esel)
+{
+   struct tlbe *stlbe = &vcpu_e500->shadow_tlb[tlbsel][esel];
+
+   local_irq_disable();
+   if (tlbsel == 0) {
+   __write_host_tlbe(stlbe);
+   } else {
+   unsigned register mas0;
+
+   mas0 = mfspr(SPRN_MAS0);
+
+   mtspr(SPRN_MAS0, MAS0_TLBSEL(1) | 
MAS0_ESEL(to_htlb1_esel(esel)));
+   __write_host_tlbe(stlbe);
+
+   mtspr(SPRN_MAS0, mas0);
+   }
+   local_irq_enable();
+}
+
+void kvmppc_e500_tlb_load(struct kvm_vcpu *vcpu, int cpu)
+{
+   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
+   int i;
+   unsigned register mas0;
+   /* Mark every guest entry in the shadow TLB entry modified, so that they
+   * will all be reloaded on the next vcpu run (instead of being
+   * demand-faulted). */
+   local_irq_disable();
+   mas0 = mfspr(SPRN_MAS0);
+   for (i = 0; i < vcpu_e500->shadow_tlb_size[1]; i++)

[PATCH 06/11] E500 instructions emulation

2008-12-11 Thread Liu Yu
Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/kvm/e500_emulate.c |  359 +++
 1 files changed, 359 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/kvm/e500_emulate.c

diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
new file mode 100644
index 000..defe1d9
--- /dev/null
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -0,0 +1,359 @@
+/*
+ * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Yu Liu, <[EMAIL PROTECTED]>
+ *
+ * Description:
+ * This file is derived from arch/powerpc/kvm/44x_emulate.c,
+ * by Hollis Blanchard <[EMAIL PROTECTED]>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+
+#include "booke.h"
+#include "e500_tlb.h"
+
+#define OP_RFI  19
+
+#define XOP_RFI50
+#define XOP_MFMSR  83
+#define XOP_WRTEE  131
+#define XOP_MTMSR  146
+#define XOP_WRTEEI 163
+#define XOP_TLBIVAX786
+#define XOP_TLBSX  914
+#define XOP_TLBRE  946
+#define XOP_TLBWE  978
+
+static void kvmppc_emul_rfi(struct kvm_vcpu *vcpu)
+{
+   vcpu->arch.pc = vcpu->arch.srr0;
+   kvmppc_set_msr(vcpu, vcpu->arch.srr1);
+}
+
+int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
+   unsigned int inst, int *advance)
+{
+   int emulated = EMULATE_DONE;
+   int ra;
+   int rb;
+   int rs;
+   int rt;
+
+   switch (get_op(inst)) {
+
+   case OP_RFI:
+   switch (get_xop(inst)) {
+   case XOP_RFI:
+   kvmppc_emul_rfi(vcpu);
+   *advance = 0;
+   break;
+
+   default:
+   emulated = EMULATE_FAIL;
+   break;
+   }
+   break;
+
+   case 31:
+   switch (get_xop(inst)) {
+
+   case XOP_MFMSR:
+   rt = get_rt(inst);
+   vcpu->arch.gpr[rt] = vcpu->arch.msr;
+   break;
+
+   case XOP_MTMSR:
+   rs = get_rs(inst);
+   kvmppc_set_msr(vcpu, vcpu->arch.gpr[rs]);
+   break;
+
+   case XOP_WRTEE:
+   rs = get_rs(inst);
+   vcpu->arch.msr = (vcpu->arch.msr & ~MSR_EE)
+   | (vcpu->arch.gpr[rs] & MSR_EE);
+   break;
+
+   case XOP_WRTEEI:
+   vcpu->arch.msr = (vcpu->arch.msr & ~MSR_EE)
+   | (inst & MSR_EE);
+   break;
+
+   case XOP_TLBRE:
+   emulated = kvmppc_e500_emul_tlbre(vcpu);
+   break;
+
+   case XOP_TLBWE:
+   emulated = kvmppc_e500_emul_tlbwe(vcpu);
+   break;
+
+   case XOP_TLBSX:
+   rb = get_rb(inst);
+   emulated = kvmppc_e500_emul_tlbsx(vcpu,rb);
+   break;
+
+   case XOP_TLBIVAX:
+   ra = get_ra(inst);
+   rb = get_rb(inst);
+   emulated = kvmppc_e500_emul_tlbivax(vcpu, ra, rb);
+   break;
+
+   default:
+   emulated = EMULATE_FAIL;
+   }
+
+   break;
+
+   default:
+   emulated = EMULATE_FAIL;
+   }
+
+   return emulated;
+}
+
+int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
+{
+   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
+
+   switch (sprn) {
+   /* E500 */
+   case SPRN_PID:
+   vcpu_e500->pid[0] = vcpu->arch.pid = vcpu->arch.gpr[rs]; break;
+   case SPRN_PID1:
+   vcpu_e500->pid[1] = vcpu->arch.gpr[rs]; break;
+   case SPRN_PID2:
+   vcpu_e500->pid[2] = vcpu->arch.gpr[rs]; break;
+   case SPRN_MAS0:
+   vcpu_e500->mas0 = vcpu->arch.gpr[rs]; break;
+   case SPRN_MAS1:
+   vcpu_e500->mas1 = vcpu->arch.gpr[rs]; break;
+   case SPRN_MAS2:
+   vcpu_e500->mas2 = vcpu->arch.gpr[rs]; break;
+   case SPRN_MAS3:
+   vcpu_e500->mas3 = vcpu->arch.gpr[rs]; break;
+   case SPRN_MAS4:
+   vcpu_e500->mas4 = vcpu->arch.gpr[rs]; break;
+   case SPRN_MAS6:
+   vcpu_e500->mas6 = vcpu->arch.gpr[rs]; break;
+   case SPRN_MAS7:
+   vcpu_e500->mas7 = vcpu->arch.gpr[rs]; break;
+   case SPRN_L1CSR1:
+   vcpu_e500->l1csr1 = vcpu->arch.gpr[rs]; break;
+   case SPRN_HID0:
+   vcpu_e500->hid0 = vcpu->arch.gpr[rs]; break;
+   case SPRN_HID1:
+  

[PATCH 05/11] E500 core-specific code

2008-12-11 Thread Liu Yu
Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/include/asm/kvm_e500.h |   67 +++
 arch/powerpc/kvm/e500.c |  151 +++
 2 files changed, 218 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kvm_e500.h
 create mode 100644 arch/powerpc/kvm/e500.c

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
new file mode 100644
index 000..9d497ce
--- /dev/null
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Yu Liu, <[EMAIL PROTECTED]>
+ *
+ * Description:
+ * This file is derived from arch/powerpc/include/asm/kvm_44x.h,
+ * by Hollis Blanchard <[EMAIL PROTECTED]>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ASM_KVM_E500_H__
+#define __ASM_KVM_E500_H__
+
+#include 
+
+#define BOOKE_INTERRUPT_SIZE 36
+
+#define E500_PID_NUM   3
+#define E500_TLB_NUM   2
+
+struct tlbe{
+   u32 mas1;
+   u32 mas2;
+   u32 mas3;
+   u32 mas7;
+};
+
+struct kvmppc_vcpu_e500 {
+   /* Unmodified copy of the guest's TLB. */
+   struct tlbe *guest_tlb[E500_TLB_NUM];
+   /* TLB that's actually used when the guest is running. */
+   struct tlbe *shadow_tlb[E500_TLB_NUM];
+   /* Pages which are referenced in the shadow TLB. */
+   struct page **shadow_pages[E500_TLB_NUM];
+
+   unsigned int guest_tlb_size[E500_TLB_NUM];
+   unsigned int shadow_tlb_size[E500_TLB_NUM];
+   unsigned int guest_tlb_nv[E500_TLB_NUM];
+
+   u32 host_pid[E500_PID_NUM];
+   u32 pid[E500_PID_NUM];
+
+   u32 mas0;
+   u32 mas1;
+   u32 mas2;
+   u32 mas3;
+   u32 mas4;
+   u32 mas5;
+   u32 mas6;
+   u32 mas7;
+   u32 l1csr1;
+   u32 hid0;
+   u32 hid1;
+
+   struct kvm_vcpu vcpu;
+};
+
+static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)
+{
+   return container_of(vcpu, struct kvmppc_vcpu_e500, vcpu);
+}
+
+#endif /* __ASM_KVM_E500_H__ */
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
new file mode 100644
index 000..b1950ff
--- /dev/null
+++ b/arch/powerpc/kvm/e500.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Yu Liu, <[EMAIL PROTECTED]>
+ *
+ * Description:
+ * This file is derived from arch/powerpc/kvm/44x.c,
+ * by Hollis Blanchard <[EMAIL PROTECTED]>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "e500_tlb.h"
+
+void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu)
+{
+}
+
+void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
+{
+}
+
+void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
+{
+   kvmppc_e500_tlb_load(vcpu, cpu);
+}
+
+void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
+{
+   kvmppc_e500_tlb_put(vcpu);
+}
+
+int kvmppc_core_check_processor_compat(void)
+{
+   int r;
+
+   if (strcmp(cur_cpu_spec->cpu_name, "e500v2") == 0)
+   r = 0;
+   else
+   r = -ENOTSUPP;
+
+   return r;
+}
+
+int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
+{
+   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
+
+   kvmppc_e500_tlb_setup(vcpu_e500);
+
+   /* Use the same core vertion as host's */
+   vcpu->arch.pvr = mfspr(SPRN_PVR);
+
+   return 0;
+}
+
+/* 'linear_address' is actually an encoding of AS|PID|EADDR . */
+int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
+   struct kvm_translation *tr)
+{
+   int index;
+   gva_t eaddr;
+   u8 pid;
+   u8 as;
+
+   eaddr = tr->linear_address;
+   pid = (tr->linear_address >> 32) & 0xff;
+   as = (tr->linear_address >> 40) & 0x1;
+
+   index = kvmppc_e500_tlb_search(vcpu, eaddr, as);
+   if (index < 0) {
+   tr->valid = 0;
+   return 0;
+   }
+
+   tr->physical_address = kvmppc_mmu_xlate(vcpu, index, eaddr);
+   /* XXX what does "writeable" and "usermode" even mean? */
+   tr->valid = 1;
+
+   return 0;
+}
+
+struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
+{
+   struct kvmppc_vcpu_e500 *vcpu_e500;
+   struct kvm_vcpu *vcpu;
+   int err;
+
+   vcpu_e500 = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
+   if (!vcpu_e500) {
+   err = -ENOMEM;
+   goto out;
+   }
+
+   vcpu = &vcpu_e500->vcpu;
+   err = kvm_vcpu_init(vcpu, kvm, id);
+   if (err)
+   goto free_vcpu;
+
+   err = 

[PATCH 04/11] Put iccci into CONFIG_44x ifdef

2008-12-11 Thread Liu Yu
E500 deosn't support this instruction.

Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/kvm/booke_interrupts.S |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index 084ebcd..4679ec2 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -347,7 +347,9 @@ lightweight_exit:
lwz r3, VCPU_SHADOW_PID(r4)
mtspr   SPRN_PID, r3
 
+#ifdef CONFIG_44x
iccci   0, 0 /* XXX hack */
+#endif
 
/* Load some guest volatiles. */
lwz r0, VCPU_GPR(r0)(r4)
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/11] Use arch.pid as shadow pid for E500

2008-12-11 Thread Liu Yu
Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/kernel/asm-offsets.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 544a27f..79fe94c 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -355,6 +355,13 @@ int main(void)
DEFINE(PTE_SIZE, sizeof(pte_t));
 
 #ifdef CONFIG_KVM
+#ifdef CONFIG_44x
+   DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
+#endif
+#ifdef CONFIG_FSL_BOOKE
+   DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.pid));
+#endif
+
DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack));
DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid));
DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr));
@@ -368,7 +375,6 @@ int main(void)
DEFINE(VCPU_SPRG5, offsetof(struct kvm_vcpu, arch.sprg5));
DEFINE(VCPU_SPRG6, offsetof(struct kvm_vcpu, arch.sprg6));
DEFINE(VCPU_SPRG7, offsetof(struct kvm_vcpu, arch.sprg7));
-   DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
 
DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/11] No need to include core header for KVM in asm-offsets.c currently

2008-12-11 Thread Liu Yu
Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/kernel/asm-offsets.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index fc3b863..544a27f 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -49,7 +49,7 @@
 #include 
 #endif
 #ifdef CONFIG_KVM
-#include 
+#include 
 #endif
 
 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
@@ -355,8 +355,6 @@ int main(void)
DEFINE(PTE_SIZE, sizeof(pte_t));
 
 #ifdef CONFIG_KVM
-   DEFINE(TLBE_BYTES, sizeof(struct kvmppc_44x_tlbe));
-
DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack));
DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid));
DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr));
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/11] Add dbsr in kvm_vcpu_arch

2008-12-11 Thread Liu Yu
Kernel for E500 will clear dbsr when startup.
So add dbsr register in kvm_vcpu_arch.

Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
 arch/powerpc/include/asm/kvm_host.h |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 850c41e..63962fa 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -163,6 +163,7 @@ struct kvm_vcpu_arch {
u32 ccr1;
u32 dbcr0;
u32 dbcr1;
+   u32 dbsr;
 
 #ifdef CONFIG_KVM_EXIT_TIMING
struct kvmppc_exit_timing timing_exit;
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/11] Add E500 support in KVM

2008-12-11 Thread Liu Yu
This patch set add E500 support in KVM,
and is already based on Hollis's feedback (a patchset which not yet commit)

btw: The latest code seems broken with this error.
---
  CC  arch/powerpc/kvm/../../../virt/kvm/kvm_main.o
arch/powerpc/kvm/../../../virt/kvm/kvm_main.c: In function 
‘make_all_cpus_request’:
arch/powerpc/kvm/../../../virt/kvm/kvm_main.c:577: error: implicit declaration 
of function ‘smp_call_function_many’
make[1]: *** [arch/powerpc/kvm/../../../virt/kvm/kvm_main.o] Error 1
make: *** [arch/powerpc/kvm] Error 2
--

Fortunately, I could test these patch based on a commit a couple of days ago.



--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html