1772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#ifndef _UAPI_MSM_ION_H
2772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define _UAPI_MSM_ION_H
3772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
4772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#include "ion.h"
5772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
6772b7facf972926b14fe303d0348c200cb20a313Prashant Malanienum msm_ion_heap_types {
7772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_HEAP_TYPE_MSM_START = ION_HEAP_TYPE_CUSTOM + 1,
8772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_HEAP_TYPE_SECURE_DMA = ION_HEAP_TYPE_MSM_START,
9464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry	ION_HEAP_TYPE_SYSTEM_SECURE,
10464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry	ION_HEAP_TYPE_HYP_CMA,
11772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	/*
12772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	 * if you add a heap type here you should also add it to
13772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	 * heap_types_info[] in msm_ion.c
14772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	 */
15772b7facf972926b14fe303d0348c200cb20a313Prashant Malani};
16772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
17772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/**
18772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * These are the only ids that should be used for Ion heap ids.
19772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * The ids listed are the order in which allocation will be attempted
20772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * if specified. Don't swap the order of heap ids unless you know what
21772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * you are doing!
22772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Id's are spaced by purpose to allow new Id's to be inserted in-between (for
23772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * possible fallbacks)
24772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
25772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
26772b7facf972926b14fe303d0348c200cb20a313Prashant Malanienum ion_heap_ids {
27772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	INVALID_HEAP_ID = -1,
28772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_CP_MM_HEAP_ID = 8,
29464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry	ION_SECURE_HEAP_ID = 9,
30464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry	ION_SECURE_DISPLAY_HEAP_ID = 10,
31772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_CP_MFC_HEAP_ID = 12,
32772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_CP_WB_HEAP_ID = 16, /* 8660 only */
33772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_CAMERA_HEAP_ID = 20, /* 8660 only */
34772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_SYSTEM_CONTIG_HEAP_ID = 21,
35772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_ADSP_HEAP_ID = 22,
36772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_PIL1_HEAP_ID = 23, /* Currently used for other PIL images */
37772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_SF_HEAP_ID = 24,
38772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_SYSTEM_HEAP_ID = 25,
39772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_PIL2_HEAP_ID = 26, /* Currently used for modem firmware images */
40772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_QSECOM_HEAP_ID = 27,
41772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_AUDIO_HEAP_ID = 28,
42772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
43772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_MM_FIRMWARE_HEAP_ID = 29,
44772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
45772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_FLAG_SECURE flag */
46772b7facf972926b14fe303d0348c200cb20a313Prashant Malani};
47772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
48772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/*
49772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * The IOMMU heap is deprecated! Here are some aliases for backwards
50772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * compatibility:
51772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
52772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_IOMMU_HEAP_ID ION_SYSTEM_HEAP_ID
53772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_HEAP_TYPE_IOMMU ION_HEAP_TYPE_SYSTEM
54772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
55772b7facf972926b14fe303d0348c200cb20a313Prashant Malanienum ion_fixed_position {
56772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	NOT_FIXED,
57772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	FIXED_LOW,
58772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	FIXED_MIDDLE,
59772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	FIXED_HIGH,
60772b7facf972926b14fe303d0348c200cb20a313Prashant Malani};
61772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
62772b7facf972926b14fe303d0348c200cb20a313Prashant Malanienum cp_mem_usage {
63772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	VIDEO_BITSTREAM = 0x1,
64772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	VIDEO_PIXEL = 0x2,
65772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	VIDEO_NONPIXEL = 0x3,
66772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	DISPLAY_SECURE_CP_USAGE = 0x4,
67772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	CAMERA_SECURE_CP_USAGE = 0x5,
68772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	MAX_USAGE = 0x6,
69772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	UNKNOWN = 0x7FFFFFFF,
70772b7facf972926b14fe303d0348c200cb20a313Prashant Malani};
71772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
72772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/**
73464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry * Flags to be used when allocating from the secure heap for
74464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry * content protection
75464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry */
76464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_CP_TOUCH (1 << 17)
77464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_CP_BITSTREAM (1 << 18)
78464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_CP_PIXEL  (1 << 19)
79464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_CP_NON_PIXEL (1 << 20)
80464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_CP_CAMERA (1 << 21)
81464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_CP_HLOS (1 << 22)
82464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_CP_HLOS_FREE (1 << 23)
83464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_CP_SEC_DISPLAY (1 << 25)
84464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_CP_APP (1 << 26)
85464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry
86464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry/**
87464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry * Flag to allow non continguous allocation of memory from secure
88464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry * heap
89464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry */
90464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_FLAG_ALLOW_NON_CONTIG (1 << 24)
91464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry
92464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry/**
93772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Flag to use when allocating to indicate that a heap is secure.
94772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
95772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_FLAG_SECURE (1 << ION_HEAP_ID_RESERVED)
96772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
97772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/**
98772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Flag for clients to force contiguous memort allocation
99772b7facf972926b14fe303d0348c200cb20a313Prashant Malani *
100772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Use of this flag is carefully monitored!
101772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
102772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_FLAG_FORCE_CONTIGUOUS (1 << 30)
103772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
104772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/*
105772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Used in conjunction with heap which pool memory to force an allocation
106772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * to come from the page allocator directly instead of from the pool allocation
107772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
108772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_FLAG_POOL_FORCE_ALLOC (1 << 16)
109772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
110772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/**
111772b7facf972926b14fe303d0348c200cb20a313Prashant Malani* Deprecated! Please use the corresponding ION_FLAG_*
112772b7facf972926b14fe303d0348c200cb20a313Prashant Malani*/
113772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_SECURE ION_FLAG_SECURE
114772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_FORCE_CONTIGUOUS ION_FLAG_FORCE_CONTIGUOUS
115772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
116772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/**
117772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Macro should be used with ion_heap_ids defined above.
118772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
119772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_HEAP(bit) (1 << (bit))
120772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
121772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_ADSP_HEAP_NAME	"adsp"
122772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_SYSTEM_HEAP_NAME	"system"
123772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_VMALLOC_HEAP_NAME	ION_SYSTEM_HEAP_NAME
124772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_KMALLOC_HEAP_NAME	"kmalloc"
125772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_AUDIO_HEAP_NAME	"audio"
126772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_SF_HEAP_NAME	"sf"
127772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_MM_HEAP_NAME	"mm"
128772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_CAMERA_HEAP_NAME	"camera_preview"
129772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_IOMMU_HEAP_NAME	"iommu"
130772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_MFC_HEAP_NAME	"mfc"
131772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_WB_HEAP_NAME	"wb"
132772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_MM_FIRMWARE_HEAP_NAME	"mm_fw"
133772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_PIL1_HEAP_NAME  "pil_1"
134772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_PIL2_HEAP_NAME  "pil_2"
135772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_QSECOM_HEAP_NAME	"qsecom"
136464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_SECURE_HEAP_NAME	"secure_heap"
137464aadab995fc0ef1616362ad795e9a3ba6c4f16Tom Cherry#define ION_SECURE_DISPLAY_HEAP_NAME "secure_display"
138772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
139772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_SET_CACHED(__cache)		(__cache | ION_FLAG_CACHED)
140772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_SET_UNCACHED(__cache)	(__cache & ~ION_FLAG_CACHED)
141772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
142772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_IS_CACHED(__flags)	((__flags) & ION_FLAG_CACHED)
143772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
144772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/* struct ion_flush_data - data passed to ion for flushing caches
145772b7facf972926b14fe303d0348c200cb20a313Prashant Malani *
146772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * @handle:	handle with data to flush
147772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * @fd:		fd to flush
148772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * @vaddr:	userspace virtual address mapped with mmap
149772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * @offset:	offset into the handle to flush
150772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * @length:	length of handle to flush
151772b7facf972926b14fe303d0348c200cb20a313Prashant Malani *
152772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Performs cache operations on the handle. If p is the start address
153772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * of the handle, p + offset through p + offset + length will have
154772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * the cache operations performed
155772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
156772b7facf972926b14fe303d0348c200cb20a313Prashant Malanistruct ion_flush_data {
157772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	ion_user_handle_t handle;
158772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	int fd;
159772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	void *vaddr;
160772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	unsigned int offset;
161772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	unsigned int length;
162772b7facf972926b14fe303d0348c200cb20a313Prashant Malani};
163772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
164772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
165772b7facf972926b14fe303d0348c200cb20a313Prashant Malanistruct ion_prefetch_data {
166772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	int heap_id;
167772b7facf972926b14fe303d0348c200cb20a313Prashant Malani	unsigned long len;
168772b7facf972926b14fe303d0348c200cb20a313Prashant Malani};
169772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
170772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_IOC_MSM_MAGIC 'M'
171772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
172772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/**
173772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * DOC: ION_IOC_CLEAN_CACHES - clean the caches
174772b7facf972926b14fe303d0348c200cb20a313Prashant Malani *
175772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Clean the caches of the handle specified.
176772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
177772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_IOC_CLEAN_CACHES	_IOWR(ION_IOC_MSM_MAGIC, 0, \
178772b7facf972926b14fe303d0348c200cb20a313Prashant Malani						struct ion_flush_data)
179772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/**
180772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * DOC: ION_IOC_INV_CACHES - invalidate the caches
181772b7facf972926b14fe303d0348c200cb20a313Prashant Malani *
182772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Invalidate the caches of the handle specified.
183772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
184772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_IOC_INV_CACHES	_IOWR(ION_IOC_MSM_MAGIC, 1, \
185772b7facf972926b14fe303d0348c200cb20a313Prashant Malani						struct ion_flush_data)
186772b7facf972926b14fe303d0348c200cb20a313Prashant Malani/**
187772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches
188772b7facf972926b14fe303d0348c200cb20a313Prashant Malani *
189772b7facf972926b14fe303d0348c200cb20a313Prashant Malani * Clean and invalidate the caches of the handle specified.
190772b7facf972926b14fe303d0348c200cb20a313Prashant Malani */
191772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_IOC_CLEAN_INV_CACHES	_IOWR(ION_IOC_MSM_MAGIC, 2, \
192772b7facf972926b14fe303d0348c200cb20a313Prashant Malani						struct ion_flush_data)
193772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
194772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_IOC_PREFETCH		_IOWR(ION_IOC_MSM_MAGIC, 3, \
195772b7facf972926b14fe303d0348c200cb20a313Prashant Malani						struct ion_prefetch_data)
196772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
197772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#define ION_IOC_DRAIN			_IOWR(ION_IOC_MSM_MAGIC, 4, \
198772b7facf972926b14fe303d0348c200cb20a313Prashant Malani						struct ion_prefetch_data)
199772b7facf972926b14fe303d0348c200cb20a313Prashant Malani
200772b7facf972926b14fe303d0348c200cb20a313Prashant Malani#endif
201