]> 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[1UL<<(32-Config::SUPERPAGE_SHIFT)];
17 };
18
19
20 IMPLEMENTATION [noncont_mem]:
21
22 #include <config.h>
23 #include <cstdio>
24
25
26 PUBLIC static
27 Address
28 Mem_layout::pmem_to_phys(Address addr)
29 {
30   printf("Mem_layout::pmem_to_phys(Address addr=%lx) is not implemented\n",
31          addr);
32   return 0;
33 }
34
35 PUBLIC static inline
36 Address
37 Mem_layout::pmem_to_phys(void const *addr)
38 {
39   return pmem_to_phys(Address(addr));
40 }
41 unsigned short Mem_layout::__ph_to_pm[1<<(32-Config::SUPERPAGE_SHIFT)];
42
43 IMPLEMENT inline NEEDS[<config.h>]
44 Address
45 Mem_layout::phys_to_pmem(Address phys)
46 {
47   Address virt = ((unsigned long)__ph_to_pm[phys >> Config::SUPERPAGE_SHIFT])
48     << 16;
49
50   if (!virt)
51     return ~0UL;
52
53   return virt | (phys & (Config::SUPERPAGE_SIZE-1));
54 }
55
56
57
58 IMPLEMENT inline ALWAYS_INLINE NEEDS[<config.h>]
59 void
60 Mem_layout::add_pmem(Address phys, Address virt, unsigned long size)
61 {
62   for (;size >= Config::SUPERPAGE_SIZE; size -= Config::SUPERPAGE_SIZE)
63     {
64       __ph_to_pm[phys >> Config::SUPERPAGE_SHIFT] = virt >> 16;
65       phys += Config::SUPERPAGE_SIZE;
66       virt += Config::SUPERPAGE_SIZE;
67     }
68 }
69
70