mtd-abi.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * $Id: mtd-abi.h,v 1.13 2005/11/07 11:14:56 gleixner Exp $
  3. *
  4. * Portions of MTD ABI definition which are shared by kernel and user space
  5. */
  6. #ifndef __MTD_ABI_H__
  7. #define __MTD_ABI_H__
  8. #if 1
  9. #include <linux/compat.h>
  10. #endif
  11. #include <linux/compiler.h>
  12. struct erase_info_user {
  13. uint32_t start;
  14. uint32_t length;
  15. };
  16. struct mtd_oob_buf {
  17. uint32_t start;
  18. uint32_t length;
  19. unsigned char __user *ptr;
  20. };
  21. /*
  22. * MTD operation modes
  23. *
  24. * @MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
  25. * @MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
  26. * which are defined by the internal ecclayout
  27. * @MTD_OPS_RAW: data are transferred as-is, with no error correction;
  28. * this mode implies %MTD_OPS_PLACE_OOB
  29. *
  30. * These modes can be passed to ioctl(MEMWRITE) and are also used internally.
  31. * See notes on "MTD file modes" for discussion on %MTD_OPS_RAW vs.
  32. * %MTD_FILE_MODE_RAW.
  33. */
  34. enum {
  35. MTD_OPS_PLACE_OOB = 0,
  36. MTD_OPS_AUTO_OOB = 1,
  37. MTD_OPS_RAW = 2,
  38. };
  39. #define MTD_ABSENT 0
  40. #define MTD_RAM 1
  41. #define MTD_ROM 2
  42. #define MTD_NORFLASH 3
  43. #define MTD_NANDFLASH 4
  44. #define MTD_DATAFLASH 6
  45. #define MTD_UBIVOLUME 7
  46. #define MTD_WRITEABLE 0x400 /* Device is writeable */
  47. #define MTD_BIT_WRITEABLE 0x800 /* Single bits can be flipped */
  48. #define MTD_NO_ERASE 0x1000 /* No erase necessary */
  49. #define MTD_STUPID_LOCK 0x2000 /* Always locked after reset */
  50. /* Some common devices / combinations of capabilities */
  51. #define MTD_CAP_ROM 0
  52. #define MTD_CAP_RAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
  53. #define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE)
  54. #define MTD_CAP_NANDFLASH (MTD_WRITEABLE)
  55. /* ECC byte placement */
  56. #define MTD_NANDECC_OFF 0 /* Switch off ECC (Not recommended) */
  57. #define MTD_NANDECC_PLACE 1 /* Use the given placement in the structure (YAFFS1 legacy mode) */
  58. #define MTD_NANDECC_AUTOPLACE 2 /* Use the default placement scheme */
  59. #define MTD_NANDECC_PLACEONLY 3 /* Use the given placement in the structure (Do not store ecc result on read) */
  60. #define MTD_NANDECC_AUTOPL_USR 4 /* Use the given autoplacement scheme rather than using the default */
  61. /* OTP mode selection */
  62. #define MTD_OTP_OFF 0
  63. #define MTD_OTP_FACTORY 1
  64. #define MTD_OTP_USER 2
  65. struct mtd_info_user {
  66. uint8_t type;
  67. uint32_t flags;
  68. uint32_t size; /* Total size of the MTD */
  69. uint32_t erasesize;
  70. uint32_t writesize;
  71. uint32_t oobsize; /* Amount of OOB data per block (e.g. 16) */
  72. /* The below two fields are obsolete and broken, do not use them
  73. * (TODO: remove at some point) */
  74. uint32_t ecctype;
  75. uint32_t eccsize;
  76. };
  77. struct region_info_user {
  78. uint32_t offset; /* At which this region starts,
  79. * from the beginning of the MTD */
  80. uint32_t erasesize; /* For this region */
  81. uint32_t numblocks; /* Number of blocks in this region */
  82. uint32_t regionindex;
  83. };
  84. struct otp_info {
  85. uint32_t start;
  86. uint32_t length;
  87. uint32_t locked;
  88. };
  89. /* Get basic MTD characteristics info (better to use sysfs) */
  90. #define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
  91. /* Erase segment of MTD */
  92. #define MEMERASE _IOW('M', 2, struct erase_info_user)
  93. /* Write out-of-band data from MTD */
  94. #define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf)
  95. /* Read out-of-band data from MTD */
  96. #define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf)
  97. /* Lock a chip (for MTD that supports it) */
  98. #define MEMLOCK _IOW('M', 5, struct erase_info_user)
  99. /* Unlock a chip (for MTD that supports it) */
  100. #define MEMUNLOCK _IOW('M', 6, struct erase_info_user)
  101. /* Get the number of different erase regions */
  102. #define MEMGETREGIONCOUNT _IOR('M', 7, int)
  103. /* Get information about the erase region for a specific index */
  104. #define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user)
  105. /* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */
  106. #define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo)
  107. #define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo)
  108. /* Check if an eraseblock is bad */
  109. #define MEMGETBADBLOCK _IOW('M', 11, loff_t)
  110. /* Mark an eraseblock as bad */
  111. #define MEMSETBADBLOCK _IOW('M', 12, loff_t)
  112. /* Set OTP (One-Time Programmable) mode (factory vs. user) */
  113. #define OTPSELECT _IOR('M', 13, int)
  114. /* Get number of OTP (One-Time Programmable) regions */
  115. #define OTPGETREGIONCOUNT _IOW('M', 14, int)
  116. /* Get all OTP (One-Time Programmable) info about MTD */
  117. #define OTPGETREGIONINFO _IOW('M', 15, struct otp_info)
  118. /* Lock a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */
  119. #define OTPLOCK _IOR('M', 16, struct otp_info)
  120. /* Get ECC layout (deprecated) */
  121. #define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout)
  122. /* Get statistics about corrected/uncorrected errors */
  123. #define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)
  124. /* Set MTD mode on a per-file-descriptor basis (see "MTD file modes") */
  125. #define MTDFILEMODE _IO('M', 19)
  126. /*
  127. * Obsolete legacy interface. Keep it in order not to break userspace
  128. * interfaces
  129. */
  130. struct nand_oobinfo {
  131. uint32_t useecc;
  132. uint32_t eccbytes;
  133. uint32_t oobfree[8][2];
  134. uint32_t eccpos[48];
  135. };
  136. struct nand_oobfree {
  137. uint32_t offset;
  138. uint32_t length;
  139. };
  140. #define MTD_MAX_OOBFREE_ENTRIES 8
  141. /*
  142. * ECC layout control structure. Exported to userspace for
  143. * diagnosis and to allow creation of raw images
  144. */
  145. struct nand_ecclayout {
  146. uint32_t eccbytes;
  147. uint32_t eccpos[128];
  148. uint32_t oobavail;
  149. struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
  150. };
  151. /**
  152. * struct mtd_ecc_stats - error correction stats
  153. *
  154. * @corrected: number of corrected bits
  155. * @failed: number of uncorrectable errors
  156. * @badblocks: number of bad blocks in this partition
  157. * @bbtblocks: number of blocks reserved for bad block tables
  158. */
  159. struct mtd_ecc_stats {
  160. uint32_t corrected;
  161. uint32_t failed;
  162. uint32_t badblocks;
  163. uint32_t bbtblocks;
  164. };
  165. /*
  166. * MTD file modes - for read/write access to MTD
  167. *
  168. * @MTD_FILE_MODE_NORMAL: OTP disabled, ECC enabled
  169. * @MTD_FILE_MODE_OTP_FACTORY: OTP enabled in factory mode
  170. * @MTD_FILE_MODE_OTP_USER: OTP enabled in user mode
  171. * @MTD_FILE_MODE_RAW: OTP disabled, ECC disabled
  172. *
  173. * These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained
  174. * separately for each open file descriptor.
  175. *
  176. * Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW -
  177. * raw access to the flash, without error correction or autoplacement schemes.
  178. * Wherever possible, the MTD_OPS_* mode will override the MTD_FILE_MODE_* mode
  179. * (e.g., when using ioctl(MEMWRITE)), but in some cases, the MTD_FILE_MODE is
  180. * used out of necessity (e.g., `write()', ioctl(MEMWRITEOOB64)).
  181. */
  182. enum mtd_file_modes {
  183. MTD_MODE_NORMAL = MTD_OTP_OFF,
  184. MTD_MODE_OTP_FACTORY = MTD_OTP_FACTORY,
  185. MTD_MODE_OTP_USER = MTD_OTP_USER,
  186. MTD_MODE_RAW,
  187. };
  188. #endif /* __MTD_ABI_H__ */