diff options
Diffstat (limited to 'src/hal/os/linux/kernel/gc_hal_kernel_allocator.h')
-rwxr-xr-x | src/hal/os/linux/kernel/gc_hal_kernel_allocator.h | 470 |
1 files changed, 470 insertions, 0 deletions
diff --git a/src/hal/os/linux/kernel/gc_hal_kernel_allocator.h b/src/hal/os/linux/kernel/gc_hal_kernel_allocator.h new file mode 100755 index 0000000..72f7c40 --- /dev/null +++ b/src/hal/os/linux/kernel/gc_hal_kernel_allocator.h | |||
@@ -0,0 +1,470 @@ | |||
1 | /**************************************************************************** | ||
2 | * | ||
3 | * The MIT License (MIT) | ||
4 | * | ||
5 | * Copyright (c) 2014 Vivante Corporation | ||
6 | * | ||
7 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | * copy of this software and associated documentation files (the "Software"), | ||
9 | * to deal in the Software without restriction, including without limitation | ||
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | * and/or sell copies of the Software, and to permit persons to whom the | ||
12 | * Software is furnished to do so, subject to the following conditions: | ||
13 | * | ||
14 | * The above copyright notice and this permission notice shall be included in | ||
15 | * all copies or substantial portions of the Software. | ||
16 | * | ||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
23 | * DEALINGS IN THE SOFTWARE. | ||
24 | * | ||
25 | ***************************************************************************** | ||
26 | * | ||
27 | * The GPL License (GPL) | ||
28 | * | ||
29 | * Copyright (C) 2014 Vivante Corporation | ||
30 | * | ||
31 | * This program is free software; you can redistribute it and/or | ||
32 | * modify it under the terms of the GNU General Public License | ||
33 | * as published by the Free Software Foundation; either version 2 | ||
34 | * of the License, or (at your option) any later version. | ||
35 | * | ||
36 | * This program is distributed in the hope that it will be useful, | ||
37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
39 | * GNU General Public License for more details. | ||
40 | * | ||
41 | * You should have received a copy of the GNU General Public License | ||
42 | * along with this program; if not, write to the Free Software Foundation, | ||
43 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
44 | * | ||
45 | ***************************************************************************** | ||
46 | * | ||
47 | * Note: This software is released under dual MIT and GPL licenses. A | ||
48 | * recipient may use this file under the terms of either the MIT license or | ||
49 | * GPL License. If you wish to use only one license not the other, you can | ||
50 | * indicate your decision by deleting one of the above license notices in your | ||
51 | * version of this file. | ||
52 | * | ||
53 | *****************************************************************************/ | ||
54 | |||
55 | |||
56 | #ifndef __gc_hal_kernel_allocator_h_ | ||
57 | #define __gc_hal_kernel_allocator_h_ | ||
58 | |||
59 | #include "gc_hal_kernel_linux.h" | ||
60 | |||
61 | typedef struct _gcsALLOCATOR * gckALLOCATOR; | ||
62 | typedef struct _gcsATTACH_DESC * gcsATTACH_DESC_PTR; | ||
63 | |||
64 | typedef struct _gcsALLOCATOR_OPERATIONS | ||
65 | { | ||
66 | /************************************************************************** | ||
67 | ** | ||
68 | ** Alloc | ||
69 | ** | ||
70 | ** Allocte memory, request size is page aligned. | ||
71 | ** | ||
72 | ** INPUT: | ||
73 | ** | ||
74 | ** gckALLOCATOR Allocator | ||
75 | ** Pointer to an gckALLOCATOER object. | ||
76 | ** | ||
77 | ** PLINUX_Mdl | ||
78 | ** Pointer to Mdl whichs stores information | ||
79 | ** about allocated memory. | ||
80 | ** | ||
81 | ** gctSIZE_T NumPages | ||
82 | ** Number of pages need to allocate. | ||
83 | ** | ||
84 | ** gctUINT32 Flag | ||
85 | ** Allocation option. | ||
86 | ** | ||
87 | ** OUTPUT: | ||
88 | ** | ||
89 | ** Nothing. | ||
90 | ** | ||
91 | */ | ||
92 | gceSTATUS | ||
93 | (*Alloc)( | ||
94 | IN gckALLOCATOR Allocator, | ||
95 | IN PLINUX_MDL Mdl, | ||
96 | IN gctSIZE_T NumPages, | ||
97 | IN gctUINT32 Flag | ||
98 | ); | ||
99 | |||
100 | /************************************************************************** | ||
101 | ** | ||
102 | ** Free | ||
103 | ** | ||
104 | ** Free memory. | ||
105 | ** | ||
106 | ** INPUT: | ||
107 | ** | ||
108 | ** gckALLOCATOR Allocator | ||
109 | ** Pointer to an gckALLOCATOER object. | ||
110 | ** | ||
111 | ** PLINUX_MDL Mdl | ||
112 | ** Mdl which stores information. | ||
113 | ** | ||
114 | ** OUTPUT: | ||
115 | ** | ||
116 | ** Nothing. | ||
117 | ** | ||
118 | */ | ||
119 | void | ||
120 | (*Free)( | ||
121 | IN gckALLOCATOR Allocator, | ||
122 | IN PLINUX_MDL Mdl | ||
123 | ); | ||
124 | |||
125 | /************************************************************************** | ||
126 | ** | ||
127 | ** MapUser | ||
128 | ** | ||
129 | ** Map memory to user space. | ||
130 | ** | ||
131 | ** INPUT: | ||
132 | ** gckALLOCATOR Allocator | ||
133 | ** Pointer to an gckALLOCATOER object. | ||
134 | ** | ||
135 | ** PLINUX_MDL Mdl | ||
136 | ** Pointer to a Mdl. | ||
137 | ** | ||
138 | ** PLINUX_MDL_MAP MdlMap | ||
139 | ** Pointer to a MdlMap, mapped address is stored | ||
140 | ** in MdlMap->vmaAddr | ||
141 | ** | ||
142 | ** gctBOOL Cacheable | ||
143 | ** Whether this mapping is cacheable. | ||
144 | ** | ||
145 | ** OUTPUT: | ||
146 | ** | ||
147 | ** Nothing. | ||
148 | ** | ||
149 | */ | ||
150 | gctINT | ||
151 | (*MapUser)( | ||
152 | IN gckALLOCATOR Allocator, | ||
153 | IN PLINUX_MDL Mdl, | ||
154 | IN PLINUX_MDL_MAP MdlMap, | ||
155 | IN gctBOOL Cacheable | ||
156 | ); | ||
157 | |||
158 | /************************************************************************** | ||
159 | ** | ||
160 | ** UnmapUser | ||
161 | ** | ||
162 | ** Unmap address from user address space. | ||
163 | ** | ||
164 | ** INPUT: | ||
165 | ** gckALLOCATOR Allocator | ||
166 | ** Pointer to an gckALLOCATOER object. | ||
167 | ** | ||
168 | ** gctPOINTER Logical | ||
169 | ** Address to be unmap | ||
170 | ** | ||
171 | ** gctUINT32 Size | ||
172 | ** Size of address space | ||
173 | ** | ||
174 | ** OUTPUT: | ||
175 | ** | ||
176 | ** Nothing. | ||
177 | ** | ||
178 | */ | ||
179 | void | ||
180 | (*UnmapUser)( | ||
181 | IN gckALLOCATOR Allocator, | ||
182 | IN gctPOINTER Logical, | ||
183 | IN gctUINT32 Size | ||
184 | ); | ||
185 | |||
186 | /************************************************************************** | ||
187 | ** | ||
188 | ** MapKernel | ||
189 | ** | ||
190 | ** Map memory to kernel space. | ||
191 | ** | ||
192 | ** INPUT: | ||
193 | ** gckALLOCATOR Allocator | ||
194 | ** Pointer to an gckALLOCATOER object. | ||
195 | ** | ||
196 | ** PLINUX_MDL Mdl | ||
197 | ** Pointer to a Mdl object. | ||
198 | ** | ||
199 | ** OUTPUT: | ||
200 | ** gctPOINTER * Logical | ||
201 | ** Mapped kernel address. | ||
202 | */ | ||
203 | gceSTATUS | ||
204 | (*MapKernel)( | ||
205 | IN gckALLOCATOR Allocator, | ||
206 | IN PLINUX_MDL Mdl, | ||
207 | OUT gctPOINTER *Logical | ||
208 | ); | ||
209 | |||
210 | /************************************************************************** | ||
211 | ** | ||
212 | ** UnmapKernel | ||
213 | ** | ||
214 | ** Unmap memory from kernel space. | ||
215 | ** | ||
216 | ** INPUT: | ||
217 | ** gckALLOCATOR Allocator | ||
218 | ** Pointer to an gckALLOCATOER object. | ||
219 | ** | ||
220 | ** PLINUX_MDL Mdl | ||
221 | ** Pointer to a Mdl object. | ||
222 | ** | ||
223 | ** gctPOINTER Logical | ||
224 | ** Mapped kernel address. | ||
225 | ** | ||
226 | ** OUTPUT: | ||
227 | ** | ||
228 | ** Nothing. | ||
229 | ** | ||
230 | */ | ||
231 | gceSTATUS | ||
232 | (*UnmapKernel)( | ||
233 | IN gckALLOCATOR Allocator, | ||
234 | IN PLINUX_MDL Mdl, | ||
235 | IN gctPOINTER Logical | ||
236 | ); | ||
237 | |||
238 | /************************************************************************** | ||
239 | ** | ||
240 | ** LogicalToPhysical | ||
241 | ** | ||
242 | ** Get physical address from logical address, logical | ||
243 | ** address could be user virtual address or kernel | ||
244 | ** virtual address. | ||
245 | ** | ||
246 | ** INPUT: | ||
247 | ** gckALLOCATOR Allocator | ||
248 | ** Pointer to an gckALLOCATOER object. | ||
249 | ** | ||
250 | ** PLINUX_MDL Mdl | ||
251 | ** Pointer to a Mdl object. | ||
252 | ** | ||
253 | ** gctPOINTER Logical | ||
254 | ** Mapped kernel address. | ||
255 | ** | ||
256 | ** gctUINT32 ProcessID | ||
257 | ** pid of current process. | ||
258 | ** OUTPUT: | ||
259 | ** | ||
260 | ** gctUINT32_PTR Physical | ||
261 | ** Physical address. | ||
262 | ** | ||
263 | */ | ||
264 | gceSTATUS | ||
265 | (*LogicalToPhysical)( | ||
266 | IN gckALLOCATOR Allocator, | ||
267 | IN PLINUX_MDL Mdl, | ||
268 | IN gctPOINTER Logical, | ||
269 | IN gctUINT32 ProcessID, | ||
270 | OUT gctPHYS_ADDR_T * Physical | ||
271 | ); | ||
272 | |||
273 | /************************************************************************** | ||
274 | ** | ||
275 | ** Cache | ||
276 | ** | ||
277 | ** Maintain cache coherency. | ||
278 | ** | ||
279 | ** INPUT: | ||
280 | ** gckALLOCATOR Allocator | ||
281 | ** Pointer to an gckALLOCATOER object. | ||
282 | ** | ||
283 | ** PLINUX_MDL Mdl | ||
284 | ** Pointer to a Mdl object. | ||
285 | ** | ||
286 | ** gctPOINTER Logical | ||
287 | ** Logical address, could be user address or kernel address | ||
288 | ** | ||
289 | ** gctUINT32_PTR Physical | ||
290 | ** Physical address. | ||
291 | ** | ||
292 | ** gctUINT32 Bytes | ||
293 | ** Size of memory region. | ||
294 | ** | ||
295 | ** gceCACHEOPERATION Opertaion | ||
296 | ** Cache operation. | ||
297 | ** | ||
298 | ** OUTPUT: | ||
299 | ** | ||
300 | ** Nothing. | ||
301 | ** | ||
302 | */ | ||
303 | gceSTATUS (*Cache)( | ||
304 | IN gckALLOCATOR Allocator, | ||
305 | IN PLINUX_MDL Mdl, | ||
306 | IN gctPOINTER Logical, | ||
307 | IN gctUINT32 Physical, | ||
308 | IN gctUINT32 Bytes, | ||
309 | IN gceCACHEOPERATION Operation | ||
310 | ); | ||
311 | |||
312 | /************************************************************************** | ||
313 | ** | ||
314 | ** Physical | ||
315 | ** | ||
316 | ** Get physical address from a offset in memory region. | ||
317 | ** | ||
318 | ** INPUT: | ||
319 | ** gckALLOCATOR Allocator | ||
320 | ** Pointer to an gckALLOCATOER object. | ||
321 | ** | ||
322 | ** PLINUX_MDL Mdl | ||
323 | ** Pointer to a Mdl object. | ||
324 | ** | ||
325 | ** gctUINT32 Offset | ||
326 | ** Offset in this memory region. | ||
327 | ** | ||
328 | ** OUTPUT: | ||
329 | ** gctUINT32_PTR Physical | ||
330 | ** Physical address. | ||
331 | ** | ||
332 | */ | ||
333 | gceSTATUS (*Physical)( | ||
334 | IN gckALLOCATOR Allocator, | ||
335 | IN PLINUX_MDL Mdl, | ||
336 | IN gctUINT32 Offset, | ||
337 | OUT gctPHYS_ADDR_T * Physical | ||
338 | ); | ||
339 | |||
340 | /************************************************************************** | ||
341 | ** | ||
342 | ** Attach | ||
343 | ** | ||
344 | ** Import memory allocated by an external allocator. | ||
345 | ** | ||
346 | ** INPUT: | ||
347 | ** gckALLOCATOR Allocator | ||
348 | ** Pointer to an gckALLOCATOER object. | ||
349 | ** | ||
350 | ** gctUINT32 Handle | ||
351 | ** Handle of the memory. | ||
352 | ** | ||
353 | ** OUTPUT: | ||
354 | ** None. | ||
355 | ** | ||
356 | */ | ||
357 | gceSTATUS (*Attach)( | ||
358 | IN gckALLOCATOR Allocator, | ||
359 | IN gcsATTACH_DESC_PTR Desc, | ||
360 | OUT PLINUX_MDL Mdl | ||
361 | ); | ||
362 | } | ||
363 | gcsALLOCATOR_OPERATIONS; | ||
364 | |||
365 | typedef struct _gcsALLOCATOR | ||
366 | { | ||
367 | /* Pointer to gckOS Object. */ | ||
368 | gckOS os; | ||
369 | |||
370 | /* Name. */ | ||
371 | gctSTRING name; | ||
372 | |||
373 | /* Operations. */ | ||
374 | gcsALLOCATOR_OPERATIONS* ops; | ||
375 | |||
376 | /* Capability of this allocator. */ | ||
377 | gctUINT32 capability; | ||
378 | |||
379 | struct list_head head; | ||
380 | |||
381 | /* Debugfs entry of this allocator. */ | ||
382 | gcsDEBUGFS_DIR debugfsDir; | ||
383 | |||
384 | /* Init allocator debugfs. */ | ||
385 | void (*debugfsInit)(gckALLOCATOR, gckDEBUGFS_DIR); | ||
386 | |||
387 | /* Cleanup allocator debugfs. */ | ||
388 | void (*debugfsCleanup)(gckALLOCATOR); | ||
389 | |||
390 | /* Private data used by customer allocator. */ | ||
391 | void * privateData; | ||
392 | |||
393 | /* Private data destructor. */ | ||
394 | void (*privateDataDestructor)(void *); | ||
395 | } | ||
396 | gcsALLOCATOR; | ||
397 | |||
398 | typedef struct _gcsALLOCATOR_DESC | ||
399 | { | ||
400 | /* Name of a allocator. */ | ||
401 | char * name; | ||
402 | |||
403 | /* Entry function to construct a allocator. */ | ||
404 | gceSTATUS (*construct)(gckOS, gckALLOCATOR *); | ||
405 | } | ||
406 | gcsALLOCATOR_DESC; | ||
407 | |||
408 | typedef struct _gcsATTACH_DESC | ||
409 | { | ||
410 | /* gcvALLOC_FLAG_DMABUF */ | ||
411 | gctUINT32 handle; | ||
412 | |||
413 | /* gcvALLOC_FLAG_USERMEMORY */ | ||
414 | gctPOINTER memory; | ||
415 | gctUINT32 physical; | ||
416 | gctSIZE_T size; | ||
417 | } | ||
418 | gcsATTACH_DESC; | ||
419 | |||
420 | /* | ||
421 | * Helpers | ||
422 | */ | ||
423 | |||
424 | /* Fill a gcsALLOCATOR_DESC structure. */ | ||
425 | #define gcmkDEFINE_ALLOCATOR_DESC(Name, Construct) \ | ||
426 | { \ | ||
427 | .name = Name, \ | ||
428 | .construct = Construct, \ | ||
429 | } | ||
430 | |||
431 | /* Construct a allocator. */ | ||
432 | gceSTATUS | ||
433 | gckALLOCATOR_Construct( | ||
434 | IN gckOS Os, | ||
435 | IN gcsALLOCATOR_OPERATIONS * Operations, | ||
436 | OUT gckALLOCATOR * Allocator | ||
437 | ); | ||
438 | |||
439 | /* | ||
440 | How to implement customer allocator | ||
441 | |||
442 | Build in customer alloctor | ||
443 | |||
444 | It is recommanded that customer allocator is implmented in independent | ||
445 | source file(s) which is specified by CUSOMTER_ALLOCATOR_OBJS in Kbuld. | ||
446 | |||
447 | Register gcsALLOCATOR | ||
448 | |||
449 | For each customer specified allocator, a desciption entry must be added | ||
450 | to allocatorArray defined in gc_hal_kernel_allocator_array.h. | ||
451 | |||
452 | An entry in allocatorArray is a gcsALLOCATOR_DESC structure which describes | ||
453 | name and constructor of a gckALLOCATOR object. | ||
454 | |||
455 | |||
456 | Implement gcsALLOCATOR_DESC.init() | ||
457 | |||
458 | In gcsALLOCATOR_DESC.init(), gckALLOCATOR_Construct should be called | ||
459 | to create a gckALLOCATOR object, customer specified private data can | ||
460 | be put in gcsALLOCATOR.privateData. | ||
461 | |||
462 | |||
463 | Implement gcsALLOCATOR_OPERATIONS | ||
464 | |||
465 | When call gckALLOCATOR_Construct to create a gckALLOCATOR object, a | ||
466 | gcsALLOCATOR_OPERATIONS structure must be provided whose all members | ||
467 | implemented. | ||
468 | |||
469 | */ | ||
470 | #endif | ||