Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
David Woodhouse | a1452a3 | 2010-08-08 20:58:20 +0100 | [diff] [blame] | 2 | * Copyright © 2003-2010 David Woodhouse <dwmw2@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
David Woodhouse | a1452a3 | 2010-08-08 20:58:20 +0100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
| 20 | #ifndef __MTD_TRANS_H__ |
| 21 | #define __MTD_TRANS_H__ |
| 22 | |
Ingo Molnar | 48b1926 | 2006-03-31 02:29:41 -0800 | [diff] [blame] | 23 | #include <linux/mutex.h> |
Maxim Levitsky | 048d871 | 2010-02-22 20:39:30 +0200 | [diff] [blame] | 24 | #include <linux/kref.h> |
Maxim Levitsky | 026ec57 | 2010-02-22 20:39:33 +0200 | [diff] [blame] | 25 | #include <linux/sysfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Ingo Molnar | 48b1926 | 2006-03-31 02:29:41 -0800 | [diff] [blame] | 37 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | int devnum; |
Artem Bityutskiy | 7bf7e37 | 2011-03-25 17:41:20 +0200 | [diff] [blame] | 39 | bool bg_stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | unsigned long size; |
| 41 | int readonly; |
Maxim Levitsky | 048d871 | 2010-02-22 20:39:30 +0200 | [diff] [blame] | 42 | int open; |
| 43 | struct kref ref; |
Maxim Levitsky | a863862 | 2010-02-22 20:39:29 +0200 | [diff] [blame] | 44 | struct gendisk *disk; |
Maxim Levitsky | 026ec57 | 2010-02-22 20:39:33 +0200 | [diff] [blame] | 45 | struct attribute_group *disk_attributes; |
Maxim Levitsky | a863862 | 2010-02-22 20:39:29 +0200 | [diff] [blame] | 46 | struct task_struct *thread; |
| 47 | struct request_queue *rq; |
| 48 | spinlock_t queue_lock; |
| 49 | void *priv; |
Alexander Stein | 70d5098 | 2012-01-10 13:26:58 +0100 | [diff] [blame^] | 50 | fmode_t file_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct mtd_blktrans_ops { |
| 54 | char *name; |
| 55 | int major; |
| 56 | int part_bits; |
Richard Purdie | 1918767 | 2006-10-27 09:09:33 +0100 | [diff] [blame] | 57 | int blksize; |
| 58 | int blkshift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* Access functions */ |
| 61 | int (*readsect)(struct mtd_blktrans_dev *dev, |
| 62 | unsigned long block, char *buffer); |
| 63 | int (*writesect)(struct mtd_blktrans_dev *dev, |
| 64 | unsigned long block, char *buffer); |
David Woodhouse | eae9acd | 2008-08-05 18:08:25 +0100 | [diff] [blame] | 65 | int (*discard)(struct mtd_blktrans_dev *dev, |
| 66 | unsigned long block, unsigned nr_blocks); |
Jarkko Lavinen | c7519db | 2011-02-14 16:16:09 +0200 | [diff] [blame] | 67 | void (*background)(struct mtd_blktrans_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | /* Block layer ioctls */ |
| 70 | int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo); |
| 71 | int (*flush)(struct mtd_blktrans_dev *dev); |
| 72 | |
| 73 | /* Called with mtd_table_mutex held; no race with add/remove */ |
| 74 | int (*open)(struct mtd_blktrans_dev *dev); |
| 75 | int (*release)(struct mtd_blktrans_dev *dev); |
| 76 | |
| 77 | /* Called on {de,}registration and on subsequent addition/removal |
| 78 | of devices, with mtd_table_mutex held. */ |
| 79 | void (*add_mtd)(struct mtd_blktrans_ops *tr, struct mtd_info *mtd); |
| 80 | void (*remove_dev)(struct mtd_blktrans_dev *dev); |
| 81 | |
| 82 | struct list_head devs; |
| 83 | struct list_head list; |
| 84 | struct module *owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | extern int register_mtd_blktrans(struct mtd_blktrans_ops *tr); |
| 88 | extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr); |
| 89 | extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev); |
| 90 | extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev); |
Jarkko Lavinen | c7519db | 2011-02-14 16:16:09 +0200 | [diff] [blame] | 91 | extern int mtd_blktrans_cease_background(struct mtd_blktrans_dev *dev); |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | #endif /* __MTD_TRANS_H__ */ |