1 #ifndef _LINUX_MSM_ION_H
2 #define _LINUX_MSM_ION_H
3 
4 #include <linux/types.h>
5 
6 #define ION_BIT(nr) (1U << (nr))
7 
8 /**
9  * TARGET_ION_ABI_VERSION can be used by user space clients to ensure that at
10  * compile time only their code which uses the appropriate ION APIs for
11  * this kernel is included.
12  */
13 #define TARGET_ION_ABI_VERSION 2
14 
15 enum msm_ion_heap_types {
16 	ION_HEAP_TYPE_MSM_START = 6,
17 	ION_HEAP_TYPE_SECURE_DMA = ION_HEAP_TYPE_MSM_START,
18 	ION_HEAP_TYPE_SYSTEM_SECURE,
19 	ION_HEAP_TYPE_HYP_CMA,
20 	ION_HEAP_TYPE_SECURE_CARVEOUT,
21 };
22 
23 /**
24  * These are the only ids that should be used for Ion heap ids.
25  * The ids listed are the order in which allocation will be attempted
26  * if specified. Don't swap the order of heap ids unless you know what
27  * you are doing!
28  * Id's are spaced by purpose to allow new Id's to be inserted in-between (for
29  * possible fallbacks)
30  */
31 
32 enum ion_heap_ids {
33 	INVALID_HEAP_ID = -1,
34 	ION_CP_MM_HEAP_ID = 8,
35 	ION_SECURE_HEAP_ID = 9,
36 	ION_SECURE_DISPLAY_HEAP_ID = 10,
37 	ION_VIDEO_HEAP_ID = 12,
38 	ION_SPSS_HEAP_ID = 13, /* Secure Processor ION heap */
39 	ION_ADSP_HEAP_ID = 22,
40 	ION_SYSTEM_HEAP_ID = 25,
41 	ION_QSECOM_HEAP_ID = 27,
42 	ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_FLAG_SECURE flag */
43 };
44 
45 /**
46  * Newly added heap ids have to be #define(d) since all API changes must
47  * include a new #define.
48  */
49 #define ION_SECURE_CARVEOUT_HEAP_ID	14
50 #define ION_QSECOM_TA_HEAP_ID		19
51 #define ION_AUDIO_HEAP_ID		28
52 #define ION_CAMERA_HEAP_ID		20
53 #define ION_USER_CONTIG_HEAP_ID		26
54 /**
55  * Flags to be used when allocating from the secure heap for
56  * content protection
57  */
58 #define ION_FLAG_CP_CAMERA_ENCODE	ION_BIT(14)
59 #define ION_FLAG_CP_DSP_EXT		ION_BIT(15)
60 /* ION_FLAG_POOL_FORCE_ALLOC uses ION_BIT(16) */
61 #define ION_FLAG_CP_TOUCH		ION_BIT(17)
62 #define ION_FLAG_CP_BITSTREAM		ION_BIT(18)
63 #define ION_FLAG_CP_PIXEL		ION_BIT(19)
64 #define ION_FLAG_CP_NON_PIXEL		ION_BIT(20)
65 #define ION_FLAG_CP_CAMERA		ION_BIT(21)
66 #define ION_FLAG_CP_HLOS		ION_BIT(22)
67 #define ION_FLAG_CP_SPSS_SP		ION_BIT(23)
68 #define ION_FLAG_CP_SPSS_SP_SHARED	ION_BIT(24)
69 #define ION_FLAG_CP_SEC_DISPLAY		ION_BIT(25)
70 #define ION_FLAG_CP_APP			ION_BIT(26)
71 #define ION_FLAG_CP_CAMERA_PREVIEW	ION_BIT(27)
72 /* ION_FLAG_ALLOW_NON_CONTIG uses ION_BIT(28) */
73 #define ION_FLAG_CP_CDSP		ION_BIT(29)
74 #define ION_FLAG_CP_SPSS_HLOS_SHARED	ION_BIT(30)
75 /* ION_FLAG_SECURE uses ION_BIT(31) */
76 
77 #define ION_FLAGS_CP_MASK	0x6FFEC000
78 
79 /**
80  * Flag to allow non continguous allocation of memory from secure
81  * heap
82  */
83 #define ION_FLAG_ALLOW_NON_CONTIG       ION_BIT(28)
84 
85 /**
86  * Flag to use when allocating to indicate that a heap is secure.
87  * Do NOT use BIT macro since it is defined in #ifdef __KERNEL__
88  */
89 #define ION_FLAG_SECURE			ION_BIT(ION_HEAP_ID_RESERVED)
90 
91 /*
92  * Used in conjunction with heap which pool memory to force an allocation
93  * to come from the page allocator directly instead of from the pool allocation
94  */
95 #define ION_FLAG_POOL_FORCE_ALLOC	ION_BIT(16)
96 
97 /**
98  * Macro should be used with ion_heap_ids defined above.
99  */
100 #define ION_HEAP(bit)			ION_BIT(bit)
101 
102 #define ION_IOC_MSM_MAGIC 'M'
103 
104 struct ion_prefetch_regions {
105 	__u64 sizes;
106 	__u32 vmid;
107 	__u32 nr_sizes;
108 };
109 
110 struct ion_prefetch_data {
111 	__u64 len;
112 	__u64 regions;
113 	__u32 heap_id;
114 	__u32 nr_regions;
115 };
116 
117 #define ION_IOC_PREFETCH		_IOWR(ION_IOC_MSM_MAGIC, 3, \
118 						struct ion_prefetch_data)
119 
120 #define ION_IOC_DRAIN			_IOWR(ION_IOC_MSM_MAGIC, 4, \
121 						struct ion_prefetch_data)
122 
123 #endif /* _LINUX_MSM_ION_H */
124