summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jacinto6/sgx_src/eurasia_km/services4/srvkm/devices/sgx/pb.c')
-rw-r--r--jacinto6/sgx_src/eurasia_km/services4/srvkm/devices/sgx/pb.c493
1 files changed, 493 insertions, 0 deletions
diff --git a/jacinto6/sgx_src/eurasia_km/services4/srvkm/devices/sgx/pb.c b/jacinto6/sgx_src/eurasia_km/services4/srvkm/devices/sgx/pb.c
new file mode 100644
index 0000000..4ed18bb
--- /dev/null
+++ b/jacinto6/sgx_src/eurasia_km/services4/srvkm/devices/sgx/pb.c
@@ -0,0 +1,493 @@
1/*************************************************************************/ /*!
2@Title Parameter Buffer management functions
3@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4@License Dual MIT/GPLv2
5
6The contents of this file are subject to the MIT license as set out below.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18Alternatively, the contents of this file may be used under the terms of
19the GNU General Public License Version 2 ("GPL") in which case the provisions
20of GPL are applicable instead of those above.
21
22If you wish to allow use of your version of this file only under the terms of
23GPL, and not to allow others to use your version of this file under the terms
24of the MIT license, indicate your decision by deleting the provisions above
25and replace them with the notice and other provisions required by GPL as set
26out in the file called "GPL-COPYING" included in this distribution. If you do
27not delete the provisions above, a recipient may use your version of this file
28under the terms of either the MIT license or GPL.
29
30This License is also included in this distribution in the file called
31"MIT-COPYING".
32
33EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40*/ /**************************************************************************/
41
42#include <stddef.h>
43
44#include "services_headers.h"
45#include "sgx_bridge_km.h"
46#include "sgxapi_km.h"
47#include "sgxinfo.h"
48#include "sgxinfokm.h"
49#include "pvr_bridge_km.h"
50#include "pdump_km.h"
51#include "sgxutils.h"
52
53#if !defined(__linux__) && !defined(__QNXNTO__)
54#pragma message("FIXME: Review use of OS_PAGEABLE vs OS_NON_PAGEABLE")
55#endif
56
57#include "lists.h"
58
59static IMPLEMENT_LIST_INSERT(PVRSRV_STUB_PBDESC)
60static IMPLEMENT_LIST_REMOVE(PVRSRV_STUB_PBDESC)
61
62static PRESMAN_ITEM psResItemCreateSharedPB = IMG_NULL;
63static PVRSRV_PER_PROCESS_DATA *psPerProcCreateSharedPB = IMG_NULL;
64
65static PVRSRV_ERROR SGXCleanupSharedPBDescCallback(IMG_PVOID pvParam, IMG_UINT32 ui32Param, IMG_BOOL bDummy);
66static PVRSRV_ERROR SGXCleanupSharedPBDescCreateLockCallback(IMG_PVOID pvParam, IMG_UINT32 ui32Param, IMG_BOOL bDummy);
67
68/* override level pointer indirection */
69/* PRQA S 5102 12 */
70IMG_EXPORT PVRSRV_ERROR
71SGXFindSharedPBDescKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
72 IMG_HANDLE hDevCookie,
73 IMG_BOOL bLockOnFailure,
74 IMG_UINT32 ui32TotalPBSize,
75 IMG_HANDLE *phSharedPBDesc,
76 PVRSRV_KERNEL_MEM_INFO **ppsSharedPBDescKernelMemInfo,
77 PVRSRV_KERNEL_MEM_INFO **ppsHWPBDescKernelMemInfo,
78 PVRSRV_KERNEL_MEM_INFO **ppsBlockKernelMemInfo,
79 PVRSRV_KERNEL_MEM_INFO **ppsHWBlockKernelMemInfo,
80 PVRSRV_KERNEL_MEM_INFO ***pppsSharedPBDescSubKernelMemInfos,
81 IMG_UINT32 *ui32SharedPBDescSubKernelMemInfosCount)
82{
83 PVRSRV_STUB_PBDESC *psStubPBDesc;
84 PVRSRV_KERNEL_MEM_INFO **ppsSharedPBDescSubKernelMemInfos=IMG_NULL;
85 PVRSRV_SGXDEV_INFO *psSGXDevInfo;
86 PVRSRV_ERROR eError;
87
88 psSGXDevInfo = ((PVRSRV_DEVICE_NODE *)hDevCookie)->pvDevice;
89
90 psStubPBDesc = psSGXDevInfo->psStubPBDescListKM;
91 if (psStubPBDesc != IMG_NULL)
92 {
93 IMG_UINT32 i;
94 PRESMAN_ITEM psResItem;
95
96 if(psStubPBDesc->ui32TotalPBSize != ui32TotalPBSize)
97 {
98 PVR_DPF((PVR_DBG_WARNING,
99 "SGXFindSharedPBDescKM: Shared PB requested with different size (0x%x) from existing shared PB (0x%x) - requested size ignored",
100 ui32TotalPBSize, psStubPBDesc->ui32TotalPBSize));
101 }
102
103 if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
104 sizeof(PVRSRV_KERNEL_MEM_INFO *)
105 * psStubPBDesc->ui32SubKernelMemInfosCount,
106 (IMG_VOID **)&ppsSharedPBDescSubKernelMemInfos,
107 IMG_NULL,
108 "Array of Kernel Memory Info") != PVRSRV_OK)
109 {
110 PVR_DPF((PVR_DBG_ERROR, "SGXFindSharedPBDescKM: OSAllocMem failed"));
111
112 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
113 goto ExitNotFound;
114 }
115
116 psResItem = ResManRegisterRes(psPerProc->hResManContext,
117 RESMAN_TYPE_SHARED_PB_DESC,
118 psStubPBDesc,
119 0,
120 &SGXCleanupSharedPBDescCallback);
121
122 if (psResItem == IMG_NULL)
123 {
124 OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
125 sizeof(PVRSRV_KERNEL_MEM_INFO *) * psStubPBDesc->ui32SubKernelMemInfosCount,
126 ppsSharedPBDescSubKernelMemInfos,
127 0);
128 /*not nulling pointer, out of scope*/
129
130 PVR_DPF((PVR_DBG_ERROR, "SGXFindSharedPBDescKM: ResManRegisterRes failed"));
131
132 eError = PVRSRV_ERROR_UNABLE_TO_REGISTER_RESOURCE;
133 goto ExitNotFound;
134 }
135
136 *ppsSharedPBDescKernelMemInfo = psStubPBDesc->psSharedPBDescKernelMemInfo;
137 *ppsHWPBDescKernelMemInfo = psStubPBDesc->psHWPBDescKernelMemInfo;
138 *ppsBlockKernelMemInfo = psStubPBDesc->psBlockKernelMemInfo;
139 *ppsHWBlockKernelMemInfo = psStubPBDesc->psHWBlockKernelMemInfo;
140
141 *ui32SharedPBDescSubKernelMemInfosCount =
142 psStubPBDesc->ui32SubKernelMemInfosCount;
143
144 *pppsSharedPBDescSubKernelMemInfos = ppsSharedPBDescSubKernelMemInfos;
145
146 for(i=0; i<psStubPBDesc->ui32SubKernelMemInfosCount; i++)
147 {
148 ppsSharedPBDescSubKernelMemInfos[i] =
149 psStubPBDesc->ppsSubKernelMemInfos[i];
150 }
151
152 psStubPBDesc->ui32RefCount++;
153 *phSharedPBDesc = (IMG_HANDLE)psResItem;
154 return PVRSRV_OK;
155 }
156
157 eError = PVRSRV_OK;
158 if (bLockOnFailure)
159 {
160 if (psResItemCreateSharedPB == IMG_NULL)
161 {
162 psResItemCreateSharedPB = ResManRegisterRes(psPerProc->hResManContext,
163 RESMAN_TYPE_SHARED_PB_DESC_CREATE_LOCK,
164 psPerProc,
165 0,
166 &SGXCleanupSharedPBDescCreateLockCallback);
167
168 if (psResItemCreateSharedPB == IMG_NULL)
169 {
170 PVR_DPF((PVR_DBG_ERROR, "SGXFindSharedPBDescKM: ResManRegisterRes failed"));
171
172 eError = PVRSRV_ERROR_UNABLE_TO_REGISTER_RESOURCE;
173 goto ExitNotFound;
174 }
175 PVR_ASSERT(psPerProcCreateSharedPB == IMG_NULL);
176 psPerProcCreateSharedPB = psPerProc;
177 }
178 else
179 {
180 eError = PVRSRV_ERROR_PROCESSING_BLOCKED;
181 }
182 }
183ExitNotFound:
184 *phSharedPBDesc = IMG_NULL;
185
186 return eError;
187}
188
189
190static PVRSRV_ERROR
191SGXCleanupSharedPBDescKM(PVRSRV_STUB_PBDESC *psStubPBDescIn)
192{
193 /*PVRSRV_STUB_PBDESC **ppsStubPBDesc;*/
194 IMG_UINT32 i;
195 PVRSRV_DEVICE_NODE *psDeviceNode;
196
197 psDeviceNode = (PVRSRV_DEVICE_NODE*)psStubPBDescIn->hDevCookie;
198
199 psStubPBDescIn->ui32RefCount--;
200 if (psStubPBDescIn->ui32RefCount == 0)
201 {
202 IMG_DEV_VIRTADDR sHWPBDescDevVAddr = psStubPBDescIn->sHWPBDescDevVAddr;
203 List_PVRSRV_STUB_PBDESC_Remove(psStubPBDescIn);
204 for(i=0 ; i<psStubPBDescIn->ui32SubKernelMemInfosCount; i++)
205 {
206 PVRSRVFreeDeviceMemKM(psStubPBDescIn->hDevCookie,
207 psStubPBDescIn->ppsSubKernelMemInfos[i]);
208 }
209
210 OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
211 sizeof(PVRSRV_KERNEL_MEM_INFO *) * psStubPBDescIn->ui32SubKernelMemInfosCount,
212 psStubPBDescIn->ppsSubKernelMemInfos,
213 0);
214 psStubPBDescIn->ppsSubKernelMemInfos = IMG_NULL;
215
216 PVRSRVFreeSharedSysMemoryKM(psStubPBDescIn->psBlockKernelMemInfo);
217
218 PVRSRVFreeDeviceMemKM(psStubPBDescIn->hDevCookie, psStubPBDescIn->psHWBlockKernelMemInfo);
219
220 PVRSRVFreeDeviceMemKM(psStubPBDescIn->hDevCookie, psStubPBDescIn->psHWPBDescKernelMemInfo);
221
222 PVRSRVFreeSharedSysMemoryKM(psStubPBDescIn->psSharedPBDescKernelMemInfo);
223
224 OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
225 sizeof(PVRSRV_STUB_PBDESC),
226 psStubPBDescIn,
227 0);
228 /*not nulling pointer, copy on stack*/
229
230 /* signal the microkernel to clear its sTAHWPBDesc and s3DHWPBDesc values in sTA3DCtl */
231 SGXCleanupRequest(psDeviceNode,
232 &sHWPBDescDevVAddr,
233 PVRSRV_CLEANUPCMD_PB,
234 CLEANUP_WITH_POLL);
235 }
236 return PVRSRV_OK;
237 /*return PVRSRV_ERROR_INVALID_PARAMS;*/
238}
239
240static PVRSRV_ERROR SGXCleanupSharedPBDescCallback(IMG_PVOID pvParam, IMG_UINT32 ui32Param, IMG_BOOL bDummy)
241{
242 PVRSRV_STUB_PBDESC *psStubPBDesc = (PVRSRV_STUB_PBDESC *)pvParam;
243
244 PVR_UNREFERENCED_PARAMETER(ui32Param);
245 PVR_UNREFERENCED_PARAMETER(bDummy);
246
247 return SGXCleanupSharedPBDescKM(psStubPBDesc);
248}
249
250static PVRSRV_ERROR SGXCleanupSharedPBDescCreateLockCallback(IMG_PVOID pvParam, IMG_UINT32 ui32Param, IMG_BOOL bDummy)
251{
252#ifdef DEBUG
253 PVRSRV_PER_PROCESS_DATA *psPerProc = (PVRSRV_PER_PROCESS_DATA *)pvParam;
254 PVR_ASSERT(psPerProc == psPerProcCreateSharedPB);
255#else
256 PVR_UNREFERENCED_PARAMETER(pvParam);
257#endif
258
259 PVR_UNREFERENCED_PARAMETER(ui32Param);
260 PVR_UNREFERENCED_PARAMETER(bDummy);
261
262 psPerProcCreateSharedPB = IMG_NULL;
263 psResItemCreateSharedPB = IMG_NULL;
264
265 return PVRSRV_OK;
266}
267
268
269IMG_EXPORT PVRSRV_ERROR
270SGXUnrefSharedPBDescKM(IMG_HANDLE hSharedPBDesc)
271{
272 PVR_ASSERT(hSharedPBDesc != IMG_NULL);
273
274 return ResManFreeResByPtr(hSharedPBDesc, CLEANUP_WITH_POLL);
275}
276
277
278IMG_EXPORT PVRSRV_ERROR
279SGXAddSharedPBDescKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
280 IMG_HANDLE hDevCookie,
281 PVRSRV_KERNEL_MEM_INFO *psSharedPBDescKernelMemInfo,
282 PVRSRV_KERNEL_MEM_INFO *psHWPBDescKernelMemInfo,
283 PVRSRV_KERNEL_MEM_INFO *psBlockKernelMemInfo,
284 PVRSRV_KERNEL_MEM_INFO *psHWBlockKernelMemInfo,
285 IMG_UINT32 ui32TotalPBSize,
286 IMG_HANDLE *phSharedPBDesc,
287 PVRSRV_KERNEL_MEM_INFO **ppsSharedPBDescSubKernelMemInfos,
288 IMG_UINT32 ui32SharedPBDescSubKernelMemInfosCount,
289 IMG_DEV_VIRTADDR sHWPBDescDevVAddr)
290{
291 PVRSRV_STUB_PBDESC *psStubPBDesc=IMG_NULL;
292 PVRSRV_ERROR eRet = PVRSRV_ERROR_INVALID_PERPROC;
293 IMG_UINT32 i;
294 PVRSRV_SGXDEV_INFO *psSGXDevInfo;
295 PRESMAN_ITEM psResItem;
296
297 /*
298 * The caller must have previously called SGXFindSharedPBDesc with
299 * bLockOnFailure set, and not managed to find a suitable shared PB.
300 */
301 if (psPerProcCreateSharedPB != psPerProc)
302 {
303 goto NoAdd;
304 }
305 else
306 {
307 PVR_ASSERT(psResItemCreateSharedPB != IMG_NULL);
308
309 ResManFreeResByPtr(psResItemCreateSharedPB, CLEANUP_WITH_POLL);
310
311 PVR_ASSERT(psResItemCreateSharedPB == IMG_NULL);
312 PVR_ASSERT(psPerProcCreateSharedPB == IMG_NULL);
313 }
314
315 psSGXDevInfo = (PVRSRV_SGXDEV_INFO *)((PVRSRV_DEVICE_NODE *)hDevCookie)->pvDevice;
316
317 psStubPBDesc = psSGXDevInfo->psStubPBDescListKM;
318 if (psStubPBDesc != IMG_NULL)
319 {
320 if(psStubPBDesc->ui32TotalPBSize != ui32TotalPBSize)
321 {
322 PVR_DPF((PVR_DBG_WARNING,
323 "SGXAddSharedPBDescKM: Shared PB requested with different size (0x%x) from existing shared PB (0x%x) - requested size ignored",
324 ui32TotalPBSize, psStubPBDesc->ui32TotalPBSize));
325
326 }
327
328 /*
329 * We make the caller think the add was successful,
330 * but return the existing shared PB desc rather than
331 * a new one.
332 */
333 psResItem = ResManRegisterRes(psPerProc->hResManContext,
334 RESMAN_TYPE_SHARED_PB_DESC,
335 psStubPBDesc,
336 0,
337 &SGXCleanupSharedPBDescCallback);
338 if (psResItem == IMG_NULL)
339 {
340 PVR_DPF((PVR_DBG_ERROR,
341 "SGXAddSharedPBDescKM: "
342 "Failed to register existing shared "
343 "PBDesc with the resource manager"));
344 goto NoAddKeepPB;
345 }
346
347 /*
348 * The caller will unreference the PB desc after
349 * a successful add, so up the reference count.
350 */
351 psStubPBDesc->ui32RefCount++;
352
353 *phSharedPBDesc = (IMG_HANDLE)psResItem;
354 eRet = PVRSRV_OK;
355 goto NoAddKeepPB;
356 }
357
358 if(OSAllocMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
359 sizeof(PVRSRV_STUB_PBDESC),
360 (IMG_VOID **)&psStubPBDesc,
361 0,
362 "Stub Parameter Buffer Description") != PVRSRV_OK)
363 {
364 PVR_DPF((PVR_DBG_ERROR, "SGXAddSharedPBDescKM: Failed to alloc "
365 "StubPBDesc"));
366 eRet = PVRSRV_ERROR_OUT_OF_MEMORY;
367 goto NoAdd;
368 }
369
370
371 psStubPBDesc->ppsSubKernelMemInfos = IMG_NULL;
372
373 if(OSAllocMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
374 sizeof(PVRSRV_KERNEL_MEM_INFO *)
375 * ui32SharedPBDescSubKernelMemInfosCount,
376 (IMG_VOID **)&psStubPBDesc->ppsSubKernelMemInfos,
377 0,
378 "Array of Kernel Memory Info") != PVRSRV_OK)
379 {
380 PVR_DPF((PVR_DBG_ERROR, "SGXAddSharedPBDescKM: "
381 "Failed to alloc "
382 "StubPBDesc->ppsSubKernelMemInfos"));
383 eRet = PVRSRV_ERROR_OUT_OF_MEMORY;
384 goto NoAdd;
385 }
386
387 if(PVRSRVDissociateMemFromResmanKM(psSharedPBDescKernelMemInfo)
388 != PVRSRV_OK)
389 {
390 goto NoAdd;
391 }
392
393 if(PVRSRVDissociateMemFromResmanKM(psHWPBDescKernelMemInfo)
394 != PVRSRV_OK)
395 {
396 goto NoAdd;
397 }
398
399 if(PVRSRVDissociateMemFromResmanKM(psBlockKernelMemInfo)
400 != PVRSRV_OK)
401 {
402 goto NoAdd;
403 }
404
405 if(PVRSRVDissociateMemFromResmanKM(psHWBlockKernelMemInfo)
406 != PVRSRV_OK)
407 {
408 goto NoAdd;
409 }
410
411 psStubPBDesc->ui32RefCount = 1;
412 psStubPBDesc->ui32TotalPBSize = ui32TotalPBSize;
413 psStubPBDesc->psSharedPBDescKernelMemInfo = psSharedPBDescKernelMemInfo;
414 psStubPBDesc->psHWPBDescKernelMemInfo = psHWPBDescKernelMemInfo;
415 psStubPBDesc->psBlockKernelMemInfo = psBlockKernelMemInfo;
416 psStubPBDesc->psHWBlockKernelMemInfo = psHWBlockKernelMemInfo;
417
418 psStubPBDesc->ui32SubKernelMemInfosCount =
419 ui32SharedPBDescSubKernelMemInfosCount;
420 for(i=0; i<ui32SharedPBDescSubKernelMemInfosCount; i++)
421 {
422 psStubPBDesc->ppsSubKernelMemInfos[i] = ppsSharedPBDescSubKernelMemInfos[i];
423 if(PVRSRVDissociateMemFromResmanKM(ppsSharedPBDescSubKernelMemInfos[i])
424 != PVRSRV_OK)
425 {
426 PVR_DPF((PVR_DBG_ERROR, "SGXAddSharedPBDescKM: "
427 "Failed to dissociate shared PBDesc "
428 "from process"));
429 goto NoAdd;
430 }
431 }
432
433 psStubPBDesc->sHWPBDescDevVAddr = sHWPBDescDevVAddr;
434
435 psResItem = ResManRegisterRes(psPerProc->hResManContext,
436 RESMAN_TYPE_SHARED_PB_DESC,
437 psStubPBDesc,
438 0,
439 &SGXCleanupSharedPBDescCallback);
440 if (psResItem == IMG_NULL)
441 {
442 PVR_DPF((PVR_DBG_ERROR, "SGXAddSharedPBDescKM: "
443 "Failed to register shared PBDesc "
444 " with the resource manager"));
445 goto NoAdd;
446 }
447 psStubPBDesc->hDevCookie = hDevCookie;
448
449 /* Finally everything was prepared successfully so link the new
450 * PB in to place. */
451 List_PVRSRV_STUB_PBDESC_Insert(&(psSGXDevInfo->psStubPBDescListKM),
452 psStubPBDesc);
453
454 *phSharedPBDesc = (IMG_HANDLE)psResItem;
455
456 return PVRSRV_OK;
457
458NoAdd:
459 if(psStubPBDesc)
460 {
461 if(psStubPBDesc->ppsSubKernelMemInfos)
462 {
463 OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
464 sizeof(PVRSRV_KERNEL_MEM_INFO *) * ui32SharedPBDescSubKernelMemInfosCount,
465 psStubPBDesc->ppsSubKernelMemInfos,
466 0);
467 psStubPBDesc->ppsSubKernelMemInfos = IMG_NULL;
468 }
469 OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
470 sizeof(PVRSRV_STUB_PBDESC),
471 psStubPBDesc,
472 0);
473 /*not nulling pointer, out of scope*/
474 }
475
476NoAddKeepPB:
477 for (i = 0; i < ui32SharedPBDescSubKernelMemInfosCount; i++)
478 {
479 PVRSRVFreeDeviceMemKM(hDevCookie, ppsSharedPBDescSubKernelMemInfos[i]);
480 }
481
482 PVRSRVFreeSharedSysMemoryKM(psSharedPBDescKernelMemInfo);
483 PVRSRVFreeDeviceMemKM(hDevCookie, psHWPBDescKernelMemInfo);
484
485 PVRSRVFreeSharedSysMemoryKM(psBlockKernelMemInfo);
486 PVRSRVFreeDeviceMemKM(hDevCookie, psHWBlockKernelMemInfo);
487
488 return eRet;
489}
490
491/******************************************************************************
492 End of file (pb.c)
493******************************************************************************/