From patchwork Tue Oct 11 14:54:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Starkey X-Patchwork-Id: 37422 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1btyTo-0000cw-1Y; Tue, 11 Oct 2016 14:56:32 +0000 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.84_2/mailfrontend-7) with esmtp id 1btyTm-0005Lh-08; Tue, 11 Oct 2016 16:56:31 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753088AbcJKOyp (ORCPT + 1 other); Tue, 11 Oct 2016 10:54:45 -0400 Received: from foss.arm.com ([217.140.101.70]:35458 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752263AbcJKOyn (ORCPT ); Tue, 11 Oct 2016 10:54:43 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 661211476; Tue, 11 Oct 2016 07:54:20 -0700 (PDT) Received: from e106950-lin.cambridge.arm.com (e106950-lin.cambridge.arm.com [10.2.133.193]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D02863F32C; Tue, 11 Oct 2016 07:54:18 -0700 (PDT) From: Brian Starkey To: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, liviu.dudau@arm.com, robdclark@gmail.com, hverkuil@xs4all.nl, eric@anholt.net, ville.syrjala@linux.intel.com, daniel@ffwll.ch Subject: [RFC PATCH 03/11] drm: Extract CRTC/plane disable from drm_framebuffer_remove Date: Tue, 11 Oct 2016 15:54:00 +0100 Message-Id: <1476197648-24918-4-git-send-email-brian.starkey@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1476197648-24918-1-git-send-email-brian.starkey@arm.com> References: <1476197648-24918-1-git-send-email-brian.starkey@arm.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2016.10.11.144516 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_4000_4999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, IN_REP_TO 0, LEGITIMATE_NEGATE 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, MULTIPLE_REAL_RCPTS 0, NO_URI_HTTPS 0, REFERENCES 0, SINGLE_URI_IN_BODY 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __FROM_DOMAIN_IN_ANY_CC2 0, __FROM_DOMAIN_IN_RCPT 0, __HAS_CC_HDR 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MULTIPLE_RCPTS_CC_X2 0, __REFERENCES 0, __SANE_MSGID 0, __SINGLE_URI_TEXT 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_IN_BODY 0, __URI_NO_WWW 0, __URI_NS , __URI_WITH_PATH 0' In preparation for adding an atomic version of the disable code, extract the actual disable operation into a separate function. Signed-off-by: Brian Starkey --- drivers/gpu/drm/drm_framebuffer.c | 87 +++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index 398efd6..528f75d 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -795,22 +795,61 @@ void drm_framebuffer_cleanup(struct drm_framebuffer *fb) EXPORT_SYMBOL(drm_framebuffer_cleanup); /** - * drm_framebuffer_remove - remove and unreference a framebuffer object + * __drm_framebuffer_remove - remove all usage of a framebuffer object + * @dev: drm device * @fb: framebuffer to remove * * Scans all the CRTCs and planes in @dev's mode_config. If they're - * using @fb, removes it, setting it to NULL. Then drops the reference to the - * passed-in framebuffer. Might take the modeset locks. + * using @fb, removes it, setting it to NULL. Takes the modeset locks. * - * Note that this function optimizes the cleanup away if the caller holds the - * last reference to the framebuffer. It is also guaranteed to not take the - * modeset locks in this case. + * Returns: + * true if the framebuffer was successfully removed from use */ -void drm_framebuffer_remove(struct drm_framebuffer *fb) +static bool __drm_framebuffer_remove(struct drm_device *dev, struct drm_framebuffer *fb) { - struct drm_device *dev; struct drm_crtc *crtc; struct drm_plane *plane; + bool ret = true; + + drm_modeset_lock_all(dev); + /* remove from any CRTC */ + drm_for_each_crtc(crtc, dev) { + if (crtc->primary->fb == fb) { + /* should turn off the crtc */ + if (drm_crtc_force_disable(crtc)) + ret = false; + } + } + + drm_for_each_plane(plane, dev) { + if (plane->fb == fb) + /* TODO: Propagate error here? */ + drm_plane_force_disable(plane); + } + drm_modeset_unlock_all(dev); + + return ret; +} + +/** + * drm_framebuffer_remove - remove and unreference a framebuffer object + * @fb: framebuffer to remove + * + * drm ABI mandates that we remove any deleted framebuffers from active usage. + * This function takes care of this detail, disabling any CRTCs/Planes which + * are using the framebuffer being removed. + * + * Since most sane clients only remove framebuffers they no longer need, we + * skip the disable step if the caller holds the last reference to the + * framebuffer. It is also guaranteed to not take the modeset locks in + * this case. + * + * Before returning this function drops (what should be) the last reference + * on the framebuffer. + */ +void drm_framebuffer_remove(struct drm_framebuffer *fb) +{ + struct drm_device *dev; if (!fb) return; @@ -820,37 +859,19 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb) WARN_ON(!list_empty(&fb->filp_head)); /* - * drm ABI mandates that we remove any deleted framebuffers from active - * useage. But since most sane clients only remove framebuffers they no - * longer need, try to optimize this away. - * * Since we're holding a reference ourselves, observing a refcount of 1 - * means that we're the last holder and can skip it. Also, the refcount - * can never increase from 1 again, so we don't need any barriers or - * locks. + * means that we're the last holder and can skip the disable. Also, the + * refcount can never increase from 1 again, so we don't need any + * barriers or locks. * - * Note that userspace could try to race with use and instate a new + * Note that userspace could try to race with us and instate a new * usage _after_ we've cleared all current ones. End result will be an * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot * in this manner. */ - if (drm_framebuffer_read_refcount(fb) > 1) { - drm_modeset_lock_all(dev); - /* remove from any CRTC */ - drm_for_each_crtc(crtc, dev) { - if (crtc->primary->fb == fb) { - /* should turn off the crtc */ - if (drm_crtc_force_disable(crtc)) - DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc); - } - } - - drm_for_each_plane(plane, dev) { - if (plane->fb == fb) - drm_plane_force_disable(plane); - } - drm_modeset_unlock_all(dev); - } + if (drm_framebuffer_read_refcount(fb) > 1) + if (!__drm_framebuffer_remove(dev, fb)) + DRM_ERROR("failed to remove fb from active usage\n"); drm_framebuffer_unreference(fb); }