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