hc
2023-05-26 a23f51ed7a39e452c1037343a84d7db1ca2c5bd7
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
/**************************************************************************/ /*!
@File
@Title          PowerVR services server header file
@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@License        Dual MIT/GPLv2
 
The contents of this file are subject to the MIT license as set out below.
 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
 
Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 2 ("GPL") in which case the provisions
of GPL are applicable instead of those above.
 
If you wish to allow use of your version of this file only under the terms of
GPL, and not to allow others to use your version of this file under the terms
of the MIT license, indicate your decision by deleting the provisions above
and replace them with the notice and other provisions required by GPL as set
out in the file called "GPL-COPYING" included in this distribution. If you do
not delete the provisions above, a recipient may use your version of this file
under the terms of either the MIT license or GPL.
 
This License is also included in this distribution in the file called
"MIT-COPYING".
 
EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ /***************************************************************************/
 
#ifndef PVRSRV_H
#define PVRSRV_H
 
 
#if defined(__KERNEL__) && defined(LINUX) && !defined(__GENKSYMS__)
#define __pvrsrv_defined_struct_enum__
#include <services_kernel_client.h>
#endif
 
#include "device.h"
#include "power.h"
#include "sysinfo.h"
#include "physheap.h"
#include "cache_ops.h"
#include "pvr_notifier.h"
#include "pvr_bridge.h"
#if defined(SUPPORT_RGX)
#include "rgx_bridge.h"
#endif
 
#include "connection_server.h"
 
#if defined(SUPPORT_GPUVIRT_VALIDATION)
#include "virt_validation_defs.h"
#endif
 
/*!
 * For OSThreadDestroy(), which may require a retry
 * Try for 100 ms to destroy an OS thread before failing
 */
#define OS_THREAD_DESTROY_TIMEOUT_US 100000ULL
#define OS_THREAD_DESTROY_RETRY_COUNT 10
 
typedef struct _BUILD_INFO_
{
   IMG_UINT32    ui32BuildOptions;
   IMG_UINT32    ui32BuildVersion;
   IMG_UINT32    ui32BuildRevision;
   IMG_UINT32    ui32BuildType;
#define BUILD_TYPE_DEBUG    0
#define BUILD_TYPE_RELEASE    1
   /*The above fields are self explanatory */
   /* B.V.N.C can be added later if required */
} BUILD_INFO;
 
typedef struct _DRIVER_INFO_
{
   BUILD_INFO    sUMBuildInfo;
   BUILD_INFO    sKMBuildInfo;
   IMG_BOOL    bIsNoMatch;
}DRIVER_INFO;
 
typedef struct PVRSRV_DATA_TAG
{
   DRIVER_INFO                    sDriverInfo;
   IMG_UINT32                    ui32RegisteredDevices;
   PVRSRV_DEVICE_NODE            *psDeviceNodeList;            /*!< List head of device nodes */
 
   PVRSRV_SERVICES_STATE        eServicesState;                /*!< global driver state */
 
   HASH_TABLE                    *psProcessHandleBase_Table; /*!< Hash table with process handle bases */
   POS_LOCK                    hProcessHandleBase_Lock;    /*!< Lock for the process handle base table */
 
   IMG_HANDLE                    hGlobalEventObject;            /*!< OS Global Event Object */
   IMG_UINT32                    ui32GEOConsecutiveTimeouts;    /*!< OS Global Event Object Timeouts */
 
   PVRSRV_CACHE_OP                uiCacheOp;                    /*!< Pending cache operations in the system */
#if (CACHEFLUSH_KM_TYPE == CACHEFLUSH_KM_RANGEBASED_DEFERRED)
   IMG_HANDLE                    hCacheOpThread;                /*!< CacheOp thread */
   IMG_HANDLE                    hCacheOpThreadEventObject;    /*!< Event object to drive CacheOp thread */
   IMG_HANDLE                    hCacheOpUpdateEventObject;    /*!< Update event object to drive CacheOp fencing */
   POS_LOCK                    hCacheOpThreadWorkListLock;    /*!< Lock protecting the cleanup thread work list */
   DLLIST_NODE                    sCacheOpThreadWorkList;        /*!< List of work for the cleanup thread */
   IMG_PID                        CacheOpThreadPid;            /*!< CacheOp thread process id */
#endif
 
   IMG_HANDLE                    hCleanupThread;                /*!< Cleanup thread */
   IMG_HANDLE                    hCleanupEventObject;        /*!< Event object to drive cleanup thread */
   POS_LOCK                    hCleanupThreadWorkListLock;    /*!< Lock protecting the cleanup thread work list */
   DLLIST_NODE                    sCleanupThreadWorkList;        /*!< List of work for the cleanup thread */
   IMG_PID                        cleanupThreadPid;            /*!< Cleanup thread process id */
 
   IMG_HANDLE                    hDevicesWatchdogThread;        /*!< Devices Watchdog thread */
   IMG_HANDLE                    hDevicesWatchdogEvObj;        /*! Event object to drive devices watchdog thread */
   volatile IMG_UINT32            ui32DevicesWatchdogPwrTrans;/*! Number of off -> on power state transitions */
   volatile IMG_UINT32            ui32DevicesWatchdogTimeout; /*! Timeout for the Devices Watchdog Thread */
#ifdef PVR_TESTING_UTILS
   volatile IMG_UINT32            ui32DevicesWdWakeupCounter;    /* Need this for the unit tests. */
#endif
 
#ifdef SUPPORT_PVRSRV_GPUVIRT
   IMG_HANDLE                    hVzData;                    /*! Additional virtualization data */
#endif
   
   IMG_BOOL                    bUnload;                    /*!< Driver unload is in progress */
} PVRSRV_DATA;
 
