1 /**********************************************************************
3 * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful but, except
10 * as otherwise stated in writing, without any warranty; without even the
11 * implied warranty of merchantability or fitness for a particular purpose.
12 * See the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * Imagination Technologies Ltd. <gpl-support@imgtec.com>
23 * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
25 ******************************************************************************/
27 #include "services_headers.h"
28 #include "sgxapi_km.h"
29 #include "pvr_bridge_km.h"
31 static enum PVRSRV_ERROR FreeSharedSysMemCallBack(void *pvParam, u32 ui32Param)
33 struct PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo = pvParam;
35 PVR_UNREFERENCED_PARAMETER(ui32Param);
37 OSFreePages(psKernelMemInfo->ui32Flags,
38 psKernelMemInfo->ui32AllocSize,
39 psKernelMemInfo->pvLinAddrKM,
40 psKernelMemInfo->sMemBlk.hOSMemHandle);
42 OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
43 sizeof(struct PVRSRV_KERNEL_MEM_INFO), psKernelMemInfo, NULL);
48 enum PVRSRV_ERROR PVRSRVAllocSharedSysMemoryKM(
49 struct PVRSRV_PER_PROCESS_DATA *psPerProc,
50 u32 ui32Flags, u32 ui32Size,
51 struct PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo)
53 struct PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo;
55 if (OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
56 sizeof(struct PVRSRV_KERNEL_MEM_INFO),
57 (void **) &psKernelMemInfo, NULL) != PVRSRV_OK) {
58 PVR_DPF(PVR_DBG_ERROR, "PVRSRVAllocSharedSysMemoryKM: "
59 "Failed to alloc memory for meminfo");
60 return PVRSRV_ERROR_OUT_OF_MEMORY;
63 OSMemSet(psKernelMemInfo, 0, sizeof(*psKernelMemInfo));
65 ui32Flags &= ~PVRSRV_HAP_MAPTYPE_MASK;
66 ui32Flags |= PVRSRV_HAP_MULTI_PROCESS;
67 psKernelMemInfo->ui32Flags = ui32Flags;
68 psKernelMemInfo->ui32AllocSize = ui32Size;
70 if (OSAllocPages(psKernelMemInfo->ui32Flags,
71 psKernelMemInfo->ui32AllocSize, HOST_PAGESIZE(),
72 &psKernelMemInfo->pvLinAddrKM,
73 &psKernelMemInfo->sMemBlk.hOSMemHandle) != PVRSRV_OK) {
74 PVR_DPF(PVR_DBG_ERROR, "PVRSRVAllocSharedSysMemoryKM: "
75 "Failed to alloc memory for block");
76 OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
77 sizeof(struct PVRSRV_KERNEL_MEM_INFO),
78 psKernelMemInfo, NULL);
79 return PVRSRV_ERROR_OUT_OF_MEMORY;
82 psKernelMemInfo->sMemBlk.hResItem = ResManRegisterRes(
83 psPerProc->hResManContext,
84 RESMAN_TYPE_SHARED_MEM_INFO,
86 FreeSharedSysMemCallBack);
88 *ppsKernelMemInfo = psKernelMemInfo;
93 enum PVRSRV_ERROR PVRSRVFreeSharedSysMemoryKM(
94 struct PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
96 enum PVRSRV_ERROR eError = PVRSRV_OK;
98 if (psKernelMemInfo->sMemBlk.hResItem)
99 ResManFreeResByPtr(psKernelMemInfo->sMemBlk.hResItem);
101 eError = FreeSharedSysMemCallBack(psKernelMemInfo, 0);
106 enum PVRSRV_ERROR PVRSRVDissociateMemFromResmanKM(
107 struct PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
109 enum PVRSRV_ERROR eError = PVRSRV_OK;
111 if (!psKernelMemInfo)
112 return PVRSRV_ERROR_INVALID_PARAMS;
114 if (psKernelMemInfo->sMemBlk.hResItem) {
115 eError = ResManDissociateRes(psKernelMemInfo->sMemBlk.hResItem,
118 if (eError != PVRSRV_OK) {
119 PVR_DPF(PVR_DBG_ERROR,
120 "PVRSRVDissociateMemFromResmanKM: "
121 "ResManDissociateRes failed");
126 psKernelMemInfo->sMemBlk.hResItem = NULL;