pci_enable_device()与pci_enable_device_mem()区别

pci_enable_device()与pci_enable_device_mem()区别

文章目录

  • pci_enable_device()与pci_enable_device_mem()区别
    • 1. pci_enable_device()源码
    • 2. pci_enable_device_mem()源码
    • 3. 区别

1. pci_enable_device()源码

/**
 * pci_enable_device - Initialize device before it's used by a driver.
 * @dev: PCI device to be initialized
 *
 *  Initialize device before it's used by a driver. Ask low-level code
 *  to enable I/O and memory. Wake up the device if it was suspended.
 *  Beware, this function can fail.
 *
 *  Note we don't actually enable the device many times if we call
 *  this function repeatedly (we just increment the count).
 */
int pci_enable_device(struct pci_dev *dev)
{
     
	return pci_enable_device_flags(dev, IORESOURCE_MEM | IORESOURCE_IO);
}

2. pci_enable_device_mem()源码

/**
 * pci_enable_device_mem - Initialize a device for use with Memory space
 * @dev: PCI device to be initialized
 *
 *  Initialize device before it's used by a driver. Ask low-level code
 *  to enable Memory resources. Wake up the device if it was suspended.
 *  Beware, this function can fail.
 */
int pci_enable_device_mem(struct pci_dev *dev)
{
     
	return pci_enable_device_flags(dev, IORESOURCE_MEM);
}

3. 区别

PCI/PCIE的BAR有两种类型,memory和IO。pci_enable_device_mem()只初始化memory类型的BAR,pci_enable_device()同时初始化memory和IO类型的BAR。如果要驱动的PCI/PCIE设备包含IO空间,那么必须使用pci_enable_device()

你可能感兴趣的:(嵌入式linux,linux,pci-e)