1 /* 2 * Copyright (c) 2018-2021, 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 "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 //! 23 //! \file cm_debug.h 24 //! \brief Contains CM debug definitions 25 //! 26 27 #ifndef __CM_DEBUG_H__ 28 #define __CM_DEBUG_H__ 29 30 #include "cm_common.h" 31 #include "mos_utilities.h" 32 #include "mos_util_debug.h" 33 34 //*----------------------------------------------------------------------------- 35 //| Assert Definitions 36 //*----------------------------------------------------------------------------- 37 #define CM_ASSERT(expr) \ 38 MOS_ASSERT(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_SELF, expr) 39 #define CM_ASSERT_DDI(expr) \ 40 MOS_ASSERT(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_DDI, expr) 41 #define CM_ASSERT_PUBLIC(expr) \ 42 MOS_ASSERT(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_PUBLIC, expr) 43 #define CM_ASSERT_RENDERHAL(expr) \ 44 MOS_ASSERT(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_RENDERHAL, expr) 45 46 //*----------------------------------------------------------------------------- 47 //| Message Print Definitions 48 //*----------------------------------------------------------------------------- 49 #define CM_ASSERTMESSAGE(msg, ...) \ 50 MOS_ASSERTMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_SELF, msg, ##__VA_ARGS__) 51 #define CM_ASSERTMESSAGE_DDI(msg, ...) \ 52 MOS_ASSERTMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_DDI, msg, ##__VA_ARGS__) 53 #define CM_ASSERTMESSAGE_PUBLIC(msg, ...) \ 54 MOS_ASSERTMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_PUBLIC, msg, ##__VA_ARGS__) 55 #define CM_ASSERTMESSAGE_RENDERHAL(msg, ...) \ 56 MOS_ASSERTMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_RENDERHAL, msg, ##__VA_ARGS__) 57 58 #define CM_NORMALMESSAGE(msg, ...) \ 59 MOS_NORMALMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_SELF, msg, ##__VA_ARGS__) 60 #define CM_NORMALMESSAGE_DDI(msg, ...) \ 61 MOS_NORMALMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_DDI, msg, ##__VA_ARGS__) 62 #define CM_NORMALMESSAGE_PUBLIC(msg, ...) \ 63 MOS_NORMALMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_PUBLIC, msg, ##__VA_ARGS__) 64 #define CM_NORMALMESSAGE_RENDERHAL(msg, ...) \ 65 MOS_NORMALMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_RENDERHAL, msg, ##__VA_ARGS__) 66 67 #define CM_FUNCTION_ENTER \ 68 MOS_FUNCTION_ENTER(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_SELF) 69 #define CM_FUNCTION_ENTER_DDI \ 70 MOS_FUNCTION_ENTER(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_DDI) 71 #define CM_FUNCTION_ENTER_PUBLIC \ 72 MOS_FUNCTION_ENTER(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_PUBLIC) 73 #define CM_FUNCTION_ENTER_RENDERHAL \ 74 MOS_FUNCTION_ENTER(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_RENDERHAL) 75 76 77 //*----------------------------------------------------------------------------- 78 //| Private Definitions (not suggest to use in other file) 79 //*----------------------------------------------------------------------------- 80 #define _CHECK_AND_GOTO_FINISH(cond, ret, retval, msg, ...) \ 81 { \ 82 if (cond) \ 83 { \ 84 ret = retval; \ 85 CM_ASSERTMESSAGE(msg, ##__VA_ARGS__); \ 86 goto finish;\ 87 } \ 88 } 89 90 #define _CHECK_AND_RETURN(cond, retval, msg, ...) \ 91 { \ 92 if (cond) \ 93 {\ 94 CM_ASSERTMESSAGE(msg, ##__VA_ARGS__); \ 95 return retval;\ 96 }\ 97 } 98 99 #define _CHECK_AND_RETURN_VOID(cond, msg, ...) \ 100 { \ 101 if(cond) \ 102 { \ 103 CM_ASSERTMESSAGE(msg, ##__VA_ARGS__); \ 104 return; \ 105 } \ 106 } 107 108 #define _MOSSTATUS2CM(mosstatus, cmstatus) \ 109 { \ 110 switch((MOS_STATUS)mosstatus) { \ 111 case MOS_STATUS_SUCCESS: \ 112 cmstatus = CM_SUCCESS; \ 113 break; \ 114 case MOS_STATUS_NULL_POINTER: \ 115 cmstatus = CM_NULL_POINTER; \ 116 break; \ 117 case MOS_STATUS_INVALID_PARAMETER: \ 118 cmstatus = CM_INVALID_ARG_VALUE; \ 119 break; \ 120 case MOS_STATUS_EXCEED_MAX_BB_SIZE: \ 121 cmstatus = CM_TOO_MUCH_THREADS; \ 122 break; \ 123 default: \ 124 cmstatus = (CM_RETURN_CODE)(0 - mosstatus + CM_MOS_STATUS_CONVERTED_CODE_OFFSET); \ 125 break; \ 126 } \ 127 } 128 129 //*----------------------------------------------------------------------------- 130 //| Public Check Definitions 131 //*----------------------------------------------------------------------------- 132 // Check general condition. 133 #define CM_CHK_COND_GOTOFINISH(cond, retval, msg, ...) \ 134 _CHECK_AND_GOTO_FINISH(cond, eStatus, retval, msg, ##__VA_ARGS__) 135 #define CM_CHK_COND_RETURN(cond, retval, msg, ...) \ 136 _CHECK_AND_RETURN(cond, retval, msg, ##__VA_ARGS__) 137 138 // Check nullptr then goto finish. 139 #define CM_CHK_NULL_GOTOFINISH_MOSERROR(ptr) \ 140 _CHECK_AND_GOTO_FINISH((ptr == nullptr), eStatus, MOS_STATUS_NULL_POINTER, "Null pointer found!") 141 #define CM_CHK_NULL_GOTOFINISH_CMERROR(ptr) \ 142 _CHECK_AND_GOTO_FINISH((ptr == nullptr), hr, CM_NULL_POINTER, "Null pointer found!") 143 #define CM_CHK_NULL_GOTOFINISH(ptr, retval) \ 144 _CHECK_AND_GOTO_FINISH((ptr == nullptr), hr, retval, "Null pointer found!") 145 #define CM_CHK_NULL_GOTOFINISH_WITH_MSG(ptr, retval, msg, ...) \ 146 _CHECK_AND_GOTO_FINISH((ptr == nullptr), hr, retval, msg, ##__VA_ARGS__); 147 148 // Check nullptr then return. 149 #define CM_CHK_NULL_RETURN_MOSERROR(ptr) \ 150 _CHECK_AND_RETURN((ptr == nullptr), MOS_STATUS_NULL_POINTER, "Null pointer found!"); 151 #define CM_CHK_NULL_RETURN_CMERROR(ptr) \ 152 _CHECK_AND_RETURN((ptr == nullptr), CM_NULL_POINTER, "Null pointer found!"); 153 #define CM_CHK_NULL_RETURN(ptr, retval) \ 154 _CHECK_AND_RETURN((ptr == nullptr), retval, "Null pointer found!"); 155 #define CM_CHK_NULL_RETURN_WITH_MSG(ptr, retval, msg, ...) \ 156 _CHECK_AND_RETURN((ptr == nullptr), retval, msg, ##__VA_ARGS__); 157 #define CM_CHK_NULL_RETURN_VOID(ptr) \ 158 _CHECK_AND_RETURN_VOID((ptr == nullptr), "Null pointer found!"); 159 160 // Check return status. 161 #define CM_CHK_MOSSTATUS_GOTOFINISH(stmt) \ 162 { \ 163 eStatus = (MOS_STATUS)(stmt); \ 164 _CHECK_AND_GOTO_FINISH((eStatus != MOS_STATUS_SUCCESS), eStatus, eStatus , "MOS return error [%d]", eStatus); \ 165 } 166 #define CM_CHK_MOSSTATUS_RETURN(stmt) \ 167 { \ 168 MOS_STATUS _tmp = (MOS_STATUS)(stmt); \ 169 _CHECK_AND_RETURN((_tmp != MOS_STATUS_SUCCESS), _tmp, "MOS return error [%d]", _tmp) \ 170 } 171 #define CM_CHK_CMSTATUS_GOTOFINISH(stmt) \ 172 { \ 173 hr = (CM_RETURN_CODE)(stmt); \ 174 _CHECK_AND_GOTO_FINISH((hr != CM_SUCCESS), hr, hr, "CM return error [%d]", hr); \ 175 } 176 #define CM_CHK_CMSTATUS_RETURN(stmt) \ 177 { \ 178 CM_RETURN_CODE _tmp = (CM_RETURN_CODE)(stmt); \ 179 _CHECK_AND_RETURN((_tmp != CM_SUCCESS), _tmp, "CM return error [%d]", _tmp) \ 180 } 181 #define CM_CHK_CMSTATUS_GOTOFINISH_WITH_MSG(stmt, msg, ...) \ 182 { \ 183 hr = (CM_RETURN_CODE)(stmt); \ 184 _CHECK_AND_GOTO_FINISH((hr != CM_SUCCESS), hr, hr, msg, ##__VA_ARGS__); \ 185 } 186 #define CM_CHK_CMSTATUS_RETURN_WITH_MSG(stmt, msg, ...) \ 187 { \ 188 CM_RETURN_CODE _tmp = (CM_RETURN_CODE)(stmt); \ 189 _CHECK_AND_RETURN((_tmp != CM_SUCCESS), _tmp, msg, ##__VA_ARGS__) \ 190 } 191 #define CM_CHK_HRESULT_GOTOFINISH_MOSERROR(stmt) \ 192 { \ 193 eStatus = (MOS_STATUS)MosUtilities::OsResultToMOSStatus(stmt); \ 194 _CHECK_AND_GOTO_FINISH((eStatus != MOS_STATUS_SUCCESS), eStatus, eStatus, "hr check failed [%d]", eStatus); \ 195 } 196 #define CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(stmt) \ 197 { \ 198 MOS_STATUS hr_mos = (MOS_STATUS)(stmt); \ 199 _MOSSTATUS2CM(hr_mos, hr); \ 200 _CHECK_AND_GOTO_FINISH((hr_mos != MOS_STATUS_SUCCESS), hr, hr, "MOS return error [%d]", hr_mos); \ 201 } 202 203 #define CMSTATUS2MOS(stmt, hr_mos) \ 204 { \ 205 CM_RETURN_CODE cm_status = (CM_RETURN_CODE)(stmt); \ 206 switch ((CM_RETURN_CODE)cm_status) \ 207 { \ 208 case CM_SUCCESS: \ 209 hr_mos = MOS_STATUS_SUCCESS; \ 210 break; \ 211 case CM_NULL_POINTER: \ 212 hr_mos = MOS_STATUS_NULL_POINTER; \ 213 break; \ 214 case CM_TOO_MUCH_THREADS: \ 215 hr_mos = MOS_STATUS_EXCEED_MAX_BB_SIZE; \ 216 break; \ 217 case CM_INVALID_ARG_VALUE: \ 218 hr_mos = MOS_STATUS_INVALID_PARAMETER; \ 219 break; \ 220 case CM_OUT_OF_HOST_MEMORY: \ 221 hr_mos = MOS_STATUS_NO_SPACE; \ 222 break; \ 223 default: \ 224 hr_mos = MOS_STATUS_UNKNOWN; \ 225 break; \ 226 } \ 227 } 228 229 /*===================== EU Debugger related stuff ===========================*/ 230 231 bool RequestSipBinary(PLATFORM platform, 232 uint32_t bti, 233 const uint8_t *& sip, 234 uint32_t& sipSize, 235 uint32_t& resSize); 236 237 /*===================== end EU Debugger related stuff =======================*/ 238 uint32_t GetLogFileLocation(const char *filename, 239 char fileNamePrefix[], 240 MOS_CONTEXT *mosContext); 241 242 int32_t GetDumpCounter(uint32_t valueID, MOS_CONTEXT *mosContext); 243 244 int32_t RecordDumpCounter(int32_t count, 245 uint32_t ValueID, 246 MOS_CONTEXT *mosContext); 247 248 int32_t GetCommandBufferDumpCounter(uint32_t valueID, MOS_CONTEXT *mosContext); 249 250 int32_t RecordCommandBufferDumpCounter(int32_t count, 251 uint32_t ValueID, 252 MOS_CONTEXT *mosContext); 253 254 int32_t GetSurfaceStateDumpCounter(uint32_t valueID, MOS_CONTEXT *mosContext); 255 256 int32_t RecordSurfaceStateDumpCounter(int32_t count, 257 uint32_t ValueID, 258 MOS_CONTEXT *mosContext); 259 260 int32_t GetInterfaceDescriptorDataDumpCounter(uint32_t valueID, MOS_CONTEXT *mosContext); 261 262 int32_t RecordInterfaceDescriptorDataDumpCounter(int32_t count, 263 uint32_t ValueID, 264 MOS_CONTEXT *mosContext); 265 266 uint32_t GetCommandBufferHeaderDWords(PMOS_INTERFACE osInterface); 267 268 #endif // __CM_DEBUG_H__ 269