diff options
Diffstat (limited to 'tools/power/cpupower/utils/helpers/pci.c')
-rw-r--r-- | tools/power/cpupower/utils/helpers/pci.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/tools/power/cpupower/utils/helpers/pci.c b/tools/power/cpupower/utils/helpers/pci.c index cd2eb6fe41c4..9690798e6446 100644 --- a/tools/power/cpupower/utils/helpers/pci.c +++ b/tools/power/cpupower/utils/helpers/pci.c | |||
@@ -10,19 +10,24 @@ | |||
10 | * **pacc : if a valid pci_dev is returned | 10 | * **pacc : if a valid pci_dev is returned |
11 | * *pacc must be passed to pci_acc_cleanup to free it | 11 | * *pacc must be passed to pci_acc_cleanup to free it |
12 | * | 12 | * |
13 | * vendor_id : the pci vendor id matching the pci device to access | 13 | * domain: domain |
14 | * dev_ids : device ids matching the pci device to access | 14 | * bus: bus |
15 | * slot: slot | ||
16 | * func: func | ||
17 | * vendor: vendor | ||
18 | * device: device | ||
19 | * Pass -1 for one of the six above to match any | ||
15 | * | 20 | * |
16 | * Returns : | 21 | * Returns : |
17 | * struct pci_dev which can be used with pci_{read,write}_* functions | 22 | * struct pci_dev which can be used with pci_{read,write}_* functions |
18 | * to access the PCI config space of matching pci devices | 23 | * to access the PCI config space of matching pci devices |
19 | */ | 24 | */ |
20 | struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id, | 25 | struct pci_dev *pci_acc_init(struct pci_access **pacc, int domain, int bus, |
21 | int *dev_ids) | 26 | int slot, int func, int vendor, int dev) |
22 | { | 27 | { |
23 | struct pci_filter filter_nb_link = { -1, -1, -1, -1, vendor_id, 0}; | 28 | struct pci_filter filter_nb_link = { domain, bus, slot, func, |
29 | vendor, dev }; | ||
24 | struct pci_dev *device; | 30 | struct pci_dev *device; |
25 | unsigned int i; | ||
26 | 31 | ||
27 | *pacc = pci_alloc(); | 32 | *pacc = pci_alloc(); |
28 | if (*pacc == NULL) | 33 | if (*pacc == NULL) |
@@ -31,14 +36,20 @@ struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id, | |||
31 | pci_init(*pacc); | 36 | pci_init(*pacc); |
32 | pci_scan_bus(*pacc); | 37 | pci_scan_bus(*pacc); |
33 | 38 | ||
34 | for (i = 0; dev_ids[i] != 0; i++) { | 39 | for (device = (*pacc)->devices; device; device = device->next) { |
35 | filter_nb_link.device = dev_ids[i]; | 40 | if (pci_filter_match(&filter_nb_link, device)) |
36 | for (device = (*pacc)->devices; device; device = device->next) { | 41 | return device; |
37 | if (pci_filter_match(&filter_nb_link, device)) | ||
38 | return device; | ||
39 | } | ||
40 | } | 42 | } |
41 | pci_cleanup(*pacc); | 43 | pci_cleanup(*pacc); |
42 | return NULL; | 44 | return NULL; |
43 | } | 45 | } |
46 | |||
47 | /* Typically one wants to get a specific slot(device)/func of the root domain | ||
48 | and bus */ | ||
49 | struct pci_dev *pci_slot_func_init(struct pci_access **pacc, int slot, | ||
50 | int func) | ||
51 | { | ||
52 | return pci_acc_init(pacc, 0, 0, slot, func, -1, -1); | ||
53 | } | ||
54 | |||
44 | #endif /* defined(__i386__) || defined(__x86_64__) */ | 55 | #endif /* defined(__i386__) || defined(__x86_64__) */ |