2021-01-20 16:34:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-20 16:34:16 +00:00
|
|
|
*/
|
|
|
|
|
2021-08-06 08:45:34 +00:00
|
|
|
#include <Kernel/Memory/ScatterGatherList.h>
|
2021-01-20 16:34:16 +00:00
|
|
|
|
2021-08-06 11:49:36 +00:00
|
|
|
namespace Kernel::Memory {
|
2021-01-20 16:34:16 +00:00
|
|
|
|
2024-05-11 15:15:51 +00:00
|
|
|
ErrorOr<LockRefPtr<ScatterGatherList>> ScatterGatherList::try_create(AsyncBlockDeviceRequest& request, Span<NonnullRefPtr<PhysicalRAMPage>> allocated_pages, size_t device_block_size, StringView region_name)
|
2021-04-24 01:30:27 +00:00
|
|
|
{
|
2023-05-17 17:23:03 +00:00
|
|
|
auto vm_object = TRY(AnonymousVMObject::try_create_with_physical_pages(allocated_pages));
|
2023-05-17 18:06:34 +00:00
|
|
|
auto size = TRY(page_round_up((request.block_count() * device_block_size)));
|
2023-05-17 18:21:00 +00:00
|
|
|
auto region = TRY(MM.allocate_kernel_region_with_vmobject(vm_object, size, region_name, Region::Access::Read | Region::Access::Write, Region::Cacheable::Yes));
|
2023-05-17 18:06:34 +00:00
|
|
|
|
|
|
|
return adopt_lock_ref_if_nonnull(new (nothrow) ScatterGatherList(vm_object, move(region)));
|
2021-04-24 01:30:27 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 18:06:34 +00:00
|
|
|
ScatterGatherList::ScatterGatherList(NonnullLockRefPtr<AnonymousVMObject> vm_object, NonnullOwnPtr<Region> dma_region)
|
2021-05-14 12:06:29 +00:00
|
|
|
: m_vm_object(move(vm_object))
|
2023-05-17 18:06:34 +00:00
|
|
|
, m_dma_region(move(dma_region))
|
2021-04-24 01:30:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-01-20 16:34:16 +00:00
|
|
|
}
|