RK3368 GPU version: Rogue M 1.31+
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / system / rk3368 / sysconfig.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          System Configuration
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    System Configuration functions
6 @License        Dual MIT/GPLv2
7
8 The contents of this file are subject to the MIT license as set out below.
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
23
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
31
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
34
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
43 #include <linux/version.h>
44 #include "pvrsrv_device.h"
45 #include "syscommon.h"
46 #include "sysconfig.h"
47 #include "physheap.h"
48 #if defined(SUPPORT_ION)
49 #include "ion_support.h"
50 #endif
51 #include "rk_init.h"
52
53 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
54 #include <linux/platform_device.h>
55 extern struct platform_device *gpsPVRLDMDev;
56 #endif
57
58 static RGX_TIMING_INFORMATION   gsRGXTimingInfo;
59 static RGX_DATA                 gsRGXData;
60 static PVRSRV_DEVICE_CONFIG     gsDevices[1];
61 static PVRSRV_SYSTEM_CONFIG     gsSysConfig;
62
63 static PHYS_HEAP_FUNCTIONS      gsPhysHeapFuncs;
64 #if defined(TDMETACODE)
65 static PHYS_HEAP_CONFIG         gsPhysHeapConfig[3];
66 #else
67 static PHYS_HEAP_CONFIG         gsPhysHeapConfig[1];
68 #endif
69
70 /*
71         CPU to Device physcial address translation
72 */
73 static
74 IMG_VOID UMAPhysHeapCpuPAddrToDevPAddr(IMG_HANDLE hPrivData,
75                                                                            IMG_UINT32 ui32NumOfAddr,
76                                                                            IMG_DEV_PHYADDR *psDevPAddr,
77                                                                            IMG_CPU_PHYADDR *psCpuPAddr)
78 {
79         PVR_UNREFERENCED_PARAMETER(hPrivData);
80
81         /* Optimise common case */
82         psDevPAddr[0].uiAddr = psCpuPAddr[0].uiAddr;
83         if (ui32NumOfAddr > 1)
84         {
85                 IMG_UINT32 ui32Idx;
86                 for (ui32Idx = 1; ui32Idx < ui32NumOfAddr; ++ui32Idx)
87                 {
88                         psDevPAddr[ui32Idx].uiAddr = psCpuPAddr[ui32Idx].uiAddr;
89                 }
90         }
91 }
92
93 /*
94         Device to CPU physcial address translation
95 */
96 static
97 IMG_VOID UMAPhysHeapDevPAddrToCpuPAddr(IMG_HANDLE hPrivData,
98                                                                            IMG_UINT32 ui32NumOfAddr,
99                                                                            IMG_CPU_PHYADDR *psCpuPAddr,
100                                                                            IMG_DEV_PHYADDR *psDevPAddr)                           
101 {
102         PVR_UNREFERENCED_PARAMETER(hPrivData);
103
104         /* Optimise common case */
105         psCpuPAddr[0].uiAddr = psDevPAddr[0].uiAddr;
106         if (ui32NumOfAddr > 1)
107         {
108                 IMG_UINT32 ui32Idx;
109                 for (ui32Idx = 1; ui32Idx < ui32NumOfAddr; ++ui32Idx)
110                 {
111                         psCpuPAddr[ui32Idx].uiAddr = psDevPAddr[ui32Idx].uiAddr;
112                 }
113         }
114 }
115
116 /*
117         SysCreateConfigData
118 */
119 PVRSRV_ERROR SysCreateConfigData(PVRSRV_SYSTEM_CONFIG **ppsSysConfig, void *hDevice)
120 {
121         PVR_UNREFERENCED_PARAMETER(hDevice);
122         /* Rk Init */
123         RgxRkInit();
124
125         /*
126          * Setup information about physical memory heap(s) we have
127          */
128         gsPhysHeapFuncs.pfnCpuPAddrToDevPAddr = UMAPhysHeapCpuPAddrToDevPAddr;
129         gsPhysHeapFuncs.pfnDevPAddrToCpuPAddr = UMAPhysHeapDevPAddrToCpuPAddr;
130
131         gsPhysHeapConfig[0].ui32PhysHeapID = 0;
132         gsPhysHeapConfig[0].pszPDumpMemspaceName = "SYSMEM";
133         gsPhysHeapConfig[0].eType = PHYS_HEAP_TYPE_UMA;
134         gsPhysHeapConfig[0].psMemFuncs = &gsPhysHeapFuncs;
135         gsPhysHeapConfig[0].hPrivData = IMG_NULL;
136
137 #if defined(TDMETACODE)
138         gsPhysHeapConfig[1].ui32PhysHeapID = 1;
139         gsPhysHeapConfig[1].pszPDumpMemspaceName = "TDMETACODEMEM";
140         gsPhysHeapConfig[1].eType = PHYS_HEAP_TYPE_UMA;
141         gsPhysHeapConfig[1].psMemFuncs = &gsPhysHeapFuncs;
142         gsPhysHeapConfig[1].hPrivData = IMG_NULL;
143
144         gsPhysHeapConfig[2].ui32PhysHeapID = 2;
145         gsPhysHeapConfig[2].pszPDumpMemspaceName = "TDSECUREBUFMEM";
146         gsPhysHeapConfig[2].eType = PHYS_HEAP_TYPE_UMA;
147         gsPhysHeapConfig[2].psMemFuncs = &gsPhysHeapFuncs;
148         gsPhysHeapConfig[2].hPrivData = IMG_NULL;
149 #endif
150
151         gsSysConfig.pasPhysHeaps = &(gsPhysHeapConfig[0]);
152         gsSysConfig.ui32PhysHeapCount = IMG_ARR_NUM_ELEMS(gsPhysHeapConfig);
153
154         gsSysConfig.pui32BIFTilingHeapConfigs = gauiBIFTilingHeapXStrides;
155         gsSysConfig.ui32BIFTilingHeapCount = IMG_ARR_NUM_ELEMS(gauiBIFTilingHeapXStrides);
156
157         /*
158          * Setup RGX specific timing data
159          */
160         gsRGXTimingInfo.ui32CoreClockSpeed        = RGX_RK_CORE_CLOCK_SPEED;
161         gsRGXTimingInfo.bEnableActivePM           = IMG_TRUE;
162         gsRGXTimingInfo.bEnableRDPowIsland        = IMG_TRUE;
163         gsRGXTimingInfo.ui32ActivePMLatencyms     = SYS_RGX_ACTIVE_POWER_LATENCY_MS;
164
165         /*
166          *Setup RGX specific data
167          */
168         gsRGXData.psRGXTimingInfo = &gsRGXTimingInfo;
169 #if defined(TDMETACODE)
170         gsRGXData.bHasTDMetaCodePhysHeap = IMG_TRUE;
171         gsRGXData.uiTDMetaCodePhysHeapID = 1;
172
173         gsRGXData.bHasTDSecureBufPhysHeap = IMG_TRUE;
174         gsRGXData.uiTDSecureBufPhysHeapID = 2;
175 #endif
176
177         /*
178          * Setup RGX device
179          */
180         gsDevices[0].eDeviceType            = PVRSRV_DEVICE_TYPE_RGX;
181         gsDevices[0].pszName                = "RGX";
182
183         /* Device setup information */
184         gsDevices[0].sRegsCpuPBase.uiAddr   = RK_GPU_PBASE;
185         gsDevices[0].ui32RegsSize           = RK_GPU_SIZE;
186 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
187         gsDevices[0].ui32IRQ                = RK_IRQ_GPU;
188 #else
189         gsDevices[0].ui32IRQ                = platform_get_irq(gpsPVRLDMDev, 0);
190 #endif
191         gsDevices[0].bIRQIsShared           = IMG_FALSE;
192
193         /* Device's physical heap IDs */
194         gsDevices[0].aui32PhysHeapID[PVRSRV_DEVICE_PHYS_HEAP_GPU_LOCAL] = 0;
195         gsDevices[0].aui32PhysHeapID[PVRSRV_DEVICE_PHYS_HEAP_CPU_LOCAL] = 0;
196
197         /* No power management on RK system */
198         gsDevices[0].pfnPrePowerState       = RkPrePowerState;
199         gsDevices[0].pfnPostPowerState      = RkPostPowerState;
200
201         /* No clock frequency either */
202         gsDevices[0].pfnClockFreqGet        = IMG_NULL;
203
204         /* No interrupt handled either */
205         gsDevices[0].pfnInterruptHandled    = IMG_NULL;
206
207         gsDevices[0].pfnCheckMemAllocSize   = SysCheckMemAllocSize;
208
209         gsDevices[0].hDevData               = &gsRGXData;
210
211         /*
212          * Setup system config
213          */
214         gsSysConfig.pszSystemName = RGX_RK_SYSTEM_NAME;
215         gsSysConfig.uiDeviceCount = sizeof(gsDevices)/sizeof(gsDevices[0]);
216         gsSysConfig.pasDevices = &gsDevices[0];
217
218         /* No power management on no HW system */
219         gsSysConfig.pfnSysPrePowerState = IMG_NULL;
220         gsSysConfig.pfnSysPostPowerState = IMG_NULL;
221
222         /* no cache snooping */
223         gsSysConfig.eCacheSnoopingMode = PVRSRV_SYSTEM_SNOOP_NONE;
224
225         /* Setup other system specific stuff */
226 #if defined(SUPPORT_ION)
227         IonInit(NULL);
228 #endif
229
230         *ppsSysConfig = &gsSysConfig;
231
232         return PVRSRV_OK;
233 }
234
235 /*
236         SysDestroyConfigData
237 */
238 IMG_VOID SysDestroyConfigData(PVRSRV_SYSTEM_CONFIG *psSysConfig)
239 {
240         PVR_UNREFERENCED_PARAMETER(psSysConfig);
241
242         /* Rk UnInit */
243         RgxRkUnInit();
244
245 #if defined(SUPPORT_ION)
246         IonDeinit();
247 #endif
248 }
249
250 PVRSRV_ERROR SysAcquireSystemData(IMG_HANDLE hSysData)
251 {
252         PVR_UNREFERENCED_PARAMETER(hSysData);
253
254         return PVRSRV_ERROR_NOT_SUPPORTED;
255 }
256
257 PVRSRV_ERROR SysReleaseSystemData(IMG_HANDLE hSysData)
258 {
259         PVR_UNREFERENCED_PARAMETER(hSysData);
260
261         return PVRSRV_ERROR_NOT_SUPPORTED;
262 }
263
264 PVRSRV_ERROR SysDebugInfo(PVRSRV_SYSTEM_CONFIG *psSysConfig, DUMPDEBUG_PRINTF_FUNC *pfnDumpDebugPrintf)
265 {
266         PVR_UNREFERENCED_PARAMETER(psSysConfig);
267         PVR_UNREFERENCED_PARAMETER(pfnDumpDebugPrintf);
268         return PVRSRV_OK;
269 }
270
271 /******************************************************************************
272  End of file (sysconfig.c)
273 ******************************************************************************/