aboutsummaryrefslogtreecommitdiff
path: root/drivers/gpu/pvr/sysconfig.c
blob: 8ce48e4efb74173f91f17c55aab3eabaf5843e91 (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
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
/**********************************************************************
 *
 * 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 <linux/platform_device.h>

#include "services_headers.h"
#include "kerneldisplay.h"
#include "oemfuncs.h"
#include "sgxinfo.h"
#include "pdump_km.h"
#include "sgxinfokm.h"
#include "syslocal.h"
#include "sysconfig.h"
#include "syscommon.h"
#include "img_types.h"
#include "ocpdefs.h"
#include "pvr_bridge_km.h"

struct SYS_DATA *gpsSysData;
static struct SYS_DATA gsSysData;

static struct SYS_SPECIFIC_DATA gsSysSpecificData;
struct SYS_SPECIFIC_DATA *gpsSysSpecificData;

static u32 gui32SGXDeviceID;
static struct SGX_DEVICE_MAP gsSGXDeviceMap;
static struct PVRSRV_DEVICE_NODE *gpsSGXDevNode;

#define DEVICE_SGX_INTERRUPT	(1 << 0)

#if defined(NO_HARDWARE)
static void *gsSGXRegsCPUVAddr;
#endif

static void __iomem *ocp_base;

static enum PVRSRV_ERROR SysLocateDevices(struct SYS_DATA *psSysData)
{
#if defined(NO_HARDWARE)
	enum PVRSRV_ERROR eError;
	struct IMG_CPU_PHYADDR sCpuPAddr;
#endif

	PVR_UNREFERENCED_PARAMETER(psSysData);

	gsSGXDeviceMap.ui32Flags = 0x0;

#if defined(NO_HARDWARE)

	eError = OSBaseAllocContigMemory(SYS_OMAP3430_SGX_REGS_SIZE,
					 &gsSGXRegsCPUVAddr, &sCpuPAddr);
	if (eError != PVRSRV_OK)
		return eError;
	gsSGXDeviceMap.sRegsCpuPBase = sCpuPAddr;
	gsSGXDeviceMap.sRegsSysPBase =
	    SysCpuPAddrToSysPAddr(gsSGXDeviceMap.sRegsCpuPBase);
	gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3430_SGX_REGS_SIZE;

	gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;

	OSMemSet(gsSGXRegsCPUVAddr, 0, SYS_OMAP3430_SGX_REGS_SIZE);

	gsSGXDeviceMap.ui32IRQ = 0;

#else

	gsSGXDeviceMap.sRegsSysPBase.uiAddr =
	    SYS_OMAP3430_SGX_REGS_SYS_PHYS_BASE;
	gsSGXDeviceMap.sRegsCpuPBase =
	    SysSysPAddrToCpuPAddr(gsSGXDeviceMap.sRegsSysPBase);
	gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3430_SGX_REGS_SIZE;

	gsSGXDeviceMap.ui32IRQ = SYS_OMAP3430_SGX_IRQ;

#endif

	return PVRSRV_OK;
}

#ifndef NO_HARDWARE
u32 sgx_get_rev(void)
{
	/*
	 * Ugly solution, used until we have proper per device instances
	 * passed to functions and get rid of most if not all globals.
	 */
	struct SYS_SPECIFIC_DATA *sysd = gpsSysSpecificData;
	void __iomem *regs;
	static u32 rev = -1UL;
	int err;

	if (rev != -1UL)
		return rev;

	regs = OSMapPhysToLin(gsSGXDeviceMap.sRegsCpuPBase,
			       SYS_OMAP3430_SGX_REGS_SIZE,
			       PVRSRV_HAP_UNCACHED | PVRSRV_HAP_KERNEL_ONLY,
			       NULL);
	if (!regs)
		return 0;

	err = clk_enable(sysd->psSGX_FCK);
	BUG_ON(err);
	err = clk_enable(sysd->psSGX_ICK);
	BUG_ON(err);

	rev = OSReadHWReg(regs, EUR_CR_CORE_REVISION);

	clk_disable(sysd->psSGX_ICK);
	clk_disable(sysd->psSGX_FCK);

	OSUnMapPhysToLin(regs, SYS_OMAP3430_SGX_REGS_SIZE,
			 PVRSRV_HAP_UNCACHED | PVRSRV_HAP_KERNEL_ONLY, NULL);

	return rev;
}

unsigned long sgx_get_max_freq(void)
{
	struct SYS_SPECIFIC_DATA *sysd = gpsSysSpecificData;

	BUG_ON(!sysd);

	if (sysd->sgx_fck_max)
		return sysd->sgx_fck_max;

	/*
	 * In case there's no board specific setting for this, return
	 * some revision specific defaults.
	 */
	if (sgx_is_530()) {
		switch (sgx_get_rev()) {
		case EUR_CR_CORE_MAKE_REV(1, 2, 1):
			return SYS_SGX_MAX_FREQ_530R121;
		case EUR_CR_CORE_MAKE_REV(1, 2, 5):
			return SYS_SGX_MAX_FREQ_530R125;
		}
	}
	BUG();
}

#else

u32 sgx_get_rev(void)
{
	return 0;
}

unsigned long sgx_get_max_freq()
{
	return SYS_SGX_MAX_FREQ_NO_HW;
}

#endif

bool sgx_is_530(void)
{
#ifdef SGX530
	return true;
#endif
	return false;
}

char *SysCreateVersionString(struct IMG_CPU_PHYADDR sRegRegion)
{
	static char aszVersionString[100];
	struct SYS_DATA *psSysData;
	u32 ui32SGXRevision;
	s32 i32Count;

	if (SysAcquireData(&psSysData) != PVRSRV_OK)
		return NULL;

	ui32SGXRevision = sgx_get_rev();

	i32Count = OSSNPrintf(aszVersionString, 100,
			      "SGX revision = %u.%u.%u",
			      (unsigned)((ui32SGXRevision &
				     EUR_CR_CORE_REVISION_MAJOR_MASK)
				    >> EUR_CR_CORE_REVISION_MAJOR_SHIFT),
			      (unsigned)((ui32SGXRevision &
				     EUR_CR_CORE_REVISION_MINOR_MASK)
				    >> EUR_CR_CORE_REVISION_MINOR_SHIFT),
			      (unsigned)((ui32SGXRevision &
				     EUR_CR_CORE_REVISION_MAINTENANCE_MASK)
				    >> EUR_CR_CORE_REVISION_MAINTENANCE_SHIFT)
	    );

	if (i32Count == -1)
		return NULL;

	return aszVersionString;
}

static int sgx_ocp_init(void)
{
	struct IMG_SYS_PHYADDR sys_pbase;
	struct IMG_CPU_PHYADDR cpu_pbase;

	sys_pbase.uiAddr = SYS_OMAP3430_OCP_REGS_SYS_PHYS_BASE;
	cpu_pbase = SysSysPAddrToCpuPAddr(sys_pbase);

	ocp_base = OSMapPhysToLin(cpu_pbase, SYS_OMAP3430_OCP_REGS_SIZE,
				  PVRSRV_HAP_UNCACHED | PVRSRV_HAP_KERNEL_ONLY,
				  NULL);

	if (!ocp_base) {
		PVR_DPF(PVR_DBG_ERROR, "%s: Failed to map OCP registers",
			__func__);
		return -ENOMEM;
	}

	return 0;
}

static void sgx_ocp_cleanup(void)
{
	OSUnMapPhysToLin(ocp_base, SYS_OMAP3430_OCP_REGS_SIZE,
			 PVRSRV_HAP_UNCACHED | PVRSRV_HAP_KERNEL_ONLY, NULL);
}

void sgx_ocp_write_reg(u32 reg, u32 val)
{
	BUG_ON(!ocp_base);

	/* OCP offsets are based at EUR_CR_OCP_REVISION */
	reg -= EUR_CR_OCP_REVISION;
	OSWriteHWReg(ocp_base, reg, val);
}

