Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3f4ef0b authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull dma-buf updates from Sumit Semwal:
 "Minor cleanup only; this could've gone in for the 4.0 merge window,
  but for a copy-paste stupidity from me.

  It has been in the for-next since then, and no issues reported.

   - cleanup of dma_buf_export()

   - correction of copy-paste stupidity while doing the cleanup"

* tag 'dma-buf-for-4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/sumits/dma-buf:
  staging: android: ion: fix wrong init of dma_buf_export_info
  dma-buf: cleanup dma_buf_export() to make it easily extensible
parents d6a4c0e5 72449cb4
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -49,25 +49,26 @@ The dma_buf buffer sharing API usage contains the following steps:
   The buffer exporter announces its wish to export a buffer. In this, it
   connects its own private buffer data, provides implementation for operations
   that can be performed on the exported dma_buf, and flags for the file
   associated with this buffer.
   associated with this buffer. All these fields are filled in struct
   dma_buf_export_info, defined via the DEFINE_DMA_BUF_EXPORT_INFO macro.

   Interface:
      struct dma_buf *dma_buf_export_named(void *priv, struct dma_buf_ops *ops,
				     size_t size, int flags,
				     const char *exp_name)
      DEFINE_DMA_BUF_EXPORT_INFO(exp_info)
      struct dma_buf *dma_buf_export(struct dma_buf_export_info *exp_info)

   If this succeeds, dma_buf_export_named allocates a dma_buf structure, and
   If this succeeds, dma_buf_export allocates a dma_buf structure, and
   returns a pointer to the same. It also associates an anonymous file with this
   buffer, so it can be exported. On failure to allocate the dma_buf object,
   it returns NULL.

   'exp_name' is the name of exporter - to facilitate information while
   debugging.
   'exp_name' in struct dma_buf_export_info is the name of exporter - to
   facilitate information while debugging. It is set to KBUILD_MODNAME by
   default, so exporters don't have to provide a specific name, if they don't
   wish to.

   DEFINE_DMA_BUF_EXPORT_INFO macro defines the struct dma_buf_export_info,
   zeroes it out and pre-populates exp_name in it.

   Exporting modules which do not wish to provide any specific name may use the
   helper define 'dma_buf_export()', with the same arguments as above, but
   without the last argument; a KBUILD_MODNAME pre-processor directive will be
   inserted in place of 'exp_name' instead.

2. Userspace gets a handle to pass around to potential buffer-users

+22 −25
Original line number Diff line number Diff line
@@ -265,43 +265,40 @@ static inline int is_dma_buf_file(struct file *file)
}

/**
 * dma_buf_export_named - Creates a new dma_buf, and associates an anon file
 * dma_buf_export - Creates a new dma_buf, and associates an anon file
 * with this buffer, so it can be exported.
 * Also connect the allocator specific data and ops to the buffer.
 * Additionally, provide a name string for exporter; useful in debugging.
 *
 * @priv:	[in]	Attach private data of allocator to this buffer
 * @ops:	[in]	Attach allocator-defined dma buf ops to the new buffer.
 * @size:	[in]	Size of the buffer
 * @flags:	[in]	mode flags for the file.
 * @exp_name:	[in]	name of the exporting module - useful for debugging.
 * @resv:	[in]	reservation-object, NULL to allocate default one.
 * @exp_info:	[in]	holds all the export related information provided
 *			by the exporter. see struct dma_buf_export_info
 *			for further details.
 *
 * Returns, on success, a newly created dma_buf object, which wraps the
 * supplied private data and operations for dma_buf_ops. On either missing
 * ops, or error in allocating struct dma_buf, will return negative error.
 *
 */
struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
				size_t size, int flags, const char *exp_name,
				struct reservation_object *resv)
struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
{
	struct dma_buf *dmabuf;
	struct reservation_object *resv = exp_info->resv;
	struct file *file;
	size_t alloc_size = sizeof(struct dma_buf);
	if (!resv)
	if (!exp_info->resv)
		alloc_size += sizeof(struct reservation_object);
	else
		/* prevent &dma_buf[1] == dma_buf->resv */
		alloc_size += 1;

	if (WARN_ON(!priv || !ops
			  || !ops->map_dma_buf
			  || !ops->unmap_dma_buf
			  || !ops->release
			  || !ops->kmap_atomic
			  || !ops->kmap
			  || !ops->mmap)) {
	if (WARN_ON(!exp_info->priv
			  || !exp_info->ops
			  || !exp_info->ops->map_dma_buf
			  || !exp_info->ops->unmap_dma_buf
			  || !exp_info->ops->release
			  || !exp_info->ops->kmap_atomic
			  || !exp_info->ops->kmap
			  || !exp_info->ops->mmap)) {
		return ERR_PTR(-EINVAL);
	}

@@ -309,10 +306,10 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
	if (dmabuf == NULL)
		return ERR_PTR(-ENOMEM);

	dmabuf->priv = priv;
	dmabuf->ops = ops;
	dmabuf->size = size;
	dmabuf->exp_name = exp_name;
	dmabuf->priv = exp_info->priv;
	dmabuf->ops = exp_info->ops;
	dmabuf->size = exp_info->size;
	dmabuf->exp_name = exp_info->exp_name;
	init_waitqueue_head(&dmabuf->poll);
	dmabuf->cb_excl.poll = dmabuf->cb_shared.poll = &dmabuf->poll;
	dmabuf->cb_excl.active = dmabuf->cb_shared.active = 0;
@@ -323,7 +320,8 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
	}
	dmabuf->resv = resv;

	file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags);
	file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf,
					exp_info->flags);
	if (IS_ERR(file)) {
		kfree(dmabuf);
		return ERR_CAST(file);
@@ -341,8 +339,7 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,

	return dmabuf;
}
EXPORT_SYMBOL_GPL(dma_buf_export_named);

EXPORT_SYMBOL_GPL(dma_buf_export);

/**
 * dma_buf_fd - returns a file descriptor for the given dma_buf
+8 −2
Original line number Diff line number Diff line
@@ -538,8 +538,14 @@ struct dma_buf *
armada_gem_prime_export(struct drm_device *dev, struct drm_gem_object *obj,
	int flags)
{
	return dma_buf_export(obj, &armada_gem_prime_dmabuf_ops, obj->size,
			      O_RDWR, NULL);
	DEFINE_DMA_BUF_EXPORT_INFO(exp_info);

	exp_info.ops = &armada_gem_prime_dmabuf_ops;
	exp_info.size = obj->size;
	exp_info.flags = O_RDWR;
	exp_info.priv = obj;

	return dma_buf_export(&exp_info);
}

struct drm_gem_object *
+8 −4
Original line number Diff line number Diff line
@@ -339,13 +339,17 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = {
struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
				     struct drm_gem_object *obj, int flags)
{
	struct reservation_object *robj = NULL;
	DEFINE_DMA_BUF_EXPORT_INFO(exp_info);

	exp_info.ops = &drm_gem_prime_dmabuf_ops;
	exp_info.size = obj->size;
	exp_info.flags = flags;
	exp_info.priv = obj;

	if (dev->driver->gem_prime_res_obj)
		robj = dev->driver->gem_prime_res_obj(obj);
		exp_info.resv = dev->driver->gem_prime_res_obj(obj);

	return dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size,
			      flags, robj);
	return dma_buf_export(&exp_info);
}
EXPORT_SYMBOL(drm_gem_prime_export);

+7 −2
Original line number Diff line number Diff line
@@ -185,9 +185,14 @@ struct dma_buf *exynos_dmabuf_prime_export(struct drm_device *drm_dev,
				struct drm_gem_object *obj, int flags)
{
	struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
	DEFINE_DMA_BUF_EXPORT_INFO(exp_info);

	return dma_buf_export(obj, &exynos_dmabuf_ops,
				exynos_gem_obj->base.size, flags, NULL);
	exp_info.ops = &exynos_dmabuf_ops;
	exp_info.size = exynos_gem_obj->base.size;
	exp_info.flags = flags;
	exp_info.priv = obj;

	return dma_buf_export(&exp_info);
}

struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev,
Loading