Skip to contentSkip to conversation

multi-phase reset mechanism

RFC Superseded Damien Hedde 4 participants 27 messages Mar 25, 2019 – May 20, 2019 Arm/Zynq architecture

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover multi-phase reset mechanism

Hi all,

This series is a proposal to implement the multi-phase reset we've discussed here (https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg00310.html) and more recently there
(https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg00081.html).

To summarize, we need a multi-phase reset to allow for a more complex initialization of a platform. In particular we need to "propagate" a clock tree, but we have to ensure that every device is initialized first.

To solve this problem, the following 3-phases reset mechanism is proposed (I've removed the 4th given our last discussion).

#DESCRIPTION

INIT PHASE: Reset the object internal state, put a resetting flag and do the
same for the reset subtree. No side effect on other devices to guarantee that, in a reset domain, everything get initialized first. This corresponds mostly to what is currently done in the device/bus reset method.

HOLD PHASE: This phase allows to control a reset with a I/O. When a I/O control
a reset procedure based on the I/O level (not edge), we may need to assert the reset, wait some time, and finally de-assert the reset. The consequence is that such a device can stay in a "resetting state" and may need to show this state to other devices through its outputs. For example, a clock controller will typically shutdown its clocks when it is in resetting state.

EXIT PHASE (previously named 'release'): This phase sets outputs to state after
reset. For a clock controller it starts the clocks. It also clears the "resetting" flag. A device should not react to inputs until this flag has been cleared. During this phase, outputs are propagated in the reset domain (and outside the reset domain).

To implement this, this series add a Resettable interface containing 3 methods:
one for each phase. The init phase's method takes a boolean argument allowing to distinguish cold and warm resets.

In this series, Device and Bus implement the interface. A vmstate description subsection is added to allow migration of reset related state for device. 3 methods (one per phase) are also added in Device's class. They correspond to the local part (see the code example below) of the reset. They avoid device specialization to have to handle the sub-domain part and "resetting" state.

Functions to add gpio control over the reset are added. It is possible to add an active low/high reset pin to control the warm reset and an active low/high power gating pin to control the cold reset.

The bus/device reset tree is converted to this 3-phases mechanism. I also added a new ResetDomain object which is just a Resettable container. It is used to have a global "system reset domain" to handle main 3-phases reset and replace the current single-phase-reset handler mechanism.

As an example, in the xilinx_zynq machine, I've converted the slcr (the resets and clocks controller device) and the uart peripheral to this 3-phases reset mechanism. Gpio are added between the devices to transmit reset control from the slcr to the uarts.

All changes have been made so that existing reset behavior is not modified.

#INTERFACE CHOICE

To be honest, I have some doubt about the interface. I've kept it minimal and the consequence is implementation is complex (and kind of duplicated in every base implementation like Device or Bus). One of the problem is the resetting flag, which in practical must be a counter to handle reset "reentrance". Indeed nothing forbids to reset some device that is already held in "resetting" state by some other means. As an example, in the zynq machine, there can be a global/system reset while an uart is reset by the slcr. It it also possible to cold and warm resets triggered concurrently.

The Resettable methods implementation have to looks this (methods are called with iothread locked):

```
void init_phase(Device *dev, bool cold)
{
    /* call sub-resettable init phases */

    dev->resetting += 1;
    /* do local init phase (eg: state reset) */
}
void hold_phase(Device *dev)
{
    /* call sub-resettable hold phases */

    /* do local hold phase (eg: set some I/O level) */
}
void exit_phase(Device *dev)
{
    /* call sub-resettable exit phases (independently of resetting value since,
       every resettable have its own resetting counter) */
   
    dev->resetting -= 1;
    if (dev->resetting == 0) {
        /* do local exit phase (eg: set some I/O level) only if the device is
           really leaving the resetting state */
    }
}
```

Since I don't think specialization should care about sub-resettable and the resetting counter, I've added the local init/hold/exit phases as DeviceClass methods.
Otherwise, I see two other solutions:
+ keep the interface as it is
+ add some state knowledge in the interface (with some kind of get_state method) so that resetting counter and some kind of sub-resettable list are handled in the common code in the interface. The 3 methods will then handle only the local actions.
+ have 6 methods in the interface, one for the local actions, one for the sub-resettable so that sub-resettable is not handled in the common code. And we need also a get_resetting method to access/update the counter.

#DEVICE RESET CHOICE

The Device is a special case, it has 2 reset entry point: qdev_reset_all and device_reset. The latter doing a device reset only, while the former also reset all buses hierarchy under the device.

I choose the put the sub-buses into the device reset domain, so that the behavior of the resettable interface on Device is the same as qdev_reset_all. I don't know if device_reset has some real meaning (resetting only the Device). It is not often used and I think every time it is used there is no sub-buses so the behavior is the same for both functions.

If I am mistaken about putting buses into device reset domain, it is possible to make a special bus-hierarchy-reset-domain for every Device/Bus that differs from the Resettable interface on Device/Bus.

# SYSBUS SUPPORT

Regarding the sysbus support Edgar mentioned in the prevous discussion: In this series, there is no support in sysbus base class for disabling memory regions. Having each sysbus device specialization, in every memory region handler, to check if resetting is set or not is not user-friendly. But for we can't modify memory region enabled flags since devices may already set/unset them. Maybe we could have some kind of super-switch to disable all memory regions in a sysbus device but I don't know how this could be done.

The series is organised as follow:
Patches 1 and 2 adds Resettable interface and ResetDomain object. Patches 3 to 7 converts Device and Bus to Resettable.
Patches 8 to 12 handles the global system reset domain
Patches 13 to 17 do the zynq implementation (patch 13 is an already-reviewed patch from the clock api patch series)

Thank you for your feedback,
Damien

Damien Hedde (17):
Create Resettable QOM interface
Create the ResetDomain QOM object
make Device and Bus Resettable
Add local reset methods in Device class
add vmstate description for device reset state Add function to control reset with gpio inputs convert qdev/bus_reset_all to Resettable
Add a global ResetDomain object for system emulation global ResetDomain support for legacy reset handlers Delete the system ResetDomain at the end of emulation Put orphan buses in system reset domain
Put default sysbus in system reset domain hw/misc/zynq_slcr: use standard register definition convert cadence_uart to 3-phases reset Convert zynq's slcr to 3-phases reset
Add uart reset support in zynq_slcr
Connect the uart reset gpios in the zynq platform

 hw/arm/xilinx_zynq.c           |  14 +-
 hw/char/cadence_uart.c         |  48 ++-
 hw/core/Makefile.objs          |   3 +
 hw/core/bus.c                  |  64 +++-
 hw/core/qdev-vmstate.c         |  27 ++
 hw/core/qdev.c                 | 166 ++++++++++-
 hw/core/reset-domain.c         | 121 ++++++++
 hw/core/reset.c                | 149 +++++++++-
 hw/core/resettable.c           |  69 +++++
 hw/misc/zynq_slcr.c            | 515 ++++++++++++++++++---------------
 include/hw/char/cadence_uart.h |  10 +-
 include/hw/qdev-core.h         |  97 +++++++
 include/hw/reset-domain.h      |  49 ++++
 include/hw/resettable.h        |  83 ++++++
 include/sysemu/reset.h         |  47 +++
 vl.c                           |   3 +-
 16 files changed, 1195 insertions(+), 270 deletions(-)
 create mode 100644 hw/core/qdev-vmstate.c
 create mode 100644 hw/core/reset-domain.c
 create mode 100644 hw/core/resettable.c
 create mode 100644 include/hw/reset-domain.h
 create mode 100644 include/hw/resettable.h
Signature · 1 line
2.21.0
#1 lore raw

RFC PATCH 1/17 Create Resettable QOM interface

This commit defines an interface allowing multi-phase reset. The phases are INIT, HOLD and EXIT.

The reset of a Resettable is controlled with 2 functions:
- resettable_assert_reset which starts the reset operation.
- resettable_deassert_reset which ends the reset operation.

There is also a resettable_reset helper function which does assert then deassert allowing to do a proper reset in one call.

The interface only contains 3 methods, one per phase. Each method should handle reset of the object and its sub-elements.

---
 hw/core/Makefile.objs   |  1 +
 hw/core/resettable.c    | 69 ++++++++++++++++++++++++++++++++++
 include/hw/resettable.h | 83 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)
 create mode 100644 hw/core/resettable.c
 create mode 100644 include/hw/resettable.h
hw/core/Makefile.objs +1 -0
index a799c83815..97007454a8 100644
@@ -1,6 +1,7 @@
 # core qdev-related obj files, also used by *-user:
 common-obj-y += qdev.o qdev-properties.o
 common-obj-y += bus.o reset.o
+common-obj-y += resettable.o
 common-obj-$(CONFIG_SOFTMMU) += qdev-fw.o
 common-obj-$(CONFIG_SOFTMMU) += fw-path-provider.o
 # irq.o needed for qdev GPIO handling:
hw/core/resettable.c new file +69 -0

69 lines not on this page · raw message

include/hw/resettable.h new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
2.21.0
#2 lore raw

RFC PATCH 2/17 Create the ResetDomain QOM object

In reply to Damien Hedde

ResetDomain is an object implementing the Resettable interface. It is a container of several other Resettable and therefore allows to control reset operation over a group of Resettable.

Addition and removal in a ResetDomain is done using the functions *reset_domain_register_object* and *reset_domain_unregister_object*

---
 hw/core/Makefile.objs     |   1 +
 hw/core/reset-domain.c    | 121 ++++++++++++++++++++++++++++++++++++++
 include/hw/reset-domain.h |  49 +++++++++++++++
 3 files changed, 171 insertions(+)
 create mode 100644 hw/core/reset-domain.c
 create mode 100644 include/hw/reset-domain.h
hw/core/Makefile.objs +1 -0
index 97007454a8..320f71707c 100644
@@ -2,6 +2,7 @@
 common-obj-y += qdev.o qdev-properties.o
 common-obj-y += bus.o reset.o
 common-obj-y += resettable.o
+common-obj-y += reset-domain.o
 common-obj-$(CONFIG_SOFTMMU) += qdev-fw.o
 common-obj-$(CONFIG_SOFTMMU) += fw-path-provider.o
 # irq.o needed for qdev GPIO handling:
hw/core/reset-domain.c new file +121 -0

121 lines not on this page · raw message

include/hw/reset-domain.h new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.21.0
#3 lore raw

RFC PATCH 3/17 make Device and Bus Resettable

In reply to Damien Hedde

This add Resettable interface implementation for both Bus and Device. The init phase default implementation is to call the legacy reset handler.

Add a *resetting* counter in both Device and Bus. This counter allows us to handle reentrancy in reset operation. If a device/bus has multiple source triggering reset, theses sources do not have to care about the current device/bus resetting state. Each source can independantly assert and eventually deassert the reset. The device/bus will behave as expected and gets out-of-reset state only when all sources have deasserted the reset.

---
 hw/core/bus.c          | 60 +++++++++++++++++++++++++++++++++++++++++
 hw/core/qdev.c         | 61 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/qdev-core.h | 30 +++++++++++++++++++++
 3 files changed, 151 insertions(+)
hw/core/bus.c +60 -0
index e09843f6ab..0a60bb4b24 100644
@@ -21,6 +21,7 @@
 #include "qemu-common.h"
 #include "hw/qdev.h"
 #include "qapi/error.h"
+#include "hw/resettable.h"
 
 void qbus_set_hotplug_handler(BusState *bus, Object *handler, Error **errp)
 {
@@ -67,6 +68,56 @@ int qbus_walk_children(BusState *bus,
     return 0;
 }
 
+void qbus_reset(BusState *bus, bool cold)
+{
+    resettable_reset(OBJECT(bus), cold);
+}
+
+bool qbus_is_resetting(BusState *bus)
+{
+    return (bus->resetting != 0);
+}
+
+static void bus_reset_init_phase(Object *obj, bool cold)
+{
+    BusState *bus = BUS(obj);
+    BusClass *bc = BUS_GET_CLASS(obj);
+    BusChild *kid;
+
+    QTAILQ_FOREACH(kid, &bus->children, sibling) {
+        resettable_init_phase(OBJECT(kid->child), cold);
+    }
+
+    bus->resetting += 1;
+
+    if (bc->reset) {
+        bc->reset(bus);
+    }
+}
+
+static void bus_reset_hold_phase(Object *obj)
+{
+    BusState *bus = BUS(obj);
+    BusChild *kid;
+
+    QTAILQ_FOREACH(kid, &bus->children, sibling) {
+        resettable_hold_phase(OBJECT(kid->child));
+    }
+}
+
+static void bus_reset_exit_phase(Object *obj)
+{
+    BusState *bus = BUS(obj);
+    BusChild *kid;
+
+    QTAILQ_FOREACH(kid, &bus->children, sibling) {
+        resettable_exit_phase(OBJECT(kid->child));
+    }
+
+    assert(bus->resetting > 0);
+    bus->resetting -= 1;
+}
+
 static void qbus_realize(BusState *bus, DeviceState *parent, const char *name)
 {
     const char *typename = object_get_typename(OBJECT(bus));
@@ -204,9 +255,14 @@ static char *default_bus_get_fw_dev_path(DeviceState *dev)
 static void bus_class_init(ObjectClass *class, void *data)
 {
     BusClass *bc = BUS_CLASS(class);
+    ResettableClass *rc = RESETTABLE_CLASS(class);
 
     class->unparent = bus_unparent;
     bc->get_fw_dev_path = default_bus_get_fw_dev_path;
+
+    rc->phases.init = bus_reset_init_phase;
+    rc->phases.hold = bus_reset_hold_phase;
+    rc->phases.exit = bus_reset_exit_phase;
 }
 
 static void qbus_finalize(Object *obj)
@@ -225,6 +281,10 @@ static const TypeInfo bus_info = {
     .instance_init = qbus_initfn,
     .instance_finalize = qbus_finalize,
     .class_init = bus_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_RESETTABLE },
+        { }
+    },
 };
 
 static void bus_register_types(void)
hw/core/qdev.c +61 -0

97 lines not on this page · raw message

