Do I need to “enable” a PCIe memory region in a Linux 3.12 driver?

后端 未结 2 2075
没有蜡笔的小新
没有蜡笔的小新 2021-02-10 05:19

I have code, called from the probe() function of my PCIe driver (loosely based on this post):

EDIT: Based on Andreas Bombe\'s response, I changed th

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-10 05:39

    You definitely have to enable it. These are the basic steps:

    pci_enable_device(dev);
    pci_request_regions(dev, "driver/device name");
    bar0 = pci_iomap(dev, 0, 0);
    x = ioread(bar0 + offset);  /* there you are */
    

    Error checking is required for all the pci_* calls. If the device needs to do DMA you also need to call pci_set_master and pci_set_dma_mask.

    To elaborate, bypassing the PCI kernel code and directly ioremapping the BARs may have worked a long time ago. I'm not sure if it is even legal anymore in current code but it certainly isn't advisable.

提交回复
热议问题