0

I have read that driver core sends uevents through netlink from sysfs to udev or some daemons which are listening to it and thenafter corresponding driver is recongnised by udev and loads it. But how this sysfs entries are created corresponding to a device which is hotplugged? .

Thanks in advance for your response.

Djames
  • 61
  • 6

1 Answers1

0

Drivers create the sysfs entries when they initialize with the major/minor number that they've either gotten or hard coded to use. The file 'uevent' file in each of those device folder allow the daemon to cause the events to be sent in through the netlink socket.

A value of "add" being written into the 'uevent' file will cause all the add events to get generated and thus you can udev or whatever daemon is running (with the appropriate privileges) can create the /dev entries.

Look at this pending hotplug.txt file to see how that works.

Ashwin
  • 270
  • 1
  • 10
  • Thanks for your response.But how the device when it is hotpluggged creates sysfs entries ?. What my understanding is ,from this sysfs entries only, the udev understands the corresponding driver using uvents and loads it.Then as you told, drivers create their entries.Is my understanding correct?. – Djames Jun 05 '13 at 16:26
  • This is a little bit device, driver & hardware dependant logic that goes in. If you take a SD card as an example, traditionally a GPIO is used as a card detect interrupt in the driver. Once the interrupt is triggered, it causes the driver to create the sysfs entries and send up any necessary events which is caught by udev or other equivalent daemons to create the end result /dev file. So every piece of hardware that is "hotpluggable" must have some similar facility to report their insertion/extraction to the driver. – Ashwin Jun 05 '13 at 20:01
  • So you are telling,a device cannot create sysfs entries without its corresponding driver support or if the corresponding driver for a device is not there, then device will not have sysfs entries? – Djames Jun 06 '13 at 05:36
  • That is correct. Without a driver, a device can do perform no action since the system and any application that wishes to use the device would not even know it's there and couldn't talk to it. The Linux Kernel doesn't automatically create the sysfs entries, it's the drivers responsibility to do that work. – Ashwin Jun 06 '13 at 14:19
  • Thanks for your response . The "uvents are created from sysfs entries created for device" which will be later parsed by udev to identify the driver for particular device using MODALIAS of device. So it means that drivers are recognised and loaded after getting uevents from sysfs for devie. Then how is it possible? – Djames Jun 06 '13 at 18:07