1 /** @file wifi-mem.c
2 *
3 * @brief This file provides WIFI dymanic memory allocation APIs.
4 *
5 * Copyright 2008-2024 NXP
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 *
9 */
10 #include <mlan_api.h>
11 #include <string.h>
12 #include <osa.h>
13
14 #include <wifi-debug.h>
15
16 /* Simple memory allocator for Operating Systems that do not support dynamic
17 * allocation. The size of the allocation is hard-coded to the need of the cli
18 * module.
19 *
20 * If required this can be blown into a better slab-kind of allocator.
21 */
22 #define HUGE_BUF_SIZE 2000
23 static char buffhuge[HUGE_BUF_SIZE];
24
wifi_mem_malloc_cmdrespbuf(void)25 void *wifi_mem_malloc_cmdrespbuf(void)
26 {
27 /* NOTE: There is no corresponding free call for cmdrespbuf */
28 /* CMD are all serialised and they dont need any locking */
29 return buffhuge;
30 }
31
wifi_malloc_eventbuf(size_t size)32 void *wifi_malloc_eventbuf(size_t size)
33 {
34 #if !CONFIG_MEM_POOLS
35 void *ptr = OSA_MemoryAllocate(size);
36
37 if (ptr != NULL)
38 {
39 w_mem_d("[evtbuf] Alloc: A: %p S: %d", ptr, size);
40 }
41 else
42 {
43 w_mem_e("[evtbuf] Alloc: S: %d FAILED", size);
44 }
45 #else
46 void *ptr = OSA_MemoryPoolAllocate(buf_2048_MemoryPool);
47 #endif
48
49 return ptr;
50 }
51
wifi_free_eventbuf(void * buffer)52 void wifi_free_eventbuf(void *buffer)
53 {
54 #if !CONFIG_MEM_POOLS
55 w_mem_d("[evtbuf] Free: A: %p\n\r", buffer);
56 OSA_MemoryFree(buffer);
57 #else
58 OSA_MemoryPoolFree(buf_2048_MemoryPool, buffer);
59 #endif
60 }
61
wrapper_moal_malloc(IN t_void * pmoal_handle,IN t_u32 size,IN t_u32 flag,OUT t_u8 ** ppbuf)62 mlan_status wrapper_moal_malloc(IN t_void *pmoal_handle, IN t_u32 size, IN t_u32 flag, OUT t_u8 **ppbuf)
63 {
64 *ppbuf = OSA_MemoryAllocate(size);
65
66 #ifdef DEBUG_11N_ALLOC
67
68 #endif /* DEBUG_11N_ALLOC */
69
70 if (*ppbuf != NULL)
71 {
72 w_mem_d("[mlan]: Alloc: A: %p S: %d", *ppbuf, size);
73 return MLAN_STATUS_SUCCESS;
74 }
75 else
76 {
77 w_mem_e("[mlan] Alloc: S: %d FAILED", size);
78 /*
79 * fixme: check if MLAN_STATUS_SUCCESS is to be returned in
80 * spite of the status failure.
81 */
82 return MLAN_STATUS_FAILURE;
83 }
84 }
85
wrapper_moal_mfree(IN t_void * pmoal_handle,IN t_u8 * pbuf)86 mlan_status wrapper_moal_mfree(IN t_void *pmoal_handle, IN t_u8 *pbuf)
87 {
88 w_mem_d("[mlan] Free: A: %p", pbuf);
89 OSA_MemoryFree(pbuf);
90 return MLAN_STATUS_SUCCESS;
91 }
92