Skip to contentSkip to conversation

PowerPC KVM support

PATCH In review Hollis Blanchard 3 participants 22 messages Dec 11, 2008 – Dec 14, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

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

helper_regs.h uses "always_inline" and MSR_* constants, which are defined in osdep.h and cpu.h.

---
 target-ppc/helper_regs.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
target-ppc/helper_regs.h +4 -0
index 9666d4b..72a3f87 100644
@@ -21,6 +21,10 @@
 #if !defined(__HELPER_REGS_H__)
 #define __HELPER_REGS_H__
 
+#include "osdep.h"
+#include <stdio.h>
+#include "cpu.h"
+
 /* Swap temporary saved registers with GPRs */
 static always_inline void hreg_swap_gpr_tgpr (CPUPPCState *env)
 {
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH 2/6 kvm: sync vcpu state during initialization

In reply to 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.

---
 kvm-all.c |   15 +++++++++++++++
 kvm.h     |    1 +
 vl.c      |   11 +++++++++++
 3 files changed, 27 insertions(+), 0 deletions(-)
kvm-all.c +15 -0
index dad80df..11034df 100644
@@ -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
  */
kvm.h +1 -0
index ac464ab..efce145 100644
@@ -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);
 
vl.c +11 -0
index c3a8d8f..0a02151 100644
@@ -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++) {
Signature · 1 line
1.5.6.5
#3 lore raw

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

Quoted 5 lines · 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.

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

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#4 lore raw

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

In reply to Hollis Blanchard
Quoted 6 lines · 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.

Segv's x86 when using -enable-kvm.

Regards,

Anthony Liguori

#5 lore raw

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

Quoted 9 lines · Anthony Liguori
Quoted 6 lines · 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.

Segv's x86 when using -enable-kvm.

qemu.git already segvs on x86 with --enable-kvm unless you specify a -cpu option. (I'd call that a bug.) Maybe you forgot that on this run?

When I use "-cpu coreduo" (for some strange reason "core2duo" is not recognized), I don't segfault.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#6 lore raw

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

Quoted 3 lines · Hollis Blanchard

When I use "-cpu coreduo" (for some strange reason "core2duo" is not recognized), I don't segfault.

I didn't have TARGET_X86_64, so that explains the missing core2duo...

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#7 lore raw

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

Quoted 8 lines · Hollis Blanchard
Quoted 3 lines · Hollis Blanchard

When I use "-cpu coreduo" (for some strange reason "core2duo" is not recognized), I don't segfault.

I didn't have TARGET_X86_64, so that explains the missing core2duo...

I'm a bit confused. You were running -enable-kvm with qemu (as opposed to qemu-system-x86_64)?

Regards,

Anthony Liguori

#8 lore raw

PATCH 3/6 Enable KVM for ppcemb.

In reply to 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.

---
 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
Makefile.target +3 -0
index 7152dff..d01231d 100644
@@ -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
configure +6 -0
index 13f6358..c534441 100755
@@ -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
target-ppc/helper.c +5 -0
index 33e8b3b..0b93f1c 100644
@@ -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;
 }
 
target-ppc/kvm.c new file +212 -0

212 lines not on this page · raw message

target-ppc/kvm_ppc.c new file +105 -0

105 lines not on this page · raw message

target-ppc/kvm_ppc.h new file +15 -0
new file mode 100644
index 0000000..e536a88
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2008 IBM Corporation.
+ * Authors: Hollis Blanchard <[email protected]>
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#ifndef __KVM_PPC_H__
+#define __KVM_PPC_H__
+
+void kvmppc_init(void);
+void kvmppc_fdt_update(void *fdt);
+
+#endif /* __KVM_PPC_H__ */
Signature · 1 line
1.5.6.5
#9 lore raw

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

Quoted 24 lines · 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.

---
 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
Makefile.target +0 -0
index 7152dff..d01231d 100644

Makefile.target OBJS+= heathrow_pic.o grackle_pci.o ppc_oldworld.o · line 658

Quoted 7 lines
Makefile.target +3 -0
@@ -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.

target-ppc/kvm.c line 5

Quoted 12 lines
Makefile.target +0 -0
 diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c

new file mode 100644
index 0000000..90b943b

target-ppc/kvm.c new file +5 -0
@@ -0,0 +1,212 @@
+int kvm_arch_put_registers(CPUState *env)
+{
+	struct kvm_regs regs;
+	int ret;
+	int i;

Your indent is off.

Quoted 6 lines
target-ppc/kvm.c new file +5 -0
+int kvm_arch_get_registers(CPUState *env)
+{
+	struct kvm_regs regs;
+	uint32_t i, ret;
+

target-ppc/kvm.c line 107

Quoted 10 lines
target-ppc/kvm.c new file +10 -0
+	ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, &regs);
+	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.

target-ppc/kvm_ppc.c

Quoted 6 lines
target-ppc/kvm_ppc.c new file +0 -0
new file mode 100644
index 0000000..b2b56df

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

#10 lore raw

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

Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Hollis Blanchard
target-ppc/kvm.c new file +11 -0
+int kvm_arch_get_registers(CPUState *env)
+{
+	struct kvm_regs regs;
+	uint32_t i, ret;
+
+	ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, &regs);
+	if (ret < 0)
+		return ret;
+
+	env->ctr = regs.ctr;
+	env->lr = regs.lr;
Quoted 8 lines

target-ppc/kvm.c line 107

Quoted 5 lines
target-ppc/kvm.c new file +4 -0
+	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.

Quoted 9 lines

target-ppc/kvm_ppc.c

Quoted 6 lines
target-ppc/kvm_ppc.c new file +0 -0
new file mode 100644
index 0000000..b2b56df

Hence my confusion. These are just kvm related helper?

Quoted 3 lines

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.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#11 lore raw

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

Quoted 7 lines · Hollis Blanchard
Quoted 2 lines

I don't know that kvm_ppc.c is a very information name for this sort

of

Quoted 1 line

stuff. Since this is really host specific, not target specific, why

not

Quoted 1 line

move it out of target-ppc.

Quoted 9 lines

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.

Any further thoughts on this issue? It's the only issue I still have unresolved from the initial reviews.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#12 lore raw

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

Quoted 23 lines · Hollis Blanchard
Quoted 10 lines · Hollis Blanchard
Quoted 2 lines

I don't know that kvm_ppc.c is a very information name for this sort

of

Quoted 2 lines

stuff. Since this is really host specific, not target specific, why

not

Quoted 2 lines

move it out of target-ppc.

Quoted 10 lines

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.

Quoted 3 lines

Any further thoughts on this issue? It's the only issue I still have unresolved from the initial reviews.

No, we can fix it later when someone comes up with a better idea.

Regards,

Anthony Liguori

#13 lore raw

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

In reply to Hollis Blanchard
Quoted 39 lines · 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.

+int kvm_arch_put_registers(CPUState *env)
+{

 +       struct kvm_regs regs;
 +       int ret;
 +       int i;
 +
 +       ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, &regs);
 +       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];
Quoted 10 lines

+
+ for (i = 0;i < 32; i++)
+ regs.gpr[i] = env->gpr[i];
+
+ ret = kvm_vcpu_ioctl(env, KVM_SET_REGS, &regs);
+ if (ret < 0)
+ return ret;
+
+ return ret;
+}

