1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:17:35 +00:00

Kernel/USB: Create controller base class and introduce USBManagement

This removes Pipes dependency on the UHCIController by introducing a
controller base class. This will be used to implement other controllers
such as OHCI.

Additionally, there can be multiple instances of a UHCI controller.
For example, multiple UHCI instances can be required for systems with
EHCI controllers. EHCI relies on using multiple of either UHCI or OHCI
controllers to drive USB 1.x devices.

This means UHCIController can no longer be a singleton. Multiple
instances of it can now be created and passed to the device and then to
the pipe.

To handle finding and creating these instances, USBManagement has been
introduced. It has the same pattern as the other management classes
such as NetworkManagement.
This commit is contained in:
Luke 2021-08-08 19:50:20 +01:00 committed by Andreas Kling
parent c5974d3518
commit 7a86a8df90
14 changed files with 261 additions and 74 deletions

View file

@ -13,6 +13,8 @@
namespace Kernel::USB {
class USBController;
//
// A pipe is the logical connection between a memory buffer on the PC (host) and
// an endpoint on the device. In this implementation, the data buffer the pipe connects
@ -39,7 +41,7 @@ public:
};
public:
static KResultOr<NonnullOwnPtr<Pipe>> try_create_pipe(Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval = 0);
static KResultOr<NonnullOwnPtr<Pipe>> try_create_pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval = 0);
Type type() const { return m_type; }
Direction direction() const { return m_direction; }
@ -57,13 +59,15 @@ public:
KResultOr<size_t> control_transfer(u8 request_type, u8 request, u16 value, u16 index, u16 length, void* data);
Pipe(Type type, Direction direction, u16 max_packet_size);
Pipe(Type type, Direction direction, USBEndpointDescriptor& endpoint);
Pipe(Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, u8 poll_interval, i8 device_address);
Pipe(USBController const& controller, Type type, Direction direction, u16 max_packet_size);
Pipe(USBController const& controller, Type type, Direction direction, USBEndpointDescriptor& endpoint);
Pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, u8 poll_interval, i8 device_address);
private:
friend class Device;
NonnullRefPtr<USBController> m_controller;
Type m_type;
Direction m_direction;
DeviceSpeed m_speed;