2009-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>

* include/bsp.h, startup/bspgetworkarea.c: Rework bsp_size_memory() to
	ensure that multiboot information regarding memory size is used as
	the primary source. This was broken in the move to supporting a
	unified workspace. It worked this way in 4.9 so this was a
	regression.
This commit is contained in:
Joel Sherrill
2009-12-10 18:44:10 +00:00
parent 44396163d3
commit c296687193
3 changed files with 42 additions and 33 deletions

View File

@@ -1,3 +1,11 @@
2009-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>
* include/bsp.h, startup/bspgetworkarea.c: Rework bsp_size_memory() to
ensure that multiboot information regarding memory size is used as
the primary source. This was broken in the move to supporting a
unified workspace. It worked this way in 4.9 so this was a
regression.
2009-12-09 Joel Sherrill <joel.sherrill@oarcorp.com> 2009-12-09 Joel Sherrill <joel.sherrill@oarcorp.com>
* startup/bspgetworkarea.c: Add debug printk's. * startup/bspgetworkarea.c: Add debug printk's.

View File

@@ -162,10 +162,6 @@ extern int rtems_dec21140_driver_attach(struct rtems_bsdnet_ifconfig *, int);
extern interrupt_gate_descriptor Interrupt_descriptor_table[IDT_SIZE]; extern interrupt_gate_descriptor Interrupt_descriptor_table[IDT_SIZE];
extern segment_descriptors Global_descriptor_table [GDT_SIZE]; extern segment_descriptors Global_descriptor_table [GDT_SIZE];
extern uint32_t rtemsFreeMemStart;
/* Address of start of free memory - should be used when creating new
partitions or regions and updated afterwards. */
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Function Prototypes. | Function Prototypes.
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/

View File

