7373#include "hw/ssi/ssi.h"
7474#include "sysemu/blockdev.h"
7575#include "sysemu/hw_accel.h"
76+ #include "sysemu/reset.h"
7677#include "sysemu/sysemu.h"
7778
7879/* ------------------------------------------------------------------------ */
@@ -1158,10 +1159,17 @@ struct OtEGBoardState {
11581159struct OtEGMachineState {
11591160 MachineState parent_obj ;
11601161
1162+ ResettableState reset ;
1163+
11611164 bool no_epmp_cfg ;
11621165 bool ignore_elf_entry ;
11631166};
11641167
1168+ struct OtEGMachineClass {
1169+ MachineClass parent_class ;
1170+ ResettablePhases parent_phases ;
1171+ };
1172+
11651173/* ------------------------------------------------------------------------ */
11661174/* Device Configuration */
11671175/* ------------------------------------------------------------------------ */
@@ -1562,6 +1570,37 @@ ot_eg_machine_set_ignore_elf_entry(Object *obj, bool value, Error **errp)
15621570 s -> ignore_elf_entry = value ;
15631571}
15641572
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+
15651604static void ot_eg_machine_instance_init (Object * obj )
15661605{
15671606 OtEGMachineState * s = RISCV_OT_EG_MACHINE (obj );
@@ -1583,6 +1622,13 @@ static void ot_eg_machine_init(MachineState *state)
15831622 DeviceState * dev = qdev_new (TYPE_RISCV_OT_EG_BOARD );
15841623
15851624 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+
15861632 qdev_realize (dev , NULL , & error_fatal );
15871633}
15881634
@@ -1593,20 +1639,35 @@ static void ot_eg_machine_class_init(ObjectClass *oc, void *data)
15931639
15941640 mc -> desc = "RISC-V Board compatible with OpenTitan EarlGrey FPGA platform" ;
15951641 mc -> init = ot_eg_machine_init ;
1642+ mc -> reset = & ot_eg_machine_reset ;
15961643 mc -> max_cpus = 1u ;
15971644 mc -> default_cpu_type = ot_eg_soc_devices [OT_EG_SOC_DEV_HART ].type ;
15981645 const IbexDeviceDef * sram =
15991646 & ot_eg_soc_devices [OT_EG_SOC_DEV_SRAM_MAIN_CTRL ];
16001647 mc -> default_ram_id = sram -> type ;
16011648 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 );
16021661}
16031662
16041663static const TypeInfo ot_eg_machine_type_info = {
16051664 .name = TYPE_RISCV_OT_EG_MACHINE ,
16061665 .parent = TYPE_MACHINE ,
16071666 .instance_size = sizeof (OtEGMachineState ),
16081667 .instance_init = & ot_eg_machine_instance_init ,
1668+ .class_size = sizeof (OtEGMachineClass ),
16091669 .class_init = & ot_eg_machine_class_init ,
1670+ .interfaces = (InterfaceInfo []){ { TYPE_RESETTABLE_INTERFACE }, {} },
16101671};
16111672
16121673static void ot_eg_machine_register_types (void )
0 commit comments