1 /* 2 * Adapted from drivers/staging/android/uapi/ion.h 3 * 4 * Copyright (C) 2019 Google, Inc. 5 * 6 * This software is licensed under the terms of the GNU General Public 7 * License version 2, as published by the Free Software Foundation, and 8 * may be copied, distributed, and modified under those terms. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 */ 16 17 #ifndef _UAPI_LINUX_ION_NEW_H 18 #define _UAPI_LINUX_ION_NEW_H 19 20 #include <linux/ioctl.h> 21 #include <linux/types.h> 22 23 #define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8) 24 25 enum ion_heap_type_ext { 26 ION_HEAP_TYPE_CUSTOM_EXT = 16, 27 ION_HEAP_TYPE_MAX = 31, 28 }; 29 30 /** 31 * ion_heap_id - list of standard heap ids that Android can use 32 * 33 * @ION_HEAP_SYSTEM Id for the ION_HEAP_TYPE_SYSTEM 34 * @ION_HEAP_DMA_START Start of reserved id range for heaps of type 35 * ION_HEAP_TYPE_DMA 36 * @ION_HEAP_DMA_END End of reserved id range for heaps of type 37 * ION_HEAP_TYPE_DMA 38 * @ION_HEAP_CUSTOM_START Start of reserved id range for heaps of custom 39 * type 40 * @ION_HEAP_CUSTOM_END End of reserved id range for heaps of custom 41 * type 42 */ 43 enum ion_heap_id { 44 ION_HEAP_SYSTEM = (1 << ION_HEAP_TYPE_SYSTEM), 45 ION_HEAP_DMA_START = (ION_HEAP_SYSTEM << 1), 46 ION_HEAP_DMA_END = (ION_HEAP_DMA_START << 7), 47 ION_HEAP_CUSTOM_START = (ION_HEAP_DMA_END << 1), 48 ION_HEAP_CUSTOM_END = (ION_HEAP_CUSTOM_START << 22), 49 }; 50 51 #define ION_NUM_MAX_HEAPS (32) 52 53 /** 54 * DOC: Ion Userspace API 55 * 56 * create a client by opening /dev/ion 57 * most operations handled via following ioctls 58 * 59 */ 60 61 /** 62 * struct ion_new_allocation_data - metadata passed from userspace for allocations 63 * @len: size of the allocation 64 * @heap_id_mask: mask of heap ids to allocate from 65 * @flags: flags passed to heap 66 * @handle: pointer that will be populated with a cookie to use to 67 * refer to this allocation 68 * 69 * Provided by userspace as an argument to the ioctl - added _new to denote 70 * this belongs to the new ION interface. 71 */ 72 struct ion_new_allocation_data { 73 __u64 len; 74 __u32 heap_id_mask; 75 __u32 flags; 76 __u32 fd; 77 __u32 unused; 78 }; 79 80 #define MAX_HEAP_NAME 32 81 82 /** 83 * struct ion_heap_data - data about a heap 84 * @name - first 32 characters of the heap name 85 * @type - heap type 86 * @heap_id - heap id for the heap 87 */ 88 struct ion_heap_data { 89 char name[MAX_HEAP_NAME]; 90 __u32 type; 91 __u32 heap_id; 92 __u32 reserved0; 93 __u32 reserved1; 94 __u32 reserved2; 95 }; 96 97 /** 98 * struct ion_heap_query - collection of data about all heaps 99 * @cnt - total number of heaps to be copied 100 * @heaps - buffer to copy heap data 101 */ 102 struct ion_heap_query { 103 __u32 cnt; /* Total number of heaps to be copied */ 104 __u32 reserved0; /* align to 64bits */ 105 __u64 heaps; /* buffer to be populated */ 106 __u32 reserved1; 107 __u32 reserved2; 108 }; 109 110 #define ION_IOC_MAGIC 'I' 111 112 /** 113 * DOC: ION_IOC_NEW_ALLOC - allocate memory 114 * 115 * Takes an ion_allocation_data struct and returns it with the handle field 116 * populated with the opaque handle for the allocation. 117 * TODO: This IOCTL will clash by design; however, only one of 118 * ION_IOC_ALLOC or ION_IOC_NEW_ALLOC paths will be exercised, 119 * so this should not conflict. 120 */ 121 #define ION_IOC_NEW_ALLOC _IOWR(ION_IOC_MAGIC, 0, struct ion_new_allocation_data) 122 123 /** 124 * DOC: ION_IOC_FREE - free memory 125 * 126 * Takes an ion_handle_data struct and frees the handle. 127 * 128 * #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) 129 * This will come from the older kernels, so don't redefine here 130 */ 131 132 /** 133 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation 134 * 135 * Takes an ion_fd_data struct with the handle field populated with a valid 136 * opaque handle. Returns the struct with the fd field set to a file 137 * descriptor open in the current address space. This file descriptor 138 * can then be passed to another process. The corresponding opaque handle can 139 * be retrieved via ION_IOC_IMPORT. 140 * 141 * #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) 142 * This will come from the older kernels, so don't redefine here 143 */ 144 145 /** 146 * DOC: ION_IOC_HEAP_QUERY - information about available heaps 147 * 148 * Takes an ion_heap_query structure and populates information about 149 * available Ion heaps. 150 */ 151 #define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, struct ion_heap_query) 152 153 /** 154 * DOC: ION_IOC_HEAP_ABI_VERSION - return ABI version 155 * 156 * Returns ABI version for this driver 157 */ 158 #define ION_IOC_ABI_VERSION _IOR(ION_IOC_MAGIC, 9, __u32) 159 160 #endif /* _UAPI_LINUX_ION_NEW_H */ 161