2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "athos_api.h"
38 #if SYSTEM_MODULE_ALLOCRAM
41 * Startup time RAM allocation.
43 * Oddly enough, we allow allocation, but not free.
44 * The central idea is to restrict compile-time RAM demands
45 * of modules to a minimum so that if a module is replaced
46 * at run-time large amounts of RAM are not wasted.
48 * Addresses returned are A_CACHE_LINE_SIZE aligned.
51 LOCAL A_UINT32 allocram_current_addr;
52 LOCAL A_UINT32 allocram_remaining_bytes;
55 cmnos_allocram_init(void *arena_start, A_UINT32 arena_sz)
57 A_UINT32 astart = (A_UINT32)arena_start;
59 #if defined(__XTENSA__)
61 * This hacky line converts from a text or data RAM address
62 * into a data RAM address. (It's all the same on MIPS, but
63 * text and data are different address spaces on Xtensa.)
65 //astart = TARG_RAM_ADDRS(TARG_RAM_OFFSET(astart));
70 /* Default arena_sz to most of available RAM */
71 arena_sz = TARG_RAM_SZ - (A_UINT32)TARG_RAM_OFFSET(astart);
72 arena_sz -= HOST_INTEREST->hi_end_RAM_reserve_sz;
76 /* Clear entire area */
77 // A_MEMSET(astart, 0, arena_sz);
79 /* Adjust for cache line alignment */
81 allocram_current_addr = A_ROUND_UP(astart, A_CACHE_LINE_SIZE);
82 arena_sz -= (allocram_current_addr-astart);
84 allocram_current_addr = astart;
86 allocram_remaining_bytes = arena_sz;
90 //A_PRINTF("cmnos_allocram_init: start=0x%x size=%d\n",
91 // allocram_current_addr, allocram_remaining_bytes);
93 return NULL; /* Future implementation may return an arena handle */
97 * Allocate nbytes from the arena. At this point, which_arena should
98 * be set to 0 for the default (and only) arena. A future allocation
99 * module may support multiple separate arenas.
102 cmnos_allocram(void * which_arena, A_UINT32 nbytes)
104 void *ptr = (void *)allocram_current_addr;
105 //nbytes = A_ROUND_UP(nbytes, A_CACHE_LINE_SIZE);
106 nbytes = A_ROUND_UP(nbytes, 4);
107 if (nbytes <= allocram_remaining_bytes) {
108 allocram_remaining_bytes -= nbytes;
109 allocram_current_addr += nbytes;
111 A_PRINTF("RAM allocation (%d bytes) failed!\n", nbytes);
120 cmnos_allocram_debug(void)
122 A_PRINTF("ALLOCRAM Current Addr 0x%x\n", allocram_current_addr);
123 A_PRINTF("ALLOCRAM Remaining Bytes %d\n", allocram_remaining_bytes);
127 cmnos_allocram_module_install(struct allocram_api *tbl)
129 tbl->cmnos_allocram_init = cmnos_allocram_init;
130 tbl->cmnos_allocram = cmnos_allocram;
131 tbl->cmnos_allocram_debug = cmnos_allocram_debug;
134 #endif /* SYSTEM_MODULE_ALLOCRAM */