RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / physheap.h
1 /*************************************************************************/ /*!
2 @File
3 @Title          Physical heap management header
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Defines the interface for the physical heap management
6 @License        Dual MIT/GPLv2
7
8 The contents of this file are subject to the MIT license as set out below.
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
23
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
31
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
34
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
43
44 #include "img_types.h"
45 #include "pvrsrv_error.h"
46 #include "pvrsrv_memallocflags.h"
47
48 #ifndef _PHYSHEAP_H_
49 #define _PHYSHEAP_H_
50
51 typedef struct _PHYS_HEAP_ PHYS_HEAP;
52
53 typedef void (*CpuPAddrToDevPAddr)(IMG_HANDLE hPrivData,
54                                                                    IMG_UINT32 ui32NumOfAddr,
55                                                                    IMG_DEV_PHYADDR *psDevPAddr,
56                                                                    IMG_CPU_PHYADDR *psCpuPAddr);
57
58 typedef void (*DevPAddrToCpuPAddr)(IMG_HANDLE hPrivData,
59                                                                    IMG_UINT32 ui32NumOfAddr,
60                                                                    IMG_CPU_PHYADDR *psCpuPAddr,
61                                                                    IMG_DEV_PHYADDR *psDevPAddr);
62
63 typedef IMG_UINT32 (*GetRegionId)(IMG_HANDLE hPrivData,
64                                                                    PVRSRV_MEMALLOCFLAGS_T uiAllocationFlags);
65
66 typedef struct _PHYS_HEAP_FUNCTIONS_
67 {
68         /*! Translate CPU physical address to device physical address */
69         CpuPAddrToDevPAddr      pfnCpuPAddrToDevPAddr;
70         /*! Translate device physical address to CPU physical address */
71         DevPAddrToCpuPAddr      pfnDevPAddrToCpuPAddr;
72         /*! Return id of heap region to allocate from */
73         GetRegionId                     pfnGetRegionId;
74 } PHYS_HEAP_FUNCTIONS;
75
76 typedef enum _PHYS_HEAP_TYPE_
77 {
78         PHYS_HEAP_TYPE_UNKNOWN = 0,
79         PHYS_HEAP_TYPE_UMA,
80         PHYS_HEAP_TYPE_LMA,
81 #if defined(SUPPORT_PVRSRV_GPUVIRT)
82         PHYS_HEAP_TYPE_DMA,
83 #endif
84 } PHYS_HEAP_TYPE;
85
86 typedef struct _PHYS_HEAP_REGION_
87 {
88         IMG_CPU_PHYADDR                 sStartAddr;
89         IMG_DEV_PHYADDR                 sCardBase;
90         IMG_UINT64                              uiSize;
91 #if defined(SUPPORT_PVRSRV_GPUVIRT)
92         IMG_HANDLE                              hPrivData;
93         IMG_BOOL                                bDynAlloc;
94 #endif
95 } PHYS_HEAP_REGION;
96
97 typedef struct _PHYS_HEAP_CONFIG_
98 {
99         IMG_UINT32                              ui32PhysHeapID;
100         PHYS_HEAP_TYPE                  eType;
101         IMG_CHAR                                *pszPDumpMemspaceName;
102         PHYS_HEAP_FUNCTIONS             *psMemFuncs;
103
104         PHYS_HEAP_REGION                *pasRegions;
105         IMG_UINT32                              ui32NumOfRegions;
106
107         IMG_HANDLE                              hPrivData;
108 } PHYS_HEAP_CONFIG;
109
110 PVRSRV_ERROR PhysHeapRegister(PHYS_HEAP_CONFIG *psConfig,
111                                                           PHYS_HEAP **ppsPhysHeap);
112
113 void PhysHeapUnregister(PHYS_HEAP *psPhysHeap);
114
115 PVRSRV_ERROR PhysHeapAcquire(IMG_UINT32 ui32PhysHeapID,
116                                                          PHYS_HEAP **ppsPhysHeap);
117
118 void PhysHeapRelease(PHYS_HEAP *psPhysHeap);
119
120 PHYS_HEAP_TYPE PhysHeapGetType(PHYS_HEAP *psPhysHeap);
121
122 PVRSRV_ERROR PhysHeapRegionGetCpuPAddr(PHYS_HEAP *psPhysHeap,
123                                                                            IMG_UINT32 ui32RegionId,
124                                                                 IMG_CPU_PHYADDR *psCpuPAddr);
125
126
127 PVRSRV_ERROR PhysHeapRegionGetSize(PHYS_HEAP *psPhysHeap,
128                                                         IMG_UINT32 ui32RegionId,
129                                                      IMG_UINT64 *puiSize);
130
131 PVRSRV_ERROR PhysHeapRegionGetDevPAddr(PHYS_HEAP *psPhysHeap,
132                                                                            IMG_UINT32 ui32RegionId,
133                                                                            IMG_DEV_PHYADDR *psDevPAddr);
134
135 PVRSRV_ERROR PhysHeapRegionGetSize(PHYS_HEAP *psPhysHeap,
136                                                                    IMG_UINT32 ui32RegionId,
137                                                            IMG_UINT64 *puiSize);
138
139 IMG_UINT32 PhysHeapNumberOfRegions(PHYS_HEAP *psPhysHeap);
140
141 void PhysHeapCpuPAddrToDevPAddr(PHYS_HEAP *psPhysHeap,
142                                                                 IMG_UINT32 ui32NumOfAddr,
143                                                                 IMG_DEV_PHYADDR *psDevPAddr,
144                                                                 IMG_CPU_PHYADDR *psCpuPAddr);
145
146 void PhysHeapDevPAddrToCpuPAddr(PHYS_HEAP *psPhysHeap,
147                                                                 IMG_UINT32 ui32NumOfAddr,
148                                                                 IMG_CPU_PHYADDR *psCpuPAddr,
149                                                                 IMG_DEV_PHYADDR *psDevPAddr);
150
151 IMG_UINT32 PhysHeapGetRegionId(PHYS_HEAP *psPhysHeap,
152                                                 PVRSRV_MEMALLOCFLAGS_T uiAllocFlags);
153
154
155 IMG_CHAR *PhysHeapPDumpMemspaceName(PHYS_HEAP *psPhysHeap);
156
157 PVRSRV_ERROR PhysHeapInit(void);
158 PVRSRV_ERROR PhysHeapDeinit(void);
159
160 #endif /* _PHYSHEAP_H_ */