Debian Codegraph @

media_softlet/agnostic/common/os/mos_util_debug.h

raw
1 /*
2 * Copyright (c) 2019-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 mos_util_debug.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_H__
31 #define __MOS_UTIL_DEBUG_H__
32 #include <memory>
33 #include "mos_defs.h"
34 #include "mos_os_trace_event.h"
35 #include "media_class_trace.h"
36 #include "mos_oca_util_debug.h"
37
38 #if MOS_MESSAGES_ENABLED
39
40 //!
41 //! \brief Max number or sub-components per debug component
42 //!
43 #define MOS_MAX_SUBCOMPONENT_COUNT 20
44
45 //!
46 //! \brief Mos message max buffer size
47 //!
48 #define MOS_MAX_MSG_BUF_SIZE 1024
49
50 //!
51 //! \brief Max length of HLT file name
52 //!
53 #define MOS_MAX_HLT_FILENAME_LEN 260
54
55 //!
56 //! \brief Define MOS Sub-Component IDs
57 //!
58 typedef enum
59 {
60 MOS_SUBCOMP_SELF = 0,
61 MOS_SUBCOMP_HLT = 1,
62 MOS_SUBCOMP_CODEC = 2,
63 MOS_SUBCOMP_VP = 3,
64 MOS_SUBCOMP_CP = 4,
65 MOS_SUBCOMP_EXT = 5,
66 MOS_SUBCOMP_COUNT
67 } MOS_SELF_SUBCOMP_ID;
68
69 //!
70 //! \brief Define MHW Sub-Component IDs
71 //!
72 typedef enum
73 {
74 MOS_HW_SUBCOMP_ALL = 0,
75 MOS_HW_SUBCOMP_COUNT
76 } MOS_HW_SUBCOMP_ID;
77
78 // Define CodecHal Sub-Component IDs
79 typedef enum
80 {
81 MOS_CODEC_SUBCOMP_DDI = 0, // DDI files.
82 MOS_CODEC_SUBCOMP_DECODE = 1, // Decoders
83 MOS_CODEC_SUBCOMP_ENCODE = 2, // Encoders
84 MOS_CODEC_SUBCOMP_HW = 3, // HW interface
85 MOS_CODEC_SUBCOMP_PUBLIC = 4, // Public interface
86 MOS_CODEC_SUBCOMP_DEBUG = 5, // Debug interface
87 MOS_CODEC_SUBCOMP_CENC = 6, // CencDecoders
88 MOS_CODEC_SUBCOMP_COUNT // Must be last in the list
89 } MOS_CODEC_SUBCOMP_ID;
90
91 // Define VpHal Sub-Component IDs
92 typedef enum
93 {
94 MOS_VP_SUBCOMP_DDI = 0, // DDI files.
95 MOS_VP_SUBCOMP_HW = 1, // HW interface
96 MOS_VP_SUBCOMP_PUBLIC = 2, // Public interface
97 MOS_VP_SUBCOMP_DEBUG = 3, // Debug interface
98 MOS_VP_SUBCOMP_RENDER = 4, // Render interface
99 MOS_VP_SUBCOMP_COUNT // Must be last in the list
100 } MOS_VP_SUBCOMP_ID;
101
102 // Define CP Sub-Component IDs
103 // Mote: please update the diagram above __MOS_USER_FEATURE_KEY_SUB_COMPONENT_CP_TAG
104 // in mos_util_user_feature_keys.h if you change this enum.
105 typedef enum
106 {
107 MOS_CP_SUBCOMP_DDI = 0, // CP-related DDIs
108 MOS_CP_SUBCOMP_DEVICE = MOS_CP_SUBCOMP_DDI, // (DDI)The CP device class
109 MOS_CP_SUBCOMP_UMD_CONTEXT = MOS_CP_SUBCOMP_DDI, // (DDI)Content Protection portions of UMD device context
110 MOS_CP_SUBCOMP_SECURESESSION = MOS_CP_SUBCOMP_DDI, // (DDI)The secure session classes
111 MOS_CP_SUBCOMP_AUTHCHANNEL = MOS_CP_SUBCOMP_DDI, // (DDI)The AuthChannel classes
112 MOS_CP_SUBCOMP_PROTECTEDSESSION = MOS_CP_SUBCOMP_DDI, // (DDI)Protected session class
113 MOS_CP_SUBCOMP_PROTECTED_RESOURCE_SESSION = MOS_CP_SUBCOMP_DDI, // (DDI)Protected Resource session class
114 MOS_CP_SUBCOMP_CAPS = MOS_CP_SUBCOMP_DDI, // (DDI)CP CAPS clas
115
116 MOS_CP_SUBCOMP_OS = 1, // The CP OS services classes
117
118 MOS_CP_SUBCOMP_TEE_HAL = 2, // CP TEE HAL class
119 MOS_CP_SUBCOMP_PCH_HAL = MOS_CP_SUBCOMP_TEE_HAL, // (TEE_HAL)The CP PCH HAL class
120 MOS_CP_SUBCOMP_DLL = MOS_CP_SUBCOMP_TEE_HAL, // (TEE_HAL)CP DLL classes
121
122 MOS_CP_SUBCOMP_GPU_HAL = 3, // The CP GPU HAL classes
123
124 MOS_CP_SUBCOMP_MHW = 4, // CP MHW classes
125
126 MOS_CP_SUBCOMP_CODEC = 5, // Content Protection portions of the Codec UMD
127 MOS_CP_SUBCOMP_CENC = MOS_CP_SUBCOMP_CODEC, // (CODEC)CP cenc class
128
129 MOS_CP_SUBCOMP_COUNT // Must be last in the list
130 } MOS_CP_SUBCOMP_ID;
131
132 //!
133 //! \brief Define DDI Sub-Component IDs
134 //!
135 typedef enum
136 {
137 MOS_DDI_SUBCOMP_SELF = 0,
138 MOS_DDI_SUBCOMP_COUNT
139 } MOS_DDI_SUBCOMP_ID;
140
141 //!
142 //! \brief Define CM Sub-Component IDs
143 //!
144 typedef enum
145 {
146 MOS_CM_SUBCOMP_DDI = 0, // DDI files.
147 MOS_CM_SUBCOMP_SELF = 1,
148 MOS_CM_SUBCOMP_PUBLIC = 2, // Public interface
149 MOS_CM_SUBCOMP_RENDERHAL = 3,
150 MOS_CM_SUBCOMP_COUNT
151 } MOS_CM_SUBCOMP_ID;
152
153 //!
154 //! \brief Define Scalability Sub-Component IDs
155 //!
156 typedef enum
157 {
158 MOS_SCALABILITY_SUBCOMP_SELF = 0,
159 MOS_SCALABILITY_SUBCOMP_COUNT
160 } MOS_SCALABILITY_SUBCOMP_ID;
161
162 //!
163 //! \brief Define MMC Sub-Component IDs
164 //!
165 typedef enum
166 {
167 MOS_MMC_SUBCOMP_SELF = 0,
168 MOS_MMC_SUBCOMP_COUNT
169 } MOS_MMC_SUBCOMP_ID;
170
171 //!
172 //! \brief Define media copy Sub-Component IDs
173 //!
174 typedef enum
175 {
176 MOS_MCPY_SUBCOMP_SELF = 0,
177 MOS_MCPY_SUBCOMP_BLT,
178 MOS_MCPY_SUBCOMP_VEBOX,
179 MOS_MCPY_SUBCOMP_RENDER,
180 MOS_MCPY_SUBCOMP_COUNT
181 } MOS_MCPY_SUBCOMP_ID;
182
183 //!
184 //! \brief Define messaging levels here in the order of importance
185 //!
186 typedef enum
187 {
188 MOS_MESSAGE_LVL_DISABLED = 0,
189 MOS_MESSAGE_LVL_CRITICAL = 1,
190 // Add warning level, which is defined in 4th bit separately, keep the 3-bit message level and 1-bit assert flag setting unchanged.
191 MOS_MESSAGE_LVL_WARNING = 2,
192 // Map the legacy message level (>= MOS_MESSAGE_LVL_NORMAL) to level+1, keep the 3-bit message level and 1-bit assert flag setting unchanged.
193 MOS_MESSAGE_LVL_NORMAL = 3,
194 MOS_MESSAGE_LVL_VERBOSE = 4,
195 MOS_MESSAGE_LVL_FUNCTION_ENTRY = 5,
196 MOS_MESSAGE_LVL_FUNCTION_EXIT = 6,
197 MOS_MESSAGE_LVL_FUNCTION_ENTRY_VERBOSE = 7,
198 MOS_MESSAGE_LVL_MEMNINJA = 8,
199 MOS_MESSAGE_LVL_COUNT
200 } MOS_MESSAGE_LEVEL;
201
202 //!
203 //! \brief Define Component IDs
204 //! When adding a component, need to update
205 //! MOS_COMPONENT_ID,
206 //! MOS_ComponentName,
207 //! pcComponentUserFeatureKeys,
208 //! subComponentCount
209 //! and MOS_MESSAGE_COMPONENT_TAG.
210 //!
211 typedef enum
212 {
213 MOS_COMPONENT_OS,
214 MOS_COMPONENT_HW,
215 MOS_COMPONENT_CODEC,
216 MOS_COMPONENT_VP,
217 MOS_COMPONENT_CP,
218 MOS_COMPONENT_DDI,
219 MOS_COMPONENT_CM,
220 MOS_COMPONENT_CPLIB,
221 MOS_COMPONENT_SCALABILITY,
222 MOS_COMPONENT_MMC,
223 MOS_COMPONENT_MCPY,
224 MOS_COMPONENT_COUNT
225 } MOS_COMPONENT_ID;
226
227 //!
228 //! \brief MOS debug params structure, includes debug level and asserts enabled.
229 //!
230 typedef struct _MOS_DEBUG_PARAMS
231 {
232 int32_t bAssertEnabled;
233 MOS_MESSAGE_LEVEL uiMessageLevel;
234 } MOS_DEBUG_PARAMS;
235
236 //!
237 //! \brief MOS component debug params structure,
238 //! Includes a component's MOS_DEBUG_PARAMS and an array of sub-component params.
239 //!
240 typedef struct _MOS_COMPONENT_DEBUG_PARAMS
241 {
242 MOS_DEBUG_PARAMS component;
243 int32_t bBySubComponent;
244 MOS_DEBUG_PARAMS subComponents[MOS_MAX_SUBCOMPONENT_COUNT]; //!< currently only 16 subcomponent for each component
245 } MOS_COMPONENT_DEBUG_PARAMS;
246
247 //!
248 //! \brief MOS message params structure
249 //! Initialized by MosUtilDebug::MosMessageInit() and cleared by MosUtilDebug::MosMessageClose()
250 //!
251 typedef struct _MOS_MESSAGE_PARAMS
252 {
253 PFILE pLogFile;
254 PFILE pTraceFile;
255 uint32_t uiCounter;
256 int32_t bUseHybridLogTrace; //!< Log debug messages and trace dumps to a file or not
257 int32_t bUseOutputDebugString; //!< Onscreen debug message prints enabled or not
258 uint32_t bEnableMaps; //!< Dump mapped memory regions to trace file
259 uint32_t bDisableAssert; //!< Disable assert
260 uint32_t bEnableFlush; //!< Enable flush
261 uint32_t bEnableMemoryFootPrint; //!< Disable Memory Foot Print
262 MOS_COMPONENT_DEBUG_PARAMS components[MOS_COMPONENT_COUNT];
263 char g_MosMsgBuffer[MOS_MAX_MSG_BUF_SIZE]; //!< Array for debug message
264 } MOS_MESSAGE_PARAMS;
265
266 //!
267 //! When printing from a C++ class, we'd like the class and function to be printed.
268 //! With our current Linux compiler, __FUNCTION__ does not include the class name.
269 //! So we use __PRETTY_FUNCTION__ and MOS_Message will remove extra data.
270 //! This is not needed for prints from C files so they will usually use __FUNCTION__.
271 //!
272
273 #if USE_PRETTY_FUNCTION
274 #define MOS_FUNCTION __PRETTY_FUNCTION__
275 #else
276 #define MOS_FUNCTION __FUNCTION__
277 #endif // USE_PRETTY_FUNCTION
278 #else
279 #define MOS_FUNCTION __FUNCTION__
280 #endif
281
282 class MosUtilDebug
283 {
284 public:
285 MosUtilDebug() = delete;
286 ~MosUtilDebug() = delete;
287
288 #if MOS_MESSAGES_ENABLED
289 //!
290 //! \brief Initialize the MOS message params structure and HLT.
291 //! \details Initialize the MOS message params structure and HLT,
292 //! to be called during device creation
293 //! \param [in] mosCtx
294 //! os device ctx handle
295 //! \return void
296 //!
297 static void MosMessageInit(MediaUserSettingSharedPtr userSettingPtr);
298
299 //!
300 //! \brief Frees the MOS message buffer and MOS message parameters structure
301 //! \details Frees the MOS message buffer and MOS message parameters structure,
302 //! to be called during device destruction
303 //! \return void
304 //!
305 static void MosMessageClose();
306
307 //!
308 //! \brief Close file handles and frees resources
309 //! \details Close file handles and frees resources,
310 //! and reopen file handles.To be called before workload submission
311 //! \return void
312 //!
313 static void MosHLTFlush();
314
315 //!
316 //! \brief Disable Memory Foot Print
317 //! \details Disable Memory Foot Print
318 //! \return bool
319 //!
320 static bool EnableMemoryFootPrint();
321
322 //!
323 //! \brief Form a string that will prefix MOS's log file name
324 //! \details Form a string that will prefix MOS's log file name
325 //! The default log file location will be under
326 //! %ProgramData%\Intel\Logs or %DriverData%\Intel\Logs
327 //! depending on OS version
328 //! \param PCHAR fileNamePrefix
329 //! [out] Pointer to the string where the prefix is returned
330 //! \param [in] userSettingPtr
331 //! MediaUserSettingSharedPtr
332 //! \return MOS_STATUS
333 //! Returns one of the MOS_STATUS error codes if failed,
334 //! else MOS_STATUS_SUCCESS
335 //!
336 static MOS_STATUS MosLogFileNamePrefix(char *fileNamePrefix, MediaUserSettingSharedPtr userSettingPtr);
337
338 //!
339 //! \brief Enable or disable asserts of a particular component, it is used by ULT also
340 //! \details Enable or disable asserts of a particular component
341 //! \param MOS_COMPONENT_ID compID
342 //! [in] Indicates which component
343 //! \param int32_t bEnable
344 //! [in] Enable/disable flag
345 //! \return void
346 //!
347 static void MosCompAssertEnableDisable(MOS_COMPONENT_ID compID, int32_t bEnable);
348
349 //!
350 //! \brief Prints debug messages in debug mode when enabled
351 //! \details Prints debug messages if the level of the comp and sub-comp is
352 //! set to less than the message level. Nop in release version.
353 //! \param MOS_MESSAGE_LEVEL level
354 //! [in] Level of the message
355 //! \param MOS_COMPONENT_ID compID
356 //! [in] Indicates which component
357 //! \param uint8_t subCompID
358 //! [in] Indicates which sub-component
359 //! \param const PCHAR functionName
360 //! [in] pointer to the function name
361 //! \param int32_t lineNum
362 //! [in] Indicates which line the message locate, -1 for no line output
363 //! \param const PCHAR message
364 //! [in] pointer to the message format string
365 //! \param var_args
366 //! [in] variable list of arguments for the message
367 //! \return VOID
368 //!
369 static void MosMessage(
370 MOS_MESSAGE_LEVEL level,
371 MOS_COMPONENT_ID compID,
372 uint8_t subCompID,
373 const PCCHAR functionName,
374 int32_t lineNum,
375 const PCCHAR message,
376 ...);
377
378 //!
379 //! \brief Prints debug messages in debug mode when enabled
380 //! \details Prints debug messages if the level of the comp and sub-comp is
381 //! set to less than the message level. Nop in release version.
382 //! \param MOS_MESSAGE_LEVEL level
383 //! [in] Level of the message
384 //! \param MOS_COMPONENT_ID compID
385 //! [in] Indicates which component
386 //! \param uint8_t subCompID
387 //! [in] Indicates which sub-component
388 //! \param const PCHAR functionName
389 //! [in] pointer to the function name
390 //! \param int32_t lineNum
391 //! [in] Indicates which line the message locate, -1 for no line output
392 //! \param const PCHAR message
393 //! [in] pointer to the message format string
394 //! \param var_args
395 //! [in] variable list of arguments for the message
396 //! \return VOID
397 //!
398 static void MosMessageInternal(
399 MOS_MESSAGE_LEVEL level,
400 MOS_COMPONENT_ID compID,
401 uint8_t subCompID,
402 const PCCHAR functionName,
403 int32_t lineNum,
404 const PCCHAR message,
405 va_list var_args);
406
407 //!
408 //! \brief Checks whether debug messages should be printed.
409 //! \details Determines by the print level, component and sub-component IDs
410 //! whether the debug message should be printed.
411 //! \param MOS_MESSAGE_LEVEL level
412 //! [in] Level of the message
413 //! \param MOS_COMPONENT_ID compID
414 //! [in] Indicates which component
415 //! \param uint8_t subCompID
416 //! [in] Indicates which sub-component
417 //! \param const char *message
418 //! [in] pointer to the message format string
419 //! \return int32_t
420 //!
421 static int32_t MosShouldPrintMessage(
422 MOS_MESSAGE_LEVEL level,
423 MOS_COMPONENT_ID compID,
424 uint8_t subCompID,
425 const char *const message);
426 #endif
427
428 #if MOS_ASSERT_ENABLED
429 //!
430 //! \brief MOS assert function for MOS internal use
431 //! \details Halts the cpu in debug mode when expression resolves to zero
432 //! and only if assert enabled for both comp and sub-comp.
433 //! Nop in release version
434 //! Called by MOS_ASSERT macro only
435 //! \param MOS_COMPONENT_ID compID
436 //! [in] Indicates which component
437 //! \param uint8_t subCompID
438 //! [in] Indicates which sub-component
439 //! \return void
440 //!
441 static void MosAssert(
442 MOS_COMPONENT_ID compID,
443 uint8_t subCompID);
444
445 #endif // MOS_ASSERT_ENABLED
446
447 private:
448
449 #if MOS_MESSAGES_ENABLED
450 //!
451 //! \brief Add preface information to the HLT log when initialized
452 //! \details Add preface information to the HLT log when initialized
453 //! Used internally by MOS_HLTInit().
454 //! \param PFILE pFile
455 //! [out] Pointer to the log file
456 //! \return void
457 //!
458 static void MosHltpPreface(
459 PFILE pFile);
460
461 /*----------------------------------------------------------------------------
462 | Name : MOS_HltpCopyFile
463 | Purpose : Copy all file content from the source file to the target file.
464 | Arguments : szFileName - source file name to copy from
465 | pFile - target file
466 | Returns : Returns one of the MOS_STATUS error codes if failed,
467 | else MOS_STATUS_SUCCESS
468 | Comments :
469 \---------------------------------------------------------------------------*/
470 static MOS_STATUS MosHltpCopyFile(PFILE pFile, const PCCHAR szFileName);
471
472 //!
473 //! \brief Set debug message level for a sub-component within a component
474 //! \details Set debug message level for a sub-component within a component
475 //! \param MOS_COMPONENT_ID compID
476 //! [in] Indicates which component
477 //! \param uint8_t subCompID
478 //! [in] Indicates which sub-component
479 //! \param MOS_MESSAGE_LEVEL msgLevel
480 //! [in] Message level that the sub component allows
481 //! \return void
482 //!
483 static void MosSetSubCompMessageLevel(MOS_COMPONENT_ID compID, uint8_t subCompID, MOS_MESSAGE_LEVEL msgLevel);
484
485 //!
486 //! \brief Set debug message level for a particular component
487 //! \details Set debug message level for a particular component
488 //! \param MOS_COMPONENT_ID compID
489 //! [in] Indicates which component
490 //! \param MOS_MESSAGE_LEVEL msgLevel
491 //! [in] Message level that the component allows
492 //! \return void
493 //!
494 static void MosSetCompMessageLevel(MOS_COMPONENT_ID compID, MOS_MESSAGE_LEVEL msgLevel);
495
496 //!
497 //! \brief Set debug message level for all components
498 //! \details Set all component to the same msg level
499 //! \param MOS_MESSAGE_LEVEL msgLevel
500 //! [in] Message level that all components allow
501 //! \return void
502 //!
503 static void MosSetCompMessageLevelAll(MOS_MESSAGE_LEVEL msgLevel);
504
505 //!
506 //! \brief Enable/disable asserts for a sub-component within a component
507 //! \details Enable/disable asserts for a sub-component within a component
508 //! \param MOS_COMPONENT_ID compID
509 //! [in] Indicates which component
510 //! \param uint8_t subCompID
511 //! [in] Indicates which sub-component
512 //! \param int32_t iFlag
513 //! [in] Enable/disable flag
514 //! \return void
515 //!
516 static void MosSubCompAssertEnableDisable(MOS_COMPONENT_ID compID, uint8_t subCompID, int32_t bEnable);
517
518 //!
519 //! \brief Set debug message level and asserts for a component and its sub-components.
520 //! \details Set debug message level and asserts for a component and its sub-components.
521 //! This includes registering all sub-components.
522 //! \param MOS_COMPONENT_ID compID
523 //! [in] Indicates which component
524 //! \param [in] mosCtx
525 //! os device ctx handle
526 //! \return void
527 //!
528 static void MosMessageInitComponent(MOS_COMPONENT_ID compID, MediaUserSettingSharedPtr userSettingPtr);
529
530 //!
531 //! \brief Initialize or refresh the Hybrid Log and Trace facility
532 //! \details Initialize or refresh the Hybrid Log and Trace facility
533 //! Called during MOS init
534 //! \param [in] mosCtx
535 //! os device ctx handle
536 //! \return MOS_STATUS
537 //! Returns one of the MOS_STATUS error codes if failed,
538 //! else MOS_STATUS_SUCCESS
539 //!
540 static MOS_STATUS MosHLTInit( MediaUserSettingSharedPtr userSettingPtr);
541
542 //!
543 //! \brief Close file handles and frees resources
544 //! \details Close file handles and frees resources
545 //! Called during MOS close
546 //! \return void
547 //!
548 static void MosHLTClose();
549
550 #if USE_PRETTY_FUNCTION
551 //!
552 //! \brief Converts a __PRETTY_FUNCTION__ into Class::Method
553 //! \details Converts a __PRETTY_FUNCTION__ into Class::Method to allow prettier debug output
554 //! \param PCCHAR pcPrettyFunction
555 //! [in] in the form of "TYPE [CLASS::]FUNCTION(INPUT LIST)"
556 //! \return PCCHAR in the form of [CLASS::]FUNCTION
557 //!
558 static PCCHAR MosGetClassMethod(PCCHAR pcPrettyFunction);
559 #endif
560
561 #endif // MOS_MESSAGES_ENABLED
562
563 #if MOS_ASSERT_ENABLED
564 //!
565 //! \brief Checks whether assert should be hit.
566 //! \details Determines by the component and sub-component IDs
567 //! whether an assert should be hit.
568 //! \param MOS_COMPONENT_ID compID
569 //! [in] Indicates which component
570 //! \param uint8_t subCompID
571 //! [in] Indicates which sub-component
572 //! \return int32_t
573 //!
574 static int32_t MosShouldAssert(MOS_COMPONENT_ID compID, uint8_t subCompID);
575 #endif
576 public:
577 #if MOS_MESSAGES_ENABLED
578
579 static const char * const m_mosLogLevelName[MOS_MESSAGE_LVL_COUNT];
580 static const char * const m_mosComponentName[MOS_COMPONENT_COUNT];
581
582 //Temporarily defined as the reference to compatible with the cases using uf key to enable/disable APG.
583 static MOS_MESSAGE_PARAMS m_mosMsgParams;
584 static const char* m_pcComponentUserFeatureKeys[MOS_COMPONENT_COUNT][3];
585 static const uint8_t m_subComponentCount[MOS_COMPONENT_COUNT];
586 #endif
587 MEDIA_CLASS_DEFINE_END(MosUtilDebug)
588 };
589
590 #if MOS_ASSERT_ENABLED
591
592 //!
593 //! \def MOS_ASSERT(_compID, _subCompID, _expr)
594 //! If \a _expr is not true, asserts with \a _compID and \a _subCompID info
595 //!
596 #define MOS_ASSERT(_compID, _subCompID, _expr) \
597 if(!(_expr)) \
598 { \
599 MosUtilDebug::MosAssert(_compID, _subCompID); \
600 }
601
602 #else // MOS_ASSERT_ENABLED
603
604 #define MOS_ASSERT(_compID, _subCompID, _expr)
605
606 #endif // MOS_ASSERT_ENABLED
607
608 #if MOS_MESSAGES_ENABLED
609
610 // flush hlt message before workload submission
611 #define MOS_FLUSH_HLT_MESSAGE MosUtilDebug::MosHLTFlush();
612
613 #define MOS_IS_MEMORY_FOOT_PRINT_ENABLED() MosUtilDebug::EnableMemoryFootPrint()
614
615
616 //!
617 //! \def MOS_DEBUGMESSAGE(_compID, _subCompID, _message, ...)
618 //! Output DEBUG message \a _message with \_a _compID and \_a _subCompID info
619 //!
620 #define MOS_DEBUGMESSAGE(_level, _compID, _subCompID, _message, ...) \
621 MosUtilDebug::MosMessage(_level, _compID, _subCompID, MOS_FUNCTION, __LINE__, _message, ##__VA_ARGS__)
622
623 //!
624 //! \def MOS_DEBUGMESSAGE(_compID, _subCompID, _message, ...)
625 //! Output DEBUG message \a _message with \_a _compID and \_a _subCompID info
626 //!
627 #define MOS_DEBUGMESSAGE_NOLINE(_level, _compID, _subCompID, _message, ...) \
628 MosUtilDebug::MosMessage(_level, _compID, _subCompID, MOS_FUNCTION, -1, _message, ##__VA_ARGS__)
629
630 //!
631 //! \def MOS_FUNCTION_ENTER(_compID, _subCompID)
632 //! Output ENTRY message with \_a _compID and \_a _subCompID info
633 //!
634 #define MOS_FUNCTION_ENTER(_compID, _subCompID) \
635 MOS_DEBUGMESSAGE_NOLINE(MOS_MESSAGE_LVL_FUNCTION_ENTRY, _compID, _subCompID, "")
636
637 //!
638 //! \def MOS_FUNCTION_EXIT(_compID, _subCompID, hr)
639 //! Output EXIT message with \_a _compID and \_a _subCompID info and the result hr.
640 //!
641 #define MOS_FUNCTION_EXIT(_compID, _subCompID, eStatus) \
642 MOS_DEBUGMESSAGE_NOLINE(MOS_MESSAGE_LVL_FUNCTION_EXIT, _compID, _subCompID, ": eStatus = 0x%x", eStatus)
643
644 //!
645 //! \def MOS_FUNCTION_ENTER_VERBOSE(_compID, _subCompID)
646 //! Output VERBOSE ENTRY message with \_a _compID and \_a _subCompID info
647 //!
648 #define MOS_FUNCTION_ENTER_VERBOSE(_compID, _subCompID) \
649 MOS_DEBUGMESSAGE(MOS_MESSAGE_LVL_FUNCTION_ENTRY_VERBOSE, _compID, _subCompID, "")
650
651 //!
652 //! \def MOS_CRITICALMESSAGE(_compID, _subCompID, _message, ...)
653 //! Output DEBUG message \a _message with \_a _compID and \_a _subCompID info
654 //!
655 #define MOS_CRITICALMESSAGE(_compID, _subCompID, _message, ...) \
656 MOS_DEBUGMESSAGE(MOS_MESSAGE_LVL_CRITICAL, _compID, _subCompID, _message, ##__VA_ARGS__)
657
658 //!
659 //! \def MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ...)
660 //! Output CRITICAL message \a _message with \_a _compID and \_a _subCompID info
661 //! and triggers an assert.
662 //!
663 #define MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ...) \
664 MOS_CRITICALMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \
665 MOS_ASSERT(_compID, _subCompID, false);
666
667 //!
668 //! \def MOS_WARNINGMESSAGE(_compID, _subCompID, _message, ...)
669 //! Output DEBUG message \a _message with \_a _compID and \_a _subCompID info
670 //!
671 #define MOS_WARNINGMESSAGE(_compID, _subCompID, _message, ...) \
672 MOS_DEBUGMESSAGE(MOS_MESSAGE_LVL_WARNING, _compID, _subCompID, _message, ##__VA_ARGS__)
673
674 //!
675 //! \def MOS_NORMALMESSAGE(_compID, _subCompID, _message, ...)
676 //! Output NORMAL message \a _message with \_a _compID and \_a _subCompID info
677 //!
678 #define MOS_NORMALMESSAGE(_compID, _subCompID, _message, ...) \
679 MOS_DEBUGMESSAGE(MOS_MESSAGE_LVL_NORMAL, _compID, _subCompID, _message, ##__VA_ARGS__)
680
681 //!
682 //! \def MOS_VERBOSEMESSAGE(_compID, _subCompID, _message, ...)
683 //! Output DEBUG message \a _message with \_a _compID and \_a _subCompID info
684 //!
685 #define MOS_VERBOSEMESSAGE(_compID, _subCompID, _message, ...) \
686 MOS_DEBUGMESSAGE(MOS_MESSAGE_LVL_VERBOSE, _compID, _subCompID, _message, ##__VA_ARGS__)
687
688 //!
689 //! \def MOS_MEMNINJAMESSAGE(_compID, _subCompID, _message, ...)
690 //! Output DEBUG message \a _message with \_a _compID and \_a _subCompID info
691 //!
692 #define MOS_MEMNINJAMESSAGE(_compID, _subCompID, _message, ...) \
693 MOS_DEBUGMESSAGE(MOS_MESSAGE_LVL_MEMNINJA, _compID, _subCompID, _message, ##__VA_ARGS__)
694
695 //!
696 //! \def MOS_DEBUGMESSAGE_IF(_cond, _level, _compID, _subCompID, _message, ...)
697 //! If \a _cond is true, output message \a _message of level \a _level with
698 //! \_a _compID and \_a _subCompID info
699 //!
700 #define MOS_DEBUGMESSAGE_IF(_cond, _level, _compID, _subCompID, _message, ...) \
701 if (_cond) \
702 { \
703 MOS_DEBUGMESSAGE(_level, _compID, _subCompID, _message, ##__VA_ARGS__); \
704 }
705
706 //!
707 //! \def MOS_TraceEventExt
708 //! this is trace event interface extension, only for debug purpose.
709 //!
710 #define MOS_TraceEventExt MOS_TraceEvent
711 #define MOS_TraceDumpExt MOS_TraceDataDump
712
713 #define MOS_TraceDataExt0 MOS_TraceData0
714 #define MOS_TraceDataExt MOS_TraceData
715
716 //!
717 //! \def New trace interface with keyword filter, need have at least 1 param in trace data
718 //!
719 #define MOS_TraceDecodePicParam(usId, usType, ...) \
720 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_PICPARAM)) \
721 { \
722 TR_FILL_PARAM(__VA_ARGS__); \
723 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
724 }
725 #define MOS_TraceDecodeSliceParam(usId, usType, ...) \
726 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_SLICEPARAM)) \
727 { \
728 TR_FILL_PARAM(__VA_ARGS__); \
729 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
730 }
731 #define MOS_TraceDecodeTileParam(usId, usType, ...) \
732 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_TILEPARAM)) \
733 { \
734 TR_FILL_PARAM(__VA_ARGS__); \
735 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
736 }
737 #define MOS_TraceDecodeQMatrix(usId, usType, ...) \
738 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_QMATRIX)) \
739 { \
740 TR_FILL_PARAM(__VA_ARGS__); \
741 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
742 }
743 #define MOS_TraceDecodeBitStreamInfo(usId, usType, ...) \
744 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_BITSTREAM_INFO)) \
745 { \
746 TR_FILL_PARAM(__VA_ARGS__); \
747 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
748 }
749 #define MOS_TraceDecodeBitStream(usId, usType, ...) \
750 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_BITSTREAM)) \
751 { \
752 TR_FILL_PARAM(__VA_ARGS__); \
753 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
754 }
755 #define MOS_TraceDecodeInternal(usId, usType, ...) \
756 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_INTERNAL)) \
757 { \
758 TR_FILL_PARAM(__VA_ARGS__); \
759 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
760 }
761 #define MOS_TraceDecodeCommand(usId, usType, ...) \
762 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_COMMAND)) \
763 { \
764 TR_FILL_PARAM(__VA_ARGS__); \
765 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
766 }
767 #define MOS_TraceDecodeDstYuv(usId, usType, ...) \
768 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_DSTYUV)) \
769 { \
770 TR_FILL_PARAM(__VA_ARGS__); \
771 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
772 }
773 #define MOS_TraceDecodeRefYuv(usId, usType, ...) \
774 if (MosUtilities::TraceKeyEnabled(TR_KEY_DECODE_REFYUV)) \
775 { \
776 TR_FILL_PARAM(__VA_ARGS__); \
777 TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \
778 }
779
780 #define MT_LOG(id, lvl) \
781 { \
782 int32_t _head[] = {id, lvl}; \
783 MosUtilities::MosTraceEvent(EVENT_MEDIA_LOG, 0, _head, sizeof(_head), nullptr, 0); \
784 }
785
786 #define MT_LOG1(id, lvl, p1, v1) \
787 { \
788 int32_t _head[] = {id, lvl}; \
789 MT_PARAM _param[] = {p1, v1}; \
790 MosUtilities::MosTraceEvent(EVENT_MEDIA_LOG, 1, _head, sizeof(_head), _param, sizeof(_param)); \
791 }
792
793 #define MT_LOG2(id, lvl, p1, v1, p2, v2) \
794 { \
795 int32_t _head[] = {id, lvl}; \
796 MT_PARAM _param[] = {{p1, v1}, {p2, v2}}; \
797 MosUtilities::MosTraceEvent(EVENT_MEDIA_LOG, 2, _head, sizeof(_head), _param, sizeof(_param)); \
798 }
799
800 #define MT_LOG3(id, lvl, p1, v1, p2, v2, p3, v3) \
801 { \
802 int32_t _head[] = {id, lvl}; \
803 MT_PARAM _param[] = {{p1, v1}, {p2, v2}, {p3, v3}}; \
804 MosUtilities::MosTraceEvent(EVENT_MEDIA_LOG, 3, _head, sizeof(_head), _param, sizeof(_param)); \
805 }
806
807 #define MT_LOG4(id, lvl, p1, v1, p2, v2, p3, v3, p4, v4) \
808 { \
809 int32_t _head[] = {id, lvl}; \
810 MT_PARAM _param[] = {{p1, v1}, {p2, v2}, {p3, v3}, {p4, v4}}; \
811 MosUtilities::MosTraceEvent(EVENT_MEDIA_LOG, 4, _head, sizeof(_head), _param, sizeof(_param)); \
812 }
813
814 #define MT_LOG5(id, lvl, p1, v1, p2, v2, p3, v3, p4, v4, p5, v5) \
815 { \
816 int32_t _head[] = {id, lvl}; \
817 MT_PARAM _param[] = {{p1, v1}, {p2, v2}, {p3, v3}, {p4, v4}, {p5, v5}}; \
818 MosUtilities::MosTraceEvent(EVENT_MEDIA_LOG, 5, _head, sizeof(_head), _param, sizeof(_param)); \
819 }
820
821 #define MT_LOG6(id, lvl, p1, v1, p2, v2, p3, v3, p4, v4, p5, v5, p6, v6) \
822 { \
823 int32_t _head[] = {id, lvl}; \
824 MT_PARAM _param[] = {{p1, v1}, {p2, v2}, {p3, v3}, {p4, v4}, {p5, v5}, {p6, v6}}; \
825 MosUtilities::MosTraceEvent(EVENT_MEDIA_LOG, 6, _head, sizeof(_head), _param, sizeof(_param)); \
826 }
827
828 #define MT_LOG7(id, lvl, p1, v1, p2, v2, p3, v3, p4, v4, p5, v5, p6, v6, p7, v7) \
829 { \
830 int32_t _head[] = {id, lvl}; \
831 MT_PARAM _param[] = {{p1, v1}, {p2, v2}, {p3, v3}, {p4, v4}, {p5, v5}, {p6, v6}, {p7, v7}}; \
832 MosUtilities::MosTraceEvent(EVENT_MEDIA_LOG, 7, _head, sizeof(_head), _param, sizeof(_param)); \
833 }
834
835 #define MT_ERR(id) \
836 { \
837 int32_t _head[] = {id}; \
838 MosUtilities::MosTraceEvent(EVENT_MEDIA_ERR, 0, _head, sizeof(_head), nullptr, 0); \
839 }
840
841 #define MT_ERR1(id, p1, v1) \
842 { \
843 int32_t _head[] = {id}; \
844 MT_PARAM _param[] = {p1, v1}; \
845 MosUtilities::MosTraceEvent(EVENT_MEDIA_ERR, 1, _head, sizeof(_head), _param, sizeof(_param)); \
846 }
847
848 #define MT_ERR2(id, p1, v1, p2, v2) \
849 { \
850 int32_t _head[] = {id}; \
851 MT_PARAM _param[] = {{p1, v1}, {p2, v2}}; \
852 MosUtilities::MosTraceEvent(EVENT_MEDIA_ERR, 2, _head, sizeof(_head), _param, sizeof(_param)); \
853 }
854
855 #define MT_ERR3(id, p1, v1, p2, v2, p3, v3) \
856 { \
857 int32_t _head[] = {id}; \
858 MT_PARAM _param[] = {{p1, v1}, {p2, v2}, {p3, v3}}; \
859 MosUtilities::MosTraceEvent(EVENT_MEDIA_ERR, 3, _head, sizeof(_head), _param, sizeof(_param)); \
860 }
861
862 #else // !MOS_MESSAGES_ENABLED
863
864 #define MOS_FLUSH_HLT_MESSAGE
865 #define MOS_IS_MEMORY_FOOT_PRINT_ENABLED() 0
866
867 //!
868 //! \brief The two methods below are used only for debug or release internal drivers
869 //! but are called in release drivers too.
870 //!
871 #define MOS_TraceEventExt(...)
872 #define MOS_TraceDumpExt(...)
873 #define MOS_TraceDataExt0(usId, usType)
874 #define MOS_TraceDataExt(usId, usType, ...)
875 #define MOS_TraceDecodePicParam(usId, usType, ...)
876 #define MOS_TraceDecodeSliceParam(usId, usType, ...)
877 #define MOS_TraceDecodeTileParam(usId, usType, ...)
878 #define MOS_TraceDecodeQMatrix(usId, usType, ...)
879 #define MOS_TraceDecodeBitStreamInfo(usId, usType, ...)
880 #define MOS_TraceDecodeBitStream(usId, usType, ...)
881 #define MOS_TraceDecodeInternal(usId, usType, ...)
882 #define MOS_TraceDecodeCommand(usId, usType, ...)
883 #define MOS_TraceDecodeDstYuv(usId, usType, ...)
884 #define MOS_TraceDecodeRefYuv(usId, usType, ...)
885 #define MT_LOG(id, lvl)
886 #define MT_LOG1(id, lvl, p1, v1)
887 #define MT_LOG2(id, lvl, p1, v1, p2, v2)
888 #define MT_LOG3(id, lvl, p1, v1, p2, v2, p3, v3)
889 #define MT_LOG4(id, lvl, p1, v1, p2, v2, p3, v3, p4, v4)
890 #define MT_LOG5(id, lvl, p1, v1, p2, v2, p3, v3, p4, v4, p5, v5)
891 #define MT_LOG6(id, lvl, p1, v1, p2, v2, p3, v3, p4, v4, p5, v5, p6, v6)
892 #define MT_LOG7(id, lvl, p1, v1, p2, v2, p3, v3, p4, v4, p5, v5, p6, v6, p7, v7)
893 #define MT_ERR(id)
894 #define MT_ERR1(id, p1, v1)
895 #define MT_ERR2(id, p1, v1, p2, v2)
896 #define MT_ERR3(id, p1, v1, p2, v2, p3, v3)
897
898 #define MOS_FUNCTION_ENTER(_compID, _subCompID)
899 #define MOS_FUNCTION_EXIT(_compID, _subCompID, hr)
900 #define MOS_FUNCTION_ENTER_VERBOSE(_compID, _subCompID)
901 #define MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ...)
902 #define MOS_WARNINGMESSAGE(_compID, _subCompID, _message, ...)
903 #define MOS_NORMALMESSAGE(_compID, _subCompID, _message, ...)
904 #define MOS_VERBOSEMESSAGE(_compID, _subCompID, _message, ...)
905 #define MOS_CRITICALMESSAGE(_compID, _subCompID, _message, ...)
906 #define MOS_DEBUGMESSAGE_IF(_cond, _level, _compID, _subCompID, _message, ...)
907 #define MOS_DEBUGMESSAGE(_compID, _subCompID, _message, ...)
908 #define MOS_MEMNINJAMESSAGE(_compID, _subCompID, _message, ...)
909
910 #endif // MOS_MESSAGES_ENABLED
911
912 //------------------------------------------------------------------------------
913 // Generic Macros for use by all components.
914 //------------------------------------------------------------------------------
915
916 //!
917 //! \def MOS_CHK_STATUS_RETURN(_compID, _subCompID, _stmt)
918 //! Check MOS_STATUS \a _stmt, assert and return an error for failure
919 //!
920 #define MOS_CHK_STATUS_RETURN(_compID, _subCompID, _stmt) \
921 { \
922 MOS_STATUS stmtStatus = (MOS_STATUS)(_stmt); \
923 if (stmtStatus != MOS_STATUS_SUCCESS) \
924 { \
925 MOS_ASSERTMESSAGE(_compID, _subCompID, "MOS returned error, eStatus = 0x%x", stmtStatus); \
926 MT_ERR3(MT_ERR_MOS_STATUS_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID, MT_ERROR_CODE, stmtStatus); \
927 return stmtStatus; \
928 } \
929 }
930
931 //!
932 //! \def MOS_CHK_STATUS_BREAK(_compID, _subCompID, _stmt)
933 //! Check MOS_STATUS \a _stmt, assert and break out of current loop
934 //!
935 #define MOS_CHK_STATUS_BREAK(_compID, _subCompID, _stmt) \
936 { \
937 eStatus = (MOS_STATUS)(_stmt); \
938 if (eStatus != MOS_STATUS_SUCCESS) \
939 { \
940 MOS_ASSERTMESSAGE(_compID, _subCompID, "MOS returned error, eStatus = 0x%x", eStatus); \
941 MT_ERR3(MT_ERR_MOS_STATUS_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID, MT_ERROR_CODE, eStatus); \
942 break; \
943 } \
944 }
945
946 //!
947 //! \def MOS_CHK_STATUS_MESSAGE_RETURN(_compID, _subCompID, _stmt, _message, ...)
948 //! Check MOS_STATUS \a _stmt, assert and return an error for failure, and print message
949 //!
950 #define MOS_CHK_STATUS_MESSAGE_RETURN(_compID, _subCompID, _stmt, _message, ...)\
951 { \
952 MOS_STATUS stmtStatus = (MOS_STATUS)(_stmt); \
953 if (stmtStatus != MOS_STATUS_SUCCESS) \
954 { \
955 MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \
956 MT_ERR3(MT_ERR_MOS_STATUS_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID, MT_ERROR_CODE, stmtStatus); \
957 return stmtStatus; \
958 } \
959 }
960
961 //!
962 //! \def MOS_CHK_NULL_RETURN(_compID, _subCompID, _ptr)
963 //! Check if \a _ptr == nullptr, if so assert and return an error
964 //!
965 #define MOS_CHK_NULL_RETURN(_compID, _subCompID, _ptr) \
966 { \
967 if ((_ptr) == nullptr) \
968 { \
969 MOS_ASSERTMESSAGE(_compID, _subCompID, "Invalid (nullptr) Pointer: " #_ptr); \
970 MT_ERR2(MT_ERR_NULL_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
971 return MOS_STATUS_NULL_POINTER; \
972 } \
973 }
974
975 //!
976 //! \def MOS_CHK_NULL_RETURN(_compID, _subCompID, _ptr)
977 //! Check if \a _ptr == nullptr, if so assert and return an error
978 //!
979 #define MOS_CHK_NULL_MESSAGE_RETURN(_compID, _subCompID, _ptr, _message, ...) \
980 { \
981 if ((_ptr) == nullptr) \
982 { \
983 MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \
984 MT_ERR2(MT_ERR_NULL_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
985 return MOS_STATUS_NULL_POINTER; \
986 } \
987 }
988
989
990 //!
991 //! \def MOS_CHK_STATUS(_compID, _subCompID, _stmt)
992 //! Check MOS_STATUS \a _stmt, assert and return an error for failure
993 //!
994 #define MOS_CHK_STATUS(_compID, _subCompID, _stmt) \
995 { \
996 eStatus = (MOS_STATUS)(_stmt); \
997 if (eStatus != MOS_STATUS_SUCCESS) \
998 { \
999 MOS_ASSERTMESSAGE(_compID, _subCompID, "MOS returned error, eStatus = 0x%x", eStatus); \
1000 MT_ERR2(MT_ERR_MOS_STATUS_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1001 goto finish; \
1002 } \
1003 }
1004
1005 //!
1006 //! \def MOS_CHK_STATUS_MESSAGE(_compID, _subCompID, _stmt, _message, ...)
1007 //! Check MOS_STATUS \a _stmt, assert and return an error for failure, and print message
1008 //!
1009 #define MOS_CHK_STATUS_MESSAGE(_compID, _subCompID, _stmt, _message, ...) \
1010 { \
1011 eStatus = (MOS_STATUS)(_stmt); \
1012 if (eStatus != MOS_STATUS_SUCCESS) \
1013 { \
1014 MT_ERR2(MT_ERR_MOS_STATUS_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1015 MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \
1016 goto finish; \
1017 } \
1018 }
1019
1020 //!
1021 //! \def MOS_CHK_STATUS_NO_STATUS_RETURN(_compID, _subCompID, _stmt)
1022 //! Check MOS_STATUS \a _stmt, return void
1023 //!
1024 #define MOS_CHK_STATUS_NO_STATUS_RETURN(_compID, _subCompID, _stmt) \
1025 { \
1026 MOS_STATUS stmtStatus = (MOS_STATUS)(_stmt); \
1027 if (stmtStatus != MOS_STATUS_SUCCESS) \
1028 { \
1029 MT_ERR3(MT_ERR_MOS_STATUS_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID, MT_ERROR_CODE, stmtStatus); \
1030 MOS_ASSERTMESSAGE(_compID, _subCompID, "MOS returned error, eStatus = 0x%x", stmtStatus);\
1031 return; \
1032 } \
1033 }
1034
1035 //!
1036 //! \def MOS_CHK_STATUS_SAFE(_stmt)
1037 //! Check MOS_STATUS \a _stmt, return for failure
1038 //!
1039 #define MOS_CHK_STATUS_SAFE(_stmt) \
1040 { \
1041 eStatus = (MOS_STATUS)(_stmt); \
1042 if (eStatus != MOS_STATUS_SUCCESS) \
1043 { \
1044 goto finish; \
1045 } \
1046 }
1047
1048 //!
1049 //! \def MOS_CHK_NULL(_compID, _subCompID, _ptr)
1050 //! Check if \a _ptr == nullptr, if so assert and return an error
1051 //!
1052 #define MOS_CHK_NULL(_compID, _subCompID, _ptr) \
1053 { \
1054 if ((_ptr) == nullptr) \
1055 { \
1056 MOS_ASSERTMESSAGE(_compID, _subCompID, "Invalid (nullptr) Pointer."); \
1057 MT_ERR2(MT_ERR_NULL_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1058 eStatus = MOS_STATUS_NULL_POINTER; \
1059 goto finish; \
1060 } \
1061 }
1062
1063 //!
1064 //! \def MOS_CHK_NULL_NO_STATUS(_compID, _subCompID, _ptr)
1065 //! Assert and print a message if \a _ptr == nullptr, but not set an error
1066 //!
1067 #define MOS_CHK_NULL_NO_STATUS(_compID, _subCompID, _ptr) \
1068 { \
1069 if ((_ptr) == nullptr) \
1070 { \
1071 MOS_ASSERTMESSAGE(_compID, _subCompID, "Invalid (nullptr) Pointer."); \
1072 MT_ERR2(MT_ERR_NULL_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1073 goto finish; \
1074 } \
1075 }
1076
1077
1078 //!
1079 //! \def MOS_CHK_NULL_RETURN_NULL(_compID, _subCompID, _ptr)
1080 //! Assert and print a message if \a _ptr == nullptr, but not set an error
1081 //!
1082 #define MOS_CHK_NULL_RETURN_NULL(_compID, _subCompID, _ptr) \
1083 { \
1084 if ((_ptr) == nullptr) \
1085 { \
1086 MOS_ASSERTMESSAGE(_compID, _subCompID, "Invalid (nullptr) Pointer."); \
1087 MT_ERR2(MT_ERR_NULL_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1088 return nullptr; \
1089 } \
1090 }
1091
1092 //!
1093 //! \def MOS_CHK_NULL_NO_STATUS_RETURN(_compID, _subCompID, _ptr)
1094 //! Assert and print a message if \a _ptr == nullptr, but not set an error
1095 //!
1096 #define MOS_CHK_NULL_NO_STATUS_RETURN(_compID, _subCompID, _ptr) \
1097 { \
1098 if ((_ptr) == nullptr) \
1099 { \
1100 MOS_ASSERTMESSAGE(_compID, _subCompID, "Invalid (nullptr) Pointer."); \
1101 MT_ERR2(MT_ERR_NULL_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1102 return; \
1103 } \
1104 }
1105
1106 //!
1107 //! \def MOS_CHK_COND(_compID, _subCompID, _condition, _str)
1108 //! Check if \a _condition is true, if so assert and return an error
1109 //!
1110 #define MOS_CHK_COND(_compID, _subCompID, _condition, _message, ...) \
1111 { \
1112 if (_condition) \
1113 { \
1114 MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \
1115 MT_ERR2(MT_ERR_CONDITION_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1116 eStatus = MOS_STATUS_INVALID_PARAMETER; \
1117 goto finish; \
1118 } \
1119 }
1120
1121 //!
1122 //! \def MOS_CHK_COND_RETURN(_compID, _subCompID, _condition, _str)
1123 //! Check if \a _condition is true, if so assert and return an error
1124 //!
1125 #define MOS_CHK_COND_RETURN(_compID, _subCompID, _condition, _message, ...) \
1126 { \
1127 if (_condition) \
1128 { \
1129 MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \
1130 MT_ERR2(MT_ERR_CONDITION_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1131 return MOS_STATUS_INVALID_PARAMETER; \
1132 } \
1133 }
1134
1135 //!
1136 //! \def MOS_CHK_COND_RETURN_VALUE(_compID, _subCompID, _condition, retVal, _str)
1137 //! Check if \a _condition is true, if so assert and return \a retVal
1138 //!
1139 #define MOS_CHK_COND_RETURN_VALUE(_compID, _subCompID, _condition, retVal, _message, ...) \
1140 { \
1141 if (_condition) \
1142 { \
1143 MT_ERR2(MT_ERR_CONDITION_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1144 MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \
1145 return retVal; \
1146 } \
1147 }
1148
1149 //!
1150 //! \def MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(_compID, _subCompID, _condition, destroyFunction, retVal, _message)
1151 //! Check if \a _condition is true, if so assert, call destroy function and return \a retVal
1152 //!
1153 #define MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(_compID, _subCompID, _condition, destroyFunction, retVal, _message, ...) \
1154 { \
1155 if (_condition) \
1156 { \
1157 destroyFunction(); \
1158 MT_ERR2(MT_ERR_CONDITION_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID); \
1159 MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \
1160 return retVal; \
1161 } \
1162 }
1163
1164 //!
1165 //! The following HR macros are temporary until MOS switches to MOS_STATUS. When that happens,
1166 //! and therefore these macros will be moved to an OS specific file.
1167 //!
1168
1169 //!
1170 //! \def MOS_CHK_HR(_compID, _subCompID, _stmt)
1171 //! Check _stmt, assert and return an error for failure
1172 //!
1173 #define MOS_CHK_HR(_compID, _subCompID, _stmt) \
1174 { \
1175 hr = (_stmt); \
1176 if (hr != MOS_STATUS_SUCCESS) \
1177 { \
1178 MOS_ASSERTMESSAGE(_compID, _subCompID, "hr check failed."); \
1179 MT_ERR3(MT_ERR_HR_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID, MT_ERROR_CODE, hr); \
1180 goto finish; \
1181 } \
1182 }
1183
1184 //!
1185 //! \def MOS_CHK_HR_NO_STATUS_RETURN(_compID, _subCompID, _stmt)
1186 //! Check _stmt, assert and return void
1187 //!
1188 #define MOS_CHK_HR_NO_STATUS_RETURN(_compID, _subCompID, _stmt) \
1189 { \
1190 hr = (_stmt); \
1191 if (hr != MOS_STATUS_SUCCESS) \
1192 { \
1193 MOS_ASSERTMESSAGE(_compID, _subCompID, "MOS returned error, hr = 0x%x", hr); \
1194 MT_ERR3(MT_ERR_HR_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID, MT_ERROR_CODE, hr); \
1195 return; \
1196 } \
1197 }
1198
1199 //!
1200 //! \def MOS_CHK_STATUS_MESSAGE(_compID, _subCompID, _stmt, _message, ...)
1201 //! Check MOS_STATUS \a _stmt, assert and return an error for failure, and print message
1202 //!
1203 #define MOS_CHK_HR_MESSAGE(_compID, _subCompID, _stmt, _message, ...) \
1204 { \
1205 hr = (_stmt); \
1206 if (hr != MOS_STATUS_SUCCESS) \
1207 { \
1208 MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__); \
1209 MT_ERR3(MT_ERR_HR_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID, MT_ERROR_CODE, hr); \
1210 goto finish; \
1211 } \
1212 }
1213
1214 //!
1215 //! \def MOS_CHECK_CONDITION(_compID, _subCompID, _condition, _str, _ret)
1216 //! Check if \a _condition is true, if so assert and print the error message _str
1217 //! and then return the specified value _ret
1218 //!
1219 #define MOS_CHECK_CONDITION(_compID, _subCompID, _condition, _str, _ret) \
1220 { \
1221 if (_condition) \
1222 { \
1223 MOS_ASSERTMESSAGE(_compID, _subCompID, _str); \
1224 return _ret; \
1225 } \
1226 }
1227
1228 //------------------------------------------------------------------------------
1229 // Macros for debug message and Assert defined for ease of use within MOS files.
1230 //------------------------------------------------------------------------------
1231
1232 //!
1233 //! \def MOS_OS_CHK_STATUS(_stmt)
1234 //! MOS_CHK_STATUS \a _stmt with MOS utility comp/subcomp info
1235 //!
1236 #define MOS_OS_CHK_STATUS(_stmt) \
1237 MOS_CHK_STATUS(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _stmt)
1238
1239 //!
1240 //! \def MOS_OS_CHK_NULL(_ptr)
1241 //! MOS_CHK_NULL \a _ptr with MOS utility comp/subcomp info
1242 //!
1243 #define MOS_OS_CHK_NULL(_ptr) \
1244 MOS_CHK_NULL(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr)
1245
1246 //!
1247 //! \def MOS_OS_CHK_NULL_NO_STATUS(_ptr)
1248 //! MOS_CHK_NULL \a _ptr with MOS utility comp/subcomp info without returning a status
1249 //!
1250 #define MOS_OS_CHK_NULL_NO_STATUS(_ptr) \
1251 MOS_CHK_NULL_NO_STATUS(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr)
1252
1253 //!
1254 //! \def MOS_OS_CHK_NULL_RETURN_NULL(_ptr)
1255 //! MOS_CHK_NULL \a _ptr with MOS utility comp/subcomp info with returning nullptr
1256 //!
1257 #define MOS_OS_CHK_NULL_RETURN_NULL(_ptr) \
1258 MOS_CHK_NULL_RETURN_NULL(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr)
1259
1260 //!
1261 //! \def MOS_OS_CHK_NULL_NO_STATUS_RETURN(_ptr)
1262 //! MOS_ASSERTMESSAGE \a _ptr with MOS utility comp/subcomp info without returning a status
1263 //!
1264 #define MOS_OS_CHK_NULL_NO_STATUS_RETURN(_ptr) \
1265 MOS_CHK_NULL_NO_STATUS_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr)
1266
1267 //!
1268 //! \def MOS_OS_CHK_STATUS_MESSAGE(_ptr)
1269 //! MOS_CHK_STATUS_MESSAGE \a _ptr with MOS utility comp/subcomp info
1270 //!
1271 #define MOS_OS_CHK_STATUS_MESSAGE(_ptr, _message, ...) \
1272 MOS_CHK_STATUS_MESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr, _message, ##__VA_ARGS__)
1273
1274 //!
1275 //! \def MOS_OS_CHK_NULL_RETURN(_ptr)
1276 //! MOS_CHK_NULL \a _ptr with MOS utility comp/subcomp info
1277 //!
1278 #define MOS_OS_CHK_NULL_RETURN(_ptr) \
1279 MOS_CHK_NULL_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr)
1280
1281 //!
1282 //! \def MOS_OS_CHK_NULL_MESSAGE_RETURN(_ptr)
1283 //! MOS_CHK_NULL \a _ptr with MOS utility comp/subcomp info
1284 //!
1285 #define MOS_OS_CHK_NULL_MESSAGE_RETURN(_ptr, _message, ...) \
1286 MOS_CHK_NULL_MESSAGE_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr, _message, ##__VA_ARGS__)
1287
1288 //!
1289 //! \def MOS_OS_CHK_HR(_ptr)
1290 //! MOS_CHK_HR \a _ptr with MOS utility comp/subcomp info
1291 //!
1292 #define MOS_OS_CHK_HR(_ptr) \
1293 MOS_CHK_HR(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr)
1294
1295 //!
1296 //! \def MOS_OS_CHK_HR_MESSAGE(_ptr)
1297 //! MOS_CHK_HR_MESSAGE \a _ptr with MOS utility comp/subcomp info
1298 //!
1299 #define MOS_OS_CHK_HR_MESSAGE(_ptr, _message, ...) \
1300 MOS_CHK_HR_MESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr, _message, ##__VA_ARGS__)
1301
1302 //!
1303 //! \def MOS_OS_CHK_NULL_WITH_HR(_ptr)
1304 //! MOS_CHK_NULL_WITH_HR \a _ptr with MOS utility comp/subcomp info
1305 //!
1306 #define MOS_OS_CHK_NULL_WITH_HR(_ptr) \
1307 MOS_CHK_NULL_WITH_HR(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr)
1308
1309 //!
1310 //! \def MOS_OS_CHK_NULL_WITH_HR_RETURN(_ptr)
1311 //! MOS_CHK_NULL_WITH_HR \a _ptr with MOS utility comp/subcomp info
1312 //!
1313 #define MOS_OS_CHK_NULL_WITH_HR_RETURN(_ptr) \
1314 MOS_CHK_NULL_WITH_HR_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr)
1315
1316 //!
1317 //! \def MOS_OS_CHECK_CONDITION(_condition, _str, _ret)
1318 //! MOS_CHECK_CONDITION \a _condition with MOS utility comp/subcomp info
1319 //!
1320 #define MOS_OS_CHECK_CONDITION(_condition, _str, _ret) \
1321 MOS_CHECK_CONDITION(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _condition, _str, _ret)
1322
1323 //!
1324 //! \def MOS_OS_ASSERT(_expr)
1325 //! MOS_ASSERT \a _expr with MOS Utility comp/subcomp info
1326 //!
1327 #define MOS_OS_ASSERT(_expr) \
1328 MOS_ASSERT(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _expr)
1329
1330 //!
1331 //! \def MOS_OS_CHK_NULL_RETURN(_ptr)
1332 //! MOS_CHK_NULL_RETURN \a _ptr with MOS utility comp/subcomp info
1333 //!
1334 #define MOS_OS_CHK_NULL_RETURN(_ptr) \
1335 MOS_CHK_NULL_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _ptr)
1336
1337 //!
1338 //! \def MOS_OS_CHK_STATUS(_stmt)
1339 //! MOS_CHK_STATUS \a _stmt with MOS utility comp/subcomp info
1340 //!
1341 #define MOS_OS_CHK_STATUS_RETURN(_stmt) \
1342 MOS_CHK_STATUS_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _stmt)
1343
1344 //!
1345 //! \def MOS_OS_CHK_STATUS_MESSAGE_RETURN(_stmt, _message, ......)
1346 //! MOS_CHK_STATUS \a _stmt with MOS utility comp/subcomp info
1347 //!
1348 #define MOS_OS_CHK_STATUS_MESSAGE_RETURN(_stmt, _message, ...) \
1349 MOS_CHK_STATUS_MESSAGE_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _stmt, _message, ##__VA_ARGS__)
1350
1351 //!
1352 //! \def MOS_OS_CHK_NULL_RETURN_VALUE(_ptr, retVal)
1353 //! MOS_CHK_COND_RETURN_VALUE \a _ptr with MOS utility comp/subcomp info
1354 //!
1355 #define MOS_OS_CHK_NULL_RETURN_VALUE(_ptr, retVal) \
1356 MOS_CHK_COND_RETURN_VALUE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, (_ptr == nullptr), retVal, "Invalid (nullptr) Pointer.")
1357
1358 //!
1359 //! \def MOS_OS_ASSERTMESSAGE(_message, ...)
1360 //! MOS_ASSERTMESSAGE \a _message with MOS Utility comp/subcomp info
1361 //!
1362 #define MOS_OS_ASSERTMESSAGE(_message, ...) \
1363 MOS_ASSERTMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _message, ##__VA_ARGS__)
1364
1365 //!
1366 //! \def MOS_OS_CRITICALMESSAGE(_message, ...)
1367 //! MOS_CRITICALMESSAGE \a _message with MOS Utility comp/subcomp info
1368 //!
1369 #define MOS_OS_CRITICALMESSAGE(_message, ...) \
1370 MOS_CRITICALMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _message, ##__VA_ARGS__)
1371
1372 //!
1373 //! \def MOS_OS_WARNINGMESSAGE(_message, ...)
1374 //! MOS_UTIL_WARNINGMESSAGE \a _message with MOS Utility comp/subcomp info
1375 //!
1376 #define MOS_OS_WARNINGMESSAGE(_message, ...) \
1377 MOS_WARNINGMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _message, ##__VA_ARGS__)
1378
1379 //!
1380 //! \def MOS_OS_NORMALMESSAGE(_message, ...)
1381 //! MOS_UTIL_NORMALMESSAGE \a _message with MOS Utility comp/subcomp info
1382 //!
1383 #define MOS_OS_NORMALMESSAGE(_message, ...) \
1384 MOS_NORMALMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _message, ##__VA_ARGS__)
1385
1386 //!
1387 //! \def MOS_OS_VERBOSEMESSAGE(_message, ...)
1388 //! MOS_VERBOSEMESSAGE \a _message with MOS Utility comp/subcomp info
1389 //!
1390 #define MOS_OS_VERBOSEMESSAGE(_message, ...) \
1391 MOS_VERBOSEMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _message, ##__VA_ARGS__)
1392
1393 //!
1394 //! \def MOS_OS_FUNCTION_ENTER
1395 //! Output ENTRY message with MOS Utility comp/subcomp info
1396 //!
1397 #define MOS_OS_FUNCTION_ENTER \
1398 MOS_FUNCTION_ENTER(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF)
1399
1400 //!
1401 //! \def MOS_OS_MEMNINJAMESSAGE(_message, ...)
1402 //! MOS_MEMNINJAMESSAGE \a _message with MOS Utility comp/subcomp info
1403 //!
1404 #define MOS_OS_MEMNINJAMESSAGE(_message, ...) \
1405 MOS_MEMNINJAMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF, _message, ##__VA_ARGS__)
1406
1407 #define MOS_OS_FUNCTION_TRACE() \
1408 MOS_FUNCTION_TRACE(MOS_COMPONENT_OS, MOS_SUBCOMP_SELF)
1409
1410 #include "mos_util_debug_specific.h"
1411
1412 #if MOS_MESSAGES_ENABLED
1413
1414 class FunctionTrace
1415 {
1416 public:
1417 FunctionTrace(MOS_COMPONENT_ID compID, uint8_t subCompID, const char* name) :
1418 m_compID(compID),
1419 m_subCompID(subCompID),
1420 m_name(name)
1421 {
1422 MOS_VERBOSEMESSAGE(m_compID, m_subCompID, "Enter Function:%s\r\n", m_name);
1423 }
1424
1425 virtual ~FunctionTrace()
1426 {
1427 MOS_VERBOSEMESSAGE(m_compID, m_subCompID, "Exit Function:%s\r\n", m_name);
1428 }
1429
1430 protected:
1431 MOS_COMPONENT_ID m_compID = MOS_COMPONENT_COUNT;
1432 uint8_t m_subCompID = 0;
1433 const char *m_name = nullptr;
1434 };
1435
1436 #define MOS_FUNCTION_TRACE(_compID, _subCompID) FunctionTrace trace(_compID, _subCompID, __FUNCTION__);
1437
1438 #else
1439
1440 #define MOS_FUNCTION_TRACE(_compID, _subCompID)
1441
1442 #endif // #if MOS_MESSAGES_ENABLED
1443 #endif // __MOS_UTIL_DEBUG_H__