Merge tag 'v4.4-rc6'
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue / 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 /* number of bits in the units returned by sizeof */
50 #define IMG_CHAR_BIT 8
51
52 /* define all address space bit depths: */
53 /* CPU virtual address space defaults to 32bits */
54 #if !defined(IMG_ADDRSPACE_CPUVADDR_BITS)
55 #define IMG_ADDRSPACE_CPUVADDR_BITS             32
56 #endif
57
58 typedef unsigned int    IMG_UINT,       *IMG_PUINT;
59 typedef signed int              IMG_INT,        *IMG_PINT;
60
61 typedef unsigned char   IMG_UINT8,      *IMG_PUINT8;
62 typedef unsigned char   IMG_BYTE,       *IMG_PBYTE;
63 typedef signed char             IMG_INT8,       *IMG_PINT8;
64 typedef char                    IMG_CHAR,       *IMG_PCHAR;
65 typedef IMG_CHAR const                          *IMG_PCCHAR;
66
67 typedef unsigned short  IMG_UINT16,     *IMG_PUINT16;
68 typedef signed short    IMG_INT16,      *IMG_PINT16;
69 typedef unsigned int    IMG_UINT32,     *IMG_PUINT32;
70 typedef signed int              IMG_INT32,      *IMG_PINT32;
71 #if !defined(IMG_UINT32_MAX)
72         #define IMG_UINT32_MAX 0xFFFFFFFFUL
73 #endif
74 #if !defined(IMG_UINT16_MAX)
75         #define IMG_UINT16_MAX 0xFFFFU
76 #endif
77
78 typedef IMG_UINT16 const* IMG_PCUINT16;
79 typedef IMG_INT16 const* IMG_PCINT16;
80 typedef IMG_UINT32 const* IMG_PCUINT32;
81 typedef IMG_INT32 const* IMG_PCINT32;
82
83 #if defined(_WIN32)
84
85 typedef unsigned __int64        IMG_UINT64, *IMG_PUINT64;
86 typedef __int64                 IMG_INT64,  *IMG_PINT64;
87 #define IMG_INT64_C(c)  c ## LL
88 #define IMG_UINT64_C(c) c ## ULL
89 #if defined(_MSC_VER)
90 #define strtoll         _strtoi64
91 #endif
92
93 #else
94         #if defined(LINUX) || defined(__METAG) || defined(__QNXNTO__)
95                 typedef unsigned long long              IMG_UINT64,     *IMG_PUINT64;
96                 typedef long long                               IMG_INT64,      *IMG_PINT64;
97                 #define IMG_INT64_C(c)  c ## LL
98                 #define IMG_UINT64_C(c) c ## ULL
99         #else
100                 #error("define an OS")
101         #endif
102 #endif
103 #if !defined(IMG_UINT64_MAX)
104         #define IMG_UINT64_MAX 0xFFFFFFFFFFFFFFFFULL
105 #endif
106
107 #if !(defined(LINUX) && defined (__KERNEL__))
108 /* Linux kernel mode does not use floating point */
109 typedef float                   IMG_FLOAT,      *IMG_PFLOAT;
110 typedef double                  IMG_DOUBLE, *IMG_PDOUBLE;
111
112 typedef union _IMG_UINT32_FLOAT_
113 {
114         IMG_UINT32 ui32;
115         IMG_FLOAT f;
116 } IMG_UINT32_FLOAT;
117
118 #endif
119
120 typedef int                             IMG_SECURE_TYPE;
121
122 typedef enum tag_img_bool
123 {
124         IMG_FALSE               = 0,
125         IMG_TRUE                = 1,
126         IMG_FORCE_ALIGN = 0x7FFFFFFF
127 } IMG_BOOL, *IMG_PBOOL;
128 typedef IMG_BOOL const* IMG_PCBOOL;
129
130 typedef void            IMG_VOID, *IMG_PVOID;
131 typedef IMG_VOID const* IMG_PCVOID;
132
133 /* Figure out which headers to include to get uintptr_t. */
134 #if !defined(_MSC_VER) && !defined(__KERNEL__)
135 /* MSVC before VS2010 doesn't have <stdint.h>, but it has uintptr_t in
136    <stddef.h>. */
137 #include <stdint.h>
138 #endif
139 #if defined(__QNXNTO__)
140 #include <stdint.h>
141 #endif
142 #if defined(LINUX) && defined (__KERNEL__)
143 #include <linux/types.h>
144 #endif
145 #include <stddef.h>
146
147 typedef uintptr_t               IMG_UINTPTR_T;
148 typedef size_t                  IMG_SIZE_T;
149
150 #define IMG_SIZE_T_MAX ((IMG_SIZE_T) -1)
151
152 #if defined(_MSC_VER)
153 #define IMG_SIZE_FMTSPEC  "%Iu"
154 #define IMG_SIZE_FMTSPECX "%Ix"
155 #else
156 #define IMG_SIZE_FMTSPEC  "%zu"
157 #define IMG_SIZE_FMTSPECX "%zx"
158 #endif
159
160 typedef IMG_PVOID       IMG_HANDLE;
161
162 #define IMG_NULL        NULL
163
164 /* services/stream ID */
165 typedef IMG_UINT64      IMG_SID;
166
167 /* Process IDs */
168 typedef IMG_UINT32      IMG_PID;
169
170
171 /*
172  * Address types.
173  * All types used to refer to a block of memory are wrapped in structures
174  * to enforce some degree of type safety, i.e. a IMG_DEV_VIRTADDR cannot
175  * be assigned to a variable of type IMG_DEV_PHYADDR because they are not the
176  * same thing.
177  *
178  * There is an assumption that the system contains at most one non-cpu mmu,
179  * and a memory block is only mapped by the MMU once.
180  *
181  * Different devices could have offset views of the physical address space.
182  * 
183  */
184
185
186 /*
187  *
188  * +------------+    +------------+      +------------+        +------------+
189  * |    CPU     |    |    DEV     |      |    DEV     |        |    DEV     |
190  * +------------+    +------------+      +------------+        +------------+
191  *       |                 |                   |                     |
192  *       | PVOID           |IMG_DEV_VIRTADDR   |IMG_DEV_VIRTADDR     |
193  *       |                 \-------------------/                     |
194  *       |                          |                                |
195  * +------------+             +------------+                         |     
196  * |    MMU     |             |    MMU     |                         |
197  * +------------+             +------------+                         | 
198  *       |                          |                                | 
199  *       |                          |                                |
200  *       |                          |                                |
201  *   +--------+                +---------+                      +--------+
202  *   | Offset |                | (Offset)|                      | Offset |
203  *   +--------+                +---------+                      +--------+    
204  *       |                          |                IMG_DEV_PHYADDR | 
205  *       |                          |                                |
206  *       |                          | IMG_DEV_PHYADDR                |
207  * +---------------------------------------------------------------------+ 
208  * |                         System Address bus                          |
209  * +---------------------------------------------------------------------+
210  *
211  */
212
213 typedef IMG_PVOID IMG_CPU_VIRTADDR;
214
215 /* device virtual address */
216 typedef struct _IMG_DEV_VIRTADDR
217 {
218         IMG_UINT64  uiAddr;
219 #define IMG_CAST_TO_DEVVADDR_UINT(var)          (IMG_UINT64)(var)
220         
221 } IMG_DEV_VIRTADDR;
222
223 typedef IMG_UINT64 IMG_DEVMEM_SIZE_T;
224 typedef IMG_UINT64 IMG_DEVMEM_ALIGN_T;
225 typedef IMG_UINT64 IMG_DEVMEM_OFFSET_T;
226 typedef IMG_UINT32 IMG_DEVMEM_LOG2ALIGN_T;
227
228 #define IMG_DEV_VIRTADDR_FMTSPEC "0x%010llX"
229 #define IMG_DEVMEM_SIZE_FMTSPEC "0x%010llX"
230 #define IMG_DEVMEM_ALIGN_FMTSPEC "0x%010llX"
231 #define IMG_DEVMEM_OFFSET_FMTSPEC "0x%010llX"
232
233 /* cpu physical address */
234 typedef struct _IMG_CPU_PHYADDR
235 {
236 #if defined(UNDER_WDDM)
237         IMG_UINTPTR_T uiAddr;
238 #define IMG_CAST_TO_CPUPHYADDR_UINT(var)                (IMG_UINTPTR_T)(var)
239 #else
240         IMG_UINT64 uiAddr;
241 #define IMG_CAST_TO_CPUPHYADDR_UINT(var)                (IMG_UINT64)(var)
242 #endif
243 } IMG_CPU_PHYADDR;
244
245 /* device physical address */
246 typedef struct _IMG_DEV_PHYADDR
247 {
248         IMG_UINT64 uiAddr;
249 } IMG_DEV_PHYADDR;
250
251 /* system physical address */
252 typedef struct _IMG_SYS_PHYADDR
253 {
254 #if defined(UNDER_WDDM)
255         IMG_UINTPTR_T uiAddr;
256 #else
257         IMG_UINT64 uiAddr;
258 #endif
259 } IMG_SYS_PHYADDR;
260
261 /*
262         rectangle structure
263 */
264 typedef struct _IMG_RECT_
265 {
266         IMG_INT32       x0;
267         IMG_INT32       y0;
268         IMG_INT32       x1;
269         IMG_INT32       y1;
270 }IMG_RECT;
271
272 typedef struct _IMG_RECT_16_
273 {
274         IMG_INT16       x0;
275         IMG_INT16       y0;
276         IMG_INT16       x1;
277         IMG_INT16       y1;
278 }IMG_RECT_16;
279
280 #if defined (__cplusplus)
281 }
282 #endif
283
284 #include "img_defs.h"
285
286 #endif  /* __IMG_TYPES_H__ */
287 /******************************************************************************
288  End of file (img_types.h)
289 ******************************************************************************/
290