From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
DRI Development <dri-devel@lists.freedesktop.org>,
Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [Intel-gfx] [PATCH 06/26] drm/atomic: Add __drm_atomic_get_current_plane_state
Date: Tue, 31 May 2016 10:35:13 +0200 [thread overview]
Message-ID: <1638f409-fdb1-1b09-e795-a47e48771a17@linux.intel.com> (raw)
In-Reply-To: <20160530150512.GN27098@phenom.ffwll.local>
Op 30-05-16 om 17:05 schreef Daniel Vetter:
> On Mon, May 30, 2016 at 01:42:40PM +0200, Maarten Lankhorst wrote:
>> Op 29-05-16 om 20:35 schreef Daniel Vetter:
>>> ... and use it in msm&vc4. Again just want to encapsulate
>>> drm_atomic_state internals a bit.
>>>
>>> The const threading is a bit awkward in vc4 since C sucks, but I still
>>> think it's worth to enforce this. Eventually I want to make all the
>>> obj->state pointers const too, but that's a lot more work ...
>>>
>>> Cc: Eric Anholt <eric@anholt.net>
>>> Cc: Rob Clark <robdclark@gmail.com>
>>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>>> ---
>>> drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c | 10 +++------
>>> drivers/gpu/drm/vc4/vc4_crtc.c | 11 +++-------
>>> drivers/gpu/drm/vc4/vc4_drv.h | 2 +-
>>> drivers/gpu/drm/vc4/vc4_plane.c | 5 +++--
>>> include/drm/drm_atomic.h | 36 ++++++++++++++++++++++++++++++++
>>> 5 files changed, 46 insertions(+), 18 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
>>> index 88fe256c1931..6d4086ee0503 100644
>>> --- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
>>> +++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
>>> @@ -383,19 +383,15 @@ static int mdp5_crtc_atomic_check(struct drm_crtc *crtc,
>>> */
>>> hw_cfg = mdp5_cfg_get_hw_config(mdp5_kms->cfg);
>>> drm_atomic_crtc_state_for_each_plane(plane, state) {
>>> - struct drm_plane_state *pstate;
>>> + const struct drm_plane_state *pstate;
>>> if (cnt >= (hw_cfg->lm.nb_stages)) {
>>> dev_err(dev->dev, "too many planes!\n");
>>> return -EINVAL;
>>> }
>>>
>>> - pstate = state->state->plane_states[drm_plane_index(plane)];
>>> + pstate = __drm_atomic_get_current_plane_state(state->state,
>>> + plane);
>>>
>>> - /* plane might not have changed, in which case take
>>> - * current state:
>>> - */
>>> - if (!pstate)
>>> - pstate = plane->state;
>>> pstates[cnt].plane = plane;
>>> pstates[cnt].state = to_mdp5_plane_state(pstate);
>>>
>>> diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c
>>> index 904d0754ad78..703bda170105 100644
>>> --- a/drivers/gpu/drm/vc4/vc4_crtc.c
>>> +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
>>> @@ -405,14 +405,9 @@ static int vc4_crtc_atomic_check(struct drm_crtc *crtc,
>>> return -EINVAL;
>>>
>>> drm_atomic_crtc_state_for_each_plane(plane, state) {
>>> - struct drm_plane_state *plane_state =
>>> - state->state->plane_states[drm_plane_index(plane)];
>>> -
>>> - /* plane might not have changed, in which case take
>>> - * current state:
>>> - */
>>> - if (!plane_state)
>>> - plane_state = plane->state;
>>> + const struct drm_plane_state *plane_state =
>>> + __drm_atomic_get_current_plane_state(state->state,
>>> + plane);
>>>
>>> dlist_count += vc4_plane_dlist_size(plane_state);
>>> }
>>> diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
>>> index 37cac59401d7..c799baabc008 100644
>>> --- a/drivers/gpu/drm/vc4/vc4_drv.h
>>> +++ b/drivers/gpu/drm/vc4/vc4_drv.h
>>> @@ -469,7 +469,7 @@ int vc4_kms_load(struct drm_device *dev);
>>> struct drm_plane *vc4_plane_init(struct drm_device *dev,
>>> enum drm_plane_type type);
>>> u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
>>> -u32 vc4_plane_dlist_size(struct drm_plane_state *state);
>>> +u32 vc4_plane_dlist_size(const struct drm_plane_state *state);
>>> void vc4_plane_async_set_fb(struct drm_plane *plane,
>>> struct drm_framebuffer *fb);
>>>
>>> diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c
>>> index 4037b52fde31..5d2c3d9fd17a 100644
>>> --- a/drivers/gpu/drm/vc4/vc4_plane.c
>>> +++ b/drivers/gpu/drm/vc4/vc4_plane.c
>>> @@ -690,9 +690,10 @@ u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist)
>>> return vc4_state->dlist_count;
>>> }
>>>
>>> -u32 vc4_plane_dlist_size(struct drm_plane_state *state)
>>> +u32 vc4_plane_dlist_size(const struct drm_plane_state *state)
>>> {
>>> - struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
>>> + const struct vc4_plane_state *vc4_state =
>>> + container_of(state, typeof(*vc4_state), base);
>>>
>>> return vc4_state->dlist_count;
>>> }
>>> diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
>>> index 92c84e9ab09a..4e97186293be 100644
>>> --- a/include/drm/drm_atomic.h
>>> +++ b/include/drm/drm_atomic.h
>>> @@ -109,6 +109,42 @@ drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
>>> return state->connector_states[index];
>>> }
>>>
>>> +/**
>>> + * __drm_atomic_get_current_plane_state - get current plane state
>>> + * @state: global atomic state object
>>> + * @plane: plane to grab
>>> + *
>>> + * This function returns the plane state for the given plane, either from
>>> + * @state, or if the plane isn't part of the atomic state update, from @plane.
>>> + * This is useful in atomic check callbacks, when drivers need to peek at, but
>>> + * not change, state of other planes, since it avoids threading an error code
>>> + * back up the call chain.
>>> + *
>>> + * WARNING:
>>> + *
>>> + * Note that this function is in general unsafe since it doesn't check for the
>>> + * required locking for access state structures. Drivers must ensure that it is
>>> + * save to access the returned state structure through other means. One commone
>>> + * example is when planes are fixed to a single CRTC, and the driver knows that
>>> + * the CRTC locks is held already. In that case holding the CRTC locks gives a
>>> + * read-lock on all planes connected to that CRTC. But if planes can be
>>> + * reassigned things get more tricky. In that case it's better to use
>>> + * drm_atomic_get_plane_state and wire up full error handling.
>>> + *
>>> + * Returns:
>>> + *
>>> + * Read-only pointer to the current plane state.
>>> + */
>>> +static inline const struct drm_plane_state *
>>> +__drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
>>> + struct drm_plane *plane)
>>> +{
>>> + if (state->plane_states[drm_plane_index(plane)])
>>> + return state->plane_states[drm_plane_index(plane)];
>> Could use a debug WARN_ON here. Just in case someone tries to use this for a plane that can't be safely checked:
>>
>> WARN_ON(!plane->state->crtc || !drm_modeset_is_locked(&plane->state->crtc->mutex));
> If you have hw like i915, where you can't move planes, this check isn't
> good enough, because plane->state->crtc might be NULL, but if you hold the
> right crtc mutex it's still perfectly safe. That's why I didn't add that
> check, and instead typed the really long warning.
Wrong! If crtc == NULL, you can set for example a different source rectangle, and plane->state would change from
underneath you since you don't hold the plane mutex.
>> Also use drm_atomic_get_existing_plane_state?
> Hm, feels like overkill since this is a core atomic function. We don't use
> get_existing_* in drm_atomic.c much either.
Ok, but that's an oversight..
Looking at drm_atomic.c it seems to me that drm_atomic_state_default_clear should use for_each_xx_in too..
drm_atomic_get_{crtc,plane}_state uses get_existing_state, drm_atomic_get_connector_state does not, since it duplicated some checks in drm_atomic_get_connector_state.
It is probably worth it to convert drm_atomic_get_connector_state too.
Apart from that I don't see what you mean..
~Maarten
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-05-31 8:35 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-29 18:34 [PATCH 00/26] RFC: generic nonblocking support in the atomic helpers Daniel Vetter
2016-05-29 18:34 ` [PATCH 01/26] drm/atomic-helper: use for_each_*_in_state more Daniel Vetter
2016-05-30 12:17 ` Maarten Lankhorst
2016-05-30 15:02 ` Daniel Vetter
2016-05-29 18:34 ` [PATCH 02/26] drm/i915: Use drm_atomic_get_existing_plane_state Daniel Vetter
2016-05-30 13:10 ` [Intel-gfx] " Maarten Lankhorst
2016-05-29 18:35 ` [PATCH 03/26] drm/msm: Use for_each_*_in_state Daniel Vetter
2016-05-29 18:35 ` [PATCH 04/26] drm/rcar-du: " Daniel Vetter
2016-05-30 9:18 ` Laurent Pinchart
2016-05-30 9:58 ` Maarten Lankhorst
2016-05-30 14:54 ` [Intel-gfx] " Daniel Vetter
2016-06-02 22:54 ` Laurent Pinchart
2016-06-03 6:55 ` [Intel-gfx] " Daniel Vetter
2016-06-03 9:40 ` Laurent Pinchart
2016-06-03 9:45 ` Daniel Vetter
2016-06-03 9:50 ` Laurent Pinchart
2016-05-29 18:35 ` [PATCH 05/26] drm/vc4: Use for_each_plane_in_state Daniel Vetter
2016-05-29 18:35 ` [PATCH 06/26] drm/atomic: Add __drm_atomic_get_current_plane_state Daniel Vetter
2016-05-30 11:42 ` [Intel-gfx] " Maarten Lankhorst
2016-05-30 15:05 ` Daniel Vetter
2016-05-31 8:35 ` Maarten Lankhorst [this message]
2016-05-29 18:35 ` [PATCH 07/26] drm/exynos: Use for_each_crtc_in_state Daniel Vetter
2016-05-31 12:19 ` Inki Dae
2016-06-13 0:52 ` Inki Dae
2016-05-29 18:35 ` [PATCH 08/26] drm: Consolidate connector arrays in drm_atomic_state Daniel Vetter
2016-05-30 14:59 ` Ville Syrjälä
2016-05-30 15:13 ` Daniel Vetter
2016-05-30 15:25 ` [Intel-gfx] " Ville Syrjälä
2016-05-30 15:33 ` Daniel Vetter
2016-05-30 15:45 ` Ville Syrjälä
2016-05-30 15:48 ` [Intel-gfx] " Daniel Vetter
2016-05-29 18:35 ` [PATCH 09/26] drm: Consolidate plane " Daniel Vetter
2016-05-29 18:35 ` [PATCH 10/26] drm: Consolidate crtc " Daniel Vetter
2016-05-29 18:35 ` [PATCH 11/26] drm/fence: add fence to drm_pending_event Daniel Vetter
2016-05-29 18:35 ` [PATCH 12/26] drm/atomic-helper: Massage swap_state signature somewhat Daniel Vetter
2016-05-30 13:08 ` Maarten Lankhorst
2016-05-30 15:09 ` [Intel-gfx] " Daniel Vetter
2016-05-31 8:43 ` Maarten Lankhorst
2016-05-31 10:46 ` Daniel Vetter
2016-05-31 12:20 ` Maarten Lankhorst
2016-05-29 18:35 ` [PATCH 13/26] drm/arc: Nuke event_list Daniel Vetter
2016-05-29 18:35 ` [PATCH 14/26] drm/arc: Actually bother with handling atomic events Daniel Vetter
2016-05-29 18:35 ` [PATCH 15/26] drm/arc: Implement nonblocking commit correctly Daniel Vetter
2016-05-30 8:15 ` [Intel-gfx] " Maarten Lankhorst
2016-05-30 9:24 ` Daniel Vetter
2016-05-30 9:36 ` Maarten Lankhorst
2016-05-30 15:10 ` [Intel-gfx] " Daniel Vetter
2016-05-29 18:35 ` [PATCH 16/26] drm/hdlcd: Use helper support for nonblocking commits Daniel Vetter
2016-05-31 11:02 ` Liviu Dudau
2016-05-31 11:07 ` Daniel Vetter
2016-05-31 13:13 ` Liviu Dudau
2016-05-29 18:35 ` [PATCH 17/26] drm/fsl-du: Implement some semblance of vblank event handling Daniel Vetter
2016-05-29 18:35 ` [PATCH 18/26] drm/hisilicon: " Daniel Vetter
2016-05-29 18:35 ` [PATCH 19/26] drm/sun4i: " Daniel Vetter
2016-06-01 16:18 ` Maxime Ripard
2016-06-01 22:02 ` Daniel Vetter
2016-05-29 18:35 ` [PATCH 20/26] drm/atomic: kerneldoc for drm_atomic_crtc_needs_modeset Daniel Vetter
2016-05-29 18:35 ` [PATCH 21/26] drm/atomic-helper: nonblocking commit support Daniel Vetter
2016-05-30 8:01 ` [PATCH] " Daniel Vetter
2016-05-31 14:22 ` [Intel-gfx] " Maarten Lankhorst
2016-05-31 14:33 ` Daniel Vetter
2016-05-29 18:35 ` [PATCH 22/26] drm/i915: Signal drm events for atomic Daniel Vetter
2016-05-29 18:35 ` [PATCH 23/26] drm/i915: Roll out the helper nonblock tracking Daniel Vetter
2016-05-29 18:35 ` [PATCH 24/26] drm/rockchip: convert to helper nonblocking atomic commit Daniel Vetter
2016-05-29 18:35 ` [PATCH 25/26] drm/rockchip: Nuke pending event handling in preclose Daniel Vetter
2016-05-29 18:35 ` [PATCH 26/26] drm/virtio: Don't reinvent a flipping wheel Daniel Vetter
2016-05-31 13:40 ` ✗ Ro.CI.BAT: failure for RFC: generic nonblocking support in the atomic helpers Patchwork
2016-05-31 13:42 ` Patchwork
2016-05-31 14:29 ` Patchwork
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=1638f409-fdb1-1b09-e795-a47e48771a17@linux.intel.com \
--to=maarten.lankhorst@linux.intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel.vetter@intel.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.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