3 * (C) COPYRIGHT ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
25 * Driver-wide include for common macros and types.
29 * @defgroup malisw Mali software definitions and types
35 #include "mali_stdtypes.h"
37 /** @brief Gets the container object when given a pointer to a member of an object. */
38 #define CONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type,member)))
40 /** @brief Gets the number of elements of type s in a fixed length array of s */
41 #define NELEMS(s) (sizeof(s)/sizeof((s)[0]))
44 * @brief The lesser of two values.
45 * May evaluate its arguments more than once.
48 #define MIN(x,y) CSTD_MIN(x,y)
51 * @brief The greater of two values.
52 * May evaluate its arguments more than once.
55 #define MAX(x,y) CSTD_MAX(x,y)
58 * @brief Clamp value x to within min and max inclusive
59 * May evaluate its arguments more than once.
62 #define CLAMP( x, min, max ) CSTD_CLAMP( x, min, max )
65 * @brief Convert a pointer into a u64 for storing in a data structure.
66 * This is commonly used when pairing a 32-bit CPU with a 64-bit peripheral,
67 * such as a Midgard GPU. C's type promotion is complex and a straight cast
68 * does not work reliably as pointers are often considered as signed.
70 #define PTR_TO_U64( x ) CSTD_PTR_TO_U64( x )
73 * @name Mali library linkage specifiers
74 * These directly map to the cstd versions described in detail here: @ref arm_cstd_linkage_specifiers
77 #define MALI_IMPORT CSTD_LINK_IMPORT
78 #define MALI_EXPORT CSTD_LINK_EXPORT
79 #define MALI_IMPL CSTD_LINK_IMPL
80 #define MALI_LOCAL CSTD_LINK_LOCAL
82 /** @brief Decorate exported function prototypes.
84 * The file containing the implementation of the function should define this to be MALI_EXPORT before including
85 * malisw/mali_malisw.h.
88 #define MALI_API MALI_IMPORT
92 /** @name Testable static functions
95 * These macros can be used to allow functions to be static in release builds but exported from a shared library in unit
96 * test builds, allowing them to be tested or used to assist testing.
98 * Example mali_foo_bar.c containing the function to test:
101 * #define MALI_API MALI_EXPORT
103 * #include <malisw/mali_malisw.h>
104 * #include "mali_foo_testable_statics.h"
106 * MALI_TESTABLE_STATIC_IMPL void my_func()
112 * Example mali_foo_testable_statics.h:
115 * #if 1 == MALI_UNIT_TEST
116 * #include <malisw/mali_malisw.h>
118 * MALI_TESTABLE_STATIC_API void my_func();
123 * Example mali_foo_tests.c:
126 * #include <foo/src/mali_foo_testable_statics.h>
128 * void my_test_func()
135 /** @brief Decorate testable static function implementations.
137 * A header file containing a MALI_TESTABLE_STATIC_API-decorated prototype for each static function will be required
138 * when MALI_UNIT_TEST == 1 in order to link the function from the test.
140 #if 1 == MALI_UNIT_TEST
141 #define MALI_TESTABLE_STATIC_IMPL MALI_IMPL
143 #define MALI_TESTABLE_STATIC_IMPL static
146 /** @brief Decorate testable static function prototypes.
148 * @note Prototypes should @em only be declared when MALI_UNIT_TEST == 1
150 #define MALI_TESTABLE_STATIC_API MALI_API
153 /** @name Testable local functions
156 * These macros can be used to allow functions to be local to a shared library in release builds but be exported in unit
157 * test builds, allowing them to be tested or used to assist testing.
159 * Example mali_foo_bar.c containing the function to test:
162 * #define MALI_API MALI_EXPORT
164 * #include <malisw/mali_malisw.h>
165 * #include "mali_foo_bar.h"
167 * MALI_TESTABLE_LOCAL_IMPL void my_func()
173 * Example mali_foo_bar.h:
176 * #include <malisw/mali_malisw.h>
178 * MALI_TESTABLE_LOCAL_API void my_func();
182 * Example mali_foo_tests.c:
185 * #include <foo/src/mali_foo_bar.h>
187 * void my_test_func()
194 /** @brief Decorate testable local function implementations.
196 * This can be used to have a function normally local to the shared library except in debug builds where it will be
199 #ifdef CONFIG_MALI_DEBUG
200 #define MALI_TESTABLE_LOCAL_IMPL MALI_IMPL
202 #define MALI_TESTABLE_LOCAL_IMPL MALI_LOCAL
203 #endif /* CONFIG_MALI_DEBUG */
205 /** @brief Decorate testable local function prototypes.
207 * This can be used to have a function normally local to the shared library except in debug builds where it will be
210 #ifdef CONFIG_MALI_DEBUG
211 #define MALI_TESTABLE_LOCAL_API MALI_API
213 #define MALI_TESTABLE_LOCAL_API MALI_LOCAL
214 #endif /* CONFIG_MALI_DEBUG */
218 * Flag a cast as a reinterpretation, usually of a pointer type.
219 * @see CSTD_REINTERPRET_CAST
221 #define REINTERPRET_CAST(type) CSTD_REINTERPRET_CAST(type)
224 * Flag a cast as casting away const, usually of a pointer type.
225 * @see CSTD_CONST_CAST
227 #define CONST_CAST(type) (type) CSTD_CONST_CAST(type)
230 * Flag a cast as a (potentially complex) value conversion, usually of a numerical type.
231 * @see CSTD_STATIC_CAST
233 #define STATIC_CAST(type) (type) CSTD_STATIC_CAST(type)
238 #endif /* _MALISW_H_ */