PageRenderTime 32ms CodeModel.GetById 56ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/mxc/gpu-viv-3.10.17/hal/kernel/inc/gc_hal_mem.h

https://gitlab.com/gioge/linux-imx_3.10.53_1.1.0_ga
C Header | 530 lines | 368 code | 29 blank | 133 comment | 0 complexity | 998a7fbfa0ccdc82c531dd94aa131cba MD5 | raw file
  1. /****************************************************************************
  2. *
  3. * Copyright (C) 2005 - 2013 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. ** Include file for the local memory management.
  22. */
  23. #ifndef __gc_hal_mem_h_
  24. #define __gc_hal_mem_h_
  25. #ifndef VIVANTE_NO_3D
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /*******************************************************************************
  30. ** Usage:
  31. The macros to declare MemPool type and functions are
  32. gcmMEM_DeclareFSMemPool (Type, TypeName, Prefix)
  33. gcmMEM_DeclareVSMemPool (Type, TypeName, Prefix)
  34. gcmMEM_DeclareAFSMemPool(Type, TypeName, Prefix)
  35. The data structures for MemPool are
  36. typedef struct _gcsMEM_FS_MEM_POOL * gcsMEM_FS_MEM_POOL;
  37. typedef struct _gcsMEM_VS_MEM_POOL * gcsMEM_VS_MEM_POOL;
  38. typedef struct _gcsMEM_AFS_MEM_POOL * gcsMEM_AFS_MEM_POOL;
  39. The MemPool constructor and destructor functions are
  40. gcfMEM_InitFSMemPool(gcsMEM_FS_MEM_POOL *, gcoOS, gctUINT, gctUINT);
  41. gcfMEM_FreeFSMemPool(gcsMEM_FS_MEM_POOL *);
  42. gcfMEM_InitVSMemPool(gcsMEM_VS_MEM_POOL *, gcoOS, gctUINT, gctBOOL);
  43. gcfMEM_FreeVSMemPool(gcsMEM_VS_MEM_POOL *);
  44. gcfMEM_InitAFSMemPool(gcsMEM_AFS_MEM_POOL *, gcoOS, gctUINT);
  45. gcfMEM_FreeAFSMemPool(gcsMEM_AFS_MEM_POOL *);
  46. FS: for Fixed-Size data structures
  47. VS: for Variable-size data structures
  48. AFS: for Array of Fixed-Size data structures
  49. // Example 1: For a fixed-size data structure, struct gcsNode.
  50. // It is used locally in a file, so the functions are static without prefix.
  51. // At top level, declear allocate and free functions.
  52. // The first argument is the data type.
  53. // The second armument is the short name used in the fuctions.
  54. gcmMEM_DeclareFSMemPool(struct gcsNode, Node, );
  55. // The previous macro creates two inline functions,
  56. // _AllocateNode and _FreeNode.
  57. // In function or struct
  58. gcsMEM_FS_MEM_POOL nodeMemPool;
  59. // In function,
  60. struct gcsNode * node;
  61. gceSTATUS status;
  62. // Before using the memory pool, initialize it.
  63. // The second argument is the gcoOS object.
  64. // The third argument is the number of data structures to allocate for each chunk.
  65. status = gcfMEM_InitFSMemPool(&nodeMemPool, os, 100, sizeof(struct gcsNode));
  66. ...
  67. // Allocate a node.
  68. status = _AllocateNode(nodeMemPool, &node);
  69. ...
  70. // Free a node.
  71. _FreeNode(nodeMemPool, node);
  72. // After using the memory pool, free it.
  73. gcfMEM_FreeFSMemPool(&nodeMemPool);
  74. // Example 2: For array of fixed-size data structures, struct gcsNode.
  75. // It is used in several files, so the functions are extern with prefix.
  76. // At top level, declear allocate and free functions.
  77. // The first argument is the data type, and the second one is the short name
  78. // used in the fuctions.
  79. gcmMEM_DeclareAFSMemPool(struct gcsNode, NodeArray, gcfOpt);
  80. // The previous macro creates two inline functions,
  81. // gcfOpt_AllocateNodeArray and gcfOpt_FreeNodeArray.
  82. // In function or struct
  83. gcsMEM_AFS_MEM_POOL nodeArrayMemPool;
  84. // In function,
  85. struct gcsNode * nodeArray;
  86. gceSTATUS status;
  87. // Before using the array memory pool, initialize it.
  88. // The second argument is the gcoOS object, the third is the number of data
  89. // structures to allocate for each chunk.
  90. status = gcfMEM_InitAFSMemPool(&nodeArrayMemPool, os, sizeof(struct gcsNode));
  91. ...
  92. // Allocate a node array of size 100.
  93. status = gcfOpt_AllocateNodeArray(nodeArrayMemPool, &nodeArray, 100);
  94. ...
  95. // Free a node array.
  96. gcfOpt_FreeNodeArray(&nodeArrayMemPool, nodeArray);
  97. // After using the array memory pool, free it.
  98. gcfMEM_FreeAFSMemPool(&nodeArrayMemPool);
  99. *******************************************************************************/
  100. /*******************************************************************************
  101. ** To switch back to use gcoOS_Allocate and gcoOS_Free, add
  102. ** #define USE_LOCAL_MEMORY_POOL 0
  103. ** before including this file.
  104. *******************************************************************************/
  105. #ifndef USE_LOCAL_MEMORY_POOL
  106. /*
  107. USE_LOCAL_MEMORY_POOL
  108. This define enables the local memory management to improve performance.
  109. */
  110. #define USE_LOCAL_MEMORY_POOL 1
  111. #endif
  112. /*******************************************************************************
  113. ** Memory Pool Data Structures
  114. *******************************************************************************/
  115. #if USE_LOCAL_MEMORY_POOL
  116. typedef struct _gcsMEM_FS_MEM_POOL * gcsMEM_FS_MEM_POOL;
  117. typedef struct _gcsMEM_VS_MEM_POOL * gcsMEM_VS_MEM_POOL;
  118. typedef struct _gcsMEM_AFS_MEM_POOL * gcsMEM_AFS_MEM_POOL;
  119. #else
  120. typedef gcoOS gcsMEM_FS_MEM_POOL;
  121. typedef gcoOS gcsMEM_VS_MEM_POOL;
  122. typedef gcoOS gcsMEM_AFS_MEM_POOL;
  123. #endif
  124. /*******************************************************************************
  125. ** Memory Pool Macros
  126. *******************************************************************************/
  127. #if USE_LOCAL_MEMORY_POOL
  128. #define gcmMEM_DeclareFSMemPool(Type, TypeName, Prefix) \
  129. gceSTATUS \
  130. Prefix##_Allocate##TypeName( \
  131. gcsMEM_FS_MEM_POOL MemPool, \
  132. Type ** Pointer \
  133. ) \
  134. { \
  135. return(gcfMEM_FSMemPoolGetANode(MemPool, (gctPOINTER *) Pointer)); \
  136. } \
  137. \
  138. gceSTATUS \
  139. Prefix##_CAllocate##TypeName( \
  140. gcsMEM_FS_MEM_POOL MemPool, \
  141. Type ** Pointer \
  142. ) \
  143. { \
  144. gceSTATUS status; \
  145. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
  146. gcmERR_RETURN(gcfMEM_FSMemPoolGetANode(MemPool, (gctPOINTER *) Pointer)); \
  147. gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, gcmSIZEOF(Type)); \
  148. gcmFOOTER(); \
  149. return gcvSTATUS_OK; \
  150. } \
  151. \
  152. gceSTATUS \
  153. Prefix##_Free##TypeName( \
  154. gcsMEM_FS_MEM_POOL MemPool, \
  155. Type * Pointer \
  156. ) \
  157. { \
  158. gceSTATUS status; \
  159. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
  160. status = gcfMEM_FSMemPoolFreeANode(MemPool, (gctPOINTER) Pointer); \
  161. gcmFOOTER(); \
  162. return status; \
  163. } \
  164. \
  165. gceSTATUS \
  166. Prefix##_Free##TypeName##List( \
  167. gcsMEM_FS_MEM_POOL MemPool, \
  168. Type * FirstPointer, \
  169. Type * LastPointer \
  170. ) \
  171. { \
  172. gceSTATUS status; \
  173. gcmHEADER_ARG("MemPool=0x%x FirstPointer=0x%x LastPointer=0x%x", MemPool, FirstPointer, LastPointer); \
  174. status = gcfMEM_FSMemPoolFreeAList(MemPool, (gctPOINTER) FirstPointer, (gctPOINTER) LastPointer); \
  175. gcmFOOTER(); \
  176. return status; \
  177. }
  178. #define gcmMEM_DeclareVSMemPool(Type, TypeName, Prefix) \
  179. gceSTATUS \
  180. Prefix##_Allocate##TypeName( \
  181. gcsMEM_FS_MEM_POOL MemPool, \
  182. Type ** Pointer, \
  183. gctUINT Size \
  184. ) \
  185. { \
  186. gceSTATUS status;\
  187. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
  188. status = gcfMEM_VSMemPoolGetANode(MemPool, Size, (gctPOINTER *) Pointer); \
  189. gcmFOOTER(); \
  190. return status; \
  191. } \
  192. \
  193. gceSTATUS \
  194. Prefix##_CAllocate##TypeName( \
  195. gcsMEM_FS_MEM_POOL MemPool, \
  196. Type ** Pointer, \
  197. gctUINT Size \
  198. ) \
  199. { \
  200. gceSTATUS status; \
  201. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
  202. gcmERR_RETURN(gcfMEM_VSMemPoolGetANode(MemPool, Size, (gctPOINTER *) Pointer)); \
  203. gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, size); \
  204. gcmFOOTER(); \
  205. return gcvSTATUS_OK; \
  206. } \
  207. \
  208. gceSTATUS \
  209. Prefix##_Free##TypeName( \
  210. gcsMEM_FS_MEM_POOL MemPool, \
  211. Type * Pointer \
  212. ) \
  213. { \
  214. gceSTATUS status; \
  215. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pinter); \
  216. status = gcfMEM_VSMemPoolFreeANode(MemPool, (gctPOINTER) Pointer); \
  217. gcmFOOTER(); \
  218. return status; \
  219. }
  220. #define gcmMEM_DeclareAFSMemPool(Type, TypeName, Prefix) \
  221. gceSTATUS \
  222. Prefix##_Allocate##TypeName( \
  223. gcsMEM_AFS_MEM_POOL MemPool, \
  224. Type ** Pointer, \
  225. gctUINT Count \
  226. ) \
  227. { \
  228. gceSTATUS status; \
  229. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
  230. status = gcfMEM_AFSMemPoolGetANode(MemPool, Count, (gctPOINTER *) Pointer); \
  231. gcmFOOTER(); \
  232. return status; \
  233. } \
  234. \
  235. gceSTATUS \
  236. Prefix##_CAllocate##TypeName( \
  237. gcsMEM_AFS_MEM_POOL MemPool, \
  238. Type ** Pointer, \
  239. gctUINT Count \
  240. ) \
  241. { \
  242. gceSTATUS status; \
  243. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
  244. gcmERR_RETURN(gcfMEM_AFSMemPoolGetANode(MemPool, Count, (gctPOINTER *) Pointer)); \
  245. gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, Count * gcmSIZEOF(Type)); \
  246. gcmFOOTER(); \
  247. return gcvSTATUS_OK; \
  248. } \
  249. \
  250. gceSTATUS \
  251. Prefix##_Free##TypeName( \
  252. gcsMEM_AFS_MEM_POOL MemPool, \
  253. Type * Pointer \
  254. ) \
  255. { \
  256. gceSTATUS status; \
  257. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
  258. status = gcfMEM_AFSMemPoolFreeANode(MemPool, (gctPOINTER) Pointer); \
  259. gcmFOOTER(); \
  260. return status; \
  261. }
  262. #else
  263. #define gcmMEM_DeclareFSMemPool(Type, TypeName, Prefix) \
  264. gceSTATUS \
  265. Prefix##_Allocate##TypeName( \
  266. gcsMEM_FS_MEM_POOL MemPool, \
  267. Type ** Pointer \
  268. ) \
  269. { \
  270. gceSTATUS status; \
  271. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
  272. status = gcoOS_Allocate(MemPool, \
  273. gcmSIZEOF(Type), \
  274. (gctPOINTER *) Pointer); \
  275. gcmFOOTER(); \
  276. return status; \
  277. } \
  278. \
  279. gceSTATUS \
  280. Prefix##_CAllocate##TypeName( \
  281. gcsMEM_FS_MEM_POOL MemPool, \
  282. Type ** Pointer \
  283. ) \
  284. { \
  285. gceSTATUS status; \
  286. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
  287. gcmERR_RETURN(gcoOS_Allocate(MemPool, \
  288. gcmSIZEOF(Type), \
  289. (gctPOINTER *) Pointer)); \
  290. gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, gcmSIZEOF(Type)); \
  291. gcmFOOTER(); \
  292. return gcvSTATUS_OK; \
  293. } \
  294. \
  295. gceSTATUS \
  296. Prefix##_Free##TypeName( \
  297. gcsMEM_FS_MEM_POOL MemPool, \
  298. Type * Pointer \
  299. ) \
  300. { \
  301. gceSTATUS status; \
  302. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
  303. status = gcmOS_SAFE_FREE(MemPool, Pointer); \
  304. gcmFOOTER(); \
  305. return status; \
  306. }
  307. #define gcmMEM_DeclareVSMemPool(Type, TypeName, Prefix) \
  308. gceSTATUS \
  309. Prefix##_Allocate##TypeName( \
  310. gcsMEM_VS_MEM_POOL MemPool, \
  311. Type ** Pointer, \
  312. gctUINT Size \
  313. ) \
  314. { \
  315. gceSTATUS status; \
  316. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
  317. status = gcoOS_Allocate(MemPool, \
  318. Size, \
  319. (gctPOINTER *) Pointer); \
  320. gcmFOOTER(); \
  321. return status; \
  322. } \
  323. \
  324. gceSTATUS \
  325. Prefix##_CAllocate##TypeName( \
  326. gcsMEM_VS_MEM_POOL MemPool, \
  327. Type ** Pointer, \
  328. gctUINT Size \
  329. ) \
  330. { \
  331. gceSTATUS status; \
  332. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Size=%u", MemPool, Pointer, Size); \
  333. gcmERR_RETURN(gcoOS_Allocate(MemPool, \
  334. Size, \
  335. (gctPOINTER *) Pointer)); \
  336. gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, Size); \
  337. gcmFOOTER(); \
  338. return gcvSTATUS_OK; \
  339. } \
  340. \
  341. gceSTATUS \
  342. Prefix##_Free##TypeName( \
  343. gcsMEM_VS_MEM_POOL MemPool, \
  344. Type * Pointer \
  345. ) \
  346. { \
  347. gceSTATUS status; \
  348. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
  349. status = gcmOS_SAFE_FREE(MemPool, Pointer); \
  350. gcmFOOTER(); \
  351. return status; \
  352. }
  353. #define gcmMEM_DeclareAFSMemPool(Type, TypeName, Prefix) \
  354. gceSTATUS \
  355. Prefix##_Allocate##TypeName( \
  356. gcsMEM_AFS_MEM_POOL MemPool, \
  357. Type ** Pointer, \
  358. gctUINT Count \
  359. ) \
  360. { \
  361. gceSTATUS status; \
  362. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
  363. status = gcoOS_Allocate(MemPool, \
  364. Count * gcmSIZEOF(Type), \
  365. (gctPOINTER *) Pointer); \
  366. gcmFOOTER(); \
  367. return status; \
  368. } \
  369. \
  370. gceSTATUS \
  371. Prefix##_CAllocate##TypeName( \
  372. gcsMEM_AFS_MEM_POOL MemPool, \
  373. Type ** Pointer, \
  374. gctUINT Count \
  375. ) \
  376. { \
  377. gceSTATUS status; \
  378. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x Count=%u", MemPool, Pointer, Count); \
  379. gcmERR_RETURN(gcoOS_Allocate(MemPool, \
  380. Count * gcmSIZEOF(Type), \
  381. (gctPOINTER *) Pointer)); \
  382. gcoOS_ZeroMemory(*(gctPOINTER *) Pointer, Count * gcmSIZEOF(Type)); \
  383. gcmFOOTER(); \
  384. return gcvSTATUS_OK; \
  385. } \
  386. \
  387. gceSTATUS \
  388. Prefix##_Free##TypeName( \
  389. gcsMEM_AFS_MEM_POOL MemPool, \
  390. Type * Pointer \
  391. ) \
  392. { \
  393. gceSTATUS status; \
  394. gcmHEADER_ARG("MemPool=0x%x Pointer=0x%x", MemPool, Pointer); \
  395. status = gcmOS_SAFE_FREE(MemPool, Pointer); \
  396. gcmFOOTER(); \
  397. return status; \
  398. }
  399. #endif
  400. /*******************************************************************************
  401. ** Memory Pool Data Functions
  402. *******************************************************************************/
  403. gceSTATUS
  404. gcfMEM_InitFSMemPool(
  405. IN gcsMEM_FS_MEM_POOL * MemPool,
  406. IN gcoOS OS,
  407. IN gctUINT NodeCount,
  408. IN gctUINT NodeSize
  409. );
  410. gceSTATUS
  411. gcfMEM_FreeFSMemPool(
  412. IN gcsMEM_FS_MEM_POOL * MemPool
  413. );
  414. gceSTATUS
  415. gcfMEM_FSMemPoolGetANode(
  416. IN gcsMEM_FS_MEM_POOL MemPool,
  417. OUT gctPOINTER * Node
  418. );
  419. gceSTATUS
  420. gcfMEM_FSMemPoolFreeANode(
  421. IN gcsMEM_FS_MEM_POOL MemPool,
  422. IN gctPOINTER Node
  423. );
  424. gceSTATUS
  425. gcfMEM_FSMemPoolFreeAList(
  426. IN gcsMEM_FS_MEM_POOL MemPool,
  427. IN gctPOINTER FirstNode,
  428. IN gctPOINTER LastNode
  429. );
  430. gceSTATUS
  431. gcfMEM_InitVSMemPool(
  432. IN gcsMEM_VS_MEM_POOL * MemPool,
  433. IN gcoOS OS,
  434. IN gctUINT BlockSize,
  435. IN gctBOOL RecycleFreeNode
  436. );
  437. gceSTATUS
  438. gcfMEM_FreeVSMemPool(
  439. IN gcsMEM_VS_MEM_POOL * MemPool
  440. );
  441. gceSTATUS
  442. gcfMEM_VSMemPoolGetANode(
  443. IN gcsMEM_VS_MEM_POOL MemPool,
  444. IN gctUINT Size,
  445. IN gctUINT Alignment,
  446. OUT gctPOINTER * Node
  447. );
  448. gceSTATUS
  449. gcfMEM_VSMemPoolFreeANode(
  450. IN gcsMEM_VS_MEM_POOL MemPool,
  451. IN gctPOINTER Node
  452. );
  453. gceSTATUS
  454. gcfMEM_InitAFSMemPool(
  455. IN gcsMEM_AFS_MEM_POOL *MemPool,
  456. IN gcoOS OS,
  457. IN gctUINT NodeCount,
  458. IN gctUINT NodeSize
  459. );
  460. gceSTATUS
  461. gcfMEM_FreeAFSMemPool(
  462. IN gcsMEM_AFS_MEM_POOL *MemPool
  463. );
  464. gceSTATUS
  465. gcfMEM_AFSMemPoolGetANode(
  466. IN gcsMEM_AFS_MEM_POOL MemPool,
  467. IN gctUINT Count,
  468. OUT gctPOINTER * Node
  469. );
  470. gceSTATUS
  471. gcfMEM_AFSMemPoolFreeANode(
  472. IN gcsMEM_AFS_MEM_POOL MemPool,
  473. IN gctPOINTER Node
  474. );
  475. #ifdef __cplusplus
  476. }
  477. #endif
  478. #endif /* VIVANTE_NO_3D */
  479. #endif /* __gc_hal_mem_h_ */