aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/ice4100/sgx535/pvr_bridge_k.c
blob: df57264afa891cf04f9a004956965a20691c5801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
/**********************************************************************
 *
 * Copyright (c) 2010 Intel Corporation.
 * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful but, except
 * as otherwise stated in writing, without any warranty; without even the
 * implied warranty of merchantability or fitness for a particular purpose.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * The full GNU General Public License is included in this distribution in
 * the file called "COPYING".
 *
 * Contact Information:
 * Imagination Technologies Ltd. <gpl-support@imgtec.com>
 * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
 *
 ******************************************************************************/


#include "services.h"
#include "pvr_bridge.h"
#include "perproc.h"
#include "syscommon.h"
#include "pvr_debug.h"
#include "proc.h"
#include "private_data.h"
#include "linkage.h"
#include "pvr_bridge_km.h"

#if defined(SUPPORT_DRI_DRM)
#include <drm/drmP.h>
#include "pvr_drm.h"
#if defined(PVR_SECURE_DRM_AUTH_EXPORT)
#include "env_perproc.h"
#endif
#endif

#if defined(SUPPORT_VGX)
#include "vgx_bridge.h"
#endif

#if defined(SUPPORT_SGX)
#include "sgx_bridge.h"
#endif

#include "bridged_pvr_bridge.h"

#ifdef MODULE_TEST
#include "pvr_test_bridge.h"
#include "kern_test.h"
#endif

#if defined(SUPPORT_DRI_DRM)
#define	PRIVATE_DATA(pFile) ((pFile)->driver_priv)
#else
#define	PRIVATE_DATA(pFile) ((pFile)->private_data)
#endif

#if defined(DEBUG_BRIDGE_KM)

#ifdef PVR_PROC_USE_SEQ_FILE
static struct proc_dir_entry *g_ProcBridgeStats = 0;
static void *ProcSeqNextBridgeStats(struct seq_file *sfile, void *el,
				    loff_t off);
static void ProcSeqShowBridgeStats(struct seq_file *sfile, void *el);
static void *ProcSeqOff2ElementBridgeStats(struct seq_file *sfile, loff_t off);
static void ProcSeqStartstopBridgeStats(struct seq_file *sfile, int start);

#else
static off_t printLinuxBridgeStats(char *buffer, size_t size, off_t off);
#endif

#endif

extern struct mutex gPVRSRVLock;

#if defined(SUPPORT_MEMINFO_IDS)
static u64 ui64Stamp;
#endif

PVRSRV_ERROR LinuxBridgeInit(void)
{
#if defined(DEBUG_BRIDGE_KM)
	{
		int iStatus;
#ifdef PVR_PROC_USE_SEQ_FILE
		g_ProcBridgeStats = CreateProcReadEntrySeq("bridge_stats",
							   NULL,
							   ProcSeqNextBridgeStats,
							   ProcSeqShowBridgeStats,
							   ProcSeqOff2ElementBridgeStats,
							   ProcSeqStartstopBridgeStats);
		iStatus = !g_ProcBridgeStats ? -1 : 0;
#else
		iStatus =
		    CreateProcReadEntry("bridge_stats", printLinuxBridgeStats);
#endif

		if (iStatus != 0) {
			return PVRSRV_ERROR_OUT_OF_MEMORY;
		}
	}
#endif
	return CommonBridgeInit();
}

void LinuxBridgeDeInit(void)
{
#if defined(DEBUG_BRIDGE_KM)
#ifdef PVR_PROC_USE_SEQ_FILE
	RemoveProcEntrySeq(g_ProcBridgeStats);
#else
	RemoveProcEntry("bridge_stats");
#endif
#endif
}

#if defined(DEBUG_BRIDGE_KM)

#ifdef PVR_PROC_USE_SEQ_FILE

static void ProcSeqStartstopBridgeStats(struct seq_file *sfile, int start)
{
	if (start) {
		mutex_lock(&gPVRSRVLock);
	} else {
		mutex_unlock(&gPVRSRVLock);
	}
}

