blob: fd064c6f5957c42fadd4ab33fa0c45a22e8f8fc2 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kapil Guptab3a981b2016-06-26 13:36:51 +05302 * Copyright (c) 2012-2016 The Linux Foundation. All rights reserved.
Kiet Lam1ed83fc2014-02-19 01:15:45 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam1ed83fc2014-02-19 01:15:45 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Jeff Johnson295189b2012-06-20 16:38:30 -070028#if !defined( __VOS_MEMORY_H )
29#define __VOS_MEMORY_H
30
31/**=========================================================================
32
33 \file vos_memory.h
34
35 \brief virtual Operating System Servies (vOSS)
36
37 Memory management functions
38
Jeff Johnson295189b2012-06-20 16:38:30 -070039
40 ========================================================================*/
41
42/* $Header$ */
43
44/*--------------------------------------------------------------------------
45 Include Files
46 ------------------------------------------------------------------------*/
47#include <vos_types.h>
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +053048#include <linux/version.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070049/*--------------------------------------------------------------------------
50 Preprocessor definitions and constants
51 ------------------------------------------------------------------------*/
52
53#ifdef MEMORY_DEBUG
54v_VOID_t vos_mem_init(v_VOID_t);
55v_VOID_t vos_mem_exit(v_VOID_t);
56void vos_mem_clean(void);
57#endif
58
59/*--------------------------------------------------------------------------
60 Type declarations
61 ------------------------------------------------------------------------*/
62
63
64/*-------------------------------------------------------------------------
65 Function declarations and documenation
66 ------------------------------------------------------------------------*/
67
68/*----------------------------------------------------------------------------
69
70 \brief vos_mem_malloc() - vOSS Memory Allocation
71
72 This function will dynamicallly allocate the specified number of bytes of
73 memory.
74
75 \param size - the number of bytes of memory to allocate.
76
77 \return Upon successful allocate, returns a non-NULL pointer to the
78 allocated memory. If this function is unable to allocate the amount of
79 memory specified (for any reason) it returns NULL.
80
81 \sa
82
83 --------------------------------------------------------------------------*/
84#ifdef MEMORY_DEBUG
85#define vos_mem_malloc(size) vos_mem_malloc_debug(size, __FILE__, __LINE__)
86v_VOID_t * vos_mem_malloc_debug( v_SIZE_t size, char* fileName, v_U32_t lineNum);
87#else
88v_VOID_t * vos_mem_malloc( v_SIZE_t size );
89#endif
90
91
92/*----------------------------------------------------------------------------
93
94 \brief vos_mem_free() - vOSS Free Memory
95
96 This function will free the memory pointed to by 'ptr'.
97
98 \param ptr - pointer to the starting address of the memory to be
99 free'd.
100
101 \return Nothing
102
103 \sa
104
105 --------------------------------------------------------------------------*/
106v_VOID_t vos_mem_free( v_VOID_t *ptr );
107
108
109/*----------------------------------------------------------------------------
110
111 \fn vos_mem_set() - set (fill) memory with a specified byte value.
112
113 \param pMemory - pointer to memory that will be set
114
115 \param numBytes - the number of bytes to be set
116
117 \param value - the byte set in memory
118
119 \return - Nothing.
120
121 \sa vos_mem_zero()
122
123 --------------------------------------------------------------------------*/
124v_VOID_t vos_mem_set( v_VOID_t *ptr, v_SIZE_t numBytes, v_BYTE_t value );
125
126
127/*----------------------------------------------------------------------------
128
129 \fn vos_mem_zero() - zero out memory
130
131 This function sets the memory location to all zeros, essentially clearing
132 the memory.
133
134 \param pMemory - pointer to memory that will be set to zero
135
136 \param numBytes - the number of bytes zero
137
138 \param value - the byte set in memory
139
140 \return - Nothing.
141
142 \sa vos_mem_set()
143
144 --------------------------------------------------------------------------*/
145v_VOID_t vos_mem_zero( v_VOID_t *ptr, v_SIZE_t numBytes );
146
Kapil Guptab3a981b2016-06-26 13:36:51 +0530147static __inline__ unsigned long vos_htonl(unsigned long ul)
148{
149 return( ( ( ul & 0x000000ff ) << 24 ) |
150 ( ( ul & 0x0000ff00 ) << 8 ) |
151 ( ( ul & 0x00ff0000 ) >> 8 ) |
152 ( ( ul & 0xff000000 ) >> 24 ) );
153}
Jeff Johnson295189b2012-06-20 16:38:30 -0700154
Kapil Guptab3a981b2016-06-26 13:36:51 +0530155void vos_buff_to_hl_buff (v_U8_t *buffer, int size);
Jeff Johnson295189b2012-06-20 16:38:30 -0700156/*----------------------------------------------------------------------------
157
158 \brief vos_mem_copy() - Copy memory
159
160 Copy host memory from one location to another, similar to memcpy in
161 standard C. Note this function does not specifically handle overlapping
162 source and destination memory locations. Calling this function with
163 overlapping source and destination memory locations will result in
164 unpredictable results. Use vos_mem_move() if the memory locations
165 for the source and destination are overlapping (or could be overlapping!)
166
167 \param pDst - pointer to destination memory location (to copy to)
168
169 \param pSrc - pointer to source memory location (to copy from)
170
171 \param numBytes - number of bytes to copy.
172
173 \return - Nothing
174
175 \sa vos_mem_move()
176
177 --------------------------------------------------------------------------*/
178v_VOID_t vos_mem_copy( v_VOID_t *pDst, const v_VOID_t *pSrc, v_SIZE_t numBytes );
179
180
181/*----------------------------------------------------------------------------
182
183 \brief vos_mem_move() - Move memory
184
185 Move host memory from one location to another, similar to memmove in
186 standard C. Note this function *does* handle overlapping
187 source and destination memory locations.
188
189 \param pDst - pointer to destination memory location (to move to)
190
191 \param pSrc - pointer to source memory location (to move from)
192
193 \param numBytes - number of bytes to move.
194
195 \return - Nothing
196
197 \sa vos_mem_move()
198
199 --------------------------------------------------------------------------*/
200v_VOID_t vos_mem_move( v_VOID_t *pDst, const v_VOID_t *pSrc, v_SIZE_t numBytes );
201
202/** ---------------------------------------------------------------------------
203
204 \fn vos_mem_compare()
205
206 \brief vos_mem_compare() - Memory compare
207
208 Function to compare two pieces of memory, similar to memcmp function
209 in standard C.
210
211 \param pMemory1 - pointer to one location in memory to compare.
212
213 \param pMemory2 - pointer to second location in memory to compare.
214
215 \param numBytes - the number of bytes to compare.
216
217 \return v_BOOL_t - returns a boolean value that tells if the memory
218 locations are equal or not equal.
219
220 -------------------------------------------------------------------------------*/
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +0530221v_BOOL_t vos_mem_compare(
222#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
223 const v_VOID_t *pMemory1,
224#else
225 v_VOID_t *pMemory1,
226#endif
227#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
228 const v_VOID_t *pMemory2,
229#else
230 v_VOID_t *pMemory2,
231#endif
232 v_U32_t numBytes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700233
234
235/** ---------------------------------------------------------------------------
236
237 \fn vos_mem_compare2()
238
239 \brief vos_mem_compare2() - Memory compare
240
241 Function to compare two pieces of memory, similar to memcmp function
242 in standard C.
243
244 \param pMemory1 - pointer to one location in memory to compare.
245
246 \param pMemory2 - pointer to second location in memory to compare.
247
248 \param numBytes - the number of bytes to compare.
249
250 \return v_SINT_t - returns a boolean value that tells if the memory
251 locations are equal or not equal.
252 0 -- equal
253 < 0 -- *pMemory1 is less than *pMemory2
254 > 0 -- *pMemory1 is bigger than *pMemory2
255
256 -------------------------------------------------------------------------------*/
257v_SINT_t vos_mem_compare2( v_VOID_t *pMemory1, v_VOID_t *pMemory2, v_U32_t numBytes );
258
259
260/*----------------------------------------------------------------------------
261
262 \brief vos_mem_dma_malloc() - vOSS DMA Memory Allocation
263
264 This function will dynamicallly allocate the specified number of bytes of
265 memory. This memory will have special attributes making it DMA friendly i.e.
266 it will exist in contiguous, 32-byte aligned uncached memory. A normal
267 vos_mem_malloc does not yield memory with these attributes.
268
269 NOTE: the special DMA friendly memory is very scarce and this API must be
270 used sparingly
271
272 \param size - the number of bytes of memory to allocate.
273
274 \return Upon successful allocate, returns a non-NULL pointer to the
275 allocated memory. If this function is unable to allocate the amount of
276 memory specified (for any reason) it returns NULL.
277
278 \sa
279
280 --------------------------------------------------------------------------*/
281#ifdef MEMORY_DEBUG
282#define vos_mem_dma_malloc(size) vos_mem_dma_malloc_debug(size, __FILE__, __LINE__)
283v_VOID_t * vos_mem_dma_malloc_debug( v_SIZE_t size, char* fileName, v_U32_t lineNum);
284#else
285v_VOID_t * vos_mem_dma_malloc( v_SIZE_t size );
286#endif
287
288
289/*----------------------------------------------------------------------------
290
291 \brief vos_mem_dma_free() - vOSS DMA Free Memory
292
293 This function will free special DMA friendly memory pointed to by 'ptr'.
294
295 \param ptr - pointer to the starting address of the memory to be
296 free'd.
297
298 \return Nothing
299
300 \sa
301
302 --------------------------------------------------------------------------*/
303v_VOID_t vos_mem_dma_free( v_VOID_t *ptr );
304
305#ifdef DMA_DIRECT_ACCESS
306/*----------------------------------------------------------------------------
307
308 \brief vos_mem_set_dma_ptr() - vOSS DMA memory poiter set by SAL
309
310 This function will set DMA Physical memory pointer.
311
312
313 \param dmaBuffer - pointer to the starting address of the memory to be
314 free'd.
315
316 \return Nothing
317
318 \sa
319
320 --------------------------------------------------------------------------*/
321v_VOID_t vos_mem_set_dma_ptr(unsigned char *dmaBuffer);
322#endif /* DMA_DIRECT_ACCESS */
Hanumantha Reddy Pothula72342952015-02-26 14:43:54 +0530323
324
325/*----------------------------------------------------------------------------
326
327 \brief vos_mem_vmalloc() - allocate memory which is virtually contiguous
328
329 Wrapper function for vmalloc
330
331 \param size memory size to be allocated
332
333 \return on success returns starting address of allocated memory or NULL
334
335 --------------------------------------------------------------------------*/
336v_VOID_t * vos_mem_vmalloc(v_SIZE_t size);
337
338/*----------------------------------------------------------------------------
339
340 \brief vos_mem_vfree() - free memory allocated by vmalloc
341
342 Wrapper function for vfree
343
344 \param address starting address of the memory to be freed
345
346 \return Nothing
347
348 --------------------------------------------------------------------------*/
349v_VOID_t vos_mem_vfree(void *addr);
350
Jeff Johnson295189b2012-06-20 16:38:30 -0700351#endif // __VOSS_LOCK_H