xref: /rk3399_rockchip-uboot/include/linux/mtd/mtd.h (revision 583deafe1bcb453d20d4f3c81cfcdd7a364ab305)
1 /*
2  * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> et al.
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  *
6  */
7 
8 #ifndef __MTD_MTD_H__
9 #define __MTD_MTD_H__
10 
11 #ifndef __UBOOT__
12 #include <linux/types.h>
13 #include <linux/uio.h>
14 #include <linux/notifier.h>
15 #include <linux/device.h>
16 
17 #include <mtd/mtd-abi.h>
18 
19 #include <asm/div64.h>
20 #else
21 #include <linux/compat.h>
22 #include <mtd/mtd-abi.h>
23 #include <linux/errno.h>
24 #include <linux/list.h>
25 #include <div64.h>
26 #if IS_ENABLED(CONFIG_DM)
27 #include <dm/device.h>
28 #endif
29 
30 #define MAX_MTD_DEVICES 32
31 #endif
32 
33 #define MTD_ERASE_PENDING	0x01
34 #define MTD_ERASING		0x02
35 #define MTD_ERASE_SUSPEND	0x04
36 #define MTD_ERASE_DONE		0x08
37 #define MTD_ERASE_FAILED	0x10
38 
39 #define MTD_FAIL_ADDR_UNKNOWN -1LL
40 
41 /*
42  * If the erase fails, fail_addr might indicate exactly which block failed. If
43  * fail_addr = MTD_FAIL_ADDR_UNKNOWN, the failure was not at the device level
44  * or was not specific to any particular block.
45  */
46 struct erase_info {
47 	struct mtd_info *mtd;
48 	uint64_t addr;
49 	uint64_t len;
50 	uint64_t fail_addr;
51 	u_long time;
52 	u_long retries;
53 	unsigned dev;
54 	unsigned cell;
55 	void (*callback) (struct erase_info *self);
56 	u_long priv;
57 	u_char state;
58 	struct erase_info *next;
59 	int scrub;
60 };
61 
62 struct mtd_erase_region_info {
63 	uint64_t offset;		/* At which this region starts, from the beginning of the MTD */
64 	uint32_t erasesize;		/* For this region */
65 	uint32_t numblocks;		/* Number of blocks of erasesize in this region */
66 	unsigned long *lockmap;		/* If keeping bitmap of locks */
67 };
68 
69 /**
70  * struct mtd_oob_ops - oob operation operands
71  * @mode:	operation mode
72  *
73  * @len:	number of data bytes to write/read
74  *
75  * @retlen:	number of data bytes written/read
76  *
77  * @ooblen:	number of oob bytes to write/read
78  * @oobretlen:	number of oob bytes written/read
79  * @ooboffs:	offset of oob data in the oob area (only relevant when
80  *		mode = MTD_OPS_PLACE_OOB or MTD_OPS_RAW)
81  * @datbuf:	data buffer - if NULL only oob data are read/written
82  * @oobbuf:	oob data buffer
83  *
84  * Note, it is allowed to read more than one OOB area at one go, but not write.
85  * The interface assumes that the OOB write requests program only one page's
86  * OOB area.
87  */
88 struct mtd_oob_ops {
89 	unsigned int	mode;
90 	size_t		len;
91 	size_t		retlen;
92 	size_t		ooblen;
93 	size_t		oobretlen;
94 	uint32_t	ooboffs;
95 	uint8_t		*datbuf;
96 	uint8_t		*oobbuf;
97 };
98 
99 #ifdef CONFIG_SYS_NAND_MAX_OOBFREE
100 #define MTD_MAX_OOBFREE_ENTRIES_LARGE	CONFIG_SYS_NAND_MAX_OOBFREE
101 #else
102 #define MTD_MAX_OOBFREE_ENTRIES_LARGE	32
103 #endif
104 
105 #ifdef CONFIG_SYS_NAND_MAX_ECCPOS
106 #define MTD_MAX_ECCPOS_ENTRIES_LARGE	CONFIG_SYS_NAND_MAX_ECCPOS
107 #else
108 #define MTD_MAX_ECCPOS_ENTRIES_LARGE	680
109 #endif
110 /**
111  * struct mtd_oob_region - oob region definition
112  * @offset: region offset
113  * @length: region length
114  *
115  * This structure describes a region of the OOB area, and is used
116  * to retrieve ECC or free bytes sections.
117  * Each section is defined by an offset within the OOB area and a
118  * length.
119  */
120 struct mtd_oob_region {
121 	u32 offset;
122 	u32 length;
123 };
124 
125 /*
126  * struct mtd_ooblayout_ops - NAND OOB layout operations
127  * @ecc: function returning an ECC region in the OOB area.
128  *	 Should return -ERANGE if %section exceeds the total number of
129  *	 ECC sections.
130  * @free: function returning a free region in the OOB area.
131  *	  Should return -ERANGE if %section exceeds the total number of
132  *	  free sections.
133  */
134 struct mtd_ooblayout_ops {
135 	int (*ecc)(struct mtd_info *mtd, int section,
136 		   struct mtd_oob_region *oobecc);
137 	int (*free)(struct mtd_info *mtd, int section,
138 		    struct mtd_oob_region *oobfree);
139 };
140 
141 /*
142  * Internal ECC layout control structure. For historical reasons, there is a
143  * similar, smaller struct nand_ecclayout_user (in mtd-abi.h) that is retained
144  * for export to user-space via the ECCGETLAYOUT ioctl.
145  * nand_ecclayout should be expandable in the future simply by the above macros.
146  */
147 struct nand_ecclayout {
148 	__u32 eccbytes;
149 	__u32 eccpos[MTD_MAX_ECCPOS_ENTRIES_LARGE];
150 	__u32 oobavail;
151 	struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES_LARGE];
152 };
153 
154 struct module;	/* only needed for owner field in mtd_info */
155 
156 struct mtd_info {
157 	u_char type;
158 	uint32_t flags;
159 	uint64_t size;	 // Total size of the MTD
160 
161 	/* "Major" erase size for the device. Naïve users may take this
162 	 * to be the only erase size available, or may use the more detailed
163 	 * information below if they desire
164 	 */
165 	uint32_t erasesize;
166 	/* Minimal writable flash unit size. In case of NOR flash it is 1 (even
167 	 * though individual bits can be cleared), in case of NAND flash it is
168 	 * one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
169 	 * it is of ECC block size, etc. It is illegal to have writesize = 0.
170 	 * Any driver registering a struct mtd_info must ensure a writesize of
171 	 * 1 or larger.
172 	 */
173 	uint32_t writesize;
174 
175 	/*
176 	 * Size of the write buffer used by the MTD. MTD devices having a write
177 	 * buffer can write multiple writesize chunks at a time. E.g. while
178 	 * writing 4 * writesize bytes to a device with 2 * writesize bytes
179 	 * buffer the MTD driver can (but doesn't have to) do 2 writesize
180 	 * operations, but not 4. Currently, all NANDs have writebufsize
181 	 * equivalent to writesize (NAND page size). Some NOR flashes do have
182 	 * writebufsize greater than writesize.
183 	 */
184 	uint32_t writebufsize;
185 
186 	uint32_t oobsize;   // Amount of OOB data per block (e.g. 16)
187 	uint32_t oobavail;  // Available OOB bytes per block
188 
189 	/*
190 	 * If erasesize is a power of 2 then the shift is stored in
191 	 * erasesize_shift otherwise erasesize_shift is zero. Ditto writesize.
192 	 */
193 	unsigned int erasesize_shift;
194 	unsigned int writesize_shift;
195 	/* Masks based on erasesize_shift and writesize_shift */
196 	unsigned int erasesize_mask;
197 	unsigned int writesize_mask;
198 
199 	/*
200 	 * read ops return -EUCLEAN if max number of bitflips corrected on any
201 	 * one region comprising an ecc step equals or exceeds this value.
202 	 * Settable by driver, else defaults to ecc_strength.  User can override
203 	 * in sysfs.  N.B. The meaning of the -EUCLEAN return code has changed;
204 	 * see Documentation/ABI/testing/sysfs-class-mtd for more detail.
205 	 */
206 	unsigned int bitflip_threshold;
207 
208 	// Kernel-only stuff starts here.
209 #ifndef __UBOOT__
210 	const char *name;
211 #else
212 	char *name;
213 #endif
214 	int index;
215 
216 	/* OOB layout description */
217 	const struct mtd_ooblayout_ops *ooblayout;
218 
219 	/* ECC layout structure pointer - read only! */
220 	struct nand_ecclayout *ecclayout;
221 
222 	/* the ecc step size. */
223 	unsigned int ecc_step_size;
224 
225 	/* max number of correctible bit errors per ecc step */
226 	unsigned int ecc_strength;
227 
228 	/* Data for variable erase regions. If numeraseregions is zero,
229 	 * it means that the whole device has erasesize as given above.
230 	 */
231 	int numeraseregions;
232 	struct mtd_erase_region_info *eraseregions;
233 
234 	/*
235 	 * Do not call via these pointers, use corresponding mtd_*()
236 	 * wrappers instead.
237 	 */
238 	int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
239 #ifndef __UBOOT__
240 	int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
241 		       size_t *retlen, void **virt, resource_size_t *phys);
242 	int (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
243 #endif
244 	unsigned long (*_get_unmapped_area) (struct mtd_info *mtd,
245 					     unsigned long len,
246 					     unsigned long offset,
247 					     unsigned long flags);
248 	int (*_read) (struct mtd_info *mtd, loff_t from, size_t len,
249 		      size_t *retlen, u_char *buf);
250 	int (*_write) (struct mtd_info *mtd, loff_t to, size_t len,
251 		       size_t *retlen, const u_char *buf);
252 	int (*_panic_write) (struct mtd_info *mtd, loff_t to, size_t len,
253 			     size_t *retlen, const u_char *buf);
254 	int (*_read_oob) (struct mtd_info *mtd, loff_t from,
255 			  struct mtd_oob_ops *ops);
256 	int (*_write_oob) (struct mtd_info *mtd, loff_t to,
257 			   struct mtd_oob_ops *ops);
258 	int (*_get_fact_prot_info) (struct mtd_info *mtd, size_t len,
259 				    size_t *retlen, struct otp_info *buf);
260 	int (*_read_fact_prot_reg) (struct mtd_info *mtd, loff_t from,
261 				    size_t len, size_t *retlen, u_char *buf);
262 	int (*_get_user_prot_info) (struct mtd_info *mtd, size_t len,
263 				    size_t *retlen, struct otp_info *buf);
264 	int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from,
265 				    size_t len, size_t *retlen, u_char *buf);
266 	int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to,
267 				     size_t len, size_t *retlen, u_char *buf);
268 	int (*_lock_user_prot_reg) (struct mtd_info *mtd, loff_t from,
269 				    size_t len);
270 #ifndef __UBOOT__
271 	int (*_writev) (struct mtd_info *mtd, const struct kvec *vecs,
272 			unsigned long count, loff_t to, size_t *retlen);
273 #endif
274 	void (*_sync) (struct mtd_info *mtd);
275 	int (*_lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
276 	int (*_unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
277 	int (*_is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
278 	int (*_block_isreserved) (struct mtd_info *mtd, loff_t ofs);
279 	int (*_block_isbad) (struct mtd_info *mtd, loff_t ofs);
280 	int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs);
281 #ifndef __UBOOT__
282 	int (*_suspend) (struct mtd_info *mtd);
283 	void (*_resume) (struct mtd_info *mtd);
284 	void (*_reboot) (struct mtd_info *mtd);
285 #endif
286 	/*
287 	 * If the driver is something smart, like UBI, it may need to maintain
288 	 * its own reference counting. The below functions are only for driver.
289 	 */
290 	int (*_get_device) (struct mtd_info *mtd);
291 	void (*_put_device) (struct mtd_info *mtd);
292 
293 #ifndef __UBOOT__
294 	/* Backing device capabilities for this device
295 	 * - provides mmap capabilities
296 	 */
297 	struct backing_dev_info *backing_dev_info;
298 
299 	struct notifier_block reboot_notifier;  /* default mode before reboot */
300 #endif
301 
302 	/* ECC status information */
303 	struct mtd_ecc_stats ecc_stats;
304 	/* Subpage shift (NAND) */
305 	int subpage_sft;
306 
307 	void *priv;
308 
309 	struct module *owner;
310 #ifndef __UBOOT__
311 	struct device dev;
312 #else
313 	struct udevice *dev;
314 #endif
315 	int usecount;
316 
317 	/* MTD devices do not have any parent. MTD partitions do. */
318 	struct mtd_info *parent;
319 
320 	/*
321 	 * Offset of the partition relatively to the parent offset.
322 	 * Is 0 for real MTD devices (ie. not partitions).
323 	 */
324 	u64 offset;
325 
326 	/*
327 	 * List node used to add an MTD partition to the parent
328 	 * partition list.
329 	 */
330 	struct list_head node;
331 
332 	/*
333 	 * List of partitions attached to this MTD device (the parent
334 	 * MTD device can itself be a partition).
335 	 */
336 	struct list_head partitions;
337 };
338 
339 #if IS_ENABLED(CONFIG_DM)
340 static inline void mtd_set_of_node(struct mtd_info *mtd,
341 				   const struct device_node *np)
342 {
343 	mtd->dev->node.np = np;
344 }
345 
346 static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd)
347 {
348 	return mtd->dev->node.np;
349 }
350 #else
351 struct device_node;
352 
353 static inline void mtd_set_of_node(struct mtd_info *mtd,
354 				   const struct device_node *np)
355 {
356 }
357 
358 static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd)
359 {
360 	return NULL;
361 }
362 #endif
363 
364 static inline bool mtd_is_partition(const struct mtd_info *mtd)
365 {
366 	return mtd->parent;
367 }
368 
369 static inline bool mtd_has_partitions(const struct mtd_info *mtd)
370 {
371 	return !list_empty(&mtd->partitions);
372 }
373 
374 int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
375 		      struct mtd_oob_region *oobecc);
376 int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
377 				 int *section,
378 				 struct mtd_oob_region *oobregion);
379 int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
380 			       const u8 *oobbuf, int start, int nbytes);
381 int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
382 			       u8 *oobbuf, int start, int nbytes);
383 int mtd_ooblayout_free(struct mtd_info *mtd, int section,
384 		       struct mtd_oob_region *oobfree);
385 int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
386 				const u8 *oobbuf, int start, int nbytes);
387 int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
388 				u8 *oobbuf, int start, int nbytes);
389 int mtd_ooblayout_count_freebytes(struct mtd_info *mtd);
390 int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd);
391 
392 static inline void mtd_set_ooblayout(struct mtd_info *mtd,
393 				     const struct mtd_ooblayout_ops *ooblayout)
394 {
395 	mtd->ooblayout = ooblayout;
396 }
397 
398 static inline int mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops)
399 {
400 	return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;
401 }
402 
403 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
404 #ifndef __UBOOT__
405 int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
406 	      void **virt, resource_size_t *phys);
407 int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
408 #endif
409 unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
410 				    unsigned long offset, unsigned long flags);
411 int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
412 	     u_char *buf);
413 int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
414 	      const u_char *buf);
415 int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
416 		    const u_char *buf);
417 
418 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
419 int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
420 
421 int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
422 			   struct otp_info *buf);
423 int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
424 			   size_t *retlen, u_char *buf);
425 int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
426 			   struct otp_info *buf);
427 int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
428 			   size_t *retlen, u_char *buf);
429 int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
430 			    size_t *retlen, u_char *buf);
431 int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
432 
433 #ifndef __UBOOT__
434 int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
435 	       unsigned long count, loff_t to, size_t *retlen);
436 #endif
437 
438 static inline void mtd_sync(struct mtd_info *mtd)
439 {
440 	if (mtd->_sync)
441 		mtd->_sync(mtd);
442 }
443 
444 int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
445 int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
446 int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len);
447 int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs);
448 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs);
449 int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs);
450 
451 #ifndef __UBOOT__
452 static inline int mtd_suspend(struct mtd_info *mtd)
453 {
454 	return mtd->_suspend ? mtd->_suspend(mtd) : 0;
455 }
456 
457 static inline void mtd_resume(struct mtd_info *mtd)
458 {
459 	if (mtd->_resume)
460 		mtd->_resume(mtd);
461 }
462 #endif
463 
464 static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
465 {
466 	if (mtd->erasesize_shift)
467 		return sz >> mtd->erasesize_shift;
468 	do_div(sz, mtd->erasesize);
469 	return sz;
470 }
471 
472 static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
473 {
474 	if (mtd->erasesize_shift)
475 		return sz & mtd->erasesize_mask;
476 	return do_div(sz, mtd->erasesize);
477 }
478 
479 static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
480 {
481 	if (mtd->writesize_shift)
482 		return sz >> mtd->writesize_shift;
483 	do_div(sz, mtd->writesize);
484 	return sz;
485 }
486 
487 static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)
488 {
489 	if (mtd->writesize_shift)
490 		return sz & mtd->writesize_mask;
491 	return do_div(sz, mtd->writesize);
492 }
493 
494 static inline int mtd_has_oob(const struct mtd_info *mtd)
495 {
496 	return mtd->_read_oob && mtd->_write_oob;
497 }
498 
499 static inline int mtd_type_is_nand(const struct mtd_info *mtd)
500 {
501 	return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
502 }
503 
504 static inline int mtd_can_have_bb(const struct mtd_info *mtd)
505 {
506 	return !!mtd->_block_isbad;
507 }
508 
509 	/* Kernel-side ioctl definitions */
510 
511 struct mtd_partition;
512 struct mtd_part_parser_data;
513 
514 extern int mtd_device_parse_register(struct mtd_info *mtd,
515 				     const char * const *part_probe_types,
516 				     struct mtd_part_parser_data *parser_data,
517 				     const struct mtd_partition *defparts,
518 				     int defnr_parts);
519 #define mtd_device_register(master, parts, nr_parts)	\
520 	mtd_device_parse_register(master, NULL, NULL, parts, nr_parts)
521 extern int mtd_device_unregister(struct mtd_info *master);
522 extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
523 extern int __get_mtd_device(struct mtd_info *mtd);
524 extern void __put_mtd_device(struct mtd_info *mtd);
525 extern struct mtd_info *get_mtd_device_nm(const char *name);
526 extern void put_mtd_device(struct mtd_info *mtd);
527 
528 
529 #ifndef __UBOOT__
530 struct mtd_notifier {
531 	void (*add)(struct mtd_info *mtd);
532 	void (*remove)(struct mtd_info *mtd);
533 	struct list_head list;
534 };
535 
536 
537 extern void register_mtd_user (struct mtd_notifier *new);
538 extern int unregister_mtd_user (struct mtd_notifier *old);
539 #endif
540 void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
541 
542 #ifdef CONFIG_MTD_PARTITIONS
543 void mtd_erase_callback(struct erase_info *instr);
544 #else
545 static inline void mtd_erase_callback(struct erase_info *instr)
546 {
547 	if (instr->callback)
548 		instr->callback(instr);
549 }
550 #endif
551 
552 #ifdef __UBOOT__
553 /*
554  * Debugging macro and defines
555  */
556 #define MTD_DEBUG_LEVEL0	(0)	/* Quiet   */
557 #define MTD_DEBUG_LEVEL1	(1)	/* Audible */
558 #define MTD_DEBUG_LEVEL2	(2)	/* Loud    */
559 #define MTD_DEBUG_LEVEL3	(3)	/* Noisy   */
560 
561 #ifdef CONFIG_MTD_DEBUG
562 #define MTDDEBUG(n, args...)				\
563 	do {						\
564 		if (n <= CONFIG_MTD_DEBUG_VERBOSE)	\
565 			printk(KERN_INFO args);		\
566 	} while(0)
567 #else /* CONFIG_MTD_DEBUG */
568 #define MTDDEBUG(n, args...)				\
569 	do {						\
570 		if (0)					\
571 			printk(KERN_INFO args);		\
572 	} while(0)
573 #endif /* CONFIG_MTD_DEBUG */
574 #endif
575 
576 static inline int mtd_is_bitflip(int err) {
577 	return err == -EUCLEAN;
578 }
579 
580 static inline int mtd_is_eccerr(int err) {
581 	return err == -EBADMSG;
582 }
583 
584 static inline int mtd_is_bitflip_or_eccerr(int err) {
585 	return mtd_is_bitflip(err) || mtd_is_eccerr(err);
586 }
587 
588 unsigned mtd_mmap_capabilities(struct mtd_info *mtd);
589 
590 #ifdef __UBOOT__
591 /* drivers/mtd/mtdcore.h */
592 int add_mtd_device(struct mtd_info *mtd);
593 int del_mtd_device(struct mtd_info *mtd);
594 int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
595 int del_mtd_partitions(struct mtd_info *);
596 
597 struct mtd_info *__mtd_next_device(int i);
598 #define mtd_for_each_device(mtd)			\
599 	for ((mtd) = __mtd_next_device(0);		\
600 	     (mtd) != NULL;				\
601 	     (mtd) = __mtd_next_device(mtd->index + 1))
602 
603 int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
604 		loff_t *maxsize, int devtype, uint64_t chipsize);
605 int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
606 		     loff_t *size, loff_t *maxsize, int devtype,
607 		     uint64_t chipsize);
608 
609 /* drivers/mtd/mtdcore.c */
610 void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
611 			  const uint64_t length, uint64_t *len_incl_bad,
612 			  int *truncated);
613 
614 /* drivers/mtd/mtd_uboot.c */
615 int mtd_search_alternate_name(const char *mtdname, char *altname,
616 			      unsigned int max_len);
617 
618 #endif
619 #endif /* __MTD_MTD_H__ */
620