From patchwork Tue Sep 25 16:16:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10614389 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 3826E13A4 for ; Tue, 25 Sep 2018 16:16:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2758B2978C for ; Tue, 25 Sep 2018 16:16:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BEA6298A7; Tue, 25 Sep 2018 16:16:24 +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 CFB312978C for ; Tue, 25 Sep 2018 16:16:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 69FCF6E3B4; Tue, 25 Sep 2018 16:16:17 +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 [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id CFBEB6E3B4 for ; Tue, 25 Sep 2018 16:16:15 +0000 (UTC) Received: from ezexps.par1.mozilla.com (unknown [IPv6:2a00:8c40:243:232:20d1:1683:13e1:7cd]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ezequiel) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 7CCDC27DB3E; Tue, 25 Sep 2018 17:16:14 +0100 (BST) From: Ezequiel Garcia To: dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Subject: [PATCH 1/3] virtio: Add virtio_gpu_object_kunmap() Date: Tue, 25 Sep 2018 18:16:04 +0200 Message-Id: <20180925161606.17980-2-ezequiel@collabora.com> X-Mailer: git-send-email 2.19.0.rc2 In-Reply-To: <20180925161606.17980-1-ezequiel@collabora.com> References: <20180925161606.17980-1-ezequiel@collabora.com> MIME-Version: 1.0 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: David Airlie , Ezequiel Garcia , Gerd Hoffmann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Implement a virtio_gpu_object_kunmap() to unmap the kernel mapping, and use it in the TTM object destroy path. Signed-off-by: Ezequiel Garcia --- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + drivers/gpu/drm/virtio/virtgpu_object.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 2de29c90bed2..a8af46570a01 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -356,6 +356,7 @@ void virtio_gpu_fence_event_process(struct virtio_gpu_device *vdev, int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, unsigned long size, bool kernel, bool pinned, struct virtio_gpu_object **bo_ptr); +void virtio_gpu_object_kunmap(struct virtio_gpu_object *bo); int virtio_gpu_object_kmap(struct virtio_gpu_object *bo, void **ptr); int virtio_gpu_object_get_sg_table(struct virtio_gpu_device *qdev, struct virtio_gpu_object *bo); diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c index 9f2f470efd9b..113eae00d293 100644 --- a/drivers/gpu/drm/virtio/virtgpu_object.c +++ b/drivers/gpu/drm/virtio/virtgpu_object.c @@ -37,6 +37,8 @@ static void virtio_gpu_ttm_bo_destroy(struct ttm_buffer_object *tbo) virtio_gpu_cmd_unref_resource(vgdev, bo->hw_res_handle); if (bo->pages) virtio_gpu_object_free_sg_table(bo); + if (bo->vmap) + virtio_gpu_object_kunmap(bo); drm_gem_object_release(&bo->gem_base); kfree(bo); } @@ -99,6 +101,12 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, return 0; } +void virtio_gpu_object_kunmap(struct virtio_gpu_object *bo) +{ + bo->vmap = NULL; + ttm_bo_kunmap(&bo->kmap); +} + int virtio_gpu_object_kmap(struct virtio_gpu_object *bo, void **ptr) { bool is_iomem; From patchwork Tue Sep 25 16:16:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10614387 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 7A90C13A4 for ; Tue, 25 Sep 2018 16:16:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A07D2971D for ; Tue, 25 Sep 2018 16:16:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B9BC297C1; Tue, 25 Sep 2018 16:16:22 +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 0DD892971D for ; Tue, 25 Sep 2018 16:16:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 75D7D6E3B6; Tue, 25 Sep 2018 16:16:17 +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 [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id E705D6E3B6 for ; Tue, 25 Sep 2018 16:16:15 +0000 (UTC) Received: from ezexps.par1.mozilla.com (unknown [IPv6:2a00:8c40:243:232:20d1:1683:13e1:7cd]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ezequiel) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id B336727DB43; Tue, 25 Sep 2018 17:16:14 +0100 (BST) From: Ezequiel Garcia To: dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Subject: [PATCH 2/3] virtio: Rework virtio_gpu_object_kmap() Date: Tue, 25 Sep 2018 18:16:05 +0200 Message-Id: <20180925161606.17980-3-ezequiel@collabora.com> X-Mailer: git-send-email 2.19.0.rc2 In-Reply-To: <20180925161606.17980-1-ezequiel@collabora.com> References: <20180925161606.17980-1-ezequiel@collabora.com> MIME-Version: 1.0 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: David Airlie , Ezequiel Garcia , Gerd Hoffmann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently, virtio_gpu_object_kmap() is only called by virtio_gpufb_create(), when a DRM framebuffer is created. Thus, instead of returning the vmap'ed address, emit a warning if virtio_gpu_object_kmap is called on an already mapped object. With this change, kmap/kunmap calls are now balanced. Signed-off-by: Ezequiel Garcia --- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 +- drivers/gpu/drm/virtio/virtgpu_fb.c | 10 ++-------- drivers/gpu/drm/virtio/virtgpu_object.c | 11 +++-------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index a8af46570a01..97f366f5d2ea 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -357,7 +357,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, unsigned long size, bool kernel, bool pinned, struct virtio_gpu_object **bo_ptr); void virtio_gpu_object_kunmap(struct virtio_gpu_object *bo); -int virtio_gpu_object_kmap(struct virtio_gpu_object *bo, void **ptr); +int virtio_gpu_object_kmap(struct virtio_gpu_object *bo); int virtio_gpu_object_get_sg_table(struct virtio_gpu_device *qdev, struct virtio_gpu_object *bo); void virtio_gpu_object_free_sg_table(struct virtio_gpu_object *bo); diff --git a/drivers/gpu/drm/virtio/virtgpu_fb.c b/drivers/gpu/drm/virtio/virtgpu_fb.c index b5cebc9a179a..08ab43b91509 100644 --- a/drivers/gpu/drm/virtio/virtgpu_fb.c +++ b/drivers/gpu/drm/virtio/virtgpu_fb.c @@ -210,12 +210,6 @@ static struct fb_ops virtio_gpufb_ops = { .fb_imageblit = virtio_gpu_3d_imageblit, }; -static int virtio_gpu_vmap_fb(struct virtio_gpu_device *vgdev, - struct virtio_gpu_object *obj) -{ - return virtio_gpu_object_kmap(obj, NULL); -} - static int virtio_gpufb_create(struct drm_fb_helper *helper, struct drm_fb_helper_surface_size *sizes) { @@ -248,9 +242,9 @@ static int virtio_gpufb_create(struct drm_fb_helper *helper, virtio_gpu_cmd_create_resource(vgdev, resid, format, mode_cmd.width, mode_cmd.height); - ret = virtio_gpu_vmap_fb(vgdev, obj); + ret = virtio_gpu_object_kmap(obj); if (ret) { - DRM_ERROR("failed to vmap fb %d\n", ret); + DRM_ERROR("failed to kmap fb %d\n", ret); goto err_obj_vmap; } diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c index 113eae00d293..eca765537470 100644 --- a/drivers/gpu/drm/virtio/virtgpu_object.c +++ b/drivers/gpu/drm/virtio/virtgpu_object.c @@ -107,22 +107,17 @@ void virtio_gpu_object_kunmap(struct virtio_gpu_object *bo) ttm_bo_kunmap(&bo->kmap); } -int virtio_gpu_object_kmap(struct virtio_gpu_object *bo, void **ptr) +int virtio_gpu_object_kmap(struct virtio_gpu_object *bo) { bool is_iomem; int r; - if (bo->vmap) { - if (ptr) - *ptr = bo->vmap; - return 0; - } + WARN_ON(bo->vmap); + r = ttm_bo_kmap(&bo->tbo, 0, bo->tbo.num_pages, &bo->kmap); if (r) return r; bo->vmap = ttm_kmap_obj_virtual(&bo->kmap, &is_iomem); - if (ptr) - *ptr = bo->vmap; return 0; } From patchwork Tue Sep 25 16:16:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10614391 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 C0637112B for ; Tue, 25 Sep 2018 16:16:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0D862971D for ; Tue, 25 Sep 2018 16:16:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3D8D297C1; Tue, 25 Sep 2018 16:16:30 +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 B40842971D for ; Tue, 25 Sep 2018 16:16:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8BC46E3BA; Tue, 25 Sep 2018 16:16:28 +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 [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0F28D6E0B3 for ; Tue, 25 Sep 2018 16:16:16 +0000 (UTC) Received: from ezexps.par1.mozilla.com (unknown [IPv6:2a00:8c40:243:232:20d1:1683:13e1:7cd]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ezequiel) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id D51AE27DB46; Tue, 25 Sep 2018 17:16:14 +0100 (BST) From: Ezequiel Garcia To: dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Subject: [PATCH 3/3] virtio: Support prime objects vmap/vunmap Date: Tue, 25 Sep 2018 18:16:06 +0200 Message-Id: <20180925161606.17980-4-ezequiel@collabora.com> X-Mailer: git-send-email 2.19.0.rc2 In-Reply-To: <20180925161606.17980-1-ezequiel@collabora.com> References: <20180925161606.17980-1-ezequiel@collabora.com> MIME-Version: 1.0 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: David Airlie , Ezequiel Garcia , Gerd Hoffmann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Implement vmap/vunmap so we can export dmabufs to other drivers, such as video4linux. Tested with a virtio-gpu / vivid (virtual capture driver) pipeline, where the vivid driver imports the dmabufs exported by virtio-gpu. Note that dma_buf_vmap() does its own vmap counting, so it's not needed to take care of it in the driver. Signed-off-by: Ezequiel Garcia --- drivers/gpu/drm/virtio/virtgpu_prime.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c index d27a1688714f..86ce0ae93f59 100644 --- a/drivers/gpu/drm/virtio/virtgpu_prime.c +++ b/drivers/gpu/drm/virtio/virtgpu_prime.c @@ -55,13 +55,18 @@ struct drm_gem_object *virtgpu_gem_prime_import_sg_table( void *virtgpu_gem_prime_vmap(struct drm_gem_object *obj) { - WARN_ONCE(1, "not implemented"); - return ERR_PTR(-ENODEV); + struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj); + int ret; + + ret = virtio_gpu_object_kmap(bo); + if (ret) + return NULL; + return bo->vmap; } void virtgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) { - WARN_ONCE(1, "not implemented"); + virtio_gpu_object_kunmap(gem_to_virtio_gpu_obj(obj)); } int virtgpu_gem_prime_mmap(struct drm_gem_object *obj,