diff options
Diffstat (limited to 'drivers/gpu/pvr/mem.c')
-rw-r--r-- | drivers/gpu/pvr/mem.c | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/drivers/gpu/pvr/mem.c b/drivers/gpu/pvr/mem.c new file mode 100644 index 00000000000..a2673d53c23 --- /dev/null +++ b/drivers/gpu/pvr/mem.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /********************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved. | ||
4 | * | ||
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. | ||
8 | * | ||
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. | ||
13 | * | ||
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. | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in | ||
19 | * the file called "COPYING". | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Imagination Technologies Ltd. <gpl-support@imgtec.com> | ||
23 | * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK | ||
24 | * | ||
25 | ******************************************************************************/ | ||
26 | |||
27 | #include "services_headers.h" | ||
28 | #include "pvr_bridge_km.h" | ||
29 | |||
30 | |||
31 | static PVRSRV_ERROR | ||
32 | FreeSharedSysMemCallBack(IMG_PVOID pvParam, | ||
33 | IMG_UINT32 ui32Param) | ||
34 | { | ||
35 | PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo = pvParam; | ||
36 | |||
37 | PVR_UNREFERENCED_PARAMETER(ui32Param); | ||
38 | |||
39 | OSFreePages(psKernelMemInfo->ui32Flags, | ||
40 | psKernelMemInfo->ui32AllocSize, | ||
41 | psKernelMemInfo->pvLinAddrKM, | ||
42 | psKernelMemInfo->sMemBlk.hOSMemHandle); | ||
43 | |||
44 | OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, | ||
45 | sizeof(PVRSRV_KERNEL_MEM_INFO), | ||
46 | psKernelMemInfo, | ||
47 | IMG_NULL); | ||
48 | |||
49 | |||
50 | return PVRSRV_OK; | ||
51 | } | ||
52 | |||
53 | |||
54 | IMG_EXPORT PVRSRV_ERROR | ||
55 | PVRSRVAllocSharedSysMemoryKM(PVRSRV_PER_PROCESS_DATA *psPerProc, | ||
56 | IMG_UINT32 ui32Flags, | ||
57 | IMG_SIZE_T ui32Size, | ||
58 | PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo) | ||
59 | { | ||
60 | PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo; | ||
61 | |||
62 | if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, | ||
63 | sizeof(PVRSRV_KERNEL_MEM_INFO), | ||
64 | (IMG_VOID **)&psKernelMemInfo, IMG_NULL, | ||
65 | "Kernel Memory Info") != PVRSRV_OK) | ||
66 | { | ||
67 | PVR_DPF((PVR_DBG_ERROR,"PVRSRVAllocSharedSysMemoryKM: Failed to alloc memory for meminfo")); | ||
68 | return PVRSRV_ERROR_OUT_OF_MEMORY; | ||
69 | } | ||
70 | |||
71 | OSMemSet(psKernelMemInfo, 0, sizeof(*psKernelMemInfo)); | ||
72 | |||
73 | ui32Flags &= ~PVRSRV_HAP_MAPTYPE_MASK; | ||
74 | ui32Flags |= PVRSRV_HAP_MULTI_PROCESS; | ||
75 | psKernelMemInfo->ui32Flags = ui32Flags; | ||
76 | psKernelMemInfo->ui32AllocSize = ui32Size; | ||
77 | |||
78 | if(OSAllocPages(psKernelMemInfo->ui32Flags, | ||
79 | psKernelMemInfo->ui32AllocSize, | ||
80 | HOST_PAGESIZE(), | ||
81 | &psKernelMemInfo->pvLinAddrKM, | ||
82 | &psKernelMemInfo->sMemBlk.hOSMemHandle) | ||
83 | != PVRSRV_OK) | ||
84 | { | ||
85 | PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSharedSysMemoryKM: Failed to alloc memory for block")); | ||
86 | OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, | ||
87 | sizeof(PVRSRV_KERNEL_MEM_INFO), | ||
88 | psKernelMemInfo, | ||
89 | 0); | ||
90 | return PVRSRV_ERROR_OUT_OF_MEMORY; | ||
91 | } | ||
92 | |||
93 | |||
94 | psKernelMemInfo->sMemBlk.hResItem = | ||
95 | ResManRegisterRes(psPerProc->hResManContext, | ||
96 | RESMAN_TYPE_SHARED_MEM_INFO, | ||
97 | psKernelMemInfo, | ||
98 | 0, | ||
99 | &FreeSharedSysMemCallBack); | ||
100 | |||
101 | *ppsKernelMemInfo = psKernelMemInfo; | ||
102 | |||
103 | return PVRSRV_OK; | ||
104 | } | ||
105 | |||
106 | |||
107 | IMG_EXPORT PVRSRV_ERROR | ||
108 | PVRSRVFreeSharedSysMemoryKM(PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo) | ||
109 | { | ||
110 | PVRSRV_ERROR eError; | ||
111 | |||
112 | if(psKernelMemInfo->sMemBlk.hResItem) | ||
113 | { | ||
114 | eError = ResManFreeResByPtr(psKernelMemInfo->sMemBlk.hResItem); | ||
115 | } | ||
116 | else | ||
117 | { | ||
118 | eError = FreeSharedSysMemCallBack(psKernelMemInfo, 0); | ||
119 | } | ||
120 | |||
121 | return eError; | ||
122 | } | ||
123 | |||
124 | |||
125 | IMG_EXPORT PVRSRV_ERROR | ||
126 | PVRSRVDissociateMemFromResmanKM(PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo) | ||
127 | { | ||
128 | PVRSRV_ERROR eError = PVRSRV_OK; | ||
129 | |||
130 | if(!psKernelMemInfo) | ||
131 | { | ||
132 | return PVRSRV_ERROR_INVALID_PARAMS; | ||
133 | } | ||
134 | |||
135 | if(psKernelMemInfo->sMemBlk.hResItem) | ||
136 | { | ||
137 | eError = ResManDissociateRes(psKernelMemInfo->sMemBlk.hResItem, IMG_NULL); | ||
138 | |||
139 | if (eError != PVRSRV_OK) | ||
140 | { | ||
141 | PVR_DPF((PVR_DBG_ERROR,"PVRSRVDissociateMemFromResmanKM: ResManDissociateRes failed")); | ||
142 | PVR_DBG_BREAK; | ||
143 | return eError; | ||
144 | } | ||
145 | |||
146 | psKernelMemInfo->sMemBlk.hResItem = IMG_NULL; | ||
147 | } | ||
148 | |||
149 | return eError; | ||
150 | } | ||
151 | |||