Skip to content

Commit

Permalink
Kernel: Support re-mapping MMIOVMObject-backed regions
Browse files Browse the repository at this point in the history
This is required for example when write combine is enabled on a region
after the initial mapping.
  • Loading branch information
IdanHo authored and nico committed Jun 25, 2024
1 parent 8d2a8db commit 3aa1bd5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions Kernel/Memory/MMIOVMObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ErrorOr<NonnullLockRefPtr<MMIOVMObject>> MMIOVMObject::try_create_for_physical_r

MMIOVMObject::MMIOVMObject(PhysicalAddress paddr, FixedArray<RefPtr<PhysicalRAMPage>>&& new_physical_pages)
: VMObject(move(new_physical_pages))
, m_base_address(paddr)
{
VERIFY(paddr.page_base() == paddr);
}
Expand Down
5 changes: 5 additions & 0 deletions Kernel/Memory/MMIOVMObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ class MMIOVMObject final : public VMObject {

virtual ErrorOr<NonnullLockRefPtr<VMObject>> try_clone() override { return ENOTSUP; }

PhysicalAddress base_address() const { return m_base_address; }

private:
MMIOVMObject(PhysicalAddress, FixedArray<RefPtr<PhysicalRAMPage>>&&);

virtual StringView class_name() const override { return "MMIOVMObject"sv; }
virtual bool is_mmio() const override { return true; }

PhysicalAddress m_base_address;
};

}
7 changes: 6 additions & 1 deletion Kernel/Memory/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Kernel/Interrupts/InterruptDisabler.h>
#include <Kernel/Library/Panic.h>
#include <Kernel/Memory/AnonymousVMObject.h>
#include <Kernel/Memory/MMIOVMObject.h>
#include <Kernel/Memory/MemoryManager.h>
#include <Kernel/Memory/Region.h>
#include <Kernel/Memory/SharedInodeVMObject.h>
Expand Down Expand Up @@ -355,7 +356,11 @@ ErrorOr<void> Region::map(PageDirectory& page_directory, PhysicalAddress paddr,
void Region::remap()
{
VERIFY(m_page_directory);
auto result = map(*m_page_directory);
ErrorOr<void> result;
if (m_vmobject->is_mmio())
result = map(*m_page_directory, static_cast<MMIOVMObject const&>(*m_vmobject).base_address());
else
result = map(*m_page_directory);
if (result.is_error())
TODO();
}
Expand Down
1 change: 1 addition & 0 deletions Kernel/Memory/VMObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class VMObject
virtual bool is_inode() const { return false; }
virtual bool is_shared_inode() const { return false; }
virtual bool is_private_inode() const { return false; }
virtual bool is_mmio() const { return false; }

size_t page_count() const { return m_physical_pages.size(); }

Expand Down

0 comments on commit 3aa1bd5

Please sign in to comment.