diff --git a/Kernel/Bus/USB/UHCIController.cpp b/Kernel/Bus/USB/UHCIController.cpp index 86dac5e9c6e..a0564103cdf 100644 --- a/Kernel/Bus/USB/UHCIController.cpp +++ b/Kernel/Bus/USB/UHCIController.cpp @@ -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); diff --git a/Kernel/Bus/USB/UHCIController.h b/Kernel/Bus/USB/UHCIController.h index a25da433572..82056ded9cb 100644 --- a/Kernel/Bus/USB/UHCIController.h +++ b/Kernel/Bus/USB/UHCIController.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include namespace Kernel::USB { diff --git a/Kernel/Bus/USB/USBTransfer.cpp b/Kernel/Bus/USB/USBTransfer.cpp index 34f4b64333c..f0504010f5b 100644 --- a/Kernel/Bus/USB/USBTransfer.cpp +++ b/Kernel/Bus/USB/USBTransfer.cpp @@ -11,14 +11,14 @@ namespace Kernel::USB { RefPtr 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(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) { diff --git a/Kernel/Bus/USB/USBTransfer.h b/Kernel/Bus/USB/USBTransfer.h index b54d3a73b3a..5eca252aa8a 100644 --- a/Kernel/Bus/USB/USBTransfer.h +++ b/Kernel/Bus/USB/USBTransfer.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -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); diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 2efc36336ad..9f4a4e96a8d 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -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 diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp index 023ffbe23cc..1f7356d6eba 100644 --- a/Kernel/VM/AnonymousVMObject.cpp +++ b/Kernel/VM/AnonymousVMObject.cpp @@ -70,6 +70,14 @@ RefPtr AnonymousVMObject::try_create_with_size(size_t size, A return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(size, commit)); } +RefPtr 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::try_create_purgeable_with_size(size_t size, AllocationStrategy commit) { if (commit == AllocationStrategy::Reserve || commit == AllocationStrategy::AllocateNow) { diff --git a/Kernel/VM/AnonymousVMObject.h b/Kernel/VM/AnonymousVMObject.h index f238c52e2d0..6388918218b 100644 --- a/Kernel/VM/AnonymousVMObject.h +++ b/Kernel/VM/AnonymousVMObject.h @@ -38,6 +38,7 @@ public: static RefPtr try_create_for_physical_range(PhysicalAddress paddr, size_t size); static RefPtr try_create_with_physical_pages(Span>); static RefPtr try_create_purgeable_with_size(size_t, AllocationStrategy); + static RefPtr try_create_physically_contiguous_with_size(size_t); virtual RefPtr try_clone() override; [[nodiscard]] NonnullRefPtr allocate_committed_page(Badge); diff --git a/Kernel/VM/ContiguousVMObject.cpp b/Kernel/VM/ContiguousVMObject.cpp deleted file mode 100644 index a946a3658e8..00000000000 --- a/Kernel/VM/ContiguousVMObject.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2020, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include - -namespace Kernel { - -RefPtr 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& 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 ContiguousVMObject::try_clone() -{ - VERIFY_NOT_REACHED(); -} - -} diff --git a/Kernel/VM/ContiguousVMObject.h b/Kernel/VM/ContiguousVMObject.h deleted file mode 100644 index 76700f1c4bb..00000000000 --- a/Kernel/VM/ContiguousVMObject.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include - -namespace Kernel { -class ContiguousVMObject final : public VMObject { -public: - virtual ~ContiguousVMObject() override; - - static RefPtr try_create_with_size(size_t); - -private: - explicit ContiguousVMObject(size_t, NonnullRefPtrVector&); - explicit ContiguousVMObject(ContiguousVMObject const&); - - virtual StringView class_name() const override { return "ContiguousVMObject"sv; } - virtual RefPtr try_clone() override; - - ContiguousVMObject& operator=(ContiguousVMObject const&) = delete; - ContiguousVMObject& operator=(ContiguousVMObject&&) = delete; - ContiguousVMObject(ContiguousVMObject&&) = delete; - - virtual bool is_contiguous() const override { return true; } -}; - -} diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 182e5dc9237..37690cd3a41 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -705,7 +704,7 @@ OwnPtr 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 {};