ScatterGatherList.cpp 1019 B

1234567891011121314151617181920212223242526
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <Kernel/Memory/ScatterGatherList.h>
  7. namespace Kernel::Memory {
  8. ErrorOr<LockRefPtr<ScatterGatherList>> ScatterGatherList::try_create(AsyncBlockDeviceRequest& request, Span<NonnullRefPtr<PhysicalPage>> allocated_pages, size_t device_block_size, StringView region_name)
  9. {
  10. auto vm_object = TRY(AnonymousVMObject::try_create_with_physical_pages(allocated_pages));
  11. auto size = TRY(page_round_up((request.block_count() * device_block_size)));
  12. auto region = TRY(MM.allocate_kernel_region_with_vmobject(vm_object, size, region_name, Region::Access::Read | Region::Access::Write, Region::Cacheable::Yes));
  13. return adopt_lock_ref_if_nonnull(new (nothrow) ScatterGatherList(vm_object, move(region)));
  14. }
  15. ScatterGatherList::ScatterGatherList(NonnullLockRefPtr<AnonymousVMObject> vm_object, NonnullOwnPtr<Region> dma_region)
  16. : m_vm_object(move(vm_object))
  17. , m_dma_region(move(dma_region))
  18. {
  19. }
  20. }