1 /* * Copyright © 2014 Intel Corporation 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a 4 * copy of this software and associated documentation files (the 5 * "Software"), to deal in the Software without restriction, including 6 * without limitation the rights to use, copy, modify, merge, publish, 7 * distribute, sub license, and/or sell copies of the Software, and to 8 * permit persons to whom the Software is furnished to do so, subject to 9 * the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the 12 * next paragraph) shall be included in all copies or substantial portions 13 * of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 18 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 19 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: 24 * Wei Lin<wei.w.lin@intel.com> 25 * Yuting Yang<yuting.yang@intel.com> 26 */ 27 28 #ifndef __OS_UTIL_DEBUG_H__ 29 #define __OS_UTIL_DEBUG_H__ 30 31 #include "os_defs.h" 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #if GENOS_MESSAGES_ENABLED 38 39 #define GENOS_MAX_SUBCOMPONENT_COUNT 16 40 41 #define GENOS_MAX_MSG_BUF_SIZE 1024 42 43 #define GENOS_MAX_HLT_FILENAME_LEN 260 44 45 typedef enum { 46 GENOS_MESSAGE_LVL_DISABLED = 0, 47 GENOS_MESSAGE_LVL_CRITICAL = 1, 48 GENOS_MESSAGE_LVL_NORMAL = 2, 49 GENOS_MESSAGE_LVL_VERBOSE = 3, 50 GENOS_MESSAGE_LVL_FUNCTION_ENTRY = 4, 51 GENOS_MESSAGE_LVL_FUNCTION_EXIT = 5, 52 GENOS_MESSAGE_LVL_FUNCTION_ENTRY_VERBOSE = 6, 53 GENOS_MESSAGE_LVL_FUNCTION_EXIT_VERBOSE = 7, 54 GENOS_MESSAGE_LVL_COUNT 55 } GENOS_MESSAGE_LEVEL; 56 57 typedef enum { 58 GENOS_COMPONENT_OS, 59 GENOS_COMPONENT_HW, 60 GENOS_COMPONENT_DDI, 61 GENOS_COMPONENT_CM, 62 GENOS_COMPONENT_COUNT 63 } GENOS_COMPONENT_ID; 64 65 extern const PCCHAR GENOS_ComponentName[GENOS_COMPONENT_COUNT]; 66 67 extern const PCCHAR GENOS_LogLevelName[GENOS_MESSAGE_LVL_COUNT]; 68 69 typedef enum { 70 GENOS_SUBCOMP_SELF = 0, 71 GENOS_SUBCOMP_HLT = 1, 72 GENOS_SUBCOMP_COUNT 73 } GENOS_SELF_SUBCOMP_ID; 74 75 typedef enum { 76 GENOS_HW_SUBCOMP_DDI = 0, 77 GENOS_HW_SUBCOMP_HW = 1, 78 GENOS_HW_SUBCOMP_PUBLIC = 2, 79 GENOS_HW_SUBCOMP_COUNT 80 } GENOS_VP_SUBCOMP_ID; 81 82 typedef enum { 83 GENOS_CM_SUBCOMP_DDI = 0, 84 GENOS_CM_SUBCOMP_SELF = 1, 85 GENOS_CM_SUBCOMP_COUNT 86 } GENOS_CM_SUBCOMP_ID; 87 88 typedef enum 89 { 90 GENOS_DDI_SUBCOMP_SELF = 0, 91 GENOS_DDI_SUBCOMP_COUNT 92 } GENOS_DDI_SUBCOMP_ID; 93 94 typedef struct _GENOS_DEBUG_PARAMS { 95 BOOL bAssertEnabled; 96 GENOS_MESSAGE_LEVEL uiMessageLevel; 97 } GENOS_DEBUG_PARAMS; 98 99 typedef struct _GENOS_COMPONENT_DEBUG_PARAMS 100 { 101 GENOS_DEBUG_PARAMS component; 102 BOOL bBySubComponent; 103 GENOS_DEBUG_PARAMS subComponents[GENOS_MAX_SUBCOMPONENT_COUNT]; 104 } GENOS_COMPONENT_DEBUG_PARAMS; 105 106 typedef struct _GENOS_MESSAGE_PARAMS { 107 PFILE pLogFile; 108 PFILE pTraceFile; 109 UINT32 uiCounter; 110 BOOL bUseHybridLogTrace; 111 BOOL bUseOutputDebugString; 112 UINT32 bEnableMaps; 113 GENOS_COMPONENT_DEBUG_PARAMS components[GENOS_COMPONENT_COUNT]; 114 CHAR g_GenOsMsgBuffer[GENOS_MAX_MSG_BUF_SIZE]; 115 } GENOS_MESSAGE_PARAMS; 116 117 VOID GENOS_MessageInit(); 118 119 VOID GENOS_MessageClose(); 120 121 VOID GENOS_HltpPreface(PFILE pFile); 122 123 VOID GENOS_Message(GENOS_MESSAGE_LEVEL level, 124 const PCCHAR logtag, 125 GENOS_COMPONENT_ID compID, 126 UINT8 subCompID, const PCCHAR message, ...); 127 128 VOID GENOS_Message_DDI_Dump(const PCCHAR message, ...); 129 130 GENOS_STATUS GENOS_LogFileNamePrefix(PCHAR fileNamePrefix); 131 132 #ifndef LOG_TAG 133 #define LOG_TAG "IntelGenOs" 134 #endif 135 136 #if USE_PRETTY_FUNCTION 137 138 PCCHAR GENOS_getClassMethod(PCCHAR pcPrettyFunction); 139 140 #define GENOS_FUNCTION GENOS_getClassMethod(__PRETTY_FUNCTION__) 141 142 #else 143 #define GENOS_FUNCTION __FUNCTION__ 144 #endif 145 146 #define GENOS_DEBUGMESSAGE(_level, _compID, _subCompID, _message, ...) \ 147 GENOS_Message(_level, LOG_TAG, _compID, _subCompID, "%s%s - %s:%d: " _message "\n", \ 148 GENOS_ComponentName[_compID], GENOS_LogLevelName[_level], GENOS_FUNCTION, __LINE__, ##__VA_ARGS__) 149 150 #define GENOS_DEBUGMESSAGE_NOLINE(_level, _compID, _subCompID, _message, ...) \ 151 GENOS_Message(_level, LOG_TAG, _compID, _subCompID, "%s%s - %s" _message "\n", \ 152 GENOS_ComponentName[_compID], GENOS_LogLevelName[_level], GENOS_FUNCTION, ##__VA_ARGS__) 153 154 #define GENOS_FUNCTION_ENTER(_compID, _subCompID) \ 155 GENOS_DEBUGMESSAGE_NOLINE(GENOS_MESSAGE_LVL_FUNCTION_ENTRY, _compID, _subCompID, "") 156 157 #define GENOS_FUNCTION_EXIT(_compID, _subCompID, hr) \ 158 GENOS_DEBUGMESSAGE_NOLINE(GENOS_MESSAGE_LVL_FUNCTION_EXIT, _compID, _subCompID, ": hr = 0x%x", hr) 159 160 #define GENOS_FUNCTION_ENTER_VERBOSE(_compID, _subCompID) \ 161 GENOS_DEBUGMESSAGE(GENOS_MESSAGE_LVL_FUNCTION_ENTRY_VERBOSE, _compID, _subCompID, "") 162 163 #define GENOS_FUNCTION_EXIT_VERBOSE(_compID, _subCompID) \ 164 GENOS_DEBUGMESSAGE(GENOS_MESSAGE_LVL_FUNCTION_EXIT_VERBOSE, _compID, _subCompID, "") 165 166 #define GENOS_ASSERTMESSAGE(_compID, _subCompID, _message, ...) \ 167 GENOS_CRITICALMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \ 168 GENOS_ASSERT(_compID, _subCompID, FALSE); 169 170 #define GENOS_NORMALMESSAGE(_compID, _subCompID, _message, ...) \ 171 GENOS_DEBUGMESSAGE(GENOS_MESSAGE_LVL_NORMAL, _compID, _subCompID, _message, ##__VA_ARGS__) 172 173 #define GENOS_VERBOSEMESSAGE(_compID, _subCompID, _message, ...) \ 174 GENOS_DEBUGMESSAGE(GENOS_MESSAGE_LVL_VERBOSE, _compID, _subCompID, _message, ##__VA_ARGS__) 175 176 #define GENOS_CRITICALMESSAGE(_compID, _subCompID, _message, ...) \ 177 GENOS_DEBUGMESSAGE(GENOS_MESSAGE_LVL_CRITICAL, _compID, _subCompID, _message, ##__VA_ARGS__) 178 179 #define GENOS_DEBUGMESSAGE_IF(_cond, _level, _compID, _subCompID, _message, ...) \ 180 if (_cond) \ 181 { \ 182 GENOS_DEBUGMESSAGE(_level, _compID, _subCompID, _message, ##__VA_ARGS__); \ 183 } 184 185 #else 186 187 #define GENOS_MessageInit() 188 #define GENOS_MessageClose() 189 190 #define GENOS_FUNCTION_ENTER(_compID, _subCompID) 191 #define GENOS_FUNCTION_EXIT(_compID, _subCompID, hr) 192 #define GENOS_FUNCTION_ENTER_VERBOSE(_compID, _subCompID) 193 #define GENOS_FUNCTION_EXIT_VERBOSE(_compID, _subCompID) 194 #define GENOS_ASSERTMESSAGE(_compID, _subCompID, _message, ...) 195 #define GENOS_NORMALMESSAGE(_compID, _subCompID, _message, ...) 196 #define GENOS_VERBOSEMESSAGE(_compID, _subCompID, _message, ...) 197 #define GENOS_DEBUGMESSAGE_IF(_cond, _level, _compID, _subCompID, _message, ...) 198 #define GENOS_DEBUGMESSAGE(_compID, _subCompID, _message, ...) 199 200 #endif 201 202 #if GENOS_ASSERT_ENABLED 203 204 #define GENOS_ASSERT(_compID, _subCompID, _expr) \ 205 if(!(_expr)) \ 206 { \ 207 _GENOS_Assert(_compID, _subCompID); \ 208 } 209 210 VOID _GENOS_Assert(GENOS_COMPONENT_ID compID, UINT8 subCompID); 211 212 #else 213 214 #define GENOS_ASSERT(_compID, _subCompID, _expr) 215 216 #endif 217 218 #define GENOS_CHK_STATUS(_compID, _subCompID, _stmt) \ 219 { \ 220 eStatus = (GENOS_STATUS)(_stmt); \ 221 if (eStatus != GENOS_STATUS_SUCCESS) \ 222 { \ 223 GENOS_ASSERTMESSAGE(_compID, _subCompID, "IntelGenOs returned error."); \ 224 goto finish; \ 225 } \ 226 } 227 228 #define GENOS_CHK_STATUS_MESSAGE(_compID, _subCompID, _stmt, _message, ...) \ 229 { \ 230 eStatus = (GENOS_STATUS)(_stmt); \ 231 if (eStatus != GENOS_STATUS_SUCCESS) \ 232 { \ 233 GENOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \ 234 goto finish; \ 235 } \ 236 } 237 238 #define GENOS_CHK_STATUS_SAFE(_stmt) \ 239 { \ 240 eStatus = (GENOS_STATUS)(_stmt); \ 241 if (eStatus != GENOS_STATUS_SUCCESS) \ 242 { \ 243 goto finish; \ 244 } \ 245 } 246 247 #define GENOS_CHK_NULL(_compID, _subCompID, _ptr) \ 248 { \ 249 if ((_ptr) == NULL) \ 250 { \ 251 GENOS_ASSERTMESSAGE(_compID, _subCompID, "Invalid (NULL) Pointer."); \ 252 eStatus = GENOS_STATUS_NULL_POINTER; \ 253 goto finish; \ 254 } \ 255 } 256 257 #define GENOS_CHK_NULL_NO_STATUS(_compID, _subCompID, _ptr) \ 258 { \ 259 if ((_ptr) == NULL) \ 260 { \ 261 GENOS_ASSERTMESSAGE(_compID, _subCompID, "Invalid (NULL) Pointer."); \ 262 goto finish; \ 263 } \ 264 } 265 266 #define GENOS_CHK_HR(_compID, _subCompID, _stmt) \ 267 { \ 268 hr = (_stmt); \ 269 if (hr != S_OK) \ 270 { \ 271 GENOS_ASSERTMESSAGE(_compID, _subCompID, "hr check failed."); \ 272 goto finish; \ 273 } \ 274 } 275 276 #define GENOS_CHK_HR_MESSAGE(_compID, _subCompID, _stmt, _message, ...) \ 277 { \ 278 hr = (_stmt); \ 279 if (hr != S_OK) \ 280 { \ 281 GENOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \ 282 goto finish; \ 283 } \ 284 } 285 286 #define GENOS_CHK_NULL_WITH_HR(_compID, _subCompID, _ptr) \ 287 { \ 288 if ((_ptr) == NULL) \ 289 { \ 290 GENOS_ASSERTMESSAGE(_compID, _subCompID, "Invalid (NULL) Pointer."); \ 291 hr = E_FAIL; \ 292 goto finish; \ 293 } \ 294 } 295 296 #define GENOS_CHECK_CONDITION(_compID, _subCompID, _condition, _str, _ret) \ 297 { \ 298 if (_condition) \ 299 { \ 300 GENOS_ASSERTMESSAGE(_compID, _subCompID, _str); \ 301 return _ret; \ 302 } \ 303 } 304 305 #define GENOS_OS_CHK_STATUS(_stmt) \ 306 GENOS_CHK_STATUS(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _stmt) 307 308 #define GENOS_OS_CHK_NULL(_ptr) \ 309 GENOS_CHK_NULL(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _ptr) 310 311 #define GENOS_OS_CHK_HR(_ptr) \ 312 GENOS_CHK_HR(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _ptr) 313 314 #define GENOS_OS_CHK_HR_MESSAGE(_ptr, _message, ...) \ 315 GENOS_CHK_HR_MESSAGE(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _ptr, _message, ##__VA_ARGS__) 316 317 #define GENOS_OS_CHK_NULL_WITH_HR(_ptr) \ 318 GENOS_CHK_NULL_WITH_HR(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _ptr) 319 320 #define GENOS_OS_CHECK_CONDITION(_condition, _str, _ret) \ 321 GENOS_CHECK_CONDITION(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _condition, _str, _ret) 322 323 #define GENOS_OS_ASSERT(_expr) \ 324 GENOS_ASSERT(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _expr) 325 326 #define GENOS_OS_ASSERTMESSAGE(_message, ...) \ 327 GENOS_ASSERTMESSAGE(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _message, ##__VA_ARGS__) 328 329 #define GENOS_OS_NORMALMESSAGE(_message, ...) \ 330 GENOS_NORMALMESSAGE(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _message, ##__VA_ARGS__) 331 332 #define GENOS_OS_VERBOSEMESSAGE(_message, ...) \ 333 GENOS_VERBOSEMESSAGE(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF, _message, ##__VA_ARGS__) 334 335 #define GENOS_OS_FUNCTION_ENTER \ 336 GENOS_FUNCTION_ENTER(GENOS_COMPONENT_OS, GENOS_SUBCOMP_SELF) 337 338 #ifdef __cplusplus 339 } 340 #endif 341 #endif 342