* about probing a device
@ 2007-10-10 1:39 wit
2007-10-10 4:46 ` Greg KH
2007-10-10 12:09 ` Alan Cox
0 siblings, 2 replies; 7+ messages in thread
From: wit @ 2007-10-10 1:39 UTC (permalink / raw)
To: linux-kernel
Hi,
I found these routines in the kernel, does this means only one driver
can be matched to a device? What if two drivers both can drive the
device, like sd & sg in scsi subsystem?
static int device_attach(struct device * dev)
{
struct bus_type * bus = dev->bus;
struct list_head * entry;
int error;
if (dev->driver) {
device_bind_driver(dev);
return 1;
}
if (bus->match) {
list_for_each(entry, &bus->drivers.list) {
struct device_driver * drv = to_drv(entry);
error = bus_match(dev, drv);
if (!error)
/* success, driver matched */
return 1;
if (error != -ENODEV && error != -ENXIO)
/* driver matched but the probe failed */
printk(KERN_WARNING
"%s: probe of %s failed with error %d\n",
drv->name, dev->bus_id, error);
}
}
return 0;
}
void driver_attach(struct device_driver * drv)
{
struct bus_type * bus = drv->bus;
struct list_head * entry;
int error;
if (!bus->match)
return;
list_for_each(entry, &bus->devices.list) {
struct device * dev = container_of(entry, struct device, bus_list);
if (!dev->driver) {
error = bus_match(dev, drv);
if (error && (error != -ENODEV))
/* driver matched but the probe failed */
printk(KERN_WARNING
"%s: probe of %s failed with error %d\n",
drv->name, dev->bus_id, error);
}
}
}
Thanks
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: about probing a device
2007-10-10 1:39 about probing a device wit
@ 2007-10-10 4:46 ` Greg KH
[not found] ` <105610bf0710100841t1c9463c1q9742534c8bb0dfe5@mail.gmail.com>
2007-10-10 12:09 ` Alan Cox
1 sibling, 1 reply; 7+ messages in thread
From: Greg KH @ 2007-10-10 4:46 UTC (permalink / raw)
To: wit; +Cc: linux-kernel
On Wed, Oct 10, 2007 at 09:39:44AM +0800, wit wrote:
> Hi,
> I found these routines in the kernel, does this means only one driver
> can be matched to a device?
Yes, you are correct, that is how the driver model currently works.
> What if two drivers both can drive the device, like sd & sg in scsi
> subsystem?
You have to go through a lot of pain to get it to work :)
Or create a virtual bus and devices, but that is not how scsi decided to
go about this.
I do have some half-baked patches to fix this in a generic way, to allow
multiple drivers to bind to devices, but it's not fully working right
now and I got side-tracked by having to clean up the kset/kobject/ktype
mess first to get this to work properly, so it might be a few months.
Why, is there some use for multiple drivers to devices that you want to
use?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: about probing a device
2007-10-10 1:39 about probing a device wit
2007-10-10 4:46 ` Greg KH
@ 2007-10-10 12:09 ` Alan Cox
2007-10-10 15:50 ` wit
1 sibling, 1 reply; 7+ messages in thread
From: Alan Cox @ 2007-10-10 12:09 UTC (permalink / raw)
To: wit; +Cc: linux-kernel
On Wed, 10 Oct 2007 09:39:44 +0800
wit <is01kzh@gmail.com> wrote:
> Hi,
> I found these routines in the kernel, does this means only one driver
> can be matched to a device? What if two drivers both can drive the
> device, like sd & sg in scsi subsystem?
The first one which matches and successfully attaches "wins". Thus you
can allow two drivers to match an identifier and load either one or the
other. You can also deal with cases where the same identifier is used for
two different devices (eg with the revision id distinguishing them), by
having the probe methods fail if the revision is wrong.
For things like sd/sg this isn't an issue. The hardware driver interfaces
to the scsi layer which itself provides interfaces for sd, sr, sg, ... etc
If you have a PCI device with multiple device functions on one PCI
function it can be a problem. We have some special case drivers for
serial/parallel multiport cards for exactly this reason, and some ugly
hacks in AGP and EDAC that arise from this limit.
Alan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-10-11 10:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-10 1:39 about probing a device wit
2007-10-10 4:46 ` Greg KH
[not found] ` <105610bf0710100841t1c9463c1q9742534c8bb0dfe5@mail.gmail.com>
2007-10-10 15:59 ` Greg KH
2007-10-10 12:09 ` Alan Cox
2007-10-10 15:50 ` wit
2007-10-10 16:26 ` Cornelia Huck
2007-10-11 10:44 ` wit
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox