pci.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #if defined(__i386__) || defined(__x86_64__)
  2. #include <helpers/helpers.h>
  3. /*
  4. * pci_acc_init
  5. *
  6. * PCI access helper function depending on libpci
  7. *
  8. * **pacc : if a valid pci_dev is returned
  9. * *pacc must be passed to pci_acc_cleanup to free it
  10. *
  11. * vendor_id : the pci vendor id matching the pci device to access
  12. * dev_ids : device ids matching the pci device to access
  13. *
  14. * Returns :
  15. * struct pci_dev which can be used with pci_{read,write}_* functions
  16. * to access the PCI config space of matching pci devices
  17. */
  18. struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id,
  19. int *dev_ids)
  20. {
  21. struct pci_filter filter_nb_link = { -1, -1, -1, -1, vendor_id, 0};
  22. struct pci_dev *device;
  23. unsigned int i;
  24. *pacc = pci_alloc();
  25. if (*pacc == NULL)
  26. return NULL;
  27. pci_init(*pacc);
  28. pci_scan_bus(*pacc);
  29. for (i = 0; dev_ids[i] != 0; i++) {
  30. filter_nb_link.device = dev_ids[i];
  31. for (device = (*pacc)->devices; device; device = device->next) {
  32. if (pci_filter_match(&filter_nb_link, device))
  33. return device;
  34. }
  35. }
  36. pci_cleanup(*pacc);
  37. return NULL;
  38. }
  39. #endif /* defined(__i386__) || defined(__x86_64__) */