From bd9bcc81d2fbfd777939b8eecbc648f84e974979 Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Tue, 7 Jun 2016 19:28:17 -0700 Subject: ion: ion_system_heap: Add an access method for pool size Allow the system secure heap to read the pool size for a particular vmid to determine the maximum size which can be freed by the DRAIN IOCTL. Change-Id: If96265753c6d2c1f210e1961ec7d6ebf8612dd37 Signed-off-by: Patrick Daly --- drivers/staging/android/ion/ion_priv.h | 1 + drivers/staging/android/ion/ion_system_heap.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 69da287c064f..b687675be02f 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -448,6 +448,7 @@ void *ion_page_pool_alloc_pool_only(struct ion_page_pool *); void ion_page_pool_free(struct ion_page_pool *, struct page *); void ion_page_pool_free_immediate(struct ion_page_pool *, struct page *); int ion_page_pool_total(struct ion_page_pool *pool, bool high); +size_t ion_system_heap_secure_page_pool_total(struct ion_heap *heap, int vmid); #ifdef CONFIG_ION_POOL_CACHE_POLICY static inline void ion_page_pool_alloc_set_cache_policy diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 981cb2f622cb..fd4d45ad8db2 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -74,6 +74,31 @@ struct page_info { struct list_head list; }; +/* + * Used by ion_system_secure_heap only + * Since no lock is held, results are approximate. + */ +size_t ion_system_heap_secure_page_pool_total(struct ion_heap *heap, + int vmid_flags) +{ + struct ion_system_heap *sys_heap; + struct ion_page_pool *pool; + size_t total = 0; + int vmid, i; + + sys_heap = container_of(heap, struct ion_system_heap, heap); + vmid = get_secure_vmid(vmid_flags); + if (!is_secure_vmid_valid(vmid)) + return 0; + + for (i = 0; i < num_orders; i++) { + pool = sys_heap->secure_pools[vmid][i]; + total += ion_page_pool_total(pool, true); + } + + return total << PAGE_SHIFT; +} + static struct page *alloc_buffer_page(struct ion_system_heap *heap, struct ion_buffer *buffer, unsigned long order, -- cgit v1.2.3