mtd.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * $Id: mtd.h,v 1.56 2004/08/09 18:46:04 dmarlin Exp $
  3. *
  4. * Copyright (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> et al.
  5. *
  6. * Released under GPL
  7. */
  8. #ifndef __MTD_MTD_H__
  9. #define __MTD_MTD_H__
  10. #include <linux/types.h>
  11. #include <linux/mtd/mtd-abi.h>
  12. #define MAX_MTD_DEVICES 16
  13. #define MTD_ERASE_PENDING 0x01
  14. #define MTD_ERASING 0x02
  15. #define MTD_ERASE_SUSPEND 0x04
  16. #define MTD_ERASE_DONE 0x08
  17. #define MTD_ERASE_FAILED 0x10
  18. /* If the erase fails, fail_addr might indicate exactly which block failed. If
  19. fail_addr = 0xffffffff, the failure was not at the device level or was not
  20. specific to any particular block. */
  21. struct erase_info {
  22. struct mtd_info *mtd;
  23. u_int32_t addr;
  24. u_int32_t len;
  25. u_int32_t fail_addr;
  26. u_long time;
  27. u_long retries;
  28. u_int dev;
  29. u_int cell;
  30. void (*callback) (struct erase_info *self);
  31. u_long priv;
  32. u_char state;
  33. struct erase_info *next;
  34. };
  35. struct mtd_erase_region_info {
  36. u_int32_t offset; /* At which this region starts, from the beginning of the MTD */
  37. u_int32_t erasesize; /* For this region */
  38. u_int32_t numblocks; /* Number of blocks of erasesize in this region */
  39. };
  40. struct mtd_info {
  41. u_char type;
  42. u_int32_t flags;
  43. u_int32_t size; // Total size of the MTD
  44. /* "Major" erase size for the device. Naïve users may take this
  45. * to be the only erase size available, or may use the more detailed
  46. * information below if they desire
  47. */
  48. u_int32_t erasesize;
  49. u_int32_t oobblock; // Size of OOB blocks (e.g. 512)
  50. u_int32_t oobsize; // Amount of OOB data per block (e.g. 16)
  51. u_int32_t oobavail; // Number of bytes in OOB area available for fs
  52. u_int32_t ecctype;
  53. u_int32_t eccsize;
  54. // Kernel-only stuff starts here.
  55. char *name;
  56. int index;
  57. // oobinfo is a nand_oobinfo structure, which can be set by iotcl (MEMSETOOBINFO)
  58. struct nand_oobinfo oobinfo;
  59. /* Data for variable erase regions. If numeraseregions is zero,
  60. * it means that the whole device has erasesize as given above.
  61. */
  62. int numeraseregions;
  63. struct mtd_erase_region_info *eraseregions;
  64. /* This really shouldn't be here. It can go away in 2.5 */
  65. u_int32_t bank_size;
  66. int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
  67. /* This stuff for eXecute-In-Place */
  68. int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
  69. /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
  70. void (*unpoint) (struct mtd_info *mtd, u_char * addr, loff_t from, size_t len);
  71. int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
  72. int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
  73. int (*read_ecc) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
  74. int (*write_ecc) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
  75. int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
  76. int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
  77. /*
  78. * Methods to access the protection register area, present in some
  79. * flash devices. The user data is one time programmable but the
  80. * factory data is read only.
  81. */
  82. int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
  83. int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
  84. /* This function is not yet implemented */
  85. int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
  86. #if 0
  87. /* kvec-based read/write methods. We need these especially for NAND flash,
  88. with its limited number of write cycles per erase.
  89. NB: The 'count' parameter is the number of _vectors_, each of
  90. which contains an (ofs, len) tuple.
  91. */
  92. int (*readv) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from, size_t *retlen);
  93. int (*readv_ecc) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from,
  94. size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
  95. int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
  96. int (*writev_ecc) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to,
  97. size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
  98. #endif
  99. /* Sync */
  100. void (*sync) (struct mtd_info *mtd);
  101. #if 0
  102. /* Chip-supported device locking */
  103. int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);
  104. int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_t len);
  105. /* Power Management functions */
  106. int (*suspend) (struct mtd_info *mtd);
  107. void (*resume) (struct mtd_info *mtd);
  108. #endif
  109. /* Bad block management functions */
  110. int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);
  111. int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);
  112. void *priv;
  113. struct module *owner;
  114. int usecount;
  115. };
  116. /* Kernel-side ioctl definitions */
  117. extern int add_mtd_device(struct mtd_info *mtd);
  118. extern int del_mtd_device (struct mtd_info *mtd);
  119. extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
  120. extern void put_mtd_device(struct mtd_info *mtd);
  121. #if 0
  122. struct mtd_notifier {
  123. void (*add)(struct mtd_info *mtd);
  124. void (*remove)(struct mtd_info *mtd);
  125. struct list_head list;
  126. };
  127. extern void register_mtd_user (struct mtd_notifier *new);
  128. extern int unregister_mtd_user (struct mtd_notifier *old);
  129. int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
  130. unsigned long count, loff_t to, size_t *retlen);
  131. int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
  132. unsigned long count, loff_t from, size_t *retlen);
  133. #endif
  134. #define MTD_ERASE(mtd, args...) (*(mtd->erase))(mtd, args)
  135. #define MTD_POINT(mtd, a,b,c,d) (*(mtd->point))(mtd, a,b,c, (u_char **)(d))
  136. #define MTD_UNPOINT(mtd, arg) (*(mtd->unpoint))(mtd, (u_char *)arg)
  137. #define MTD_READ(mtd, args...) (*(mtd->read))(mtd, args)
  138. #define MTD_WRITE(mtd, args...) (*(mtd->write))(mtd, args)
  139. #define MTD_READV(mtd, args...) (*(mtd->readv))(mtd, args)
  140. #define MTD_WRITEV(mtd, args...) (*(mtd->writev))(mtd, args)
  141. #define MTD_READECC(mtd, args...) (*(mtd->read_ecc))(mtd, args)
  142. #define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args)
  143. #define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args)
  144. #define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args)
  145. #define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd); } while (0)
  146. #ifdef CONFIG_MTD_PARTITIONS
  147. void mtd_erase_callback(struct erase_info *instr);
  148. #else
  149. static inline void mtd_erase_callback(struct erase_info *instr)
  150. {
  151. if (instr->callback)
  152. instr->callback(instr);
  153. }
  154. #endif
  155. /*
  156. * Debugging macro and defines
  157. */
  158. #define MTD_DEBUG_LEVEL0 (0) /* Quiet */
  159. #define MTD_DEBUG_LEVEL1 (1) /* Audible */
  160. #define MTD_DEBUG_LEVEL2 (2) /* Loud */
  161. #define MTD_DEBUG_LEVEL3 (3) /* Noisy */
  162. #ifdef CONFIG_MTD_DEBUG
  163. #define DEBUG(n, args...) \
  164. do { \
  165. if (n <= CONFIG_MTD_DEBUG_VERBOSE) \
  166. printk(KERN_INFO args); \
  167. } while(0)
  168. #else /* CONFIG_MTD_DEBUG */
  169. #define DEBUG(n, args...) do { } while(0)
  170. #endif /* CONFIG_MTD_DEBUG */
  171. #endif /* __MTD_MTD_H__ */