remove bug in the initialization of heap_start_address

This commit is contained in:
Stefan Lankes 2011-10-17 01:55:22 -07:00
parent 14d3aba6ed
commit cd6f8b56fc

View file

@ -65,7 +65,7 @@
#define USE_CACHE 0
// set to 1 if you want to use the message passing buffer
#define MMNIF_USE_MPB 1
#define MMNIF_USE_MPB 0
#if USE_CACHE && MMNIF_USE_MBP
#error MBP version uses implicitly the cache
@ -275,14 +275,6 @@ static void mmnif_irqhandler(struct state* s);
inline static void* memcpy_from_nc(void *dest, const void *src, size_t count)
{
#if 0
size_t i;
for(i=0; i<count; i++)
((uint8_t*) dest)[i] = ((uint8_t*) src)[i];
return dest;
#else
int32_t h, i, j, k, l, m;
asm volatile ("cld;\n\t"
@ -316,19 +308,10 @@ inline static void* memcpy_from_nc(void *dest, const void *src, size_t count)
: "0"(count / 32), "1"(dest), "2"(src), "3"(count) : "memory","cc");
return dest;
#endif
}
inline static void* memcpy_to_nc(void* dest, const void *src, size_t count)
{
#if 0
size_t i;
for(i=0; i<count; i++)
((uint8_t*) dest)[i] = ((uint8_t*) src)[i];
return dest;
#else
int32_t i, j, k;
asm volatile (
@ -340,7 +323,6 @@ inline static void* memcpy_to_nc(void* dest, const void *src, size_t count)
: "0"(count/4), "g"(count), "1"(dest), "2"(src) : "memory","cc");
return dest;
#endif
}
/*
@ -494,11 +476,11 @@ static uint8_t mmnif_get_destination(struct netif *netif, struct pbuf *p)
*/
static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
{
uint32_t ret;
uint32_t ret = 0;
mm_rx_buffer_t *rb = (mm_rx_buffer_t *) ((char *)header_start_address + (dest - 1) * header_size);
#if MMNIF_USE_MPB
char *memblock = (char *)heap_start_address + (dest - 1) * 0x2000;
char* memblock = (char*)heap_start_address + (dest-1)/2*16*1024*1024 + (dest-1)%2 * 0x2000;
#else
char *memblock = (char *)heap_start_address + (dest - 1) * heap_size;
#endif
@ -524,8 +506,6 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
rb->dcount--;
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
rb->tail = (rb->tail + len);
RCCE_release_lock(dest-1);
return ret;
} else if (rb->head > len) {
rb->desc_table[rb->dwrite].stat = MMNIF_STATUS_PENDING;
ret = (uint32_t) memblock;
@ -534,11 +514,6 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
rb->dcount--;
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
rb->tail = len;
RCCE_release_lock(dest-1);
return ret;
} else {
RCCE_release_lock(dest-1);
return 0;
}
} else {
if (rb->head - rb->tail > len)
@ -550,8 +525,6 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
rb->dcount--;
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
rb->tail = (rb->tail + len);
RCCE_release_lock(dest-1);
return ret;
} else if (rb->tail == rb->head) {
if (MMNIF_RX_BUFFERLEN - rb->tail < len)
{
@ -566,17 +539,13 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
rb->dcount--;
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
rb->tail = (rb->tail + len);
RCCE_release_lock(dest-1);
return ret;
} else {
RCCE_release_lock(dest-1);
return 0;
}
}
} else {
RCCE_release_lock(dest-1);
return 0;
}
out:
RCCE_release_lock(dest-1);
return ret;
}
/* mmnif_commit_packet: this function set the state of the (in advance)
@ -701,9 +670,6 @@ realloc:
goto realloc;
}
if (!write_address)
goto drop_packet;
#if MMNIF_USE_MPB
asm volatile (".byte 0x0f; .byte 0x0a;\n");
#endif
@ -711,7 +677,7 @@ realloc:
for (q = p, i = 0; q != 0; q = q->next)
{
#if !MMNIF_USE_MBP
memcpy_to_nc((char*) write_address+ i, q->payload, q->len);
memcpy_to_nc((char*) write_address + i, q->payload, q->len);
#else
memcpy_put((char*) write_address + i, q->payload, q->len);
#endif
@ -1018,9 +984,8 @@ err_t mmnif_init(struct netif *netif)
// map physical address in the virtual address space
#if USE_CACHE
//heap_start_address = map_region(0, heap_start_address, (MMNIF_CORES*heap_size) >> PAGE_SHIFT, MAP_KERNEL_SPACE|MAP_MPE);
//uint32_t n = (uint32_t) heap_start_address;
heap_start_address = map_region(0, heap_start_address, (MMNIF_CORES * heap_size) >> PAGE_SHIFT, MAP_KERNEL_SPACE | MAP_NO_CACHE | MAP_MPE | MAP_WT);
uint32_t n = (uint32_t) heap_start_address;
map_region(heap_start_address + (heap_size) * (own_ip_address - router_ip_address), n + (heap_size) * (own_ip_address - router_ip_address), header_size >> PAGE_SHIFT, MAP_KERNEL_SPACE | MAP_MPE | MAP_WT | MAP_REMAP);
#else
heap_start_address = (void*) map_region(0, (size_t) heap_start_address, (MMNIF_CORES * heap_size) >> PAGE_SHIFT, MAP_KERNEL_SPACE | MAP_NO_CACHE | MAP_MPE | MAP_WT);
@ -1030,7 +995,7 @@ err_t mmnif_init(struct netif *netif)
#if MMNIF_USE_MPB
mmnif->rx_heap = heap_start_address;
heap_start_address = heap_start_address - (own_ip_address - router_ip_address) * 0x2000;
heap_start_address = heap_start_address - (RC_MY_COREID/2 * 16*1024*1024 ) - (RC_MY_COREID%2 * 0x2000);
DEBUGPRINTF("heap_start_address : %p\n", heap_start_address);
#else
mmnif->rx_heap = heap_start_address + (heap_size) * (own_ip_address - router_ip_address);
@ -1230,7 +1195,7 @@ anotherpacket:
* and other higher layer can handle it
*/
p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL);
if (!p)
if (BUILTIN_EXPECT(!p, 0))
{
DEBUGPRINTF("mmnif_rx(): low on mem - packet dropped\n");
goto drop_packet;