]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/slutils/slutils-0.1.0/sltime/mtduser.h
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / slutils / slutils-0.1.0 / sltime / mtduser.h
1
2 /* $Id: mtd.h,v 1.35 2002/08/29 21:41:42 gleixner Exp $ */
3
4 /*
5  * ChangeLog:
6  *     19-Sep-2002 Lineo Japan, Inc.  add erase-by-force mode
7  *
8  */
9
10 /*
11  * ChangeLog:
12  *     19-Sep-2002 Lineo Japan, Inc.  add erase-by-force mode
13  *     23-Oct-2002 SHARP  add definitions for CONFIG_MTD_NAND_LOGICAL_ADDRESS_ACCESS
14  *
15  */
16
17 #ifndef __MTD_MTD_H__
18 #define __MTD_MTD_H__
19
20 #ifdef __KERNEL__
21
22 #include <linux/config.h>
23 #include <linux/version.h>
24 #include <linux/types.h>
25 #include <linux/mtd/compatmac.h>
26 #include <linux/module.h>
27 #include <linux/uio.h>
28
29 #endif /* __KERNEL__ */
30
31 struct erase_info_user {
32         u_int32_t start;
33         u_int32_t length;
34 };
35
36 struct mtd_oob_buf {
37         u_int32_t start;
38         u_int32_t length;
39         unsigned char *ptr;
40 };
41
42
43 #define MTD_CHAR_MAJOR 90
44 #define MTD_BLOCK_MAJOR 31
45 #define MAX_MTD_DEVICES 16
46
47
48
49 #define MTD_ABSENT              0
50 #define MTD_RAM                 1
51 #define MTD_ROM                 2
52 #define MTD_NORFLASH            3
53 #define MTD_NANDFLASH           4
54 #define MTD_PEROM               5
55 #define MTD_OTHER               14
56 #define MTD_UNKNOWN             15
57
58
59
60 #define MTD_CLEAR_BITS          1       // Bits can be cleared (flash)
61 #define MTD_SET_BITS            2       // Bits can be set
62 #define MTD_ERASEABLE           4       // Has an erase function
63 #define MTD_WRITEB_WRITEABLE    8       // Direct IO is possible
64 #define MTD_VOLATILE            16      // Set for RAMs
65 #define MTD_XIP                 32      // eXecute-In-Place possible
66 #define MTD_OOB                 64      // Out-of-band data (NAND flash)
67 #define MTD_ECC                 128     // Device capable of automatic ECC
68
69 // Some common devices / combinations of capabilities
70 #define MTD_CAP_ROM             0
71 #define MTD_CAP_RAM             (MTD_CLEAR_BITS|MTD_SET_BITS|MTD_WRITEB_WRITEABLE)
72 #define MTD_CAP_NORFLASH        (MTD_CLEAR_BITS|MTD_ERASEABLE)
73 #define MTD_CAP_NANDFLASH       (MTD_CLEAR_BITS|MTD_ERASEABLE|MTD_OOB)
74 #define MTD_WRITEABLE           (MTD_CLEAR_BITS|MTD_SET_BITS)
75
76
77 // Types of automatic ECC/Checksum available
78 #define MTD_ECC_NONE            0       // No automatic ECC available
79 #define MTD_ECC_RS_DiskOnChip   1       // Automatic ECC on DiskOnChip
80 #define MTD_ECC_SW              2       // SW ECC for Toshiba & Samsung devices
81
82 struct mtd_info_user {
83         u_char type;
84         u_int32_t flags;
85         u_int32_t size;  // Total size of the MTD
86         u_int32_t erasesize;
87         u_int32_t oobblock;  // Size of OOB blocks (e.g. 512)
88         u_int32_t oobsize;   // Amount of OOB data per block (e.g. 16)
89         u_int32_t ecctype;
90         u_int32_t eccsize;
91 };
92
93 struct region_info_user {
94         u_int32_t offset;               /* At which this region starts, 
95                                          * from the beginning of the MTD */
96         u_int32_t erasesize;            /* For this region */
97         u_int32_t numblocks;            /* Number of blocks in this region */
98         u_int32_t regionindex;
99 };
100
101 #ifdef CONFIG_MTD_NAND_LOGICAL_ADDRESS_ACCESS
102 struct read_laddr_info_user {
103         loff_t from;
104         size_t len;
105         u_char* buf;
106 };
107
108 struct write_laddr_info_user {
109         loff_t to;
110         size_t len;
111         u_char* buf;
112 };    
113 #endif
114
115 #define MEMGETINFO              _IOR('M', 1, struct mtd_info_user)
116 #define MEMERASE                _IOW('M', 2, struct erase_info_user)
117 #define MEMWRITEOOB             _IOWR('M', 3, struct mtd_oob_buf)
118 #define MEMREADOOB              _IOWR('M', 4, struct mtd_oob_buf)
119 #define MEMLOCK                 _IOW('M', 5, struct erase_info_user)
120 #define MEMUNLOCK               _IOW('M', 6, struct erase_info_user)
121 #define MEMGETREGIONCOUNT       _IOR('M', 7, int)
122 #define MEMGETREGIONINFO        _IOWR('M', 8, struct region_info_user)
123 #ifdef CONFIG_MTD_NAND_ERASE_BY_FORCE
124 #define MEMERASEBYFORCE         _IOW('M', 9, struct erase_info_user)
125 #else
126 #define MEMIOCTLRSV9            _IO('M', 9)
127 #endif
128 #ifdef CONFIG_MTD_NAND_LOGICAL_ADDRESS_ACCESS
129 #define MEMCLEANUPLADDR         _IO('M', 10)
130 #define MEMREADLADDR            _IOR('M', 11, struct read_laddr_info_user)
131 #define MEMWRITELADDR           _IOW('M', 12, struct write_laddr_info_user)
132 #else
133 #define MEMIOCTLRSV10           _IO('M', 10)
134 #define MEMIOCTLRSV11           _IO('M', 11)
135 #define MEMIOCTLRSV12           _IO('M', 12)
136 #endif
137
138 #ifndef __KERNEL__
139
140 typedef struct mtd_info_user mtd_info_t;
141 typedef struct erase_info_user erase_info_t;
142 typedef struct region_info_user region_info_t;
143
144         /* User-space ioctl definitions */
145
146
147 #else /* __KERNEL__ */
148
149
150 #define MTD_ERASE_PENDING       0x01
151 #define MTD_ERASING             0x02
152 #define MTD_ERASE_SUSPEND       0x04
153 #define MTD_ERASE_DONE          0x08
154 #define MTD_ERASE_FAILED        0x10
155
156 struct erase_info {
157         struct mtd_info *mtd;
158         u_int32_t addr;
159         u_int32_t len;
160         u_long time;
161         u_long retries;
162         u_int dev;
163         u_int cell;
164         void (*callback) (struct erase_info *self);
165         u_long priv;
166         u_char state;
167         struct erase_info *next;
168 #ifdef CONFIG_MTD_NAND_ERASE_BY_FORCE
169         int by_force;
170 #endif
171 };
172
173 struct mtd_erase_region_info {
174         u_int32_t offset;                       /* At which this region starts, from the beginning of the MTD */
175         u_int32_t erasesize;            /* For this region */
176         u_int32_t numblocks;            /* Number of blocks of erasesize in this region */
177 };
178
179 struct mtd_info {
180         u_char type;
181         u_int32_t flags;
182         u_int32_t size;  // Total size of the MTD
183
184         /* "Major" erase size for the device. Naïve users may take this
185          * to be the only erase size available, or may use the more detailed
186          * information below if they desire
187          */
188         u_int32_t erasesize;
189
190         u_int32_t oobblock;  // Size of OOB blocks (e.g. 512)
191         u_int32_t oobsize;   // Amount of OOB data per block (e.g. 16)
192         u_int32_t ecctype;
193         u_int32_t eccsize;
194
195         // Kernel-only stuff starts here.
196         char *name;
197         int index;
198
199         /* Data for variable erase regions. If numeraseregions is zero,
200          * it means that the whole device has erasesize as given above. 
201          */
202         int numeraseregions;
203         struct mtd_erase_region_info *eraseregions; 
204
205         /* This really shouldn't be here. It can go away in 2.5 */
206         u_int32_t bank_size;
207
208         struct module *module;
209         int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
210
211         /* This stuff for eXecute-In-Place */
212         int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
213
214         /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
215         void (*unpoint) (struct mtd_info *mtd, u_char * addr);
216
217
218         int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
219         int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
220
221         int (*read_ecc) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, u_char *eccbuf, int oobsel);
222         int (*write_ecc) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf, u_char *eccbuf, int oobsel);
223
224         int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
225         int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
226
227         /* 
228          * Methods to access the protection register area, present in some 
229          * flash devices. The user data is one time programmable but the
230          * factory data is read only. 
231          */
232         int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
233
234         int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
235
236         /* This function is not yet implemented */
237         int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
238
239         /* iovec-based read/write methods. We need these especially for NAND flash,
240            with its limited number of write cycles per erase.
241            NB: The 'count' parameter is the number of _vectors_, each of 
242            which contains an (ofs, len) tuple.
243         */
244         int (*readv) (struct mtd_info *mtd, struct iovec *vecs, unsigned long count, loff_t from, size_t *retlen);
245         int (*readv_ecc) (struct mtd_info *mtd, struct iovec *vecs, unsigned long count, loff_t from, 
246                 size_t *retlen, u_char *eccbuf, int oobsel);
247         int (*writev) (struct mtd_info *mtd, const struct iovec *vecs, unsigned long count, loff_t to, size_t *retlen);
248         int (*writev_ecc) (struct mtd_info *mtd, const struct iovec *vecs, unsigned long count, loff_t to, 
249                 size_t *retlen, u_char *eccbuf, int oobsel);
250
251         /* Sync */
252         void (*sync) (struct mtd_info *mtd);
253
254         /* Chip-supported device locking */
255         int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);
256         int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_t len);
257
258         /* Power Management functions */
259         int (*suspend) (struct mtd_info *mtd);
260         void (*resume) (struct mtd_info *mtd);
261
262 #ifdef CONFIG_MTD_NAND_LOGICAL_ADDRESS_ACCESS
263         /* Logical Address Access functions */
264         int (*cleanup_laddr)(struct mtd_info *mtd);
265         int (*read_laddr)(struct mtd_info *mtd, loff_t from, size_t len, u_char *buf);
266         int (*write_laddr)(struct mtd_info *mtd, loff_t to, size_t len, u_char *buf, int (*eraseproc)(struct mtd_info *mtd, u_int32_t addr));
267 #endif
268
269         void *priv;
270 };
271
272
273         /* Kernel-side ioctl definitions */
274
275 extern int add_mtd_device(struct mtd_info *mtd);
276 extern int del_mtd_device (struct mtd_info *mtd);
277
278 extern struct mtd_info *__get_mtd_device(struct mtd_info *mtd, int num);
279
280 static inline struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
281 {
282         struct mtd_info *ret;
283         
284         ret = __get_mtd_device(mtd, num);
285
286         if (ret && ret->module && !try_inc_mod_count(ret->module))
287                 return NULL;
288
289         return ret;
290 }
291
292 static inline void put_mtd_device(struct mtd_info *mtd)
293 {
294        if (mtd->module)
295                __MOD_DEC_USE_COUNT(mtd->module);
296 }
297
298
299 struct mtd_notifier {
300         void (*add)(struct mtd_info *mtd);
301         void (*remove)(struct mtd_info *mtd);
302         struct mtd_notifier *next;
303 };
304
305
306 extern void register_mtd_user (struct mtd_notifier *new);
307 extern int unregister_mtd_user (struct mtd_notifier *old);
308
309
310 #ifndef MTDC
311 #define MTD_ERASE(mtd, args...) (*(mtd->erase))(mtd, args)
312 #define MTD_POINT(mtd, a,b,c,d) (*(mtd->point))(mtd, a,b,c, (u_char **)(d))
313 #define MTD_UNPOINT(mtd, arg) (*(mtd->unpoint))(mtd, (u_char *)arg)
314 #define MTD_READ(mtd, args...) (*(mtd->read))(mtd, args)
315 #define MTD_WRITE(mtd, args...) (*(mtd->write))(mtd, args)
316 #define MTD_READV(mtd, args...) (*(mtd->readv))(mtd, args)
317 #define MTD_WRITEV(mtd, args...) (*(mtd->writev))(mtd, args)
318 #define MTD_READECC(mtd, args...) (*(mtd->read_ecc))(mtd, args)
319 #define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args)
320 #define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args)
321 #define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args)
322 #define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd);  } while (0) 
323 #endif /* MTDC */
324
325 /*
326  * Debugging macro and defines
327  */
328 #define MTD_DEBUG_LEVEL0        (0)     /* Quiet   */
329 #define MTD_DEBUG_LEVEL1        (1)     /* Audible */
330 #define MTD_DEBUG_LEVEL2        (2)     /* Loud    */
331 #define MTD_DEBUG_LEVEL3        (3)     /* Noisy   */
332
333 #ifdef CONFIG_MTD_DEBUG
334 #define DEBUG(n, args...)                       \
335         if (n <=  CONFIG_MTD_DEBUG_VERBOSE) {   \
336                 printk(KERN_INFO args); \
337         }
338 #else /* CONFIG_MTD_DEBUG */
339 #define DEBUG(n, args...)
340 #endif /* CONFIG_MTD_DEBUG */
341
342 #endif /* __KERNEL__ */
343
344 #endif /* __MTD_MTD_H__ */