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 7 #ifndef __MTD_ABI_H__ 8 #define __MTD_ABI_H__ 9 10 #if 1 11 #include <linux/compat.h> 12 #endif 13 14 #include <linux/compiler.h> 15 16 struct erase_info_user { 17 uint32_t start; 18 uint32_t length; 19 }; 20 21 struct mtd_oob_buf { 22 uint32_t start; 23 uint32_t length; 24 unsigned char __user *ptr; 25 }; 26 27 /* 28 * MTD operation modes 29 * 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 35 * 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. 38 * %MTD_FILE_MODE_RAW. 39 */ 40 enum { 41 MTD_OPS_PLACE_OOB = 0, 42 MTD_OPS_AUTO_OOB = 1, 43 MTD_OPS_RAW = 2, 44 }; 45 46 #define MTD_ABSENT 0 47 #define MTD_RAM 1 48 #define MTD_ROM 2 49 #define MTD_NORFLASH 3 50 #define MTD_NANDFLASH 4 51 #define MTD_DATAFLASH 6 52 #define MTD_UBIVOLUME 7 53 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 */ 58 59 /* Some common devices / combinations of capabilities */ 60 #define MTD_CAP_ROM 0 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) 64 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 */ 71 72 /* OTP mode selection */ 73 #define MTD_OTP_OFF 0 74 #define MTD_OTP_FACTORY 1 75 #define MTD_OTP_USER 2 76 77 struct mtd_info_user { 78 uint8_t type; 79 uint32_t flags; 80 uint32_t size; /* Total size of the MTD */ 81 uint32_t erasesize; 82 uint32_t writesize; 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) */ 86 uint32_t ecctype; 87 uint32_t eccsize; 88 }; 89 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 */ 95 uint32_t regionindex; 96 }; 97 98 struct otp_info { 99 uint32_t start; 100 uint32_t length; 101 uint32_t locked; 102 }; 103 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) 141 142 /* 143 * Obsolete legacy interface. Keep it in order not to break userspace 144 * interfaces 145 */ 146 struct nand_oobinfo { 147 uint32_t useecc; 148 uint32_t eccbytes; 149 uint32_t oobfree[8][2]; 150 uint32_t eccpos[48]; 151 }; 152 153 struct nand_oobfree { 154 uint32_t offset; 155 uint32_t length; 156 }; 157 158 #define MTD_MAX_OOBFREE_ENTRIES 8 159 /* 160 * ECC layout control structure. Exported to userspace for 161 * diagnosis and to allow creation of raw images 162 */ 163 struct nand_ecclayout { 164 uint32_t eccbytes; 165 uint32_t eccpos[128]; 166 uint32_t oobavail; 167 struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES]; 168 }; 169 170 /** 171 * struct mtd_ecc_stats - error correction stats 172 * 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 177 */ 178 struct mtd_ecc_stats { 179 uint32_t corrected; 180 uint32_t failed; 181 uint32_t badblocks; 182 uint32_t bbtblocks; 183 }; 184 185 /* 186 * MTD file modes - for read/write access to MTD 187 * 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 192 * 193 * These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained 194 * separately for each open file descriptor. 195 * 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)). 201 */ 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, 206 MTD_MODE_RAW, 207 }; 208 209 #endif /* __MTD_ABI_H__ */ 210