1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:07: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:
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

@ -19,7 +19,7 @@ namespace Kernel::USB {
class Transfer : public RefCounted<Transfer> {
public:
static ErrorOr<NonnullRefPtr<Transfer>> try_create(Pipe&, u16 length);
static ErrorOr<NonnullRefPtr<Transfer>> try_create(Pipe&, u16 length, Memory::Region& dma_buffer);
Transfer() = delete;
~Transfer();
@ -34,20 +34,20 @@ public:
USBRequestData const& request() const { return m_request; }
Pipe const& pipe() const { return m_pipe; }
Pipe& pipe() { return m_pipe; }
VirtualAddress buffer() const { return m_data_buffer->vaddr(); }
PhysicalAddress buffer_physical() const { return m_data_buffer->physical_page(0)->paddr(); }
VirtualAddress buffer() const { return m_dma_buffer.vaddr(); }
PhysicalAddress buffer_physical() const { return m_dma_buffer.physical_page(0)->paddr(); }
u16 transfer_data_size() const { return m_transfer_data_size; }
bool complete() const { return m_complete; }
bool error_occurred() const { return m_error_occurred; }
private:
Transfer(Pipe& pipe, u16 len, NonnullOwnPtr<Memory::Region>);
Pipe& m_pipe; // Pipe that initiated this transfer
USBRequestData m_request; // USB request
NonnullOwnPtr<Memory::Region> m_data_buffer; // DMA Data buffer for transaction
u16 m_transfer_data_size { 0 }; // Size of the transfer's data stage
bool m_complete { false }; // Has this transfer been completed?
bool m_error_occurred { false }; // Did an error occur during this transfer?
Transfer(Pipe& pipe, u16 len, Memory::Region& dma_buffer);
Pipe& m_pipe; // Pipe that initiated this transfer
Memory::Region& m_dma_buffer; // DMA buffer
USBRequestData m_request; // USB request
u16 m_transfer_data_size { 0 }; // Size of the transfer's data stage
bool m_complete { false }; // Has this transfer been completed?
bool m_error_occurred { false }; // Did an error occur during this transfer?
};
}