typedef IMG_BOOL (*PFN_LISR)(void *pvData);
 
/*!
******************************************************************************
 
 @Function    PVRSRVGetPVRSRVData
 
 @Description    Get a pointer to the global data
 
 @Return   PVRSRV_DATA *
 
******************************************************************************/
PVRSRV_DATA *PVRSRVGetPVRSRVData(void);
 
PVRSRV_ERROR LMA_PhyContigPagesAlloc(PVRSRV_DEVICE_NODE *psDevNode, size_t uiSize,
                           PG_HANDLE *psMemHandle, IMG_DEV_PHYADDR *psDevPAddr);
 
void LMA_PhyContigPagesFree(PVRSRV_DEVICE_NODE *psDevNode, PG_HANDLE *psMemHandle);
 
PVRSRV_ERROR LMA_PhyContigPagesMap(PVRSRV_DEVICE_NODE *psDevNode, PG_HANDLE *psMemHandle,
                           size_t uiSize, IMG_DEV_PHYADDR *psDevPAddr,
                           void **pvPtr);
 
void LMA_PhyContigPagesUnmap(PVRSRV_DEVICE_NODE *psDevNode, PG_HANDLE *psMemHandle,
                   void *pvPtr);
 
PVRSRV_ERROR LMA_PhyContigPagesClean(PVRSRV_DEVICE_NODE *psDevNode,
                                     PG_HANDLE *psMemHandle,
                                     IMG_UINT32 uiOffset,
                                     IMG_UINT32 uiLength);
 
 
/*!
******************************************************************************
 @Function    PVRSRVPollForValueKM
 
 @Description
 Polls for a value to match a masked read
 
 @Input pui32LinMemAddr : CPU linear address to poll
 @Input ui32Value : required value
 @Input ui32Mask : Mask
 
 @Return   PVRSRV_ERROR :
******************************************************************************/
IMG_IMPORT PVRSRV_ERROR IMG_CALLCONV PVRSRVPollForValueKM(volatile IMG_UINT32    *pui32LinMemAddr,
                                                         IMG_UINT32            ui32Value,
                                                         IMG_UINT32            ui32Mask);
 
/*!
******************************************************************************
 @Function    PVRSRVWaitForValueKM
 
 @Description
 Waits (using EventObjects) for a value to match a masked read
 
 @Input pui32LinMemAddr            : CPU linear address to poll
 @Input ui32Value                : required value
 @Input ui32Mask                : Mask
 
 @Return   PVRSRV_ERROR :
******************************************************************************/
IMG_IMPORT PVRSRV_ERROR IMG_CALLCONV PVRSRVWaitForValueKM(volatile IMG_UINT32    *pui32LinMemAddr,
                                                       IMG_UINT32            ui32Value,
                                                       IMG_UINT32            ui32Mask);
 
/*!
******************************************************************************
 @Function    PVRSRVWaitForValueKMAndHoldBridgeLockKM
 
 @Description
 Waits without releasing bridge lock (using EventObjects) for a value
 to match a masked read
 
 @Input pui32LinMemAddr            : CPU linear address to poll
 @Input ui32Value                : required value
 @Input ui32Mask                : Mask
 
 @Return   PVRSRV_ERROR :
******************************************************************************/
PVRSRV_ERROR IMG_CALLCONV PVRSRVWaitForValueKMAndHoldBridgeLockKM(volatile IMG_UINT32 *pui32LinMemAddr,
                                                                  IMG_UINT32          ui32Value,
                                                                  IMG_UINT32          ui32Mask);
 
/*!
*****************************************************************************
 @Function    : PVRSRVSystemHasCacheSnooping
 
 @Description    : Returns whether the system has cache snooping
 
 @Return : IMG_TRUE if the system has cache snooping
*****************************************************************************/
IMG_BOOL PVRSRVSystemHasCacheSnooping(PVRSRV_DEVICE_CONFIG *psDevConfig);
 
/*!
*****************************************************************************
 @Function    : PVRSRVSystemSnoopingOfCPUCache
 
 @Description    : Returns whether the system supports snooping of the CPU cache
 
 @Return : IMG_TRUE if the system has CPU cache snooping
*****************************************************************************/
IMG_BOOL PVRSRVSystemSnoopingOfCPUCache(PVRSRV_DEVICE_CONFIG *psDevConfig);
 
/*!
*****************************************************************************
 @Function    : PVRSRVSystemSnoopingOfDeviceCache
 
 @Description    : Returns whether the system supports snooping of the device cache
 
 @Return : IMG_TRUE if the system has device cache snooping
*****************************************************************************/
IMG_BOOL PVRSRVSystemSnoopingOfDeviceCache(PVRSRV_DEVICE_CONFIG *psDevConfig);
 
