Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved. |
| 3 | * |
| 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. |
| 20 | */ |
| 21 | |
| 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 | |
| 28 | #if !defined(__CDF_MEMORY_H) |
| 29 | #define __CDF_MEMORY_H |
| 30 | |
| 31 | /** |
| 32 | * DOC: cdf_memory |
| 33 | * |
| 34 | * Connectivity driver framework (CDF) memory management APIs |
| 35 | */ |
| 36 | |
| 37 | /* Include Files */ |
| 38 | #include <cdf_types.h> |
| 39 | |
| 40 | /* Preprocessor definitions and constants */ |
| 41 | |
| 42 | #ifdef MEMORY_DEBUG |
| 43 | void cdf_mem_clean(void); |
| 44 | void cdf_mem_init(void); |
| 45 | void cdf_mem_exit(void); |
| 46 | #else |
| 47 | /** |
| 48 | * cdf_mem_init() - initialize cdf memory debug functionality |
| 49 | * |
| 50 | * Return: none |
| 51 | */ |
| 52 | static inline void cdf_mem_init(void) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * cdf_mem_exit() - exit cdf memory debug functionality |
| 58 | * |
| 59 | * Return: none |
| 60 | */ |
| 61 | static inline void cdf_mem_exit(void) |
| 62 | { |
| 63 | } |
| 64 | #endif |
| 65 | /* Type declarations */ |
| 66 | |
| 67 | /* Function declarations and documenation */ |
| 68 | |
| 69 | /** |
| 70 | * cdf_mem_malloc() - allocation CDF memory |
| 71 | * @size: Number of bytes of memory to allocate. |
| 72 | * |
| 73 | * This function will dynamicallly allocate the specified number of bytes of |
| 74 | * memory. |
| 75 | * |
| 76 | * |
| 77 | * Return: |
| 78 | * Upon successful allocate, returns a non-NULL pointer to the allocated |
| 79 | * memory. If this function is unable to allocate the amount of memory |
| 80 | * specified (for any reason) it returns %NULL. |
| 81 | * |
| 82 | */ |
| 83 | #ifdef MEMORY_DEBUG |
| 84 | #define cdf_mem_malloc(size) cdf_mem_malloc_debug(size, __FILE__, __LINE__) |
| 85 | void *cdf_mem_malloc_debug(size_t size, char *fileName, uint32_t lineNum); |
| 86 | #else |
| 87 | void *cdf_mem_malloc(size_t size); |
| 88 | #endif |
| 89 | |
| 90 | /** |
| 91 | * cdf_mem_free() - free CDF memory |
| 92 | * @ptr: Pointer to the starting address of the memory to be free'd. |
| 93 | * |
| 94 | * This function will free the memory pointed to by 'ptr'. |
| 95 | * |
| 96 | * Return: |
| 97 | * Nothing |
| 98 | * |
| 99 | */ |
| 100 | void cdf_mem_free(void *ptr); |
| 101 | |
| 102 | /** |
| 103 | * cdf_mem_set() - set (fill) memory with a specified byte value. |
| 104 | * @pMemory: Pointer to memory that will be set |
| 105 | * @numBytes: Number of bytes to be set |
| 106 | * @value: Byte set in memory |
| 107 | * |
| 108 | * Return: |
| 109 | * Nothing |
| 110 | * |
| 111 | */ |
| 112 | void cdf_mem_set(void *ptr, uint32_t numBytes, uint32_t value); |
| 113 | |
| 114 | /** |
| 115 | * cdf_mem_zero() - zero out memory |
| 116 | * @pMemory: pointer to memory that will be set to zero |
| 117 | * @numBytes: number of bytes zero |
| 118 | * @value: byte set in memory |
| 119 | * |
| 120 | * This function sets the memory location to all zeros, essentially clearing |
| 121 | * the memory. |
| 122 | * |
| 123 | * Return: |
| 124 | * Nothing |
| 125 | * |
| 126 | */ |
| 127 | void cdf_mem_zero(void *ptr, uint32_t numBytes); |
| 128 | |
| 129 | /** |
| 130 | * cdf_mem_copy() - copy memory |
| 131 | * @pDst: Pointer to destination memory location (to copy to) |
| 132 | * @pSrc: Pointer to source memory location (to copy from) |
| 133 | * @numBytes: Number of bytes to copy. |
| 134 | * |
| 135 | * Copy host memory from one location to another, similar to memcpy in |
| 136 | * standard C. Note this function does not specifically handle overlapping |
| 137 | * source and destination memory locations. Calling this function with |
| 138 | * overlapping source and destination memory locations will result in |
| 139 | * unpredictable results. Use cdf_mem_move() if the memory locations |
| 140 | * for the source and destination are overlapping (or could be overlapping!) |
| 141 | * |
| 142 | * Return: |
| 143 | * Nothing |
| 144 | * |
| 145 | */ |
| 146 | void cdf_mem_copy(void *pDst, const void *pSrc, uint32_t numBytes); |
| 147 | |
| 148 | /** |
| 149 | * cdf_mem_move() - move memory |
| 150 | * @pDst: pointer to destination memory location (to move to) |
| 151 | * @pSrc: pointer to source memory location (to move from) |
| 152 | * @numBytes: number of bytes to move. |
| 153 | * |
| 154 | * Move host memory from one location to another, similar to memmove in |
| 155 | * standard C. Note this function *does* handle overlapping |
| 156 | * source and destination memory locations. |
| 157 | |
| 158 | * Return: |
| 159 | * Nothing |
| 160 | */ |
| 161 | void cdf_mem_move(void *pDst, const void *pSrc, uint32_t numBytes); |
| 162 | |
| 163 | /** |
| 164 | * cdf_mem_compare() - memory compare |
| 165 | * @pMemory1: pointer to one location in memory to compare. |
| 166 | * @pMemory2: pointer to second location in memory to compare. |
| 167 | * @numBytes: the number of bytes to compare. |
| 168 | * |
| 169 | * Function to compare two pieces of memory, similar to memcmp function |
| 170 | * in standard C. |
| 171 | * |
| 172 | * Return: |
| 173 | * bool - returns a bool value that tells if the memory locations |
| 174 | * are equal or not equal. |
| 175 | * |
| 176 | */ |
| 177 | bool cdf_mem_compare(const void *pMemory1, const void *pMemory2, |
| 178 | uint32_t numBytes); |
| 179 | |
| 180 | /** |
| 181 | * cdf_mem_compare2() - memory compare |
| 182 | * @pMemory1: pointer to one location in memory to compare. |
| 183 | * @pMemory2: pointer to second location in memory to compare. |
| 184 | * @numBytes: the number of bytes to compare. |
| 185 | * |
| 186 | * Function to compare two pieces of memory, similar to memcmp function |
| 187 | * in standard C. |
| 188 | * Return: |
| 189 | * int32_t - returns a bool value that tells if the memory |
| 190 | * locations are equal or not equal. |
| 191 | * 0 -- equal |
| 192 | * < 0 -- *pMemory1 is less than *pMemory2 |
| 193 | * > 0 -- *pMemory1 is bigger than *pMemory2 |
| 194 | */ |
| 195 | int32_t cdf_mem_compare2(const void *pMemory1, const void *pMemory2, |
| 196 | uint32_t numBytes); |
| 197 | |
| 198 | void *cdf_os_mem_alloc_consistent(cdf_device_t osdev, cdf_size_t size, |
| 199 | cdf_dma_addr_t *paddr, |
| 200 | cdf_dma_context_t mctx); |
| 201 | void |
| 202 | cdf_os_mem_free_consistent(cdf_device_t osdev, |
| 203 | cdf_size_t size, |
| 204 | void *vaddr, |
| 205 | cdf_dma_addr_t paddr, cdf_dma_context_t memctx); |
| 206 | |
| 207 | void |
| 208 | cdf_os_mem_dma_sync_single_for_device(cdf_device_t osdev, |
| 209 | cdf_dma_addr_t bus_addr, |
| 210 | cdf_size_t size, |
| 211 | enum dma_data_direction direction); |
| 212 | |
| 213 | /** |
| 214 | * cdf_str_len() - returns the length of a string |
| 215 | * @str: input string |
| 216 | * |
| 217 | * Return: |
| 218 | * length of string |
| 219 | */ |
| 220 | static inline int32_t cdf_str_len(const char *str) |
| 221 | { |
| 222 | return strlen(str); |
| 223 | } |
| 224 | |
| 225 | #endif /* __CDF_MEMORY_H */ |