4 #include "kmem_space.h"
10 Kmem_alloc::map_pmem(unsigned long phy, unsigned long size)
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);
16 if (next_map + size > Mem_layout::Map_end)
19 for (unsigned long i = 0; i <size; i+=Config::SUPERPAGE_SIZE)
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),
28 Mem_layout::add_pmem(phy, next_map, size);
34 Kmem_alloc::Kmem_alloc()
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);
41 for (int i = map.length() - 1; i >= 0 && alloc_size > 0; --i)
43 Mem_region f = map[i];
44 if (f.size() > alloc_size)
45 f.start += (f.size() - alloc_size);
47 Kip::k()->add_mem_region(Mem_desc(f.start, f.end,
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();
58 printf("Kmem_alloc::Kmem_alloc(): cannot allocate sufficient kernel memory\n");
61 //----------------------------------------------------------------------------
62 IMPLEMENTATION [arm && debug]:
70 void Kmem_alloc::debug_dump()
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);