1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * drivers/staging/android/uapi/ion.h 4 * 5 * Copyright (C) 2011 Google, Inc. 6 */ 7 8 #ifndef _LINUX_ION_H 9 #define _LINUX_ION_H 10 11 #include <linux/ioctl.h> 12 #include <linux/types.h> 13 14 /** 15 * ion_heap_types - list of all possible types of heaps that Android can use 16 * 17 * @ION_HEAP_TYPE_SYSTEM: Reserved heap id for ion heap that allocates 18 * memory using alloc_page(). Also, supports 19 * deferred free and allocation pools. 20 * @ION_HEAP_TYPE_DMA: Reserved heap id for ion heap that manages 21 * single CMA (contiguous memory allocator) 22 * region. Uses standard DMA APIs for 23 * managing memory within the CMA region. 24 */ 25 enum ion_heap_type { 26 ION_HEAP_TYPE_SYSTEM = 0, 27 ION_HEAP_TYPE_DMA = 2, 28 /* reserved range for future standard heap types */ 29 ION_HEAP_TYPE_CUSTOM = 16, 30 ION_HEAP_TYPE_MAX = 31, 31 }; 32 33 /** 34 * ion_heap_id - list of standard heap ids that Android can use 35 * 36 * @ION_HEAP_SYSTEM Id for the ION_HEAP_TYPE_SYSTEM 37 * @ION_HEAP_DMA_START Start of reserved id range for heaps of type 38 * ION_HEAP_TYPE_DMA 39 * @ION_HEAP_DMA_END End of reserved id range for heaps of type 40 * ION_HEAP_TYPE_DMA 41 * @ION_HEAP_CUSTOM_START Start of reserved id range for heaps of custom 42 * type 43 * @ION_HEAP_CUSTOM_END End of reserved id range for heaps of custom 44 * type 45 */ 46 enum ion_heap_id { 47 ION_HEAP_SYSTEM = (1 << ION_HEAP_TYPE_SYSTEM), 48 ION_HEAP_DMA_START = (ION_HEAP_SYSTEM << 1), 49 ION_HEAP_DMA_END = (ION_HEAP_DMA_START << 7), 50 ION_HEAP_CUSTOM_START = (ION_HEAP_DMA_END << 1), 51 ION_HEAP_CUSTOM_END = (ION_HEAP_CUSTOM_START << 22), 52 }; 53 54 #define ION_NUM_MAX_HEAPS (32) 55 56 /** 57 * allocation flags - the lower 16 bits are used by core ion, the upper 16 58 * bits are reserved for use by the heaps themselves. 59 */ 60 61 /* 62 * mappings of this buffer should be cached, ion will do cache maintenance 63 * when the buffer is mapped for dma 64 */ 65 #define ION_FLAG_CACHED 1 66 67 /** 68 * DOC: Ion Userspace API 69 * 70 * create a client by opening /dev/ion 71 * most operations handled via following ioctls 72 * 73 */ 74 75 /** 76 * struct ion_allocation_data - metadata passed from userspace for allocations 77 * @len: size of the allocation 78 * @heap_id_mask: mask of heap ids to allocate from 79 * @flags: flags passed to heap 80 * @handle: pointer that will be populated with a cookie to use to 81 * refer to this allocation 82 * 83 * Provided by userspace as an argument to the ioctl 84 */ 85 struct ion_allocation_data { 86 __u64 len; 87 __u32 heap_id_mask; 88 __u32 flags; 89 __u32 fd; 90 __u32 unused; 91 }; 92 93 #define MAX_HEAP_NAME 32 94 95 /** 96 * struct ion_heap_data - data about a heap 97 * @name - first 32 characters of the heap name 98 * @type - heap type 99 * @heap_id - heap id for the heap 100 */ 101 struct ion_heap_data { 102 char name[MAX_HEAP_NAME]; 103 __u32 type; 104 __u32 heap_id; 105 __u32 reserved0; 106 __u32 reserved1; 107 __u32 reserved2; 108 }; 109 110 /** 111 * struct ion_heap_query - collection of data about all heaps 112 * @cnt - total number of heaps to be copied 113 * @heaps - buffer to copy heap data 114 */ 115 struct ion_heap_query { 116 __u32 cnt; /* Total number of heaps to be copied */ 117 __u32 reserved0; /* align to 64bits */ 118 __u64 heaps; /* buffer to be populated */ 119 __u32 reserved1; 120 __u32 reserved2; 121 }; 122 123 #define ION_IOC_MAGIC 'I' 124 125 /** 126 * DOC: ION_IOC_ALLOC - allocate memory 127 * 128 * Takes an ion_allocation_data struct and returns it with the handle field 129 * populated with the opaque handle for the allocation. 130 */ 131 #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ 132 struct ion_allocation_data) 133 134 /** 135 * DOC: ION_IOC_HEAP_QUERY - information about available heaps 136 * 137 * Takes an ion_heap_query structure and populates information about 138 * available Ion heaps. 139 */ 140 #define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \ 141 struct ion_heap_query) 142 143 /** 144 * DOC: ION_IOC_HEAP_ABI_VERSION - return ABI version 145 * 146 * Returns ABI version for this driver 147 */ 148 #define ION_IOC_ABI_VERSION _IOR(ION_IOC_MAGIC, 9, \ 149 __u32) 150 #endif /* _LINUX_ION_H */ 151