1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * ION Memory Allocator - Internal header 4 * 5 * Copyright (C) 2019 Google, Inc. 6 */ 7 8 #ifndef _ION_PRIVATE_H 9 #define _ION_PRIVATE_H 10 11 #include <linux/dcache.h> 12 #include <linux/dma-buf.h> 13 #include <linux/ion.h> 14 #include <linux/miscdevice.h> 15 #include <linux/mutex.h> 16 #include <linux/plist.h> 17 #include <linux/rbtree.h> 18 #include <linux/rwsem.h> 19 #include <linux/types.h> 20 21 /** 22 * struct ion_device - the metadata of the ion device node 23 * @dev: the actual misc device 24 * @lock: rwsem protecting the tree of heaps, heap_bitmap and 25 * clients 26 * @heap_ids: bitmap of register heap ids 27 */ 28 struct ion_device { 29 struct miscdevice dev; 30 struct rw_semaphore lock; 31 DECLARE_BITMAP(heap_ids, ION_NUM_MAX_HEAPS); 32 struct plist_head heaps; 33 struct dentry *debug_root; 34 int heap_cnt; 35 }; 36 37 /* ion_buffer manipulators */ 38 extern struct ion_buffer *ion_buffer_alloc(struct ion_device *dev, size_t len, 39 unsigned int heap_id_mask, 40 unsigned int flags); 41 extern void ion_buffer_release(struct ion_buffer *buffer); 42 extern int ion_buffer_destroy(struct ion_device *dev, 43 struct ion_buffer *buffer); 44 extern void *ion_buffer_kmap_get(struct ion_buffer *buffer); 45 extern void ion_buffer_kmap_put(struct ion_buffer *buffer); 46 47 /* ion dmabuf allocator */ 48 extern struct dma_buf *ion_dmabuf_alloc(struct ion_device *dev, size_t len, 49 unsigned int heap_id_mask, 50 unsigned int flags); 51 extern int ion_free(struct ion_buffer *buffer); 52 53 /* ion heap helpers */ 54 extern int ion_heap_cleanup(struct ion_heap *heap); 55 56 u64 ion_get_total_heap_bytes(void); 57 58 #endif /* _ION_PRIVATE_H */ 59