The Pedigree Project  0.1
kernel/core/processor/hosted/PhysicalMemoryManager.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_PROCESSOR_HOSTED_PHYSICALMEMORYMANAGER_H
21 #define KERNEL_PROCESSOR_HOSTED_PHYSICALMEMORYMANAGER_H
22 
23 #include "pedigree/kernel/BootstrapInfo.h"
24 #include "pedigree/kernel/Spinlock.h"
25 #include "pedigree/kernel/compiler.h"
26 #include "pedigree/kernel/processor/PhysicalMemoryManager.h"
27 #include "pedigree/kernel/utilities/HashTable.h"
28 #include "pedigree/kernel/utilities/RangeList.h"
29 
33 #define HOSTED_PHYSICAL_MEMORY_SIZE (1UL << 31)
34 
38 {
39  friend class CacheManager;
40  friend class Cache;
43 
44  public:
48  {
49  return m_Instance;
50  }
51 
52  //
53  // PhysicalMemoryManager Interface
54  //
55  virtual physical_uintptr_t allocatePage();
56  virtual void freePage(physical_uintptr_t page);
57  virtual bool allocateRegion(
58  MemoryRegion &Region, size_t cPages, size_t pageConstraints,
59  size_t Flags, physical_uintptr_t start = -1);
60 
61  virtual void pin(physical_uintptr_t page);
62 
66 
68  void initialisationDone();
69 
70 #if defined(ACPI)
71  inline const RangeList<uint64_t> &getAcpiRanges() const
72  {
73  return m_AcpiRanges;
74  }
75 #endif
76 
77  protected:
82 
83  private:
90 
91  inline int getBackingFile() const
92  {
93  return m_BackingFile;
94  }
95 
96  void unmapRegion(MemoryRegion *pRegion);
97 
100  virtual void freePageUnlocked(physical_uintptr_t page);
101 
106  class PageStack
107  {
108  public:
114  physical_uintptr_t allocate(size_t constraints);
117  void free(uint64_t physicalAddress);
119  inline ~PageStack()
120  {
121  }
122 
123  inline size_t freePages() const
124  {
125  return m_FreePages;
126  }
127 
128  private:
131  PageStack(const PageStack &);
134  PageStack &operator=(const PageStack &);
135 
137  static const size_t StackCount = 1;
138 
147  size_t m_FreePages;
148  };
149 
152 
155 
160 
162  Spinlock m_Lock, m_RegionLock;
163 
166  {
167  public:
168  PageHashable()
169  {
170  m_Hash = m_Page = 0;
171  }
172 
173  PageHashable(physical_uintptr_t p)
174  {
175  m_Hash = p / getPageSize();
176  m_Page = p;
177  }
178 
179  size_t hash() const
180  {
181  return m_Hash;
182  }
183 
184  bool operator==(const PageHashable &p) const
185  {
186  return p.m_Page == m_Page;
187  }
188 
189  private:
190  size_t m_Hash;
191  physical_uintptr_t m_Page;
192  };
193 
195  struct page
196  {
197  page() : active(false), refcount(0)
198  {
199  }
200 
201  bool active;
202  size_t refcount;
203  };
204 
206  struct page *m_PageMetadata;
207 
210 
213 };
214 
217 #endif
HostedPhysicalMemoryManager & operator=(const HostedPhysicalMemoryManager &)
Bootstrap structure passed to the kernel entry point.
virtual void freePage(physical_uintptr_t page)
The Stack of pages (below4GB, below64GB, no constraint).
physical_uintptr_t allocate(size_t constraints)
Definition: Cache.h:118
void unmapRegion(MemoryRegion *pRegion)
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Definition: utils.h:38
HostedPhysicalMemoryManager() INITIALISATION_ONLY
Special memory entity in the kernel&#39;s virtual address space.
Definition: MemoryRegion.h:35
virtual bool allocateRegion(MemoryRegion &Region, size_t cPages, size_t pageConstraints, size_t Flags, physical_uintptr_t start=-1)
void initialise(const BootstrapStruct_t &Info) INITIALISATION_ONLY
virtual void pin(physical_uintptr_t page)
Implementation of the PhysicalMemoryManager for common x86.
bool operator==(const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T1 > &x1, const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T2 > &x2)
Definition: Iterator.h:326
PageStack & operator=(const PageStack &)
virtual void freePageUnlocked(physical_uintptr_t page)