mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel/USB: Add driver search on device plug
When a device is plugged into the machine (and hence, when `Device::try_create()` is called), then we attempt to load a driver by calling that driver's probe function.
This commit is contained in:
parent
b0ed126538
commit
b4cd354bae
Notes:
sideshowbarker
2024-07-17 03:18:29 +09:00
Author: https://github.com/Quaker762 Commit: https://github.com/SerenityOS/serenity/commit/b4cd354bae Pull-request: https://github.com/SerenityOS/serenity/pull/21090 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/BertalanD Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/kleinesfilmroellchen ✅ Reviewed-by: https://github.com/supercomputer7 ✅
1 changed files with 18 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
|
||||
* Copyright (c) 2021-2023, Jesse Buhagiar <jooster669@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -10,6 +10,7 @@
|
|||
#include <Kernel/Bus/USB/USBController.h>
|
||||
#include <Kernel/Bus/USB/USBDescriptors.h>
|
||||
#include <Kernel/Bus/USB/USBDevice.h>
|
||||
#include <Kernel/Bus/USB/USBManagement.h>
|
||||
#include <Kernel/Bus/USB/USBRequest.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Bus/USB/DeviceInformation.h>
|
||||
#include <Kernel/Library/StdLib.h>
|
||||
|
@ -25,6 +26,22 @@ ErrorOr<NonnullLockRefPtr<Device>> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue