What is the difference between pci_enable_device_mem and pci_enable_device?

2.4k Views Asked by At

What is the difference between pci_enable_device_mem and pci_enable_device?

In ixgbe pf driver uses pci_enable_device_mem and vf driver uses pci_enable_device.

2

There are 2 best solutions below

0
On

pci_enable_device_mem — Initialize a device for use with Memory space https://www.kernel.org/doc/htmldocs/kernel-api/API-pci-enable-device-mem.html

pci_enable_device — Initialize device before it's used by a driver. https://www.kernel.org/doc/htmldocs/kernel-api/API-pci-enable-device.html

The first one is the initialize the device so it can be used with memory space. The second one will initialize a device before it is used by a driver.

0
On

Well, both functions internally call pci_enable_device_flags(). The difference is that pci_enable_device_mem() variant initializes only Memory-mapped BARs, whereas pci_enable_device() will initialize both Memory-mapped and IO BARs.

If your PCI device does not have IO spaces (most probably this is indeed the case) you can easily use pci_enable_device_mem().

This is the code from drivers/pci/pci.c:

int pci_enable_device_mem(struct pci_dev *dev)
{
    return pci_enable_device_flags(dev, IORESOURCE_MEM);
}

int pci_enable_device(struct pci_dev *dev)
{
    return pci_enable_device_flags(dev, IORESOURCE_MEM | IORESOURCE_IO);
}