Changeset 038faca1 in rtems


Ignore:
Timestamp:
Nov 25, 2014, 3:47:20 PM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
cbc433c7
Parents:
b164303
git-author:
Sebastian Huber <sebastian.huber@…> (11/25/14 15:47:20)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/27/14 09:33:30)
Message:

rtems: Add rtems_cache_coherent_allocate()

Add rtems_cache_coherent_free() and rtems_cache_coherent_add_area().

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/Makefile.am

    rb164303 r038faca1  
    110110    src/rtems_heap_greedy.c
    111111MALLOC_C_FILES += src/cachealignedalloc.c
     112MALLOC_C_FILES += src/cachecoherentalloc.c
    112113
    113114PASSWORD_GROUP_C_FILES = src/pwdgrp.c
  • cpukit/rtems/include/rtems/rtems/cache.h

    rb164303 r038faca1  
    192192void *rtems_cache_aligned_malloc ( size_t nbytes );
    193193
     194/**
     195 * @brief Allocates a memory area of size @a size bytes from cache coherent
     196 * memory.
     197 *
     198 * A size value of zero will return a unique address which may be freed with
     199 * rtems_cache_coherent_free().
     200 *
     201 * The memory allocated by this function can be released with a call to
     202 * rtems_cache_coherent_free().
     203 *
     204 * By default the C program heap allocator is used.  In case special memory
     205 * areas must be used, then the BSP or the application must add cache coherent
     206 * memory areas for the allocator via rtems_cache_coherent_add_area().
     207 *
     208 * This function must be called from driver initialization or task context
     209 * only.
     210 *
     211 * @param[in] alignment If the alignment parameter is not equal to zero, the
     212 *   allocated memory area will begin at an address aligned by this value.
     213 * @param[in] boundary If the boundary parameter is not equal to zero, the
     214 *   allocated memory area will comply with a boundary constraint.  The
     215 *   boundary value specifies the set of addresses which are aligned by the
     216 *   boundary value.  The interior of the allocated memory area will not
     217 *   contain an element of this set.  The begin or end address of the area may
     218 *   be a member of the set.
     219 *
     220 * @retval NULL If no memory is available or the parameters are inconsistent.
     221 * @retval other A pointer to the begin of the allocated memory area.
     222 */
     223void *rtems_cache_coherent_allocate(
     224  size_t size,
     225  uintptr_t alignment,
     226  uintptr_t boundary
     227);
     228
     229/**
     230 * @brief Frees memory allocated by rtems_cache_coherent_allocate().
     231 *
     232 * This function must be called from driver initialization or task context
     233 * only.
     234 *
     235 * @param[in] ptr A pointer returned by rtems_cache_coherent_allocate().
     236 */
     237void rtems_cache_coherent_free( void *ptr );
     238
     239/**
     240 * @brief Adds a cache coherent memory area to the cache coherent allocator.
     241 *
     242 * This function must be called from BSP initialization, driver initialization
     243 * or task context only.
     244 *
     245 * @param[in] area_begin The area begin address.
     246 * @param[in] area_size The area size in bytes.
     247 *
     248 * @see rtems_cache_coherent_allocate().
     249 */
     250void rtems_cache_coherent_add_area(
     251  void *area_begin,
     252  uintptr_t area_size
     253);
     254
    194255#if defined( RTEMS_SMP )
    195256
  • testsuites/sptests/spcache01/init.c

    rb164303 r038faca1  
    2323#include <rtems.h>
    2424#include <rtems/counter.h>
     25#include <rtems/score/sysstate.h>
    2526
    2627#define TESTS_USE_PRINTF
     
    410411}
    411412
     413#define AREA_SIZE 256
     414
     415static char cache_coherent_area_0[AREA_SIZE];
     416
     417static char cache_coherent_area_1[AREA_SIZE];
     418
     419static char cache_coherent_area_2[AREA_SIZE];
     420
     421static void add_area(void *begin)
     422{
     423  rtems_cache_coherent_add_area(NULL, 0);
     424  rtems_cache_coherent_add_area(begin, AREA_SIZE);
     425}
     426
     427static void test_cache_coherent_alloc(void)
     428{
     429  void *p0;
     430  void *p1;
     431  System_state_Codes previous_state;
     432
     433  printf("test cache coherent allocation\n");
     434
     435  p0 = rtems_cache_coherent_allocate(1, 0, 0);
     436  rtems_test_assert(p0 != NULL);
     437
     438  rtems_cache_coherent_free(p0);
     439
     440  p0 = rtems_cache_coherent_allocate(1, 0, 0);
     441  rtems_test_assert(p0 != NULL);
     442
     443  add_area(&cache_coherent_area_0[0]);
     444  add_area(&cache_coherent_area_1[0]);
     445
     446  previous_state = _System_state_Get();
     447  _System_state_Set(previous_state + 1);
     448  add_area(&cache_coherent_area_2[0]);
     449  _System_state_Set(previous_state);
     450
     451  p1 = rtems_cache_coherent_allocate(1, 0, 0);
     452  rtems_test_assert(p1 != NULL);
     453
     454  rtems_cache_coherent_free(p0);
     455  rtems_cache_coherent_free(p1);
     456}
     457
    412458static void Init(rtems_task_argument arg)
    413459{
     
    417463  test_timing();
    418464  test_cache_aligned_alloc();
     465  test_cache_coherent_alloc();
    419466
    420467  TEST_END();
  • testsuites/sptests/spcache01/spcache01.scn

    rb164303 r038faca1  
    4444  duration with invalidated cache 2600 ns
    4545test rtems_cache_aligned_malloc()
     46test cache coherent allocation
    4647*** END OF TEST SPCACHE 1 ***
Note: See TracChangeset for help on using the changeset viewer.