1 /* 2 * Copyright (c) 2019-2022, 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 mos_util_debug_next.h 24 //! \brief 25 //! \brief Common OS Debug and Print utilities across different platform 26 //! \details Provides assert and print to debug console functionality 27 //! All MOS debug and print utilities will only function in debug or 28 //! release internal drivers, in a release driver they will be NOPs. 29 //! 30 #ifndef __MOS_UTIL_DEBUG_NEXT_H__ 31 #define __MOS_UTIL_DEBUG_NEXT_H__ 32 33 #include "mos_defs.h" 34 #include "mos_util_debug_specific.h" 35 #include "media_user_setting.h" 36 37 class MosUtilDebug 38 { 39 public: 40 MosUtilDebug() = delete; 41 ~MosUtilDebug() = delete; 42 43 #if MOS_MESSAGES_ENABLED 44 //! 45 //! \brief Initialize the MOS message params structure and HLT. 46 //! \details Initialize the MOS message params structure and HLT, 47 //! to be called during device creation 48 //! \param [in] mosCtx 49 //! os device ctx handle 50 //! \return void 51 //! 52 static void MosMessageInit(MediaUserSettingSharedPtr userSettingPtr); 53 54 //! 55 //! \brief Frees the MOS message buffer and MOS message parameters structure 56 //! \details Frees the MOS message buffer and MOS message parameters structure, 57 //! to be called during device destruction 58 //! \return void 59 //! 60 static void MosMessageClose(); 61 62 //! 63 //! \brief Form a string that will prefix MOS's log file name 64 //! \details Form a string that will prefix MOS's log file name 65 //! The default log file location will be under 66 //! %ProgramData%\Intel\Logs or %DriverData%\Intel\Logs 67 //! depending on OS version 68 //! \param PCHAR fileNamePrefix 69 //! [out] Pointer to the string where the prefix is returned 70 //! \param [in] userSettingPtr 71 //! MediaUserSettingSharedPtr 72 //! \return MOS_STATUS 73 //! Returns one of the MOS_STATUS error codes if failed, 74 //! else MOS_STATUS_SUCCESS 75 //! 76 static MOS_STATUS MosLogFileNamePrefix(char *fileNamePrefix, MediaUserSettingSharedPtr userSettingPtr); 77 78 //! 79 //! \brief Enable or disable asserts of a particular component, it is used by ULT also 80 //! \details Enable or disable asserts of a particular component 81 //! \param MOS_COMPONENT_ID compID 82 //! [in] Indicates which component 83 //! \param int32_t bEnable 84 //! [in] Enable/disable flag 85 //! \return void 86 //! 87 static void MosCompAssertEnableDisable(MOS_COMPONENT_ID compID, int32_t bEnable); 88 #endif // MOS_MESSAGES_ENABLED 89 90 #if MOS_ASSERT_ENABLED 91 //! 92 //! \brief MOS assert function for MOS internal use 93 //! \details Halts the cpu in debug mode when expression resolves to zero 94 //! and only if assert enabled for both comp and sub-comp. 95 //! Nop in release version 96 //! Called by MOS_ASSERT macro only 97 //! \param MOS_COMPONENT_ID compID 98 //! [in] Indicates which component 99 //! \param uint8_t subCompID 100 //! [in] Indicates which sub-component 101 //! \return void 102 //! 103 static void MosAssert( 104 MOS_COMPONENT_ID compID, 105 uint8_t subCompID); 106 107 #endif // MOS_ASSERT_ENABLED 108 109 #if MOS_MESSAGES_ENABLED 110 //! 111 //! \brief Checks whether debug messages should be printed. 112 //! \details Determines by the print level, component and sub-component IDs 113 //! whether the debug message should be printed. 114 //! \param MOS_MESSAGE_LEVEL level 115 //! [in] Level of the message 116 //! \param MOS_COMPONENT_ID compID 117 //! [in] Indicates which component 118 //! \param uint8_t subCompID 119 //! [in] Indicates which sub-component 120 //! \param const char *message 121 //! [in] pointer to the message format string 122 //! \return int32_t 123 //! 124 static int32_t MosShouldPrintMessage( 125 MOS_MESSAGE_LEVEL level, 126 MOS_COMPONENT_ID compID, 127 uint8_t subCompID, 128 const char *const message); 129 #endif 130 131 private: 132 133 #if MOS_MESSAGES_ENABLED 134 //! 135 //! \brief Add preface information to the HLT log when initialized 136 //! \details Add preface information to the HLT log when initialized 137 //! Used internally by MOS_HLTInit(). 138 //! \param PFILE pFile 139 //! [out] Pointer to the log file 140 //! \return void 141 //! 142 static void MosHltpPreface( 143 PFILE pFile); 144 145 /*---------------------------------------------------------------------------- 146 | Name : MOS_HltpCopyFile 147 | Purpose : Copy all file content from the source file to the target file. 148 | Arguments : szFileName - source file name to copy from 149 | pFile - target file 150 | Returns : Returns one of the MOS_STATUS error codes if failed, 151 | else MOS_STATUS_SUCCESS 152 | Comments : 153 \---------------------------------------------------------------------------*/ 154 static MOS_STATUS MosHltpCopyFile(PFILE pFile, const PCCHAR szFileName); 155 156 //! 157 //! \brief Set debug message level for a sub-component within a component 158 //! \details Set debug message level for a sub-component within a component 159 //! \param MOS_COMPONENT_ID compID 160 //! [in] Indicates which component 161 //! \param uint8_t subCompID 162 //! [in] Indicates which sub-component 163 //! \param MOS_MESSAGE_LEVEL msgLevel 164 //! [in] Message level that the sub component allows 165 //! \return void 166 //! 167 static void MosSetSubCompMessageLevel(MOS_COMPONENT_ID compID, uint8_t subCompID, MOS_MESSAGE_LEVEL msgLevel); 168 169 //! 170 //! \brief Set debug message level for a particular component 171 //! \details Set debug message level for a particular component 172 //! \param MOS_COMPONENT_ID compID 173 //! [in] Indicates which component 174 //! \param MOS_MESSAGE_LEVEL msgLevel 175 //! [in] Message level that the component allows 176 //! \return void 177 //! 178 static void MosSetCompMessageLevel(MOS_COMPONENT_ID compID, MOS_MESSAGE_LEVEL msgLevel); 179 180 //! 181 //! \brief Set debug message level for all components 182 //! \details Set all component to the same msg level 183 //! \param MOS_MESSAGE_LEVEL msgLevel 184 //! [in] Message level that all components allow 185 //! \return void 186 //! 187 static void MosSetCompMessageLevelAll(MOS_MESSAGE_LEVEL msgLevel); 188 189 //! 190 //! \brief Enable/disable asserts for a sub-component within a component 191 //! \details Enable/disable asserts for a sub-component within a component 192 //! \param MOS_COMPONENT_ID compID 193 //! [in] Indicates which component 194 //! \param uint8_t subCompID 195 //! [in] Indicates which sub-component 196 //! \param int32_t iFlag 197 //! [in] Enable/disable flag 198 //! \return void 199 //! 200 static void MosSubCompAssertEnableDisable(MOS_COMPONENT_ID compID, uint8_t subCompID, int32_t bEnable); 201 202 //! 203 //! \brief Set debug message level and asserts for a component and its sub-components. 204 //! \details Set debug message level and asserts for a component and its sub-components. 205 //! This includes registering all sub-components. 206 //! \param MOS_COMPONENT_ID compID 207 //! [in] Indicates which component 208 //! \param [in] mosCtx 209 //! os device ctx handle 210 //! \return void 211 //! 212 static void MosMessageInitComponent(MOS_COMPONENT_ID compID, MediaUserSettingSharedPtr userSettingPtr); 213 214 //! 215 //! \brief Initialize or refresh the Hybrid Log and Trace facility 216 //! \details Initialize or refresh the Hybrid Log and Trace facility 217 //! Called during MOS init 218 //! \param [in] mosCtx 219 //! os device ctx handle 220 //! \return MOS_STATUS 221 //! Returns one of the MOS_STATUS error codes if failed, 222 //! else MOS_STATUS_SUCCESS 223 //! 224 static MOS_STATUS MosHLTInit( MediaUserSettingSharedPtr userSettingPtr); 225 226 //! 227 //! \brief Close file handles and frees resources 228 //! \details Close file handles and frees resources 229 //! Called during MOS close 230 //! \return void 231 //! 232 static void MosHLTClose(); 233 234 #endif // MOS_MESSAGES_ENABLED 235 236 #if MOS_ASSERT_ENABLED 237 //! 238 //! \brief Checks whether assert should be hit. 239 //! \details Determines by the component and sub-component IDs 240 //! whether an assert should be hit. 241 //! \param MOS_COMPONENT_ID compID 242 //! [in] Indicates which component 243 //! \param uint8_t subCompID 244 //! [in] Indicates which sub-component 245 //! \return int32_t 246 //! 247 static int32_t MosShouldAssert(MOS_COMPONENT_ID compID, uint8_t subCompID); 248 #endif 249 public: 250 #if MOS_MESSAGES_ENABLED 251 252 static const char * const m_mosLogLevelName[MOS_MESSAGE_LVL_COUNT]; 253 static const char * const m_mosComponentName[MOS_COMPONENT_COUNT]; 254 255 //Temporarily defined as the reference to compatible with the cases using uf key to enable/disable APG. 256 static MOS_MESSAGE_PARAMS m_mosMsgParams; 257 #endif 258 259 #if MOS_MESSAGES_ENABLED 260 261 static const char* const m_mosLogPathTemplate; 262 static const char* const m_DdiLogPathTemplate; 263 static const char* m_pcComponentUserFeatureKeys[MOS_COMPONENT_COUNT][3]; 264 static const uint8_t m_subComponentCount[MOS_COMPONENT_COUNT]; 265 static const PCCHAR m_mosUltLogPathPrefix; 266 static const PCCHAR m_mosLogPathPrefix; 267 #endif 268 MEDIA_CLASS_DEFINE_END(MosUtilDebug) 269 }; 270 271 #if MOS_MESSAGES_ENABLED 272 273 class FunctionTrace 274 { 275 public: FunctionTrace(MOS_COMPONENT_ID compID,uint8_t subCompID,const char * name)276 FunctionTrace(MOS_COMPONENT_ID compID, uint8_t subCompID, const char* name) : 277 m_compID(compID), 278 m_subCompID(subCompID), 279 m_name(name) 280 { 281 MOS_VERBOSEMESSAGE(m_compID, m_subCompID, "Enter Function: %s\r\n", m_name); 282 } 283 ~FunctionTrace()284 virtual ~FunctionTrace() 285 { 286 MOS_VERBOSEMESSAGE(m_compID, m_subCompID, "Exit Function: %s\r\n", m_name); 287 } 288 289 protected: 290 MOS_COMPONENT_ID m_compID = MOS_COMPONENT_COUNT; 291 uint8_t m_subCompID = 0; 292 const char *m_name = nullptr; 293 }; 294 295 #define MOS_FUNCTION_TRACE(_compID, _subCompID) FunctionTrace trace(_compID, _subCompID, __FUNCTION__); 296 297 #else 298 299 #define MOS_FUNCTION_TRACE(_compID, _subCompID) 300 301 #endif // #if MOS_MESSAGES_ENABLED 302 #endif // __MOS_UTIL_DEBUG_NEXT_H__ 303