physheap.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*************************************************************************/ /*!
  2. @File
  3. @Title Physical heap management header
  4. @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
  5. @Description Defines the interface for the physical heap management
  6. @License Dual MIT/GPLv2
  7. The contents of this file are subject to the MIT license as set out below.
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16. Alternatively, the contents of this file may be used under the terms of
  17. the GNU General Public License Version 2 ("GPL") in which case the provisions
  18. of GPL are applicable instead of those above.
  19. If you wish to allow use of your version of this file only under the terms of
  20. GPL, and not to allow others to use your version of this file under the terms
  21. of the MIT license, indicate your decision by deleting the provisions above
  22. and replace them with the notice and other provisions required by GPL as set
  23. out in the file called "GPL-COPYING" included in this distribution. If you do
  24. not delete the provisions above, a recipient may use your version of this file
  25. under the terms of either the MIT license or GPL.
  26. This License is also included in this distribution in the file called
  27. "MIT-COPYING".
  28. EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
  29. PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  30. BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  31. PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
  32. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  33. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  34. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35. */ /**************************************************************************/
  36. #include "img_types.h"
  37. #include "pvrsrv_error.h"
  38. #include "pvrsrv_memallocflags.h"
  39. #include "devicemem_typedefs.h"
  40. #include "opaque_types.h"
  41. #include "pmr_impl.h"
  42. #include "physheap_config.h"
  43. #ifndef PHYSHEAP_H
  44. #define PHYSHEAP_H
  45. typedef struct _PHYS_HEAP_ PHYS_HEAP;
  46. #define INVALID_PHYS_HEAP 0xDEADDEAD
  47. struct _CONNECTION_DATA_;
  48. /*! Pointer to private implementation specific data */
  49. typedef void *PHEAP_IMPL_DATA;
  50. /*************************************************************************/ /*!
  51. @Function Callback function PFN_DESTROY_DATA
  52. @Description Destroy private implementation specific data.
  53. @Input PHEAP_IMPL_DATA Pointer to implementation data.
  54. */ /**************************************************************************/
  55. typedef void (*PFN_DESTROY_DATA)(PHEAP_IMPL_DATA);
  56. /*************************************************************************/ /*!
  57. @Function Callback function PFN_GET_DEV_PADDR
  58. @Description Get heap device physical address.
  59. @Input PHEAP_IMPL_DATA Pointer to implementation data.
  60. @Output IMG_DEV_PHYADDR Device physical address.
  61. @Return PVRSRV_ERROR PVRSRV_OK or error code
  62. */ /**************************************************************************/
  63. typedef PVRSRV_ERROR (*PFN_GET_DEV_PADDR)(PHEAP_IMPL_DATA, IMG_DEV_PHYADDR*);
  64. /*************************************************************************/ /*!
  65. @Function Callback function PFN_GET_CPU_PADDR
  66. @Description Get heap CPU physical address.
  67. @Input PHEAP_IMPL_DATA Pointer to implementation data.
  68. @Output IMG_CPU_PHYADDR CPU physical address.
  69. @Return PVRSRV_ERROR PVRSRV_OK or error code
  70. */ /**************************************************************************/
  71. typedef PVRSRV_ERROR (*PFN_GET_CPU_PADDR)(PHEAP_IMPL_DATA, IMG_CPU_PHYADDR*);
  72. /*************************************************************************/ /*!
  73. @Function Callback function PFN_GET_SIZE
  74. @Description Get size of heap.
  75. @Input PHEAP_IMPL_DATA Pointer to implementation data.
  76. @Output IMG_UINT64 Size of heap.
  77. @Return PVRSRV_ERROR PVRSRV_OK or error code
  78. */ /**************************************************************************/
  79. typedef PVRSRV_ERROR (*PFN_GET_SIZE)(PHEAP_IMPL_DATA, IMG_UINT64*);
  80. /*************************************************************************/ /*!
  81. @Function Callback function PFN_GET_MEM_STATS
  82. @Description Get total and free memory size of the physical heap managed by
  83. the PMR Factory.
  84. @Input PHEAP_IMPL_DATA Pointer to implementation data.
  85. @Output IMG_UINT64 total Size of heap.
  86. @Output IMG_UINT64 free Size available in a heap.
  87. @Return none
  88. */ /**************************************************************************/
  89. typedef void (*PFN_GET_MEM_STATS)(PHEAP_IMPL_DATA, IMG_UINT64 *, IMG_UINT64 *);
  90. /*************************************************************************/ /*!
  91. @Function Callback function PFN_CREATE_PMR
  92. @Description Create a PMR physical allocation and back with RAM on creation,
  93. if required. The RAM page comes either directly from
  94. the Phys Heap's associated pool of memory or from an OS API.
  95. @Input psPhysHeap Pointer to Phys Heap.
  96. @Input psConnection Pointer to device connection.
  97. @Input uiSize Allocation size.
  98. @Input uiChunkSize Chunk size.
  99. @Input ui32NumPhysChunks Physical chunk count.
  100. @Input ui32NumVirtChunks Virtual chunk count.
  101. @Input pui32MappingTable Mapping Table.
  102. @Input uiLog2PageSize Page size.
  103. @Input uiFlags Memalloc flags.
  104. @Input pszAnnotation Annotation.
  105. @Input uiPid Process ID.
  106. @Output ppsPMRPtr Pointer to PMR.
  107. @Input ui32PDumpFlag PDump flags.
  108. @Return PVRSRV_ERROR PVRSRV_OK or error code
  109. */ /**************************************************************************/
  110. typedef PVRSRV_ERROR (*PFN_CREATE_PMR)(PHYS_HEAP *psPhysHeap,
  111. struct _CONNECTION_DATA_ *psConnection,
  112. IMG_DEVMEM_SIZE_T uiSize,
  113. IMG_DEVMEM_SIZE_T uiChunkSize,
  114. IMG_UINT32 ui32NumPhysChunks,
  115. IMG_UINT32 ui32NumVirtChunks,
  116. IMG_UINT32 *pui32MappingTable,
  117. IMG_UINT32 uiLog2PageSize,
  118. PVRSRV_MEMALLOCFLAGS_T uiFlags,
  119. const IMG_CHAR *pszAnnotation,
  120. IMG_PID uiPid,
  121. PMR **ppsPMRPtr,
  122. IMG_UINT32 ui32PDumpFlags);
  123. /*! Implementation specific function table */
  124. typedef struct PHEAP_IMPL_FUNCS_TAG
  125. {
  126. PFN_DESTROY_DATA pfnDestroyData;
  127. PFN_GET_DEV_PADDR pfnGetDevPAddr;
  128. PFN_GET_CPU_PADDR pfnGetCPUPAddr;
  129. PFN_GET_SIZE pfnGetSize;
  130. PFN_GET_MEM_STATS pfnGetPMRFactoryMemStats;
  131. PFN_CREATE_PMR pfnCreatePMR;
  132. } PHEAP_IMPL_FUNCS;
  133. /*************************************************************************/ /*!
  134. @Function PhysHeapCreateHeapsFromConfigs
  135. @Description Create new heaps from configs.
  136. @Input psDevNode Pointer to device node struct
  137. @Input pasConfigs Pointer to array of Heap configurations.
  138. @Input ui32NumConfigs Number of configurations in array.
  139. @Output papsPhysHeaps Pointer to array of phys heap pointers.
  140. @Output pui32NumHeaps Number of heaps created. Can be less than
  141. ui32NumConfigs if error.
  142. @Return PVRSRV_ERROR PVRSRV_OK or error code
  143. */ /**************************************************************************/
  144. PVRSRV_ERROR
  145. PhysHeapCreateHeapsFromConfigs(PPVRSRV_DEVICE_NODE psDevNode,
  146. PHYS_HEAP_CONFIG *pasConfigs,
  147. IMG_UINT32 ui32NumConfigs,
  148. PHYS_HEAP **papsPhysHeaps,
  149. IMG_UINT32 *pui32NumHeaps);
  150. /*************************************************************************/ /*!
  151. @Function PhysHeapCreateHeapFromConfig
  152. @Description Create a new heap. Calls specific heap API depending
  153. on heap type.
  154. @Input psDevNode Pointer to device node struct.
  155. @Input psConfig Heap configuration.
  156. @Output ppsPhysHeap Pointer to the created heap.
  157. @Return PVRSRV_ERROR PVRSRV_OK or error code
  158. */ /**************************************************************************/
  159. PVRSRV_ERROR
  160. PhysHeapCreateHeapFromConfig(PPVRSRV_DEVICE_NODE psDevNode,
  161. PHYS_HEAP_CONFIG *psConfig,
  162. PHYS_HEAP **ppsPhysHeap);
  163. /*************************************************************************/ /*!
  164. @Function PhysHeapCreate
  165. @Description Create a new heap. Allocated and stored internally.
  166. Destroy with PhysHeapDestroy when no longer required.
  167. @Input psDevNode Pointer to device node struct
  168. @Input psConfig Heap configuration.
  169. @Input pvImplData Implementation specific data. Can be NULL.
  170. @Input psImplFuncs Implementation specific function table. Must be
  171. a valid pointer.
  172. @Output ppsPhysHeap Pointer to the created heap. Must be a valid
  173. pointer.
  174. @Return PVRSRV_ERROR PVRSRV_OK or error code
  175. */ /**************************************************************************/
  176. PVRSRV_ERROR PhysHeapCreate(PPVRSRV_DEVICE_NODE psDevNode,
  177. PHYS_HEAP_CONFIG *psConfig,
  178. PHEAP_IMPL_DATA pvImplData,
  179. PHEAP_IMPL_FUNCS *psImplFuncs,
  180. PHYS_HEAP **ppsPhysHeap);
  181. void PhysHeapDestroy(PHYS_HEAP *psPhysHeap);
  182. PVRSRV_ERROR PhysHeapAcquire(PHYS_HEAP *psPhysHeap);
  183. /*************************************************************************/ /*!
  184. @Function PhysHeapAcquireByUsage
  185. @Description Acquire PhysHeap by usage flag.
  186. @Input ui32UsageFlag PhysHeap usage flag
  187. @Input psDevNode Pointer to device node struct
  188. @Output ppsPhysHeap PhysHeap if found.
  189. @Return PVRSRV_ERROR PVRSRV_OK or error code
  190. */ /**************************************************************************/
  191. PVRSRV_ERROR PhysHeapAcquireByUsage(PHYS_HEAP_USAGE_FLAGS ui32UsageFlag,
  192. PPVRSRV_DEVICE_NODE psDevNode,
  193. PHYS_HEAP **ppsPhysHeap);
  194. /*************************************************************************/ /*!
  195. @Function PhysHeapAcquireByDevPhysHeap
  196. @Description Acquire PhysHeap by DevPhysHeap.
  197. @Input eDevPhysHeap Device Phys Heap.
  198. @Input psDevNode Pointer to device node struct
  199. @Output ppsPhysHeap PhysHeap if found.
  200. @Return PVRSRV_ERROR PVRSRV_OK or error code
  201. */ /**************************************************************************/
  202. PVRSRV_ERROR PhysHeapAcquireByDevPhysHeap(PVRSRV_PHYS_HEAP eDevPhysHeap,
  203. PPVRSRV_DEVICE_NODE psDevNode,
  204. PHYS_HEAP **ppsPhysHeap);
  205. void PhysHeapRelease(PHYS_HEAP *psPhysHeap);
  206. /*************************************************************************/ /*!
  207. @Function PhysHeapGetImplData
  208. @Description Get physical heap implementation specific data.
  209. @Input psPhysHeap Pointer to physical heap.
  210. @Input psConfig Heap configuration.
  211. @Return pvImplData Implementation specific data. Can be NULL.
  212. */ /**************************************************************************/
  213. PHEAP_IMPL_DATA PhysHeapGetImplData(PHYS_HEAP *psPhysHeap);
  214. PHYS_HEAP_TYPE PhysHeapGetType(PHYS_HEAP *psPhysHeap);
  215. /*************************************************************************/ /*!
  216. @Function PhysHeapGetFlags
  217. @Description Get phys heap usage flags.
  218. @Input psPhysHeap Pointer to physical heap.
  219. @Return PHYS_HEAP_USAGE_FLAGS Phys heap usage flags.
  220. */ /**************************************************************************/
  221. PHYS_HEAP_USAGE_FLAGS PhysHeapGetFlags(PHYS_HEAP *psPhysHeap);
  222. IMG_BOOL PhysHeapValidateDefaultHeapExists(PPVRSRV_DEVICE_NODE psDevNode);
  223. PVRSRV_ERROR PhysHeapGetCpuPAddr(PHYS_HEAP *psPhysHeap,
  224. IMG_CPU_PHYADDR *psCpuPAddr);
  225. PVRSRV_ERROR PhysHeapGetSize(PHYS_HEAP *psPhysHeap,
  226. IMG_UINT64 *puiSize);
  227. /*************************************************************************/ /*!
  228. @Function PVRSRVGetDevicePhysHeapCount
  229. @Description Get the physical heap count supported by the device.
  230. @Input psDevNode Device node, the heap count is requested for.
  231. @Output pui32PhysHeapCount Buffer that holds the heap count
  232. @Return None
  233. */ /**************************************************************************/
  234. void PVRSRVGetDevicePhysHeapCount(PPVRSRV_DEVICE_NODE psDevNode,
  235. IMG_UINT32 *pui32PhysHeapCount);
  236. /*************************************************************************/ /*!
  237. @Function PhysHeapGetMemInfo
  238. @Description Get phys heap memory statistics for a given physical heap ID.
  239. @Input psDevNode Pointer to device node struct
  240. @Input ui32PhysHeapCount Physical heap count
  241. @Input paePhysHeapID Physical heap ID
  242. @Output paPhysHeapMemStats Buffer that holds the memory statistics
  243. @Return PVRSRV_ERROR PVRSRV_OK or error code
  244. */ /**************************************************************************/
  245. PVRSRV_ERROR
  246. PhysHeapGetMemInfo(PPVRSRV_DEVICE_NODE psDevNode,
  247. IMG_UINT32 ui32PhysHeapCount,
  248. PVRSRV_PHYS_HEAP *paePhysHeapID,
  249. PHYS_HEAP_MEM_STATS_PTR paPhysHeapMemStats);
  250. /*************************************************************************/ /*!
  251. @Function PhysheapGetPhysMemUsage
  252. @Description Get memory statistics for a given physical heap.
  253. @Input psPhysHeap Physical heap
  254. @Output pui64TotalSize Buffer that holds the total memory size of the
  255. given physical heap.
  256. @Output pui64FreeSize Buffer that holds the free memory available in
  257. a given physical heap.
  258. @Return none
  259. */ /**************************************************************************/
  260. void PhysheapGetPhysMemUsage(PHYS_HEAP *psPhysHeap,
  261. IMG_UINT64 *pui64TotalSize,
  262. IMG_UINT64 *pui64FreeSize);
  263. PVRSRV_ERROR PhysHeapGetDevPAddr(PHYS_HEAP *psPhysHeap,
  264. IMG_DEV_PHYADDR *psDevPAddr);
  265. void PhysHeapCpuPAddrToDevPAddr(PHYS_HEAP *psPhysHeap,
  266. IMG_UINT32 ui32NumOfAddr,
  267. IMG_DEV_PHYADDR *psDevPAddr,
  268. IMG_CPU_PHYADDR *psCpuPAddr);
  269. void PhysHeapDevPAddrToCpuPAddr(PHYS_HEAP *psPhysHeap,
  270. IMG_UINT32 ui32NumOfAddr,
  271. IMG_CPU_PHYADDR *psCpuPAddr,
  272. IMG_DEV_PHYADDR *psDevPAddr);
  273. IMG_CHAR *PhysHeapPDumpMemspaceName(PHYS_HEAP *psPhysHeap);
  274. /*************************************************************************/ /*!
  275. @Function PhysHeapCreatePMR
  276. @Description Function calls an implementation-specific function pointer.
  277. See function pointer for details.
  278. @Return PVRSRV_ERROR PVRSRV_OK or error code
  279. */ /**************************************************************************/
  280. PVRSRV_ERROR PhysHeapCreatePMR(PHYS_HEAP *psPhysHeap,
  281. struct _CONNECTION_DATA_ *psConnection,
  282. IMG_DEVMEM_SIZE_T uiSize,
  283. IMG_DEVMEM_SIZE_T uiChunkSize,
  284. IMG_UINT32 ui32NumPhysChunks,
  285. IMG_UINT32 ui32NumVirtChunks,
  286. IMG_UINT32 *pui32MappingTable,
  287. IMG_UINT32 uiLog2PageSize,
  288. PVRSRV_MEMALLOCFLAGS_T uiFlags,
  289. const IMG_CHAR *pszAnnotation,
  290. IMG_PID uiPid,
  291. PMR **ppsPMRPtr,
  292. IMG_UINT32 ui32PDumpFlags);
  293. PVRSRV_ERROR PhysHeapInit(void);
  294. PVRSRV_ERROR PhysHeapDeinit(void);
  295. /*************************************************************************/ /*!
  296. @Function PhysHeapDeviceNode
  297. @Description Get pointer to the device node this heap belongs to.
  298. @Input psPhysHeap Pointer to physical heap.
  299. @Return PPVRSRV_DEVICE_NODE Pointer to device node.
  300. */ /**************************************************************************/
  301. PPVRSRV_DEVICE_NODE PhysHeapDeviceNode(PHYS_HEAP *psPhysHeap);
  302. /*************************************************************************/ /*!
  303. @Function PhysHeapPVRLayerAcquire
  304. @Description Is phys heap to be acquired in PVR layer?
  305. @Input ePhysHeap phys heap
  306. @Return IMG_BOOL return IMG_TRUE if yes
  307. */ /**************************************************************************/
  308. IMG_BOOL PhysHeapPVRLayerAcquire(PVRSRV_PHYS_HEAP ePhysHeap);
  309. /*************************************************************************/ /*!
  310. @Function PhysHeapUserModeAlloc
  311. @Description Is allocation from UM allowed?
  312. @Input ePhysHeap phys heap
  313. @Return IMG_BOOL return IMG_TRUE if yes
  314. */ /**************************************************************************/
  315. IMG_BOOL PhysHeapUserModeAlloc(PVRSRV_PHYS_HEAP ePhysHeap);
  316. #endif /* PHYSHEAP_H */