diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-11-25 16:47:20 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-11-27 10:33:30 +0100 |
commit | 038faca16018945b65249e0e3c332effb5dec82b (patch) | |
tree | 8a8f529d9f66eb5d687adfdbf2afde01a45604f8 /cpukit/libcsupport | |
parent | tools/build/*.c: Clean up issues reported by CodeSonar (diff) | |
download | rtems-038faca16018945b65249e0e3c332effb5dec82b.tar.bz2 |
rtems: Add rtems_cache_coherent_allocate()
Add rtems_cache_coherent_free() and rtems_cache_coherent_add_area().
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r-- | cpukit/libcsupport/Makefile.am | 1 | ||||
-rw-r--r-- | cpukit/libcsupport/src/cachecoherentalloc.c | 122 |
2 files changed, 123 insertions, 0 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index 95c85c4ede..dfa8736ee0 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -109,6 +109,7 @@ MALLOC_C_FILES = src/malloc_initialize.c src/calloc.c src/malloc.c \ src/rtems_heap_extend.c \ src/rtems_heap_greedy.c MALLOC_C_FILES += src/cachealignedalloc.c +MALLOC_C_FILES += src/cachecoherentalloc.c PASSWORD_GROUP_C_FILES = src/pwdgrp.c PASSWORD_GROUP_C_FILES += src/getgrent.c diff --git a/cpukit/libcsupport/src/cachecoherentalloc.c b/cpukit/libcsupport/src/cachecoherentalloc.c new file mode 100644 index 0000000000..bf8167de88 --- /dev/null +++ b/cpukit/libcsupport/src/cachecoherentalloc.c @@ -0,0 +1,122 @@ +/** + * @file + * + * @ingroup ClassicCache + */ + +/* + * Copyright (c) 2014 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * <rtems@embedded-brains.de> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#if HAVE_CONFIG_H + #include "config.h" +#endif + +#include <rtems.h> +#include <rtems/malloc.h> +#include <rtems/score/apimutex.h> +#include <rtems/score/heapimpl.h> +#include <rtems/score/sysstate.h> + +static Heap_Control cache_coherent_heap_instance; + +static Heap_Control *cache_coherent_heap; + +void *rtems_cache_coherent_allocate( + size_t size, + uintptr_t alignment, + uintptr_t boundary +) +{ + void *ptr; + Heap_Control *heap; + + _RTEMS_Lock_allocator(); + + heap = cache_coherent_heap; + if ( heap == NULL ) { + heap = RTEMS_Malloc_Heap; + } + + ptr = _Heap_Allocate_aligned_with_boundary( + heap, + size, + alignment, + boundary + ); + + _RTEMS_Unlock_allocator(); + + return ptr; +} + +void rtems_cache_coherent_free( void *ptr ) +{ + Heap_Control *heap; + + _RTEMS_Lock_allocator(); + + heap = cache_coherent_heap; + if ( heap != NULL ) { + if ( _Heap_Free( heap, ptr ) ) { + heap = NULL; + } else { + heap = RTEMS_Malloc_Heap; + } + } else { + heap = RTEMS_Malloc_Heap; + } + + if ( heap != NULL ) { + _Heap_Free( heap, ptr ); + } + + _RTEMS_Unlock_allocator(); +} + +static void add_area( + void *area_begin, + uintptr_t area_size +) +{ + Heap_Control *heap = cache_coherent_heap; + + if ( heap == NULL ) { + bool ok; + + heap = &cache_coherent_heap_instance; + + ok = _Heap_Initialize( heap, area_begin, area_size, 0 ); + if ( ok ) { + cache_coherent_heap = heap; + } + } else { + _Heap_Extend( heap, area_begin, area_size, 0 ); + } +} + +void rtems_cache_coherent_add_area( + void *area_begin, + uintptr_t area_size +) +{ + if ( _System_state_Is_up( _System_state_Get()) ) { + _RTEMS_Lock_allocator(); + + add_area( area_begin, area_size ); + + _RTEMS_Unlock_allocator(); + } else { + add_area( area_begin, area_size ); + } +} |