Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp579048ybl; Wed, 11 Dec 2019 04:20:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxLwrKJnL2MIJ/fHpaq3hNWrOAIDK+s/DUUFU+gQ360VAHu9Jm2ujFAmHt1lwWUXQMOzzPv X-Received: by 2002:a05:6830:1e69:: with SMTP id m9mr1979035otr.335.1576066857279; Wed, 11 Dec 2019 04:20:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576066857; cv=none; d=google.com; s=arc-20160816; b=IwaueZclQqzzN+WsfFalHRmwE9XFQfPfvLGvYgzA32iEUUGE2t8I9W6KIaS9bJr4z9 FoqjZ3hR2kZZcnF1eZY/5klRCam8VB5rhf8SVTEuFJAqOclGe3rGGhNIjQM3kJLogpec xQdAs6g5qY0tFs0fec8Ea+EmM6yMdAD6L6jxwMq5fGHTMv43auYdp28xftjW2skerbim VxCJp56z0nzI7BMiGnNj+VPJJWouuyeyzgn6lofAHvp+d2AZOhQYaGg4W/8Hfl1LPSBH LpIzvvKb76NHdCA64FvdNJQ2MvisFgHe2ub2DBRogLooLAjNNO57kveiiR3YsuuRkNGr 41ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=Aya/nycTrUQ34itusmCkgEMEDKSIN7dICC56yrlcxiA=; b=VrFo1uuD2F6m0Sofj8AFsM/nOpCxvS/LqKZYFuerdJzfv/rGk7wIgJGnejmT5pm2L2 BttrEciFBnWJMBHdrOZ3069vjDhcRZNbS4h7CB/Rrl0ebNiym8i7mu4QbWNr+QJ+0ymD SV2vKjyuvDhrSyb/b5cGIvCIRq5Y/r1HiK2bBkDq8o2w2xwKUEQuTmcYLbQADK2glt6d +b+iSex7pQtUzCwkj0i9+t0eaXUS5nhclgZkFwsi3WLrBfp9uxBQusTfV5fNL3AxZbgv a2FbiddbimleRDpX94TVmUuJlT22XyGa1lQ26UERTdlF+W9OLTq/Uux/N1J2FCaae3X6 CQkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RX5+qDSu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si946683oth.267.2019.12.11.04.20.44; Wed, 11 Dec 2019 04:20:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RX5+qDSu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729196AbfLKMUJ (ORCPT + 99 others); Wed, 11 Dec 2019 07:20:09 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:22167 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729117AbfLKMUH (ORCPT ); Wed, 11 Dec 2019 07:20:07 -0500 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 Cc: tzimmermann@suse.de, gurchetansingh@chromium.org, Gerd Hoffmann , Maarten Lankhorst , Maxime Ripard , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 { =09 */ =09int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma); =20 +=09/** +=09 * @pgprot: +=09 * +=09 * Tweak pgprot as needed, typically used to set cache bits. +=09 * +=09 * This callback is optional. +=09 * +=09 * If unset drm_gem_pgprot_wc() will be used. +=09 */ +=09pgprot_t (*pgprot)(struct drm_gem_object *obj, pgprot_t prot); + =09/** =09 * @vm_ops: =09 * @@ -350,6 +361,10 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsig= ned long obj_size, =09=09 struct vm_area_struct *vma); int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); =20 +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, unsi= gned long obj_size, =09=09=09return -EINVAL; =20 =09=09vma->vm_flags |=3D VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; -=09=09vma->vm_page_prot =3D pgprot_writecombine(vm_get_page_prot(vma->vm_f= lags)); +=09=09vma->vm_page_prot =3D vm_get_page_prot(vma->vm_flags); +=09=09vma->vm_page_prot =3D drm_gem_pgprot(obj, vma->vm_page_prot); =09=09vma->vm_page_prot =3D pgprot_decrypted(vma->vm_page_prot); =09} =20 @@ -1210,6 +1211,49 @@ int drm_gem_mmap(struct file *filp, struct vm_area_s= truct *vma) } EXPORT_SYMBOL(drm_gem_mmap); =20 +/** + * 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) +{ +=09return 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) +{ +=09return 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) +{ +=09if (obj->funcs->pgprot) +=09=09return obj->funcs->pgprot(obj, prot); +=09return drm_gem_pgprot_wc(obj, prot); +} +EXPORT_SYMBOL(drm_gem_pgprot); + void drm_gem_print_info(struct drm_printer *p, unsigned int indent, =09=09=09const struct drm_gem_object *obj) { --=20 2.18.1