1 /*************************************************************************/ /*!
3 @Title Physical heap management
4 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description Management functions for the physical heap(s). A heap contains
6 all the information required by services when using memory from
7 that heap (such as CPU <> Device physical address translation).
8 A system must register one heap but can have more then one which
9 is why a heap must register with a (system) unique ID.
10 @License Dual MIT/GPLv2
12 The contents of this file are subject to the MIT license as set out below.
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
21 The above copyright notice and this permission notice shall be included in
22 all copies or substantial portions of the Software.
24 Alternatively, the contents of this file may be used under the terms of
25 the GNU General Public License Version 2 ("GPL") in which case the provisions
26 of GPL are applicable instead of those above.
28 If you wish to allow use of your version of this file only under the terms of
29 GPL, and not to allow others to use your version of this file under the terms
30 of the MIT license, indicate your decision by deleting the provisions above
31 and replace them with the notice and other provisions required by GPL as set
32 out in the file called "GPL-COPYING" included in this distribution. If you do
33 not delete the provisions above, a recipient may use your version of this file
34 under the terms of either the MIT license or GPL.
36 This License is also included in this distribution in the file called
39 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
40 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
41 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
42 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
43 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
44 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
45 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 */ /***************************************************************************/
47 #include "img_types.h"
50 #include "pvr_debug.h"
55 /*! ID of this physcial memory heap */
56 IMG_UINT32 ui32PhysHeapID;
57 /*! The type of this heap */
60 /*! Start address of the physcial memory heap (LMA only) */
61 IMG_CPU_PHYADDR sStartAddr;
62 /*! Size of the physcial memory heap (LMA only) */
65 /*! PDump name of this physcial memory heap */
66 IMG_CHAR *pszPDumpMemspaceName;
67 /*! Private data for the translate routines */
69 /*! Function callbacks */
70 PHYS_HEAP_FUNCTIONS *psMemFuncs;
74 IMG_UINT32 ui32RefCount;
75 /*! Pointer to next physcial heap */
76 struct _PHYS_HEAP_ *psNext;
79 PHYS_HEAP *g_psPhysHeapList;
81 #if defined(REFCOUNT_DEBUG)
82 #define PHYSHEAP_REFCOUNT_PRINT(fmt, ...) \
83 PVRSRVDebugPrintf(PVR_DBG_WARNING, \
89 #define PHYSHEAP_REFCOUNT_PRINT(fmt, ...)
93 PVRSRV_ERROR PhysHeapRegister(PHYS_HEAP_CONFIG *psConfig,
94 PHYS_HEAP **ppsPhysHeap)
101 if (psConfig->eType == PHYS_HEAP_TYPE_UNKNOWN)
103 return PVRSRV_ERROR_INVALID_PARAMS;
106 /* Check this heap ID isn't already in use */
107 psTmp = g_psPhysHeapList;
110 if (psTmp->ui32PhysHeapID == psConfig->ui32PhysHeapID)
112 return PVRSRV_ERROR_PHYSHEAP_ID_IN_USE;
114 psTmp = psTmp->psNext;
117 psNew = OSAllocMem(sizeof(PHYS_HEAP));
118 if (psNew == IMG_NULL)
120 return PVRSRV_ERROR_OUT_OF_MEMORY;
123 psNew->ui32PhysHeapID = psConfig->ui32PhysHeapID;
124 psNew->eType = psConfig->eType;
125 psNew->sStartAddr = psConfig->sStartAddr;
126 psNew->uiSize = psConfig->uiSize;
127 psNew->psMemFuncs = psConfig->psMemFuncs;
128 psNew->hPrivData = psConfig->hPrivData;
129 psNew->ui32RefCount = 0;
130 psNew->pszPDumpMemspaceName = psConfig->pszPDumpMemspaceName;
132 psNew->psNext = g_psPhysHeapList;
133 g_psPhysHeapList = psNew;
135 *ppsPhysHeap = psNew;
137 PVR_DPF_RETURN_RC1(PVRSRV_OK, *ppsPhysHeap);
140 IMG_VOID PhysHeapUnregister(PHYS_HEAP *psPhysHeap)
142 PVR_DPF_ENTERED1(psPhysHeap);
144 PVR_ASSERT(psPhysHeap->ui32RefCount == 0);
146 if (g_psPhysHeapList == psPhysHeap)
148 g_psPhysHeapList = psPhysHeap->psNext;
152 PHYS_HEAP *psTmp = g_psPhysHeapList;
154 while(psTmp->psNext != psPhysHeap)
156 psTmp = psTmp->psNext;
158 psTmp->psNext = psPhysHeap->psNext;
161 OSFreeMem(psPhysHeap);
166 PVRSRV_ERROR PhysHeapAcquire(IMG_UINT32 ui32PhysHeapID,
167 PHYS_HEAP **ppsPhysHeap)
169 PHYS_HEAP *psTmp = g_psPhysHeapList;
170 PVRSRV_ERROR eError = PVRSRV_OK;
172 PVR_DPF_ENTERED1(ui32PhysHeapID);
176 if (psTmp->ui32PhysHeapID == ui32PhysHeapID)
180 psTmp = psTmp->psNext;
183 if (psTmp == IMG_NULL)
185 eError = PVRSRV_ERROR_PHYSHEAP_ID_INVALID;
189 psTmp->ui32RefCount++;
190 PHYSHEAP_REFCOUNT_PRINT("%s: Heap %p, refcount = %d", __FUNCTION__, psTmp, psTmp->ui32RefCount);
193 *ppsPhysHeap = psTmp;
194 PVR_DPF_RETURN_RC1(eError, *ppsPhysHeap);
197 IMG_VOID PhysHeapRelease(PHYS_HEAP *psPhysHeap)
199 PVR_DPF_ENTERED1(psPhysHeap);
201 psPhysHeap->ui32RefCount--;
202 PHYSHEAP_REFCOUNT_PRINT("%s: Heap %p, refcount = %d", __FUNCTION__, psPhysHeap, psPhysHeap->ui32RefCount);
207 PHYS_HEAP_TYPE PhysHeapGetType(PHYS_HEAP *psPhysHeap)
209 return psPhysHeap->eType;
212 PVRSRV_ERROR PhysHeapGetAddress(PHYS_HEAP *psPhysHeap,
213 IMG_CPU_PHYADDR *psCpuPAddr)
215 if (psPhysHeap->eType == PHYS_HEAP_TYPE_LMA)
217 *psCpuPAddr = psPhysHeap->sStartAddr;
221 return PVRSRV_ERROR_INVALID_PARAMS;
224 PVRSRV_ERROR PhysHeapGetSize(PHYS_HEAP *psPhysHeap,
227 if (psPhysHeap->eType == PHYS_HEAP_TYPE_LMA)
229 *puiSize = psPhysHeap->uiSize;
233 return PVRSRV_ERROR_INVALID_PARAMS;
236 IMG_VOID PhysHeapCpuPAddrToDevPAddr(PHYS_HEAP *psPhysHeap,
237 IMG_UINT32 ui32NumOfAddr,
238 IMG_DEV_PHYADDR *psDevPAddr,
239 IMG_CPU_PHYADDR *psCpuPAddr)
241 psPhysHeap->psMemFuncs->pfnCpuPAddrToDevPAddr(psPhysHeap->hPrivData,
247 IMG_VOID PhysHeapDevPAddrToCpuPAddr(PHYS_HEAP *psPhysHeap,
248 IMG_UINT32 ui32NumOfAddr,
249 IMG_CPU_PHYADDR *psCpuPAddr,
250 IMG_DEV_PHYADDR *psDevPAddr)
252 psPhysHeap->psMemFuncs->pfnDevPAddrToCpuPAddr(psPhysHeap->hPrivData,
258 IMG_CHAR *PhysHeapPDumpMemspaceName(PHYS_HEAP *psPhysHeap)
260 return psPhysHeap->pszPDumpMemspaceName;
263 PVRSRV_ERROR PhysHeapInit(IMG_VOID)
265 g_psPhysHeapList = IMG_NULL;
270 PVRSRV_ERROR PhysHeapDeinit(IMG_VOID)
272 PVR_ASSERT(g_psPhysHeapList == IMG_NULL);