c - How Callback is maintained from Userspace to Kernel Space -


i learning driver , looking watchdog driver code value being written /sys/devices/virtual/wdc_per guess logic how driver gets value userspace , exposed file in user space

 "sys/devices/virtual/wdc_per" 

but how value wdc_per reached driver, there must callback maintained

in case gpio based watchdog driver , gpio_wdt.c may having callback.

but not figure out how happens

anybody can me find out userspace kernel space link.

first of all, driver, gpio_wdt.c, doesn't seem exist in mainline kernel of date, it's hard comment it.

sysfs (usually mounted @ /sys) easy use. this great example of how create sysfs attributes. basically, create attributes (will become sysfs file names) , register them 2 defined operations (callbacks): store , show, equivalent of resp. write , read. show callback called everytime sysfs file (attribute) read , store when it's written.

when writing device driver belongs existing class (most situation), need yourself. because standard linux device classes have working set of sysfs attributes driver use more or less indirectly.

for example, leds class (led devices), of find devices in /sys/class/leds, has bunch of sysfs attributes per led user may read/modify them userspace (brightness, maximum brightness, trigger, etc.). now, if @ led specific drivers in /drivers/leds, won't find manual sysfs attributes creations. find, however, call led_classdev_register when driver probed, takes struct led_classdev* parameter. structure has brightness_set callback member specific driver needs provide. when user writes /sys/class/leds/whatever-led/brightness, leds class' store sysfs callback gets called in turn calls specific driver's brightness_set callback.

my point is: make sure know device class before manually adding sysfs attributes. anyway, when submitting driver lkml, know fast enough if decision.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -