]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/mxc/gpu-viv/hal/kernel/inc/gc_hal_mem.h
gpu: vivante: Update driver from Freescale 3.10.53-1.1-ga BSP
[karo-tx-linux.git] / drivers / mxc / gpu-viv / hal / kernel / inc / gc_hal_mem.h
1 /****************************************************************************
2 *
3 *    Copyright (C) 2005 - 2014 by Vivante Corp.
4 *
5 *    This program is free software; you can redistribute it and/or modify
6 *    it under the terms of the GNU General Public License as published by
7 *    the Free Software Foundation; either version 2 of the license, or
8 *    (at your option) any later version.
9 *
10 *    This program is distributed in the hope that it will be useful,
11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *    GNU General Public License for more details.
14 *
15 *    You should have received a copy of the GNU General Public License
16 *    along with this program; if not write to the Free Software
17 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 *****************************************************************************/
20
21
22 /*
23 **    Include file for the local memory management.
24 */
25
26 #ifndef __gc_hal_mem_h_
27 #define __gc_hal_mem_h_
28 #if (gcdENABLE_3D || gcdENABLE_VG)
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /*******************************************************************************
35 **  Usage:
36
37     The macros to declare MemPool type and functions are
38     gcmMEM_DeclareFSMemPool (Type, TypeName, Prefix)
39     gcmMEM_DeclareVSMemPool (Type, TypeName, Prefix)
40     gcmMEM_DeclareAFSMemPool(Type, TypeName, Prefix)
41
42     The data structures for MemPool are
43     typedef struct _gcsMEM_FS_MEM_POOL *    gcsMEM_FS_MEM_POOL;
44     typedef struct _gcsMEM_VS_MEM_POOL *    gcsMEM_VS_MEM_POOL;
45     typedef struct _gcsMEM_AFS_MEM_POOL *    gcsMEM_AFS_MEM_POOL;
46
47     The MemPool constructor and destructor functions are
48     gcfMEM_InitFSMemPool(gcsMEM_FS_MEM_POOL *, gcoOS, gctUINT, gctUINT);
49     gcfMEM_FreeFSMemPool(gcsMEM_FS_MEM_POOL *);
50     gcfMEM_InitVSMemPool(gcsMEM_VS_MEM_POOL *, gcoOS, gctUINT, gctBOOL);
51     gcfMEM_FreeVSMemPool(gcsMEM_VS_MEM_POOL *);
52     gcfMEM_InitAFSMemPool(gcsMEM_AFS_MEM_POOL *, gcoOS, gctUINT);
53     gcfMEM_FreeAFSMemPool(gcsMEM_AFS_MEM_POOL *);
54
55     FS:  for Fixed-Size data structures
56     VS:  for Variable-size data structures
57     AFS: for Array of Fixed-Size data structures
58
59
60     // Example 1: For a fixed-size data structure, struct gcsNode.
61     // It is used locally in a file, so the functions are static without prefix.
62     // At top level, declear allocate and free functions.
63     // The first argument is the data type.
64     // The second armument is the short name used in the fuctions.
65     gcmMEM_DeclareFSMemPool(struct gcsNode, Node, );
66
67     // The previous macro creates two inline functions,
68     // _AllocateNode and _FreeNode.
69
70     // In function or struct
71     gcsMEM_FS_MEM_POOL nodeMemPool;
72
73     // In function,
74     struct gcsNode * node;
75     gceSTATUS status;
76
77     // Before using the memory pool, initialize it.
78     // The second argument is the gcoOS object.
79     // The third argument is the number of data structures to allocate for each chunk.
80     status = gcfMEM_InitFSMemPool(&nodeMemPool, os, 100, sizeof(struct gcsNode));
81     ...
82
83     // Allocate a node.
84     status = _AllocateNode(nodeMemPool, &node);
85     ...
86     // Free a node.
87     _FreeNode(nodeMemPool, node);
88
89     // After using the memory pool, free it.
90     gcfMEM_FreeFSMemPool(&nodeMemPool);
91
92
93     // Example 2: For array of fixed-size data structures, struct gcsNode.
94     // It is used in several files, so the functions are extern with prefix.
95     // At top level, declear allocate and free functions.
96     // The first argument is the data type, and the second one is the short name
97     // used in the fuctions.
98     gcmMEM_DeclareAFSMemPool(struct gcsNode, NodeArray, gcfOpt);
99
100     // The previous macro creates two inline functions,
101     // gcfOpt_AllocateNodeArray and gcfOpt_FreeNodeArray.
102
103     // In function or struct
104     gcsMEM_AFS_MEM_POOL nodeArrayMemPool;
105
106     // In function,
107     struct gcsNode * nodeArray;
108     gceSTATUS status;
109
110     // Before using the array memory pool, initialize it.
111     // The second argument is the gcoOS object, the third is the number of data
112     // structures to allocate for each chunk.
113     status = gcfMEM_InitAFSMemPool(&nodeArrayMemPool, os, sizeof(struct gcsNode));
114     ...
115
116     // Allocate a node array of size 100.
117     status = gcfOpt_AllocateNodeArray(nodeArrayMemPool, &nodeArray, 100);
118     ...
119     // Free a node array.
120     gcfOpt_FreeNodeArray(&nodeArrayMemPool, nodeArray);
121
122     // After using the array memory pool, free it.
123     gcfMEM_FreeAFSMemPool(&nodeArrayMemPool);
124
125 *******************************************************************************/
126
127 /*******************************************************************************
128 **    To switch back to use gcoOS_Allocate and gcoOS_Free, add
129 **    #define USE_LOCAL_MEMORY_POOL 0
130 **    before including this file.
131 *******************************************************************************/
132 #ifndef USE_LOCAL_MEMORY_POOL
133 /*
134     USE_LOCAL_MEMORY_POOL
135
136     This define enables the local memory management to improve performance.
137 */
138 #define USE_LOCAL_MEMORY_POOL        1
139 #endif
140
141 /*******************************************************************************
142 **                            Memory Pool Data Structures
143 *******************************************************************************/
144 #if USE_LOCAL_MEMORY_POOL
145     typedef struct _gcsMEM_FS_MEM_POOL *    gcsMEM_FS_MEM_POOL;
146     typedef struct _gcsMEM_VS_MEM_POOL *    gcsMEM_VS_MEM_POOL;
147     typedef struct _gcsMEM_AFS_MEM_POOL *    gcsMEM_AFS_MEM_POOL;
148 #else
149     typedef gcoOS    gcsMEM_FS_MEM_POOL;
150     typedef gcoOS    gcsMEM_VS_MEM_POOL;
151     typedef gcoOS    gcsMEM_AFS_MEM_POOL;
152 #endif
153
154 /*******************************************************************************
155 **                            Memory Pool Macros
156 *******************************************************************************/
157 #if USE_LOCAL_MEMORY_POOL
158 #define gcmMEM_DeclareFSMemPool(Type, TypeName, Prefix) \
159 gceSTATUS \
160 Prefix##_Allocate##TypeName( \
161     gcsMEM_FS_MEM_POOL        MemPool, \
162     Type **                    Pointer \
163     ) \
164 { \
165     return(gcfMEM_FSMemPoolGetANode(MemPool, (gctPOINTER *) Pointer)); \
166 } \
167  \
168 gceSTATUS \
169 Prefix##_CAllocate##TypeName( \
170     gcsMEM_FS_MEM_POOL        MemPool, \
171     Type **                    Pointer \
172     ) \
173 { \
174     gceSTATUS                status; \
175     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
176     gcmERR_RETURN(gcfMEM_FSMemPoolGetANode(MemPool, (gctPOINTER *) Pointer)); \
177     gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, gcmSIZEOF(Type)); \
178     gcmFOOTER(); \
179     return gcvSTATUS_OK; \
180 } \
181  \
182 gceSTATUS \
183 Prefix##_Free##TypeName( \
184     gcsMEM_FS_MEM_POOL        MemPool, \
185     Type *                    Pointer \
186     ) \
187 { \
188     gceSTATUS                status; \
189     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
190     status = gcfMEM_FSMemPoolFreeANode(MemPool, (gctPOINTER) Pointer); \
191     gcmFOOTER(); \
192     return status; \
193 } \
194  \
195 gceSTATUS \
196 Prefix##_Free##TypeName##List( \
197     gcsMEM_FS_MEM_POOL        MemPool, \
198     Type *                    FirstPointer, \
199     Type *                    LastPointer \
200     ) \
201 { \
202     gceSTATUS               status; \
203     gcmHEADER_ARG("MemPool=0x%x FirstPointer=0x%x LastPointer=0x%x", MemPool, FirstPointer, LastPointer); \
204     status = gcfMEM_FSMemPoolFreeAList(MemPool, (gctPOINTER) FirstPointer, (gctPOINTER) LastPointer); \
205     gcmFOOTER(); \
206     return status; \
207 }
208
209 #define gcmMEM_DeclareVSMemPool(Type, TypeName, Prefix) \
210 gceSTATUS \
211 Prefix##_Allocate##TypeName( \
212     gcsMEM_FS_MEM_POOL        MemPool, \
213     Type **                    Pointer, \
214     gctUINT                    Size \
215     ) \
216 { \
217     gceSTATUS               status;\
218     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
219     status = gcfMEM_VSMemPoolGetANode(MemPool, Size, (gctPOINTER *) Pointer); \
220     gcmFOOTER(); \
221     return status; \
222 } \
223  \
224 gceSTATUS \
225  Prefix##_CAllocate##TypeName( \
226     gcsMEM_FS_MEM_POOL        MemPool, \
227     Type **                    Pointer, \
228     gctUINT                    Size \
229     ) \
230 { \
231     gceSTATUS                status; \
232     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
233     gcmERR_RETURN(gcfMEM_VSMemPoolGetANode(MemPool, Size, (gctPOINTER *) Pointer)); \
234     gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, size); \
235     gcmFOOTER(); \
236     return gcvSTATUS_OK; \
237 } \
238  \
239 gceSTATUS \
240 Prefix##_Free##TypeName( \
241     gcsMEM_FS_MEM_POOL        MemPool, \
242     Type *                    Pointer \
243     ) \
244 { \
245     gceSTATUS               status; \
246     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pinter); \
247     status = gcfMEM_VSMemPoolFreeANode(MemPool, (gctPOINTER) Pointer); \
248     gcmFOOTER(); \
249     return status; \
250 }
251
252 #define gcmMEM_DeclareAFSMemPool(Type, TypeName, Prefix) \
253 gceSTATUS \
254 Prefix##_Allocate##TypeName( \
255     gcsMEM_AFS_MEM_POOL        MemPool, \
256     Type **                    Pointer, \
257     gctUINT                    Count \
258     ) \
259 { \
260     gceSTATUS               status; \
261     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
262     status = gcfMEM_AFSMemPoolGetANode(MemPool, Count, (gctPOINTER *) Pointer); \
263     gcmFOOTER(); \
264     return status; \
265 } \
266  \
267 gceSTATUS \
268 Prefix##_CAllocate##TypeName( \
269     gcsMEM_AFS_MEM_POOL        MemPool, \
270     Type **                    Pointer, \
271     gctUINT                    Count \
272     ) \
273 { \
274     gceSTATUS                status; \
275     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
276     gcmERR_RETURN(gcfMEM_AFSMemPoolGetANode(MemPool, Count, (gctPOINTER *) Pointer)); \
277     gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, Count * gcmSIZEOF(Type)); \
278     gcmFOOTER(); \
279     return gcvSTATUS_OK; \
280 } \
281  \
282 gceSTATUS \
283 Prefix##_Free##TypeName( \
284     gcsMEM_AFS_MEM_POOL        MemPool, \
285     Type *                    Pointer \
286     ) \
287 { \
288     gceSTATUS               status; \
289     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
290     status = gcfMEM_AFSMemPoolFreeANode(MemPool, (gctPOINTER) Pointer); \
291     gcmFOOTER(); \
292     return status; \
293 }
294
295 #else
296
297 #define gcmMEM_DeclareFSMemPool(Type, TypeName, Prefix) \
298 gceSTATUS \
299 Prefix##_Allocate##TypeName( \
300     gcsMEM_FS_MEM_POOL        MemPool, \
301     Type **                    Pointer \
302     ) \
303 { \
304     gceSTATUS               status; \
305     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
306     status = gcoOS_Allocate(MemPool, \
307                             gcmSIZEOF(Type), \
308                             (gctPOINTER *) Pointer); \
309     gcmFOOTER(); \
310     return status; \
311 } \
312  \
313 gceSTATUS \
314 Prefix##_CAllocate##TypeName( \
315     gcsMEM_FS_MEM_POOL        MemPool, \
316     Type **                    Pointer \
317     ) \
318 { \
319     gceSTATUS                status; \
320     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
321     gcmERR_RETURN(gcoOS_Allocate(MemPool, \
322                             gcmSIZEOF(Type), \
323                             (gctPOINTER *) Pointer)); \
324     gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, gcmSIZEOF(Type)); \
325     gcmFOOTER(); \
326     return gcvSTATUS_OK; \
327 } \
328  \
329 gceSTATUS \
330 Prefix##_Free##TypeName( \
331     gcsMEM_FS_MEM_POOL        MemPool, \
332     Type *                    Pointer \
333     ) \
334 { \
335     gceSTATUS                status; \
336     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
337     status = gcmOS_SAFE_FREE(MemPool, Pointer); \
338     gcmFOOTER(); \
339     return status; \
340 }
341
342 #define gcmMEM_DeclareVSMemPool(Type, TypeName, Prefix) \
343 gceSTATUS \
344 Prefix##_Allocate##TypeName( \
345     gcsMEM_VS_MEM_POOL        MemPool, \
346     Type **                    Pointer, \
347     gctUINT                    Size \
348     ) \
349 { \
350     gceSTATUS                status; \
351     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
352     status = gcoOS_Allocate(MemPool, \
353                             Size, \
354                             (gctPOINTER *) Pointer); \
355     gcmFOOTER(); \
356     return status; \
357 } \
358  \
359 gceSTATUS \
360 Prefix##_CAllocate##TypeName( \
361     gcsMEM_VS_MEM_POOL        MemPool, \
362     Type **                    Pointer, \
363     gctUINT                    Size \
364     ) \
365 { \
366     gceSTATUS                status; \
367     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
368     gcmERR_RETURN(gcoOS_Allocate(MemPool, \
369                             Size, \
370                             (gctPOINTER *) Pointer)); \
371     gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, Size); \
372     gcmFOOTER(); \
373     return gcvSTATUS_OK; \
374 } \
375  \
376 gceSTATUS \
377 Prefix##_Free##TypeName( \
378     gcsMEM_VS_MEM_POOL        MemPool, \
379     Type *                    Pointer \
380     ) \
381 { \
382     gceSTATUS                status; \
383     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
384     status = gcmOS_SAFE_FREE(MemPool, Pointer); \
385     gcmFOOTER(); \
386     return status; \
387 }
388
389 #define gcmMEM_DeclareAFSMemPool(Type, TypeName, Prefix) \
390 gceSTATUS \
391 Prefix##_Allocate##TypeName( \
392     gcsMEM_AFS_MEM_POOL        MemPool, \
393     Type **                    Pointer, \
394     gctUINT                    Count \
395     ) \
396 { \
397     gceSTATUS                status; \
398     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
399     status = gcoOS_Allocate(MemPool, \
400                             Count * gcmSIZEOF(Type), \
401                             (gctPOINTER *) Pointer); \
402     gcmFOOTER(); \
403     return status; \
404 } \
405  \
406 gceSTATUS \
407 Prefix##_CAllocate##TypeName( \
408     gcsMEM_AFS_MEM_POOL        MemPool, \
409     Type **                    Pointer, \
410     gctUINT                    Count \
411     ) \
412 { \
413     gceSTATUS                status; \
414     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
415     gcmERR_RETURN(gcoOS_Allocate(MemPool, \
416                             Count * gcmSIZEOF(Type), \
417                             (gctPOINTER *) Pointer)); \
418     gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, Count * gcmSIZEOF(Type)); \
419     gcmFOOTER(); \
420     return gcvSTATUS_OK; \
421 } \
422  \
423 gceSTATUS \
424 Prefix##_Free##TypeName( \
425     gcsMEM_AFS_MEM_POOL        MemPool, \
426     Type *                    Pointer \
427     ) \
428 { \
429     gceSTATUS                status; \
430     gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
431     status = gcmOS_SAFE_FREE(MemPool, Pointer); \
432     gcmFOOTER(); \
433     return status; \
434 }
435 #endif
436
437 /*******************************************************************************
438 **                            Memory Pool Data Functions
439 *******************************************************************************/
440 gceSTATUS
441 gcfMEM_InitFSMemPool(
442     IN gcsMEM_FS_MEM_POOL * MemPool,
443     IN gcoOS                OS,
444     IN gctUINT                NodeCount,
445     IN gctUINT                NodeSize
446     );
447
448 gceSTATUS
449 gcfMEM_FreeFSMemPool(
450     IN gcsMEM_FS_MEM_POOL * MemPool
451     );
452
453 gceSTATUS
454 gcfMEM_FSMemPoolGetANode(
455     IN gcsMEM_FS_MEM_POOL    MemPool,
456     OUT gctPOINTER *        Node
457     );
458
459 gceSTATUS
460 gcfMEM_FSMemPoolFreeANode(
461     IN gcsMEM_FS_MEM_POOL    MemPool,
462     IN gctPOINTER            Node
463     );
464
465 gceSTATUS
466 gcfMEM_FSMemPoolFreeAList(
467     IN gcsMEM_FS_MEM_POOL    MemPool,
468     IN gctPOINTER            FirstNode,
469     IN gctPOINTER            LastNode
470     );
471
472 gceSTATUS
473 gcfMEM_InitVSMemPool(
474     IN gcsMEM_VS_MEM_POOL * MemPool,
475     IN gcoOS                OS,
476     IN gctUINT                BlockSize,
477     IN gctBOOL                RecycleFreeNode
478     );
479
480 gceSTATUS
481 gcfMEM_FreeVSMemPool(
482     IN gcsMEM_VS_MEM_POOL * MemPool
483     );
484
485 gceSTATUS
486 gcfMEM_VSMemPoolGetANode(
487     IN gcsMEM_VS_MEM_POOL    MemPool,
488     IN gctUINT                Size,
489     IN gctUINT                Alignment,
490     OUT gctPOINTER *        Node
491     );
492
493 gceSTATUS
494 gcfMEM_VSMemPoolFreeANode(
495     IN gcsMEM_VS_MEM_POOL    MemPool,
496     IN gctPOINTER            Node
497     );
498
499 gceSTATUS
500 gcfMEM_InitAFSMemPool(
501     IN gcsMEM_AFS_MEM_POOL *MemPool,
502     IN gcoOS                OS,
503     IN gctUINT                NodeCount,
504     IN gctUINT                NodeSize
505     );
506
507 gceSTATUS
508 gcfMEM_FreeAFSMemPool(
509     IN gcsMEM_AFS_MEM_POOL *MemPool
510     );
511
512 gceSTATUS
513 gcfMEM_AFSMemPoolGetANode(
514     IN gcsMEM_AFS_MEM_POOL    MemPool,
515     IN gctUINT                Count,
516     OUT gctPOINTER *        Node
517     );
518
519 gceSTATUS
520 gcfMEM_AFSMemPoolFreeANode(
521     IN gcsMEM_AFS_MEM_POOL    MemPool,
522     IN gctPOINTER            Node
523     );
524
525 #ifdef __cplusplus
526 }
527 #endif
528
529 #endif /* (gcdENABLE_3D || gcdENABLE_VG) */
530 #endif /* __gc_hal_mem_h_ */