enum PVRSRV_ERROR SysInitialise(struct platform_device *pdev)
{
	u32 i;
	enum PVRSRV_ERROR eError;
	struct PVRSRV_DEVICE_NODE *psDeviceNode;
	struct IMG_CPU_PHYADDR TimerRegPhysBase;
	struct sgx_platform_data *spd;

	gpsSysData = &gsSysData;

	gpsSysSpecificData = &gsSysSpecificData;

	gpsSysData->pvSysSpecificData = gpsSysSpecificData;

	spd = pdev->dev.platform_data;
	if (spd)
		gpsSysSpecificData->sgx_fck_max = spd->fclock_max;

	eError = OSInitEnvData(&gpsSysData->pvEnvSpecificData);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed to setup env structure");
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}
	SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
			      SYS_SPECIFIC_DATA_ENABLE_ENVDATA);

	gpsSysData->ui32NumDevices = SYS_DEVICE_COUNT;

	for (i = 0; i < SYS_DEVICE_COUNT; i++) {
		gpsSysData->sDeviceID[i].uiID = i;
		gpsSysData->sDeviceID[i].bInUse = IMG_FALSE;
	}

	gpsSysData->psDeviceNodeList = NULL;
	gpsSysData->psQueueList = NULL;

	eError = SysInitialiseCommon(gpsSysData);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed in SysInitialiseCommon");
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}

	TimerRegPhysBase.uiAddr =
	    SYS_OMAP3430_GP11TIMER_PHYS_BASE + SYS_OMAP3430_GPTIMER_REGS;
	gpsSysData->pvSOCTimerRegisterKM = NULL;
	gpsSysData->hSOCTimerRegisterOSMemHandle = NULL;
	OSReservePhys(TimerRegPhysBase, 4,
		      PVRSRV_HAP_MULTI_PROCESS | PVRSRV_HAP_UNCACHED,
		      (void **)&gpsSysData->pvSOCTimerRegisterKM,
		      &gpsSysData->hSOCTimerRegisterOSMemHandle);

	gpsSysSpecificData->ui32SrcClockDiv = 3;

	eError = SysLocateDevices(gpsSysData);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed to locate devices");
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}
	SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
			      SYS_SPECIFIC_DATA_ENABLE_LOCATEDEV);

	if (sgx_ocp_init() < 0) {
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;

		return PVRSRV_ERROR_GENERIC;
	}

	eError = PVRSRVRegisterDevice(gpsSysData, SGXRegisterDevice,
				      DEVICE_SGX_INTERRUPT, &gui32SGXDeviceID);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed to register device!");
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}
	SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
			      SYS_SPECIFIC_DATA_ENABLE_REGDEV);

	psDeviceNode = gpsSysData->psDeviceNodeList;
	while (psDeviceNode) {
		switch (psDeviceNode->sDevId.eDeviceType) {
		case PVRSRV_DEVICE_TYPE_SGX:
			{
				struct DEVICE_MEMORY_INFO *psDevMemoryInfo;
				struct DEVICE_MEMORY_HEAP_INFO
							*psDeviceMemoryHeap;

				psDeviceNode->psLocalDevMemArena = NULL;

				psDevMemoryInfo = &psDeviceNode->sDevMemoryInfo;
				psDeviceMemoryHeap =
				    psDevMemoryInfo->psDeviceMemoryHeap;

				for (i = 0; i < psDevMemoryInfo->ui32HeapCount;
				     i++)
					psDeviceMemoryHeap[i].ui32Attribs |=
					   PVRSRV_BACKINGSTORE_SYSMEM_NONCONTIG;

				gpsSGXDevNode = psDeviceNode;
				gsSysSpecificData.psSGXDevNode = psDeviceNode;

				break;
			}
		default:
			PVR_DPF(PVR_DBG_ERROR, "SysInitialise: "
					"Failed to find SGX device node!");
			return PVRSRV_ERROR_INIT_FAILURE;
		}

		psDeviceNode = psDeviceNode->psNext;
	}

	PDUMPINIT();
	SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
			      SYS_SPECIFIC_DATA_ENABLE_PDUMPINIT);

	eError = InitSystemClocks(gpsSysData);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed to init system clocks (%d)",
			 eError);
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}

	eError = EnableSystemClocks(gpsSysData);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed to Enable system clocks (%d)",
			 eError);
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}
	SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
			      SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS);

	eError = OSInitPerf(gpsSysData);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed to init DVFS (%d)", eError);
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}
	SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
			      SYS_SPECIFIC_DATA_ENABLE_PERF);

	eError = EnableSGXClocks(gpsSysData);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed to Enable SGX clocks (%d)",
			 eError);
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}

	eError = PVRSRVInitialiseDevice(gui32SGXDeviceID);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed to initialise device!");
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}
	SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
			      SYS_SPECIFIC_DATA_ENABLE_INITDEV);

	gpsSysData->pszVersionString =
	    SysCreateVersionString(gsSGXDeviceMap.sRegsCpuPBase);
	if (!gpsSysData->pszVersionString)
		PVR_DPF(PVR_DBG_ERROR,
		"SysFinalise: Failed to create a system version string");
	else
		PVR_DPF(PVR_DBG_WARNING, "SysFinalise: Version string: %s",
			 gpsSysData->pszVersionString);

	DisableSGXClocks(gpsSysData);

	return PVRSRV_OK;
}

