Path: blob/master/tools/power/cpupower/utils/helpers/pci.c
26299 views
// SPDX-License-Identifier: GPL-2.01#if defined(__i386__) || defined(__x86_64__)23#include <helpers/helpers.h>45/*6* pci_acc_init7*8* PCI access helper function depending on libpci9*10* **pacc : if a valid pci_dev is returned11* *pacc must be passed to pci_acc_cleanup to free it12*13* domain: domain14* bus: bus15* slot: slot16* func: func17* vendor: vendor18* device: device19* Pass -1 for one of the six above to match any20*21* Returns :22* struct pci_dev which can be used with pci_{read,write}_* functions23* to access the PCI config space of matching pci devices24*/25struct pci_dev *pci_acc_init(struct pci_access **pacc, int domain, int bus,26int slot, int func, int vendor, int dev)27{28struct pci_filter filter_nb_link;29struct pci_dev *device;3031*pacc = pci_alloc();32if (*pacc == NULL)33return NULL;3435pci_filter_init(*pacc, &filter_nb_link);36filter_nb_link.domain = domain;37filter_nb_link.bus = bus;38filter_nb_link.slot = slot;39filter_nb_link.func = func;40filter_nb_link.vendor = vendor;41filter_nb_link.device = dev;4243pci_init(*pacc);44pci_scan_bus(*pacc);4546for (device = (*pacc)->devices; device; device = device->next) {47if (pci_filter_match(&filter_nb_link, device))48return device;49}50pci_cleanup(*pacc);51return NULL;52}5354/* Typically one wants to get a specific slot(device)/func of the root domain55and bus */56struct pci_dev *pci_slot_func_init(struct pci_access **pacc, int slot,57int func)58{59return pci_acc_init(pacc, 0, 0, slot, func, -1, -1);60}6162#endif /* defined(__i386__) || defined(__x86_64__) */636465