Maybe this is a dumb question, but why don't you get/put floating point registers?

Quoted 1 line

+#include "device_tree.h"

The sequencing is not correct, you introduce FDT in #4.

#14 lore raw

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

Quoted 44 lines · Blue Swirl
Quoted 11 lines

+int kvm_arch_put_registers(CPUState *env)
+{

 +       struct kvm_regs regs;
 +       int ret;
 +       int i;

+
+ ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, &regs);
+ if (ret < 0)
+ return ret;
+
+ /* cr is untouched in qemu and not existant in CPUState fr

ppr */

Quoted 1 line

+ /* hflags is a morphed to MSR on ppc, no need to sync that

down to kvm */

Quoted 19 lines

+
+ 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];
Quoted 10 lines

+
+ for (i = 0;i < 32; i++)
+ regs.gpr[i] = env->gpr[i];
+
+ ret = kvm_vcpu_ioctl(env, KVM_SET_REGS, &regs);
+ if (ret < 0)
+ return ret;
+
+ return ret;
+}

Quoted 2 lines

Maybe this is a dumb question, but why don't you get/put floating point registers?

Not a dumb question. Qemu won't change the floating point registers at all, so there is no need to push to KVM. For debugging purposes ("info registers" or gdbstub) it might be nice to pull the FP state from KVM, but we simply haven't needed to do that so far.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#15 lore raw

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

In reply to 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.

---
 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
Makefile.target +4 -0
index d01231d..5da4994 100644
@@ -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
configure +18 -0
index c534441..b54c15d 100755
@@ -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
device_tree.c new file +116 -0

