All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Cc: linaro-kernel@lists.linaro.org, michel@daenzer.net,
	philippe.cornu@st.com, dri-devel@lists.freedesktop.org,
	yannick.fertre@st.com, airlied@redhat.com
Subject: Re: [PATCH v4 4/4] drm: allow to use mmuless SoC
Date: Wed, 07 Dec 2016 16:32:44 +0200	[thread overview]
Message-ID: <4115654.e0qukbEXW0@avalon> (raw)
In-Reply-To: <1481105211-18020-5-git-send-email-benjamin.gaignard@linaro.org>

Hi Benjamin,

Thank you for the patch.

On Wednesday 07 Dec 2016 11:06:51 Benjamin Gaignard wrote:
> Some SoC without MMU have display driver where a drm/kms driver
> could be implemented.
> 
> Before doing such kind of thing drm/kms must allow to use mmuless devices.
> This patch propose to remove MMU configuration flag and add a cma helper
> function to help implementing mmuless display driver
> 
> version 4:
> - add documentation about drm_gem_cma_get_unmapped_area()
> - stub it MMU case
> 
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> ---
>  Documentation/gpu/drm-mm.rst         | 11 ++++++
>  drivers/gpu/drm/Kconfig              |  4 +--
>  drivers/gpu/drm/drm_gem_cma_helper.c | 69 +++++++++++++++++++++++++++++++++
>  include/drm/drm_gem_cma_helper.h     | 17 +++++++++
>  4 files changed, 99 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/gpu/drm-mm.rst b/Documentation/gpu/drm-mm.rst
> index bca8085..6e7efab 100644
> --- a/Documentation/gpu/drm-mm.rst
> +++ b/Documentation/gpu/drm-mm.rst
> @@ -303,6 +303,17 @@ created.
>  Drivers that want to map the GEM object upfront instead of handling page
>  faults can implement their own mmap file operation handler.
> 
> +For platforms without MMU GEM care provides a helper method

s/GEM care/the GEM core/

