]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - test/k2h/c66/bios/rm_osal.c
Resolved SDOCM00112612: Memory leak when extracting resources via Linux DTB
[keystone-rtos/rm-lld.git] / test / k2h / c66 / bios / rm_osal.c
1 /**
2  *   @file  rm_osal.c
3  *
4  *   @brief
5  *      This is the OS abstraction layer used by the Resource Manager.
6  *
7  *  \par
8  *  ============================================================================
9  *  @n   (C) Copyright 2012-2013, Texas Instruments, Inc.
10  *
11  *  Redistribution and use in source and binary forms, with or without
12  *  modification, are permitted provided that the following conditions
13  *  are met:
14  *
15  *    Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  *
18  *    Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the
21  *    distribution.
22  *
23  *    Neither the name of Texas Instruments Incorporated nor the names of
24  *    its contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  *  \par
40 */
42 /* Standard Includes */
43 #include <stdarg.h>
45 /* XDC Includes */
46 #include <xdc/std.h>
47 #include <xdc/runtime/Memory.h>
48 #include <xdc/runtime/Error.h>
49 #include <xdc/runtime/System.h>
51 /* BIOS Includes */
52 #include <ti/sysbios/BIOS.h>
53 #include <ti/sysbios/hal/Hwi.h>
54 #include <ti/sysbios/knl/Semaphore.h>
56 /* CSL includes */
57 #include <ti/csl/csl_cacheAux.h>
58 #include <ti/csl/csl_xmcAux.h>
60 /**********************************************************************
61  ****************************** Defines *******************************
62  **********************************************************************/
64 /**********************************************************************
65  ************************** Global Variables **************************
66  **********************************************************************/
67 uint32_t rmMallocCounter = 0;
68 uint32_t rmFreeCounter   = 0;
70 int32_t rmByteAlloc = 0;
71 int32_t rmByteFree = 0;
73 /**********************************************************************
74  *************************** OSAL Functions **************************
75  **********************************************************************/
77 /* FUNCTION PURPOSE: Allocates memory
78  ***********************************************************************
79  * DESCRIPTION: The function is used to allocate a memory block of the
80  *              specified size.
81  */
82 void *Osal_rmMalloc (uint32_t num_bytes)
83 {
84         Error_Block     errorBlock;
86     /* Increment the allocation counter. */
87     rmMallocCounter++;
88     rmByteAlloc += num_bytes;
90         /* Allocate memory. */
91         return Memory_alloc(NULL, num_bytes, 0, &errorBlock);
92 }
94 /* FUNCTION PURPOSE: Frees memory
95  ***********************************************************************
96  * DESCRIPTION: The function is used to free a memory block of the
97  *              specified size.
98  */ 
99 void Osal_rmFree (void *ptr, uint32_t size)
101     /* Increment the free counter. */
102     rmFreeCounter++;
103     rmByteFree += size;
104         Memory_free(NULL, ptr, size);
107 /* FUNCTION PURPOSE: Critical section enter
108  ***********************************************************************
109  * DESCRIPTION: The function is used to enter a critical section.
110  *              Function protects against 
111  *      
112  *              access from multiple cores 
113  *              and 
114  *              access from multiple threads on single core
115  */  
116 void *Osal_rmCsEnter(void)
119     return NULL;
122 /* FUNCTION PURPOSE: Critical section exit
123  ***********************************************************************
124  * DESCRIPTION: The function is used to exit a critical section 
125  *              protected using Osal_cppiCsEnter() API.
126  */  
127 void Osal_rmCsExit(void *CsHandle)
132 /* FUNCTION PURPOSE: Cache invalidate
133  ***********************************************************************
134  * DESCRIPTION: The function is used to indicate that a block of memory is 
135  *              about to be accessed. If the memory block is cached then this 
136  *              indicates that the application would need to ensure that the 
137  *              cache is updated with the data from the actual memory.
138  */  
139 void Osal_rmBeginMemAccess(void *ptr, uint32_t size)
141     uint32_t    key;
143     /* Disable Interrupts */
144     key = Hwi_disable();
146     /* Cleanup the prefetch buffer also. */
147     CSL_XMC_invalidatePrefetchBuffer();
149 #ifdef L2_CACHE
150     /* Invalidate L2 cache. This should invalidate L1D as well. 
151      * Wait until operation is complete. */    
152     CACHE_invL2 (ptr, size, CACHE_FENCE_WAIT);
153 #else       
154     /* Invalidate L1D cache and wait until operation is complete. 
155      * Use this approach if L2 cache is not enabled */    
156     CACHE_invL1d (ptr, size, CACHE_FENCE_WAIT);
157 #endif
159     /* Reenable Interrupts. */
160     Hwi_restore(key);
162     return;
165 /* FUNCTION PURPOSE: Cache writeback
166  ***********************************************************************
167  * DESCRIPTION: The function is used to indicate that the block of memory has 
168  *              finished being accessed. If the memory block is cached then the 
169  *              application would need to ensure that the contents of the cache 
170  *              are updated immediately to the actual memory. 
171  */  
172 void Osal_rmEndMemAccess(void *ptr, uint32_t size)
174     uint32_t    key;
176     /* Disable Interrupts */
177     key = Hwi_disable();
179 #ifdef L2_CACHE
180     /* Writeback L2 cache. This should Writeback L1D as well. 
181      * Wait until operation is complete. */ 
182     CACHE_wbL2 (ptr, size, CACHE_FENCE_WAIT);
184 #else    
185     /* Writeback L1D cache and wait until operation is complete. 
186      * Use this approach if L2 cache is not enabled */    
187     CACHE_wbL1d (ptr, size, CACHE_FENCE_WAIT);
188 #endif
190     /* Reenable Interrupts. */
191     Hwi_restore(key);
193     return;
196 /* FUNCTION PURPOSE: Creates a task blocking object
197  ***********************************************************************
198  * DESCRIPTION: The function is used to create a task blocking object
199  *              capable of blocking the task a RM instance is running
200  *              within
201  */
202 void *Osal_rmTaskBlockCreate(void)
204     Semaphore_Params semParams;    
206     Semaphore_Params_init(&semParams);
207     return((void *)Semaphore_create(0, &semParams, NULL));
210 /* FUNCTION PURPOSE: Blocks a RM instance
211  ***********************************************************************
212  * DESCRIPTION: The function is used to block a task whose context a
213  *              RM instance is running within.
214  */
215 void Osal_rmTaskBlock(void *handle)
217     Semaphore_pend((Semaphore_Handle)handle, BIOS_WAIT_FOREVER);
220 /* FUNCTION PURPOSE: unBlocks a RM instance
221  ***********************************************************************
222  * DESCRIPTION: The function is used to unblock a task whose context a
223  *              RM instance is running within.
224  */
225 void Osal_rmTaskUnblock(void *handle)
227     Semaphore_post((Semaphore_Handle)handle);
230 /* FUNCTION PURPOSE: Deletes a task blocking object
231  ***********************************************************************
232  * DESCRIPTION: The function is used to delete a task blocking object
233  *              provided to a RM instance
234  */
235 void Osal_rmTaskBlockDelete(void *handle)
237     Semaphore_delete((Semaphore_Handle *)&handle);
240 /* FUNCTION PURPOSE: Prints a variable list
241  ***********************************************************************
242  * DESCRIPTION: The function is used to print a string to the console
243  */
244 void Osal_rmLog (char *fmt, ... )
246     VaList ap;
247     
248     va_start(ap, fmt);
249     System_vprintf(fmt, ap);
250     va_end(ap);