KVM PowerPC support v3
I've fixed the configure output in patch #1, and the comment in patch #4. Patch #2 was already acked.
-Hollis
PATCH 1/4 Implement device tree support needed for Bamboo emulation
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.
---
Fixed configure output.
--- Makefile.target | 4 ++ configure | 18 +++++++++ device_tree.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ device_tree.h | 26 ++++++++++++ libfdt_env.h | 41 ++++++++++++++++++++ 5 files changed, 203 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
@@ -655,6 +655,10 @@ 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 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
@@ -119,6 +119,7 @@ kvm="yes" kerneldir="" aix="no" blobs="yes" +fdt="yes" # OS specific targetos=`uname -s`
@@ -966,6 +967,18 @@ if $cc $ARCH_CFLAGS -o $TMPE $TMPC > /dev/null 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
@@ -1061,6 +1074,7 @@ echo "vde support $vde" echo "AIO support $aio" echo "Install blobs $blobs" echo "KVM support $kvm" +echo "fdt support $fdt" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -1350,6 +1364,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 +114 -0
114 lines not on this page · raw message
device_tree.h new file +26 -0
@@ -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 +41 -0
41 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 2/4 Enable KVM for ppcemb.
In reply to Hollis BlanchardImplement 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 | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.c | 110 +++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 15 ++++ 6 files changed, 343 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
@@ -659,6 +659,9 @@ ifdef FDT_LIBS OBJS+= device_tree.o LIBS+= $(FDT_LIBS) endif +ifdef CONFIG_KVM +OBJS+= kvm_ppc.o +endif # virtio support OBJS+= virtio.o virtio-blk.o virtio-balloon.o endif
configure +6 -0
@@ -1491,6 +1491,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"
@@ -1585,6 +1586,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
@@ -29,6 +29,7 @@#include "exec-all.h" #include "helper_regs.h" #include "qemu-common.h" +#include "kvm.h" //#define DEBUG_MMU //#define DEBUG_BATS
@@ -2920,6 +2921,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 +204 -0
204 lines not on this page · raw message
target-ppc/kvm_ppc.c new file +110 -0
110 lines not on this page · raw message
target-ppc/kvm_ppc.h new file +15 -0
@@ -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
PATCH 3/4 PowerPC 440EP SoC emulation
In reply to Hollis BlanchardWire 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 | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc440.h | 20 +++++++++++ 3 files changed, 124 insertions(+), 0 deletions(-) create mode 100644 hw/ppc440.c create mode 100644 hw/ppc440.h
Makefile.target +1 -0
@@ -655,6 +655,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 FDT_LIBS OBJS+= device_tree.o LIBS+= $(FDT_LIBS)
hw/ppc440.c new file +103 -0
103 lines not on this page · raw message
hw/ppc440.h new file +20 -0
@@ -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
Re: [Qemu-devel] [PATCH 3/4] PowerPC 440EP SoC emulation
Quoted 6 lines · 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.
What are the mains differences between 405 and 440 cores? Would it be easy to add support for 440 core in QEMU?
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Re: [Qemu-devel] [PATCH 3/4] PowerPC 440EP SoC emulation
Quoted 10 lines · Aurelien Jarno
Quoted 6 lines · 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.What are the mains differences between 405 and 440 cores? Would it be easy to add support for 440 core in QEMU?
It's been a while since I programmed for the 405, but from memory:
Unlike the 405, the 440 is a Book E core. The biggest difference is that there is no real mode; MMU translation is always active. MSR[IR] and DR have been replaced with IS and DS, and those "address space" bits contribute to the 41-bit virtual address (32-bit effective, 8-bit PID like 405, 1-bit AS). The TLB organization is pretty much the same as 405 (64-entry fully associative), though the data in each entry has changed a little.
Fixed interrupt vectors have been replaced with programmable ones, via the IVPR base register and 16 IVOR registers, indicating the offset of each vector from IVPR.
There is a Application Note that more fully lists the software differences:
https://www.amcc.com/MyAMCC/retrieveDocument/PowerPC/440GP/PPC440GP_AN2020_SWC405GP.pdf
Because the MMU is always on, tlbia doesn't exist any more. There are a few other minor instruction and register changes.
As I've mentioned, most 440 peripherals are the same or similar to 405, which is definitely helpful.
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center
PATCH 4/4 IBM PowerPC 440EP Bamboo reference board emulation
In reply to Hollis BlanchardSince 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.
---
Made comment more specific.
--- 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 | 1 + 7 files changed, 428 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
@@ -222,7 +222,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
@@ -655,7 +655,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 FDT_LIBS OBJS+= device_tree.o LIBS+= $(FDT_LIBS)
hw/boards.h +1 -0
@@ -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
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 +1 -0
@@ -8,6 +8,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
Re: [Qemu-devel] [PATCH 4/4] IBM PowerPC 440EP Bamboo reference
Quoted 13 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.
Signed-off-by Hollis Blanchard <[email protected]>---
Made comment more specific.
Quoted 7 lines
--- 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 ++++++++++++++++++++++++++++++++++++++++++++++++++
I guess the .dtb file is generated from the .dts. Could you give us more details about that? When the tools need to generate the dtb file are installed on the build machine, we may want to generate the .dtb during the build process.
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Re: [Qemu-devel] [PATCH 4/4] IBM PowerPC 440EP Bamboo reference
Quoted 22 lines · Aurelien Jarno
Quoted 13 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.
Signed-off-by Hollis Blanchard <[email protected]>---
Made comment more specific.Quoted 7 lines
--- 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 ++++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 4 lines
I guess the .dtb file is generated from the .dts. Could you give us more details about that? When the tools need to generate the dtb file are installed on the build machine, we may want to generate the .dtb during the build process.
The dtb file ("device tree binary") is generated from the dts ("device tree source") by a tool called dtc, the device tree compiler.[1]
dtc is available in major distributions: in Fedora the package name is "dtc"; in Debian it is "device-tree-compiler" (available in testing and unstable).
[1] http://git.jdl.com/gitweb/?p=dtc.git;a=summary
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center
Quoted 3 lines · Hollis Blanchard
I've fixed the configure output in patch #1, and the comment in patch #4. Patch #2 was already acked.
Thanks, all applied. I still have a few questions though, see the answer to individual patches.
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net