Home | History | Annotate | Download | only in nds
      1 /*
      2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 
     12 #define __VPX_MEM_C__
     13 #include "vpx_mem.h"
     14 #include <nitro.h>
     15 #include "vpx_mem_intrnl.h"
     16 
     17 // Allocate memory from the Arena specified by id.  Align it to
     18 //  the value specified by align.
     19 void *vpx_mem_nds_alloc(osarena_id id, osheap_handle handle, size_t size, size_t align)
     20 {
     21     void *addr,
     22          * x = NULL;
     23 
     24     addr = os_alloc_from_heap((osarena_id) id, handle,
     25                               size + align - 1 + ADDRESS_STORAGE_SIZE);
     26 
     27     if (addr)
     28     {
     29         x = align_addr((unsigned char *)addr + ADDRESS_STORAGE_SIZE, (int)align);
     30 
     31         // save the actual malloc address
     32         ((size_t *)x)[-1] = (size_t)addr;
     33     }
     34 
     35     return x;
     36 }
     37 
     38 // Free them memory allocated by vpx_mem_nds_alloc
     39 void vpx_mem_nds_free(osarena_id id, osheap_handle handle, void *mem)
     40 {
     41     if (mem)
     42     {
     43         void *addr = (void *)(((size_t *)mem)[-1]);
     44         os_free_to_heap(id, handle, addr);
     45     }
     46 }
     47 
     48 int vpx_nds_alloc_heap(osarena_id id, u32 size)
     49 {
     50     osheap_handle    arena_handle;
     51     void           *nstart;
     52     void           *heap_start;
     53 
     54     nstart = os_init_alloc(id, os_get_arena_lo(id), os_get_arena_hi(id), 1);
     55     os_set_arena_lo(id, nstart);
     56 
     57     heap_start = os_alloc_from_arena_lo(id, size, 32);
     58     arena_handle = os_create_heap(id, heap_start, (void *)((u32)heap_start + size));
     59 
     60     if (os_check_heap(id, arena_handle) == -1)
     61         return -1;      //ERROR: DTCM heap is not consistent
     62 
     63     (void)os_set_current_heap(id, arena_handle);
     64 
     65     return arena_handle;
     66 }
     67