Changeset 94f3c2db in rtems


Ignore:
Timestamp:
Dec 19, 2017, 11:53:20 AM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5, master
Children:
31c8db4
Parents:
f0e5e17
git-author:
Sebastian Huber <sebastian.huber@…> (12/19/17 11:53:20)
git-committer:
Sebastian Huber <sebastian.huber@…> (12/19/17 11:54:53)
Message:

bsp/altera-cyclone-v: Remove reserved memory

Removed reserved memory from work area, e.g. used by FPGA devices.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/altera-cyclone-v/startup/bspgetworkarea.c

    rf0e5e17 r94f3c2db  
    1919
    2020static const char memory_path[] = "/memory";
     21
     22static const char reserved_memory_path[] = "/reserved-memory";
    2123
    2224static void adjust_memory_size(const void *fdt, Heap_Area *area)
     
    6668}
    6769
     70static Heap_Area *find_area(
     71  Heap_Area *areas,
     72  size_t area_count,
     73  uint32_t begin
     74)
     75{
     76  size_t i;
     77
     78  for (i = 0; i < area_count; ++i) {
     79    uintptr_t b;
     80    uintptr_t e;
     81
     82    b = (uintptr_t) areas[i].begin;
     83    e = b + (uintptr_t) areas[i].size;
     84
     85    if (b <= begin && begin < e) {
     86      return &areas[i];
     87    }
     88  }
     89
     90  return NULL;
     91}
     92
     93static size_t remove_reserved_memory(
     94  const void *fdt,
     95  Heap_Area *areas,
     96  size_t area_count
     97)
     98{
     99  int node;
     100
     101  node = fdt_path_offset_namelen(
     102    fdt,
     103    reserved_memory_path,
     104    (int) sizeof(reserved_memory_path) - 1
     105  );
     106
     107  if (node >= 0) {
     108    node = fdt_first_subnode(fdt, node);
     109
     110    while (node >= 0) {
     111      int len;
     112      const void *val;
     113      uintptr_t area_begin;
     114      uintptr_t area_end;
     115      uintptr_t hole_begin;
     116      uintptr_t hole_end;
     117      Heap_Area *area;
     118
     119      val = fdt_getprop(fdt, node, "reg", &len);
     120      if (len == 8) {
     121        hole_begin = fdt32_to_cpu(((fdt32_t *) val)[0]);
     122        hole_end = hole_begin + fdt32_to_cpu(((fdt32_t *) val)[1]);
     123      } else {
     124        rtems_panic("unexpected reserved memory area");
     125      }
     126
     127      area = find_area(areas, area_count, hole_begin);
     128      area_begin = (uintptr_t) area->begin;
     129      area_end = area_begin + (uintptr_t) area->size;
     130      area->size = hole_begin - area_begin;
     131
     132      if (hole_end <= area_end) {
     133        if (area_count >= AREA_COUNT_MAX) {
     134          rtems_panic("too many reserved memory areas");
     135        }
     136
     137        area = &areas[area_count];
     138        ++area_count;
     139        area->begin = (void *) hole_end;
     140        area->size = area_end - hole_end;
     141      }
     142
     143      node = fdt_next_subnode(fdt, node);
     144    }
     145  }
     146
     147  return area_count;
     148}
     149
    68150void bsp_work_area_initialize(void)
    69151{
     
    80162
    81163  adjust_memory_size(fdt, &areas[0]);
     164  area_count = remove_reserved_memory(fdt, areas, area_count);
    82165
    83166  for (i = 0; i < area_count; ++i) {
Note: See TracChangeset for help on using the changeset viewer.