2008-12-16 11:44:14 +01:00
|
|
|
/*
|
|
|
|
* Qemu PowerPC 440 Bamboo board emulation
|
|
|
|
*
|
|
|
|
* Copyright 2007 IBM Corporation.
|
|
|
|
* Authors:
|
2012-01-10 16:49:22 +01:00
|
|
|
* Jerone Young <jyoung5@us.ibm.com>
|
|
|
|
* Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
|
|
|
|
* Hollis Blanchard <hollisb@us.ibm.com>
|
2008-12-16 11:44:14 +01:00
|
|
|
*
|
|
|
|
* 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 "kvm.h"
|
|
|
|
#include "kvm_ppc.h"
|
|
|
|
#include "device_tree.h"
|
2009-09-20 16:58:02 +02:00
|
|
|
#include "loader.h"
|
|
|
|
#include "elf.h"
|
2011-08-12 01:07:18 +02:00
|
|
|
#include "exec-memory.h"
|
2012-01-10 19:39:38 +01:00
|
|
|
#include "pc.h"
|
|
|
|
#include "ppc.h"
|
|
|
|
#include "ppc405.h"
|
|
|
|
#include "sysemu.h"
|
2008-12-16 11:44:14 +01:00
|
|
|
|
|
|
|
#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
|
|
|
|
|
2010-08-05 02:21:37 +02:00
|
|
|
/* from u-boot */
|
|
|
|
#define KERNEL_ADDR 0x1000000
|
|
|
|
#define FDT_ADDR 0x1800000
|
|
|
|
#define RAMDISK_ADDR 0x1900000
|
|
|
|
|
2012-01-10 19:39:38 +01:00
|
|
|
#define PPC440EP_PCI_CONFIG 0xeec00000
|
|
|
|
#define PPC440EP_PCI_INTACK 0xeed00000
|
|
|
|
#define PPC440EP_PCI_SPECIAL 0xeed00000
|
|
|
|
#define PPC440EP_PCI_REGS 0xef400000
|
|
|
|
#define PPC440EP_PCI_IO 0xe8000000
|
|
|
|
#define PPC440EP_PCI_IOLEN 0x00010000
|
|
|
|
|
|
|
|
#define PPC440EP_SDRAM_NR_BANKS 4
|
|
|
|
|
|
|
|
static const unsigned int ppc440ep_sdram_bank_sizes[] = {
|
|
|
|
256<<20, 128<<20, 64<<20, 32<<20, 16<<20, 8<<20, 0
|
|
|
|
};
|
|
|
|
|
2012-01-03 19:10:02 +01:00
|
|
|
static target_phys_addr_t entry;
|
|
|
|
|
2012-01-10 19:36:26 +01:00
|
|
|
static PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4],
|
|
|
|
target_phys_addr_t config_space,
|
|
|
|
target_phys_addr_t int_ack,
|
|
|
|
target_phys_addr_t special_cycle,
|
|
|
|
target_phys_addr_t registers)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-10 19:39:38 +01:00
|
|
|
CPUState *ppc440ep_init(MemoryRegion *address_space_mem, ram_addr_t *ram_size,
|
|
|
|
PCIBus **pcip, const unsigned int pci_irq_nrs[4],
|
|
|
|
int do_init, const char *cpu_model)
|
|
|
|
{
|
|
|
|
MemoryRegion *ram_memories
|
|
|
|
= g_malloc(PPC440EP_SDRAM_NR_BANKS * sizeof(*ram_memories));
|
|
|
|
target_phys_addr_t ram_bases[PPC440EP_SDRAM_NR_BANKS];
|
|
|
|
target_phys_addr_t ram_sizes[PPC440EP_SDRAM_NR_BANKS];
|
|
|
|
CPUState *env;
|
|
|
|
qemu_irq *pic;
|
|
|
|
qemu_irq *irqs;
|
|
|
|
qemu_irq *pci_irqs;
|
|
|
|
|
|
|
|
if (cpu_model == NULL) {
|
|
|
|
cpu_model = "440EP";
|
|
|
|
}
|
|
|
|
env = cpu_init(cpu_model);
|
|
|
|
if (!env) {
|
|
|
|
fprintf(stderr, "Unable to initialize CPU!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ppc_booke_timers_init(env, 400000000, 0);
|
|
|
|
ppc_dcr_init(env, NULL, NULL);
|
|
|
|
|
|
|
|
/* interrupt controller */
|
|
|
|
irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
|
|
|
|
irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
|
|
|
|
irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
|
|
|
|
pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);
|
|
|
|
|
|
|
|
/* SDRAM controller */
|
|
|
|
memset(ram_bases, 0, sizeof(ram_bases));
|
|
|
|
memset(ram_sizes, 0, sizeof(ram_sizes));
|
|
|
|
*ram_size = ppc4xx_sdram_adjust(*ram_size, PPC440EP_SDRAM_NR_BANKS,
|
|
|
|
ram_memories,
|
|
|
|
ram_bases, ram_sizes,
|
|
|
|
ppc440ep_sdram_bank_sizes);
|
|
|
|
/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */
|
|
|
|
ppc4xx_sdram_init(env, pic[14], PPC440EP_SDRAM_NR_BANKS, ram_memories,
|
|
|
|
ram_bases, ram_sizes, do_init);
|
|
|
|
|
|
|
|
/* PCI */
|
|
|
|
pci_irqs = g_malloc(sizeof(qemu_irq) * 4);
|
|
|
|
pci_irqs[0] = pic[pci_irq_nrs[0]];
|
|
|
|
pci_irqs[1] = pic[pci_irq_nrs[1]];
|
|
|
|
pci_irqs[2] = pic[pci_irq_nrs[2]];
|
|
|
|
pci_irqs[3] = pic[pci_irq_nrs[3]];
|
|
|
|
*pcip = ppc4xx_pci_init(env, pci_irqs,
|
|
|
|
PPC440EP_PCI_CONFIG,
|
|
|
|
PPC440EP_PCI_INTACK,
|
|
|
|
PPC440EP_PCI_SPECIAL,
|
|
|
|
PPC440EP_PCI_REGS);
|
|
|
|
if (!*pcip)
|
|
|
|
printf("couldn't create PCI controller!\n");
|
|
|
|
|
|
|
|
isa_mmio_init(PPC440EP_PCI_IO, PPC440EP_PCI_IOLEN);
|
|
|
|
|
|
|
|
if (serial_hds[0] != NULL) {
|
|
|
|
serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],
|
|
|
|
PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
|
|
|
|
DEVICE_BIG_ENDIAN);
|
|
|
|
}
|
|
|
|
if (serial_hds[1] != NULL) {
|
|
|
|
serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],
|
|
|
|
PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
|
|
|
|
DEVICE_BIG_ENDIAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return env;
|
|
|
|
}
|
|
|
|
|
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;
|
2011-07-21 02:44:53 +02:00
|
|
|
uint32_t tb_freq = 400000000;
|
|
|
|
uint32_t clock_freq = 400000000;
|
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);
|
2011-08-21 05:09:37 +02:00
|
|
|
g_free(filename);
|
2009-05-30 01:52:44 +02:00
|
|
|
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");
|
|
|
|
|
2011-07-21 02:44:53 +02: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 02:08:10 +02:00
|
|
|
if (kvm_enabled()) {
|
2011-07-21 02:44:53 +02:00
|
|
|
tb_freq = kvmppc_get_tbfreq();
|
|
|
|
clock_freq = kvmppc_get_clockfreq();
|
2011-07-21 02:08:10 +02:00
|
|
|
}
|
2008-12-16 11:44:14 +01:00
|
|
|
|
2011-07-21 02:44:53 +02: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 11:44:14 +01:00
|
|
|
|
2010-02-02 09:49:02 +01:00
|
|
|
ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
|
2011-08-21 05:09:37 +02:00
|
|
|
g_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
|
|
|
}
|
|
|
|
|
2012-01-03 19:12:47 +01:00
|
|
|
/* Create reset TLB entries for BookE, spanning the 32bit addr space. */
|
|
|
|
static void mmubooke_create_initial_mapping(CPUState *env,
|
|
|
|
target_ulong va,
|
|
|
|
target_phys_addr_t pa)
|
|
|
|
{
|
|
|
|
ppcemb_tlb_t *tlb = &env->tlb.tlbe[0];
|
|
|
|
|
|
|
|
tlb->attr = 0;
|
|
|
|
tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4);
|
|
|
|
tlb->size = 1 << 31; /* up to 0x80000000 */
|
|
|
|
tlb->EPN = va & TARGET_PAGE_MASK;
|
|
|
|
tlb->RPN = pa & TARGET_PAGE_MASK;
|
|
|
|
tlb->PID = 0;
|
|
|
|
|
|
|
|
tlb = &env->tlb.tlbe[1];
|
|
|
|
tlb->attr = 0;
|
|
|
|
tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4);
|
|
|
|
tlb->size = 1 << 31; /* up to 0xffffffff */
|
|
|
|
tlb->EPN = 0x80000000 & TARGET_PAGE_MASK;
|
|
|
|
tlb->RPN = 0x80000000 & TARGET_PAGE_MASK;
|
|
|
|
tlb->PID = 0;
|
|
|
|
}
|
|
|
|
|
2012-01-03 19:10:02 +01:00
|
|
|
static void main_cpu_reset(void *opaque)
|
|
|
|
{
|
|
|
|
CPUState *env = opaque;
|
|
|
|
|
|
|
|
cpu_reset(env);
|
|
|
|
env->gpr[1] = (16<<20) - 8;
|
|
|
|
env->gpr[3] = FDT_ADDR;
|
|
|
|
env->nip = entry;
|
2012-01-03 19:12:47 +01:00
|
|
|
|
|
|
|
/* Create a mapping for the kernel. */
|
|
|
|
mmubooke_create_initial_mapping(env, 0, 0);
|
2012-01-03 19:10:02 +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 };
|
2011-08-12 01:07:18 +02:00
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
2008-12-16 11:44:14 +01:00
|
|
|
PCIBus *pcibus;
|
|
|
|
CPUState *env;
|
|
|
|
uint64_t elf_entry;
|
|
|
|
uint64_t elf_lowaddr;
|
2009-10-01 23:12:16 +02:00
|
|
|
target_phys_addr_t loadaddr = 0;
|
2008-12-16 11:44:14 +01:00
|
|
|
target_long initrd_size = 0;
|
2010-08-05 02:21:37 +02:00
|
|
|
int success;
|
2008-12-16 11:44:14 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Setup CPU. */
|
2011-08-12 01:07:18 +02:00
|
|
|
env = ppc440ep_init(address_space_mem, &ram_size, &pcibus,
|
|
|
|
pci_irq_nrs, 1, cpu_model);
|
2012-01-03 19:10:02 +01:00
|
|
|
qemu_register_reset(main_cpu_reset, env);
|
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) {
|
2010-08-05 02:21:37 +02: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 11:44:14 +01:00
|
|
|
entry = elf_entry;
|
|
|
|
loadaddr = elf_lowaddr;
|
|
|
|
}
|
|
|
|
/* XXX try again as binary */
|
2010-08-05 02:21:37 +02:00
|
|
|
if (success < 0) {
|
2008-12-16 11:44:14 +01:00
|
|
|
fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
|
|
|
kernel_filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load initrd. */
|
|
|
|
if (initrd_filename) {
|
2010-08-05 02:21:37 +02:00
|
|
|
initrd_size = load_image_targphys(initrd_filename, RAMDISK_ADDR,
|
|
|
|
ram_size - RAMDISK_ADDR);
|
2008-12-16 11:44:14 +01:00
|
|
|
|
|
|
|
if (initrd_size < 0) {
|
2010-08-05 02:21:37 +02:00
|
|
|
fprintf(stderr, "qemu: could not load ram disk '%s' at %x\n",
|
|
|
|
initrd_filename, RAMDISK_ADDR);
|
2008-12-16 11:44:14 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're loading a kernel directly, we must load the device tree too. */
|
|
|
|
if (kernel_filename) {
|
2010-08-05 02:21:37 +02:00
|
|
|
if (bamboo_load_device_tree(FDT_ADDR, ram_size, RAMDISK_ADDR,
|
|
|
|
initrd_size, kernel_cmdline) < 0) {
|
2008-12-16 11:44:14 +01:00
|
|
|
fprintf(stderr, "couldn't load device tree\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kvm_enabled())
|
|
|
|
kvmppc_init();
|
|
|
|
}
|
|
|
|
|
2009-05-21 01:38:09 +02:00
|
|
|
static QEMUMachine bamboo_machine = {
|
2012-01-10 16:36:10 +01:00
|
|
|
.name = "bamboo",
|
2010-02-25 14:56:11 +01:00
|
|
|
.desc = "bamboo",
|
|
|
|
.init = bamboo_init,
|
|
|
|
};
|
|
|
|
|
2009-05-21 01:38:09 +02:00
|
|
|
static void bamboo_machine_init(void)
|
|
|
|
{
|
|
|
|
qemu_register_machine(&bamboo_machine);
|
|
|
|
}
|
|
|
|
|
|
|
|
machine_init(bamboo_machine_init);
|