116 lines not on this page · raw message

device_tree.h new file +26 -0
new file mode 100644
index 0000000..9e6ef3d
@@ -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 <[email protected]>
+ *          Hollis Blanchard <[email protected]>
+ *
+ * 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__ */
libfdt_env.h new file +22 -0
new file mode 100644
index 0000000..59f2536
@@ -0,0 +1,22 @@
+#ifndef _LIBFDT_ENV_H
+#define _LIBFDT_ENV_H
+
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include <endian.h>
+#include <byteswap.h>
+
+#if __BYTE_ORDER = __BIG_ENDIAN
+#define fdt32_to_cpu(x)		(x)
+#define cpu_to_fdt32(x)		(x)
+#define fdt64_to_cpu(x)		(x)
+#define cpu_to_fdt64(x)		(x)
+#else
+#define fdt32_to_cpu(x)		(bswap_32((x)))
+#define cpu_to_fdt32(x)		(bswap_32((x)))
+#define fdt64_to_cpu(x)		(bswap_64((x)))
+#define cpu_to_fdt64(x)		(bswap_64((x)))
+#endif
+
+#endif /* _LIBFDT_ENV_H */
Signature · 1 line
1.5.6.5
#16 lore raw

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

Quoted 23 lines · Hollis Blanchard
device_tree.c new file +16 -0
new file mode 100644
index 0000000..d7350e3
@@ -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 <[email protected]>
+ *          Hollis Blanchard <[email protected]>
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>

device_tree.c line 26

Quoted 10 lines
device_tree.c new file +10 -0
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "qemu-common.h"
+#include "sysemu.h"
+#include "device_tree.h"
+
+#include "libfdt.h"

#include <libfdt.h>

Quoted 15 lines
device_tree.c new file +13 -0
+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);

device_tree.c line 50

Quoted 10 lines
device_tree.c new file +10 -0
+		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.

Quoted 18 lines
device_tree.c new file +17 -0
+	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",

device_tree.c line 78

Quoted 10 lines
device_tree.c new file +10 -0
+			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.

device_tree.c line 89

Quoted 12 lines
device_tree.c new file +11 -0
+	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 :-)

libfdt_env.h

Quoted 38 lines
device_tree.h new file +26 -0
new file mode 100644
index 0000000..9e6ef3d
@@ -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 <[email protected]>
+ *          Hollis Blanchard <[email protected]>
+ *
+ * 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__ */
libfdt_env.h new file +0 -0
new file mode 100644
index 0000000..59f2536

Missing copyright?

Regards,

Anthony Liguori

#17 lore raw

PATCH 5/6 PowerPC 440EP SoC emulation

In reply to 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.

---
 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
Makefile.target +1 -0
index 5da4994..6032af0 100644
@@ -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
hw/ppc440.c new file +144 -0

144 lines not on this page · raw message

hw/ppc440.h new file +20 -0
new file mode 100644
index 0000000..b6843eb
@@ -0,0 +1,20 @@
+/*
+ * Qemu PowerPC 440 board emualtion
+ *
+ * Copyright 2007 IBM Corporation.
+ * Authors: Jerone Young <[email protected]>
+ * 	    Christian Ehrhardt <[email protected]>
+ *
+ * This work is licensed under the GNU GPL licence version 2 or later
+ *
+ */
+
+#ifndef QEMU_PPC440_H
+#define QEMU_PPC440_H
+
+#include "hw.h"
+
+CPUState *ppc440ep_init(ram_addr_t *ram_size, PCIBus **pcip,
+                        const unsigned int pci_irq_nrs[4], int do_init);
+
+#endif
Signature · 1 line
1.5.6.5
#18 lore raw

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

In reply to 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.

---
 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
Makefile +1 -1
index a2a03ec..f9496fe 100644
@@ -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
Makefile.target +1 -1
index 6032af0..82bc746 100644
@@ -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
hw/boards.h +1 -0
index d30c0fc..debe9a6 100644
@@ -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;
hw/ppc440_bamboo.c new file +190 -0

190 lines not on this page · raw message

pc-bios/bamboo.dtb new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..81f971c64745aaf79152e1ed6f09e5d36137e461
GIT binary patch

