1 /*
2  * Copyright � 2014 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *     Wei Lin<wei.w.lin@intel.com>
26  *     Yuting Yang<yuting.yang@intel.com>
27  */
28 #ifndef __OS_DEFS_H__
29 #define __OS_DEFS_H__
30 
31 #define BASIC_TYPES_DEFINED 1
32 #define BOOL_DEF            1
33 
34 #include <stdio.h>
35 
36 #define GENOS_ASSERT_ENABLED   (_DEBUG)
37 
38 #define GENOS_MESSAGES_ENABLED (_DEBUG || GENOS_ASSERT_ENABLED)
39 
40 #include <pthread.h>
41 #include <semaphore.h>
42 
43 #ifndef WINDEF4LINUX_H
44 #define WINDEF4LINUX_H
45 
46 #include <stdint.h>
47 #include <stdbool.h>
48 #include <sys/types.h>
49 
50 typedef int HANDLE;
51 typedef void *HINSTANCE;
52 typedef void *HMODULE;
53 typedef int *PHANDLE;
54 typedef void VOID, *PVOID, *LPVOID;
55 
56 typedef char INT8, *PINT8;
57 typedef char CHAR, *PCHAR, *LPSTR, TCHAR, *LPTSTR;
58 typedef const char *PCSTR, *LPCSTR, *LPCTSTR;
59 typedef unsigned char BYTE, *PBYTE, *LPBYTE;
60 typedef unsigned char UINT8, *PUINT8, UCHAR, *PUCHAR;
61 typedef int16_t INT16, *PINT16, SHORT, *PSHORT;
62 typedef uint16_t UINT16, *PUINT16, WORD, *PWORD, USHORT;
63 
64 typedef int32_t INT, *PINT, INT32, *PINT32;
65 typedef int32_t HRESULT, LSTATUS;
66 typedef uint32_t UINT, *PUINT, UINT32, *PUINT32;
67 typedef uint32_t DWORD, *PDWORD, *LPDWORD;
68 typedef uint32_t BOOL, *PBOOL, BOOLEAN;
69 
70 typedef int32_t LONG, *PLONG;
71 typedef int64_t INT64, *PINT64, LONGLONG, *PLONGLONG;
72 typedef uint32_t ULONG, *PULONG;
73 typedef uint64_t UINT64, *PUINT64, ULONGLONG;
74 typedef uint64_t ULONG64;
75 typedef uint64_t QWORD, *PQWORD;
76 
77 typedef float FLOAT, *PFLOAT;
78 typedef double DOUBLE;
79 
80 typedef size_t SIZE_T;
81 
82 typedef uintptr_t ULONG_PTR;
83 typedef intptr_t INT_PTR;
84 
85 typedef union _LARGE_INTEGER {
86 	struct {
87 		int32_t LowPart;
88 		int32_t HighPart;
89 	} u;
90 	int64_t QuadPart;
91 } LARGE_INTEGER;
92 
93 typedef LARGE_INTEGER *PLARGE_INTEGER;
94 
95 typedef struct tagRECT {
96 	int32_t left;
97 	int32_t top;
98 	int32_t right;
99 	int32_t bottom;
100 } RECT, *PRECT;
101 
102 #define TRUE                    1
103 #define FALSE                   0
104 
105 #define S_OK                    0
106 #define S_FALSE                 1
107 #define E_FAIL                  (0x80004005)
108 #define E_OUTOFMEMORY           (0x8007000E)
109 
110 #define CONST const
111 
112 #define __UNIQUENAME( a1, a2 )  __CONCAT( a1, a2 )
113 #define UNIQUENAME( __text )    __UNIQUENAME( __text, __COUNTER__ )
114 #define STATIC_ASSERT(e)  typedef char UNIQUENAME(STATIC_ASSERT_)[(e)?1:-1]
115 #define C_ASSERT(e) STATIC_ASSERT(e)
116 
117 typedef INT_PTR(*PROC) ();
118 typedef INT_PTR(*FARPROC) ();
119 #endif
120 
121 typedef pthread_mutex_t GENOS_MUTEX, *PGENOS_MUTEX;
122 typedef sem_t GENOS_SEMAPHORE, *PGENOS_SEMAPHORE;
123 typedef pthread_t GENOS_THREADHANDLE;
124 
125 #define INFINITE                0xFFFFFFFF
126 
127 typedef FILE *PFILE;
128 typedef FILE **PPFILE;
129 typedef HMODULE *PHMODULE;
130 typedef const void *PCVOID;
131 typedef void **PPVOID;
132 typedef const char *PCCHAR;
133 typedef char **PPCHAR;
134 
135 #define GENOS_PAGE_SIZE                       4096
136 
137 #define GENOS_PI                              3.14159265358979324f
138 
139 #define GENOS_BYTES_TO_PAGES(_b)              ((_b + GENOS_PAGE_SIZE - 1)/(GENOS_PAGE_SIZE))
140 
141 #define GENOS_PAGES_TO_BYTES(_p)              (_p*GENOS_PAGE_SIZE)
142 
143 #define GENOS_KB_TO_BYTES(_kb)                (_kb*1024)
144 
145 #define GENOS_MB_TO_BYTES(_mb)                (_mb*1024*1024)
146 
147 #define GENOS_IS_ALIGNED(_a, _alignment)      (((_a & (_alignment-1)) == 0) ? 1 : 0)
148 
149 #define GENOS_ALIGN_CEIL(_a, _alignment)      (((_a) + (_alignment-1)) & (~(_alignment-1)))
150 
151 #define GENOS_ALIGN_FLOOR(_a, _alignment)     ((_a) & (~(_alignment-1)))
152 
153 #define GENOS_ROUNDUP_SHIFT(_a, _shift)       (((_a) + (1 << (_shift)) - 1) >> (_shift))
154 
155 #define GENOS_ROUNDUP_DIVIDE(_x, _divide)     (((_x) + (_divide) - 1) / (_divide))
156 
157 #define GENOS_NUMBER_OF_ELEMENTS(_A)          (sizeof(_A) / sizeof((_A)[0]))
158 
159 #define GENOS_MIN(_a, _b)                     (((_a) < (_b)) ? (_a) : (_b))
160 
161 #define GENOS_MIN3(_a, _b, _c)                GENOS_MIN(GENOS_MIN(_a, _b), _c)
162 
163 #define GENOS_MAX(_a, _b)                     (((_a) > (_b)) ? (_a) : (_b))
164 
165 #define GENOS_MAX3(_a, _b, _c)                GENOS_MAX(GENOS_MAX(_a, _b), _c)
166 
167 #define GENOS_MASKBITS32(_low, _high)         ((((((UINT32)1) << (_high+1)) - 1) >> _low) << _low)
168 
169 #define GENOS_MASKBITS64(_low, _high)         ((((((UINT64)1) << (_high+1)) - 1) >> _low) << _low)
170 
171 #define GENOS_BIT_ON(_a, _bit)                ((_a) |= (_bit))
172 
173 #define GENOS_BIT_OFF(_a, _bit)               ((_a) &= ~(_bit))
174 
175 #define GENOS_IS_BIT_SET(_a, _bit)            ((_a) & (_bit))
176 
177 #define GENOS_ABS(_x)                         (((_x) > 0) ? (_x) : -(_x))
178 
179 #define GENOS_WITHIN_RANGE(_x, _min, _max)  (((_x >= _min) && (_x <= _max)) ? (TRUE) : (FALSE))
180 
181 #if defined(_MSC_VER)
182 #define GENOS_ALIGNED(_alignment) __declspec(align(_alignment))
183 #else
184 #define GENOS_ALIGNED(_alignment) __attribute__ ((aligned(_alignment)))
185 #endif
186 
187 typedef enum _GENOS_STATUS {
188 	GENOS_STATUS_SUCCESS = 0,
189 	GENOS_STATUS_NO_SPACE = 1,
190 	GENOS_STATUS_INVALID_PARAMETER = 2,
191 	GENOS_STATUS_INVALID_HANDLE = 3,
192 	GENOS_STATUS_INVALID_FILE_SIZE = 4,
193 	GENOS_STATUS_NULL_POINTER = 5,
194 	GENOS_STATUS_FILE_EXISTS = 6,
195 	GENOS_STATUS_FILE_NOT_FOUND = 7,
196 	GENOS_STATUS_FILE_OPEN_FAILED = 8,
197 	GENOS_STATUS_FILE_READ_ONLY = 9,
198 	GENOS_STATUS_FILE_READ_FAILED = 10,
199 	GENOS_STATUS_FILE_WRITE_FAILED = 11,
200 	GENOS_STATUS_DIR_CREATE_FAILED = 12,
201 	GENOS_STATUS_SET_FILE_POINTER_FAILED = 13,
202 	GENOS_STATUS_LOAD_LIBRARY_FAILED = 14,
203 	GENOS_STATUS_MORE_DATA = 15,
204 	GENOS_STATUS_USER_CONTROL_MAX_NAME_SIZE = 16,
205 	GENOS_STATUS_USER_CONTROL_MIN_DATA_SIZE = 17,
206 	GENOS_STATUS_USER_CONTROL_MAX_DATA_SIZE = 18,
207 	GENOS_STATUS_READ_REGISTRY_FAILED = 19,
208 	GENOS_STATUS_REG_BADKEY = 20,
209 	GENOS_STATUS_REG_BADVALUE = 21,
210 	GENOS_STATUS_REG_NOT_READ = 22,
211 	GENOS_STATUS_REG_NOT_WRITE = 23,
212 	GENOS_STATUS_REG_TYPE_UNKNOWN = 24,
213 	GENOS_STATUS_REG_ITEM_UNKNOWN = 25,
214 	GENOS_STATUS_REG_KEYNAME_NOT_FOUND = 26,
215 	GENOS_STATUS_REG_KEYID_NOT_FOUND = 27,
216 	GENOS_STATUS_EVENT_WAIT_REGISTER_FAILED = 28,
217 	GENOS_STATUS_EVENT_WAIT_UNREGISTER_FAILED = 29,
218 	GENOS_STATUS_REG_KEY_CHANGE_NOTIFY_FAILED = 30,
219 	GENOS_STATUS_HLT_INIT_FAILED = 31,
220 	GENOS_STATUS_UNIMPLEMENTED = 32,
221 	GENOS_STATUS_EXCEED_MAX_BB_SIZE = 33,
222 	GENOS_STATUS_PLATFORM_NOT_SUPPORTED = 34,
223 	GENOS_STATUS_CLIENT_AR_NO_SPACE = 35,
224 	GENOS_STATUS_UNKNOWN = 36
225 } GENOS_STATUS;
226 
227 #define GENOS_SUCCEEDED(_status)                                                               \
228     (_status == GENOS_STATUS_SUCCESS)
229 
230 #define GENOS_FAILED(_status)                                                                 \
231     (_status != GENOS_STATUS_SUCCESS)
232 
233 typedef enum _GENOS_GPU_CONTEXT {
234 	GENOS_GPU_CONTEXT_RENDER = 0,
235 	GENOS_GPU_CONTEXT_RENDER3 = 11,
236 	GENOS_GPU_CONTEXT_RENDER4 = 12,
237 	GENOS_GPU_CONTEXT_MAX,
238 	GENOS_GPU_CONTEXT_INVALID_HANDLE = GENOS_GPU_CONTEXT_MAX
239 } GENOS_GPU_CONTEXT;
240 
241 #endif
242