From: Damien Hedde <damien.hedde@greensocs.com>
To: qemu-devel@nongnu.org
Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org,
marc.burton@greensocs.com, alistair@alistair23.me,
qemu-arm@nongnu.org, Damien Hedde <damien.hedde@greensocs.com>,
marcandre.lureau@redhat.com, pbonzini@redhat.com,
philmd@redhat.com, luc.michel@greensocs.com
Subject: [Qemu-devel] [RFC PATCH v2 05/12] Add function to control reset with gpio inputs
Date: Tue, 4 Jun 2019 18:25:19 +0200 [thread overview]
Message-ID: <20190604162526.10655-6-damien.hedde@greensocs.com> (raw)
In-Reply-To: <20190604162526.10655-1-damien.hedde@greensocs.com>
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.
Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---
hw/core/qdev.c | 57 ++++++++++++++++++++++++++++++++++++++++++
include/hw/qdev-core.h | 44 ++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 8c3911c2bd..89405398ae 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -429,6 +429,61 @@ void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
qdev_init_gpio_in_named(dev, handler, NULL, n);
}
+static void device_reset_handler(DeviceState *dev, bool cold, bool level)
+{
+ DeviceResetInputState *dris;
+
+ dris = cold ? &dev->cold_reset_input : &dev->warm_reset_input;
+
+ if (level == dris->state) {
+ /* io state has not changed */
+ return;
+ }
+
+ dris->state = level;
+ switch (dris->type) {
+ case DEVICE_ACTIVE_LOW:
+ level = !level;
+ case DEVICE_ACTIVE_HIGH:
+ if (level) {
+ resettable_assert_reset(OBJECT(dev), cold);
+ } else {
+ resettable_deassert_reset(OBJECT(dev));
+ }
+ break;
+ }
+}
+
+static void device_cold_reset_handler(void *opaque, int n, int level)
+{
+ device_reset_handler((DeviceState *) opaque, true, level);
+}
+
+static void device_warm_reset_handler(void *opaque, int n, int level)
+{
+ device_reset_handler((DeviceState *) opaque, false, level);
+}
+
+void qdev_init_reset_gpio_in_named(DeviceState *dev, const char *name,
+ bool cold, DeviceActiveType type)
+{
+ qemu_irq_handler handler;
+
+ if (cold) {
+ assert(!dev->cold_reset_input.exists);
+ dev->cold_reset_input.exists = true;
+ dev->cold_reset_input.type = type;
+ handler = device_cold_reset_handler;
+ } else {
+ assert(!dev->warm_reset_input.exists);
+ dev->warm_reset_input.exists = true;
+ dev->warm_reset_input.type = type;
+ handler = device_warm_reset_handler;
+ }
+
+ qdev_init_gpio_in_named(dev, handler, name, 1);
+}
+
void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
const char *name, int n)
{
@@ -986,6 +1041,8 @@ static void device_initfn(Object *obj)
dev->instance_id_alias = -1;
dev->realized = false;
dev->resetting = 0;
+ dev->cold_reset_input.exists = false;
+ dev->warm_reset_input.exists = false;
object_property_add_bool(obj, "realized",
device_get_realized, device_set_realized, NULL);
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 658a419350..693f79b385 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -134,6 +134,17 @@ struct NamedGPIOList {
QLIST_ENTRY(NamedGPIOList) node;
};
+typedef enum DeviceActiveType {
+ DEVICE_ACTIVE_LOW,
+ DEVICE_ACTIVE_HIGH,
+} DeviceActiveType;
+
+typedef struct DeviceResetInputState {
+ bool exists;
+ DeviceActiveType type;
+ bool state;
+} DeviceResetInputState;
+
/**
* DeviceState:
* @realized: Indicates whether the device has been fully constructed.
@@ -161,6 +172,8 @@ struct DeviceState {
int instance_id_alias;
int alias_required_for_version;
uint32_t resetting;
+ DeviceResetInputState cold_reset_input;
+ DeviceResetInputState warm_reset_input;
};
struct DeviceListener {
@@ -362,6 +375,37 @@ static inline void qdev_init_gpio_in_named(DeviceState *dev,
void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
const char *name);
+/**
+ * qdev_init_reset_gpio_in_named:
+ * Create a gpio controlling the warm or cold reset of the device.
+ * @cold specify whether it triggers cold or warm reset
+ * @type what kind of reset io it is
+ */
+void qdev_init_reset_gpio_in_named(DeviceState *dev, const char *name,
+ bool cold, DeviceActiveType type);
+
+/**
+ * qdev_init_warm_reset_gpio:
+ * Create a reset input to control the device warm reset.
+ */
+static inline void qdev_init_warm_reset_gpio(DeviceState *dev,
+ const char *name,
+ DeviceActiveType type)
+{
+ qdev_init_reset_gpio_in_named(dev, name, false, type);
+}
+
+/**
+ * qdev_init_power_gate_gpio:
+ * Create a power gate input to control the device cold reset.
+ */
+static inline void qdev_init_power_gate_gpio(DeviceState *dev,
+ const char *name,
+ DeviceActiveType type)
+{
+ qdev_init_reset_gpio_in_named(dev, name, true, type);
+}
+
BusState *qdev_get_parent_bus(DeviceState *dev);
/*** BUS API. ***/
--
2.21.0
next prev parent reply other threads:[~2019-06-04 16:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-04 16:25 [Qemu-devel] [RFC PATCH v2 00/12] Multi-phase reset Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 01/12] Create Resettable QOM interface Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 02/12] add device_legacy_reset function to do the transition with device_reset Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 03/12] replace all occurences of device_reset by device_legacy_reset Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 04/12] make Device and Bus Resettable Damien Hedde
2019-06-04 16:25 ` Damien Hedde [this message]
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 06/12] add vmstate description for device reset state Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 07/12] add doc about Resettable interface Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 08/12] hw/misc/zynq_slcr: use standard register definition Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 09/12] convert cadence_uart to 3-phases reset Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 10/12] Convert zynq's slcr " Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 11/12] Add uart reset support in zynq_slcr Damien Hedde
2019-06-04 16:25 ` [Qemu-devel] [RFC PATCH v2 12/12] Connect the uart reset gpios in the zynq platform Damien Hedde
2019-06-18 16:13 ` [Qemu-devel] [RFC PATCH v2 00/12] Multi-phase reset Peter Maydell
2019-06-27 9:13 ` Damien Hedde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190604162526.10655-6-damien.hedde@greensocs.com \
--to=damien.hedde@greensocs.com \
--cc=alistair@alistair23.me \
--cc=edgar.iglesias@xilinx.com \
--cc=luc.michel@greensocs.com \
--cc=marc.burton@greensocs.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).