diff options
author | Brian Norris <computersforpeace@gmail.com> | 2011-08-30 21:45:44 -0400 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@intel.com> | 2011-09-11 08:57:44 -0400 |
commit | 4180f24a7bff3aa7978e3785d0edd5dcc4af9049 (patch) | |
tree | c5b59491f451abf150149e9aeb2ce4f591d8e8a7 /include/mtd | |
parent | e99d8b089a6c6fd72f022168e3bf8f22d4e5e137 (diff) |
mtd: document ABI
We're missing a lot of important documentation in include/mtd/mtd-abi.h:
* add a simple description of each ioctl (feel free to expand!)
* give full explanations of recently added and modified operations
* explain the usage of "RAW" that appear in different modes and types of
operations
* fix some comment style along the way
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
Diffstat (limited to 'include/mtd')
-rw-r--r-- | include/mtd/mtd-abi.h | 86 |
1 files changed, 73 insertions, 13 deletions
diff --git a/include/mtd/mtd-abi.h b/include/mtd/mtd-abi.h index 1a16046b1d97..7dee9709fbfc 100644 --- a/include/mtd/mtd-abi.h +++ b/include/mtd/mtd-abi.h | |||
@@ -45,14 +45,18 @@ struct mtd_oob_buf64 { | |||
45 | __u64 usr_ptr; | 45 | __u64 usr_ptr; |
46 | }; | 46 | }; |
47 | 47 | ||
48 | /* | 48 | /** |
49 | * MTD operation modes | 49 | * MTD operation modes |
50 | * | 50 | * |
51 | * MTD_OPS_PLACE_OOB: oob data are placed at the given offset (default) | 51 | * @MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default) |
52 | * MTD_OPS_AUTO_OOB: oob data are automatically placed at the free areas | 52 | * @MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas |
53 | * which are defined by the internal ecclayout | 53 | * which are defined by the internal ecclayout |
54 | * MTD_OPS_RAW: mode to read or write oob and data without doing ECC | 54 | * @MTD_OPS_RAW: data are transferred as-is, with no error correction; |
55 | * checking | 55 | * this mode implies %MTD_OPS_PLACE_OOB |
56 | * | ||
57 | * These modes can be passed to ioctl(MEMWRITE) and are also used internally. | ||
58 | * See notes on "MTD file modes" for discussion on %MTD_OPS_RAW vs. | ||
59 | * %MTD_FILE_MODE_RAW. | ||
56 | */ | 60 | */ |
57 | enum { | 61 | enum { |
58 | MTD_OPS_PLACE_OOB = 0, | 62 | MTD_OPS_PLACE_OOB = 0, |
@@ -60,6 +64,22 @@ enum { | |||
60 | MTD_OPS_RAW = 2, | 64 | MTD_OPS_RAW = 2, |
61 | }; | 65 | }; |
62 | 66 | ||
67 | /** | ||
68 | * struct mtd_write_req - data structure for requesting a write operation | ||
69 | * | ||
70 | * @start: start address | ||
71 | * @len: length of data buffer | ||
72 | * @ooblen: length of OOB buffer | ||
73 | * @usr_data: user-provided data buffer | ||
74 | * @usr_oob: user-provided OOB buffer | ||
75 | * @mode: MTD mode (see "MTD operation modes") | ||
76 | * @padding: reserved, must be set to 0 | ||
77 | * | ||
78 | * This structure supports ioctl(MEMWRITE) operations, allowing data and/or OOB | ||
79 | * writes in various modes. To write to OOB-only, set @usr_data == NULL, and to | ||
80 | * write data-only, set @usr_oob == NULL. However, setting both @usr_data and | ||
81 | * @usr_oob to NULL is not allowed. | ||
82 | */ | ||
63 | struct mtd_write_req { | 83 | struct mtd_write_req { |
64 | __u64 start; | 84 | __u64 start; |
65 | __u64 len; | 85 | __u64 len; |
@@ -84,13 +104,13 @@ struct mtd_write_req { | |||
84 | #define MTD_NO_ERASE 0x1000 /* No erase necessary */ | 104 | #define MTD_NO_ERASE 0x1000 /* No erase necessary */ |
85 | #define MTD_POWERUP_LOCK 0x2000 /* Always locked after reset */ | 105 | #define MTD_POWERUP_LOCK 0x2000 /* Always locked after reset */ |
86 | 106 | ||
87 | // Some common devices / combinations of capabilities | 107 | /* Some common devices / combinations of capabilities */ |
88 | #define MTD_CAP_ROM 0 | 108 | #define MTD_CAP_ROM 0 |
89 | #define MTD_CAP_RAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE) | 109 | #define MTD_CAP_RAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE) |
90 | #define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE) | 110 | #define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE) |
91 | #define MTD_CAP_NANDFLASH (MTD_WRITEABLE) | 111 | #define MTD_CAP_NANDFLASH (MTD_WRITEABLE) |
92 | 112 | ||
93 | /* ECC byte placement */ | 113 | /* Obsolete ECC byte placement modes (used with obsolete MEMGETOOBSEL) */ |
94 | #define MTD_NANDECC_OFF 0 // Switch off ECC (Not recommended) | 114 | #define MTD_NANDECC_OFF 0 // Switch off ECC (Not recommended) |
95 | #define MTD_NANDECC_PLACE 1 // Use the given placement in the structure (YAFFS1 legacy mode) | 115 | #define MTD_NANDECC_PLACE 1 // Use the given placement in the structure (YAFFS1 legacy mode) |
96 | #define MTD_NANDECC_AUTOPLACE 2 // Use the default placement scheme | 116 | #define MTD_NANDECC_AUTOPLACE 2 // Use the default placement scheme |
@@ -105,10 +125,10 @@ struct mtd_write_req { | |||
105 | struct mtd_info_user { | 125 | struct mtd_info_user { |
106 | __u8 type; | 126 | __u8 type; |
107 | __u32 flags; | 127 | __u32 flags; |
108 | __u32 size; // Total size of the MTD | 128 | __u32 size; /* Total size of the MTD */ |
109 | __u32 erasesize; | 129 | __u32 erasesize; |
110 | __u32 writesize; | 130 | __u32 writesize; |
111 | __u32 oobsize; // Amount of OOB data per block (e.g. 16) | 131 | __u32 oobsize; /* Amount of OOB data per block (e.g. 16) */ |
112 | /* The below two fields are obsolete and broken, do not use them | 132 | /* The below two fields are obsolete and broken, do not use them |
113 | * (TODO: remove at some point) */ | 133 | * (TODO: remove at some point) */ |
114 | __u32 ecctype; | 134 | __u32 ecctype; |
@@ -117,9 +137,9 @@ struct mtd_info_user { | |||
117 | 137 | ||
118 | struct region_info_user { | 138 | struct region_info_user { |
119 | __u32 offset; /* At which this region starts, | 139 | __u32 offset; /* At which this region starts, |
120 | * from the beginning of the MTD */ | 140 | * from the beginning of the MTD */ |
121 | __u32 erasesize; /* For this region */ | 141 | __u32 erasesize; /* For this region */ |
122 | __u32 numblocks; /* Number of blocks in this region */ | 142 | __u32 numblocks; /* Number of blocks in this region */ |
123 | __u32 regionindex; | 143 | __u32 regionindex; |
124 | }; | 144 | }; |
125 | 145 | ||
@@ -135,28 +155,54 @@ struct otp_info { | |||
135 | * Try to avoid adding a new ioctl with the same ioctl number. | 155 | * Try to avoid adding a new ioctl with the same ioctl number. |
136 | */ | 156 | */ |
137 | 157 | ||
158 | /* Get basic MTD characteristics info (better to use sysfs) */ | ||
138 | #define MEMGETINFO _IOR('M', 1, struct mtd_info_user) | 159 | #define MEMGETINFO _IOR('M', 1, struct mtd_info_user) |
160 | /* Erase segment of MTD */ | ||
139 | #define MEMERASE _IOW('M', 2, struct erase_info_user) | 161 | #define MEMERASE _IOW('M', 2, struct erase_info_user) |
162 | /* Write out-of-band data from MTD */ | ||
140 | #define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf) | 163 | #define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf) |
164 | /* Read out-of-band data from MTD */ | ||
141 | #define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf) | 165 | #define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf) |
166 | /* Lock a chip (for MTD that supports it) */ | ||
142 | #define MEMLOCK _IOW('M', 5, struct erase_info_user) | 167 | #define MEMLOCK _IOW('M', 5, struct erase_info_user) |
168 | /* Unlock a chip (for MTD that supports it) */ | ||
143 | #define MEMUNLOCK _IOW('M', 6, struct erase_info_user) | 169 | #define MEMUNLOCK _IOW('M', 6, struct erase_info_user) |
170 | /* Get the number of different erase regions */ | ||
144 | #define MEMGETREGIONCOUNT _IOR('M', 7, int) | 171 | #define MEMGETREGIONCOUNT _IOR('M', 7, int) |
172 | /* Get information about the erase region for a specific index */ | ||
145 | #define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user) | 173 | #define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user) |
174 | /* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */ | ||
146 | #define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo) | 175 | #define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo) |
176 | /* Check if an eraseblock is bad */ | ||
147 | #define MEMGETBADBLOCK _IOW('M', 11, __kernel_loff_t) | 177 | #define MEMGETBADBLOCK _IOW('M', 11, __kernel_loff_t) |
178 | /* Mark an eraseblock as bad */ | ||
148 | #define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t) | 179 | #define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t) |
180 | /* Set OTP (One-Time Programmable) mode (factory vs. user) */ | ||
149 | #define OTPSELECT _IOR('M', 13, int) | 181 | #define OTPSELECT _IOR('M', 13, int) |
182 | /* Get number of OTP (One-Time Programmable) regions */ | ||
150 | #define OTPGETREGIONCOUNT _IOW('M', 14, int) | 183 | #define OTPGETREGIONCOUNT _IOW('M', 14, int) |
184 | /* Get all OTP (One-Time Programmable) info about MTD */ | ||
151 | #define OTPGETREGIONINFO _IOW('M', 15, struct otp_info) | 185 | #define OTPGETREGIONINFO _IOW('M', 15, struct otp_info) |
186 | /* Lock a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */ | ||
152 | #define OTPLOCK _IOR('M', 16, struct otp_info) | 187 | #define OTPLOCK _IOR('M', 16, struct otp_info) |
188 | /* Get ECC layout (deprecated) */ | ||
153 | #define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout_user) | 189 | #define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout_user) |
190 | /* Get statistics about corrected/uncorrected errors */ | ||
154 | #define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats) | 191 | #define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats) |
192 | /* Set MTD mode on a per-file-descriptor basis (see "MTD file modes") */ | ||
155 | #define MTDFILEMODE _IO('M', 19) | 193 | #define MTDFILEMODE _IO('M', 19) |
194 | /* Erase segment of MTD (supports 64-bit address) */ | ||
156 | #define MEMERASE64 _IOW('M', 20, struct erase_info_user64) | 195 | #define MEMERASE64 _IOW('M', 20, struct erase_info_user64) |
196 | /* Write data to OOB (64-bit version) */ | ||
157 | #define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64) | 197 | #define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64) |
198 | /* Read data from OOB (64-bit version) */ | ||
158 | #define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64) | 199 | #define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64) |
200 | /* Check if chip is locked (for MTD that supports it) */ | ||
159 | #define MEMISLOCKED _IOR('M', 23, struct erase_info_user) | 201 | #define MEMISLOCKED _IOR('M', 23, struct erase_info_user) |
202 | /* | ||
203 | * Most generic write interface; can write in-band and/or out-of-band in various | ||
204 | * modes (see "struct mtd_write_req") | ||
205 | */ | ||
160 | #define MEMWRITE _IOWR('M', 24, struct mtd_write_req) | 206 | #define MEMWRITE _IOWR('M', 24, struct mtd_write_req) |
161 | 207 | ||
162 | /* | 208 | /* |
@@ -208,7 +254,21 @@ struct mtd_ecc_stats { | |||
208 | }; | 254 | }; |
209 | 255 | ||
210 | /* | 256 | /* |
211 | * Read/write file modes for access to MTD | 257 | * MTD file modes - for read/write access to MTD |
258 | * | ||
259 | * @MTD_FILE_MODE_NORMAL: OTP disabled, ECC enabled | ||
260 | * @MTD_FILE_MODE_OTP_FACTORY: OTP enabled in factory mode | ||
261 | * @MTD_FILE_MODE_OTP_USER: OTP enabled in user mode | ||
262 | * @MTD_FILE_MODE_RAW: OTP disabled, ECC disabled | ||
263 | * | ||
264 | * These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained | ||
265 | * separately for each open file descriptor. | ||
266 | * | ||
267 | * Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW - | ||
268 | * raw access to the flash, without error correction or autoplacement schemes. | ||
269 | * Wherever possible, the MTD_OPS_* mode will override the MTD_FILE_MODE_* mode | ||
270 | * (e.g., when using ioctl(MEMWRITE)), but in some cases, the MTD_FILE_MODE is | ||
271 | * used out of necessity (e.g., `write()', ioctl(MEMWRITEOOB64)). | ||
212 | */ | 272 | */ |
213 | enum mtd_file_modes { | 273 | enum mtd_file_modes { |
214 | MTD_FILE_MODE_NORMAL = MTD_OTP_OFF, | 274 | MTD_FILE_MODE_NORMAL = MTD_OTP_OFF, |