summaryrefslogtreecommitdiff
path: root/tools/power/cpupower/utils/helpers/pci.c
diff options
context:
space:
mode:
authorStephen Rothwell <sfr@canb.auug.org.au>2011-06-17 11:33:18 +1000
committerStephen Rothwell <sfr@canb.auug.org.au>2011-06-17 11:33:18 +1000
commit64c952db698012efa47e73eb8c309673261c524c (patch)
tree5963ccac8310d7d6225d2a8c1d069f8c2bfd087c /tools/power/cpupower/utils/helpers/pci.c
parentc0aa7e98d44506f66496834d984fadfc3e7d86d5 (diff)
parent9cd581865c6ad25348b6b6d61859a1773c1728bf (diff)
Merge remote-tracking branch 'cpupowerutils/master'
Diffstat (limited to 'tools/power/cpupower/utils/helpers/pci.c')
-rw-r--r--tools/power/cpupower/utils/helpers/pci.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/power/cpupower/utils/helpers/pci.c b/tools/power/cpupower/utils/helpers/pci.c
new file mode 100644
index 000000000000..cd2eb6fe41c4
--- /dev/null
+++ b/tools/power/cpupower/utils/helpers/pci.c
@@ -0,0 +1,44 @@
+#if defined(__i386__) || defined(__x86_64__)
+
+#include <helpers/helpers.h>
+
+/*
+ * pci_acc_init
+ *
+ * PCI access helper function depending on libpci
+ *
+ * **pacc : if a valid pci_dev is returned
+ * *pacc must be passed to pci_acc_cleanup to free it
+ *
+ * vendor_id : the pci vendor id matching the pci device to access
+ * dev_ids : device ids matching the pci device to access
+ *
+ * Returns :
+ * struct pci_dev which can be used with pci_{read,write}_* functions
+ * to access the PCI config space of matching pci devices
+ */
+struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id,
+ int *dev_ids)
+{
+ struct pci_filter filter_nb_link = { -1, -1, -1, -1, vendor_id, 0};
+ struct pci_dev *device;
+ unsigned int i;
+
+ *pacc = pci_alloc();
+ if (*pacc == NULL)
+ return NULL;
+
+ pci_init(*pacc);
+ pci_scan_bus(*pacc);
+
+ for (i = 0; dev_ids[i] != 0; i++) {
+ filter_nb_link.device = dev_ids[i];
+ for (device = (*pacc)->devices; device; device = device->next) {
+ if (pci_filter_match(&filter_nb_link, device))
+ return device;
+ }
+ }
+ pci_cleanup(*pacc);
+ return NULL;
+}
+#endif /* defined(__i386__) || defined(__x86_64__) */