static void *ProcSeqOff2ElementBridgeStats(struct seq_file *sfile, loff_t off)
{
	if (!off) {
		return PVR_PROC_SEQ_START_TOKEN;
	}

	if (off > BRIDGE_DISPATCH_TABLE_ENTRY_COUNT) {
		return (void *)0;
	}

	return (void *)&g_BridgeDispatchTable[off - 1];
}

static void *ProcSeqNextBridgeStats(struct seq_file *sfile, void *el,
				    loff_t off)
{
	return ProcSeqOff2ElementBridgeStats(sfile, off);
}

static void ProcSeqShowBridgeStats(struct seq_file *sfile, void *el)
{
	PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY *psEntry =
	    (PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY *) el;

	if (el == PVR_PROC_SEQ_START_TOKEN) {
		seq_printf(sfile,
			   "Total ioctl call count = %lu\n"
			   "Total number of bytes copied via copy_from_user = %lu\n"
			   "Total number of bytes copied via copy_to_user = %lu\n"
			   "Total number of bytes copied via copy_*_user = %lu\n\n"
			   "%-45s | %-40s | %10s | %20s | %10s\n",
			   g_BridgeGlobalStats.ui32IOCTLCount,
			   g_BridgeGlobalStats.ui32TotalCopyFromUserBytes,
			   g_BridgeGlobalStats.ui32TotalCopyToUserBytes,
			   g_BridgeGlobalStats.ui32TotalCopyFromUserBytes +
			   g_BridgeGlobalStats.ui32TotalCopyToUserBytes,
			   "Bridge Name", "Wrapper Function", "Call Count",
			   "copy_from_user Bytes", "copy_to_user Bytes");
		return;
	}

	seq_printf(sfile,
		   "%-45s   %-40s   %-10lu   %-20lu   %-10lu\n",
		   psEntry->pszIOCName,
		   psEntry->pszFunctionName,
		   psEntry->ui32CallCount,
		   psEntry->ui32CopyFromUserTotalBytes,
		   psEntry->ui32CopyToUserTotalBytes);
}

#else

static off_t printLinuxBridgeStats(char *buffer, size_t count, off_t off)
{
	PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY *psEntry;
	off_t Ret;

	mutex_lock(&gPVRSRVLock);

	if (!off) {
		if (count < 500) {
			Ret = 0;
			goto unlock_and_return;
		}
		Ret = printAppend(buffer, count, 0,
				  "Total ioctl call count = %lu\n"
				  "Total number of bytes copied via copy_from_user = %lu\n"
				  "Total number of bytes copied via copy_to_user = %lu\n"
				  "Total number of bytes copied via copy_*_user = %lu\n\n"
				  "%-45s | %-40s | %10s | %20s | %10s\n",
				  g_BridgeGlobalStats.ui32IOCTLCount,
				  g_BridgeGlobalStats.
				  ui32TotalCopyFromUserBytes,
				  g_BridgeGlobalStats.ui32TotalCopyToUserBytes,
				  g_BridgeGlobalStats.
				  ui32TotalCopyFromUserBytes +
				  g_BridgeGlobalStats.ui32TotalCopyToUserBytes,
				  "Bridge Name", "Wrapper Function",
				  "Call Count", "copy_from_user Bytes",
				  "copy_to_user Bytes");
		goto unlock_and_return;
	}

	if (off > BRIDGE_DISPATCH_TABLE_ENTRY_COUNT) {
		Ret = END_OF_FILE;
		goto unlock_and_return;
	}

	if (count < 300) {
		Ret = 0;
		goto unlock_and_return;
	}

	psEntry = &g_BridgeDispatchTable[off - 1];
	Ret = printAppend(buffer, count, 0,
			  "%-45s   %-40s   %-10lu   %-20lu   %-10lu\n",
			  psEntry->pszIOCName,
			  psEntry->pszFunctionName,
			  psEntry->ui32CallCount,
			  psEntry->ui32CopyFromUserTotalBytes,
			  psEntry->ui32CopyToUserTotalBytes);

unlock_and_return:
	mutex_unlock(&gPVRSRVLock);
	return Ret;
}
#endif
#endif