zAnQWs)y1Oyrb<A4PC#>cQf54dnWuYyD0c90w%rSVeD)r2fZUÀvc@{beD6Kd8><G z*zav)eKh*I8mvKX^N6#^*<XYpv7qxJS#%~2sj64e87s((wjS4jB@T369E)r{Jb&&b zo6DWpuSLh!f<Dq_c(Sw2Y{%eoBqyFT#%b$!?ytdjz=0WQ45Gh=QFub<@wCYD^!#1@ zu410QZ;a<-pF271+O>Ut=b>l5QoG8ONt6!E-pyX^5+O^koji#s;a)Pi;)9>o>Qz zTR-qpcTPXz6z;LhIk;hUGzbs%?Fq!z{)P&E^6|R>u4c@Yb!2loj(qpX3&#ùB1w z%e+PRXx^ML&tnyD)^?dU;|cHNhHi>|t06s)rG~HpE}oBM;d^J1Js&{M-|hpqO+8~{ zfJ3l~A9;}9BA?s;2OrY<S3d525k4l1ba<R4NmHfRvSR&swudx@a##}dVU}AyvX| z_W1?jpsg4oJewNZnq4Md{Jv_eu6xpGMC1Cb*|5+Oz+$-{mcJd$!}&uLnfN7i;mGeX zudtB8c#ZLMZ3A0>48aFhò8=7SSR&3RQ1?ukrJ3-ake^n7wn{AUFn5@P#Wp7XH- zO!9vF-GRoy82B~^<}IgR8fOir-x~Z1rT$#<5FXG6pIhp_o&5Rj$6jFiVxw&x9k%Bd zEzMrM(AYYwY|l3~IpcD!^f<4~L|n-g_TbAc)Oz=!Pbh8AbdEF{o-a6$EB&NP@6QZ z)Mk|&8!KmdY*MB3tib=#C^ah9WmrU|nbfL@+Oy+z6O-Zn-A-w!l=^hE1l;0Zn#&P zkEdp$k5rvxWv(lPnCo^(qj{*$;5<QR>fyD&S$~g0C1WAO$oI~YbKJJdYs1!VW)@P zVjN9kP+#>6rkFCx7ZxYeDdD(9Hk&-G}*^5bE~e@K~mP!C=DgeX~}YgRbfm#cXCxK i$|Q^M*T}1WIZ&8I1$uSYn+BETUDa_utr4dltA7BYxVh&5

literal 0
HcmV?d00001

pc-bios/bamboo.dts new file +234 -0

234 lines not on this page · raw message

target-ppc/machine.c +2 -0
index be0cbe1..72f67d0 100644
@@ -1,5 +1,6 @@
 #include "hw/hw.h"
 #include "hw/boards.h"
+#include "kvm.h"
 
 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)
Signature · 1 line
1.5.6.5
#19 lore raw

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

Quoted 10 lines · 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.

Quoted 8 lines

--- 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?

#20 lore raw

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

In reply to Hollis Blanchard
Quoted 94 lines · 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.

---
 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
Makefile +1 -1
index a2a03ec..f9496fe 100644
@@ -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
Makefile.target +1 -1
index 6032af0..82bc746 100644
@@ -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
hw/boards.h +1 -0
index d30c0fc..debe9a6 100644
@@ -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;
hw/ppc440_bamboo.c new file +26 -0
new file mode 100644
index 0000000..b0e3106
@@ -0,0 +1,190 @@
+/*
+ * Qemu PowerPC 440 board emulation
+ *
+ * Copyright 2007 IBM Corporation.
+ * Authors:
+ * 	Jerone Young <[email protected]>
+ * 	Christian Ehrhardt <[email protected]>
+ * 	Hollis Blanchard <[email protected]>
+ *
+ * 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"
+

hw/ppc440_bamboo.c line 36

Quoted 10 lines
hw/ppc440_bamboo.c new file +10 -0
+#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.

hw/ppc440_bamboo.c line 42

Quoted 7 lines
hw/ppc440_bamboo.c new file +6 -0
+    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.

target-ppc/machine.c line 3

Quoted 8 lines
target-ppc/machine.c +1 -0
index be0cbe1..72f67d0 100644
@@ -1,5 +1,6 @@
 #include "hw/hw.h"
 #include "hw/boards.h"
+#include "kvm.h"

Is this necessary?

target-ppc/machine.c void register_machines(void) · line 15

Quoted 12 lines
target-ppc/machine.c +1 -0
 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

#21 lore raw

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

Quoted 16 lines · Anthony Liguori

hw/ppc440_bamboo.c line 36

Quoted 12 lines · Hollis Blanchard
hw/ppc440_bamboo.c new file +11 -0
+
+#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.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center