1 /*************************************************************************/ /*!
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
8 The contents of this file are subject to the MIT license as set out below.
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:
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
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.
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.
32 This License is also included in this distribution in the file called
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 */ /**************************************************************************/
44 #ifndef __IMG_TYPES_H__
45 #define __IMG_TYPES_H__
46 #if defined (__cplusplus)
50 /* To use C99 types and definitions, there are two special cases we need to
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
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.
61 * For other cases (userspace code under Linux, Android or Neutrino, or
62 * firmware code), we can include the standard headers.
65 #include "msvc_types.h"
66 #elif defined(LINUX) && defined(__KERNEL__)
67 #include <linux/types.h>
68 #include "kernel_types.h"
69 #elif defined(LINUX) || defined(__METAG) || defined(__QNXNTO__) || defined(INTEGRITY_OS)
70 #include <stddef.h> /* NULL */
71 #include <inttypes.h> /* intX_t/uintX_t, format specifiers */
72 #include <limits.h> /* INT_MIN, etc */
74 #include <stddef.h> /* NULL */
75 #include <inttypes.h> /* intX_t/uintX_t, format specifiers */
77 #error C99 support not set up for this build
80 typedef unsigned int IMG_UINT, *IMG_PUINT;
81 typedef int IMG_INT, *IMG_PINT;
83 typedef uint8_t IMG_UINT8, *IMG_PUINT8;
84 typedef uint8_t IMG_BYTE, *IMG_PBYTE;
85 typedef int8_t IMG_INT8, *IMG_PINT8;
86 typedef char IMG_CHAR, *IMG_PCHAR;
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;
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_FMTSPEC PRIu64
98 #define IMG_UINT64_FMTSPECX PRIX64
99 #define IMG_UINT64_FMTSPECx PRIx64
100 #define IMG_UINT64_FMTSPECo PRIo64
101 #define IMG_INT64_FMTSPECd PRId64
103 #define IMG_UINT16_MAX UINT16_MAX
104 #define IMG_UINT32_MAX UINT32_MAX
105 #define IMG_UINT64_MAX UINT64_MAX
107 #define IMG_INT16_MAX INT16_MAX
108 #define IMG_INT32_MAX INT32_MAX
109 #define IMG_INT64_MAX INT64_MAX
111 /* Linux kernel mode does not use floating point */
112 typedef float IMG_FLOAT, *IMG_PFLOAT;
113 typedef double IMG_DOUBLE, *IMG_PDOUBLE;
115 typedef union _IMG_UINT32_FLOAT_
121 typedef int IMG_SECURE_TYPE;
123 typedef enum tag_img_bool
127 IMG_FORCE_ALIGN = 0x7FFFFFFF
128 } IMG_BOOL, *IMG_PBOOL;
130 #if defined(UNDER_WDDM) || defined(WINDOWS_WDF)
131 typedef void IMG_VOID, *IMG_PVOID;
133 typedef uintptr_t IMG_UINTPTR_T;
134 typedef size_t IMG_SIZE_T;
136 #define IMG_SIZE_T_MAX SIZE_MAX
137 #define IMG_NULL NULL
139 typedef IMG_CHAR const* IMG_PCCHAR;
142 #if defined(_MSC_VER)
143 #define IMG_SIZE_FMTSPEC "%Iu"
144 #define IMG_SIZE_FMTSPECX "%Ix"
146 #define IMG_SIZE_FMTSPEC "%zu"
147 #define IMG_SIZE_FMTSPECX "%zx"
150 #if defined(LINUX) && defined(__KERNEL__)
151 /* prints the function name when used with printk */
152 #define IMG_PFN_FMTSPEC "%pf"
154 #define IMG_PFN_FMTSPEC "%p"
157 typedef void *IMG_HANDLE;
159 /* services/stream ID */
160 typedef IMG_UINT64 IMG_SID;
163 typedef IMG_UINT32 IMG_PID;
165 /* OS connection type */
166 typedef int IMG_OS_CONNECTION;
171 * All types used to refer to a block of memory are wrapped in structures
172 * to enforce some degree of type safety, i.e. a IMG_DEV_VIRTADDR cannot
173 * be assigned to a variable of type IMG_DEV_PHYADDR because they are not the
176 * There is an assumption that the system contains at most one non-cpu mmu,
177 * and a memory block is only mapped by the MMU once.
179 * Different devices could have offset views of the physical address space.
186 * +------------+ +------------+ +------------+ +------------+
187 * | CPU | | DEV | | DEV | | DEV |
188 * +------------+ +------------+ +------------+ +------------+
190 * | void * |IMG_DEV_VIRTADDR |IMG_DEV_VIRTADDR |
191 * | \-------------------/ |
193 * +------------+ +------------+ |
195 * +------------+ +------------+ |
199 * +--------+ +---------+ +--------+
200 * | Offset | | (Offset)| | Offset |
201 * +--------+ +---------+ +--------+
202 * | | IMG_DEV_PHYADDR |
204 * | | IMG_DEV_PHYADDR |
205 * +---------------------------------------------------------------------+
206 * | System Address bus |
207 * +---------------------------------------------------------------------+
211 #define IMG_DEV_VIRTADDR_FMTSPEC "0x%010" IMG_UINT64_FMTSPECX
212 #define IMG_DEVMEM_SIZE_FMTSPEC "0x%010" IMG_UINT64_FMTSPECX
213 #define IMG_DEVMEM_ALIGN_FMTSPEC "0x%010" IMG_UINT64_FMTSPECX
214 #define IMG_DEVMEM_OFFSET_FMTSPEC "0x%010" IMG_UINT64_FMTSPECX
216 /* cpu physical address */
217 typedef struct _IMG_CPU_PHYADDR
219 #if defined(UNDER_WDDM) || defined(WINDOWS_WDF)
221 #define IMG_CAST_TO_CPUPHYADDR_UINT(var) (uintptr_t)(var)
222 #elif defined(LINUX) && defined(__KERNEL__)
224 #define IMG_CAST_TO_CPUPHYADDR_UINT(var) (phys_addr_t)(var)
227 #define IMG_CAST_TO_CPUPHYADDR_UINT(var) (IMG_UINT64)(var)
231 /* device physical address */
232 typedef struct _IMG_DEV_PHYADDR
237 /* system physical address */
238 typedef struct _IMG_SYS_PHYADDR
240 #if defined(UNDER_WDDM) || defined(WINDOWS_WDF)
247 /* 32-bit device virtual address (e.g. MSVDX) */
248 typedef struct _IMG_DEV_VIRTADDR32
251 #define IMG_CAST_TO_DEVVADDR_UINT32(var) (IMG_UINT32)(var)
252 } IMG_DEV_VIRTADDR32;
257 typedef struct _IMG_RECT_
263 }IMG_RECT, *PIMG_RECT;
265 typedef struct _IMG_RECT_16_
271 }IMG_RECT_16, *PIMG_RECT_16;
273 typedef struct _IMG_RECT_32_
279 } IMG_RECT_F32, *PIMG_RECT_F32;
284 typedef struct _IMG_BOX_
292 } IMG_BOX, *PIMG_BOX;
294 #if defined (__cplusplus)
298 #include "img_defs.h"
300 #endif /* __IMG_TYPES_H__ */
301 /******************************************************************************
302 End of file (img_types.h)
303 ******************************************************************************/