drm/GPU: Add support Imagination PowerVR GPU driver v1.17
[platform/kernel/linux-starfive.git] / drivers / gpu / drm / img / img-rogue / services / server / include / physmem_osmem.h
1 /*************************************************************************/ /*!
2 @File           physmem_osmem.h
3 @Title          OS memory PMR factory API
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Part of Services memory management.  This file defines the
6                 OS memory PMR factory API that must be defined so that the
7                 common & device layer code in the Services Server can allocate
8                 new PMRs back with pages from the OS page allocator. Applicable
9                 for UMA based platforms, such platforms must implement this API
10                 in the OS Porting layer, in the "env" directory for that
11                 system.
12
13 @License        Dual MIT/GPLv2
14
15 The contents of this file are subject to the MIT license as set out below.
16
17 Permission is hereby granted, free of charge, to any person obtaining a copy
18 of this software and associated documentation files (the "Software"), to deal
19 in the Software without restriction, including without limitation the rights
20 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 copies of the Software, and to permit persons to whom the Software is
22 furnished to do so, subject to the following conditions:
23
24 The above copyright notice and this permission notice shall be included in
25 all copies or substantial portions of the Software.
26
27 Alternatively, the contents of this file may be used under the terms of
28 the GNU General Public License Version 2 ("GPL") in which case the provisions
29 of GPL are applicable instead of those above.
30
31 If you wish to allow use of your version of this file only under the terms of
32 GPL, and not to allow others to use your version of this file under the terms
33 of the MIT license, indicate your decision by deleting the provisions above
34 and replace them with the notice and other provisions required by GPL as set
35 out in the file called "GPL-COPYING" included in this distribution. If you do
36 not delete the provisions above, a recipient may use your version of this file
37 under the terms of either the MIT license or GPL.
38
39 This License is also included in this distribution in the file called
40 "MIT-COPYING".
41
42 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
43 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
44 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
45 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
46 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
47 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
48 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49 */ /**************************************************************************/
50
51 #ifndef PHYSMEM_OSMEM_H
52 #define PHYSMEM_OSMEM_H
53
54 /* include/ */
55 #include "img_types.h"
56 #include "pvrsrv_error.h"
57 #include "pvrsrv_memallocflags.h"
58
59 /* services/server/include/ */
60 #include "pmr.h"
61 #include "pmr_impl.h"
62 #include "connection_server.h"
63 #include "physheap.h"
64
65 /*************************************************************************/ /*!
66 @Function       PhysmemNewOSRamBackedPMR
67 @Description    Rogue Services will call this function to allocate GPU device
68                 memory from the PMR factory supported by the OS DDK port. This
69                 factory typically obtains physical memory from the kernel/OS
70                 API that allocates memory from the default heap of shared
71                 system memory available on the platform. The allocated memory
72                 must be page-aligned and be a whole number of pages.
73                 After allocating the required memory, the implementation must
74                 then call PMRCreatePMR() to obtain the PMR structure that
75                 describes this allocation to the upper layers of the Services.
76                 memory management sub-system.
77                 NB. Implementation of this function is mandatory. If shared
78                 system memory is not to be used in the OS port then the
79                 implementation must return PVRSRV_ERROR_NOT_SUPPORTED.
80
81 @Input          psPhysHeap       the phys heap
82 @Input          psConnection     the connection to the originator process
83 @Input          uiSize           the size of the allocation
84                                  (must be a multiple of page size)
85 @Input          uiChunkSize      when sparse allocations are requested,
86                                  this is the allocated chunk size.
87                                  For regular allocations, this will be
88                                  the same as uiSize.
89                                  (must be a multiple of page size)
90 @Input          ui32NumPhysChunks  when sparse allocations are requested,
91                                    this is the number of physical chunks
92                                    to be allocated.
93                                    For regular allocations, this will be 1.
94 @Input          ui32NumVirtChunks  when sparse allocations are requested,
95                                    this is the number of virtual chunks
96                                    covering the sparse allocation.
97                                    For regular allocations, this will be 1.
98 @Input          pui32MappingTable  when sparse allocations are requested,
99                                    this is the list of the indices of
100                                    each physically-backed virtual chunk
101                                    For regular allocations, this will
102                                    be NULL.
103 @Input          uiLog2PageSize   the physical pagesize in log2(bytes).
104 @Input          uiFlags          the allocation flags.
105 @Input          pszAnnotation    string describing the PMR (for debug).
106                                  This should be passed into the function
107                                  PMRCreatePMR().
108 @Input          uiPid            The process ID that this allocation should
109                                  be associated with.
110 @Output         ppsPMROut        pointer to the PMR created for the
111                                  new allocation
112 @Input          ui32PDumpFlags   the pdump flags.
113 @Return         PVRSRV_OK on success, a failure code otherwise.
114 */ /**************************************************************************/
115 PVRSRV_ERROR
116 PhysmemNewOSRamBackedPMR(PHYS_HEAP *psPhysHeap,
117                          CONNECTION_DATA *psConnection,
118                          IMG_DEVMEM_SIZE_T uiSize,
119                          IMG_DEVMEM_SIZE_T uiChunkSize,
120                          IMG_UINT32 ui32NumPhysChunks,
121                          IMG_UINT32 ui32NumVirtChunks,
122                          IMG_UINT32 *pui32MappingTable,
123                          IMG_UINT32 uiLog2PageSize,
124                          PVRSRV_MEMALLOCFLAGS_T uiFlags,
125                          const IMG_CHAR *pszAnnotation,
126                          IMG_PID uiPid,
127                          PMR **ppsPMROut,
128                          IMG_UINT32 ui32PDumpFlags);
129
130 /*************************************************************************/ /*!
131 @Function       PhysmemGetOSRamMemStats
132 @Description    Function that gets the OS memory usage statistics
133 @Input          pvImplData     Physical heap private data.
134 @Output         pui64TotalSize Buffer that holds the total OS memory size
135 @Output         pui64FreeSize  Buffer that holds the free OS memory size
136 @Return         None.
137 */ /**************************************************************************/
138 void PhysmemGetOSRamMemStats(PHEAP_IMPL_DATA pvImplData,
139                             IMG_UINT64 *pui64TotalSize,
140                             IMG_UINT64 *pui64FreeSize);
141
142 #endif /* PHYSMEM_OSMEM_H */