summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-22 09:03:13 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-22 09:17:02 +0200
commit5217875f6ae204e6b23862ab28549364599a9729 (patch)
treeb17ba0a078a43f2514e187c95de16e5a3a83ac0f
parent9e15708aa08454d6418c256a82ac21597eee20fe (diff)
downloadserenity-5217875f6ae204e6b23862ab28549364599a9729.zip
Kernel: Consolidate API for creating AnonymousVMObject with given pages
We don't need to have a dedicated API for creating a VMObject with a single page, the multi-page API option works in all cases. Also make the API take a Span<NonnullRefPtr<PhysicalPage>> instead of a NonnullRefPtrVector<PhysicalPage>.
-rw-r--r--Kernel/Devices/SB16.cpp3
-rw-r--r--Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp2
-rw-r--r--Kernel/Storage/AHCIPort.cpp2
-rw-r--r--Kernel/VM/AnonymousVMObject.cpp16
-rw-r--r--Kernel/VM/AnonymousVMObject.h6
-rw-r--r--Kernel/VM/ScatterGatherList.cpp2
-rw-r--r--Kernel/VM/ScatterGatherList.h2
7 files changed, 10 insertions, 23 deletions
diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp
index 3e4a9cc705..db0c2ae644 100644
--- a/Kernel/Devices/SB16.cpp
+++ b/Kernel/Devices/SB16.cpp
@@ -237,7 +237,8 @@ KResultOr<size_t> SB16::write(FileDescription&, u64, const UserOrKernelBuffer& d
auto page = MM.allocate_supervisor_physical_page();
if (!page)
return ENOMEM;
- auto vmobject = AnonymousVMObject::try_create_with_physical_page(*page);
+ auto nonnull_page = page.release_nonnull();
+ auto vmobject = AnonymousVMObject::try_create_with_physical_pages({ &nonnull_page, 1 });
if (!vmobject)
return ENOMEM;
m_dma_region = MM.allocate_kernel_region_with_vmobject(*vmobject, PAGE_SIZE, "SB16 DMA buffer", Region::Access::Write);
diff --git a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp
index 4ea92dcb99..49b9bee8f7 100644
--- a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp
+++ b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp
@@ -40,7 +40,7 @@ void FrameBufferDevice::create_framebuffer()
for (auto i = 0u; i < num_needed_pages; ++i) {
pages.append(write_sink_page);
}
- m_framebuffer_sink_vmobject = AnonymousVMObject::try_create_with_physical_pages(move(pages));
+ m_framebuffer_sink_vmobject = AnonymousVMObject::try_create_with_physical_pages(pages.span());
MutexLocker locker(m_gpu.operation_lock());
m_current_buffer = &buffer_from_index(m_last_set_buffer_index.load());
diff --git a/Kernel/Storage/AHCIPort.cpp b/Kernel/Storage/AHCIPort.cpp
index b85dd8112f..e9231fcc93 100644
--- a/Kernel/Storage/AHCIPort.cpp
+++ b/Kernel/Storage/AHCIPort.cpp
@@ -437,7 +437,7 @@ Optional<AsyncDeviceRequest::RequestResult> AHCIPort::prepare_and_set_scatter_li
allocated_dma_regions.append(m_dma_buffers.at(index));
}
- m_current_scatter_list = ScatterGatherList::create(request, move(allocated_dma_regions), m_connected_device->block_size());
+ m_current_scatter_list = ScatterGatherList::try_create(request, allocated_dma_regions.span(), m_connected_device->block_size());
if (!m_current_scatter_list)
return AsyncDeviceRequest::Failure;
if (request.request_type() == AsyncBlockDeviceRequest::Write) {
diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp
index e91ae6ffa9..d41a1ae146 100644
--- a/Kernel/VM/AnonymousVMObject.cpp
+++ b/Kernel/VM/AnonymousVMObject.cpp
@@ -65,16 +65,11 @@ 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_with_physical_pages(NonnullRefPtrVector<PhysicalPage> physical_pages)
+RefPtr<AnonymousVMObject> AnonymousVMObject::try_create_with_physical_pages(Span<NonnullRefPtr<PhysicalPage>> physical_pages)
{
return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(physical_pages));
}
-RefPtr<AnonymousVMObject> AnonymousVMObject::try_create_with_physical_page(PhysicalPage& page)
-{
- return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(page));
-}
-
RefPtr<AnonymousVMObject> AnonymousVMObject::try_create_for_physical_range(PhysicalAddress paddr, size_t size)
{
if (paddr.offset(size) < paddr) {
@@ -109,14 +104,7 @@ AnonymousVMObject::AnonymousVMObject(PhysicalAddress paddr, size_t size)
physical_pages()[i] = PhysicalPage::create(paddr.offset(i * PAGE_SIZE), MayReturnToFreeList::No);
}
-AnonymousVMObject::AnonymousVMObject(PhysicalPage& page)
- : VMObject(PAGE_SIZE)
- , m_volatile_ranges_cache({ 0, page_count() })
-{
- physical_pages()[0] = page;
-}
-
-AnonymousVMObject::AnonymousVMObject(NonnullRefPtrVector<PhysicalPage> physical_pages)
+AnonymousVMObject::AnonymousVMObject(Span<NonnullRefPtr<PhysicalPage>> physical_pages)
: VMObject(physical_pages.size() * PAGE_SIZE)
, m_volatile_ranges_cache({ 0, page_count() })
{
diff --git a/Kernel/VM/AnonymousVMObject.h b/Kernel/VM/AnonymousVMObject.h
index 22bd7ccc8a..6cbe9d0117 100644
--- a/Kernel/VM/AnonymousVMObject.h
+++ b/Kernel/VM/AnonymousVMObject.h
@@ -23,8 +23,7 @@ public:
static RefPtr<AnonymousVMObject> try_create_with_size(size_t, AllocationStrategy);
static RefPtr<AnonymousVMObject> try_create_for_physical_range(PhysicalAddress paddr, size_t size);
- static RefPtr<AnonymousVMObject> try_create_with_physical_page(PhysicalPage& page);
- static RefPtr<AnonymousVMObject> try_create_with_physical_pages(NonnullRefPtrVector<PhysicalPage>);
+ static RefPtr<AnonymousVMObject> try_create_with_physical_pages(Span<NonnullRefPtr<PhysicalPage>>);
virtual RefPtr<VMObject> try_clone() override;
RefPtr<PhysicalPage> allocate_committed_page(size_t);
@@ -118,8 +117,7 @@ public:
private:
explicit AnonymousVMObject(size_t, AllocationStrategy);
explicit AnonymousVMObject(PhysicalAddress, size_t);
- explicit AnonymousVMObject(PhysicalPage&);
- explicit AnonymousVMObject(NonnullRefPtrVector<PhysicalPage>);
+ explicit AnonymousVMObject(Span<NonnullRefPtr<PhysicalPage>>);
explicit AnonymousVMObject(AnonymousVMObject const&);
virtual StringView class_name() const override { return "AnonymousVMObject"sv; }
diff --git a/Kernel/VM/ScatterGatherList.cpp b/Kernel/VM/ScatterGatherList.cpp
index aeb2aa9d65..9bca559616 100644
--- a/Kernel/VM/ScatterGatherList.cpp
+++ b/Kernel/VM/ScatterGatherList.cpp
@@ -8,7 +8,7 @@
namespace Kernel {
-RefPtr<ScatterGatherList> ScatterGatherList::create(AsyncBlockDeviceRequest& request, NonnullRefPtrVector<PhysicalPage> allocated_pages, size_t device_block_size)
+RefPtr<ScatterGatherList> ScatterGatherList::try_create(AsyncBlockDeviceRequest& request, Span<NonnullRefPtr<PhysicalPage>> allocated_pages, size_t device_block_size)
{
auto vm_object = AnonymousVMObject::try_create_with_physical_pages(allocated_pages);
if (!vm_object)
diff --git a/Kernel/VM/ScatterGatherList.h b/Kernel/VM/ScatterGatherList.h
index 4f3f5b983b..1a087095c2 100644
--- a/Kernel/VM/ScatterGatherList.h
+++ b/Kernel/VM/ScatterGatherList.h
@@ -18,7 +18,7 @@ namespace Kernel {
class ScatterGatherList : public RefCounted<ScatterGatherList> {
public:
- static RefPtr<ScatterGatherList> create(AsyncBlockDeviceRequest&, NonnullRefPtrVector<PhysicalPage> allocated_pages, size_t device_block_size);
+ static RefPtr<ScatterGatherList> try_create(AsyncBlockDeviceRequest&, Span<NonnullRefPtr<PhysicalPage>> allocated_pages, size_t device_block_size);
const VMObject& vmobject() const { return m_vm_object; }
VirtualAddress dma_region() const { return m_dma_region->vaddr(); }
size_t scatters_count() const { return m_vm_object->physical_pages().size(); }