2012-07-20 11:50:48 +04: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 16:46:50 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-07-20 11:50:48 +04: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 21:17:22 +03: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 11:43:08 +03: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 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2016-01-19 23:51:44 +03:00
|
|
|
#include "cpu.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/boards.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/char/serial.h"
|
2012-10-24 10:43:34 +04:00
|
|
|
#include "net/net.h"
|
2022-05-27 19:42:34 +03:00
|
|
|
#include "hw/openrisc/boot.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2022-02-10 00:39:12 +03:00
|
|
|
#include "exec/address-spaces.h"
|
|
|
|
#include "sysemu/device_tree.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/sysemu.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/sysbus.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/qtest.h"
|
2019-08-12 08:23:38 +03:00
|
|
|
#include "sysemu/reset.h"
|
2020-11-28 01:51:25 +03:00
|
|
|
#include "hw/core/split-irq.h"
|
2012-07-20 11:50:48 +04:00
|
|
|
|
2022-02-10 00:39:12 +03:00
|
|
|
#include <libfdt.h>
|
|
|
|
|
2012-07-20 11:50:48 +04:00
|
|
|
#define KERNEL_LOAD_ADDR 0x100
|
|
|
|
|
2022-02-19 08:57:07 +03:00
|
|
|
#define OR1KSIM_CPUS_MAX 4
|
2022-02-10 00:39:12 +03:00
|
|
|
#define OR1KSIM_CLK_MHZ 20000000
|
2022-02-19 08:57:07 +03:00
|
|
|
|
2022-02-10 00:22:46 +03: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-10 00:39:12 +03:00
|
|
|
void *fdt;
|
|
|
|
int fdt_size;
|
2022-02-10 00:22:46 +03:00
|
|
|
|
|
|
|
} Or1ksimState;
|
|
|
|
|
2022-02-10 00:26:59 +03:00
|
|
|
enum {
|
|
|
|
OR1KSIM_DRAM,
|
|
|
|
OR1KSIM_UART,
|
|
|
|
OR1KSIM_ETHOC,
|
|
|
|
OR1KSIM_OMPIC,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
OR1KSIM_OMPIC_IRQ = 1,
|
|
|
|
OR1KSIM_UART_IRQ = 2,
|
|
|
|
OR1KSIM_ETHOC_IRQ = 4,
|
|
|
|
};
|
|
|
|
|
2022-05-03 02:20:56 +03:00
|
|
|
enum {
|
|
|
|
OR1KSIM_UART_COUNT = 4
|
|
|
|
};
|
|
|
|
|
2022-02-10 00:26:59 +03:00
|
|
|
static const struct MemmapEntry {
|
|
|
|
hwaddr base;
|
|
|
|
hwaddr size;
|
|
|
|
} or1ksim_memmap[] = {
|
|
|
|
[OR1KSIM_DRAM] = { 0x00000000, 0 },
|
|
|
|
[OR1KSIM_UART] = { 0x90000000, 0x100 },
|
|
|
|
[OR1KSIM_ETHOC] = { 0x92000000, 0x800 },
|
2022-05-03 12:45:33 +03:00
|
|
|
[OR1KSIM_OMPIC] = { 0x98000000, OR1KSIM_CPUS_MAX * 8 },
|
2022-02-10 00:26:59 +03:00
|
|
|
};
|
|
|
|
|
2017-10-21 00:36:58 +03:00
|
|
|
static struct openrisc_boot_info {
|
|
|
|
uint32_t bootstrap_pc;
|
2022-02-10 00:39:12 +03:00
|
|
|
uint32_t fdt_addr;
|
2017-10-21 00:36:58 +03:00
|
|
|
} boot_info;
|
|
|
|
|
2012-07-20 11:50:48 +04:00
|
|
|
static void main_cpu_reset(void *opaque)
|
|
|
|
{
|
|
|
|
OpenRISCCPU *cpu = opaque;
|
2017-10-21 00:36:58 +03:00
|
|
|
CPUState *cs = CPU(cpu);
|
2012-07-20 11:50:48 +04:00
|
|
|
|
|
|
|
cpu_reset(CPU(cpu));
|
2017-10-21 00:36:58 +03:00
|
|
|
|
|
|
|
cpu_set_pc(cs, boot_info.bootstrap_pc);
|
2022-02-10 00:39:12 +03:00
|
|
|
cpu_set_gpr(&cpu->env, 3, boot_info.fdt_addr);
|
2012-07-20 11:50:48 +04:00
|
|
|
}
|
|
|
|
|
2020-11-28 01:51:26 +03:00
|
|
|
static qemu_irq get_cpu_irq(OpenRISCCPU *cpus[], int cpunum, int irq_pin)
|
|
|
|
{
|
2020-11-28 01:51:27 +03:00
|
|
|
return qdev_get_gpio_in_named(DEVICE(cpus[cpunum]), "IRQ", irq_pin);
|
2020-11-28 01:51:26 +03:00
|
|
|
}
|
|
|
|
|
2022-02-10 00:39:12 +03: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-28 01:51:26 +03:00
|
|
|
int num_cpus, OpenRISCCPU *cpus[],
|
2017-10-21 00:36:58 +03:00
|
|
|
int irq_pin, NICInfo *nd)
|
2012-07-20 11:50:48 +04:00
|
|
|
{
|
2022-02-10 00:39:12 +03:00
|
|
|
void *fdt = state->fdt;
|
2012-07-20 11:50:48 +04:00
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *s;
|
2022-02-10 00:39:12 +03:00
|
|
|
char *nodename;
|
2017-10-21 00:36:58 +03:00
|
|
|
int i;
|
2012-07-20 11:50:48 +04: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 08:31:58 +03:00
|
|
|
dev = qdev_new("open_eth");
|
2012-07-20 11:50:48 +04:00
|
|
|
qdev_set_nic_properties(dev, nd);
|
|
|
|
|
2013-01-20 05:47:33 +04: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 08:32:34 +03:00
|
|
|
sysbus_realize_and_unref(s, &error_fatal);
|
2020-11-28 01:51:25 +03: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-28 01:51:26 +03:00
|
|
|
qdev_connect_gpio_out(splitter, i, get_cpu_irq(cpus, i, irq_pin));
|
2020-11-28 01:51:25 +03:00
|
|
|
}
|
|
|
|
sysbus_connect_irq(s, 0, qdev_get_gpio_in(splitter, 0));
|
|
|
|
} else {
|
2020-11-28 01:51:26 +03:00
|
|
|
sysbus_connect_irq(s, 0, get_cpu_irq(cpus, 0, irq_pin));
|
2017-10-21 00:36:58 +03:00
|
|
|
}
|
|
|
|
sysbus_mmio_map(s, 0, base);
|
2022-02-10 00:39:12 +03: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-21 00:36:58 +03:00
|
|
|
}
|
|
|
|
|
2022-02-10 00:39:12 +03:00
|
|
|
static void openrisc_sim_ompic_init(Or1ksimState *state, hwaddr base,
|
|
|
|
hwaddr size, int num_cpus,
|
2020-11-28 01:51:26 +03:00
|
|
|
OpenRISCCPU *cpus[], int irq_pin)
|
2017-10-21 00:36:58 +03:00
|
|
|
{
|
2022-02-10 00:39:12 +03:00
|
|
|
void *fdt = state->fdt;
|
2017-10-21 00:36:58 +03:00
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *s;
|
2022-02-10 00:39:12 +03:00
|
|
|
char *nodename;
|
2017-10-21 00:36:58 +03: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 08:31:58 +03:00
|
|
|
dev = qdev_new("or1k-ompic");
|
2017-10-21 00:36:58 +03: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 08:32:34 +03:00
|
|
|
sysbus_realize_and_unref(s, &error_fatal);
|
2017-10-21 00:36:58 +03:00
|
|
|
for (i = 0; i < num_cpus; i++) {
|
2020-11-28 01:51:26 +03:00
|
|
|
sysbus_connect_irq(s, i, get_cpu_irq(cpus, i, irq_pin));
|
2017-10-21 00:36:58 +03:00
|
|
|
}
|
|
|
|
sysbus_mmio_map(s, 0, base);
|
2022-02-10 00:39:12 +03: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 11:50:48 +04:00
|
|
|
}
|
|
|
|
|
2022-02-10 00:39:12 +03:00
|
|
|
static void openrisc_sim_serial_init(Or1ksimState *state, hwaddr base,
|
|
|
|
hwaddr size, int num_cpus,
|
2022-05-03 02:20:56 +03:00
|
|
|
OpenRISCCPU *cpus[], int irq_pin,
|
|
|
|
int uart_idx)
|
2022-02-19 08:48:46 +03:00
|
|
|
{
|
2022-02-10 00:39:12 +03:00
|
|
|
void *fdt = state->fdt;
|
|
|
|
char *nodename;
|
2022-02-19 08:48:46 +03:00
|
|
|
qemu_irq serial_irq;
|
2022-05-03 02:20:56 +03:00
|
|
|
char alias[sizeof("uart0")];
|
2022-02-19 08:48:46 +03:00
|
|
|
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,
|
2022-05-03 02:20:56 +03:00
|
|
|
serial_hd(OR1KSIM_UART_COUNT - uart_idx - 1),
|
|
|
|
DEVICE_NATIVE_ENDIAN);
|
2022-02-19 08:48:46 +03:00
|
|
|
|
2022-02-10 00:39:12 +03: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);
|
2022-05-03 02:20:56 +03:00
|
|
|
snprintf(alias, sizeof(alias), "uart%d", uart_idx);
|
|
|
|
qemu_fdt_setprop_string(fdt, "/aliases", alias, nodename);
|
2022-02-10 00:39:12 +03:00
|
|
|
g_free(nodename);
|
|
|
|
}
|
2022-02-19 08:48:46 +03:00
|
|
|
|
2014-05-07 18:42:57 +04:00
|
|
|
static void openrisc_sim_init(MachineState *machine)
|
2012-07-20 11:50:48 +04:00
|
|
|
{
|
2014-05-07 18:42:57 +04:00
|
|
|
ram_addr_t ram_size = machine->ram_size;
|
|
|
|
const char *kernel_filename = machine->kernel_filename;
|
2022-02-19 08:57:07 +03:00
|
|
|
OpenRISCCPU *cpus[OR1KSIM_CPUS_MAX] = {};
|
2022-02-10 00:39:12 +03:00
|
|
|
Or1ksimState *state = OR1KSIM_MACHINE(machine);
|
2012-07-20 11:50:48 +04:00
|
|
|
MemoryRegion *ram;
|
2022-02-10 00:39:12 +03:00
|
|
|
hwaddr load_addr;
|
2012-07-20 11:50:48 +04:00
|
|
|
int n;
|
2019-05-18 23:54:27 +03:00
|
|
|
unsigned int smp_cpus = machine->smp.cpus;
|
2012-07-20 11:50:48 +04:00
|
|
|
|
2022-02-19 08:57:07 +03:00
|
|
|
assert(smp_cpus >= 1 && smp_cpus <= OR1KSIM_CPUS_MAX);
|
2012-07-20 11:50:48 +04:00
|
|
|
for (n = 0; n < smp_cpus; n++) {
|
2020-11-28 01:51:26 +03:00
|
|
|
cpus[n] = OPENRISC_CPU(cpu_create(machine->cpu_type));
|
|
|
|
if (cpus[n] == NULL) {
|
2017-10-21 00:36:58 +03:00
|
|
|
fprintf(stderr, "Unable to find CPU definition!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-11-28 01:51:26 +03:00
|
|
|
cpu_openrisc_clock_init(cpus[n]);
|
2017-10-21 00:36:58 +03:00
|
|
|
|
2020-11-28 01:51:26 +03:00
|
|
|
qemu_register_reset(main_cpu_reset, cpus[n]);
|
2012-07-20 11:50:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ram = g_malloc(sizeof(*ram));
|
2017-07-07 17:42:53 +03:00
|
|
|
memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, &error_fatal);
|
2012-07-20 11:50:48 +04:00
|
|
|
memory_region_add_subregion(get_system_memory(), 0, ram);
|
|
|
|
|
2022-02-10 00:39:12 +03:00
|
|
|
openrisc_create_fdt(state, or1ksim_memmap, smp_cpus, machine->ram_size,
|
|
|
|
machine->kernel_cmdline);
|
|
|
|
|
2017-10-21 00:36:58 +03:00
|
|
|
if (nd_table[0].used) {
|
2022-02-10 00:39:12 +03:00
|
|
|
openrisc_sim_net_init(state, or1ksim_memmap[OR1KSIM_ETHOC].base,
|
|
|
|
or1ksim_memmap[OR1KSIM_ETHOC].size,
|
2022-02-10 00:26:59 +03:00
|
|
|
smp_cpus, cpus,
|
|
|
|
OR1KSIM_ETHOC_IRQ, nd_table);
|
2017-10-21 00:36:58 +03:00
|
|
|
}
|
2012-07-20 11:50:48 +04:00
|
|
|
|
2017-10-21 00:36:58 +03:00
|
|
|
if (smp_cpus > 1) {
|
2022-02-10 00:39:12 +03:00
|
|
|
openrisc_sim_ompic_init(state, or1ksim_memmap[OR1KSIM_OMPIC].base,
|
2022-05-03 12:45:33 +03:00
|
|
|
or1ksim_memmap[OR1KSIM_OMPIC].size,
|
2022-02-10 00:39:12 +03:00
|
|
|
smp_cpus, cpus, OR1KSIM_OMPIC_IRQ);
|
2012-07-20 11:50:48 +04:00
|
|
|
}
|
|
|
|
|
2022-05-03 02:20:56 +03:00
|
|
|
for (n = 0; n < OR1KSIM_UART_COUNT; ++n)
|
|
|
|
openrisc_sim_serial_init(state, or1ksim_memmap[OR1KSIM_UART].base +
|
|
|
|
or1ksim_memmap[OR1KSIM_UART].size * n,
|
|
|
|
or1ksim_memmap[OR1KSIM_UART].size,
|
|
|
|
smp_cpus, cpus, OR1KSIM_UART_IRQ, n);
|
2017-10-21 00:36:58 +03:00
|
|
|
|
2022-05-27 19:42:34 +03:00
|
|
|
load_addr = openrisc_load_kernel(ram_size, kernel_filename,
|
|
|
|
&boot_info.bootstrap_pc);
|
2022-02-10 00:39:12 +03:00
|
|
|
if (load_addr > 0) {
|
2022-02-10 00:40:45 +03:00
|
|
|
if (machine->initrd_filename) {
|
2022-05-27 19:42:34 +03:00
|
|
|
load_addr = openrisc_load_initrd(state->fdt,
|
|
|
|
machine->initrd_filename,
|
2022-02-10 00:40:45 +03:00
|
|
|
load_addr, machine->ram_size);
|
|
|
|
}
|
2022-05-27 19:42:34 +03:00
|
|
|
boot_info.fdt_addr = openrisc_load_fdt(state->fdt, load_addr,
|
2022-02-10 00:39:12 +03:00
|
|
|
machine->ram_size);
|
|
|
|
}
|
2012-07-20 11:50:48 +04:00
|
|
|
}
|
|
|
|
|
2022-02-10 00:22:46 +03:00
|
|
|
static void openrisc_sim_machine_init(ObjectClass *oc, void *data)
|
2012-07-20 11:50:48 +04:00
|
|
|
{
|
2022-02-10 00:22:46 +03:00
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
2017-02-09 02:06:54 +03:00
|
|
|
mc->desc = "or1k simulation";
|
2015-09-04 21:37:08 +03:00
|
|
|
mc->init = openrisc_sim_init;
|
2022-02-19 08:57:07 +03:00
|
|
|
mc->max_cpus = OR1KSIM_CPUS_MAX;
|
2020-02-07 19:19:47 +03:00
|
|
|
mc->is_default = true;
|
2017-10-05 16:50:52 +03:00
|
|
|
mc->default_cpu_type = OPENRISC_CPU_TYPE_NAME("or1200");
|
2012-07-20 11:50:48 +04:00
|
|
|
}
|
|
|
|
|
2022-02-10 00:22:46 +03: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)
|