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

2008-12-15 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 holl...@us.ibm.com
---
 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

diff --git a/Makefile b/Makefile
index 01f0121..85523d7 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/Makefile.target b/Makefile.target
index ef2d25f..c4d0f05 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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)
diff --git a/hw/boards.h b/hw/boards.h
index a7b8126..bff1cf0 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..0a3b6e4
--- /dev/null
+++ b/hw/ppc440_bamboo.c
@@ -0,0 +1,190 @@
+/*
+ * Qemu PowerPC 440 board emulation
+ *
+ * Copyright 2007 IBM Corporation.
+ * Authors:
+ * Jerone Young jyou...@us.ibm.com
+ * Christian Ehrhardt ehrha...@linux.vnet.ibm.com
+ * Hollis Blanchard holl...@us.ibm.com
+ *
+ * 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;
+int pathlen;
+int ret;
+
+pathlen = snprintf(NULL, 0, %s/%s, bios_dir, BINARY_DEVICE_TREE_FILE) + 
1;
+path = qemu_malloc(pathlen);
+if (path == NULL)
+return NULL;
+
+snprintf(path, pathlen, %s/%s, bios_dir, BINARY_DEVICE_TREE_FILE);
+
+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 

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

2008-12-15 Thread Paul Brook
On Monday 15 December 2008, Hollis Blanchard wrote:
 + * Qemu PowerPC 440 board emulation

Is this emulating an actual board, or something you invented. I'm guessing the 
latter, inwhich case you should say which one.

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