File indexing completed on 2025-05-11 08:23:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #include <bsp.h>
0041 #include <bsp/bootcard.h>
0042
0043 #include <rtems/sysinit.h>
0044
0045 #ifdef BSP_GET_WORK_AREA_DEBUG
0046 #include <rtems/bspIo.h>
0047 #endif
0048
0049
0050
0051
0052 extern char WorkAreaBase[];
0053 extern char HeapSize[];
0054 extern char RamSize[];
0055
0056
0057 struct multiboot_info {
0058 uint32_t flags;
0059
0060
0061 uint32_t mem_lower;
0062 uint32_t mem_upper;
0063
0064 };
0065
0066 extern struct multiboot_info _boot_multiboot_info;
0067
0068
0069
0070
0071
0072 static uintptr_t rtemsWorkAreaStart;
0073
0074
0075
0076
0077 uint32_t bsp_mem_size = 0;
0078
0079 static void bsp_size_memory(void)
0080 {
0081 uintptr_t topAddr;
0082
0083
0084 rtemsWorkAreaStart = (uint32_t)WorkAreaBase;
0085
0086
0087 if (rtemsWorkAreaStart & (CPU_ALIGNMENT - 1))
0088 rtemsWorkAreaStart = (rtemsWorkAreaStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
0089
0090
0091
0092
0093 if ( ((uintptr_t)RamSize == (uintptr_t) 0xFFFFFFFF) &&
0094 (_boot_multiboot_info.flags & 1) &&
0095 _boot_multiboot_info.mem_upper ) {
0096 topAddr = _boot_multiboot_info.mem_upper * 1024;
0097 #ifdef BSP_GET_WORK_AREA_DEBUG
0098 printk( "Multiboot info says we have 0x%08x\n", topAddr );
0099 #endif
0100 } else if ( (uintptr_t) RamSize == (uintptr_t) 0xFFFFFFFF ) {
0101 uintptr_t lowest;
0102 uint32_t val;
0103 int i;
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115 lowest = ((rtemsWorkAreaStart + (1<<20)) >> 20) + 1;
0116 if ( lowest < 2 )
0117 lowest = 2;
0118
0119 for (i=2048; i>=lowest; i--) {
0120 topAddr = i*1024*1024 - 4;
0121 *(volatile uint32_t*)topAddr = topAddr;
0122 }
0123
0124 for(i=lowest; i<=2048; i++) {
0125 topAddr = i*1024*1024 - 4;
0126 val = *(volatile uint32_t*)topAddr;
0127 if (val != topAddr) {
0128 break;
0129 }
0130 }
0131
0132 topAddr = (i-1)*1024*1024;
0133 #ifdef BSP_GET_WORK_AREA_DEBUG
0134 printk( "Dynamically sized to 0x%08x\n", topAddr );
0135 #endif
0136 } else {
0137 topAddr = (uintptr_t) RamSize;
0138 #ifdef BSP_GET_WORK_AREA_DEBUG
0139 printk( "hardcoded to 0x%08x\n", topAddr );
0140 #endif
0141 }
0142
0143 bsp_mem_size = topAddr;
0144 }
0145
0146 static Memory_Area _Memory_Areas[ 1 ];
0147
0148 static void bsp_memory_initialize( void )
0149 {
0150
0151
0152
0153 bsp_size_memory();
0154
0155 _Memory_Initialize_by_size(
0156 &_Memory_Areas[0],
0157 (void *) rtemsWorkAreaStart,
0158 (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart
0159 );
0160 }
0161
0162 RTEMS_SYSINIT_ITEM(
0163 bsp_memory_initialize,
0164 RTEMS_SYSINIT_MEMORY,
0165 RTEMS_SYSINIT_ORDER_MIDDLE
0166 );
0167
0168 static const Memory_Information _Memory_Information =
0169 MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
0170
0171 const Memory_Information *_Memory_Get( void )
0172 {
0173 return &_Memory_Information;
0174 }