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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
/**************************************************************************/ /*!
@File
@Title          Implementation Callbacks for Physmem (PMR) abstraction
@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description    Part of the memory management.  This file is for definitions
                that are private to the world of PMRs, but that need to be
                shared between pmr.c itself and the modules that implement the
                callbacks for the PMR.
@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 _SRVSRV_PMR_IMPL_H_
#define _SRVSRV_PMR_IMPL_H_
 
/* include/ */
#include "powervr/mem_types.h"
#include "pvrsrv_memallocflags.h"
#include "img_types.h"
#include "pvrsrv_error.h"
 
typedef struct _PMR_ PMR;
/* stuff that per-flavour callbacks need to share with pmr.c */
typedef void *PMR_IMPL_PRIVDATA;
 
typedef PVRSRV_MEMALLOCFLAGS_T PMR_FLAGS_T;
typedef struct _PMR_MAPPING_TABLE_ PMR_MAPPING_TABLE;
typedef void *PMR_MMAP_DATA;
 
/**
 *  Which PMR factory has created this PMR?
 */
typedef enum _PMR_IMPL_TYPE_
{
   PMR_TYPE_NONE = 0,
   PMR_TYPE_OSMEM,
   PMR_TYPE_LMA,
   PMR_TYPE_DMABUF,
   PMR_TYPE_EXTMEM,
   PMR_TYPE_DC,
   PMR_TYPE_TDFWCODE,
   PMR_TYPE_TDSECBUF
} PMR_IMPL_TYPE;
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_LOCK_PHYS_ADDRESSES_FN
 
@Description    Called to lock down the physical addresses for all pages
                allocated for a PMR.
                The default implementation is to simply increment a
                lock-count for debugging purposes.
                If overridden, the PFN_LOCK_PHYS_ADDRESSES_FN function will
                be called when someone first requires a physical address,
                and the PFN_UNLOCK_PHYS_ADDRESSES_FN counterpart will be
                called when the last such reference is released.
                The PMR implementation may assume that physical addresses
                will have been "locked" in this manner before any call is
                made to the pfnDevPhysAddr() callback
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
 
@Return         PVRSRV_OK if the operation was successful, an error code
                otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_LOCK_PHYS_ADDRESSES_FN)(PMR_IMPL_PRIVDATA pvPriv);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_UNLOCK_PHYS_ADDRESSES_FN
 
@Description    Called to release the lock taken on the physical addresses
                for all pages allocated for a PMR.
                The default implementation is to simply decrement a
                lock-count for debugging purposes.
                If overridden, the PFN_UNLOCK_PHYS_ADDRESSES_FN will be
                called when the last reference taken on the PMR is
                released.
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
 
@Return         PVRSRV_OK if the operation was successful, an error code
                otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_UNLOCK_PHYS_ADDRESSES_FN)(PMR_IMPL_PRIVDATA pvPriv);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_DEV_PHYS_ADDR_FN
 
@Description    Called to obtain one or more physical addresses for given
                offsets within a PMR.
 
                The PFN_LOCK_PHYS_ADDRESSES_FN callback (if overridden) is
                guaranteed to have been called prior to calling the
                PFN_DEV_PHYS_ADDR_FN callback and the caller promises not to
                rely on the physical address thus obtained after the
                PFN_UNLOCK_PHYS_ADDRESSES_FN callback is called.
 
   Implementation of this callback is mandatory.
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
@Input          ui32Log2PageSize          The log2 page size.
@Input          ui32NumOfAddr             The number of addresses to be
                                          returned
@Input          puiOffset                 The offset from the start of the
                                          PMR (in bytes) for which the
                                          physical address is required.
                                          Where multiple addresses are
                                          requested, this will contain a
                                          list of offsets.
@Output         pbValid                   List of boolean flags indicating
                                          which addresses in the returned
                                          list (psDevAddrPtr) are valid
                                          (for sparse allocations, not all
                                          pages may have a physical backing)
@Output         psDevAddrPtr              Returned list of physical addresses
 
