1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:37:45 +00:00

Kernel/USB: Move buffer allocation from USB transfer to USB pipe

Currently when allocating buffers for USB transfers, it is done
once for every transfer rather than once upon creation of the
USB device. This commit changes that by moving allocation of buffers
to the USB Pipe class where they can be reused.
This commit is contained in:
b14ckcat 2022-06-26 18:33:53 -04:00 committed by Linus Groh
parent 5f726ace53
commit 143339767b
4 changed files with 37 additions and 27 deletions

View file

@ -9,17 +9,14 @@
namespace Kernel::USB {
ErrorOr<NonnullRefPtr<Transfer>> Transfer::try_create(Pipe& pipe, u16 length)
ErrorOr<NonnullRefPtr<Transfer>> Transfer::try_create(Pipe& pipe, u16 length, Memory::Region& dma_buffer)
{
// Initialize data buffer for transfer
// This will definitely need to be refactored in the future, I doubt this will scale well...
auto region = TRY(MM.allocate_kernel_region(PAGE_SIZE, "USB Transfer Buffer", Memory::Region::Access::ReadWrite));
return adopt_nonnull_ref_or_enomem(new (nothrow) Transfer(pipe, length, move(region)));
return adopt_nonnull_ref_or_enomem(new (nothrow) Transfer(pipe, length, dma_buffer));
}
Transfer::Transfer(Pipe& pipe, u16 len, NonnullOwnPtr<Memory::Region> data_buffer)
Transfer::Transfer(Pipe& pipe, u16 len, Memory::Region& dma_buffer)
: m_pipe(pipe)
, m_data_buffer(move(data_buffer))
, m_dma_buffer(dma_buffer)
, m_transfer_data_size(len)
{
}
@ -45,7 +42,7 @@ void Transfer::set_setup_packet(USBRequestData const& request)
ErrorOr<void> Transfer::write_buffer(u16 len, void* data)
{
VERIFY(len <= m_data_buffer->size());
VERIFY(len <= m_dma_buffer.size());
m_transfer_data_size = len;
memcpy(buffer().as_ptr(), data, len);