staging: csr: remove CsrCharString typedef
[deliverable/linux.git] / drivers / staging / csr / csr_pmem.h
CommitLineData
635d2b00
GKH
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 "csr_types.h"
14#include "csr_util.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#ifndef CSR_PMEM_DEBUG_ENABLE
21/*****************************************************************************
22
23 NAME
24 CsrPmemAlloc
25
26 DESCRIPTION
27 This function will allocate a contiguous block of memory of at least
28 the specified size in bytes and return a pointer to the allocated
29 memory. This function is not allowed to return NULL. A size of 0 is a
30 valid request, and a unique and valid (not NULL) pointer must be
31 returned in this case.
32
33 PARAMETERS
34 size - Size of memory requested. Note that a size of 0 is valid.
35
36 RETURNS
37 Pointer to allocated memory.
38
39*****************************************************************************/
40#ifdef CSR_PMEM_DEBUG
41void *CsrPmemAllocDebug(CsrSize size,
c781b96b 42 const char *file, u32 line);
635d2b00
GKH
43#define CsrPmemAlloc(sz) CsrPmemAllocDebug((sz), __FILE__, __LINE__)
44#else
45void *CsrPmemAlloc(CsrSize size);
46#endif
47
48
49/*****************************************************************************
50
51 NAME
52 CsrPmemFree
53
54 DESCRIPTION
55 This function will deallocate a previously allocated block of memory.
56
57 PARAMETERS
58 ptr - Pointer to allocated memory.
59
60*****************************************************************************/
61void CsrPmemFree(void *ptr);
62#endif
63
64/*****************************************************************************
65
66 NAME
67 CsrPmemZalloc
68
69 DESCRIPTION
70 This function is equivalent to CsrPmemAlloc, but the allocated memory
71 is initialised to zero.
72
73 PARAMETERS
74 size - Size of memory requested. Note that a size of 0 is valid.
75
76 RETURNS
77 Pointer to allocated memory.
78
79*****************************************************************************/
80#define CsrPmemZalloc(s) (CsrMemSet(CsrPmemAlloc(s), 0x00, (s)))
81
82
83/*****************************************************************************
84
85 NAME
86 pnew and zpnew
87
88 DESCRIPTIOM
89 Type-safe wrappers for CsrPmemAlloc and CsrPmemZalloc, for allocating
90 single instances of a specified and named type.
91
92 PARAMETERS
93 t - type to allocate.
94
95*****************************************************************************/
96#define pnew(t) ((t *) (CsrPmemAlloc(sizeof(t))))
97#define zpnew(t) ((t *) (CsrPmemZalloc(sizeof(t))))
98
99
100/*----------------------------------------------------------------------------*
101 * Csr Pmem Debug code. Allows custom callbacks on CsrPmemAlloc and CsrPmemFree
102 *----------------------------------------------------------------------------*/
103#ifdef CSR_PMEM_DEBUG_ENABLE
104
7e6f5794 105typedef u8 CsrPmemDebugAllocType;
635d2b00
GKH
106#define CSR_PMEM_DEBUG_TYPE_PMEM_ALLOC 1
107#define CSR_PMEM_DEBUG_TYPE_MEM_ALLOC 2
108#define CSR_PMEM_DEBUG_TYPE_MEM_CALLOC 3
109#define CSR_PMEM_DEBUG_TYPE_MEM_ALLOC_DMA 4
110
c781b96b
GKH
111typedef void (CsrPmemDebugOnAlloc)(void *ptr, void *userptr, CsrSize size, CsrPmemDebugAllocType type, const char* file, u32 line);
112typedef void (CsrPmemDebugOnFree)(void *ptr, void *userptr, CsrPmemDebugAllocType type, const char* file, u32 line);
635d2b00
GKH
113
114/*----------------------------------------------------------------------------*
115 * NAME
116 * CsrPmemInstallHooks
117 *
118 * DESCRIPTION
119 * Install debug hooks for memory allocation
120 * Use NULL values to uninstall the hooks
121 * headSize = The number of extra bytes to allocate in the head of the Allocated buffer
122 * footSize = The number of extra bytes to allocate in the end of the Allocated buffer
123 *
124 * RETURNS
125 * void
126 *
127 *----------------------------------------------------------------------------*/
7e6f5794 128void CsrPmemDebugInstallHooks(u8 headSize, u8 endSize, CsrPmemDebugOnAlloc *onAllocCallback, CsrPmemDebugOnFree *onFreeCallback);
635d2b00 129
c781b96b 130void *CsrPmemDebugAlloc(CsrSize size, CsrPmemDebugAllocType type, const char* file, u32 line);
635d2b00
GKH
131#define CsrPmemAlloc(size) CsrPmemDebugAlloc(size, CSR_PMEM_DEBUG_TYPE_PMEM_ALLOC, __FILE__, __LINE__)
132
c781b96b 133void CsrPmemDebugFree(void *ptr, CsrPmemDebugAllocType type, const char* file, u32 line);
635d2b00
GKH
134#define CsrPmemFree(ptr) CsrPmemDebugFree(ptr, CSR_PMEM_DEBUG_TYPE_PMEM_ALLOC, __FILE__, __LINE__)
135
136#endif
137
138
139#ifdef __cplusplus
140}
141#endif
142
143#endif
This page took 0.045035 seconds and 5 git commands to generate.