Kernel: Add AnonymousVMObject constructor for a Vector of physical pages

This will be used later on by the AHCI code to create a Region
that spans over scattered DMA pages.
This commit is contained in:
Liav A 2021-02-26 14:32:43 +02:00 committed by Andreas Kling
parent e65fd83e23
commit ecb169b61e
4 changed files with 22 additions and 0 deletions

View file

@ -81,6 +81,11 @@ RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size, Alloc
return adopt(*new AnonymousVMObject(size, commit));
}
NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_pages(NonnullRefPtrVector<PhysicalPage> physical_pages)
{
return adopt(*new AnonymousVMObject(physical_pages));
}
NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_page(PhysicalPage& page)
{
return adopt(*new AnonymousVMObject(page));
@ -127,6 +132,15 @@ AnonymousVMObject::AnonymousVMObject(PhysicalPage& page)
physical_pages()[0] = page;
}
AnonymousVMObject::AnonymousVMObject(NonnullRefPtrVector<PhysicalPage> physical_pages)
: VMObject()
, m_volatile_ranges_cache({ 0, page_count() })
{
for (auto& page : physical_pages) {
m_physical_pages.append(page);
}
}
AnonymousVMObject::AnonymousVMObject(const AnonymousVMObject& other)
: VMObject(other)
, m_volatile_ranges_cache({ 0, page_count() }) // do *not* clone this

View file

@ -43,6 +43,7 @@ public:
static RefPtr<AnonymousVMObject> create_with_size(size_t, AllocationStrategy);
static RefPtr<AnonymousVMObject> create_for_physical_range(PhysicalAddress paddr, size_t size);
static NonnullRefPtr<AnonymousVMObject> create_with_physical_page(PhysicalPage& page);
static NonnullRefPtr<AnonymousVMObject> create_with_physical_pages(NonnullRefPtrVector<PhysicalPage>);
virtual RefPtr<VMObject> clone() override;
RefPtr<PhysicalPage> allocate_committed_page(size_t);
@ -119,6 +120,7 @@ private:
explicit AnonymousVMObject(size_t, AllocationStrategy);
explicit AnonymousVMObject(PhysicalAddress, size_t);
explicit AnonymousVMObject(PhysicalPage&);
explicit AnonymousVMObject(NonnullRefPtrVector<PhysicalPage>);
explicit AnonymousVMObject(const AnonymousVMObject&);
virtual const char* class_name() const override { return "AnonymousVMObject"; }

View file

@ -35,6 +35,11 @@ VMObject::VMObject(const VMObject& other)
MM.register_vmobject(*this);
}
VMObject::VMObject()
{
MM.register_vmobject(*this);
}
VMObject::VMObject(size_t size)
{
m_physical_pages.resize(ceil_div(size, static_cast<size_t>(PAGE_SIZE)));

View file

@ -88,6 +88,7 @@ public:
}
protected:
VMObject();
explicit VMObject(size_t);
explicit VMObject(const VMObject&);