Kernel/USB: Pass the configuration value in the GET_DESCRIPTOR request

The low byte of wValue is the configuration value for
GetDescriptor(Configuration) requests.
This commit is contained in:
Sönke Holz 2024-07-27 12:51:06 +02:00 committed by Nico Weber
parent a5b33734f8
commit d8cfe3b4a8
4 changed files with 8 additions and 6 deletions

View file

@ -339,7 +339,7 @@ ErrorOr<void> UHCIController::initialize_device(USB::Device& device)
// Fetch the configuration descriptors from the device
auto& configurations = device.configurations<UHCIController>({});
configurations.ensure_capacity(dev_descriptor.num_configurations);
for (auto configuration = 0u; configuration < dev_descriptor.num_configurations; configuration++) {
for (u8 configuration = 0u; configuration < dev_descriptor.num_configurations; configuration++) {
USBConfigurationDescriptor configuration_descriptor;
transfer_length = TRY(device.control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_CONFIGURATION << 8u) | configuration, 0, sizeof(USBConfigurationDescriptor), &configuration_descriptor));
@ -352,7 +352,7 @@ ErrorOr<void> UHCIController::initialize_device(USB::Device& device)
dbgln("Maximum Power: {}mA", configuration_descriptor.max_power_in_ma * 2u); // This value is in 2mA steps
}
USBConfiguration device_configuration(device, configuration_descriptor);
USBConfiguration device_configuration(device, configuration_descriptor, configuration);
TRY(device_configuration.enumerate_interfaces());
configurations.append(device_configuration);
}

View file

@ -20,7 +20,7 @@ ErrorOr<void> USBConfiguration::enumerate_interfaces()
// The USB spec is a little bit janky here... Interface and Endpoint descriptors aren't fetched
// through a `GET_DESCRIPTOR` request to the device. Instead, the _entire_ hierarchy is returned
// to us in one go.
auto transfer_length = TRY(m_device.control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_CONFIGURATION << 8), 0, m_descriptor.total_length, descriptor_hierarchy_buffer.data()));
auto transfer_length = TRY(m_device.control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_CONFIGURATION << 8) | m_descriptor_index, 0, m_descriptor.total_length, descriptor_hierarchy_buffer.data()));
// FIXME: Why does transfer length return the actual size +8 bytes?
if (transfer_length < m_descriptor.total_length)

View file

@ -18,9 +18,10 @@ class Device;
class USBConfiguration {
public:
USBConfiguration() = delete;
USBConfiguration(Device& device, USBConfigurationDescriptor const descriptor)
USBConfiguration(Device& device, USBConfigurationDescriptor const descriptor, u8 descriptor_index)
: m_device(device)
, m_descriptor(descriptor)
, m_descriptor_index(descriptor_index)
{
m_interfaces.ensure_capacity(descriptor.number_of_interfaces);
}
@ -40,6 +41,7 @@ public:
private:
Device& m_device; // Reference to the device linked to this configuration
USBConfigurationDescriptor const m_descriptor; // Descriptor that backs this configuration
u8 m_descriptor_index; // Descriptor index for {GET,SET}_DESCRIPTOR
Vector<USBInterface> m_interfaces; // Interfaces for this device
};

View file

@ -690,14 +690,14 @@ ErrorOr<void> xHCIController::initialize_device(USB::Device& device)
// Fetch the configuration descriptors from the device
auto& configurations = device.configurations<xHCIController>({});
configurations.ensure_capacity(dev_descriptor.num_configurations);
for (auto configuration = 0u; configuration < dev_descriptor.num_configurations; configuration++) {
for (u8 configuration = 0u; configuration < dev_descriptor.num_configurations; configuration++) {
USBConfigurationDescriptor configuration_descriptor;
transfer_length = TRY(device.control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_CONFIGURATION << 8u) | configuration, 0, sizeof(USBConfigurationDescriptor), &configuration_descriptor));
if (transfer_length < sizeof(USBConfigurationDescriptor)) {
dbgln_if(XHCI_DEBUG, "xHCI: Did not receive enough bytes for configuration descriptor - Expected {} but got {}", sizeof(USBConfigurationDescriptor), transfer_length);
continue;
}
USBConfiguration device_configuration(device, configuration_descriptor);
USBConfiguration device_configuration(device, configuration_descriptor, configuration);
TRY(device_configuration.enumerate_interfaces());
configurations.append(device_configuration);
}