Iros
 
Loading...
Searching...
No Matches
physical_page.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/assert/prelude.h"
6#include "di/meta/trivial.h"
8#include "di/types/integers.h"
9#include "di/types/prelude.h"
10#include "di/util/prelude.h"
15
16namespace iris::mm {
30
31struct BackedPhysicalPage;
32
40
42 static void did_remove(auto&, auto& node);
43};
44
46struct BackedPhysicalPage : di::IntrusiveTreeSetNode<BackedPhysicalPageTreeTag> {
48
51
52private:
53 constexpr friend auto operator==(BackedPhysicalPage const& a, BackedPhysicalPage const& b) -> bool {
54 return a.page_number == b.page_number;
55 }
56 constexpr friend auto operator<=>(BackedPhysicalPage const& a, BackedPhysicalPage const& b) -> di::strong_ordering {
57 return a.page_number <=> b.page_number;
58 }
59
60 constexpr friend auto operator==(BackedPhysicalPage const& a, u64 b) -> bool { return a.page_number == b; }
61 constexpr friend auto operator<=>(BackedPhysicalPage const& a, u64 b) -> di::strong_ordering {
62 return a.page_number <=> b;
63 }
64};
65
77
78constexpr inline auto physical_page_base =
79 VirtualAddress(0xFFFF800000000000_u64 + 4096_u64 * 512_u64 * 512_u64 * 512_u64);
80
81namespace detail {
83 auto operator()(PhysicalPage const& page) const -> PhysicalAddress {
84 return void_pointer_to_physical_address(&page);
85 }
86
87 auto operator()(BackedPhysicalPage const& page) const -> PhysicalAddress {
88 return void_pointer_to_physical_address(&page);
89 }
90
92 return void_pointer_to_physical_address(&page);
93 }
94
95 private:
96 static auto void_pointer_to_physical_address(void const* pointer) -> PhysicalAddress {
97 auto page_number = (VirtualAddress(di::to_uintptr(pointer)) - physical_page_base) / sizeof(PhysicalPage);
98 return PhysicalAddress(page_number * 4096);
99 }
100 };
101}
102
104
106 ASSERT(address.raw_value() % 4096 == 0);
107 auto const page_number = address.raw_value() / 4096;
108 return *(reinterpret_cast<PhysicalPage*>(physical_page_base.raw_value()) + page_number);
109}
110
112 return physical_page(address).as_page_structure_page;
113}
114
116 return physical_page(address).as_backed_page;
117}
118
119namespace detail {
120 struct BumpPage {
124
125 void operator()(PhysicalAddress address) const {
126 auto& page = backed_page(address);
127 page.reference_count.fetch_add(1, di::sync::MemoryOrder::AcquireRelease);
128 }
129 };
130}
131
132constexpr inline auto bump_page = detail::BumpPage {};
133
134namespace detail {
141
142 void operator()(PhysicalAddress address) const {
143 auto& page = backed_page(address);
144 if (page.reference_count.fetch_sub(1, di::sync::MemoryOrder::AcquireRelease) == 1) {
146 }
147 }
148 };
149}
150
152
154 drop_page(node);
155}
156}
#define ASSERT
Definition assert_bool.h:16
Definition list_node.h:9
Definition list_forward_declaration.h:12
Definition atomic.h:15
constexpr auto fetch_add(DeltaType delta, MemoryOrder order=MemoryOrder::SequentialConsistency) -> T requires(concepts::Integral< T >||concepts::Pointer< T >)
Definition atomic.h:88
constexpr auto fetch_sub(DeltaType delta, MemoryOrder order=MemoryOrder::SequentialConsistency) -> T requires(concepts::Integral< T >||concepts::Pointer< T >)
Definition atomic.h:99
RBTreeNode< Tag > IntrusiveTreeSetNode
Definition tree_set.h:11
@ AcquireRelease
Definition memory_order.h:11
__UINT64_TYPE__ u64
Definition integers.h:12
di::meta::Decay< decltype(T)> Tag
Definition tag_invoke.h:28
constexpr auto to_uintptr
Definition to_uintptr.h:13
Definition object_pool.h:14
Definition physical_page.h:81
Definition address_space.cpp:20
void deallocate_page_frame(PhysicalAddress)
Definition page_frame_allocator.cpp:81
auto page_structure_page(PhysicalAddress address) -> PageStructurePhysicalPage &
Definition physical_page.h:111
constexpr auto bump_page
Definition physical_page.h:132
constexpr auto physical_page_base
Definition physical_page.h:78
di::StrongInt< VirtualAddressTag > VirtualAddress
Definition virtual_address.h:25
constexpr auto drop_page
Definition physical_page.h:151
di::StrongInt< PhysicalAddressTag > PhysicalAddress
Definition physical_address.h:12
constexpr auto physical_address
Definition physical_page.h:103
auto backed_page(PhysicalAddress address) -> BackedPhysicalPage &
Definition physical_page.h:115
auto physical_page(PhysicalAddress address) -> PhysicalPage &
Definition physical_page.h:105
Definition intrusive_tag_base.h:8
Definition in_place_type.h:5
Definition physical_page.h:33
friend void tag_invoke(di::Tag< di::vocab::intrusive_ptr_increment >, di::InPlaceType< BackedPhysicalPagePtrTag >, BackedPhysicalPage *ptr)
friend void tag_invoke(di::Tag< di::vocab::intrusive_ptr_decrement >, di::InPlaceType< BackedPhysicalPagePtrTag >, BackedPhysicalPage *ptr)
Definition physical_page.h:41
static void did_remove(auto &, auto &node)
Definition physical_page.h:153
A physical page of memory tracked by a backing object.
Definition physical_page.h:46
constexpr friend auto operator<=>(BackedPhysicalPage const &a, u64 b) -> di::strong_ordering
Definition physical_page.h:61
constexpr friend auto operator==(BackedPhysicalPage const &a, BackedPhysicalPage const &b) -> bool
Definition physical_page.h:53
u64 page_number
Definition physical_page.h:50
constexpr BackedPhysicalPage(u64 page_number)
Definition physical_page.h:47
constexpr friend auto operator<=>(BackedPhysicalPage const &a, BackedPhysicalPage const &b) -> di::strong_ordering
Definition physical_page.h:56
constexpr friend auto operator==(BackedPhysicalPage const &a, u64 b) -> bool
Definition physical_page.h:60
di::sync::Atomic< usize > reference_count
Definition physical_page.h:49
Definition physical_page.h:20
Definition physical_page.h:19
A physical page of memory used for the page tables themselves.
Definition physical_page.h:18
u64 mapped_page_count
Definition physical_page.h:27
di::IntrusiveList< PageStructurePhysicalPage > children
Definition physical_page.h:26
constexpr PageStructurePhysicalPage(Parent)
Definition physical_page.h:22
constexpr PageStructurePhysicalPage(Leaf)
Definition physical_page.h:23
A physical page of memory.
Definition physical_page.h:71
BackedPhysicalPage as_backed_page
Definition physical_page.h:74
PageStructurePhysicalPage as_page_structure_page
Definition physical_page.h:73
Definition physical_page.h:120
void operator()(BackedPhysicalPage &page) const
Definition physical_page.h:121
void operator()(PhysicalAddress address) const
Definition physical_page.h:125
Definition physical_page.h:135
void operator()(PhysicalAddress address) const
Definition physical_page.h:142
void operator()(BackedPhysicalPage &page) const
Definition physical_page.h:136
Definition physical_page.h:82
auto operator()(PhysicalPage const &page) const -> PhysicalAddress
Definition physical_page.h:83
auto operator()(PageStructurePhysicalPage const &page) const -> PhysicalAddress
Definition physical_page.h:91
auto operator()(BackedPhysicalPage const &page) const -> PhysicalAddress
Definition physical_page.h:87