| 1 |
/* |
| 2 |
* Copyright (c) 2018-2025, 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 |
#define CM_WARNINGMESSAGE(msg, ...) \ |
| 58 |
MOS_WARNINGMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_SELF, msg, ##__VA_ARGS__) |
| 59 |
#define CM_WARNINGMESSAGE_DDI(msg, ...) \ |
| 60 |
MOS_WARNINGMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_DDI, msg, ##__VA_ARGS__) |
| 61 |
#define CM_WARNINGMESSAGE_PUBLIC(msg, ...) \ |
| 62 |
MOS_WARNINGMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_PUBLIC, msg, ##__VA_ARGS__) |
| 63 |
#define CM_WARNINGMESSAGE_RENDERHAL(msg, ...) \ |
| 64 |
MOS_WARNINGMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_RENDERHAL, msg, ##__VA_ARGS__) |
| 65 |
#define CM_NORMALMESSAGE(msg, ...) \ |
| 66 |
MOS_NORMALMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_SELF, msg, ##__VA_ARGS__) |
| 67 |
#define CM_NORMALMESSAGE_DDI(msg, ...) \ |
| 68 |
MOS_NORMALMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_DDI, msg, ##__VA_ARGS__) |
| 69 |
#define CM_NORMALMESSAGE_PUBLIC(msg, ...) \ |
| 70 |
MOS_NORMALMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_PUBLIC, msg, ##__VA_ARGS__) |
| 71 |
#define CM_NORMALMESSAGE_RENDERHAL(msg, ...) \ |
| 72 |
MOS_NORMALMESSAGE(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_RENDERHAL, msg, ##__VA_ARGS__) |
| 73 |
|
| 74 |
#define CM_FUNCTION_ENTER \ |
| 75 |
MOS_FUNCTION_ENTER(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_SELF) |
| 76 |
#define CM_FUNCTION_ENTER_DDI \ |
| 77 |
MOS_FUNCTION_ENTER(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_DDI) |
| 78 |
#define CM_FUNCTION_ENTER_PUBLIC \ |
| 79 |
MOS_FUNCTION_ENTER(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_PUBLIC) |
| 80 |
#define CM_FUNCTION_ENTER_RENDERHAL \ |
| 81 |
MOS_FUNCTION_ENTER(MOS_COMPONENT_CM, MOS_CM_SUBCOMP_RENDERHAL) |
| 82 |
|
| 83 |
|
| 84 |
//*----------------------------------------------------------------------------- |
| 85 |
//| Private Definitions (not suggest to use in other file) |
| 86 |
//*----------------------------------------------------------------------------- |
| 87 |
#define _CHECK_AND_GOTO_FINISH(cond, ret, retval, msg, ...) \ |
| 88 |
{ \ |
| 89 |
if (cond) \ |
| 90 |
{ \ |
| 91 |
ret = retval; \ |
| 92 |
CM_ASSERTMESSAGE(msg, ##__VA_ARGS__); \ |
| 93 |
goto finish;\ |
| 94 |
} \ |
| 95 |
} |
| 96 |
|
| 97 |
#define _CHECK_AND_RETURN(cond, retval, msg, ...) \ |
| 98 |
{ \ |
| 99 |
if (cond) \ |
| 100 |
{\ |
| 101 |
CM_ASSERTMESSAGE(msg, ##__VA_ARGS__); \ |
| 102 |
return retval;\ |
| 103 |
}\ |
| 104 |
} |
| 105 |
|
| 106 |
#define _CHECK_AND_RETURN_VOID(cond, msg, ...) \ |
| 107 |
{ \ |
| 108 |
if(cond) \ |
| 109 |
{ \ |
| 110 |
CM_ASSERTMESSAGE(msg, ##__VA_ARGS__); \ |
| 111 |
return; \ |
| 112 |
} \ |
| 113 |
} |
| 114 |
|
| 115 |
#define _MOSSTATUS2CM(mosstatus, cmstatus) \ |
| 116 |
{ \ |
| 117 |
switch((MOS_STATUS)mosstatus) { \ |
| 118 |
case MOS_STATUS_SUCCESS: \ |
| 119 |
cmstatus = CM_SUCCESS; \ |
| 120 |
break; \ |
| 121 |
case MOS_STATUS_NULL_POINTER: \ |
| 122 |
cmstatus = CM_NULL_POINTER; \ |
| 123 |
break; \ |
| 124 |
case MOS_STATUS_INVALID_PARAMETER: \ |
| 125 |
cmstatus = CM_INVALID_ARG_VALUE; \ |
| 126 |
break; \ |
| 127 |
case MOS_STATUS_EXCEED_MAX_BB_SIZE: \ |
| 128 |
cmstatus = CM_TOO_MUCH_THREADS; \ |
| 129 |
break; \ |
| 130 |
default: \ |
| 131 |
cmstatus = (CM_RETURN_CODE)(0 - mosstatus + CM_MOS_STATUS_CONVERTED_CODE_OFFSET); \ |
| 132 |
break; \ |
| 133 |
} \ |
| 134 |
} |
| 135 |
|
| 136 |
//*----------------------------------------------------------------------------- |
| 137 |
//| Public Check Definitions |
| 138 |
//*----------------------------------------------------------------------------- |
| 139 |
// Check general condition. |
| 140 |
#define CM_CHK_COND_GOTOFINISH(cond, retval, msg, ...) \ |
| 141 |
_CHECK_AND_GOTO_FINISH(cond, eStatus, retval, msg, ##__VA_ARGS__) |
| 142 |
#define CM_CHK_COND_RETURN(cond, retval, msg, ...) \ |
| 143 |
_CHECK_AND_RETURN(cond, retval, msg, ##__VA_ARGS__) |
| 144 |
|
| 145 |
// Check nullptr then goto finish. |
| 146 |
#define CM_CHK_NULL_GOTOFINISH_MOSERROR(ptr) \ |
| 147 |
_CHECK_AND_GOTO_FINISH((ptr == nullptr), eStatus, MOS_STATUS_NULL_POINTER, "Null pointer found!") |
| 148 |
#define CM_CHK_NULL_GOTOFINISH_CMERROR(ptr) \ |
| 149 |
_CHECK_AND_GOTO_FINISH((ptr == nullptr), hr, CM_NULL_POINTER, "Null pointer found!") |
| 150 |
#define CM_CHK_NULL_GOTOFINISH(ptr, retval) \ |
| 151 |
_CHECK_AND_GOTO_FINISH((ptr == nullptr), hr, retval, "Null pointer found!") |
| 152 |
#define CM_CHK_NULL_GOTOFINISH_WITH_MSG(ptr, retval, msg, ...) \ |
| 153 |
_CHECK_AND_GOTO_FINISH((ptr == nullptr), hr, retval, msg, ##__VA_ARGS__); |
| 154 |
|
| 155 |
// Check nullptr then return. |
| 156 |
#define CM_CHK_NULL_RETURN_MOSERROR(ptr) \ |
| 157 |
_CHECK_AND_RETURN((ptr == nullptr), MOS_STATUS_NULL_POINTER, "Null pointer found!"); |
| 158 |
#define CM_CHK_NULL_RETURN_CMERROR(ptr) \ |
| 159 |
_CHECK_AND_RETURN((ptr == nullptr), CM_NULL_POINTER, "Null pointer found!"); |
| 160 |
#define CM_CHK_NULL_RETURN(ptr, retval) \ |
| 161 |
_CHECK_AND_RETURN((ptr == nullptr), retval, "Null pointer found!"); |
| 162 |
#define CM_CHK_NULL_RETURN_WITH_MSG(ptr, retval, msg, ...) \ |
| 163 |
_CHECK_AND_RETURN((ptr == nullptr), retval, msg, ##__VA_ARGS__); |
| 164 |
#define CM_CHK_NULL_RETURN_VOID(ptr) \ |
| 165 |
_CHECK_AND_RETURN_VOID((ptr == nullptr), "Null pointer found!"); |
| 166 |
|
| 167 |
// Check return status. |
| 168 |
#define CM_CHK_MOSSTATUS_GOTOFINISH(stmt) \ |
| 169 |
{ \ |
| 170 |
eStatus = (MOS_STATUS)(stmt); \ |
| 171 |
_CHECK_AND_GOTO_FINISH((eStatus != MOS_STATUS_SUCCESS), eStatus, eStatus , "MOS return error [%d]", eStatus); \ |
| 172 |
} |
| 173 |
#define CM_CHK_MOSSTATUS_RETURN(stmt) \ |
| 174 |
{ \ |
| 175 |
MOS_STATUS _tmp = (MOS_STATUS)(stmt); \ |
| 176 |
_CHECK_AND_RETURN((_tmp != MOS_STATUS_SUCCESS), _tmp, "MOS return error [%d]", _tmp) \ |
| 177 |
} |
| 178 |
#define CM_CHK_CMSTATUS_GOTOFINISH(stmt) \ |
| 179 |
{ \ |
| 180 |
hr = (CM_RETURN_CODE)(stmt); \ |
| 181 |
_CHECK_AND_GOTO_FINISH((hr != CM_SUCCESS), hr, hr, "CM return error [%d]", hr); \ |
| 182 |
} |
| 183 |
#define CM_CHK_CMSTATUS_RETURN(stmt) \ |
| 184 |
{ \ |
| 185 |
CM_RETURN_CODE _tmp = (CM_RETURN_CODE)(stmt); \ |
| 186 |
_CHECK_AND_RETURN((_tmp != CM_SUCCESS), _tmp, "CM return error [%d]", _tmp) \ |
| 187 |
} |
| 188 |
#define CM_CHK_CMSTATUS_GOTOFINISH_WITH_MSG(stmt, msg, ...) \ |
| 189 |
{ \ |
| 190 |
hr = (CM_RETURN_CODE)(stmt); \ |
| 191 |
_CHECK_AND_GOTO_FINISH((hr != CM_SUCCESS), hr, hr, msg, ##__VA_ARGS__); \ |
| 192 |
} |
| 193 |
#define CM_CHK_CMSTATUS_RETURN_WITH_MSG(stmt, msg, ...) \ |
| 194 |
{ \ |
| 195 |
CM_RETURN_CODE _tmp = (CM_RETURN_CODE)(stmt); \ |
| 196 |
_CHECK_AND_RETURN((_tmp != CM_SUCCESS), _tmp, msg, ##__VA_ARGS__) \ |
| 197 |
} |
| 198 |
#define CM_CHK_HRESULT_GOTOFINISH_MOSERROR(stmt) \ |
| 199 |
{ \ |
| 200 |
eStatus = (MOS_STATUS)MosUtilities::OsResultToMOSStatus(stmt); \ |
| 201 |
_CHECK_AND_GOTO_FINISH((eStatus != MOS_STATUS_SUCCESS), eStatus, eStatus, "hr check failed [%d]", eStatus); \ |
| 202 |
} |
| 203 |
#define CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(stmt) \ |
| 204 |
{ \ |
| 205 |
MOS_STATUS hr_mos = (MOS_STATUS)(stmt); \ |
| 206 |
_MOSSTATUS2CM(hr_mos, hr); \ |
| 207 |
_CHECK_AND_GOTO_FINISH((hr_mos != MOS_STATUS_SUCCESS), hr, hr, "MOS return error [%d]", hr_mos); \ |
| 208 |
} |
| 209 |
|
| 210 |
#define CMSTATUS2MOS(stmt, hr_mos) \ |
| 211 |
{ \ |
| 212 |
CM_RETURN_CODE cm_status = (CM_RETURN_CODE)(stmt); \ |
| 213 |
switch ((CM_RETURN_CODE)cm_status) \ |
| 214 |
{ \ |
| 215 |
case CM_SUCCESS: \ |
| 216 |
hr_mos = MOS_STATUS_SUCCESS; \ |
| 217 |
break; \ |
| 218 |
case CM_NULL_POINTER: \ |
| 219 |
hr_mos = MOS_STATUS_NULL_POINTER; \ |
| 220 |
break; \ |
| 221 |
case CM_TOO_MUCH_THREADS: \ |
| 222 |
hr_mos = MOS_STATUS_EXCEED_MAX_BB_SIZE; \ |
| 223 |
break; \ |
| 224 |
case CM_INVALID_ARG_VALUE: \ |
| 225 |
hr_mos = MOS_STATUS_INVALID_PARAMETER; \ |
| 226 |
break; \ |
| 227 |
case CM_OUT_OF_HOST_MEMORY: \ |
| 228 |
hr_mos = MOS_STATUS_NO_SPACE; \ |
| 229 |
break; \ |
| 230 |
default: \ |
| 231 |
hr_mos = MOS_STATUS_UNKNOWN; \ |
| 232 |
break; \ |
| 233 |
} \ |
| 234 |
} |
| 235 |
|
| 236 |
/*===================== EU Debugger related stuff ===========================*/ |
| 237 |
|
| 238 |
bool RequestSipBinary(PLATFORM platform, |
| 239 |
uint32_t bti, |
| 240 |
const uint8_t *& sip, |
| 241 |
uint32_t& sipSize, |
| 242 |
uint32_t& resSize); |
| 243 |
|
| 244 |
/*===================== end EU Debugger related stuff =======================*/ |
| 245 |
uint32_t GetLogFileLocation(const char *filename, |
| 246 |
char fileNamePrefix[], |
| 247 |
MOS_CONTEXT *mosContext); |
| 248 |
|
| 249 |
int32_t GetDumpCounter(uint32_t valueID, MOS_CONTEXT *mosContext); |
| 250 |
|
| 251 |
int32_t RecordDumpCounter(int32_t count, |
| 252 |
uint32_t ValueID, |
| 253 |
MOS_CONTEXT *mosContext); |
| 254 |
|
| 255 |
int32_t GetCommandBufferDumpCounter(uint32_t valueID, MOS_CONTEXT *mosContext); |
| 256 |
|
| 257 |
int32_t RecordCommandBufferDumpCounter(int32_t count, |
| 258 |
uint32_t ValueID, |
| 259 |
MOS_CONTEXT *mosContext); |
| 260 |
|
| 261 |
int32_t GetSurfaceStateDumpCounter(uint32_t valueID, MOS_CONTEXT *mosContext); |
| 262 |
|
| 263 |
int32_t RecordSurfaceStateDumpCounter(int32_t count, |
| 264 |
uint32_t ValueID, |
| 265 |
MOS_CONTEXT *mosContext); |
| 266 |
|
| 267 |
int32_t GetInterfaceDescriptorDataDumpCounter(uint32_t valueID, MOS_CONTEXT *mosContext); |
| 268 |
|
| 269 |
int32_t RecordInterfaceDescriptorDataDumpCounter(int32_t count, |
| 270 |
uint32_t ValueID, |
| 271 |
MOS_CONTEXT *mosContext); |
| 272 |
|
| 273 |
uint32_t GetCommandBufferHeaderDWords(PMOS_INTERFACE osInterface); |
| 274 |
|
| 275 |
#endif // __CM_DEBUG_H__ |