* How to generate hotplug events in drivers?
@ 2004-08-13 1:52 Stephen Glow
2004-08-13 7:06 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Glow @ 2004-08-13 1:52 UTC (permalink / raw)
To: linux-kernel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'm in the process of porting a device driver from the 2.4 kernel to the
2.6 kernel. In the older version of the drivers I was using the devfs
system to create the device files. I've decided to rip this out and
move everything to udev since this seems to be the preferred method now.
The problem I'm having with this port is that I can't get the udev
system to create a device file when I install the module. As far as I
can tell, no hotplug events are being generated when I insmod the device
driver. In other respects the driver seems to be loading correctly;
I'm able to request the PCI regions, enable, and start the PCI device,
and allocate a dynamic device major number. I can also see an entry
create in the /sys/bus/pci/drivers directory.
The device in question is a PCI card of my own design. Since my system
doesn't actually support hot plugging of PCI cards the card will be in
place from system boot. Technically then, there is no hot plugging of a
new piece of hardware when I install the driver, the board has been
there since boot time. Still, the device number has just been
allocated, so it's hard to see how a device file could have been created
before that time.
Should a hotplug event be generated when a new driver is installed for
an existing piece of hardware?
Is there something I need to do in my driver to explicitly generate a
hotplug event?
Please copy my e-mail address with responses.
Thanks,
Steve
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFBHB7ADMBOo/wgA5QRApErAJ0TQMkGEQ9PmyAm1w5uxdFp30PIYACgyVqB
CzQz88Oy7P2vvK5n4SgOhUs=
=xEbx
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to generate hotplug events in drivers?
2004-08-13 1:52 How to generate hotplug events in drivers? Stephen Glow
@ 2004-08-13 7:06 ` Greg KH
2004-08-13 17:09 ` Stephen Glow
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2004-08-13 7:06 UTC (permalink / raw)
To: Stephen Glow; +Cc: linux-kernel
On Thu, Aug 12, 2004 at 09:52:00PM -0400, Stephen Glow wrote:
>
> I'm in the process of porting a device driver from the 2.4 kernel to the
> 2.6 kernel. In the older version of the drivers I was using the devfs
> system to create the device files. I've decided to rip this out and
> move everything to udev since this seems to be the preferred method now.
>
> The problem I'm having with this port is that I can't get the udev
> system to create a device file when I install the module. As far as I
> can tell, no hotplug events are being generated when I insmod the device
> driver. In other respects the driver seems to be loading correctly;
> I'm able to request the PCI regions, enable, and start the PCI device,
> and allocate a dynamic device major number. I can also see an entry
> create in the /sys/bus/pci/drivers directory.
udev needs to see a file called "dev" in the proper structure show up in
the sysfs tree in either /sys/class/* or /sys/block/*. So, you need to
either use the misc char device interface, the block interface, some
other char interface that already has sysfs support, or add your own.
If you need to add your own, I suggest looking into the class_simple
interface, as that's a lot easier to work with to start out with.
Hope this helps,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to generate hotplug events in drivers?
2004-08-13 7:06 ` Greg KH
@ 2004-08-13 17:09 ` Stephen Glow
2004-08-13 17:23 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Glow @ 2004-08-13 17:09 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Greg KH wrote:
| udev needs to see a file called "dev" in the proper structure show up in
| the sysfs tree in either /sys/class/* or /sys/block/*. So, you need to
| either use the misc char device interface, the block interface, some
| other char interface that already has sysfs support, or add your own.
| If you need to add your own, I suggest looking into the class_simple
| interface, as that's a lot easier to work with to start out with.
|
| Hope this helps,
|
| greg k-h
Hi Greg;
Thanks for the response, things seem to be working now.
I'm still a little fuzzy about how all this works together, but the
picture is starting to become a bit clearer. Here are the basic steps I
took in my PCI driver to get the device node to show up, please let me
know if anyone sees an error here:
In the init module function, I create a new class_simple pointer:
static struct class_simple *myclass;
int init_module( void )
{
~ ...
~ myclass = class_simple_create( THIS_MODULE, "myclassname" );
~ ...
}
This causes the new class directory to show up under /sys/class
In the PCI probe function I do the following:
probe(...)
{
~ ...
~ // Allocate a device numer
~ dev_t mydev;
~ alloc_chrdev_region( &mydev, 0, 1, "mydevicename" );
~ // Add this device number to my class. Note I'm passing NULL for
~ // the device pointer. I'm not exactly sure what this is for, but
~ // most devices in the kernel tree seem to pass NULL here.
~ class_simple_add_device( myclass, mydev, NULL, "mydevicename" );
~ // Finally, I init and add my cdev structure.
~ cdev_init( &mycdev, &myfops );
~ mycdev.owner = THIS_MODULE;
~ kobject_set_name( &mycdev.kobj, "mydevicename" );
~ cdev_add( &mycdev, mydev, 1 );
~ ...
}
Of course, my real code has error checking and does cleanup in the PCI
remove function and the module exit function.
Thanks again!
Steve
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFBHPXNDMBOo/wgA5QRAlAkAKCFrxmtrkEhVcCPQ8pBZzPQZccM5ACeJz/e
G/ulXO9/OdoScmgwSBJJ3xM=
=ylWm
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to generate hotplug events in drivers?
2004-08-13 17:09 ` Stephen Glow
@ 2004-08-13 17:23 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2004-08-13 17:23 UTC (permalink / raw)
To: Stephen Glow; +Cc: linux-kernel
On Fri, Aug 13, 2004 at 01:09:33PM -0400, Stephen Glow wrote:
> Thanks for the response, things seem to be working now.
Good.
> I'm still a little fuzzy about how all this works together, but the
> picture is starting to become a bit clearer. Here are the basic steps I
> took in my PCI driver to get the device node to show up, please let me
> know if anyone sees an error here:
>
> In the init module function, I create a new class_simple pointer:
>
> static struct class_simple *myclass;
>
> int init_module( void )
> {
> ~ ...
> ~ myclass = class_simple_create( THIS_MODULE, "myclassname" );
> ~ ...
> }
>
> This causes the new class directory to show up under /sys/class
>
> In the PCI probe function I do the following:
>
> probe(...)
> {
> ~ ...
>
> ~ // Allocate a device numer
> ~ dev_t mydev;
> ~ alloc_chrdev_region( &mydev, 0, 1, "mydevicename" );
>
> ~ // Add this device number to my class. Note I'm passing NULL for
> ~ // the device pointer. I'm not exactly sure what this is for, but
> ~ // most devices in the kernel tree seem to pass NULL here.
> ~ class_simple_add_device( myclass, mydev, NULL, "mydevicename" );
Pass in a pointer to the struct pci_dev ->dev structure. Something
like &pci_dev->dev should work well. Then you will see the "device"
symlink show up in your class device directory in sysfs, which makes
tools like udev much easier to use.
> ~ // Finally, I init and add my cdev structure.
> ~ cdev_init( &mycdev, &myfops );
> ~ mycdev.owner = THIS_MODULE;
Not needed, as it should be pulled from the fops structure.
> ~ kobject_set_name( &mycdev.kobj, "mydevicename" );
Not needed anymore.
> ~ cdev_add( &mycdev, mydev, 1 );
You might want to move the class_simple_add_device() line after the
cdev_add line, just to handle the error conditions easier.
Other than those minor things, this looks good.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-08-13 17:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-13 1:52 How to generate hotplug events in drivers? Stephen Glow
2004-08-13 7:06 ` Greg KH
2004-08-13 17:09 ` Stephen Glow
2004-08-13 17:23 ` Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.