From patchwork Wed Dec 11 12:19:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 11284811 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 0D0546C1 for ; Wed, 11 Dec 2019 12:20:15 +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 DF9BA214D8 for ; Wed, 11 Dec 2019 12:20:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RX5+qDSu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF9BA214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 C0CB46EB29; Wed, 11 Dec 2019 12:20:08 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5B3826EB21 for ; Wed, 11 Dec 2019 12:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576066806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Aya/nycTrUQ34itusmCkgEMEDKSIN7dICC56yrlcxiA=; b=RX5+qDSux4bEGHeDt/pP8WfypqDIXYIad1G6OwYm2MDaSaCnkUuUD3pwNOPQWzLulICW85 PIPxk6+Jcin/P5m1C7AzAeF2RyOe+iycFbrLGiUDGf7WV6SlZyOhxSrFT5FrtsgJBYuyaT 8kGYqrdwnZ6CwMw+0RI/NjnYtcKYp5s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-134-VbEHjdUdNpma6zsmh9Vx_A-1; Wed, 11 Dec 2019 07:20:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 64BE5800D4C; Wed, 11 Dec 2019 12:20:01 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-67.ams2.redhat.com [10.36.116.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B25719756; Wed, 11 Dec 2019 12:19:58 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 3DB3616E2D; Wed, 11 Dec 2019 13:19:57 +0100 (CET) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 1/4] drm: add pgprot callback to drm_gem_object_funcs Date: Wed, 11 Dec 2019 13:19:53 +0100 Message-Id: <20191211121957.18637-2-kraxel@redhat.com> In-Reply-To: <20191211121957.18637-1-kraxel@redhat.com> References: <20191211121957.18637-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: VbEHjdUdNpma6zsmh9Vx_A-1 X-Mimecast-Spam-Score: 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: David Airlie , open list , gurchetansingh@chromium.org, Gerd Hoffmann , tzimmermann@suse.de MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The callback allows drivers and helpers to tweak pgprot for mappings. This is especially helpful when using shmem helpers. It allows drivers to switch mappings from writecombine (default) to something else (cached for example) on a per-object base without having to supply their own mmap() and vmap() functions. The patch also adds two implementations for the callback, for cached and writecombine mappings, and the drm_gem_pgprot() function to update pgprot for a given object, using the new &drm_gem_object_funcs.pgprot callback if available. Signed-off-by: Gerd Hoffmann --- include/drm/drm_gem.h | 15 +++++++++++++ drivers/gpu/drm/drm_gem.c | 46 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 0b375069cd48..5beef7226e69 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -163,6 +163,17 @@ struct drm_gem_object_funcs { */ int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma); + /** + * @pgprot: + * + * Tweak pgprot as needed, typically used to set cache bits. + * + * This callback is optional. + * + * If unset drm_gem_pgprot_wc() will be used. + */ + pgprot_t (*pgprot)(struct drm_gem_object *obj, pgprot_t prot); + /** * @vm_ops: * @@ -350,6 +361,10 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, struct vm_area_struct *vma); int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); +pgprot_t drm_gem_pgprot_cached(struct drm_gem_object *obj, pgprot_t prot); +pgprot_t drm_gem_pgprot_wc(struct drm_gem_object *obj, pgprot_t prot); +pgprot_t drm_gem_pgprot(struct drm_gem_object *obj, pgprot_t prot); + /** * drm_gem_object_get - acquire a GEM buffer object reference * @obj: GEM buffer object diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 56f42e0f2584..1c468fe8e342 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1119,7 +1119,8 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, return -EINVAL; vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; - vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); + vma->vm_page_prot = drm_gem_pgprot(obj, vma->vm_page_prot); vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); } @@ -1210,6 +1211,49 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) } EXPORT_SYMBOL(drm_gem_mmap); +/** + * drm_gem_mmap - update pgprot for objects needing a cachable mapping. + * @obj: the GEM object. + * @prot: page attributes. + * + * This function can be used as &drm_gem_object_funcs.pgprot callback. + */ +pgprot_t drm_gem_pgprot_cached(struct drm_gem_object *obj, pgprot_t prot) +{ + return prot; +} +EXPORT_SYMBOL(drm_gem_pgprot_cached); + +/** + * drm_gem_mmap - update pgprot for objects needing a wc mapping. + * @obj: the GEM object. + * @prot: page attributes. + * + * This function can be used as &drm_gem_object_funcs.pgprot callback. + */ +pgprot_t drm_gem_pgprot_wc(struct drm_gem_object *obj, pgprot_t prot) +{ + return pgprot_writecombine(prot); +} +EXPORT_SYMBOL(drm_gem_pgprot_wc); + +/** + * drm_gem_mmap - update pgprot for a given gem object. + * @obj: the GEM object. + * @prot: page attributes. + * + * This function updates pgprot according to the needs of the given + * object. If present &drm_gem_object_funcs.pgprot callback will be + * used, otherwise drm_gem_pgprot_wc() is called. + */ +pgprot_t drm_gem_pgprot(struct drm_gem_object *obj, pgprot_t prot) +{ + if (obj->funcs->pgprot) + return obj->funcs->pgprot(obj, prot); + return drm_gem_pgprot_wc(obj, prot); +} +EXPORT_SYMBOL(drm_gem_pgprot); + void drm_gem_print_info(struct drm_printer *p, unsigned int indent, const struct drm_gem_object *obj) { From patchwork Wed Dec 11 12:19:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 11284813 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 1E8CB6C1 for ; Wed, 11 Dec 2019 12:20:17 +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 F17A5214D8 for ; Wed, 11 Dec 2019 12:20:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ilGDDQPj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F17A5214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 40A386EB27; Wed, 11 Dec 2019 12:20:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3A5206EB2C for ; Wed, 11 Dec 2019 12:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576066808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PkdD4/AJY6bHnmvm2xfOY1Z5pyo8lh7Kbp9qetU0nC8=; b=ilGDDQPjEeDoEEqDiXjP8MahyzLruMwc7pFrwtvHzjRL06n2X9KdD2EeVxU420aEE23qrE 3rdndF0JMx4CtSBYcYKXo5GKS8Y6KaaNv3BK+d7AJ3z/F97ovJI6E4igubuqK9cEW8OVjN 44Pz6eSWaAV5KvVudn1rdlomJKqR0DQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-138-UBI4tOyRMcmcvF9FM1qicw-1; Wed, 11 Dec 2019 07:20:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 718631804488; Wed, 11 Dec 2019 12:20:03 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-67.ams2.redhat.com [10.36.116.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1533260BE0; Wed, 11 Dec 2019 12:19:58 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 5B1421747D; Wed, 11 Dec 2019 13:19:57 +0100 (CET) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 2/4] drm/shmem: add support for per object caching flags. Date: Wed, 11 Dec 2019 13:19:54 +0100 Message-Id: <20191211121957.18637-3-kraxel@redhat.com> In-Reply-To: <20191211121957.18637-1-kraxel@redhat.com> References: <20191211121957.18637-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: UBI4tOyRMcmcvF9FM1qicw-1 X-Mimecast-Spam-Score: 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: David Airlie , open list , gurchetansingh@chromium.org, Gerd Hoffmann , tzimmermann@suse.de MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use drm_gem_pgprot_wc() as pgprot callback in drm_gem_shmem_funcs. Use drm_gem_pgprot() to update pgprot caching flags. Signed-off-by: Gerd Hoffmann --- drivers/gpu/drm/drm_gem_shmem_helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index a421a2eed48a..2a662ed77115 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -33,6 +33,7 @@ static const struct drm_gem_object_funcs drm_gem_shmem_funcs = { .vmap = drm_gem_shmem_vmap, .vunmap = drm_gem_shmem_vunmap, .mmap = drm_gem_shmem_mmap, + .pgprot = drm_gem_pgprot_wc, }; /** @@ -258,7 +259,7 @@ static void *drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem) shmem->vaddr = dma_buf_vmap(obj->import_attach->dmabuf); else shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT, - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + VM_MAP, drm_gem_pgprot(obj, PAGE_KERNEL)); if (!shmem->vaddr) { DRM_DEBUG_KMS("Failed to vmap pages\n"); @@ -540,7 +541,8 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) } vma->vm_flags |= VM_MIXEDMAP | VM_DONTEXPAND; - vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); + vma->vm_page_prot = drm_gem_pgprot(obj, vma->vm_page_prot); vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); vma->vm_ops = &drm_gem_shmem_vm_ops; From patchwork Wed Dec 11 12:19:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 11284815 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 EA0BB109A for ; Wed, 11 Dec 2019 12:20:18 +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 C8DF9214D8 for ; Wed, 11 Dec 2019 12:20:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="M5luoWqU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8DF9214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 A31F16EB2D; Wed, 11 Dec 2019 12:20:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id BF7886EB29 for ; Wed, 11 Dec 2019 12:20:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576066805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UIewAyx++ktQ/Uek8hL3crFT01ZthoO/ZwsAoVP4Ej8=; b=M5luoWqUburszTX0dzw3tt03OFPZp1XV52tbTTZY1du9xL4uo+WlibZ6QAKEQRk4Xwy29O 6ZuCi96/T/mOGSzTCuL28iKuXTCfYalGoWGou3CT8YJEnizDnhFX10Q3qLTTz3I9bXpRnT KL4MfTChAvhRADsA4MlSM1X6r0Nk4QU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-279-VXS_jZefO9GEJcB7iAO75Q-1; Wed, 11 Dec 2019 07:20:02 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 052361005524; Wed, 11 Dec 2019 12:20:01 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-67.ams2.redhat.com [10.36.116.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D956691A0; Wed, 11 Dec 2019 12:19:58 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 746BA17536; Wed, 11 Dec 2019 13:19:57 +0100 (CET) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 3/4] drm/virtio: fix mmap page attributes Date: Wed, 11 Dec 2019 13:19:55 +0100 Message-Id: <20191211121957.18637-4-kraxel@redhat.com> In-Reply-To: <20191211121957.18637-1-kraxel@redhat.com> References: <20191211121957.18637-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: VXS_jZefO9GEJcB7iAO75Q-1 X-Mimecast-Spam-Score: 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: tzimmermann@suse.de, David Airlie , open list , "open list:VIRTIO GPU DRIVER" , Gerd Hoffmann , gurchetansingh@chromium.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" virtio-gpu uses cached mappings, set virtio_gpu_gem_funcs.pgprot accordingly. Reported-by: Gurchetan Singh Signed-off-by: Gerd Hoffmann --- drivers/gpu/drm/virtio/virtgpu_object.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c index 017a9e0fc3bb..0b754c5bbcce 100644 --- a/drivers/gpu/drm/virtio/virtgpu_object.c +++ b/drivers/gpu/drm/virtio/virtgpu_object.c @@ -87,6 +87,7 @@ static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .vmap = drm_gem_shmem_vmap, .vunmap = drm_gem_shmem_vunmap, .mmap = &drm_gem_shmem_mmap, + .pgprot = &drm_gem_pgprot_cached, }; struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev, From patchwork Wed Dec 11 12:19:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 11284807 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 3EE5F109A for ; Wed, 11 Dec 2019 12:20:09 +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 1AA00214D8 for ; Wed, 11 Dec 2019 12:20:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JuWLwj81" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1AA00214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 B61E66EB1F; Wed, 11 Dec 2019 12:20:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8E6D36EB1F for ; Wed, 11 Dec 2019 12:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576066803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CO314128W7CDNlXEcy+PWsJG51Toka8m6TWFPQjhhH4=; b=JuWLwj81zqtQF8e+LsBv8NGYKCsZNglL4nfnKcdi4tf/FKyvx6dOXCEVfMn/EIbsb6EsCS LPjPz7SkeoQzoznOSnZ8fWtsX+r5WlarJGMx3Et/xAtORd7cTemSe+Ui4AfhZc+MVHWdCT KuPRKohOLyiJbdM5GsqS6jChUcHys24= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-ptuNYTXuPj6rCyVckKaV4A-1; Wed, 11 Dec 2019 07:20:02 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C40E31804488; Wed, 11 Dec 2019 12:20:00 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-67.ams2.redhat.com [10.36.116.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 464BC6364F; Wed, 11 Dec 2019 12:19:58 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 91A7A17538; Wed, 11 Dec 2019 13:19:57 +0100 (CET) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 4/4] drm/udl: simplify gem object mapping. Date: Wed, 11 Dec 2019 13:19:56 +0100 Message-Id: <20191211121957.18637-5-kraxel@redhat.com> In-Reply-To: <20191211121957.18637-1-kraxel@redhat.com> References: <20191211121957.18637-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: ptuNYTXuPj6rCyVckKaV4A-1 X-Mimecast-Spam-Score: 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: David Airlie , open list , gurchetansingh@chromium.org, Gerd Hoffmann , tzimmermann@suse.de, Dave Airlie , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" With shmem helpers allowing to update pgprot caching flags via drm_gem_object_funcs.pgprot we can just use that and ditch our own implementations of mmap() and vmap(). Signed-off-by: Gerd Hoffmann --- drivers/gpu/drm/udl/udl_gem.c | 62 ++++------------------------------- 1 file changed, 7 insertions(+), 55 deletions(-) diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c index b6e26f98aa0a..b82a4a921f1b 100644 --- a/drivers/gpu/drm/udl/udl_gem.c +++ b/drivers/gpu/drm/udl/udl_gem.c @@ -17,61 +17,12 @@ * GEM object funcs */ -static int udl_gem_object_mmap(struct drm_gem_object *obj, - struct vm_area_struct *vma) +static pgprot_t udl_gem_object_pgprot(struct drm_gem_object *obj, + pgprot_t pgprot) { - 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; - - ret = drm_gem_shmem_get_pages(shmem); - if (ret) - goto err_zero_use; - - if (obj->import_attach) - shmem->vaddr = dma_buf_vmap(obj->import_attach->dmabuf); - else - shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT, - VM_MAP, PAGE_KERNEL); - - if (!shmem->vaddr) { - DRM_DEBUG_KMS("Failed to vmap pages\n"); - ret = -ENOMEM; - goto err_put_pages; - } - -out: - mutex_unlock(&shmem->vmap_lock); - return shmem->vaddr; - -err_put_pages: - drm_gem_shmem_put_pages(shmem); -err_zero_use: - shmem->vmap_use_count = 0; - mutex_unlock(&shmem->vmap_lock); - return ERR_PTR(ret); + pgprot = pgprot_writecombine(pgprot); + return pgprot; } static const struct drm_gem_object_funcs udl_gem_object_funcs = { @@ -80,9 +31,10 @@ static const struct drm_gem_object_funcs udl_gem_object_funcs = { .pin = drm_gem_shmem_pin, .unpin = drm_gem_shmem_unpin, .get_sg_table = drm_gem_shmem_get_sg_table, - .vmap = udl_gem_object_vmap, + .vmap = drm_gem_shmem_vmap, .vunmap = drm_gem_shmem_vunmap, - .mmap = udl_gem_object_mmap, + .mmap = drm_gem_shmem_mmap, + .pgprot = udl_gem_object_pgprot, }; /*