From patchwork Thu Dec 15 10:24:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 9475823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8E4D060825 for ; Thu, 15 Dec 2016 10:25:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C1842865A for ; Thu, 15 Dec 2016 10:25:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E85D28678; Thu, 15 Dec 2016 10:25:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C8E982865A for ; Thu, 15 Dec 2016 10:25:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5F1F76E94E; Thu, 15 Dec 2016 10:24:59 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id C16976E94D for ; Thu, 15 Dec 2016 10:24:57 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 15 Dec 2016 02:24:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,351,1477983600"; d="scan'208";a="18437279" Received: from cpeconom-mobl1.amr.corp.intel.com (HELO patser.lan) ([10.252.2.176]) by orsmga002.jf.intel.com with ESMTP; 15 Dec 2016 02:24:55 -0800 Subject: [PATCH v2.2 2/4] drm/atomic: Add accessor macros for the current state, v3. To: Daniel Vetter References: <1479304688-24010-3-git-send-email-maarten.lankhorst@linux.intel.com> <20161116143545.GQ31595@intel.com> <20161116150439.vmi7bycdcqjytwcz@phenom.ffwll.local> <8e1575af-4e91-caea-0f35-c3a03771a0e8@linux.intel.com> <20161116163236.GS31595@intel.com> <20161117122619.GT31595@intel.com> <52d48256-d2d2-4926-fbdf-256745e033a3@linux.intel.com> <20161117125045.GU31595@intel.com> <20161214131502.qjmwchex5mqemt5q@phenom.ffwll.local> From: Maarten Lankhorst Message-ID: <6c4dfe15-508d-166b-a6ac-b9557e1f91b9@linux.intel.com> Date: Thu, 15 Dec 2016 11:24:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20161214131502.qjmwchex5mqemt5q@phenom.ffwll.local> Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP With checks! This will allow safe access to the current state, while ensuring that the correct locks are held. Changes since v1: - Constify returned states. - Require plane lock to return plane state, don't allow crtc_lock to be sufficient. Changes since v2: - Include drmP.h for drm_device, change the macro drm_atomic_get_current_connector_state back to a function. Signed-off-by: Maarten Lankhorst --- include/drm/drm_atomic.h | 62 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modeset_lock.h | 9 ++++++ 2 files changed, 71 insertions(+) diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index ca9b32d157bd..63b5fc8e1fdc 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -29,6 +29,7 @@ #define DRM_ATOMIC_H_ #include +#include /** * struct drm_crtc_commit - track modeset commits on a CRTC @@ -335,6 +336,67 @@ __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 const struct drm_plane_state * +drm_atomic_get_current_plane_state(struct drm_plane *plane) +{ + 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 const 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. + */ +static inline const struct drm_connector_state * +drm_atomic_get_current_connector_state(struct drm_connector *connector) +{ + drm_modeset_lock_assert_held(&connector->dev->mode_config.connection_mutex); + + return connector->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..3ca4ee838b07 100644 --- a/include/drm/drm_modeset_lock.h +++ b/include/drm/drm_modeset_lock.h @@ -109,6 +109,15 @@ 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 +} + 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,