]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/arm/kmem_alloc-arm.cpp
Inital import
[l4.git] / kernel / fiasco / src / kern / arm / kmem_alloc-arm.cpp
1 IMPLEMENTATION [arm]:
2
3 #include "mem_unit.h"
4 #include "kmem_space.h"
5 #include "pagetable.h"
6 #include "ram_quota.h"
7
8 PRIVATE //inline
9 bool
10 Kmem_alloc::map_pmem(unsigned long phy, unsigned long size)
11 {
12   static unsigned long next_map = Mem_layout::Map_base + (4 << 20);
13   size = Mem_layout::round_superpage(size + (phy & ~Config::SUPERPAGE_MASK));
14   phy = Mem_layout::trunc_superpage(phy);
15
16   if (next_map + size > Mem_layout::Map_end)
17     return false;
18
19   for (unsigned long i = 0; i <size; i+=Config::SUPERPAGE_SIZE)
20     {
21       Pte pte = Kmem_space::kdir()->walk((char*)next_map+i,
22           Config::SUPERPAGE_SIZE, false, Ram_quota::root);
23       pte.set(phy+i, Config::SUPERPAGE_SIZE, 
24           Mem_page_attr(Page::KERN_RW | Page::CACHEABLE),
25           true);
26
27     }
28   Mem_layout::add_pmem(phy, next_map, size);
29   next_map += size;
30   return true;
31 }
32
33 IMPLEMENT
34 Kmem_alloc::Kmem_alloc()
35 {
36   Mword alloc_size = Config::KMEM_SIZE;
37   a->init(Mem_layout::Map_base);
38   Mem_region_map<64> map;
39   /*unsigned long available_size =*/ create_free_map(Kip::k(), &map);
40
41   for (int i = map.length() - 1; i >= 0 && alloc_size > 0; --i)
42     {
43       Mem_region f = map[i];
44       if (f.size() > alloc_size)
45         f.start += (f.size() - alloc_size);
46
47       Kip::k()->add_mem_region(Mem_desc(f.start, f.end,
48             Mem_desc::Reserved));
49       //printf("ALLOC1: [%08lx; %08lx] sz=%ld\n", f.start, f.end, f.size());
50       if (Mem_layout::phys_to_pmem(f.start) == ~0UL)
51         if (!map_pmem(f.start, f.size()))
52           panic("Kmem_alloc::Kmem_alloc(): cannot map physical memory %p\n", (void*)f.start);
53       a->add_mem((void*)Mem_layout::phys_to_pmem(f.start), f.size());
54       alloc_size -= f.size();
55     }
56
57   if (alloc_size)
58     printf("Kmem_alloc::Kmem_alloc(): cannot allocate sufficient kernel memory\n");
59 }
60
61 //----------------------------------------------------------------------------
62 IMPLEMENTATION [arm && debug]:
63
64 #include <cstdio>
65
66 #include "kip_init.h"
67 #include "panic.h"
68
69 PUBLIC
70 void Kmem_alloc::debug_dump()
71 {
72   a->dump();
73
74   unsigned long free = a->avail();
75   printf("Used %ldKB out of %dKB of Kmem\n",
76          (Config::KMEM_SIZE - free + 1023)/1024,
77          (Config::KMEM_SIZE        + 1023)/1024);
78 }