Kernel: Add API for getting contiguous physcial pages

This will be used to create DMA regions.
This commit is contained in:
2023-10-08 02:41:05 +03:00
parent 0fae2c7309
commit 799aab02f5
4 changed files with 95 additions and 1 deletions

View File

@@ -79,6 +79,25 @@ namespace Kernel
ASSERT_NOT_REACHED();
}
paddr_t Heap::take_free_contiguous_pages(size_t pages)
{
LockGuard _(m_lock);
for (auto& range : m_physical_ranges)
if (range.free_pages() >= pages)
if (paddr_t paddr = range.reserve_contiguous_pages(pages))
return paddr;
return 0;
}
void Heap::release_contiguous_pages(paddr_t paddr, size_t pages)
{
LockGuard _(m_lock);
for (auto& range : m_physical_ranges)
if (range.contains(paddr))
return range.release_contiguous_pages(paddr, pages);
ASSERT_NOT_REACHED();
}
size_t Heap::used_pages() const
{
LockGuard _(m_lock);