aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/kapi/memory.cpp')
-rw-r--r--kernel/kapi/memory.cpp87
1 files changed, 0 insertions, 87 deletions
diff --git a/kernel/kapi/memory.cpp b/kernel/kapi/memory.cpp
index 12e9e23f..4160092d 100644
--- a/kernel/kapi/memory.cpp
+++ b/kernel/kapi/memory.cpp
@@ -1,14 +1,11 @@
#include <kapi/memory.hpp>
#include <kernel/memory/bitmap_allocator.hpp>
-#include <kernel/memory/mmio_allocator.hpp>
#include <kapi/system.hpp>
#include <kstd/memory.hpp>
#include <kstd/print.hpp>
-#include <kstd/result.hpp>
-#include <kstd/system_error.hpp>
#include <kstd/units.hpp>
#include <algorithm>
@@ -67,23 +64,10 @@ namespace kapi::memory
constinit bad_frame_allocator bad_frame_allocator::instance{};
constinit bad_page_mapper bad_page_mapper::instance{};
auto constinit allocator = std::optional<kernel::memory::bitmap_frame_allocator>{};
- auto constinit mmio_allocator = std::optional<kernel::memory::mmio_allocator>{};
constinit auto active_frame_allocator = static_cast<frame_allocator *>(&bad_frame_allocator::instance);
constinit auto active_page_mapper = static_cast<page_mapper *>(&bad_page_mapper::instance);
- auto unmap_range_if_mapped(page start, std::size_t count) -> void
- {
- for (auto page_index = 0uz; page_index < count; ++page_index)
- {
- auto const current_page = start + page_index;
-
- // NOTE: We ignore the returned frame, since it has never been allocated by any kernel code. Rather, this frame
- // corresponds to a frame which is "always present" since it is an abstraction of a memory mapped device,
- // provided by the firmware. Additionally, we use try unmap to avoid panicking if the page was not mapped.
- std::ignore = active_page_mapper->try_unmap(current_page);
- }
- }
} // namespace
auto get_frame_allocator() -> frame_allocator &
@@ -165,75 +149,4 @@ namespace kapi::memory
kstd::println("[OS:MEM] Physical memory manager initialized.");
}
- auto init_mmio(linear_address base, std::size_t page_count) -> void
- {
- mmio_allocator.emplace(base, page_count);
- }
-
- auto allocate_mmio_region(std::size_t page_count) -> kstd::result<mmio_region>
- {
- if (!mmio_allocator)
- {
- system::panic("[OS:MEM] MMIO allocator not initialized!");
- }
-
- return mmio_allocator->allocate(page_count).transform([&](auto base) -> mmio_region { return {base, page_count}; });
- }
-
- auto map_mmio_region(mmio_region region, physical_address hw_base, page_mapper::flags flags)
- -> kstd::result<kstd::observer_ptr<std::byte>>
- {
- // Ensure that the MMIO region is not mapped as executable. Asking for an executable mapping of an MMIO region is a
- // logical error, not a runtime issue.
- if ((flags & page_mapper::flags::executable) != page_mapper::flags::empty)
- {
- system::panic("[OS:MEM] Attempt to map MMIO region at {:#018x} as executable!", region.first);
- }
-
- auto [start, count] = region;
-
- auto start_page = page::containing(start);
- auto start_frame = frame::containing(hw_base);
- auto frame_offset = hw_base.raw() % frame::size.value;
-
- flags |= page_mapper::flags::uncached | page_mapper::flags::supervisor_only | page_mapper::flags::global;
-
- auto first_mapped_page = map(start_page, start_frame, flags);
-
- if (!first_mapped_page)
- {
- return kstd::failure(make_error_code(kstd::errc::not_enough_memory));
- }
-
- for (auto page_index = 1uz; page_index < count; ++page_index)
- {
- auto page = start_page + page_index;
- auto frame = start_frame + page_index;
- auto mapped = map(page, frame, flags);
-
- if (!mapped)
- {
- unmap_range_if_mapped(start_page, page_index);
- return kstd::failure(make_error_code(kstd::errc::not_enough_memory));
- }
- }
-
- return kstd::success(first_mapped_page + frame_offset);
- }
-
- auto release_mmio_region(mmio_region region) -> void
- {
- if (!mmio_allocator)
- {
- system::panic("[OS:MEM] MMIO allocator not initialized!");
- }
-
- auto start_address = region.first;
- auto start_page = kapi::memory::page::containing(start_address);
-
- unmap_range_if_mapped(start_page, region.second);
-
- mmio_allocator->release(region.first);
- }
-
} // namespace kapi::memory