|
1 | 1 | /*
|
2 | 2 | * QEMU RISC-V Board Compatible with OpenTitan "integrated" Darjeeling platform
|
3 | 3 | *
|
4 |
| - * Copyright (c) 2023-2024 Rivos, Inc. |
| 4 | + * Copyright (c) 2023-2025 Rivos, Inc. |
5 | 5 | *
|
6 | 6 | * Author(s):
|
7 | 7 | * Emmanuel Blot <eblot@rivosinc.com>
|
@@ -1420,6 +1420,11 @@ struct OtDjMachineState {
|
1420 | 1420 | bool ignore_elf_entry;
|
1421 | 1421 | };
|
1422 | 1422 |
|
| 1423 | +struct OtDjMachineClass { |
| 1424 | + MachineClass parent_class; |
| 1425 | + ResettablePhases parent_phases; |
| 1426 | +}; |
| 1427 | + |
1423 | 1428 | /* ------------------------------------------------------------------------ */
|
1424 | 1429 | /* Device Configuration */
|
1425 | 1430 | /* ------------------------------------------------------------------------ */
|
@@ -1866,19 +1871,35 @@ ot_dj_machine_set_ignore_elf_entry(Object *obj, bool value, Error **errp)
|
1866 | 1871 | s->ignore_elf_entry = value;
|
1867 | 1872 | }
|
1868 | 1873 |
|
1869 |
| -static void ot_dj_machine_reset_hold(MachineState *mc, ResetType type) |
| 1874 | +static ResettableState *ot_dj_get_reset_state(Object *obj) |
1870 | 1875 | {
|
1871 |
| - (void)mc; |
1872 |
| - (void)type; |
| 1876 | + OtDjMachineState *s = RISCV_OT_DJ_MACHINE(obj); |
1873 | 1877 |
|
1874 |
| - qemu_devices_reset(RESET_TYPE_COLD); |
| 1878 | + return &s->reset; |
1875 | 1879 | }
|
1876 | 1880 |
|
1877 |
| -static ResettableState *ot_dj_get_reset_state(Object *obj) |
| 1881 | +static void ot_dj_reset_hold(Object *obj, ResetType type) |
1878 | 1882 | {
|
1879 |
| - OtDjMachineState *s = RISCV_OT_DJ_MACHINE(obj); |
| 1883 | + (void)obj; |
1880 | 1884 |
|
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); |
1882 | 1903 | }
|
1883 | 1904 |
|
1884 | 1905 | static void ot_dj_machine_instance_init(Object *obj)
|
@@ -1918,20 +1939,31 @@ static void ot_dj_machine_class_init(ObjectClass *oc, void *data)
|
1918 | 1939 | (void)data;
|
1919 | 1940 |
|
1920 | 1941 | 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; |
1922 | 1944 | mc->max_cpus = 1u;
|
1923 | 1945 | 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 | + */ |
1925 | 1952 | ResettableClass *rc = RESETTABLE_CLASS(oc);
|
1926 | 1953 |
|
1927 | 1954 | 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); |
1928 | 1959 | }
|
1929 | 1960 |
|
1930 | 1961 | static const TypeInfo ot_dj_machine_type_info = {
|
1931 | 1962 | .name = TYPE_RISCV_OT_DJ_MACHINE,
|
1932 | 1963 | .parent = TYPE_MACHINE,
|
1933 | 1964 | .instance_size = sizeof(OtDjMachineState),
|
1934 | 1965 | .instance_init = &ot_dj_machine_instance_init,
|
| 1966 | + .class_size = sizeof(OtDjMachineClass), |
1935 | 1967 | .class_init = &ot_dj_machine_class_init,
|
1936 | 1968 | .interfaces = (InterfaceInfo[]){ { TYPE_RESETTABLE_INTERFACE }, {} },
|
1937 | 1969 | };
|
|
0 commit comments