mtd.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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. /**
  195. * struct mtd_debug_info - debugging information for an MTD device.
  196. *
  197. * @dfs_dir: direntry object of the MTD device debugfs directory
  198. */
  199. struct mtd_debug_info {
  200. struct dentry *dfs_dir;
  201. };
  202. struct mtd_info {
  203. u_char type;
  204. uint32_t flags;
  205. uint64_t size; // Total size of the MTD
  206. /* "Major" erase size for the device. Naïve users may take this
  207. * to be the only erase size available, or may use the more detailed
  208. * information below if they desire
  209. */
  210. uint32_t erasesize;
  211. /* Minimal writable flash unit size. In case of NOR flash it is 1 (even
  212. * though individual bits can be cleared), in case of NAND flash it is
  213. * one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
  214. * it is of ECC block size, etc. It is illegal to have writesize = 0.
  215. * Any driver registering a struct mtd_info must ensure a writesize of
  216. * 1 or larger.
  217. */
  218. uint32_t writesize;
  219. /*
  220. * Size of the write buffer used by the MTD. MTD devices having a write
  221. * buffer can write multiple writesize chunks at a time. E.g. while
  222. * writing 4 * writesize bytes to a device with 2 * writesize bytes
  223. * buffer the MTD driver can (but doesn't have to) do 2 writesize
  224. * operations, but not 4. Currently, all NANDs have writebufsize
  225. * equivalent to writesize (NAND page size). Some NOR flashes do have
  226. * writebufsize greater than writesize.
  227. */
  228. uint32_t writebufsize;
  229. uint32_t oobsize; // Amount of OOB data per block (e.g. 16)
  230. uint32_t oobavail; // Available OOB bytes per block
  231. /*
  232. * If erasesize is a power of 2 then the shift is stored in
  233. * erasesize_shift otherwise erasesize_shift is zero. Ditto writesize.
  234. */
  235. unsigned int erasesize_shift;
  236. unsigned int writesize_shift;
  237. /* Masks based on erasesize_shift and writesize_shift */
  238. unsigned int erasesize_mask;
  239. unsigned int writesize_mask;
  240. /*
  241. * read ops return -EUCLEAN if max number of bitflips corrected on any
  242. * one region comprising an ecc step equals or exceeds this value.
  243. * Settable by driver, else defaults to ecc_strength. User can override
  244. * in sysfs. N.B. The meaning of the -EUCLEAN return code has changed;
  245. * see Documentation/ABI/testing/sysfs-class-mtd for more detail.
  246. */
  247. unsigned int bitflip_threshold;
  248. // Kernel-only stuff starts here.
  249. const char *name;
  250. int index;
  251. /* OOB layout description */
  252. const struct mtd_ooblayout_ops *ooblayout;
  253. /* NAND pairing scheme, only provided for MLC/TLC NANDs */
  254. const struct mtd_pairing_scheme *pairing;
  255. /* the ecc step size. */
  256. unsigned int ecc_step_size;
  257. /* max number of correctible bit errors per ecc step */
  258. unsigned int ecc_strength;
  259. /* Data for variable erase regions. If numeraseregions is zero,
  260. * it means that the whole device has erasesize as given above.
  261. */
  262. int numeraseregions;
  263. struct mtd_erase_region_info *eraseregions;
  264. /*
  265. * Do not call via these pointers, use corresponding mtd_*()
  266. * wrappers instead.
  267. */
  268. int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
  269. int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
  270. size_t *retlen, void **virt, resource_size_t *phys);
  271. int (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
  272. unsigned long (*_get_unmapped_area) (struct mtd_info *mtd,
  273. unsigned long len,
  274. unsigned long offset,
  275. unsigned long flags);
  276. int (*_read) (struct mtd_info *mtd, loff_t from, size_t len,
  277. size_t *retlen, u_char *buf);
  278. int (*_write) (struct mtd_info *mtd, loff_t to, size_t len,
  279. size_t *retlen, const u_char *buf);
  280. int (*_panic_write) (struct mtd_info *mtd, loff_t to, size_t len,
  281. size_t *retlen, const u_char *buf);
  282. int (*_read_oob) (struct mtd_info *mtd, loff_t from,
  283. struct mtd_oob_ops *ops);
  284. int (*_write_oob) (struct mtd_info *mtd, loff_t to,
  285. struct mtd_oob_ops *ops);
  286. int (*_get_fact_prot_info) (struct mtd_info *mtd, size_t len,
  287. size_t *retlen, struct otp_info *buf);
  288. int (*_read_fact_prot_reg) (struct mtd_info *mtd, loff_t from,
  289. size_t len, size_t *retlen, u_char *buf);
  290. int (*_get_user_prot_info) (struct mtd_info *mtd, size_t len,
  291. size_t *retlen, struct otp_info *buf);
  292. int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from,
  293. size_t len, size_t *retlen, u_char *buf);
  294. int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to,
  295. size_t len, size_t *retlen, u_char *buf);
  296. int (*_lock_user_prot_reg) (struct mtd_info *mtd, loff_t from,
  297. size_t len);
  298. int (*_writev) (struct mtd_info *mtd, const struct kvec *vecs,
  299. unsigned long count, loff_t to, size_t *retlen);
  300. void (*_sync) (struct mtd_info *mtd);
  301. int (*_lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
  302. int (*_unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
  303. int (*_is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
  304. int (*_block_isreserved) (struct mtd_info *mtd, loff_t ofs);
  305. int (*_block_isbad) (struct mtd_info *mtd, loff_t ofs);
  306. int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs);
  307. int (*_max_bad_blocks) (struct mtd_info *mtd, loff_t ofs, size_t len);
  308. int (*_suspend) (struct mtd_info *mtd);
  309. void (*_resume) (struct mtd_info *mtd);
  310. void (*_reboot) (struct mtd_info *mtd);
  311. /*
  312. * If the driver is something smart, like UBI, it may need to maintain
  313. * its own reference counting. The below functions are only for driver.
  314. */
  315. int (*_get_device) (struct mtd_info *mtd);
  316. void (*_put_device) (struct mtd_info *mtd);
  317. struct notifier_block reboot_notifier; /* default mode before reboot */
  318. /* ECC status information */
  319. struct mtd_ecc_stats ecc_stats;
  320. /* Subpage shift (NAND) */
  321. int subpage_sft;
  322. void *priv;
  323. struct module *owner;
  324. struct device dev;
  325. int usecount;
  326. struct mtd_debug_info dbg;
  327. };
  328. int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
  329. struct mtd_oob_region *oobecc);
  330. int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
  331. int *section,
  332. struct mtd_oob_region *oobregion);
  333. int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
  334. const u8 *oobbuf, int start, int nbytes);
  335. int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
  336. u8 *oobbuf, int start, int nbytes);
  337. int mtd_ooblayout_free(struct mtd_info *mtd, int section,
  338. struct mtd_oob_region *oobfree);
  339. int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
  340. const u8 *oobbuf, int start, int nbytes);
  341. int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
  342. u8 *oobbuf, int start, int nbytes);
  343. int mtd_ooblayout_count_freebytes(struct mtd_info *mtd);
  344. int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd);
  345. static inline void mtd_set_ooblayout(struct mtd_info *mtd,
  346. const struct mtd_ooblayout_ops *ooblayout)
  347. {
  348. mtd->ooblayout = ooblayout;
  349. }
  350. static inline void mtd_set_pairing_scheme(struct mtd_info *mtd,
  351. const struct mtd_pairing_scheme *pairing)
  352. {
  353. mtd->pairing = pairing;
  354. }
  355. static inline void mtd_set_of_node(struct mtd_info *mtd,
  356. struct device_node *np)
  357. {
  358. mtd->dev.of_node = np;
  359. if (!mtd->name)
  360. of_property_read_string(np, "label", &mtd->name);
  361. }
  362. static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd)
  363. {
  364. return dev_of_node(&mtd->dev);
  365. }
  366. static inline int mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops)
  367. {
  368. return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;
  369. }
  370. static inline int mtd_max_bad_blocks(struct mtd_info *mtd,
  371. loff_t ofs, size_t len)
  372. {
  373. if (!mtd->_max_bad_blocks)
  374. return -ENOTSUPP;
  375. if (mtd->size < (len + ofs) || ofs < 0)
  376. return -EINVAL;
  377. return mtd->_max_bad_blocks(mtd, ofs, len);
  378. }
  379. int mtd_wunit_to_pairing_info(struct mtd_info *mtd, int wunit,
  380. struct mtd_pairing_info *info);
  381. int mtd_pairing_info_to_wunit(struct mtd_info *mtd,
  382. const struct mtd_pairing_info *info);
  383. int mtd_pairing_groups(struct mtd_info *mtd);
  384. int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
  385. int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  386. void **virt, resource_size_t *phys);
  387. int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
  388. unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
  389. unsigned long offset, unsigned long flags);
  390. int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  391. u_char *buf);
  392. int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  393. const u_char *buf);
  394. int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  395. const u_char *buf);
  396. int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
  397. int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
  398. int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
  399. struct otp_info *buf);
  400. int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
  401. size_t *retlen, u_char *buf);
  402. int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
  403. struct otp_info *buf);
  404. int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
  405. size_t *retlen, u_char *buf);
  406. int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
  407. size_t *retlen, u_char *buf);
  408. int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
  409. int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
  410. unsigned long count, loff_t to, size_t *retlen);
  411. static inline void mtd_sync(struct mtd_info *mtd)
  412. {
  413. if (mtd->_sync)
  414. mtd->_sync(mtd);
  415. }
  416. int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  417. int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  418. int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  419. int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs);
  420. int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs);
  421. int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs);
  422. static inline int mtd_suspend(struct mtd_info *mtd)
  423. {
  424. return mtd->_suspend ? mtd->_suspend(mtd) : 0;
  425. }
  426. static inline void mtd_resume(struct mtd_info *mtd)
  427. {
  428. if (mtd->_resume)
  429. mtd->_resume(mtd);
  430. }
  431. static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
  432. {
  433. if (mtd->erasesize_shift)
  434. return sz >> mtd->erasesize_shift;
  435. do_div(sz, mtd->erasesize);
  436. return sz;
  437. }
  438. static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
  439. {
  440. if (mtd->erasesize_shift)
  441. return sz & mtd->erasesize_mask;
  442. return do_div(sz, mtd->erasesize);
  443. }
  444. static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
  445. {
  446. if (mtd->writesize_shift)
  447. return sz >> mtd->writesize_shift;
  448. do_div(sz, mtd->writesize);
  449. return sz;
  450. }
  451. static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)
  452. {
  453. if (mtd->writesize_shift)
  454. return sz & mtd->writesize_mask;
  455. return do_div(sz, mtd->writesize);
  456. }
  457. static inline int mtd_wunit_per_eb(struct mtd_info *mtd)
  458. {
  459. return mtd->erasesize / mtd->writesize;
  460. }
  461. static inline int mtd_offset_to_wunit(struct mtd_info *mtd, loff_t offs)
  462. {
  463. return mtd_div_by_ws(mtd_mod_by_eb(offs, mtd), mtd);
  464. }
  465. static inline loff_t mtd_wunit_to_offset(struct mtd_info *mtd, loff_t base,
  466. int wunit)
  467. {
  468. return base + (wunit * mtd->writesize);
  469. }
  470. static inline int mtd_has_oob(const struct mtd_info *mtd)
  471. {
  472. return mtd->_read_oob && mtd->_write_oob;
  473. }
  474. static inline int mtd_type_is_nand(const struct mtd_info *mtd)
  475. {
  476. return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
  477. }
  478. static inline int mtd_can_have_bb(const struct mtd_info *mtd)
  479. {
  480. return !!mtd->_block_isbad;
  481. }
  482. /* Kernel-side ioctl definitions */
  483. struct mtd_partition;
  484. struct mtd_part_parser_data;
  485. extern int mtd_device_parse_register(struct mtd_info *mtd,
  486. const char * const *part_probe_types,
  487. struct mtd_part_parser_data *parser_data,
  488. const struct mtd_partition *defparts,
  489. int defnr_parts);
  490. #define mtd_device_register(master, parts, nr_parts) \
  491. mtd_device_parse_register(master, NULL, NULL, parts, nr_parts)
  492. extern int mtd_device_unregister(struct mtd_info *master);
  493. extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
  494. extern int __get_mtd_device(struct mtd_info *mtd);
  495. extern void __put_mtd_device(struct mtd_info *mtd);
  496. extern struct mtd_info *get_mtd_device_nm(const char *name);
  497. extern void put_mtd_device(struct mtd_info *mtd);
  498. struct mtd_notifier {
  499. void (*add)(struct mtd_info *mtd);
  500. void (*remove)(struct mtd_info *mtd);
  501. struct list_head list;
  502. };
  503. extern void register_mtd_user (struct mtd_notifier *new);
  504. extern int unregister_mtd_user (struct mtd_notifier *old);
  505. void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
  506. void mtd_erase_callback(struct erase_info *instr);
  507. static inline int mtd_is_bitflip(int err) {
  508. return err == -EUCLEAN;
  509. }
  510. static inline int mtd_is_eccerr(int err) {
  511. return err == -EBADMSG;
  512. }
  513. static inline int mtd_is_bitflip_or_eccerr(int err) {
  514. return mtd_is_bitflip(err) || mtd_is_eccerr(err);
  515. }
  516. unsigned mtd_mmap_capabilities(struct mtd_info *mtd);
  517. #endif /* __MTD_MTD_H__ */