]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/mtd/mtdcore.c
Merge tag 'for-linus-20150216' of git://git.infradead.org/linux-mtd
[mirror_ubuntu-bionic-kernel.git] / drivers / mtd / mtdcore.c
index 52eea932c312b7466a8d2632bd993f609f15fa17..11883bd26d9d35e8234cc7dc74f51b7ed57d7566 100644 (file)
 
 #include "mtdcore.h"
 
-/*
- * backing device capabilities for non-mappable devices (such as NAND flash)
- * - permits private mappings, copies are taken of the data
- */
-static struct backing_dev_info mtd_bdi_unmappable = {
-       .capabilities   = BDI_CAP_MAP_COPY,
-};
-
-/*
- * backing device capabilities for R/O mappable devices (such as ROM)
- * - permits private mappings, copies are taken of the data
- * - permits non-writable shared mappings
- */
-static struct backing_dev_info mtd_bdi_ro_mappable = {
-       .capabilities   = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
-                          BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP),
-};
-
-/*
- * backing device capabilities for writable mappable devices (such as RAM)
- * - permits private mappings, copies are taken of the data
- * - permits non-writable shared mappings
- */
-static struct backing_dev_info mtd_bdi_rw_mappable = {
-       .capabilities   = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
-                          BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP |
-                          BDI_CAP_WRITE_MAP),
+static struct backing_dev_info mtd_bdi = {
 };
 
 static int mtd_cls_suspend(struct device *dev, pm_message_t state);
@@ -366,6 +340,23 @@ static struct device_type mtd_devtype = {
        .release        = mtd_release,
 };
 
+#ifndef CONFIG_MMU
+unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
+{
+       switch (mtd->type) {
+       case MTD_RAM:
+               return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
+                       NOMMU_MAP_READ | NOMMU_MAP_WRITE;
+       case MTD_ROM:
+               return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
+                       NOMMU_MAP_READ;
+       default:
+               return NOMMU_MAP_COPY;
+       }
+}
+EXPORT_SYMBOL_GPL(mtd_mmap_capabilities);
+#endif
+
 static int mtd_reboot_notifier(struct notifier_block *n, unsigned long state,
                               void *cmd)
 {
@@ -392,19 +383,7 @@ int add_mtd_device(struct mtd_info *mtd)
        struct mtd_notifier *not;
        int i, error;
 
-       if (!mtd->backing_dev_info) {
-               switch (mtd->type) {
-               case MTD_RAM:
-                       mtd->backing_dev_info = &mtd_bdi_rw_mappable;
-                       break;
-               case MTD_ROM:
-                       mtd->backing_dev_info = &mtd_bdi_ro_mappable;
-                       break;
-               default:
-                       mtd->backing_dev_info = &mtd_bdi_unmappable;
-                       break;
-               }
-       }
+       mtd->backing_dev_info = &mtd_bdi;
 
        BUG_ON(mtd->writesize == 0);
        mutex_lock(&mtd_table_mutex);
@@ -1265,17 +1244,9 @@ static int __init init_mtd(void)
        if (ret)
                goto err_reg;
 
-       ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap");
-       if (ret)
-               goto err_bdi1;
-
-       ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap");
-       if (ret)
-               goto err_bdi2;
-
-       ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap");
+       ret = mtd_bdi_init(&mtd_bdi, "mtd");
        if (ret)
-               goto err_bdi3;
+               goto err_bdi;
 
        proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
 
@@ -1288,11 +1259,7 @@ static int __init init_mtd(void)
 out_procfs:
        if (proc_mtd)
                remove_proc_entry("mtd", NULL);
-err_bdi3:
-       bdi_destroy(&mtd_bdi_ro_mappable);
-err_bdi2:
-       bdi_destroy(&mtd_bdi_unmappable);
-err_bdi1:
+err_bdi:
        class_unregister(&mtd_class);
 err_reg:
        pr_err("Error registering mtd class or bdi: %d\n", ret);
@@ -1305,9 +1272,7 @@ static void __exit cleanup_mtd(void)
        if (proc_mtd)
                remove_proc_entry("mtd", NULL);
        class_unregister(&mtd_class);
-       bdi_destroy(&mtd_bdi_unmappable);
-       bdi_destroy(&mtd_bdi_ro_mappable);
-       bdi_destroy(&mtd_bdi_rw_mappable);
+       bdi_destroy(&mtd_bdi);
 }
 
 module_init(init_mtd);