File indexing completed on 2025-05-11 08:24:01
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 #include <bsp.h>
0038 #include <bsp/fdt.h>
0039
0040 #include <rtems/sysinit.h>
0041
0042 #include <libfdt.h>
0043
0044
0045
0046
0047 extern char WorkAreaBase[];
0048 extern char RamEnd[];
0049
0050 static Memory_Area _Memory_Areas[ 1 ];
0051
0052 static const char memory_path[] = "/memory";
0053
0054 static void* get_end_of_memory_from_fdt(void)
0055 {
0056 const void *fdt;
0057 const void *val;
0058 int node;
0059 int parent;
0060 int ac;
0061 int sc;
0062 int len;
0063 uintptr_t start;
0064 uintptr_t size;
0065
0066 fdt = bsp_fdt_get();
0067
0068 node = fdt_path_offset_namelen(
0069 fdt,
0070 memory_path,
0071 (int) sizeof(memory_path) - 1
0072 );
0073
0074 if (node < 0) {
0075 return NULL;
0076 }
0077
0078 parent = fdt_parent_offset(fdt, node);
0079 if (parent < 0) {
0080 return NULL;
0081 }
0082
0083 ac = fdt_address_cells(fdt, parent);
0084 if (ac != 1 && ac != 2) {
0085 return NULL;
0086 }
0087
0088 sc = fdt_size_cells(fdt, parent);
0089 if (sc != 1 && sc != 2) {
0090 return NULL;
0091 }
0092
0093 if (sc > ac) {
0094 return NULL;
0095 }
0096
0097 val = fdt_getprop(fdt, node, "reg", &len);
0098 if (len < sc + ac) {
0099 return NULL;
0100 }
0101
0102 if (ac == 1) {
0103 start = fdt32_ld(&((fdt32_t *)val)[0]);
0104 size = fdt32_ld(&((fdt32_t *)val)[1]);
0105 }
0106
0107 if (ac == 2) {
0108 start = fdt64_ld(&((fdt64_t *)val)[0]);
0109 if (sc == 1) {
0110 size = fdt32_ld(&((fdt32_t *)(val+8))[0]);
0111 } else {
0112 size = fdt64_ld(&((fdt64_t *)val)[1]);
0113 }
0114 }
0115
0116 return (void*) (start + size);
0117 }
0118
0119 static void bsp_memory_initialize( void )
0120 {
0121 void *end;
0122
0123
0124 end = get_end_of_memory_from_fdt();
0125 if (end == NULL) {
0126
0127 end = RamEnd;
0128 }
0129 _Memory_Initialize( &_Memory_Areas[ 0 ], WorkAreaBase, end );
0130 }
0131
0132 RTEMS_SYSINIT_ITEM(
0133 bsp_memory_initialize,
0134 RTEMS_SYSINIT_MEMORY,
0135 RTEMS_SYSINIT_ORDER_MIDDLE
0136 );
0137
0138 static const Memory_Information _Memory_Information =
0139 MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
0140
0141 const Memory_Information *_Memory_Get( void )
0142 {
0143 return &_Memory_Information;
0144 }