2008-12-16 13:44:14 +03: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 "ppc440.h"
|
|
|
|
#include "kvm.h"
|
|
|
|
#include "kvm_ppc.h"
|
|
|
|
#include "device_tree.h"
|
2009-09-20 18:58:02 +04:00
|
|
|
#include "loader.h"
|
|
|
|
#include "elf.h"
|
2011-08-12 03:07:18 +04:00
|
|
|
#include "exec-memory.h"
|
2008-12-16 13:44:14 +03:00
|
|
|
|
|
|
|
#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
|
|
|
|
|
2010-08-05 04:21:37 +04:00
|
|
|
/* from u-boot */
|
|
|
|
#define KERNEL_ADDR 0x1000000
|
|
|
|
#define FDT_ADDR 0x1800000
|
|
|
|
#define RAMDISK_ADDR 0x1900000
|
|
|
|
|
2010-02-02 11:49:02 +03:00
|
|
|
static int bamboo_load_device_tree(target_phys_addr_t addr,
|
2008-12-16 13:44:14 +03:00
|
|
|
uint32_t ramsize,
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t initrd_base,
|
|
|
|
target_phys_addr_t initrd_size,
|
2008-12-16 13:44:14 +03:00
|
|
|
const char *kernel_cmdline)
|
|
|
|
{
|
2010-02-27 21:47:22 +03:00
|
|
|
int ret = -1;
|
2009-07-27 18:12:52 +04:00
|
|
|
#ifdef CONFIG_FDT
|
2008-12-16 13:44:14 +03:00
|
|
|
uint32_t mem_reg_property[] = { 0, 0, ramsize };
|
2009-05-30 03:52:44 +04:00
|
|
|
char *filename;
|
2009-04-10 20:23:59 +04:00
|
|
|
int fdt_size;
|
2010-02-27 21:47:22 +03:00
|
|
|
void *fdt;
|
2011-07-21 04:44:53 +04:00
|
|
|
uint32_t tb_freq = 400000000;
|
|
|
|
uint32_t clock_freq = 400000000;
|
2008-12-16 13:44:14 +03:00
|
|
|
|
2009-05-30 03:52:44 +04:00
|
|
|
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
|
|
|
|
if (!filename) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
fdt = load_device_tree(filename, &fdt_size);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(filename);
|
2009-05-30 03:52:44 +04:00
|
|
|
if (fdt == NULL) {
|
2008-12-16 13:44:14 +03:00
|
|
|
goto out;
|
2009-05-30 03:52:44 +04:00
|
|
|
}
|
2008-12-16 13:44:14 +03: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");
|
|
|
|
|
2011-07-21 04:44:53 +04:00
|
|
|
/* Copy data from the host device tree into the guest. Since the guest can
|
|
|
|
* directly access the timebase without host involvement, we must expose
|
|
|
|
* the correct frequencies. */
|
2011-07-21 04:08:10 +04:00
|
|
|
if (kvm_enabled()) {
|
2011-07-21 04:44:53 +04:00
|
|
|
tb_freq = kvmppc_get_tbfreq();
|
|
|
|
clock_freq = kvmppc_get_clockfreq();
|
2011-07-21 04:08:10 +04:00
|
|
|
}
|
2008-12-16 13:44:14 +03:00
|
|
|
|
2011-07-21 04:44:53 +04:00
|
|
|
qemu_devtree_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",
|
|
|
|
clock_freq);
|
|
|
|
qemu_devtree_setprop_cell(fdt, "/cpus/cpu@0", "timebase-frequency",
|
|
|
|
tb_freq);
|
2008-12-16 13:44:14 +03:00
|
|
|
|
2010-02-02 11:49:02 +03:00
|
|
|
ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(fdt);
|
2009-04-10 20:23:59 +04:00
|
|
|
|
2008-12-16 13:44:14 +03:00
|
|
|
out:
|
|
|
|
#endif
|
|
|
|
|
2010-02-02 11:49:02 +03:00
|
|
|
return ret;
|
2008-12-16 13:44:14 +03:00
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void bamboo_init(ram_addr_t ram_size,
|
2009-01-16 22:41:04 +03:00
|
|
|
const char *boot_device,
|
2008-12-16 13:44:14 +03: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 };
|
2011-08-12 03:07:18 +04:00
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
2008-12-16 13:44:14 +03:00
|
|
|
PCIBus *pcibus;
|
|
|
|
CPUState *env;
|
|
|
|
uint64_t elf_entry;
|
|
|
|
uint64_t elf_lowaddr;
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t entry = 0;
|
|
|
|
target_phys_addr_t loadaddr = 0;
|
2008-12-16 13:44:14 +03:00
|
|
|
target_long initrd_size = 0;
|
2010-08-05 04:21:37 +04:00
|
|
|
int success;
|
2008-12-16 13:44:14 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Setup CPU. */
|
2011-08-12 03:07:18 +04:00
|
|
|
env = ppc440ep_init(address_space_mem, &ram_size, &pcibus,
|
|
|
|
pci_irq_nrs, 1, cpu_model);
|
2008-12-16 13:44:14 +03:00
|
|
|
|
|
|
|
if (pcibus) {
|
|
|
|
/* Register network interfaces. */
|
|
|
|
for (i = 0; i < nb_nics; i++) {
|
2009-01-13 22:47:10 +03: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 05:53:51 +04:00
|
|
|
pci_nic_init_nofail(&nd_table[i], "e1000", NULL);
|
2008-12-16 13:44:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load kernel. */
|
|
|
|
if (kernel_filename) {
|
2010-08-05 04:21:37 +04:00
|
|
|
success = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
|
|
|
|
if (success < 0) {
|
|
|
|
success = load_elf(kernel_filename, NULL, NULL, &elf_entry,
|
|
|
|
&elf_lowaddr, NULL, 1, ELF_MACHINE, 0);
|
2008-12-16 13:44:14 +03:00
|
|
|
entry = elf_entry;
|
|
|
|
loadaddr = elf_lowaddr;
|
|
|
|
}
|
|
|
|
/* XXX try again as binary */
|
2010-08-05 04:21:37 +04:00
|
|
|
if (success < 0) {
|
2008-12-16 13:44:14 +03:00
|
|
|
fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
|
|
|
kernel_filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load initrd. */
|
|
|
|
if (initrd_filename) {
|
2010-08-05 04:21:37 +04:00
|
|
|
initrd_size = load_image_targphys(initrd_filename, RAMDISK_ADDR,
|
|
|
|
ram_size - RAMDISK_ADDR);
|
2008-12-16 13:44:14 +03:00
|
|
|
|
|
|
|
if (initrd_size < 0) {
|
2010-08-05 04:21:37 +04:00
|
|
|
fprintf(stderr, "qemu: could not load ram disk '%s' at %x\n",
|
|
|
|
initrd_filename, RAMDISK_ADDR);
|
2008-12-16 13:44:14 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're loading a kernel directly, we must load the device tree too. */
|
|
|
|
if (kernel_filename) {
|
2010-08-05 04:21:37 +04:00
|
|
|
if (bamboo_load_device_tree(FDT_ADDR, ram_size, RAMDISK_ADDR,
|
|
|
|
initrd_size, kernel_cmdline) < 0) {
|
2008-12-16 13:44:14 +03:00
|
|
|
fprintf(stderr, "couldn't load device tree\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set initial guest state. */
|
|
|
|
env->gpr[1] = (16<<20) - 8;
|
2010-08-05 04:21:37 +04:00
|
|
|
env->gpr[3] = FDT_ADDR;
|
2008-12-16 13:44:14 +03:00
|
|
|
env->nip = entry;
|
|
|
|
/* XXX we currently depend on KVM to create some initial TLB entries. */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kvm_enabled())
|
|
|
|
kvmppc_init();
|
|
|
|
}
|
|
|
|
|
2009-05-21 03:38:09 +04:00
|
|
|
static QEMUMachine bamboo_machine = {
|
2010-02-25 16:56:11 +03: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 13:44:14 +03:00
|
|
|
.desc = "bamboo",
|
|
|
|
.init = bamboo_init,
|
2010-02-25 16:56:12 +03:00
|
|
|
.compat_props = (GlobalProperty[]) {
|
|
|
|
{
|
|
|
|
.driver = "virtio-serial-pci",
|
2010-06-23 21:19:20 +04:00
|
|
|
.property = "max_ports",
|
2010-02-25 16:56:12 +03:00
|
|
|
.value = stringify(1),
|
|
|
|
},{
|
|
|
|
.driver = "virtio-serial-pci",
|
|
|
|
.property = "vectors",
|
|
|
|
.value = stringify(0),
|
|
|
|
},
|
|
|
|
{ /* end of list */ }
|
|
|
|
},
|
2008-12-16 13:44:14 +03:00
|
|
|
};
|
2009-05-21 03:38:09 +04:00
|
|
|
|
|
|
|
static void bamboo_machine_init(void)
|
|
|
|
{
|
|
|
|
qemu_register_machine(&bamboo_machine);
|
2010-02-25 16:56:11 +03:00
|
|
|
qemu_register_machine(&bamboo_machine_v0_12);
|
2009-05-21 03:38:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
machine_init(bamboo_machine_init);
|