enum PVRSRV_ERROR SysFinalise(void)
{
	enum PVRSRV_ERROR eError = PVRSRV_OK;

	eError = EnableSGXClocks(gpsSysData);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR,
			 "SysInitialise: Failed to Enable SGX clocks (%d)",
			 eError);
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}


	eError = OSInstallMISR(gpsSysData);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR, "SysFinalise: Failed to install MISR");
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}
	SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
			      SYS_SPECIFIC_DATA_ENABLE_MISR);

	eError =
	    OSInstallDeviceLISR(gpsSysData, gsSGXDeviceMap.ui32IRQ, "SGX ISR",
				gpsSGXDevNode);
	if (eError != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR, "SysFinalise: Failed to install ISR");
		SysDeinitialise(gpsSysData);
		gpsSysData = NULL;
		return eError;
	}
	SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
			      SYS_SPECIFIC_DATA_ENABLE_LISR);

	DisableSGXClocks(gpsSysData);

	gpsSysSpecificData->bSGXInitComplete = IMG_TRUE;

	return eError;
}

enum PVRSRV_ERROR SysDeinitialise(struct SYS_DATA *psSysData)
{
	enum PVRSRV_ERROR eError;

	if (SYS_SPECIFIC_DATA_TEST
	    (gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LISR)) {
		eError = OSUninstallDeviceLISR(psSysData);
		if (eError != PVRSRV_OK) {
			PVR_DPF(PVR_DBG_ERROR, "SysDeinitialise: "
					"OSUninstallDeviceLISR failed");
			return eError;
		}
	}

	if (SYS_SPECIFIC_DATA_TEST
	    (gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_MISR)) {
		eError = OSUninstallMISR(psSysData);
		if (eError != PVRSRV_OK) {
			PVR_DPF(PVR_DBG_ERROR, "SysDeinitialise: "
						"OSUninstallMISR failed");
			return eError;
		}
	}

	if (SYS_SPECIFIC_DATA_TEST
	    (gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_INITDEV)) {
		PVR_ASSERT(SYS_SPECIFIC_DATA_TEST
			   (gpsSysSpecificData,
			    SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS));

		eError = EnableSGXClocks(gpsSysData);
		if (eError != PVRSRV_OK) {
			PVR_DPF(PVR_DBG_ERROR,
				 "SysDeinitialise: EnableSGXClocks failed");
			return eError;
		}

		eError = PVRSRVDeinitialiseDevice(gui32SGXDeviceID);

		DisableSGXClocks(gpsSysData);

		if (eError != PVRSRV_OK) {
			PVR_DPF(PVR_DBG_ERROR, "SysDeinitialise: "
					"failed to de-init the device");
			return eError;
		}
	}

