mtd.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /*
  2. * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> et al.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. *
  18. */
  19. #ifndef __MTD_MTD_H__
  20. #define __MTD_MTD_H__
  21. #include <linux/types.h>
  22. #include <linux/uio.h>
  23. #include <linux/notifier.h>
  24. #include <linux/device.h>
  25. #include <mtd/mtd-abi.h>
  26. #include <asm/div64.h>
  27. #define MTD_ERASE_PENDING 0x01
  28. #define MTD_ERASING 0x02
  29. #define MTD_ERASE_SUSPEND 0x04
  30. #define MTD_ERASE_DONE 0x08
  31. #define MTD_ERASE_FAILED 0x10
  32. #define MTD_FAIL_ADDR_UNKNOWN -1LL
  33. /*
  34. * If the erase fails, fail_addr might indicate exactly which block failed. If
  35. * fail_addr = MTD_FAIL_ADDR_UNKNOWN, the failure was not at the device level
  36. * or was not specific to any particular block.
  37. */
  38. struct erase_info {
  39. struct mtd_info *mtd;
  40. uint64_t addr;
  41. uint64_t len;
  42. uint64_t fail_addr;
  43. u_long time;
  44. u_long retries;
  45. unsigned dev;
  46. unsigned cell;
  47. void (*callback) (struct erase_info *self);
  48. u_long priv;
  49. u_char state;
  50. struct erase_info *next;
  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. * Note, it is allowed to read more than one OOB area at one go, but not write.
  74. * The interface assumes that the OOB write requests program only one page's
  75. * OOB area.
  76. */
  77. struct mtd_oob_ops {
  78. unsigned int mode;
  79. size_t len;
  80. size_t retlen;
  81. size_t ooblen;
  82. size_t oobretlen;
  83. uint32_t ooboffs;
  84. uint8_t *datbuf;
  85. uint8_t *oobbuf;
  86. };
  87. #define MTD_MAX_OOBFREE_ENTRIES_LARGE 32
  88. #define MTD_MAX_ECCPOS_ENTRIES_LARGE 640
  89. /**
  90. * struct mtd_oob_region - oob region definition
  91. * @offset: region offset
  92. * @length: region length
  93. *
  94. * This structure describes a region of the OOB area, and is used
  95. * to retrieve ECC or free bytes sections.
  96. * Each section is defined by an offset within the OOB area and a
  97. * length.
  98. */
  99. struct mtd_oob_region {
  100. u32 offset;
  101. u32 length;
  102. };
  103. /*
  104. * struct mtd_ooblayout_ops - NAND OOB layout operations
  105. * @ecc: function returning an ECC region in the OOB area.
  106. * Should return -ERANGE if %section exceeds the total number of
  107. * ECC sections.
  108. * @free: function returning a free region in the OOB area.
  109. * Should return -ERANGE if %section exceeds the total number of
  110. * free sections.
  111. */
  112. struct mtd_ooblayout_ops {
  113. int (*ecc)(struct mtd_info *mtd, int section,
  114. struct mtd_oob_region *oobecc);
  115. int (*free)(struct mtd_info *mtd, int section,
  116. struct mtd_oob_region *oobfree);
  117. };
  118. /**
  119. * struct mtd_pairing_info - page pairing information
  120. *
  121. * @pair: pair id
  122. * @group: group id
  123. *
  124. * The term "pair" is used here, even though TLC NANDs might group pages by 3
  125. * (3 bits in a single cell). A pair should regroup all pages that are sharing
  126. * the same cell. Pairs are then indexed in ascending order.
  127. *
  128. * @group is defining the position of a page in a given pair. It can also be
  129. * seen as the bit position in the cell: page attached to bit 0 belongs to
  130. * group 0, page attached to bit 1 belongs to group 1, etc.
  131. *
  132. * Example:
  133. * The H27UCG8T2BTR-BC datasheet describes the following pairing scheme:
  134. *
  135. * group-0 group-1
  136. *
  137. * pair-0 page-0 page-4
  138. * pair-1 page-1 page-5
  139. * pair-2 page-2 page-8
  140. * ...
  141. * pair-127 page-251 page-255
  142. *
  143. *
  144. * Note that the "group" and "pair" terms were extracted from Samsung and
  145. * Hynix datasheets, and might be referenced under other names in other
  146. * datasheets (Micron is describing this concept as "shared pages").
  147. */
  148. struct mtd_pairing_info {
  149. int pair;
  150. int group;
  151. };
  152. /**
  153. * struct mtd_pairing_scheme - page pairing scheme description
  154. *
  155. * @ngroups: number of groups. Should be related to the number of bits
  156. * per cell.
  157. * @get_info: converts a write-unit (page number within an erase block) into
  158. * mtd_pairing information (pair + group). This function should
  159. * fill the info parameter based on the wunit index or return
  160. * -EINVAL if the wunit parameter is invalid.
  161. * @get_wunit: converts pairing information into a write-unit (page) number.
  162. * This function should return the wunit index pointed by the
  163. * pairing information described in the info argument. It should
  164. * return -EINVAL, if there's no wunit corresponding to the
  165. * passed pairing information.
  166. *
  167. * See mtd_pairing_info documentation for a detailed explanation of the
  168. * pair and group concepts.
  169. *
  170. * The mtd_pairing_scheme structure provides a generic solution to represent
  171. * NAND page pairing scheme. Instead of exposing two big tables to do the
  172. * write-unit <-> (pair + group) conversions, we ask the MTD drivers to
  173. * implement the ->get_info() and ->get_wunit() functions.
  174. *
  175. * MTD users will then be able to query these information by using the
  176. * mtd_pairing_info_to_wunit() and mtd_wunit_to_pairing_info() helpers.
  177. *
  178. * @ngroups is here to help MTD users iterating over all the pages in a
  179. * given pair. This value can be retrieved by MTD users using the
  180. * mtd_pairing_groups() helper.
  181. *
  182. * Examples are given in the mtd_pairing_info_to_wunit() and
  183. * mtd_wunit_to_pairing_info() documentation.
  184. */
  185. struct mtd_pairing_scheme {
  186. int ngroups;
  187. int (*get_info)(struct mtd_info *mtd, int wunit,
  188. struct mtd_pairing_info *info);
  189. int (*get_wunit)(struct mtd_info *mtd,
  190. const struct mtd_pairing_info *info);
  191. };
  192. struct module; /* only needed for owner field in mtd_info */
  193. struct mtd_info {
  194. u_char type;
  195. uint32_t flags;
  196. uint64_t size; // Total size of the MTD
  197. /* "Major" erase size for the device. Naïve users may take this
  198. * to be the only erase size available, or may use the more detailed
  199. * information below if they desire
  200. */
  201. uint32_t erasesize;
  202. /* Minimal writable flash unit size. In case of NOR flash it is 1 (even
  203. * though individual bits can be cleared), in case of NAND flash it is
  204. * one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
  205. * it is of ECC block size, etc. It is illegal to have writesize = 0.
  206. * Any driver registering a struct mtd_info must ensure a writesize of
  207. * 1 or larger.
  208. */
  209. uint32_t writesize;
  210. /*
  211. * Size of the write buffer used by the MTD. MTD devices having a write
  212. * buffer can write multiple writesize chunks at a time. E.g. while
  213. * writing 4 * writesize bytes to a device with 2 * writesize bytes
  214. * buffer the MTD driver can (but doesn't have to) do 2 writesize
  215. * operations, but not 4. Currently, all NANDs have writebufsize
  216. * equivalent to writesize (NAND page size). Some NOR flashes do have
  217. * writebufsize greater than writesize.
  218. */
  219. uint32_t writebufsize;
  220. uint32_t oobsize; // Amount of OOB data per block (e.g. 16)
  221. uint32_t oobavail; // Available OOB bytes per block
  222. /*
  223. * If erasesize is a power of 2 then the shift is stored in
  224. * erasesize_shift otherwise erasesize_shift is zero. Ditto writesize.
  225. */
  226. unsigned int erasesize_shift;
  227. unsigned int writesize_shift;
  228. /* Masks based on erasesize_shift and writesize_shift */
  229. unsigned int erasesize_mask;
  230. unsigned int writesize_mask;
  231. /*
  232. * read ops return -EUCLEAN if max number of bitflips corrected on any
  233. * one region comprising an ecc step equals or exceeds this value.
  234. * Settable by driver, else defaults to ecc_strength. User can override
  235. * in sysfs. N.B. The meaning of the -EUCLEAN return code has changed;
  236. * see Documentation/ABI/testing/sysfs-class-mtd for more detail.
  237. */
  238. unsigned int bitflip_threshold;
  239. // Kernel-only stuff starts here.
  240. const char *name;
  241. int index;
  242. /* OOB layout description */
  243. const struct mtd_ooblayout_ops *ooblayout;
  244. /* NAND pairing scheme, only provided for MLC/TLC NANDs */
  245. const struct mtd_pairing_scheme *pairing;
  246. /* the ecc step size. */
  247. unsigned int ecc_step_size;
  248. /* max number of correctible bit errors per ecc step */
  249. unsigned int ecc_strength;
  250. /* Data for variable erase regions. If numeraseregions is zero,
  251. * it means that the whole device has erasesize as given above.
  252. */
  253. int numeraseregions;
  254. struct mtd_erase_region_info *eraseregions;
  255. /*
  256. * Do not call via these pointers, use corresponding mtd_*()
  257. * wrappers instead.
  258. */
  259. int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
  260. int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
  261. size_t *retlen, void **virt, resource_size_t *phys);
  262. int (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
  263. unsigned long (*_get_unmapped_area) (struct mtd_info *mtd,
  264. unsigned long len,
  265. unsigned long offset,
  266. unsigned long flags);
  267. int (*_read) (struct mtd_info *mtd, loff_t from, size_t len,
  268. size_t *retlen, u_char *buf);
  269. int (*_write) (struct mtd_info *mtd, loff_t to, size_t len,
  270. size_t *retlen, const u_char *buf);
  271. int (*_panic_write) (struct mtd_info *mtd, loff_t to, size_t len,
  272. size_t *retlen, const u_char *buf);
  273. int (*_read_oob) (struct mtd_info *mtd, loff_t from,
  274. struct mtd_oob_ops *ops);
  275. int (*_write_oob) (struct mtd_info *mtd, loff_t to,
  276. struct mtd_oob_ops *ops);
  277. int (*_get_fact_prot_info) (struct mtd_info *mtd, size_t len,
  278. size_t *retlen, struct otp_info *buf);
  279. int (*_read_fact_prot_reg) (struct mtd_info *mtd, loff_t from,
  280. size_t len, size_t *retlen, u_char *buf);
  281. int (*_get_user_prot_info) (struct mtd_info *mtd, size_t len,
  282. size_t *retlen, struct otp_info *buf);
  283. int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from,
  284. size_t len, size_t *retlen, u_char *buf);
  285. int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to,
  286. size_t len, size_t *retlen, u_char *buf);
  287. int (*_lock_user_prot_reg) (struct mtd_info *mtd, loff_t from,
  288. size_t len);
  289. int (*_writev) (struct mtd_info *mtd, const struct kvec *vecs,
  290. unsigned long count, loff_t to, size_t *retlen);
  291. void (*_sync) (struct mtd_info *mtd);
  292. int (*_lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
  293. int (*_unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
  294. int (*_is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
  295. int (*_block_isreserved) (struct mtd_info *mtd, loff_t ofs);
  296. int (*_block_isbad) (struct mtd_info *mtd, loff_t ofs);
  297. int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs);
  298. int (*_suspend) (struct mtd_info *mtd);
  299. void (*_resume) (struct mtd_info *mtd);
  300. void (*_reboot) (struct mtd_info *mtd);
  301. /*
  302. * If the driver is something smart, like UBI, it may need to maintain
  303. * its own reference counting. The below functions are only for driver.
  304. */
  305. int (*_get_device) (struct mtd_info *mtd);
  306. void (*_put_device) (struct mtd_info *mtd);
  307. /* Backing device capabilities for this device
  308. * - provides mmap capabilities
  309. */
  310. struct backing_dev_info *backing_dev_info;
  311. struct notifier_block reboot_notifier; /* default mode before reboot */
  312. /* ECC status information */
  313. struct mtd_ecc_stats ecc_stats;
  314. /* Subpage shift (NAND) */
  315. int subpage_sft;
  316. void *priv;
  317. struct module *owner;
  318. struct device dev;
  319. int usecount;
  320. };
  321. int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
  322. struct mtd_oob_region *oobecc);
  323. int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
  324. int *section,
  325. struct mtd_oob_region *oobregion);
  326. int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
  327. const u8 *oobbuf, int start, int nbytes);
  328. int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
  329. u8 *oobbuf, int start, int nbytes);
  330. int mtd_ooblayout_free(struct mtd_info *mtd, int section,
  331. struct mtd_oob_region *oobfree);
  332. int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
  333. const u8 *oobbuf, int start, int nbytes);
  334. int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
  335. u8 *oobbuf, int start, int nbytes);
  336. int mtd_ooblayout_count_freebytes(struct mtd_info *mtd);
  337. int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd);
  338. static inline void mtd_set_ooblayout(struct mtd_info *mtd,
  339. const struct mtd_ooblayout_ops *ooblayout)
  340. {
  341. mtd->ooblayout = ooblayout;
  342. }
  343. static inline void mtd_set_pairing_scheme(struct mtd_info *mtd,
  344. const struct mtd_pairing_scheme *pairing)
  345. {
  346. mtd->pairing = pairing;
  347. }
  348. static inline void mtd_set_of_node(struct mtd_info *mtd,
  349. struct device_node *np)
  350. {
  351. mtd->dev.of_node = np;
  352. }
  353. static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd)
  354. {
  355. return mtd->dev.of_node;
  356. }
  357. static inline int mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops)
  358. {
  359. return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;
  360. }
  361. int mtd_wunit_to_pairing_info(struct mtd_info *mtd, int wunit,
  362. struct mtd_pairing_info *info);
  363. int mtd_pairing_info_to_wunit(struct mtd_info *mtd,
  364. const struct mtd_pairing_info *info);
  365. int mtd_pairing_groups(struct mtd_info *mtd);
  366. int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
  367. int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  368. void **virt, resource_size_t *phys);
  369. int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
  370. unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
  371. unsigned long offset, unsigned long flags);
  372. int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  373. u_char *buf);
  374. int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  375. const u_char *buf);
  376. int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  377. const u_char *buf);
  378. int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
  379. int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
  380. int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
  381. struct otp_info *buf);
  382. int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
  383. size_t *retlen, u_char *buf);
  384. int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
  385. struct otp_info *buf);
  386. int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
  387. size_t *retlen, u_char *buf);
  388. int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
  389. size_t *retlen, u_char *buf);
  390. int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
  391. int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
  392. unsigned long count, loff_t to, size_t *retlen);
  393. static inline void mtd_sync(struct mtd_info *mtd)
  394. {
  395. if (mtd->_sync)
  396. mtd->_sync(mtd);
  397. }
  398. int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  399. int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  400. int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  401. int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs);
  402. int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs);
  403. int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs);
  404. static inline int mtd_suspend(struct mtd_info *mtd)
  405. {
  406. return mtd->_suspend ? mtd->_suspend(mtd) : 0;
  407. }
  408. static inline void mtd_resume(struct mtd_info *mtd)
  409. {
  410. if (mtd->_resume)
  411. mtd->_resume(mtd);
  412. }
  413. static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
  414. {
  415. if (mtd->erasesize_shift)
  416. return sz >> mtd->erasesize_shift;
  417. do_div(sz, mtd->erasesize);
  418. return sz;
  419. }
  420. static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
  421. {
  422. if (mtd->erasesize_shift)
  423. return sz & mtd->erasesize_mask;
  424. return do_div(sz, mtd->erasesize);
  425. }
  426. static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
  427. {
  428. if (mtd->writesize_shift)
  429. return sz >> mtd->writesize_shift;
  430. do_div(sz, mtd->writesize);
  431. return sz;
  432. }
  433. static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)
  434. {
  435. if (mtd->writesize_shift)
  436. return sz & mtd->writesize_mask;
  437. return do_div(sz, mtd->writesize);
  438. }
  439. static inline int mtd_wunit_per_eb(struct mtd_info *mtd)
  440. {
  441. return mtd->erasesize / mtd->writesize;
  442. }
  443. static inline int mtd_offset_to_wunit(struct mtd_info *mtd, loff_t offs)
  444. {
  445. return mtd_div_by_ws(mtd_mod_by_eb(offs, mtd), mtd);
  446. }
  447. static inline loff_t mtd_wunit_to_offset(struct mtd_info *mtd, loff_t base,
  448. int wunit)
  449. {
  450. return base + (wunit * mtd->writesize);
  451. }
  452. static inline int mtd_has_oob(const struct mtd_info *mtd)
  453. {
  454. return mtd->_read_oob && mtd->_write_oob;
  455. }
  456. static inline int mtd_type_is_nand(const struct mtd_info *mtd)
  457. {
  458. return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
  459. }
  460. static inline int mtd_can_have_bb(const struct mtd_info *mtd)
  461. {
  462. return !!mtd->_block_isbad;
  463. }
  464. /* Kernel-side ioctl definitions */
  465. struct mtd_partition;
  466. struct mtd_part_parser_data;
  467. extern int mtd_device_parse_register(struct mtd_info *mtd,
  468. const char * const *part_probe_types,
  469. struct mtd_part_parser_data *parser_data,
  470. const struct mtd_partition *defparts,
  471. int defnr_parts);
  472. #define mtd_device_register(master, parts, nr_parts) \
  473. mtd_device_parse_register(master, NULL, NULL, parts, nr_parts)
  474. extern int mtd_device_unregister(struct mtd_info *master);
  475. extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
  476. extern int __get_mtd_device(struct mtd_info *mtd);
  477. extern void __put_mtd_device(struct mtd_info *mtd);
  478. extern struct mtd_info *get_mtd_device_nm(const char *name);
  479. extern void put_mtd_device(struct mtd_info *mtd);
  480. struct mtd_notifier {
  481. void (*add)(struct mtd_info *mtd);
  482. void (*remove)(struct mtd_info *mtd);
  483. struct list_head list;
  484. };
  485. extern void register_mtd_user (struct mtd_notifier *new);
  486. extern int unregister_mtd_user (struct mtd_notifier *old);
  487. void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
  488. void mtd_erase_callback(struct erase_info *instr);
  489. static inline int mtd_is_bitflip(int err) {
  490. return err == -EUCLEAN;
  491. }
  492. static inline int mtd_is_eccerr(int err) {
  493. return err == -EBADMSG;
  494. }
  495. static inline int mtd_is_bitflip_or_eccerr(int err) {
  496. return mtd_is_bitflip(err) || mtd_is_eccerr(err);
  497. }
  498. unsigned mtd_mmap_capabilities(struct mtd_info *mtd);
  499. #endif /* __MTD_MTD_H__ */