From patchwork Fri Jul 13 15:50:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 10523651 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 B2FD06028E for ; Fri, 13 Jul 2018 15:50:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A14F429D48 for ; Fri, 13 Jul 2018 15:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9389529D9C; Fri, 13 Jul 2018 15:50:51 +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=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 2850729D73 for ; Fri, 13 Jul 2018 15:50:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 56D856F2D0; Fri, 13 Jul 2018 15:50:47 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id DF7526F2CC; Fri, 13 Jul 2018 15:50:45 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jul 2018 08:50:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,348,1526367600"; d="scan'208";a="54815012" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by fmsmga008.fm.intel.com with SMTP; 13 Jul 2018 08:50:42 -0700 Received: by stinkbox (sSMTP sendmail emulation); Fri, 13 Jul 2018 18:50:41 +0300 From: Ville Syrjala To: dri-devel@lists.freedesktop.org Date: Fri, 13 Jul 2018 18:50:34 +0300 Message-Id: <20180713155035.3866-3-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180713155035.3866-1-ville.syrjala@linux.intel.com> References: <20180713155035.3866-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 3/4] drm: Extract page_flip_{internal, atomic}() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Ville Syrjälä Yank out the code for the plane->fb/old_fb/crtc handling from the page flip path into page_flip_internal(), and provide a simpler variant for atomic drivers. We'll also move the fb vs. src viewport checks into the new functions as they are slightly different between the two paths. If the atomic .page_flip() implementations are guaranteed to call drm_atomic_plane_check() we could even drop the check entirely from page_flip_atomic(). For now toss in a FIXME. Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/drm_plane.c | 162 ++++++++++++++++++++++++++++---------------- 1 file changed, 105 insertions(+), 57 deletions(-) diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c index d269231d63c5..e3f2ddf7deae 100644 --- a/drivers/gpu/drm/drm_plane.c +++ b/drivers/gpu/drm/drm_plane.c @@ -1003,13 +1003,112 @@ int drm_mode_cursor2_ioctl(struct drm_device *dev, return drm_mode_cursor_common(dev, req, file_priv); } +static int page_flip_check_fbs(const struct drm_framebuffer *fb, + const struct drm_framebuffer *old_fb) +{ + /* The framebuffer is currently unbound, presumably + * due to a hotplug event, that userspace has not + * yet discovered. + */ + if (!old_fb) + return -EBUSY; + + if (old_fb->format != fb->format) { + DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n"); + return -EINVAL; + } + + return 0; +} + +static int page_flip_internal(struct drm_crtc *crtc, + struct drm_framebuffer *fb, + struct drm_pending_vblank_event *e, + u32 flags, + u32 target_vblank, + struct drm_modeset_acquire_ctx *ctx) +{ + struct drm_plane *plane = crtc->primary; + int ret; + + WARN_ON(drm_drv_uses_atomic_modeset(crtc->dev)); + + ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y, + &crtc->mode, fb); + if (ret) + return ret; + + ret = page_flip_check_fbs(fb, plane->fb); + if (ret) + return ret; + + plane->old_fb = plane->fb; + + if (crtc->funcs->page_flip_target) + ret = crtc->funcs->page_flip_target(crtc, fb, e, flags, + target_vblank, ctx); + else + ret = crtc->funcs->page_flip(crtc, fb, e, flags, ctx); + + if (ret) { + /* Keep the old fb, don't unref it. */ + plane->old_fb = NULL; + } else { + plane->fb = fb; + drm_framebuffer_get(plane->fb); + } + + if (plane->old_fb) + drm_framebuffer_put(plane->old_fb); + plane->old_fb = NULL; + + return ret; +} + +static int page_flip_atomic(struct drm_crtc *crtc, + struct drm_framebuffer *fb, + struct drm_pending_vblank_event *e, + u32 flags, + u32 target_vblank, + struct drm_modeset_acquire_ctx *ctx) +{ + struct drm_plane *plane = crtc->primary; + struct drm_plane_state *plane_state = plane->state; + int ret; + + WARN_ON(!drm_drv_uses_atomic_modeset(crtc->dev)); + + /* + * FIXME: Can we assume all drivers end up calling + * drm_atomic_plane_check() in their page flip paths? + * If so we could remove this. + */ + ret = drm_framebuffer_check_src_coords(plane_state->src_x, + plane_state->src_y, + plane_state->src_w, + plane_state->src_h, + fb); + if (ret) + return ret; + + ret = page_flip_check_fbs(fb, plane_state->fb); + if (ret) + return ret; + + if (crtc->funcs->page_flip_target) + return crtc->funcs->page_flip_target(crtc, fb, e, flags, + target_vblank, ctx); + else + return crtc->funcs->page_flip(crtc, fb, e, flags, ctx); +} + int drm_mode_page_flip_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_mode_crtc_page_flip_target *page_flip = data; struct drm_crtc *crtc; struct drm_plane *plane; - struct drm_framebuffer *fb, *old_fb; + struct drm_framebuffer *fb; struct drm_pending_vblank_event *e = NULL; u32 target_vblank = page_flip->sequence; struct drm_modeset_acquire_ctx ctx; @@ -1114,65 +1213,14 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, if (ret) goto out; - if (plane->state) - old_fb = plane->state->fb; - else - old_fb = plane->fb; - - if (old_fb == NULL) { - /* The framebuffer is currently unbound, presumably - * due to a hotplug event, that userspace has not - * yet discovered. - */ - ret = -EBUSY; - goto out; - } - - if (plane->state) { - const struct drm_plane_state *state = plane->state; - - ret = drm_framebuffer_check_src_coords(state->src_x, - state->src_y, - state->src_w, - state->src_h, - fb); - } else { - ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y, - &crtc->mode, fb); - } - if (ret) - goto out; - - if (old_fb->format != fb->format) { - DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n"); - ret = -EINVAL; - goto out; - } - - plane->old_fb = plane->fb; - if (crtc->funcs->page_flip_target) - ret = crtc->funcs->page_flip_target(crtc, fb, e, - page_flip->flags, - target_vblank, - &ctx); + if (drm_drv_uses_atomic_modeset(dev)) + ret = page_flip_atomic(crtc, fb, e, page_flip->flags, + target_vblank, &ctx); else - ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags, - &ctx); - if (ret) { - /* Keep the old fb, don't unref it. */ - plane->old_fb = NULL; - } else { - if (!plane->state) { - plane->fb = fb; - drm_framebuffer_get(fb); - } - } + ret = page_flip_internal(crtc, fb, e, page_flip->flags, + target_vblank, &ctx); out: - if (plane->old_fb) - drm_framebuffer_put(plane->old_fb); - plane->old_fb = NULL; - if (ret == -EDEADLK) { ret = drm_modeset_backoff(&ctx); if (!ret)