- David Miller: sparc and net updates. Fix merge_segments.
[davej-history.git] / include / linux / mtd / mtd.h
blob708f4f203091b3217a9a643d0f18570afbd1bfa8
2 /* $Id: mtd.h,v 1.26 2000/10/30 17:18:04 sjhill Exp $ */
4 #ifndef __MTD_MTD_H__
5 #define __MTD_MTD_H__
7 #ifdef __KERNEL__
9 #include <linux/version.h>
10 #include <linux/types.h>
11 #include <linux/mtd/compatmac.h>
12 #include <linux/module.h>
13 #include <linux/uio.h>
15 #endif /* __KERNEL__ */
17 struct erase_info_user {
18 unsigned long start;
19 unsigned long length;
22 struct mtd_oob_buf {
23 loff_t start;
24 ssize_t length;
25 unsigned char *ptr;
29 #define MTD_CHAR_MAJOR 90
30 #define MTD_BLOCK_MAJOR 31
31 #define MAX_MTD_DEVICES 16
35 #define MTD_ABSENT 0
36 #define MTD_RAM 1
37 #define MTD_ROM 2
38 #define MTD_NORFLASH 3
39 #define MTD_NANDFLASH 4
40 #define MTD_PEROM 5
41 #define MTD_OTHER 14
42 #define MTD_UNKNOWN 15
46 #define MTD_CLEAR_BITS 1 // Bits can be cleared (flash)
47 #define MTD_SET_BITS 2 // Bits can be set
48 #define MTD_ERASEABLE 4 // Has an erase function
49 #define MTD_WRITEB_WRITEABLE 8 // Direct IO is possible
50 #define MTD_VOLATILE 16 // Set for RAMs
51 #define MTD_XIP 32 // eXecute-In-Place possible
52 #define MTD_OOB 64 // Out-of-band data (NAND flash)
53 #define MTD_ECC 128 // Device capable of automatic ECC
55 // Some common devices / combinations of capabilities
56 #define MTD_CAP_ROM 0
57 #define MTD_CAP_RAM (MTD_CLEAR_BITS|MTD_SET_BITS|MTD_WRITEB_WRITEABLE)
58 #define MTD_CAP_NORFLASH (MTD_CLEAR_BITS|MTD_ERASEABLE)
59 #define MTD_CAP_NANDFLASH (MTD_CLEAR_BITS|MTD_ERASEABLE|MTD_OOB)
60 #define MTD_WRITEABLE (MTD_CLEAR_BITS|MTD_SET_BITS)
63 // Types of automatic ECC/Checksum available
64 #define MTD_ECC_NONE 0 // No automatic ECC available
65 #define MTD_ECC_RS_DiskOnChip 1 // Automatic ECC on DiskOnChip
66 #define MTD_ECC_SW 2 // SW ECC for Toshiba & Samsung devices
68 struct mtd_info_user {
69 u_char type;
70 u_long flags;
71 u_long size; // Total size of the MTD
72 u_long erasesize;
73 u_long oobblock; // Size of OOB blocks (e.g. 512)
74 u_long oobsize; // Amount of OOB data per block (e.g. 16)
75 u_long ecctype;
76 u_long eccsize;
79 #define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
80 #define MEMERASE _IOW('M', 2, struct erase_info_user)
81 #define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf)
82 #define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf)
83 #define MEMLOCK _IOW('M', 5, struct erase_info_user)
84 #define MEMUNLOCK _IOW('M', 6, struct erase_info_user)
86 #ifndef __KERNEL__
88 typedef struct mtd_info_user mtd_info_t;
89 typedef struct erase_info_user erase_info_t;
91 /* User-space ioctl definitions */
94 #else /* __KERNEL__ */
97 #define MTD_ERASE_PENDING 0x01
98 #define MTD_ERASING 0x02
99 #define MTD_ERASE_SUSPEND 0x04
100 #define MTD_ERASE_DONE 0x08
101 #define MTD_ERASE_FAILED 0x10
103 struct erase_info {
104 struct mtd_info *mtd;
105 u_long addr;
106 u_long len;
107 u_long time;
108 u_long retries;
109 u_int dev;
110 u_int cell;
111 void (*callback) (struct erase_info *self);
112 u_long priv;
113 u_char state;
114 struct erase_info *next;
118 struct mtd_info {
119 u_char type;
120 u_long flags;
121 u_long size; // Total size of the MTD
122 u_long erasesize;
123 u_long oobblock; // Size of OOB blocks (e.g. 512)
124 u_long oobsize; // Amount of OOB data per block (e.g. 16)
125 u_long ecctype;
126 u_long eccsize;
128 // Kernel-only stuff starts here.
129 char *name;
130 int index;
132 u_long bank_size;
134 struct module *module;
135 int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
137 /* This stuff for eXecute-In-Place */
138 int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
140 /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
141 void (*unpoint) (struct mtd_info *mtd, u_char * addr);
144 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
145 int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
147 int (*read_ecc) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, u_char *eccbuf);
148 int (*write_ecc) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf, u_char *eccbuf);
150 int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
151 int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
153 /* iovec-based read/write methods. We need these especially for NAND flash,
154 with its limited number of write cycles per erase.
155 NB: The 'count' parameter is the number of _vectors_, each of
156 which contains an (ofs, len) tuple.
158 int (*readv) (struct mtd_info *mtd, struct iovec *vecs, unsigned long count, loff_t from, size_t *retlen);
159 int (*writev) (struct mtd_info *mtd, const struct iovec *vecs, unsigned long count, loff_t to, size_t *retlen);
161 /* Sync */
162 void (*sync) (struct mtd_info *mtd);
164 /* Chip-supported device locking */
165 int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);
166 int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_t len);
168 /* Power Management functions */
169 int (*suspend) (struct mtd_info *mtd);
170 void (*resume) (struct mtd_info *mtd);
172 void *priv;
176 /* Kernel-side ioctl definitions */
178 extern int add_mtd_device(struct mtd_info *mtd);
179 extern int del_mtd_device (struct mtd_info *mtd);
181 extern struct mtd_info *__get_mtd_device(struct mtd_info *mtd, int num);
183 static inline struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
185 struct mtd_info *ret;
187 ret = __get_mtd_device(mtd, num);
189 if (ret && ret->module && !try_inc_mod_count(ret->module))
190 return NULL;
192 return ret;
195 static inline void put_mtd_device(struct mtd_info *mtd)
197 if (mtd->module)
198 __MOD_DEC_USE_COUNT(mtd->module);
202 struct mtd_notifier {
203 void (*add)(struct mtd_info *mtd);
204 void (*remove)(struct mtd_info *mtd);
205 struct mtd_notifier *next;
209 extern void register_mtd_user (struct mtd_notifier *new);
210 extern int unregister_mtd_user (struct mtd_notifier *old);
213 #ifndef MTDC
214 #define MTD_ERASE(mtd, args...) (*(mtd->erase))(mtd, args)
215 #define MTD_POINT(mtd, a,b,c,d) (*(mtd->point))(mtd, a,b,c, (u_char **)(d))
216 #define MTD_UNPOINT(mtd, arg) (*(mtd->unpoint))(mtd, (u_char *)arg)
217 #define MTD_READ(mtd, args...) (*(mtd->read))(mtd, args)
218 #define MTD_WRITE(mtd, args...) (*(mtd->write))(mtd, args)
219 #define MTD_READV(mtd, args...) (*(mtd->readv))(mtd, args)
220 #define MTD_WRITEV(mtd, args...) (*(mtd->writev))(mtd, args)
221 #define MTD_READECC(mtd, args...) (*(mtd->read_ecc))(mtd, args)
222 #define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args)
223 #define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args)
224 #define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args)
225 #define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd); } while (0)
226 #endif /* MTDC */
229 * Debugging macro and defines
231 #define MTD_DEBUG_LEVEL0 (0) /* Quiet */
232 #define MTD_DEBUG_LEVEL1 (1) /* Audible */
233 #define MTD_DEBUG_LEVEL2 (2) /* Loud */
234 #define MTD_DEBUG_LEVEL3 (3) /* Noisy */
236 #ifdef CONFIG_MTD_DEBUG
237 #define DEBUG(n, args...) \
238 if (n <= CONFIG_MTD_DEBUG_VERBOSE) { \
239 printk(KERN_INFO args); \
241 #else /* CONFIG_MTD_DEBUG */
242 #define DEBUG(n, args...)
243 #endif /* CONFIG_MTD_DEBUG */
245 #endif /* __KERNEL__ */
247 #endif /* __MTD_MTD_H__ */