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
/* SPDX-License-Identifier: GPL-2.0 */
 
/*  --------------------------------------------------------------------------------------------------------
 *  File: pvrsrv_device_node.h
 *  --------------------------------------------------------------------------------------------------------
 */
 
#ifndef __PVRSRV_DEVICE_NODE_H__
#define __PVRSRV_DEVICE_NODE_H__
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* ---------------------------------------------------------------------------------------------------------
 *  Include Files
 * ---------------------------------------------------------------------------------------------------------
 */
 
#include "powervr/sync_external.h"
#include "ra.h"
#include "devicemem_heapcfg.h"
#include "pvrsrv_device.h"
#include "mmu_common.h"
#include "img_types.h"
#include "lock_types.h"
 
 
/* ---------------------------------------------------------------------------------------------------------
 *  Macros Definition
 * ---------------------------------------------------------------------------------------------------------
 */
 
 
/* ---------------------------------------------------------------------------------------------------------
 *  Types and Structures Definition
 * ---------------------------------------------------------------------------------------------------------
 */
 
typedef struct _PG_HANDLE_ {
   union {
       void *pvHandle;
       IMG_UINT64 ui64Handle;
   } u;
   /*Order of the corresponding allocation */
   IMG_UINT32    ui32Order;
} PG_HANDLE;
 
typedef PVRSRV_ERROR (*FN_CREATERAMBACKEDPMR)(struct _PVRSRV_DEVICE_NODE_ *psDevNode,
                                       IMG_DEVMEM_SIZE_T uiSize,
                                       IMG_DEVMEM_SIZE_T uiChunkSize,
                                       IMG_UINT32 ui32NumPhysChunks,
                                       IMG_UINT32 ui32NumVirtChunks,
                                       IMG_UINT32 *pui32MappingTable,
                                       IMG_UINT32 uiLog2PageSize,
                                       PVRSRV_MEMALLOCFLAGS_T uiFlags,
                                       const IMG_CHAR *pszAnnotation,
                                       PMR **ppsPMRPtr);
 
 
typedef struct _PVRSRV_POWER_DEV_TAG_ PVRSRV_POWER_DEV;
 
typedef enum _PVRSRV_DEVICE_STATE_ {
   PVRSRV_DEVICE_STATE_UNDEFINED = 0,
   PVRSRV_DEVICE_STATE_INIT,
   PVRSRV_DEVICE_STATE_ACTIVE,
   PVRSRV_DEVICE_STATE_DEINIT,
   PVRSRV_DEVICE_STATE_BAD,
} PVRSRV_DEVICE_STATE;
 
typedef struct _PVRSRV_DEVICE_IDENTIFIER_ {
   /* Pdump memory and register bank names */
   IMG_CHAR                *pszPDumpDevName;
   IMG_CHAR                *pszPDumpRegName;
} PVRSRV_DEVICE_IDENTIFIER;
 
typedef struct _DEVICE_MEMORY_INFO_ {
   /* heap count.  Doesn't include additional heaps from PVRSRVCreateDeviceMemHeap */
   IMG_UINT32                ui32HeapCount;
 
    /* Blueprints for creating new device memory contexts */
   IMG_UINT32              uiNumHeapConfigs;
   DEVMEM_HEAP_CONFIG      *psDeviceMemoryHeapConfigArray;
   DEVMEM_HEAP_BLUEPRINT   *psDeviceMemoryHeap;
} DEVICE_MEMORY_INFO;
 
/*********************************************************************/ /*!
 @Function      AllocUFOCallback
 @Description   Device specific callback for allocation of an UFO block
 
 @Input            psDeviceNode            Pointer to device node to allocate
                                       the UFO for.
 @Output        ppsMemDesc                Pointer to pointer for the memdesc of
                                       the allocation
 @Output        pui32SyncAddr            FW Base address of the UFO block
 @Output        puiSyncPrimBlockSize    Size of the UFO block
 
 @Return        PVRSRV_OK if allocation was successful
 */
/*********************************************************************/
typedef PVRSRV_ERROR (*AllocUFOBlockCallback)(struct _PVRSRV_DEVICE_NODE_ *psDeviceNode,
                                                       DEVMEM_MEMDESC **ppsMemDesc,
                                                       IMG_UINT32 *pui32SyncAddr,
                                                       IMG_UINT32 *puiSyncPrimBlockSize);
 
