diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-08 13:54:52 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-08 13:54:52 +0200 |
| commit | 878852c94c4d56f303366cec177b3edef9b3b9c5 (patch) | |
| tree | b7c33b89201f6a8ae55fdc4ba041c4f1b9b97f99 /kernel/kapi | |
| parent | 0bbec5ceba0df5668ab1aedcbf2905bf599f6eba (diff) | |
| download | teachos-878852c94c4d56f303366cec177b3edef9b3b9c5.tar.xz teachos-878852c94c4d56f303366cec177b3edef9b3b9c5.zip | |
kapi: add basic support for MMIO mapping
Diffstat (limited to 'kernel/kapi')
| -rw-r--r-- | kernel/kapi/memory.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/kernel/kapi/memory.cpp b/kernel/kapi/memory.cpp index 06a3165..b224c50 100644 --- a/kernel/kapi/memory.cpp +++ b/kernel/kapi/memory.cpp @@ -3,6 +3,7 @@ #include "kapi/system.hpp" #include "kernel/memory/bitmap_allocator.hpp" +#include "kernel/memory/mmio_allocator.hpp" #include <kstd/print> #include <kstd/units> @@ -63,6 +64,7 @@ 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>{}; } // namespace constinit auto static active_frame_allocator = static_cast<frame_allocator *>(&bad_frame_allocator::instance); @@ -147,4 +149,27 @@ 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) -> linear_address + { + auto region = mmio_allocator->allocate(page_count); + return region; + } + + auto map_mmio_region(linear_address base, physical_address hw_base, page_mapper::flags flags) -> std::byte * + { + auto start_page = page::containing(base); + auto start_frame = frame::containing(hw_base); + return map(start_page, start_frame, flags | page_mapper::flags::uncached); + } + + auto release_mmio_region(linear_address base) -> void + { + mmio_allocator->release(base); + } + } // namespace kapi::memory |
