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 "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 */
73 #error C99 support not set up for this build
76 /* number of bits in the units returned by sizeof */
77 #define IMG_CHAR_BIT CHAR_BIT
79 typedef unsigned int IMG_UINT, *IMG_PUINT;
80 typedef int IMG_INT, *IMG_PINT;
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;
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_FMTSPECX PRIX64
98 #define IMG_UINT64_FMTSPEC PRIu64
100 #define IMG_UINT16_MAX UINT16_MAX
101 #define IMG_UINT32_MAX UINT32_MAX
102 #define IMG_UINT64_MAX UINT64_MAX
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;
109 /* Linux kernel mode does not use floating point */
110 typedef float IMG_FLOAT, *IMG_PFLOAT;
111 typedef double IMG_DOUBLE, *IMG_PDOUBLE;
113 typedef union _IMG_UINT32_FLOAT_
119 typedef int IMG_SECURE_TYPE;
121 typedef enum tag_img_bool
125 IMG_FORCE_ALIGN = 0x7FFFFFFF
126 } IMG_BOOL, *IMG_PBOOL;
127 typedef IMG_BOOL const* IMG_PCBOOL;
129 typedef void IMG_VOID, *IMG_PVOID;
130 typedef IMG_VOID const* IMG_PCVOID;
132 typedef uintptr_t IMG_UINTPTR_T;
133 typedef size_t IMG_SIZE_T;
135 #define IMG_SIZE_T_MAX SIZE_MAX
137 #if defined(_MSC_VER)
138 #define IMG_SIZE_FMTSPEC "%Iu"
139 #define IMG_SIZE_FMTSPECX "%Ix"
141 #define IMG_SIZE_FMTSPEC "%zu"
142 #define IMG_SIZE_FMTSPECX "%zx"
145 typedef IMG_PVOID IMG_HANDLE;
147 #define IMG_NULL NULL
149 #if defined(LINUX) && defined(__KERNEL__)
150 /* prints the function name when used with printk */
151 #define IMG_PFN_FMTSPEC "%pf"
153 #define IMG_PFN_FMTSPEC "%p"
156 /* services/stream ID */
157 typedef IMG_UINT64 IMG_SID;
160 typedef IMG_UINT32 IMG_PID;
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
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.
173 * Different devices could have offset views of the physical address space.
180 * +------------+ +------------+ +------------+ +------------+
181 * | CPU | | DEV | | DEV | | DEV |
182 * +------------+ +------------+ +------------+ +------------+
184 * | PVOID |IMG_DEV_VIRTADDR |IMG_DEV_VIRTADDR |
185 * | \-------------------/ |
187 * +------------+ +------------+ |
189 * +------------+ +------------+ |
193 * +--------+ +---------+ +--------+
194 * | Offset | | (Offset)| | Offset |
195 * +--------+ +---------+ +--------+
196 * | | IMG_DEV_PHYADDR |
198 * | | IMG_DEV_PHYADDR |
199 * +---------------------------------------------------------------------+
200 * | System Address bus |
201 * +---------------------------------------------------------------------+
205 typedef IMG_PVOID IMG_CPU_VIRTADDR;
207 /* device virtual address */
208 typedef struct _IMG_DEV_VIRTADDR
211 #define IMG_CAST_TO_DEVVADDR_UINT(var) (IMG_UINT64)(var)
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;
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
225 /* cpu physical address */
226 typedef struct _IMG_CPU_PHYADDR
228 #if defined(UNDER_WDDM)
229 IMG_UINTPTR_T uiAddr;
230 #define IMG_CAST_TO_CPUPHYADDR_UINT(var) (IMG_UINTPTR_T)(var)
233 #define IMG_CAST_TO_CPUPHYADDR_UINT(var) (IMG_UINT64)(var)
237 /* device physical address */
238 typedef struct _IMG_DEV_PHYADDR
243 /* system physical address */
244 typedef struct _IMG_SYS_PHYADDR
246 #if defined(UNDER_WDDM)
247 IMG_UINTPTR_T uiAddr;
253 /* 32-bit device virtual address (e.g. MSVDX) */
254 typedef struct _IMG_DEV_VIRTADDR32
257 #define IMG_CAST_TO_DEVVADDR_UINT32(var) (IMG_UINT32)(var)
258 } IMG_DEV_VIRTADDR32;
263 typedef struct _IMG_RECT_
271 typedef struct _IMG_RECT_16_
279 #if defined (__cplusplus)
283 #include "img_defs.h"
285 #endif /* __IMG_TYPES_H__ */
286 /******************************************************************************
287 End of file (img_types.h)
288 ******************************************************************************/