Page MenuHomeFreeBSD

pci: Add pci_find_class_from
ClosedPublic

Authored by manu on Dec 10 2020, 6:19 PM.

Details

Summary

pci_find_class_from help finding one or multiple device matching
a class and subclass.
If the from argument is not null we will first loop in the device list
until we find the matching device and only then start to check if the
class/subclass matches.

Diff Detail

Repository
R10 FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

jhb added inline comments.
sys/dev/pci/pci.c
496

I assume this isn't a hot path, so this approach is fine vs trying to restart the iteration from the existing device. That is, you could perhaps write this as:

if (from == NULL)
    return (pci_find_class(class, subclass);

dinfo = device_get_ivars(from);
for (; dinfo != NULL; info = STAILQ_NEXT(dinfo, pci_links) {
    if (dinfo->cfg.baseclass == class &&
...

But I think your current approach is fine assuming it's only used in things like attach, and it's a bit more robust against bogus input arguments.

This revision is now accepted and ready to land.Dec 17 2020, 7:13 PM
This revision was automatically updated to reflect the committed changes.