[opensuse-kernel] Creating device nodes for kernel driver
Hi there, I wrote a kernel device driver for a special purpose PCI framegrapper device which I maintain using a kmp rpm-package. Sofar I am grep'ing /proc/devices for the major number during startup and create the device nodes at startup. The documentation I found on the web and in /usr/src/linux/Documentations seems to be outdated, incomplete or contradicting. I am now wondering what is the most uptodate and recommended method to create the device nodes without the need for a user space setup script? Mit freundlichen Grüßen / Best regards Martin Konold Robert Bosch GmbH Automotive Electronics Postfach 13 42 72703 Reutlingen GERMANY www.bosch.com Tel. +49 7121 35 3322 Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart, HRB 14000; Aufsichtsratsvorsitzender: Hermann Scholl; Geschäftsführung: Franz Fehrenbach, Siegfried Dais; Stefan Asenkerschbaumer, Bernd Bohr, Rudolf Colm, Volkmar Denner, Wolfgang Malchow, Peter Marks, Uwe Raschke, Wolf-Henning Scheider, Peter Tyroller -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On 07/19/2011 12:53 PM, EXTERNAL Konold Martin (Firma, RtP2/TEF72) wrote:
Hi there,
I wrote a kernel device driver for a special purpose PCI framegrapper device which I maintain using a kmp rpm-package.
Sofar I am grep'ing /proc/devices for the major number during startup and create the device nodes at startup.
Argl.
The documentation I found on the web and in /usr/src/linux/Documentations seems to be outdated, incomplete or contradicting.
I am now wondering what is the most uptodate and recommended method to create the device nodes without the need for a user space setup script?
The 'optimal' way would be to request a dynamic device number; it should then be created automatically via udev. Just call 'request_blkdev' (or request_chrdev) with major = 0, and you'll get a new dynamic major number allocated. Obviously you have to track minor numbers yourself; check for drivers/md/dm.c for how it might be done. Cheers, Hannes -- Dr. Hannes Reinecke zSeries & Storage hare@suse.de +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg) -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
Hi Hannes, Thanks for hinting me! -----Original Message-----
From: Hannes Reinecke [mailto:hare@suse.de]
Sofar I am grep'ing /proc/devices for the major number during startup and create the device nodes at startup.
Argl.
I am now wondering what is the most uptodate and recommended method to create the device nodes without the need for a user space setup script?
The 'optimal' way would be to request a dynamic device number; it should then be created automatically via udev.
Just call 'request_blkdev' (or request_chrdev) with major = 0, and you'll get a new dynamic major number allocated. Obviously you have to track minor numbers yourself; check for drivers/md/dm.c for how it might be done.
Well, I am currently calling register_chrdev() (I could not find a reference to either request_blkdev() nor request_chrdev()) register_chrdev(MajorNr, name, &SSHT_fops); This gives me the dynamically allocated major number which I then printk to klog. In user space I then grep in /proc&devices in order to figure out which major number got dynamically allocated and then create the device nodes algorithmically. I am therefore wondering how to avoid having to use such an awkward startup script while keeping the dynamic major number (I consider this an improvement to the kernel)? Sofar I have seen code which create the devices nodes via ugly kernel space code calling user space tools which imho is not nice either. Mit freundlichen Grüßen / Best regards Martin Konold Robert Bosch GmbH Automotive Electronics Postfach 13 42 72703 Reutlingen GERMANY www.bosch.com Tel. +49 7121 35 3322 Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart, HRB 14000; Aufsichtsratsvorsitzender: Hermann Scholl; Geschäftsführung: Franz Fehrenbach, Siegfried Dais; Stefan Asenkerschbaumer, Bernd Bohr, Rudolf Colm, Volkmar Denner, Wolfgang Malchow, Peter Marks, Uwe Raschke, Wolf-Henning Scheider, Peter Tyroller -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
Am Tue, 19 Jul 2011 13:41:56 +0200
schrieb "EXTERNAL Konold Martin (Firma, RtP2/TEF72)"
register_chrdev(MajorNr, name, &SSHT_fops);
This gives me the dynamically allocated major number which I then printk to klog.
No, it doesnt. AFAICT. I'm pretty sure you need to set "MajorNr" to some value before (or if you don't, it will be "0", but you won't retrieve the allocated number then) This is how I did it (using a char device): hrt_class = class_create(THIS_MODULE, DEVICE_NAME); if (IS_ERR(hrt_class)) { printk(KERN_ERR "%s: can't register device class\n", DRV_NAM); close_clocks(); return PTR_ERR(hrt_class); } major = register_chrdev(0, DEVICE_NAME, &fops); if (major < 0) { printk(KERN_ALERT "Registering char device failed with %d\n", major); class_destroy(hrt_class); close_clocks(); return major; } hrt_class->devnode = hrt_devnode; device_create(hrt_class, NULL, MKDEV(major, 0), NULL, DEVICE_NAME); (no Greg, you really don't want to see the rest of this code, this module was simply written to abstract crappy vendor drivers (Meinberg and TSYNC) in order to not having to touch them and I'm not proud of it ;-)
In user space I then grep in /proc&devices in order to figure out which major number got dynamically allocated and then create the device nodes algorithmically.
udev creates the device for me. I think that the device_create() is the trigger for that. -- Stefan Seyfried "Dispatch war rocket Ajax to bring back his body!" -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Tue, Jul 19, 2011 at 12:53:00PM +0200, EXTERNAL Konold Martin (Firma, RtP2/TEF72) wrote:
Hi there,
I wrote a kernel device driver for a special purpose PCI framegrapper device which I maintain using a kmp rpm-package.
Great, why not work to get it upstream into the main kernel.org repo so that all distros and users can get to it?
Sofar I am grep'ing /proc/devices for the major number during startup and create the device nodes at startup.
Ick, no, that's not good.
The documentation I found on the web and in /usr/src/linux/Documentations seems to be outdated, incomplete or contradicting.
It shouldn't be, have you read the book, Linux Device Drivers, 3rd edition, that says how to do this? It's a bit out of date, but you will get the basic idea. Hint, use a misc device if you want an easy way to do this automatically from your driver. Have a pointer to your source code anywhere? greg k-h -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
participants (4)
-
EXTERNAL Konold Martin (Firma, RtP2/TEF72)
-
Greg KH
-
Hannes Reinecke
-
Stefan Seyfried