From patchwork Wed Sep 26 19:41:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 10616695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60E8A13A4 for ; Wed, 26 Sep 2018 19:42:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 501832B6A6 for ; Wed, 26 Sep 2018 19:42:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 442B82B6BA; Wed, 26 Sep 2018 19:42:31 +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 D4E072B6A6 for ; Wed, 26 Sep 2018 19:42:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9864889CC1; Wed, 26 Sep 2018 19:42:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6769289BC0 for ; Wed, 26 Sep 2018 19:42:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0321B30001E3; Wed, 26 Sep 2018 19:42:18 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-104.ams2.redhat.com [10.36.116.104]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE93210021B2; Wed, 26 Sep 2018 19:42:16 +0000 (UTC) From: Hans de Goede To: Greg Kroah-Hartman Subject: [PATCH 06/15] staging: vboxvideo: Atomic phase 1: Use drm_plane_helpers for primary plane Date: Wed, 26 Sep 2018 21:41:57 +0200 Message-Id: <20180926194206.23517-7-hdegoede@redhat.com> In-Reply-To: <20180926194206.23517-1-hdegoede@redhat.com> References: <20180926194206.23517-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 26 Sep 2018 19:42:18 +0000 (UTC) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, Hans de Goede , Michael Thayer , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use drm_plane_helpers for the primary plane and replace our custom mode_set callback with drm_helper_crtc_mode_set. Signed-off-by: Hans de Goede --- drivers/staging/vboxvideo/vbox_mode.c | 116 ++++++++++++++++++++------ 1 file changed, 90 insertions(+), 26 deletions(-) diff --git a/drivers/staging/vboxvideo/vbox_mode.c b/drivers/staging/vboxvideo/vbox_mode.c index 75e112d33cf0..e560e36e7953 100644 --- a/drivers/staging/vboxvideo/vbox_mode.c +++ b/drivers/staging/vboxvideo/vbox_mode.c @@ -257,50 +257,48 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc, mutex_unlock(&vbox->hw_mutex); } -static int vbox_crtc_mode_set(struct drm_crtc *crtc, - struct drm_display_mode *mode, - struct drm_display_mode *adjusted_mode, - int x, int y, struct drm_framebuffer *old_fb) +static void vbox_crtc_disable(struct drm_crtc *crtc) { - struct drm_framebuffer *new_fb = CRTC_FB(crtc); - struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(new_fb)->obj); - int ret; - - ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM); - if (ret) { - DRM_WARN("Error %d pinning new fb, out of video mem?\n", ret); - return ret; - } - - vbox_crtc_set_base_and_mode(crtc, new_fb, mode, x, y); - - if (old_fb) { - bo = gem_to_vbox_bo(to_vbox_framebuffer(old_fb)->obj); - vbox_bo_unpin(bo); - } +} - return 0; +static void vbox_crtc_prepare(struct drm_crtc *crtc) +{ } -static void vbox_crtc_disable(struct drm_crtc *crtc) +static void vbox_crtc_commit(struct drm_crtc *crtc) { } -static void vbox_crtc_prepare(struct drm_crtc *crtc) +static void vbox_crtc_mode_set_nofb(struct drm_crtc *crtc) { + /* We always set the mode when we set the fb/base */ } -static void vbox_crtc_commit(struct drm_crtc *crtc) +static void vbox_crtc_atomic_flush(struct drm_crtc *crtc, + struct drm_crtc_state *old_crtc_state) { + struct drm_pending_vblank_event *event; + unsigned long flags; + + if (crtc->state && crtc->state->event) { + event = crtc->state->event; + crtc->state->event = NULL; + + spin_lock_irqsave(&crtc->dev->event_lock, flags); + drm_crtc_send_vblank_event(crtc, event); + spin_unlock_irqrestore(&crtc->dev->event_lock, flags); + } } static const struct drm_crtc_helper_funcs vbox_crtc_helper_funcs = { .dpms = vbox_crtc_dpms, .mode_fixup = vbox_crtc_mode_fixup, - .mode_set = vbox_crtc_mode_set, + .mode_set = drm_helper_crtc_mode_set, + .mode_set_nofb = vbox_crtc_mode_set_nofb, .disable = vbox_crtc_disable, .prepare = vbox_crtc_prepare, .commit = vbox_crtc_commit, + .atomic_flush = vbox_crtc_atomic_flush, }; static void vbox_crtc_reset(struct drm_crtc *crtc) @@ -320,6 +318,63 @@ static const struct drm_crtc_funcs vbox_crtc_funcs = { .destroy = vbox_crtc_destroy, }; +static int vbox_primary_atomic_check(struct drm_plane *plane, + struct drm_plane_state *new_state) +{ + return 0; +} + +static void vbox_primary_atomic_update(struct drm_plane *plane, + struct drm_plane_state *old_state) +{ + struct drm_crtc *crtc = plane->state->crtc; + struct drm_framebuffer *fb = plane->state->fb; + + vbox_crtc_set_base_and_mode(crtc, fb, &crtc->state->mode, + plane->state->src_x >> 16, + plane->state->src_y >> 16); +} + +void vbox_primary_atomic_disable(struct drm_plane *plane, + struct drm_plane_state *old_state) +{ + struct drm_crtc *crtc = old_state->crtc; + + /* vbox_do_modeset checks plane->state->fb and will disable if NULL */ + vbox_crtc_set_base_and_mode(crtc, old_state->fb, &crtc->state->mode, + old_state->src_x >> 16, + old_state->src_y >> 16); +} + +static int vbox_primary_prepare_fb(struct drm_plane *plane, + struct drm_plane_state *new_state) +{ + struct vbox_bo *bo; + int ret; + + if (!new_state->fb) + return 0; + + bo = gem_to_vbox_bo(to_vbox_framebuffer(new_state->fb)->obj); + ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM); + if (ret) + DRM_WARN("Error %d pinning new fb, out of video mem?\n", ret); + + return ret; +} + +static void vbox_primary_cleanup_fb(struct drm_plane *plane, + struct drm_plane_state *old_state) +{ + struct vbox_bo *bo; + + if (!old_state->fb) + return; + + bo = gem_to_vbox_bo(to_vbox_framebuffer(old_state->fb)->obj); + vbox_bo_unpin(bo); +} + static int vbox_cursor_atomic_check(struct drm_plane *plane, struct drm_plane_state *new_state) { @@ -479,8 +534,16 @@ static const uint32_t vbox_primary_plane_formats[] = { DRM_FORMAT_ARGB8888, }; +static const struct drm_plane_helper_funcs vbox_primary_helper_funcs = { + .atomic_check = vbox_primary_atomic_check, + .atomic_update = vbox_primary_atomic_update, + .atomic_disable = vbox_primary_atomic_disable, + .prepare_fb = vbox_primary_prepare_fb, + .cleanup_fb = vbox_primary_cleanup_fb, +}; + static const struct drm_plane_funcs vbox_primary_plane_funcs = { - .update_plane = drm_primary_helper_update, + .update_plane = drm_plane_helper_update, .disable_plane = drm_primary_helper_disable, .destroy = drm_primary_helper_destroy, }; @@ -499,6 +562,7 @@ static struct drm_plane *vbox_create_plane(struct vbox_private *vbox, if (type == DRM_PLANE_TYPE_PRIMARY) { funcs = &vbox_primary_plane_funcs; formats = vbox_primary_plane_formats; + helper_funcs = &vbox_primary_helper_funcs; num_formats = ARRAY_SIZE(vbox_primary_plane_formats); } else if (type == DRM_PLANE_TYPE_CURSOR) { funcs = &vbox_cursor_plane_funcs;