MemoryManager: Add get_kernel_mapping_for_frames()
This function allocates a continuous range of VM and maps the physical frames passed to said VM range.
This commit is contained in:
parent
74235c2c99
commit
6ff92b1714
@ -247,6 +247,32 @@ namespace MemoryManager
|
||||
return start;
|
||||
}
|
||||
|
||||
Result<u64> get_kernel_mapping_for_frames(u64 phys, usize count, int flags)
|
||||
{
|
||||
u64 start = TRY(KernelVM::alloc_several_pages(count));
|
||||
|
||||
usize pages_mapped = 0;
|
||||
|
||||
auto guard = make_scope_guard([=, &pages_mapped] {
|
||||
KernelVM::free_several_pages(start, pages_mapped);
|
||||
unmap_weak(start, pages_mapped);
|
||||
});
|
||||
|
||||
u64 virt = start;
|
||||
|
||||
while (pages_mapped < count)
|
||||
{
|
||||
TRY(MMU::map(virt, phys, flags));
|
||||
virt += ARCH_PAGE_SIZE;
|
||||
phys += ARCH_PAGE_SIZE;
|
||||
pages_mapped++;
|
||||
}
|
||||
|
||||
guard.deactivate();
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
Result<void> unmap_owned(u64 virt, usize count)
|
||||
{
|
||||
CHECK_PAGE_ALIGNED(virt);
|
||||
|
@ -25,6 +25,8 @@ namespace MemoryManager
|
||||
Result<u64> alloc_at(u64 virt, usize count, int flags);
|
||||
Result<u64> alloc_for_kernel(usize count, int flags);
|
||||
|
||||
Result<u64> get_kernel_mapping_for_frames(u64 phys, usize count, int flags);
|
||||
|
||||
Result<void> unmap_owned(u64 virt, usize count);
|
||||
Result<void> unmap_owned_and_free_vm(u64 virt, usize count);
|
||||
Result<void> unmap_weak(u64 virt, usize count);
|
||||
|
Loading…
Reference in New Issue
Block a user