From 568a89904c7fc93071efd7f811fc58aff6d5774a Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Tue, 11 Oct 2011 15:33:50 +0200 Subject: cpupower: Better interface for accessing AMD pci registers AMD's BKDG (Bios and Kernel Developers Guide) talks in the CPU spec of their CPU families about PCI registers defined by "device" (slot) and func(tion). Assuming that CPU specific configuration PCI devices are always on domain and bus zero a pci_slot_func_init() func which gets the slot and func of the desired PCI device passed looks like the most convenient way. This also obsoletes the PCI device id maintenance. Signed-off-by: Thomas Renninger CC: Andreas Herrmann Signed-off-by: Dominik Brodowski --- tools/power/cpupower/utils/helpers/amd.c | 4 +--- tools/power/cpupower/utils/helpers/helpers.h | 7 ++++-- tools/power/cpupower/utils/helpers/pci.c | 35 ++++++++++++++++++---------- 3 files changed, 29 insertions(+), 17 deletions(-) (limited to 'tools/power/cpupower/utils/helpers') diff --git a/tools/power/cpupower/utils/helpers/amd.c b/tools/power/cpupower/utils/helpers/amd.c index 87d5605bdda..6437ef39aee 100644 --- a/tools/power/cpupower/utils/helpers/amd.c +++ b/tools/power/cpupower/utils/helpers/amd.c @@ -112,14 +112,12 @@ int decode_pstates(unsigned int cpu, unsigned int cpu_family, int amd_pci_get_num_boost_states(int *active, int *states) { struct pci_access *pci_acc; - int vendor_id = 0x1022; - int boost_dev_ids[4] = {0x1204, 0x1604, 0x1704, 0}; struct pci_dev *device; uint8_t val = 0; *active = *states = 0; - device = pci_acc_init(&pci_acc, vendor_id, boost_dev_ids); + device = pci_slot_func_init(&pci_acc, 0x18, 4); if (device == NULL) return -ENODEV; diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h index 2747e738efb..6280daa4e24 100644 --- a/tools/power/cpupower/utils/helpers/helpers.h +++ b/tools/power/cpupower/utils/helpers/helpers.h @@ -132,8 +132,11 @@ extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu); /* PCI stuff ****************************/ extern int amd_pci_get_num_boost_states(int *active, int *states); -extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id, - int *dev_ids); +extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int domain, + int bus, int slot, int func, int vendor, + int dev); +extern struct pci_dev *pci_slot_func_init(struct pci_access **pacc, + int slot, int func); /* PCI stuff ****************************/ diff --git a/tools/power/cpupower/utils/helpers/pci.c b/tools/power/cpupower/utils/helpers/pci.c index cd2eb6fe41c..9690798e644 100644 --- a/tools/power/cpupower/utils/helpers/pci.c +++ b/tools/power/cpupower/utils/helpers/pci.c @@ -10,19 +10,24 @@ * **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 + * domain: domain + * bus: bus + * slot: slot + * func: func + * vendor: vendor + * device: device + * Pass -1 for one of the six above to match any * * 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_dev *pci_acc_init(struct pci_access **pacc, int domain, int bus, + int slot, int func, int vendor, int dev) { - struct pci_filter filter_nb_link = { -1, -1, -1, -1, vendor_id, 0}; + struct pci_filter filter_nb_link = { domain, bus, slot, func, + vendor, dev }; struct pci_dev *device; - unsigned int i; *pacc = pci_alloc(); if (*pacc == NULL) @@ -31,14 +36,20 @@ struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id, 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; - } + for (device = (*pacc)->devices; device; device = device->next) { + if (pci_filter_match(&filter_nb_link, device)) + return device; } pci_cleanup(*pacc); return NULL; } + +/* Typically one wants to get a specific slot(device)/func of the root domain + and bus */ +struct pci_dev *pci_slot_func_init(struct pci_access **pacc, int slot, + int func) +{ + return pci_acc_init(pacc, 0, 0, slot, func, -1, -1); +} + #endif /* defined(__i386__) || defined(__x86_64__) */ -- cgit v1.2.3