diff --git a/Kernel/Bus/USB/USBDevice.cpp b/Kernel/Bus/USB/USBDevice.cpp index 1f1d1b24ae..49c449427c 100644 --- a/Kernel/Bus/USB/USBDevice.cpp +++ b/Kernel/Bus/USB/USBDevice.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Jesse Buhagiar + * Copyright (c) 2021-2023, Jesse Buhagiar * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,22 @@ ErrorOr> Device::try_create(USBController const& contr node = move(sysfs_node); }); TRY(device->enumerate_device()); + + // Attempt to find a driver for this device. If one is found, we call the driver's + // "probe" function, which initialises the local state for the device driver. + // It is currently the driver's responsibility to search the configuration/interface + // and take the appropriate action. + for (auto& driver : USBManagement::the().available_drivers()) { + // FIXME: Some devices have multiple configurations, for which we may have a better driver, + // than the first we find, or we have a vendor specific driver for the device, + // so we want a prioritization mechanism here + auto result = driver->probe(device); + if (result.is_error()) + continue; + dbgln_if(USB_DEBUG, "Found driver {} for device {:04x}:{:04x}!", driver->name(), device->m_vendor_id, device->m_product_id); + break; + } + return device; }