The Pedigree Project  0.1
include/pedigree/kernel/processor/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_PHYSICALMEMORYMANAGER_H
21 #define KERNEL_PROCESSOR_PHYSICALMEMORYMANAGER_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/processor/types.h"
25 #include "pedigree/kernel/utilities/Vector.h"
26 
30 class MemoryRegion;
31 
35 {
36  friend class CacheManager;
37  friend class Cache;
38 
39  public:
41  friend class MemoryRegion;
42 
44  static const size_t continuous = 1 << 0;
46  static const size_t nonRamMemory = 1 << 1;
50  static const size_t force = 1 << 2;
52  static const size_t virtualOnly = 1 << 3;
53 
54 // x86/x64 specific flags
55 #if defined(X86_COMMON)
56 
57  static const size_t below1MB = 1 << 4;
59  static const size_t below16MB = 1 << 5;
61  static const size_t below4GB = 1 << 6;
63  static const size_t below64GB = 1 << 7;
64 
66  static const size_t addressConstraints =
67  below1MB | below16MB | below4GB | below64GB;
68 #endif
69 
70  static const size_t anonymous = 1 << 8;
71 
74  static PhysicalMemoryManager &instance();
75 
78  inline static size_t getPageSize() PURE
79  {
80  return PAGE_SIZE;
81  }
84  virtual physical_uintptr_t allocatePage(size_t pageConstraints = 0) = 0;
87  virtual void freePage(physical_uintptr_t page) = 0;
88 
98  virtual void pin(physical_uintptr_t page) = 0;
99 
108  virtual bool allocateRegion(
109  MemoryRegion &Region, size_t cPages, size_t pageConstraints,
110  size_t Flags, physical_uintptr_t start = -1) = 0;
111 
114  {
122  void *VirtualAddress, physical_uintptr_t PhysicalAddress,
123  size_t size, const char *name)
124  : pVirtualAddress(VirtualAddress), physicalAddress(PhysicalAddress),
125  sVirtualAddress(size), pName(name)
126  {
127  }
128 
132  physical_uintptr_t physicalAddress;
136  const char *pName;
137  };
138 
142  void allocateMemoryRegionList(Vector<MemoryRegionInfo *> &MemoryRegions);
146  void freeMemoryRegionList(Vector<MemoryRegionInfo *> &MemoryRegions);
147 
149  virtual size_t freePageCount() const;
150 
151  protected:
155  virtual ~PhysicalMemoryManager();
156 
159 
160  private:
166  PhysicalMemoryManager &operator=(const PhysicalMemoryManager &);
167 
170  virtual void freePageUnlocked(physical_uintptr_t page) = 0;
171 
173  virtual void unmapRegion(MemoryRegion *pRegion) = 0;
174 };
175 
178 #endif
A vector / dynamic array.
Definition: Cache.h:118
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Definition: utils.h:38
Special memory entity in the kernel&#39;s virtual address space.
Definition: MemoryRegion.h:35
MemoryRegionInfo(void *VirtualAddress, physical_uintptr_t PhysicalAddress, size_t size, const char *name)