2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-22 00:12:45 +00:00
|
|
|
#include <Kernel/Heap/kmalloc.h>
|
2019-04-03 13:13:07 +00:00
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
2019-06-07 09:43:58 +00:00
|
|
|
#include <Kernel/VM/PhysicalPage.h>
|
2019-04-03 13:13:07 +00:00
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-06-21 16:37:47 +00:00
|
|
|
NonnullRefPtr<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist)
|
2019-04-03 13:13:07 +00:00
|
|
|
{
|
2021-07-08 01:50:05 +00:00
|
|
|
auto& physical_page_entry = MM.get_physical_page_entry(paddr);
|
|
|
|
return adopt_ref(*new (&physical_page_entry.physical_page) PhysicalPage(supervisor, may_return_to_freelist));
|
2019-04-03 13:13:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 01:50:05 +00:00
|
|
|
PhysicalPage::PhysicalPage(bool supervisor, bool may_return_to_freelist)
|
2019-04-03 13:13:07 +00:00
|
|
|
: m_may_return_to_freelist(may_return_to_freelist)
|
|
|
|
, m_supervisor(supervisor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-07-08 01:50:05 +00:00
|
|
|
PhysicalAddress PhysicalPage::paddr() const
|
|
|
|
{
|
|
|
|
return MM.get_physical_address(*this);
|
|
|
|
}
|
|
|
|
|
2020-08-22 03:49:50 +00:00
|
|
|
void PhysicalPage::return_to_freelist() const
|
2019-04-03 13:13:07 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY((paddr().get() & ~PAGE_MASK) == 0);
|
2019-06-11 11:13:02 +00:00
|
|
|
|
2019-04-03 13:13:07 +00:00
|
|
|
if (m_supervisor)
|
2020-08-22 03:49:50 +00:00
|
|
|
MM.deallocate_supervisor_physical_page(*this);
|
2019-04-03 13:13:07 +00:00
|
|
|
else
|
2020-08-22 03:49:50 +00:00
|
|
|
MM.deallocate_user_physical_page(*this);
|
2019-04-03 13:13:07 +00:00
|
|
|
}
|
2020-02-16 00:27:42 +00:00
|
|
|
|
|
|
|
}
|