#if defined(SUPPORT_DRI_DRM)
int
PVRSRV_BridgeDispatchKM(struct drm_device *dev, void *arg,
			struct drm_file *pFile)
#else
int PVRSRV_BridgeDispatchKM(struct file *pFile, u32 unref__ ioctlCmd, u32 arg)
#endif
{
	u32 cmd;
#if !defined(SUPPORT_DRI_DRM)
	PVRSRV_BRIDGE_PACKAGE *psBridgePackageUM =
	    (PVRSRV_BRIDGE_PACKAGE *) arg;
	PVRSRV_BRIDGE_PACKAGE sBridgePackageKM;
#endif
	PVRSRV_BRIDGE_PACKAGE *psBridgePackageKM;
	u32 ui32PID = OSGetCurrentProcessIDKM();
	PVRSRV_PER_PROCESS_DATA *psPerProc;
	int err = -EFAULT;

	mutex_lock(&gPVRSRVLock);

#if defined(SUPPORT_DRI_DRM)
	psBridgePackageKM = (PVRSRV_BRIDGE_PACKAGE *) arg;
	PVR_ASSERT(psBridgePackageKM != NULL);
#else
	psBridgePackageKM = &sBridgePackageKM;

	if (!OSAccessOK(PVR_VERIFY_WRITE,
			psBridgePackageUM, sizeof(PVRSRV_BRIDGE_PACKAGE))) {
		PVR_DPF((PVR_DBG_ERROR,
			 "%s: Received invalid pointer to function arguments",
			 __FUNCTION__));

		goto unlock_and_return;
	}

	if (OSCopyFromUser(NULL,
			   psBridgePackageKM,
			   psBridgePackageUM, sizeof(PVRSRV_BRIDGE_PACKAGE))
	    != PVRSRV_OK) {
		goto unlock_and_return;
	}
#endif

	cmd = psBridgePackageKM->ui32BridgeID;

#if defined(MODULE_TEST)
	switch (cmd) {
	case PVRSRV_BRIDGE_SERVICES_TEST_MEM1:
		{
			PVRSRV_ERROR eError = MemTest1();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;
	case PVRSRV_BRIDGE_SERVICES_TEST_MEM2:
		{
			PVRSRV_ERROR eError = MemTest2();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;

	case PVRSRV_BRIDGE_SERVICES_TEST_RESOURCE:
		{
			PVRSRV_ERROR eError = ResourceTest();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;

	case PVRSRV_BRIDGE_SERVICES_TEST_EVENTOBJECT:
		{
			PVRSRV_ERROR eError = EventObjectTest();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;

	case PVRSRV_BRIDGE_SERVICES_TEST_MEMMAPPING:
		{
			PVRSRV_ERROR eError = MemMappingTest();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;

	case PVRSRV_BRIDGE_SERVICES_TEST_PROCESSID:
		{
			PVRSRV_ERROR eError = ProcessIDTest();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;

	case PVRSRV_BRIDGE_SERVICES_TEST_CLOCKUSWAITUS:
		{
			PVRSRV_ERROR eError = ClockusWaitusTest();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;

	case PVRSRV_BRIDGE_SERVICES_TEST_TIMER:
		{
			PVRSRV_ERROR eError = TimerTest();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;

	case PVRSRV_BRIDGE_SERVICES_TEST_PRIVSRV:
		{
			PVRSRV_ERROR eError = PrivSrvTest();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;
	case PVRSRV_BRIDGE_SERVICES_TEST_COPYDATA:
		{
			u32 ui32PID;
			PVRSRV_PER_PROCESS_DATA *psPerProc;
			PVRSRV_ERROR eError;

			ui32PID = OSGetCurrentProcessIDKM();

			PVRSRVTrace("PVRSRV_BRIDGE_SERVICES_TEST_COPYDATA %d",
				    ui32PID);

			psPerProc = PVRSRVPerProcessData(ui32PID);

			eError =
			    CopyDataTest(psBridgePackageKM->pvParamIn,
					 psBridgePackageKM->pvParamOut,
					 psPerProc);

			*(PVRSRV_ERROR *) psBridgePackageKM->pvParamOut =
			    eError;
			err = 0;
			goto unlock_and_return;
		}

	case PVRSRV_BRIDGE_SERVICES_TEST_POWERMGMT:
		{
			PVRSRV_ERROR eError = PowerMgmtTest();
			if (psBridgePackageKM->ui32OutBufferSize ==
			    sizeof(PVRSRV_BRIDGE_RETURN)) {
				PVRSRV_BRIDGE_RETURN *pReturn =
				    (PVRSRV_BRIDGE_RETURN *) psBridgePackageKM->
				    pvParamOut;
				pReturn->eError = eError;
			}
		}
		err = 0;
		goto unlock_and_return;

	}
#endif

	if (cmd != PVRSRV_BRIDGE_CONNECT_SERVICES) {
		PVRSRV_ERROR eError;

		eError = PVRSRVLookupHandle(KERNEL_HANDLE_BASE,
					    (void **)&psPerProc,
					    psBridgePackageKM->hKernelServices,
					    PVRSRV_HANDLE_TYPE_PERPROC_DATA);
		if (eError != PVRSRV_OK) {
			PVR_DPF((PVR_DBG_ERROR,
				 "%s: Invalid kernel services handle (%d)",
				 __FUNCTION__, eError));
			goto unlock_and_return;
		}

		if (psPerProc->ui32PID != ui32PID) {
			PVR_DPF((PVR_DBG_ERROR,
				 "%s: Process %d tried to access data "
				 "belonging to process %d", __FUNCTION__,
				 ui32PID, psPerProc->ui32PID));
			goto unlock_and_return;
		}
	} else {

		psPerProc = PVRSRVPerProcessData(ui32PID);
		if (psPerProc == NULL) {
			PVR_DPF((PVR_DBG_ERROR, "PVRSRV_BridgeDispatchKM: "
				 "Couldn't create per-process data area"));
			goto unlock_and_return;
		}
	}

	psBridgePackageKM->ui32BridgeID =
	    PVRSRV_GET_BRIDGE_ID(psBridgePackageKM->ui32BridgeID);

#if defined(PVR_SECURE_FD_EXPORT)
	switch (cmd) {
	case PVRSRV_BRIDGE_EXPORT_DEVICEMEM:
		{
			PVRSRV_FILE_PRIVATE_DATA *psPrivateData =
			    PRIVATE_DATA(pFile);

			if (psPrivateData->hKernelMemInfo) {
				PVR_DPF((PVR_DBG_ERROR,
					 "%s: Can only export one MemInfo "
					 "per file descriptor", __FUNCTION__));
				err = -EINVAL;
				goto unlock_and_return;
			}
			break;
		}

	case PVRSRV_BRIDGE_MAP_DEV_MEMORY:
		{
			PVRSRV_BRIDGE_IN_MAP_DEV_MEMORY *psMapDevMemIN =
			    (PVRSRV_BRIDGE_IN_MAP_DEV_MEMORY *)
			    psBridgePackageKM->pvParamIn;
			PVRSRV_FILE_PRIVATE_DATA *psPrivateData =
			    PRIVATE_DATA(pFile);

			if (!psPrivateData->hKernelMemInfo) {
				PVR_DPF((PVR_DBG_ERROR,
					 "%s: File descriptor has no "
					 "associated MemInfo handle",
					 __FUNCTION__));
				err = -EINVAL;
				goto unlock_and_return;
			}

			psMapDevMemIN->hKernelMemInfo =
			    psPrivateData->hKernelMemInfo;
			break;
		}

	default:
		{
			PVRSRV_FILE_PRIVATE_DATA *psPrivateData =
			    PRIVATE_DATA(pFile);

			if (psPrivateData->hKernelMemInfo) {
				PVR_DPF((PVR_DBG_ERROR,
					 "%s: Import/Export handle tried "
					 "to use privileged service",
					 __FUNCTION__));
				goto unlock_and_return;
			}
			break;
		}
	}
#endif
#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
	switch (cmd) {
	case PVRSRV_BRIDGE_MAP_DEV_MEMORY:
	case PVRSRV_BRIDGE_MAP_DEVICECLASS_MEMORY:
		{
			PVRSRV_FILE_PRIVATE_DATA *psPrivateData;
			int authenticated = pFile->authenticated;
			PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc;

			if (authenticated) {
				break;
			}

			psEnvPerProc =
			    (PVRSRV_ENV_PER_PROCESS_DATA *)
			    PVRSRVProcessPrivateData(psPerProc);
			if (psEnvPerProc == NULL) {
				PVR_DPF((PVR_DBG_ERROR,
					 "%s: Process private data not allocated",
					 __FUNCTION__));
				err = -EFAULT;
				goto unlock_and_return;
			}

			list_for_each_entry(psPrivateData,
					    &psEnvPerProc->sDRMAuthListHead,
					    sDRMAuthListItem) {
				struct drm_file *psDRMFile =
				    psPrivateData->psDRMFile;

				if (pFile->master == psDRMFile->master) {
					authenticated |=
					    psDRMFile->authenticated;
					if (authenticated) {
						break;
					}
				}
			}

			if (!authenticated) {
				PVR_DPF((PVR_DBG_ERROR,
					 "%s: Not authenticated for mapping device or device class memory",
					 __FUNCTION__));
				err = -EPERM;
				goto unlock_and_return;
			}
			break;
		}
	default:
		break;
	}
#endif

	err = BridgedDispatchKM(psPerProc, psBridgePackageKM);
	if (err != PVRSRV_OK)
		goto unlock_and_return;

	switch (cmd) {
#if defined(PVR_SECURE_FD_EXPORT)
	case PVRSRV_BRIDGE_EXPORT_DEVICEMEM:
		{
			PVRSRV_BRIDGE_OUT_EXPORTDEVICEMEM *psExportDeviceMemOUT
			    =
			    (PVRSRV_BRIDGE_OUT_EXPORTDEVICEMEM *)
			    psBridgePackageKM->pvParamOut;
			PVRSRV_FILE_PRIVATE_DATA *psPrivateData =
			    PRIVATE_DATA(pFile);

			psPrivateData->hKernelMemInfo =
			    psExportDeviceMemOUT->hMemInfo;
#if defined(SUPPORT_MEMINFO_IDS)
			psExportDeviceMemOUT->ui64Stamp =
			    psPrivateData->ui64Stamp = ++ui64Stamp;
#endif
			break;
		}
#endif

#if defined(SUPPORT_MEMINFO_IDS)
	case PVRSRV_BRIDGE_MAP_DEV_MEMORY:
		{
			PVRSRV_BRIDGE_OUT_MAP_DEV_MEMORY *psMapDeviceMemoryOUT =
			    (PVRSRV_BRIDGE_OUT_MAP_DEV_MEMORY *)
			    psBridgePackageKM->pvParamOut;
			PVRSRV_FILE_PRIVATE_DATA *psPrivateData =
			    PRIVATE_DATA(pFile);
			psMapDeviceMemoryOUT->sDstClientMemInfo.ui64Stamp =
			    psPrivateData->ui64Stamp;
			break;
		}

	case PVRSRV_BRIDGE_MAP_DEVICECLASS_MEMORY:
		{
			PVRSRV_BRIDGE_OUT_MAP_DEVICECLASS_MEMORY
			    *psDeviceClassMemoryOUT =
			    (PVRSRV_BRIDGE_OUT_MAP_DEVICECLASS_MEMORY *)
			    psBridgePackageKM->pvParamOut;
			psDeviceClassMemoryOUT->sClientMemInfo.ui64Stamp =
			    ++ui64Stamp;
			break;
		}
#endif

	default:
		break;
	}

unlock_and_return:
	mutex_unlock(&gPVRSRVLock);
	return err;
}