@@ -40,37 +40,30 @@ struct multiboot_info {
extern struct multiboot_info _boot_multiboot_info; extern struct multiboot_info _boot_multiboot_info;
/*
* This is the first address of the memory we can use for the RTEMS
* Work Area.
*/
static uintptr_t rtemsWorkAreaStart;
/* /*
* Board's memory size easily be overridden by application. * Board's memory size easily be overridden by application.
*/ */
uint32_t bsp_mem_size = 0; static uint32_t bsp_mem_size = 0;
/* Size of stack used during initialization. Defined in 'start.s'. */ /* Size of stack used during initialization. Defined in 'start.s'. */
extern uint32_t _stack_size; extern uint32_t _stack_size;
/* Address of start of free memory. */
uintptr_t rtemsFreeMemStart;
void bsp_size_memory(void) void bsp_size_memory(void)
{ {
uintptr_t topAddr; uintptr_t topAddr;
uintptr_t lowest;
uint32_t val;
int i;
/* set the value of start of free memory. */ /* Set the value of start of free memory. */
rtemsFreeMemStart = (uint32_t)WorkAreaBase + _stack_size; rtemsWorkAreaStart = (uint32_t)WorkAreaBase + _stack_size;
/* Place RTEMS workspace at beginning of free memory. */ /* Align the RTEMS Work Area at beginning of free memory. */
if (rtemsWorkAreaStart & (CPU_ALIGNMENT - 1)) /* not aligned => align it */
if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1)) /* not aligned => align it */ rtemsWorkAreaStart = (rtemsWorkAreaStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
/* find the lowest 1M boundary to probe */
lowest = ((rtemsFreeMemStart + (1<<20)) >> 20) + 1;
if ( lowest < 2 )
lowest = 2;
/* The memory detection algorithm is very crude; try /* The memory detection algorithm is very crude; try
* to use multiboot info, if possible (set from start.S) * to use multiboot info, if possible (set from start.S)
@@ -78,18 +71,29 @@ void bsp_size_memory(void)
if ( ((uintptr_t)RamSize == (uintptr_t) 0xFFFFFFFF) && if ( ((uintptr_t)RamSize == (uintptr_t) 0xFFFFFFFF) &&
(_boot_multiboot_info.flags & 1) && (_boot_multiboot_info.flags & 1) &&
_boot_multiboot_info.mem_upper ) { _boot_multiboot_info.mem_upper ) {
bsp_mem_size = _boot_multiboot_info.mem_upper * 1024; topAddr = _boot_multiboot_info.mem_upper * 1024;
#ifdef BSP_GET_WORK_AREA_DEBUG #ifdef BSP_GET_WORK_AREA_DEBUG
printk( "Multiboot info says we have 0x%08x\n", bsp_mem_size ); printk( "Multiboot info says we have 0x%08x\n", topAddr );
#endif #endif
} } else if ( (uintptr_t) RamSize == (uintptr_t) 0xFFFFFFFF ) {
uintptr_t lowest;
uint32_t val;
int i;
if ( (uintptr_t) RamSize == (uintptr_t) 0xFFFFFFFF ) {
/* /*
* We have to dynamically size memory. Memory size can be anything * We have to dynamically size memory. Memory size can be anything
* between no less than 2M and 2048M. * between no less than 2M and 2048M. If we can write a value to
* let us first write * an address and read the same value back, then the memory is there.
*
* WARNING: This can detect memory which should be reserved for
* graphics controllers which share the CPU's RAM.
*/ */
/* find the lowest 1M boundary to probe */
lowest = ((rtemsWorkAreaStart + (1<<20)) >> 20) + 1;
if ( lowest < 2 )
lowest = 2;
for (i=2048; i>=lowest; i--) { for (i=2048; i>=lowest; i--) {
topAddr = i*1024*1024 - 4; topAddr = i*1024*1024 - 4;
*(volatile uint32_t*)topAddr = topAddr; *(volatile uint32_t*)topAddr = topAddr;
@@ -103,7 +107,7 @@ void bsp_size_memory(void)
} }
} }
topAddr = (i-1)*1024*1024 - 4; topAddr = (i-1)*1024*1024;
#ifdef BSP_GET_WORK_AREA_DEBUG #ifdef BSP_GET_WORK_AREA_DEBUG
printk( "Dynamically sized to 0x%08x\n", topAddr ); printk( "Dynamically sized to 0x%08x\n", topAddr );
#endif #endif
@@ -116,6 +120,7 @@ void bsp_size_memory(void)
bsp_mem_size = topAddr; bsp_mem_size = topAddr;
} }
/* /*
* This method returns the base address and size of the area which * This method returns the base address and size of the area which
* is to be allocated between the RTEMS Workspace and the C Program * is to be allocated between the RTEMS Workspace and the C Program
@@ -128,14 +133,14 @@ void bsp_get_work_area(
uintptr_t *heap_size uintptr_t *heap_size
) )
{ {
*work_area_start = (void *) rtemsFreeMemStart; *work_area_start = (void *) rtemsWorkAreaStart;
*work_area_size = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsFreeMemStart; *work_area_size = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
*heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA; *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
*heap_size = (uintptr_t) HeapSize; *heap_size = (uintptr_t) HeapSize;
#ifdef BSP_GET_WORK_AREA_DEBUG #ifdef BSP_GET_WORK_AREA_DEBUG
printk( "bsp_mem_size = 0x%08x\n", bsp_mem_size ); printk( "bsp_mem_size = 0x%08x\n", bsp_mem_size );
printk( "rtemsFreeMemStart = 0x%08x\n", rtemsFreeMemStart ); printk( "rtemsWorkAreaStart = 0x%08x\n", rtemsWorkAreaStart );
printk( "WorkArea Base = %p\n", *work_area_start ); printk( "WorkArea Base = %p\n", *work_area_start );
printk( "WorkArea Size = 0x%08x\n", *work_area_size ); printk( "WorkArea Size = 0x%08x\n", *work_area_size );
printk( "C Program Heap Base = %p\n", *heap_start ); printk( "C Program Heap Base = %p\n", *heap_start );