blob: 26529ebd59ccf3872fddca921c141184915fcf62 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
David Woodhousea1452a32010-08-08 20:58:20 +01002 * Copyright © 2003-2010 David Woodhouse <dwmw2@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
David Woodhousea1452a32010-08-08 20:58:20 +01004 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 *
18 */
19
20#ifndef __MTD_TRANS_H__
21#define __MTD_TRANS_H__
22
Ingo Molnar48b19262006-03-31 02:29:41 -080023#include <linux/mutex.h>
Maxim Levitsky048d8712010-02-22 20:39:30 +020024#include <linux/kref.h>
Maxim Levitsky026ec572010-02-22 20:39:33 +020025#include <linux/sysfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27struct hd_geometry;
28struct mtd_info;
29struct mtd_blktrans_ops;
30struct file;
31struct inode;
32
33struct mtd_blktrans_dev {
34 struct mtd_blktrans_ops *tr;
35 struct list_head list;
36 struct mtd_info *mtd;
Ingo Molnar48b19262006-03-31 02:29:41 -080037 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 int devnum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 unsigned long size;
40 int readonly;
Maxim Levitsky048d8712010-02-22 20:39:30 +020041 int open;
42 struct kref ref;
Maxim Levitskya8638622010-02-22 20:39:29 +020043 struct gendisk *disk;
Maxim Levitsky026ec572010-02-22 20:39:33 +020044 struct attribute_group *disk_attributes;
Maxim Levitskya8638622010-02-22 20:39:29 +020045 struct task_struct *thread;
46 struct request_queue *rq;
47 spinlock_t queue_lock;
48 void *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049};
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051struct mtd_blktrans_ops {
52 char *name;
53 int major;
54 int part_bits;
Richard Purdie19187672006-10-27 09:09:33 +010055 int blksize;
56 int blkshift;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 /* Access functions */
59 int (*readsect)(struct mtd_blktrans_dev *dev,
60 unsigned long block, char *buffer);
61 int (*writesect)(struct mtd_blktrans_dev *dev,
62 unsigned long block, char *buffer);
David Woodhouseeae9acd2008-08-05 18:08:25 +010063 int (*discard)(struct mtd_blktrans_dev *dev,
64 unsigned long block, unsigned nr_blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 /* Block layer ioctls */
67 int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);
68 int (*flush)(struct mtd_blktrans_dev *dev);
69
70 /* Called with mtd_table_mutex held; no race with add/remove */
71 int (*open)(struct mtd_blktrans_dev *dev);
72 int (*release)(struct mtd_blktrans_dev *dev);
73
74 /* Called on {de,}registration and on subsequent addition/removal
75 of devices, with mtd_table_mutex held. */
76 void (*add_mtd)(struct mtd_blktrans_ops *tr, struct mtd_info *mtd);
77 void (*remove_dev)(struct mtd_blktrans_dev *dev);
78
79 struct list_head devs;
80 struct list_head list;
81 struct module *owner;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082};
83
84extern int register_mtd_blktrans(struct mtd_blktrans_ops *tr);
85extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr);
86extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
87extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
Thomas Gleixner61ecfa82005-11-07 11:15:31 +000088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90#endif /* __MTD_TRANS_H__ */