From: Peter Maydell <peter.maydell@linaro.org>
To: Damien Hedde <damien.hedde@greensocs.com>
Cc: "Daniel P. Berrange" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
qemu-s390x <qemu-s390x@nongnu.org>,
"Cornelia Huck" <cohuck@redhat.com>,
"Mark Burton" <mark.burton@greensocs.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Edgar Iglesias" <edgari@xilinx.com>,
qemu-arm <qemu-arm@nongnu.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"David Gibson" <david@gibson.dropbear.id.au>
Subject: Re: [PATCH v5 05/13] hw/core/resettable: add support for changing parent
Date: Fri, 29 Nov 2019 18:38:22 +0000 [thread overview]
Message-ID: <CAFEAcA-UV7rSL1mPD=NLyLtan60WNsc+MDjR6p2aDoz34bq8dg@mail.gmail.com> (raw)
In-Reply-To: <20191018150630.31099-6-damien.hedde@greensocs.com>
On Fri, 18 Oct 2019 at 16:07, Damien Hedde <damien.hedde@greensocs.com> wrote:
>
> Add a function resettable_change_parent() to do the required
> plumbing when changing the parent a of Resettable object.
>
> We need to make sure that the reset state of the object remains
> coherent with the reset state of the new parent.
>
> We make the 2 following hypothesis:
> + when an object is put in a parent under reset, the object goes in
> reset.
> + when an object is removed from a parent under reset, the object
> leaves reset.
>
> The added function avoid any glitch if both old and new parent are
> already in reset.
>
> Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
> ---
> hw/core/resettable.c | 54 +++++++++++++++++++++++++++++++++++++++++
> hw/core/trace-events | 1 +
> include/hw/resettable.h | 16 ++++++++++++
> 3 files changed, 71 insertions(+)
>
> diff --git a/hw/core/resettable.c b/hw/core/resettable.c
> index c5e11cff4f..60d4285fcc 100644
> --- a/hw/core/resettable.c
> +++ b/hw/core/resettable.c
> @@ -32,6 +32,14 @@ static void resettable_phase_exit(Object *obj, void *opaque, ResetType type);
> */
> static bool enter_phase_in_progress;
>
> +/**
> + * exit_phase_in_progress:
> + * Flag telling whether we are currently in an enter phase where side
> + * effects are forbidden. This flag allows us to catch if
> + * resettable_change_parent() is called during exit phase.
> + */
> +static unsigned exit_phase_in_progress;
This is another global that I don't think we should have.
Is it also just for asserts ?
> +
> void resettable_reset(Object *obj, ResetType type)
> {
> trace_resettable_reset(obj, type);
> @@ -58,7 +66,9 @@ void resettable_release_reset(Object *obj, ResetType type)
> /* TODO: change that assert when adding support for other reset types */
> assert(type == RESET_TYPE_COLD);
> trace_resettable_reset_release_begin(obj, type);
> + exit_phase_in_progress += 1;
> resettable_phase_exit(obj, NULL, type);
> + exit_phase_in_progress -= 1;
> trace_resettable_reset_release_end(obj);
> }
>
> @@ -198,6 +208,50 @@ static void resettable_phase_exit(Object *obj, void *opaque, ResetType type)
> trace_resettable_phase_exit_end(obj, obj_typename, s->count);
> }
>
> +/*
> + * resettable_get_count:
> + * Get the count of the Resettable object @obj. Return 0 if @obj is NULL.
> + */
> +static uint32_t resettable_get_count(Object *obj)
> +{
> + if (obj) {
> + ResettableClass *rc = RESETTABLE_GET_CLASS(obj);
> + return rc->get_state(obj)->count;
> + }
> + return 0;
> +}
> +
> +void resettable_change_parent(Object *obj, Object *newp, Object *oldp)
> +{
> + ResettableClass *rc = RESETTABLE_GET_CLASS(obj);
> + ResettableState *s = rc->get_state(obj);
> + uint32_t newp_count = resettable_get_count(newp);
> + uint32_t oldp_count = resettable_get_count(oldp);
> +
> + assert(!enter_phase_in_progress && !exit_phase_in_progress);
> + trace_resettable_change_parent(obj, oldp, oldp_count, newp, newp_count);
> +
> + /*
> + * At most one of the two 'for' loop will be executed below
"loops"
> + * in order to cope with the diff between the two count.
"difference". "counts".
> + */
> + /* if newp is more reset than oldp */
> + for (uint32_t i = oldp_count; i < newp_count; i++) {
> + resettable_assert_reset(obj, RESET_TYPE_COLD);
> + }
> + /*
> + * if obj is leaving a bus under reset, we need to ensure
> + * hold phase is not pending.
> + */
> + if (oldp_count && s->hold_phase_pending) {
> + resettable_phase_hold(obj, NULL, RESET_TYPE_COLD);
> + }
> + /* if oldp is more reset than newp */
> + for (uint32_t i = newp_count; i < oldp_count; i++) {
> + resettable_release_reset(obj, RESET_TYPE_COLD);
> + }
> +}
> +
> void resettable_class_set_parent_phases(ResettableClass *rc,
> ResettableEnterPhase enter,
> ResettableHoldPhase hold,
> diff --git a/hw/core/trace-events b/hw/core/trace-events
> index 66081d0fb4..6d03ef7ff9 100644
> --- a/hw/core/trace-events
> +++ b/hw/core/trace-events
> @@ -16,6 +16,7 @@ resettable_reset_assert_begin(void *obj, int cold) "obj=%p cold=%d"
> resettable_reset_assert_end(void *obj) "obj=%p"
> resettable_reset_release_begin(void *obj, int cold) "obj=%p cold=%d"
> resettable_reset_release_end(void *obj) "obj=%p"
> +resettable_change_parent(void *obj, void *o, uint32_t oc, void *n, uint32_t nc) "obj=%p from=%p(%" PRIu32 ") to=%p(%" PRIu32 ")"
> resettable_phase_enter_begin(void *obj, const char *objtype, uint32_t count, int type) "obj=%p(%s) count=%" PRIu32 " type=%d"
> resettable_phase_enter_exec(void *obj, const char *objtype, int type, int has_method) "obj=%p(%s) type=%d method=%d"
> resettable_phase_enter_end(void *obj, const char *objtype, uint32_t count) "obj=%p(%s) count=%" PRIu32
> diff --git a/include/hw/resettable.h b/include/hw/resettable.h
> index 6b24e1633b..f6d379669f 100644
> --- a/include/hw/resettable.h
> +++ b/include/hw/resettable.h
> @@ -182,6 +182,22 @@ void resettable_release_reset(Object *obj, ResetType type);
> */
> bool resettable_is_in_reset(Object *obj);
>
> +/**
> + * resettable_change_parent:
> + * Indicate that the parent of Ressettable @obj change from @oldp to @newp.
"is changing from"
> + * All 3 objects must implements resettable interface. @oldp or @newp may be
"implement"
> + * NULL.
> + *
> + * This function will adapt the reset state of @obj so that it is coherent
> + * with the reset state of @newp. It may trigger @resettable_assert_reset()
> + * or @resettable_release_reset(). It will do such things only if the reset
> + * state of @newp and @oldp are different.
> + *
> + * When using this function during reset, it must only be called during
> + * an hold phase method. Calling this during enter or exit phase is an error.
"a hold phase"
> + */
> +void resettable_change_parent(Object *obj, Object *newp, Object *oldp);
> +
thanks
-- PMM
next prev parent reply other threads:[~2019-11-29 18:42 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-18 15:06 [PATCH v5 00/13] Multi-phase reset mechanism Damien Hedde
2019-10-18 15:06 ` [PATCH v5 01/13] add device_legacy_reset function to prepare for reset api change Damien Hedde
2019-10-19 17:35 ` Richard Henderson
2019-12-03 10:55 ` Cornelia Huck
2019-10-18 15:06 ` [PATCH v5 02/13] hw/core/qdev: add trace events to help with resettable transition Damien Hedde
2019-10-19 17:44 ` Richard Henderson
2019-10-31 23:23 ` Philippe Mathieu-Daudé
2019-11-04 12:16 ` Damien Hedde
2019-11-04 14:33 ` Philippe Mathieu-Daudé
2019-12-03 10:57 ` Cornelia Huck
2019-10-18 15:06 ` [PATCH v5 03/13] hw/core: create Resettable QOM interface Damien Hedde
2019-11-29 18:32 ` Peter Maydell
2019-12-02 11:07 ` Damien Hedde
2019-12-02 11:14 ` Peter Maydell
2019-12-03 11:16 ` Cornelia Huck
2019-10-18 15:06 ` [PATCH v5 04/13] hw/core: add Resettable support to BusClass and DeviceClass Damien Hedde
2019-10-19 18:49 ` Richard Henderson
2019-11-29 18:36 ` Peter Maydell
2019-12-02 11:38 ` Damien Hedde
2019-10-18 15:06 ` [PATCH v5 05/13] hw/core/resettable: add support for changing parent Damien Hedde
2019-11-29 18:38 ` Peter Maydell [this message]
2019-12-02 11:43 ` Damien Hedde
2019-10-18 15:06 ` [PATCH v5 06/13] hw/core/qdev: handle parent bus change regarding resettable Damien Hedde
2019-11-29 18:41 ` Peter Maydell
2019-12-03 11:37 ` Cornelia Huck
2019-10-18 15:06 ` [PATCH v5 07/13] hw/core/qdev: update hotplug reset " Damien Hedde
2019-11-08 15:14 ` Damien Hedde
2019-10-18 15:06 ` [PATCH v5 08/13] hw/core: deprecate old reset functions and introduce new ones Damien Hedde
2019-10-31 23:35 ` Philippe Mathieu-Daudé
2019-11-04 12:01 ` Damien Hedde
2019-11-04 15:42 ` Philippe Mathieu-Daudé
2019-11-29 18:42 ` Peter Maydell
2019-10-18 15:06 ` [PATCH v5 09/13] docs/devel/reset.txt: add doc about Resettable interface Damien Hedde
2019-11-29 19:00 ` Peter Maydell
2019-12-06 15:40 ` Damien Hedde
2019-12-06 16:21 ` Damien Hedde
2019-10-18 15:06 ` [PATCH v5 10/13] vl: replace deprecated qbus_reset_all registration Damien Hedde
2019-11-29 19:01 ` Peter Maydell
2019-10-18 15:06 ` [PATCH v5 11/13] hw/s390x/ipl: replace deprecated qdev_reset_all registration Damien Hedde
2019-10-31 23:38 ` Philippe Mathieu-Daudé
2019-11-29 19:02 ` Peter Maydell
2019-12-03 11:41 ` Cornelia Huck
2019-10-18 15:06 ` [PATCH v5 12/13] hw/gpio/bcm2835_gpio: Isolate sdbus reparenting Damien Hedde
2019-11-29 19:05 ` Peter Maydell
2019-12-02 12:27 ` Damien Hedde
2019-12-02 12:33 ` Peter Maydell
2019-12-02 13:05 ` Damien Hedde
2019-12-02 13:10 ` Peter Maydell
2019-10-18 15:06 ` [PATCH v5 13/13] hw/gpio/bcm2835_gpio: Update to resettable Damien Hedde
2019-11-29 19:02 ` Peter Maydell
2019-10-19 9:01 ` [PATCH v5 00/13] Multi-phase reset mechanism no-reply
2019-10-29 15:53 ` Damien Hedde
2019-11-08 15:26 ` Damien Hedde
2019-11-08 15:28 ` Peter Maydell
2019-11-08 15:58 ` Damien Hedde
2019-11-29 19:07 ` Peter Maydell
2019-12-03 11:44 ` 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='CAFEAcA-UV7rSL1mPD=NLyLtan60WNsc+MDjR6p2aDoz34bq8dg@mail.gmail.com' \
--to=peter.maydell@linaro.org \
--cc=berrange@redhat.com \
--cc=cohuck@redhat.com \
--cc=damien.hedde@greensocs.com \
--cc=david@gibson.dropbear.id.au \
--cc=edgari@xilinx.com \
--cc=ehabkost@redhat.com \
--cc=mark.burton@greensocs.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@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).