Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 510  / 2 Years ago, thu, october 13, 2022, 5:55:31

Obvious by the question, does the USB core have an array or something (maybe a linked list) where all the class drivers' information and HCD's information (a name or some kinda number) is stored so that it checks and assign the required when a device is plugged in?


More From » drivers

 Answers
7

In the Linux kernel, the module loader is woken up when a new device is
detected. It's passed a "modalias" string, which identifies the device and
looks something like this for USB devices:



usb:v058Fp6387d0103dc00dsc00dp00ic08isc06ip50in00


You can find your device modalias (and the HCD driver) using the following command:



udevadm info --export-db


This is the section related to my USB drive:



P: /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0
E: DEVTYPE=usb_interface
E: DRIVER=usb-storage
E: ID_MODEL_FROM_DATABASE=Flash Drive
E: ID_VENDOR_FROM_DATABASE=Alcor Micro Corp.
E: INTERFACE=8/6/80
E: MODALIAS=usb:v058Fp6387d0103dc00dsc00dp00ic08isc06ip50in00
E: PRODUCT=58f/6387/103
E: SUBSYSTEM=usb
E: TYPE=0/0/0
E: USEC_INITIALIZED=530904794


This string contains the device class (usb) and class-specific information
(vendor/product/serial number, device class, etc). Each kernel driver
contains a line such as:



MODULE_ALIAS("usb:...")


Which must match the usbalias (wildcards are used to match multiple
devices). If the modalias matches one that the driver supports, this driver
is loaded (or notified of the new device, if it's there already).



You can see the supported devices (by modalias) and their associated modules with



more /lib/modules/`uname -r`/modules.alias


If you grep for the usb-storage device driver, you'll see it has some
specific devices it supports by vendor and device ID, and will also attempt
to support any device with the right (storage) class, no matter the
vendor/device.



The USB modalias can be decoded like this:



usb:
v vendor_id (4 hex)
p product_id (4 hex)
d revision (4 hex)
dc class (2 hex)
dsc subclass (2 hex)
dp protocol (2 hex)
ic interface_class (2 hex)
isc interface_subclass (2 hex)
ip interface_protocol (2 hex)


Source


[#26101] Saturday, October 15, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lawain

Total Points: 150
Total Questions: 106
Total Answers: 101

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
lawain questions
;