Messages in this thread | | | Date | Sun, 12 Sep 1999 23:52:16 -0400 | From | Jeff Garzik <> | Subject | [patch] pci probing |
| |
What do the Penguins At Large think about this? The following is a presentation of simple PCI probe code which I think can be useful. It is small, and can easily replace existing probe mechanisms. As the structure itself is only three members, it is quick to put into the code, and painless to maintain. For small or simple drivers this may be enough. For more complex drivers, using a callback scheme makes it easier to step up to the pci-scan code.
Regards,
Jeff
typedef int (*pci_simple_probe_callback) (struct pci_dev *dev, int match_num, void *dev_data, void *drvr_data);
struct pci_simple_probe_entry { unsigned short vendor; /* vendor id, PCI_ANY_ID, or 0 for last entry */ unsigned short device; /* device id, PCI_ANY_ID, or 0 for last entry */ void *dev_data; /* driver-private, entry-specific data */ };
int pci_simple_probe (struct pci_simple_probe_entry *list, size_t match_limit, pci_simple_probe_callback cb, void *drvr_data) { struct pci_dev *dev; struct pci_simple_probe_entry *ent; size_t matches = 0;
if (!list || !cb) return -ENODEV;
dev = pci_find_device (PCI_ANY_ID, PCI_ANY_ID, NULL); while (dev) { ent = list; while (ent->vendor && ent->device) { if (((PCI_ANY_ID != ent->vendor) && (dev->vendor != ent->vendor)) || ((PCI_ANY_ID != ent->vendor) && (dev->device != ent->device))) continue;
int rc = (* cb) (dev, matches, ent->dev_data, drvr_data); if (rc < 0) return rc;
matches++;
if (match_limit && match_limit == matches) return matches;
ent++; }
dev = pci_find_device (PCI_ANY_ID, PCI_ANY_ID, dev); }
return matches; }
-- Custom driver development | Never worry about theory as long Open source programming | as the machinery does what it's | supposed to do. -- R. A. Heinlein
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |