X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=lib%2Fgenalloc.c;h=dda31168844f42c9c6fe2f9c9d25526e30884529;hb=db0b2d01163cc3050eb52a979541e0d16553be48;hp=26cf20be72b74013dd874abc551c3f9a412bc1b6;hpb=7c6a4acc645cdd938300d5f9bb367f72170af310;p=mirror_ubuntu-bionic-kernel.git diff --git a/lib/genalloc.c b/lib/genalloc.c index 26cf20be72b7..dda31168844f 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c @@ -312,6 +312,34 @@ retry: } EXPORT_SYMBOL(gen_pool_alloc); +/** + * gen_pool_dma_alloc - allocate special memory from the pool for DMA usage + * @pool: pool to allocate from + * @size: number of bytes to allocate from the pool + * @dma: dma-view physical address + * + * Allocate the requested number of bytes from the specified pool. + * Uses the pool allocation function (with first-fit algorithm by default). + * Can not be used in NMI handler on architectures without + * NMI-safe cmpxchg implementation. + */ +void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma) +{ + unsigned long vaddr; + + if (!pool) + return NULL; + + vaddr = gen_pool_alloc(pool, size); + if (!vaddr) + return NULL; + + *dma = gen_pool_virt_to_phys(pool, vaddr); + + return (void *)vaddr; +} +EXPORT_SYMBOL(gen_pool_dma_alloc); + /** * gen_pool_free - free allocated special memory back to the pool * @pool: pool to free to