2009-03-02 19:42:42 +03:00
|
|
|
/*
|
2012-07-02 17:03:19 +04:00
|
|
|
* QEMU PowerPC e500-based platforms
|
2009-03-02 19:42:42 +03:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Yu Liu, <yu.liu@freescale.com>
|
|
|
|
*
|
|
|
|
* This file is derived from hw/ppc440_bamboo.c,
|
|
|
|
* the copyright for that material belongs to the original owners.
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "qemu-common.h"
|
2012-07-02 17:03:20 +04:00
|
|
|
#include "e500.h"
|
2012-10-10 08:28:28 +04:00
|
|
|
#include "e500-ccsr.h"
|
2012-10-24 10:43:34 +04:00
|
|
|
#include "net/net.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/config-file.h"
|
2012-07-02 17:03:18 +04:00
|
|
|
#include "hw/hw.h"
|
2012-10-17 11:54:19 +04:00
|
|
|
#include "hw/serial.h"
|
2012-12-12 16:24:50 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2012-07-02 17:03:18 +04:00
|
|
|
#include "hw/boards.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
#include "sysemu/kvm.h"
|
2009-03-02 19:42:42 +03:00
|
|
|
#include "kvm_ppc.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/device_tree.h"
|
2012-07-02 17:03:18 +04:00
|
|
|
#include "hw/openpic.h"
|
|
|
|
#include "hw/ppc.h"
|
|
|
|
#include "hw/loader.h"
|
2009-09-20 18:58:02 +04:00
|
|
|
#include "elf.h"
|
2012-07-02 17:03:18 +04:00
|
|
|
#include "hw/sysbus.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/address-spaces.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/host-utils.h"
|
2012-12-13 04:16:24 +04:00
|
|
|
#include "hw/ppce500_pci.h"
|
2009-03-02 19:42:42 +03:00
|
|
|
|
|
|
|
#define BINARY_DEVICE_TREE_FILE "mpc8544ds.dtb"
|
|
|
|
#define UIMAGE_LOAD_BASE 0
|
2012-08-22 18:55:40 +04:00
|
|
|
#define DTC_LOAD_PAD 0x1800000
|
2010-02-02 11:49:03 +03:00
|
|
|
#define DTC_PAD_MASK 0xFFFFF
|
|
|
|
#define INITRD_LOAD_PAD 0x2000000
|
|
|
|
#define INITRD_PAD_MASK 0xFFFFFF
|
2009-03-02 19:42:42 +03:00
|
|
|
|
|
|
|
#define RAM_SIZES_ALIGN (64UL << 20)
|
|
|
|
|
2012-07-02 17:03:19 +04:00
|
|
|
/* TODO: parameterize */
|
2012-06-06 02:30:36 +04:00
|
|
|
#define MPC8544_CCSRBAR_BASE 0xE0000000ULL
|
|
|
|
#define MPC8544_CCSRBAR_SIZE 0x00100000ULL
|
2012-10-10 08:28:27 +04:00
|
|
|
#define MPC8544_MPIC_REGS_OFFSET 0x40000ULL
|
2012-12-08 17:26:37 +04:00
|
|
|
#define MPC8544_MSI_REGS_OFFSET 0x41600ULL
|
2012-10-10 08:28:27 +04:00
|
|
|
#define MPC8544_SERIAL0_REGS_OFFSET 0x4500ULL
|
|
|
|
#define MPC8544_SERIAL1_REGS_OFFSET 0x4600ULL
|
|
|
|
#define MPC8544_PCI_REGS_OFFSET 0x8000ULL
|
|
|
|
#define MPC8544_PCI_REGS_BASE (MPC8544_CCSRBAR_BASE + \
|
|
|
|
MPC8544_PCI_REGS_OFFSET)
|
2012-06-06 02:30:36 +04:00
|
|
|
#define MPC8544_PCI_REGS_SIZE 0x1000ULL
|
|
|
|
#define MPC8544_PCI_IO 0xE1000000ULL
|
2012-10-10 08:28:27 +04:00
|
|
|
#define MPC8544_UTIL_OFFSET 0xe0000ULL
|
2012-06-06 02:30:36 +04:00
|
|
|
#define MPC8544_SPIN_BASE 0xEF000000ULL
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2011-05-01 01:34:53 +04:00
|
|
|
struct boot_info
|
|
|
|
{
|
|
|
|
uint32_t dt_base;
|
2012-05-19 02:48:50 +04:00
|
|
|
uint32_t dt_size;
|
2011-05-01 01:34:53 +04:00
|
|
|
uint32_t entry;
|
|
|
|
};
|
|
|
|
|
2012-12-12 16:47:07 +04:00
|
|
|
static uint32_t *pci_map_create(void *fdt, uint32_t mpic, int first_slot,
|
|
|
|
int nr_slots, int *len)
|
2012-05-17 17:34:34 +04:00
|
|
|
{
|
2012-12-12 16:47:07 +04:00
|
|
|
int i = 0;
|
|
|
|
int slot;
|
|
|
|
int pci_irq;
|
2012-12-13 04:16:24 +04:00
|
|
|
int host_irq;
|
2012-12-12 16:47:07 +04:00
|
|
|
int last_slot = first_slot + nr_slots;
|
|
|
|
uint32_t *pci_map;
|
|
|
|
|
|
|
|
*len = nr_slots * 4 * 7 * sizeof(uint32_t);
|
|
|
|
pci_map = g_malloc(*len);
|
|
|
|
|
|
|
|
for (slot = first_slot; slot < last_slot; slot++) {
|
|
|
|
for (pci_irq = 0; pci_irq < 4; pci_irq++) {
|
|
|
|
pci_map[i++] = cpu_to_be32(slot << 11);
|
|
|
|
pci_map[i++] = cpu_to_be32(0x0);
|
|
|
|
pci_map[i++] = cpu_to_be32(0x0);
|
|
|
|
pci_map[i++] = cpu_to_be32(pci_irq + 1);
|
|
|
|
pci_map[i++] = cpu_to_be32(mpic);
|
2012-12-13 04:16:24 +04:00
|
|
|
host_irq = ppce500_pci_map_irq_slot(slot, pci_irq);
|
|
|
|
pci_map[i++] = cpu_to_be32(host_irq + 1);
|
2012-12-12 16:47:07 +04:00
|
|
|
pci_map[i++] = cpu_to_be32(0x1);
|
|
|
|
}
|
2012-05-17 17:34:34 +04:00
|
|
|
}
|
2012-12-12 16:47:07 +04:00
|
|
|
|
|
|
|
assert((i * sizeof(uint32_t)) == *len);
|
|
|
|
|
|
|
|
return pci_map;
|
2012-05-17 17:34:34 +04:00
|
|
|
}
|
|
|
|
|
2012-06-06 03:19:40 +04:00
|
|
|
static void dt_serial_create(void *fdt, unsigned long long offset,
|
|
|
|
const char *soc, const char *mpic,
|
|
|
|
const char *alias, int idx, bool defcon)
|
|
|
|
{
|
|
|
|
char ser[128];
|
|
|
|
|
|
|
|
snprintf(ser, sizeof(ser), "%s/serial@%llx", soc, offset);
|
|
|
|
qemu_devtree_add_subnode(fdt, ser);
|
|
|
|
qemu_devtree_setprop_string(fdt, ser, "device_type", "serial");
|
|
|
|
qemu_devtree_setprop_string(fdt, ser, "compatible", "ns16550");
|
|
|
|
qemu_devtree_setprop_cells(fdt, ser, "reg", offset, 0x100);
|
|
|
|
qemu_devtree_setprop_cell(fdt, ser, "cell-index", idx);
|
|
|
|
qemu_devtree_setprop_cell(fdt, ser, "clock-frequency", 0);
|
2012-08-10 00:57:14 +04:00
|
|
|
qemu_devtree_setprop_cells(fdt, ser, "interrupts", 42, 2);
|
2012-06-06 03:19:40 +04:00
|
|
|
qemu_devtree_setprop_phandle(fdt, ser, "interrupt-parent", mpic);
|
|
|
|
qemu_devtree_setprop_string(fdt, "/aliases", alias, ser);
|
|
|
|
|
|
|
|
if (defcon) {
|
|
|
|
qemu_devtree_setprop_string(fdt, "/chosen", "linux,stdout-path", ser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-02 17:03:19 +04:00
|
|
|
static int ppce500_load_device_tree(CPUPPCState *env,
|
2012-07-02 17:03:20 +04:00
|
|
|
PPCE500Params *params,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr,
|
|
|
|
hwaddr initrd_base,
|
|
|
|
hwaddr initrd_size)
|
2009-03-02 19:42:42 +03:00
|
|
|
{
|
2010-02-27 21:47:22 +03:00
|
|
|
int ret = -1;
|
2012-07-02 17:03:20 +04:00
|
|
|
uint64_t mem_reg_property[] = { 0, cpu_to_be64(params->ram_size) };
|
2009-04-10 20:23:59 +04:00
|
|
|
int fdt_size;
|
2010-02-27 21:47:22 +03:00
|
|
|
void *fdt;
|
2011-06-16 01:34:04 +04:00
|
|
|
uint8_t hypercall[16];
|
2011-07-21 04:34:11 +04:00
|
|
|
uint32_t clock_freq = 400000000;
|
|
|
|
uint32_t tb_freq = 400000000;
|
2011-07-21 05:01:11 +04:00
|
|
|
int i;
|
2012-07-02 17:03:20 +04:00
|
|
|
const char *toplevel_compat = NULL; /* user override */
|
2012-06-06 02:20:20 +04:00
|
|
|
char compatible_sb[] = "fsl,mpc8544-immr\0simple-bus";
|
2012-05-17 16:51:07 +04:00
|
|
|
char soc[128];
|
2012-05-17 16:51:51 +04:00
|
|
|
char mpic[128];
|
|
|
|
uint32_t mpic_ph;
|
2012-12-08 17:26:37 +04:00
|
|
|
uint32_t msi_ph;
|
2012-05-17 16:52:46 +04:00
|
|
|
char gutil[128];
|
2012-05-17 17:34:34 +04:00
|
|
|
char pci[128];
|
2012-12-08 17:26:37 +04:00
|
|
|
char msi[128];
|
2012-12-12 16:47:07 +04:00
|
|
|
uint32_t *pci_map = NULL;
|
|
|
|
int len;
|
2012-06-06 02:25:06 +04:00
|
|
|
uint32_t pci_ranges[14] =
|
|
|
|
{
|
|
|
|
0x2000000, 0x0, 0xc0000000,
|
|
|
|
0x0, 0xc0000000,
|
|
|
|
0x0, 0x20000000,
|
|
|
|
|
|
|
|
0x1000000, 0x0, 0x0,
|
|
|
|
0x0, 0xe1000000,
|
|
|
|
0x0, 0x10000,
|
|
|
|
};
|
2012-05-18 02:11:33 +04:00
|
|
|
QemuOpts *machine_opts;
|
2012-05-22 16:28:50 +04:00
|
|
|
const char *dtb_file = NULL;
|
|
|
|
|
|
|
|
machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
|
|
|
|
if (machine_opts) {
|
|
|
|
dtb_file = qemu_opt_get(machine_opts, "dtb");
|
2012-07-02 17:03:20 +04:00
|
|
|
toplevel_compat = qemu_opt_get(machine_opts, "dt_compatible");
|
2012-05-22 16:28:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dtb_file) {
|
|
|
|
char *filename;
|
|
|
|
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, dtb_file);
|
|
|
|
if (!filename) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
fdt = load_device_tree(filename, &fdt_size);
|
|
|
|
if (!fdt) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2012-05-17 17:50:14 +04:00
|
|
|
fdt = create_device_tree(&fdt_size);
|
2009-05-30 03:52:44 +04:00
|
|
|
if (fdt == NULL) {
|
|
|
|
goto out;
|
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
|
|
|
|
/* Manipulate device tree in memory. */
|
2012-06-06 02:25:06 +04:00
|
|
|
qemu_devtree_setprop_cell(fdt, "/", "#address-cells", 2);
|
|
|
|
qemu_devtree_setprop_cell(fdt, "/", "#size-cells", 2);
|
2012-05-17 14:20:50 +04:00
|
|
|
|
2012-05-17 13:34:50 +04:00
|
|
|
qemu_devtree_add_subnode(fdt, "/memory");
|
|
|
|
qemu_devtree_setprop_string(fdt, "/memory", "device_type", "memory");
|
|
|
|
qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
|
|
|
|
sizeof(mem_reg_property));
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2012-05-17 16:49:20 +04:00
|
|
|
qemu_devtree_add_subnode(fdt, "/chosen");
|
2011-05-01 01:34:53 +04:00
|
|
|
if (initrd_size) {
|
|
|
|
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");
|
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2011-05-01 01:34:53 +04:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
|
|
|
|
ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
|
2012-07-02 17:03:20 +04:00
|
|
|
params->kernel_cmdline);
|
2009-03-02 19:42:42 +03:00
|
|
|
if (ret < 0)
|
|
|
|
fprintf(stderr, "couldn't set /chosen/bootargs\n");
|
|
|
|
|
|
|
|
if (kvm_enabled()) {
|
2011-07-21 04:34:11 +04:00
|
|
|
/* Read out host's frequencies */
|
|
|
|
clock_freq = kvmppc_get_clockfreq();
|
|
|
|
tb_freq = kvmppc_get_tbfreq();
|
2011-06-16 01:34:04 +04:00
|
|
|
|
|
|
|
/* indicate KVM hypercall interface */
|
2012-05-17 13:50:05 +04:00
|
|
|
qemu_devtree_add_subnode(fdt, "/hypervisor");
|
2011-06-16 01:34:04 +04:00
|
|
|
qemu_devtree_setprop_string(fdt, "/hypervisor", "compatible",
|
|
|
|
"linux,kvm");
|
|
|
|
kvmppc_get_hypercall(env, hypercall, sizeof(hypercall));
|
|
|
|
qemu_devtree_setprop(fdt, "/hypervisor", "hcall-instructions",
|
|
|
|
hypercall, sizeof(hypercall));
|
2009-03-02 19:42:42 +03:00
|
|
|
}
|
2011-05-01 01:34:53 +04:00
|
|
|
|
2012-05-17 13:48:16 +04:00
|
|
|
/* Create CPU nodes */
|
|
|
|
qemu_devtree_add_subnode(fdt, "/cpus");
|
|
|
|
qemu_devtree_setprop_cell(fdt, "/cpus", "#address-cells", 1);
|
|
|
|
qemu_devtree_setprop_cell(fdt, "/cpus", "#size-cells", 0);
|
|
|
|
|
2011-07-23 12:56:40 +04:00
|
|
|
/* We need to generate the cpu nodes in reverse order, so Linux can pick
|
|
|
|
the first node as boot node and be happy */
|
|
|
|
for (i = smp_cpus - 1; i >= 0; i--) {
|
2011-07-21 05:01:11 +04:00
|
|
|
char cpu_name[128];
|
2012-05-18 03:56:46 +04:00
|
|
|
uint64_t cpu_release_addr = MPC8544_SPIN_BASE + (i * 0x20);
|
2011-07-21 05:06:12 +04:00
|
|
|
|
2011-07-23 12:56:40 +04:00
|
|
|
for (env = first_cpu; env != NULL; env = env->next_cpu) {
|
|
|
|
if (env->cpu_index == i) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!env) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(cpu_name, sizeof(cpu_name), "/cpus/PowerPC,8544@%x", env->cpu_index);
|
|
|
|
qemu_devtree_add_subnode(fdt, cpu_name);
|
2011-07-21 05:01:11 +04:00
|
|
|
qemu_devtree_setprop_cell(fdt, cpu_name, "clock-frequency", clock_freq);
|
|
|
|
qemu_devtree_setprop_cell(fdt, cpu_name, "timebase-frequency", tb_freq);
|
2011-07-23 12:56:40 +04:00
|
|
|
qemu_devtree_setprop_string(fdt, cpu_name, "device_type", "cpu");
|
|
|
|
qemu_devtree_setprop_cell(fdt, cpu_name, "reg", env->cpu_index);
|
|
|
|
qemu_devtree_setprop_cell(fdt, cpu_name, "d-cache-line-size",
|
|
|
|
env->dcache_line_size);
|
|
|
|
qemu_devtree_setprop_cell(fdt, cpu_name, "i-cache-line-size",
|
|
|
|
env->icache_line_size);
|
|
|
|
qemu_devtree_setprop_cell(fdt, cpu_name, "d-cache-size", 0x8000);
|
|
|
|
qemu_devtree_setprop_cell(fdt, cpu_name, "i-cache-size", 0x8000);
|
|
|
|
qemu_devtree_setprop_cell(fdt, cpu_name, "bus-frequency", 0);
|
|
|
|
if (env->cpu_index) {
|
|
|
|
qemu_devtree_setprop_string(fdt, cpu_name, "status", "disabled");
|
|
|
|
qemu_devtree_setprop_string(fdt, cpu_name, "enable-method", "spin-table");
|
2012-05-18 03:56:46 +04:00
|
|
|
qemu_devtree_setprop_u64(fdt, cpu_name, "cpu-release-addr",
|
|
|
|
cpu_release_addr);
|
2011-07-23 12:56:40 +04:00
|
|
|
} else {
|
|
|
|
qemu_devtree_setprop_string(fdt, cpu_name, "status", "okay");
|
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
}
|
|
|
|
|
2012-05-17 16:51:34 +04:00
|
|
|
qemu_devtree_add_subnode(fdt, "/aliases");
|
2012-05-17 16:51:07 +04:00
|
|
|
/* XXX These should go into their respective devices' code */
|
2012-06-06 02:30:36 +04:00
|
|
|
snprintf(soc, sizeof(soc), "/soc@%llx", MPC8544_CCSRBAR_BASE);
|
2012-05-17 16:51:07 +04:00
|
|
|
qemu_devtree_add_subnode(fdt, soc);
|
|
|
|
qemu_devtree_setprop_string(fdt, soc, "device_type", "soc");
|
2012-06-06 02:20:20 +04:00
|
|
|
qemu_devtree_setprop(fdt, soc, "compatible", compatible_sb,
|
|
|
|
sizeof(compatible_sb));
|
2012-05-17 16:51:07 +04:00
|
|
|
qemu_devtree_setprop_cell(fdt, soc, "#address-cells", 1);
|
|
|
|
qemu_devtree_setprop_cell(fdt, soc, "#size-cells", 1);
|
2012-06-06 02:25:06 +04:00
|
|
|
qemu_devtree_setprop_cells(fdt, soc, "ranges", 0x0,
|
|
|
|
MPC8544_CCSRBAR_BASE >> 32, MPC8544_CCSRBAR_BASE,
|
2012-05-17 16:51:07 +04:00
|
|
|
MPC8544_CCSRBAR_SIZE);
|
|
|
|
/* XXX should contain a reasonable value */
|
|
|
|
qemu_devtree_setprop_cell(fdt, soc, "bus-frequency", 0);
|
|
|
|
|
2012-10-10 08:28:27 +04:00
|
|
|
snprintf(mpic, sizeof(mpic), "%s/pic@%llx", soc, MPC8544_MPIC_REGS_OFFSET);
|
2012-05-17 16:51:51 +04:00
|
|
|
qemu_devtree_add_subnode(fdt, mpic);
|
|
|
|
qemu_devtree_setprop_string(fdt, mpic, "device_type", "open-pic");
|
2012-08-10 00:57:14 +04:00
|
|
|
qemu_devtree_setprop_string(fdt, mpic, "compatible", "chrp,open-pic");
|
2012-10-10 08:28:27 +04:00
|
|
|
qemu_devtree_setprop_cells(fdt, mpic, "reg", MPC8544_MPIC_REGS_OFFSET,
|
|
|
|
0x40000);
|
2012-05-17 16:51:51 +04:00
|
|
|
qemu_devtree_setprop_cell(fdt, mpic, "#address-cells", 0);
|
2012-08-10 00:57:14 +04:00
|
|
|
qemu_devtree_setprop_cell(fdt, mpic, "#interrupt-cells", 2);
|
2012-05-17 16:51:51 +04:00
|
|
|
mpic_ph = qemu_devtree_alloc_phandle(fdt);
|
|
|
|
qemu_devtree_setprop_cell(fdt, mpic, "phandle", mpic_ph);
|
|
|
|
qemu_devtree_setprop_cell(fdt, mpic, "linux,phandle", mpic_ph);
|
|
|
|
qemu_devtree_setprop(fdt, mpic, "interrupt-controller", NULL, 0);
|
|
|
|
|
2012-05-17 16:51:34 +04:00
|
|
|
/*
|
|
|
|
* We have to generate ser1 first, because Linux takes the first
|
|
|
|
* device it finds in the dt as serial output device. And we generate
|
|
|
|
* devices in reverse order to the dt.
|
|
|
|
*/
|
2012-10-10 08:28:27 +04:00
|
|
|
dt_serial_create(fdt, MPC8544_SERIAL1_REGS_OFFSET,
|
2012-06-06 03:19:40 +04:00
|
|
|
soc, mpic, "serial1", 1, false);
|
2012-10-10 08:28:27 +04:00
|
|
|
dt_serial_create(fdt, MPC8544_SERIAL0_REGS_OFFSET,
|
2012-06-06 03:19:40 +04:00
|
|
|
soc, mpic, "serial0", 0, true);
|
2012-05-17 16:51:34 +04:00
|
|
|
|
2012-06-06 02:30:36 +04:00
|
|
|
snprintf(gutil, sizeof(gutil), "%s/global-utilities@%llx", soc,
|
2012-10-10 08:28:27 +04:00
|
|
|
MPC8544_UTIL_OFFSET);
|
2012-05-17 16:52:46 +04:00
|
|
|
qemu_devtree_add_subnode(fdt, gutil);
|
|
|
|
qemu_devtree_setprop_string(fdt, gutil, "compatible", "fsl,mpc8544-guts");
|
2012-10-10 08:28:27 +04:00
|
|
|
qemu_devtree_setprop_cells(fdt, gutil, "reg", MPC8544_UTIL_OFFSET, 0x1000);
|
2012-05-17 16:52:46 +04:00
|
|
|
qemu_devtree_setprop(fdt, gutil, "fsl,has-rstcr", NULL, 0);
|
|
|
|
|
2012-12-08 17:26:37 +04:00
|
|
|
snprintf(msi, sizeof(msi), "/%s/msi@%llx", soc, MPC8544_MSI_REGS_OFFSET);
|
|
|
|
qemu_devtree_add_subnode(fdt, msi);
|
|
|
|
qemu_devtree_setprop_string(fdt, msi, "compatible", "fsl,mpic-msi");
|
|
|
|
qemu_devtree_setprop_cells(fdt, msi, "reg", MPC8544_MSI_REGS_OFFSET, 0x200);
|
|
|
|
msi_ph = qemu_devtree_alloc_phandle(fdt);
|
|
|
|
qemu_devtree_setprop_cells(fdt, msi, "msi-available-ranges", 0x0, 0x100);
|
|
|
|
qemu_devtree_setprop_phandle(fdt, msi, "interrupt-parent", mpic);
|
|
|
|
qemu_devtree_setprop_cells(fdt, msi, "interrupts",
|
|
|
|
0xe0, 0x0,
|
|
|
|
0xe1, 0x0,
|
|
|
|
0xe2, 0x0,
|
|
|
|
0xe3, 0x0,
|
|
|
|
0xe4, 0x0,
|
|
|
|
0xe5, 0x0,
|
|
|
|
0xe6, 0x0,
|
|
|
|
0xe7, 0x0);
|
|
|
|
qemu_devtree_setprop_cell(fdt, msi, "phandle", msi_ph);
|
|
|
|
qemu_devtree_setprop_cell(fdt, msi, "linux,phandle", msi_ph);
|
|
|
|
|
2012-06-06 02:30:36 +04:00
|
|
|
snprintf(pci, sizeof(pci), "/pci@%llx", MPC8544_PCI_REGS_BASE);
|
2012-05-17 17:34:34 +04:00
|
|
|
qemu_devtree_add_subnode(fdt, pci);
|
|
|
|
qemu_devtree_setprop_cell(fdt, pci, "cell-index", 0);
|
|
|
|
qemu_devtree_setprop_string(fdt, pci, "compatible", "fsl,mpc8540-pci");
|
|
|
|
qemu_devtree_setprop_string(fdt, pci, "device_type", "pci");
|
|
|
|
qemu_devtree_setprop_cells(fdt, pci, "interrupt-map-mask", 0xf800, 0x0,
|
|
|
|
0x0, 0x7);
|
2012-12-12 16:47:07 +04:00
|
|
|
pci_map = pci_map_create(fdt, qemu_devtree_get_phandle(fdt, mpic),
|
2012-12-12 16:53:53 +04:00
|
|
|
params->pci_first_slot, params->pci_nr_slots,
|
|
|
|
&len);
|
2012-12-12 16:47:07 +04:00
|
|
|
qemu_devtree_setprop(fdt, pci, "interrupt-map", pci_map, len);
|
2012-05-17 17:34:34 +04:00
|
|
|
qemu_devtree_setprop_phandle(fdt, pci, "interrupt-parent", mpic);
|
2012-08-10 00:57:14 +04:00
|
|
|
qemu_devtree_setprop_cells(fdt, pci, "interrupts", 24, 2);
|
2012-05-17 17:34:34 +04:00
|
|
|
qemu_devtree_setprop_cells(fdt, pci, "bus-range", 0, 255);
|
2012-06-06 02:25:06 +04:00
|
|
|
for (i = 0; i < 14; i++) {
|
2012-05-17 17:34:34 +04:00
|
|
|
pci_ranges[i] = cpu_to_be32(pci_ranges[i]);
|
|
|
|
}
|
2012-12-08 17:26:37 +04:00
|
|
|
qemu_devtree_setprop_cell(fdt, pci, "fsl,msi", msi_ph);
|
2012-05-17 17:34:34 +04:00
|
|
|
qemu_devtree_setprop(fdt, pci, "ranges", pci_ranges, sizeof(pci_ranges));
|
2012-06-06 02:25:06 +04:00
|
|
|
qemu_devtree_setprop_cells(fdt, pci, "reg", MPC8544_PCI_REGS_BASE >> 32,
|
|
|
|
MPC8544_PCI_REGS_BASE, 0, 0x1000);
|
2012-05-17 17:34:34 +04:00
|
|
|
qemu_devtree_setprop_cell(fdt, pci, "clock-frequency", 66666666);
|
|
|
|
qemu_devtree_setprop_cell(fdt, pci, "#interrupt-cells", 1);
|
|
|
|
qemu_devtree_setprop_cell(fdt, pci, "#size-cells", 2);
|
|
|
|
qemu_devtree_setprop_cell(fdt, pci, "#address-cells", 3);
|
|
|
|
qemu_devtree_setprop_string(fdt, "/aliases", "pci0", pci);
|
|
|
|
|
2012-07-02 17:03:20 +04:00
|
|
|
params->fixup_devtree(params, fdt);
|
|
|
|
|
|
|
|
if (toplevel_compat) {
|
|
|
|
qemu_devtree_setprop(fdt, "/", "compatible", toplevel_compat,
|
|
|
|
strlen(toplevel_compat) + 1);
|
|
|
|
}
|
|
|
|
|
2012-05-22 16:28:50 +04:00
|
|
|
done:
|
2012-09-23 10:37:59 +04:00
|
|
|
qemu_devtree_dumpdtb(fdt, fdt_size);
|
2010-02-02 11:49:02 +03:00
|
|
|
ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
|
2012-05-19 02:48:50 +04:00
|
|
|
if (ret < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(fdt);
|
2012-05-19 02:48:50 +04:00
|
|
|
ret = fdt_size;
|
2009-04-10 20:23:59 +04:00
|
|
|
|
2009-03-02 19:42:42 +03:00
|
|
|
out:
|
2012-12-12 16:47:07 +04:00
|
|
|
g_free(pci_map);
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2010-02-02 11:49:02 +03:00
|
|
|
return ret;
|
2009-03-02 19:42:42 +03:00
|
|
|
}
|
|
|
|
|
2012-05-19 02:48:50 +04:00
|
|
|
/* Create -kernel TLB entries for BookE. */
|
2012-10-23 14:30:10 +04:00
|
|
|
static inline hwaddr booke206_page_size_to_tlb(uint64_t size)
|
2011-06-16 20:45:43 +04:00
|
|
|
{
|
2012-05-19 02:48:50 +04:00
|
|
|
return 63 - clz64(size >> 10);
|
2011-06-16 20:45:43 +04:00
|
|
|
}
|
|
|
|
|
2012-05-19 02:48:50 +04:00
|
|
|
static void mmubooke_create_initial_mapping(CPUPPCState *env)
|
2011-05-01 01:34:53 +04:00
|
|
|
{
|
2012-05-19 02:48:50 +04:00
|
|
|
struct boot_info *bi = env->load_info;
|
2011-06-16 20:45:43 +04:00
|
|
|
ppcmas_tlb_t *tlb = booke206_get_tlbm(env, 1, 0, 0);
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr size, dt_end;
|
2012-05-19 02:48:50 +04:00
|
|
|
int ps;
|
|
|
|
|
|
|
|
/* Our initial TLB entry needs to cover everything from 0 to
|
|
|
|
the device tree top */
|
|
|
|
dt_end = bi->dt_base + bi->dt_size;
|
|
|
|
ps = booke206_page_size_to_tlb(dt_end) + 1;
|
2012-10-04 20:52:21 +04:00
|
|
|
if (ps & 1) {
|
|
|
|
/* e500v2 can only do even TLB size bits */
|
|
|
|
ps++;
|
|
|
|
}
|
2012-05-19 02:48:50 +04:00
|
|
|
size = (ps << MAS1_TSIZE_SHIFT);
|
2011-06-16 20:45:43 +04:00
|
|
|
tlb->mas1 = MAS1_VALID | size;
|
2012-05-19 02:48:50 +04:00
|
|
|
tlb->mas2 = 0;
|
|
|
|
tlb->mas7_3 = 0;
|
2011-06-16 20:45:43 +04:00
|
|
|
tlb->mas7_3 |= MAS3_UR | MAS3_UW | MAS3_UX | MAS3_SR | MAS3_SW | MAS3_SX;
|
2011-08-31 15:26:56 +04:00
|
|
|
|
|
|
|
env->tlb_dirty = true;
|
2011-05-01 01:34:53 +04:00
|
|
|
}
|
|
|
|
|
2012-07-02 17:03:19 +04:00
|
|
|
static void ppce500_cpu_reset_sec(void *opaque)
|
2011-07-22 15:32:29 +04:00
|
|
|
{
|
2012-05-04 04:09:06 +04:00
|
|
|
PowerPCCPU *cpu = opaque;
|
|
|
|
CPUPPCState *env = &cpu->env;
|
2011-07-22 15:32:29 +04:00
|
|
|
|
2012-05-04 04:09:06 +04:00
|
|
|
cpu_reset(CPU(cpu));
|
2011-07-22 15:32:29 +04:00
|
|
|
|
|
|
|
/* Secondary CPU starts in halted state for now. Needs to change when
|
|
|
|
implementing non-kernel boot. */
|
|
|
|
env->halted = 1;
|
|
|
|
env->exception_index = EXCP_HLT;
|
2011-05-01 01:34:53 +04:00
|
|
|
}
|
|
|
|
|
2012-07-02 17:03:19 +04:00
|
|
|
static void ppce500_cpu_reset(void *opaque)
|
2011-05-01 01:34:53 +04:00
|
|
|
{
|
2012-05-04 04:09:06 +04:00
|
|
|
PowerPCCPU *cpu = opaque;
|
|
|
|
CPUPPCState *env = &cpu->env;
|
2011-05-01 01:34:53 +04:00
|
|
|
struct boot_info *bi = env->load_info;
|
|
|
|
|
2012-05-04 04:09:06 +04:00
|
|
|
cpu_reset(CPU(cpu));
|
2011-05-01 01:34:53 +04:00
|
|
|
|
|
|
|
/* Set initial guest state. */
|
2011-07-22 15:32:29 +04:00
|
|
|
env->halted = 0;
|
2011-05-01 01:34:53 +04:00
|
|
|
env->gpr[1] = (16<<20) - 8;
|
|
|
|
env->gpr[3] = bi->dt_base;
|
|
|
|
env->nip = bi->entry;
|
2012-05-19 02:48:50 +04:00
|
|
|
mmubooke_create_initial_mapping(env);
|
2011-05-01 01:34:53 +04:00
|
|
|
}
|
|
|
|
|
2012-07-02 17:03:20 +04:00
|
|
|
void ppce500_init(PPCE500Params *params)
|
2009-03-02 19:42:42 +03:00
|
|
|
{
|
2011-08-12 03:07:16 +04:00
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
2011-10-02 18:43:01 +04:00
|
|
|
MemoryRegion *ram = g_new(MemoryRegion, 1);
|
2009-03-02 19:42:42 +03:00
|
|
|
PCIBus *pci_bus;
|
2012-03-14 04:38:23 +04:00
|
|
|
CPUPPCState *env = NULL;
|
2009-03-02 19:42:42 +03:00
|
|
|
uint64_t elf_entry;
|
|
|
|
uint64_t elf_lowaddr;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr entry=0;
|
|
|
|
hwaddr loadaddr=UIMAGE_LOAD_BASE;
|
2009-03-02 19:42:42 +03:00
|
|
|
target_long kernel_size=0;
|
2010-02-02 11:49:03 +03:00
|
|
|
target_ulong dt_base = 0;
|
|
|
|
target_ulong initrd_base = 0;
|
2009-03-02 19:42:42 +03:00
|
|
|
target_long initrd_size=0;
|
2012-12-08 08:17:14 +04:00
|
|
|
int i = 0, j, k;
|
2009-03-02 19:42:42 +03:00
|
|
|
unsigned int pci_irq_nrs[4] = {1, 2, 3, 4};
|
2011-07-21 03:42:58 +04:00
|
|
|
qemu_irq **irqs, *mpic;
|
2010-08-31 02:22:28 +04:00
|
|
|
DeviceState *dev;
|
2012-03-14 04:38:23 +04:00
|
|
|
CPUPPCState *firstenv = NULL;
|
2012-10-10 08:28:28 +04:00
|
|
|
MemoryRegion *ccsr_addr_space;
|
2012-10-10 08:28:27 +04:00
|
|
|
SysBusDevice *s;
|
2012-10-10 08:28:28 +04:00
|
|
|
PPCE500CCSRState *ccsr;
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2011-07-21 03:41:16 +04:00
|
|
|
/* Setup CPUs */
|
2012-07-02 17:03:20 +04:00
|
|
|
if (params->cpu_model == NULL) {
|
|
|
|
params->cpu_model = "e500v2_v30";
|
2011-05-01 01:05:03 +04:00
|
|
|
}
|
|
|
|
|
2011-07-21 03:42:58 +04:00
|
|
|
irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
|
|
|
|
irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
|
2011-07-21 03:41:16 +04:00
|
|
|
for (i = 0; i < smp_cpus; i++) {
|
2012-05-03 07:43:05 +04:00
|
|
|
PowerPCCPU *cpu;
|
2011-07-21 03:41:16 +04:00
|
|
|
qemu_irq *input;
|
2012-05-03 07:43:05 +04:00
|
|
|
|
2012-07-02 17:03:20 +04:00
|
|
|
cpu = cpu_ppc_init(params->cpu_model);
|
2012-05-03 07:43:05 +04:00
|
|
|
if (cpu == NULL) {
|
2011-07-21 03:41:16 +04:00
|
|
|
fprintf(stderr, "Unable to initialize CPU!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-05-03 07:43:05 +04:00
|
|
|
env = &cpu->env;
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2011-07-21 03:41:16 +04:00
|
|
|
if (!firstenv) {
|
|
|
|
firstenv = env;
|
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2011-07-21 03:42:58 +04:00
|
|
|
irqs[i] = irqs[0] + (i * OPENPIC_OUTPUT_NB);
|
|
|
|
input = (qemu_irq *)env->irq_inputs;
|
|
|
|
irqs[i][OPENPIC_OUTPUT_INT] = input[PPCE500_INPUT_INT];
|
|
|
|
irqs[i][OPENPIC_OUTPUT_CINT] = input[PPCE500_INPUT_CINT];
|
2011-07-21 03:41:16 +04:00
|
|
|
env->spr[SPR_BOOKE_PIR] = env->cpu_index = i;
|
2012-10-10 08:28:27 +04:00
|
|
|
env->mpic_cpu_base = MPC8544_CCSRBAR_BASE +
|
|
|
|
MPC8544_MPIC_REGS_OFFSET + 0x20000;
|
2011-05-01 01:34:53 +04:00
|
|
|
|
2012-12-01 07:43:18 +04:00
|
|
|
ppc_booke_timers_init(cpu, 400000000, PPC_TIMER_E500);
|
2011-07-21 03:41:16 +04:00
|
|
|
|
|
|
|
/* Register reset handler */
|
2011-07-22 15:32:29 +04:00
|
|
|
if (!i) {
|
|
|
|
/* Primary CPU */
|
|
|
|
struct boot_info *boot_info;
|
|
|
|
boot_info = g_malloc0(sizeof(struct boot_info));
|
2012-07-02 17:03:19 +04:00
|
|
|
qemu_register_reset(ppce500_cpu_reset, cpu);
|
2011-07-22 15:32:29 +04:00
|
|
|
env->load_info = boot_info;
|
|
|
|
} else {
|
|
|
|
/* Secondary CPUs */
|
2012-07-02 17:03:19 +04:00
|
|
|
qemu_register_reset(ppce500_cpu_reset_sec, cpu);
|
2011-07-22 15:32:29 +04:00
|
|
|
}
|
2011-07-21 03:41:16 +04:00
|
|
|
}
|
2011-05-01 01:34:53 +04:00
|
|
|
|
2011-07-21 03:41:16 +04:00
|
|
|
env = firstenv;
|
2011-05-01 01:34:53 +04:00
|
|
|
|
2009-03-02 19:42:42 +03:00
|
|
|
/* Fixup Memory size on a alignment boundary */
|
|
|
|
ram_size &= ~(RAM_SIZES_ALIGN - 1);
|
|
|
|
|
|
|
|
/* Register Memory */
|
2011-12-20 17:59:12 +04:00
|
|
|
memory_region_init_ram(ram, "mpc8544ds.ram", ram_size);
|
|
|
|
vmstate_register_ram_global(ram);
|
2011-10-02 18:43:01 +04:00
|
|
|
memory_region_add_subregion(address_space_mem, 0, ram);
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2012-10-10 08:28:28 +04:00
|
|
|
dev = qdev_create(NULL, "e500-ccsr");
|
|
|
|
object_property_add_child(qdev_get_machine(), "e500-ccsr",
|
|
|
|
OBJECT(dev), NULL);
|
|
|
|
qdev_init_nofail(dev);
|
|
|
|
ccsr = CCSR(dev);
|
|
|
|
ccsr_addr_space = &ccsr->ccsr_space;
|
|
|
|
memory_region_add_subregion(address_space_mem, MPC8544_CCSRBAR_BASE,
|
|
|
|
ccsr_addr_space);
|
2012-10-10 08:28:27 +04:00
|
|
|
|
2009-03-02 19:42:42 +03:00
|
|
|
/* MPIC */
|
2012-12-08 08:17:14 +04:00
|
|
|
mpic = g_new(qemu_irq, 256);
|
|
|
|
dev = qdev_create(NULL, "openpic");
|
|
|
|
qdev_prop_set_uint32(dev, "nb_cpus", smp_cpus);
|
|
|
|
qdev_prop_set_uint32(dev, "model", OPENPIC_MODEL_FSL_MPIC_20);
|
|
|
|
qdev_init_nofail(dev);
|
|
|
|
s = sysbus_from_qdev(dev);
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
for (i = 0; i < smp_cpus; i++) {
|
|
|
|
for (j = 0; j < OPENPIC_OUTPUT_NB; j++) {
|
|
|
|
sysbus_connect_irq(s, k++, irqs[i][j]);
|
|
|
|
}
|
|
|
|
}
|
2011-07-21 03:42:58 +04:00
|
|
|
|
2012-12-08 08:17:14 +04:00
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
mpic[i] = qdev_get_gpio_in(dev, i);
|
2011-07-21 03:42:58 +04:00
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2012-12-08 08:17:14 +04:00
|
|
|
memory_region_add_subregion(ccsr_addr_space, MPC8544_MPIC_REGS_OFFSET,
|
|
|
|
s->mmio[0].memory);
|
|
|
|
|
2009-03-02 19:42:42 +03:00
|
|
|
/* Serial */
|
2010-03-21 22:47:11 +03:00
|
|
|
if (serial_hds[0]) {
|
2012-10-10 08:28:28 +04:00
|
|
|
serial_mm_init(ccsr_addr_space, MPC8544_SERIAL0_REGS_OFFSET,
|
2012-12-07 19:10:34 +04:00
|
|
|
0, mpic[42], 399193,
|
2011-08-12 03:07:15 +04:00
|
|
|
serial_hds[0], DEVICE_BIG_ENDIAN);
|
2010-03-21 22:47:11 +03:00
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2010-03-21 22:47:11 +03:00
|
|
|
if (serial_hds[1]) {
|
2012-10-10 08:28:28 +04:00
|
|
|
serial_mm_init(ccsr_addr_space, MPC8544_SERIAL1_REGS_OFFSET,
|
2012-12-07 19:10:34 +04:00
|
|
|
0, mpic[42], 399193,
|
2012-10-08 10:46:54 +04:00
|
|
|
serial_hds[1], DEVICE_BIG_ENDIAN);
|
2010-03-21 22:47:11 +03:00
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
|
2011-06-02 15:53:40 +04:00
|
|
|
/* General Utility device */
|
2012-10-10 08:28:27 +04:00
|
|
|
dev = qdev_create(NULL, "mpc8544-guts");
|
|
|
|
qdev_init_nofail(dev);
|
|
|
|
s = SYS_BUS_DEVICE(dev);
|
2012-10-10 08:28:28 +04:00
|
|
|
memory_region_add_subregion(ccsr_addr_space, MPC8544_UTIL_OFFSET,
|
2012-10-10 08:28:27 +04:00
|
|
|
sysbus_mmio_get_region(s, 0));
|
2011-06-02 15:53:40 +04:00
|
|
|
|
2009-03-02 19:42:42 +03:00
|
|
|
/* PCI */
|
2012-10-10 08:28:27 +04:00
|
|
|
dev = qdev_create(NULL, "e500-pcihost");
|
2012-12-12 16:53:53 +04:00
|
|
|
qdev_prop_set_uint32(dev, "first_slot", params->pci_first_slot);
|
2012-10-10 08:28:27 +04:00
|
|
|
qdev_init_nofail(dev);
|
|
|
|
s = SYS_BUS_DEVICE(dev);
|
|
|
|
sysbus_connect_irq(s, 0, mpic[pci_irq_nrs[0]]);
|
|
|
|
sysbus_connect_irq(s, 1, mpic[pci_irq_nrs[1]]);
|
|
|
|
sysbus_connect_irq(s, 2, mpic[pci_irq_nrs[2]]);
|
|
|
|
sysbus_connect_irq(s, 3, mpic[pci_irq_nrs[3]]);
|
2012-10-10 08:28:28 +04:00
|
|
|
memory_region_add_subregion(ccsr_addr_space, MPC8544_PCI_REGS_OFFSET,
|
2012-10-10 08:28:27 +04:00
|
|
|
sysbus_mmio_get_region(s, 0));
|
|
|
|
|
2011-05-27 05:23:26 +04:00
|
|
|
pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");
|
2009-03-02 19:42:42 +03:00
|
|
|
if (!pci_bus)
|
|
|
|
printf("couldn't create PCI controller!\n");
|
|
|
|
|
2012-10-08 14:21:30 +04:00
|
|
|
sysbus_mmio_map(sysbus_from_qdev(dev), 1, MPC8544_PCI_IO);
|
2009-03-02 19:42:42 +03:00
|
|
|
|
|
|
|
if (pci_bus) {
|
|
|
|
/* Register network interfaces. */
|
|
|
|
for (i = 0; i < nb_nics; i++) {
|
2009-09-25 05:53:51 +04:00
|
|
|
pci_nic_init_nofail(&nd_table[i], "virtio", NULL);
|
2009-03-02 19:42:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-22 15:32:29 +04:00
|
|
|
/* Register spinning region */
|
|
|
|
sysbus_create_simple("e500-spin", MPC8544_SPIN_BASE, NULL);
|
|
|
|
|
2009-03-02 19:42:42 +03:00
|
|
|
/* Load kernel. */
|
2012-07-02 17:03:20 +04:00
|
|
|
if (params->kernel_filename) {
|
|
|
|
kernel_size = load_uimage(params->kernel_filename, &entry,
|
|
|
|
&loadaddr, NULL);
|
2009-03-02 19:42:42 +03:00
|
|
|
if (kernel_size < 0) {
|
2012-07-02 17:03:20 +04:00
|
|
|
kernel_size = load_elf(params->kernel_filename, NULL, NULL,
|
|
|
|
&elf_entry, &elf_lowaddr, NULL, 1,
|
|
|
|
ELF_MACHINE, 0);
|
2009-03-02 19:42:42 +03: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",
|
2012-07-02 17:03:20 +04:00
|
|
|
params->kernel_filename);
|
2009-03-02 19:42:42 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load initrd. */
|
2012-07-02 17:03:20 +04:00
|
|
|
if (params->initrd_filename) {
|
2012-08-22 18:55:41 +04:00
|
|
|
initrd_base = (loadaddr + kernel_size + INITRD_LOAD_PAD) &
|
|
|
|
~INITRD_PAD_MASK;
|
2012-07-02 17:03:20 +04:00
|
|
|
initrd_size = load_image_targphys(params->initrd_filename, initrd_base,
|
2009-04-10 07:36:49 +04:00
|
|
|
ram_size - initrd_base);
|
2009-03-02 19:42:42 +03:00
|
|
|
|
|
|
|
if (initrd_size < 0) {
|
|
|
|
fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
2012-07-02 17:03:20 +04:00
|
|
|
params->initrd_filename);
|
2009-03-02 19:42:42 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're loading a kernel directly, we must load the device tree too. */
|
2012-07-02 17:03:20 +04:00
|
|
|
if (params->kernel_filename) {
|
2011-07-22 15:32:29 +04:00
|
|
|
struct boot_info *boot_info;
|
2012-05-19 02:48:50 +04:00
|
|
|
int dt_size;
|
2011-07-22 15:32:29 +04:00
|
|
|
|
2012-05-19 02:48:50 +04:00
|
|
|
dt_base = (loadaddr + kernel_size + DTC_LOAD_PAD) & ~DTC_PAD_MASK;
|
2012-07-02 17:03:20 +04:00
|
|
|
dt_size = ppce500_load_device_tree(env, params, dt_base, initrd_base,
|
|
|
|
initrd_size);
|
2012-05-19 02:48:50 +04:00
|
|
|
if (dt_size < 0) {
|
2009-03-02 19:42:42 +03:00
|
|
|
fprintf(stderr, "couldn't load device tree\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-07-21 03:41:16 +04:00
|
|
|
boot_info = env->load_info;
|
2011-05-01 01:34:53 +04:00
|
|
|
boot_info->entry = entry;
|
|
|
|
boot_info->dt_base = dt_base;
|
2012-05-19 02:48:50 +04:00
|
|
|
boot_info->dt_size = dt_size;
|
2009-03-02 19:42:42 +03:00
|
|
|
}
|
|
|
|
|
2011-05-01 01:34:53 +04:00
|
|
|
if (kvm_enabled()) {
|
2009-03-02 19:42:42 +03:00
|
|
|
kvmppc_init();
|
2011-05-01 01:34:53 +04:00
|
|
|
}
|
2009-03-02 19:42:42 +03:00
|
|
|
}
|
2012-10-10 08:28:28 +04:00
|
|
|
|
|
|
|
static int e500_ccsr_initfn(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
PPCE500CCSRState *ccsr;
|
|
|
|
|
|
|
|
ccsr = CCSR(dev);
|
|
|
|
memory_region_init(&ccsr->ccsr_space, "e500-ccsr",
|
|
|
|
MPC8544_CCSRBAR_SIZE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void e500_ccsr_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
k->init = e500_ccsr_initfn;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo e500_ccsr_info = {
|
|
|
|
.name = TYPE_CCSR,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(PPCE500CCSRState),
|
|
|
|
.class_init = e500_ccsr_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void e500_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&e500_ccsr_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(e500_register_types)
|