xref: /utopia/UTPA2-700.0.x/modules/msos/msos/linux/mdrv_ipa_pool_uapi.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 #ifndef _MDRV_IPA_POOL_UAPI_H_
2 #define _MDRV_IPA_POOL_UAPI_H_
3 
4 #define MAP_USAGE_APPLICATION 0x00000001//application(upper layer of utopia) will access virtual address
5 #define MAP_USAGE_UTOPIA 0x00000002   //utopia will access Virtual address internally
6 #define IPAPOOL_HEAP_NAME_MAX_LEN 32
7 
8 #define IPAPOOL_NAME_MAX_LONG 128
9 
10 //enum for mapping virtual address type
11 enum IPA_MAP_VA_TYPE
12 {
13     IPA_MAP_VA_NO_NEEDED = 0,  //we don't need to map VA
14     IPA_VA_CACHE_WRITE_BACK = 1, //we need to map VA with cache type "write back", which is normally used
15     IPA_VA_CACHE_WRITE_THROUGH = 2, //we need to map VA with cache type "write through", which is //mostly used by graphic system
16     IPA_VA_CACHE_NONE_CACHE = 3,  //we don't need data cache
17     IPA_VA_TYPE_MAX = 0xFFFFFFFF//force enum size to be 4 byte alignment
18 };
19 //enum for IPA_HEAP_TYPE
20 enum IPA_HEAP_TYPE
21 {
22     IPA_HEAP_TYPE_PA = 0,  //directly PA heap
23     IPA_HEAP_TYPE_MTLB = 1, //MTLB heap
24     IPA_HEAP_TYPE_CMA = 2, //CMA heap
25     IPA_IPA_HEAP_TYPE_INVALID = 0xFFFFFFFF//force enum size to be 4 byte alignment
26 };
27 
28 struct IPA_Pool_Init_Args
29 {
30     MS_U32 heap_id;     //in: maybe shared with more than one pools which based on this heap
31     MS_U8 pool_name[IPAPOOL_NAME_MAX_LONG];   //global identify name for pool to shared between multiple process (char*)
32 
33     MS_U64 offset_in_heap;    //in: pool location in heap address heap
34     MS_U64 len;       //in: pool length inheap address heap
35 
36     MS_U32 map_usage;// MAP_USAGE_APPLICATION or MAP_USAGE_UTOPIA or both
37 
38     MS_U32 pool_handle_id; //out: generate pool id based on heap specified by heap id
39     MS_U32 miu;  //out: miu id this heap belongs, index from 0.
40     MS_U32 heap_type;//out: return heap type to application (enum IPA_HEAP_TYPE )
41     MS_S32 error_code; // error code when failed
42 
43     MS_U64 heap_length; //out: heap leagth
44     MS_U64 heap_miu_start_offset; //out: heap start offset in miu, meaningless in case of MTLB heap
45 };
46 
47 struct IPA_Pool_Deinit_Args
48 {
49     MS_U32 pool_handle_id; //out: generate pool id based on heap specified by heap id
50 };
51 
52 struct IPA_Pool_Alloc_Args
53 {
54     MS_U32 pool_handle_id; //in: pool handle id, when pool init, returned by kernel
55     MS_U64 offset_in_pool;  //in: offset in pool
56     MS_U64 length;               //in  alloc length
57     MS_U32 timeout;//in :if using polling thread,will set timeout value(unit in ms),else is 0
58     MS_S32 error_code; // out: error code when failed
59 };
60 
61 #ifdef STR_ALLOC_FREE_DEBUG//only  debug code
62 struct IPA_Pool_STR_Alloc_Args
63 {
64     MS_U64 start; //in: start pos refer to bus
65     MS_U64 length;               //in  alloc length
66     MS_S32 error_code;
67 };
68 #endif
69 
70 
71 struct IPA_Pool_free_Args
72 {
73     MS_U32 pool_handle_id; //in: pool handle id, when pool init, returned by kernel
74     MS_U64 offset_in_pool;  //in: offset in pool
75     MS_U64 length;               //in  free length
76 };
77 
78 #ifdef STR_ALLOC_FREE_DEBUG//only  debug code
79 struct IPA_Pool_STR_free_Args
80 {
81     MS_U64 start; //in: start pos refer to bus
82     MS_U64 length;               //in  free length
83     MS_S32 error_code;
84 };
85 #endif
86 
87 struct IPA_Pool_Map_Args
88 {
89     MS_U32 pool_handle_id; //in: pool handle id, when pool init, returned by kernel
90     MS_U64 offset_in_pool;  //in: offset in pool
91     MS_U64 length;               //in  mapping length
92     MS_U32 map_va_type;//in: indicate dcache type of Virtual address mapping (enum IPA_MAP_VA_TYPE)
93     MS_U64 virt_addr;          //out: if map_usage: MAP_USAGE_APPLICATION is setted & map_va_type
94                                        //doesn't equal to IPA_MAP_VA_NO_NEEDED
95     MS_S32 error_code; // out: error code when failed
96 };
97 
98 struct IPA_Pool_Unmap_Args
99 {
100     MS_U64 virt_addr; //in: the VA need to unmap
101     MS_U64 length;               //in: unmap length
102 };
103 
104 struct IPA_Pool_GetIpcHandle_Args
105 {
106     MS_U32 pool_handle_id; //in: pool handle id, when pool init, returned by kernel
107     MS_U32 ipc_handle_id;  //out: returned by kernel
108     MS_S32 error_code; // out: error code when failed
109 };
110 
111 struct IPA_Pool_InstallIpcHandle_Args
112 {
113     MS_U32 ipc_handle_id;  //in: returned by kernel, when get IPC handle
114     MS_U32 pool_handle_id; //out: pool handle id
115     MS_S32 error_code; // out: error code when failed
116 };
117 
118 enum IPA_DCACHE_FLUSH_TYPE
119 {
120     IPA_DCACHE_FLUSH,//flush dcache into DRAM
121     IPA_DCACHE_INVALID,// invalid dcache lines
122     IPA_DCACHE_FLUSH_INVALID// flush and invalid dcache lines
123 };
124 
125 struct IPA_Pool_DCacheFlush_Args
126 {
127     MS_U64 virt_addr; //in: the VA need to flush
128     MS_U64 length;               //in: flush length
129     MS_U32 flush_type;// in: flush type (enum IPA_DCACHE_FLUSH_TYPE)
130 };
131 
132 struct IPA_Pool_Heap_Attr
133 {
134     MS_U32 heap_id;     //in: maybe shared with more than one pools which based on this heap
135 
136     char   name[IPAPOOL_HEAP_NAME_MAX_LEN]; //out: heap name
137     MS_U64 heap_miu_start_offset; //out: heap start offset in miu
138     MS_U64 heap_length; //out: heap leagth
139     MS_U32 miu;  //out: miu id this heap belongs, index from 0.
140     MS_U32 heap_type;//out: return heap type to application (enum IPA_HEAP_TYPE )
141     MS_S32 error_code; // error code when failed
142 };
143 
144 enum IPA_event_Args
145 {
146   IPA_EVENT_CONFLICT = (1<<0),
147   IPA_EVENT_NO_WAIT =(1<<1),
148   IPA_EVENT_NUM
149 };
150 
151 struct IPA_Pool_Event_Args
152 {
153     MS_U32 pool_handle_id;//in
154     enum IPA_event_Args event;//out
155     MS_U64 start;//out
156     MS_U64 length;//out
157 };
158 
159 //if PA in a pool but not allocated,this state meanless for user .
160 //so here state in pool means allocated,not in pool means not allocated.
161 enum PA_In_IPA_Pool_State
162 {
163     PA_NOT_IN_MIU = (1<<0),//PA not in any miu
164     PA_NOT_IN_HEAP =(1<<1),//PA in a miu,but not in any heap
165     PA_NOT_IN_POOL =(1<<2),//PA in a heap ,but not in any pool(means not allocated)
166     PA_ALLOCATED =(1<<3),//PA in a pool(means pa allocated)
167     PA_CASE_NUM
168 };
169 
170 struct PA_In_IPA_Pool_Args
171 {
172     MS_U64 PA;//in:   PA value
173     MS_S32 miu;//out:  in which miu
174 
175     MS_BOOL in_heap;//out:  whether in heap.If not, relative value can not get.
176     MS_S32 heap_id;     //out: heap id the pa in
177     enum IPA_HEAP_TYPE heap_type;//out: return heap type to application
178     MS_U64 heap_miu_start_offset; //out: heap start offset in miu
179     MS_U64 heap_length; //out: heap leagth
180     MS_U64 pa_offset_in_heap;    //out: pa location in heap
181 
182     MS_BOOL allocated;//out :whether already allocated,if not , relative value can not get.
183     //MS_S32 pool_handle_id; //out: allocated by which pool.
184     MS_U8 pool_name[IPAPOOL_NAME_MAX_LONG];//out: name of pool.
185     MS_U64 pool_len;       //out: pool length in  heap
186     MS_U64 pool_offset_in_heap;    //out: pool location in heap
187     MS_U64 pa_offset_in_pool;    //out: pa location in pool
188 
189     enum PA_In_IPA_Pool_State pa_state;//out:pa state summary
190     MS_S32 error_code; // error code when failed,not used yet
191 };
192 
193 /*N.B.
194  PA:base ARM_MIU0_BUS_BASE/ARM_MIU1_BUS_BASE/ARM_MIU2_BUS_BASE
195 if PA value inside [ARM_MIU0_BUS_BASE,ARM_MIU1_BUS_BASE),PA is in miu0
196 if PA value inside [ARM_MIU1_BUS_BASE,ARM_MIU2_BUS_BASE),PA is in miu1
197 ......
198 
199 
200 to meet modules less use/store global variables request,
201 input of this API only have pool_handle_id and offset_in_pool.
202 */
203 struct Pool_To_PA_Args
204 {
205     MS_U32 pool_handle_id;//in : pa in which pool.
206     MS_U64 offset_in_pool;//in: pa offset in pool.
207 
208     MS_U64 PA;//out:   PA value.
209     MS_S32 error_code; // out: reason why failed.
210 
211     //give more out ,which nowadays no modules use,but may future use.
212     MS_U32 miu;//out:  in which miu.
213     MS_U32 heap_id;     //out: heap id the pa in .After get this,with the help of MApi_IPA_Pool_HEAP_ATTR,can get more more info.
214 };
215 
216 //-------------------------------------------------------------------------------------------------
217 //  IO command
218 //-------------------------------------------------------------------------------------------------
219 #define IPA_POOL_IOC_MAGIC   'P'
220 
221 #define IPA_POOL_IOC_INIT   _IOWR(IPA_POOL_IOC_MAGIC, 0x00, struct IPA_Pool_Init_Args)
222 #define IPA_POOL_IOC_ALLOC  _IOWR(IPA_POOL_IOC_MAGIC, 0x01, struct IPA_Pool_Alloc_Args)
223 #define IPA_POOL_IOC_FREE   _IOW(IPA_POOL_IOC_MAGIC, 0x02, struct IPA_Pool_free_Args)
224 #define IPA_POOL_IOC_MAP   _IOWR(IPA_POOL_IOC_MAGIC, 0x03, struct IPA_Pool_Map_Args)
225 #define IPA_POOL_IOC_UNMAP   _IOW(IPA_POOL_IOC_MAGIC, 0x04, struct IPA_Pool_Unmap_Args)
226 #define IPA_POOL_IOC_FLUSH   _IOW(IPA_POOL_IOC_MAGIC, 0x05, struct IPA_Pool_DCacheFlush_Args)
227 #define IPA_POOL_IOC_DEINIT   _IOW(IPA_POOL_IOC_MAGIC, 0x06, struct IPA_Pool_Deinit_Args)
228 #define IPA_POOL_IOC_HEAP_ATTR   _IOWR(IPA_POOL_IOC_MAGIC, 0x07, struct IPA_Pool_Heap_Attr)
229 #define IPA_POOL_IOC_GETIPCHANDLE _IOWR(IPA_POOL_IOC_MAGIC, 0x08, struct IPA_Pool_GetIpcHandle_Args)
230 #define IPA_POOL_IOC_INSTALLIPCHANDLE _IOWR(IPA_POOL_IOC_MAGIC, 0x09, struct IPA_Pool_InstallIpcHandle_Args)
231 #define IPA_POOL_IOC_KERNEL_MAP   _IOWR(IPA_POOL_IOC_MAGIC, 0x0A, struct IPA_Pool_Map_Args)
232 #define IPA_POOL_IOC_KERNEL_UNMAP   _IOW(IPA_POOL_IOC_MAGIC, 0x0B, struct IPA_Pool_Unmap_Args)
233 #define IPA_POOL_IOC_PA_INFO   _IOWR(IPA_POOL_IOC_MAGIC, 0x0C, struct PA_In_IPA_Pool_Args)
234 #define IPA_POOL_IOC_POOL_TO_PA   _IOWR(IPA_POOL_IOC_MAGIC, 0x0D, struct Pool_To_PA_Args)
235 
236 #ifdef STR_ALLOC_FREE_DEBUG//only debug code
237 #define IPA_POOL_IOC_STR_ALLOC _IOWR(IPA_POOL_IOC_MAGIC, 0x10, struct IPA_Pool_STR_Alloc_Args)
238 #define IPA_POOL_IOC_STR_FREE _IOW(IPA_POOL_IOC_MAGIC, 0x11, struct IPA_Pool_STR_free_Args)
239 
240 #endif
241 
242 #define IPAERROR_OK     0
243 #define IPAERROR_RANGE_INVLAID    1
244 #define IPAERROR_RANGE_NOALIGN    2
245 #define IPAERROR_CREATE_POOL      3
246 #define IPAERROR_ATTACH_POOL      4
247 #define IPAERROR_NO_POOL           5
248 #define IPAERROR_POOL_NOT_INIT    6
249 #define IPAERROR_ADDR_TYPE_INV    7
250 #define IPAERROR_CREATE_VM        8
251 #define IPAERROR_CANT_MAP         9
252 #define IPAERROR_MAP_FAIL         10
253 #define IPAERROR_KERNEL_NOMEM    11
254 #define IPAERROR_RANGE_NOTMAPPED 12
255 #endif
256