Skip to content

Commit 35cbf60

Browse files
rivos-eblotloiclefort
authored andcommitted
[ot] hw/riscv: ot_darjeeling, ot_earlgrey: connect RSTMGR reset request line to SoC
Signed-off-by: Emmanuel Blot <eblot@rivosinc.com>
1 parent 9ba1288 commit 35cbf60

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

hw/riscv/ot_darjeeling.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include "hw/riscv/ot_darjeeling.h"
7878
#include "hw/ssi/ssi.h"
7979
#include "sysemu/blockdev.h"
80+
#include "sysemu/hw_accel.h"
8081
#include "sysemu/reset.h"
8182
#include "sysemu/sysemu.h"
8283

@@ -341,6 +342,8 @@ static const uint32_t ot_dj_pmp_addrs[] = {
341342

342343
#define OT_DJ_MSECCFG IBEX_MSECCFG(1, 1, 0)
343344

345+
#define OT_DJ_SOC_RST_REQ TYPE_RISCV_OT_DJ_SOC "-reset"
346+
344347
#define OT_DJ_SOC_GPIO(_irq_, _target_, _num_) \
345348
IBEX_GPIO(_irq_, OT_DJ_SOC_DEV_##_target_, _num_)
346349

@@ -1498,6 +1501,20 @@ static void ot_dj_soc_uart_configure(DeviceState *dev, const IbexDeviceDef *def,
14981501
/* SoC */
14991502
/* ------------------------------------------------------------------------ */
15001503

1504+
static void ot_dj_soc_hw_reset(void *opaque, int irq, int level)
1505+
{
1506+
OtDjSoCState *s = opaque;
1507+
1508+
g_assert(irq == 0);
1509+
1510+
if (level) {
1511+
CPUState *cs = CPU(s->devices[OT_DJ_SOC_DEV_HART]);
1512+
cpu_synchronize_state(cs);
1513+
bus_cold_reset(sysbus_get_default());
1514+
cpu_synchronize_post_reset(cs);
1515+
}
1516+
}
1517+
15011518
static void ot_dj_soc_reset_hold(Object *obj)
15021519
{
15031520
OtDjSoCClass *c = RISCV_OT_DJ_SOC_GET_CLASS(obj);
@@ -1641,6 +1658,11 @@ static void ot_dj_soc_realize(DeviceState *dev, Error **errp)
16411658
object_property_add_child(OBJECT(dev), "ctn-dma", oas);
16421659
ot_address_space_set(OT_ADDRESS_SPACE(oas), ctn_dma_as);
16431660

1661+
qdev_connect_gpio_out_named(DEVICE(s->devices[OT_DJ_SOC_DEV_RSTMGR]),
1662+
OT_RSTMGR_SOC_RST, 0,
1663+
qdev_get_gpio_in_named(DEVICE(s),
1664+
OT_DJ_SOC_RST_REQ, 0));
1665+
16441666
/* load kernel if provided */
16451667
ibex_load_kernel(cpu);
16461668
}
@@ -1651,6 +1673,9 @@ static void ot_dj_soc_init(Object *obj)
16511673

16521674
s->devices = ibex_create_devices(ot_dj_soc_devices,
16531675
ARRAY_SIZE(ot_dj_soc_devices), DEVICE(s));
1676+
1677+
qdev_init_gpio_in_named(DEVICE(obj), &ot_dj_soc_hw_reset, OT_DJ_SOC_RST_REQ,
1678+
1);
16541679
}
16551680

16561681
static void ot_dj_soc_class_init(ObjectClass *oc, void *data)

hw/riscv/ot_earlgrey.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "hw/riscv/ot_earlgrey.h"
6969
#include "hw/ssi/ssi.h"
7070
#include "sysemu/blockdev.h"
71+
#include "sysemu/hw_accel.h"
7172
#include "sysemu/sysemu.h"
7273

7374
/* ------------------------------------------------------------------------ */
@@ -202,6 +203,8 @@ static const uint32_t ot_eg_pmp_addrs[] = {
202203

203204
#define OT_EG_MSECCFG IBEX_MSECCFG(1, 1, 0)
204205

206+
#define OT_EG_SOC_RST_REQ TYPE_RISCV_OT_EG_SOC "-reset"
207+
205208
#define OT_EG_SOC_GPIO(_irq_, _target_, _num_) \
206209
IBEX_GPIO(_irq_, OT_EG_SOC_DEV_##_target_, _num_)
207210

@@ -1148,6 +1151,20 @@ static void ot_eg_soc_uart_configure(DeviceState *dev, const IbexDeviceDef *def,
11481151
/* SoC */
11491152
/* ------------------------------------------------------------------------ */
11501153

1154+
static void ot_eg_soc_hw_reset(void *opaque, int irq, int level)
1155+
{
1156+
OtEGSoCState *s = opaque;
1157+
1158+
g_assert(irq == 0);
1159+
1160+
if (level) {
1161+
CPUState *cs = CPU(s->devices[OT_EG_SOC_DEV_HART]);
1162+
cpu_synchronize_state(cs);
1163+
bus_cold_reset(sysbus_get_default());
1164+
cpu_synchronize_post_reset(cs);
1165+
}
1166+
}
1167+
11511168
static void ot_eg_soc_reset_hold(Object *obj)
11521169
{
11531170
OtEGSoCClass *c = RISCV_OT_EG_SOC_GET_CLASS(obj);
@@ -1208,6 +1225,11 @@ static void ot_eg_soc_realize(DeviceState *dev, Error **errp)
12081225
ibex_map_devices(s->devices, mrs, ot_eg_soc_devices,
12091226
ARRAY_SIZE(ot_eg_soc_devices));
12101227

1228+
qdev_connect_gpio_out_named(DEVICE(s->devices[OT_EG_SOC_DEV_RSTMGR]),
1229+
OT_RSTMGR_SOC_RST, 0,
1230+
qdev_get_gpio_in_named(DEVICE(s),
1231+
OT_EG_SOC_RST_REQ, 0));
1232+
12111233
/* load kernel if provided */
12121234
ibex_load_kernel(NULL);
12131235
}
@@ -1218,6 +1240,9 @@ static void ot_eg_soc_init(Object *obj)
12181240

12191241
s->devices = ibex_create_devices(ot_eg_soc_devices,
12201242
ARRAY_SIZE(ot_eg_soc_devices), DEVICE(s));
1243+
1244+
qdev_init_gpio_in_named(DEVICE(obj), &ot_eg_soc_hw_reset, OT_EG_SOC_RST_REQ,
1245+
1);
12211246
}
12221247

12231248
static void ot_eg_soc_class_init(ObjectClass *oc, void *data)

0 commit comments

Comments
 (0)