	if (SYS_SPECIFIC_DATA_TEST
	    (gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS))
		DisableSystemClocks(gpsSysData);

	CleanupSystemClocks(gpsSysData);

	if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData,
				   SYS_SPECIFIC_DATA_ENABLE_PERF)) {
		eError = OSCleanupPerf(psSysData);
		if (eError != PVRSRV_OK) {
			PVR_DPF(PVR_DBG_ERROR,
				 "SysDeinitialise: OSCleanupDvfs failed");
			return eError;
		}
	}

	sgx_ocp_cleanup();

	if (SYS_SPECIFIC_DATA_TEST
	    (gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_ENVDATA)) {
		eError = OSDeInitEnvData(gpsSysData->pvEnvSpecificData);
		if (eError != PVRSRV_OK) {
			PVR_DPF(PVR_DBG_ERROR,
			"SysDeinitialise: failed to de-init env structure");
			return eError;
		}
	}

	if (gpsSysData->pvSOCTimerRegisterKM)
		OSUnReservePhys(gpsSysData->pvSOCTimerRegisterKM, 4,
				PVRSRV_HAP_MULTI_PROCESS | PVRSRV_HAP_UNCACHED,
				gpsSysData->hSOCTimerRegisterOSMemHandle);

	SysDeinitialiseCommon(gpsSysData);

#if defined(NO_HARDWARE)
	if (SYS_SPECIFIC_DATA_TEST
	    (gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LOCATEDEV))

		OSBaseFreeContigMemory(SYS_OMAP3430_SGX_REGS_SIZE,
				       gsSGXRegsCPUVAddr,
				       gsSGXDeviceMap.sRegsCpuPBase);
#endif

	if (SYS_SPECIFIC_DATA_TEST
	    (gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PDUMPINIT))
		PDUMPDEINIT();

	gpsSysSpecificData->ui32SysSpecificData = 0;
	gpsSysSpecificData->bSGXInitComplete = IMG_FALSE;

	gpsSysData = NULL;

	return PVRSRV_OK;
}

enum PVRSRV_ERROR SysGetDeviceMemoryMap(enum PVRSRV_DEVICE_TYPE eDeviceType,
				   void **ppvDeviceMap)
{
	switch (eDeviceType) {
	case PVRSRV_DEVICE_TYPE_SGX:
		*ppvDeviceMap = (void *) &gsSGXDeviceMap;
		break;
	default:
		PVR_DPF(PVR_DBG_ERROR, "SysGetDeviceMemoryMap: "
					"unsupported device type");
	}
	return PVRSRV_OK;
}

struct IMG_DEV_PHYADDR SysCpuPAddrToDevPAddr(
				enum PVRSRV_DEVICE_TYPE eDeviceType,
				struct IMG_CPU_PHYADDR CpuPAddr)
{
	struct IMG_DEV_PHYADDR DevPAddr;

	PVR_UNREFERENCED_PARAMETER(eDeviceType);

	DevPAddr.uiAddr = CpuPAddr.uiAddr;

	return DevPAddr;
}

struct IMG_CPU_PHYADDR SysSysPAddrToCpuPAddr(struct IMG_SYS_PHYADDR sys_paddr)
{
	struct IMG_CPU_PHYADDR cpu_paddr;

	cpu_paddr.uiAddr = sys_paddr.uiAddr;
	return cpu_paddr;
}

struct IMG_SYS_PHYADDR SysCpuPAddrToSysPAddr(struct IMG_CPU_PHYADDR cpu_paddr)
{
	struct IMG_SYS_PHYADDR sys_paddr;

	sys_paddr.uiAddr = cpu_paddr.uiAddr;
	return sys_paddr;
}

