mtd.h 19 KB

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