include/hw/qdev-core.h +30 -0
index 33ed3b8dde..f4aa8dbaa2 100644
@@ -131,6 +131,8 @@ struct NamedGPIOList {
 /**
  * DeviceState:
  * @realized: Indicates whether the device has been fully constructed.
+ * @resetting: Indicates whether the device is under reset. Also
+ * used to count how many times reset has been initiated on the device.
  *
  * This structure should not be accessed directly.  We declare it here
  * so that it can be embedded in individual device state structures.
@@ -152,6 +154,7 @@ struct DeviceState {
     int num_child_bus;
     int instance_id_alias;
     int alias_required_for_version;
+    uint32_t resetting;
 };
 
 struct DeviceListener {
@@ -198,6 +201,8 @@ typedef struct BusChild {
 /**
  * BusState:
  * @hotplug_handler: link to a hotplug handler associated with bus.
+ * @resetting: Indicates whether the device is under reset. Also
+ * used to count how many times reset has been initiated on the device.
  */
 struct BusState {
     Object obj;
@@ -209,6 +214,7 @@ struct BusState {
     int num_children;
     QTAILQ_HEAD(, BusChild) children;
     QLIST_ENTRY(BusState) sibling;
+    uint32_t resetting;
 };
 
 /**
@@ -378,6 +384,30 @@ int qdev_walk_children(DeviceState *dev,
                        qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
                        void *opaque);
 
+/**
+ * @qdev_reset:
+ * Reset the device @dev, @cold tell whether to do a cold or warm reset.
+ */
+void qdev_reset(DeviceState *dev, bool cold);
+
+/**
+ * @qbus_reset:
+ * Reset the bus @bus, @cold tell whether to do a cold or warm reset.
+ */
+void qbus_reset(BusState *bus, bool cold);
+
+/**
+ * @qdev_is_resetting:
+ * Tell whether the device @dev is currently under reset.
+ */
+bool qdev_is_resetting(DeviceState *dev);
+
+/**
+ * @qbus_is_resetting:
+ * Tell whether the bus @bus is currently under reset.
+ */
+bool qbus_is_resetting(BusState *bus);
+
 void qdev_reset_all(DeviceState *dev);
 void qdev_reset_all_fn(void *opaque);
 
Signature · 1 line
2.21.0
#4 lore raw

RFC PATCH 4/17 Add local reset methods in Device class

In reply to Damien Hedde

Add 3 methods in device class corresponding to the local part of the 3-phases reset. This allows specialization classes not to care about the ressetting counter and sub-buses. The exit phase method is called only if resetting counter hits 0.

Also, these methods are called in device_reset. Specializations can switch from the single-phase reset to the 3-phases reset with no effects on the device_reset behavior.

---
 hw/core/qdev.c         | 44 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/qdev-core.h | 17 ++++++++++++++++
 2 files changed, 61 insertions(+)
hw/core/qdev.c +44 -0
index 98d173f34f..884a49efa4 100644
@@ -280,21 +280,30 @@ static void device_reset_init_phase(Object *obj, bool cold)
     if (dc->reset) {
         dc->reset(dev);
     }
+    if (dc->reset_phases.init) {
+        dc->reset_phases.init(OBJECT(dev), cold);
+    }
 }
 
 static void device_reset_hold_phase(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
+    DeviceClass *dc = DEVICE_GET_CLASS(obj);
     BusState *child;
 
     QLIST_FOREACH(child, &dev->child_bus, sibling) {
         resettable_hold_phase(OBJECT(child));
     }
+
+    if (dc->reset_phases.hold) {
+        dc->reset_phases.hold(OBJECT(dev));
+    }
 }
 
 static void device_reset_exit_phase(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
+    DeviceClass *dc = DEVICE_GET_CLASS(obj);
     BusState *child;
 
     QLIST_FOREACH(child, &dev->child_bus, sibling) {
@@ -303,6 +312,12 @@ static void device_reset_exit_phase(Object *obj)
 
     assert(dev->resetting > 0);
     dev->resetting -= 1;
+
+    if (dev->resetting == 0) {
+        if (dc->reset_phases.exit) {
+            dc->reset_phases.exit(OBJECT(dev));
+        }
+    }
 }
 
 static int qdev_reset_one(DeviceState *dev, void *opaque)
@@ -1143,6 +1158,24 @@ void device_class_set_parent_unrealize(DeviceClass *dc,
     dc->unrealize = dev_unrealize;
 }
 
+void device_class_set_parent_reset_phases(DeviceClass *dc,
+                                   ResettableInitPhase dev_reset_init,
+                                   ResettableHoldPhase dev_reset_hold,
+                                   ResettableExitPhase dev_reset_exit,
+                                   ResettablePhases *parent_phases)
+{
+    *parent_phases = dc->reset_phases;
+    if (dev_reset_init) {
+        dc->reset_phases.init = dev_reset_init;
+    }
+    if (dev_reset_hold) {
+        dc->reset_phases.hold = dev_reset_hold;
+    }
+    if (dev_reset_exit) {
+        dc->reset_phases.exit = dev_reset_exit;
+    }
+}
+
 void device_reset(DeviceState *dev)
 {
     DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -1150,6 +1183,17 @@ void device_reset(DeviceState *dev)
     if (klass->reset) {
         klass->reset(dev);
     }
+    dev->resetting += 1;
+    if (klass->reset_phases.init) {
+        klass->reset_phases.init(OBJECT(dev), false);
+    }
+    if (klass->reset_phases.hold) {
+        klass->reset_phases.hold(OBJECT(dev));
+    }
+    dev->resetting -= 1;
+    if (klass->reset_phases.exit) {
+        klass->reset_phases.exit(OBJECT(dev));
+    }
 }
 
 Object *qdev_get_machine(void)
include/hw/qdev-core.h +17 -0
index f4aa8dbaa2..0ef4d6c920 100644
@@ -6,6 +6,7 @@
 #include "qom/object.h"
 #include "hw/irq.h"
 #include "hw/hotplug.h"
+#include "hw/resettable.h"
 
 enum {
     DEV_NVECTORS_UNSPECIFIED = -1,
@@ -110,6 +111,7 @@ typedef struct DeviceClass {
     DeviceReset reset;
     DeviceRealize realize;
     DeviceUnrealize unrealize;
+    ResettablePhases reset_phases;
 
     /* device state */
     const struct VMStateDescription *vmsd;
@@ -455,6 +457,21 @@ void device_class_set_parent_unrealize(DeviceClass *dc,
                                        DeviceUnrealize dev_unrealize,
                                        DeviceUnrealize *parent_unrealize);
 
+/**
+ * @device_class_set_parent_reset_phases:
+ *
+ * Save @dc current reset phases into @parent_phases and override @dc phases
+ * by the given new methods (@dev_reset_init, @dev_reset_hold and
+ * @dev_reset_exit).
+ * Each phase is overriden only if the new one is not NULL allowing to
+ * override a subset of phases.
+ */
+void device_class_set_parent_reset_phases(DeviceClass *dc,
+                                   ResettableInitPhase dev_reset_init,
+                                   ResettableHoldPhase dev_reset_hold,
+                                   ResettableExitPhase dev_reset_exit,
+                                   ResettablePhases *parent_phases);
+
 const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
 
 const char *qdev_fw_name(DeviceState *dev);
Signature · 1 line
2.21.0
#5 lore raw

RFC PATCH 5/17 add vmstate description for device reset state

In reply to Damien Hedde

The device_vmstate_reset can be added by device specialization, as vmsd subsection, to migrate the reset related device state part.

---
 hw/core/Makefile.objs  |  1 +
 hw/core/qdev-vmstate.c | 25 +++++++++++++++++++++++++
 include/hw/qdev-core.h |  6 ++++++
 3 files changed, 32 insertions(+)
 create mode 100644 hw/core/qdev-vmstate.c
hw/core/Makefile.objs +1 -0
index 320f71707c..562cf1034e 100644
@@ -5,6 +5,7 @@ common-obj-y += resettable.o
 common-obj-y += reset-domain.o
 common-obj-$(CONFIG_SOFTMMU) += qdev-fw.o
 common-obj-$(CONFIG_SOFTMMU) += fw-path-provider.o
+common-obj-$(CONFIG_SOFTMMU) += qdev-vmstate.o
 # irq.o needed for qdev GPIO handling:
 common-obj-y += irq.o
 common-obj-y += hotplug.o
hw/core/qdev-vmstate.c new file +25 -0
new file mode 100644
index 0000000000..a9834f1a1c
@@ -0,0 +1,25 @@
+/*
+ * Device vmstate
+ *
+ * Copyright (c) 2019 GreenSocs
+ *
+ * Authors:
+ *   Damien Hedde
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/qdev.h"
+#include "migration/vmstate.h"
+
+const struct VMStateDescription device_vmstate_reset = {
+    .name = "device_reset",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32(resetting, DeviceState),
+        VMSTATE_END_OF_LIST()
+    }
+};
include/hw/qdev-core.h +6 -0
index 0ef4d6c920..baad2e7066 100644
@@ -500,4 +500,10 @@ static inline bool qbus_is_hotpluggable(BusState *bus)
 void device_listener_register(DeviceListener *listener);
 void device_listener_unregister(DeviceListener *listener);
 
+/**
+ * device_vmstate_reset:
+ * vmstate entry for reset related state
+ */
+extern const struct VMStateDescription device_vmstate_reset;
+
 #endif
Signature · 1 line
2.21.0
#6 lore raw

RFC PATCH 6/17 Add function to control reset with gpio inputs

In reply to Damien Hedde

It adds the possibility to add 2 gpios to control the warm and cold reset. With theses ios, the reset can be maintained during some time. Each io is associated with a state to detect level changes.

The cold reset io function is named power_gate as it is really the meaning of this io.

---
 hw/core/qdev-vmstate.c |  2 ++
 hw/core/qdev.c         | 57 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/qdev-core.h | 44 ++++++++++++++++++++++++++++++++
 3 files changed, 103 insertions(+)
hw/core/qdev-vmstate.c +2 -0
index a9834f1a1c..dec6a72f75 100644
@@ -20,6 +20,8 @@ const struct VMStateDescription device_vmstate_reset = {
     .minimum_version_id = 0,
     .fields = (VMStateField[]) {
         VMSTATE_UINT32(resetting, DeviceState),
+        VMSTATE_BOOL(cold_reset_input.state, DeviceState),
+        VMSTATE_BOOL(warm_reset_input.state, DeviceState),
         VMSTATE_END_OF_LIST()
     }
 };
hw/core/qdev.c +57 -0

69 lines not on this page · raw message

include/hw/qdev-core.h +44 -0

62 lines not on this page · raw message

Signature · 1 line
2.21.0
#7 lore raw

RFC PATCH 7/17 convert qdev/bus_reset_all to Resettable

In reply to Damien Hedde

Change qdev/bus_reset_all implementation. It now triggers a warm reset using the Resettable interface.

---
 hw/core/qdev.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)
hw/core/qdev.c +2 -18
index 8dae26d957..7adf234474 100644
@@ -320,25 +320,9 @@ static void device_reset_exit_phase(Object *obj)
     }
 }
 
-static int qdev_reset_one(DeviceState *dev, void *opaque)
-{
-    device_reset(dev);
-
-    return 0;
-}
-
-static int qbus_reset_one(BusState *bus, void *opaque)
-{
-    BusClass *bc = BUS_GET_CLASS(bus);
-    if (bc->reset) {
-        bc->reset(bus);
-    }
-    return 0;
-}
-
 void qdev_reset_all(DeviceState *dev)
 {
-    qdev_walk_children(dev, NULL, NULL, qdev_reset_one, qbus_reset_one, NULL);
+    qdev_reset(dev, false);
 }
 
 void qdev_reset_all_fn(void *opaque)
@@ -348,7 +332,7 @@ void qdev_reset_all_fn(void *opaque)
 
 void qbus_reset_all(BusState *bus)
 {
-    qbus_walk_children(bus, NULL, NULL, qdev_reset_one, qbus_reset_one, NULL);
+    qbus_reset(bus, false);
 }
 
 void qbus_reset_all_fn(void *opaque)
Signature · 1 line
2.21.0
#8 lore raw

RFC PATCH 8/17 Add a global ResetDomain object for system emulation

In reply to Damien Hedde

All objects contained in this ResetDomain are cold-reset when calling qemu_devices_reset.
Also add 2 functions to register/unregister object in this ResetDomain.

---
 hw/core/reset.c        | 56 +++++++++++++++++++++++++++++++++++++++++-
 include/sysemu/reset.h | 47 +++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 1 deletion(-)
hw/core/reset.c +55 -1
index 9c477f2bf5..d013c9feb9 100644
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
  * Copyright (c) 2016 Red Hat, Inc.
+ * Copyright (c) 2019 GreenSocs
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,7 @@
 #include "qemu/osdep.h"
 #include "qemu/queue.h"
 #include "sysemu/reset.h"
+#include "hw/reset-domain.h"
 
 /* reset/shutdown handler */
 
@@ -38,6 +40,49 @@ typedef struct QEMUResetEntry {
 static QTAILQ_HEAD(, QEMUResetEntry) reset_handlers =
     QTAILQ_HEAD_INITIALIZER(reset_handlers);
 
+/* global/system reset domain */
+static ResetDomain *reset_domain;
+
+static ResetDomain *get_reset_domain(void)
+{
+    if (reset_domain == NULL) {
+        /*
+         * the ref to the object will be deleted by
+         * qemu_delete_system_reset_domain function below.
+         */
+        reset_domain = RESET_DOMAIN(object_new(TYPE_RESET_DOMAIN));
+    }
+    return reset_domain;
+}
+
+ResetDomain *qemu_get_system_reset_domain(void)
+{
+    return get_reset_domain();
+}
+
+void qemu_delete_system_reset_domain(void)
+{
+    /* unref the reset_domain object if it exists */
+    if (reset_domain != NULL) {
+        object_unref(OBJECT(reset_domain));
+        reset_domain = NULL;
+    }
+}
+
+void qemu_register_system_reset_domain_object(Object *obj)
+{
+    ResetDomain *domain = get_reset_domain();
+
+    reset_domain_register_object(domain, obj);
+}
+
+void qemu_unregister_system_reset_domain_object(Object *obj)
+{
+    ResetDomain *domain = get_reset_domain();
+
+    reset_domain_unregister_object(domain, obj);
+}
+
 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
 {
     QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
@@ -62,11 +107,20 @@ void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
 
 void qemu_devices_reset(void)
 {
+    qemu_system_reset_domain_reset(true);
+}
+
+void qemu_system_reset_domain_reset(bool cold)
+{
+    ResetDomain *domain = get_reset_domain();
     QEMUResetEntry *re, *nre;
 
-    /* reset all devices */
+    /* call function handlers first */
     QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
         re->func(re->opaque);
     }
+
+    /* then handle the objects in the ResetDomain */
+    resettable_reset(OBJECT(domain), cold);
 }
 
include/sysemu/reset.h +47 -0

57 lines not on this page · raw message

Signature · 1 line
2.21.0
#9 lore raw

RFC PATCH 9/17 global ResetDomain support for legacy reset handlers

In reply to Damien Hedde

INIT phase of the global ResetDomain now triggers the legacy reset handlers.
*qemu_devices_reset* is now equivalent to do a cold reset of the global ResetDomain.

---
 hw/core/reset.c | 109 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 95 insertions(+), 14 deletions(-)
hw/core/reset.c +95 -14
index d013c9feb9..1b25f9c8f8 100644
@@ -26,9 +26,31 @@
 
 #include "qemu/osdep.h"
 #include "qemu/queue.h"
+#include "qemu/module.h"
 #include "sysemu/reset.h"
 #include "hw/reset-domain.h"
 
+#define TYPE_SYSTEM_RESET_DOMAIN "system-reset-domain"
+#define SYSTEM_RESET_DOMAIN(obj) \
+    OBJECT_CHECK(SystemResetDomain, (obj), TYPE_SYSTEM_RESET_DOMAIN)
+#define SYSTEM_RESET_DOMAIN_CLASS(class) \
+    OBJECT_CLASS_CHECK(SystemResetDomainClass, (class), \
+                       TYPE_SYSTEM_RESET_DOMAIN)
+#define SYSTEM_RESET_DOMAIN_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(SystemResetDomainClass, (obj), \
+                     TYPE_SYSTEM_RESET_DOMAIN)
+
+/**
+ * SystemResetDomainClass:
+ * Class to hold the global reset domain and handlers
+ * @parent_init_phase hold parent init_phase method
+ */
+typedef struct SystemResetDomainClass {
+    ResetDomainClass parent_class;
+
+    ResettableInitPhase parent_init_phase;
+} SystemResetDomainClass;
+
 /* reset/shutdown handler */
 
 typedef struct QEMUResetEntry {
@@ -37,27 +59,35 @@ typedef struct QEMUResetEntry {
     void *opaque;
 } QEMUResetEntry;
 
-static QTAILQ_HEAD(, QEMUResetEntry) reset_handlers =
-    QTAILQ_HEAD_INITIALIZER(reset_handlers);
+/**
+ * SystemResetDomain:
+ * @reset_handlers list of legacy reset handlers
+ */
+typedef struct SystemResetDomain {
+    ResetDomain parent_obj;
+
+    QTAILQ_HEAD(, QEMUResetEntry) reset_handlers;
+} SystemResetDomain;
 
 /* global/system reset domain */
-static ResetDomain *reset_domain;
+static SystemResetDomain *reset_domain;
 
-static ResetDomain *get_reset_domain(void)
+static SystemResetDomain *get_reset_domain(void)
 {
     if (reset_domain == NULL) {
+        Object *obj = object_new(TYPE_SYSTEM_RESET_DOMAIN);
         /*
          * the ref to the object will be deleted by
          * qemu_delete_system_reset_domain function below.
          */
-        reset_domain = RESET_DOMAIN(object_new(TYPE_RESET_DOMAIN));
+        reset_domain = SYSTEM_RESET_DOMAIN(obj);
     }
     return reset_domain;
 }
 
 ResetDomain *qemu_get_system_reset_domain(void)
 {
-    return get_reset_domain();
+    return RESET_DOMAIN(get_reset_domain());
 }
 
 void qemu_delete_system_reset_domain(void)
@@ -71,34 +101,36 @@ void qemu_delete_system_reset_domain(void)
 
 void qemu_register_system_reset_domain_object(Object *obj)
 {
-    ResetDomain *domain = get_reset_domain();
+    ResetDomain *domain = RESET_DOMAIN(get_reset_domain());
 
     reset_domain_register_object(domain, obj);
 }
 
 void qemu_unregister_system_reset_domain_object(Object *obj)
 {
-    ResetDomain *domain = get_reset_domain();
+    ResetDomain *domain = RESET_DOMAIN(get_reset_domain());
 
     reset_domain_unregister_object(domain, obj);
 }
 
 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
 {
+    SystemResetDomain *domain = get_reset_domain();
     QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
 
     re->func = func;
     re->opaque = opaque;
-    QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
+    QTAILQ_INSERT_TAIL(&domain->reset_handlers, re, entry);
 }
 
 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
 {
+    SystemResetDomain *domain = get_reset_domain();
     QEMUResetEntry *re;
 
-    QTAILQ_FOREACH(re, &reset_handlers, entry) {
+    QTAILQ_FOREACH(re, &domain->reset_handlers, entry) {
         if (re->func == func && re->opaque == opaque) {
-            QTAILQ_REMOVE(&reset_handlers, re, entry);
+            QTAILQ_REMOVE(&domain->reset_handlers, re, entry);
             g_free(re);
             return;
         }
@@ -112,15 +144,64 @@ void qemu_devices_reset(void)
 
 void qemu_system_reset_domain_reset(bool cold)
 {
-    ResetDomain *domain = get_reset_domain();
+    resettable_reset(OBJECT(get_reset_domain()), cold);
+}
+
+static void system_reset_domain_init_phase(Object *obj, bool cold)
+{
+    SystemResetDomain *domain = SYSTEM_RESET_DOMAIN(obj);
+    SystemResetDomainClass *srdc = SYSTEM_RESET_DOMAIN_GET_CLASS(obj);
     QEMUResetEntry *re, *nre;
 
     /* call function handlers first */
-    QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
+    QTAILQ_FOREACH_SAFE(re, &domain->reset_handlers, entry, nre) {
         re->func(re->opaque);
     }
 
     /* then handle the objects in the ResetDomain */
-    resettable_reset(OBJECT(domain), cold);
+    srdc->parent_init_phase(OBJECT(domain), cold);
+}
+
+static void system_reset_domain_init(Object *obj)
+{
+    SystemResetDomain *domain = SYSTEM_RESET_DOMAIN(obj);
+
+    QTAILQ_INIT(&domain->reset_handlers);
+}
+
+static void system_reset_domain_finalize(Object *obj)
+{
+    SystemResetDomain *domain = SYSTEM_RESET_DOMAIN(obj);
+    QEMUResetEntry *re, *nre;
+
+    QTAILQ_FOREACH_SAFE(re, &domain->reset_handlers, entry, nre) {
+        QTAILQ_REMOVE(&domain->reset_handlers, re, entry);
+        g_free(re);
+    }
+}
+
+static void system_reset_domain_class_init(ObjectClass *class, void *data)
+{
+    ResettableClass *rc = RESETTABLE_CLASS(class);
+    SystemResetDomainClass *srdc = SYSTEM_RESET_DOMAIN_CLASS(class);
+
+    srdc->parent_init_phase = rc->phases.init;
+    rc->phases.init = system_reset_domain_init_phase;
+}
+
+static const TypeInfo system_reset_domain_type_info = {
+    .name = TYPE_SYSTEM_RESET_DOMAIN,
+    .parent = TYPE_RESET_DOMAIN,
+    .instance_size = sizeof(SystemResetDomain),
+    .instance_init = system_reset_domain_init,
+    .instance_finalize = system_reset_domain_finalize,
+    .class_init = system_reset_domain_class_init,
+    .class_size = sizeof(SystemResetDomainClass),
+};
+
+static void system_reset_register_types(void)
+{
+    type_register_static(&system_reset_domain_type_info);
 }
 
+type_init(system_reset_register_types)
Signature · 1 line
2.21.0
#10 lore raw

RFC PATCH 10/17 Delete the system ResetDomain at the end of emulation

In reply to Damien Hedde
---
 vl.c | 1 +
 1 file changed, 1 insertion(+)
vl.c +1 -0
index d61d5604e5..cf081d5264 100644
@@ -4611,6 +4611,7 @@ int main(int argc, char **argv, char **envp)
     monitor_cleanup();
     qemu_chr_cleanup();
     user_creatable_cleanup();
+    qemu_delete_system_reset_domain();
     /* TODO: unref root container, check all devices are ok */
 
     return 0;
Signature · 1 line
2.21.0
#11 lore raw

RFC PATCH 11/17 Put orphan buses in system reset domain

In reply to Damien Hedde

Switch from the legacy reset handlers to the system reset domain in order to use the Resettable interface.

---
 hw/core/bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/core/bus.c +2 -2
index 0a60bb4b24..73b215d2bb 100644
@@ -150,7 +150,7 @@ static void qbus_realize(BusState *bus, DeviceState *parent, const char *name)
     } else if (bus != sysbus_get_default()) {
         /* TODO: once all bus devices are qdevified,
            only reset handler for main_system_bus should be registered here. */
-        qemu_register_reset(qbus_reset_all_fn, bus);
+        qemu_register_system_reset_domain_object(OBJECT(bus));
     }
 }
 
@@ -169,7 +169,7 @@ static void bus_unparent(Object *obj)
         bus->parent = NULL;
     } else {
         assert(bus != sysbus_get_default()); /* main_system_bus is never freed */
-        qemu_unregister_reset(qbus_reset_all_fn, bus);
+        qemu_unregister_system_reset_domain_object(OBJECT(bus));
     }
 }
 
Signature · 1 line
2.21.0
#12 lore raw

RFC PATCH 12/17 Put default sysbus in system reset domain

In reply to Damien Hedde

Switch from reset handler to Resettable interface.

---
 vl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +1 -1
index cf081d5264..e67f6e6c50 100644
@@ -4537,7 +4537,7 @@ int main(int argc, char **argv, char **envp)
 
     /* TODO: once all bus devices are qdevified, this should be done
      * when bus is created by qdev.c */
-    qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
+    qemu_register_system_reset_domain_object(OBJECT(sysbus_get_default()));
     qemu_run_machine_init_done_notifiers();
 
     if (rom_check_and_register_reset() != 0) {
Signature · 1 line
2.21.0
#13 lore raw

RFC PATCH 13/17 hw/misc/zynq_slcr: use standard register definition

In reply to Damien Hedde

Replace the zynq_slcr registers enum and macros using the hw/registerfields.h macros.

---
 hw/misc/zynq_slcr.c | 472 ++++++++++++++++++++++----------------------
 1 file changed, 236 insertions(+), 236 deletions(-)
hw/misc/zynq_slcr.c +236 -236
index d6bdd027ef..baa13d1316 100644
@@ -20,6 +20,7 @@
 #include "hw/sysbus.h"
 #include "sysemu/sysemu.h"
 #include "qemu/log.h"
+#include "hw/registerfields.h"
 
 #ifndef ZYNQ_SLCR_ERR_DEBUG
 #define ZYNQ_SLCR_ERR_DEBUG 0
@@ -35,138 +36,135 @@
 #define XILINX_LOCK_KEY 0x767b
 #define XILINX_UNLOCK_KEY 0xdf0d
 
-#define R_PSS_RST_CTRL_SOFT_RST 0x1
-
-enum {
-    SCL             = 0x000 / 4,
-    LOCK,
-    UNLOCK,
-    LOCKSTA,
-
-    ARM_PLL_CTRL    = 0x100 / 4,
-    DDR_PLL_CTRL,
-    IO_PLL_CTRL,
-    PLL_STATUS,
-    ARM_PLL_CFG,
-    DDR_PLL_CFG,
-    IO_PLL_CFG,
-
-    ARM_CLK_CTRL    = 0x120 / 4,
-    DDR_CLK_CTRL,
-    DCI_CLK_CTRL,
-    APER_CLK_CTRL,
-    USB0_CLK_CTRL,
-    USB1_CLK_CTRL,
-    GEM0_RCLK_CTRL,
-    GEM1_RCLK_CTRL,
-    GEM0_CLK_CTRL,
-    GEM1_CLK_CTRL,
-    SMC_CLK_CTRL,
-    LQSPI_CLK_CTRL,
-    SDIO_CLK_CTRL,
-    UART_CLK_CTRL,
-    SPI_CLK_CTRL,
-    CAN_CLK_CTRL,
-    CAN_MIOCLK_CTRL,
-    DBG_CLK_CTRL,
-    PCAP_CLK_CTRL,
-    TOPSW_CLK_CTRL,
+REG32(SCL, 0x000)
+REG32(LOCK, 0x004)
+REG32(UNLOCK, 0x008)
+REG32(LOCKSTA, 0x00c)
+
+REG32(ARM_PLL_CTRL, 0x100)
+REG32(DDR_PLL_CTRL, 0x104)
+REG32(IO_PLL_CTRL, 0x108)
+REG32(PLL_STATUS, 0x10c)
+REG32(ARM_PLL_CFG, 0x110)
+REG32(DDR_PLL_CFG, 0x114)
+REG32(IO_PLL_CFG, 0x118)
+
+REG32(ARM_CLK_CTRL, 0x120)
+REG32(DDR_CLK_CTRL, 0x124)
+REG32(DCI_CLK_CTRL, 0x128)
+REG32(APER_CLK_CTRL, 0x12c)
+REG32(USB0_CLK_CTRL, 0x130)
+REG32(USB1_CLK_CTRL, 0x134)
+REG32(GEM0_RCLK_CTRL, 0x138)
+REG32(GEM1_RCLK_CTRL, 0x13c)
+REG32(GEM0_CLK_CTRL, 0x140)
+REG32(GEM1_CLK_CTRL, 0x144)
+REG32(SMC_CLK_CTRL, 0x148)
+REG32(LQSPI_CLK_CTRL, 0x14c)
+REG32(SDIO_CLK_CTRL, 0x150)
+REG32(UART_CLK_CTRL, 0x154)
+REG32(SPI_CLK_CTRL, 0x158)
+REG32(CAN_CLK_CTRL, 0x15c)
+REG32(CAN_MIOCLK_CTRL, 0x160)
+REG32(DBG_CLK_CTRL, 0x164)
+REG32(PCAP_CLK_CTRL, 0x168)
+REG32(TOPSW_CLK_CTRL, 0x16c)
 
 #define FPGA_CTRL_REGS(n, start) \
-    FPGA ## n ## _CLK_CTRL = (start) / 4, \
-    FPGA ## n ## _THR_CTRL, \
-    FPGA ## n ## _THR_CNT, \
-    FPGA ## n ## _THR_STA,
-    FPGA_CTRL_REGS(0, 0x170)
-    FPGA_CTRL_REGS(1, 0x180)
-    FPGA_CTRL_REGS(2, 0x190)
-    FPGA_CTRL_REGS(3, 0x1a0)
-
-    BANDGAP_TRIP    = 0x1b8 / 4,
-    PLL_PREDIVISOR  = 0x1c0 / 4,
-    CLK_621_TRUE,
-
-    PSS_RST_CTRL    = 0x200 / 4,
-    DDR_RST_CTRL,
-    TOPSW_RESET_CTRL,
-    DMAC_RST_CTRL,
-    USB_RST_CTRL,
-    GEM_RST_CTRL,
-    SDIO_RST_CTRL,
-    SPI_RST_CTRL,
-    CAN_RST_CTRL,
-    I2C_RST_CTRL,
-    UART_RST_CTRL,
-    GPIO_RST_CTRL,
-    LQSPI_RST_CTRL,
-    SMC_RST_CTRL,
-    OCM_RST_CTRL,
-    FPGA_RST_CTRL   = 0x240 / 4,
-    A9_CPU_RST_CTRL,
-
-    RS_AWDT_CTRL    = 0x24c / 4,
-    RST_REASON,
-
-    REBOOT_STATUS   = 0x258 / 4,
-    BOOT_MODE,
-
-    APU_CTRL        = 0x300 / 4,
-    WDT_CLK_SEL,
-
-    TZ_DMA_NS       = 0x440 / 4,
-    TZ_DMA_IRQ_NS,
-    TZ_DMA_PERIPH_NS,
-
-    PSS_IDCODE      = 0x530 / 4,
-
-    DDR_URGENT      = 0x600 / 4,
-    DDR_CAL_START   = 0x60c / 4,
-    DDR_REF_START   = 0x614 / 4,
-    DDR_CMD_STA,
-    DDR_URGENT_SEL,
-    DDR_DFI_STATUS,
-
-    MIO             = 0x700 / 4,
+    REG32(FPGA ## n ## _CLK_CTRL, (start)) \
+    REG32(FPGA ## n ## _THR_CTRL, (start) + 0x4)\
+    REG32(FPGA ## n ## _THR_CNT,  (start) + 0x8)\
+    REG32(FPGA ## n ## _THR_STA,  (start) + 0xc)
+FPGA_CTRL_REGS(0, 0x170)
+FPGA_CTRL_REGS(1, 0x180)
+FPGA_CTRL_REGS(2, 0x190)
+FPGA_CTRL_REGS(3, 0x1a0)
+
+REG32(BANDGAP_TRIP, 0x1b8)
+REG32(PLL_PREDIVISOR, 0x1c0)
+REG32(CLK_621_TRUE, 0x1c4)
+
+REG32(PSS_RST_CTRL, 0x200)
+    FIELD(PSS_RST_CTRL, SOFT_RST, 0, 1)
+REG32(DDR_RST_CTRL, 0x204)
+REG32(TOPSW_RESET_CTRL, 0x208)
+REG32(DMAC_RST_CTRL, 0x20c)
+REG32(USB_RST_CTRL, 0x210)
+REG32(GEM_RST_CTRL, 0x214)
+REG32(SDIO_RST_CTRL, 0x218)
+REG32(SPI_RST_CTRL, 0x21c)
+REG32(CAN_RST_CTRL, 0x220)
+REG32(I2C_RST_CTRL, 0x224)
+REG32(UART_RST_CTRL, 0x228)
+REG32(GPIO_RST_CTRL, 0x22c)
+REG32(LQSPI_RST_CTRL, 0x230)
+REG32(SMC_RST_CTRL, 0x234)
+REG32(OCM_RST_CTRL, 0x238)
+REG32(FPGA_RST_CTRL, 0x240)
+REG32(A9_CPU_RST_CTRL, 0x244)
+
+REG32(RS_AWDT_CTRL, 0x24c)
+REG32(RST_REASON, 0x250)
+
+REG32(REBOOT_STATUS, 0x258)
+REG32(BOOT_MODE, 0x25c)
+
+REG32(APU_CTRL, 0x300)
+REG32(WDT_CLK_SEL, 0x304)
+
+REG32(TZ_DMA_NS, 0x440)
+REG32(TZ_DMA_IRQ_NS, 0x444)
+REG32(TZ_DMA_PERIPH_NS, 0x448)
+
+REG32(PSS_IDCODE, 0x530)
+
+REG32(DDR_URGENT, 0x600)
+REG32(DDR_CAL_START, 0x60c)
+REG32(DDR_REF_START, 0x614)
+REG32(DDR_CMD_STA, 0x618)
+REG32(DDR_URGENT_SEL, 0x61c)
+REG32(DDR_DFI_STATUS, 0x620)
+
+REG32(MIO, 0x700)
 #define MIO_LENGTH 54
 
-    MIO_LOOPBACK    = 0x804 / 4,
-    MIO_MST_TRI0,
-    MIO_MST_TRI1,
+REG32(MIO_LOOPBACK, 0x804)
+REG32(MIO_MST_TRI0, 0x808)
+REG32(MIO_MST_TRI1, 0x80c)
 
-    SD0_WP_CD_SEL   = 0x830 / 4,
-    SD1_WP_CD_SEL,
+REG32(SD0_WP_CD_SEL, 0x830)
+REG32(SD1_WP_CD_SEL, 0x834)
 
-    LVL_SHFTR_EN    = 0x900 / 4,
-    OCM_CFG         = 0x910 / 4,
+REG32(LVL_SHFTR_EN, 0x900)
+REG32(OCM_CFG, 0x910)
 
-    CPU_RAM         = 0xa00 / 4,
+REG32(CPU_RAM, 0xa00)
 
-    IOU             = 0xa30 / 4,
+REG32(IOU, 0xa30)
 
-    DMAC_RAM        = 0xa50 / 4,
+REG32(DMAC_RAM, 0xa50)
 
-    AFI0            = 0xa60 / 4,
-    AFI1 = AFI0 + 3,
-    AFI2 = AFI1 + 3,
-    AFI3 = AFI2 + 3,
+REG32(AFI0, 0xa60)
+REG32(AFI1, 0xa6c)
+REG32(AFI2, 0xa78)
+REG32(AFI3, 0xa84)
 #define AFI_LENGTH 3
 
-    OCM             = 0xa90 / 4,
+REG32(OCM, 0xa90)
 
-    DEVCI_RAM       = 0xaa0 / 4,
+REG32(DEVCI_RAM, 0xaa0)
 
-    CSG_RAM         = 0xab0 / 4,
+REG32(CSG_RAM, 0xab0)
 
-    GPIOB_CTRL      = 0xb00 / 4,
-    GPIOB_CFG_CMOS18,
-    GPIOB_CFG_CMOS25,
-    GPIOB_CFG_CMOS33,
-    GPIOB_CFG_HSTL  = 0xb14 / 4,
-    GPIOB_DRVR_BIAS_CTRL,
+REG32(GPIOB_CTRL, 0xb00)
+REG32(GPIOB_CFG_CMOS18, 0xb04)
+REG32(GPIOB_CFG_CMOS25, 0xb08)
+REG32(GPIOB_CFG_CMOS33, 0xb0c)
+REG32(GPIOB_CFG_HSTL, 0xb14)
+REG32(GPIOB_DRVR_BIAS_CTRL, 0xb18)
 
-    DDRIOB          = 0xb40 / 4,
+REG32(DDRIOB, 0xb40)
 #define DDRIOB_LENGTH 14
-};
 
 #define ZYNQ_SLCR_MMIO_SIZE     0x1000
 #define ZYNQ_SLCR_NUM_REGS      (ZYNQ_SLCR_MMIO_SIZE / 4)
@@ -189,150 +187,152 @@ static void zynq_slcr_reset(DeviceState *d)
 
     DB_PRINT("RESET\n");
 
-    s->regs[LOCKSTA] = 1;
+    s->regs[R_LOCKSTA] = 1;
     /* 0x100 - 0x11C */
-    s->regs[ARM_PLL_CTRL]   = 0x0001A008;
-    s->regs[DDR_PLL_CTRL]   = 0x0001A008;
-    s->regs[IO_PLL_CTRL]    = 0x0001A008;
-    s->regs[PLL_STATUS]     = 0x0000003F;
-    s->regs[ARM_PLL_CFG]    = 0x00014000;
-    s->regs[DDR_PLL_CFG]    = 0x00014000;
-    s->regs[IO_PLL_CFG]     = 0x00014000;
+    s->regs[R_ARM_PLL_CTRL]   = 0x0001A008;
+    s->regs[R_DDR_PLL_CTRL]   = 0x0001A008;
+    s->regs[R_IO_PLL_CTRL]    = 0x0001A008;
+    s->regs[R_PLL_STATUS]     = 0x0000003F;
+    s->regs[R_ARM_PLL_CFG]    = 0x00014000;
+    s->regs[R_DDR_PLL_CFG]    = 0x00014000;
+    s->regs[R_IO_PLL_CFG]     = 0x00014000;
 
     /* 0x120 - 0x16C */
-    s->regs[ARM_CLK_CTRL]   = 0x1F000400;
-    s->regs[DDR_CLK_CTRL]   = 0x18400003;
-    s->regs[DCI_CLK_CTRL]   = 0x01E03201;
-    s->regs[APER_CLK_CTRL]  = 0x01FFCCCD;
-    s->regs[USB0_CLK_CTRL]  = s->regs[USB1_CLK_CTRL]    = 0x00101941;
-    s->regs[GEM0_RCLK_CTRL] = s->regs[GEM1_RCLK_CTRL]   = 0x00000001;
-    s->regs[GEM0_CLK_CTRL]  = s->regs[GEM1_CLK_CTRL]    = 0x00003C01;
-    s->regs[SMC_CLK_CTRL]   = 0x00003C01;
-    s->regs[LQSPI_CLK_CTRL] = 0x00002821;
-    s->regs[SDIO_CLK_CTRL]  = 0x00001E03;
-    s->regs[UART_CLK_CTRL]  = 0x00003F03;
-    s->regs[SPI_CLK_CTRL]   = 0x00003F03;
-    s->regs[CAN_CLK_CTRL]   = 0x00501903;
-    s->regs[DBG_CLK_CTRL]   = 0x00000F03;
-    s->regs[PCAP_CLK_CTRL]  = 0x00000F01;
+    s->regs[R_ARM_CLK_CTRL]   = 0x1F000400;
+    s->regs[R_DDR_CLK_CTRL]   = 0x18400003;
+    s->regs[R_DCI_CLK_CTRL]   = 0x01E03201;
+    s->regs[R_APER_CLK_CTRL]  = 0x01FFCCCD;
+    s->regs[R_USB0_CLK_CTRL]  = s->regs[R_USB1_CLK_CTRL]  = 0x00101941;
+    s->regs[R_GEM0_RCLK_CTRL] = s->regs[R_GEM1_RCLK_CTRL] = 0x00000001;
+    s->regs[R_GEM0_CLK_CTRL]  = s->regs[R_GEM1_CLK_CTRL]  = 0x00003C01;
+    s->regs[R_SMC_CLK_CTRL]   = 0x00003C01;
+    s->regs[R_LQSPI_CLK_CTRL] = 0x00002821;
+    s->regs[R_SDIO_CLK_CTRL]  = 0x00001E03;
+    s->regs[R_UART_CLK_CTRL]  = 0x00003F03;
+    s->regs[R_SPI_CLK_CTRL]   = 0x00003F03;
+    s->regs[R_CAN_CLK_CTRL]   = 0x00501903;
+    s->regs[R_DBG_CLK_CTRL]   = 0x00000F03;
+    s->regs[R_PCAP_CLK_CTRL]  = 0x00000F01;
 
     /* 0x170 - 0x1AC */
-    s->regs[FPGA0_CLK_CTRL] = s->regs[FPGA1_CLK_CTRL] = s->regs[FPGA2_CLK_CTRL]
-                            = s->regs[FPGA3_CLK_CTRL] = 0x00101800;
-    s->regs[FPGA0_THR_STA] = s->regs[FPGA1_THR_STA] = s->regs[FPGA2_THR_STA]
-                           = s->regs[FPGA3_THR_STA] = 0x00010000;
+    s->regs[R_FPGA0_CLK_CTRL] = s->regs[R_FPGA1_CLK_CTRL]
+                              = s->regs[R_FPGA2_CLK_CTRL]
+                              = s->regs[R_FPGA3_CLK_CTRL] = 0x00101800;
+    s->regs[R_FPGA0_THR_STA] = s->regs[R_FPGA1_THR_STA]
+                             = s->regs[R_FPGA2_THR_STA]
+                             = s->regs[R_FPGA3_THR_STA] = 0x00010000;
 
     /* 0x1B0 - 0x1D8 */
-    s->regs[BANDGAP_TRIP]   = 0x0000001F;
-    s->regs[PLL_PREDIVISOR] = 0x00000001;
-    s->regs[CLK_621_TRUE]   = 0x00000001;
+    s->regs[R_BANDGAP_TRIP]   = 0x0000001F;
+    s->regs[R_PLL_PREDIVISOR] = 0x00000001;
+    s->regs[R_CLK_621_TRUE]   = 0x00000001;
 
     /* 0x200 - 0x25C */
-    s->regs[FPGA_RST_CTRL]  = 0x01F33F0F;
-    s->regs[RST_REASON]     = 0x00000040;
+    s->regs[R_FPGA_RST_CTRL]  = 0x01F33F0F;
+    s->regs[R_RST_REASON]     = 0x00000040;
 
-    s->regs[BOOT_MODE]      = 0x00000001;
+    s->regs[R_BOOT_MODE]      = 0x00000001;
 
     /* 0x700 - 0x7D4 */
     for (i = 0; i < 54; i++) {
-        s->regs[MIO + i] = 0x00001601;
+        s->regs[R_MIO + i] = 0x00001601;
     }
     for (i = 2; i <= 8; i++) {
-        s->regs[MIO + i] = 0x00000601;
+        s->regs[R_MIO + i] = 0x00000601;
     }
 
-    s->regs[MIO_MST_TRI0] = s->regs[MIO_MST_TRI1] = 0xFFFFFFFF;
+    s->regs[R_MIO_MST_TRI0] = s->regs[R_MIO_MST_TRI1] = 0xFFFFFFFF;
 
-    s->regs[CPU_RAM + 0] = s->regs[CPU_RAM + 1] = s->regs[CPU_RAM + 3]
-                         = s->regs[CPU_RAM + 4] = s->regs[CPU_RAM + 7]
-                         = 0x00010101;
-    s->regs[CPU_RAM + 2] = s->regs[CPU_RAM + 5] = 0x01010101;
-    s->regs[CPU_RAM + 6] = 0x00000001;
+    s->regs[R_CPU_RAM + 0] = s->regs[R_CPU_RAM + 1] = s->regs[R_CPU_RAM + 3]
+                           = s->regs[R_CPU_RAM + 4] = s->regs[R_CPU_RAM + 7]
+                           = 0x00010101;
+    s->regs[R_CPU_RAM + 2] = s->regs[R_CPU_RAM + 5] = 0x01010101;
+    s->regs[R_CPU_RAM + 6] = 0x00000001;
 
-    s->regs[IOU + 0] = s->regs[IOU + 1] = s->regs[IOU + 2] = s->regs[IOU + 3]
-                     = 0x09090909;
-    s->regs[IOU + 4] = s->regs[IOU + 5] = 0x00090909;
-    s->regs[IOU + 6] = 0x00000909;
+    s->regs[R_IOU + 0] = s->regs[R_IOU + 1] = s->regs[R_IOU + 2]
+                       = s->regs[R_IOU + 3] = 0x09090909;
+    s->regs[R_IOU + 4] = s->regs[R_IOU + 5] = 0x00090909;
+    s->regs[R_IOU + 6] = 0x00000909;
 
-    s->regs[DMAC_RAM] = 0x00000009;
+    s->regs[R_DMAC_RAM] = 0x00000009;
 
-    s->regs[AFI0 + 0] = s->regs[AFI0 + 1] = 0x09090909;
-    s->regs[AFI1 + 0] = s->regs[AFI1 + 1] = 0x09090909;
-    s->regs[AFI2 + 0] = s->regs[AFI2 + 1] = 0x09090909;
-    s->regs[AFI3 + 0] = s->regs[AFI3 + 1] = 0x09090909;
-    s->regs[AFI0 + 2] = s->regs[AFI1 + 2] = s->regs[AFI2 + 2]
-                      = s->regs[AFI3 + 2] = 0x00000909;
+    s->regs[R_AFI0 + 0] = s->regs[R_AFI0 + 1] = 0x09090909;
+    s->regs[R_AFI1 + 0] = s->regs[R_AFI1 + 1] = 0x09090909;
+    s->regs[R_AFI2 + 0] = s->regs[R_AFI2 + 1] = 0x09090909;
+    s->regs[R_AFI3 + 0] = s->regs[R_AFI3 + 1] = 0x09090909;
+    s->regs[R_AFI0 + 2] = s->regs[R_AFI1 + 2] = s->regs[R_AFI2 + 2]
+                        = s->regs[R_AFI3 + 2] = 0x00000909;
 
-    s->regs[OCM + 0]    = 0x01010101;
-    s->regs[OCM + 1]    = s->regs[OCM + 2] = 0x09090909;
+    s->regs[R_OCM + 0] = 0x01010101;
+    s->regs[R_OCM + 1] = s->regs[R_OCM + 2] = 0x09090909;
 
-    s->regs[DEVCI_RAM]  = 0x00000909;
-    s->regs[CSG_RAM]    = 0x00000001;
+    s->regs[R_DEVCI_RAM] = 0x00000909;
+    s->regs[R_CSG_RAM]   = 0x00000001;
 
-    s->regs[DDRIOB + 0] = s->regs[DDRIOB + 1] = s->regs[DDRIOB + 2]
-                        = s->regs[DDRIOB + 3] = 0x00000e00;
-    s->regs[DDRIOB + 4] = s->regs[DDRIOB + 5] = s->regs[DDRIOB + 6]
-                        = 0x00000e00;
-    s->regs[DDRIOB + 12] = 0x00000021;
+    s->regs[R_DDRIOB + 0] = s->regs[R_DDRIOB + 1] = s->regs[R_DDRIOB + 2]
+                          = s->regs[R_DDRIOB + 3] = 0x00000e00;
+    s->regs[R_DDRIOB + 4] = s->regs[R_DDRIOB + 5] = s->regs[R_DDRIOB + 6]
+                          = 0x00000e00;
+    s->regs[R_DDRIOB + 12] = 0x00000021;
 }
 
 
 static bool zynq_slcr_check_offset(hwaddr offset, bool rnw)
 {
     switch (offset) {
-    case LOCK:
-    case UNLOCK:
-    case DDR_CAL_START:
-    case DDR_REF_START:
+    case R_LOCK:
+    case R_UNLOCK:
+    case R_DDR_CAL_START:
+    case R_DDR_REF_START:
         return !rnw; /* Write only */
-    case LOCKSTA:
-    case FPGA0_THR_STA:
-    case FPGA1_THR_STA:
-    case FPGA2_THR_STA:
-    case FPGA3_THR_STA:
-    case BOOT_MODE:
-    case PSS_IDCODE:
-    case DDR_CMD_STA:
-    case DDR_DFI_STATUS:
-    case PLL_STATUS:
+    case R_LOCKSTA:
+    case R_FPGA0_THR_STA:
+    case R_FPGA1_THR_STA:
+    case R_FPGA2_THR_STA:
+    case R_FPGA3_THR_STA:
+    case R_BOOT_MODE:
+    case R_PSS_IDCODE:
+    case R_DDR_CMD_STA:
+    case R_DDR_DFI_STATUS:
+    case R_PLL_STATUS:
         return rnw;/* read only */
-    case SCL:
-    case ARM_PLL_CTRL ... IO_PLL_CTRL:
-    case ARM_PLL_CFG ... IO_PLL_CFG:
-    case ARM_CLK_CTRL ... TOPSW_CLK_CTRL:
-    case FPGA0_CLK_CTRL ... FPGA0_THR_CNT:
-    case FPGA1_CLK_CTRL ... FPGA1_THR_CNT:
-    case FPGA2_CLK_CTRL ... FPGA2_THR_CNT:
-    case FPGA3_CLK_CTRL ... FPGA3_THR_CNT:
-    case BANDGAP_TRIP:
-    case PLL_PREDIVISOR:
-    case CLK_621_TRUE:
-    case PSS_RST_CTRL ... A9_CPU_RST_CTRL:
-    case RS_AWDT_CTRL:
-    case RST_REASON:
-    case REBOOT_STATUS:
-    case APU_CTRL:
-    case WDT_CLK_SEL:
-    case TZ_DMA_NS ... TZ_DMA_PERIPH_NS:
-    case DDR_URGENT:
-    case DDR_URGENT_SEL:
-    case MIO ... MIO + MIO_LENGTH - 1:
-    case MIO_LOOPBACK ... MIO_MST_TRI1:
-    case SD0_WP_CD_SEL:
-    case SD1_WP_CD_SEL:
-    case LVL_SHFTR_EN:
-    case OCM_CFG:
-    case CPU_RAM:
-    case IOU:
-    case DMAC_RAM:
-    case AFI0 ... AFI3 + AFI_LENGTH - 1:
-    case OCM:
-    case DEVCI_RAM:
-    case CSG_RAM:
-    case GPIOB_CTRL ... GPIOB_CFG_CMOS33:
-    case GPIOB_CFG_HSTL:
-    case GPIOB_DRVR_BIAS_CTRL:
-    case DDRIOB ... DDRIOB + DDRIOB_LENGTH - 1:
+    case R_SCL:
+    case R_ARM_PLL_CTRL ... R_IO_PLL_CTRL:
+    case R_ARM_PLL_CFG ... R_IO_PLL_CFG:
+    case R_ARM_CLK_CTRL ... R_TOPSW_CLK_CTRL:
+    case R_FPGA0_CLK_CTRL ... R_FPGA0_THR_CNT:
+    case R_FPGA1_CLK_CTRL ... R_FPGA1_THR_CNT:
+    case R_FPGA2_CLK_CTRL ... R_FPGA2_THR_CNT:
+    case R_FPGA3_CLK_CTRL ... R_FPGA3_THR_CNT:
+    case R_BANDGAP_TRIP:
+    case R_PLL_PREDIVISOR:
+    case R_CLK_621_TRUE:
+    case R_PSS_RST_CTRL ... R_A9_CPU_RST_CTRL:
+    case R_RS_AWDT_CTRL:
+    case R_RST_REASON:
+    case R_REBOOT_STATUS:
+    case R_APU_CTRL:
+    case R_WDT_CLK_SEL:
+    case R_TZ_DMA_NS ... R_TZ_DMA_PERIPH_NS:
+    case R_DDR_URGENT:
+    case R_DDR_URGENT_SEL:
+    case R_MIO ... R_MIO + MIO_LENGTH - 1:
+    case R_MIO_LOOPBACK ... R_MIO_MST_TRI1:
+    case R_SD0_WP_CD_SEL:
+    case R_SD1_WP_CD_SEL:
+    case R_LVL_SHFTR_EN:
+    case R_OCM_CFG:
+    case R_CPU_RAM:
+    case R_IOU:
+    case R_DMAC_RAM:
+    case R_AFI0 ... R_AFI3 + AFI_LENGTH - 1:
+    case R_OCM:
+    case R_DEVCI_RAM:
+    case R_CSG_RAM:
+    case R_GPIOB_CTRL ... R_GPIOB_CFG_CMOS33:
+    case R_GPIOB_CFG_HSTL:
+    case R_GPIOB_DRVR_BIAS_CTRL:
+    case R_DDRIOB ... R_DDRIOB + DDRIOB_LENGTH - 1:
         return true;
     default:
         return false;
@@ -370,24 +370,24 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,
     }
 
     switch (offset) {
-    case SCL:
-        s->regs[SCL] = val & 0x1;
+    case R_SCL:
+        s->regs[R_SCL] = val & 0x1;
         return;
-    case LOCK:
+    case R_LOCK:
         if ((val & 0xFFFF) == XILINX_LOCK_KEY) {
             DB_PRINT("XILINX LOCK 0xF8000000 + 0x%x <= 0x%x\n", (int)offset,
                 (unsigned)val & 0xFFFF);
-            s->regs[LOCKSTA] = 1;
+            s->regs[R_LOCKSTA] = 1;
         } else {
             DB_PRINT("WRONG XILINX LOCK KEY 0xF8000000 + 0x%x <= 0x%x\n",
                 (int)offset, (unsigned)val & 0xFFFF);
         }
         return;
-    case UNLOCK:
+    case R_UNLOCK:
         if ((val & 0xFFFF) == XILINX_UNLOCK_KEY) {
             DB_PRINT("XILINX UNLOCK 0xF8000000 + 0x%x <= 0x%x\n", (int)offset,
                 (unsigned)val & 0xFFFF);
-            s->regs[LOCKSTA] = 0;
+            s->regs[R_LOCKSTA] = 0;
         } else {
             DB_PRINT("WRONG XILINX UNLOCK KEY 0xF8000000 + 0x%x <= 0x%x\n",
                 (int)offset, (unsigned)val & 0xFFFF);
@@ -395,7 +395,7 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,
         return;
     }
 
-    if (s->regs[LOCKSTA]) {
+    if (s->regs[R_LOCKSTA]) {
         qemu_log_mask(LOG_GUEST_ERROR,
                       "SCLR registers are locked. Unlock them first\n");
         return;
@@ -403,8 +403,8 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,
     s->regs[offset] = val;
 
     switch (offset) {
-    case PSS_RST_CTRL:
-        if (val & R_PSS_RST_CTRL_SOFT_RST) {
+    case R_PSS_RST_CTRL:
+        if (FIELD_EX32(val, PSS_RST_CTRL, SOFT_RST)) {
             qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
         }
         break;
Signature · 1 line
2.21.0
#14 lore raw

RFC PATCH 14/17 convert cadence_uart to 3-phases reset

In reply to Damien Hedde

Split the existing reset procedure into 3 phases. Test the resetting flag to discard register accesses and character reception.
Also adds a active high reset io.

---
 hw/char/cadence_uart.c | 48 ++++++++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 4 deletions(-)
hw/char/cadence_uart.c +44 -4
index fbdbd463bb..694c8ea614 100644
@@ -222,6 +222,10 @@ static int uart_can_receive(void *opaque)
     int ret = MAX(CADENCE_UART_RX_FIFO_SIZE, CADENCE_UART_TX_FIFO_SIZE);
     uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE;
 
+    if (qdev_is_resetting((DeviceState *) opaque)) {
+        return 0;
+    }
+
     if (ch_mode == NORMAL_MODE || ch_mode == ECHO_MODE) {
         ret = MIN(ret, CADENCE_UART_RX_FIFO_SIZE - s->rx_count);
     }
@@ -337,6 +341,10 @@ static void uart_receive(void *opaque, const uint8_t *buf, int size)
     CadenceUARTState *s = opaque;
     uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE;
 
+    if (qdev_is_resetting((DeviceState *) opaque)) {
+        return;
+    }
+
     if (ch_mode == NORMAL_MODE || ch_mode == ECHO_MODE) {
         uart_write_rx_fifo(opaque, buf, size);
     }
@@ -350,6 +358,10 @@ static void uart_event(void *opaque, int event)
     CadenceUARTState *s = opaque;
     uint8_t buf = '\0';
 
+    if (qdev_is_resetting((DeviceState *) opaque)) {
+        return;
+    }
+
     if (event == CHR_EVENT_BREAK) {
         uart_write_rx_fifo(opaque, &buf, 1);
     }
@@ -382,6 +394,10 @@ static void uart_write(void *opaque, hwaddr offset,
 {
     CadenceUARTState *s = opaque;
 
+    if (qdev_is_resetting((DeviceState *)opaque)) {
+        return;
+    }
+
     DB_PRINT(" offset:%x data:%08x\n", (unsigned)offset, (unsigned)value);
     offset >>= 2;
     if (offset >= CADENCE_UART_R_MAX) {
@@ -440,6 +456,10 @@ static uint64_t uart_read(void *opaque, hwaddr offset,
     CadenceUARTState *s = opaque;
     uint32_t c = 0;
 
+    if (qdev_is_resetting((DeviceState *)opaque)) {
+        return 0;
+    }
+
     offset >>= 2;
     if (offset >= CADENCE_UART_R_MAX) {
         c = 0;
@@ -459,9 +479,9 @@ static const MemoryRegionOps uart_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void cadence_uart_reset(DeviceState *dev)
+static void cadence_uart_reset_init(Object *obj, bool cold)
 {
-    CadenceUARTState *s = CADENCE_UART(dev);
+    CadenceUARTState *s = CADENCE_UART(obj);
 
     s->r[R_CR] = 0x00000128;
     s->r[R_IMR] = 0;
@@ -470,6 +490,18 @@ static void cadence_uart_reset(DeviceState *dev)
     s->r[R_BRGR] = 0x0000028B;
     s->r[R_BDIV] = 0x0000000F;
     s->r[R_TTRIG] = 0x00000020;
+}
+
+static void cadence_uart_reset_hold(Object *obj)
+{
+    CadenceUARTState *s = CADENCE_UART(obj);
+
+    qemu_set_irq(s->irq, 0);
+}
+
+static void cadence_uart_reset_exit(Object *obj)
+{
+    CadenceUARTState *s = CADENCE_UART(obj);
 
     uart_rx_reset(s);
     uart_tx_reset(s);
@@ -498,6 +530,8 @@ static void cadence_uart_init(Object *obj)
     sysbus_init_irq(sbd, &s->irq);
 
     s->char_tx_time = (NANOSECONDS_PER_SECOND / 9600) * 10;
+
+    qdev_init_warm_reset_gpio(DEVICE(obj), "rst", DEVICE_ACTIVE_HIGH);
 }
 
 static int cadence_uart_post_load(void *opaque, int version_id)
@@ -532,6 +566,10 @@ static const VMStateDescription vmstate_cadence_uart = {
         VMSTATE_UINT32(rx_wpos, CadenceUARTState),
         VMSTATE_TIMER_PTR(fifo_trigger_handle, CadenceUARTState),
         VMSTATE_END_OF_LIST()
+    },
+    .subsections = (const VMStateDescription * []) {
+        &device_vmstate_reset,
+        NULL
     }
 };
 
@@ -546,9 +584,11 @@ static void cadence_uart_class_init(ObjectClass *klass, void *data)
 
     dc->realize = cadence_uart_realize;
     dc->vmsd = &vmstate_cadence_uart;
-    dc->reset = cadence_uart_reset;
+    dc->reset_phases.init = cadence_uart_reset_init;
+    dc->reset_phases.hold = cadence_uart_reset_hold;
+    dc->reset_phases.exit = cadence_uart_reset_exit;
     dc->props = cadence_uart_properties;
-  }
+}
 
 static const TypeInfo cadence_uart_info = {
     .name          = TYPE_CADENCE_UART,
Signature · 1 line
2.21.0
#15 lore raw

RFC PATCH 15/17 Convert zynq's slcr to 3-phases reset

In reply to Damien Hedde

Change the legacy reset function into the init phase and test the resetting flag in register accesses.

---
 hw/misc/zynq_slcr.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
hw/misc/zynq_slcr.c +11 -3
index baa13d1316..47f43e1d8d 100644
@@ -180,9 +180,9 @@ typedef struct ZynqSLCRState {
     uint32_t regs[ZYNQ_SLCR_NUM_REGS];
 } ZynqSLCRState;
 
-static void zynq_slcr_reset(DeviceState *d)
+static void zynq_slcr_reset_init(Object *obj, bool cold)
 {
-    ZynqSLCRState *s = ZYNQ_SLCR(d);
+    ZynqSLCRState *s = ZYNQ_SLCR(obj);
     int i;
 
     DB_PRINT("RESET\n");
@@ -346,6 +346,10 @@ static uint64_t zynq_slcr_read(void *opaque, hwaddr offset,
     offset /= 4;
     uint32_t ret = s->regs[offset];
 
+    if (qdev_is_resetting((DeviceState *) opaque)) {
+        return 0;
+    }
+
     if (!zynq_slcr_check_offset(offset, true)) {
         qemu_log_mask(LOG_GUEST_ERROR, "zynq_slcr: Invalid read access to "
                       " addr %" HWADDR_PRIx "\n", offset * 4);
@@ -361,6 +365,10 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,
     ZynqSLCRState *s = (ZynqSLCRState *)opaque;
     offset /= 4;
 
+    if (qdev_is_resetting((DeviceState *) opaque)) {
+        return;
+    }
+
     DB_PRINT("addr: %08" HWADDR_PRIx " data: %08" PRIx64 "\n", offset * 4, val);
 
     if (!zynq_slcr_check_offset(offset, false)) {
@@ -441,7 +449,7 @@ static void zynq_slcr_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd = &vmstate_zynq_slcr;
-    dc->reset = zynq_slcr_reset;
+    dc->reset_phases.init = zynq_slcr_reset_init;
 }
 
 static const TypeInfo zynq_slcr_info = {
Signature · 1 line
2.21.0
Reviewed-by on v1 15/17
#16 lore raw

Re: [Qemu-arm] [RFC PATCH 15/17] Convert zynq's slcr to 3-phases reset

Hi Damien,

Le lun. 25 mars 2019 12:16, Damien Hedde <[email protected]> a écrit :

Quoted 38 lines

Change the legacy reset function into the init phase and test the resetting flag in register accesses.

---
 hw/misc/zynq_slcr.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
hw/misc/zynq_slcr.c +6 -2
index baa13d1316..47f43e1d8d 100644
@@ -180,9 +180,9 @@ typedef struct ZynqSLCRState {
     uint32_t regs[ZYNQ_SLCR_NUM_REGS];
 } ZynqSLCRState;
 
-static void zynq_slcr_reset(DeviceState *d)
+static void zynq_slcr_reset_init(Object *obj, bool cold)
 {
-    ZynqSLCRState *s = ZYNQ_SLCR(d);
+    ZynqSLCRState *s = ZYNQ_SLCR(obj);
     int i;
 
     DB_PRINT("RESET\n");
@@ -346,6 +346,10 @@ static uint64_t zynq_slcr_read(void *opaque, hwaddr
 offset,
     offset /= 4;
     uint32_t ret = s->regs[offset];
 
+    if (qdev_is_resetting((DeviceState *) opaque)) {
+        return 0;
+    }
+
     if (!zynq_slcr_check_offset(offset, true)) {
         qemu_log_mask(LOG_GUEST_ERROR, "zynq_slcr: Invalid read access to

"

                       " addr %" HWADDR_PRIx "\n", offset * 4);

hw/misc/zynq_slcr.c static void zynq_slcr_write(void *opaque, hwaddr · line 371

Quoted 7 lines
hw/misc/zynq_slcr.c +2 -0
@@ -361,6 +365,10 @@ static void zynq_slcr_write(void *opaque, hwaddr
 offset,
     ZynqSLCRState *s = (ZynqSLCRState *)opaque;
     offset /= 4;
 
+    if (qdev_is_resetting((DeviceState *) opaque)) {
+        return;
 

I wonder if that could be moved to generic parent, as an abstract method. But then I'm not sure we can use a generic read() return value.

+ }

Quoted 14 lines
hw/misc/zynq_slcr.c +1 -0
+
     DB_PRINT("addr: %08" HWADDR_PRIx " data: %08" PRIx64 "\n", offset *

4, val);

     if (!zynq_slcr_check_offset(offset, false)) {
hw/misc/zynq_slcr.c +1 -1
@@ -441,7 +449,7 @@ static void zynq_slcr_class_init(ObjectClass *klass,
 void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd = &vmstate_zynq_slcr;
-    dc->reset = zynq_slcr_reset;
+    dc->reset_phases.init = zynq_slcr_reset_init;
 }
 
Quoted 4 lines

static const TypeInfo zynq_slcr_info = {
--
2.21.0

Quoted 1 line
#17 lore raw

Re: [Qemu-arm] [RFC PATCH 15/17] Convert zynq's slcr to 3-phases reset

Hi Philippe,

Quoted 36 lines · Philippe Mathieu-Daudé

Hi Damien,

Le lun. 25 mars 2019 12:16, Damien Hedde <[email protected] <mailto:[email protected]>> a écrit :

Change the legacy reset function into the init phase and test the resetting flag in register accesses.

<mailto:[email protected]>>
---
 hw/misc/zynq_slcr.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
[...]

    @@ -346,6 +346,10 @@ static uint64_t zynq_slcr_read(void *opaque,
    hwaddr offset,
         offset /= 4;
         uint32_t ret = s->regs[offset];

    +    if (qdev_is_resetting((DeviceState *) opaque)) {
    +        return 0;
    +    }
    +
         if (!zynq_slcr_check_offset(offset, true)) {
             qemu_log_mask(LOG_GUEST_ERROR, "zynq_slcr: Invalid read
    access to "
                           " addr %" HWADDR_PRIx "\n", offset * 4);
    @@ -361,6 +365,10 @@ static void zynq_slcr_write(void *opaque,
    hwaddr offset,
         ZynqSLCRState *s = (ZynqSLCRState *)opaque;
         offset /= 4;

    +    if (qdev_is_resetting((DeviceState *) opaque)) {
    +        return;
Quoted 3 lines

I wonder if that could be moved to generic parent, as an abstract method. But then I'm not sure we can use a generic read() return value.

I agree it would be better not have to add this kind of test everywhere. It is one my unresolved problem but I am not sure what is the best solution.

There is two approachs here I think:
Either we disable/enable explicitely the memory regions in the reset handlers. But then we have to handle the migration of the memory regions flags.
Or the memory region handlers somehow check the resetting state (like here) and we have only to handle the resetting state migration.

Memory region are added using the following code in sysbus:

```
memory_region_init_io(&s->iomem, obj, &uart_ops, s, "uart", 0x1000);
sysbus_init_mmio(sbd, &s->iomem);
sysbus_mmio_map(s, mmio_index, addr);
```

To intercept the read and write without needing a modification of every read/write handlers, I see two options:

+ we can either find a way to "override" the read and write handlers of the memory regions. For example, this could be done in sysbus_init_mmio, or in a dedicated version of the function (eg sysbus_init_mmio_with_reset)

+ or we can use the MemoryRegion owner field (here _obj_ in memory_region_init_io call) to test if the owner is Resettable and whether it is resetting or not before calling the handlers. In that case, this will not be limited to sysbus devices.

--
Thanks
Damien

#18 lore raw

RFC PATCH 16/17 Add uart reset support in zynq_slcr

In reply to Damien Hedde

Add two gpio outputs to control the uart resets.

---
 hw/misc/zynq_slcr.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
hw/misc/zynq_slcr.c +29 -0
index 47f43e1d8d..5aa8f55b45 100644
@@ -96,6 +96,10 @@ REG32(SPI_RST_CTRL, 0x21c)
 REG32(CAN_RST_CTRL, 0x220)
 REG32(I2C_RST_CTRL, 0x224)
 REG32(UART_RST_CTRL, 0x228)
+    FIELD(UART_RST_CTRL, UART0_CPU1X_RST, 0, 1)
+    FIELD(UART_RST_CTRL, UART1_CPU1X_RST, 1, 1)
+    FIELD(UART_RST_CTRL, UART0_REF_RST, 2, 1)
+    FIELD(UART_RST_CTRL, UART1_REF_RST, 3, 1)
 REG32(GPIO_RST_CTRL, 0x22c)
 REG32(LQSPI_RST_CTRL, 0x230)
 REG32(SMC_RST_CTRL, 0x234)
@@ -178,8 +182,14 @@ typedef struct ZynqSLCRState {
     MemoryRegion iomem;
 
     uint32_t regs[ZYNQ_SLCR_NUM_REGS];
+
+    qemu_irq uart0_rst;
+    qemu_irq uart1_rst;
 } ZynqSLCRState;
 
+#define ZYNQ_SLCR_REGFIELD_TO_OUT(state, irq, reg, field) \
+    qemu_set_irq((state)->irq, ARRAY_FIELD_EX32((state)->regs, reg, field) != 0)
+
 static void zynq_slcr_reset_init(Object *obj, bool cold)
 {
     ZynqSLCRState *s = ZYNQ_SLCR(obj);
@@ -276,6 +286,18 @@ static void zynq_slcr_reset_init(Object *obj, bool cold)
     s->regs[R_DDRIOB + 12] = 0x00000021;
 }
 
+static void zynq_slcr_compute_uart_reset(ZynqSLCRState *s)
+{
+    ZYNQ_SLCR_REGFIELD_TO_OUT(s, uart0_rst, UART_RST_CTRL, UART0_REF_RST);
+    ZYNQ_SLCR_REGFIELD_TO_OUT(s, uart1_rst, UART_RST_CTRL, UART1_REF_RST);
+}
+
+static void zynq_slcr_reset_hold(Object *obj)
+{
+    ZynqSLCRState *s = ZYNQ_SLCR(obj);
+
+    zynq_slcr_compute_uart_reset(s);
+}
 
 static bool zynq_slcr_check_offset(hwaddr offset, bool rnw)
 {
@@ -416,6 +438,9 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,
             qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
         }
         break;
+    case R_UART_RST_CTRL:
+        zynq_slcr_compute_uart_reset(s);
+        break;
     }
 }
 
@@ -432,6 +457,9 @@ static void zynq_slcr_init(Object *obj)
     memory_region_init_io(&s->iomem, obj, &slcr_ops, s, "slcr",
                           ZYNQ_SLCR_MMIO_SIZE);
     sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+
+    qdev_init_gpio_out_named(DEVICE(obj), &s->uart0_rst, "uart0_rst", 1);
+    qdev_init_gpio_out_named(DEVICE(obj), &s->uart1_rst, "uart1_rst", 1);
 }
 
 static const VMStateDescription vmstate_zynq_slcr = {
@@ -450,6 +478,7 @@ static void zynq_slcr_class_init(ObjectClass *klass, void *data)
 
     dc->vmsd = &vmstate_zynq_slcr;
     dc->reset_phases.init = zynq_slcr_reset_init;
+    dc->reset_phases.hold = zynq_slcr_reset_hold;
 }
 
 static const TypeInfo zynq_slcr_info = {
Signature · 1 line
2.21.0
#19 lore raw

RFC PATCH 17/17 Connect the uart reset gpios in the zynq platform

In reply to Damien Hedde

Connect the two uart reset inputs to the slcr corresponding outputs.

---
 hw/arm/xilinx_zynq.c           | 14 ++++++++------
 include/hw/char/cadence_uart.h | 10 +++++++++-
 2 files changed, 17 insertions(+), 7 deletions(-)
hw/arm/xilinx_zynq.c +8 -6
index b3b8215759..528d1c42fd 100644
@@ -166,7 +166,7 @@ static void zynq_init(MachineState *machine)
     MemoryRegion *address_space_mem = get_system_memory();
     MemoryRegion *ext_ram = g_new(MemoryRegion, 1);
     MemoryRegion *ocm_ram = g_new(MemoryRegion, 1);
-    DeviceState *dev;
+    DeviceState *dev, *slcr;
     SysBusDevice *busdev;
     qemu_irq pic[64];
     int n;
@@ -211,9 +211,9 @@ static void zynq_init(MachineState *machine)
                           1, 0x0066, 0x0022, 0x0000, 0x0000, 0x0555, 0x2aa,
                           0);
 
-    dev = qdev_create(NULL, "xilinx,zynq_slcr");
-    qdev_init_nofail(dev);
-    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xF8000000);
+    slcr = qdev_create(NULL, "xilinx,zynq_slcr");
+    qdev_init_nofail(slcr);
+    sysbus_mmio_map(SYS_BUS_DEVICE(slcr), 0, 0xF8000000);
 
     dev = qdev_create(NULL, TYPE_A9MPCORE_PRIV);
     qdev_prop_set_uint32(dev, "num-cpu", 1);
@@ -234,8 +234,10 @@ static void zynq_init(MachineState *machine)
     sysbus_create_simple("xlnx,ps7-usb", 0xE0002000, pic[53-IRQ_OFFSET]);
     sysbus_create_simple("xlnx,ps7-usb", 0xE0003000, pic[76-IRQ_OFFSET]);
 
-    cadence_uart_create(0xE0000000, pic[59 - IRQ_OFFSET], serial_hd(0));
-    cadence_uart_create(0xE0001000, pic[82 - IRQ_OFFSET], serial_hd(1));
+    cadence_uart_create(0xE0000000, pic[59 - IRQ_OFFSET], serial_hd(0),
+                        slcr, "uart0-rst", 0);
+    cadence_uart_create(0xE0001000, pic[82 - IRQ_OFFSET], serial_hd(1),
+                        slcr, "uart1-rst", 0);
 
     sysbus_create_varargs("cadence_ttc", 0xF8001000,
             pic[42-IRQ_OFFSET], pic[43-IRQ_OFFSET], pic[44-IRQ_OFFSET], NULL);
include/hw/char/cadence_uart.h +9 -1
index 118e3f10de..b7489a711f 100644
@@ -51,7 +51,10 @@ typedef struct {
 
 static inline DeviceState *cadence_uart_create(hwaddr addr,
                                         qemu_irq irq,
-                                        Chardev *chr)
+                                        Chardev *chr,
+                                        DeviceState *rst_dev,
+                                        const char *rst_name,
+                                        int rst_n)
 {
     DeviceState *dev;
     SysBusDevice *s;
@@ -63,6 +66,11 @@ static inline DeviceState *cadence_uart_create(hwaddr addr,
     sysbus_mmio_map(s, 0, addr);
     sysbus_connect_irq(s, 0, irq);
 
+    if (rst_dev) {
+        qdev_connect_gpio_out_named(rst_dev, rst_name, rst_n,
+                qdev_get_gpio_in_named(dev, "rst", 0));
+    }
+
     return dev;
 }
 
Signature · 1 line
2.21.0
#20 lore raw
In reply to Damien Hedde
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the asan build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1 === TEST SCRIPT END ===

/usr/bin/ld: /tmp/qemu-test/src/include/hw/resettable.h:80: undefined reference to `resettable_deassert_reset'

clang++ -L/tmp/qemu-test/build/dtc/libfdt  -I/usr/include/pixman-1  -I/tmp/qemu-test/src/dtc/libfdt -Werror -DHAS_LIBSSH2_SFTP_FSYNC  -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include  -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99  -Wno-string-plus-int -Wno-initializer-overrides -Wexpansion-to-defined -Wendif-labels -Wno-shift-negative-value -Wno-missing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-definition -Wtype-limits -fstack-protector-strong  -I/usr/include/p11-kit-1    -I/usr/include/libpng16  -I/usr/include/spice-1 -I/usr/include/spice-server -I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/nss3 -I/usr/include/nspr4 -pthread -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -I/usr/include/pixman-1  -I/tmp/qemu-test/src/tests -fsanitize=undefined -fsanitize=address -g  -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g  -o tests/test-crypto-secret tests/test-crypto-secret.o authz/base.o authz/simple.o authz/list.o authz/listfile.o crypto/init.o crypto/hash.o crypto/hash-nettle.o crypto/hmac.o crypto/hmac-nettle.o crypto/aes.o crypto/desrfb.o crypto/cipher.o crypto/tlscreds.o crypto/tlscredsanon.o crypto/tlscredspsk.o crypto/tlscredsx509.o crypto/tlssession.o crypto/secret.o crypto/random-gnutls.o crypto/pbkdf.o crypto/pbkdf-nettle.o crypto/ivgen.o crypto/ivgen-essiv.o crypto/ivgen-plain.o crypto/ivgen-plain64.o crypto/afsplit.o crypto/xts.o crypto/block.o crypto/block-qcow.o crypto/block-luks.o qom/object.o qom/container.o qom/qom-qobject.o qom/object_interfaces.o  libqemuutil.a   -lm -lz  -lgthread-2.0 -pthread -lglib-2.0   -lrt -lz -lutil -lcap-ng -lnettle  -lgnutls  
clang++ -L/tmp/qemu-test/build/dtc/libfdt  -I/usr/include/pixman-1  -I/tmp/qemu-test/src/dtc/libfdt -Werror -DHAS_LIBSSH2_SFTP_FSYNC  -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include  -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99  -Wno-string-plus-int -Wno-initializer-overrides -Wexpansion-to-defined -Wendif-labels -Wno-shift-negative-value -Wno-missing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-definition -Wtype-limits -fstack-protector-strong  -I/usr/include/p11-kit-1    -I/usr/include/libpng16  -I/usr/include/spice-1 -I/usr/include/spice-server -I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/nss3 -I/usr/include/nspr4 -pthread -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -I/usr/include/pixman-1  -I/tmp/qemu-test/src/tests -fsanitize=undefined -fsanitize=address -g  -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g  -o tests/test-crypto-tlscredsx509 tests/test-crypto-tlscredsx509.o tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o authz/base.o authz/simple.o authz/list.o authz/listfile.o crypto/init.o crypto/hash.o crypto/hash-nettle.o crypto/hmac.o crypto/hmac-nettle.o crypto/aes.o crypto/desrfb.o crypto/cipher.o crypto/tlscreds.o crypto/tlscredsanon.o crypto/tlscredspsk.o crypto/tlscredsx509.o crypto/tlssession.o crypto/secret.o crypto/random-gnutls.o crypto/pbkdf.o crypto/pbkdf-nettle.o crypto/ivgen.o crypto/ivgen-essiv.o crypto/ivgen-plain.o crypto/ivgen-plain64.o crypto/afsplit.o crypto/xts.o crypto/block.o crypto/block-qcow.o crypto/block-luks.o qom/object.o qom/container.o qom/qom-qobject.o qom/object_interfaces.o  libqemuutil.a  -ltasn1 -lm -lz  -lgthread-2.0 -pthread -lglib-2.0   -lrt -lz -lutil -lcap-ng -lnettle  -lgnutls  

clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/tmp/qemu-test/src/rules.mak:124: tests/test-qdev-global-props] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):

The full log is available at
http://patchew.org/logs/[email protected]/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#21 lore raw
In reply to Damien Hedde

Hi All,

Any comment about this ?

Thanks,
Damien

Quoted 190 lines · Damien Hedde

Hi all,

This series is a proposal to implement the multi-phase reset we've discussed here (https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg00310.html) and more recently there
(https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg00081.html).

To summarize, we need a multi-phase reset to allow for a more complex initialization of a platform. In particular we need to "propagate" a clock tree, but we have to ensure that every device is initialized first.

To solve this problem, the following 3-phases reset mechanism is proposed (I've removed the 4th given our last discussion).

#DESCRIPTION

INIT PHASE: Reset the object internal state, put a resetting flag and do the
same for the reset subtree. No side effect on other devices to guarantee that, in a reset domain, everything get initialized first. This corresponds mostly to what is currently done in the device/bus reset method.

HOLD PHASE: This phase allows to control a reset with a I/O. When a I/O control
a reset procedure based on the I/O level (not edge), we may need to assert the reset, wait some time, and finally de-assert the reset. The consequence is that such a device can stay in a "resetting state" and may need to show this state to other devices through its outputs. For example, a clock controller will typically shutdown its clocks when it is in resetting state.

EXIT PHASE (previously named 'release'): This phase sets outputs to state after
reset. For a clock controller it starts the clocks. It also clears the "resetting" flag. A device should not react to inputs until this flag has been cleared. During this phase, outputs are propagated in the reset domain (and outside the reset domain).

To implement this, this series add a Resettable interface containing 3 methods:
one for each phase. The init phase's method takes a boolean argument allowing to distinguish cold and warm resets.

In this series, Device and Bus implement the interface. A vmstate description subsection is added to allow migration of reset related state for device. 3 methods (one per phase) are also added in Device's class. They correspond to the local part (see the code example below) of the reset. They avoid device specialization to have to handle the sub-domain part and "resetting" state.

Functions to add gpio control over the reset are added. It is possible to add an active low/high reset pin to control the warm reset and an active low/high power gating pin to control the cold reset.

The bus/device reset tree is converted to this 3-phases mechanism. I also added a new ResetDomain object which is just a Resettable container. It is used to have a global "system reset domain" to handle main 3-phases reset and replace the current single-phase-reset handler mechanism.

As an example, in the xilinx_zynq machine, I've converted the slcr (the resets and clocks controller device) and the uart peripheral to this 3-phases reset mechanism. Gpio are added between the devices to transmit reset control from the slcr to the uarts.

All changes have been made so that existing reset behavior is not modified.

#INTERFACE CHOICE

To be honest, I have some doubt about the interface. I've kept it minimal and the consequence is implementation is complex (and kind of duplicated in every base implementation like Device or Bus). One of the problem is the resetting flag, which in practical must be a counter to handle reset "reentrance". Indeed nothing forbids to reset some device that is already held in "resetting" state by some other means. As an example, in the zynq machine, there can be a global/system reset while an uart is reset by the slcr. It it also possible to cold and warm resets triggered concurrently.

The Resettable methods implementation have to looks this (methods are called with iothread locked):

```
void init_phase(Device *dev, bool cold)
{
    /* call sub-resettable init phases */

    dev->resetting += 1;
    /* do local init phase (eg: state reset) */
}
void hold_phase(Device *dev)
{
    /* call sub-resettable hold phases */

    /* do local hold phase (eg: set some I/O level) */
}
void exit_phase(Device *dev)
{
    /* call sub-resettable exit phases (independently of resetting value since,
       every resettable have its own resetting counter) */
   
    dev->resetting -= 1;
    if (dev->resetting == 0) {
        /* do local exit phase (eg: set some I/O level) only if the device is
           really leaving the resetting state */
    }
}
```

Since I don't think specialization should care about sub-resettable and the resetting counter, I've added the local init/hold/exit phases as DeviceClass methods.
Otherwise, I see two other solutions:
+ keep the interface as it is
+ add some state knowledge in the interface (with some kind of get_state method) so that resetting counter and some kind of sub-resettable list are handled in the common code in the interface. The 3 methods will then handle only the local actions.
+ have 6 methods in the interface, one for the local actions, one for the sub-resettable so that sub-resettable is not handled in the common code. And we need also a get_resetting method to access/update the counter.

#DEVICE RESET CHOICE

The Device is a special case, it has 2 reset entry point: qdev_reset_all and device_reset. The latter doing a device reset only, while the former also reset all buses hierarchy under the device.

I choose the put the sub-buses into the device reset domain, so that the behavior of the resettable interface on Device is the same as qdev_reset_all. I don't know if device_reset has some real meaning (resetting only the Device). It is not often used and I think every time it is used there is no sub-buses so the behavior is the same for both functions.

If I am mistaken about putting buses into device reset domain, it is possible to make a special bus-hierarchy-reset-domain for every Device/Bus that differs from the Resettable interface on Device/Bus.

# SYSBUS SUPPORT

Regarding the sysbus support Edgar mentioned in the prevous discussion: In this series, there is no support in sysbus base class for disabling memory regions. Having each sysbus device specialization, in every memory region handler, to check if resetting is set or not is not user-friendly. But for we can't modify memory region enabled flags since devices may already set/unset them. Maybe we could have some kind of super-switch to disable all memory regions in a sysbus device but I don't know how this could be done.

The series is organised as follow:
Patches 1 and 2 adds Resettable interface and ResetDomain object. Patches 3 to 7 converts Device and Bus to Resettable.
Patches 8 to 12 handles the global system reset domain
Patches 13 to 17 do the zynq implementation (patch 13 is an already-reviewed patch from the clock api patch series)

Thank you for your feedback,
Damien

Damien Hedde (17):
Create Resettable QOM interface
Create the ResetDomain QOM object
make Device and Bus Resettable
Add local reset methods in Device class
add vmstate description for device reset state Add function to control reset with gpio inputs convert qdev/bus_reset_all to Resettable
Add a global ResetDomain object for system emulation global ResetDomain support for legacy reset handlers Delete the system ResetDomain at the end of emulation Put orphan buses in system reset domain
Put default sysbus in system reset domain hw/misc/zynq_slcr: use standard register definition convert cadence_uart to 3-phases reset Convert zynq's slcr to 3-phases reset
Add uart reset support in zynq_slcr
Connect the uart reset gpios in the zynq platform

 hw/arm/xilinx_zynq.c           |  14 +-
 hw/char/cadence_uart.c         |  48 ++-
 hw/core/Makefile.objs          |   3 +
 hw/core/bus.c                  |  64 +++-
 hw/core/qdev-vmstate.c         |  27 ++
 hw/core/qdev.c                 | 166 ++++++++++-
 hw/core/reset-domain.c         | 121 ++++++++
 hw/core/reset.c                | 149 +++++++++-
 hw/core/resettable.c           |  69 +++++
 hw/misc/zynq_slcr.c            | 515 ++++++++++++++++++---------------
 include/hw/char/cadence_uart.h |  10 +-
 include/hw/qdev-core.h         |  97 +++++++
 include/hw/reset-domain.h      |  49 ++++
 include/hw/resettable.h        |  83 ++++++
 include/sysemu/reset.h         |  47 +++
 vl.c                           |   3 +-
 16 files changed, 1195 insertions(+), 270 deletions(-)
 create mode 100644 hw/core/qdev-vmstate.c
 create mode 100644 hw/core/reset-domain.c
 create mode 100644 hw/core/resettable.c
 create mode 100644 include/hw/reset-domain.h
 create mode 100644 include/hw/resettable.h
#22 lore raw
Quoted 4 lines · Damien Hedde

Hi All,

Any comment about this ?

Sorry we haven't got to this yet. This is on my to-review list, but so are 23 other series, and I've been on holiday for the past week or so. I will try to get to it this week.

thanks
-- PMM

#23 lore raw
Quoted 10 lines · Peter Maydell
Quoted 4 lines · Damien Hedde

Hi All,

Any comment about this ?

Sorry we haven't got to this yet. This is on my to-review list, but so are 23 other series, and I've been on holiday for the past week or so. I will try to get to it this week.

I made a start on this, but it's going to take me some time to wrap my head around the design and the issues you raise in the cover letter. Given the bank holiday on Monday and some other commitments I have on Tuesday I think it's going to be the second half of next week at best before I can do a proper response.

In general I like the code (though as you say we may not have got the interface quite right -- I had not appreciated some of the nested-reset cases when I proposed it I think).

I think we could use a document (which would eventually live in docs/devel) that describes the reset system and provides some how-to style documentation for
* what you need to do if you're writing a device
* what you need to do if you are an external user of a device model and you want to reset it
plus some notes on whatever we still have left over as remnants of the old reset scheme and any intended transitions to try to remove those remnants. I'll have a go at writing something because I think that will help me personally in trying to understand the problem domain and what the new design is doing.

thanks
-- PMM

#24 lore raw
In reply to Damien Hedde
Quoted 11 lines · Damien Hedde

Hi all,

This series is a proposal to implement the multi-phase reset we've discussed here (https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg00310.html) and more recently there
(https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg00081.html).

To summarize, we need a multi-phase reset to allow for a more complex initialization of a platform. In particular we need to "propagate" a clock tree, but we have to ensure that every device is initialized first.

Hi; I finally managed to get my thoughts about reset coherent enough to write down in an email.

OVERVIEW

I had a read through the patchset and spent a while trying to understand what we currently have.

Our current (device) reset model is:
* single-phase
-- there is only one 'reset' method
* implicit
-- devices don't need to be explicitly registered anywhere
in a "reset hierarchy"; instead they are reset by virtue of being in the bus heirarchy they are already in
* bus-based
-- sysbus reset is registered in vl.c; free-floating other buses[*]
(ie those with a NULL parent) have a reset registered in qbus_realize; buses with parents (ie anything with a non-NULL parent passed to qbus_create() or qbus_create_inplace()) will get traversed by the recursive traversal of whatever bus their parent is on.
* not exhaustive
-- any devices not put on a bus, or put on a bus whose parent device
is not on a bus, will not get reset
* not modelling GPIO reset signal lines

[*] It turns out we actually don't have any of these any more, so we can remove the code that deals with them. The only parentless bus is the main system bus, which is the root of the "reset hierarchy".

This patchset is trying to address:
* changing to multi-phase
* modelling of GPIO reset signal lines

It leaves reset as bus-based: currently we do this via qbus_walk_children/ qdev_walk_children, which traverse the bus->children and dev->child_bus lists, and in the patchset's implementation of Resettable for qdev/qbus the methods iterate through those.

I think this is reasonable -- we don't want to try to tackle every reset related problem at once. The two issues the patchset is looking at fit well together, because the GPIO-reset-lines are a motivation for switching to multiphase (you need to handle both entering and leaving reset).

("not exhaustive" is the thing we should really try to fix at some point, but I have no good ideas for how to do this.)

API DESIGN

On what the right APIs should be: I think we should separate "the API that's nice for devices to implement" from "the API that's nice for callers wanting to reset a device". Here's my suggestion for doing that:

Have the Resettable interface be:
* init
* hold
* exit
* get_reset_count
* increment_reset_count (returns previous count)
* decrement_reset_count (returns new count)
* some method for "iterate over any Resettable child objects" (probably a "call this callback for each child" type API)

Individual devices implement init/hold/exit
Device base class implements the reset_count methods
Device base class implements a default 'init' method that calls dc->reset
and default hold/exit that are no-ops
Device base class has a new vmstate subsection which migrates the
reset count, subsection's needed function says "only send if reset count is non-zero". Back-compat here should be fine as current machines don't implement any way that a device in the system can be being held in reset at the point where a migration happens. If future changes add features to a machine model that permit that, the migration is forwards-compatible.
Device base class implements the iterate-over-children method to
iterate over the dev->child_bus buses
Bus base class implements reset_count methods
Bus base class implements default no-op init/hold/exit
Bus base class implements the iterate-over-children method to
iterate over the bus->children devices
Handling migration of the bus base class reset count is a little
awkward -- we'll need to put it in a vmstate subsection which is part of the vmstate of the device which owns the bus.
(I talked to David Gilbert on IRC about this and have some possibilities for how to do it, but will postpone writing them out until we've decided whether we like the APIs.)

The "API for devices to implement" is then the init/hold/exit methods of the Resettable interface -- they don't need to worry about these methods possibly being called multiple times, and they don't need to handle the reference count or passing on the calling of the phase methods to their children. They just need to implement the correct behaviour for their device for this phase.

The "API for callers wanting to reset a device" is a set of helper functions that take a pointer to a Resettable object. It's these that deal with the reset count and children:

resettable_assert_reset(Resettable *r)
{

   if (r->increment_reset_count() == 0) {
       r->init();
       r->foreach_child(do_call_init);
       r->hold();
       r->foreach_child(do_call_hold);

}
}

resettable_deassert_reset(Resettable *r)
{

   if (r->decrement_reset_count() == 0) {
      r->foreach_child(do_call_exit);
      r->exit();

}
}

plus a utility function for "call assert then deassert", and maybe one that wraps the get_reset_count method. So callers that want to reset devices (or buses) don't need to care about phases, they just assert and then deassert reset.

Do you think that works ?

API TRANSITIONS

The other issue here is API transitions: the patchset essentially obsoletes the old DeviceClass::reset function, for instance. I think we should be clear about what the old and new APIs here are, and what our plans for transitioning to the new ones are. In some cases there are really very few users of the old API -- for instance the patchset makes qbus_reset_all(bus) a synonym for qbus_reset(bus, false), but there are only a dozen or so users of qbus_reset_all(). I think we should just go ahead and convert them all. (For purposes of structuring the patchset starting with a patch that says "reimplement qbus_reset_all() in terms of qbus_reset()" is OK, but then we should fix up the callers afterwards.) There are of course a lot more implementations of DeviceState::reset so transitioning away from that is a lot trickier, but we could look at a coccinelle script that could automate it.

If you could describe in the cover letter of the next version of the patchseries all the old APIs being deprecated and the new ones that replace them, I think that would be very helpful.

MISCELLANEOUS MINOR POINTS

I know I suggested the idea of a ResetDomain object, but in the series as it stands I'm not sure it's serving very much purpose; perhaps we should drop it for the moment (just leaving the legacy reset handlers and sysbus reset the way they are) ? We can come back to it later as a concept.

The "support reset via GPIO line" patch looks generally OK, but you can't just add fields to the DeviceState vmstate struct -- you'll break migration from older QEMU versions. The new fields need to go in a vmstate subsection with an appropriate 'needed' function.

We should definitely make sure we have good documentation for what device authors should do to implement reset.

thanks
-- PMM

#25 lore raw

Hi,

Quoted 95 lines · Peter Maydell
Quoted 11 lines · Damien Hedde

Hi all,

This series is a proposal to implement the multi-phase reset we've discussed here (https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg00310.html) and more recently there
(https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg00081.html).

To summarize, we need a multi-phase reset to allow for a more complex initialization of a platform. In particular we need to "propagate" a clock tree, but we have to ensure that every device is initialized first.

Hi; I finally managed to get my thoughts about reset coherent enough to write down in an email.

OVERVIEW

I had a read through the patchset and spent a while trying to understand what we currently have.

Our current (device) reset model is:
* single-phase
-- there is only one 'reset' method
* implicit
-- devices don't need to be explicitly registered anywhere
in a "reset hierarchy"; instead they are reset by virtue of being in the bus heirarchy they are already in
* bus-based
-- sysbus reset is registered in vl.c; free-floating other buses[*]
(ie those with a NULL parent) have a reset registered in qbus_realize; buses with parents (ie anything with a non-NULL parent passed to qbus_create() or qbus_create_inplace()) will get traversed by the recursive traversal of whatever bus their parent is on.
* not exhaustive
-- any devices not put on a bus, or put on a bus whose parent device
is not on a bus, will not get reset
* not modelling GPIO reset signal lines

[*] It turns out we actually don't have any of these any more, so we can remove the code that deals with them. The only parentless bus is the main system bus, which is the root of the "reset hierarchy".

This patchset is trying to address:
* changing to multi-phase
* modelling of GPIO reset signal lines

It leaves reset as bus-based: currently we do this via qbus_walk_children/ qdev_walk_children, which traverse the bus->children and dev->child_bus lists, and in the patchset's implementation of Resettable for qdev/qbus the methods iterate through those.

I think this is reasonable -- we don't want to try to tackle every reset related problem at once. The two issues the patchset is looking at fit well together, because the GPIO-reset-lines are a motivation for switching to multiphase (you need to handle both entering and leaving reset).

("not exhaustive" is the thing we should really try to fix at some point, but I have no good ideas for how to do this.)

API DESIGN

On what the right APIs should be: I think we should separate "the API that's nice for devices to implement" from "the API that's nice for callers wanting to reset a device". Here's my suggestion for doing that:

Have the Resettable interface be:
* init
* hold
* exit
* get_reset_count
* increment_reset_count (returns previous count)
* decrement_reset_count (returns new count)
* some method for "iterate over any Resettable child objects" (probably a "call this callback for each child" type API)

Individual devices implement init/hold/exit
Device base class implements the reset_count methods
Device base class implements a default 'init' method that calls dc->reset
and default hold/exit that are no-ops
Device base class has a new vmstate subsection which migrates the
reset count, subsection's needed function says "only send if reset count is non-zero". Back-compat here should be fine as current machines don't implement any way that a device in the system can be being held in reset at the point where a migration happens. If future changes add features to a machine model that permit that, the migration is forwards-compatible.
Device base class implements the iterate-over-children method to
iterate over the dev->child_bus buses
Bus base class implements reset_count methods
Bus base class implements default no-op init/hold/exit

Quoted 8 lines

Bus base class implements the iterate-over-children method to
iterate over the bus->children devices
Handling migration of the bus base class reset count is a little
awkward -- we'll need to put it in a vmstate subsection which is part of the vmstate of the device which owns the bus. (I talked to David Gilbert on IRC about this and have some possibilities for how to do it, but will postpone writing them out until we've decided whether we like the APIs.)

If:
1. we say we cannot use a Bus as holdable reset entry point (we can
reset it but not (de)assert_reset it without passing by its parent Device)
2. if there is no additional reset dedicated state (right now a reset
on a bus mostly propagates it to sub-devices)
Then we have no state migration needed for buses and we can probably find a way to use the parent Device's reset_count.

This is somewhat related to the API TRANSITION part below but I was wondering if I should add some kind of flag in the interface class to indicate the support of "migration-during-reset" functionality. It could be used to at least warn when trying to hold the reset state in such an class.
This flag will default to false and one would have to set it when implementing the functionality for a given object class (like I did with the cadence_uart device).
Maybe a similar flag can be used to allow/forbid using a class as an holdable reset entry point.

Quoted 31 lines

The "API for devices to implement" is then the init/hold/exit methods of the Resettable interface -- they don't need to worry about these methods possibly being called multiple times, and they don't need to handle the reference count or passing on the calling of the phase methods to their children. They just need to implement the correct behaviour for their device for this phase.

The "API for callers wanting to reset a device" is a set of helper functions that take a pointer to a Resettable object. It's these that deal with the reset count and children:

resettable_assert_reset(Resettable *r)

{
   if (r->increment_reset_count() == 0) {
       r->init();
       r->foreach_child(do_call_init);
       r->hold();
       r->foreach_child(do_call_hold);
   }
}

resettable_deassert_reset(Resettable *r)

{
   if (r->decrement_reset_count() == 0) {
      r->foreach_child(do_call_exit);
      r->exit();
   }
}
Quoted 6 lines

plus a utility function for "call assert then deassert", and maybe one that wraps the get_reset_count method. So callers that want to reset devices (or buses) don't need to care about phases, they just assert and then deassert reset.

Do you think that works ?

I'll have to handle cold/warm cases but I think it will work.

Quoted 23 lines

API TRANSITIONS

The other issue here is API transitions: the patchset essentially obsoletes the old DeviceClass::reset function, for instance. I think we should be clear about what the old and new APIs here are, and what our plans for transitioning to the new ones are. In some cases there are really very few users of the old API -- for instance the patchset makes qbus_reset_all(bus) a synonym for qbus_reset(bus, false), but there are only a dozen or so users of qbus_reset_all(). I think we should just go ahead and convert them all. (For purposes of structuring the patchset starting with a patch that says "reimplement qbus_reset_all() in terms of qbus_reset()" is OK, but then we should fix up the callers afterwards.) There are of course a lot more implementations of DeviceState::reset so transitioning away from that is a lot trickier, but we could look at a coccinelle script that could automate it.

If you could describe in the cover letter of the next version of the patchseries all the old APIs being deprecated and the new ones that replace them, I think that would be very helpful.>

Quoted 7 lines

MISCELLANEOUS MINOR POINTS

I know I suggested the idea of a ResetDomain object, but in the series as it stands I'm not sure it's serving very much purpose; perhaps we should drop it for the moment (just leaving the legacy reset handlers and sysbus reset the way they are) ? We can come back to it later as a concept.

I'm ok with that. It seems unnecessary at that point given that it was not used by Device/Bus classes. It will make the series simplier.

Quoted 8 lines

The "support reset via GPIO line" patch looks generally OK, but you can't just add fields to the DeviceState vmstate struct -- you'll break migration from older QEMU versions. The new fields need to go in a vmstate subsection with an appropriate 'needed' function.

We should definitely make sure we have good documentation for what device authors should do to implement reset.

I agree, I did not want to commit too much into it before having a more satisfying API. I'll work on it for the next version.

Quoted 4 lines

thanks
-- PMM

Thanks a lot for the review,
Damien

#26 lore raw
Quoted 11 lines · Damien Hedde

Hi,

Quoted 6 lines · Peter Maydell

Handling migration of the bus base class reset count is a little
awkward -- we'll need to put it in a vmstate subsection which is part of the vmstate of the device which owns the bus. (I talked to David Gilbert on IRC about this and have some possibilities for how to do it, but will postpone writing them out until we've decided whether we like the APIs.)

Quoted 7 lines

If:
1. we say we cannot use a Bus as holdable reset entry point (we can
reset it but not (de)assert_reset it without passing by its parent Device)
2. if there is no additional reset dedicated state (right now a reset
on a bus mostly propagates it to sub-devices)
Then we have no state migration needed for buses and we can probably find a way to use the parent Device's reset_count.

Yeah, I thought about this, but I decided I didn't like having "there's a Resettable interface but you have to know that some implementations are special and it's not possible to do the same things with them you can with some others". Implementing migration of the child bus reset state as part of the parent device's vmstate is a bit tedious but not impossible. (Basically in the parent device's pre-save function you have to create a temporary array, populate it by walking the list of child buses and looking at their reset flags, then migrate the contents of the array, and in post-load you do "walk child buses and fill in the reset flags from the array". There's a VMSTATE_WITH_TMP macro that can apparently assist with this.)

Quoted 8 lines

This is somewhat related to the API TRANSITION part below but I was wondering if I should add some kind of flag in the interface class to indicate the support of "migration-during-reset" functionality. It could be used to at least warn when trying to hold the reset state in such an class.
This flag will default to false and one would have to set it when implementing the functionality for a given object class (like I did with the cadence_uart device).

I think that migration-during-reset should Just Work, without necessarily needing any specific changes for a device. I'm not sure a warning that only prints when the guest does something to cause device-reset is going to be very helpful:
what would be the thing that the warning would tell us we needed to do?

thanks
-- PMM