]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/ccree/cc_pal_log.h
Merge branches 'acpi-button' and 'acpi-tools'
[mirror_ubuntu-artful-kernel.git] / drivers / staging / ccree / cc_pal_log.h
1 /*
2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #ifndef _CC_PAL_LOG_H_
18 #define _CC_PAL_LOG_H_
19
20 #include "cc_pal_types.h"
21 #include "cc_pal_log_plat.h"
22
23 /*!
24 @file
25 @brief This file contains the PAL layer log definitions, by default the log is disabled.
26 @defgroup cc_pal_log CryptoCell PAL logging APIs and definitions
27 @{
28 @ingroup cc_pal
29 */
30
31 /* PAL log levels (to be used in CC_PAL_logLevel) */
32 /*! PAL log level - disabled. */
33 #define CC_PAL_LOG_LEVEL_NULL (-1) /*!< \internal Disable logging */
34 /*! PAL log level - error. */
35 #define CC_PAL_LOG_LEVEL_ERR 0
36 /*! PAL log level - warning. */
37 #define CC_PAL_LOG_LEVEL_WARN 1
38 /*! PAL log level - info. */
39 #define CC_PAL_LOG_LEVEL_INFO 2
40 /*! PAL log level - debug. */
41 #define CC_PAL_LOG_LEVEL_DEBUG 3
42 /*! PAL log level - trace. */
43 #define CC_PAL_LOG_LEVEL_TRACE 4
44 /*! PAL log level - data. */
45 #define CC_PAL_LOG_LEVEL_DATA 5
46
47 #ifndef CC_PAL_LOG_CUR_COMPONENT
48 /* Setting default component mask in case caller did not define */
49 /* (a mask that is always on for every log mask value but full masking) */
50 /*! Default log debugged component.*/
51 #define CC_PAL_LOG_CUR_COMPONENT 0xFFFFFFFF
52 #endif
53 #ifndef CC_PAL_LOG_CUR_COMPONENT_NAME
54 /*! Default log debugged component.*/
55 #define CC_PAL_LOG_CUR_COMPONENT_NAME "CC"
56 #endif
57
58 /* Select compile time log level (default if not explicitly specified by caller) */
59 #ifndef CC_PAL_MAX_LOG_LEVEL /* Can be overriden by external definition of this constant */
60 #ifdef DEBUG
61 /*! Default debug log level (when debug is set to on).*/
62 #define CC_PAL_MAX_LOG_LEVEL CC_PAL_LOG_LEVEL_ERR /*CC_PAL_LOG_LEVEL_DEBUG*/
63 #else /* Disable logging */
64 /*! Default debug log level (when debug is set to on).*/
65 #define CC_PAL_MAX_LOG_LEVEL CC_PAL_LOG_LEVEL_NULL
66 #endif
67 #endif /*CC_PAL_MAX_LOG_LEVEL*/
68 /*! Evaluate CC_PAL_MAX_LOG_LEVEL in case provided by caller */
69 #define __CC_PAL_LOG_LEVEL_EVAL(level) level
70 /*! Maximal log level defintion.*/
71 #define _CC_PAL_MAX_LOG_LEVEL __CC_PAL_LOG_LEVEL_EVAL(CC_PAL_MAX_LOG_LEVEL)
72
73
74 #ifdef ARM_DSM
75 /*! Log init function. */
76 #define CC_PalLogInit() do {} while (0)
77 /*! Log set level function - sets the level of logging in case of debug. */
78 #define CC_PalLogLevelSet(setLevel) do {} while (0)
79 /*! Log set mask function - sets the component masking in case of debug. */
80 #define CC_PalLogMaskSet(setMask) do {} while (0)
81 #else
82 #if _CC_PAL_MAX_LOG_LEVEL > CC_PAL_LOG_LEVEL_NULL
83 /*! Log init function. */
84 void CC_PalLogInit(void);
85 /*! Log set level function - sets the level of logging in case of debug. */
86 void CC_PalLogLevelSet(int setLevel);
87 /*! Log set mask function - sets the component masking in case of debug. */
88 void CC_PalLogMaskSet(uint32_t setMask);
89 /*! Global variable for log level */
90 extern int CC_PAL_logLevel;
91 /*! Global variable for log mask */
92 extern uint32_t CC_PAL_logMask;
93 #else /* No log */
94 /*! Log init function. */
95 static inline void CC_PalLogInit(void) {}
96 /*! Log set level function - sets the level of logging in case of debug. */
97 static inline void CC_PalLogLevelSet(int setLevel) {CC_UNUSED_PARAM(setLevel);}
98 /*! Log set mask function - sets the component masking in case of debug. */
99 static inline void CC_PalLogMaskSet(uint32_t setMask) {CC_UNUSED_PARAM(setMask);}
100 #endif
101 #endif
102
103 /*! Filter logging based on logMask and dispatch to platform specific logging mechanism. */
104 #define _CC_PAL_LOG(level, format, ...) \
105 if (CC_PAL_logMask & CC_PAL_LOG_CUR_COMPONENT) \
106 __CC_PAL_LOG_PLAT(CC_PAL_LOG_LEVEL_ ## level, "%s:%s: " format, CC_PAL_LOG_CUR_COMPONENT_NAME, __func__, ##__VA_ARGS__)
107
108 #if (_CC_PAL_MAX_LOG_LEVEL >= CC_PAL_LOG_LEVEL_ERR)
109 /*! Log messages according to log level.*/
110 #define CC_PAL_LOG_ERR(format, ... ) \
111 _CC_PAL_LOG(ERR, format, ##__VA_ARGS__)
112 #else
113 /*! Log messages according to log level.*/
114 #define CC_PAL_LOG_ERR( ... ) do {} while (0)
115 #endif
116
117 #if (_CC_PAL_MAX_LOG_LEVEL >= CC_PAL_LOG_LEVEL_WARN)
118 /*! Log messages according to log level.*/
119 #define CC_PAL_LOG_WARN(format, ... ) \
120 if (CC_PAL_logLevel >= CC_PAL_LOG_LEVEL_WARN) \
121 _CC_PAL_LOG(WARN, format, ##__VA_ARGS__)
122 #else
123 /*! Log messages according to log level.*/
124 #define CC_PAL_LOG_WARN( ... ) do {} while (0)
125 #endif
126
127 #if (_CC_PAL_MAX_LOG_LEVEL >= CC_PAL_LOG_LEVEL_INFO)
128 /*! Log messages according to log level.*/
129 #define CC_PAL_LOG_INFO(format, ... ) \
130 if (CC_PAL_logLevel >= CC_PAL_LOG_LEVEL_INFO) \
131 _CC_PAL_LOG(INFO, format, ##__VA_ARGS__)
132 #else
133 /*! Log messages according to log level.*/
134 #define CC_PAL_LOG_INFO( ... ) do {} while (0)
135 #endif
136
137 #if (_CC_PAL_MAX_LOG_LEVEL >= CC_PAL_LOG_LEVEL_DEBUG)
138 /*! Log messages according to log level.*/
139 #define CC_PAL_LOG_DEBUG(format, ... ) \
140 if (CC_PAL_logLevel >= CC_PAL_LOG_LEVEL_DEBUG) \
141 _CC_PAL_LOG(DEBUG, format, ##__VA_ARGS__)
142
143 /*! Log message buffer.*/
144 #define CC_PAL_LOG_DUMP_BUF(msg, buf, size) \
145 do { \
146 int i; \
147 uint8_t *pData = (uint8_t*)buf; \
148 \
149 PRINTF("%s (%d):\n", msg, size); \
150 for (i = 0; i < size; i++) { \
151 PRINTF("0x%02X ", pData[i]); \
152 if ((i & 0xF) == 0xF) { \
153 PRINTF("\n"); \
154 } \
155 } \
156 PRINTF("\n"); \
157 } while (0)
158 #else
159 /*! Log debug messages.*/
160 #define CC_PAL_LOG_DEBUG( ... ) do {} while (0)
161 /*! Log debug buffer.*/
162 #define CC_PAL_LOG_DUMP_BUF(msg, buf, size) do {} while (0)
163 #endif
164
165 #if (_CC_PAL_MAX_LOG_LEVEL >= CC_PAL_LOG_LEVEL_TRACE)
166 /*! Log debug trace.*/
167 #define CC_PAL_LOG_TRACE(format, ... ) \
168 if (CC_PAL_logLevel >= CC_PAL_LOG_LEVEL_TRACE) \
169 _CC_PAL_LOG(TRACE, format, ##__VA_ARGS__)
170 #else
171 /*! Log debug trace.*/
172 #define CC_PAL_LOG_TRACE(...) do {} while (0)
173 #endif
174
175 #if (_CC_PAL_MAX_LOG_LEVEL >= CC_PAL_LOG_LEVEL_TRACE)
176 /*! Log debug data.*/
177 #define CC_PAL_LOG_DATA(format, ...) \
178 if (CC_PAL_logLevel >= CC_PAL_LOG_LEVEL_TRACE) \
179 _CC_PAL_LOG(DATA, format, ##__VA_ARGS__)
180 #else
181 /*! Log debug data.*/
182 #define CC_PAL_LOG_DATA( ...) do {} while (0)
183 #endif
184 /**
185 @}
186 */
187
188 #endif /*_CC_PAL_LOG_H_*/