summaryrefslogtreecommitdiff
path: root/drivers/mxc/security/sahara2/include/diagnostic.h
blob: 57f84d4cbb050998ad33edffce733be56da1ee57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

/*!
* @file    diagnostic.h
*
* @brief   Macros for outputting kernel and user space diagnostics.
*/

#ifndef DIAGNOSTIC_H
#define DIAGNOSTIC_H

#ifndef __KERNEL__		/* linux flag */
#include <stdio.h>
#endif
#include "fsl_platform.h"

#if defined(FSL_HAVE_SAHARA2) || defined(FSL_HAVE_SAHARA4)
#define DEV_NAME "sahara"
#elif defined(FSL_HAVE_RNGA) || defined(FSL_HAVE_RNGB) ||                     \
      defined(FSL_HAVE_RNGC)
#define DEV_NAME "shw"
#endif

/*!
********************************************************************
* @brief   This macro logs diagnostic messages to stderr.
*
* @param   diag  String that must be logged, char *.
*
* @return   void
*
*/
//#if defined DIAG_SECURITY_FUNC || defined DIAG_ADAPTOR
#define LOG_DIAG(diag)                                              \
({                                                                  \
    const char* fname = strrchr(__FILE__, '/');                           \
                                                                    \
     sah_Log_Diag(fname ? fname+1 : __FILE__, __LINE__, diag);     \
})

#ifdef __KERNEL__

#define LOG_DIAG_ARGS(fmt, ...)                                               \
({                                                                            \
    const char* fname = strrchr(__FILE__, '/');                               \
    os_printk(KERN_ALERT "%s:%i: " fmt "\n",                                  \
              fname ? fname+1 : __FILE__,                                     \
              __LINE__,                                                       \
              __VA_ARGS__);                                                   \
})

#else

#define LOG_DIAG_ARGS(fmt, ...)                                               \
({                                                                            \
    const char* fname = strrchr(__FILE__, '/');                               \
    printf("%s:%i: " fmt "\n",                                                \
           fname ? fname+1 : __FILE__,                                        \
           __LINE__,                                                          \
           __VA_ARGS__);                                                      \
})

#ifndef __KERNEL__
void sah_Log_Diag(char *source_name, int source_line, char *diag);
#endif
#endif /* if define DIAG_SECURITY_FUNC ... */

#ifdef __KERNEL__
/*!
********************************************************************
* @brief   This macro logs kernel diagnostic  messages to the kernel
*          log.
*
* @param   diag  String that must be logged, char *.
*
* @return  As for printf()
*/
#if 0
#if defined(DIAG_DRV_IF) || defined(DIAG_DRV_QUEUE) ||                        \
  defined(DIAG_DRV_STATUS) || defined(DIAG_DRV_INTERRUPT) ||                  \
   defined(DIAG_MEM) || defined(DIAG_SECURITY_FUNC) || defined(DIAG_ADAPTOR)
#endif
#endif

#define LOG_KDIAG_ARGS(fmt, ...)                                              \
({                                                                            \
    os_printk (KERN_ALERT "%s (%s:%i): " fmt "\n",                            \
               DEV_NAME, strrchr(__FILE__, '/')+1, __LINE__, __VA_ARGS__);              \
})

#define LOG_KDIAG(diag)                                                       \
    os_printk (KERN_ALERT "%s (%s:%i): %s\n",                             \
               DEV_NAME, strrchr(__FILE__, '/')+1, __LINE__, diag);

#define sah_Log_Diag(n, l, d)                                                 \
    os_printk(KERN_ALERT "%s:%i: %s\n", n, l, d)

#else				/* not KERNEL */

#define sah_Log_Diag(n, l, d)                                                 \
    printf("%s:%i: %s\n", n, l, d)

#endif				/* __KERNEL__ */

#endif				/* DIAGNOSTIC_H */