From patchwork Tue Jun 9 09:08:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 11594945 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97A1690 for ; Tue, 9 Jun 2020 09:08:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7F2E8207C3 for ; Tue, 9 Jun 2020 09:08:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F2E8207C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 21480898C0; Tue, 9 Jun 2020 09:08:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id E8F0A89824 for ; Tue, 9 Jun 2020 09:08:26 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CD49EAE9D; Tue, 9 Jun 2020 09:08:28 +0000 (UTC) From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@linux.ie, daniel@ffwll.ch, sean@poorly.run, kraxel@redhat.com, emil.l.velikov@gmail.com, sam@ravnborg.org, noralf@tronnes.org Subject: [PATCH v3 2/2] drm/udl: Use GEM vmap/mmap function from SHMEM helpers Date: Tue, 9 Jun 2020 11:08:20 +0200 Message-Id: <20200609090820.20256-3-tzimmermann@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200609090820.20256-1-tzimmermann@suse.de> References: <20200609090820.20256-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The udl driver contains an implementation of GEM vmap and mmap operations that is identical to the common SHMEM helper; except that udl's code uses cached pages by default. Convert udl to regular SHMEM helper functions. There's no reason to have udl behave differently from all other SHMEM drivers. The udl driver uses the SHMEM helper to enable caching. v3: * rebased onto Daniel's shmem untangle series v2: * implement .gem_create_object with SHMEM helper Signed-off-by: Thomas Zimmermann Reviewed-by: Emil Velikov --- drivers/gpu/drm/udl/Makefile | 2 +- drivers/gpu/drm/udl/udl_drv.c | 4 +- drivers/gpu/drm/udl/udl_drv.h | 3 - drivers/gpu/drm/udl/udl_gem.c | 108 ---------------------------------- 4 files changed, 3 insertions(+), 114 deletions(-) delete mode 100644 drivers/gpu/drm/udl/udl_gem.c diff --git a/drivers/gpu/drm/udl/Makefile b/drivers/gpu/drm/udl/Makefile index b50179bb4de06..24d61f61d7db2 100644 --- a/drivers/gpu/drm/udl/Makefile +++ b/drivers/gpu/drm/udl/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -udl-y := udl_drv.o udl_modeset.o udl_connector.o udl_main.o udl_transfer.o udl_gem.o +udl-y := udl_drv.o udl_modeset.o udl_connector.o udl_main.o udl_transfer.o obj-$(CONFIG_DRM_UDL) := udl.o diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c index d1aa50fd6d65a..96d4317a2c1bd 100644 --- a/drivers/gpu/drm/udl/udl_drv.c +++ b/drivers/gpu/drm/udl/udl_drv.c @@ -37,8 +37,8 @@ DEFINE_DRM_GEM_FOPS(udl_driver_fops); static struct drm_driver driver = { .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET, - /* gem hooks */ - .gem_create_object = udl_driver_gem_create_object, + /* GEM hooks */ + .gem_create_object = drm_gem_shmem_create_object_cached, .fops = &udl_driver_fops, DRM_GEM_SHMEM_DRIVER_OPS, diff --git a/drivers/gpu/drm/udl/udl_drv.h b/drivers/gpu/drm/udl/udl_drv.h index 2642f94a63fc8..b1461f30780bc 100644 --- a/drivers/gpu/drm/udl/udl_drv.h +++ b/drivers/gpu/drm/udl/udl_drv.h @@ -81,9 +81,6 @@ int udl_render_hline(struct drm_device *dev, int log_bpp, struct urb **urb_ptr, const char *front, char **urb_buf_ptr, u32 byte_offset, u32 device_byte_offset, u32 byte_width); -struct drm_gem_object *udl_driver_gem_create_object(struct drm_device *dev, - size_t size); - int udl_drop_usb(struct drm_device *dev); #define CMD_WRITE_RAW8 "\xAF\x60" /**< 8 bit raw write command. */ diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c deleted file mode 100644 index c68d3e265329b..0000000000000 --- a/drivers/gpu/drm/udl/udl_gem.c +++ /dev/null @@ -1,108 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2012 Red Hat - */ - -#include -#include - -#include -#include -#include -#include - -#include "udl_drv.h" - -/* - * GEM object funcs - */ - -static int udl_gem_object_mmap(struct drm_gem_object *obj, - struct vm_area_struct *vma) -{ - int ret; - - ret = drm_gem_shmem_mmap(obj, vma); - if (ret) - return ret; - - vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); - if (obj->import_attach) - vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); - vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); - - return 0; -} - -static void *udl_gem_object_vmap(struct drm_gem_object *obj) -{ - struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj); - int ret; - - ret = mutex_lock_interruptible(&shmem->vmap_lock); - if (ret) - return ERR_PTR(ret); - - if (shmem->vmap_use_count++ > 0) - goto out; - - if (obj->import_attach) { - shmem->vaddr = dma_buf_vmap(obj->import_attach->dmabuf); - } else { - ret = drm_gem_shmem_get_pages(shmem); - if (ret) - goto err; - - shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT, - VM_MAP, PAGE_KERNEL); - - if (!shmem->vaddr) - drm_gem_shmem_put_pages(shmem); - } - - if (!shmem->vaddr) { - DRM_DEBUG_KMS("Failed to vmap pages\n"); - ret = -ENOMEM; - goto err; - } - -out: - mutex_unlock(&shmem->vmap_lock); - return shmem->vaddr; - -err: - shmem->vmap_use_count = 0; - mutex_unlock(&shmem->vmap_lock); - return ERR_PTR(ret); -} - -static const struct drm_gem_object_funcs udl_gem_object_funcs = { - .free = drm_gem_shmem_free_object, - .print_info = drm_gem_shmem_print_info, - .pin = drm_gem_shmem_pin, - .unpin = drm_gem_shmem_unpin, - .get_sg_table = drm_gem_shmem_get_sg_table, - .vmap = udl_gem_object_vmap, - .vunmap = drm_gem_shmem_vunmap, - .mmap = udl_gem_object_mmap, -}; - -/* - * Helpers for struct drm_driver - */ - -struct drm_gem_object *udl_driver_gem_create_object(struct drm_device *dev, - size_t size) -{ - struct drm_gem_shmem_object *shmem; - struct drm_gem_object *obj; - - shmem = kzalloc(sizeof(*shmem), GFP_KERNEL); - if (!shmem) - return NULL; - - obj = &shmem->base; - obj->funcs = &udl_gem_object_funcs; - - return obj; -}