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