struct IMG_DEV_PHYADDR SysSysPAddrToDevPAddr(
				enum PVRSRV_DEVICE_TYPE eDeviceType,
				struct IMG_SYS_PHYADDR SysPAddr)
{
	struct IMG_DEV_PHYADDR DevPAddr;

	PVR_UNREFERENCED_PARAMETER(eDeviceType);

	DevPAddr.uiAddr = SysPAddr.uiAddr;

	return DevPAddr;
}

struct IMG_SYS_PHYADDR SysDevPAddrToSysPAddr(
				      enum PVRSRV_DEVICE_TYPE eDeviceType,
				      struct IMG_DEV_PHYADDR DevPAddr)
{
	struct IMG_SYS_PHYADDR SysPAddr;

	PVR_UNREFERENCED_PARAMETER(eDeviceType);

	SysPAddr.uiAddr = DevPAddr.uiAddr;

	return SysPAddr;
}

void SysRegisterExternalDevice(struct PVRSRV_DEVICE_NODE *psDeviceNode)
{
	PVR_UNREFERENCED_PARAMETER(psDeviceNode);
}

void SysRemoveExternalDevice(struct PVRSRV_DEVICE_NODE *psDeviceNode)
{
	PVR_UNREFERENCED_PARAMETER(psDeviceNode);
}

u32 SysGetInterruptSource(struct SYS_DATA *psSysData,
				 struct PVRSRV_DEVICE_NODE *psDeviceNode)
{
	PVR_UNREFERENCED_PARAMETER(psSysData);
#if defined(NO_HARDWARE)

	return 0xFFFFFFFF;
#else

	return psDeviceNode->ui32SOCInterruptBit;
#endif
}

void SysClearInterrupts(struct SYS_DATA *psSysData, u32 ui32ClearBits)
{
	PVR_UNREFERENCED_PARAMETER(psSysData);
	PVR_UNREFERENCED_PARAMETER(ui32ClearBits);

	OSReadHWReg(((struct PVRSRV_SGXDEV_INFO *)gpsSGXDevNode->pvDevice)->
		    pvRegsBaseKM, EUR_CR_EVENT_HOST_CLEAR);
}

enum PVRSRV_ERROR SysSystemPrePowerState(enum PVR_POWER_STATE eNewPowerState)
{
	enum PVRSRV_ERROR eError = PVRSRV_OK;

	if (eNewPowerState == PVRSRV_POWER_STATE_D3) {
		PVR_TRACE("SysSystemPrePowerState: Entering state D3");

		if (SYS_SPECIFIC_DATA_TEST
		    (&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LISR)) {
			eError = OSUninstallDeviceLISR(gpsSysData);
			if (eError != PVRSRV_OK) {
				PVR_DPF(PVR_DBG_ERROR,
						"SysSystemPrePowerState: "
						"OSUninstallDeviceLISR failed "
						"(%d)",
					 eError);
				return eError;
			}
			SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
					SYS_SPECIFIC_DATA_PM_UNINSTALL_LISR);
			SYS_SPECIFIC_DATA_CLEAR(&gsSysSpecificData,
					SYS_SPECIFIC_DATA_ENABLE_LISR);
		}

		if (SYS_SPECIFIC_DATA_TEST
		    (&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS)) {
			DisableSystemClocks(gpsSysData);

			SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
				SYS_SPECIFIC_DATA_PM_DISABLE_SYSCLOCKS);
			SYS_SPECIFIC_DATA_CLEAR(&gsSysSpecificData,
				SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS);
		}
	}

	return eError;
}

enum PVRSRV_ERROR SysSystemPostPowerState(enum PVR_POWER_STATE eNewPowerState)
{
	enum PVRSRV_ERROR eError = PVRSRV_OK;

