Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / include / linux / mtd / blktrans.h
1 /*
2  * Copyright © 2003-2010 David Woodhouse <dwmw2@infradead.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  */
19
20 #ifndef __MTD_TRANS_H__
21 #define __MTD_TRANS_H__
22
23 #include <linux/mutex.h>
24 #include <linux/kref.h>
25 #include <linux/sysfs.h>
26
27 struct hd_geometry;
28 struct mtd_info;
29 struct mtd_blktrans_ops;
30 struct file;
31 struct inode;
32
33 struct mtd_blktrans_dev {
34         struct mtd_blktrans_ops *tr;
35         struct list_head list;
36         struct mtd_info *mtd;
37         struct mutex lock;
38         int devnum;
39         bool bg_stop;
40         unsigned long size;
41         int readonly;
42         int open;
43         struct kref ref;
44         struct gendisk *disk;
45         struct attribute_group *disk_attributes;
46         struct request_queue *rq;
47         struct list_head rq_list;
48         struct blk_mq_tag_set *tag_set;
49         spinlock_t queue_lock;
50         void *priv;
51         fmode_t file_mode;
52 };
53
54 struct mtd_blktrans_ops {
55         char *name;
56         int major;
57         int part_bits;
58         int blksize;
59         int blkshift;
60
61         /* Access functions */
62         int (*readsect)(struct mtd_blktrans_dev *dev,
63                     unsigned long block, char *buffer);
64         int (*writesect)(struct mtd_blktrans_dev *dev,
65                      unsigned long block, char *buffer);
66         int (*discard)(struct mtd_blktrans_dev *dev,
67                        unsigned long block, unsigned nr_blocks);
68         void (*background)(struct mtd_blktrans_dev *dev);
69
70         /* Block layer ioctls */
71         int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);
72         int (*flush)(struct mtd_blktrans_dev *dev);
73
74         /* Called with mtd_table_mutex held; no race with add/remove */
75         int (*open)(struct mtd_blktrans_dev *dev);
76         void (*release)(struct mtd_blktrans_dev *dev);
77
78         /* Called on {de,}registration and on subsequent addition/removal
79            of devices, with mtd_table_mutex held. */
80         void (*add_mtd)(struct mtd_blktrans_ops *tr, struct mtd_info *mtd);
81         void (*remove_dev)(struct mtd_blktrans_dev *dev);
82
83         struct list_head devs;
84         struct list_head list;
85         struct module *owner;
86 };
87
88 extern int register_mtd_blktrans(struct mtd_blktrans_ops *tr);
89 extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr);
90 extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
91 extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
92 extern int mtd_blktrans_cease_background(struct mtd_blktrans_dev *dev);
93
94
95 #endif /* __MTD_TRANS_H__ */