diff options
author | Christoph Hellwig <hch@lst.de> | 2015-01-14 04:42:32 -0500 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2015-01-20 16:02:58 -0500 |
commit | b4caecd48005fbed3949dde6c1cb233142fd69e9 (patch) | |
tree | 1fdd9b7c15568c79eb3c1ed84a39858ddbcbc88b /drivers/mtd/mtdcore.c | |
parent | 97b713ba3ebaa6c8d84c2c720f5468a7c6a6eb4e (diff) |
fs: introduce f_op->mmap_capabilities for nommu mmap support
Since "BDI: Provide backing device capability information [try #3]" the
backing_dev_info structure also provides flags for the kind of mmap
operation available in a nommu environment, which is entirely unrelated
to it's original purpose.
Introduce a new nommu-only file operation to provide this information to
the nommu mmap code instead. Splitting this from the backing_dev_info
structure allows to remove lots of backing_dev_info instance that aren't
otherwise needed, and entirely gets rid of the concept of providing a
backing_dev_info for a character device. It also removes the need for
the mtd_inodefs filesystem.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Tejun Heo <tj@kernel.org>
Acked-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r-- | drivers/mtd/mtdcore.c | 80 |
1 files changed, 22 insertions, 58 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 4c611871d7e6..ff38a1df22f7 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c | |||
@@ -43,33 +43,7 @@ | |||
43 | 43 | ||
44 | #include "mtdcore.h" | 44 | #include "mtdcore.h" |
45 | 45 | ||
46 | /* | 46 | static struct backing_dev_info mtd_bdi = { |
47 | * backing device capabilities for non-mappable devices (such as NAND flash) | ||
48 | * - permits private mappings, copies are taken of the data | ||
49 | */ | ||
50 | static struct backing_dev_info mtd_bdi_unmappable = { | ||
51 | .capabilities = BDI_CAP_MAP_COPY, | ||
52 | }; | ||
53 | |||
54 | /* | ||
55 | * backing device capabilities for R/O mappable devices (such as ROM) | ||
56 | * - permits private mappings, copies are taken of the data | ||
57 | * - permits non-writable shared mappings | ||
58 | */ | ||
59 | static struct backing_dev_info mtd_bdi_ro_mappable = { | ||
60 | .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT | | ||
61 | BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP), | ||
62 | }; | ||
63 | |||
64 | /* | ||
65 | * backing device capabilities for writable mappable devices (such as RAM) | ||
66 | * - permits private mappings, copies are taken of the data | ||
67 | * - permits non-writable shared mappings | ||
68 | */ | ||
69 | static struct backing_dev_info mtd_bdi_rw_mappable = { | ||
70 | .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT | | ||
71 | BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP | | ||
72 | BDI_CAP_WRITE_MAP), | ||
73 | }; | 47 | }; |
74 | 48 | ||
75 | static int mtd_cls_suspend(struct device *dev, pm_message_t state); | 49 | static int mtd_cls_suspend(struct device *dev, pm_message_t state); |
@@ -365,6 +339,22 @@ static struct device_type mtd_devtype = { | |||
365 | .release = mtd_release, | 339 | .release = mtd_release, |
366 | }; | 340 | }; |
367 | 341 | ||
342 | #ifndef CONFIG_MMU | ||
343 | unsigned mtd_mmap_capabilities(struct mtd_info *mtd) | ||
344 | { | ||
345 | switch (mtd->type) { | ||
346 | case MTD_RAM: | ||
347 | return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC | | ||
348 | NOMMU_MAP_READ | NOMMU_MAP_WRITE; | ||
349 | case MTD_ROM: | ||
350 | return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC | | ||
351 | NOMMU_MAP_READ; | ||
352 | default: | ||
353 | return NOMMU_MAP_COPY; | ||
354 | } | ||
355 | } | ||
356 | #endif | ||
357 | |||
368 | /** | 358 | /** |
369 | * add_mtd_device - register an MTD device | 359 | * add_mtd_device - register an MTD device |
370 | * @mtd: pointer to new MTD device info structure | 360 | * @mtd: pointer to new MTD device info structure |
@@ -380,19 +370,7 @@ int add_mtd_device(struct mtd_info *mtd) | |||
380 | struct mtd_notifier *not; | 370 | struct mtd_notifier *not; |
381 | int i, error; | 371 | int i, error; |
382 | 372 | ||
383 | if (!mtd->backing_dev_info) { | 373 | mtd->backing_dev_info = &mtd_bdi; |
384 | switch (mtd->type) { | ||
385 | case MTD_RAM: | ||
386 | mtd->backing_dev_info = &mtd_bdi_rw_mappable; | ||
387 | break; | ||
388 | case MTD_ROM: | ||
389 | mtd->backing_dev_info = &mtd_bdi_ro_mappable; | ||
390 | break; | ||
391 | default: | ||
392 | mtd->backing_dev_info = &mtd_bdi_unmappable; | ||
393 | break; | ||
394 | } | ||
395 | } | ||
396 | 374 | ||
397 | BUG_ON(mtd->writesize == 0); | 375 | BUG_ON(mtd->writesize == 0); |
398 | mutex_lock(&mtd_table_mutex); | 376 | mutex_lock(&mtd_table_mutex); |
@@ -1237,17 +1215,9 @@ static int __init init_mtd(void) | |||
1237 | if (ret) | 1215 | if (ret) |
1238 | goto err_reg; | 1216 | goto err_reg; |
1239 | 1217 | ||
1240 | ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap"); | 1218 | ret = mtd_bdi_init(&mtd_bdi, "mtd"); |
1241 | if (ret) | ||
1242 | goto err_bdi1; | ||
1243 | |||
1244 | ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap"); | ||
1245 | if (ret) | ||
1246 | goto err_bdi2; | ||
1247 | |||
1248 | ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap"); | ||
1249 | if (ret) | 1219 | if (ret) |
1250 | goto err_bdi3; | 1220 | goto err_bdi; |
1251 | 1221 | ||
1252 | proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops); | 1222 | proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops); |
1253 | 1223 | ||
@@ -1260,11 +1230,7 @@ static int __init init_mtd(void) | |||
1260 | out_procfs: | 1230 | out_procfs: |
1261 | if (proc_mtd) | 1231 | if (proc_mtd) |
1262 | remove_proc_entry("mtd", NULL); | 1232 | remove_proc_entry("mtd", NULL); |
1263 | err_bdi3: | 1233 | err_bdi: |
1264 | bdi_destroy(&mtd_bdi_ro_mappable); | ||
1265 | err_bdi2: | ||
1266 | bdi_destroy(&mtd_bdi_unmappable); | ||
1267 | err_bdi1: | ||
1268 | class_unregister(&mtd_class); | 1234 | class_unregister(&mtd_class); |
1269 | err_reg: | 1235 | err_reg: |
1270 | pr_err("Error registering mtd class or bdi: %d\n", ret); | 1236 | pr_err("Error registering mtd class or bdi: %d\n", ret); |
@@ -1277,9 +1243,7 @@ static void __exit cleanup_mtd(void) | |||
1277 | if (proc_mtd) | 1243 | if (proc_mtd) |
1278 | remove_proc_entry("mtd", NULL); | 1244 | remove_proc_entry("mtd", NULL); |
1279 | class_unregister(&mtd_class); | 1245 | class_unregister(&mtd_class); |
1280 | bdi_destroy(&mtd_bdi_unmappable); | 1246 | bdi_destroy(&mtd_bdi); |
1281 | bdi_destroy(&mtd_bdi_ro_mappable); | ||
1282 | bdi_destroy(&mtd_bdi_rw_mappable); | ||
1283 | } | 1247 | } |
1284 | 1248 | ||
1285 | module_init(init_mtd); | 1249 | module_init(init_mtd); |