qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Damien Hedde <damien.hedde@greensocs.com>
Cc: fam@euphon.net, peter.maydell@linaro.org, walling@linux.ibm.com,
	dmitry.fleytman@gmail.com, mst@redhat.com,
	mark.cave-ayland@ilande.co.uk, qemu-devel@nongnu.org,
	kraxel@redhat.com, edgar.iglesias@xilinx.com, hare@suse.com,
	qemu-block@nongnu.org, david@redhat.com, pasic@linux.ibm.com,
	borntraeger@de.ibm.com, marcandre.lureau@redhat.com,
	thuth@redhat.com, ehabkost@redhat.com, alistair@alistair23.me,
	qemu-s390x@nongnu.org, qemu-arm@nongnu.org, clg@kaod.org,
	jsnow@redhat.com, rth@twiddle.net, berrange@redhat.com,
	cohuck@redhat.com, mark.burton@greensocs.com,
	qemu-ppc@nongnu.org, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 08/33] Add function to control reset with gpio inputs
Date: Wed, 31 Jul 2019 16:11:08 +1000	[thread overview]
Message-ID: <20190731061108.GF2032@umbus.fritz.box> (raw)
In-Reply-To: <20190729145654.14644-9-damien.hedde@greensocs.com>

[-- Attachment #1: Type: text/plain, Size: 8225 bytes --]

On Mon, Jul 29, 2019 at 04:56:29PM +0200, Damien Hedde wrote:
> 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.
> 
> Vmstate subsections are also added to the existsing device_reset
> subsection.

This doesn't seem like a thing that should be present on every single
DeviceState.

> 
> Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
> ---
>  hw/core/qdev-vmstate.c | 15 ++++++++++
>  hw/core/qdev.c         | 65 ++++++++++++++++++++++++++++++++++++++++++
>  include/hw/qdev-core.h | 57 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 137 insertions(+)
> 
> diff --git a/hw/core/qdev-vmstate.c b/hw/core/qdev-vmstate.c
> index 24f8465c61..72f84c6cee 100644
> --- a/hw/core/qdev-vmstate.c
> +++ b/hw/core/qdev-vmstate.c
> @@ -24,10 +24,23 @@ static int device_vmstate_reset_post_load(void *opaque, int version_id)
>  {
>      DeviceState *dev = (DeviceState *) opaque;
>      BusState *bus;
> +    uint32_t io_count = 0;
> +
>      QLIST_FOREACH(bus, &dev->child_bus, sibling) {
>          bus->resetting = dev->resetting;
>          bus->reset_is_cold = dev->reset_is_cold;
>      }
> +
> +    if (dev->cold_reset_input.state) {
> +        io_count += 1;
> +    }
> +    if (dev->warm_reset_input.state) {
> +        io_count += 1;
> +    }
> +    /* ensure resetting count is coherent with io states */
> +    if (dev->resetting < io_count) {
> +        return -1;
> +    }
>      return 0;
>  }
>  
> @@ -40,6 +53,8 @@ const struct VMStateDescription device_vmstate_reset = {
>      .fields = (VMStateField[]) {
>          VMSTATE_UINT32(resetting, DeviceState),
>          VMSTATE_BOOL(reset_is_cold, DeviceState),
> +        VMSTATE_BOOL(cold_reset_input.state, DeviceState),
> +        VMSTATE_BOOL(warm_reset_input.state, DeviceState),
>          VMSTATE_END_OF_LIST()
>      },
>  };
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 88387d3743..11a4de55ea 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -450,6 +450,67 @@ void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
>      qdev_init_gpio_in_named(dev, handler, NULL, n);
>  }
>  
> +static DeviceResetInputState *device_get_reset_input_state(DeviceState *dev,
> +                                                            bool cold)
> +{
> +    return cold ? &dev->cold_reset_input : &dev->warm_reset_input;
> +}
> +
> +static void device_reset_handler(DeviceState *dev, bool cold, bool level)
> +{
> +    DeviceResetInputState *dris = device_get_reset_input_state(dev, cold);
> +
> +    if (dris->type == DEVICE_RESET_ACTIVE_LOW) {
> +        level = !level;
> +    }
> +
> +    if (dris->state == level) {
> +        /* io state has not changed */
> +        return;
> +    }
> +
> +    dris->state = level;
> +
> +    if (level) {
> +        resettable_assert_reset(OBJECT(dev), cold);
> +    } else {
> +        resettable_deassert_reset(OBJECT(dev));
> +    }
> +}
> +
> +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, DeviceResetActiveType type)
> +{
> +    DeviceResetInputState *dris = device_get_reset_input_state(dev, cold);
> +    qemu_irq_handler handler;
> +
> +    switch (type) {
> +    case DEVICE_RESET_ACTIVE_LOW:
> +    case DEVICE_RESET_ACTIVE_HIGH:
> +        break;
> +    default:
> +        assert(false);
> +        break;
> +    }
> +
> +    assert(!dris->exists);
> +    dris->exists = true;
> +    dris->type = type;
> +
> +    handler = cold ? device_cold_reset_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)
>  {
> @@ -1007,6 +1068,10 @@ static void device_initfn(Object *obj)
>      dev->instance_id_alias = -1;
>      dev->realized = false;
>      dev->resetting = 0;
> +    dev->cold_reset_input.exists = false;
> +    dev->cold_reset_input.state = false;
> +    dev->warm_reset_input.exists = false;
> +    dev->warm_reset_input.state = 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 926d4bbcb1..f724ddc8f4 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -136,6 +136,23 @@ struct NamedGPIOList {
>      QLIST_ENTRY(NamedGPIOList) node;
>  };
>  
> +typedef enum DeviceResetActiveType {
> +    DEVICE_RESET_ACTIVE_LOW,
> +    DEVICE_RESET_ACTIVE_HIGH,
> +} DeviceResetActiveType;
> +
> +/**
> + * DeviceResetInputState:
> + * @exists: tell if io exists
> + * @type: tell whether the io active low or high
> + * @state: true if reset is currently active
> + */
> +typedef struct DeviceResetInputState {
> +    bool exists;
> +    DeviceResetActiveType type;
> +    bool state;
> +} DeviceResetInputState;
> +
>  /**
>   * DeviceState:
>   * @realized: Indicates whether the device has been fully constructed.
> @@ -143,6 +160,8 @@ struct NamedGPIOList {
>   * used to count how many times reset has been initiated on the device.
>   * @reset_is_cold: If the device is under reset, indicates whether it is cold
>   * or warm.
> + * @cold_reset_input: state data for cold reset io
> + * @warm_reset_input: state data for warm reset io
>   *
>   * This structure should not be accessed directly.  We declare it here
>   * so that it can be embedded in individual device state structures.
> @@ -167,6 +186,8 @@ struct DeviceState {
>      uint32_t resetting;
>      bool reset_is_cold;
>      bool reset_hold_needed;
> +    DeviceResetInputState cold_reset_input;
> +    DeviceResetInputState warm_reset_input;
>  };
>  
>  struct DeviceListener {
> @@ -372,6 +393,42 @@ 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
> + *
> + * Note: the io is considered created in its inactive state. No reset
> + * is started by this function.
> + */
> +void qdev_init_reset_gpio_in_named(DeviceState *dev, const char *name,
> +                                   bool cold, DeviceResetActiveType type);
> +
> +/**
> + * qdev_init_warm_reset_gpio:
> + * Create the input to control the device warm reset.
> + */
> +static inline void qdev_init_warm_reset_gpio(DeviceState *dev,
> +                                             const char *name,
> +                                             DeviceResetActiveType type)
> +{
> +    qdev_init_reset_gpio_in_named(dev, name, false, type);
> +}
> +
> +/**
> + * qdev_init_cold_reset_gpio:
> + * Create the input to control the device cold reset.
> + * It can also be used as a power gate control.
> + */
> +static inline void qdev_init_cold_reset_gpio(DeviceState *dev,
> +                                             const char *name,
> +                                             DeviceResetActiveType type)
> +{
> +    qdev_init_reset_gpio_in_named(dev, name, true, type);
> +}
> +
>  BusState *qdev_get_parent_bus(DeviceState *dev);
>  
>  /*** BUS API. ***/

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-07-31  6:36 UTC|newest]

Thread overview: 113+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-29 14:56 [Qemu-devel] [PATCH v3 00/33] Multi-phase reset mechanism Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 01/33] Create Resettable QOM interface Damien Hedde
2019-07-30 13:42   ` Cornelia Huck
2019-07-30 13:44     ` Peter Maydell
2019-07-30 13:55       ` Cornelia Huck
2019-07-30 13:59         ` Peter Maydell
2019-07-30 14:08           ` Damien Hedde
2019-07-30 15:47             ` Cornelia Huck
2019-07-31  5:46             ` David Gibson
2019-08-01  9:35               ` Damien Hedde
2019-08-12 10:27                 ` David Gibson
2019-07-31 10:17           ` Christophe de Dinechin
2019-08-01  9:19             ` Damien Hedde
2019-08-01  9:30               ` Christophe de Dinechin
2019-08-07 14:20   ` Peter Maydell
2019-08-07 15:03     ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 02/33] add temporary device_legacy_reset function to replace device_reset Damien Hedde
2019-08-07 14:27   ` Peter Maydell
2019-08-09  9:20     ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 03/33] Replace all call to device_reset by call to device_legacy_reset Damien Hedde
2019-07-31  5:52   ` David Gibson
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 04/33] make Device and Bus Resettable Damien Hedde
2019-07-31  5:56   ` David Gibson
2019-07-31  9:09     ` Damien Hedde
2019-08-06  0:35       ` David Gibson
2019-08-07  7:55         ` Damien Hedde
2019-08-12 10:28           ` David Gibson
2019-08-07 14:41   ` Peter Maydell
2019-08-07 15:23     ` Damien Hedde
2019-08-07 15:28       ` Peter Maydell
2019-08-12  9:08     ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 05/33] Switch to new api in qdev/bus Damien Hedde
2019-07-31  6:05   ` David Gibson
2019-07-31  9:29     ` Damien Hedde
2019-07-31 11:31       ` Philippe Mathieu-Daudé
2019-08-08  6:47         ` David Gibson
2019-08-09 11:08           ` Peter Maydell
2019-08-12 10:34             ` David Gibson
2019-08-08  6:48       ` David Gibson
2019-08-09 11:39         ` Cédric Le Goater
2019-08-12 10:36           ` David Gibson
2019-08-07 14:48   ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 06/33] add the vmstate description for device reset state Damien Hedde
2019-07-31  6:08   ` David Gibson
2019-07-31 11:04     ` Damien Hedde
2019-08-07 14:53   ` Peter Maydell
2019-08-07 14:54   ` Peter Maydell
2019-08-07 15:27     ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 07/33] automatically add vmstate for reset support in devices Damien Hedde
2019-08-07 15:07   ` Peter Maydell
2019-08-07 17:22     ` Damien Hedde
2019-08-08 15:42     ` Dr. David Alan Gilbert
2019-08-09 10:07       ` Peter Maydell
2019-08-09 10:29         ` Damien Hedde
2019-08-09 10:32           ` Peter Maydell
2019-08-09 10:46             ` Damien Hedde
2019-08-09 13:02               ` Juan Quintela
2019-08-09 13:01             ` Juan Quintela
2019-08-09 13:50         ` Dr. David Alan Gilbert
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 08/33] Add function to control reset with gpio inputs Damien Hedde
2019-07-31  6:11   ` David Gibson [this message]
2019-07-31 10:09     ` Damien Hedde
2019-08-07 10:37     ` Peter Maydell
2019-08-09  5:51       ` David Gibson
2019-08-09  8:45         ` Damien Hedde
2019-08-12 10:29           ` David Gibson
2019-08-07 15:18   ` Peter Maydell
2019-08-07 16:56     ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 09/33] add doc about Resettable interface Damien Hedde
2019-07-31  6:30   ` David Gibson
2019-07-31 10:05     ` Damien Hedde
2019-08-07 10:34     ` Peter Maydell
2019-08-08  6:49       ` David Gibson
2019-08-07 16:01     ` Peter Maydell
2019-08-12 10:15       ` David Gibson
2019-08-07 15:58   ` Peter Maydell
2019-08-07 16:02   ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 10/33] vl.c: remove qbus_reset_all registration Damien Hedde
2019-08-07 15:20   ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 11/33] hw/s390x/ipl.c: " Damien Hedde
2019-08-07 15:24   ` Peter Maydell
2019-08-08 10:25     ` Cornelia Huck
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 12/33] hw/pci/: remove qdev/qbus_reset_all call Damien Hedde
2019-08-07 15:31   ` Peter Maydell
2019-08-09  9:47     ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 13/33] hw/scsi/: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 14/33] hw/s390x/s390-virtio-ccw.c: remove qdev_reset_all call Damien Hedde
2019-08-08 10:50   ` Cornelia Huck
2019-08-09  8:31     ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 15/33] hw/ide/piix.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 16/33] hw/input/adb.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 17/33] hw/usb/dev-uas.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 18/33] hw/audio/intel-hda.c: remove device_legacy_reset call Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 19/33] hw/sd/pl181.c & omap_mmc.c: " Damien Hedde
2019-07-31 15:48   ` Philippe Mathieu-Daudé
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 20/33] hw/hyperv/hyperv.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 21/33] hw/intc/spapr_xive.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 22/33] hw/ppc/pnv_psi.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 23/33] hw/scsi/vmw_pvscsi.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 24/33] hw/ppc/spapr: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 25/33] hw/i386/pc.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 26/33] hw/s390x/s390-pci-inst.c: " Damien Hedde
2019-08-08 10:52   ` Cornelia Huck
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 27/33] hw/ide/microdrive.c: remove device_legacy_reset calls Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 28/33] qdev: Remove unused deprecated reset functions Damien Hedde
2019-08-07 15:29   ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 29/33] hw/misc/zynq_slcr: use standard register definition Damien Hedde
2019-08-07 15:33   ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 30/33] convert cadence_uart to 3-phases reset Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 31/33] Convert zynq's slcr " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 32/33] Add uart reset support in zynq_slcr Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 33/33] Connect the uart reset gpios in the zynq platform Damien Hedde
2019-07-30 10:14 ` [Qemu-devel] [PATCH v3 00/33] Multi-phase reset mechanism Cornelia Huck

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=20190731061108.GF2032@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=alistair@alistair23.me \
    --cc=berrange@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=clg@kaod.org \
    --cc=cohuck@redhat.com \
    --cc=damien.hedde@greensocs.com \
    --cc=david@redhat.com \
    --cc=dmitry.fleytman@gmail.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=ehabkost@redhat.com \
    --cc=fam@euphon.net \
    --cc=hare@suse.com \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mark.burton@greensocs.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mst@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=thuth@redhat.com \
    --cc=walling@linux.ibm.com \
    /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).