mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:47:34 +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:
parent
5f726ace53
commit
143339767b
4 changed files with 37 additions and 27 deletions
|
@ -14,10 +14,11 @@ namespace Kernel::USB {
|
|||
|
||||
ErrorOr<NonnullOwnPtr<Pipe>> Pipe::try_create_pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval)
|
||||
{
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) Pipe(controller, type, direction, endpoint_address, max_packet_size, poll_interval, device_address));
|
||||
auto dma_region = TRY(MM.allocate_kernel_region(PAGE_SIZE, "USB device DMA buffer", Memory::Region::Access::ReadWrite));
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) Pipe(controller, type, direction, endpoint_address, max_packet_size, poll_interval, device_address, move(dma_region)));
|
||||
}
|
||||
|
||||
Pipe::Pipe(USBController const& controller, Type type, Pipe::Direction direction, u16 max_packet_size)
|
||||
Pipe::Pipe(USBController const& controller, Type type, Pipe::Direction direction, u16 max_packet_size, NonnullOwnPtr<Memory::Region> dma_buffer)
|
||||
: m_controller(controller)
|
||||
, m_type(type)
|
||||
, m_direction(direction)
|
||||
|
@ -25,18 +26,20 @@ Pipe::Pipe(USBController const& controller, Type type, Pipe::Direction direction
|
|||
, m_max_packet_size(max_packet_size)
|
||||
, m_poll_interval(0)
|
||||
, m_data_toggle(false)
|
||||
, m_dma_buffer(move(dma_buffer))
|
||||
{
|
||||
}
|
||||
|
||||
Pipe::Pipe(USBController const& controller, Type type, Direction direction, USBEndpointDescriptor& endpoint [[maybe_unused]])
|
||||
Pipe::Pipe(USBController const& controller, Type type, Direction direction, USBEndpointDescriptor& endpoint [[maybe_unused]], NonnullOwnPtr<Memory::Region> dma_buffer)
|
||||
: m_controller(controller)
|
||||
, m_type(type)
|
||||
, m_direction(direction)
|
||||
, m_dma_buffer(move(dma_buffer))
|
||||
{
|
||||
// TODO: decode endpoint structure
|
||||
}
|
||||
|
||||
Pipe::Pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, u8 poll_interval, i8 device_address)
|
||||
Pipe::Pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, u8 poll_interval, i8 device_address, NonnullOwnPtr<Memory::Region> dma_buffer)
|
||||
: m_controller(controller)
|
||||
, m_type(type)
|
||||
, m_direction(direction)
|
||||
|
@ -45,11 +48,14 @@ Pipe::Pipe(USBController const& controller, Type type, Direction direction, u8 e
|
|||
, m_max_packet_size(max_packet_size)
|
||||
, m_poll_interval(poll_interval)
|
||||
, m_data_toggle(false)
|
||||
, m_dma_buffer(move(dma_buffer))
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<size_t> Pipe::control_transfer(u8 request_type, u8 request, u16 value, u16 index, u16 length, void* data)
|
||||
{
|
||||
MutexLocker lock(m_dma_buffer_lock);
|
||||
|
||||
USBRequestData usb_request;
|
||||
|
||||
usb_request.request_type = request_type;
|
||||
|
@ -58,7 +64,7 @@ ErrorOr<size_t> Pipe::control_transfer(u8 request_type, u8 request, u16 value, u
|
|||
usb_request.index = index;
|
||||
usb_request.length = length;
|
||||
|
||||
auto transfer = TRY(Transfer::try_create(*this, length));
|
||||
auto transfer = TRY(Transfer::try_create(*this, length, *m_dma_buffer));
|
||||
transfer->set_setup_packet(usb_request);
|
||||
|
||||
dbgln_if(USB_DEBUG, "Pipe: Transfer allocated @ {}", transfer->buffer_physical());
|
||||
|
@ -74,8 +80,10 @@ ErrorOr<size_t> Pipe::control_transfer(u8 request_type, u8 request, u16 value, u
|
|||
|
||||
ErrorOr<size_t> Pipe::bulk_transfer(u16 length, void* data)
|
||||
{
|
||||
MutexLocker lock(m_dma_buffer_lock);
|
||||
|
||||
size_t transfer_length = 0;
|
||||
auto transfer = TRY(Transfer::try_create(*this, length));
|
||||
auto transfer = TRY(Transfer::try_create(*this, length, *m_dma_buffer));
|
||||
|
||||
if (m_direction == Direction::In) {
|
||||
dbgln_if(USB_DEBUG, "Pipe: Bulk in transfer allocated @ {}", transfer->buffer_physical());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue