1 /**********************************************************************
2 Copyright (c) Imagination Technologies Ltd.
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 ******************************************************************************/
23 #include "services_headers.h"
24 #include "pvr_bridge_km.h"
28 FreeSharedSysMemCallBack(IMG_PVOID pvParam,
31 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo = pvParam;
33 PVR_UNREFERENCED_PARAMETER(ui32Param);
35 OSFreePages(psKernelMemInfo->ui32Flags,
36 psKernelMemInfo->ui32AllocSize,
37 psKernelMemInfo->pvLinAddrKM,
38 psKernelMemInfo->sMemBlk.hOSMemHandle);
40 OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
41 sizeof(PVRSRV_KERNEL_MEM_INFO),
50 IMG_EXPORT PVRSRV_ERROR
51 PVRSRVAllocSharedSysMemoryKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
54 PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo)
56 PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo;
58 if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
59 sizeof(PVRSRV_KERNEL_MEM_INFO),
60 (IMG_VOID **)&psKernelMemInfo, IMG_NULL,
61 "Kernel Memory Info") != PVRSRV_OK)
63 PVR_DPF((PVR_DBG_ERROR,"PVRSRVAllocSharedSysMemoryKM: Failed to alloc memory for meminfo"));
64 return PVRSRV_ERROR_OUT_OF_MEMORY;
67 OSMemSet(psKernelMemInfo, 0, sizeof(*psKernelMemInfo));
69 ui32Flags &= ~PVRSRV_HAP_MAPTYPE_MASK;
70 ui32Flags |= PVRSRV_HAP_MULTI_PROCESS;
71 psKernelMemInfo->ui32Flags = ui32Flags;
72 psKernelMemInfo->ui32AllocSize = ui32Size;
74 if(OSAllocPages(psKernelMemInfo->ui32Flags,
75 psKernelMemInfo->ui32AllocSize,
77 &psKernelMemInfo->pvLinAddrKM,
78 &psKernelMemInfo->sMemBlk.hOSMemHandle)
81 PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSharedSysMemoryKM: Failed to alloc memory for block"));
82 OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
83 sizeof(PVRSRV_KERNEL_MEM_INFO),
86 return PVRSRV_ERROR_OUT_OF_MEMORY;
90 psKernelMemInfo->sMemBlk.hResItem =
91 ResManRegisterRes(psPerProc->hResManContext,
92 RESMAN_TYPE_SHARED_MEM_INFO,
95 FreeSharedSysMemCallBack);
97 *ppsKernelMemInfo = psKernelMemInfo;
103 IMG_EXPORT PVRSRV_ERROR
104 PVRSRVFreeSharedSysMemoryKM(PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
108 if(psKernelMemInfo->sMemBlk.hResItem)
110 eError = ResManFreeResByPtr(psKernelMemInfo->sMemBlk.hResItem);
114 eError = FreeSharedSysMemCallBack(psKernelMemInfo, 0);
121 IMG_EXPORT PVRSRV_ERROR
122 PVRSRVDissociateMemFromResmanKM(PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
124 PVRSRV_ERROR eError = PVRSRV_OK;
128 return PVRSRV_ERROR_INVALID_PARAMS;
131 if(psKernelMemInfo->sMemBlk.hResItem)
133 eError = ResManDissociateRes(psKernelMemInfo->sMemBlk.hResItem, IMG_NULL);
135 if (eError != PVRSRV_OK)
137 PVR_DPF((PVR_DBG_ERROR,"PVRSRVDissociateMemFromResmanKM: ResManDissociateRes failed"));
142 psKernelMemInfo->sMemBlk.hResItem = IMG_NULL;