1 /*************************************************************************/ /*!
3 @Title RGX Proactive DVFS Functionality
5 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
6 @Description Kernel mode Proactive DVFS Functionality.
7 @License Dual MIT/GPLv2
9 The contents of this file are subject to the MIT license as set out below.
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
21 Alternatively, the contents of this file may be used under the terms of
22 the GNU General Public License Version 2 ("GPL") in which case the provisions
23 of GPL are applicable instead of those above.
25 If you wish to allow use of your version of this file only under the terms of
26 GPL, and not to allow others to use your version of this file under the terms
27 of the MIT license, indicate your decision by deleting the provisions above
28 and replace them with the notice and other provisions required by GPL as set
29 out in the file called "GPL-COPYING" included in this distribution. If you do
30 not delete the provisions above, a recipient may use your version of this file
31 under the terms of either the MIT license or GPL.
33 This License is also included in this distribution in the file called
36 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
37 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
39 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
40 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
41 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
42 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 */ /**************************************************************************/
46 #include "rgxfwutils.h"
47 #include "rgx_options.h"
48 #include "rgxtimecorr.h"
50 #define USEC_TO_MSEC 1000
52 static inline IMG_BOOL _PDVFSEnabled(void)
54 PVRSRV_DATA *psSRVData = PVRSRVGetPVRSRVData();
56 if (psSRVData->sDriverInfo.sKMBuildInfo.ui32BuildOptions &
57 psSRVData->sDriverInfo.sUMBuildInfo.ui32BuildOptions &
66 PVRSRV_ERROR PDVFSLimitMaxFrequency(PVRSRV_RGXDEV_INFO *psDevInfo, IMG_UINT32 ui32MaxOPPPoint)
68 RGXFWIF_KCCB_CMD sGPCCBCmd;
70 IMG_UINT32 ui32CmdKCCBSlot;
72 PVRSRV_VZ_RET_IF_MODE(GUEST, PVRSRV_ERROR_NOT_SUPPORTED);
76 /* No error message to avoid excessive messages */
81 sGPCCBCmd.eCmdType = RGXFWIF_KCCB_CMD_PDVFS_LIMIT_MAX_FREQ;
82 sGPCCBCmd.uCmdData.sPDVFSMaxFreqData.ui32MaxOPPPoint = ui32MaxOPPPoint;
84 /* Submit command to the firmware. */
85 LOOP_UNTIL_TIMEOUT(MAX_HW_TIME_US)
87 eError = RGXSendCommandAndGetKCCBSlot(psDevInfo,
89 PDUMP_FLAGS_CONTINUOUS,
91 if (eError != PVRSRV_ERROR_RETRY)
95 OSWaitus(MAX_HW_TIME_US/WAIT_TRY_COUNT);
96 } END_LOOP_UNTIL_TIMEOUT();
101 PVRSRV_ERROR PDVFSLimitMinFrequency(PVRSRV_RGXDEV_INFO *psDevInfo, IMG_UINT32 ui32MinOPPPoint)
103 RGXFWIF_KCCB_CMD sGPCCBCmd;
105 IMG_UINT32 ui32CmdKCCBSlot;
107 PVRSRV_VZ_RET_IF_MODE(GUEST, PVRSRV_ERROR_NOT_SUPPORTED);
109 if (!_PDVFSEnabled())
111 /* No error message to avoid excessive messages */
116 sGPCCBCmd.eCmdType = RGXFWIF_KCCB_CMD_PDVFS_LIMIT_MIN_FREQ;
117 sGPCCBCmd.uCmdData.sPDVFSMinFreqData.ui32MinOPPPoint = ui32MinOPPPoint;
119 /* Submit command to the firmware. */
120 LOOP_UNTIL_TIMEOUT(MAX_HW_TIME_US)
122 eError = RGXSendCommandAndGetKCCBSlot(psDevInfo,
124 PDUMP_FLAGS_CONTINUOUS,
126 if (eError != PVRSRV_ERROR_RETRY)
130 OSWaitus(MAX_HW_TIME_US/WAIT_TRY_COUNT);
131 } END_LOOP_UNTIL_TIMEOUT();
137 #if (PDVFS_COM == PDVFS_COM_HOST)
138 /*************************************************************************/ /*!
139 @Function PDVFSProcessCoreClkChangeRequest
140 @Description Processes a core clock rate change request.
141 @Input psDevInfo A pointer to PVRSRV_RGXDEV_INFO.
142 @Input ui32CoreClockRate New core clock rate.
143 @Return PVRSRV_ERROR.
144 */ /**************************************************************************/
145 PVRSRV_ERROR PDVFSProcessCoreClkChangeRequest(PVRSRV_RGXDEV_INFO *psDevInfo, IMG_UINT32 ui32CoreClockRate)
147 PVRSRV_DEVICE_CONFIG *psDevConfig = psDevInfo->psDeviceNode->psDevConfig;
148 IMG_DVFS_DEVICE_CFG *psDVFSDeviceCfg = &psDevConfig->sDVFS.sDVFSDeviceCfg;
149 RGX_TIMING_INFORMATION *psRGXTimingInfo = ((RGX_DATA*)(psDevConfig->hDevData))->psRGXTimingInfo;
150 IMG_UINT32 ui32CoreClockRateCurrent = psRGXTimingInfo->ui32CoreClockSpeed;
151 const IMG_OPP *psOpp = NULL;
152 IMG_UINT32 ui32Index;
155 if (!_PDVFSEnabled())
157 /* No error message to avoid excessive messages */
161 PVR_DPF((PVR_DBG_MESSAGE, "Core clock rate = %u", ui32CoreClockRate));
163 /* Find the matching OPP (Exact). */
164 for (ui32Index = 0; ui32Index < psDVFSDeviceCfg->ui32OPPTableSize; ui32Index++)
166 if (ui32CoreClockRate == psDVFSDeviceCfg->pasOPPTable[ui32Index].ui32Freq)
168 psOpp = &psDVFSDeviceCfg->pasOPPTable[ui32Index];
175 PVR_DPF((PVR_DBG_ERROR, "Frequency not present in OPP table - %u", ui32CoreClockRate));
176 return PVRSRV_ERROR_INVALID_PARAMS;
179 eError = PVRSRVDevicePreClockSpeedChange(psDevInfo->psDeviceNode, psDVFSDeviceCfg->bIdleReq, NULL);
180 if (eError != PVRSRV_OK)
182 PVR_DPF((PVR_DBG_ERROR, "PVRSRVDevicePreClockSpeedChange failed"));
186 psRGXTimingInfo->ui32CoreClockSpeed = ui32CoreClockRate;
188 /* Increasing frequency, change voltage first */
189 if (ui32CoreClockRate > ui32CoreClockRateCurrent)
191 psDVFSDeviceCfg->pfnSetVoltage(psOpp->ui32Volt);
194 psDVFSDeviceCfg->pfnSetFrequency(ui32CoreClockRate);
196 /* Decreasing frequency, change frequency first */
197 if (ui32CoreClockRate < ui32CoreClockRateCurrent)
199 psDVFSDeviceCfg->pfnSetVoltage(psOpp->ui32Volt);
202 PVRSRVDevicePostClockSpeedChange(psDevInfo->psDeviceNode, psDVFSDeviceCfg->bIdleReq, NULL);
207 /*************************************************************************/ /*!
208 @Function PDVFSProcessCoreClkChangeNotification
209 @Description Processes a core clock rate change notification.
210 @Input psDevInfo A pointer to PVRSRV_RGXDEV_INFO.
211 @Input ui32CoreClockRate New core clock rate.
212 @Return PVRSRV_ERROR.
213 */ /**************************************************************************/
214 PVRSRV_ERROR PDVFSProcessCoreClkChangeNotification(PVRSRV_RGXDEV_INFO *psDevInfo, IMG_UINT32 ui32CoreClockRate)
216 PVRSRV_DEVICE_CONFIG *psDevConfig = psDevInfo->psDeviceNode->psDevConfig;
217 RGX_TIMING_INFORMATION *psRGXTimingInfo = ((RGX_DATA*)(psDevConfig->hDevData))->psRGXTimingInfo;
218 PVRSRV_DEV_POWER_STATE ePowerState;
221 eError = PVRSRVPowerLock(psDevInfo->psDeviceNode);
223 if (eError != PVRSRV_OK)
225 PVR_DPF((PVR_DBG_ERROR, "%s: failed to acquire lock (%s)",
226 __func__, PVRSRVGetErrorString(eError)));
230 eError = PVRSRVGetDevicePowerState(psDevInfo->psDeviceNode, &ePowerState);
232 if (eError != PVRSRV_OK)
234 PVR_DPF((PVR_DBG_ERROR, "%s: failed to acquire power state (%s)",
235 __func__, PVRSRVGetErrorString(eError)));
236 PVRSRVPowerUnlock(psDevInfo->psDeviceNode);
240 /* Guest drivers do not initialize psRGXFWIfFwSysData */
241 if ((ePowerState != PVRSRV_DEV_POWER_STATE_OFF)
242 && ((psDevInfo->psRGXFWIfFwSysData == NULL) || (psDevInfo->psRGXFWIfFwSysData->ePowState != RGXFWIF_POW_OFF)))
244 /* Update GPU frequency and timer correlation related data */
245 RGXTimeCorrEnd(psDevInfo->psDeviceNode, RGXTIMECORR_EVENT_DVFS);
246 psRGXTimingInfo->ui32CoreClockSpeed = ui32CoreClockRate;
247 RGXTimeCorrBegin(psDevInfo->psDeviceNode, RGXTIMECORR_EVENT_DVFS);
251 psRGXTimingInfo->ui32CoreClockSpeed = ui32CoreClockRate;
254 PVRSRVPowerUnlock(psDevInfo->psDeviceNode);
261 #if defined(RGXFW_META_SUPPORT_2ND_THREAD)
262 /*************************************************************************/ /*!
263 @Function RGXPDVFSCheckCoreClkRateChange
264 @Description Checks if core clock rate has changed since the last snap-shot.
265 @Input psDevInfo A pointer to PVRSRV_RGXDEV_INFO.
267 */ /**************************************************************************/
268 void RGXPDVFSCheckCoreClkRateChange(PVRSRV_RGXDEV_INFO *psDevInfo)
270 IMG_UINT32 ui32CoreClkRate = *psDevInfo->pui32RGXFWIFCoreClkRate;
272 if (!_PDVFSEnabled())
274 /* No error message to avoid excessive messages */
278 if (ui32CoreClkRate != 0 && psDevInfo->ui32CoreClkRateSnapshot != ui32CoreClkRate)
280 psDevInfo->ui32CoreClkRateSnapshot = ui32CoreClkRate;
281 PDVFS_PROCESS_CORE_CLK_RATE_CHANGE(psDevInfo, ui32CoreClkRate);