> +:c:func:`drm_gem_cma_get_unmapped_area`. The mmap() routines will call
> +this to get a proposed address for the mapping.
> +
> +To use :c:func:`drm_gem_cma_get_unmapped_area`, drivers must fill the
> +struct :c:type:`struct file_operations <file_operations>` get_unmapped_area
> +field with a pointer on :c:func:`drm_gem_cma_get_unmapped_area`.
> +
> +More detailed information about get_unmapped_area can be found in
> +Documentation/nommu-mmap.txt
> +
>  Memory Coherency
>  ----------------
> 
> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
> index 83ac815..0eae4ad 100644
> --- a/drivers/gpu/drm/Kconfig
> +++ b/drivers/gpu/drm/Kconfig
> @@ -6,7 +6,7 @@
>  #
>  menuconfig DRM
>  	tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI 
support)"
> -	depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU && HAS_DMA
> +	depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && HAS_DMA
>  	select HDMI
>  	select FB_CMDLINE
>  	select I2C
> @@ -98,7 +98,7 @@ config DRM_LOAD_EDID_FIRMWARE
> 
>  config DRM_TTM
>  	tristate
> -	depends on DRM
> +	depends on DRM && MMU
>  	help
>  	  GPU memory management subsystem for devices with multiple
>  	  GPU memory types. Will be enabled automatically if a device driver
> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c
> b/drivers/gpu/drm/drm_gem_cma_helper.c index 1d6c335..01016b1 100644
> --- a/drivers/gpu/drm/drm_gem_cma_helper.c
> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
> @@ -358,6 +358,75 @@ int drm_gem_cma_mmap(struct file *filp, struct
> vm_area_struct *vma) }
>  EXPORT_SYMBOL_GPL(drm_gem_cma_mmap);
> 
> +#ifndef CONFIG_MMU
> +/**
> + * drm_gem_cma_get_unmapped_area - propose address for mapping in noMMU
> cases
> + * @filp: file object
> + * @addr: memory address
> + * @len: buffer size
> + * @pgoff: page offset
> + * @flags: memory flags
> + *
> + * This function is used in noMMU platforms to propose address mapping
> + * for a given buffer.

I would add

"It's intended to be used as a direct handler for the :c:type:`struct 
file_operations <file_operations>` .get_unmapped_area() operation."

Apart from that,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> + * Returns:
> + * mapping address on success or a negative error code on failure
> + */
> +unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
> +					    unsigned long addr,
> +					    unsigned long len,
> +					    unsigned long pgoff,
> +					    unsigned long flags)
> +{
> +	struct drm_gem_cma_object *cma_obj;
> +	struct drm_gem_object *obj = NULL;
> +	struct drm_file *priv = filp->private_data;
> +	struct drm_device *dev = priv->minor->dev;
> +	struct drm_vma_offset_node *node;
> +
> +	if (drm_device_is_unplugged(dev))
> +		return -ENODEV;
> +
> +	drm_vma_offset_lock_lookup(dev->vma_offset_manager);
> +	node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,
> +						  pgoff,
> +						  len >> PAGE_SHIFT);
> +	if (likely(node)) {
> +		obj = container_of(node, struct drm_gem_object, vma_node);
> +		/*
> +		 * When the object is being freed, after it hits 0-refcnt it
> +		 * proceeds to tear down the object. In the process it will
> +		 * attempt to remove the VMA offset and so acquire this
> +		 * mgr->vm_lock.  Therefore if we find an object with a 0-
refcnt
> +		 * that matches our range, we know it is in the process of 
being
> +		 * destroyed and will be freed as soon as we release the lock 
-
> +		 * so we have to check for the 0-refcnted object and treat it 
as
> +		 * invalid.
> +		 */
> +		if (!kref_get_unless_zero(&obj->refcount))
> +			obj = NULL;
> +	}
> +
> +	drm_vma_offset_unlock_lookup(dev->vma_offset_manager);
> +
> +	if (!obj)
> +		return -EINVAL;
> +
> +	if (!drm_vma_node_is_allowed(node, priv)) {
> +		drm_gem_object_unreference_unlocked(obj);
> +		return -EACCES;
> +	}
> +
> +	cma_obj = to_drm_gem_cma_obj(obj);
> +
> +	drm_gem_object_unreference_unlocked(obj);
> +
> +	return cma_obj->vaddr ? (unsigned long)cma_obj->vaddr : -EINVAL;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_cma_get_unmapped_area);
> +#endif
> +
>  #ifdef CONFIG_DEBUG_FS
>  /**
>   * drm_gem_cma_describe - describe a CMA GEM object for debugfs
> diff --git a/include/drm/drm_gem_cma_helper.h
> b/include/drm/drm_gem_cma_helper.h index acd6af8..180b586 100644
> --- a/include/drm/drm_gem_cma_helper.h
> +++ b/include/drm/drm_gem_cma_helper.h
> @@ -53,6 +53,23 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct
> drm_device *drm,
> 
>  extern const struct vm_operations_struct drm_gem_cma_vm_ops;
> 
> +#ifndef CONFIG_MMU
> +unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
> +					    unsigned long addr,
> +					    unsigned long len,
> +					    unsigned long pgoff,
> +					    unsigned long flags);
> +#else
> +unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
> +					    unsigned long addr,
> +					    unsigned long len,
> +					    unsigned long pgoff,
> +					    unsigned long flags)
> +{
> +	return -EINVAL;
> +}
> +#endif
> +
>  #ifdef CONFIG_DEBUG_FS
>  void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file
> *m); #endif

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2016-12-07 14:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 10:06 [PATCH v4 0/4] DRM: allow to use mmuless devices Benjamin Gaignard
2016-12-07 10:06 ` [PATCH v4 1/4] nommu: allow mmap when !CONFIG_MMU Benjamin Gaignard
2016-12-07 10:06 ` [PATCH v4 2/4] fbmem: add a default get_fb_unmapped_area function Benjamin Gaignard
2016-12-07 14:35   ` Laurent Pinchart
2016-12-07 14:57     ` Benjamin Gaignard
2016-12-07 15:19       ` Laurent Pinchart
2016-12-07 15:31         ` Benjamin Gaignard
2016-12-07 10:06 ` [PATCH v4 3/4] drm: compile drm_vm.c only when needed Benjamin Gaignard
2016-12-07 14:34   ` Laurent Pinchart
2016-12-07 10:06 ` [PATCH v4 4/4] drm: allow to use mmuless SoC Benjamin Gaignard
2016-12-07 10:27   ` Daniel Vetter
2016-12-07 10:42     ` Benjamin Gaignard
2016-12-07 14:32   ` Laurent Pinchart [this message]
2016-12-07 14:49     ` Daniel Vetter
2016-12-07 15:19   ` Benjamin Gaignard
2016-12-07 16:17     ` Eric Engestrom
2016-12-07 20:44     ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4115654.e0qukbEXW0@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=airlied@redhat.com \
    --cc=benjamin.gaignard@linaro.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=michel@daenzer.net \
    --cc=philippe.cornu@st.com \
    --cc=yannick.fertre@st.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.