PCI_MULTI FUNCTION DEVICE DRIVERS

M. Warner Losh imp at bsdimp.com
Wed Sep 14 07:50:34 PDT 2005


In message: <432798A5.7070105 at samsco.org>
            Scott Long <scottl at samsco.org> writes:
: In the FreeBSD driver model, the driver 'probe' method will get called
: for each PCI function in the system.  The driver can either bid to
: claim it, or reject it.  It's up to the driver author as to what
: criteria is used to bid/accept vs reject a function.  Almost all drivers
: look at the pci device id set.  Looking at merely the PCI class code is
: not recommended since it it far too ambiguous.

Generally speaking this is true.  However, the class is available for
inspection and is used by some drivers in the tree (cardbus bridges,
pci bridge, some serial cards).  Extra care has to be taken when
matching this way.

: Also, unlike Linux, the
: driver does not have easy access to the PCI enumeration internals of the
: OS.  There are also no guarantees as to what order the bus will be
: probed or what order functions will be enumerated in.

There's also no guarantee that attach will be called after probe
without other probe routines being called. That's how it is currently
implemented, but there's no iron clad guarnatee that this will always
be the case.

: Do you actually need to program both functions of the hardware?  Usually
: a bridge device tends to be passive from a driver standpoint.  Is there
: something special that your bridge does?  If so then you'll need to
: write two sets of drivers, each with a unique probe, attach, and detach
: method.  Making the separate driver instances work together will be a
: bit tricky.  The easy but really messy approach is to create some global
: variables and methods and have the drivers cheat.  I'd avoid this is at
: all possible.  Probably the more correct approach is to have each
: function walk the device tree and look for its sibling, then communicate
: via custom DEVMETHOD's.  This does have performance implications though,
: so a combination of walking the tree then calling via direct dispatch
: is probably the best approach if performance is a factor.

I've done this on other drivers in the past like this, and it works
relatively well.  Finding siblings can be a bit of a pain, so I
usually do it once and cache the results.  If your bridge function is
just a pci bridge, for example, then the standard driver will likely
do all that's required.

Warner


More information about the freebsd-hackers mailing list