2009-03-02 17:42:42 +01:00
|
|
|
/*
|
2012-07-02 15:03:19 +02:00
|
|
|
* QEMU PowerPC e500-based platforms
|
2009-03-02 17:42:42 +01: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 15:03:20 +02:00
|
|
|
#include "e500.h"
|
2012-10-10 06:28:28 +02:00
|
|
|
#include "e500-ccsr.h"
|
2012-10-24 08:43:34 +02:00
|
|
|
#include "net/net.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/config-file.h"
|
2012-07-02 15:03:18 +02:00
|
|
|
#include "hw/hw.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/char/serial.h"
|
2012-12-12 13:24:50 +01:00
|
|
|
#include "hw/pci/pci.h"
|
2012-07-02 15:03:18 +02:00
|
|
|
#include "hw/boards.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
#include "sysemu/kvm.h"
|
2009-03-02 17:42:42 +01:00
|
|
|
#include "kvm_ppc.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/device_tree.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/ppc/openpic.h"
|
|
|
|
#include "hw/ppc/ppc.h"
|
2012-07-02 15:03:18 +02:00
|
|
|
#include "hw/loader.h"
|
2009-09-20 16:58:02 +02:00
|
|
|
#include "elf.h"
|
2012-07-02 15:03:18 +02:00
|
|
|
#include "hw/sysbus.h"
|
2012-12-17 18:19:49 +01:00
|
|
|
#include "exec/address-spaces.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/host-utils.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/pci-host/ppce500.h"
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2013-04-29 06:40:56 +02:00
|
|
|
#define EPAPR_MAGIC (0x45504150)
|
2009-03-02 17:42:42 +01:00
|
|
|
#define BINARY_DEVICE_TREE_FILE "mpc8544ds.dtb"
|
2012-08-22 16:55:40 +02:00
|
|
|
#define DTC_LOAD_PAD 0x1800000
|
2010-02-02 09:49:03 +01:00
|
|
|
#define DTC_PAD_MASK 0xFFFFF
|
2013-01-17 11:19:28 +01:00
|
|
|
#define DTB_MAX_SIZE (8 * 1024 * 1024)
|
2010-02-02 09:49:03 +01:00
|
|
|
#define INITRD_LOAD_PAD 0x2000000
|
|
|
|
#define INITRD_PAD_MASK 0xFFFFFF
|
2009-03-02 17:42:42 +01:00
|
|
|
|
|
|
|
#define RAM_SIZES_ALIGN (64UL << 20)
|
|
|
|
|
2012-07-02 15:03:19 +02:00
|
|
|
/* TODO: parameterize */
|
2012-06-06 00:30:36 +02:00
|
|
|
#define MPC8544_CCSRBAR_BASE 0xE0000000ULL
|
|
|
|
#define MPC8544_CCSRBAR_SIZE 0x00100000ULL
|
2012-10-10 06:28:27 +02:00
|
|
|
#define MPC8544_MPIC_REGS_OFFSET 0x40000ULL
|
2012-12-08 14:26:37 +01:00
|
|
|
#define MPC8544_MSI_REGS_OFFSET 0x41600ULL
|
2012-10-10 06:28:27 +02: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 00:30:36 +02:00
|
|
|
#define MPC8544_PCI_REGS_SIZE 0x1000ULL
|
|
|
|
#define MPC8544_PCI_IO 0xE1000000ULL
|
2012-10-10 06:28:27 +02:00
|
|
|
#define MPC8544_UTIL_OFFSET 0xe0000ULL
|
2012-06-06 00:30:36 +02:00
|
|
|
#define MPC8544_SPIN_BASE 0xEF000000ULL
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2011-04-30 23:34:53 +02:00
|
|
|
struct boot_info
|
|
|
|
{
|
|
|
|
uint32_t dt_base;
|
2012-05-19 00:48:50 +02:00
|
|
|
uint32_t dt_size;
|
2011-04-30 23:34:53 +02:00
|
|
|
uint32_t entry;
|
|
|
|
};
|
|
|
|
|
2012-12-12 13:47:07 +01:00
|
|
|
static uint32_t *pci_map_create(void *fdt, uint32_t mpic, int first_slot,
|
|
|
|
int nr_slots, int *len)
|
2012-05-17 15:34:34 +02:00
|
|
|
{
|
2012-12-12 13:47:07 +01:00
|
|
|
int i = 0;
|
|
|
|
int slot;
|
|
|
|
int pci_irq;
|
2012-12-13 01:16:24 +01:00
|
|
|
int host_irq;
|
2012-12-12 13:47:07 +01: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 01:16:24 +01:00
|
|
|
host_irq = ppce500_pci_map_irq_slot(slot, pci_irq);
|
|
|
|
pci_map[i++] = cpu_to_be32(host_irq + 1);
|
2012-12-12 13:47:07 +01:00
|
|
|
pci_map[i++] = cpu_to_be32(0x1);
|
|
|
|
}
|
2012-05-17 15:34:34 +02:00
|
|
|
}
|
2012-12-12 13:47:07 +01:00
|
|
|
|
|
|
|
assert((i * sizeof(uint32_t)) == *len);
|
|
|
|
|
|
|
|
return pci_map;
|
2012-05-17 15:34:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-06 01:19:40 +02: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);
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, ser);
|
|
|
|
qemu_fdt_setprop_string(fdt, ser, "device_type", "serial");
|
|
|
|
qemu_fdt_setprop_string(fdt, ser, "compatible", "ns16550");
|
|
|
|
qemu_fdt_setprop_cells(fdt, ser, "reg", offset, 0x100);
|
|
|
|
qemu_fdt_setprop_cell(fdt, ser, "cell-index", idx);
|
|
|
|
qemu_fdt_setprop_cell(fdt, ser, "clock-frequency", 0);
|
|
|
|
qemu_fdt_setprop_cells(fdt, ser, "interrupts", 42, 2);
|
|
|
|
qemu_fdt_setprop_phandle(fdt, ser, "interrupt-parent", mpic);
|
|
|
|
qemu_fdt_setprop_string(fdt, "/aliases", alias, ser);
|
2012-06-06 01:19:40 +02:00
|
|
|
|
|
|
|
if (defcon) {
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop_string(fdt, "/chosen", "linux,stdout-path", ser);
|
2012-06-06 01:19:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 16:42:57 +02:00
|
|
|
static int ppce500_load_device_tree(MachineState *machine,
|
2012-07-02 15:03:20 +02:00
|
|
|
PPCE500Params *params,
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr addr,
|
|
|
|
hwaddr initrd_base,
|
2013-07-19 12:56:24 +02:00
|
|
|
hwaddr initrd_size,
|
2014-01-20 00:21:04 +01:00
|
|
|
hwaddr kernel_base,
|
|
|
|
hwaddr kernel_size,
|
2013-07-19 12:56:24 +02:00
|
|
|
bool dry_run)
|
2009-03-02 17:42:42 +01:00
|
|
|
{
|
2013-07-19 12:56:24 +02:00
|
|
|
CPUPPCState *env = first_cpu->env_ptr;
|
2010-02-27 19:47:22 +01:00
|
|
|
int ret = -1;
|
2014-05-07 16:42:57 +02:00
|
|
|
uint64_t mem_reg_property[] = { 0, cpu_to_be64(machine->ram_size) };
|
2009-04-10 18:23:59 +02:00
|
|
|
int fdt_size;
|
2010-02-27 19:47:22 +01:00
|
|
|
void *fdt;
|
2011-06-15 23:34:04 +02:00
|
|
|
uint8_t hypercall[16];
|
2011-07-21 02:34:11 +02:00
|
|
|
uint32_t clock_freq = 400000000;
|
|
|
|
uint32_t tb_freq = 400000000;
|
2011-07-21 03:01:11 +02:00
|
|
|
int i;
|
2012-06-06 00:20:20 +02:00
|
|
|
char compatible_sb[] = "fsl,mpc8544-immr\0simple-bus";
|
2012-05-17 14:51:07 +02:00
|
|
|
char soc[128];
|
2012-05-17 14:51:51 +02:00
|
|
|
char mpic[128];
|
|
|
|
uint32_t mpic_ph;
|
2012-12-08 14:26:37 +01:00
|
|
|
uint32_t msi_ph;
|
2012-05-17 14:52:46 +02:00
|
|
|
char gutil[128];
|
2012-05-17 15:34:34 +02:00
|
|
|
char pci[128];
|
2012-12-08 14:26:37 +01:00
|
|
|
char msi[128];
|
2012-12-12 13:47:07 +01:00
|
|
|
uint32_t *pci_map = NULL;
|
|
|
|
int len;
|
2012-06-06 00:25:06 +02:00
|
|
|
uint32_t pci_ranges[14] =
|
|
|
|
{
|
|
|
|
0x2000000, 0x0, 0xc0000000,
|
|
|
|
0x0, 0xc0000000,
|
|
|
|
0x0, 0x20000000,
|
|
|
|
|
|
|
|
0x1000000, 0x0, 0x0,
|
|
|
|
0x0, 0xe1000000,
|
|
|
|
0x0, 0x10000,
|
|
|
|
};
|
2013-07-04 15:09:22 +02:00
|
|
|
QemuOpts *machine_opts = qemu_get_machine_opts();
|
|
|
|
const char *dtb_file = qemu_opt_get(machine_opts, "dtb");
|
|
|
|
const char *toplevel_compat = qemu_opt_get(machine_opts, "dt_compatible");
|
2012-05-22 14:28:50 +02: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 17:42:42 +01:00
|
|
|
|
2012-05-17 15:50:14 +02:00
|
|
|
fdt = create_device_tree(&fdt_size);
|
2009-05-30 01:52:44 +02:00
|
|
|
if (fdt == NULL) {
|
|
|
|
goto out;
|
|
|
|
}
|
2009-03-02 17:42:42 +01:00
|
|
|
|
|
|
|
/* Manipulate device tree in memory. */
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 2);
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 2);
|
2012-05-17 12:20:50 +02:00
|
|
|
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, "/memory");
|
|
|
|
qemu_fdt_setprop_string(fdt, "/memory", "device_type", "memory");
|
|
|
|
qemu_fdt_setprop(fdt, "/memory", "reg", mem_reg_property,
|
|
|
|
sizeof(mem_reg_property));
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, "/chosen");
|
2011-04-30 23:34:53 +02:00
|
|
|
if (initrd_size) {
|
2013-11-11 09:14:41 +01:00
|
|
|
ret = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start",
|
|
|
|
initrd_base);
|
2011-04-30 23:34:53 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
|
|
|
|
}
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2013-11-11 09:14:41 +01:00
|
|
|
ret = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end",
|
|
|
|
(initrd_base + initrd_size));
|
2011-04-30 23:34:53 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
|
|
|
|
}
|
2014-01-20 00:21:04 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kernel_base != -1ULL) {
|
|
|
|
qemu_fdt_setprop_cells(fdt, "/chosen", "qemu,boot-kernel",
|
|
|
|
kernel_base >> 32, kernel_base,
|
|
|
|
kernel_size >> 32, kernel_size);
|
2011-04-30 23:34:53 +02:00
|
|
|
}
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2013-11-11 09:14:41 +01:00
|
|
|
ret = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",
|
2014-05-07 16:42:57 +02:00
|
|
|
machine->kernel_cmdline);
|
2009-03-02 17:42:42 +01:00
|
|
|
if (ret < 0)
|
|
|
|
fprintf(stderr, "couldn't set /chosen/bootargs\n");
|
|
|
|
|
|
|
|
if (kvm_enabled()) {
|
2011-07-21 02:34:11 +02:00
|
|
|
/* Read out host's frequencies */
|
|
|
|
clock_freq = kvmppc_get_clockfreq();
|
|
|
|
tb_freq = kvmppc_get_tbfreq();
|
2011-06-15 23:34:04 +02:00
|
|
|
|
|
|
|
/* indicate KVM hypercall interface */
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, "/hypervisor");
|
|
|
|
qemu_fdt_setprop_string(fdt, "/hypervisor", "compatible",
|
|
|
|
"linux,kvm");
|
2011-06-15 23:34:04 +02:00
|
|
|
kvmppc_get_hypercall(env, hypercall, sizeof(hypercall));
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop(fdt, "/hypervisor", "hcall-instructions",
|
|
|
|
hypercall, sizeof(hypercall));
|
2013-01-03 13:37:02 +01:00
|
|
|
/* if KVM supports the idle hcall, set property indicating this */
|
|
|
|
if (kvmppc_get_hasidle(env)) {
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop(fdt, "/hypervisor", "has-idle", NULL, 0);
|
2013-01-03 13:37:02 +01:00
|
|
|
}
|
2009-03-02 17:42:42 +01:00
|
|
|
}
|
2011-04-30 23:34:53 +02:00
|
|
|
|
2012-05-17 11:48:16 +02:00
|
|
|
/* Create CPU nodes */
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, "/cpus");
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 1);
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0);
|
2012-05-17 11:48:16 +02:00
|
|
|
|
2011-07-23 10:56:40 +02: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--) {
|
2013-02-15 15:21:13 +01:00
|
|
|
CPUState *cpu;
|
2014-02-01 15:45:52 +01:00
|
|
|
PowerPCCPU *pcpu;
|
2011-07-21 03:01:11 +02:00
|
|
|
char cpu_name[128];
|
2012-05-18 01:56:46 +02:00
|
|
|
uint64_t cpu_release_addr = MPC8544_SPIN_BASE + (i * 0x20);
|
2011-07-21 03:06:12 +02:00
|
|
|
|
2013-02-15 15:21:13 +01:00
|
|
|
cpu = qemu_get_cpu(i);
|
2012-12-17 06:18:02 +01:00
|
|
|
if (cpu == NULL) {
|
2011-07-23 10:56:40 +02:00
|
|
|
continue;
|
|
|
|
}
|
2013-02-15 15:21:13 +01:00
|
|
|
env = cpu->env_ptr;
|
2014-02-01 15:45:52 +01:00
|
|
|
pcpu = POWERPC_CPU(cpu);
|
2011-07-23 10:56:40 +02:00
|
|
|
|
2012-12-17 06:18:02 +01:00
|
|
|
snprintf(cpu_name, sizeof(cpu_name), "/cpus/PowerPC,8544@%x",
|
2014-02-01 15:45:52 +01:00
|
|
|
ppc_get_vcpu_dt_id(pcpu));
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, cpu_name);
|
|
|
|
qemu_fdt_setprop_cell(fdt, cpu_name, "clock-frequency", clock_freq);
|
|
|
|
qemu_fdt_setprop_cell(fdt, cpu_name, "timebase-frequency", tb_freq);
|
|
|
|
qemu_fdt_setprop_string(fdt, cpu_name, "device_type", "cpu");
|
2014-02-01 15:45:52 +01:00
|
|
|
qemu_fdt_setprop_cell(fdt, cpu_name, "reg",
|
|
|
|
ppc_get_vcpu_dt_id(pcpu));
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop_cell(fdt, cpu_name, "d-cache-line-size",
|
|
|
|
env->dcache_line_size);
|
|
|
|
qemu_fdt_setprop_cell(fdt, cpu_name, "i-cache-line-size",
|
|
|
|
env->icache_line_size);
|
|
|
|
qemu_fdt_setprop_cell(fdt, cpu_name, "d-cache-size", 0x8000);
|
|
|
|
qemu_fdt_setprop_cell(fdt, cpu_name, "i-cache-size", 0x8000);
|
|
|
|
qemu_fdt_setprop_cell(fdt, cpu_name, "bus-frequency", 0);
|
2012-12-17 06:18:02 +01:00
|
|
|
if (cpu->cpu_index) {
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop_string(fdt, cpu_name, "status", "disabled");
|
|
|
|
qemu_fdt_setprop_string(fdt, cpu_name, "enable-method",
|
|
|
|
"spin-table");
|
|
|
|
qemu_fdt_setprop_u64(fdt, cpu_name, "cpu-release-addr",
|
|
|
|
cpu_release_addr);
|
2011-07-23 10:56:40 +02:00
|
|
|
} else {
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop_string(fdt, cpu_name, "status", "okay");
|
2011-07-23 10:56:40 +02:00
|
|
|
}
|
2009-03-02 17:42:42 +01:00
|
|
|
}
|
|
|
|
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, "/aliases");
|
2012-05-17 14:51:07 +02:00
|
|
|
/* XXX These should go into their respective devices' code */
|
2012-06-06 00:30:36 +02:00
|
|
|
snprintf(soc, sizeof(soc), "/soc@%llx", MPC8544_CCSRBAR_BASE);
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, soc);
|
|
|
|
qemu_fdt_setprop_string(fdt, soc, "device_type", "soc");
|
|
|
|
qemu_fdt_setprop(fdt, soc, "compatible", compatible_sb,
|
|
|
|
sizeof(compatible_sb));
|
|
|
|
qemu_fdt_setprop_cell(fdt, soc, "#address-cells", 1);
|
|
|
|
qemu_fdt_setprop_cell(fdt, soc, "#size-cells", 1);
|
|
|
|
qemu_fdt_setprop_cells(fdt, soc, "ranges", 0x0,
|
|
|
|
MPC8544_CCSRBAR_BASE >> 32, MPC8544_CCSRBAR_BASE,
|
|
|
|
MPC8544_CCSRBAR_SIZE);
|
2012-05-17 14:51:07 +02:00
|
|
|
/* XXX should contain a reasonable value */
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop_cell(fdt, soc, "bus-frequency", 0);
|
2012-05-17 14:51:07 +02:00
|
|
|
|
2012-10-10 06:28:27 +02:00
|
|
|
snprintf(mpic, sizeof(mpic), "%s/pic@%llx", soc, MPC8544_MPIC_REGS_OFFSET);
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, mpic);
|
|
|
|
qemu_fdt_setprop_string(fdt, mpic, "device_type", "open-pic");
|
|
|
|
qemu_fdt_setprop_string(fdt, mpic, "compatible", "fsl,mpic");
|
|
|
|
qemu_fdt_setprop_cells(fdt, mpic, "reg", MPC8544_MPIC_REGS_OFFSET,
|
|
|
|
0x40000);
|
|
|
|
qemu_fdt_setprop_cell(fdt, mpic, "#address-cells", 0);
|
|
|
|
qemu_fdt_setprop_cell(fdt, mpic, "#interrupt-cells", 2);
|
|
|
|
mpic_ph = qemu_fdt_alloc_phandle(fdt);
|
|
|
|
qemu_fdt_setprop_cell(fdt, mpic, "phandle", mpic_ph);
|
|
|
|
qemu_fdt_setprop_cell(fdt, mpic, "linux,phandle", mpic_ph);
|
|
|
|
qemu_fdt_setprop(fdt, mpic, "interrupt-controller", NULL, 0);
|
2012-05-17 14:51:51 +02:00
|
|
|
|
2012-05-17 14:51:34 +02: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.
|
|
|
|
*/
|
2014-06-04 13:48:18 +02:00
|
|
|
if (serial_hds[1]) {
|
|
|
|
dt_serial_create(fdt, MPC8544_SERIAL1_REGS_OFFSET,
|
|
|
|
soc, mpic, "serial1", 1, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serial_hds[0]) {
|
|
|
|
dt_serial_create(fdt, MPC8544_SERIAL0_REGS_OFFSET,
|
|
|
|
soc, mpic, "serial0", 0, true);
|
|
|
|
}
|
2012-05-17 14:51:34 +02:00
|
|
|
|
2012-06-06 00:30:36 +02:00
|
|
|
snprintf(gutil, sizeof(gutil), "%s/global-utilities@%llx", soc,
|
2012-10-10 06:28:27 +02:00
|
|
|
MPC8544_UTIL_OFFSET);
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, gutil);
|
|
|
|
qemu_fdt_setprop_string(fdt, gutil, "compatible", "fsl,mpc8544-guts");
|
|
|
|
qemu_fdt_setprop_cells(fdt, gutil, "reg", MPC8544_UTIL_OFFSET, 0x1000);
|
|
|
|
qemu_fdt_setprop(fdt, gutil, "fsl,has-rstcr", NULL, 0);
|
2012-05-17 14:52:46 +02:00
|
|
|
|
2012-12-08 14:26:37 +01:00
|
|
|
snprintf(msi, sizeof(msi), "/%s/msi@%llx", soc, MPC8544_MSI_REGS_OFFSET);
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, msi);
|
|
|
|
qemu_fdt_setprop_string(fdt, msi, "compatible", "fsl,mpic-msi");
|
|
|
|
qemu_fdt_setprop_cells(fdt, msi, "reg", MPC8544_MSI_REGS_OFFSET, 0x200);
|
|
|
|
msi_ph = qemu_fdt_alloc_phandle(fdt);
|
|
|
|
qemu_fdt_setprop_cells(fdt, msi, "msi-available-ranges", 0x0, 0x100);
|
|
|
|
qemu_fdt_setprop_phandle(fdt, msi, "interrupt-parent", mpic);
|
|
|
|
qemu_fdt_setprop_cells(fdt, msi, "interrupts",
|
2012-12-08 14:26:37 +01:00
|
|
|
0xe0, 0x0,
|
|
|
|
0xe1, 0x0,
|
|
|
|
0xe2, 0x0,
|
|
|
|
0xe3, 0x0,
|
|
|
|
0xe4, 0x0,
|
|
|
|
0xe5, 0x0,
|
|
|
|
0xe6, 0x0,
|
|
|
|
0xe7, 0x0);
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop_cell(fdt, msi, "phandle", msi_ph);
|
|
|
|
qemu_fdt_setprop_cell(fdt, msi, "linux,phandle", msi_ph);
|
2012-12-08 14:26:37 +01:00
|
|
|
|
2012-06-06 00:30:36 +02:00
|
|
|
snprintf(pci, sizeof(pci), "/pci@%llx", MPC8544_PCI_REGS_BASE);
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_add_subnode(fdt, pci);
|
|
|
|
qemu_fdt_setprop_cell(fdt, pci, "cell-index", 0);
|
|
|
|
qemu_fdt_setprop_string(fdt, pci, "compatible", "fsl,mpc8540-pci");
|
|
|
|
qemu_fdt_setprop_string(fdt, pci, "device_type", "pci");
|
|
|
|
qemu_fdt_setprop_cells(fdt, pci, "interrupt-map-mask", 0xf800, 0x0,
|
|
|
|
0x0, 0x7);
|
|
|
|
pci_map = pci_map_create(fdt, qemu_fdt_get_phandle(fdt, mpic),
|
2012-12-12 13:53:53 +01:00
|
|
|
params->pci_first_slot, params->pci_nr_slots,
|
|
|
|
&len);
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop(fdt, pci, "interrupt-map", pci_map, len);
|
|
|
|
qemu_fdt_setprop_phandle(fdt, pci, "interrupt-parent", mpic);
|
|
|
|
qemu_fdt_setprop_cells(fdt, pci, "interrupts", 24, 2);
|
|
|
|
qemu_fdt_setprop_cells(fdt, pci, "bus-range", 0, 255);
|
2012-06-06 00:25:06 +02:00
|
|
|
for (i = 0; i < 14; i++) {
|
2012-05-17 15:34:34 +02:00
|
|
|
pci_ranges[i] = cpu_to_be32(pci_ranges[i]);
|
|
|
|
}
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop_cell(fdt, pci, "fsl,msi", msi_ph);
|
|
|
|
qemu_fdt_setprop(fdt, pci, "ranges", pci_ranges, sizeof(pci_ranges));
|
|
|
|
qemu_fdt_setprop_cells(fdt, pci, "reg", MPC8544_PCI_REGS_BASE >> 32,
|
|
|
|
MPC8544_PCI_REGS_BASE, 0, 0x1000);
|
|
|
|
qemu_fdt_setprop_cell(fdt, pci, "clock-frequency", 66666666);
|
|
|
|
qemu_fdt_setprop_cell(fdt, pci, "#interrupt-cells", 1);
|
|
|
|
qemu_fdt_setprop_cell(fdt, pci, "#size-cells", 2);
|
|
|
|
qemu_fdt_setprop_cell(fdt, pci, "#address-cells", 3);
|
|
|
|
qemu_fdt_setprop_string(fdt, "/aliases", "pci0", pci);
|
2012-05-17 15:34:34 +02:00
|
|
|
|
2012-07-02 15:03:20 +02:00
|
|
|
params->fixup_devtree(params, fdt);
|
|
|
|
|
|
|
|
if (toplevel_compat) {
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_setprop(fdt, "/", "compatible", toplevel_compat,
|
|
|
|
strlen(toplevel_compat) + 1);
|
2012-07-02 15:03:20 +02:00
|
|
|
}
|
|
|
|
|
2012-05-22 14:28:50 +02:00
|
|
|
done:
|
2013-07-19 12:56:24 +02:00
|
|
|
if (!dry_run) {
|
2013-11-11 09:14:41 +01:00
|
|
|
qemu_fdt_dumpdtb(fdt, fdt_size);
|
2013-07-19 12:56:24 +02:00
|
|
|
cpu_physical_memory_write(addr, fdt, fdt_size);
|
2012-05-19 00:48:50 +02:00
|
|
|
}
|
|
|
|
ret = fdt_size;
|
2009-04-10 18:23:59 +02:00
|
|
|
|
2009-03-02 17:42:42 +01:00
|
|
|
out:
|
2012-12-12 13:47:07 +01:00
|
|
|
g_free(pci_map);
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2010-02-02 09:49:02 +01:00
|
|
|
return ret;
|
2009-03-02 17:42:42 +01:00
|
|
|
}
|
|
|
|
|
2013-07-19 12:56:24 +02:00
|
|
|
typedef struct DeviceTreeParams {
|
2014-05-07 16:42:57 +02:00
|
|
|
MachineState *machine;
|
2013-07-19 12:56:24 +02:00
|
|
|
PPCE500Params params;
|
|
|
|
hwaddr addr;
|
|
|
|
hwaddr initrd_base;
|
|
|
|
hwaddr initrd_size;
|
2014-01-20 00:21:04 +01:00
|
|
|
hwaddr kernel_base;
|
|
|
|
hwaddr kernel_size;
|
2013-07-19 12:56:24 +02:00
|
|
|
} DeviceTreeParams;
|
|
|
|
|
|
|
|
static void ppce500_reset_device_tree(void *opaque)
|
|
|
|
{
|
|
|
|
DeviceTreeParams *p = opaque;
|
2014-01-20 00:27:25 +01:00
|
|
|
ppce500_load_device_tree(p->machine, &p->params, p->addr, p->initrd_base,
|
2014-01-20 00:21:04 +01:00
|
|
|
p->initrd_size, p->kernel_base, p->kernel_size,
|
|
|
|
false);
|
2013-07-19 12:56:24 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 16:42:57 +02:00
|
|
|
static int ppce500_prep_device_tree(MachineState *machine,
|
2013-07-19 12:56:24 +02:00
|
|
|
PPCE500Params *params,
|
|
|
|
hwaddr addr,
|
|
|
|
hwaddr initrd_base,
|
2014-01-20 00:21:04 +01:00
|
|
|
hwaddr initrd_size,
|
|
|
|
hwaddr kernel_base,
|
|
|
|
hwaddr kernel_size)
|
2013-07-19 12:56:24 +02:00
|
|
|
{
|
|
|
|
DeviceTreeParams *p = g_new(DeviceTreeParams, 1);
|
2014-05-07 16:42:57 +02:00
|
|
|
p->machine = machine;
|
2013-07-19 12:56:24 +02:00
|
|
|
p->params = *params;
|
|
|
|
p->addr = addr;
|
|
|
|
p->initrd_base = initrd_base;
|
|
|
|
p->initrd_size = initrd_size;
|
2014-01-20 00:21:04 +01:00
|
|
|
p->kernel_base = kernel_base;
|
|
|
|
p->kernel_size = kernel_size;
|
2013-07-19 12:56:24 +02:00
|
|
|
|
|
|
|
qemu_register_reset(ppce500_reset_device_tree, p);
|
|
|
|
|
|
|
|
/* Issue the device tree loader once, so that we get the size of the blob */
|
2014-05-07 16:42:57 +02:00
|
|
|
return ppce500_load_device_tree(machine, params, addr, initrd_base,
|
2014-01-20 00:21:04 +01:00
|
|
|
initrd_size, kernel_base, kernel_size,
|
|
|
|
true);
|
2013-07-19 12:56:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-19 00:48:50 +02:00
|
|
|
/* Create -kernel TLB entries for BookE. */
|
2012-10-23 12:30:10 +02:00
|
|
|
static inline hwaddr booke206_page_size_to_tlb(uint64_t size)
|
2011-06-16 18:45:43 +02:00
|
|
|
{
|
2012-05-19 00:48:50 +02:00
|
|
|
return 63 - clz64(size >> 10);
|
2011-06-16 18:45:43 +02:00
|
|
|
}
|
|
|
|
|
2013-04-29 06:40:56 +02:00
|
|
|
static int booke206_initial_map_tsize(CPUPPCState *env)
|
2011-04-30 23:34:53 +02:00
|
|
|
{
|
2012-05-19 00:48:50 +02:00
|
|
|
struct boot_info *bi = env->load_info;
|
2013-04-29 06:40:56 +02:00
|
|
|
hwaddr dt_end;
|
2012-05-19 00:48:50 +02: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 18:52:21 +02:00
|
|
|
if (ps & 1) {
|
|
|
|
/* e500v2 can only do even TLB size bits */
|
|
|
|
ps++;
|
|
|
|
}
|
2013-04-29 06:40:56 +02:00
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t mmubooke_initial_mapsize(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
int tsize;
|
|
|
|
|
|
|
|
tsize = booke206_initial_map_tsize(env);
|
|
|
|
return (1ULL << 10 << tsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mmubooke_create_initial_mapping(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
ppcmas_tlb_t *tlb = booke206_get_tlbm(env, 1, 0, 0);
|
|
|
|
hwaddr size;
|
|
|
|
int ps;
|
|
|
|
|
|
|
|
ps = booke206_initial_map_tsize(env);
|
2012-05-19 00:48:50 +02:00
|
|
|
size = (ps << MAS1_TSIZE_SHIFT);
|
2011-06-16 18:45:43 +02:00
|
|
|
tlb->mas1 = MAS1_VALID | size;
|
2012-05-19 00:48:50 +02:00
|
|
|
tlb->mas2 = 0;
|
|
|
|
tlb->mas7_3 = 0;
|
2011-06-16 18:45:43 +02:00
|
|
|
tlb->mas7_3 |= MAS3_UR | MAS3_UW | MAS3_UX | MAS3_SR | MAS3_SW | MAS3_SX;
|
2011-08-31 13:26:56 +02:00
|
|
|
|
|
|
|
env->tlb_dirty = true;
|
2011-04-30 23:34:53 +02:00
|
|
|
}
|
|
|
|
|
2012-07-02 15:03:19 +02:00
|
|
|
static void ppce500_cpu_reset_sec(void *opaque)
|
2011-07-22 13:32:29 +02:00
|
|
|
{
|
2012-05-04 02:09:06 +02:00
|
|
|
PowerPCCPU *cpu = opaque;
|
2013-01-17 18:51:17 +01:00
|
|
|
CPUState *cs = CPU(cpu);
|
2011-07-22 13:32:29 +02:00
|
|
|
|
2013-01-17 18:51:17 +01:00
|
|
|
cpu_reset(cs);
|
2011-07-22 13:32:29 +02:00
|
|
|
|
|
|
|
/* Secondary CPU starts in halted state for now. Needs to change when
|
|
|
|
implementing non-kernel boot. */
|
2013-01-17 18:51:17 +01:00
|
|
|
cs->halted = 1;
|
2013-08-26 08:31:06 +02:00
|
|
|
cs->exception_index = EXCP_HLT;
|
2011-04-30 23:34:53 +02:00
|
|
|
}
|
|
|
|
|
2012-07-02 15:03:19 +02:00
|
|
|
static void ppce500_cpu_reset(void *opaque)
|
2011-04-30 23:34:53 +02:00
|
|
|
{
|
2012-05-04 02:09:06 +02:00
|
|
|
PowerPCCPU *cpu = opaque;
|
2013-01-17 18:51:17 +01:00
|
|
|
CPUState *cs = CPU(cpu);
|
2012-05-04 02:09:06 +02:00
|
|
|
CPUPPCState *env = &cpu->env;
|
2011-04-30 23:34:53 +02:00
|
|
|
struct boot_info *bi = env->load_info;
|
|
|
|
|
2013-01-17 18:51:17 +01:00
|
|
|
cpu_reset(cs);
|
2011-04-30 23:34:53 +02:00
|
|
|
|
|
|
|
/* Set initial guest state. */
|
2013-01-17 18:51:17 +01:00
|
|
|
cs->halted = 0;
|
2011-04-30 23:34:53 +02:00
|
|
|
env->gpr[1] = (16<<20) - 8;
|
|
|
|
env->gpr[3] = bi->dt_base;
|
2013-04-29 06:40:56 +02:00
|
|
|
env->gpr[4] = 0;
|
|
|
|
env->gpr[5] = 0;
|
|
|
|
env->gpr[6] = EPAPR_MAGIC;
|
|
|
|
env->gpr[7] = mmubooke_initial_mapsize(env);
|
|
|
|
env->gpr[8] = 0;
|
|
|
|
env->gpr[9] = 0;
|
2011-04-30 23:34:53 +02:00
|
|
|
env->nip = bi->entry;
|
2012-05-19 00:48:50 +02:00
|
|
|
mmubooke_create_initial_mapping(env);
|
2011-04-30 23:34:53 +02:00
|
|
|
}
|
|
|
|
|
2013-06-12 22:32:51 +02:00
|
|
|
static DeviceState *ppce500_init_mpic_qemu(PPCE500Params *params,
|
|
|
|
qemu_irq **irqs)
|
2013-04-15 15:19:33 +02:00
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *s;
|
|
|
|
int i, j, k;
|
|
|
|
|
2013-06-18 03:58:07 +02:00
|
|
|
dev = qdev_create(NULL, TYPE_OPENPIC);
|
2013-04-15 15:19:33 +02:00
|
|
|
qdev_prop_set_uint32(dev, "model", params->mpic_version);
|
2013-06-12 22:32:51 +02:00
|
|
|
qdev_prop_set_uint32(dev, "nb_cpus", smp_cpus);
|
|
|
|
|
2013-04-15 15:19:33 +02:00
|
|
|
qdev_init_nofail(dev);
|
|
|
|
s = SYS_BUS_DEVICE(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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-12 22:32:51 +02:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DeviceState *ppce500_init_mpic_kvm(PPCE500Params *params,
|
|
|
|
qemu_irq **irqs)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
CPUState *cs;
|
|
|
|
int r;
|
|
|
|
|
2013-06-16 21:30:40 +02:00
|
|
|
dev = qdev_create(NULL, TYPE_KVM_OPENPIC);
|
2013-06-12 22:32:51 +02:00
|
|
|
qdev_prop_set_uint32(dev, "model", params->mpic_version);
|
|
|
|
|
|
|
|
r = qdev_init(dev);
|
|
|
|
if (r) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-24 23:50:24 +02:00
|
|
|
CPU_FOREACH(cs) {
|
2013-06-12 22:32:51 +02:00
|
|
|
if (kvm_openpic_connect_vcpu(dev, cs)) {
|
|
|
|
fprintf(stderr, "%s: failed to connect vcpu to irqchip\n",
|
|
|
|
__func__);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static qemu_irq *ppce500_init_mpic(PPCE500Params *params, MemoryRegion *ccsr,
|
|
|
|
qemu_irq **irqs)
|
|
|
|
{
|
|
|
|
qemu_irq *mpic;
|
|
|
|
DeviceState *dev = NULL;
|
|
|
|
SysBusDevice *s;
|
|
|
|
int i;
|
|
|
|
|
2014-08-15 10:15:10 +02:00
|
|
|
mpic = g_new0(qemu_irq, 256);
|
2013-06-12 22:32:51 +02:00
|
|
|
|
|
|
|
if (kvm_enabled()) {
|
Fix -machine options accel, kernel_irqchip, kvm_shadow_mem
Multiple -machine options with the same ID are merged. All but the
one without an ID are to be silently ignored.
In most places, we query these options with a null ID. This is
correct.
In some places, we instead query whatever options come first in the
list. This is wrong. When the -machine processed first happens to
have an ID, options are taken from that ID, and the ones specified
without ID are silently ignored.
Example:
$ upstream-qemu -nodefaults -S -display none -monitor stdio -machine id=foo -machine accel=kvm,usb=on
$ upstream-qemu -nodefaults -S -display none -monitor stdio -machine id=foo,accel=kvm,usb=on -machine accel=xen
$ upstream-qemu -nodefaults -S -display none -monitor stdio -machine accel=xen -machine id=foo,accel=kvm,usb=on
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine accel=kvm,usb=on
QEMU 1.5.50 monitor - type 'help' for more information
(qemu) info kvm
kvm support: enabled
(qemu) info usb
(qemu) q
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine id=foo -machine accel=kvm,usb=on
QEMU 1.5.50 monitor - type 'help' for more information
(qemu) info kvm
kvm support: disabled
(qemu) info usb
(qemu) q
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine id=foo,accel=kvm,usb=on -machine accel=xen
QEMU 1.5.50 monitor - type 'help' for more information
(qemu) info kvm
kvm support: enabled
(qemu) info usb
USB support not enabled
(qemu) q
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine accel=xen -machine id=foo,accel=kvm,usb=on
xc: error: Could not obtain handle on privileged command interface (2 = No such file or directory): Internal error
xen be core: can't open xen interface
failed to initialize Xen: Operation not permitted
Option usb is queried correctly, and the one without an ID wins,
regardless of option order.
Option accel is queried incorrectly, and which one wins depends on
option order and ID.
Affected options are accel (and its sugared forms -enable-kvm and
-no-kvm), kernel_irqchip, kvm_shadow_mem.
Additionally, option kernel_irqchip is normally on by default, except
it's off when no -machine options are given. Bug can't bite, because
kernel_irqchip is used only when KVM is enabled, KVM is off by
default, and enabling always creates -machine options. Downstreams
that enable KVM by default do get bitten, though.
Use qemu_get_machine_opts() to fix these bugs.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1372943363-24081-5-git-send-email-armbru@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-07-04 15:09:20 +02:00
|
|
|
QemuOpts *machine_opts = qemu_get_machine_opts();
|
|
|
|
bool irqchip_allowed = qemu_opt_get_bool(machine_opts,
|
2013-06-12 22:32:51 +02:00
|
|
|
"kernel_irqchip", true);
|
Fix -machine options accel, kernel_irqchip, kvm_shadow_mem
Multiple -machine options with the same ID are merged. All but the
one without an ID are to be silently ignored.
In most places, we query these options with a null ID. This is
correct.
In some places, we instead query whatever options come first in the
list. This is wrong. When the -machine processed first happens to
have an ID, options are taken from that ID, and the ones specified
without ID are silently ignored.
Example:
$ upstream-qemu -nodefaults -S -display none -monitor stdio -machine id=foo -machine accel=kvm,usb=on
$ upstream-qemu -nodefaults -S -display none -monitor stdio -machine id=foo,accel=kvm,usb=on -machine accel=xen
$ upstream-qemu -nodefaults -S -display none -monitor stdio -machine accel=xen -machine id=foo,accel=kvm,usb=on
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine accel=kvm,usb=on
QEMU 1.5.50 monitor - type 'help' for more information
(qemu) info kvm
kvm support: enabled
(qemu) info usb
(qemu) q
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine id=foo -machine accel=kvm,usb=on
QEMU 1.5.50 monitor - type 'help' for more information
(qemu) info kvm
kvm support: disabled
(qemu) info usb
(qemu) q
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine id=foo,accel=kvm,usb=on -machine accel=xen
QEMU 1.5.50 monitor - type 'help' for more information
(qemu) info kvm
kvm support: enabled
(qemu) info usb
USB support not enabled
(qemu) q
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine accel=xen -machine id=foo,accel=kvm,usb=on
xc: error: Could not obtain handle on privileged command interface (2 = No such file or directory): Internal error
xen be core: can't open xen interface
failed to initialize Xen: Operation not permitted
Option usb is queried correctly, and the one without an ID wins,
regardless of option order.
Option accel is queried incorrectly, and which one wins depends on
option order and ID.
Affected options are accel (and its sugared forms -enable-kvm and
-no-kvm), kernel_irqchip, kvm_shadow_mem.
Additionally, option kernel_irqchip is normally on by default, except
it's off when no -machine options are given. Bug can't bite, because
kernel_irqchip is used only when KVM is enabled, KVM is off by
default, and enabling always creates -machine options. Downstreams
that enable KVM by default do get bitten, though.
Use qemu_get_machine_opts() to fix these bugs.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1372943363-24081-5-git-send-email-armbru@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-07-04 15:09:20 +02:00
|
|
|
bool irqchip_required = qemu_opt_get_bool(machine_opts,
|
|
|
|
"kernel_irqchip", false);
|
2013-06-12 22:32:51 +02:00
|
|
|
|
|
|
|
if (irqchip_allowed) {
|
|
|
|
dev = ppce500_init_mpic_kvm(params, irqs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irqchip_required && !dev) {
|
|
|
|
fprintf(stderr, "%s: irqchip requested but unavailable\n",
|
|
|
|
__func__);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dev) {
|
|
|
|
dev = ppce500_init_mpic_qemu(params, irqs);
|
|
|
|
}
|
|
|
|
|
2013-04-15 15:19:33 +02:00
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
mpic[i] = qdev_get_gpio_in(dev, i);
|
|
|
|
}
|
|
|
|
|
2013-06-12 22:32:51 +02:00
|
|
|
s = SYS_BUS_DEVICE(dev);
|
2013-04-15 15:19:33 +02:00
|
|
|
memory_region_add_subregion(ccsr, MPC8544_MPIC_REGS_OFFSET,
|
|
|
|
s->mmio[0].memory);
|
|
|
|
|
|
|
|
return mpic;
|
|
|
|
}
|
|
|
|
|
2014-05-07 16:42:57 +02:00
|
|
|
void ppce500_init(MachineState *machine, PPCE500Params *params)
|
2009-03-02 17:42:42 +01:00
|
|
|
{
|
2011-08-12 01:07:16 +02:00
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
2011-10-02 16:43:01 +02:00
|
|
|
MemoryRegion *ram = g_new(MemoryRegion, 1);
|
2009-03-02 17:42:42 +01:00
|
|
|
PCIBus *pci_bus;
|
2012-03-14 01:38:23 +01:00
|
|
|
CPUPPCState *env = NULL;
|
2014-01-20 00:27:25 +01:00
|
|
|
uint64_t loadaddr;
|
|
|
|
hwaddr kernel_base = -1LL;
|
|
|
|
int kernel_size = 0;
|
|
|
|
hwaddr dt_base = 0;
|
|
|
|
hwaddr initrd_base = 0;
|
|
|
|
int initrd_size = 0;
|
|
|
|
hwaddr cur_base = 0;
|
|
|
|
char *filename;
|
|
|
|
hwaddr bios_entry = 0;
|
|
|
|
target_long bios_size;
|
|
|
|
struct boot_info *boot_info;
|
|
|
|
int dt_size;
|
2013-04-15 15:19:33 +02:00
|
|
|
int i;
|
2014-05-12 11:45:39 +02:00
|
|
|
/* irq num for pin INTA, INTB, INTC and INTD is 1, 2, 3 and
|
|
|
|
* 4 respectively */
|
|
|
|
unsigned int pci_irq_nrs[PCI_NUM_PINS] = {1, 2, 3, 4};
|
2011-07-21 01:42:58 +02:00
|
|
|
qemu_irq **irqs, *mpic;
|
2010-08-31 00:22:28 +02:00
|
|
|
DeviceState *dev;
|
2012-03-14 01:38:23 +01:00
|
|
|
CPUPPCState *firstenv = NULL;
|
2012-10-10 06:28:28 +02:00
|
|
|
MemoryRegion *ccsr_addr_space;
|
2012-10-10 06:28:27 +02:00
|
|
|
SysBusDevice *s;
|
2012-10-10 06:28:28 +02:00
|
|
|
PPCE500CCSRState *ccsr;
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2011-07-21 01:41:16 +02:00
|
|
|
/* Setup CPUs */
|
2014-05-07 16:42:57 +02:00
|
|
|
if (machine->cpu_model == NULL) {
|
|
|
|
machine->cpu_model = "e500v2_v30";
|
2011-04-30 23:05:03 +02:00
|
|
|
}
|
|
|
|
|
2011-07-21 01:42:58 +02:00
|
|
|
irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
|
|
|
|
irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
|
2011-07-21 01:41:16 +02:00
|
|
|
for (i = 0; i < smp_cpus; i++) {
|
2012-05-03 05:43:05 +02:00
|
|
|
PowerPCCPU *cpu;
|
2012-12-17 06:18:02 +01:00
|
|
|
CPUState *cs;
|
2011-07-21 01:41:16 +02:00
|
|
|
qemu_irq *input;
|
2012-05-03 05:43:05 +02:00
|
|
|
|
2014-05-07 16:42:57 +02:00
|
|
|
cpu = cpu_ppc_init(machine->cpu_model);
|
2012-05-03 05:43:05 +02:00
|
|
|
if (cpu == NULL) {
|
2011-07-21 01:41:16 +02:00
|
|
|
fprintf(stderr, "Unable to initialize CPU!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-05-03 05:43:05 +02:00
|
|
|
env = &cpu->env;
|
2012-12-17 06:18:02 +01:00
|
|
|
cs = CPU(cpu);
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2011-07-21 01:41:16 +02:00
|
|
|
if (!firstenv) {
|
|
|
|
firstenv = env;
|
|
|
|
}
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2011-07-21 01:42:58 +02: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];
|
2014-04-03 20:45:27 +02:00
|
|
|
env->spr_cb[SPR_BOOKE_PIR].default_value = cs->cpu_index = i;
|
2013-01-04 11:21:04 +01:00
|
|
|
env->mpic_iack = MPC8544_CCSRBAR_BASE +
|
2013-01-21 16:53:54 +01:00
|
|
|
MPC8544_MPIC_REGS_OFFSET + 0xa0;
|
2011-04-30 23:34:53 +02:00
|
|
|
|
2012-12-01 04:43:18 +01:00
|
|
|
ppc_booke_timers_init(cpu, 400000000, PPC_TIMER_E500);
|
2011-07-21 01:41:16 +02:00
|
|
|
|
|
|
|
/* Register reset handler */
|
2011-07-22 13:32:29 +02:00
|
|
|
if (!i) {
|
|
|
|
/* Primary CPU */
|
|
|
|
struct boot_info *boot_info;
|
|
|
|
boot_info = g_malloc0(sizeof(struct boot_info));
|
2012-07-02 15:03:19 +02:00
|
|
|
qemu_register_reset(ppce500_cpu_reset, cpu);
|
2011-07-22 13:32:29 +02:00
|
|
|
env->load_info = boot_info;
|
|
|
|
} else {
|
|
|
|
/* Secondary CPUs */
|
2012-07-02 15:03:19 +02:00
|
|
|
qemu_register_reset(ppce500_cpu_reset_sec, cpu);
|
2011-07-22 13:32:29 +02:00
|
|
|
}
|
2011-07-21 01:41:16 +02:00
|
|
|
}
|
2011-04-30 23:34:53 +02:00
|
|
|
|
2011-07-21 01:41:16 +02:00
|
|
|
env = firstenv;
|
2011-04-30 23:34:53 +02:00
|
|
|
|
2009-03-02 17:42:42 +01:00
|
|
|
/* Fixup Memory size on a alignment boundary */
|
|
|
|
ram_size &= ~(RAM_SIZES_ALIGN - 1);
|
2014-05-07 16:42:57 +02:00
|
|
|
machine->ram_size = ram_size;
|
2009-03-02 17:42:42 +01:00
|
|
|
|
|
|
|
/* Register Memory */
|
2014-07-10 14:01:03 +02:00
|
|
|
memory_region_allocate_system_memory(ram, NULL, "mpc8544ds.ram", ram_size);
|
2011-10-02 16:43:01 +02:00
|
|
|
memory_region_add_subregion(address_space_mem, 0, ram);
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2012-10-10 06:28:28 +02: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 06:28:27 +02:00
|
|
|
|
2013-04-15 15:19:33 +02:00
|
|
|
mpic = ppce500_init_mpic(params, ccsr_addr_space, irqs);
|
2012-12-08 05:17:14 +01:00
|
|
|
|
2009-03-02 17:42:42 +01:00
|
|
|
/* Serial */
|
2010-03-21 20:47:11 +01:00
|
|
|
if (serial_hds[0]) {
|
2012-10-10 06:28:28 +02:00
|
|
|
serial_mm_init(ccsr_addr_space, MPC8544_SERIAL0_REGS_OFFSET,
|
2012-12-07 16:10:34 +01:00
|
|
|
0, mpic[42], 399193,
|
2011-08-12 01:07:15 +02:00
|
|
|
serial_hds[0], DEVICE_BIG_ENDIAN);
|
2010-03-21 20:47:11 +01:00
|
|
|
}
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2010-03-21 20:47:11 +01:00
|
|
|
if (serial_hds[1]) {
|
2012-10-10 06:28:28 +02:00
|
|
|
serial_mm_init(ccsr_addr_space, MPC8544_SERIAL1_REGS_OFFSET,
|
2012-12-07 16:10:34 +01:00
|
|
|
0, mpic[42], 399193,
|
2012-10-08 08:46:54 +02:00
|
|
|
serial_hds[1], DEVICE_BIG_ENDIAN);
|
2010-03-21 20:47:11 +01:00
|
|
|
}
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2011-06-02 13:53:40 +02:00
|
|
|
/* General Utility device */
|
2012-10-10 06:28:27 +02:00
|
|
|
dev = qdev_create(NULL, "mpc8544-guts");
|
|
|
|
qdev_init_nofail(dev);
|
|
|
|
s = SYS_BUS_DEVICE(dev);
|
2012-10-10 06:28:28 +02:00
|
|
|
memory_region_add_subregion(ccsr_addr_space, MPC8544_UTIL_OFFSET,
|
2012-10-10 06:28:27 +02:00
|
|
|
sysbus_mmio_get_region(s, 0));
|
2011-06-02 13:53:40 +02:00
|
|
|
|
2009-03-02 17:42:42 +01:00
|
|
|
/* PCI */
|
2012-10-10 06:28:27 +02:00
|
|
|
dev = qdev_create(NULL, "e500-pcihost");
|
2012-12-12 13:53:53 +01:00
|
|
|
qdev_prop_set_uint32(dev, "first_slot", params->pci_first_slot);
|
2014-05-12 11:45:40 +02:00
|
|
|
qdev_prop_set_uint32(dev, "first_pin_irq", pci_irq_nrs[0]);
|
2012-10-10 06:28:27 +02:00
|
|
|
qdev_init_nofail(dev);
|
|
|
|
s = SYS_BUS_DEVICE(dev);
|
2014-05-12 11:45:39 +02:00
|
|
|
for (i = 0; i < PCI_NUM_PINS; i++) {
|
|
|
|
sysbus_connect_irq(s, i, mpic[pci_irq_nrs[i]]);
|
|
|
|
}
|
|
|
|
|
2012-10-10 06:28:28 +02:00
|
|
|
memory_region_add_subregion(ccsr_addr_space, MPC8544_PCI_REGS_OFFSET,
|
2012-10-10 06:28:27 +02:00
|
|
|
sysbus_mmio_get_region(s, 0));
|
|
|
|
|
2011-05-27 03:23:26 +02:00
|
|
|
pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");
|
2009-03-02 17:42:42 +01:00
|
|
|
if (!pci_bus)
|
|
|
|
printf("couldn't create PCI controller!\n");
|
|
|
|
|
2013-01-20 02:47:33 +01:00
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, MPC8544_PCI_IO);
|
2009-03-02 17:42:42 +01:00
|
|
|
|
|
|
|
if (pci_bus) {
|
|
|
|
/* Register network interfaces. */
|
|
|
|
for (i = 0; i < nb_nics; i++) {
|
2013-06-06 10:48:51 +02:00
|
|
|
pci_nic_init_nofail(&nd_table[i], pci_bus, "virtio", NULL);
|
2009-03-02 17:42:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-22 13:32:29 +02:00
|
|
|
/* Register spinning region */
|
|
|
|
sysbus_create_simple("e500-spin", MPC8544_SPIN_BASE, NULL);
|
|
|
|
|
2014-01-20 00:27:25 +01:00
|
|
|
if (cur_base < (32 * 1024 * 1024)) {
|
|
|
|
/* u-boot occupies memory up to 32MB, so load blobs above */
|
|
|
|
cur_base = (32 * 1024 * 1024);
|
|
|
|
}
|
|
|
|
|
2009-03-02 17:42:42 +01:00
|
|
|
/* Load kernel. */
|
2014-05-07 16:42:57 +02:00
|
|
|
if (machine->kernel_filename) {
|
2014-01-20 00:27:25 +01:00
|
|
|
kernel_base = cur_base;
|
|
|
|
kernel_size = load_image_targphys(machine->kernel_filename,
|
|
|
|
cur_base,
|
|
|
|
ram_size - cur_base);
|
2009-03-02 17:42:42 +01:00
|
|
|
if (kernel_size < 0) {
|
|
|
|
fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
2014-05-07 16:42:57 +02:00
|
|
|
machine->kernel_filename);
|
2009-03-02 17:42:42 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
2013-01-14 20:24:16 +01:00
|
|
|
|
2014-01-20 00:27:25 +01:00
|
|
|
cur_base += kernel_size;
|
2009-03-02 17:42:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Load initrd. */
|
2014-05-07 16:42:57 +02:00
|
|
|
if (machine->initrd_filename) {
|
2013-01-14 20:24:16 +01:00
|
|
|
initrd_base = (cur_base + INITRD_LOAD_PAD) & ~INITRD_PAD_MASK;
|
2014-05-07 16:42:57 +02:00
|
|
|
initrd_size = load_image_targphys(machine->initrd_filename, initrd_base,
|
2009-04-10 05:36:49 +02:00
|
|
|
ram_size - initrd_base);
|
2009-03-02 17:42:42 +01:00
|
|
|
|
|
|
|
if (initrd_size < 0) {
|
|
|
|
fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
2014-05-07 16:42:57 +02:00
|
|
|
machine->initrd_filename);
|
2009-03-02 17:42:42 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
2013-01-14 20:24:16 +01:00
|
|
|
|
|
|
|
cur_base = initrd_base + initrd_size;
|
2009-03-02 17:42:42 +01:00
|
|
|
}
|
|
|
|
|
2014-01-20 00:27:25 +01:00
|
|
|
/*
|
|
|
|
* Smart firmware defaults ahead!
|
|
|
|
*
|
|
|
|
* We follow the following table to select which payload we execute.
|
|
|
|
*
|
|
|
|
* -kernel | -bios | payload
|
|
|
|
* ---------+-------+---------
|
|
|
|
* N | Y | u-boot
|
|
|
|
* N | N | u-boot
|
|
|
|
* Y | Y | u-boot
|
|
|
|
* Y | N | kernel
|
|
|
|
*
|
|
|
|
* This ensures backwards compatibility with how we used to expose
|
|
|
|
* -kernel to users but allows them to run through u-boot as well.
|
|
|
|
*/
|
|
|
|
if (bios_name == NULL) {
|
|
|
|
if (machine->kernel_filename) {
|
|
|
|
bios_name = machine->kernel_filename;
|
|
|
|
} else {
|
|
|
|
bios_name = "u-boot.e500";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
|
|
|
|
|
|
|
|
bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL,
|
|
|
|
1, ELF_MACHINE, 0);
|
|
|
|
if (bios_size < 0) {
|
|
|
|
/*
|
|
|
|
* Hrm. No ELF image? Try a uImage, maybe someone is giving us an
|
|
|
|
* ePAPR compliant kernel
|
|
|
|
*/
|
2014-10-19 05:42:22 +02:00
|
|
|
kernel_size = load_uimage(filename, &bios_entry, &loadaddr, NULL,
|
|
|
|
NULL, NULL);
|
2014-01-20 00:27:25 +01:00
|
|
|
if (kernel_size < 0) {
|
|
|
|
fprintf(stderr, "qemu: could not load firmware '%s'\n", filename);
|
2009-03-02 17:42:42 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
2014-01-20 00:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserve space for dtb */
|
|
|
|
dt_base = (loadaddr + bios_size + DTC_LOAD_PAD) & ~DTC_PAD_MASK;
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2014-01-20 00:27:25 +01:00
|
|
|
dt_size = ppce500_prep_device_tree(machine, params, dt_base,
|
|
|
|
initrd_base, initrd_size,
|
|
|
|
kernel_base, kernel_size);
|
|
|
|
if (dt_size < 0) {
|
|
|
|
fprintf(stderr, "couldn't load device tree\n");
|
|
|
|
exit(1);
|
2009-03-02 17:42:42 +01:00
|
|
|
}
|
2014-01-20 00:27:25 +01:00
|
|
|
assert(dt_size < DTB_MAX_SIZE);
|
|
|
|
|
|
|
|
boot_info = env->load_info;
|
|
|
|
boot_info->entry = bios_entry;
|
|
|
|
boot_info->dt_base = dt_base;
|
|
|
|
boot_info->dt_size = dt_size;
|
2009-03-02 17:42:42 +01:00
|
|
|
|
2011-04-30 23:34:53 +02:00
|
|
|
if (kvm_enabled()) {
|
2009-03-02 17:42:42 +01:00
|
|
|
kvmppc_init();
|
2011-04-30 23:34:53 +02:00
|
|
|
}
|
2009-03-02 17:42:42 +01:00
|
|
|
}
|
2012-10-10 06:28:28 +02:00
|
|
|
|
|
|
|
static int e500_ccsr_initfn(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
PPCE500CCSRState *ccsr;
|
|
|
|
|
|
|
|
ccsr = CCSR(dev);
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init(&ccsr->ccsr_space, OBJECT(ccsr), "e500-ccsr",
|
2012-10-10 06:28:28 +02:00
|
|
|
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)
|