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