@Return         PVRSRV_OK if the operation was successful, an error code
                otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_DEV_PHYS_ADDR_FN)(PMR_IMPL_PRIVDATA pvPriv,
                      IMG_UINT32 ui32Log2PageSize,
                      IMG_UINT32 ui32NumOfAddr,
                      IMG_DEVMEM_OFFSET_T *puiOffset,
                      IMG_BOOL *pbValid,
                      IMG_DEV_PHYADDR *psDevAddrPtr);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_ACQUIRE_KERNEL_MAPPING_DATA_FN
 
@Description    Called to obtain a kernel-accessible address (mapped to a
                virtual address if required) for the PMR for use internally
                in Services.
 
    Implementation of this function for the (default) PMR factory providing
    OS-allocations is mandatory (the driver will expect to be able to call
    this function for OS-provided allocations).
    For other PMR factories, implementation of this function is only necessary
    where an MMU mapping is required for the Kernel to be able to access the
    allocated memory.
    If no mapping is needed, this function can remain unimplemented and the
    pfn may be set to NULL.
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
@Input          uiOffset                  Offset from the beginning of
                                          the PMR at which mapping is to
                                          start
@Input          uiSize                    Size of mapping (in bytes)
@Output         ppvKernelAddressOut       Mapped kernel address
@Output         phHandleOut                  Returned handle of the new mapping
@Input          ulFlags                   Mapping flags
 
@Return         PVRSRV_OK if the mapping was successful, an error code
                otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_ACQUIRE_KERNEL_MAPPING_DATA_FN)(PMR_IMPL_PRIVDATA pvPriv,
                      size_t uiOffset,
                      size_t uiSize,
                      void **ppvKernelAddressOut,
                      IMG_HANDLE *phHandleOut,
                      PMR_FLAGS_T ulFlags);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_RELEASE_KERNEL_MAPPING_DATA_FN
 
@Description    Called to release a mapped kernel virtual address
 
   Implementation of this callback is mandatory if PFN_ACQUIRE_KERNEL_MAPPING_DATA_FN
   is provided for the PMR factory, otherwise this function can remain unimplemented
   and the pfn may be set to NULL.
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
@Input          hHandle                   Handle of the mapping to be
                                          released
 
@Return         None
*/
/*****************************************************************************/
typedef void (*PFN_RELEASE_KERNEL_MAPPING_DATA_FN)(PMR_IMPL_PRIVDATA pvPriv,
              IMG_HANDLE hHandle);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_READ_BYTES_FN
 
@Description    Called to read bytes from an unmapped allocation
 
   Implementation of this callback is optional -
   where it is not provided, the driver will use PFN_ACQUIRE_KERNEL_MAPPING_DATA_FN
   to map the entire PMR (if an MMU mapping is required for the Kernel to be
   able to access the allocated memory).
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
@Input          uiOffset                  Offset from the beginning of
                                          the PMR at which to begin
                                          reading
@Output         pcBuffer                  Buffer in which to return the
                                          read data
@Input          uiBufSz                   Number of bytes to be read
@Output         puiNumBytes               Number of bytes actually read
                                          (may be less than uiBufSz)
 
@Return         PVRSRV_OK if the read was successful, an error code
                otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_READ_BYTES_FN)(PMR_IMPL_PRIVDATA pvPriv,
                      IMG_DEVMEM_OFFSET_T uiOffset,
                      IMG_UINT8 *pcBuffer,
                      size_t uiBufSz,
                      size_t *puiNumBytes);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_WRITE_BYTES_FN
 
@Description    Called to write bytes into an unmapped allocation
 
   Implementation of this callback is optional -
   where it is not provided, the driver will use PFN_ACQUIRE_KERNEL_MAPPING_DATA_FN
   to map the entire PMR (if an MMU mapping is required for the Kernel to be
   able to access the allocated memory).
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
@Input          uiOffset                  Offset from the beginning of
                                          the PMR at which to begin
                                          writing
@Input          pcBuffer                  Buffer containing the data to be
                                          written
@Input          uiBufSz                   Number of bytes to be written
@Output         puiNumBytes               Number of bytes actually written
                                          (may be less than uiBufSz)
 
@Return         PVRSRV_OK if the write was successful, an error code
                otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_WRITE_BYTES_FN)(PMR_IMPL_PRIVDATA pvPriv,
                      IMG_DEVMEM_OFFSET_T uiOffset,
                      IMG_UINT8 *pcBuffer,
                      size_t uiBufSz,
                      size_t *puiNumBytes);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_UNPIN_MEM_FN
 
@Description    Called to unpin an allocation.
                Once unpinned, the pages backing the allocation may be
                re-used by the Operating System for another purpose.
                When the pages are required again, they may be re-pinned
                (by calling PFN_PIN_MEM_FN). The driver will try to return
                same pages as before. The caller will be told if the
                content of these returned pages has been modified or if
                the pages returned are not the original pages.
 
   Implementation of this callback is optional.
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
 
@Return         PVRSRV_OK if the unpin was successful, an error code
                otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_UNPIN_MEM_FN)(PMR_IMPL_PRIVDATA pPriv);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_PIN_MEM_FN
 
@Description    Called to pin a previously unpinned allocation.
                The driver will try to return same pages as were previously
                assigned to the allocation. The caller will be told if the
                content of these returned pages has been modified or if
                the pages returned are not the original pages.
 
   Implementation of this callback is optional.
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
 
@Input          psMappingTable            Mapping table, which describes how
                                          virtual 'chunks' are to be mapped to
                                          physical 'chunks' for the allocation.
 
@Return         PVRSRV_OK if the original pages were returned unmodified.
                PVRSRV_ERROR_PMR_NEW_MEMORY if the memory returned was modified
                or different pages were returned.
                Another PVRSRV_ERROR code on failure.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_PIN_MEM_FN)(PMR_IMPL_PRIVDATA pPriv,
                      PMR_MAPPING_TABLE *psMappingTable);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_CHANGE_SPARSE_MEM_FN
 
@Description    Called to modify the physical backing for a given sparse
                allocation.
                The caller provides a list of the pages within the sparse
                allocation which should be backed with a physical allocation
                and a list of the pages which do not require backing.
 
                Implementation of this callback is mandatory.
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
@Input          psPMR                     The PMR of the sparse allocation
                                          to be modified
@Input          ui32AllocPageCount        The number of pages specified in
                                          pai32AllocIndices
@Input          pai32AllocIndices         The list of pages in the sparse
                                          allocation that should be backed
                                          with a physical allocation. Pages
                                          are referenced by their index
                                          within the sparse allocation
                                          (e.g. in a 10 page allocation, pages
                                          are denoted by indices 0 to 9)
@Input          ui32FreePageCount         The number of pages specified in
                                          pai32FreeIndices
@Input          pai32FreeIndices          The list of pages in the sparse
                                          allocation that do not require
                                          a physical allocation.
@Input          ui32Flags                 Allocation flags
 
@Return         PVRSRV_OK if the sparse allocation physical backing was updated
                successfully, an error code otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_CHANGE_SPARSE_MEM_FN)(PMR_IMPL_PRIVDATA pPriv,
                      const PMR *psPMR,
                      IMG_UINT32 ui32AllocPageCount,
                      IMG_UINT32 *pai32AllocIndices,
                      IMG_UINT32 ui32FreePageCount,
                      IMG_UINT32 *pai32FreeIndices,
                      IMG_UINT32 uiFlags);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_CHANGE_SPARSE_MEM_CPU_MAP_FN
 
@Description    Called to modify which pages are mapped for a given sparse
                allocation.
                The caller provides a list of the pages within the sparse
                allocation which should be given a CPU mapping and a list
                of the pages which do not require a CPU mapping.
 
   Implementation of this callback is mandatory.
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
@Input          psPMR                     The PMR of the sparse allocation
                                          to be modified
@Input          sCpuVAddrBase             The virtual base address of the
                                          sparse allocation
@Input          ui32AllocPageCount        The number of pages specified in
                                          pai32AllocIndices
@Input          pai32AllocIndices         The list of pages in the sparse
                                          allocation that should be given
                                          a CPU mapping. Pages are referenced
                                          by their index within the sparse
                                          allocation (e.g. in a 10 page
                                          allocation, pages are denoted by
                                          indices 0 to 9)
@Input          ui32FreePageCount         The number of pages specified in
                                          pai32FreeIndices
@Input          pai32FreeIndices          The list of pages in the sparse
                                          allocation that do not require a CPU
                                          mapping.
 
@Return         PVRSRV_OK if the page mappings were updated successfully, an
                error code otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_CHANGE_SPARSE_MEM_CPU_MAP_FN)(PMR_IMPL_PRIVDATA pPriv,
                      const PMR *psPMR,
                      IMG_UINT64 sCpuVAddrBase,
                      IMG_UINT32 ui32AllocPageCount,
                      IMG_UINT32 *pai32AllocIndices,
                      IMG_UINT32 ui32FreePageCount,
                      IMG_UINT32 *pai32FreeIndices);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_MMAP_FN
 
@Description    Called to map pages in the specified PMR.
 
   Implementation of this callback is optional.
   Where it is provided, it will be used in place of OSMMapPMRGeneric().
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
@Input          psPMR                     The PMR of the allocation to be
                                          mapped
@Input          pMMapData                 OS-specific data to describe how
                                          mapping should be performed
 
@Return         PVRSRV_OK if the mapping was successful, an error code
                otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_MMAP_FN)(PMR_IMPL_PRIVDATA pPriv,
                                    PMR *psPMR,
                                    PMR_MMAP_DATA pMMapData);
 
/*************************************************************************/ /*!
@Brief          Callback function type PFN_FINALIZE_FN
 
@Description    Called to destroy the PMR.
                This callback will be called only when all references to
                the PMR have been dropped.
                The PMR was created via a call to PhysmemNewRamBackedPMR()
                and is destroyed via this callback.
 
   Implementation of this callback is mandatory.
 
@Input          pvPriv                    Private data (which was generated
                                          by the PMR factory when PMR was
                                          created)
 
@Return         PVRSRV_OK if the PMR destruction was successful, an error
                code otherwise.
*/
/*****************************************************************************/
typedef PVRSRV_ERROR (*PFN_FINALIZE_FN)(PMR_IMPL_PRIVDATA pvPriv);
 
#if 1
struct _PMR_IMPL_FUNCTAB_ {
#else
typedef struct _PMR_IMPL_FUNCTAB_ {
#endif
    PFN_LOCK_PHYS_ADDRESSES_FN pfnLockPhysAddresses;
    PFN_UNLOCK_PHYS_ADDRESSES_FN pfnUnlockPhysAddresses;
 
    PFN_DEV_PHYS_ADDR_FN pfnDevPhysAddr;
 
    PFN_ACQUIRE_KERNEL_MAPPING_DATA_FN pfnAcquireKernelMappingData;
    PFN_RELEASE_KERNEL_MAPPING_DATA_FN pfnReleaseKernelMappingData;
 
#if defined (INTEGRITY_OS)
    /*
     * MapMemoryObject()/UnmapMemoryObject()
     *
     * called to map/unmap memory objects in Integrity OS
     */
 
    PVRSRV_ERROR (*pfnMapMemoryObject)(PMR_IMPL_PRIVDATA pvPriv,
                                                IMG_HANDLE *phMemObj);
    PVRSRV_ERROR (*pfnUnmapMemoryObject)(PMR_IMPL_PRIVDATA pvPriv);
   
#if defined(USING_HYPERVISOR)
    IMG_HANDLE (*pfnGetPmr)(PMR_IMPL_PRIVDATA pvPriv, size_t ulOffset);
#endif
#endif
    
    PFN_READ_BYTES_FN pfnReadBytes;
    PFN_WRITE_BYTES_FN pfnWriteBytes;
 
    PFN_UNPIN_MEM_FN pfnUnpinMem;
    PFN_PIN_MEM_FN pfnPinMem;
 
    PFN_CHANGE_SPARSE_MEM_FN pfnChangeSparseMem;
    PFN_CHANGE_SPARSE_MEM_CPU_MAP_FN pfnChangeSparseMemCPUMap;
 
    PFN_MMAP_FN pfnMMap;
 
    PFN_FINALIZE_FN pfnFinalize;
} ;
typedef struct _PMR_IMPL_FUNCTAB_ PMR_IMPL_FUNCTAB;
 
 
#endif /* of #ifndef _SRVSRV_PMR_IMPL_H_ */