	if (eNewPowerState == PVRSRV_POWER_STATE_D0) {
		PVR_TRACE("SysSystemPostPowerState: Entering state D0");

		if (SYS_SPECIFIC_DATA_TEST
		    (&gsSysSpecificData,
		     SYS_SPECIFIC_DATA_PM_DISABLE_SYSCLOCKS)) {
			eError = EnableSystemClocks(gpsSysData);
			if (eError != PVRSRV_OK) {
				PVR_DPF(PVR_DBG_ERROR,
					"SysSystemPostPowerState: "
					"EnableSystemClocks failed (%d)",
					 eError);
				return eError;
			}
			SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
					SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS);
			SYS_SPECIFIC_DATA_CLEAR(&gsSysSpecificData,
					SYS_SPECIFIC_DATA_PM_DISABLE_SYSCLOCKS);
		}
		if (SYS_SPECIFIC_DATA_TEST
		    (&gsSysSpecificData, SYS_SPECIFIC_DATA_PM_UNINSTALL_LISR)) {
			eError =
			    OSInstallDeviceLISR(gpsSysData,
						gsSGXDeviceMap.ui32IRQ,
						"SGX ISR", gpsSGXDevNode);
			if (eError != PVRSRV_OK) {
				PVR_DPF(PVR_DBG_ERROR,
						"SysSystemPostPowerState: "
						"OSInstallDeviceLISR failed "
						"to install ISR (%d)",
					 eError);
				return eError;
			}
			SYS_SPECIFIC_DATA_SET(&gsSysSpecificData,
				SYS_SPECIFIC_DATA_ENABLE_LISR);
			SYS_SPECIFIC_DATA_CLEAR(&gsSysSpecificData,
				SYS_SPECIFIC_DATA_PM_UNINSTALL_LISR);
		}
	}
	return eError;
}

enum PVRSRV_ERROR SysDevicePrePowerState(u32 ui32DeviceIndex,
				    enum PVR_POWER_STATE eNewPowerState,
				    enum PVR_POWER_STATE eCurrentPowerState)
{
	PVR_UNREFERENCED_PARAMETER(eCurrentPowerState);

	if (ui32DeviceIndex != gui32SGXDeviceID)
		return PVRSRV_OK;
	if (eNewPowerState == PVRSRV_POWER_STATE_D3) {
		PVR_DPF(PVR_DBG_MESSAGE,
			 "SysDevicePrePowerState: SGX Entering state D3");
		DisableSGXClocks(gpsSysData);
	}
	return PVRSRV_OK;
}

enum PVRSRV_ERROR SysDevicePostPowerState(u32 ui32DeviceIndex,
				     enum PVR_POWER_STATE eNewPowerState,
				     enum PVR_POWER_STATE eCurrentPowerState)
{
	enum PVRSRV_ERROR eError = PVRSRV_OK;

	PVR_UNREFERENCED_PARAMETER(eNewPowerState);

	if (ui32DeviceIndex != gui32SGXDeviceID)
		return eError;
	if (eCurrentPowerState == PVRSRV_POWER_STATE_D3) {
		PVR_DPF(PVR_DBG_MESSAGE,
			 "SysDevicePostPowerState: SGX Leaving state D3");
		eError = EnableSGXClocks(gpsSysData);
	}

	return eError;
}

enum PVRSRV_ERROR SysOEMFunction(u32 ui32ID, void *pvIn, u32 ulInSize,
			    void *pvOut, u32 ulOutSize)
{
	PVR_UNREFERENCED_PARAMETER(ui32ID);
	PVR_UNREFERENCED_PARAMETER(pvIn);
	PVR_UNREFERENCED_PARAMETER(ulInSize);
	PVR_UNREFERENCED_PARAMETER(pvOut);
	PVR_UNREFERENCED_PARAMETER(ulOutSize);

	if ((ui32ID == OEM_GET_EXT_FUNCS) &&
	    (ulOutSize == sizeof(struct PVRSRV_DC_OEM_JTABLE))) {

		struct PVRSRV_DC_OEM_JTABLE *psOEMJTable =
		    (struct PVRSRV_DC_OEM_JTABLE *)pvOut;
		psOEMJTable->pfnOEMBridgeDispatch = &PVRSRV_BridgeDispatchKM;
		return PVRSRV_OK;
	}

	return PVRSRV_ERROR_INVALID_PARAMS;
}