问题
https://elixir.bootlin.com/linux/latest/source/include/linux/pci.h#L286
In
struct pci_dev,
I can only see bus and function:
struct pci_bus *bus;
and
unsigned int devfn;
seems no device (of B/D/F) information?
and
struct pci_slot *slot;
In my test, the *slot point to NULL, why ?
回答1:
I found:
device = PCI_SLOT(pdev->devfn);
fn = PCI_FUNC(pdev->devfn);
https://elixir.bootlin.com/linux/v3.5/source/include/linux/pci.h#L31
回答2:
Devfn contains the device number in bits 7:3 and the function number in bits 2:0. The bus number is in bus->number. So the BDF is
bus->number << 8 | devfn
I don’t know about slot; perhaps the device you are looking at is an integrated device?
来源:https://stackoverflow.com/questions/53809842/how-to-get-bus-device-number-from-struct-pci-dev