2 * Copyright (c) 2007 Atheros Communications Inc.
9 #if SYSTEM_MODULE_ALLOCRAM
12 * Startup time RAM allocation.
14 * Oddly enough, we allow allocation, but not free.
15 * The central idea is to restrict compile-time RAM demands
16 * of modules to a minimum so that if a module is replaced
17 * at run-time large amounts of RAM are not wasted.
19 * Addresses returned are A_CACHE_LINE_SIZE aligned.
22 LOCAL A_UINT32 allocram_current_addr;
23 LOCAL A_UINT32 allocram_remaining_bytes;
26 cmnos_allocram_init(void *arena_start, A_UINT32 arena_sz)
28 A_UINT32 astart = (A_UINT32)arena_start;
30 #if defined(__XTENSA__)
32 * This hacky line converts from a text or data RAM address
33 * into a data RAM address. (It's all the same on MIPS, but
34 * text and data are different address spaces on Xtensa.)
36 //astart = TARG_RAM_ADDRS(TARG_RAM_OFFSET(astart));
41 /* Default arena_sz to most of available RAM */
42 arena_sz = TARG_RAM_SZ - (A_UINT32)TARG_RAM_OFFSET(astart);
43 arena_sz -= HOST_INTEREST->hi_end_RAM_reserve_sz;
47 /* Clear entire area */
48 // A_MEMSET(astart, 0, arena_sz);
50 /* Adjust for cache line alignment */
52 allocram_current_addr = A_ROUND_UP(astart, A_CACHE_LINE_SIZE);
53 arena_sz -= (allocram_current_addr-astart);
55 allocram_current_addr = astart;
57 allocram_remaining_bytes = arena_sz;
61 //A_PRINTF("cmnos_allocram_init: start=0x%x size=%d\n",
62 // allocram_current_addr, allocram_remaining_bytes);
64 return NULL; /* Future implementation may return an arena handle */
68 * Allocate nbytes from the arena. At this point, which_arena should
69 * be set to 0 for the default (and only) arena. A future allocation
70 * module may support multiple separate arenas.
73 cmnos_allocram(void * which_arena, A_UINT32 nbytes)
75 void *ptr = (void *)allocram_current_addr;
76 //nbytes = A_ROUND_UP(nbytes, A_CACHE_LINE_SIZE);
77 nbytes = A_ROUND_UP(nbytes, 4);
78 if (nbytes <= allocram_remaining_bytes) {
79 allocram_remaining_bytes -= nbytes;
80 allocram_current_addr += nbytes;
82 A_PRINTF("RAM allocation (%d bytes) failed!\n", nbytes);
91 cmnos_allocram_debug(void)
93 A_PRINTF("ALLOCRAM Current Addr 0x%x\n", allocram_current_addr);
94 A_PRINTF("ALLOCRAM Remaining Bytes %d\n", allocram_remaining_bytes);
98 cmnos_allocram_module_install(struct allocram_api *tbl)
100 tbl->cmnos_allocram_init = cmnos_allocram_init;
101 tbl->cmnos_allocram = cmnos_allocram;
102 tbl->cmnos_allocram_debug = cmnos_allocram_debug;
105 #endif /* SYSTEM_MODULE_ALLOCRAM */