3 /*****************************************************************************
5 (c) Cambridge Silicon Radio Limited 2010
6 All rights reserved and confidential information of CSR
8 Refer to LICENSE.txt included with this source for details
11 *****************************************************************************/
13 #include <linux/types.h>
14 #include "csr_macro.h"
20 /*****************************************************************************
26 This function is equivalent to CsrPmemAlloc, but the allocated memory
27 is initialised to zero.
30 size - Size of memory requested. Note that a size of 0 is valid.
33 Pointer to allocated memory.
35 *****************************************************************************/
36 #define CsrPmemZalloc(s) (CsrMemSet(CsrPmemAlloc(s), 0x00, (s)))
39 /*****************************************************************************
45 Type-safe wrappers for CsrPmemAlloc and CsrPmemZalloc, for allocating
46 single instances of a specified and named type.
51 *****************************************************************************/
52 #define pnew(t) ((t *) (CsrPmemAlloc(sizeof(t))))
53 #define zpnew(t) ((t *) (CsrPmemZalloc(sizeof(t))))
56 /*----------------------------------------------------------------------------*
57 * Csr Pmem Debug code. Allows custom callbacks on CsrPmemAlloc and CsrPmemFree
58 *----------------------------------------------------------------------------*/
59 #ifdef CSR_PMEM_DEBUG_ENABLE
61 typedef u8 CsrPmemDebugAllocType;
62 #define CSR_PMEM_DEBUG_TYPE_PMEM_ALLOC 1
63 #define CSR_PMEM_DEBUG_TYPE_MEM_ALLOC 2
64 #define CSR_PMEM_DEBUG_TYPE_MEM_CALLOC 3
65 #define CSR_PMEM_DEBUG_TYPE_MEM_ALLOC_DMA 4
67 typedef void (CsrPmemDebugOnAlloc)(void *ptr, void *userptr, size_t size, CsrPmemDebugAllocType type, const char* file, u32 line);
68 typedef void (CsrPmemDebugOnFree)(void *ptr, void *userptr, CsrPmemDebugAllocType type, const char* file, u32 line);
70 /*----------------------------------------------------------------------------*
75 * Install debug hooks for memory allocation
76 * Use NULL values to uninstall the hooks
77 * headSize = The number of extra bytes to allocate in the head of the Allocated buffer
78 * footSize = The number of extra bytes to allocate in the end of the Allocated buffer
83 *----------------------------------------------------------------------------*/
84 void CsrPmemDebugInstallHooks(u8 headSize, u8 endSize, CsrPmemDebugOnAlloc *onAllocCallback, CsrPmemDebugOnFree *onFreeCallback);
86 void *CsrPmemDebugAlloc(size_t size, CsrPmemDebugAllocType type, const char* file, u32 line);
88 void CsrPmemDebugFree(void *ptr, CsrPmemDebugAllocType type, const char* file, u32 line);