1 /*
2 * Copyright (c) 2019-2023, 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_bufmgr_util_debug.h
24 //! \brief
25 //! \brief    Bufmgr Debug and Print utilities
26 //! \details  Provides assert and print to debug console functionality
27 //!           All Bufmgr debug and print utilities will only function in debug or
28 //!           release internal drivers, in a release driver they will be NOPs.
29 //!           To enable log in mos bufmgr by bellow config:
30 //!           [config]
31 //!           Mos Message Tags=4
32 //!           Mos Sub Components Tags=15728640 //uint32_t(24:21) -> (F00000)
33 //!           Mos Tags By Sub Component=1
34 //!
35 #ifndef __MOS_BUFMGR_UTIL_DEBUG_H__
36 #define __MOS_BUFMGR_UTIL_DEBUG_H__
37 #include "mos_util_debug.h"
38 
39 //
40 //!
41 //! \def MOS_CHK_STATUS_MESSAGE_RETURN_WH_OP(_compID, _subCompID, _stmt, _ptr, _freeFunc, _message, ...)
42 //!  Check MOS_STATUS \a _stmt, assert and return an error for failure, and print message, and delete given ptr
43 //!
44 #define MOS_CHK_STATUS_MESSAGE_RETURN_VALUE_WH_OP(_compID, _subCompID, _stmt, _ptr, _freeFunc, _retVal, _message, ...)\
45 {                                                                               \
46     MOS_STATUS stmtStatus = (MOS_STATUS)(_stmt);                                \
47     if (stmtStatus != MOS_STATUS_SUCCESS)                                       \
48     {                                                                           \
49         if(_ptr)                                                                \
50             _freeFunc(_ptr);                                                    \
51         MOS_ASSERTMESSAGE(_compID, _subCompID, _message, ##__VA_ARGS__);        \
52         MT_ERR3(MT_ERR_MOS_STATUS_CHECK, MT_COMPONENT, _compID, MT_SUB_COMPONENT, _subCompID, MT_ERROR_CODE, stmtStatus); \
53         return _retVal;                                                         \
54     }                                                                           \
55 }
56 
57 //!
58 //! \def MOS_DRM_CHK_NULL_NO_STATUS_RETURN(_ptr)
59 //!  MOS_ASSERTMESSAGE \a _ptr with MOS utility comp/subcomp info without returning a status
60 //!
61 #define MOS_DRM_CHK_NULL_NO_STATUS_RETURN(_ptr)                                                               \
62     MOS_CHK_NULL_NO_STATUS_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _ptr)
63 
64 //!
65 //! \def MOS_DRM_CHK_NULL_RETURN(_ptr)
66 //!  MOS_CHK_NULL \a _ptr with MOS utility comp/subcomp info
67 //!
68 #define MOS_DRM_CHK_NULL_RETURN(_ptr)                                                               \
69     MOS_CHK_NULL_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _ptr)
70 
71 //!
72 //! \def MOS_DRM_CHK_NULL_RETURN_VALUE(_ptr, retVal)
73 //!  MOS_CHK_COND_RETURN_VALUE \a _ptr with MOS utility comp/subcomp info
74 //!
75 #define MOS_DRM_CHK_NULL_RETURN_VALUE(_ptr, retVal)                                         \
76     MOS_CHK_COND_RETURN_VALUE(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, (_ptr == nullptr), retVal, "Invalid (nullptr) Pointer.")
77 
78 //!
79 //! \def MOS_DRM_CHK_NULL_MESSAGE_RETURN(_ptr)
80 //!  MOS_CHK_NULL \a _ptr with MOS utility comp/subcomp info
81 //!
82 #define MOS_DRM_CHK_NULL_MESSAGE_RETURN(_ptr, _message, ...) \
83     MOS_CHK_NULL_MESSAGE_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _ptr, _message,  ##__VA_ARGS__)
84 
85 //!
86 //! \def MOS_DRM_CHECK_CONDITION(_condition, _str, _ret)
87 //!  MOS_CHECK_CONDITION \a _condition with MOS utility comp/subcomp info
88 //!
89 #define MOS_DRM_CHECK_CONDITION(_condition, _str, _ret)                                      \
90    MOS_CHECK_CONDITION(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _condition, _str, _ret)
91 
92 //!
93 //! \def MOS_DRM_ASSERT(_expr)
94 //!  MOS_ASSERT \a _expr with MOS Utility comp/subcomp info
95 //!
96 #define MOS_DRM_ASSERT(_expr)                                                                \
97     MOS_ASSERT(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _expr)
98 
99 //!
100 //! \def MOS_DRM_CHK_STATUS(_stmt)
101 //!  MOS_CHK_STATUS \a _stmt with MOS utility comp/subcomp info
102 //!
103 #define MOS_DRM_CHK_STATUS_RETURN(_stmt)                                                            \
104     MOS_CHK_STATUS_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _stmt)
105 
106 //!
107 //! \def MOS_DRM_CHK_STATUS_MESSAGE_RETURN(_stmt, _message, ......)
108 //!  MOS_CHK_STATUS \a _stmt with MOS utility comp/subcomp info
109 //!
110 #define MOS_DRM_CHK_STATUS_MESSAGE_RETURN(_stmt, _message, ...)                                  \
111     MOS_CHK_STATUS_MESSAGE_RETURN(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _stmt, _message, ##__VA_ARGS__)
112 
113 //!
114 //! \def MOS_DRM_CHK_STATUS_MESSAGE_RETURN_WH_OP(_stmt, _ptr, _freeFunc, _message, ...)
115 //!  MOS_CHK_STATUS \a _stmt with MOS utility comp/subcomp info
116 //!
117 #define MOS_DRM_CHK_STATUS_MESSAGE_RETURN_WH_OP(_stmt, _ptr, _freeFunc, _message, ...)                                  \
118     MOS_CHK_STATUS_MESSAGE_RETURN_VALUE_WH_OP(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _stmt, _ptr, _freeFunc, _stmt, _message, ##__VA_ARGS__)
119 
120 //!
121 //! \def MOS_DRM_CHK_STATUS_MESSAGE_RETURN_VALUE_WH_OP(_stmt, _ptr, _freeFunc, _retVal, _message, ...)
122 //!  MOS_CHK_STATUS \a _stmt with MOS utility comp/subcomp info
123 //!
124 #define MOS_DRM_CHK_STATUS_MESSAGE_RETURN_VALUE_WH_OP(_stmt, _ptr, _freeFunc, _retVal, _message, ...)                                  \
125     MOS_CHK_STATUS_MESSAGE_RETURN_VALUE_WH_OP(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _stmt, _ptr, _freeFunc, _retVal, _message, ##__VA_ARGS__)
126 
127 //!
128 //! \def MOS_DRM_ASSERTMESSAGE(_message, ...)
129 //!  MOS_ASSERTMESSAGE \a _message with MOS Utility comp/subcomp info
130 //!
131 #define MOS_DRM_ASSERTMESSAGE(_message, ...)                                                 \
132     MOS_ASSERTMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _message, ##__VA_ARGS__)
133 
134 //!
135 //! \def MOS_DRM_CRITICALMESSAGE(_message, ...)
136 //!  MOS_CRITICALMESSAGE \a _message with MOS Utility comp/subcomp info
137 //!
138 #define MOS_DRM_CRITICALMESSAGE(_message, ...)                                                 \
139     MOS_CRITICALMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _message, ##__VA_ARGS__)
140 
141 //!
142 //! \def MOS_DRM_NORMALMESSAGE(_message, ...)
143 //!  MOS_UTIL_NORMALMESSAGE \a _message with MOS Utility comp/subcomp info
144 //!
145 #define MOS_DRM_NORMALMESSAGE(_message, ...)                                                 \
146     MOS_NORMALMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _message, ##__VA_ARGS__)
147 
148 //!
149 //! \def MOS_DRM_VERBOSEMESSAGE(_message, ...)
150 //!  MOS_VERBOSEMESSAGE \a _message with MOS Utility comp/subcomp info
151 //!
152 #define MOS_DRM_VERBOSEMESSAGE(_message, ...)                                                \
153     MOS_VERBOSEMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _message, ##__VA_ARGS__)
154 
155 //!
156 //! \def MOS_DRM_FUNCTION_ENTER
157 //!  Output ENTRY message with MOS Utility comp/subcomp info
158 //!
159 #define MOS_DRM_FUNCTION_ENTER                                                               \
160     MOS_FUNCTION_ENTER(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT)
161 
162 //!
163 //! \def MOS_DRM_MEMNINJAMESSAGE(_message, ...)
164 //!  MOS_MEMNINJAMESSAGE \a _message with MOS Utility comp/subcomp info
165 //!
166 #define MOS_DRM_MEMNINJAMESSAGE(_message, ...)                                               \
167     MOS_MEMNINJAMESSAGE(MOS_COMPONENT_OS, MOS_SUBCOMP_EXT, _message, ##__VA_ARGS__)
168 
169 
170 #endif //__MOS_BUFMGR_UTIL_DEBUG_H__
171