1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

Kernel: Move AHCIPort::ScatterList to VM::ScatterGatherList

We want to move this out of the AHCI subsystem into the VM system,
since other parts of the kernel may need to perform scatter-gather IO.

We rename the current VM::ScatterGatherList impl that's used in the
virtio subsystem to VM::ScatterGatherRefList, since its distinguishing
feature from the AHCI scatter-gather list is that it doesn't own its
buffers.
This commit is contained in:
Sahan Fernando 2021-04-24 11:30:27 +10:00 committed by Andreas Kling
parent b63b15eeb5
commit 8131c0de8c
11 changed files with 53 additions and 46 deletions

View file

@ -11,22 +11,12 @@
#include <Kernel/Storage/SATADiskDevice.h>
#include <Kernel/VM/AnonymousVMObject.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/ScatterGatherList.h>
#include <Kernel/VM/TypedMapping.h>
#include <Kernel/WorkQueue.h>
namespace Kernel {
NonnullRefPtr<AHCIPort::ScatterList> AHCIPort::ScatterList::create(AsyncBlockDeviceRequest& request, NonnullRefPtrVector<PhysicalPage> allocated_pages, size_t device_block_size)
{
return adopt_ref(*new ScatterList(request, allocated_pages, device_block_size));
}
AHCIPort::ScatterList::ScatterList(AsyncBlockDeviceRequest& request, NonnullRefPtrVector<PhysicalPage> allocated_pages, size_t device_block_size)
: m_vm_object(AnonymousVMObject::create_with_physical_pages(allocated_pages))
{
m_dma_region = MM.allocate_kernel_region_with_vmobject(m_vm_object, page_round_up((request.block_count() * device_block_size)), "AHCI Scattered DMA", Region::Access::Read | Region::Access::Write, Region::Cacheable::Yes);
}
NonnullRefPtr<AHCIPort> AHCIPort::create(const AHCIPortHandler& handler, volatile AHCI::PortRegisters& registers, u32 port_index)
{
return adopt_ref(*new AHCIPort(handler, registers, port_index));
@ -443,7 +433,7 @@ Optional<AsyncDeviceRequest::RequestResult> AHCIPort::prepare_and_set_scatter_li
allocated_dma_regions.append(m_dma_buffers.at(index));
}
m_current_scatter_list = ScatterList::create(request, allocated_dma_regions, m_connected_device->block_size());
m_current_scatter_list = ScatterGatherList::create(request, allocated_dma_regions, m_connected_device->block_size());
if (request.request_type() == AsyncBlockDeviceRequest::Write) {
if (!request.read_from_buffer(request.buffer(), m_current_scatter_list->dma_region().as_ptr(), m_connected_device->block_size() * request.block_count())) {
return AsyncDeviceRequest::MemoryFault;

View file

@ -20,6 +20,7 @@
#include <Kernel/Storage/StorageDevice.h>
#include <Kernel/VM/AnonymousVMObject.h>
#include <Kernel/VM/PhysicalPage.h>
#include <Kernel/VM/ScatterGatherList.h>
#include <Kernel/WaitQueue.h>
namespace Kernel {
@ -32,20 +33,6 @@ class AHCIPort : public RefCounted<AHCIPort> {
friend class AHCIPortHandler;
friend class SATADiskDevice;
private:
class ScatterList : public RefCounted<ScatterList> {
public:
static NonnullRefPtr<ScatterList> create(AsyncBlockDeviceRequest&, NonnullRefPtrVector<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(); }
private:
ScatterList(AsyncBlockDeviceRequest&, NonnullRefPtrVector<PhysicalPage> allocated_pages, size_t device_block_size);
NonnullRefPtr<AnonymousVMObject> m_vm_object;
OwnPtr<Region> m_dma_region;
};
public:
UNMAP_AFTER_INIT static NonnullRefPtr<AHCIPort> create(const AHCIPortHandler&, volatile AHCI::PortRegisters&, u32 port_index);
@ -132,7 +119,7 @@ private:
AHCI::PortInterruptStatusBitField m_interrupt_status;
AHCI::PortInterruptEnableBitField m_interrupt_enable;
RefPtr<AHCIPort::ScatterList> m_current_scatter_list;
RefPtr<ScatterGatherList> m_current_scatter_list;
bool m_disabled_by_firmware { false };
};
}