1fb74fa0d1c7178ed39d8d9b6d187502879d5a75
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / csr / csr_pmem.h
1 #ifndef CSR_PMEM_H__
2 #define CSR_PMEM_H__
3 /*****************************************************************************
4
5             (c) Cambridge Silicon Radio Limited 2010
6             All rights reserved and confidential information of CSR
7
8             Refer to LICENSE.txt included with this source for details
9             on the license terms.
10
11 *****************************************************************************/
12
13 #include <linux/types.h>
14 #include "csr_macro.h"
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 /*****************************************************************************
21
22     NAME
23         CsrPmemZalloc
24
25     DESCRIPTION
26         This function is equivalent to CsrPmemAlloc, but the allocated memory
27         is initialised to zero.
28
29     PARAMETERS
30         size - Size of memory requested. Note that a size of 0 is valid.
31
32     RETURNS
33         Pointer to allocated memory.
34
35 *****************************************************************************/
36 #define CsrPmemZalloc(s) (CsrMemSet(CsrPmemAlloc(s), 0x00, (s)))
37
38
39 /*****************************************************************************
40
41     NAME
42         pnew and zpnew
43
44     DESCRIPTIOM
45         Type-safe wrappers for CsrPmemAlloc and CsrPmemZalloc, for allocating
46         single instances of a specified and named type.
47
48     PARAMETERS
49         t - type to allocate.
50
51 *****************************************************************************/
52 #define pnew(t) ((t *) (CsrPmemAlloc(sizeof(t))))
53 #define zpnew(t) ((t *) (CsrPmemZalloc(sizeof(t))))
54
55
56 /*----------------------------------------------------------------------------*
57  * Csr Pmem Debug code. Allows custom callbacks on CsrPmemAlloc and CsrPmemFree
58  *----------------------------------------------------------------------------*/
59 #ifdef CSR_PMEM_DEBUG_ENABLE
60
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
66
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);
69
70 /*----------------------------------------------------------------------------*
71  *  NAME
72  *      CsrPmemInstallHooks
73  *
74  *  DESCRIPTION
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
79  *
80  *  RETURNS
81  *      void
82  *
83  *----------------------------------------------------------------------------*/
84 void CsrPmemDebugInstallHooks(u8 headSize, u8 endSize, CsrPmemDebugOnAlloc *onAllocCallback, CsrPmemDebugOnFree *onFreeCallback);
85
86 void *CsrPmemDebugAlloc(size_t size, CsrPmemDebugAllocType type, const char* file, u32 line);
87
88 void CsrPmemDebugFree(void *ptr, CsrPmemDebugAllocType type, const char* file, u32 line);
89
90 #endif
91
92
93 #ifdef __cplusplus
94 }
95 #endif
96
97 #endif