/*!
*****************************************************************************
 @Function    : PVRSRVSystemHasNonMappableLocalMemory
 
 @Description    : Returns whether the device has non-mappable part of local memory
 
 @Return : IMG_TRUE if the device has non-mappable part of local memory
*****************************************************************************/
IMG_BOOL PVRSRVSystemHasNonMappableLocalMemory(PVRSRV_DEVICE_CONFIG *psDevConfig);
 
/*!
*****************************************************************************
 @Function    : PVRSRVSystemWaitCycles
 
 @Description    : Waits for at least ui32Cycles of the Device clk.
 
*****************************************************************************/
void PVRSRVSystemWaitCycles(PVRSRV_DEVICE_CONFIG *psDevConfig, IMG_UINT32 ui32Cycles);
 
PVRSRV_ERROR PVRSRVSystemInstallDeviceLISR(void *pvOSDevice,
                                          IMG_UINT32 ui32IRQ,
                                          const IMG_CHAR *pszName,
                                          PFN_LISR pfnLISR,
                                          void *pvData,
                                          IMG_HANDLE *phLISRData);
 
PVRSRV_ERROR PVRSRVSystemUninstallDeviceLISR(IMG_HANDLE hLISRData);
 
int PVRSRVGetDriverStatus(void);
 
/*!
*****************************************************************************
 @Function    : PVRSRVIsBridgeEnabled
 
 @Description    : Returns whether the given bridge group is enabled
 
 @Return : IMG_TRUE if the given bridge group is enabled
*****************************************************************************/
static inline IMG_BOOL PVRSRVIsBridgeEnabled(IMG_HANDLE hServices, IMG_UINT32 ui32BridgeGroup)
{
   PVR_UNREFERENCED_PARAMETER(hServices);
 
#if defined(SUPPORT_RGX)
   if(ui32BridgeGroup >= PVRSRV_BRIDGE_RGX_FIRST)
   {
       return ((1U << (ui32BridgeGroup - PVRSRV_BRIDGE_RGX_FIRST)) &
                           gui32RGXBridges) != 0;
   }
   else
#endif /* SUPPORT_RGX */
   {
       return ((1U << (ui32BridgeGroup - PVRSRV_BRIDGE_FIRST)) &
                           gui32PVRBridges) != 0;
   }
}
 
/*!
*****************************************************************************
 @Function    : PVRSRVSystemBIFTilingHeapGetXStride
 
 @Description    : return the default x-stride configuration for the given
                  BIF tiling heap number
 
 @Input psDevConfig: Pointer to a device config
 
 @Input uiHeapNum: BIF tiling heap number, starting from 1
 
 @Output puiXStride: pointer to x-stride output of the requested heap
 
*****************************************************************************/
PVRSRV_ERROR
PVRSRVSystemBIFTilingHeapGetXStride(PVRSRV_DEVICE_CONFIG *psDevConfig,
                                   IMG_UINT32 uiHeapNum,
                                   IMG_UINT32 *puiXStride);
 
/*!
*****************************************************************************
 @Function              : PVRSRVSystemBIFTilingGetConfig
 
 @Description           : return the BIF tiling mode and number of BIF
                          tiling heaps for the given device config
 
 @Input psDevConfig     : Pointer to a device config
 
 @Output peBifTilingMode: Pointer to a BIF tiling mode enum
 
 @Output puiNumHeaps    : pointer to uint to hold number of heaps
 
*****************************************************************************/
PVRSRV_ERROR
PVRSRVSystemBIFTilingGetConfig(PVRSRV_DEVICE_CONFIG  *psDevConfig,
                               RGXFWIF_BIFTILINGMODE *peBifTilingMode,
                               IMG_UINT32            *puiNumHeaps);
 
#if defined(SUPPORT_GPUVIRT_VALIDATION)
/*!
***********************************************************************************
 @Function                : PopulateLMASubArenas
 
 @Description            : Uses the Apphints passed by the client at initialization
                         time to add bases and sizes in the various arenas in the
                         LMA memory
 
 @Input psDeviceNode    : Pointer to the device node struct containing all the
                         arena information
 
 @Input ui32OSidMin        : Single dimensional array containing the minimum values
                         for each OSid area
 
 @Input ui32OSidMax        : Single dimensional array containing the maximum values
                         for each OSid area
***********************************************************************************/
 
void PopulateLMASubArenas(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_UINT32 aui32OSidMin[GPUVIRT_VALIDATION_NUM_OS][GPUVIRT_VALIDATION_NUM_REGIONS], IMG_UINT32 aui32OSidMax[GPUVIRT_VALIDATION_NUM_OS][GPUVIRT_VALIDATION_NUM_REGIONS]);
 
#if defined(EMULATOR)
   void SetAxiProtOSid(IMG_UINT32 ui32OSid, IMG_BOOL bState);
   void SetTrustedDeviceAceEnabled(void);
#endif
 
#endif
 
#endif /* PVRSRV_H */