]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - drivers/staging/wilc1000/wilc_memory.h
1 #ifndef __WILC_MEMORY_H__
2 #define __WILC_MEMORY_H__
6 * @brief Memory OS wrapper functionality
8 * @sa wilc_oswrapper.h top level OS wrapper file
13 #include <linux/types.h>
14 #include <linux/slab.h>
17 * @struct tstrWILC_MemoryAttrs
18 * @brief Memory API options
24 } tstrWILC_MemoryAttrs
;
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
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
47 void *WILC_MemoryAlloc(u32 u32Size
, tstrWILC_MemoryAttrs
*strAttrs
,
48 char *pcFileName
, u32 u32LineNo
);
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
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
71 void *WILC_MemoryCalloc(u32 u32Size
, tstrWILC_MemoryAttrs
*strAttrs
,
72 char *pcFileName
, u32 u32LineNo
);
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
99 void *WILC_MemoryRealloc(void *pvOldBlock
, u32 u32NewSize
,
100 tstrWILC_MemoryAttrs
*strAttrs
, char *pcFileName
, u32 u32LineNo
);
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
113 * @sa WILC_FREE_SET_NULL
114 * @sa WILC_FREE_IF_TRUE
119 void WILC_MemoryFree(const void *pvBlock
, tstrWILC_MemoryAttrs
*strAttrs
,
120 char *pcFileName
, u32 u32LineNo
);
123 * @brief standrad malloc wrapper with custom attributes
125 #define WILC_MALLOC_EX(__size__, __attrs__) \
127 (__size__), __attrs__, NULL, 0))
130 * @brief standrad calloc wrapper with custom attributes
132 #define WILC_CALLOC_EX(__size__, __attrs__) \
133 (WILC_MemoryCalloc( \
134 (__size__), __attrs__, NULL, 0))
137 * @brief standrad realloc wrapper with custom attributes
139 #define WILC_REALLOC_EX(__ptr__, __new_size__, __attrs__) \
140 (WILC_MemoryRealloc( \
141 (__ptr__), (__new_size__), __attrs__, NULL, 0))
143 * @brief standrad free wrapper with custom attributes
145 #define WILC_FREE_EX(__ptr__, __attrs__) \
147 (__ptr__), __attrs__, NULL, 0))
150 * @brief Allocates a block (with custom attributes) of given type and number of
153 #define WILC_NEW_EX(__struct_type__, __n_structs__, __attrs__) \
154 ((__struct_type__ *)WILC_MALLOC_EX( \
155 sizeof(__struct_type__) * (u32)(__n_structs__), __attrs__))
158 * @brief Allocates a block (with custom attributes) of given type and number of
159 * elements and Zero-fills it
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__))
166 * @brief Frees a block (with custom attributes), also setting the original pointer
169 #define WILC_FREE_SET_NULL_EX(__ptr__, __attrs__) do { \
170 if (__ptr__ != NULL) { \
171 WILC_FREE_EX(__ptr__, __attrs__); \
177 * @brief Frees a block (with custom attributes) if the pointer expression evaluates
180 #define WILC_FREE_IF_TRUE_EX(__ptr__, __attrs__) do { \
181 if (__ptr__ != NULL) { \
182 WILC_FREE_EX(__ptr__, __attrs__); \
187 * @brief standrad malloc wrapper with default attributes
189 #define WILC_MALLOC(__size__) \
190 WILC_MALLOC_EX(__size__, NULL)
193 * @brief standrad calloc wrapper with default attributes
195 #define WILC_CALLOC(__size__) \
196 WILC_CALLOC_EX(__size__, NULL)
199 * @brief standrad realloc wrapper with default attributes
201 #define WILC_REALLOC(__ptr__, __new_size__) \
202 WILC_REALLOC_EX(__ptr__, __new_size__, NULL)
205 * @brief standrad free wrapper with default attributes
207 #define WILC_FREE(__ptr__) \
208 WILC_FREE_EX(__ptr__, NULL)
211 * @brief Allocates a block (with default attributes) of given type and number of
214 #define WILC_NEW(__struct_type__, __n_structs__) \
215 WILC_NEW_EX(__struct_type__, __n_structs__, NULL)
218 * @brief Allocates a block (with default attributes) of given type and number of
219 * elements and Zero-fills it
221 #define WILC_NEW_0(__struct_type__, __n_structs__) \
222 WILC_NEW_O_EX(__struct_type__, __n_structs__, NULL)
225 * @brief Frees a block (with default attributes), also setting the original pointer
228 #define WILC_FREE_SET_NULL(__ptr__) \
229 WILC_FREE_SET_NULL_EX(__ptr__, NULL)
232 * @brief Frees a block (with default attributes) if the pointer expression evaluates
235 #define WILC_FREE_IF_TRUE(__ptr__) \
236 WILC_FREE_IF_TRUE_EX(__ptr__, NULL)