From patchwork Wed Feb 15 21:39:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 9575107 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 140A96045F for ; Wed, 15 Feb 2017 21:41:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 081DF28544 for ; Wed, 15 Feb 2017 21:41:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFC4A28560; Wed, 15 Feb 2017 21:41:01 +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, UNPARSEABLE_RELAY 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 9EA3C2851B for ; Wed, 15 Feb 2017 21:41:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 10D4B6E9EA; Wed, 15 Feb 2017 21:41:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id AF8B16E9EA for ; Wed, 15 Feb 2017 21:40:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 2D7DF26128C From: Gabriel Krisman Bertazi To: dri-devel@lists.freedesktop.org Subject: [PATCH 06/14] drm: qxl: Atomic phase 1: Use drm_plane_helpers for primary plane Date: Wed, 15 Feb 2017 19:39:59 -0200 Message-Id: <20170215214007.10004-7-krisman@collabora.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170215214007.10004-1-krisman@collabora.co.uk> References: <20170215214007.10004-1-krisman@collabora.co.uk> Cc: Gabriel Krisman Bertazi 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Gabriel Krisman Bertazi --- drivers/gpu/drm/qxl/qxl_display.c | 101 +++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c index fef464730c9b..8ccf62ae0efd 100644 --- a/drivers/gpu/drm/qxl/qxl_display.c +++ b/drivers/gpu/drm/qxl/qxl_display.c @@ -252,6 +252,23 @@ static int qxl_add_common_modes(struct drm_connector *connector, return i - 1; } +static void qxl_crtc_atomic_flush(struct drm_crtc *crtc, + struct drm_crtc_state *old_crtc_state) +{ + struct drm_device *dev = crtc->dev; + 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(&dev->event_lock, flags); + drm_crtc_send_vblank_event(crtc, event); + spin_unlock_irqrestore(&dev->event_lock, flags); + } +} + static void qxl_crtc_destroy(struct drm_crtc *crtc) { struct qxl_crtc *qxl_crtc = to_qxl_crtc(crtc); @@ -553,8 +570,81 @@ static const struct drm_crtc_helper_funcs qxl_crtc_helper_funcs = { .mode_set = qxl_crtc_mode_set, .prepare = qxl_crtc_prepare, .commit = qxl_crtc_commit, + .atomic_flush = qxl_crtc_atomic_flush, }; +int qxl_primary_atomic_check(struct drm_plane *plane, + struct drm_plane_state *state) +{ + struct qxl_device *qdev = plane->dev->dev_private; + struct qxl_framebuffer *qfb; + struct qxl_bo *bo; + + if (!state->crtc || !state->fb) + return 0; + + qfb = to_qxl_framebuffer(state->fb); + bo = gem_to_qxl_bo(qfb->obj); + + if (bo->surf.stride * bo->surf.height > qdev->vram_size) { + DRM_ERROR("Mode doesn't fit in vram size (vgamem)"); + return -EINVAL; + } + + return 0; +} + +static void qxl_primary_atomic_update(struct drm_plane *plane, + struct drm_plane_state *old_state) +{ + struct qxl_device *qdev = plane->dev->dev_private; + struct qxl_framebuffer *qfb = + to_qxl_framebuffer(plane->state->fb); + struct qxl_framebuffer *qfb_old; + struct qxl_bo *bo = gem_to_qxl_bo(qfb->obj); + struct qxl_bo *bo_old; + struct drm_clip_rect norect = { + .x1 = 0, + .y1 = 0, + .x2 = qfb->base.width, + .y2 = qfb->base.height + }; + + if (!old_state->fb) { + qxl_io_log(qdev, + "create primary fb: %dx%d,%d,%d\n", + bo->surf.width, bo->surf.height, + bo->surf.stride, bo->surf.format); + + qxl_io_create_primary(qdev, 0, bo); + bo->is_primary = true; + return; + + } else { + qfb_old = to_qxl_framebuffer(old_state->fb); + bo_old = gem_to_qxl_bo(qfb_old->obj); + bo_old->is_primary = false; + } + + bo->is_primary = true; + qxl_draw_dirty_fb(qdev, qfb, bo, 0, 0, &norect, 1, 1); +} + +static void qxl_primary_atomic_disable(struct drm_plane *plane, + struct drm_plane_state *old_state) +{ + struct qxl_device *qdev = plane->dev->dev_private; + + if (old_state->fb) + { struct qxl_framebuffer *qfb = + to_qxl_framebuffer(old_state->fb); + struct qxl_bo *bo = gem_to_qxl_bo(qfb->obj); + + qxl_io_destroy_primary(qdev); + bo->is_primary = false; + } +} + int qxl_plane_atomic_check(struct drm_plane *plane, struct drm_plane_state *state) { @@ -742,8 +832,16 @@ static const uint32_t qxl_primary_plane_formats[] = { DRM_FORMAT_ARGB8888, }; +static const struct drm_plane_helper_funcs primary_helper_funcs = { + .atomic_check = qxl_primary_atomic_check, + .atomic_update = qxl_primary_atomic_update, + .atomic_disable = qxl_primary_atomic_disable, + .prepare_fb = qxl_plane_prepare_fb, + .cleanup_fb = qxl_plane_cleanup_fb, +}; + static const struct drm_plane_funcs qxl_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, }; @@ -763,6 +861,7 @@ static struct drm_plane *qxl_create_plane(struct qxl_device *qdev, funcs = &qxl_primary_plane_funcs; formats = qxl_primary_plane_formats; num_formats = ARRAY_SIZE(qxl_primary_plane_formats); + helper_funcs = &primary_helper_funcs; } else if (type == DRM_PLANE_TYPE_CURSOR) { funcs = &qxl_cursor_plane_funcs; formats = qxl_cursor_plane_formats;