diff --git a/drivers/staging/android/ion/heaps/ion_cma_heap.c b/drivers/staging/android/ion/heaps/ion_cma_heap.c index 0872e5d630f8..83f7dce74f18 100644 --- a/drivers/staging/android/ion/heaps/ion_cma_heap.c +++ b/drivers/staging/android/ion/heaps/ion_cma_heap.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -14,8 +15,6 @@ #include #include -#include "../ion.h" - struct ion_cma_heap { struct ion_heap heap; struct cma *cma; diff --git a/drivers/staging/android/ion/heaps/ion_system_heap.c b/drivers/staging/android/ion/heaps/ion_system_heap.c index f6e20892499f..3d072dd015ba 100644 --- a/drivers/staging/android/ion/heaps/ion_system_heap.c +++ b/drivers/staging/android/ion/heaps/ion_system_heap.c @@ -9,12 +9,12 @@ #include #include #include +#include #include #include #include #include -#include "../ion.h" #include "ion_page_pool.h" #define NUM_ORDERS ARRAY_SIZE(orders) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 0f5884f37411..6a9f01ec4aed 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -246,7 +246,6 @@ void ion_device_add_heap(struct ion_heap *heap) pr_err("%s: Failed to register shrinker\n", __func__); } - heap->dev = dev; heap->num_of_buffers = 0; heap->num_of_alloc_bytes = 0; heap->alloc_bytes_wm = 0; diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h deleted file mode 100644 index 6b7727f5736e..000000000000 --- a/drivers/staging/android/ion/ion.h +++ /dev/null @@ -1,248 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * ION Memory Allocator kernel interface header - * - * Copyright (C) 2011 Google, Inc. - */ - -#ifndef _ION_H -#define _ION_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../uapi/ion.h" - -/** - * struct ion_buffer - metadata for a particular buffer - * @node: node in the ion_device buffers tree - * @list: element in list of deferred freeable buffers - * @dev: back pointer to the ion_device - * @heap: back pointer to the heap the buffer came from - * @flags: buffer specific flags - * @private_flags: internal buffer specific flags - * @size: size of the buffer - * @priv_virt: private data to the buffer representable as - * a void * - * @lock: protects the buffers cnt fields - * @kmap_cnt: number of times the buffer is mapped to the kernel - * @vaddr: the kernel mapping if kmap_cnt is not zero - * @sg_table: the sg table for the buffer - * @attachments: list of devices attached to this buffer - */ -struct ion_buffer { - union { - struct rb_node node; - struct list_head list; - }; - struct ion_heap *heap; - unsigned long flags; - unsigned long private_flags; - size_t size; - void *priv_virt; - struct mutex lock; - int kmap_cnt; - void *vaddr; - struct sg_table *sg_table; - struct list_head attachments; -}; - -/** - * struct ion_heap_ops - ops to operate on a given heap - * @allocate: allocate memory - * @free: free memory - * @map_kernel map memory to the kernel - * @unmap_kernel unmap memory to the kernel - * @map_user map memory to userspace - * - * allocate, phys, and map_user return 0 on success, -errno on error. - * map_dma and map_kernel return pointer on success, ERR_PTR on - * error. @free will be called with ION_PRIV_FLAG_SHRINKER_FREE set in - * the buffer's private_flags when called from a shrinker. In that - * case, the pages being free'd must be truly free'd back to the - * system, not put in a page pool or otherwise cached. - */ -struct ion_heap_ops { - int (*allocate)(struct ion_heap *heap, - struct ion_buffer *buffer, unsigned long len, - unsigned long flags); - void (*free)(struct ion_buffer *buffer); - void * (*map_kernel)(struct ion_heap *heap, struct ion_buffer *buffer); - void (*unmap_kernel)(struct ion_heap *heap, struct ion_buffer *buffer); - int (*map_user)(struct ion_heap *mapper, struct ion_buffer *buffer, - struct vm_area_struct *vma); - int (*shrink)(struct ion_heap *heap, gfp_t gfp_mask, int nr_to_scan); -}; - -/** - * heap flags - flags between the heaps and core ion code - */ -#define ION_HEAP_FLAG_DEFER_FREE BIT(0) - -/** - * private flags - flags internal to ion - */ -/* - * Buffer is being freed from a shrinker function. Skip any possible - * heap-specific caching mechanism (e.g. page pools). Guarantees that - * any buffer storage that came from the system allocator will be - * returned to the system allocator. - */ -#define ION_PRIV_FLAG_SHRINKER_FREE BIT(0) - -/** - * struct ion_heap - represents a heap in the system - * @node: rb node to put the heap on the device's tree of heaps - * @dev: back pointer to the ion_device - * @type: type of heap - * @ops: ops struct as above - * @flags: flags - * @id: id of heap, also indicates priority of this heap when - * allocating. These are specified by platform data and - * MUST be unique - * @name: used for debugging - * @shrinker: a shrinker for the heap - * @free_list: free list head if deferred free is used - * @free_list_size size of the deferred free list in bytes - * @lock: protects the free list - * @waitqueue: queue to wait on from deferred free thread - * @task: task struct of deferred free thread - * @num_of_buffers the number of currently allocated buffers - * @num_of_alloc_bytes the number of allocated bytes - * @alloc_bytes_wm the number of allocated bytes watermark - * - * Represents a pool of memory from which buffers can be made. In some - * systems the only heap is regular system memory allocated via vmalloc. - * On others, some blocks might require large physically contiguous buffers - * that are allocated from a specially reserved heap. - */ -struct ion_heap { - struct plist_node node; - struct ion_device *dev; - enum ion_heap_type type; - struct ion_heap_ops *ops; - unsigned long flags; - unsigned int id; - const char *name; - - /* deferred free support */ - struct shrinker shrinker; - struct list_head free_list; - size_t free_list_size; - spinlock_t free_lock; - wait_queue_head_t waitqueue; - struct task_struct *task; - - /* heap statistics */ - u64 num_of_buffers; - u64 num_of_alloc_bytes; - u64 alloc_bytes_wm; - - /* protect heap statistics */ - spinlock_t stat_lock; -}; - -/** - * ion_device_add_heap - adds a heap to the ion device - * @heap: the heap to add - */ -void ion_device_add_heap(struct ion_heap *heap); - -/* ion_buffer_zero - zeroes out an ion buffer respecting the ION_FLAGs. - * - * @buffer: ion_buffer to zero - * - * Returns 0 on success, negative error otherwise. - */ -int ion_buffer_zero(struct ion_buffer *buffer); - -/** - * some helpers for common operations on buffers using the sg_table - * and vaddr fields - */ -void *ion_heap_map_kernel(struct ion_heap *heap, struct ion_buffer *buffer); -void ion_heap_unmap_kernel(struct ion_heap *heap, struct ion_buffer *buffer); -int ion_heap_map_user(struct ion_heap *heap, struct ion_buffer *buffer, - struct vm_area_struct *vma); -int ion_heap_pages_zero(struct page *page, size_t size, pgprot_t pgprot); -int ion_heap_sglist_zero(struct scatterlist *sgl, unsigned int nents, - pgprot_t pgprot); - -/** - * ion_heap_init_shrinker - * @heap: the heap - * - * If a heap sets the ION_HEAP_FLAG_DEFER_FREE flag or defines the shrink op - * this function will be called to setup a shrinker to shrink the freelists - * and call the heap's shrink op. - */ -int ion_heap_init_shrinker(struct ion_heap *heap); - -/** - * ion_heap_init_deferred_free -- initialize deferred free functionality - * @heap: the heap - * - * If a heap sets the ION_HEAP_FLAG_DEFER_FREE flag this function will - * be called to setup deferred frees. Calls to free the buffer will - * return immediately and the actual free will occur some time later - */ -int ion_heap_init_deferred_free(struct ion_heap *heap); - -/** - * ion_heap_freelist_add - add a buffer to the deferred free list - * @heap: the heap - * @buffer: the buffer - * - * Adds an item to the deferred freelist. - */ -void ion_heap_freelist_add(struct ion_heap *heap, struct ion_buffer *buffer); - -/** - * ion_heap_freelist_drain - drain the deferred free list - * @heap: the heap - * @size: amount of memory to drain in bytes - * - * Drains the indicated amount of memory from the deferred freelist immediately. - * Returns the total amount freed. The total freed may be higher depending - * on the size of the items in the list, or lower if there is insufficient - * total memory on the freelist. - */ -size_t ion_heap_freelist_drain(struct ion_heap *heap, size_t size); - -/** - * ion_heap_freelist_shrink - drain the deferred free - * list, skipping any heap-specific - * pooling or caching mechanisms - * - * @heap: the heap - * @size: amount of memory to drain in bytes - * - * Drains the indicated amount of memory from the deferred freelist immediately. - * Returns the total amount freed. The total freed may be higher depending - * on the size of the items in the list, or lower if there is insufficient - * total memory on the freelist. - * - * Unlike with @ion_heap_freelist_drain, don't put any pages back into - * page pools or otherwise cache the pages. Everything must be - * genuinely free'd back to the system. If you're free'ing from a - * shrinker you probably want to use this. Note that this relies on - * the heap.ops.free callback honoring the ION_PRIV_FLAG_SHRINKER_FREE - * flag. - */ -size_t ion_heap_freelist_shrink(struct ion_heap *heap, - size_t size); - -/** - * ion_heap_freelist_size - returns the size of the freelist in bytes - * @heap: the heap - */ -size_t ion_heap_freelist_size(struct ion_heap *heap); - -#endif /* _ION_H */ diff --git a/drivers/staging/android/ion/ion_buffer.c b/drivers/staging/android/ion/ion_buffer.c index 50c2dbc3ebec..adce2d489f56 100644 --- a/drivers/staging/android/ion/ion_buffer.c +++ b/drivers/staging/android/ion/ion_buffer.c @@ -92,6 +92,41 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, return ERR_PTR(ret); } +static int ion_clear_pages(struct page **pages, int num, pgprot_t pgprot) +{ + void *addr = vm_map_ram(pages, num, -1, pgprot); + + if (!addr) + return -ENOMEM; + memset(addr, 0, PAGE_SIZE * num); + vm_unmap_ram(addr, num); + + return 0; +} + +static int ion_sglist_zero(struct scatterlist *sgl, unsigned int nents, + pgprot_t pgprot) +{ + int p = 0; + int ret = 0; + struct sg_page_iter piter; + struct page *pages[32]; + + for_each_sg_page(sgl, &piter, nents, 0) { + pages[p++] = sg_page_iter_page(&piter); + if (p == ARRAY_SIZE(pages)) { + ret = ion_clear_pages(pages, p, pgprot); + if (ret) + return ret; + p = 0; + } + } + if (p) + ret = ion_clear_pages(pages, p, pgprot); + + return ret; +} + struct ion_buffer *ion_buffer_alloc(struct ion_device *dev, size_t len, unsigned int heap_id_mask, unsigned int flags) @@ -147,7 +182,7 @@ int ion_buffer_zero(struct ion_buffer *buffer) else pgprot = pgprot_writecombine(PAGE_KERNEL); - return ion_heap_sglist_zero(table->sgl, table->nents, pgprot); + return ion_sglist_zero(table->sgl, table->nents, pgprot); } void ion_buffer_release(struct ion_buffer *buffer) diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c index 39eb60e4842e..755548a4382d 100644 --- a/drivers/staging/android/ion/ion_heap.c +++ b/drivers/staging/android/ion/ion_heap.c @@ -61,18 +61,6 @@ static unsigned long ion_heap_shrink_scan(struct shrinker *shrinker, return freed; } -static int ion_heap_clear_pages(struct page **pages, int num, pgprot_t pgprot) -{ - void *addr = vm_map_ram(pages, num, -1, pgprot); - - if (!addr) - return -ENOMEM; - memset(addr, 0, PAGE_SIZE * num); - vm_unmap_ram(addr, num); - - return 0; -} - static size_t _ion_heap_freelist_drain(struct ion_heap *heap, size_t size, bool skip_pools) { @@ -211,38 +199,6 @@ int ion_heap_map_user(struct ion_heap *heap, struct ion_buffer *buffer, return 0; } -int ion_heap_sglist_zero(struct scatterlist *sgl, unsigned int nents, - pgprot_t pgprot) -{ - int p = 0; - int ret = 0; - struct sg_page_iter piter; - struct page *pages[32]; - - for_each_sg_page(sgl, &piter, nents, 0) { - pages[p++] = sg_page_iter_page(&piter); - if (p == ARRAY_SIZE(pages)) { - ret = ion_heap_clear_pages(pages, p, pgprot); - if (ret) - return ret; - p = 0; - } - } - if (p) - ret = ion_heap_clear_pages(pages, p, pgprot); - - return ret; -} - -int ion_heap_pages_zero(struct page *page, size_t size, pgprot_t pgprot) -{ - struct scatterlist sg; - - sg_init_table(&sg, 1); - sg_set_page(&sg, page, size, 0); - return ion_heap_sglist_zero(&sg, 1, pgprot); -} - void ion_heap_freelist_add(struct ion_heap *heap, struct ion_buffer *buffer) { spin_lock(&heap->free_lock); diff --git a/drivers/staging/android/ion/ion_private.h b/drivers/staging/android/ion/ion_private.h index 9c8f482cd9d2..ed7ed39d0df1 100644 --- a/drivers/staging/android/ion/ion_private.h +++ b/drivers/staging/android/ion/ion_private.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -17,8 +18,6 @@ #include #include -#include "ion.h" - /** * struct ion_device - the metadata of the ion device node * @dev: the actual misc device diff --git a/include/linux/ion.h b/include/linux/ion.h index 66a694b875ca..775e948a362c 100644 --- a/include/linux/ion.h +++ b/include/linux/ion.h @@ -8,9 +8,264 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * struct ion_buffer - metadata for a particular buffer + * @node: node in the ion_device buffers tree + * @list: element in list of deferred freeable buffers + * @heap: back pointer to the heap the buffer came from + * @flags: buffer specific flags + * @private_flags: internal buffer specific flags + * @size: size of the buffer + * @priv_virt: private data to the buffer representable as + * a void * + * @lock: protects the buffers cnt fields + * @kmap_cnt: number of times the buffer is mapped to the kernel + * @vaddr: the kernel mapping if kmap_cnt is not zero + * @sg_table: the sg table for the buffer + * @attachments: list of devices attached to this buffer + */ +struct ion_buffer { + union { + struct rb_node node; + struct list_head list; + }; + struct ion_heap *heap; + unsigned long flags; + unsigned long private_flags; + size_t size; + void *priv_virt; + struct mutex lock; + int kmap_cnt; + void *vaddr; + struct sg_table *sg_table; + struct list_head attachments; +}; + +/** + * struct ion_heap_ops - ops to operate on a given heap + * @allocate: allocate memory + * @free: free memory + * @map_kernel map memory to the kernel + * @unmap_kernel unmap memory to the kernel + * @map_user map memory to userspace + * + * allocate, phys, and map_user return 0 on success, -errno on error. + * map_dma and map_kernel return pointer on success, ERR_PTR on + * error. @free will be called with ION_PRIV_FLAG_SHRINKER_FREE set in + * the buffer's private_flags when called from a shrinker. In that + * case, the pages being free'd must be truly free'd back to the + * system, not put in a page pool or otherwise cached. + */ +struct ion_heap_ops { + int (*allocate)(struct ion_heap *heap, + struct ion_buffer *buffer, unsigned long len, + unsigned long flags); + void (*free)(struct ion_buffer *buffer); + void * (*map_kernel)(struct ion_heap *heap, struct ion_buffer *buffer); + void (*unmap_kernel)(struct ion_heap *heap, struct ion_buffer *buffer); + int (*map_user)(struct ion_heap *mapper, struct ion_buffer *buffer, + struct vm_area_struct *vma); + int (*shrink)(struct ion_heap *heap, gfp_t gfp_mask, int nr_to_scan); +}; + +/** + * heap flags - flags between the heaps and core ion code + */ +#define ION_HEAP_FLAG_DEFER_FREE BIT(0) + +/** + * private flags - flags internal to ion + */ +/* + * Buffer is being freed from a shrinker function. Skip any possible + * heap-specific caching mechanism (e.g. page pools). Guarantees that + * any buffer storage that came from the system allocator will be + * returned to the system allocator. + */ +#define ION_PRIV_FLAG_SHRINKER_FREE BIT(0) + +/** + * struct ion_heap - represents a heap in the system + * @node: rb node to put the heap on the device's tree of heaps + * @type: type of heap + * @ops: ops struct as above + * @flags: flags + * @id: id of heap, also indicates priority of this heap when + * allocating. These are specified by platform data and + * MUST be unique + * @name: used for debugging + * @shrinker: a shrinker for the heap + * @free_list: free list head if deferred free is used + * @free_list_size size of the deferred free list in bytes + * @lock: protects the free list + * @waitqueue: queue to wait on from deferred free thread + * @task: task struct of deferred free thread + * @num_of_buffers the number of currently allocated buffers + * @num_of_alloc_bytes the number of allocated bytes + * @alloc_bytes_wm the number of allocated bytes watermark + * + * Represents a pool of memory from which buffers can be made. In some + * systems the only heap is regular system memory allocated via vmalloc. + * On others, some blocks might require large physically contiguous buffers + * that are allocated from a specially reserved heap. + */ +struct ion_heap { + struct plist_node node; + enum ion_heap_type type; + struct ion_heap_ops *ops; + unsigned long flags; + unsigned int id; + const char *name; + + /* deferred free support */ + struct shrinker shrinker; + struct list_head free_list; + size_t free_list_size; + spinlock_t free_lock; + wait_queue_head_t waitqueue; + struct task_struct *task; + + /* heap statistics */ + u64 num_of_buffers; + u64 num_of_alloc_bytes; + u64 alloc_bytes_wm; + + /* protect heap statistics */ + spinlock_t stat_lock; +}; #ifdef CONFIG_ION +/** + * ion_device_add_heap - adds a heap to the ion device + * + * @heap: the heap to add + */ +void ion_device_add_heap(struct ion_heap *heap); + +/** + * ion_heap_init_shrinker + * @heap: the heap + * + * If a heap sets the ION_HEAP_FLAG_DEFER_FREE flag or defines the shrink op + * this function will be called to setup a shrinker to shrink the freelists + * and call the heap's shrink op. + */ +int ion_heap_init_shrinker(struct ion_heap *heap); + +/** + * ion_heap_init_deferred_free -- initialize deferred free functionality + * @heap: the heap + * + * If a heap sets the ION_HEAP_FLAG_DEFER_FREE flag this function will + * be called to setup deferred frees. Calls to free the buffer will + * return immediately and the actual free will occur some time later + */ +int ion_heap_init_deferred_free(struct ion_heap *heap); + +/** + * ion_heap_freelist_add - add a buffer to the deferred free list + * @heap: the heap + * @buffer: the buffer + * + * Adds an item to the deferred freelist. + */ +void ion_heap_freelist_add(struct ion_heap *heap, struct ion_buffer *buffer); + +/** + * ion_heap_freelist_drain - drain the deferred free list + * @heap: the heap + * @size: amount of memory to drain in bytes + * + * Drains the indicated amount of memory from the deferred freelist immediately. + * Returns the total amount freed. The total freed may be higher depending + * on the size of the items in the list, or lower if there is insufficient + * total memory on the freelist. + */ +size_t ion_heap_freelist_drain(struct ion_heap *heap, size_t size); + +/** + * ion_heap_freelist_shrink - drain the deferred free + * list, skipping any heap-specific + * pooling or caching mechanisms + * + * @heap: the heap + * @size: amount of memory to drain in bytes + * + * Drains the indicated amount of memory from the deferred freelist immediately. + * Returns the total amount freed. The total freed may be higher depending + * on the size of the items in the list, or lower if there is insufficient + * total memory on the freelist. + * + * Unlike with @ion_heap_freelist_drain, don't put any pages back into + * page pools or otherwise cache the pages. Everything must be + * genuinely free'd back to the system. If you're free'ing from a + * shrinker you probably want to use this. Note that this relies on + * the heap.ops.free callback honoring the ION_PRIV_FLAG_SHRINKER_FREE + * flag. + */ +size_t ion_heap_freelist_shrink(struct ion_heap *heap, + size_t size); + +/** + * ion_heap_freelist_size - returns the size of the freelist in bytes + * @heap: the heap + */ +size_t ion_heap_freelist_size(struct ion_heap *heap); + +/** + * ion_heap_map_kernel - map the ion_buffer in kernel virtual address space. + * + * @heap: the heap + * @buffer: buffer to be mapped + * + * Maps the buffer using vmap(). The function respects cache flags for the + * buffer and creates the page table entries accordingly. Returns virtual + * address at the beginning of the buffer or ERR_PTR. + */ +void *ion_heap_map_kernel(struct ion_heap *heap, struct ion_buffer *buffer); + +/** + * ion_heap_unmap_kernel - unmap ion_buffer + * + * @buffer: buffer to be unmapped + * + * ION wrapper for vunmap() of the ion buffer. + */ +void ion_heap_unmap_kernel(struct ion_heap *heap, struct ion_buffer *buffer); + +/** + * ion_heap_map_user - map given ion buffer in provided vma + * + * @heap: the heap this buffer belongs to + * @buffer: Ion buffer to be mapped + * @vma: vma of the process where buffer should be mapped. + * + * Maps the buffer using remap_pfn_range() into specific process's vma starting + * with vma->vm_start. The vma size is expected to be >= ion buffer size. + * If not, a partial buffer mapping may be created. Returns 0 on success. + */ +int ion_heap_map_user(struct ion_heap *heap, struct ion_buffer *buffer, + struct vm_area_struct *vma); + +/* ion_buffer_zero - zeroes out an ion buffer respecting the ION_FLAGs. + * + * @buffer: ion_buffer to zero + * + * Returns 0 on success, negative error otherwise. + */ +int ion_buffer_zero(struct ion_buffer *buffer); /** * ion_alloc - Allocates an ion buffer of given size from given heap @@ -27,12 +282,67 @@ struct dma_buf *ion_alloc(size_t len, unsigned int heap_id_mask, unsigned int flags); #else + +static inline int ion_device_add_heap(struct ion_heap *heap) +{ + return -ENODEV; +} + +static inline int ion_heap_init_shrinker(struct ion_heap *heap) +{ + return -ENODEV; +} + +static inline int ion_heap_init_deferred_free(struct ion_heap *heap) +{ + return -ENODEV; +} + +static inline void ion_heap_freelist_add(struct ion_heap *heap, + struct ion_buffer *buffer) {} + +static inline size_t ion_heap_freelist_drain(struct ion_heap *heap, size_t size) +{ + return -ENODEV; +} + +static inline size_t ion_heap_freelist_shrink(struct ion_heap *heap, + size_t size) +{ + return -ENODEV; +} + +static inline size_t ion_heap_freelist_size(struct ion_heap *heap) +{ + return -ENODEV; +} + +static inline void *ion_heap_map_kernel(struct ion_heap *heap, + struct ion_buffer *buffer) +{ + return ERR_PTR(-ENODEV); +} + +static inline void ion_heap_unmap_kernel(struct ion_heap *heap, + struct ion_buffer *buffer) {} + +static inline int ion_heap_map_user(struct ion_heap *heap, + struct ion_buffer *buffer, + struct vm_area_struct *vma) +{ + return -ENODEV; +} + +static inline int ion_buffer_zero(struct ion_buffer *buffer) +{ + return -EINVAL; +} + static inline struct dma_buf *ion_alloc(size_t len, unsigned int heap_id_mask, unsigned int flags) { return ERR_PTR(-ENOMEM); } - #endif /* CONFIG_ION */ #endif /* _ION_KERNEL_H */ diff --git a/drivers/staging/android/uapi/ion.h b/include/uapi/ion.h similarity index 74% rename from drivers/staging/android/uapi/ion.h rename to include/uapi/ion.h index 46c93fcb46d6..bfcbc0e70921 100644 --- a/drivers/staging/android/uapi/ion.h +++ b/include/uapi/ion.h @@ -13,26 +13,25 @@ /** * enum ion_heap_types - list of all possible types of heaps - * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc + * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc - * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved - * carveout heap, allocations are physically - * contiguous - * @ION_HEAP_TYPE_DMA: memory allocated via DMA API - * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask - * is used to identify the heaps, so only 32 - * total heap types are supported + * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved + * carveout heap, allocations are physically + * contiguous + * @ION_HEAP_TYPE_DMA: memory allocated via DMA API + * @ION_HEAP_TYPE_MAX: helper for iterating over standard + * (not device specific) heaps + * @ION_NUM_HEAPS_IDS: helper for iterating over heaps, a bit mask + * is used to identify the heaps, so only 32 + * total heap types are supported */ enum ion_heap_type { - ION_HEAP_TYPE_SYSTEM, - ION_HEAP_TYPE_SYSTEM_CONTIG, - ION_HEAP_TYPE_CARVEOUT, - ION_HEAP_TYPE_CHUNK, - ION_HEAP_TYPE_DMA, - ION_HEAP_TYPE_CUSTOM, /* - * must be last so device specific heaps always - * are at the end of this enum - */ + ION_HEAP_TYPE_SYSTEM = (1 << 0), + ION_HEAP_TYPE_SYSTEM_CONTIG = (1 << 1), + ION_HEAP_TYPE_CARVEOUT = (1 << 2), + ION_HEAP_TYPE_CHUNK = (1 << 3), + ION_HEAP_TYPE_DMA = (1 << 4), + ION_HEAP_TYPE_MAX = (1 << 15), }; #define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8) @@ -46,7 +45,7 @@ enum ion_heap_type { * mappings of this buffer should be cached, ion will do cache maintenance * when the buffer is mapped for dma */ -#define ION_FLAG_CACHED 1 +#define ION_FLAG_CACHED 1 /** * DOC: Ion Userspace API