/*********************************************************************/ /*!
 @Function        FreeUFOCallback
 @Description   Device specific callback for freeing of an UFO
 
 @Input            psDeviceNode    Pointer to device node that the UFO block was
                               allocated from.
 @Input            psMemDesc        Pointer to pointer for the memdesc of
                               the UFO block to free.
 */
/*********************************************************************/
typedef void (*FreeUFOBlockCallback)(struct _PVRSRV_DEVICE_NODE_ *psDeviceNode,
                                           DEVMEM_MEMDESC *psMemDesc);
 
typedef struct __DUMMY_PAGE__ {
   /*Page handle for the dummy page allocated (UMA/LMA)*/
   PG_HANDLE    sDummyPageHandle;
   POS_LOCK    psDummyPgLock;
   ATOMIC_T    atRefCounter;
   /*Dummy page size in terms of log2 */
   IMG_UINT32    ui32Log2DummyPgSize;
   IMG_UINT64    ui64DummyPgPhysAddr;
#if defined(PDUMP)
#define DUMMY_PAGE    ("DUMMY_PAGE")
   IMG_HANDLE hPdumpDummyPg;
#endif
} PVRSRV_DUMMY_PAGE ;
 
// .CP :
typedef struct _PVRSRV_DEVICE_NODE_ {
   PVRSRV_DEVICE_IDENTIFIER    sDevId;
 
   PVRSRV_DEVICE_STATE            eDevState;
   ATOMIC_T                    eHealthStatus; /* Holds values from PVRSRV_DEVICE_HEALTH_STATUS */
   ATOMIC_T                    eHealthReason; /* Holds values from PVRSRV_DEVICE_HEALTH_REASON */
 
   IMG_HANDLE                    *hDebugTable;
 
   /* device specific MMU attributes */
   MMU_DEVICEATTRIBS            *psMMUDevAttrs;
   /* device specific MMU firmware atrributes, used only in some devices*/
   MMU_DEVICEATTRIBS            *psFirmwareMMUDevAttrs;
 
   /* lock for power state transitions */
   POS_LOCK                    hPowerLock;
   /* current system device power state */
   PVRSRV_SYS_POWER_STATE        eCurrentSysPowerState;
   PVRSRV_POWER_DEV            *psPowerDev;
 
   /*
       callbacks the device must support:
   */
 
   FN_CREATERAMBACKEDPMR pfnCreateRamBackedPMR[PVRSRV_DEVICE_PHYS_HEAP_LAST];
 
   PVRSRV_ERROR (*pfnDevPxAlloc)(struct _PVRSRV_DEVICE_NODE_ *psDevNode, size_t uiSize,
                               PG_HANDLE *psMemHandle, IMG_DEV_PHYADDR *psDevPAddr);
 
   void (*pfnDevPxFree)(struct _PVRSRV_DEVICE_NODE_ *psDevNode, PG_HANDLE *psMemHandle);
 
   PVRSRV_ERROR (*pfnDevPxMap)(struct _PVRSRV_DEVICE_NODE_ *psDevNode, PG_HANDLE *pshMemHandle,
                               size_t uiSize, IMG_DEV_PHYADDR *psDevPAddr,
                               void **pvPtr);
 
   void (*pfnDevPxUnMap)(struct _PVRSRV_DEVICE_NODE_ *psDevNode,
                         PG_HANDLE *psMemHandle, void *pvPtr);
 
   PVRSRV_ERROR (*pfnDevPxClean)(struct _PVRSRV_DEVICE_NODE_ *psDevNode,
                               PG_HANDLE *pshMemHandle,
                               IMG_UINT32 uiOffset,
                               IMG_UINT32 uiLength);
 
   IMG_UINT32 uiMMUPxLog2AllocGran;
 
   void (*pfnMMUCacheInvalidate)(struct _PVRSRV_DEVICE_NODE_ *psDevNode,
                                   IMG_HANDLE hDeviceData,
                                   MMU_LEVEL eLevel,
                                   IMG_BOOL bUnmap);
 
   PVRSRV_ERROR (*pfnMMUCacheInvalidateKick)(struct _PVRSRV_DEVICE_NODE_ *psDevNode,
                                   IMG_UINT32 *pui32NextMMUInvalidateUpdate,
                                   IMG_BOOL bInterrupt);
 
   IMG_UINT32 (*pfnMMUCacheGetInvalidateCounter)(struct _PVRSRV_DEVICE_NODE_ *psDevNode);
 
   void (*pfnDumpDebugInfo)(struct _PVRSRV_DEVICE_NODE_ *psDevNode);
 
   PVRSRV_ERROR (*pfnUpdateHealthStatus)(struct _PVRSRV_DEVICE_NODE_ *psDevNode,
                                   IMG_BOOL bIsTimerPoll);
 
   PVRSRV_ERROR (*pfnResetHWRLogs)(struct _PVRSRV_DEVICE_NODE_ *psDevNode);
 
   /* Method to drain device HWPerf packets from firmware buffer to host buffer */
   PVRSRV_ERROR (*pfnServiceHWPerf)(struct _PVRSRV_DEVICE_NODE_ *psDevNode);
 
   PVRSRV_ERROR (*pfnDeviceVersionString)(struct _PVRSRV_DEVICE_NODE_ *psDevNode, IMG_CHAR **ppszVersionString);
 
   PVRSRV_ERROR (*pfnDeviceClockSpeed)(struct _PVRSRV_DEVICE_NODE_ *psDevNode, IMG_PUINT32 pui32RGXClockSpeed);
 
   PVRSRV_ERROR (*pfnSoftReset)(struct _PVRSRV_DEVICE_NODE_ *psDevNode, IMG_UINT64 ui64ResetValue1, IMG_UINT64 ui64ResetValue2);
 
#if defined(SUPPORT_KERNEL_SRVINIT) && defined(RGXFW_ALIGNCHECKS)
   PVRSRV_ERROR (*pfnAlignmentCheck)(struct _PVRSRV_DEVICE_NODE_ *psDevNode, IMG_UINT32 ui32FWAlignChecksSize, IMG_UINT32 aui32FWAlignChecks[]);
#endif
   IMG_BOOL    (*pfnCheckDeviceFeature)(struct _PVRSRV_DEVICE_NODE_ *psDevNode, IMG_UINT64 ui64FeatureMask);
 
   IMG_INT32    (*pfnGetDeviceFeatureValue)(struct _PVRSRV_DEVICE_NODE_ *psDevNode, IMG_UINT64 ui64FeatureMask);
 
   PVRSRV_DEVICE_CONFIG    *psDevConfig;
 
   /* device post-finalise compatibility check */
   PVRSRV_ERROR            (*pfnInitDeviceCompatCheck)(struct _PVRSRV_DEVICE_NODE_ *);
 
   /* information about the device's address space and heaps */
   DEVICE_MEMORY_INFO        sDevMemoryInfo;
 
   /* device's shared-virtual-memory heap size */
   IMG_UINT64                ui64GeneralSVMHeapSize;
 
   /* private device information */
   void                    *pvDevice;
 
 
 
#if defined(SUPPORT_GPUVIRT_VALIDATION)
   RA_ARENA                *psOSidSubArena[GPUVIRT_VALIDATION_NUM_OS];
#endif
 
 
#define PVRSRV_MAX_RA_NAME_LENGTH (50)
   RA_ARENA                **apsLocalDevMemArenas;
   IMG_CHAR                **apszRANames;
   IMG_UINT32                ui32NumOfLocalMemArenas;
 
#if defined(SUPPORT_PVRSRV_GPUVIRT)
   IMG_CHAR                szKernelFwRAName[RGXFW_NUM_OS][PVRSRV_MAX_RA_NAME_LENGTH];
   RA_ARENA                *psKernelFwMemArena[RGXFW_NUM_OS];
   IMG_UINT32                uiKernelFwRAIdx;
   RA_BASE_T                ui64RABase[RGXFW_NUM_OS];
#endif
 
   IMG_UINT32                ui32RegisteredPhysHeaps;
   PHYS_HEAP                **papsRegisteredPhysHeaps;
 
   /*
    * Pointers to the device's physical memory heap(s)
    * The first entry (apsPhysHeap[PVRSRV_DEVICE_PHYS_HEAP_GPU_LOCAL]) will be used for allocations
    *  where the PVRSRV_MEMALLOCFLAG_CPU_LOCAL flag is not set. Normally this will be an LMA heap
    *  (but the device configuration could specify a UMA heap here, if desired)
    * The second entry (apsPhysHeap[PVRSRV_DEVICE_PHYS_HEAP_CPU_LOCAL]) will be used for allocations
    *  where the PVRSRV_MEMALLOCFLAG_CPU_LOCAL flag is set. Normally this will be a UMA heap
    *  (but the configuration could specify an LMA heap here, if desired)
    * The third entry (apsPhysHeap[PVRSRV_DEVICE_PHYS_HEAP_FW_LOCAL]) will be used for allocations
    *  where the PVRSRV_MEMALLOCFLAG_FW_LOCAL flag is set; this is used when SUPPORT_PVRSRV_GPUVIRT is enabled
    * The device configuration will always specify two physical heap IDs - in the event of the device
    *  only using one physical heap, both of these IDs will be the same, and hence both pointers below
    *  will also be the same; when SUPPORT_PVRSRV_GPUVIRT is enabled the device configuration specifies
    *  three physical heap IDs, the last being for PVRSRV_DEVICE_PHYS_HEAP_FW_LOCAL allocations
    */
   PHYS_HEAP                *apsPhysHeap[PVRSRV_DEVICE_PHYS_HEAP_LAST];
 
   struct _PVRSRV_DEVICE_NODE_    *psNext;
   struct _PVRSRV_DEVICE_NODE_    **ppsThis;
 
   /* Functions for notification about memory contexts */
   PVRSRV_ERROR            (*pfnRegisterMemoryContext)(struct _PVRSRV_DEVICE_NODE_    *psDeviceNode,
                                                       MMU_CONTEXT                    *psMMUContext,
                                                       IMG_HANDLE                    *hPrivData);
   void                    (*pfnUnregisterMemoryContext)(IMG_HANDLE hPrivData);
 
   /* Functions for allocation/freeing of UFOs */
   AllocUFOBlockCallback    pfnAllocUFOBlock;    /*!< Callback for allocation of a block of UFO memory */
   FreeUFOBlockCallback    pfnFreeUFOBlock;    /*!< Callback for freeing of a block of UFO memory */
 
#if defined(SUPPORT_BUFFER_SYNC)
   struct pvr_buffer_sync_context *psBufferSyncContext;
#endif
 
   IMG_HANDLE                hSyncServerNotify;
   POS_LOCK                hSyncServerListLock;
   DLLIST_NODE                sSyncServerSyncsList;
 
#if defined(PVRSRV_ENABLE_FULL_SYNC_TRACKING)
   IMG_HANDLE                hSyncServerRecordNotify;
   POS_LOCK                hSyncServerRecordLock;
   DLLIST_NODE                sSyncServerRecordList;
   struct SYNC_RECORD        *apsSyncServerRecordsFreed[PVRSRV_FULL_SYNC_TRACKING_HISTORY_LEN];
   IMG_UINT32                uiSyncServerRecordFreeIdx;
#endif
 
   PSYNC_PRIM_CONTEXT        hSyncPrimContext;
 
   PVRSRV_CLIENT_SYNC_PRIM    *psSyncPrim;
   /* With this sync-prim we make sure the MMU cache is flushed
    * before we free the page table memory */
   PVRSRV_CLIENT_SYNC_PRIM    *psMMUCacheSyncPrim;
   IMG_UINT32                ui32NextMMUInvalidateUpdate;
 
   IMG_HANDLE                hCmdCompNotify;
   IMG_HANDLE                hDbgReqNotify;
   IMG_HANDLE                hHtbDbgReqNotify;
   IMG_HANDLE                hAppHintDbgReqNotify;
 
   PVRSRV_DUMMY_PAGE        sDummyPage;
 
   DLLIST_NODE                sMemoryContextPageFaultNotifyListHead;
 
#if defined(PDUMP)
   /*     device-level callback which is called when pdump.exe starts.
    *    Should be implemented in device-specific init code, e.g. rgxinit.c
    */
   PVRSRV_ERROR            (*pfnPDumpInitDevice)(struct _PVRSRV_DEVICE_NODE_ *psDeviceNode);
   /* device-level callback to return pdump ID associated to a memory context */
   IMG_UINT32                (*pfnMMUGetContextID)(IMG_HANDLE hDevMemContext);
#endif
} PVRSRV_DEVICE_NODE;
 
/* ---------------------------------------------------------------------------------------------------------
 *  Global Functions' Prototype
 * ---------------------------------------------------------------------------------------------------------
 */
 
 
/* ---------------------------------------------------------------------------------------------------------
 *  Inline Functions Implementation
 * ---------------------------------------------------------------------------------------------------------
 */
 
#ifdef __cplusplus
}
#endif
 
#endif /* __PVRSRV_DEVICE_NODE_H__ */