mtd-abi.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/mtd/compat.h>
  10. #endif
  11. struct erase_info_user {
  12. uint32_t start;
  13. uint32_t length;
  14. };
  15. struct mtd_oob_buf {
  16. uint32_t start;
  17. uint32_t length;
  18. unsigned char __user *ptr;
  19. };
  20. #define MTD_ABSENT 0
  21. #define MTD_RAM 1
  22. #define MTD_ROM 2
  23. #define MTD_NORFLASH 3
  24. #define MTD_NANDFLASH 4
  25. #define MTD_DATAFLASH 6
  26. #define MTD_UBIVOLUME 7
  27. #define MTD_WRITEABLE 0x400 /* Device is writeable */
  28. #define MTD_BIT_WRITEABLE 0x800 /* Single bits can be flipped */
  29. #define MTD_NO_ERASE 0x1000 /* No erase necessary */
  30. #define MTD_STUPID_LOCK 0x2000 /* Always locked after reset */
  31. // Some common devices / combinations of capabilities
  32. #define MTD_CAP_ROM 0
  33. #define MTD_CAP_RAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
  34. #define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE)
  35. #define MTD_CAP_NANDFLASH (MTD_WRITEABLE)
  36. /* ECC byte placement */
  37. #define MTD_NANDECC_OFF 0 // Switch off ECC (Not recommended)
  38. #define MTD_NANDECC_PLACE 1 // Use the given placement in the structure (YAFFS1 legacy mode)
  39. #define MTD_NANDECC_AUTOPLACE 2 // Use the default placement scheme
  40. #define MTD_NANDECC_PLACEONLY 3 // Use the given placement in the structure (Do not store ecc result on read)
  41. #define MTD_NANDECC_AUTOPL_USR 4 // Use the given autoplacement scheme rather than using the default
  42. /* OTP mode selection */
  43. #define MTD_OTP_OFF 0
  44. #define MTD_OTP_FACTORY 1
  45. #define MTD_OTP_USER 2
  46. struct mtd_info_user {
  47. uint8_t type;
  48. uint32_t flags;
  49. uint32_t size; // Total size of the MTD
  50. uint32_t erasesize;
  51. uint32_t writesize;
  52. uint32_t oobsize; // Amount of OOB data per block (e.g. 16)
  53. /* The below two fields are obsolete and broken, do not use them
  54. * (TODO: remove at some point) */
  55. uint32_t ecctype;
  56. uint32_t eccsize;
  57. };
  58. struct region_info_user {
  59. uint32_t offset; /* At which this region starts,
  60. * from the beginning of the MTD */
  61. uint32_t erasesize; /* For this region */
  62. uint32_t numblocks; /* Number of blocks in this region */
  63. uint32_t regionindex;
  64. };
  65. struct otp_info {
  66. uint32_t start;
  67. uint32_t length;
  68. uint32_t locked;
  69. };
  70. #define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
  71. #define MEMERASE _IOW('M', 2, struct erase_info_user)
  72. #define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf)
  73. #define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf)
  74. #define MEMLOCK _IOW('M', 5, struct erase_info_user)
  75. #define MEMUNLOCK _IOW('M', 6, struct erase_info_user)
  76. #define MEMGETREGIONCOUNT _IOR('M', 7, int)
  77. #define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user)
  78. #define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo)
  79. #define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo)
  80. #define MEMGETBADBLOCK _IOW('M', 11, loff_t)
  81. #define MEMSETBADBLOCK _IOW('M', 12, loff_t)
  82. #define OTPSELECT _IOR('M', 13, int)
  83. #define OTPGETREGIONCOUNT _IOW('M', 14, int)
  84. #define OTPGETREGIONINFO _IOW('M', 15, struct otp_info)
  85. #define OTPLOCK _IOR('M', 16, struct otp_info)
  86. #define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout)
  87. #define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)
  88. #define MTDFILEMODE _IO('M', 19)
  89. /*
  90. * Obsolete legacy interface. Keep it in order not to break userspace
  91. * interfaces
  92. */
  93. struct nand_oobinfo {
  94. uint32_t useecc;
  95. uint32_t eccbytes;
  96. uint32_t oobfree[8][2];
  97. uint32_t eccpos[48];
  98. };
  99. struct nand_oobfree {
  100. uint32_t offset;
  101. uint32_t length;
  102. };
  103. #define MTD_MAX_OOBFREE_ENTRIES 8
  104. /*
  105. * ECC layout control structure. Exported to userspace for
  106. * diagnosis and to allow creation of raw images
  107. */
  108. struct nand_ecclayout {
  109. uint32_t eccbytes;
  110. uint32_t eccpos[64];
  111. uint32_t oobavail;
  112. struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
  113. };
  114. /**
  115. * struct mtd_ecc_stats - error correction stats
  116. *
  117. * @corrected: number of corrected bits
  118. * @failed: number of uncorrectable errors
  119. * @badblocks: number of bad blocks in this partition
  120. * @bbtblocks: number of blocks reserved for bad block tables
  121. */
  122. struct mtd_ecc_stats {
  123. uint32_t corrected;
  124. uint32_t failed;
  125. uint32_t badblocks;
  126. uint32_t bbtblocks;
  127. };
  128. /*
  129. * Read/write file modes for access to MTD
  130. */
  131. enum mtd_file_modes {
  132. MTD_MODE_NORMAL = MTD_OTP_OFF,
  133. MTD_MODE_OTP_FACTORY = MTD_OTP_FACTORY,
  134. MTD_MODE_OTP_USER = MTD_OTP_USER,
  135. MTD_MODE_RAW,
  136. };
  137. #endif /* __MTD_ABI_H__ */