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#include "pedigree/kernel/BootstrapInfo.h"
23#include "pedigree/kernel/Spinlock.h"
24#include "pedigree/kernel/compiler.h"
25#include "pedigree/kernel/processor/PhysicalMemoryManager.h"
26#include "pedigree/kernel/utilities/HashTable.h"
27#include "pedigree/kernel/utilities/RangeList.h"
28
29#include <config.h>
30
31#include "../x86_common/PhysicalMemoryManager.h"
32
36#define HOSTED_PHYSICAL_MEMORY_SIZE (1UL << 31)
37
41 friend class CacheManager;
42 friend class Cache;
43 friend class PhysicalMemoryManager;
46
47 public:
51
52 //
53 // PhysicalMemoryManager Interface
54 //
55 virtual physical_uintptr_t allocatePage(size_t pageConstraints = 0) override;
56 physical_uintptr_t tryAllocatePage() override;
57 bool copyPhysicalPageToBuffer(physical_uintptr_t page, void* buffer) override;
58 bool copyPhysicalPageFromBuffer(physical_uintptr_t page, const void* buffer) override;
59 MemorySnapshot memorySnapshot() const override;
60 virtual void freePage(physical_uintptr_t page) override;
61 virtual bool allocateRegion(MemoryRegion& Region, size_t cPages, size_t pageConstraints,
62 size_t Flags, physical_uintptr_t start = -1) override;
63
64 virtual void pin(physical_uintptr_t page) override;
65
69
71 void initialisationDone();
72
73 const RangeList<uint64_t>& getAcpiRanges() const {
74 return m_AcpiRanges;
75 }
76
77 protected:
81 virtual ~HostedPhysicalMemoryManager() override;
82
83 private:
90
91 inline int getBackingFile() const {
92 return m_BackingFile;
93 }
94
95#if PEDIGREE_HOSTED_SMOKE_TESTS
96 size_t pageReferenceCountForTestImpl(physical_uintptr_t page);
97#endif
98
99 void unmapRegion(MemoryRegion* pRegion) override;
100
103 virtual void freePageUnlocked(physical_uintptr_t page) override;
104
106
109
112
117
118 RangeList<uint64_t> m_AcpiRanges;
119
121 Spinlock m_Lock, m_RegionLock;
122
125 public:
126 PageHashable() {
127 m_Hash = m_Page = 0;
128 }
129
130 PageHashable(physical_uintptr_t p) {
131 m_Hash = p / getPageSize();
132 m_Page = p;
133 }
134
135 size_t hash() const {
136 return m_Hash;
137 }
138
139 bool operator==(const PageHashable& p) const {
140 return p.m_Page == m_Page;
141 }
142
143 private:
144 size_t m_Hash;
145 physical_uintptr_t m_Page;
146 };
147
149 struct page {
150 page() : active(false), refcount(0) {}
151
152 bool active;
153 size_t refcount;
154 };
155
157
160
163
166};
167
170#endif
Definition Cache.h:207
Implementation of the PhysicalMemoryManager for common x86.
virtual physical_uintptr_t allocatePage(size_t pageConstraints=0) override
virtual void freePage(physical_uintptr_t page) override
void unmapRegion(MemoryRegion *pRegion) override
static HostedPhysicalMemoryManager & instance()
virtual void pin(physical_uintptr_t page) override
virtual bool allocateRegion(MemoryRegion &Region, size_t cPages, size_t pageConstraints, size_t Flags, physical_uintptr_t start=-1) override
void initialise(const BootstrapStruct_t &Info) INITIALISATION_ONLY
virtual void freePageUnlocked(physical_uintptr_t page) override
Special memory entity in the kernel's virtual address space.