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/include | |
| parent | 0bbec5ceba0df5668ab1aedcbf2905bf599f6eba (diff) | |
| download | teachos-878852c94c4d56f303366cec177b3edef9b3b9c5.tar.xz teachos-878852c94c4d56f303366cec177b3edef9b3b9c5.zip | |
kapi: add basic support for MMIO mapping
Diffstat (limited to 'kernel/include')
| -rw-r--r-- | kernel/include/kernel/memory/mmio_allocator.hpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/kernel/include/kernel/memory/mmio_allocator.hpp b/kernel/include/kernel/memory/mmio_allocator.hpp new file mode 100644 index 0000000..4ec6bec --- /dev/null +++ b/kernel/include/kernel/memory/mmio_allocator.hpp @@ -0,0 +1,41 @@ +#ifndef TEACHOS_KERNEL_MEMORY_MMIO_ALLOCATOR_HPP +#define TEACHOS_KERNEL_MEMORY_MMIO_ALLOCATOR_HPP + +#include "kapi/memory.hpp" + +#include <kstd/allocator> +#include <kstd/memory> + +#include <cstddef> + +namespace kernel::memory +{ + + struct mmio_allocator + { + mmio_allocator(kapi::memory::linear_address base, std::size_t pages); + + [[nodiscard]] auto allocate(std::size_t page_count) -> kapi::memory::linear_address; + auto release(kapi::memory::linear_address base) -> void; + + private: + struct node + { + kapi::memory::linear_address base{}; + std::size_t page_count{}; + node * next{}; + node * previous{}; + bool is_free{}; + }; + + auto make_node(kapi::memory::linear_address base, std::size_t page_count, node * next, node * previous, + bool is_free) -> node *; + auto destroy_node(node *) -> void; + + [[no_unique_address]] kstd::allocator<node> m_allocator{}; + node * m_head{}; + }; + +} // namespace kernel::memory + +#endif |
