73
73
#include "hw/ssi/ssi.h"
74
74
#include "sysemu/blockdev.h"
75
75
#include "sysemu/hw_accel.h"
76
+ #include "sysemu/reset.h"
76
77
#include "sysemu/sysemu.h"
77
78
78
79
/* ------------------------------------------------------------------------ */
@@ -1158,10 +1159,17 @@ struct OtEGBoardState {
1158
1159
struct OtEGMachineState {
1159
1160
MachineState parent_obj ;
1160
1161
1162
+ ResettableState reset ;
1163
+
1161
1164
bool no_epmp_cfg ;
1162
1165
bool ignore_elf_entry ;
1163
1166
};
1164
1167
1168
+ struct OtEGMachineClass {
1169
+ MachineClass parent_class ;
1170
+ ResettablePhases parent_phases ;
1171
+ };
1172
+
1165
1173
/* ------------------------------------------------------------------------ */
1166
1174
/* Device Configuration */
1167
1175
/* ------------------------------------------------------------------------ */
@@ -1562,6 +1570,37 @@ ot_eg_machine_set_ignore_elf_entry(Object *obj, bool value, Error **errp)
1562
1570
s -> ignore_elf_entry = value ;
1563
1571
}
1564
1572
1573
+ static ResettableState * ot_eg_get_reset_state (Object * obj )
1574
+ {
1575
+ OtEGMachineState * s = RISCV_OT_EG_MACHINE (obj );
1576
+
1577
+ return & s -> reset ;
1578
+ }
1579
+
1580
+ static void ot_eg_reset_hold (Object * obj , ResetType type )
1581
+ {
1582
+ (void )obj ;
1583
+
1584
+ /*
1585
+ * The way the resettable APIs are implemented does not allow to call the
1586
+ * legacy qemu_devices_reset from the enter phase, where a global static
1587
+ * variable singleton enforces that entering reset is exclusive. However
1588
+ * qemu_devices_reset implements the full enter/hold/exit reset sequence.
1589
+ * This legacy function is therefore invoked from the hold stage of the
1590
+ * machine reset sequence.
1591
+ */
1592
+ qemu_devices_reset (type );
1593
+ }
1594
+
1595
+ static void ot_eg_machine_reset (MachineState * ms , ResetType reason )
1596
+ {
1597
+ OtEGMachineState * s = RISCV_OT_EG_MACHINE (ms );
1598
+
1599
+ g_assert (reason == RESET_TYPE_COLD );
1600
+
1601
+ resettable_reset (OBJECT (s ), reason );
1602
+ }
1603
+
1565
1604
static void ot_eg_machine_instance_init (Object * obj )
1566
1605
{
1567
1606
OtEGMachineState * s = RISCV_OT_EG_MACHINE (obj );
@@ -1583,6 +1622,13 @@ static void ot_eg_machine_init(MachineState *state)
1583
1622
DeviceState * dev = qdev_new (TYPE_RISCV_OT_EG_BOARD );
1584
1623
1585
1624
object_property_add_child (OBJECT (state ), "board" , OBJECT (dev ));
1625
+
1626
+ /*
1627
+ * any object not part of the default system bus hiearchy is never reset
1628
+ * otherwise
1629
+ */
1630
+ qemu_register_reset (resettable_cold_reset_fn , dev );
1631
+
1586
1632
qdev_realize (dev , NULL , & error_fatal );
1587
1633
}
1588
1634
@@ -1593,20 +1639,35 @@ static void ot_eg_machine_class_init(ObjectClass *oc, void *data)
1593
1639
1594
1640
mc -> desc = "RISC-V Board compatible with OpenTitan EarlGrey FPGA platform" ;
1595
1641
mc -> init = ot_eg_machine_init ;
1642
+ mc -> reset = & ot_eg_machine_reset ;
1596
1643
mc -> max_cpus = 1u ;
1597
1644
mc -> default_cpu_type = ot_eg_soc_devices [OT_EG_SOC_DEV_HART ].type ;
1598
1645
const IbexDeviceDef * sram =
1599
1646
& ot_eg_soc_devices [OT_EG_SOC_DEV_SRAM_MAIN_CTRL ];
1600
1647
mc -> default_ram_id = sram -> type ;
1601
1648
mc -> default_ram_size = SRAM_MAIN_SIZE ;
1649
+ /*
1650
+ * Implement the resettable interface to ensure the proper initialization
1651
+ * sequence.
1652
+ * The hold stage is used to perform most of the device reset sequence.
1653
+ */
1654
+ ResettableClass * rc = RESETTABLE_CLASS (oc );
1655
+
1656
+ rc -> get_state = & ot_eg_get_reset_state ;
1657
+
1658
+ OtEGMachineClass * sc = RISCV_OT_EG_MACHINE_CLASS (oc );
1659
+ resettable_class_set_parent_phases (rc , NULL , & ot_eg_reset_hold , NULL ,
1660
+ & sc -> parent_phases );
1602
1661
}
1603
1662
1604
1663
static const TypeInfo ot_eg_machine_type_info = {
1605
1664
.name = TYPE_RISCV_OT_EG_MACHINE ,
1606
1665
.parent = TYPE_MACHINE ,
1607
1666
.instance_size = sizeof (OtEGMachineState ),
1608
1667
.instance_init = & ot_eg_machine_instance_init ,
1668
+ .class_size = sizeof (OtEGMachineClass ),
1609
1669
.class_init = & ot_eg_machine_class_init ,
1670
+ .interfaces = (InterfaceInfo []){ { TYPE_RESETTABLE_INTERFACE }, {} },
1610
1671
};
1611
1672
1612
1673
static void ot_eg_machine_register_types (void )
0 commit comments