mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 18:55:07 +00:00
Kernel: Remove ContiguousVMObject, let AnonymousVMObject do the job
We don't need an entirely separate VMObject subclass to influence the location of the physical pages. Instead, we simply allocate enough physically contiguous memory first, and then pass it to the AnonymousVMObject constructor that takes a span of physical pages.
This commit is contained in:
parent
9a701eafc4
commit
6a537ceef1
10 changed files with 18 additions and 89 deletions
|
@ -289,7 +289,7 @@ void UHCIController::reset()
|
|||
}
|
||||
|
||||
// Let's allocate the physical page for the Frame List (which is 4KiB aligned)
|
||||
auto framelist_vmobj = ContiguousVMObject::try_create_with_size(PAGE_SIZE);
|
||||
auto framelist_vmobj = AnonymousVMObject::try_create_physically_contiguous_with_size(PAGE_SIZE);
|
||||
m_framelist = MemoryManager::the().allocate_kernel_region_with_vmobject(*framelist_vmobj, PAGE_SIZE, "UHCI Framelist", Region::Access::Write);
|
||||
dbgln("UHCI: Allocated framelist at physical address {}", m_framelist->physical_page(0)->paddr());
|
||||
dbgln("UHCI: Framelist is at virtual address {}", m_framelist->vaddr());
|
||||
|
@ -311,7 +311,7 @@ UNMAP_AFTER_INIT void UHCIController::create_structures()
|
|||
{
|
||||
// Let's allocate memory for both the QH and TD pools
|
||||
// First the QH pool and all of the Interrupt QH's
|
||||
auto qh_pool_vmobject = ContiguousVMObject::try_create_with_size(2 * PAGE_SIZE);
|
||||
auto qh_pool_vmobject = AnonymousVMObject::try_create_physically_contiguous_with_size(2 * PAGE_SIZE);
|
||||
m_qh_pool = MemoryManager::the().allocate_kernel_region_with_vmobject(*qh_pool_vmobject, 2 * PAGE_SIZE, "UHCI Queue Head Pool", Region::Access::Write);
|
||||
memset(m_qh_pool->vaddr().as_ptr(), 0, 2 * PAGE_SIZE); // Zero out both pages
|
||||
|
||||
|
@ -331,7 +331,7 @@ UNMAP_AFTER_INIT void UHCIController::create_structures()
|
|||
m_dummy_qh = allocate_queue_head();
|
||||
|
||||
// Now the Transfer Descriptor pool
|
||||
auto td_pool_vmobject = ContiguousVMObject::try_create_with_size(2 * PAGE_SIZE);
|
||||
auto td_pool_vmobject = AnonymousVMObject::try_create_physically_contiguous_with_size(2 * PAGE_SIZE);
|
||||
m_td_pool = MemoryManager::the().allocate_kernel_region_with_vmobject(*td_pool_vmobject, 2 * PAGE_SIZE, "UHCI Transfer Descriptor Pool", Region::Access::Write);
|
||||
memset(m_td_pool->vaddr().as_ptr(), 0, 2 * PAGE_SIZE);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <Kernel/IO.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Time/TimeManagement.h>
|
||||
#include <Kernel/VM/ContiguousVMObject.h>
|
||||
#include <Kernel/VM/AnonymousVMObject.h>
|
||||
|
||||
namespace Kernel::USB {
|
||||
|
||||
|
|
|
@ -11,14 +11,14 @@ namespace Kernel::USB {
|
|||
|
||||
RefPtr<Transfer> Transfer::try_create(Pipe& pipe, u16 len)
|
||||
{
|
||||
auto vmobject = ContiguousVMObject::try_create_with_size(PAGE_SIZE);
|
||||
auto vmobject = AnonymousVMObject::try_create_physically_contiguous_with_size(PAGE_SIZE);
|
||||
if (!vmobject)
|
||||
return nullptr;
|
||||
|
||||
return AK::try_create<Transfer>(pipe, len, *vmobject);
|
||||
}
|
||||
|
||||
Transfer::Transfer(Pipe& pipe, u16 len, ContiguousVMObject& vmobject)
|
||||
Transfer::Transfer(Pipe& pipe, u16 len, AnonymousVMObject& vmobject)
|
||||
: m_pipe(pipe)
|
||||
, m_transfer_data_size(len)
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <AK/RefPtr.h>
|
||||
#include <Kernel/Bus/USB/PacketTypes.h>
|
||||
#include <Kernel/Bus/USB/USBPipe.h>
|
||||
#include <Kernel/VM/ContiguousVMObject.h>
|
||||
#include <Kernel/VM/AnonymousVMObject.h>
|
||||
#include <Kernel/VM/PhysicalPage.h>
|
||||
#include <Kernel/VM/Region.h>
|
||||
|
||||
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
public:
|
||||
Transfer() = delete;
|
||||
Transfer(Pipe& pipe, u16 len, ContiguousVMObject&);
|
||||
Transfer(Pipe& pipe, u16 len, AnonymousVMObject&);
|
||||
~Transfer();
|
||||
|
||||
void set_setup_packet(const USBRequestData& request);
|
||||
|
|
|
@ -255,7 +255,6 @@ set(KERNEL_SOURCES
|
|||
VirtIO/VirtIOQueue.cpp
|
||||
VirtIO/VirtIORNG.cpp
|
||||
VM/AnonymousVMObject.cpp
|
||||
VM/ContiguousVMObject.cpp
|
||||
VM/InodeVMObject.cpp
|
||||
VM/MemoryManager.cpp
|
||||
VM/PageDirectory.cpp
|
||||
|
|
|
@ -70,6 +70,14 @@ RefPtr<AnonymousVMObject> AnonymousVMObject::try_create_with_size(size_t size, A
|
|||
return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(size, commit));
|
||||
}
|
||||
|
||||
RefPtr<AnonymousVMObject> AnonymousVMObject::try_create_physically_contiguous_with_size(size_t size)
|
||||
{
|
||||
auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size);
|
||||
if (contiguous_physical_pages.is_empty())
|
||||
return {};
|
||||
return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(contiguous_physical_pages.span()));
|
||||
}
|
||||
|
||||
RefPtr<AnonymousVMObject> AnonymousVMObject::try_create_purgeable_with_size(size_t size, AllocationStrategy commit)
|
||||
{
|
||||
if (commit == AllocationStrategy::Reserve || commit == AllocationStrategy::AllocateNow) {
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
static RefPtr<AnonymousVMObject> try_create_for_physical_range(PhysicalAddress paddr, size_t size);
|
||||
static RefPtr<AnonymousVMObject> try_create_with_physical_pages(Span<NonnullRefPtr<PhysicalPage>>);
|
||||
static RefPtr<AnonymousVMObject> try_create_purgeable_with_size(size_t, AllocationStrategy);
|
||||
static RefPtr<AnonymousVMObject> try_create_physically_contiguous_with_size(size_t);
|
||||
virtual RefPtr<VMObject> try_clone() override;
|
||||
|
||||
[[nodiscard]] NonnullRefPtr<PhysicalPage> allocate_committed_page(Badge<Region>);
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/VM/ContiguousVMObject.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <Kernel/VM/PhysicalPage.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
RefPtr<ContiguousVMObject> ContiguousVMObject::try_create_with_size(size_t size)
|
||||
{
|
||||
auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size);
|
||||
if (contiguous_physical_pages.is_empty())
|
||||
return {};
|
||||
return adopt_ref_if_nonnull(new (nothrow) ContiguousVMObject(size, contiguous_physical_pages));
|
||||
}
|
||||
|
||||
ContiguousVMObject::ContiguousVMObject(size_t size, NonnullRefPtrVector<PhysicalPage>& contiguous_physical_pages)
|
||||
: VMObject(size)
|
||||
{
|
||||
for (size_t i = 0; i < page_count(); i++) {
|
||||
physical_pages()[i] = contiguous_physical_pages[i];
|
||||
dbgln_if(CONTIGUOUS_VMOBJECT_DEBUG, "Contiguous page[{}]: {}", i, physical_pages()[i]->paddr());
|
||||
}
|
||||
}
|
||||
|
||||
ContiguousVMObject::ContiguousVMObject(ContiguousVMObject const& other)
|
||||
: VMObject(other)
|
||||
{
|
||||
}
|
||||
|
||||
ContiguousVMObject::~ContiguousVMObject()
|
||||
{
|
||||
}
|
||||
|
||||
RefPtr<VMObject> ContiguousVMObject::try_clone()
|
||||
{
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Kernel/PhysicalAddress.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <Kernel/VM/VMObject.h>
|
||||
|
||||
namespace Kernel {
|
||||
class ContiguousVMObject final : public VMObject {
|
||||
public:
|
||||
virtual ~ContiguousVMObject() override;
|
||||
|
||||
static RefPtr<ContiguousVMObject> try_create_with_size(size_t);
|
||||
|
||||
private:
|
||||
explicit ContiguousVMObject(size_t, NonnullRefPtrVector<PhysicalPage>&);
|
||||
explicit ContiguousVMObject(ContiguousVMObject const&);
|
||||
|
||||
virtual StringView class_name() const override { return "ContiguousVMObject"sv; }
|
||||
virtual RefPtr<VMObject> try_clone() override;
|
||||
|
||||
ContiguousVMObject& operator=(ContiguousVMObject const&) = delete;
|
||||
ContiguousVMObject& operator=(ContiguousVMObject&&) = delete;
|
||||
ContiguousVMObject(ContiguousVMObject&&) = delete;
|
||||
|
||||
virtual bool is_contiguous() const override { return true; }
|
||||
};
|
||||
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
#include <Kernel/Sections.h>
|
||||
#include <Kernel/StdLib.h>
|
||||
#include <Kernel/VM/AnonymousVMObject.h>
|
||||
#include <Kernel/VM/ContiguousVMObject.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <Kernel/VM/PageDirectory.h>
|
||||
#include <Kernel/VM/PhysicalRegion.h>
|
||||
|
@ -705,7 +704,7 @@ OwnPtr<Region> MemoryManager::allocate_contiguous_kernel_region(size_t size, Str
|
|||
auto range = kernel_page_directory().range_allocator().allocate_anywhere(size);
|
||||
if (!range.has_value())
|
||||
return {};
|
||||
auto vmobject = ContiguousVMObject::try_create_with_size(size);
|
||||
auto vmobject = AnonymousVMObject::try_create_physically_contiguous_with_size(size);
|
||||
if (!vmobject) {
|
||||
kernel_page_directory().range_allocator().deallocate(range.value());
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue