diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 0499be80d23d..bf18aa205fdf 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -393,6 +393,24 @@ static char *dma_heap_devnode(const struct device *dev, umode_t *mode) return kasprintf(GFP_KERNEL, "dma_heap/%s", dev_name(dev)); } +long dma_heap_try_get_pool_size_kb(void) +{ + struct dma_heap *heap; + u64 total_pool_size = 0; + + if (!mutex_trylock(&heap_list_lock)) + return -1; + + list_for_each_entry(heap, &heap_list, list) { + if (heap->ops->get_pool_size) + total_pool_size += heap->ops->get_pool_size(heap); + } + mutex_unlock(&heap_list_lock); + + return (long)(total_pool_size / 1024); +} +EXPORT_SYMBOL_GPL(dma_heap_try_get_pool_size_kb); + static ssize_t total_pools_kb_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index c31af802ea86..15bd3a7cd24d 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -109,4 +109,11 @@ void dma_heap_buffer_free(struct dma_buf *); int dma_heap_bufferfd_alloc(struct dma_heap *heap, size_t len, unsigned int fd_flags, unsigned int heap_flags); + +/** + * dma_heap_try_get_pool_size_kb - Returns total dma-heap pool size in kb + * if there is no lock contention. The pool size will always be 0 if no heaps + * use pools, or do not implement get_pool_size. + **/ +long dma_heap_try_get_pool_size_kb(void); #endif /* _DMA_HEAPS_H */