1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 17:15:09 +00:00

Kernel/USB: Refactor USB Pipe

Decompose the current monolithic USBD Pipe interface into several
subclasses, one for each pair of endpoint type & direction. This is to
make it more clear what data and functionality belongs to which Pipe
type, and prevent nonsensical things like trying to execute a control
transfer on a non-control pipe. This is important, because the Pipe
class is the interface by which USB device drivers will interact with
the HCD, so the clearer and more explicit this interface is the better.
This commit is contained in:
b14ckcat 2022-10-15 20:34:49 -04:00 committed by Andreas Kling
parent 1304575190
commit bf3c99ef23
6 changed files with 179 additions and 69 deletions

View file

@ -18,25 +18,25 @@ namespace Kernel::USB {
ErrorOr<NonnullLockRefPtr<Hub>> Hub::try_create_root_hub(NonnullLockRefPtr<USBController> controller, DeviceSpeed device_speed)
{
// NOTE: Enumeration does not happen here, as the controller must know what the device address is at all times during enumeration to intercept requests.
auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0));
auto pipe = TRY(ControlPipe::create(controller, 0, 8, 0));
auto hub = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) Hub(controller, device_speed, move(pipe))));
return hub;
}
ErrorOr<NonnullLockRefPtr<Hub>> Hub::try_create_from_device(Device const& device)
{
auto pipe = TRY(Pipe::try_create_pipe(device.controller(), Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, device.device_descriptor().max_packet_size, device.address()));
auto pipe = TRY(ControlPipe::create(device.controller(), 0, device.device_descriptor().max_packet_size, device.address()));
auto hub = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) Hub(device, move(pipe))));
TRY(hub->enumerate_and_power_on_hub());
return hub;
}
Hub::Hub(NonnullLockRefPtr<USBController> controller, DeviceSpeed device_speed, NonnullOwnPtr<Pipe> default_pipe)
Hub::Hub(NonnullLockRefPtr<USBController> controller, DeviceSpeed device_speed, NonnullOwnPtr<ControlPipe> default_pipe)
: Device(move(controller), 1 /* Port 1 */, device_speed, move(default_pipe))
{
}
Hub::Hub(Device const& device, NonnullOwnPtr<Pipe> default_pipe)
Hub::Hub(Device const& device, NonnullOwnPtr<ControlPipe> default_pipe)
: Device(device, move(default_pipe))
{
}