RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / include / img_types.h
1 /*************************************************************************/ /*!
2 @File
3 @Title          Global types for use by IMG APIs
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Defines type aliases for use by IMG APIs.
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 #ifndef __IMG_TYPES_H__
45 #define __IMG_TYPES_H__
46 #if defined (__cplusplus)
47 extern "C" {
48 #endif
49
50 /* To use C99 types and definitions, there are two special cases we need to
51  * cater for:
52  *
53  * - Visual Studio: in VS2010 or later, some standard headers are available,
54  *   and MSVC has its own built-in sized types. We can define the C99 types
55  *   in terms of these.
56  *
57  * - Linux kernel code: C99 sized types are defined in <linux/types.h>, but
58  *   some other features (like macros for constants or printf format
59  *   strings) are missing, so we need to fill in the gaps ourselves.
60  *
61  * For other cases (userspace code under Linux, Android or Neutrino, or
62  * firmware code), we can include the standard headers.
63  */
64 #if defined(_MSC_VER)
65         #include "msvc_types.h"
66 #elif defined(LINUX) && defined(__KERNEL__)
67         #include "kernel_types.h"
68 #elif defined(LINUX) || defined(__METAG) || defined(__QNXNTO__)
69         #include <stddef.h>                     /* NULL */
70         #include <inttypes.h>           /* intX_t/uintX_t, format specifiers */
71         #include <limits.h>                     /* INT_MIN, etc */
72 #else
73         #error C99 support not set up for this build
74 #endif
75
76 /* number of bits in the units returned by sizeof */
77 #define IMG_CHAR_BIT CHAR_BIT
78
79 typedef unsigned int    IMG_UINT,       *IMG_PUINT;
80 typedef int                             IMG_INT,        *IMG_PINT;
81
82 typedef uint8_t                 IMG_UINT8,      *IMG_PUINT8;
83 typedef uint8_t                 IMG_BYTE,       *IMG_PBYTE;
84 typedef int8_t                  IMG_INT8,       *IMG_PINT8;
85 typedef char                    IMG_CHAR,       *IMG_PCHAR;
86 typedef IMG_CHAR const                          *IMG_PCCHAR;
87
88 typedef uint16_t                IMG_UINT16,     *IMG_PUINT16;
89 typedef int16_t                 IMG_INT16,      *IMG_PINT16;
90 typedef uint32_t                IMG_UINT32,     *IMG_PUINT32;
91 typedef int32_t                 IMG_INT32,      *IMG_PINT32;
92
93 typedef uint64_t                IMG_UINT64,     *IMG_PUINT64;
94 typedef int64_t                 IMG_INT64,      *IMG_PINT64;
95 #define IMG_INT64_C(c)  INT64_C(c)
96 #define IMG_UINT64_C(c) UINT64_C(c)
97 #define IMG_UINT64_FMTSPECX PRIX64
98 #define IMG_UINT64_FMTSPEC PRIu64
99
100 #define IMG_UINT16_MAX  UINT16_MAX
101 #define IMG_UINT32_MAX  UINT32_MAX
102 #define IMG_UINT64_MAX  UINT64_MAX
103
104 typedef IMG_UINT16 const* IMG_PCUINT16;
105 typedef IMG_INT16 const* IMG_PCINT16;
106 typedef IMG_UINT32 const* IMG_PCUINT32;
107 typedef IMG_INT32 const* IMG_PCINT32;
108
109 /* Linux kernel mode does not use floating point */
110 typedef float                   IMG_FLOAT,      *IMG_PFLOAT;
111 typedef double                  IMG_DOUBLE, *IMG_PDOUBLE;
112
113 typedef union _IMG_UINT32_FLOAT_
114 {
115         IMG_UINT32 ui32;
116         IMG_FLOAT f;
117 } IMG_UINT32_FLOAT;
118
119 typedef int                             IMG_SECURE_TYPE;
120
121 typedef enum tag_img_bool
122 {
123         IMG_FALSE               = 0,
124         IMG_TRUE                = 1,
125         IMG_FORCE_ALIGN = 0x7FFFFFFF
126 } IMG_BOOL, *IMG_PBOOL;
127 typedef IMG_BOOL const* IMG_PCBOOL;
128
129 typedef void            IMG_VOID, *IMG_PVOID;
130 typedef IMG_VOID const* IMG_PCVOID;
131
132 typedef uintptr_t               IMG_UINTPTR_T;
133 typedef size_t                  IMG_SIZE_T;
134
135 #define IMG_SIZE_T_MAX  SIZE_MAX
136
137 #if defined(_MSC_VER)
138 #define IMG_SIZE_FMTSPEC  "%Iu"
139 #define IMG_SIZE_FMTSPECX "%Ix"
140 #else
141 #define IMG_SIZE_FMTSPEC  "%zu"
142 #define IMG_SIZE_FMTSPECX "%zx"
143 #endif
144
145 typedef IMG_PVOID       IMG_HANDLE;
146
147 #define IMG_NULL        NULL
148
149 #if defined(LINUX) && defined(__KERNEL__)
150 /* prints the function name when used with printk */
151 #define IMG_PFN_FMTSPEC "%pf"
152 #else
153 #define IMG_PFN_FMTSPEC "%p"
154 #endif
155
156 /* services/stream ID */
157 typedef IMG_UINT64      IMG_SID;
158
159 /* Process IDs */
160 typedef IMG_UINT32      IMG_PID;
161
162
163 /*
164  * Address types.
165  * All types used to refer to a block of memory are wrapped in structures
166  * to enforce some degree of type safety, i.e. a IMG_DEV_VIRTADDR cannot
167  * be assigned to a variable of type IMG_DEV_PHYADDR because they are not the
168  * same thing.
169  *
170  * There is an assumption that the system contains at most one non-cpu mmu,
171  * and a memory block is only mapped by the MMU once.
172  *
173  * Different devices could have offset views of the physical address space.
174  * 
175  */
176
177
178 /*
179  *
180  * +------------+    +------------+      +------------+        +------------+
181  * |    CPU     |    |    DEV     |      |    DEV     |        |    DEV     |
182  * +------------+    +------------+      +------------+        +------------+
183  *       |                 |                   |                     |
184  *       | PVOID           |IMG_DEV_VIRTADDR   |IMG_DEV_VIRTADDR     |
185  *       |                 \-------------------/                     |
186  *       |                          |                                |
187  * +------------+             +------------+                         |     
188  * |    MMU     |             |    MMU     |                         |
189  * +------------+             +------------+                         | 
190  *       |                          |                                | 
191  *       |                          |                                |
192  *       |                          |                                |
193  *   +--------+                +---------+                      +--------+
194  *   | Offset |                | (Offset)|                      | Offset |
195  *   +--------+                +---------+                      +--------+    
196  *       |                          |                IMG_DEV_PHYADDR | 
197  *       |                          |                                |
198  *       |                          | IMG_DEV_PHYADDR                |
199  * +---------------------------------------------------------------------+ 
200  * |                         System Address bus                          |
201  * +---------------------------------------------------------------------+
202  *
203  */
204
205 typedef IMG_PVOID IMG_CPU_VIRTADDR;
206
207 /* device virtual address */
208 typedef struct _IMG_DEV_VIRTADDR
209 {
210         IMG_UINT64  uiAddr;
211 #define IMG_CAST_TO_DEVVADDR_UINT(var)          (IMG_UINT64)(var)
212         
213 } IMG_DEV_VIRTADDR;
214
215 typedef IMG_UINT64 IMG_DEVMEM_SIZE_T;
216 typedef IMG_UINT64 IMG_DEVMEM_ALIGN_T;
217 typedef IMG_UINT64 IMG_DEVMEM_OFFSET_T;
218 typedef IMG_UINT32 IMG_DEVMEM_LOG2ALIGN_T;
219
220 #define IMG_DEV_VIRTADDR_FMTSPEC "0x%010" IMG_UINT64_FMTSPECX
221 #define IMG_DEVMEM_SIZE_FMTSPEC "0x%010" IMG_UINT64_FMTSPECX
222 #define IMG_DEVMEM_ALIGN_FMTSPEC "0x%010" IMG_UINT64_FMTSPECX
223 #define IMG_DEVMEM_OFFSET_FMTSPEC "0x%010" IMG_UINT64_FMTSPECX
224
225 /* cpu physical address */
226 typedef struct _IMG_CPU_PHYADDR
227 {
228 #if defined(UNDER_WDDM)
229         IMG_UINTPTR_T uiAddr;
230 #define IMG_CAST_TO_CPUPHYADDR_UINT(var)                (IMG_UINTPTR_T)(var)
231 #else
232         IMG_UINT64 uiAddr;
233 #define IMG_CAST_TO_CPUPHYADDR_UINT(var)                (IMG_UINT64)(var)
234 #endif
235 } IMG_CPU_PHYADDR;
236
237 /* device physical address */
238 typedef struct _IMG_DEV_PHYADDR
239 {
240         IMG_UINT64 uiAddr;
241 } IMG_DEV_PHYADDR;
242
243 /* system physical address */
244 typedef struct _IMG_SYS_PHYADDR
245 {
246 #if defined(UNDER_WDDM)
247         IMG_UINTPTR_T uiAddr;
248 #else
249         IMG_UINT64 uiAddr;
250 #endif
251 } IMG_SYS_PHYADDR;
252
253 /* 32-bit device virtual address (e.g. MSVDX) */
254 typedef struct _IMG_DEV_VIRTADDR32
255 {
256         IMG_UINT32 uiAddr;
257 #define IMG_CAST_TO_DEVVADDR_UINT32(var) (IMG_UINT32)(var)
258 } IMG_DEV_VIRTADDR32;
259
260 /*
261         rectangle structure
262 */
263 typedef struct _IMG_RECT_
264 {
265         IMG_INT32       x0;
266         IMG_INT32       y0;
267         IMG_INT32       x1;
268         IMG_INT32       y1;
269 }IMG_RECT;
270
271 typedef struct _IMG_RECT_16_
272 {
273         IMG_INT16       x0;
274         IMG_INT16       y0;
275         IMG_INT16       x1;
276         IMG_INT16       y1;
277 }IMG_RECT_16;
278
279 #if defined (__cplusplus)
280 }
281 #endif
282
283 #include "img_defs.h"
284
285 #endif  /* __IMG_TYPES_H__ */
286 /******************************************************************************
287  End of file (img_types.h)
288 ******************************************************************************/
289