mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 07:05:08 +00:00
Kernel: Convert the PhysicalPage bool parameter to an enum
This commit is contained in:
parent
399be9bcc3
commit
d879709ec7
6 changed files with 18 additions and 13 deletions
|
@ -23,7 +23,7 @@ UNMAP_AFTER_INIT DeviceConfigurationSpaceMapping::DeviceConfigurationSpaceMappin
|
||||||
PhysicalAddress segment_lower_addr = mmio_segment.get_paddr();
|
PhysicalAddress segment_lower_addr = mmio_segment.get_paddr();
|
||||||
PhysicalAddress device_physical_mmio_space = segment_lower_addr.offset(
|
PhysicalAddress device_physical_mmio_space = segment_lower_addr.offset(
|
||||||
PCI_MMIO_CONFIG_SPACE_SIZE * m_device_address.function() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE) * m_device_address.device() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE * PCI_MAX_DEVICES_PER_BUS) * (m_device_address.bus() - mmio_segment.get_start_bus()));
|
PCI_MMIO_CONFIG_SPACE_SIZE * m_device_address.function() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE) * m_device_address.device() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE * PCI_MAX_DEVICES_PER_BUS) * (m_device_address.bus() - mmio_segment.get_start_bus()));
|
||||||
m_mapped_region->physical_page_slot(0) = PhysicalPage::create(device_physical_mmio_space, false);
|
m_mapped_region->physical_page_slot(0) = PhysicalPage::create(device_physical_mmio_space, MayReturnToFreeList::No);
|
||||||
m_mapped_region->remap();
|
m_mapped_region->remap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ AnonymousVMObject::AnonymousVMObject(PhysicalAddress paddr, size_t size)
|
||||||
{
|
{
|
||||||
VERIFY(paddr.page_base() == paddr);
|
VERIFY(paddr.page_base() == paddr);
|
||||||
for (size_t i = 0; i < page_count(); ++i)
|
for (size_t i = 0; i < page_count(); ++i)
|
||||||
physical_pages()[i] = PhysicalPage::create(paddr.offset(i * PAGE_SIZE), false);
|
physical_pages()[i] = PhysicalPage::create(paddr.offset(i * PAGE_SIZE), MayReturnToFreeList::No);
|
||||||
}
|
}
|
||||||
|
|
||||||
AnonymousVMObject::AnonymousVMObject(PhysicalPage& page)
|
AnonymousVMObject::AnonymousVMObject(PhysicalPage& page)
|
||||||
|
|
|
@ -475,7 +475,7 @@ UNMAP_AFTER_INIT void MemoryManager::initialize_physical_pages()
|
||||||
auto pt_paddr = page_tables_base.offset(pt_index * PAGE_SIZE);
|
auto pt_paddr = page_tables_base.offset(pt_index * PAGE_SIZE);
|
||||||
auto physical_page_index = PhysicalAddress::physical_page_index(pt_paddr.get());
|
auto physical_page_index = PhysicalAddress::physical_page_index(pt_paddr.get());
|
||||||
auto& physical_page_entry = m_physical_page_entries[physical_page_index];
|
auto& physical_page_entry = m_physical_page_entries[physical_page_index];
|
||||||
auto physical_page = adopt_ref(*new (&physical_page_entry.allocated.physical_page) PhysicalPage(false));
|
auto physical_page = adopt_ref(*new (&physical_page_entry.allocated.physical_page) PhysicalPage(MayReturnToFreeList::No));
|
||||||
auto result = kernel_page_tables.set(virtual_page_array_current_page & ~0x1fffff, move(physical_page));
|
auto result = kernel_page_tables.set(virtual_page_array_current_page & ~0x1fffff, move(physical_page));
|
||||||
VERIFY(result == AK::HashSetResult::InsertedNewEntry);
|
VERIFY(result == AK::HashSetResult::InsertedNewEntry);
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ UNMAP_AFTER_INIT void PageDirectory::allocate_kernel_directory()
|
||||||
#if ARCH(X86_64)
|
#if ARCH(X86_64)
|
||||||
PhysicalAddress boot_pml4t_paddr(virtual_to_low_physical((FlatPtr)boot_pml4t));
|
PhysicalAddress boot_pml4t_paddr(virtual_to_low_physical((FlatPtr)boot_pml4t));
|
||||||
dmesgln("MM: boot_pml4t @ {}", boot_pml4t_paddr);
|
dmesgln("MM: boot_pml4t @ {}", boot_pml4t_paddr);
|
||||||
m_pml4t = PhysicalPage::create(boot_pml4t_paddr, false);
|
m_pml4t = PhysicalPage::create(boot_pml4t_paddr, MayReturnToFreeList::No);
|
||||||
#endif
|
#endif
|
||||||
PhysicalAddress boot_pdpt_paddr(virtual_to_low_physical((FlatPtr)boot_pdpt));
|
PhysicalAddress boot_pdpt_paddr(virtual_to_low_physical((FlatPtr)boot_pdpt));
|
||||||
PhysicalAddress boot_pd0_paddr(virtual_to_low_physical((FlatPtr)boot_pd0));
|
PhysicalAddress boot_pd0_paddr(virtual_to_low_physical((FlatPtr)boot_pd0));
|
||||||
|
@ -55,9 +55,9 @@ UNMAP_AFTER_INIT void PageDirectory::allocate_kernel_directory()
|
||||||
dmesgln("MM: boot_pdpt @ {}", boot_pdpt_paddr);
|
dmesgln("MM: boot_pdpt @ {}", boot_pdpt_paddr);
|
||||||
dmesgln("MM: boot_pd0 @ {}", boot_pd0_paddr);
|
dmesgln("MM: boot_pd0 @ {}", boot_pd0_paddr);
|
||||||
dmesgln("MM: boot_pd3 @ {}", boot_pd3_paddr);
|
dmesgln("MM: boot_pd3 @ {}", boot_pd3_paddr);
|
||||||
m_directory_table = PhysicalPage::create(boot_pdpt_paddr, false);
|
m_directory_table = PhysicalPage::create(boot_pdpt_paddr, MayReturnToFreeList::No);
|
||||||
m_directory_pages[0] = PhysicalPage::create(boot_pd0_paddr, false);
|
m_directory_pages[0] = PhysicalPage::create(boot_pd0_paddr, MayReturnToFreeList::No);
|
||||||
m_directory_pages[3] = PhysicalPage::create(boot_pd3_paddr, false);
|
m_directory_pages[3] = PhysicalPage::create(boot_pd3_paddr, MayReturnToFreeList::No);
|
||||||
}
|
}
|
||||||
|
|
||||||
PageDirectory::PageDirectory(const RangeAllocator* parent_range_allocator)
|
PageDirectory::PageDirectory(const RangeAllocator* parent_range_allocator)
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
NonnullRefPtr<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool may_return_to_freelist)
|
NonnullRefPtr<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, MayReturnToFreeList may_return_to_freelist)
|
||||||
{
|
{
|
||||||
auto& physical_page_entry = MM.get_physical_page_entry(paddr);
|
auto& physical_page_entry = MM.get_physical_page_entry(paddr);
|
||||||
return adopt_ref(*new (&physical_page_entry.allocated.physical_page) PhysicalPage(may_return_to_freelist));
|
return adopt_ref(*new (&physical_page_entry.allocated.physical_page) PhysicalPage(may_return_to_freelist));
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicalPage::PhysicalPage(bool may_return_to_freelist)
|
PhysicalPage::PhysicalPage(MayReturnToFreeList may_return_to_freelist)
|
||||||
: m_may_return_to_freelist(may_return_to_freelist)
|
: m_may_return_to_freelist(may_return_to_freelist)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ PhysicalAddress PhysicalPage::paddr() const
|
||||||
void PhysicalPage::free_this()
|
void PhysicalPage::free_this()
|
||||||
{
|
{
|
||||||
auto paddr = MM.get_physical_address(*this);
|
auto paddr = MM.get_physical_address(*this);
|
||||||
if (m_may_return_to_freelist) {
|
if (m_may_return_to_freelist == MayReturnToFreeList::Yes) {
|
||||||
auto& this_as_freelist_entry = MM.get_physical_page_entry(paddr).freelist;
|
auto& this_as_freelist_entry = MM.get_physical_page_entry(paddr).freelist;
|
||||||
this->~PhysicalPage(); // delete in place
|
this->~PhysicalPage(); // delete in place
|
||||||
this_as_freelist_entry.next_index = -1;
|
this_as_freelist_entry.next_index = -1;
|
||||||
|
|
|
@ -11,6 +11,11 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
enum class MayReturnToFreeList : bool {
|
||||||
|
No,
|
||||||
|
Yes
|
||||||
|
};
|
||||||
|
|
||||||
class PhysicalPage {
|
class PhysicalPage {
|
||||||
AK_MAKE_NONCOPYABLE(PhysicalPage);
|
AK_MAKE_NONCOPYABLE(PhysicalPage);
|
||||||
AK_MAKE_NONMOVABLE(PhysicalPage);
|
AK_MAKE_NONMOVABLE(PhysicalPage);
|
||||||
|
@ -31,7 +36,7 @@ public:
|
||||||
free_this();
|
free_this();
|
||||||
}
|
}
|
||||||
|
|
||||||
static NonnullRefPtr<PhysicalPage> create(PhysicalAddress, bool may_return_to_freelist = true);
|
static NonnullRefPtr<PhysicalPage> create(PhysicalAddress, MayReturnToFreeList may_return_to_freelist = MayReturnToFreeList::Yes);
|
||||||
|
|
||||||
u32 ref_count() const { return m_ref_count.load(AK::memory_order_consume); }
|
u32 ref_count() const { return m_ref_count.load(AK::memory_order_consume); }
|
||||||
|
|
||||||
|
@ -39,13 +44,13 @@ public:
|
||||||
bool is_lazy_committed_page() const;
|
bool is_lazy_committed_page() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit PhysicalPage(bool may_return_to_freelist = true);
|
explicit PhysicalPage(MayReturnToFreeList may_return_to_freelist);
|
||||||
~PhysicalPage() = default;
|
~PhysicalPage() = default;
|
||||||
|
|
||||||
void free_this();
|
void free_this();
|
||||||
|
|
||||||
Atomic<u32> m_ref_count { 1 };
|
Atomic<u32> m_ref_count { 1 };
|
||||||
bool m_may_return_to_freelist { true };
|
MayReturnToFreeList m_may_return_to_freelist { MayReturnToFreeList::Yes };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PhysicalPageEntry {
|
struct PhysicalPageEntry {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue