2012-07-20 09:50:48 +02:00
|
|
|
/*
|
|
|
|
* OpenRISC simulator for use as an IIS.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011-2012 Jia Liu <proljc@gmail.com>
|
|
|
|
* Feng Gao <gf91597@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2019-02-13 14:46:50 +01:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-07-20 09:50:48 +02:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:22 +01:00
|
|
|
#include "qemu/osdep.h"
|
hw/openrisc: Replace fprintf(stderr, "*\n" with error_report()
Replace a large number of the fprintf(stderr, "*\n" calls with
error_report(). The functions were renamed with these commands and then
compiler issues where manually fixed.
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
Some lines where then manually tweaked to pass checkpatch.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Cc: Jia Liu <proljc@gmail.com>
Cc: Stafford Horne <shorne@gmail.com>
Acked-by: Stafford Horne <shorne@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180203084315.20497-8-armbru@redhat.com>
2018-02-03 09:43:08 +01:00
|
|
|
#include "qemu/error-report.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2016-01-19 21:51:44 +01:00
|
|
|
#include "cpu.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/boards.h"
|
2012-07-20 09:50:48 +02:00
|
|
|
#include "elf.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/char/serial.h"
|
2012-10-24 08:43:34 +02:00
|
|
|
#include "net/net.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/loader.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2022-02-09 22:39:12 +01:00
|
|
|
#include "exec/address-spaces.h"
|
|
|
|
#include "sysemu/device_tree.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/qtest.h"
|
2019-08-12 07:23:38 +02:00
|
|
|
#include "sysemu/reset.h"
|
2020-11-27 23:51:25 +01:00
|
|
|
#include "hw/core/split-irq.h"
|
2012-07-20 09:50:48 +02:00
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
#include <libfdt.h>
|
|
|
|
|
2012-07-20 09:50:48 +02:00
|
|
|
#define KERNEL_LOAD_ADDR 0x100
|
|
|
|
|
2022-02-19 06:57:07 +01:00
|
|
|
#define OR1KSIM_CPUS_MAX 4
|
2022-02-09 22:39:12 +01:00
|
|
|
#define OR1KSIM_CLK_MHZ 20000000
|
2022-02-19 06:57:07 +01:00
|
|
|
|
2022-02-09 22:22:46 +01:00
|
|
|
#define TYPE_OR1KSIM_MACHINE MACHINE_TYPE_NAME("or1k-sim")
|
|
|
|
#define OR1KSIM_MACHINE(obj) \
|
|
|
|
OBJECT_CHECK(Or1ksimState, (obj), TYPE_OR1KSIM_MACHINE)
|
|
|
|
|
|
|
|
typedef struct Or1ksimState {
|
|
|
|
/*< private >*/
|
|
|
|
MachineState parent_obj;
|
|
|
|
|
|
|
|
/*< public >*/
|
2022-02-09 22:39:12 +01:00
|
|
|
void *fdt;
|
|
|
|
int fdt_size;
|
2022-02-09 22:22:46 +01:00
|
|
|
|
|
|
|
} Or1ksimState;
|
|
|
|
|
2022-02-09 22:26:59 +01:00
|
|
|
enum {
|
|
|
|
OR1KSIM_DRAM,
|
|
|
|
OR1KSIM_UART,
|
|
|
|
OR1KSIM_ETHOC,
|
|
|
|
OR1KSIM_OMPIC,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
OR1KSIM_OMPIC_IRQ = 1,
|
|
|
|
OR1KSIM_UART_IRQ = 2,
|
|
|
|
OR1KSIM_ETHOC_IRQ = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct MemmapEntry {
|
|
|
|
hwaddr base;
|
|
|
|
hwaddr size;
|
|
|
|
} or1ksim_memmap[] = {
|
|
|
|
[OR1KSIM_DRAM] = { 0x00000000, 0 },
|
|
|
|
[OR1KSIM_UART] = { 0x90000000, 0x100 },
|
|
|
|
[OR1KSIM_ETHOC] = { 0x92000000, 0x800 },
|
|
|
|
[OR1KSIM_OMPIC] = { 0x98000000, 16 },
|
|
|
|
};
|
|
|
|
|
2017-10-20 23:36:58 +02:00
|
|
|
static struct openrisc_boot_info {
|
|
|
|
uint32_t bootstrap_pc;
|
2022-02-09 22:39:12 +01:00
|
|
|
uint32_t fdt_addr;
|
2017-10-20 23:36:58 +02:00
|
|
|
} boot_info;
|
|
|
|
|
2012-07-20 09:50:48 +02:00
|
|
|
static void main_cpu_reset(void *opaque)
|
|
|
|
{
|
|
|
|
OpenRISCCPU *cpu = opaque;
|
2017-10-20 23:36:58 +02:00
|
|
|
CPUState *cs = CPU(cpu);
|
2012-07-20 09:50:48 +02:00
|
|
|
|
|
|
|
cpu_reset(CPU(cpu));
|
2017-10-20 23:36:58 +02:00
|
|
|
|
|
|
|
cpu_set_pc(cs, boot_info.bootstrap_pc);
|
2022-02-09 22:39:12 +01:00
|
|
|
cpu_set_gpr(&cpu->env, 3, boot_info.fdt_addr);
|
2012-07-20 09:50:48 +02:00
|
|
|
}
|
|
|
|
|
2020-11-27 23:51:26 +01:00
|
|
|
static qemu_irq get_cpu_irq(OpenRISCCPU *cpus[], int cpunum, int irq_pin)
|
|
|
|
{
|
2020-11-27 23:51:27 +01:00
|
|
|
return qdev_get_gpio_in_named(DEVICE(cpus[cpunum]), "IRQ", irq_pin);
|
2020-11-27 23:51:26 +01:00
|
|
|
}
|
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
static void openrisc_create_fdt(Or1ksimState *state,
|
|
|
|
const struct MemmapEntry *memmap,
|
|
|
|
int num_cpus, uint64_t mem_size,
|
|
|
|
const char *cmdline)
|
|
|
|
{
|
|
|
|
void *fdt;
|
|
|
|
int cpu;
|
|
|
|
char *nodename;
|
|
|
|
int pic_ph;
|
|
|
|
|
|
|
|
fdt = state->fdt = create_device_tree(&state->fdt_size);
|
|
|
|
if (!fdt) {
|
|
|
|
error_report("create_device_tree() failed");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_fdt_setprop_string(fdt, "/", "compatible", "opencores,or1ksim");
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x1);
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x1);
|
|
|
|
|
|
|
|
nodename = g_strdup_printf("/memory@%" HWADDR_PRIx,
|
|
|
|
memmap[OR1KSIM_DRAM].base);
|
|
|
|
qemu_fdt_add_subnode(fdt, nodename);
|
|
|
|
qemu_fdt_setprop_cells(fdt, nodename, "reg",
|
|
|
|
memmap[OR1KSIM_DRAM].base, mem_size);
|
|
|
|
qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory");
|
|
|
|
g_free(nodename);
|
|
|
|
|
|
|
|
qemu_fdt_add_subnode(fdt, "/cpus");
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0x0);
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 0x1);
|
|
|
|
|
|
|
|
for (cpu = 0; cpu < num_cpus; cpu++) {
|
|
|
|
nodename = g_strdup_printf("/cpus/cpu@%d", cpu);
|
|
|
|
qemu_fdt_add_subnode(fdt, nodename);
|
|
|
|
qemu_fdt_setprop_string(fdt, nodename, "compatible",
|
|
|
|
"opencores,or1200-rtlsvn481");
|
|
|
|
qemu_fdt_setprop_cell(fdt, nodename, "reg", cpu);
|
|
|
|
qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency",
|
|
|
|
OR1KSIM_CLK_MHZ);
|
|
|
|
g_free(nodename);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodename = (char *)"/pic";
|
|
|
|
qemu_fdt_add_subnode(fdt, nodename);
|
|
|
|
pic_ph = qemu_fdt_alloc_phandle(fdt);
|
|
|
|
qemu_fdt_setprop_string(fdt, nodename, "compatible",
|
|
|
|
"opencores,or1k-pic-level");
|
|
|
|
qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 1);
|
|
|
|
qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0);
|
|
|
|
qemu_fdt_setprop_cell(fdt, nodename, "phandle", pic_ph);
|
|
|
|
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/", "interrupt-parent", pic_ph);
|
|
|
|
|
|
|
|
qemu_fdt_add_subnode(fdt, "/chosen");
|
|
|
|
if (cmdline) {
|
|
|
|
qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create aliases node for use by devices. */
|
|
|
|
qemu_fdt_add_subnode(fdt, "/aliases");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void openrisc_sim_net_init(Or1ksimState *state, hwaddr base, hwaddr size,
|
2020-11-27 23:51:26 +01:00
|
|
|
int num_cpus, OpenRISCCPU *cpus[],
|
2017-10-20 23:36:58 +02:00
|
|
|
int irq_pin, NICInfo *nd)
|
2012-07-20 09:50:48 +02:00
|
|
|
{
|
2022-02-09 22:39:12 +01:00
|
|
|
void *fdt = state->fdt;
|
2012-07-20 09:50:48 +02:00
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *s;
|
2022-02-09 22:39:12 +01:00
|
|
|
char *nodename;
|
2017-10-20 23:36:58 +02:00
|
|
|
int i;
|
2012-07-20 09:50:48 +02:00
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new("open_eth");
|
2012-07-20 09:50:48 +02:00
|
|
|
qdev_set_nic_properties(dev, nd);
|
|
|
|
|
2013-01-20 02:47:33 +01:00
|
|
|
s = SYS_BUS_DEVICE(dev);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(s, &error_fatal);
|
2020-11-27 23:51:25 +01:00
|
|
|
if (num_cpus > 1) {
|
|
|
|
DeviceState *splitter = qdev_new(TYPE_SPLIT_IRQ);
|
|
|
|
qdev_prop_set_uint32(splitter, "num-lines", num_cpus);
|
|
|
|
qdev_realize_and_unref(splitter, NULL, &error_fatal);
|
|
|
|
for (i = 0; i < num_cpus; i++) {
|
2020-11-27 23:51:26 +01:00
|
|
|
qdev_connect_gpio_out(splitter, i, get_cpu_irq(cpus, i, irq_pin));
|
2020-11-27 23:51:25 +01:00
|
|
|
}
|
|
|
|
sysbus_connect_irq(s, 0, qdev_get_gpio_in(splitter, 0));
|
|
|
|
} else {
|
2020-11-27 23:51:26 +01:00
|
|
|
sysbus_connect_irq(s, 0, get_cpu_irq(cpus, 0, irq_pin));
|
2017-10-20 23:36:58 +02:00
|
|
|
}
|
|
|
|
sysbus_mmio_map(s, 0, base);
|
2022-02-09 22:39:12 +01:00
|
|
|
sysbus_mmio_map(s, 1, base + 0x400);
|
|
|
|
|
|
|
|
/* Init device tree node for ethoc. */
|
|
|
|
nodename = g_strdup_printf("/ethoc@%" HWADDR_PRIx, base);
|
|
|
|
qemu_fdt_add_subnode(fdt, nodename);
|
|
|
|
qemu_fdt_setprop_string(fdt, nodename, "compatible", "opencores,ethoc");
|
|
|
|
qemu_fdt_setprop_cells(fdt, nodename, "reg", base, size);
|
|
|
|
qemu_fdt_setprop_cell(fdt, nodename, "interrupts", irq_pin);
|
|
|
|
qemu_fdt_setprop(fdt, nodename, "big-endian", NULL, 0);
|
|
|
|
|
|
|
|
qemu_fdt_setprop_string(fdt, "/aliases", "enet0", nodename);
|
|
|
|
g_free(nodename);
|
2017-10-20 23:36:58 +02:00
|
|
|
}
|
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
static void openrisc_sim_ompic_init(Or1ksimState *state, hwaddr base,
|
|
|
|
hwaddr size, int num_cpus,
|
2020-11-27 23:51:26 +01:00
|
|
|
OpenRISCCPU *cpus[], int irq_pin)
|
2017-10-20 23:36:58 +02:00
|
|
|
{
|
2022-02-09 22:39:12 +01:00
|
|
|
void *fdt = state->fdt;
|
2017-10-20 23:36:58 +02:00
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *s;
|
2022-02-09 22:39:12 +01:00
|
|
|
char *nodename;
|
2017-10-20 23:36:58 +02:00
|
|
|
int i;
|
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new("or1k-ompic");
|
2017-10-20 23:36:58 +02:00
|
|
|
qdev_prop_set_uint32(dev, "num-cpus", num_cpus);
|
|
|
|
|
|
|
|
s = SYS_BUS_DEVICE(dev);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(s, &error_fatal);
|
2017-10-20 23:36:58 +02:00
|
|
|
for (i = 0; i < num_cpus; i++) {
|
2020-11-27 23:51:26 +01:00
|
|
|
sysbus_connect_irq(s, i, get_cpu_irq(cpus, i, irq_pin));
|
2017-10-20 23:36:58 +02:00
|
|
|
}
|
|
|
|
sysbus_mmio_map(s, 0, base);
|
2022-02-09 22:39:12 +01:00
|
|
|
|
|
|
|
/* Add device tree node for ompic. */
|
|
|
|
nodename = g_strdup_printf("/ompic@%" HWADDR_PRIx, base);
|
|
|
|
qemu_fdt_add_subnode(fdt, nodename);
|
|
|
|
qemu_fdt_setprop_string(fdt, nodename, "compatible", "openrisc,ompic");
|
|
|
|
qemu_fdt_setprop_cells(fdt, nodename, "reg", base, size);
|
|
|
|
qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0);
|
|
|
|
qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 0);
|
|
|
|
qemu_fdt_setprop_cell(fdt, nodename, "interrupts", irq_pin);
|
|
|
|
g_free(nodename);
|
2012-07-20 09:50:48 +02:00
|
|
|
}
|
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
static void openrisc_sim_serial_init(Or1ksimState *state, hwaddr base,
|
|
|
|
hwaddr size, int num_cpus,
|
2022-02-19 06:48:46 +01:00
|
|
|
OpenRISCCPU *cpus[], int irq_pin)
|
|
|
|
{
|
2022-02-09 22:39:12 +01:00
|
|
|
void *fdt = state->fdt;
|
|
|
|
char *nodename;
|
2022-02-19 06:48:46 +01:00
|
|
|
qemu_irq serial_irq;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (num_cpus > 1) {
|
|
|
|
DeviceState *splitter = qdev_new(TYPE_SPLIT_IRQ);
|
|
|
|
qdev_prop_set_uint32(splitter, "num-lines", num_cpus);
|
|
|
|
qdev_realize_and_unref(splitter, NULL, &error_fatal);
|
|
|
|
for (i = 0; i < num_cpus; i++) {
|
|
|
|
qdev_connect_gpio_out(splitter, i, get_cpu_irq(cpus, i, irq_pin));
|
|
|
|
}
|
|
|
|
serial_irq = qdev_get_gpio_in(splitter, 0);
|
|
|
|
} else {
|
|
|
|
serial_irq = get_cpu_irq(cpus, 0, irq_pin);
|
|
|
|
}
|
|
|
|
serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200,
|
|
|
|
serial_hd(0), DEVICE_NATIVE_ENDIAN);
|
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
/* Add device tree node for serial. */
|
|
|
|
nodename = g_strdup_printf("/serial@%" HWADDR_PRIx, base);
|
|
|
|
qemu_fdt_add_subnode(fdt, nodename);
|
|
|
|
qemu_fdt_setprop_string(fdt, nodename, "compatible", "ns16550a");
|
|
|
|
qemu_fdt_setprop_cells(fdt, nodename, "reg", base, size);
|
|
|
|
qemu_fdt_setprop_cell(fdt, nodename, "interrupts", irq_pin);
|
|
|
|
qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency", OR1KSIM_CLK_MHZ);
|
|
|
|
qemu_fdt_setprop(fdt, nodename, "big-endian", NULL, 0);
|
|
|
|
|
|
|
|
/* The /chosen node is created during fdt creation. */
|
|
|
|
qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename);
|
|
|
|
qemu_fdt_setprop_string(fdt, "/aliases", "uart0", nodename);
|
|
|
|
g_free(nodename);
|
|
|
|
}
|
2022-02-19 06:48:46 +01:00
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
static hwaddr openrisc_load_kernel(ram_addr_t ram_size,
|
|
|
|
const char *kernel_filename)
|
2012-07-20 09:50:48 +02:00
|
|
|
{
|
|
|
|
long kernel_size;
|
|
|
|
uint64_t elf_entry;
|
2022-02-09 22:39:12 +01:00
|
|
|
uint64_t high_addr;
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr entry;
|
2012-07-20 09:50:48 +02:00
|
|
|
|
|
|
|
if (kernel_filename && !qtest_enabled()) {
|
2019-01-15 13:18:03 +01:00
|
|
|
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
|
2022-02-09 22:39:12 +01:00
|
|
|
&elf_entry, NULL, &high_addr, NULL, 1,
|
|
|
|
EM_OPENRISC, 1, 0);
|
2012-07-20 09:50:48 +02:00
|
|
|
entry = elf_entry;
|
|
|
|
if (kernel_size < 0) {
|
|
|
|
kernel_size = load_uimage(kernel_filename,
|
2014-10-19 05:42:22 +02:00
|
|
|
&entry, NULL, NULL, NULL, NULL);
|
2022-02-09 22:39:12 +01:00
|
|
|
high_addr = entry + kernel_size;
|
2012-07-20 09:50:48 +02:00
|
|
|
}
|
|
|
|
if (kernel_size < 0) {
|
|
|
|
kernel_size = load_image_targphys(kernel_filename,
|
|
|
|
KERNEL_LOAD_ADDR,
|
|
|
|
ram_size - KERNEL_LOAD_ADDR);
|
2022-02-09 22:39:12 +01:00
|
|
|
high_addr = KERNEL_LOAD_ADDR + kernel_size;
|
2017-10-20 23:36:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entry <= 0) {
|
2012-07-20 09:50:48 +02:00
|
|
|
entry = KERNEL_LOAD_ADDR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kernel_size < 0) {
|
hw/openrisc: Replace fprintf(stderr, "*\n" with error_report()
Replace a large number of the fprintf(stderr, "*\n" calls with
error_report(). The functions were renamed with these commands and then
compiler issues where manually fixed.
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
Some lines where then manually tweaked to pass checkpatch.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Cc: Jia Liu <proljc@gmail.com>
Cc: Stafford Horne <shorne@gmail.com>
Acked-by: Stafford Horne <shorne@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180203084315.20497-8-armbru@redhat.com>
2018-02-03 09:43:08 +01:00
|
|
|
error_report("couldn't load the kernel '%s'", kernel_filename);
|
2012-07-20 09:50:48 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2017-10-20 23:36:58 +02:00
|
|
|
boot_info.bootstrap_pc = entry;
|
2022-02-09 22:39:12 +01:00
|
|
|
|
|
|
|
return high_addr;
|
2012-07-20 09:50:48 +02:00
|
|
|
}
|
2022-02-09 22:39:12 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-02-09 22:40:45 +01:00
|
|
|
static hwaddr openrisc_load_initrd(Or1ksimState *state, const char *filename,
|
|
|
|
hwaddr load_start, uint64_t mem_size)
|
|
|
|
{
|
|
|
|
void *fdt = state->fdt;
|
|
|
|
int size;
|
|
|
|
hwaddr start;
|
|
|
|
|
|
|
|
/* We put the initrd right after the kernel; page aligned. */
|
|
|
|
start = TARGET_PAGE_ALIGN(load_start);
|
|
|
|
|
|
|
|
size = load_ramdisk(filename, start, mem_size - start);
|
|
|
|
if (size < 0) {
|
|
|
|
size = load_image_targphys(filename, start, mem_size - start);
|
|
|
|
if (size < 0) {
|
|
|
|
error_report("could not load ramdisk '%s'", filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/chosen",
|
|
|
|
"linux,initrd-start", start);
|
|
|
|
qemu_fdt_setprop_cell(fdt, "/chosen",
|
|
|
|
"linux,initrd-end", start + size);
|
|
|
|
|
|
|
|
return start + size;
|
|
|
|
}
|
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
static uint32_t openrisc_load_fdt(Or1ksimState *state, hwaddr load_start,
|
|
|
|
uint64_t mem_size)
|
|
|
|
{
|
|
|
|
void *fdt = state->fdt;
|
|
|
|
uint32_t fdt_addr;
|
|
|
|
int ret;
|
|
|
|
int fdtsize = fdt_totalsize(fdt);
|
|
|
|
|
|
|
|
if (fdtsize <= 0) {
|
|
|
|
error_report("invalid device-tree");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We put fdt right after the kernel and/or initrd. */
|
|
|
|
fdt_addr = ROUND_UP(load_start, 4);
|
|
|
|
|
|
|
|
ret = fdt_pack(fdt);
|
|
|
|
/* Should only fail if we've built a corrupted tree */
|
|
|
|
g_assert(ret == 0);
|
|
|
|
/* copy in the device tree */
|
|
|
|
qemu_fdt_dumpdtb(fdt, fdtsize);
|
|
|
|
|
|
|
|
rom_add_blob_fixed_as("fdt", fdt, fdtsize, fdt_addr,
|
|
|
|
&address_space_memory);
|
|
|
|
|
|
|
|
return fdt_addr;
|
2012-07-20 09:50:48 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 16:42:57 +02:00
|
|
|
static void openrisc_sim_init(MachineState *machine)
|
2012-07-20 09:50:48 +02:00
|
|
|
{
|
2014-05-07 16:42:57 +02:00
|
|
|
ram_addr_t ram_size = machine->ram_size;
|
|
|
|
const char *kernel_filename = machine->kernel_filename;
|
2022-02-19 06:57:07 +01:00
|
|
|
OpenRISCCPU *cpus[OR1KSIM_CPUS_MAX] = {};
|
2022-02-09 22:39:12 +01:00
|
|
|
Or1ksimState *state = OR1KSIM_MACHINE(machine);
|
2012-07-20 09:50:48 +02:00
|
|
|
MemoryRegion *ram;
|
2022-02-09 22:39:12 +01:00
|
|
|
hwaddr load_addr;
|
2012-07-20 09:50:48 +02:00
|
|
|
int n;
|
2019-05-18 22:54:27 +02:00
|
|
|
unsigned int smp_cpus = machine->smp.cpus;
|
2012-07-20 09:50:48 +02:00
|
|
|
|
2022-02-19 06:57:07 +01:00
|
|
|
assert(smp_cpus >= 1 && smp_cpus <= OR1KSIM_CPUS_MAX);
|
2012-07-20 09:50:48 +02:00
|
|
|
for (n = 0; n < smp_cpus; n++) {
|
2020-11-27 23:51:26 +01:00
|
|
|
cpus[n] = OPENRISC_CPU(cpu_create(machine->cpu_type));
|
|
|
|
if (cpus[n] == NULL) {
|
2017-10-20 23:36:58 +02:00
|
|
|
fprintf(stderr, "Unable to find CPU definition!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-11-27 23:51:26 +01:00
|
|
|
cpu_openrisc_clock_init(cpus[n]);
|
2017-10-20 23:36:58 +02:00
|
|
|
|
2020-11-27 23:51:26 +01:00
|
|
|
qemu_register_reset(main_cpu_reset, cpus[n]);
|
2012-07-20 09:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ram = g_malloc(sizeof(*ram));
|
2017-07-07 16:42:53 +02:00
|
|
|
memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, &error_fatal);
|
2012-07-20 09:50:48 +02:00
|
|
|
memory_region_add_subregion(get_system_memory(), 0, ram);
|
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
openrisc_create_fdt(state, or1ksim_memmap, smp_cpus, machine->ram_size,
|
|
|
|
machine->kernel_cmdline);
|
|
|
|
|
2017-10-20 23:36:58 +02:00
|
|
|
if (nd_table[0].used) {
|
2022-02-09 22:39:12 +01:00
|
|
|
openrisc_sim_net_init(state, or1ksim_memmap[OR1KSIM_ETHOC].base,
|
|
|
|
or1ksim_memmap[OR1KSIM_ETHOC].size,
|
2022-02-09 22:26:59 +01:00
|
|
|
smp_cpus, cpus,
|
|
|
|
OR1KSIM_ETHOC_IRQ, nd_table);
|
2017-10-20 23:36:58 +02:00
|
|
|
}
|
2012-07-20 09:50:48 +02:00
|
|
|
|
2017-10-20 23:36:58 +02:00
|
|
|
if (smp_cpus > 1) {
|
2022-02-09 22:39:12 +01:00
|
|
|
openrisc_sim_ompic_init(state, or1ksim_memmap[OR1KSIM_OMPIC].base,
|
|
|
|
or1ksim_memmap[OR1KSIM_UART].size,
|
|
|
|
smp_cpus, cpus, OR1KSIM_OMPIC_IRQ);
|
2012-07-20 09:50:48 +02:00
|
|
|
}
|
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
openrisc_sim_serial_init(state, or1ksim_memmap[OR1KSIM_UART].base,
|
|
|
|
or1ksim_memmap[OR1KSIM_UART].size, smp_cpus, cpus,
|
2022-02-19 06:48:46 +01:00
|
|
|
OR1KSIM_UART_IRQ);
|
2017-10-20 23:36:58 +02:00
|
|
|
|
2022-02-09 22:39:12 +01:00
|
|
|
load_addr = openrisc_load_kernel(ram_size, kernel_filename);
|
|
|
|
if (load_addr > 0) {
|
2022-02-09 22:40:45 +01:00
|
|
|
if (machine->initrd_filename) {
|
|
|
|
load_addr = openrisc_load_initrd(state, machine->initrd_filename,
|
|
|
|
load_addr, machine->ram_size);
|
|
|
|
}
|
2022-02-09 22:39:12 +01:00
|
|
|
boot_info.fdt_addr = openrisc_load_fdt(state, load_addr,
|
|
|
|
machine->ram_size);
|
|
|
|
}
|
2012-07-20 09:50:48 +02:00
|
|
|
}
|
|
|
|
|
2022-02-09 22:22:46 +01:00
|
|
|
static void openrisc_sim_machine_init(ObjectClass *oc, void *data)
|
2012-07-20 09:50:48 +02:00
|
|
|
{
|
2022-02-09 22:22:46 +01:00
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
2017-02-09 00:06:54 +01:00
|
|
|
mc->desc = "or1k simulation";
|
2015-09-04 20:37:08 +02:00
|
|
|
mc->init = openrisc_sim_init;
|
2022-02-19 06:57:07 +01:00
|
|
|
mc->max_cpus = OR1KSIM_CPUS_MAX;
|
2020-02-07 17:19:47 +01:00
|
|
|
mc->is_default = true;
|
2017-10-05 15:50:52 +02:00
|
|
|
mc->default_cpu_type = OPENRISC_CPU_TYPE_NAME("or1200");
|
2012-07-20 09:50:48 +02:00
|
|
|
}
|
|
|
|
|
2022-02-09 22:22:46 +01:00
|
|
|
static const TypeInfo or1ksim_machine_typeinfo = {
|
|
|
|
.name = TYPE_OR1KSIM_MACHINE,
|
|
|
|
.parent = TYPE_MACHINE,
|
|
|
|
.class_init = openrisc_sim_machine_init,
|
|
|
|
.instance_size = sizeof(Or1ksimState),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void or1ksim_machine_init_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&or1ksim_machine_typeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(or1ksim_machine_init_register_types)
|