11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
2a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * Copyright © 2003-2010 David Woodhouse <dwmw2@infradead.org>
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
4a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * This program is free software; you can redistribute it and/or modify
5a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * it under the terms of the GNU General Public License as published by
6a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * the Free Software Foundation; either version 2 of the License, or
7a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * (at your option) any later version.
8a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse *
9a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * This program is distributed in the hope that it will be useful,
10a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * but WITHOUT ANY WARRANTY; without even the implied warranty of
11a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * GNU General Public License for more details.
13a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse *
14a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * You should have received a copy of the GNU General Public License
15a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * along with this program; if not, write to the Free Software
16a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef __MTD_TRANS_H__
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __MTD_TRANS_H__
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2348b192686dd20cb1576ae1d8ccd17a07971ef24aIngo Molnar#include <linux/mutex.h>
24048d87199566663e4edc4880df3703c04bcf41d9Maxim Levitsky#include <linux/kref.h>
25026ec57886b67c092bf7baecd029a7c1c4998c28Maxim Levitsky#include <linux/sysfs.h>
2622a8578fca5a47e643bb4f70c232d0ec84db9e4eEzequiel Garcia#include <linux/workqueue.h>
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct hd_geometry;
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct mtd_info;
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct mtd_blktrans_ops;
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct file;
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct inode;
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct mtd_blktrans_dev {
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct mtd_blktrans_ops *tr;
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct list_head list;
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct mtd_info *mtd;
3848b192686dd20cb1576ae1d8ccd17a07971ef24aIngo Molnar	struct mutex lock;
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int devnum;
407bf7e370d5919112c223a269462cd0b546903829Artem Bityutskiy	bool bg_stop;
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned long size;
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int readonly;
43048d87199566663e4edc4880df3703c04bcf41d9Maxim Levitsky	int open;
44048d87199566663e4edc4880df3703c04bcf41d9Maxim Levitsky	struct kref ref;
45a863862257b7dd08d855bafcb0aedd9ad848ed91Maxim Levitsky	struct gendisk *disk;
46026ec57886b67c092bf7baecd029a7c1c4998c28Maxim Levitsky	struct attribute_group *disk_attributes;
4722a8578fca5a47e643bb4f70c232d0ec84db9e4eEzequiel Garcia	struct workqueue_struct *wq;
4822a8578fca5a47e643bb4f70c232d0ec84db9e4eEzequiel Garcia	struct work_struct work;
49a863862257b7dd08d855bafcb0aedd9ad848ed91Maxim Levitsky	struct request_queue *rq;
50a863862257b7dd08d855bafcb0aedd9ad848ed91Maxim Levitsky	spinlock_t queue_lock;
51a863862257b7dd08d855bafcb0aedd9ad848ed91Maxim Levitsky	void *priv;
5270d5098a4b1551864dd7df43f67b7f606a1a6438Alexander Stein	fmode_t file_mode;
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct mtd_blktrans_ops {
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	char *name;
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int major;
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int part_bits;
59191876729901d0c8dab8a331f9a1e4b73a56457bRichard Purdie	int blksize;
60191876729901d0c8dab8a331f9a1e4b73a56457bRichard Purdie	int blkshift;
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Access functions */
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int (*readsect)(struct mtd_blktrans_dev *dev,
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		    unsigned long block, char *buffer);
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int (*writesect)(struct mtd_blktrans_dev *dev,
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		     unsigned long block, char *buffer);
67eae9acd13a8d14b50c00a961fa959606f34bbd92David Woodhouse	int (*discard)(struct mtd_blktrans_dev *dev,
68eae9acd13a8d14b50c00a961fa959606f34bbd92David Woodhouse		       unsigned long block, unsigned nr_blocks);
69c7519dbf6f4b4408229d279d799c938ffdd06f21Jarkko Lavinen	void (*background)(struct mtd_blktrans_dev *dev);
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Block layer ioctls */
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int (*flush)(struct mtd_blktrans_dev *dev);
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Called with mtd_table_mutex held; no race with add/remove */
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int (*open)(struct mtd_blktrans_dev *dev);
77a8ca889ed9585894d53fd8919d80cbe8baff09e7Al Viro	void (*release)(struct mtd_blktrans_dev *dev);
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Called on {de,}registration and on subsequent addition/removal
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	   of devices, with mtd_table_mutex held. */
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	void (*add_mtd)(struct mtd_blktrans_ops *tr, struct mtd_info *mtd);
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	void (*remove_dev)(struct mtd_blktrans_dev *dev);
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct list_head devs;
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct list_head list;
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct module *owner;
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int register_mtd_blktrans(struct mtd_blktrans_ops *tr);
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr);
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
93c7519dbf6f4b4408229d279d799c938ffdd06f21Jarkko Lavinenextern int mtd_blktrans_cease_background(struct mtd_blktrans_dev *dev);
9461ecfa8777d0bc8e33dc0e5c2cca9b3247da2d37Thomas Gleixner
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* __MTD_TRANS_H__ */
97