[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 01/17] Create Resettable QOM interface
From: |
Damien Hedde |
Subject: |
[Qemu-devel] [RFC PATCH 01/17] Create Resettable QOM interface |
Date: |
Mon, 25 Mar 2019 12:01:44 +0100 |
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.
Signed-off-by: Damien Hedde <address@hidden>
---
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
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index a799c83815..97007454a8 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -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:
diff --git a/hw/core/resettable.c b/hw/core/resettable.c
new file mode 100644
index 0000000000..6ea1e5b54a
--- /dev/null
+++ b/hw/core/resettable.c
@@ -0,0 +1,69 @@
+/*
+ * Resettable interface.
+ *
+ * Copyright (c) 2019 GreenSocs SAS
+ *
+ * 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 "qemu/module.h"
+#include "hw/resettable.h"
+
+#define RESETTABLE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(ResettableClass, (obj), TYPE_RESETTABLE)
+
+void resettable_init_phase(Object *obj, bool cold)
+{
+ ResettableClass *rc = RESETTABLE_GET_CLASS(obj);
+
+ if (rc->phases.init) {
+ rc->phases.init(obj, cold);
+ }
+}
+
+void resettable_hold_phase(Object *obj)
+{
+ ResettableClass *rc = RESETTABLE_GET_CLASS(obj);
+
+ if (rc->phases.hold) {
+ rc->phases.hold(obj);
+ }
+}
+
+void resettable_exit_phase(Object *obj)
+{
+ ResettableClass *rc = RESETTABLE_GET_CLASS(obj);
+
+ if (rc->phases.exit) {
+ rc->phases.exit(obj);
+ }
+}
+
+void resettable_assert_reset(Object *obj, bool cold)
+{
+ resettable_init_phase(obj, cold);
+ resettable_hold_phase(obj);
+}
+
+void resettable_deassert_reset(Object *obj)
+{
+ resettable_exit_phase(obj);
+}
+
+static const TypeInfo resettable_interface_info = {
+ .name = TYPE_RESETTABLE,
+ .parent = TYPE_INTERFACE,
+ .class_size = sizeof(ResettableClass),
+};
+
+static void reset_register_types(void)
+{
+ type_register_static(&resettable_interface_info);
+}
+
+type_init(reset_register_types)
diff --git a/include/hw/resettable.h b/include/hw/resettable.h
new file mode 100644
index 0000000000..15d5bd878d
--- /dev/null
+++ b/include/hw/resettable.h
@@ -0,0 +1,83 @@
+#ifndef HW_RESETTABLE_H
+#define HW_RESETTABLE_H
+
+#include "qom/object.h"
+
+#define TYPE_RESETTABLE "resettable"
+
+#define RESETTABLE_CLASS(class) \
+ OBJECT_CLASS_CHECK(ResettableClass, (class), TYPE_RESETTABLE)
+
+/*
+ * ResettableClass:
+ * Interface for resettable objects.
+ *
+ * The reset operation is divided in several phases each represented by a
+ * method.
+ *
+ * @phases.init: should reset local state only. Takes a bool @cold argument
+ * specifying whether the reset is cold or warm. It must not do side-effect
+ * on others objects.
+ *
+ * @phases.hold: side-effects action on others objects due to staying in a
+ * resetting state.
+ *
+ * @phases.exit: leave the reset state, may do side-effects action on others
+ * objects.
+ *
+ * "Entering the reset state" corresponds to the init and hold phases.
+ * "Leaving the reset state" corresponds to the exit phase.
+ */
+typedef void (*ResettableInitPhase)(Object *obj, bool cold);
+typedef void (*ResettableHoldPhase)(Object *obj);
+typedef void (*ResettableExitPhase)(Object *obj);
+typedef struct ResettableClass {
+ InterfaceClass parent_class;
+
+ struct ResettablePhases {
+ ResettableInitPhase init;
+ ResettableHoldPhase hold;
+ ResettableExitPhase exit;
+ } phases;
+} ResettableClass;
+typedef struct ResettablePhases ResettablePhases;
+
+/*
+ * Helpers to do a single phase of a Resettable.
+ * Call the corresponding ResettableClass method if it is not NULL.
+ */
+void resettable_init_phase(Object *obj, bool cold);
+void resettable_hold_phase(Object *obj);
+void resettable_exit_phase(Object *obj);
+
+/**
+ * resettable_assert_reset:
+ * Put an object in reset state.
+ * Each time resettable_assert_reset is called, resettable_deassert_reset
+ * must be eventually called once and only once.
+ *
+ * @obj object to reset, must implement Resettable interface.
+ * @cold boolean indicating the type of reset (cold or warm)
+ */
+void resettable_assert_reset(Object *obj, bool cold);
+
+/**
+ * resettable_deassert_reset:
+ * End the reset state if an object.
+ *
+ * @obj object to reset, must implement Resettable interface.
+ */
+void resettable_deassert_reset(Object *obj);
+
+/**
+ * resettable_reset:
+ * Calling this function is equivalent to call @assert_reset then
+ * @deassert_reset.
+ */
+static inline void resettable_reset(Object *obj, bool cold)
+{
+ resettable_assert_reset(obj, cold);
+ resettable_deassert_reset(obj);
+}
+
+#endif
--
2.21.0
- [Qemu-devel] [RFC 00/17] multi-phase reset mechanism, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 07/17] convert qdev/bus_reset_all to Resettable, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 02/17] Create the ResetDomain QOM object, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 08/17] Add a global ResetDomain object for system emulation, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 03/17] make Device and Bus Resettable, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 09/17] global ResetDomain support for legacy reset handlers, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 10/17] Delete the system ResetDomain at the end of emulation, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 04/17] Add local reset methods in Device class, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 05/17] add vmstate description for device reset state, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 06/17] Add function to control reset with gpio inputs, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 01/17] Create Resettable QOM interface,
Damien Hedde <=
- [Qemu-devel] [RFC PATCH 11/17] Put orphan buses in system reset domain, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 12/17] Put default sysbus in system reset domain, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 17/17] Connect the uart reset gpios in the zynq platform, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 14/17] convert cadence_uart to 3-phases reset, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 16/17] Add uart reset support in zynq_slcr, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 13/17] hw/misc/zynq_slcr: use standard register definition, Damien Hedde, 2019/03/25
- [Qemu-devel] [RFC PATCH 15/17] Convert zynq's slcr to 3-phases reset, Damien Hedde, 2019/03/25
- Re: [Qemu-devel] [RFC 00/17] multi-phase reset mechanism, no-reply, 2019/03/25