1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2011 Google, Inc. 4 */ 5 6 #ifndef _LINUX_ION_H 7 #define _LINUX_ION_H 8 9 #include <linux/ioctl.h> 10 #include <linux/types.h> 11 12 /** 13 * enum ion_heap_types - list of all possible types of heaps 14 * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc 15 * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc 16 * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved 17 * carveout heap, allocations are physically 18 * contiguous 19 * @ION_HEAP_TYPE_DMA: memory allocated via DMA API 20 * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask 21 * is used to identify the heaps, so only 32 22 * total heap types are supported 23 */ 24 enum ion_heap_type { 25 ION_HEAP_TYPE_SYSTEM, 26 ION_HEAP_TYPE_SYSTEM_CONTIG, 27 ION_HEAP_TYPE_CARVEOUT, 28 ION_HEAP_TYPE_CHUNK, 29 ION_HEAP_TYPE_DMA, 30 ION_HEAP_TYPE_CUSTOM, /* 31 * must be last so device specific heaps always 32 * are at the end of this enum 33 */ 34 }; 35 36 #define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8) 37 38 /** 39 * allocation flags - the lower 16 bits are used by core ion, the upper 16 40 * bits are reserved for use by the heaps themselves. 41 */ 42 43 /* 44 * mappings of this buffer should be cached, ion will do cache maintenance 45 * when the buffer is mapped for dma 46 */ 47 #define ION_FLAG_CACHED 1 48 49 /** 50 * DOC: Ion Userspace API 51 * 52 * create a client by opening /dev/ion 53 * most operations handled via following ioctls 54 * 55 */ 56 57 /** 58 * struct ion_allocation_data - metadata passed from userspace for allocations 59 * @len: size of the allocation 60 * @heap_id_mask: mask of heap ids to allocate from 61 * @flags: flags passed to heap 62 * @handle: pointer that will be populated with a cookie to use to 63 * refer to this allocation 64 * 65 * Provided by userspace as an argument to the ioctl 66 */ 67 struct ion_allocation_data { 68 __u64 len; 69 __u32 heap_id_mask; 70 __u32 flags; 71 __u32 fd; 72 __u32 unused; 73 }; 74 75 #define MAX_HEAP_NAME 32 76 77 /** 78 * struct ion_heap_data - data about a heap 79 * @name - first 32 characters of the heap name 80 * @type - heap type 81 * @heap_id - heap id for the heap 82 */ 83 struct ion_heap_data { 84 char name[MAX_HEAP_NAME]; 85 __u32 type; 86 __u32 heap_id; 87 __u32 reserved0; 88 __u32 reserved1; 89 __u32 reserved2; 90 }; 91 92 /** 93 * struct ion_heap_query - collection of data about all heaps 94 * @cnt - total number of heaps to be copied 95 * @heaps - buffer to copy heap data 96 */ 97 struct ion_heap_query { 98 __u32 cnt; /* Total number of heaps to be copied */ 99 __u32 reserved0; /* align to 64bits */ 100 __u64 heaps; /* buffer to be populated */ 101 __u32 reserved1; 102 __u32 reserved2; 103 }; 104 105 #define ION_IOC_MAGIC 'I' 106 107 /** 108 * DOC: ION_IOC_ALLOC - allocate memory 109 * 110 * Takes an ion_allocation_data struct and returns it with the handle field 111 * populated with the opaque handle for the allocation. 112 */ 113 #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ 114 struct ion_allocation_data) 115 /** 116 * DOC: ION_IOC_HEAP_QUERY - information about available heaps 117 * 118 * Takes an ion_heap_query structure and populates information about 119 * available Ion heaps. 120 */ 121 #define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \ 122 struct ion_heap_query) 123 124 #endif /* _LINUX_ION_H */ 125