Skip to content

Commit 22dfdf8

Browse files
committed
[ot] hw/opentitan: ot_darjeeling: rework machine reset for QEMU v9.2
Signed-off-by: Emmanuel Blot <eblot@rivosinc.com> (cherry picked from commit c857d1b)
1 parent bb1efde commit 22dfdf8

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

hw/riscv/ot_darjeeling.c

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* QEMU RISC-V Board Compatible with OpenTitan "integrated" Darjeeling platform
33
*
4-
* Copyright (c) 2023-2024 Rivos, Inc.
4+
* Copyright (c) 2023-2025 Rivos, Inc.
55
*
66
* Author(s):
77
* Emmanuel Blot <eblot@rivosinc.com>
@@ -1420,6 +1420,11 @@ struct OtDjMachineState {
14201420
bool ignore_elf_entry;
14211421
};
14221422

1423+
struct OtDjMachineClass {
1424+
MachineClass parent_class;
1425+
ResettablePhases parent_phases;
1426+
};
1427+
14231428
/* ------------------------------------------------------------------------ */
14241429
/* Device Configuration */
14251430
/* ------------------------------------------------------------------------ */
@@ -1866,19 +1871,35 @@ ot_dj_machine_set_ignore_elf_entry(Object *obj, bool value, Error **errp)
18661871
s->ignore_elf_entry = value;
18671872
}
18681873

1869-
static void ot_dj_machine_reset_hold(MachineState *mc, ResetType type)
1874+
static ResettableState *ot_dj_get_reset_state(Object *obj)
18701875
{
1871-
(void)mc;
1872-
(void)type;
1876+
OtDjMachineState *s = RISCV_OT_DJ_MACHINE(obj);
18731877

1874-
qemu_devices_reset(RESET_TYPE_COLD);
1878+
return &s->reset;
18751879
}
18761880

1877-
static ResettableState *ot_dj_get_reset_state(Object *obj)
1881+
static void ot_dj_reset_hold(Object *obj, ResetType type)
18781882
{
1879-
OtDjMachineState *s = RISCV_OT_DJ_MACHINE(obj);
1883+
(void)obj;
18801884

1881-
return &s->reset;
1885+
/*
1886+
* The way the resettable APIs are implemented does not allow to call the
1887+
* legacy qemu_devices_reset from the enter phase, where a global static
1888+
* variable singleton enforces that entering reset is exclusive. However
1889+
* qemu_devices_reset implements the full enter/hold/exit reset sequence.
1890+
* This legacy function is therefore invoked from the hold stage of the
1891+
* machine reset sequence.
1892+
*/
1893+
qemu_devices_reset(type);
1894+
}
1895+
1896+
static void ot_dj_machine_reset(MachineState *ms, ResetType reason)
1897+
{
1898+
OtDjMachineState *s = RISCV_OT_DJ_MACHINE(ms);
1899+
1900+
g_assert(reason == RESET_TYPE_COLD);
1901+
1902+
resettable_reset(OBJECT(s), reason);
18821903
}
18831904

18841905
static void ot_dj_machine_instance_init(Object *obj)
@@ -1918,20 +1939,31 @@ static void ot_dj_machine_class_init(ObjectClass *oc, void *data)
19181939
(void)data;
19191940

19201941
mc->desc = "RISC-V Board compatible with OpenTitan Darjeeling platform";
1921-
mc->init = ot_dj_machine_init;
1942+
mc->init = &ot_dj_machine_init;
1943+
mc->reset = &ot_dj_machine_reset;
19221944
mc->max_cpus = 1u;
19231945
mc->default_cpus = 1u;
1924-
mc->reset = ot_dj_machine_reset_hold;
1946+
1947+
/*
1948+
* Implement the resettable interface to ensure the proper initialization
1949+
* sequence.
1950+
* The hold stage is used to perform most of the device reset sequence.
1951+
*/
19251952
ResettableClass *rc = RESETTABLE_CLASS(oc);
19261953

19271954
rc->get_state = &ot_dj_get_reset_state;
1955+
1956+
OtDjMachineClass *sc = RISCV_OT_DJ_MACHINE_CLASS(oc);
1957+
resettable_class_set_parent_phases(rc, NULL, &ot_dj_reset_hold, NULL,
1958+
&sc->parent_phases);
19281959
}
19291960

19301961
static const TypeInfo ot_dj_machine_type_info = {
19311962
.name = TYPE_RISCV_OT_DJ_MACHINE,
19321963
.parent = TYPE_MACHINE,
19331964
.instance_size = sizeof(OtDjMachineState),
19341965
.instance_init = &ot_dj_machine_instance_init,
1966+
.class_size = sizeof(OtDjMachineClass),
19351967
.class_init = &ot_dj_machine_class_init,
19361968
.interfaces = (InterfaceInfo[]){ { TYPE_RESETTABLE_INTERFACE }, {} },
19371969
};

include/hw/riscv/ot_darjeeling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* QEMU RISC-V Board Compatible with OpenTitan "integrated" Darjeeling platform
33
*
4-
* Copyright (c) 2023-2024 Rivos, Inc.
4+
* Copyright (c) 2023-2025 Rivos, Inc.
55
*
66
* Author(s):
77
* Loïc Lefort <loic@rivosinc.com>
@@ -26,7 +26,7 @@
2626
#include "qom/object.h"
2727

2828
#define TYPE_RISCV_OT_DJ_MACHINE MACHINE_TYPE_NAME("ot-darjeeling")
29-
OBJECT_DECLARE_SIMPLE_TYPE(OtDjMachineState, RISCV_OT_DJ_MACHINE)
29+
OBJECT_DECLARE_TYPE(OtDjMachineState, OtDjMachineClass, RISCV_OT_DJ_MACHINE)
3030

3131
#define TYPE_RISCV_OT_DJ_BOARD "riscv.ot_darjeeling.board"
3232
OBJECT_DECLARE_SIMPLE_TYPE(OtDjBoardState, RISCV_OT_DJ_BOARD)

0 commit comments

Comments
 (0)