mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:57:36 +00:00
Kernel/USB: Use proper verbs for Pipe transfer methods
This commit is contained in:
parent
7400eb3640
commit
9baa521b04
4 changed files with 18 additions and 18 deletions
|
@ -62,7 +62,7 @@ ErrorOr<void> Device::enumerate_device()
|
||||||
|
|
||||||
// Send 8-bytes to get at least the `max_packet_size` from the device
|
// Send 8-bytes to get at least the `max_packet_size` from the device
|
||||||
constexpr u8 short_device_descriptor_length = 8;
|
constexpr u8 short_device_descriptor_length = 8;
|
||||||
auto transfer_length = TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_DEVICE << 8), 0, short_device_descriptor_length, &dev_descriptor));
|
auto transfer_length = TRY(m_default_pipe->submit_control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_DEVICE << 8), 0, short_device_descriptor_length, &dev_descriptor));
|
||||||
|
|
||||||
// FIXME: This be "not equal to" instead of "less than", but control transfers report a higher transfer length than expected.
|
// FIXME: This be "not equal to" instead of "less than", but control transfers report a higher transfer length than expected.
|
||||||
if (transfer_length < short_device_descriptor_length) {
|
if (transfer_length < short_device_descriptor_length) {
|
||||||
|
@ -85,7 +85,7 @@ ErrorOr<void> Device::enumerate_device()
|
||||||
VERIFY(dev_descriptor.descriptor_header.descriptor_type == DESCRIPTOR_TYPE_DEVICE);
|
VERIFY(dev_descriptor.descriptor_header.descriptor_type == DESCRIPTOR_TYPE_DEVICE);
|
||||||
m_default_pipe->set_max_packet_size(dev_descriptor.max_packet_size);
|
m_default_pipe->set_max_packet_size(dev_descriptor.max_packet_size);
|
||||||
|
|
||||||
transfer_length = TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_DEVICE << 8), 0, sizeof(USBDeviceDescriptor), &dev_descriptor));
|
transfer_length = TRY(m_default_pipe->submit_control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_DEVICE << 8), 0, sizeof(USBDeviceDescriptor), &dev_descriptor));
|
||||||
|
|
||||||
// FIXME: This be "not equal to" instead of "less than", but control transfers report a higher transfer length than expected.
|
// FIXME: This be "not equal to" instead of "less than", but control transfers report a higher transfer length than expected.
|
||||||
if (transfer_length < sizeof(USBDeviceDescriptor)) {
|
if (transfer_length < sizeof(USBDeviceDescriptor)) {
|
||||||
|
@ -108,7 +108,7 @@ ErrorOr<void> Device::enumerate_device()
|
||||||
auto new_address = m_controller->allocate_address();
|
auto new_address = m_controller->allocate_address();
|
||||||
|
|
||||||
// Attempt to set devices address on the bus
|
// Attempt to set devices address on the bus
|
||||||
transfer_length = TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE, USB_REQUEST_SET_ADDRESS, new_address, 0, 0, nullptr));
|
transfer_length = TRY(m_default_pipe->submit_control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE, USB_REQUEST_SET_ADDRESS, new_address, 0, 0, nullptr));
|
||||||
|
|
||||||
// This has to be set after we send out the "Set Address" request because it might be sent to the root hub.
|
// This has to be set after we send out the "Set Address" request because it might be sent to the root hub.
|
||||||
// The root hub uses the address to intercept requests to itself.
|
// The root hub uses the address to intercept requests to itself.
|
||||||
|
@ -123,7 +123,7 @@ ErrorOr<void> Device::enumerate_device()
|
||||||
m_configurations.ensure_capacity(m_device_descriptor.num_configurations);
|
m_configurations.ensure_capacity(m_device_descriptor.num_configurations);
|
||||||
for (auto configuration = 0u; configuration < m_device_descriptor.num_configurations; configuration++) {
|
for (auto configuration = 0u; configuration < m_device_descriptor.num_configurations; configuration++) {
|
||||||
USBConfigurationDescriptor configuration_descriptor;
|
USBConfigurationDescriptor configuration_descriptor;
|
||||||
transfer_length = TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_CONFIGURATION << 8u) | configuration, 0, sizeof(USBConfigurationDescriptor), &configuration_descriptor));
|
transfer_length = TRY(m_default_pipe->submit_control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_CONFIGURATION << 8u) | configuration, 0, sizeof(USBConfigurationDescriptor), &configuration_descriptor));
|
||||||
|
|
||||||
if constexpr (USB_DEBUG) {
|
if constexpr (USB_DEBUG) {
|
||||||
dbgln("USB Configuration Descriptor {}", configuration);
|
dbgln("USB Configuration Descriptor {}", configuration);
|
||||||
|
@ -144,7 +144,7 @@ ErrorOr<void> Device::enumerate_device()
|
||||||
|
|
||||||
ErrorOr<size_t> Device::control_transfer(u8 request_type, u8 request, u16 value, u16 index, u16 length, void* data)
|
ErrorOr<size_t> Device::control_transfer(u8 request_type, u8 request, u16 value, u16 index, u16 length, void* data)
|
||||||
{
|
{
|
||||||
return TRY(m_default_pipe->control_transfer(request_type, request, value, index, length, data));
|
return TRY(m_default_pipe->submit_control_transfer(request_type, request, value, index, length, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ ErrorOr<void> Hub::enumerate_and_power_on_hub()
|
||||||
USBHubDescriptor descriptor {};
|
USBHubDescriptor descriptor {};
|
||||||
|
|
||||||
// Get the first hub descriptor. All hubs are required to have a hub descriptor at index 0. USB 2.0 Specification Section 11.24.2.5.
|
// Get the first hub descriptor. All hubs are required to have a hub descriptor at index 0. USB 2.0 Specification Section 11.24.2.5.
|
||||||
auto transfer_length = TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS, HubRequest::GET_DESCRIPTOR, (DESCRIPTOR_TYPE_HUB << 8), 0, sizeof(USBHubDescriptor), &descriptor));
|
auto transfer_length = TRY(m_default_pipe->submit_control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS, HubRequest::GET_DESCRIPTOR, (DESCRIPTOR_TYPE_HUB << 8), 0, sizeof(USBHubDescriptor), &descriptor));
|
||||||
|
|
||||||
// FIXME: This be "not equal to" instead of "less than", but control transfers report a higher transfer length than expected.
|
// FIXME: This be "not equal to" instead of "less than", but control transfers report a higher transfer length than expected.
|
||||||
if (transfer_length < sizeof(USBHubDescriptor)) {
|
if (transfer_length < sizeof(USBHubDescriptor)) {
|
||||||
|
@ -78,7 +78,7 @@ ErrorOr<void> Hub::enumerate_and_power_on_hub()
|
||||||
|
|
||||||
// Enable all the ports
|
// Enable all the ports
|
||||||
for (u8 port_index = 0; port_index < descriptor.number_of_downstream_ports; ++port_index) {
|
for (u8 port_index = 0; port_index < descriptor.number_of_downstream_ports; ++port_index) {
|
||||||
auto result = m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::SET_FEATURE, HubFeatureSelector::PORT_POWER, port_index + 1, 0, nullptr);
|
auto result = m_default_pipe->submit_control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::SET_FEATURE, HubFeatureSelector::PORT_POWER, port_index + 1, 0, nullptr);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
dbgln("USB: Failed to power on port {} on hub at address {}.", port_index + 1, m_address);
|
dbgln("USB: Failed to power on port {} on hub at address {}.", port_index + 1, m_address);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ ErrorOr<void> Hub::get_port_status(u8 port, HubStatus& hub_status)
|
||||||
if (port == 0 || port > m_hub_descriptor.number_of_downstream_ports)
|
if (port == 0 || port > m_hub_descriptor.number_of_downstream_ports)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
auto transfer_length = TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::GET_STATUS, 0, port, sizeof(HubStatus), &hub_status));
|
auto transfer_length = TRY(m_default_pipe->submit_control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::GET_STATUS, 0, port, sizeof(HubStatus), &hub_status));
|
||||||
|
|
||||||
// FIXME: This be "not equal to" instead of "less than", but control transfers report a higher transfer length than expected.
|
// FIXME: This be "not equal to" instead of "less than", but control transfers report a higher transfer length than expected.
|
||||||
if (transfer_length < sizeof(HubStatus)) {
|
if (transfer_length < sizeof(HubStatus)) {
|
||||||
|
@ -116,7 +116,7 @@ ErrorOr<void> Hub::clear_port_feature(u8 port, HubFeatureSelector feature_select
|
||||||
if (port == 0 || port > m_hub_descriptor.number_of_downstream_ports)
|
if (port == 0 || port > m_hub_descriptor.number_of_downstream_ports)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::CLEAR_FEATURE, feature_selector, port, 0, nullptr));
|
TRY(m_default_pipe->submit_control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::CLEAR_FEATURE, feature_selector, port, 0, nullptr));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ ErrorOr<void> Hub::set_port_feature(u8 port, HubFeatureSelector feature_selector
|
||||||
if (port == 0 || port > m_hub_descriptor.number_of_downstream_ports)
|
if (port == 0 || port > m_hub_descriptor.number_of_downstream_ports)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::SET_FEATURE, feature_selector, port, 0, nullptr));
|
TRY(m_default_pipe->submit_control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_REQUEST_RECIPIENT_OTHER, HubRequest::SET_FEATURE, feature_selector, port, 0, nullptr));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ ControlPipe::ControlPipe(USBController const& controller, u8 endpoint_address, u
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<size_t> ControlPipe::control_transfer(u8 request_type, u8 request, u16 value, u16 index, size_t length, void* data)
|
ErrorOr<size_t> ControlPipe::submit_control_transfer(u8 request_type, u8 request, u16 value, u16 index, size_t length, void* data)
|
||||||
{
|
{
|
||||||
VERIFY(length <= m_dma_buffer->size());
|
VERIFY(length <= m_dma_buffer->size());
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ BulkInPipe::BulkInPipe(USBController const& controller, u8 endpoint_address, u16
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<size_t> BulkInPipe::bulk_in_transfer(size_t length, void* data)
|
ErrorOr<size_t> BulkInPipe::submit_bulk_in_transfer(size_t length, void* data)
|
||||||
{
|
{
|
||||||
VERIFY(length <= m_dma_buffer->size());
|
VERIFY(length <= m_dma_buffer->size());
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ BulkOutPipe::BulkOutPipe(USBController const& controller, u8 endpoint_address, u
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<size_t> BulkOutPipe::bulk_out_transfer(size_t length, void* data)
|
ErrorOr<size_t> BulkOutPipe::submit_bulk_out_transfer(size_t length, void* data)
|
||||||
{
|
{
|
||||||
VERIFY(length <= m_dma_buffer->size());
|
VERIFY(length <= m_dma_buffer->size());
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ InterruptInPipe::InterruptInPipe(USBController const& controller, u8 endpoint_ad
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullLockRefPtr<Transfer>> InterruptInPipe::interrupt_in_transfer(size_t length, u16 ms_interval, USBAsyncCallback callback)
|
ErrorOr<NonnullLockRefPtr<Transfer>> InterruptInPipe::submit_interrupt_in_transfer(size_t length, u16 ms_interval, USBAsyncCallback callback)
|
||||||
{
|
{
|
||||||
VERIFY(length <= m_dma_buffer->size());
|
VERIFY(length <= m_dma_buffer->size());
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ class ControlPipe : public Pipe {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullOwnPtr<ControlPipe>> create(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, size_t buffer_size = PAGE_SIZE);
|
static ErrorOr<NonnullOwnPtr<ControlPipe>> create(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, size_t buffer_size = PAGE_SIZE);
|
||||||
|
|
||||||
ErrorOr<size_t> control_transfer(u8 request_type, u8 request, u16 value, u16 index, size_t length, void* data);
|
ErrorOr<size_t> submit_control_transfer(u8 request_type, u8 request, u16 value, u16 index, size_t length, void* data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ControlPipe(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, NonnullOwnPtr<Memory::Region> dma_buffer);
|
ControlPipe(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, NonnullOwnPtr<Memory::Region> dma_buffer);
|
||||||
|
@ -93,7 +93,7 @@ class BulkInPipe : public Pipe {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullOwnPtr<BulkInPipe>> create(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, size_t buffer_size = PAGE_SIZE);
|
static ErrorOr<NonnullOwnPtr<BulkInPipe>> create(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, size_t buffer_size = PAGE_SIZE);
|
||||||
|
|
||||||
ErrorOr<size_t> bulk_in_transfer(size_t length, void* data);
|
ErrorOr<size_t> submit_bulk_in_transfer(size_t length, void* data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BulkInPipe(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, NonnullOwnPtr<Memory::Region> dma_buffer);
|
BulkInPipe(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, NonnullOwnPtr<Memory::Region> dma_buffer);
|
||||||
|
@ -103,7 +103,7 @@ class BulkOutPipe : public Pipe {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullOwnPtr<BulkOutPipe>> create(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, size_t buffer_size = PAGE_SIZE);
|
static ErrorOr<NonnullOwnPtr<BulkOutPipe>> create(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, size_t buffer_size = PAGE_SIZE);
|
||||||
|
|
||||||
ErrorOr<size_t> bulk_out_transfer(size_t length, void* data);
|
ErrorOr<size_t> submit_bulk_out_transfer(size_t length, void* data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BulkOutPipe(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, NonnullOwnPtr<Memory::Region> dma_buffer);
|
BulkOutPipe(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, NonnullOwnPtr<Memory::Region> dma_buffer);
|
||||||
|
@ -113,7 +113,7 @@ class InterruptInPipe : public Pipe {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullOwnPtr<InterruptInPipe>> create(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, u16 poll_interval, size_t buffer_size = PAGE_SIZE);
|
static ErrorOr<NonnullOwnPtr<InterruptInPipe>> create(USBController const& controller, u8 endpoint_address, u16 max_packet_size, i8 device_address, u16 poll_interval, size_t buffer_size = PAGE_SIZE);
|
||||||
|
|
||||||
ErrorOr<NonnullLockRefPtr<Transfer>> interrupt_in_transfer(size_t length, u16 ms_interval, USBAsyncCallback callback);
|
ErrorOr<NonnullLockRefPtr<Transfer>> submit_interrupt_in_transfer(size_t length, u16 ms_interval, USBAsyncCallback callback);
|
||||||
|
|
||||||
u16 poll_interval() const { return m_poll_interval; }
|
u16 poll_interval() const { return m_poll_interval; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue