Merge tag 'fbdev-v4.12' of git://github.com/bzolnier/linux
[linux-2.6-block.git] / drivers / pci / pci-sysfs.c
index 25d010d449a31408fe3058783eec32f0be92e3e4..31e99613a12e4d9737d082ac0c5f3be19bbdae7d 100644 (file)
@@ -526,10 +526,37 @@ exit:
        return count;
 }
 
+static ssize_t sriov_drivers_autoprobe_show(struct device *dev,
+                                           struct device_attribute *attr,
+                                           char *buf)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+
+       return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe);
+}
+
+static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
+                                            struct device_attribute *attr,
+                                            const char *buf, size_t count)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       bool drivers_autoprobe;
+
+       if (kstrtobool(buf, &drivers_autoprobe) < 0)
+               return -EINVAL;
+
+       pdev->sriov->drivers_autoprobe = drivers_autoprobe;
+
+       return count;
+}
+
 static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs);
 static struct device_attribute sriov_numvfs_attr =
                __ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP),
                       sriov_numvfs_show, sriov_numvfs_store);
+static struct device_attribute sriov_drivers_autoprobe_attr =
+               __ATTR(sriov_drivers_autoprobe, (S_IRUGO|S_IWUSR|S_IWGRP),
+                      sriov_drivers_autoprobe_show, sriov_drivers_autoprobe_store);
 #endif /* CONFIG_PCI_IOV */
 
 static ssize_t driver_override_store(struct device *dev,
@@ -980,20 +1007,24 @@ void pci_remove_legacy_files(struct pci_bus *b)
 }
 #endif /* HAVE_PCI_LEGACY */
 
-#ifdef HAVE_PCI_MMAP
+#if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)
 
 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
                  enum pci_mmap_api mmap_api)
 {
-       unsigned long nr, start, size, pci_start;
+       unsigned long nr, start, size;
+       resource_size_t pci_start = 0, pci_end;
 
        if (pci_resource_len(pdev, resno) == 0)
                return 0;
        nr = vma_pages(vma);
        start = vma->vm_pgoff;
        size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
-       pci_start = (mmap_api == PCI_MMAP_PROCFS) ?
-                       pci_resource_start(pdev, resno) >> PAGE_SHIFT : 0;
+       if (mmap_api == PCI_MMAP_PROCFS) {
+               pci_resource_to_user(pdev, resno, &pdev->resource[resno],
+                                    &pci_start, &pci_end);
+               pci_start >>= PAGE_SHIFT;
+       }
        if (start >= pci_start && start < pci_start + size &&
                        start + nr <= pci_start + size)
                return 1;
@@ -1013,37 +1044,24 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
                             struct vm_area_struct *vma, int write_combine)
 {
        struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
-       struct resource *res = attr->private;
+       int bar = (unsigned long)attr->private;
        enum pci_mmap_state mmap_type;
-       resource_size_t start, end;
-       int i;
-
-       for (i = 0; i < PCI_ROM_RESOURCE; i++)
-               if (res == &pdev->resource[i])
-                       break;
-       if (i >= PCI_ROM_RESOURCE)
-               return -ENODEV;
+       struct resource *res = &pdev->resource[bar];
 
        if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start))
                return -EINVAL;
 
-       if (!pci_mmap_fits(pdev, i, vma, PCI_MMAP_SYSFS)) {
+       if (!pci_mmap_fits(pdev, bar, vma, PCI_MMAP_SYSFS)) {
                WARN(1, "process \"%s\" tried to map 0x%08lx bytes at page 0x%08lx on %s BAR %d (start 0x%16Lx, size 0x%16Lx)\n",
                        current->comm, vma->vm_end-vma->vm_start, vma->vm_pgoff,
-                       pci_name(pdev), i,
-                       (u64)pci_resource_start(pdev, i),
-                       (u64)pci_resource_len(pdev, i));
+                       pci_name(pdev), bar,
+                       (u64)pci_resource_start(pdev, bar),
+                       (u64)pci_resource_len(pdev, bar));
                return -EINVAL;
        }
-
-       /* pci_mmap_page_range() expects the same kind of entry as coming
-        * from /proc/bus/pci/ which is a "user visible" value. If this is
-        * different from the resource itself, arch will do necessary fixup.
-        */
-       pci_resource_to_user(pdev, i, res, &start, &end);
-       vma->vm_pgoff += start >> PAGE_SHIFT;
        mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
-       return pci_mmap_page_range(pdev, vma, mmap_type, write_combine);
+
+       return pci_mmap_resource_range(pdev, bar, vma, mmap_type, write_combine);
 }
 
 static int pci_mmap_resource_uc(struct file *filp, struct kobject *kobj,
@@ -1065,22 +1083,18 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
                               loff_t off, size_t count, bool write)
 {
        struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
-       struct resource *res = attr->private;
+       int bar = (unsigned long)attr->private;
+       struct resource *res;
        unsigned long port = off;
-       int i;
 
-       for (i = 0; i < PCI_ROM_RESOURCE; i++)
-               if (res == &pdev->resource[i])
-                       break;
-       if (i >= PCI_ROM_RESOURCE)
-               return -ENODEV;
+       res = &pdev->resource[bar];
 
-       port += pci_resource_start(pdev, i);
+       port += pci_resource_start(pdev, bar);
 
-       if (port > pci_resource_end(pdev, i))
+       if (port > pci_resource_end(pdev, bar))
                return 0;
 
-       if (port + count - 1 > pci_resource_end(pdev, i))
+       if (port + count - 1 > pci_resource_end(pdev, bar))
                return -EINVAL;
 
        switch (count) {
@@ -1170,16 +1184,19 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
        } else {
                pdev->res_attr[num] = res_attr;
                sprintf(res_attr_name, "resource%d", num);
-               res_attr->mmap = pci_mmap_resource_uc;
-       }
-       if (pci_resource_flags(pdev, num) & IORESOURCE_IO) {
-               res_attr->read = pci_read_resource_io;
-               res_attr->write = pci_write_resource_io;
+               if (pci_resource_flags(pdev, num) & IORESOURCE_IO) {
+                       res_attr->read = pci_read_resource_io;
+                       res_attr->write = pci_write_resource_io;
+                       if (arch_can_pci_mmap_io())
+                               res_attr->mmap = pci_mmap_resource_uc;
+               } else {
+                       res_attr->mmap = pci_mmap_resource_uc;
+               }
        }
        res_attr->attr.name = res_attr_name;
        res_attr->attr.mode = S_IRUSR | S_IWUSR;
        res_attr->size = pci_resource_len(pdev, num);
-       res_attr->private = &pdev->resource[num];
+       res_attr->private = (void *)(unsigned long)num;
        retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
        if (retval)
                kfree(res_attr);
@@ -1207,9 +1224,9 @@ static int pci_create_resource_files(struct pci_dev *pdev)
 
                retval = pci_create_attr(pdev, i, 0);
                /* for prefetchable resources, create a WC mappable file */
-               if (!retval && pdev->resource[i].flags & IORESOURCE_PREFETCH)
+               if (!retval && arch_can_pci_mmap_wc() &&
+                   pdev->resource[i].flags & IORESOURCE_PREFETCH)
                        retval = pci_create_attr(pdev, i, 1);
-
                if (retval) {
                        pci_remove_resource_files(pdev);
                        return retval;
@@ -1549,6 +1566,7 @@ static struct attribute_group pci_dev_hp_attr_group = {
 static struct attribute *sriov_dev_attrs[] = {
        &sriov_totalvfs_attr.attr,
        &sriov_numvfs_attr.attr,
+       &sriov_drivers_autoprobe_attr.attr,
        NULL,
 };