]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/assert_support.h
92fb15d047032ad9e0c3d3f5ea4c5dad4cce4742
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / hive_isp_css_include / assert_support.h
1 /*
2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15 #ifndef __ASSERT_SUPPORT_H_INCLUDED__
16 #define __ASSERT_SUPPORT_H_INCLUDED__
17
18 #include "storage_class.h"
19
20 /**
21 * The following macro can help to test the size of a struct at compile
22 * time rather than at run-time. It does not work for all compilers; see
23 * below.
24 *
25 * Depending on the value of 'condition', the following macro is expanded to:
26 * - condition==true:
27 * an expression containing an array declaration with negative size,
28 * usually resulting in a compilation error
29 * - condition==false:
30 * (void) 1; // C statement with no effect
31 *
32 * example:
33 * COMPILATION_ERROR_IF( sizeof(struct host_sp_queues) != SIZE_OF_HOST_SP_QUEUES_STRUCT);
34 *
35 * verify that the macro indeed triggers a compilation error with your compiler:
36 * COMPILATION_ERROR_IF( sizeof(struct host_sp_queues) != (sizeof(struct host_sp_queues)+1) );
37 *
38 * Not all compilers will trigger an error with this macro; use a search engine to search for
39 * BUILD_BUG_ON to find other methods.
40 */
41 #define COMPILATION_ERROR_IF(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
42
43 /* Compile time assertion */
44 #ifndef CT_ASSERT
45 #define CT_ASSERT(cnd) ((void)sizeof(char[(cnd)?1:-1]))
46 #endif /* CT_ASSERT */
47
48 #ifdef NDEBUG
49
50 #define assert(cnd) ((void)0)
51
52 #else
53
54 #if defined(_MSC_VER)
55 #ifdef _KERNEL_MODE
56 /* Windows kernel mode compilation */
57 #include <wdm.h>
58 #define assert(cnd) ASSERT(cnd)
59 #else
60 /* Windows usermode compilation */
61 #include <assert.h>
62 #endif
63
64 #elif defined(__KERNEL__)
65 #include <linux/bug.h>
66
67 /* TODO: it would be cleaner to use this:
68 * #define assert(cnd) BUG_ON(cnd)
69 * but that causes many compiler warnings (==errors) under Android
70 * because it seems that the BUG_ON() macro is not seen as a check by
71 * gcc like the BUG() macro is. */
72 #define assert(cnd) \
73 do { \
74 if (!(cnd)) \
75 BUG(); \
76 } while (0)
77
78 #elif defined(__FIST__) || defined(__GNUC__)
79
80 /* enable assert for crun */
81 #include "assert.h"
82
83 #else /* default for unknown environments */
84 #define assert(cnd) ((void)0)
85 #endif
86
87 #endif /* NDEBUG */
88
89 #ifndef PIPE_GENERATION
90 /* Deprecated OP___assert, this is still used in ~1000 places
91 * in the code. This will be removed over time.
92 * The implemenation for the pipe generation tool is in see support.isp.h */
93 #define OP___assert(cnd) assert(cnd)
94
95 STORAGE_CLASS_INLINE void compile_time_assert (unsigned cond)
96 {
97 /* Call undefined function if cond is false */
98 extern void _compile_time_assert (void);
99 if (!cond) _compile_time_assert();
100 }
101 #endif /* PIPE_GENERATION */
102
103 #endif /* __ASSERT_SUPPORT_H_INCLUDED__ */