2008-12-16 11:44:14 +01:00
|
|
|
/*
|
|
|
|
* Qemu PowerPC 440 Bamboo board emulation
|
|
|
|
*
|
|
|
|
* Copyright 2007 IBM Corporation.
|
|
|
|
* Authors:
|
|
|
|
* Jerone Young <jyoung5@us.ibm.com>
|
|
|
|
* Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
|
|
|
|
* Hollis Blanchard <hollisb@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 "boards.h"
|
|
|
|
#include "sysemu.h"
|
|
|
|
#include "ppc440.h"
|
|
|
|
#include "kvm.h"
|
|
|
|
#include "kvm_ppc.h"
|
|
|
|
#include "device_tree.h"
|
2009-09-20 16:58:02 +02:00
|
|
|
#include "loader.h"
|
|
|
|
#include "elf.h"
|
2008-12-16 11:44:14 +01:00
|
|
|
|
|
|
|
#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
|
|
|
|
|
2010-02-02 09:49:02 +01:00
|
|
|
static int bamboo_load_device_tree(target_phys_addr_t addr,
|
2008-12-16 11:44:14 +01:00
|
|
|
uint32_t ramsize,
|
2009-10-01 23:12:16 +02:00
|
|
|
target_phys_addr_t initrd_base,
|
|
|
|
target_phys_addr_t initrd_size,
|
2008-12-16 11:44:14 +01:00
|
|
|
const char *kernel_cmdline)
|
|
|
|
{
|
2010-02-27 19:47:22 +01:00
|
|
|
int ret = -1;
|
2009-07-27 16:12:52 +02:00
|
|
|
#ifdef CONFIG_FDT
|
2008-12-16 11:44:14 +01:00
|
|
|
uint32_t mem_reg_property[] = { 0, 0, ramsize };
|
2009-05-30 01:52:44 +02:00
|
|
|
char *filename;
|
2009-04-10 18:23:59 +02:00
|
|
|
int fdt_size;
|
2010-02-27 19:47:22 +01:00
|
|
|
void *fdt;
|
2008-12-16 11:44:14 +01:00
|
|
|
|
2009-05-30 01:52:44 +02:00
|
|
|
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
|
|
|
|
if (!filename) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
fdt = load_device_tree(filename, &fdt_size);
|
|
|
|
qemu_free(filename);
|
|
|
|
if (fdt == NULL) {
|
2008-12-16 11:44:14 +01:00
|
|
|
goto out;
|
2009-05-30 01:52:44 +02:00
|
|
|
}
|
2008-12-16 11:44:14 +01:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2010-02-02 09:49:02 +01:00
|
|
|
ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
|
|
|
|
qemu_free(fdt);
|
2009-04-10 18:23:59 +02:00
|
|
|
|
2008-12-16 11:44:14 +01:00
|
|
|
out:
|
|
|
|
#endif
|
|
|
|
|
2010-02-02 09:49:02 +01:00
|
|
|
return ret;
|
2008-12-16 11:44:14 +01:00
|
|
|
}
|
|
|
|
|
2009-10-01 23:12:16 +02:00
|
|
|
static void bamboo_init(ram_addr_t ram_size,
|
2009-01-16 20:41:04 +01:00
|
|
|
const char *boot_device,
|
2008-12-16 11:44:14 +01:00
|
|
|
const char *kernel_filename,
|
|
|
|
const char *kernel_cmdline,
|
|
|
|
const char *initrd_filename,
|
|
|
|
const char *cpu_model)
|
|
|
|
{
|
|
|
|
unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
|
|
|
|
PCIBus *pcibus;
|
|
|
|
CPUState *env;
|
|
|
|
uint64_t elf_entry;
|
|
|
|
uint64_t elf_lowaddr;
|
2009-10-01 23:12:16 +02:00
|
|
|
target_phys_addr_t entry = 0;
|
|
|
|
target_phys_addr_t loadaddr = 0;
|
2008-12-16 11:44:14 +01:00
|
|
|
target_long kernel_size = 0;
|
|
|
|
target_ulong initrd_base = 0;
|
|
|
|
target_long initrd_size = 0;
|
|
|
|
target_ulong dt_base = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Setup CPU. */
|
2009-06-17 17:49:37 +02:00
|
|
|
env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
|
2008-12-16 11:44:14 +01:00
|
|
|
|
|
|
|
if (pcibus) {
|
|
|
|
/* Register network interfaces. */
|
|
|
|
for (i = 0; i < nb_nics; i++) {
|
2009-01-13 20:47:10 +01:00
|
|
|
/* There are no PCI NICs on the Bamboo board, but there are
|
|
|
|
* PCI slots, so we can pick whatever default model we want. */
|
2009-09-25 03:53:51 +02:00
|
|
|
pci_nic_init_nofail(&nd_table[i], "e1000", NULL);
|
2008-12-16 11:44:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load kernel. */
|
|
|
|
if (kernel_filename) {
|
|
|
|
kernel_size = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
|
|
|
|
if (kernel_size < 0) {
|
|
|
|
kernel_size = load_elf(kernel_filename, 0, &elf_entry, &elf_lowaddr,
|
2009-09-20 16:58:02 +02:00
|
|
|
NULL, 1, ELF_MACHINE, 0);
|
2008-12-16 11:44:14 +01:00
|
|
|
entry = elf_entry;
|
|
|
|
loadaddr = elf_lowaddr;
|
|
|
|
}
|
|
|
|
/* XXX try again as binary */
|
|
|
|
if (kernel_size < 0) {
|
|
|
|
fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
|
|
|
kernel_filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load initrd. */
|
|
|
|
if (initrd_filename) {
|
|
|
|
initrd_base = kernel_size + loadaddr;
|
2009-04-09 22:05:49 +02:00
|
|
|
initrd_size = load_image_targphys(initrd_filename, initrd_base,
|
|
|
|
ram_size - initrd_base);
|
2008-12-16 11:44:14 +01:00
|
|
|
|
|
|
|
if (initrd_size < 0) {
|
|
|
|
fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
|
|
|
initrd_filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're loading a kernel directly, we must load the device tree too. */
|
|
|
|
if (kernel_filename) {
|
|
|
|
if (initrd_base)
|
|
|
|
dt_base = initrd_base + initrd_size;
|
|
|
|
else
|
|
|
|
dt_base = kernel_size + loadaddr;
|
|
|
|
|
2010-02-02 09:49:02 +01:00
|
|
|
if (bamboo_load_device_tree(dt_base, ram_size,
|
|
|
|
initrd_base, initrd_size, kernel_cmdline) < 0) {
|
2008-12-16 11:44:14 +01:00
|
|
|
fprintf(stderr, "couldn't load device tree\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-01-27 07:14:09 +01:00
|
|
|
cpu_synchronize_state(env);
|
|
|
|
|
2008-12-16 11:44:14 +01:00
|
|
|
/* Set initial guest state. */
|
|
|
|
env->gpr[1] = (16<<20) - 8;
|
|
|
|
env->gpr[3] = dt_base;
|
|
|
|
env->nip = entry;
|
|
|
|
/* XXX we currently depend on KVM to create some initial TLB entries. */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kvm_enabled())
|
|
|
|
kvmppc_init();
|
|
|
|
}
|
|
|
|
|
2009-05-21 01:38:09 +02:00
|
|
|
static QEMUMachine bamboo_machine = {
|
2010-02-25 14:56:11 +01:00
|
|
|
.name = "bamboo-0.13",
|
|
|
|
.alias = "bamboo",
|
|
|
|
.desc = "bamboo",
|
|
|
|
.init = bamboo_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static QEMUMachine bamboo_machine_v0_12 = {
|
|
|
|
.name = "bamboo-0.12",
|
2008-12-16 11:44:14 +01:00
|
|
|
.desc = "bamboo",
|
|
|
|
.init = bamboo_init,
|
2010-02-25 14:56:12 +01:00
|
|
|
.compat_props = (GlobalProperty[]) {
|
|
|
|
{
|
|
|
|
.driver = "virtio-serial-pci",
|
|
|
|
.property = "max_nr_ports",
|
|
|
|
.value = stringify(1),
|
|
|
|
},{
|
|
|
|
.driver = "virtio-serial-pci",
|
|
|
|
.property = "vectors",
|
|
|
|
.value = stringify(0),
|
|
|
|
},
|
|
|
|
{ /* end of list */ }
|
|
|
|
},
|
2008-12-16 11:44:14 +01:00
|
|
|
};
|
2009-05-21 01:38:09 +02:00
|
|
|
|
|
|
|
static void bamboo_machine_init(void)
|
|
|
|
{
|
|
|
|
qemu_register_machine(&bamboo_machine);
|
2010-02-25 14:56:11 +01:00
|
|
|
qemu_register_machine(&bamboo_machine_v0_12);
|
2009-05-21 01:38:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
machine_init(bamboo_machine_init);
|