2517e04866bf28f984687e6be3b76916bf067c9a
[sgx.git] / pvr / sgxinfokm.h
1 /**********************************************************************
2  *
3  * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful but, except
10  * as otherwise stated in writing, without any warranty; without even the
11  * implied warranty of merchantability or fitness for a particular purpose.
12  * See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * The full GNU General Public License is included in this distribution in
19  * the file called "COPYING".
20  *
21  * Contact Information:
22  * Imagination Technologies Ltd. <gpl-support@imgtec.com>
23  * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
24  *
25  ******************************************************************************/
26
27 #ifndef __SGXINFOKM_H__
28 #define __SGXINFOKM_H__
29
30 #include <linux/workqueue.h>
31 #include "sgxdefs.h"
32 #include "device.h"
33 #include "sysconfig.h"
34 #include "sgxscript.h"
35 #include "sgxinfo.h"
36
37
38 #define SGX_HOSTPORT_PRESENT                                    0x00000001UL
39
40 #define PVRSRV_USSE_EDM_POWMAN_IDLE_COMPLETE                    (1UL << 2)
41 #define PVRSRV_USSE_EDM_POWMAN_POWEROFF_COMPLETE                (1UL << 3)
42 #define PVRSRV_USSE_EDM_POWMAN_POWEROFF_RESTART_IMMEDIATE       (1UL << 4)
43 #define PVRSRV_USSE_EDM_POWMAN_NO_WORK                          (1UL << 5)
44
45 #define PVRSRV_USSE_EDM_INTERRUPT_HWR                           (1UL << 0)
46 #define PVRSRV_USSE_EDM_INTERRUPT_ACTIVE_POWER                  (1UL << 1)
47
48 #define PVRSRV_USSE_EDM_RESMAN_CLEANUP_RT_REQUEST               0x01UL
49 #define PVRSRV_USSE_EDM_RESMAN_CLEANUP_RC_REQUEST               0x02UL
50 #define PVRSRV_USSE_EDM_RESMAN_CLEANUP_TC_REQUEST               0x04UL
51 #define PVRSRV_USSE_EDM_RESMAN_CLEANUP_2DC_REQUEST              0x08UL
52 #define PVRSRV_USSE_EDM_RESMAN_CLEANUP_SHAREDPBDESC             0x10UL
53 #define PVRSRV_USSE_EDM_RESMAN_CLEANUP_INVALPD                  0x20UL
54 #define PVRSRV_USSE_EDM_RESMAN_CLEANUP_INVALPT                  0x40UL
55 #define PVRSRV_USSE_EDM_RESMAN_CLEANUP_COMPLETE                 0x80UL
56
57 #define PVRSRV_USSE_MISCINFO_READY                              0x1UL
58
59 struct PVRSRV_SGX_CCB_INFO;
60
61 struct PVRSRV_SGXDEV_INFO {
62         enum PVRSRV_DEVICE_TYPE eDeviceType;
63         enum PVRSRV_DEVICE_CLASS eDeviceClass;
64
65         u8 ui8VersionMajor;
66         u8 ui8VersionMinor;
67         u32 ui32CoreConfig;
68         u32 ui32CoreFlags;
69
70         void __iomem *pvRegsBaseKM;
71
72         void *hRegMapping;
73
74         struct IMG_SYS_PHYADDR sRegsPhysBase;
75
76         u32 ui32RegSize;
77
78         u32 ui32CoreClockSpeed;
79         u32 ui32uKernelTimerClock;
80
81         void *psStubPBDescListKM;
82
83         struct IMG_DEV_PHYADDR sKernelPDDevPAddr;
84
85         void *pvDeviceMemoryHeap;
86         struct PVRSRV_KERNEL_MEM_INFO *psKernelCCBMemInfo;
87         struct PVRSRV_SGX_KERNEL_CCB *psKernelCCB;
88         struct PVRSRV_SGX_CCB_INFO *psKernelCCBInfo;
89         struct PVRSRV_KERNEL_MEM_INFO *psKernelCCBCtlMemInfo;
90         struct PVRSRV_SGX_CCB_CTL *psKernelCCBCtl;
91         struct PVRSRV_KERNEL_MEM_INFO *psKernelCCBEventKickerMemInfo;
92         u32 *pui32KernelCCBEventKicker;
93         struct PVRSRV_KERNEL_MEM_INFO *psKernelSGXMiscMemInfo;
94         u32 ui32HostKickAddress;
95         u32 ui32GetMiscInfoAddress;
96         u32 ui32KickTACounter;
97         u32 ui32KickTARenderCounter;
98         struct PVRSRV_KERNEL_MEM_INFO *psKernelHWPerfCBMemInfo;
99         struct PVRSRV_SGXDEV_DIFF_INFO sDiffInfo;
100         u32 ui32HWGroupRequested;
101         u32 ui32HWReset;
102
103         /*!< Meminfo for EDM status buffer */
104         struct PVRSRV_KERNEL_MEM_INFO *psKernelEDMStatusBufferMemInfo;
105
106         u32 ui32ClientRefCount;
107
108         u32 ui32CacheControl;
109
110         void *pvMMUContextList;
111
112         IMG_BOOL bForcePTOff;
113
114         u32 ui32EDMTaskReg0;
115         u32 ui32EDMTaskReg1;
116
117         u32 ui32ClkGateStatusReg;
118         u32 ui32ClkGateStatusMask;
119         struct SGX_INIT_SCRIPTS sScripts;
120
121         void *hBIFResetPDOSMemHandle;
122         struct IMG_DEV_PHYADDR sBIFResetPDDevPAddr;
123         struct IMG_DEV_PHYADDR sBIFResetPTDevPAddr;
124         struct IMG_DEV_PHYADDR sBIFResetPageDevPAddr;
125         u32 *pui32BIFResetPD;
126         u32 *pui32BIFResetPT;
127
128         void *hTimer;
129         u32 ui32TimeStamp;
130         u32 ui32NumResets;
131
132         unsigned long long last_idle;
133         unsigned long long burst_start;
134         int burst_size;
135         int burst_cnt;
136         int power_down_delay;
137
138         struct PVRSRV_KERNEL_MEM_INFO *psKernelSGXHostCtlMemInfo;
139         struct SGXMKIF_HOST_CTL __iomem *psSGXHostCtl;
140
141         struct PVRSRV_KERNEL_MEM_INFO *psKernelSGXTA3DCtlMemInfo;
142
143         u32 ui32Flags;
144
145 #if defined(PDUMP)
146         struct PVRSRV_SGX_PDUMP_CONTEXT sPDContext;
147 #endif
148
149
150         u32 asSGXDevData[SGX_MAX_DEV_DATA];
151
152         u32 state_buf_ofs;
153 };
154
155 struct SGX_TIMING_INFORMATION {
156         u32 ui32CoreClockSpeed;
157         u32 ui32HWRecoveryFreq;
158         u32 ui32ActivePowManLatencyms;
159         u32 ui32uKernelFreq;
160 };
161
162 struct SGX_DEVICE_MAP {
163         u32 ui32Flags;
164
165         struct IMG_SYS_PHYADDR sRegsSysPBase;
166         struct IMG_CPU_PHYADDR sRegsCpuPBase;
167         void __iomem *pvRegsCpuVBase;
168         u32 ui32RegsSize;
169
170         struct IMG_SYS_PHYADDR sLocalMemSysPBase;
171         struct IMG_DEV_PHYADDR sLocalMemDevPBase;
172         struct IMG_CPU_PHYADDR sLocalMemCpuPBase;
173         u32 ui32LocalMemSize;
174
175         u32 ui32IRQ;
176 };
177
178 struct PVRSRV_STUB_PBDESC;
179 struct PVRSRV_STUB_PBDESC {
180         u32 ui32RefCount;
181         u32 ui32TotalPBSize;
182         struct PVRSRV_KERNEL_MEM_INFO *psSharedPBDescKernelMemInfo;
183         struct PVRSRV_KERNEL_MEM_INFO *psHWPBDescKernelMemInfo;
184         struct PVRSRV_KERNEL_MEM_INFO **ppsSubKernelMemInfos;
185         u32 ui32SubKernelMemInfosCount;
186         void *hDevCookie;
187         struct PVRSRV_KERNEL_MEM_INFO *psBlockKernelMemInfo;
188         struct PVRSRV_STUB_PBDESC *psNext;
189 };
190
191 struct PVRSRV_SGX_CCB_INFO {
192         struct PVRSRV_KERNEL_MEM_INFO *psCCBMemInfo;
193         struct PVRSRV_KERNEL_MEM_INFO *psCCBCtlMemInfo;
194         struct SGXMKIF_COMMAND *psCommands;
195         u32 *pui32WriteOffset;
196         volatile u32 *pui32ReadOffset;
197 #if defined(PDUMP)
198         u32 ui32CCBDumpWOff;
199 #endif
200 };
201
202 struct timer_work_data {
203         struct PVRSRV_DEVICE_NODE *psDeviceNode;
204         struct delayed_work work;
205         struct workqueue_struct *work_queue;
206         unsigned int interval;
207         bool armed;
208 };
209
210 enum PVRSRV_ERROR SGXRegisterDevice(struct PVRSRV_DEVICE_NODE *psDeviceNode);
211 enum PVRSRV_ERROR SGXOSTimerEnable(struct timer_work_data *data);
212 enum PVRSRV_ERROR SGXOSTimerCancel(struct timer_work_data *data);
213 struct timer_work_data *
214 SGXOSTimerInit(struct PVRSRV_DEVICE_NODE *psDeviceNode);
215 void SGXOSTimerDeInit(struct timer_work_data *data);
216
217 void HWRecoveryResetSGX(struct PVRSRV_DEVICE_NODE *psDeviceNode,
218                         const char *caller);
219 void SGXReset(struct PVRSRV_SGXDEV_INFO *psDevInfo, u32 ui32PDUMPFlags);
220
221 enum PVRSRV_ERROR SGXInitialise(struct PVRSRV_SGXDEV_INFO *psDevInfo,
222                                 IMG_BOOL bHardwareRecovery);
223 enum PVRSRV_ERROR SGXDeinitialise(void *hDevCookie);
224
225 void sgx_mark_new_command(struct PVRSRV_DEVICE_NODE *node);
226 void sgx_mark_power_down(struct PVRSRV_DEVICE_NODE *node);
227
228 void SGXStartTimer(struct PVRSRV_SGXDEV_INFO *psDevInfo,
229                    IMG_BOOL bStartOSTimer);
230
231 enum PVRSRV_ERROR SGXPrePowerStateExt(void *hDevHandle,
232                                       enum PVR_POWER_STATE eNewPowerState,
233                                       enum PVR_POWER_STATE eCurrentPowerState);
234
235 enum PVRSRV_ERROR SGXPostPowerStateExt(void *hDevHandle,
236                                        enum PVR_POWER_STATE eNewPowerState,
237                                        enum PVR_POWER_STATE eCurrentPowerState);
238
239 enum PVRSRV_ERROR SGXPreClockSpeedChange(void *hDevHandle,
240                                          IMG_BOOL bIdleDevice,
241                                          enum PVR_POWER_STATE
242                                          eCurrentPowerState);
243
244 enum PVRSRV_ERROR SGXPostClockSpeedChange(void *hDevHandle,
245                                           IMG_BOOL bIdleDevice,
246                                           enum PVR_POWER_STATE
247                                           eCurrentPowerState);
248
249 enum PVRSRV_ERROR SGXDevInitCompatCheck(struct PVRSRV_DEVICE_NODE
250                                         *psDeviceNode);
251
252 void SysGetSGXTimingInformation(struct SGX_TIMING_INFORMATION *psSGXTimingInfo);
253
254 #if defined(NO_HARDWARE)
255 static inline void NoHardwareGenerateEvent(struct PVRSRV_SGXDEV_INFO *psDevInfo,
256                                            u32 ui32StatusRegister,
257                                            u32 ui32StatusValue,
258                                            u32 ui32StatusMask)
259 {
260         u32 ui32RegVal;
261
262         ui32RegVal = OSReadHWReg(psDevInfo->pvRegsBaseKM, ui32StatusRegister);
263
264         ui32RegVal &= ~ui32StatusMask;
265         ui32RegVal |= (ui32StatusValue & ui32StatusMask);
266
267         OSWriteHWReg(psDevInfo->pvRegsBaseKM, ui32StatusRegister, ui32RegVal);
268 }
269 #endif
270
271 #endif