2018-03-02 15:31:14 +03:00
|
|
|
/*
|
|
|
|
* QEMU RISC-V Board Compatible with SiFive Freedom E SDK
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 SiFive, Inc.
|
|
|
|
*
|
|
|
|
* Provides a board compatible with the SiFive Freedom E SDK:
|
|
|
|
*
|
|
|
|
* 0) UART
|
|
|
|
* 1) CLINT (Core Level Interruptor)
|
|
|
|
* 2) PLIC (Platform Level Interrupt Controller)
|
|
|
|
* 3) PRCI (Power, Reset, Clock, Interrupt)
|
|
|
|
* 4) Registers emulated as RAM: AON, GPIO, QSPI, PWM
|
|
|
|
* 5) Flash memory emulated as RAM
|
|
|
|
*
|
|
|
|
* The Mask ROM reset vector jumps to the flash payload at 0x2040_0000.
|
|
|
|
* The OTP ROM and Flash boot code will be emulated in a future version.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
2021-10-20 04:41:10 +03:00
|
|
|
#include "qemu/cutils.h"
|
2018-03-02 15:31:14 +03:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "hw/boards.h"
|
|
|
|
#include "hw/loader.h"
|
|
|
|
#include "hw/sysbus.h"
|
|
|
|
#include "hw/char/serial.h"
|
2019-09-06 19:20:01 +03:00
|
|
|
#include "hw/misc/unimp.h"
|
2018-03-02 15:31:14 +03:00
|
|
|
#include "target/riscv/cpu.h"
|
|
|
|
#include "hw/riscv/riscv_hart.h"
|
|
|
|
#include "hw/riscv/sifive_e.h"
|
2019-06-25 01:11:49 +03:00
|
|
|
#include "hw/riscv/boot.h"
|
2020-09-03 13:40:19 +03:00
|
|
|
#include "hw/char/sifive_uart.h"
|
2021-08-31 14:06:00 +03:00
|
|
|
#include "hw/intc/riscv_aclint.h"
|
2020-09-03 13:40:17 +03:00
|
|
|
#include "hw/intc/sifive_plic.h"
|
2020-09-03 13:40:12 +03:00
|
|
|
#include "hw/misc/sifive_e_prci.h"
|
2018-03-02 15:31:14 +03:00
|
|
|
#include "chardev/char.h"
|
2019-08-12 08:23:57 +03:00
|
|
|
#include "sysemu/sysemu.h"
|
2018-03-02 15:31:14 +03:00
|
|
|
|
2021-03-31 13:36:12 +03:00
|
|
|
static const MemMapEntry sifive_e_memmap[] = {
|
2020-09-11 20:34:46 +03:00
|
|
|
[SIFIVE_E_DEV_DEBUG] = { 0x0, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_MROM] = { 0x1000, 0x2000 },
|
|
|
|
[SIFIVE_E_DEV_OTP] = { 0x20000, 0x2000 },
|
|
|
|
[SIFIVE_E_DEV_CLINT] = { 0x2000000, 0x10000 },
|
|
|
|
[SIFIVE_E_DEV_PLIC] = { 0xc000000, 0x4000000 },
|
|
|
|
[SIFIVE_E_DEV_AON] = { 0x10000000, 0x8000 },
|
|
|
|
[SIFIVE_E_DEV_PRCI] = { 0x10008000, 0x8000 },
|
|
|
|
[SIFIVE_E_DEV_OTP_CTRL] = { 0x10010000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_GPIO0] = { 0x10012000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_UART0] = { 0x10013000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_QSPI0] = { 0x10014000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_PWM0] = { 0x10015000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_UART1] = { 0x10023000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_QSPI1] = { 0x10024000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_PWM1] = { 0x10025000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_QSPI2] = { 0x10034000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_PWM2] = { 0x10035000, 0x1000 },
|
|
|
|
[SIFIVE_E_DEV_XIP] = { 0x20000000, 0x20000000 },
|
|
|
|
[SIFIVE_E_DEV_DTIM] = { 0x80000000, 0x4000 }
|
2018-03-02 15:31:14 +03:00
|
|
|
};
|
|
|
|
|
2020-06-08 17:17:30 +03:00
|
|
|
static void sifive_e_machine_init(MachineState *machine)
|
2018-03-02 15:31:14 +03:00
|
|
|
{
|
2021-10-20 04:41:10 +03:00
|
|
|
MachineClass *mc = MACHINE_GET_CLASS(machine);
|
2021-02-20 17:48:04 +03:00
|
|
|
const MemMapEntry *memmap = sifive_e_memmap;
|
2018-03-02 15:31:14 +03:00
|
|
|
|
2020-05-13 20:37:08 +03:00
|
|
|
SiFiveEState *s = RISCV_E_MACHINE(machine);
|
2018-03-02 15:31:14 +03:00
|
|
|
MemoryRegion *sys_mem = get_system_memory();
|
2018-03-04 01:52:13 +03:00
|
|
|
int i;
|
2018-03-02 15:31:14 +03:00
|
|
|
|
2021-10-20 04:41:10 +03:00
|
|
|
if (machine->ram_size != mc->default_ram_size) {
|
|
|
|
char *sz = size_to_str(mc->default_ram_size);
|
|
|
|
error_report("Invalid RAM size, should be %s", sz);
|
|
|
|
g_free(sz);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2018-05-04 02:54:02 +03:00
|
|
|
/* Initialize SoC */
|
qom: Less verbose object_initialize_child()
All users of object_initialize_child() pass the obvious child size
argument. Almost all pass &error_abort and no properties. Tiresome.
Rename object_initialize_child() to
object_initialize_child_with_props() to free the name. New
convenience wrapper object_initialize_child() automates the size
argument, and passes &error_abort and no properties.
Rename object_initialize_childv() to
object_initialize_child_with_propsv() for consistency.
Convert callers with this Coccinelle script:
@@
expression parent, propname, type;
expression child, size;
symbol error_abort;
@@
- object_initialize_child(parent, propname, OBJECT(child), size, type, &error_abort, NULL)
+ object_initialize_child(parent, propname, child, size, type, &error_abort, NULL)
@@
expression parent, propname, type;
expression child;
symbol error_abort;
@@
- object_initialize_child(parent, propname, child, sizeof(*child), type, &error_abort, NULL)
+ object_initialize_child(parent, propname, child, type)
@@
expression parent, propname, type;
expression child;
symbol error_abort;
@@
- object_initialize_child(parent, propname, &child, sizeof(child), type, &error_abort, NULL)
+ object_initialize_child(parent, propname, &child, type)
@@
expression parent, propname, type;
expression child, size, err;
expression list props;
@@
- object_initialize_child(parent, propname, child, size, type, err, props)
+ object_initialize_child_with_props(parent, propname, child, size, type, err, props)
Note that Coccinelle chokes on ARMSSE typedef vs. macro in
hw/arm/armsse.c. Worked around by temporarily renaming the macro for
the spatch run.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
[Rebased: machine opentitan is new (commit fe0fe4735e7)]
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-37-armbru@redhat.com>
2020-06-10 08:32:25 +03:00
|
|
|
object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_RISCV_E_SOC);
|
qdev: Convert bus-less devices to qdev_realize() with Coccinelle
All remaining conversions to qdev_realize() are for bus-less devices.
Coccinelle script:
// only correct for bus-less @dev!
@@
expression errp;
expression dev;
@@
- qdev_init_nofail(dev);
+ qdev_realize(dev, NULL, &error_fatal);
@ depends on !(file in "hw/core/qdev.c") && !(file in "hw/core/bus.c")@
expression errp;
expression dev;
symbol true;
@@
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize(DEVICE(dev), NULL, errp);
@ depends on !(file in "hw/core/qdev.c") && !(file in "hw/core/bus.c")@
expression errp;
expression dev;
symbol true;
@@
- object_property_set_bool(dev, true, "realized", errp);
+ qdev_realize(DEVICE(dev), NULL, errp);
Note that Coccinelle chokes on ARMSSE typedef vs. macro in
hw/arm/armsse.c. Worked around by temporarily renaming the macro for
the spatch run.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-57-armbru@redhat.com>
2020-06-10 08:32:45 +03:00
|
|
|
qdev_realize(DEVICE(&s->soc), NULL, &error_abort);
|
2018-03-02 15:31:14 +03:00
|
|
|
|
|
|
|
/* Data Tightly Integrated Memory */
|
|
|
|
memory_region_add_subregion(sys_mem,
|
2021-10-20 04:41:10 +03:00
|
|
|
memmap[SIFIVE_E_DEV_DTIM].base, machine->ram);
|
2018-03-02 15:31:14 +03:00
|
|
|
|
2018-05-04 02:54:02 +03:00
|
|
|
/* Mask ROM reset vector */
|
2020-06-16 03:50:38 +03:00
|
|
|
uint32_t reset_vec[4];
|
2020-05-13 20:42:46 +03:00
|
|
|
|
|
|
|
if (s->revb) {
|
2020-06-16 03:50:38 +03:00
|
|
|
reset_vec[1] = 0x200102b7; /* 0x1004: lui t0,0x20010 */
|
2020-05-13 20:42:46 +03:00
|
|
|
} else {
|
2020-06-16 03:50:38 +03:00
|
|
|
reset_vec[1] = 0x204002b7; /* 0x1004: lui t0,0x20400 */
|
2020-05-13 20:42:46 +03:00
|
|
|
}
|
2020-06-16 03:50:38 +03:00
|
|
|
reset_vec[2] = 0x00028067; /* 0x1008: jr t0 */
|
|
|
|
|
|
|
|
reset_vec[0] = reset_vec[3] = 0;
|
2018-05-04 02:54:02 +03:00
|
|
|
|
|
|
|
/* copy in the reset vector in little_endian byte order */
|
|
|
|
for (i = 0; i < sizeof(reset_vec) >> 2; i++) {
|
|
|
|
reset_vec[i] = cpu_to_le32(reset_vec[i]);
|
|
|
|
}
|
|
|
|
rom_add_blob_fixed_as("mrom.reset", reset_vec, sizeof(reset_vec),
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_MROM].base, &address_space_memory);
|
2018-05-04 02:54:02 +03:00
|
|
|
|
|
|
|
if (machine->kernel_filename) {
|
2020-10-14 03:17:33 +03:00
|
|
|
riscv_load_kernel(machine->kernel_filename,
|
|
|
|
memmap[SIFIVE_E_DEV_DTIM].base, NULL);
|
2018-05-04 02:54:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 20:42:46 +03:00
|
|
|
static bool sifive_e_machine_get_revb(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
SiFiveEState *s = RISCV_E_MACHINE(obj);
|
|
|
|
|
|
|
|
return s->revb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sifive_e_machine_set_revb(Object *obj, bool value, Error **errp)
|
|
|
|
{
|
|
|
|
SiFiveEState *s = RISCV_E_MACHINE(obj);
|
|
|
|
|
|
|
|
s->revb = value;
|
|
|
|
}
|
|
|
|
|
2020-05-13 20:37:08 +03:00
|
|
|
static void sifive_e_machine_instance_init(Object *obj)
|
|
|
|
{
|
2020-05-13 20:42:46 +03:00
|
|
|
SiFiveEState *s = RISCV_E_MACHINE(obj);
|
|
|
|
|
|
|
|
s->revb = false;
|
2020-05-13 20:37:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sifive_e_machine_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
|
|
|
mc->desc = "RISC-V Board compatible with SiFive E SDK";
|
2020-06-08 17:17:30 +03:00
|
|
|
mc->init = sifive_e_machine_init;
|
2020-05-13 20:37:08 +03:00
|
|
|
mc->max_cpus = 1;
|
|
|
|
mc->default_cpu_type = SIFIVE_E_CPU;
|
2021-10-20 04:41:10 +03:00
|
|
|
mc->default_ram_id = "riscv.sifive.e.ram";
|
|
|
|
mc->default_ram_size = sifive_e_memmap[SIFIVE_E_DEV_DTIM].size;
|
2020-09-22 01:10:44 +03:00
|
|
|
|
|
|
|
object_class_property_add_bool(oc, "revb", sifive_e_machine_get_revb,
|
|
|
|
sifive_e_machine_set_revb);
|
|
|
|
object_class_property_set_description(oc, "revb",
|
|
|
|
"Set on to tell QEMU that it should model "
|
|
|
|
"the revB HiFive1 board");
|
2020-05-13 20:37:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo sifive_e_machine_typeinfo = {
|
|
|
|
.name = MACHINE_TYPE_NAME("sifive_e"),
|
|
|
|
.parent = TYPE_MACHINE,
|
|
|
|
.class_init = sifive_e_machine_class_init,
|
|
|
|
.instance_init = sifive_e_machine_instance_init,
|
|
|
|
.instance_size = sizeof(SiFiveEState),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sifive_e_machine_init_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&sifive_e_machine_typeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(sifive_e_machine_init_register_types)
|
|
|
|
|
2020-06-08 17:17:30 +03:00
|
|
|
static void sifive_e_soc_init(Object *obj)
|
2018-05-04 02:54:02 +03:00
|
|
|
{
|
2019-05-18 23:54:23 +03:00
|
|
|
MachineState *ms = MACHINE(qdev_get_machine());
|
2018-05-04 02:54:02 +03:00
|
|
|
SiFiveESoCState *s = RISCV_E_SOC(obj);
|
|
|
|
|
sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 2
This is the same transformation as in the previous commit, except
sysbus_init_child_obj() and realize are too separated for the commit's
Coccinelle script to handle, typically because sysbus_init_child_obj()
is in a device's instance_init() method, and the matching realize is
in its realize() method.
Perhaps a Coccinelle wizard could make it transform that pattern, but
I'm just a bungler, and the best I can do is transforming the two
separate parts separately:
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(OBJECT(child), true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(child, true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
@@
- qdev_init_nofail(DEVICE(child));
+ sysbus_realize(SYS_BUS_DEVICE(child), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
expression dev;
@@
dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
identifier dev;
@@
DeviceState *dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression parent, name, size, type;
expression child;
symbol true;
@@
- sysbus_init_child_obj(parent, name, child, size, type);
+ sysbus_init_child_XXX(parent, name, child, size, type);
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, child, sizeof(*child), type)
+ object_initialize_child(parent, propname, child, type)
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, &child, sizeof(child), type)
+ object_initialize_child(parent, propname, &child, type)
This script is *unsound*: we need to manually verify init and realize
conversions are properly paired.
This commit has only the pairs where object_initialize_child()'s
@child and sysbus_realize()'s @dev argument text match exactly within
the same source file.
Note that Coccinelle chokes on ARMSSE typedef vs. macro in
hw/arm/armsse.c. Worked around by temporarily renaming the macro for
the spatch run.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-49-armbru@redhat.com>
2020-06-10 08:32:37 +03:00
|
|
|
object_initialize_child(obj, "cpus", &s->cpus, TYPE_RISCV_HART_ARRAY);
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 19:05:54 +03:00
|
|
|
object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
|
2018-05-04 02:54:02 +03:00
|
|
|
&error_abort);
|
2020-09-01 04:38:58 +03:00
|
|
|
object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x1004, &error_abort);
|
sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 2
This is the same transformation as in the previous commit, except
sysbus_init_child_obj() and realize are too separated for the commit's
Coccinelle script to handle, typically because sysbus_init_child_obj()
is in a device's instance_init() method, and the matching realize is
in its realize() method.
Perhaps a Coccinelle wizard could make it transform that pattern, but
I'm just a bungler, and the best I can do is transforming the two
separate parts separately:
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(OBJECT(child), true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(child, true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
@@
- qdev_init_nofail(DEVICE(child));
+ sysbus_realize(SYS_BUS_DEVICE(child), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
expression dev;
@@
dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
identifier dev;
@@
DeviceState *dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression parent, name, size, type;
expression child;
symbol true;
@@
- sysbus_init_child_obj(parent, name, child, size, type);
+ sysbus_init_child_XXX(parent, name, child, size, type);
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, child, sizeof(*child), type)
+ object_initialize_child(parent, propname, child, type)
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, &child, sizeof(child), type)
+ object_initialize_child(parent, propname, &child, type)
This script is *unsound*: we need to manually verify init and realize
conversions are properly paired.
This commit has only the pairs where object_initialize_child()'s
@child and sysbus_realize()'s @dev argument text match exactly within
the same source file.
Note that Coccinelle chokes on ARMSSE typedef vs. macro in
hw/arm/armsse.c. Worked around by temporarily renaming the macro for
the spatch run.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-49-armbru@redhat.com>
2020-06-10 08:32:37 +03:00
|
|
|
object_initialize_child(obj, "riscv.sifive.e.gpio0", &s->gpio,
|
|
|
|
TYPE_SIFIVE_GPIO);
|
2018-05-04 02:54:02 +03:00
|
|
|
}
|
|
|
|
|
2020-06-08 17:17:30 +03:00
|
|
|
static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
|
2018-05-04 02:54:02 +03:00
|
|
|
{
|
2019-05-18 23:54:23 +03:00
|
|
|
MachineState *ms = MACHINE(qdev_get_machine());
|
2021-02-20 17:48:04 +03:00
|
|
|
const MemMapEntry *memmap = sifive_e_memmap;
|
2018-05-04 02:54:02 +03:00
|
|
|
SiFiveESoCState *s = RISCV_E_SOC(dev);
|
|
|
|
MemoryRegion *sys_mem = get_system_memory();
|
|
|
|
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 19:05:54 +03:00
|
|
|
object_property_set_str(OBJECT(&s->cpus), "cpu-type", ms->cpu_type,
|
2020-03-13 22:34:28 +03:00
|
|
|
&error_abort);
|
sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 2
This is the same transformation as in the previous commit, except
sysbus_init_child_obj() and realize are too separated for the commit's
Coccinelle script to handle, typically because sysbus_init_child_obj()
is in a device's instance_init() method, and the matching realize is
in its realize() method.
Perhaps a Coccinelle wizard could make it transform that pattern, but
I'm just a bungler, and the best I can do is transforming the two
separate parts separately:
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(OBJECT(child), true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(child, true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
@@
- qdev_init_nofail(DEVICE(child));
+ sysbus_realize(SYS_BUS_DEVICE(child), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
expression dev;
@@
dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
identifier dev;
@@
DeviceState *dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression parent, name, size, type;
expression child;
symbol true;
@@
- sysbus_init_child_obj(parent, name, child, size, type);
+ sysbus_init_child_XXX(parent, name, child, size, type);
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, child, sizeof(*child), type)
+ object_initialize_child(parent, propname, child, type)
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, &child, sizeof(child), type)
+ object_initialize_child(parent, propname, &child, type)
This script is *unsound*: we need to manually verify init and realize
conversions are properly paired.
This commit has only the pairs where object_initialize_child()'s
@child and sysbus_realize()'s @dev argument text match exactly within
the same source file.
Note that Coccinelle chokes on ARMSSE typedef vs. macro in
hw/arm/armsse.c. Worked around by temporarily renaming the macro for
the spatch run.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-49-armbru@redhat.com>
2020-06-10 08:32:37 +03:00
|
|
|
sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort);
|
2018-05-04 02:54:02 +03:00
|
|
|
|
2018-03-02 15:31:14 +03:00
|
|
|
/* Mask ROM */
|
2020-02-22 20:12:57 +03:00
|
|
|
memory_region_init_rom(&s->mask_rom, OBJECT(dev), "riscv.sifive.e.mrom",
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_MROM].size, &error_fatal);
|
2018-03-02 15:31:14 +03:00
|
|
|
memory_region_add_subregion(sys_mem,
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_MROM].base, &s->mask_rom);
|
2018-03-02 15:31:14 +03:00
|
|
|
|
|
|
|
/* MMIO */
|
2020-09-11 20:34:46 +03:00
|
|
|
s->plic = sifive_plic_create(memmap[SIFIVE_E_DEV_PLIC].base,
|
2021-08-30 08:35:02 +03:00
|
|
|
(char *)SIFIVE_E_PLIC_HART_CONFIG, ms->smp.cpus, 0,
|
2018-03-02 15:31:14 +03:00
|
|
|
SIFIVE_E_PLIC_NUM_SOURCES,
|
|
|
|
SIFIVE_E_PLIC_NUM_PRIORITIES,
|
|
|
|
SIFIVE_E_PLIC_PRIORITY_BASE,
|
|
|
|
SIFIVE_E_PLIC_PENDING_BASE,
|
|
|
|
SIFIVE_E_PLIC_ENABLE_BASE,
|
|
|
|
SIFIVE_E_PLIC_ENABLE_STRIDE,
|
|
|
|
SIFIVE_E_PLIC_CONTEXT_BASE,
|
|
|
|
SIFIVE_E_PLIC_CONTEXT_STRIDE,
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_PLIC].size);
|
2021-08-31 14:06:01 +03:00
|
|
|
riscv_aclint_swi_create(memmap[SIFIVE_E_DEV_CLINT].base,
|
|
|
|
0, ms->smp.cpus, false);
|
|
|
|
riscv_aclint_mtimer_create(memmap[SIFIVE_E_DEV_CLINT].base +
|
|
|
|
RISCV_ACLINT_SWI_SIZE,
|
|
|
|
RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, ms->smp.cpus,
|
|
|
|
RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,
|
|
|
|
RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, false);
|
2019-09-06 19:20:01 +03:00
|
|
|
create_unimplemented_device("riscv.sifive.e.aon",
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_AON].base, memmap[SIFIVE_E_DEV_AON].size);
|
|
|
|
sifive_e_prci_create(memmap[SIFIVE_E_DEV_PRCI].base);
|
2019-02-12 20:38:39 +03:00
|
|
|
|
|
|
|
/* GPIO */
|
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) {
|
2019-02-12 20:38:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Map GPIO registers */
|
2020-09-11 20:34:46 +03:00
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, memmap[SIFIVE_E_DEV_GPIO0].base);
|
2019-02-12 20:38:39 +03:00
|
|
|
|
|
|
|
/* Pass all GPIOs to the SOC layer so they are available to the board */
|
|
|
|
qdev_pass_gpios(DEVICE(&s->gpio), dev, NULL);
|
|
|
|
|
|
|
|
/* Connect GPIO interrupts to the PLIC */
|
|
|
|
for (int i = 0; i < 32; i++) {
|
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), i,
|
|
|
|
qdev_get_gpio_in(DEVICE(s->plic),
|
|
|
|
SIFIVE_E_GPIO0_IRQ0 + i));
|
|
|
|
}
|
|
|
|
|
2020-09-11 20:34:46 +03:00
|
|
|
sifive_uart_create(sys_mem, memmap[SIFIVE_E_DEV_UART0].base,
|
2018-04-26 23:54:12 +03:00
|
|
|
serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_E_UART0_IRQ));
|
2019-09-06 19:20:01 +03:00
|
|
|
create_unimplemented_device("riscv.sifive.e.qspi0",
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_QSPI0].base, memmap[SIFIVE_E_DEV_QSPI0].size);
|
2019-09-06 19:20:01 +03:00
|
|
|
create_unimplemented_device("riscv.sifive.e.pwm0",
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_PWM0].base, memmap[SIFIVE_E_DEV_PWM0].size);
|
|
|
|
sifive_uart_create(sys_mem, memmap[SIFIVE_E_DEV_UART1].base,
|
2018-12-14 03:19:03 +03:00
|
|
|
serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_E_UART1_IRQ));
|
2019-09-06 19:20:01 +03:00
|
|
|
create_unimplemented_device("riscv.sifive.e.qspi1",
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_QSPI1].base, memmap[SIFIVE_E_DEV_QSPI1].size);
|
2019-09-06 19:20:01 +03:00
|
|
|
create_unimplemented_device("riscv.sifive.e.pwm1",
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_PWM1].base, memmap[SIFIVE_E_DEV_PWM1].size);
|
2019-09-06 19:20:01 +03:00
|
|
|
create_unimplemented_device("riscv.sifive.e.qspi2",
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_QSPI2].base, memmap[SIFIVE_E_DEV_QSPI2].size);
|
2019-09-06 19:20:01 +03:00
|
|
|
create_unimplemented_device("riscv.sifive.e.pwm2",
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_PWM2].base, memmap[SIFIVE_E_DEV_PWM2].size);
|
2018-03-02 15:31:14 +03:00
|
|
|
|
|
|
|
/* Flash memory */
|
2020-02-22 20:12:57 +03:00
|
|
|
memory_region_init_rom(&s->xip_mem, OBJECT(dev), "riscv.sifive.e.xip",
|
2020-09-11 20:34:46 +03:00
|
|
|
memmap[SIFIVE_E_DEV_XIP].size, &error_fatal);
|
|
|
|
memory_region_add_subregion(sys_mem, memmap[SIFIVE_E_DEV_XIP].base,
|
2019-06-14 14:58:41 +03:00
|
|
|
&s->xip_mem);
|
2018-03-02 15:31:14 +03:00
|
|
|
}
|
|
|
|
|
2020-06-08 17:17:30 +03:00
|
|
|
static void sifive_e_soc_class_init(ObjectClass *oc, void *data)
|
2018-05-04 02:54:02 +03:00
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
2020-06-08 17:17:30 +03:00
|
|
|
dc->realize = sifive_e_soc_realize;
|
2018-05-04 02:54:02 +03:00
|
|
|
/* Reason: Uses serial_hds in realize function, thus can't be used twice */
|
|
|
|
dc->user_creatable = false;
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:17:30 +03:00
|
|
|
static const TypeInfo sifive_e_soc_type_info = {
|
2018-05-04 02:54:02 +03:00
|
|
|
.name = TYPE_RISCV_E_SOC,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(SiFiveESoCState),
|
2020-06-08 17:17:30 +03:00
|
|
|
.instance_init = sifive_e_soc_init,
|
|
|
|
.class_init = sifive_e_soc_class_init,
|
2018-05-04 02:54:02 +03:00
|
|
|
};
|
|
|
|
|
2020-06-08 17:17:30 +03:00
|
|
|
static void sifive_e_soc_register_types(void)
|
2018-05-04 02:54:02 +03:00
|
|
|
{
|
2020-06-08 17:17:30 +03:00
|
|
|
type_register_static(&sifive_e_soc_type_info);
|
2018-05-04 02:54:02 +03:00
|
|
|
}
|
|
|
|
|
2020-06-08 17:17:30 +03:00
|
|
|
type_init(sifive_e_soc_register_types)
|