Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 1 | /* |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 2 | * $Id: mtd-abi.h,v 1.13 2005/11/07 11:14:56 gleixner Exp $ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 3 | * |
Wolfgang Denk | ac7eb8a | 2005-09-14 23:53:32 +0200 | [diff] [blame] | 4 | * Portions of MTD ABI definition which are shared by kernel and user space |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __MTD_ABI_H__ |
| 8 | #define __MTD_ABI_H__ |
| 9 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 10 | #if 1 |
Mike Frysinger | 7b15e2b | 2012-04-09 13:39:55 +0000 | [diff] [blame] | 11 | #include <linux/compat.h> |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 12 | #endif |
| 13 | |
Kim Phillips | 0d4c1c9 | 2012-10-29 13:34:24 +0000 | [diff] [blame] | 14 | #include <linux/compiler.h> |
| 15 | |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 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; |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 24 | unsigned char __user *ptr; |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 25 | }; |
| 26 | |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 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 | |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 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 |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 51 | #define MTD_DATAFLASH 6 |
| 52 | #define MTD_UBIVOLUME 7 |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 53 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 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 */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 58 | |
Wolfgang Denk | 4b07080 | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 59 | /* Some common devices / combinations of capabilities */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 60 | #define MTD_CAP_ROM 0 |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 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) |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 64 | |
| 65 | /* ECC byte placement */ |
Wolfgang Denk | 4b07080 | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 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 */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 71 | |
| 72 | /* OTP mode selection */ |
| 73 | #define MTD_OTP_OFF 0 |
| 74 | #define MTD_OTP_FACTORY 1 |
| 75 | #define MTD_OTP_USER 2 |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 76 | |
| 77 | struct mtd_info_user { |
| 78 | uint8_t type; |
| 79 | uint32_t flags; |
Wolfgang Denk | 4b07080 | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 80 | uint32_t size; /* Total size of the MTD */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 81 | uint32_t erasesize; |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 82 | uint32_t writesize; |
Wolfgang Denk | 4b07080 | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 83 | uint32_t oobsize; /* Amount of OOB data per block (e.g. 16) */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 84 | /* The below two fields are obsolete and broken, do not use them |
| 85 | * (TODO: remove at some point) */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 86 | uint32_t ecctype; |
| 87 | uint32_t eccsize; |
| 88 | }; |
| 89 | |
| 90 | struct region_info_user { |
Wolfgang Denk | ac7eb8a | 2005-09-14 23:53:32 +0200 | [diff] [blame] | 91 | uint32_t offset; /* At which this region starts, |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 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 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 98 | struct otp_info { |
| 99 | uint32_t start; |
| 100 | uint32_t length; |
| 101 | uint32_t locked; |
| 102 | }; |
| 103 | |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 104 | /* Get basic MTD characteristics info (better to use sysfs) */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 105 | #define MEMGETINFO _IOR('M', 1, struct mtd_info_user) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 106 | /* Erase segment of MTD */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 107 | #define MEMERASE _IOW('M', 2, struct erase_info_user) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 108 | /* Write out-of-band data from MTD */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 109 | #define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 110 | /* Read out-of-band data from MTD */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 111 | #define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 112 | /* Lock a chip (for MTD that supports it) */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 113 | #define MEMLOCK _IOW('M', 5, struct erase_info_user) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 114 | /* Unlock a chip (for MTD that supports it) */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 115 | #define MEMUNLOCK _IOW('M', 6, struct erase_info_user) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 116 | /* Get the number of different erase regions */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 117 | #define MEMGETREGIONCOUNT _IOR('M', 7, int) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 118 | /* Get information about the erase region for a specific index */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 119 | #define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 120 | /* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 121 | #define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo) |
| 122 | #define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 123 | /* Check if an eraseblock is bad */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 124 | #define MEMGETBADBLOCK _IOW('M', 11, loff_t) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 125 | /* Mark an eraseblock as bad */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 126 | #define MEMSETBADBLOCK _IOW('M', 12, loff_t) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 127 | /* Set OTP (One-Time Programmable) mode (factory vs. user) */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 128 | #define OTPSELECT _IOR('M', 13, int) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 129 | /* Get number of OTP (One-Time Programmable) regions */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 130 | #define OTPGETREGIONCOUNT _IOW('M', 14, int) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 131 | /* Get all OTP (One-Time Programmable) info about MTD */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 132 | #define OTPGETREGIONINFO _IOW('M', 15, struct otp_info) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 133 | /* Lock a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 134 | #define OTPLOCK _IOR('M', 16, struct otp_info) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 135 | /* Get ECC layout (deprecated) */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 136 | #define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 137 | /* Get statistics about corrected/uncorrected errors */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 138 | #define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats) |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 139 | /* Set MTD mode on a per-file-descriptor basis (see "MTD file modes") */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 140 | #define MTDFILEMODE _IO('M', 19) |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 141 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 142 | /* |
| 143 | * Obsolete legacy interface. Keep it in order not to break userspace |
| 144 | * interfaces |
| 145 | */ |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 146 | struct nand_oobinfo { |
| 147 | uint32_t useecc; |
| 148 | uint32_t eccbytes; |
| 149 | uint32_t oobfree[8][2]; |
Sergei Poselenov | 248ae5c | 2008-06-06 15:42:43 +0200 | [diff] [blame] | 150 | uint32_t eccpos[48]; |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 151 | }; |
| 152 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 153 | struct nand_oobfree { |
| 154 | uint32_t offset; |
| 155 | uint32_t length; |
| 156 | }; |
| 157 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 158 | /** |
| 159 | * struct mtd_ecc_stats - error correction stats |
| 160 | * |
| 161 | * @corrected: number of corrected bits |
| 162 | * @failed: number of uncorrectable errors |
| 163 | * @badblocks: number of bad blocks in this partition |
| 164 | * @bbtblocks: number of blocks reserved for bad block tables |
| 165 | */ |
| 166 | struct mtd_ecc_stats { |
| 167 | uint32_t corrected; |
| 168 | uint32_t failed; |
| 169 | uint32_t badblocks; |
| 170 | uint32_t bbtblocks; |
| 171 | }; |
| 172 | |
| 173 | /* |
Sergey Lapin | dfe64e2 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 174 | * MTD file modes - for read/write access to MTD |
| 175 | * |
| 176 | * @MTD_FILE_MODE_NORMAL: OTP disabled, ECC enabled |
| 177 | * @MTD_FILE_MODE_OTP_FACTORY: OTP enabled in factory mode |
| 178 | * @MTD_FILE_MODE_OTP_USER: OTP enabled in user mode |
| 179 | * @MTD_FILE_MODE_RAW: OTP disabled, ECC disabled |
| 180 | * |
| 181 | * These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained |
| 182 | * separately for each open file descriptor. |
| 183 | * |
| 184 | * Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW - |
| 185 | * raw access to the flash, without error correction or autoplacement schemes. |
| 186 | * Wherever possible, the MTD_OPS_* mode will override the MTD_FILE_MODE_* mode |
| 187 | * (e.g., when using ioctl(MEMWRITE)), but in some cases, the MTD_FILE_MODE is |
| 188 | * used out of necessity (e.g., `write()', ioctl(MEMWRITEOOB64)). |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 189 | */ |
| 190 | enum mtd_file_modes { |
| 191 | MTD_MODE_NORMAL = MTD_OTP_OFF, |
| 192 | MTD_MODE_OTP_FACTORY = MTD_OTP_FACTORY, |
| 193 | MTD_MODE_OTP_USER = MTD_OTP_USER, |
| 194 | MTD_MODE_RAW, |
| 195 | }; |
| 196 | |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 197 | #endif /* __MTD_ABI_H__ */ |