diff options
| author | Sumit Semwal <sumit.semwal@linaro.org> | 2015-01-23 02:23:43 -0500 |
|---|---|---|
| committer | Sumit Semwal <sumit.semwal@linaro.org> | 2015-04-21 05:17:16 -0400 |
| commit | d8fbe341beb617ebb22b98fb893e4aa32ae2d864 (patch) | |
| tree | 2e19c951d2b6ffef2319d87ec8a6c39e4e1ab8ee /drivers/dma-buf | |
| parent | 646da63172f660ba84f195c1165360a9b73583ee (diff) | |
dma-buf: cleanup dma_buf_export() to make it easily extensible
At present, dma_buf_export() takes a series of parameters, which
makes it difficult to add any new parameters for exporters, if required.
Make it simpler by moving all these parameters into a struct, and pass
the struct * as parameter to dma_buf_export().
While at it, unite dma_buf_export_named() with dma_buf_export(), and
change all callers accordingly.
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
Acked-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Diffstat (limited to 'drivers/dma-buf')
| -rw-r--r-- | drivers/dma-buf/dma-buf.c | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 5be225c2ba98..c5a9138a6a8d 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c | |||
| @@ -265,43 +265,40 @@ static inline int is_dma_buf_file(struct file *file) | |||
| 265 | } | 265 | } |
| 266 | 266 | ||
| 267 | /** | 267 | /** |
| 268 | * dma_buf_export_named - Creates a new dma_buf, and associates an anon file | 268 | * dma_buf_export - Creates a new dma_buf, and associates an anon file |
| 269 | * with this buffer, so it can be exported. | 269 | * with this buffer, so it can be exported. |
| 270 | * Also connect the allocator specific data and ops to the buffer. | 270 | * Also connect the allocator specific data and ops to the buffer. |
| 271 | * Additionally, provide a name string for exporter; useful in debugging. | 271 | * Additionally, provide a name string for exporter; useful in debugging. |
| 272 | * | 272 | * |
| 273 | * @priv: [in] Attach private data of allocator to this buffer | 273 | * @exp_info: [in] holds all the export related information provided |
| 274 | * @ops: [in] Attach allocator-defined dma buf ops to the new buffer. | 274 | * by the exporter. see struct dma_buf_export_info |
| 275 | * @size: [in] Size of the buffer | 275 | * for further details. |
| 276 | * @flags: [in] mode flags for the file. | ||
| 277 | * @exp_name: [in] name of the exporting module - useful for debugging. | ||
| 278 | * @resv: [in] reservation-object, NULL to allocate default one. | ||
| 279 | * | 276 | * |
| 280 | * Returns, on success, a newly created dma_buf object, which wraps the | 277 | * Returns, on success, a newly created dma_buf object, which wraps the |
| 281 | * supplied private data and operations for dma_buf_ops. On either missing | 278 | * supplied private data and operations for dma_buf_ops. On either missing |
| 282 | * ops, or error in allocating struct dma_buf, will return negative error. | 279 | * ops, or error in allocating struct dma_buf, will return negative error. |
| 283 | * | 280 | * |
| 284 | */ | 281 | */ |
| 285 | struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops, | 282 | struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) |
| 286 | size_t size, int flags, const char *exp_name, | ||
| 287 | struct reservation_object *resv) | ||
| 288 | { | 283 | { |
| 289 | struct dma_buf *dmabuf; | 284 | struct dma_buf *dmabuf; |
| 285 | struct reservation_object *resv = exp_info->resv; | ||
| 290 | struct file *file; | 286 | struct file *file; |
| 291 | size_t alloc_size = sizeof(struct dma_buf); | 287 | size_t alloc_size = sizeof(struct dma_buf); |
| 292 | if (!resv) | 288 | if (!exp_info->resv) |
| 293 | alloc_size += sizeof(struct reservation_object); | 289 | alloc_size += sizeof(struct reservation_object); |
| 294 | else | 290 | else |
| 295 | /* prevent &dma_buf[1] == dma_buf->resv */ | 291 | /* prevent &dma_buf[1] == dma_buf->resv */ |
| 296 | alloc_size += 1; | 292 | alloc_size += 1; |
| 297 | 293 | ||
| 298 | if (WARN_ON(!priv || !ops | 294 | if (WARN_ON(!exp_info->priv |
| 299 | || !ops->map_dma_buf | 295 | || !exp_info->ops |
| 300 | || !ops->unmap_dma_buf | 296 | || !exp_info->ops->map_dma_buf |
| 301 | || !ops->release | 297 | || !exp_info->ops->unmap_dma_buf |
| 302 | || !ops->kmap_atomic | 298 | || !exp_info->ops->release |
| 303 | || !ops->kmap | 299 | || !exp_info->ops->kmap_atomic |
| 304 | || !ops->mmap)) { | 300 | || !exp_info->ops->kmap |
| 301 | || !exp_info->ops->mmap)) { | ||
| 305 | return ERR_PTR(-EINVAL); | 302 | return ERR_PTR(-EINVAL); |
| 306 | } | 303 | } |
| 307 | 304 | ||
| @@ -309,10 +306,10 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops, | |||
| 309 | if (dmabuf == NULL) | 306 | if (dmabuf == NULL) |
| 310 | return ERR_PTR(-ENOMEM); | 307 | return ERR_PTR(-ENOMEM); |
| 311 | 308 | ||
| 312 | dmabuf->priv = priv; | 309 | dmabuf->priv = exp_info->priv; |
| 313 | dmabuf->ops = ops; | 310 | dmabuf->ops = exp_info->ops; |
| 314 | dmabuf->size = size; | 311 | dmabuf->size = exp_info->size; |
| 315 | dmabuf->exp_name = exp_name; | 312 | dmabuf->exp_name = exp_info->exp_name; |
| 316 | init_waitqueue_head(&dmabuf->poll); | 313 | init_waitqueue_head(&dmabuf->poll); |
| 317 | dmabuf->cb_excl.poll = dmabuf->cb_shared.poll = &dmabuf->poll; | 314 | dmabuf->cb_excl.poll = dmabuf->cb_shared.poll = &dmabuf->poll; |
| 318 | dmabuf->cb_excl.active = dmabuf->cb_shared.active = 0; | 315 | 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, | |||
| 323 | } | 320 | } |
| 324 | dmabuf->resv = resv; | 321 | dmabuf->resv = resv; |
| 325 | 322 | ||
| 326 | file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags); | 323 | file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, |
| 324 | exp_info->flags); | ||
| 327 | if (IS_ERR(file)) { | 325 | if (IS_ERR(file)) { |
| 328 | kfree(dmabuf); | 326 | kfree(dmabuf); |
| 329 | return ERR_CAST(file); | 327 | return ERR_CAST(file); |
| @@ -341,8 +339,7 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops, | |||
| 341 | 339 | ||
| 342 | return dmabuf; | 340 | return dmabuf; |
| 343 | } | 341 | } |
| 344 | EXPORT_SYMBOL_GPL(dma_buf_export_named); | 342 | EXPORT_SYMBOL_GPL(dma_buf_export); |
| 345 | |||
| 346 | 343 | ||
| 347 | /** | 344 | /** |
| 348 | * dma_buf_fd - returns a file descriptor for the given dma_buf | 345 | * dma_buf_fd - returns a file descriptor for the given dma_buf |
