ENGR00156850 gpu-viv: add gpu-viv driver source
[wandboard.git] / drivers / mxc / gpu-viv / hal / kernel / inc / gc_hal_mem.h
blob9599388d683d246268b410de482059e2821b4363
1 /****************************************************************************
3 * Copyright (C) 2005 - 2011 by Vivante Corp.
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.
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.
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.
19 *****************************************************************************/
25 ** Include file for the local memory management.
28 #ifndef __gc_hal_mem_h_
29 #define __gc_hal_mem_h_
30 #ifndef VIVANTE_NO_3D
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
36 /*******************************************************************************
37 ** Usage:
39 The macros to declare MemPool type and functions are
40 gcmMEM_DeclareFSMemPool (Type, TypeName, Prefix)
41 gcmMEM_DeclareVSMemPool (Type, TypeName, Prefix)
42 gcmMEM_DeclareAFSMemPool(Type, TypeName, Prefix)
44 The data structures for MemPool are
45 typedef struct _gcsMEM_FS_MEM_POOL * gcsMEM_FS_MEM_POOL;
46 typedef struct _gcsMEM_VS_MEM_POOL * gcsMEM_VS_MEM_POOL;
47 typedef struct _gcsMEM_AFS_MEM_POOL * gcsMEM_AFS_MEM_POOL;
49 The MemPool constructor and destructor functions are
50 gcfMEM_InitFSMemPool(gcsMEM_FS_MEM_POOL *, gcoOS, gctUINT, gctUINT);
51 gcfMEM_FreeFSMemPool(gcsMEM_FS_MEM_POOL *);
52 gcfMEM_InitVSMemPool(gcsMEM_VS_MEM_POOL *, gcoOS, gctUINT, gctBOOL);
53 gcfMEM_FreeVSMemPool(gcsMEM_VS_MEM_POOL *);
54 gcfMEM_InitAFSMemPool(gcsMEM_AFS_MEM_POOL *, gcoOS, gctUINT);
55 gcfMEM_FreeAFSMemPool(gcsMEM_AFS_MEM_POOL *);
57 FS: for Fixed-Size data structures
58 VS: for Variable-size data structures
59 AFS: for Array of Fixed-Size data structures
62 // Example 1: For a fixed-size data structure, struct gcsNode.
63 // It is used locally in a file, so the functions are static without prefix.
64 // At top level, declear allocate and free functions.
65 // The first argument is the data type.
66 // The second armument is the short name used in the fuctions.
67 gcmMEM_DeclareFSMemPool(struct gcsNode, Node, );
69 // The previous macro creates two inline functions,
70 // _AllocateNode and _FreeNode.
72 // In function or struct
73 gcsMEM_FS_MEM_POOL nodeMemPool;
75 // In function,
76 struct gcsNode * node;
77 gceSTATUS status;
79 // Before using the memory pool, initialize it.
80 // The second argument is the gcoOS object.
81 // The third argument is the number of data structures to allocate for each chunk.
82 status = gcfMEM_InitFSMemPool(&nodeMemPool, os, 100, sizeof(struct gcsNode));
83 ...
85 // Allocate a node.
86 status = _AllocateNode(nodeMemPool, &node);
87 ...
88 // Free a node.
89 _FreeNode(nodeMemPool, node);
91 // After using the memory pool, free it.
92 gcfMEM_FreeFSMemPool(&nodeMemPool);
95 // Example 2: For array of fixed-size data structures, struct gcsNode.
96 // It is used in several files, so the functions are extern with prefix.
97 // At top level, declear allocate and free functions.
98 // The first argument is the data type, and the second one is the short name
99 // used in the fuctions.
100 gcmMEM_DeclareAFSMemPool(struct gcsNode, NodeArray, gcfOpt);
102 // The previous macro creates two inline functions,
103 // gcfOpt_AllocateNodeArray and gcfOpt_FreeNodeArray.
105 // In function or struct
106 gcsMEM_AFS_MEM_POOL nodeArrayMemPool;
108 // In function,
109 struct gcsNode * nodeArray;
110 gceSTATUS status;
112 // Before using the array memory pool, initialize it.
113 // The second argument is the gcoOS object, the third is the number of data
114 // structures to allocate for each chunk.
115 status = gcfMEM_InitAFSMemPool(&nodeArrayMemPool, os, sizeof(struct gcsNode));
118 // Allocate a node array of size 100.
119 status = gcfOpt_AllocateNodeArray(nodeArrayMemPool, &nodeArray, 100);
121 // Free a node array.
122 gcfOpt_FreeNodeArray(&nodeArrayMemPool, nodeArray);
124 // After using the array memory pool, free it.
125 gcfMEM_FreeAFSMemPool(&nodeArrayMemPool);
127 *******************************************************************************/
129 /*******************************************************************************
130 ** To switch back to use gcoOS_Allocate and gcoOS_Free, add
131 ** #define USE_LOCAL_MEMORY_POOL 0
132 ** before including this file.
133 *******************************************************************************/
134 #ifndef USE_LOCAL_MEMORY_POOL
136 USE_LOCAL_MEMORY_POOL
138 This define enables the local memory management to improve performance.
140 #define USE_LOCAL_MEMORY_POOL 1
141 #endif
143 /*******************************************************************************
144 ** Memory Pool Data Structures
145 *******************************************************************************/
146 #if USE_LOCAL_MEMORY_POOL
147 typedef struct _gcsMEM_FS_MEM_POOL * gcsMEM_FS_MEM_POOL;
148 typedef struct _gcsMEM_VS_MEM_POOL * gcsMEM_VS_MEM_POOL;
149 typedef struct _gcsMEM_AFS_MEM_POOL * gcsMEM_AFS_MEM_POOL;
150 #else
151 typedef gcoOS gcsMEM_FS_MEM_POOL;
152 typedef gcoOS gcsMEM_VS_MEM_POOL;
153 typedef gcoOS gcsMEM_AFS_MEM_POOL;
154 #endif
156 /*******************************************************************************
157 ** Memory Pool Macros
158 *******************************************************************************/
159 #if USE_LOCAL_MEMORY_POOL
160 #define gcmMEM_DeclareFSMemPool(Type, TypeName, Prefix) \
161 gceSTATUS \
162 Prefix##_Allocate##TypeName( \
163 gcsMEM_FS_MEM_POOL MemPool, \
164 Type ** Pointer \
167 return(gcfMEM_FSMemPoolGetANode(MemPool, (gctPOINTER *) Pointer)); \
170 gceSTATUS \
171 Prefix##_CAllocate##TypeName( \
172 gcsMEM_FS_MEM_POOL MemPool, \
173 Type ** Pointer \
176 gceSTATUS status; \
177 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
178 gcmERR_RETURN(gcfMEM_FSMemPoolGetANode(MemPool, (gctPOINTER *) Pointer)); \
179 gcmVERIFY_OK(gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, gcmSIZEOF(Type))); \
180 gcmFOOTER(); \
181 return gcvSTATUS_OK; \
184 gceSTATUS \
185 Prefix##_Free##TypeName( \
186 gcsMEM_FS_MEM_POOL MemPool, \
187 Type * Pointer \
190 gceSTATUS status; \
191 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
192 status = gcfMEM_FSMemPoolFreeANode(MemPool, (gctPOINTER) Pointer); \
193 gcmFOOTER(); \
194 return status; \
197 gceSTATUS \
198 Prefix##_Free##TypeName##List( \
199 gcsMEM_FS_MEM_POOL MemPool, \
200 Type * FirstPointer, \
201 Type * LastPointer \
204 gceSTATUS status; \
205 gcmHEADER_ARG("MemPool=0x%x FirstPointer=0x%x LastPointer=0x%x", MemPool, FirstPointer, LastPointer); \
206 status = gcfMEM_FSMemPoolFreeAList(MemPool, (gctPOINTER) FirstPointer, (gctPOINTER) LastPointer); \
207 gcmFOOTER(); \
208 return status; \
211 #define gcmMEM_DeclareVSMemPool(Type, TypeName, Prefix) \
212 gceSTATUS \
213 Prefix##_Allocate##TypeName( \
214 gcsMEM_FS_MEM_POOL MemPool, \
215 Type ** Pointer, \
216 gctUINT Size \
219 gceSTATUS status;\
220 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
221 status = gcfMEM_VSMemPoolGetANode(MemPool, Size, (gctPOINTER *) Pointer); \
222 gcmFOOTER(); \
223 return status; \
226 gceSTATUS \
227 Prefix##_CAllocate##TypeName( \
228 gcsMEM_FS_MEM_POOL MemPool, \
229 Type ** Pointer, \
230 gctUINT Size \
233 gceSTATUS status; \
234 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
235 gcmERR_RETURN(gcfMEM_VSMemPoolGetANode(MemPool, Size, (gctPOINTER *) Pointer)); \
236 gcmVERIFY_OK(gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, size)); \
237 gcmFOOTER(); \
238 return gcvSTATUS_OK; \
241 gceSTATUS \
242 Prefix##_Free##TypeName( \
243 gcsMEM_FS_MEM_POOL MemPool, \
244 Type * Pointer \
247 gceSTATUS status; \
248 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pinter); \
249 status = gcfMEM_VSMemPoolFreeANode(MemPool, (gctPOINTER) Pointer); \
250 gcmFOOTER(); \
251 return status; \
254 #define gcmMEM_DeclareAFSMemPool(Type, TypeName, Prefix) \
255 gceSTATUS \
256 Prefix##_Allocate##TypeName( \
257 gcsMEM_AFS_MEM_POOL MemPool, \
258 Type ** Pointer, \
259 gctUINT Count \
262 gceSTATUS status; \
263 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
264 status = gcfMEM_AFSMemPoolGetANode(MemPool, Count, (gctPOINTER *) Pointer); \
265 gcmFOOTER(); \
266 return status; \
269 gceSTATUS \
270 Prefix##_CAllocate##TypeName( \
271 gcsMEM_AFS_MEM_POOL MemPool, \
272 Type ** Pointer, \
273 gctUINT Count \
276 gceSTATUS status; \
277 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
278 gcmERR_RETURN(gcfMEM_AFSMemPoolGetANode(MemPool, Count, (gctPOINTER *) Pointer)); \
279 gcmVERIFY_OK(gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, Count * gcmSIZEOF(Type))); \
280 gcmFOOTER(); \
281 return gcvSTATUS_OK; \
284 gceSTATUS \
285 Prefix##_Free##TypeName( \
286 gcsMEM_AFS_MEM_POOL MemPool, \
287 Type * Pointer \
290 gceSTATUS status; \
291 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
292 status = gcfMEM_AFSMemPoolFreeANode(MemPool, (gctPOINTER) Pointer); \
293 gcmFOOTER(); \
294 return status; \
297 #else
299 #define gcmMEM_DeclareFSMemPool(Type, TypeName, Prefix) \
300 gceSTATUS \
301 Prefix##_Allocate##TypeName( \
302 gcsMEM_FS_MEM_POOL MemPool, \
303 Type ** Pointer \
306 gceSTATUS status; \
307 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
308 status = gcoOS_Allocate(MemPool, \
309 gcmSIZEOF(Type), \
310 (gctPOINTER *) Pointer); \
311 gcmFOOTER(); \
312 return status; \
315 gceSTATUS \
316 Prefix##_CAllocate##TypeName( \
317 gcsMEM_FS_MEM_POOL MemPool, \
318 Type ** Pointer \
321 gceSTATUS status; \
322 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
323 gcmERR_RETURN(gcoOS_Allocate(MemPool, \
324 gcmSIZEOF(Type), \
325 (gctPOINTER *) Pointer)); \
326 gcmVERIFY_OK(gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, gcmSIZEOF(Type))); \
327 gcmFOOTER(); \
328 return gcvSTATUS_OK; \
331 gceSTATUS \
332 Prefix##_Free##TypeName( \
333 gcsMEM_FS_MEM_POOL MemPool, \
334 Type * Pointer \
337 gceSTATUS status; \
338 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
339 status = gcmOS_SAFE_FREE(MemPool, Pointer); \
340 gcmFOOTER(); \
341 return status; \
344 #define gcmMEM_DeclareVSMemPool(Type, TypeName, Prefix) \
345 gceSTATUS \
346 Prefix##_Allocate##TypeName( \
347 gcsMEM_VS_MEM_POOL MemPool, \
348 Type ** Pointer, \
349 gctUINT Size \
352 gceSTATUS status; \
353 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
354 status = gcoOS_Allocate(MemPool, \
355 Size, \
356 (gctPOINTER *) Pointer); \
357 gcmFOOTER(); \
358 return status; \
361 gceSTATUS \
362 Prefix##_CAllocate##TypeName( \
363 gcsMEM_VS_MEM_POOL MemPool, \
364 Type ** Pointer, \
365 gctUINT Size \
368 gceSTATUS status; \
369 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
370 gcmERR_RETURN(gcoOS_Allocate(MemPool, \
371 Size, \
372 (gctPOINTER *) Pointer)); \
373 gcmVERIFY_OK(gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, Size)); \
374 gcmFOOTER(); \
375 return gcvSTATUS_OK; \
378 gceSTATUS \
379 Prefix##_Free##TypeName( \
380 gcsMEM_VS_MEM_POOL MemPool, \
381 Type * Pointer \
384 gceSTATUS status; \
385 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
386 status = gcmOS_SAFE_FREE(MemPool, Pointer); \
387 gcmFOOTER(); \
388 return status; \
391 #define gcmMEM_DeclareAFSMemPool(Type, TypeName, Prefix) \
392 gceSTATUS \
393 Prefix##_Allocate##TypeName( \
394 gcsMEM_AFS_MEM_POOL MemPool, \
395 Type ** Pointer, \
396 gctUINT Count \
399 gceSTATUS status; \
400 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
401 status = gcoOS_Allocate(MemPool, \
402 Count * gcmSIZEOF(Type), \
403 (gctPOINTER *) Pointer); \
404 gcmFOOTER(); \
405 return status; \
408 gceSTATUS \
409 Prefix##_CAllocate##TypeName( \
410 gcsMEM_AFS_MEM_POOL MemPool, \
411 Type ** Pointer, \
412 gctUINT Count \
415 gceSTATUS status; \
416 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
417 gcmERR_RETURN(gcoOS_Allocate(MemPool, \
418 Count * gcmSIZEOF(Type), \
419 (gctPOINTER *) Pointer)); \
420 gcmVERIFY_OK(gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, Count * gcmSIZEOF(Type))); \
421 gcmFOOTER(); \
422 return gcvSTATUS_OK; \
425 gceSTATUS \
426 Prefix##_Free##TypeName( \
427 gcsMEM_AFS_MEM_POOL MemPool, \
428 Type * Pointer \
431 gceSTATUS status; \
432 gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
433 status = gcmOS_SAFE_FREE(MemPool, Pointer); \
434 gcmFOOTER(); \
435 return status; \
437 #endif
439 /*******************************************************************************
440 ** Memory Pool Data Functions
441 *******************************************************************************/
442 gceSTATUS
443 gcfMEM_InitFSMemPool(
444 IN gcsMEM_FS_MEM_POOL * MemPool,
445 IN gcoOS OS,
446 IN gctUINT NodeCount,
447 IN gctUINT NodeSize
450 gceSTATUS
451 gcfMEM_FreeFSMemPool(
452 IN gcsMEM_FS_MEM_POOL * MemPool
455 gceSTATUS
456 gcfMEM_FSMemPoolGetANode(
457 IN gcsMEM_FS_MEM_POOL MemPool,
458 OUT gctPOINTER * Node
461 gceSTATUS
462 gcfMEM_FSMemPoolFreeANode(
463 IN gcsMEM_FS_MEM_POOL MemPool,
464 IN gctPOINTER Node
467 gceSTATUS
468 gcfMEM_FSMemPoolFreeAList(
469 IN gcsMEM_FS_MEM_POOL MemPool,
470 IN gctPOINTER FirstNode,
471 IN gctPOINTER LastNode
474 gceSTATUS
475 gcfMEM_InitVSMemPool(
476 IN gcsMEM_VS_MEM_POOL * MemPool,
477 IN gcoOS OS,
478 IN gctUINT BlockSize,
479 IN gctBOOL RecycleFreeNode
482 gceSTATUS
483 gcfMEM_FreeVSMemPool(
484 IN gcsMEM_VS_MEM_POOL * MemPool
487 gceSTATUS
488 gcfMEM_VSMemPoolGetANode(
489 IN gcsMEM_VS_MEM_POOL MemPool,
490 IN gctUINT Size,
491 IN gctUINT Alignment,
492 OUT gctPOINTER * Node
495 gceSTATUS
496 gcfMEM_VSMemPoolFreeANode(
497 IN gcsMEM_VS_MEM_POOL MemPool,
498 IN gctPOINTER Node
501 gceSTATUS
502 gcfMEM_InitAFSMemPool(
503 IN gcsMEM_AFS_MEM_POOL *MemPool,
504 IN gcoOS OS,
505 IN gctUINT NodeCount,
506 IN gctUINT NodeSize
509 gceSTATUS
510 gcfMEM_FreeAFSMemPool(
511 IN gcsMEM_AFS_MEM_POOL *MemPool
514 gceSTATUS
515 gcfMEM_AFSMemPoolGetANode(
516 IN gcsMEM_AFS_MEM_POOL MemPool,
517 IN gctUINT Count,
518 OUT gctPOINTER * Node
521 gceSTATUS
522 gcfMEM_AFSMemPoolFreeANode(
523 IN gcsMEM_AFS_MEM_POOL MemPool,
524 IN gctPOINTER Node
527 #ifdef __cplusplus
529 #endif
531 #endif /* VIVANTE_NO_3D */
532 #endif /* __gc_hal_mem_h_ */