dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tomasz Stanislawski <t.stanislaws@samsung.com>
Cc: arnd@arndb.de, "Daniel Vetter" <daniel.vetter@ffwll.ch>,
	dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
	'박경민' <kyungmin.park@samsung.com>, "Rob Clark" <rob@ti.com>,
	"Dave Airlie" <airlied@redhat.com>,
	"Marek Szyprowski" <m.szyprowski@samsung.com>
Subject: Re: [PATCH 5/7] drm/vgem: prime export support
Date: Mon, 27 Feb 2012 16:43:02 +0100	[thread overview]
Message-ID: <4F4BA486.2030400@samsung.com> (raw)
In-Reply-To: <1329938960-4903-7-git-send-email-ben@bwidawsk.net>

Hi Ben and Sumit,

Please refer to comments below:

On 02/22/2012 08:29 PM, Ben Widawsky wrote:
> dma-buf export implementation. Heavily influenced by Dave Airlie's proof
> of concept work.
>
> Cc: Daniel Vetter<daniel.vetter@ffwll.ch>
> Cc: Dave Airlie<airlied@redhat.com>
> Signed-off-by: Ben Widawsky<ben@bwidawsk.net>
> ---
>   drivers/gpu/drm/vgem/Makefile       |    2 +-
>   drivers/gpu/drm/vgem/vgem_dma_buf.c |  128 +++++++++++++++++++++++++++++++++++
>   drivers/gpu/drm/vgem/vgem_drv.c     |    6 ++
>   drivers/gpu/drm/vgem/vgem_drv.h     |    7 ++
>   4 files changed, 142 insertions(+), 1 deletions(-)
>   create mode 100644 drivers/gpu/drm/vgem/vgem_dma_buf.c
>

[snip]

> +struct sg_table *vgem_gem_map_dma_buf(struct dma_buf_attachment *attachment,
> +                                      enum dma_data_direction dir)
> +{
> +	struct drm_vgem_gem_object *obj = attachment->dmabuf->priv;
> +	struct sg_table *sg;
> +	int ret;
> +
> +	ret = vgem_gem_get_pages(obj);
> +	if (ret) {
> +		vgem_gem_put_pages(obj);

is it safe to call vgem_gem_put_pages if vgem_gem_get_pages failed (I 
mean ret < 0 was returned) ?

> +		return NULL;
> +	}
> +
> +	BUG_ON(obj->pages == NULL);
> +
> +	sg = drm_prime_pages_to_sg(obj->pages, obj->base.size / PAGE_SIZE);

if drm_prime_pages_to_sg fails then you should call vgem_gem_put_pages 
for cleanup.

> +	return sg;
> +}

The documentation of DMABUF says fallowing words about map_dma_buf callback.

"It is one of the buffer operations that must be implemented by the 
exporter. It should return the sg_table containing scatterlist for this 
buffer, mapped into caller's address space."

The scatterlist returned by drm_prime_pages_to_sg is not mapped to any 
device. The map_dma_buf callback should call dma_map_sg for caller 
device, which is attachment->dev. Otherwise the implementation is not 
consistent with the DMABUF spec.

I think that it should be chosen to change implementation in map_dma_buf 
in DRM drivers or to drop mentioned sentence from the DMABUF spec.

I bear to the second solution because IMO there is no reliable way of 
mapping a scatterlist to importer device by an exporter. The dma_map_sg 
could be used but not all drivers makes use of DMA framework.

Sumit, what is your opinion about it?

> +
> +void vgem_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
> +			    struct sg_table *sg)
> +{
> +	sg_free_table(sg);
> +	kfree(sg);
> +}
> +
> +void vgem_gem_release(struct dma_buf *buf)
> +{
> +	struct drm_vgem_gem_object *obj = buf->priv;
> +
> +	BUG_ON(buf != obj->base.export_dma_buf);
> +
> +	obj->base.prime_fd = -1;
> +	obj->base.export_dma_buf = NULL;
> +	drm_gem_object_unreference_unlocked(&obj->base);
> +}
> +
> +struct dma_buf_ops vgem_dmabuf_ops = {
> +	.map_dma_buf = vgem_gem_map_dma_buf,
> +	.unmap_dma_buf = vgem_gem_unmap_dma_buf,
> +	.release = vgem_gem_release
> +};
> +

Regards,
Tomasz Stanislawski

  parent reply	other threads:[~2012-02-27 15:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-22 19:29 [PATCH 0/7] RFCv3 VGEM Prime (dma-buf) Ben Widawsky
2012-02-22 19:29 ` [PATCH 1/7] drm: base prime support Ben Widawsky
2012-02-22 19:58   ` Kristian Høgsberg
2012-02-27  2:49   ` InKi Dae
2012-02-22 19:29 ` [PATCH 2/7] DRM_DEBUG_PRIME Ben Widawsky
2012-02-22 19:29 ` [PATCH 2/7] drm: DRM_DEBUG_PRIME Ben Widawsky
2012-02-22 19:29 ` [PATCH 3/7] drm/vgem: virtual GEM provider Ben Widawsky
2012-02-22 19:29 ` [PATCH 4/7] drm: per device prime dma buf hash Ben Widawsky
2012-02-22 19:29 ` [PATCH 5/7] drm/vgem: prime export support Ben Widawsky
2012-02-23 19:00   ` [Linaro-mm-sig] " Chris Wilson
2012-02-27 13:37   ` Tomasz Stanislawski
2012-02-27 15:43   ` Tomasz Stanislawski [this message]
2012-02-29 15:50     ` Daniel Vetter
2012-02-22 19:29 ` [PATCH 6/7] drm/vgem: import support Ben Widawsky
2012-02-23 19:10   ` [Linaro-mm-sig] " Chris Wilson
2012-02-23 23:00   ` Chris Wilson
2012-02-22 19:29 ` [PATCH 7/7] drm: actually enable PRIME Ben Widawsky

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=4F4BA486.2030400@samsung.com \
    --to=t.stanislaws@samsung.com \
    --cc=airlied@redhat.com \
    --cc=arnd@arndb.de \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=m.szyprowski@samsung.com \
    --cc=rob@ti.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox