From patchwork Fri Sep 9 15:09:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Strode X-Patchwork-Id: 9323753 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 7738B60752 for ; Fri, 9 Sep 2016 15:09:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6843629F4C for ; Fri, 9 Sep 2016 15:09:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CC3429F4F; Fri, 9 Sep 2016 15:09:37 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 71BD029F4C for ; Fri, 9 Sep 2016 15:09:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 79D9D6E8E1; Fri, 9 Sep 2016 15:09:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-x242.google.com (mail-yw0-x242.google.com [IPv6:2607:f8b0:4002:c05::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 300B86E8E1 for ; Fri, 9 Sep 2016 15:09:32 +0000 (UTC) Received: by mail-yw0-x242.google.com with SMTP id g192so3049042ywh.0 for ; Fri, 09 Sep 2016 08:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=q4tAbJc96A10ETroUBvbO0DB3VGhihf3vp2C9K4pgss=; b=qnD6FY3ZjtpHTOPyMvHQDSEPPhq6oE3D6Bukb2SesCQ7SpSwkEpegASdOcue8F61ft rNWypKh8wUOLfC/rsj/i+OmdNzKjSehmTe8EEFjJhHPzTkDeHXgHOn55BSAeOMIij1A/ q9Q8RSbHIJTsGglxoKSLbmchL3yqQ5IkGWHCK5SLD0QnmXsmJvUAqH2ACo/nCAez/DnV k38ZfoKZCIYi8/JpryI3zP7rqAhYrwTcqn7MAJFYzESwlwPYhsR6Kd2ptbPNwX+ve2An ymt9TZtB+3DCllbzoc9lhVuSbxqeQiGgr0nG8/zdcydSbyPuqXxT+kuUhGbyJex1PqII lGYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=q4tAbJc96A10ETroUBvbO0DB3VGhihf3vp2C9K4pgss=; b=I/F3QhotOIJcGzUR5SWovHwFodWxXYM050iDyJEWSe0tnwvmXDAlIej0fomx3ywCCK HBHodQdU4VygvvFpyx8Ary87Fd9+xD45IuCiuguwd24hIPiXVLLIoZk05bpu+rSkTKz4 g1OoetT5y2tlOJUdM9wElzVGrU1jihbSfa4tWj6ezyHi2Socupg0X4CsUAiugTC+Tjd1 0dso1FpXPnclG6+5jrtvwtwZ9xCXuPZdtyHuenr3J5FlWtfwSfheSrfDYxEOpWGaZ4nj ojaya4VgodYqMz4mndEoxBKm33NnCjOx5NZVZW/O0p43vJSSvehmaIU3S3vURyNqi3Cl OkgA== X-Gm-Message-State: AE9vXwNE8nNjV800M0KwEZ722uyrndsofTZXpsYU0SB9mHnIzbRc9jn1E4Xg41+LapKKzQ== X-Received: by 10.129.39.206 with SMTP id n197mr3520129ywn.294.1473433771353; Fri, 09 Sep 2016 08:09:31 -0700 (PDT) Received: from halflap.usersys.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id h15sm1300251ywc.41.2016.09.09.08.09.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Sep 2016 08:09:30 -0700 (PDT) From: Ray Strode To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/qxl: reapply cursor after SetCrtc calls Date: Fri, 9 Sep 2016 11:09:05 -0400 Message-Id: <1473433745-11016-1-git-send-email-halfline@gmail.com> X-Mailer: git-send-email 2.7.4 Cc: Dave Airlie , Ray Strode , Gerd Hoffmann 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 From: Ray Strode The qxl driver currently destroys and recreates the qxl "primary" any time the first crtc is set. A side-effect of destroying the primary is mouse state associated with the crtc is lost, which leads to disappearing mouse cursors on wayland sessions. This commit changes the driver to reapply the cursor any time SetCrtc is called. It achieves this by keeping a reference to the cursor bo on the qxl_crtc struct. Signed-off-by: Ray Strode https://bugzilla.redhat.com/show_bug.cgi?id=1200901 --- drivers/gpu/drm/qxl/qxl_display.c | 56 ++++++++++++++++++++++++++++++++++++++- drivers/gpu/drm/qxl/qxl_drv.h | 1 + 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c index 3aef127..a61c0d4 100644 --- a/drivers/gpu/drm/qxl/qxl_display.c +++ b/drivers/gpu/drm/qxl/qxl_display.c @@ -184,60 +184,61 @@ static struct mode_size { {1440, 900}, {1400, 1050}, {1680, 1050}, {1600, 1200}, {1920, 1080}, {1920, 1200} }; static int qxl_add_common_modes(struct drm_connector *connector, unsigned pwidth, unsigned pheight) { struct drm_device *dev = connector->dev; struct drm_display_mode *mode = NULL; int i; for (i = 0; i < ARRAY_SIZE(common_modes); i++) { mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false); if (common_modes[i].w == pwidth && common_modes[i].h == pheight) mode->type |= DRM_MODE_TYPE_PREFERRED; drm_mode_probed_add(connector, mode); } return i - 1; } static void qxl_crtc_destroy(struct drm_crtc *crtc) { struct qxl_crtc *qxl_crtc = to_qxl_crtc(crtc); drm_crtc_cleanup(crtc); + qxl_bo_unref(&qxl_crtc->cursor_bo); kfree(qxl_crtc); } static int qxl_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, uint32_t page_flip_flags) { struct drm_device *dev = crtc->dev; struct qxl_device *qdev = dev->dev_private; struct qxl_framebuffer *qfb_src = to_qxl_framebuffer(fb); struct qxl_framebuffer *qfb_old = to_qxl_framebuffer(crtc->primary->fb); struct qxl_bo *bo_old = gem_to_qxl_bo(qfb_old->obj); struct qxl_bo *bo = gem_to_qxl_bo(qfb_src->obj); unsigned long flags; struct drm_clip_rect norect = { .x1 = 0, .y1 = 0, .x2 = fb->width, .y2 = fb->height }; int inc = 1; int one_clip_rect = 1; int ret = 0; crtc->primary->fb = fb; bo_old->is_primary = false; bo->is_primary = true; ret = qxl_bo_reserve(bo, false); @@ -269,60 +270,106 @@ static int qxl_crtc_page_flip(struct drm_crtc *crtc, return 0; } static int qxl_hide_cursor(struct qxl_device *qdev) { struct qxl_release *release; struct qxl_cursor_cmd *cmd; int ret; ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd), QXL_RELEASE_CURSOR_CMD, &release, NULL); if (ret) return ret; ret = qxl_release_reserve_list(release, true); if (ret) { qxl_release_free(qdev, release); return ret; } cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release); cmd->type = QXL_CURSOR_HIDE; qxl_release_unmap(qdev, release, &cmd->release_info); qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); qxl_release_fence_buffer_objects(release); return 0; } +static int qxl_crtc_apply_cursor(struct drm_crtc *crtc) +{ + struct qxl_crtc *qcrtc = to_qxl_crtc(crtc); + struct drm_device *dev = crtc->dev; + struct qxl_device *qdev = dev->dev_private; + struct qxl_cursor_cmd *cmd; + struct qxl_release *release; + int ret = 0; + + if (!qcrtc->cursor_bo) + return 0; + + ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd), + QXL_RELEASE_CURSOR_CMD, + &release, NULL); + if (ret) + return ret; + + ret = qxl_release_list_add(release, qcrtc->cursor_bo); + if (ret) + goto out_free_release; + + ret = qxl_release_reserve_list(release, false); + if (ret) + goto out_free_release; + + cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release); + cmd->type = QXL_CURSOR_SET; + cmd->u.set.position.x = qcrtc->cur_x + qcrtc->hot_spot_x; + cmd->u.set.position.y = qcrtc->cur_y + qcrtc->hot_spot_y; + + cmd->u.set.shape = qxl_bo_physical_address(qdev, qcrtc->cursor_bo, 0); + + cmd->u.set.visible = 1; + qxl_release_unmap(qdev, release, &cmd->release_info); + + qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); + qxl_release_fence_buffer_objects(release); + + return ret; + +out_free_release: + qxl_release_free(qdev, release); + return ret; +} + static int qxl_crtc_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv, uint32_t handle, uint32_t width, uint32_t height, int32_t hot_x, int32_t hot_y) { struct drm_device *dev = crtc->dev; struct qxl_device *qdev = dev->dev_private; struct qxl_crtc *qcrtc = to_qxl_crtc(crtc); struct drm_gem_object *obj; struct qxl_cursor *cursor; struct qxl_cursor_cmd *cmd; struct qxl_bo *cursor_bo, *user_bo; struct qxl_release *release; void *user_ptr; int size = 64*64*4; int ret = 0; if (!handle) return qxl_hide_cursor(qdev); obj = drm_gem_object_lookup(file_priv, handle); if (!obj) { DRM_ERROR("cannot find cursor object\n"); return -ENOENT; } user_bo = gem_to_qxl_bo(obj); ret = qxl_bo_reserve(user_bo, false); @@ -373,61 +420,62 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc, qxl_bo_kunmap(cursor_bo); qxl_bo_kunmap(user_bo); qcrtc->cur_x += qcrtc->hot_spot_x - hot_x; qcrtc->cur_y += qcrtc->hot_spot_y - hot_y; qcrtc->hot_spot_x = hot_x; qcrtc->hot_spot_y = hot_y; cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release); cmd->type = QXL_CURSOR_SET; cmd->u.set.position.x = qcrtc->cur_x + qcrtc->hot_spot_x; cmd->u.set.position.y = qcrtc->cur_y + qcrtc->hot_spot_y; cmd->u.set.shape = qxl_bo_physical_address(qdev, cursor_bo, 0); cmd->u.set.visible = 1; qxl_release_unmap(qdev, release, &cmd->release_info); qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); qxl_release_fence_buffer_objects(release); /* finish with the userspace bo */ ret = qxl_bo_reserve(user_bo, false); if (!ret) { qxl_bo_unpin(user_bo); qxl_bo_unreserve(user_bo); } drm_gem_object_unreference_unlocked(obj); - qxl_bo_unref(&cursor_bo); + qxl_bo_unref (&qcrtc->cursor_bo); + qcrtc->cursor_bo = cursor_bo; return ret; out_backoff: qxl_release_backoff_reserve_list(release); out_free_bo: qxl_bo_unref(&cursor_bo); out_free_release: qxl_release_free(qdev, release); out_kunmap: qxl_bo_kunmap(user_bo); out_unpin: qxl_bo_unpin(user_bo); out_unref: drm_gem_object_unreference_unlocked(obj); return ret; } static int qxl_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) { struct drm_device *dev = crtc->dev; struct qxl_device *qdev = dev->dev_private; struct qxl_crtc *qcrtc = to_qxl_crtc(crtc); struct qxl_release *release; struct qxl_cursor_cmd *cmd; int ret; ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd), QXL_RELEASE_CURSOR_CMD, &release, NULL); @@ -628,60 +676,66 @@ static int qxl_crtc_mode_set(struct drm_crtc *crtc, x, y, mode->hdisplay, mode->vdisplay, adjusted_mode->hdisplay, adjusted_mode->vdisplay); if (bo->is_primary == false) recreate_primary = true; if (bo->surf.stride * bo->surf.height > qdev->vram_size) { DRM_ERROR("Mode doesn't fit in vram size (vgamem)"); return -EINVAL; } ret = qxl_bo_reserve(bo, false); if (ret != 0) return ret; ret = qxl_bo_pin(bo, bo->type, NULL); if (ret != 0) { qxl_bo_unreserve(bo); return -EINVAL; } qxl_bo_unreserve(bo); if (recreate_primary) { qxl_io_destroy_primary(qdev); qxl_io_log(qdev, "recreate primary: %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; + + ret = qxl_crtc_apply_cursor(crtc); + if (ret) { + DRM_ERROR("could not set cursor after modeset"); + ret = 0; + } } if (bo->is_primary) { DRM_DEBUG_KMS("setting surface_id to 0 for primary surface %d on crtc %d\n", bo->surface_id, qcrtc->index); surf_id = 0; } else { surf_id = bo->surface_id; } if (old_bo && old_bo != bo) { old_bo->is_primary = false; ret = qxl_bo_reserve(old_bo, false); qxl_bo_unpin(old_bo); qxl_bo_unreserve(old_bo); } qxl_monitors_config_set(qdev, qcrtc->index, x, y, mode->hdisplay, mode->vdisplay, surf_id); return 0; } static void qxl_crtc_prepare(struct drm_crtc *crtc) { DRM_DEBUG("current: %dx%d+%d+%d (%d).\n", crtc->mode.hdisplay, crtc->mode.vdisplay, crtc->x, crtc->y, crtc->enabled); } static void qxl_crtc_commit(struct drm_crtc *crtc) diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h index 8e633ca..5f3e5ad 100644 --- a/drivers/gpu/drm/qxl/qxl_drv.h +++ b/drivers/gpu/drm/qxl/qxl_drv.h @@ -110,60 +110,61 @@ struct qxl_bo { void *kptr; int type; /* Constant after initialization */ struct drm_gem_object gem_base; bool is_primary; /* is this now a primary surface */ bool hw_surf_alloc; struct qxl_surface surf; uint32_t surface_id; struct qxl_release *surf_create; }; #define gem_to_qxl_bo(gobj) container_of((gobj), struct qxl_bo, gem_base) #define to_qxl_bo(tobj) container_of((tobj), struct qxl_bo, tbo) struct qxl_gem { struct mutex mutex; struct list_head objects; }; struct qxl_bo_list { struct ttm_validate_buffer tv; }; struct qxl_crtc { struct drm_crtc base; int index; int cur_x; int cur_y; int hot_spot_x; int hot_spot_y; + struct qxl_bo *cursor_bo; }; struct qxl_output { int index; struct drm_connector base; struct drm_encoder enc; }; struct qxl_framebuffer { struct drm_framebuffer base; struct drm_gem_object *obj; }; #define to_qxl_crtc(x) container_of(x, struct qxl_crtc, base) #define drm_connector_to_qxl_output(x) container_of(x, struct qxl_output, base) #define drm_encoder_to_qxl_output(x) container_of(x, struct qxl_output, enc) #define to_qxl_framebuffer(x) container_of(x, struct qxl_framebuffer, base) struct qxl_mman { struct ttm_bo_global_ref bo_global_ref; struct drm_global_reference mem_global_ref; bool mem_global_referenced; struct ttm_bo_device bdev; }; struct qxl_mode_info { int num_modes; struct qxl_mode *modes; bool mode_config_initialized;