mtd.h 18 KB

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