]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/arm/mem_layout-noncont.cpp
update
[l4.git] / kernel / fiasco / src / kern / arm / mem_layout-noncont.cpp
1 INTERFACE [noncont_mem]:
2
3 #include <config.h>
4
5 EXTENSION class Mem_layout
6 {
7 public:
8   static Address phys_to_pmem(Address addr);
9   static void add_pmem(Address phys, Address virt, unsigned long size);
10
11   static inline unsigned long round_superpage(unsigned long addr)
12   { return (addr + Config::SUPERPAGE_SIZE - 1) & ~(Config::SUPERPAGE_SIZE-1); }
13   static inline unsigned long trunc_superpage(unsigned long addr)
14   { return addr & ~(Config::SUPERPAGE_SIZE-1); }
15 private:
16   static unsigned short __ph_to_pm[1<<(32-Config::SUPERPAGE_SHIFT)];
17 };
18
19
20 IMPLEMENTATION [noncont_mem]:
21
22 #include <config.h>
23 #include <cstdio>
24
25 PUBLIC static
26 Address
27 Mem_layout::pmem_to_phys (Address addr)
28 {
29   printf("Mem_layout::pmem_to_phys(Address addr=%lx) is not implemented\n",
30          addr);
31   return 0;
32 }
33
34 PUBLIC static inline
35 Address
36 Mem_layout::pmem_to_phys(void const *addr)
37 {
38   return pmem_to_phys(Address(addr));
39 }
40 unsigned short Mem_layout::__ph_to_pm[1<<(32-Config::SUPERPAGE_SHIFT)];
41
42 IMPLEMENT inline NEEDS[<config.h>]
43 Address
44 Mem_layout::phys_to_pmem(Address phys)
45 {
46   Address virt = ((unsigned long)__ph_to_pm[phys >> Config::SUPERPAGE_SHIFT]) 
47     << 16;
48
49   if (!virt) 
50     return ~0UL;
51
52   return virt | (phys & (Config::SUPERPAGE_SIZE-1));
53 }
54
55
56
57 IMPLEMENT inline NEEDS[<config.h>]
58 void
59 Mem_layout::add_pmem(Address phys, Address virt, unsigned long size)
60 {
61   for (;size >= Config::SUPERPAGE_SIZE; size -= Config::SUPERPAGE_SIZE)
62     {
63       __ph_to_pm[phys >> Config::SUPERPAGE_SHIFT] = virt >> 16;
64       phys += Config::SUPERPAGE_SIZE;
65       virt += Config::SUPERPAGE_SIZE;
66     }
67
68 }
69