PCI: Add I/O BAR support to generic pci_mmap_resource_range()
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 12 Apr 2017 12:26:08 +0000 (13:26 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 20 Apr 2017 13:47:47 +0000 (08:47 -0500)
This will need to call into an arch-provided pci_iobar_pfn() function.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/mmap.c
include/linux/pci.h

index b7aca9c89c318f9fd950a9b1482274239f5c438d..9a5e5a9055eb2a8275d1ce4523bd17dc9d448949 100644 (file)
@@ -48,9 +48,7 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar,
                            enum pci_mmap_state mmap_state, int write_combine)
 {
        unsigned long size;
-
-       if (mmap_state == pci_mmap_io)
-               return -EINVAL;
+       int ret;
 
        size = ((pci_resource_len(pdev, bar) - 1) >> PAGE_SHIFT) + 1;
        if (vma->vm_pgoff + vma_pages(vma) > size)
@@ -61,7 +59,13 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar,
        else
                vma->vm_page_prot = pgprot_device(vma->vm_page_prot);
 
-       vma->vm_pgoff += (pci_resource_start(pdev, bar) >> PAGE_SHIFT);
+       if (mmap_state == pci_mmap_io) {
+               ret = pci_iobar_pfn(pdev, bar, vma);
+               if (ret)
+                       return ret;
+       } else
+               vma->vm_pgoff += (pci_resource_start(pdev, bar) >> PAGE_SHIFT);
+
        vma->vm_ops = &pci_phys_vm_ops;
 
        return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
index 98a72abcf3611619140ef97bb2ce14b938777006..9f302444d4ac1d51aac39a9357c5de78a6a0b654 100644 (file)
@@ -1648,8 +1648,12 @@ int pci_mmap_page_range(struct pci_dev *pdev, int bar,
 #ifndef arch_can_pci_mmap_wc
 #define arch_can_pci_mmap_wc()         0
 #endif
+
 #ifndef arch_can_pci_mmap_io
 #define arch_can_pci_mmap_io()         0
+#define pci_iobar_pfn(pdev, bar, vma) (-EINVAL)
+#else
+int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma);
 #endif
 
 #ifndef pci_root_bus_fwnode