diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-11-14 17:20:53 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-11-22 14:20:36 +0100 |
| commit | 1071297ee44d5102feb92b7a5d5ceb44e90622b7 (patch) | |
| tree | e9a255b01d2ad15449d74a1b1213979373b700da /kapi | |
| parent | 36a2fd5eb75e87bfe6f6f6c775ebac3d80902110 (diff) | |
| download | kernel-1071297ee44d5102feb92b7a5d5ceb44e90622b7.tar.xz kernel-1071297ee44d5102feb92b7a5d5ceb44e90622b7.zip | |
memory: improve MMIO allocation/mapping robustness
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/kapi/memory.hpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/kapi/kapi/memory.hpp b/kapi/kapi/memory.hpp index 2ae8b91b..4cdd6ac1 100644 --- a/kapi/kapi/memory.hpp +++ b/kapi/kapi/memory.hpp @@ -10,6 +10,7 @@ #include <kapi/memory/page_mapper.hpp> // IWYU pragma: export #include <kstd/memory.hpp> +#include <kstd/result.hpp> #include <cstddef> #include <optional> @@ -94,8 +95,10 @@ namespace kapi::memory //! Allocate a Memory-mapped I/O region of the given size. //! //! @warning This function will panic if the MMIO system has not been initialized! + //! //! @param page_count The number of pages to allocate. - auto allocate_mmio_region(std::size_t page_count) -> mmio_region; + //! @return The newly allocated MMIO region on success, an error otherwise. + auto allocate_mmio_region(std::size_t page_count) -> kstd::result<mmio_region>; //! Map a region of Memory-mapped I/O address space to a given hardware address using the given flags. //! @@ -107,10 +110,15 @@ namespace kapi::memory //! @param region The region to map. //! @param hw_base The base of the hardware region. //! @param flags The flags to apply. + //! @return A result containing a pointer to the first byte of the mapped region on success, an error otherwise, in + //! which case any partial mappings have been rolled back. auto map_mmio_region(mmio_region region, physical_address hw_base, page_mapper::flags flags = {}) - -> kstd::observer_ptr<std::byte>; + -> kstd::result<kstd::observer_ptr<std::byte>>; - //! Release a Memory-mapped I/O region. + //! Release (unmap and free) a Memory-mapped I/O region. + //! + //! This function is tolerant of partially mapped regions and will unmap any mapped pages within the region before + //! releasing the MMIO region. //! //! @warning This function will panic if the MMIO system has not been initialized! //! @param region The region to release. |
