diff --git a/drivers/dma-buf/heaps/page_pool.c b/drivers/dma-buf/heaps/page_pool.c index 7d46c36d96a7..831fea60176b 100644 --- a/drivers/dma-buf/heaps/page_pool.c +++ b/drivers/dma-buf/heaps/page_pool.c @@ -16,6 +16,35 @@ #include #include +/* page types we track in the pool */ +enum { + POOL_LOWPAGE, /* Clean lowmem pages */ + POOL_HIGHPAGE, /* Clean highmem pages */ + + POOL_TYPE_SIZE, +}; + +/** + * struct dmabuf_page_pool - pagepool struct + * @count[]: array of number of pages of that type in the pool + * @items[]: array of list of pages of the specific type + * @lock: lock protecting this struct and especially the count + * item list + * @gfp_mask: gfp_mask to use from alloc + * @order: order of pages in the pool + * @list: list node for list of pools + * + * Allows you to keep a pool of pre allocated pages to use + */ +struct dmabuf_page_pool { + int count[POOL_TYPE_SIZE]; + struct list_head items[POOL_TYPE_SIZE]; + struct spinlock lock; + gfp_t gfp_mask; + unsigned int order; + struct list_head list; +}; + static LIST_HEAD(pool_list); static DEFINE_MUTEX(pool_list_lock); @@ -158,6 +187,21 @@ void dmabuf_page_pool_destroy(struct dmabuf_page_pool *pool) } EXPORT_SYMBOL_GPL(dmabuf_page_pool_destroy); +unsigned long dmabuf_page_pool_get_size(struct dmabuf_page_pool *pool) +{ + int i; + unsigned long num_pages = 0; + + spin_lock(&pool->lock); + for (i = 0; i < POOL_TYPE_SIZE; ++i) + num_pages += pool->count[i]; + spin_unlock(&pool->lock); + num_pages <<= pool->order; /* pool order is immutable */ + + return num_pages * PAGE_SIZE; +} +EXPORT_SYMBOL_GPL(dmabuf_page_pool_get_size); + static int dmabuf_page_pool_do_shrink(struct dmabuf_page_pool *pool, gfp_t gfp_mask, int nr_to_scan) { diff --git a/drivers/dma-buf/heaps/page_pool.h b/drivers/dma-buf/heaps/page_pool.h index 891adee7491f..5f6f938fa5d9 100644 --- a/drivers/dma-buf/heaps/page_pool.h +++ b/drivers/dma-buf/heaps/page_pool.h @@ -11,37 +11,9 @@ #define _DMABUF_PAGE_POOL_H #include -#include #include -/* page types we track in the pool */ -enum { - POOL_LOWPAGE, /* Clean lowmem pages */ - POOL_HIGHPAGE, /* Clean highmem pages */ - - POOL_TYPE_SIZE, -}; - -/** - * struct dmabuf_page_pool - pagepool struct - * @count[]: array of number of pages of that type in the pool - * @items[]: array of list of pages of the specific type - * @lock: lock protecting this struct and especially the count - * item list - * @gfp_mask: gfp_mask to use from alloc - * @order: order of pages in the pool - * @list: list node for list of pools - * - * Allows you to keep a pool of pre allocated pages to use - */ -struct dmabuf_page_pool { - int count[POOL_TYPE_SIZE]; - struct list_head items[POOL_TYPE_SIZE]; - struct spinlock lock; - gfp_t gfp_mask; - unsigned int order; - struct list_head list; -}; +struct dmabuf_page_pool; struct dmabuf_page_pool *dmabuf_page_pool_create(gfp_t gfp_mask, unsigned int order); @@ -49,4 +21,7 @@ void dmabuf_page_pool_destroy(struct dmabuf_page_pool *pool); struct page *dmabuf_page_pool_alloc(struct dmabuf_page_pool *pool); void dmabuf_page_pool_free(struct dmabuf_page_pool *pool, struct page *page); +/* get pool size in bytes */ +unsigned long dmabuf_page_pool_get_size(struct dmabuf_page_pool *pool); + #endif /* _DMABUF_PAGE_POOL_H */ diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 3971676aa789..b7e78e497493 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -493,16 +493,13 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, static long system_get_pool_size(struct dma_heap *heap) { int i; - long num_pages = 0; - struct dmabuf_page_pool **pool; + unsigned long num_bytes = 0; + struct dmabuf_page_pool **pool = pools; - pool = pools; - for (i = 0; i < NUM_ORDERS; i++, pool++) { - num_pages += ((*pool)->count[POOL_LOWPAGE] + - (*pool)->count[POOL_HIGHPAGE]) << (*pool)->order; - } + for (i = 0; i < NUM_ORDERS; i++, pool++) + num_bytes += dmabuf_page_pool_get_size(*pool); - return num_pages << PAGE_SHIFT; + return num_bytes; } static const struct dma_heap_ops system_heap_ops = {