diff options
Diffstat (limited to 'drivers/base/dmapool.c')
-rw-r--r-- | drivers/base/dmapool.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c index f95d50277274..cd467c9f33b3 100644 --- a/drivers/base/dmapool.c +++ b/drivers/base/dmapool.c | |||
@@ -415,8 +415,67 @@ dma_pool_free (struct dma_pool *pool, void *vaddr, dma_addr_t dma) | |||
415 | spin_unlock_irqrestore (&pool->lock, flags); | 415 | spin_unlock_irqrestore (&pool->lock, flags); |
416 | } | 416 | } |
417 | 417 | ||
418 | /* | ||
419 | * Managed DMA pool | ||
420 | */ | ||
421 | static void dmam_pool_release(struct device *dev, void *res) | ||
422 | { | ||
423 | struct dma_pool *pool = *(struct dma_pool **)res; | ||
424 | |||
425 | dma_pool_destroy(pool); | ||
426 | } | ||
427 | |||
428 | static int dmam_pool_match(struct device *dev, void *res, void *match_data) | ||
429 | { | ||
430 | return *(struct dma_pool **)res == match_data; | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * dmam_pool_create - Managed dma_pool_create() | ||
435 | * @name: name of pool, for diagnostics | ||
436 | * @dev: device that will be doing the DMA | ||
437 | * @size: size of the blocks in this pool. | ||
438 | * @align: alignment requirement for blocks; must be a power of two | ||
439 | * @allocation: returned blocks won't cross this boundary (or zero) | ||
440 | * | ||
441 | * Managed dma_pool_create(). DMA pool created with this function is | ||
442 | * automatically destroyed on driver detach. | ||
443 | */ | ||
444 | struct dma_pool *dmam_pool_create(const char *name, struct device *dev, | ||
445 | size_t size, size_t align, size_t allocation) | ||
446 | { | ||
447 | struct dma_pool **ptr, *pool; | ||
448 | |||
449 | ptr = devres_alloc(dmam_pool_release, sizeof(*ptr), GFP_KERNEL); | ||
450 | if (!ptr) | ||
451 | return NULL; | ||
452 | |||
453 | pool = *ptr = dma_pool_create(name, dev, size, align, allocation); | ||
454 | if (pool) | ||
455 | devres_add(dev, ptr); | ||
456 | else | ||
457 | devres_free(ptr); | ||
458 | |||
459 | return pool; | ||
460 | } | ||
461 | |||
462 | /** | ||
463 | * dmam_pool_destroy - Managed dma_pool_destroy() | ||
464 | * @pool: dma pool that will be destroyed | ||
465 | * | ||
466 | * Managed dma_pool_destroy(). | ||
467 | */ | ||
468 | void dmam_pool_destroy(struct dma_pool *pool) | ||
469 | { | ||
470 | struct device *dev = pool->dev; | ||
471 | |||
472 | dma_pool_destroy(pool); | ||
473 | WARN_ON(devres_destroy(dev, dmam_pool_release, dmam_pool_match, pool)); | ||
474 | } | ||
418 | 475 | ||
419 | EXPORT_SYMBOL (dma_pool_create); | 476 | EXPORT_SYMBOL (dma_pool_create); |
420 | EXPORT_SYMBOL (dma_pool_destroy); | 477 | EXPORT_SYMBOL (dma_pool_destroy); |
421 | EXPORT_SYMBOL (dma_pool_alloc); | 478 | EXPORT_SYMBOL (dma_pool_alloc); |
422 | EXPORT_SYMBOL (dma_pool_free); | 479 | EXPORT_SYMBOL (dma_pool_free); |
480 | EXPORT_SYMBOL (dmam_pool_create); | ||
481 | EXPORT_SYMBOL (dmam_pool_destroy); | ||