]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - drivers/staging/wilc1000/wilc_memory.h
Merge tag 'tegra-for-4.3-cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-eoan-kernel.git] / drivers / staging / wilc1000 / wilc_memory.h
1 #ifndef __WILC_MEMORY_H__
2 #define __WILC_MEMORY_H__
3
4 /*!
5 * @file wilc_memory.h
6 * @brief Memory OS wrapper functionality
7 * @author syounan
8 * @sa wilc_oswrapper.h top level OS wrapper file
9 * @date 16 Aug 2010
10 * @version 1.0
11 */
12
13 #include <linux/types.h>
14 #include <linux/slab.h>
15
16 /*!
17 * @struct tstrWILC_MemoryAttrs
18 * @brief Memory API options
19 * @author syounan
20 * @date 16 Aug 2010
21 * @version 1.0
22 */
23 typedef struct {
24 } tstrWILC_MemoryAttrs;
25
26 /*!
27 * @brief Allocates a given size of bytes
28 * @param[in] u32Size size of memory in bytes to be allocated
29 * @param[in] strAttrs Optional attributes, NULL for default
30 * if not NULL, pAllocationPool should point to the pool to use for
31 * this allocation. if NULL memory will be allocated directly from
32 * the system
33 * @param[in] pcFileName file name of the calling code for debugging
34 * @param[in] u32LineNo line number of the calling code for debugging
35 * @return The new allocated block, NULL if allocation fails
36 * @note It is recommended to use of of the wrapper macros instead of
37 * calling this function directly
38 * @sa sttrWILC_MemoryAttrs
39 * @sa WILC_MALLOC
40 * @sa WILC_MALLOC_EX
41 * @sa WILC_NEW
42 * @sa WILC_NEW_EX
43 * @author syounan
44 * @date 16 Aug 2010
45 * @version 1.0
46 */
47 void *WILC_MemoryAlloc(u32 u32Size, tstrWILC_MemoryAttrs *strAttrs,
48 char *pcFileName, u32 u32LineNo);
49
50 /*!
51 * @brief Allocates a given size of bytes and zero filling it
52 * @param[in] u32Size size of memory in bytes to be allocated
53 * @param[in] strAttrs Optional attributes, NULL for default
54 * if not NULL, pAllocationPool should point to the pool to use for
55 * this allocation. if NULL memory will be allocated directly from
56 * the system
57 * @param[in] pcFileName file name of the calling code for debugging
58 * @param[in] u32LineNo line number of the calling code for debugging
59 * @return The new allocated block, NULL if allocation fails
60 * @note It is recommended to use of of the wrapper macros instead of
61 * calling this function directly
62 * @sa sttrWILC_MemoryAttrs
63 * @sa WILC_CALLOC
64 * @sa WILC_CALLOC_EX
65 * @sa WILC_NEW_0
66 * @sa WILC_NEW_0_EX
67 * @author syounan
68 * @date 16 Aug 2010
69 * @version 1.0
70 */
71 void *WILC_MemoryCalloc(u32 u32Size, tstrWILC_MemoryAttrs *strAttrs,
72 char *pcFileName, u32 u32LineNo);
73
74 /*!
75 * @brief Reallocates a given block to a new size
76 * @param[in] pvOldBlock the old memory block, if NULL then this function
77 * behaves as a new allocation function
78 * @param[in] u32NewSize size of the new memory block in bytes, if zero then
79 * this function behaves as a free function
80 * @param[in] strAttrs Optional attributes, NULL for default
81 * if pAllocationPool!=NULL and pvOldBlock==NULL, pAllocationPool
82 * should point to the pool to use for this allocation.
83 * if pAllocationPool==NULL and pvOldBlock==NULL memory will be
84 * allocated directly from the system
85 * if and pvOldBlock!=NULL, pAllocationPool will not be inspected
86 * and reallocation is done from the same pool as the original block
87 * @param[in] pcFileName file name of the calling code for debugging
88 * @param[in] u32LineNo line number of the calling code for debugging
89 * @return The new allocated block, possibly same as pvOldBlock
90 * @note It is recommended to use of of the wrapper macros instead of
91 * calling this function directly
92 * @sa sttrWILC_MemoryAttrs
93 * @sa WILC_REALLOC
94 * @sa WILC_REALLOC_EX
95 * @author syounan
96 * @date 16 Aug 2010
97 * @version 1.0
98 */
99 void *WILC_MemoryRealloc(void *pvOldBlock, u32 u32NewSize,
100 tstrWILC_MemoryAttrs *strAttrs, char *pcFileName, u32 u32LineNo);
101
102 /*!
103 * @brief Frees given block
104 * @param[in] pvBlock the memory block to be freed
105 * @param[in] strAttrs Optional attributes, NULL for default
106 * @param[in] pcFileName file name of the calling code for debugging
107 * @param[in] u32LineNo line number of the calling code for debugging
108 * @note It is recommended to use of of the wrapper macros instead of
109 * calling this function directly
110 * @sa sttrWILC_MemoryAttrs
111 * @sa WILC_FREE
112 * @sa WILC_FREE_EX
113 * @sa WILC_FREE_SET_NULL
114 * @sa WILC_FREE_IF_TRUE
115 * @author syounan
116 * @date 16 Aug 2010
117 * @version 1.0
118 */
119 void WILC_MemoryFree(const void *pvBlock, tstrWILC_MemoryAttrs *strAttrs,
120 char *pcFileName, u32 u32LineNo);
121
122 /*!
123 * @brief standrad malloc wrapper with custom attributes
124 */
125 #define WILC_MALLOC_EX(__size__, __attrs__) \
126 (WILC_MemoryAlloc( \
127 (__size__), __attrs__, NULL, 0))
128
129 /*!
130 * @brief standrad calloc wrapper with custom attributes
131 */
132 #define WILC_CALLOC_EX(__size__, __attrs__) \
133 (WILC_MemoryCalloc( \
134 (__size__), __attrs__, NULL, 0))
135
136 /*!
137 * @brief standrad realloc wrapper with custom attributes
138 */
139 #define WILC_REALLOC_EX(__ptr__, __new_size__, __attrs__) \
140 (WILC_MemoryRealloc( \
141 (__ptr__), (__new_size__), __attrs__, NULL, 0))
142 /*!
143 * @brief standrad free wrapper with custom attributes
144 */
145 #define WILC_FREE_EX(__ptr__, __attrs__) \
146 (WILC_MemoryFree( \
147 (__ptr__), __attrs__, NULL, 0))
148
149 /*!
150 * @brief Allocates a block (with custom attributes) of given type and number of
151 * elements
152 */
153 #define WILC_NEW_EX(__struct_type__, __n_structs__, __attrs__) \
154 ((__struct_type__ *)WILC_MALLOC_EX( \
155 sizeof(__struct_type__) * (u32)(__n_structs__), __attrs__))
156
157 /*!
158 * @brief Allocates a block (with custom attributes) of given type and number of
159 * elements and Zero-fills it
160 */
161 #define WILC_NEW_0_EX(__struct_type__, __n_structs__, __attrs__) \
162 ((__struct_type__ *)WILC_CALLOC_EX( \
163 sizeof(__struct_type__) * (u32)(__n_structs__), __attrs__))
164
165 /*!
166 * @brief Frees a block (with custom attributes), also setting the original pointer
167 * to NULL
168 */
169 #define WILC_FREE_SET_NULL_EX(__ptr__, __attrs__) do { \
170 if (__ptr__ != NULL) { \
171 WILC_FREE_EX(__ptr__, __attrs__); \
172 __ptr__ = NULL; \
173 } \
174 } while (0)
175
176 /*!
177 * @brief Frees a block (with custom attributes) if the pointer expression evaluates
178 * to true
179 */
180 #define WILC_FREE_IF_TRUE_EX(__ptr__, __attrs__) do { \
181 if (__ptr__ != NULL) { \
182 WILC_FREE_EX(__ptr__, __attrs__); \
183 } \
184 } while (0)
185
186 /*!
187 * @brief standrad malloc wrapper with default attributes
188 */
189 #define WILC_MALLOC(__size__) \
190 WILC_MALLOC_EX(__size__, NULL)
191
192 /*!
193 * @brief standrad calloc wrapper with default attributes
194 */
195 #define WILC_CALLOC(__size__) \
196 WILC_CALLOC_EX(__size__, NULL)
197
198 /*!
199 * @brief standrad realloc wrapper with default attributes
200 */
201 #define WILC_REALLOC(__ptr__, __new_size__) \
202 WILC_REALLOC_EX(__ptr__, __new_size__, NULL)
203
204 /*!
205 * @brief standrad free wrapper with default attributes
206 */
207 #define WILC_FREE(__ptr__) \
208 WILC_FREE_EX(__ptr__, NULL)
209
210 /*!
211 * @brief Allocates a block (with default attributes) of given type and number of
212 * elements
213 */
214 #define WILC_NEW(__struct_type__, __n_structs__) \
215 WILC_NEW_EX(__struct_type__, __n_structs__, NULL)
216
217 /*!
218 * @brief Allocates a block (with default attributes) of given type and number of
219 * elements and Zero-fills it
220 */
221 #define WILC_NEW_0(__struct_type__, __n_structs__) \
222 WILC_NEW_O_EX(__struct_type__, __n_structs__, NULL)
223
224 /*!
225 * @brief Frees a block (with default attributes), also setting the original pointer
226 * to NULL
227 */
228 #define WILC_FREE_SET_NULL(__ptr__) \
229 WILC_FREE_SET_NULL_EX(__ptr__, NULL)
230
231 /*!
232 * @brief Frees a block (with default attributes) if the pointer expression evaluates
233 * to true
234 */
235 #define WILC_FREE_IF_TRUE(__ptr__) \
236 WILC_FREE_IF_TRUE_EX(__ptr__, NULL)
237
238
239 #endif