dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state.
Date: Wed, 16 Nov 2016 14:58:06 +0100	[thread overview]
Message-ID: <1479304688-24010-3-git-send-email-maarten.lankhorst@linux.intel.com> (raw)
In-Reply-To: <1479304688-24010-1-git-send-email-maarten.lankhorst@linux.intel.com>

With checks! This will allow safe access to the current state,
while ensuring that the correct locks are held.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 include/drm/drm_atomic.h       | 66 ++++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_modeset_lock.h | 21 ++++++++++++++
 2 files changed, 87 insertions(+)

diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index e527684dd394..462408a2d1b8 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -334,6 +334,72 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
 	return plane->state;
 }
 
+
+/**
+ * drm_atomic_get_current_plane_state - get current plane state
+ * @plane: plane to grab
+ *
+ * This function returns the current plane state for the given plane,
+ * with extra locking checks to make sure that the plane state can be
+ * retrieved safely.
+ *
+ * Returns:
+ *
+ * Pointer to the current plane state.
+ */
+static inline struct drm_plane_state *
+drm_atomic_get_current_plane_state(struct drm_plane *plane)
+{
+	struct drm_plane_state *plane_state = plane->state;
+	struct drm_crtc *crtc = plane_state ? plane_state->crtc : NULL;
+
+	if (crtc)
+		drm_modeset_lock_assert_one_held(&plane->mutex, &crtc->mutex);
+	else
+		drm_modeset_lock_assert_held(&plane->mutex);
+
+	return plane_state;
+}
+
+/**
+ * drm_atomic_get_current_crtc_state - get current crtc state
+ * @crtc: crtc to grab
+ *
+ * This function returns the current crtc state for the given crtc,
+ * with extra locking checks to make sure that the crtc state can be
+ * retrieved safely.
+ *
+ * Returns:
+ *
+ * Pointer to the current crtc state.
+ */
+static inline struct drm_crtc_state *
+drm_atomic_get_current_crtc_state(struct drm_crtc *crtc)
+{
+	drm_modeset_lock_assert_held(&crtc->mutex);
+
+	return crtc->state;
+}
+
+/**
+ * drm_atomic_get_current_connector_state - get current connector state
+ * @connector: connector to grab
+ *
+ * This function returns the current connector state for the given connector,
+ * with extra locking checks to make sure that the connector state can be
+ * retrieved safely.
+ *
+ * Returns:
+ *
+ * Pointer to the current connector state.
+ */
+#define drm_atomic_get_current_connector_state(connector) \
+({ /* Implemented as macro to avoid including drmP for struct drm_device */ \
+	struct drm_connector *con__ = (connector); \
+	drm_modeset_lock_assert_held(&con__->dev->mode_config.connection_mutex); \
+	con__->state; \
+})
+
 int __must_check
 drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
 			     struct drm_display_mode *mode);
diff --git a/include/drm/drm_modeset_lock.h b/include/drm/drm_modeset_lock.h
index d918ce45ec2c..7635ff18ab99 100644
--- a/include/drm/drm_modeset_lock.h
+++ b/include/drm/drm_modeset_lock.h
@@ -109,6 +109,27 @@ static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)
 	return ww_mutex_is_locked(&lock->mutex);
 }
 
+static inline void drm_modeset_lock_assert_held(struct drm_modeset_lock *lock)
+{
+#ifdef CONFIG_LOCKDEP
+	lockdep_assert_held(&lock->mutex.base);
+#else
+	WARN_ON(!drm_modeset_is_locked(lock));
+#endif
+}
+
+static inline void drm_modeset_lock_assert_one_held(struct drm_modeset_lock *lock1,
+						    struct drm_modeset_lock *lock2)
+{
+#ifdef CONFIG_LOCKDEP
+	WARN_ON(debug_locks &&
+		!lockdep_is_held(&lock1->mutex.base) &&
+		!lockdep_is_held(&lock2->mutex.base));
+#else
+	WARN_ON(!drm_modeset_is_locked(lock1) && !drm_modeset_is_locked(lock2));
+#endif
+}
+
 int drm_modeset_lock(struct drm_modeset_lock *lock,
 		struct drm_modeset_acquire_ctx *ctx);
 int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2016-11-16 13:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-16 13:58 [PATCH v2 0/4] drm/atomic: Add accessor macros for all atomic state Maarten Lankhorst
2016-11-16 13:58 ` [PATCH v2 1/4] drm/atomic: Add new iterators over all state, v2 Maarten Lankhorst
2016-11-16 13:58 ` Maarten Lankhorst [this message]
2016-11-16 14:35   ` [PATCH v2 2/4] drm/atomic: Add accessor macros for the current state Ville Syrjälä
2016-11-16 15:04     ` Daniel Vetter
2016-11-16 16:11       ` Maarten Lankhorst
2016-11-16 16:26         ` Daniel Vetter
2016-11-16 16:32         ` Ville Syrjälä
2016-11-17 11:58           ` Maarten Lankhorst
2016-11-17 12:26             ` Ville Syrjälä
2016-11-17 12:42               ` Maarten Lankhorst
2016-11-17 12:50                 ` Ville Syrjälä
2016-11-17 13:20                   ` [PATCH v2.1 2/4] drm/atomic: Add accessor macros for the current state, v2 Maarten Lankhorst
2016-12-09 22:27                     ` Daniel Vetter
2016-12-14 13:15                     ` Daniel Vetter
2016-12-15 10:24                       ` [PATCH v2.2 2/4] drm/atomic: Add accessor macros for the current state, v3 Maarten Lankhorst
2016-11-16 13:58 ` [PATCH v2 3/4] drm/atomic: Add macros to access existing old/new state Maarten Lankhorst
2016-12-28 14:25   ` Daniel Vetter
2016-11-16 13:58 ` [PATCH v2 4/4] drm/atomic: Add checks to ensure get_state is not called after swapping Maarten Lankhorst
2016-11-16 14:18 ` [PATCH v2 0/4] drm/atomic: Add accessor macros for all atomic state Daniel Vetter
2016-11-16 16:11   ` Maarten Lankhorst
2016-11-16 16:27     ` Daniel Vetter
2016-12-14 13:17 ` Daniel Vetter
2016-12-15  9:19   ` Maarten Lankhorst

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=1479304688-24010-3-git-send-email-maarten.lankhorst@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=dri-devel@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;
as well as URLs for NNTP newsgroup(s).